Multitask and WM_LOCK()/WM_UNLOCK()

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Multitask and WM_LOCK()/WM_UNLOCK()

    Hello,

    Recent day I was struggling in handling with multitasks calling emWin.

    It seems that sometimes I need to use the pair of WM_LOCK()/WM_UNLOCK().
    But not very sure. The manual does not mention it in details.

    In my multitask system (FreeRTOS), I follow the recommendations (chapter 17.4.5) strictly:
    - All UI requests are organized as events
    - One task handling with UI events as UI foreground task
    - One task calling GUI_Exec() as UI background task
    - Other real time tasks sending UI events to UI foreground task
    - Also there're some custom widgets

    But the code does not seem that stable, sometimes complains with "DataAbortFault".
    So I start to think about using the pair of WM_LOCK()/WM_UNLOCK(), just as a try.

    The questions are:

    Do I need to use them in any callbacks? (I thought NOT)
    Or just in the creation/callback/get/set functions of the custom widgets? (I thought NOT ENOUGH)
    Is there any general guideline to use the pair of WM_LOCK()/WM_UNLOCK()?

    Would anybody kindly give a clear answer?
    Thanks in advance!

    Kenmux
  • Hi,

    WM_LOCK and WM_UNLOCK shouldn't be used. This functions are not documented and for internal use only.

    The recommended way to use emWin in a multitasking environment is to have only one task for emWin (and other tasks for e.g. IP). It is possible to use emWin from multiple tasks but you have to take care what you are doing. Otherwise unpredictable things can happen.

    But if you use emWin from multiple tasks please make sure you have implemented the following functions in GUI_X.c correctly (besides the things you have listed already). Attached is a sample file for FreeRTOS.

    C Source Code

    1. GUI_X_InitOS()
    2. GUI_X_Unlock()
    3. GUI_X_Lock()
    4. GUI_X_GetTaskId()
    5. GUI_X_WaitEvent()
    6. GUI_X_SignalEvent()
    7. GUI_X_WaitEventTimed()


    Further the define GUI_OS has to be set to 1 in GUIConf.h. If this is not the case multitask is disabled. When using a precompiled library it is not possible to enable it afterwards.

    Regards,
    Sven
    Files
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Sven,

    Thanks for your reply.
    Your info is useful, but there's something else.

    Consider in this scenario under multitask system:

    Two widgets use the same callback. Then how to protect it?
    Any mechanism to make sure only one use it at the same time?
    Use GUI_X_Lock()/GUI_X_Unlock()? Any recommendations?

    Thanks,
    Kenmux

    The post was edited 2 times, last by kenmux ().