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 );
}