Question about restarting GUI in multi-task system

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

  • Question about restarting GUI in multi-task system

    Hello,

    In my project, there's a requirement for restarting GUI.

    My debugging code as follows:

    1) In the main UI task:

    C Source Code

    1. // Exit task
    2. EXIT :
    3. #if (GUI_X_SINGLE_TASK == 0)
    4. GUI_X_Task_Delete(); //Delete background GUI task
    5. #endif
    6. GUI_Exit();
    7. vTaskDelay(10);
    8. GUI_Init();
    9. WM_SelectWindow(WM_GetDesktopWindowEx(0));
    10. GUI_DrawBitmap(UI_ImageTable[IMG_SPLASH_1_INDEX], 0, 0);
    11. GUI_Delay(500);
    12. UI_NotifyFTTask(TASK_EVENT_MISC_RETURN_TO_FT); //Ask test UI task to continue
    13. vTaskDelete(NULL);
    Display All


    2) In the test UI task

    C Source Code

    1. // Clear Key Message Buffer before starting UI
    2. START : GUI_ClearKeyBuffer();
    3. // Start UI
    4. DEBUG_MSG("FT\r\n");
    5. UI_EnterFTMenu(WM_HBKWIN);
    6. vTaskDelay(50);


    3) Background task:

    C Source Code

    1. #if (GUI_X_SINGLE_TASK == 0)
    2. /*******************************************************************
    3. *
    4. * _GUI_Task
    5. *
    6. * This task does the background processing.
    7. * The MainTask job is to update invalid windows, but other things such as
    8. * evaluating mouse or touch input may also be done.
    9. */
    10. static void _GUI_Task( void *pvParameters ) {
    11. (void)pvParameters;
    12. DEBUG_MSG ("<I> _GUI_Task Up\r\n");
    13. while (1) {
    14. /* Do the background work */
    15. GUI_Exec();
    16. GUI_X_ExecIdle();
    17. }
    18. }
    19. #endif
    Display All


    4) GUI Init custom code:

    C Source Code

    1. /*********************************************************************
    2. *
    3. * GUI_X_Init()
    4. *
    5. * Note:
    6. * This routine is called from GUI_Init() in any case whether there
    7. * is an RTOS or not. You can use it for additional initializations
    8. * needed.
    9. */
    10. void GUI_X_Init(void) {
    11. #if (GUI_X_SINGLE_TASK == 0)
    12. BaseType_t result = xTaskCreate(_GUI_Task, "XBKG", configUI_BKG_TASK_STACK_SIZE,
    13. NULL, mainQUEUE_UI_BG_TASK_PRIORITY, &_pGUITask);
    14. if (result != pdPASS) for (;;) ;
    15. #endif
    16. }
    Display All


    It's all okay if I don't use the background task (GUI_X_SINGLE_TASK == 1).
    But, the codes always stop at calling the first "GUI_XXX" function in the test UI task when using background task.

    So, my question is:
    Is deleting background task is the only work to do during restarting GUI?
    Am I missing something crucial else?

    emWin Version: v5.44b
    Also, I use the FreeRTOS.

    Any idea or advice? Thanks.

    Kenmux

    The post was edited 1 time, last by kenmux ().

  • Hi,

    Is the define GUI_OS set to 1 in GUIConf.h?

    Did you implemented the functions GUI_X_InitOS(), GUI_X_Unlock(), GUI_X_Lock(), GUI_X_GetTaskId() properly?

    Where exactly does it crash (check how far you get when stepping into the code)?

    Is the test UI task still running after GUI_Exit()?
    I think it should also be terminated because it's calling GUI functions.

    Also, we recommend to call GUI_Exec() from only one task (GUI_Exec() gets called indirectly from GUI_Delay()).

    Regards
    Sven
  • Hello Sven,

    Thanks for your reply!

    I checked carefully with the code, and did some modifications:

    1) In the main UI task, calling GUI_Exec() before calling GUI_Exit():

    C Source Code

    1. // Exit task
    2. EXIT : GUI_Exec();
    3. GUI_X_Exit();
    4. GUI_Exit();
    5. vTaskDelay(10);
    6. GUI_Init();
    7. WM_SelectWindow(WM_GetDesktopWindowEx(0));
    8. GUI_DrawBitmap(UI_ImageTable[IMG_SPLASH_1_INDEX], 0, 0);
    9. GUI_Delay(500);
    10. UI_NotifyFTTask(TASK_EVENT_MISC_RETURN_TO_FT);
    11. vTaskDelete(NULL);
    Display All


    2) To make sure all resources released, I added this function:

    C Source Code

    1. void GUI_X_Exit(void) {
    2. #if (GUI_X_SINGLE_TASK == 0)
    3. if (_pGUITask) {
    4. vTaskDelete(_pGUITask);
    5. _pGUITask = NULL;
    6. }
    7. #endif
    8. if (_Semaphore) {
    9. vSemaphoreDelete(_Semaphore);
    10. _Semaphore = NULL;
    11. }
    12. }
    Display All


    Then it worked perfectly.
    Yes you are right! There should be ONLY ONE task to call GUI_Exec()...
    I'll look into the code to make sure it!

    Best regards,
    Kenmux

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