cancel
Showing results for 
Search instead for 
Did you mean: 

When using other OS

Ebun.1
Senior

Hello

How to approach when using other OS, for example, when using Mbed OS5?

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

Hi @Ebun.1​,

Using a different operating system requires two things, generally:

  1. Implement the hooks provided by the OSWrappers interface.
  2. Write code to start touchgfx in a task for your OS

The interface for OSWrappers is as follows:

#ifndef OSWRAPPERS_HPP
#define OSWRAPPERS_HPP
 
#include <touchgfx/hal/Types.hpp>
 
namespace touchgfx
{
class OSWrappers
{
public:
 
    /**
     * @fn static void OSWrappers::initialize();
     *
     * @brief Initialize frame buffer semaphore and queue/mutex for VSYNC signal.
     *
     *        Initialize frame buffer semaphore and queue/mutex for VSYNC signal.
     */
    static void initialize();
 
    /**
     * @fn static void OSWrappers::signalVSync();
     *
     * @brief Signal that a VSYNC has occurred.
     *
     *        Signal that a VSYNC has occurred. Should make the vsync queue/mutex available.
     *
     * @note This function is called from an ISR, and should (depending on OS) trigger a
     *       scheduling.
     */
    static void signalVSync();
 
    /**
     * @fn static void OSWrappers::waitForVSync();
     *
     * @brief This function blocks until a VSYNC occurs.
     *
     *        This function blocks until a VSYNC occurs.
     *
     * @note This function must first clear the mutex/queue and then wait for the next one to
     *       occur.
     */
    static void waitForVSync();
 
    /**
     * @fn static void OSWrappers::takeFrameBufferSemaphore();
     *
     * @brief Take the frame buffer semaphore.
     *
     *        Take the frame buffer semaphore. Blocks until semaphore is available.
     */
    static void takeFrameBufferSemaphore();
 
    /**
     * @fn static void OSWrappers::tryTakeFrameBufferSemaphore();
     *
     * @brief Attempt to obtain the frame buffer semaphore.
     *
     *        Attempt to obtain the frame buffer semaphore. If semaphore is not available, do
     *        nothing.
     *
     * @note must return immediately! This function does not care who has the taken the semaphore,
     *       it only serves to make sure that the semaphore is taken by someone.
     */
    static void tryTakeFrameBufferSemaphore();
 
    /**
     * @fn static void OSWrappers::giveFrameBufferSemaphore();
     *
     * @brief Release the frame buffer semaphore.
     *
     *        Release the frame buffer semaphore.
     */
    static void giveFrameBufferSemaphore();
 
    /**
     * @fn static void OSWrappers::giveFrameBufferSemaphoreFromISR();
     *
     * @brief Release the frame buffer semaphore in a way that is safe in interrupt context. Called
     *        from ISR.
     *
     *        Release the frame buffer semaphore in a way that is safe in interrupt context.
     *        Called from ISR.
     */
    static void giveFrameBufferSemaphoreFromISR();
 
    /**
     * @fn static void taskDelay(uint16_t ms);
     *
     * @brief A function that causes executing task to sleep for a number of milliseconds.
     *
     *        A function that causes executing task to sleep for a number of milliseconds.
     *        This function is OPTIONAL. It is only used by the TouchGFX in the case of
     *        a specific frame refresh strategy (REFRESH_STRATEGY_OPTIM_SINGLE_BUFFER_TFT_CTRL).
     *        Due to backwards compatibility, in order for this function to be useable by the HAL
     *        the function must be explicitly registered:
     *          hal.registerTaskDelayFunction(&OSWrappers::taskDelay)
     * @param ms The number of milliseconds to sleep
     * @see HAL::setFrameRefreshStrategy(FrameRefreshStrategy s)
     * @see HAL::registerTaskDelayFunction(void (*delayF)(uint16_t))
     */
    static void taskDelay(uint16_t ms);
};
} // namespace touchgfx
#endif // OSWRAPPERS_HPP

You need to provide implementations for these functions that use OS primitives for your particular OS. I haven't tried creating one for MBED OS, but i'd be happy to help give some pointers.

/Martin

View solution in original post

3 REPLIES 3
Martin KJELDSEN
Chief III

Hi @Ebun.1​,

Using a different operating system requires two things, generally:

  1. Implement the hooks provided by the OSWrappers interface.
  2. Write code to start touchgfx in a task for your OS

The interface for OSWrappers is as follows:

