46 views
in GUI Development by

Hello,

I am using Embedded Wizard to develop our product, TFT panel for appliance is our application. In the device having a button for power on/off control, when power on, the TFT will display animation and user interface in the end. so I create a task named MainTask in main loop to detect the status of button, when user press button to power on, in code function will create task GuiThread to display animation. when user press button to power off, task GuiThread will delete task by himself. I take a behavior that power on / off repeatedly, sometime the animation will run abnormal and GuiThread will halt in the end, I can't figure out the problem, please help me to save this problem, thank. 

int main( void )
{
  /* initialize system */
  EwBspSystemInit();

  /* initialize console interface for debug messages */
  EwBspConsoleInit();

  EwBspClockInit();
  if ( EwBspClockGetTime() < RTC_MINIMUM_TIME )
    EwBspClockSetTime( RTC_DEFAULT_TIME );

  DeviceDriver_Initialize();

  InitialRAM();

  xTaskCreate( Maintask , "MainTask" , 1000, NULL, 0, NULL );

  /* ...and start scheduler */
  vTaskStartScheduler();

  /* restore console */
  EwBspConsoleDone();

  /* terminate the system */
  EwBspSystemDone();

  return 0;
}

static void Maintask(void *pvParameters)
{
    for (;;)
    {
        PowerManager();
        vTaskDelay(1);
    }
}

void PowerManager(void)
{
    ButtonStatusBuf = GPIO_PinRead( BOARD_USER_BUTTON_GPIO, BOARD_USER_BUTTON_GPIO_PIN );

    if (ButtonStatusBuf == 0)
    {
      if ((POWER.bits.bit7 == 0U) || (POWER.bits.bit6 == 0U))
      {
        if(++Power40msCnt >= 0x05U)
        {
          Power40msCnt = 0U;
          PowerIgnOn();
        }
      }
      else
      {
        Power40msCnt = 0U;
      }
    }
    else
    {
      if ((POWER.bits.bit7 == 0U) || ((POWER.bits.bit6 == 1U) && (POWER.bits.bit3 == 1U)))
      {
        if(++Power40msCnt >= 0x05U)
        {
          Power40msCnt = 0U;
          PowerIgnOff();
        }
      }
      else
      {
        Power40msCnt = 0U;
      }
    }
}

void PowerIgnOn(void)
{
  POWER.bits.bit7 = 1U;
  POWER.bits.bit6 = 1U;
  InitialRAM1();
  EwPrint( "Power On\n" );
  if (POWER.bits.bit4 == 0)
  {
    xTaskCreate( GuiThread, "EmWi_Task", semtstSTACK_SIZE, NULL, 2, &GuiThreadHandle);
    POWER.bits.bit4 = 1U;
  }

}

void PowerIgnOff(void)
{
  POWER.bits.bit7 = 1U;
  POWER.bits.bit6 = 0U;
  EwPrint( "Power Off\n" );
  InitialRAM1();
}

void GuiThread( void* arg )
{
  /* initialize Embedded Wizard application */
  if ( EwInit() == 0 )
  {
    EwPrint( "GUI Init Fail\n" );
    return; 
  }
  EwPrint( "GUI Init OK\n" );
  EwProcessStatus = 1U;
 
  while (EwProcessStatus)
  {
      EwProcess();
  }

  /* de-initialize Embedded Wizard application */
  EwDone();
  EwPrint( "Gui Close\n" );
  POWER.bits.bit4 = 0U;
  vTaskDelete( NULL );
}

 

1 Answer

0 votes
by
Hello,

difficult to give you the right answer for your question - but it seems to be more related to FreeRTOS than to GUI programming with Embedded Wizard.

From what I understand based on the provided source code, I can imagine that it is possible that

a) a GUIThread is created while the previous is still not terminated (POWER.bits.bit4 is cleared before vTaskDelete).

b) the function InitialRAM1() is called while the GUI thread is running.

It seems that you have implemented some state machine with different bits (POWER.bits.bit4...7) - maybe there are some states possible which are not foreseen or which results in unpredictable behavior.

Let me recommend to check with FreeRTOS functions whether the GUIThread is running or not.

Best regards,

Manfred.
by

Hi Manfred,

Thanks for your answer, 

a) POWER.bits.bit4 is used to prevent GUIThread be created while the previous is still not terminated, 

and each POWER ON not be executed immediately after POWER OFF, it is waiting for 3 second for POWER ON be executed. 

So the 3 second is enough for Task deleted. 

b) InitialRAM1 have nothing, just a blank function.

void InitialRAM1(void)

{

}

below debug message for repeating power on / off. Nothing different for each power on/off, but the Guithread is halt in the end.

by
Hi,

just to understand: What do you mean with "GUI thread was halt in the end"?

Another question: What happens when you remove EwInit(), EwProcess() and EwDone() - so that your software just creates and destroys the (empty) GUI Thread. Does this work?

Best regards,

Manfred.
by
Hi Manfred,

Used the EwPrint( "GUI Run\n" ) in the while loop of Guithread to confirm whether the Guithread still running.  I can't see the message "GUI Run" while the animation running abnormal.

  while (EwProcessStatus)

  {

      EwPrint( "GUI Run\n" );

      EwProcess();

  }

 

"What happens when you remove EwInit(), EwProcess() and EwDone() - so that your software just creates and destroys the (empty) GUI Thread. Does this work?"

I will try it, thanks.
by
Hi,

sorry, but I do not understand the complete issue... What means "while the animation running abnormal"?

Please try in a first step that creating and destroying of the FreeRTOS task works properly and that it is not possible to create a new thread while the old one is still running.

Then try to include a very simple GUI application (e.g. an animated rectangle) and verify if your power up / power down mechanism still works.

Finally, you can include your entire GUI application.

Best regards,

Manfred.

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...