// ============================================================================ void vDebugTask(void *pvParameters) { char ch; portBASE_TYPE xStatus; //uint16_t u16StackSize; /* The parameters are not used. */ (void) pvParameters; vDebugString("Debug task started.\r\n"); while(1) { // As long as there are characters in the queue fifo this code should // pop them out and send them as quick as possible out the UART. if(USART_GetFlagStatus(USART2, USART_FLAG_TXE)) { // We don't want to block forever - need to check on Rx too. xStatus = xQueueReceive(xDebugQueue, &ch, 10 / portTICK_RATE_MS); if(xStatus == pdPASS) USART_SendData(USART2, ch); } if (USART_GetFlagStatus(USART2, USART_FLAG_RXNE)) { ch = USART_ReceiveData(USART2); // Handle Debug Console Commands Here. switch (ch) { // Alphabetical list of commands the console debugger responds to. case 'm': vDebugPrintf("Mems dump Stopped.\r\n"); //vSetMemsDump(false); break; case 'M': vDebugPrintf("Mems dump Started.\r\n"); //vSetMemsDump(true); break; case 'a': vDebugPrintf("AtoD dump Stopped.\r\n"); //vSetAtoDDump(FALSE); break; case 'A': vDebugPrintf("AtoD dump Started.\r\n"); //vSetAtoDDump(TRUE); break; // Print out how much stack space remains on each task stack. case 's': vDebugPrintf("Remaining space on Task Stack:\r\n"); break; // Add general test code here... case 't': break; default: break; } } taskYIELD(); } }
void vDebugInit(int exampleNum) { vUSART2_Init(); vDebugInitQueue(); xTaskCreate((pdTASK_CODE)vDebugTask, (const signed char * const)"DEBUG", (unsigned short)configMINIMAL_STACK_SIZE, NULL, (unsigned portBASE_TYPE)mainDEBUG_TASK_PRIORITY, (xTaskHandle)NULL); // Clear the screen. vDebugPrintf("\e[2J\e[H"); vDebugPrintf("Example: %d\r\n",exampleNum); vDebugPrintf("System Core Clock is running at: %dMHz\r\n",SystemCoreClock/1000000); }
// ============================================================================ int main( void ) { HwInit(); vDebugInitQueue(); vDebugPrintf( "\r\nEPS Test1 0.0.1 - 1/4/2012\r\n" ); vDebugPrintResetType(); // Tasks get started here... xTaskCreate( vTimeTask, (signed char *) "TIME", configMINIMAL_STACK_SIZE, NULL, mainTIME_TASK_PRIORITY, &hTimeTask ); xTaskCreate( vMemsTask, (signed char *) "MEMS", configMINIMAL_STACK_SIZE, NULL, mainMEMS_TASK_PRIORITY, &hMemsTask ); xTaskCreate( vDebugTask, (signed char *) "DEBUG", configMINIMAL_STACK_SIZE, NULL, mainDEBUG_TASK_PRIORITY, &hDebugTask ); xTaskCreate( vEOBDTask, (signed char *) "EOBD", configMINIMAL_STACK_SIZE, NULL, mainEOBD_TASK_PRIORITY, &hEOBDTask ); vTaskStartScheduler(); // This should never return. // Will only get here if there was insufficient memory to create // the idle task. for( ;; ); }
portTASK_FUNCTION( vEOBDPrimitiveTask, pvParameters ) { EOBDMSG TxMsg; EOBDMSG RxMsg; EOBD_Primitive_Configure(); xEOBDQueueHandle = xQueueCreate(QLENGTH,sizeof(struct EOBSMessage *)); if(xEOBDQueueHandle == 0) { vDebugPrintf( "xEOBDQueueHandle == 0\r\n"); } vDebugString( "EOBD primitive task started.\r\n"); while(1) { if(xQueueReceive(xEOBDQueueHandleToPrim,&TxMsg , portMAX_DELAY)) { xQueueSend(xEOBDQueueHandle,&RxMsg, (portTickType)0); } } }
portTASK_FUNCTION( vEOBDTask, pvParameters ) { EOBDMSG RxMsg; EOBDMSG TxMsg; xEOBDQueueHandleToPrim = xQueueCreate(QLENGTH,sizeof(struct EOBSMessage *)); if(xEOBDQueueHandleToPrim == 0) { vDebugPrintf( "xEOBDQueueHandle == 0\r\n"); } xTaskCreate( vEOBDPrimitiveTask, (signed char *) "EOBDPrim", configMINIMAL_STACK_SIZE, NULL, mainEOBDPRIM_TASK_PRIORITY, &hEOBDPrimitiveTask ); vDebugString( "EOBD task started.\r\n"); while(1) { if(SendRcvd(&TxMsg, &RxMsg, (portTickType)50)) { } else { vDebugString( "SendRcvd timeout\r\n"); } } }
void vPrintStringAndNumber(const char *pcString, unsigned int ulValue) { /* Print the string, suspending the scheduler as method of mutual exclusion. */ vTaskSuspendAll(); { vDebugPrintf("%s %d\r\n", pcString, ulValue); } xTaskResumeAll(); }
void vPrintString(const char *pcString) { /* Print the string, suspending the scheduler as method of mutual exclusion. */ vTaskSuspendAll(); { vDebugPrintf(pcString); } xTaskResumeAll(); }
// Simply print to the debug console a string based on the type of reset. // ============================================================================ void vDebugPrintResetType( void ) { if ( PWR_GetFlagStatus( PWR_FLAG_WU ) ) vDebugPrintf( "PWR: Wake Up flag\r\n" ); if ( PWR_GetFlagStatus( PWR_FLAG_SB ) ) vDebugPrintf( "PWR: StandBy flag.\r\n" ); if ( PWR_GetFlagStatus( PWR_FLAG_PVDO ) ) vDebugPrintf( "PWR: PVD Output.\r\n" ); if ( PWR_GetFlagStatus( PWR_FLAG_BRR ) ) vDebugPrintf( "PWR: Backup regulator ready flag.\r\n" ); if ( PWR_GetFlagStatus( PWR_FLAG_REGRDY ) ) vDebugPrintf( "PWR: Main regulator ready flag.\r\n" ); if ( RCC_GetFlagStatus( RCC_FLAG_BORRST ) ) vDebugPrintf( "RCC: POR/PDR or BOR reset\r\n" ); if ( RCC_GetFlagStatus( RCC_FLAG_PINRST ) ) vDebugPrintf( "RCC: Pin reset.\r\n" ); if ( RCC_GetFlagStatus( RCC_FLAG_PORRST ) ) vDebugPrintf( "RCC: POR/PDR reset.\r\n" ); if ( RCC_GetFlagStatus( RCC_FLAG_SFTRST ) ) vDebugPrintf( "RCC: Software reset.\r\n" ); if ( RCC_GetFlagStatus( RCC_FLAG_IWDGRST ) ) vDebugPrintf( "RCC: Independent Watchdog reset.\r\n" ); if ( RCC_GetFlagStatus( RCC_FLAG_WWDGRST ) ) vDebugPrintf( "RCC: Window Watchdog reset.\r\n" ); if ( RCC_GetFlagStatus( RCC_FLAG_LPWRRST ) ) vDebugPrintf( "RCC: Low Power reset.\r\n" ); }
portTASK_FUNCTION( vDebugTask, pvParameters ) { /*---------------------------------------------------------- Local variables ----------------------------------------------------------*/ char ch; portBASE_TYPE xStatus; //uint16_t u16StackSize; /*---------------------------------------------------------- What. ----------------------------------------------------------*/ ( void ) pvParameters; /*---------------------------------------------------------- Start Debug task loop ----------------------------------------------------------*/ vDebugString( "Debug task started.\r\n"); for(;;) { /*------------------------------------------------------ Send characters in the FIFO queue ------------------------------------------------------*/ if( USART_GetFlagStatus( USART2, USART_FLAG_TXE ) ) { /*-------------------------------------------------- Don't block forever, need to check RX too --------------------------------------------------*/ xStatus = xQueueReceive( xDebugQueue, &ch, 10 / portTICK_RATE_MS ); if( xStatus == pdPASS ) { USART_SendData( USART2, ch ); } } /*------------------------------------------------------ Receive incoming characters ------------------------------------------------------*/ if ( USART_GetFlagStatus( USART2, USART_FLAG_RXNE ) ) { ch = USART_ReceiveData( USART2 ); /*-------------------------------------------------- Handle console commands --------------------------------------------------*/ switch ( ch ) { case 'a': vDebugPrintf( "AtoD dump Stopped.\r\n"); //vSetAtoDDump( FALSE ); break; case 'A': vDebugPrintf( "AtoD dump Started.\r\n"); //vSetAtoDDump( TRUE ); break; case 'l': vDebugPrintf( "Loop Count Stopped.\r\n"); //vSetCntLoops( FALSE ); break; case 'L': vDebugPrintf( "Loop Count Started.\r\n"); //vSetCntLoops( TRUE ); break; case 's': vDebugPrintf( "Remaining space on Task Stack:\r\n" ); //u16StackSize = uxTaskGetStackHighWaterMark( hDebugTask ); //vDebugPrintf( "Debug\t%d\r\n", u16StackSize); //u16StackSize = uxTaskGetStackHighWaterMark( hTimeTask ); //vDebugPrintf( "Time\t%d\r\n", u16StackSize); break; default: break; } } taskYIELD(); } }