#ifndef OSWRAPPERS_HPP
#define OSWRAPPERS_HPP
 
#include <touchgfx/hal/Types.hpp>
 
namespace touchgfx
{
class OSWrappers
{
public:
 
    /**
     * @fn static void OSWrappers::initialize();
     *
     * @brief Initialize frame buffer semaphore and queue/mutex for VSYNC signal.
     *
     *        Initialize frame buffer semaphore and queue/mutex for VSYNC signal.
     */
    static void initialize();
 
    /**
     * @fn static void OSWrappers::signalVSync();
     *
     * @brief Signal that a VSYNC has occurred.
     *
     *        Signal that a VSYNC has occurred. Should make the vsync queue/mutex available.
     *
     * @note This function is called from an ISR, and should (depending on OS) trigger a
     *       scheduling.
     */
    static void signalVSync();
 
    /**
     * @fn static void OSWrappers::waitForVSync();
     *
     * @brief This function blocks until a VSYNC occurs.
     *
     *        This function blocks until a VSYNC occurs.
     *
     * @note This function must first clear the mutex/queue and then wait for the next one to
     *       occur.
     */
    static void waitForVSync();
 
    /**
     * @fn static void OSWrappers::takeFrameBufferSemaphore();
     *
     * @brief Take the frame buffer semaphore.
     *
     *        Take the frame buffer semaphore. Blocks until semaphore is available.
     */
    static void takeFrameBufferSemaphore();
 
    /**
     * @fn static void OSWrappers::tryTakeFrameBufferSemaphore();
     *
     * @brief Attempt to obtain the frame buffer semaphore.
     *
     *        Attempt to obtain the frame buffer semaphore. If semaphore is not available, do
     *        nothing.
     *
     * @note must return immediately! This function does not care who has the taken the semaphore,
     *       it only serves to make sure that the semaphore is taken by someone.
     */
    static void tryTakeFrameBufferSemaphore();
 
    /**
     * @fn static void OSWrappers::giveFrameBufferSemaphore();
     *
     * @brief Release the frame buffer semaphore.
     *
     *        Release the frame buffer semaphore.
     */
    static void giveFrameBufferSemaphore();
 
    /**
     * @fn static void OSWrappers::giveFrameBufferSemaphoreFromISR();
     *
     * @brief Release the frame buffer semaphore in a way that is safe in interrupt context. Called
     *        from ISR.
     *
     *        Release the frame buffer semaphore in a way that is safe in interrupt context.
     *        Called from ISR.
     */
    static void giveFrameBufferSemaphoreFromISR();
 
    /**
     * @fn static void taskDelay(uint16_t ms);
     *
     * @brief A function that causes executing task to sleep for a number of milliseconds.
     *
     *        A function that causes executing task to sleep for a number of milliseconds.
     *        This function is OPTIONAL. It is only used by the TouchGFX in the case of
     *        a specific frame refresh strategy (REFRESH_STRATEGY_OPTIM_SINGLE_BUFFER_TFT_CTRL).
     *        Due to backwards compatibility, in order for this function to be useable by the HAL
     *        the function must be explicitly registered:
     *          hal.registerTaskDelayFunction(&OSWrappers::taskDelay)
     * @param ms The number of milliseconds to sleep
     * @see HAL::setFrameRefreshStrategy(FrameRefreshStrategy s)
     * @see HAL::registerTaskDelayFunction(void (*delayF)(uint16_t))
     */
    static void taskDelay(uint16_t ms);
};
} // namespace touchgfx
#endif // OSWRAPPERS_HPP

You need to provide implementations for these functions that use OS primitives for your particular OS. I haven't tried creating one for MBED OS, but i'd be happy to help give some pointers.

/Martin

Hello

Thank you for your reply.

I wanted to know what to do.

I haven't even considered implementation yet.

Here's a quick example of how to start TouchGFX using old school FreeRTOS:

#define configGUI_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 3 )
#define configGUI_TASK_STK_SIZE                 ( 950 )
 
static void GUITask(void* params)
{
    touchgfx::HAL::getInstance()->taskEntry();
}
 
int main(void)
{
    //Init hardware
 
   //Init touchgfx
 
    xTaskCreate(GUITask, (TASKCREATE_NAME_TYPE)"GUITask",
                configGUI_TASK_STK_SIZE,
                NULL,
                configGUI_TASK_PRIORITY,
                NULL);
 
    vTaskStartScheduler();
 
    for (;;);
}