static void prvLCDTask( void *pvParameters ) { xQueueMessage xReceivedMessage; /* Buffer into which strings are formatted and placed ready for display on the LCD. Note this is a static variable to prevent it being allocated on the task stack, which is too small to hold such a variable. The stack size is configured when the task is created. */ static char cBuffer[ 512 ]; unsigned char ucLine = 1; /* This function is the only function that uses printf(). If printf() is used from any other function then some sort of mutual exclusion on stdout will be necessary. This is also the only function that is permitted to access the LCD. First print out the number of bytes that remain in the FreeRTOS heap. This can be viewed in the terminal IO window within the IAR Embedded Workbench. */ printf( "%d bytes of heap space remain unallocated\n", ( int ) xPortGetFreeHeapSize() ); /* Just as a test of the port, and for no functional reason, check the task parameter contains its expected value. */ if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE ) { halLcdPrintLine( "Invalid parameter", ucLine, OVERWRITE_TEXT ); ucLine++; } for( ;; ) { /* Wait for a message to be received. Using portMAX_DELAY as the block time will result in an indefinite wait provided INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h, therefore there is no need to check the function return value and the function will only return when a value has been received. */ xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY ); /* Clear the LCD if no room remains for any more text output. */ if( ucLine > mainMAX_LCD_LINES ) { halLcdClearScreen(); ucLine = 0; } /* What is this message? What does it contain? */ switch( xReceivedMessage.cMessageID ) { case mainMESSAGE_BUTTON_UP : /* The button poll task has just informed this task that the up button on the joystick input has been pressed or released. */ sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue ); break; case mainMESSAGE_BUTTON_SEL : /* The select button interrupt just informed this task that the select button was pressed. Generate a table of task run time statistics and output this to the terminal IO window in the IAR embedded workbench. */ printf( "\nTask\t Abs Time\t %%Time\n*****************************************" ); vTaskGetRunTimeStats( ( signed char * ) cBuffer ); printf( cBuffer ); /* Also print out a message to the LCD - in this case the pointer to the string to print is sent directly in the ulMessageValue member of the message. This just demonstrates a different communication technique. */ sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue ); break; case mainMESSAGE_STATUS : /* The tick interrupt hook function has just informed this task of the system status. Generate a string in accordance with the status value. */ prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue ); break; default : sprintf( cBuffer, "Unknown message" ); break; } /* Output the message that was placed into the cBuffer array within the switch statement above, then move onto the next line ready for the next message to arrive on the queue. */ halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT ); ucLine++; } }
static void prvLCDTask( void *pvParameters ) { xQueueMessage xReceivedMessage; long lLine = Line1; const long lFontHeight = (((sFONT *)LCD_GetFont())->Height); /* Buffer into which strings are formatted and placed ready for display on the LCD. Note this is a static variable to prevent it being allocated on the task stack, which is too small to hold such a variable. The stack size is configured when the task is created. */ static char cBuffer[ 512 ]; /* This function is the only function that uses printf(). If printf() is used from any other function then some sort of mutual exclusion on stdout will be necessary. This is also the only function that is permitted to access the LCD. First print out the number of bytes that remain in the FreeRTOS heap. This can be viewed in the terminal IO window within the IAR Embedded Workbench. */ printf( "%d bytes of heap space remain unallocated\n", xPortGetFreeHeapSize() ); for( ;; ) { /* Wait for a message to be received. Using portMAX_DELAY as the block time will result in an indefinite wait provided INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h, therefore there is no need to check the function return value and the function will only return when a value has been received. */ xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY ); /* Clear the LCD if no room remains for any more text output. */ if( lLine > Line9 ) { LCD_Clear( Blue ); lLine = 0; } /* What is this message? What does it contain? */ switch( xReceivedMessage.cMessageID ) { case mainMESSAGE_BUTTON_UP : /* The button poll task has just informed this task that the up button on the joystick input has been pressed or released. */ sprintf( cBuffer, "Button up = %d", xReceivedMessage.lMessageValue ); break; case mainMESSAGE_BUTTON_SEL : /* The select button interrupt just informed this task that the select button was pressed. Generate a table of task run time statistics and output this to the terminal IO window in the IAR embedded workbench. */ printf( "\nTask\t Abs Time\t %%Time\n*****************************************" ); vTaskGetRunTimeStats( cBuffer ); printf( cBuffer ); /* Also print out a message to the LCD - in this case the pointer to the string to print is sent directly in the lMessageValue member of the message. This just demonstrates a different communication technique. */ sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.lMessageValue ); break; case mainMESSAGE_STATUS : /* The tick interrupt hook function has just informed this task of the system status. Generate a string in accordance with the status value. */ prvGenerateStatusMessage( cBuffer, xReceivedMessage.lMessageValue ); break; default : sprintf( cBuffer, "Unknown message" ); break; } /* Output the message that was placed into the cBuffer array within the switch statement above. */ LCD_DisplayStringLine( lLine, ( uint8_t * ) cBuffer ); /* Move onto the next LCD line, ready for the next iteration of this loop. */ lLine += lFontHeight; } }
static void prvLCDTask( void *pvParameters ) { xQueueMessage xReceivedMessage; /* Buffer into which strings are formatted and placed ready for display on the LCD. Note this is a static variable to prevent it being allocated on the task stack, which is too small to hold such a variable. The stack size is configured when the task is created. */ static char cBuffer[ 50 ]; unsigned char ucLine = 1; /* Now the scheduler has been started (it must have been for this task to be running), start the check timer too. The call to xTimerStart() will block until the command has been accepted. */ if( xCheckTimer != NULL ) { xTimerStart( xCheckTimer, portMAX_DELAY ); } /* This is the only function that is permitted to access the LCD. First print out the number of bytes that remain in the FreeRTOS heap. This is done after a short delay to ensure all the demo tasks have created all the objects they are going to use. */ vTaskDelay( mainTIMER_TEST_PERIOD * 10 ); sprintf( cBuffer, "%d heap free", ( int ) xPortGetFreeHeapSize() ); halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT ); ucLine++; /* Just as a test of the port, and for no functional reason, check the task parameter contains its expected value. */ if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE ) { halLcdPrintLine( "Invalid parameter", ucLine, OVERWRITE_TEXT ); ucLine++; } for( ;; ) { /* Wait for a message to be received. Using portMAX_DELAY as the block time will result in an indefinite wait provided INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h, therefore there is no need to check the function return value and the function will only return when a value has been received. */ xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY ); /* Clear the LCD if no room remains for any more text output. */ if( ucLine > mainMAX_LCD_LINES ) { halLcdClearScreen(); ucLine = 0; } /* What is this message? What does it contain? */ switch( xReceivedMessage.cMessageID ) { case mainMESSAGE_BUTTON_UP : /* The button poll task has just informed this task that the up button on the joystick input has been pressed or released. */ sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue ); break; case mainMESSAGE_BUTTON_SEL : /* The select button interrupt just informed this task that the select button has been pressed. In this case the pointer to the string to print is sent directly in the ulMessageValue member of the message. This just demonstrates a different communication technique. */ sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue ); break; case mainMESSAGE_STATUS : /* The tick interrupt hook function has just informed this task of the system status. Generate a string in accordance with the status value. */ prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue ); break; default : sprintf( cBuffer, "Unknown message" ); break; } /* Output the message that was placed into the cBuffer array within the switch statement above, then move onto the next line ready for the next message to arrive on the queue. */ halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT ); ucLine++; } }