Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

FreeRTOS Xilinx Vivado: Hello World!

Hello World C Code example in Xilinx Vivado SDK.

  • Login to see the comments

FreeRTOS Xilinx Vivado: Hello World!

  1. 1. Embedded Operating System: FreeRTOS: Hello World! Vincent Claes
  2. 2. Hello World Example in Xilinx Vivado SDK (FreeRTOS) /* FreeRTOS includes. */ #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "timers.h" /* Xilinx includes. */ #include "xil_printf.h" #include "xparameters.h" Vincent Claes
  3. 3. #define TIMER_ID 1 #define DELAY_10_SECONDS 10000UL #define DELAY_1_SECOND 1000UL #define TIMER_CHECK_THRESHOLD 9 Vincent Claes
  4. 4. /* The Tx and Rx tasks as described at the top of this file. */ static void prvTxTask( void *pvParameters ); static void prvRxTask( void *pvParameters ); static void vTimerCallback( TimerHandle_t pxTimer ); Vincent Claes
  5. 5. /* The queue used by the Tx and Rx tasks, as described at the top of this file. */ static TaskHandle_t xTxTask; static TaskHandle_t xRxTask; static QueueHandle_t xQueue = NULL; static TimerHandle_t xTimer = NULL; char HWstring[15] = "Hello World"; long RxtaskCntr = 0; Vincent Claes
  6. 6. int main( void ) { /* pdMS_TO_TICKS: Converts a time in milliseconds to a time in ticks. */ const TickType_t x10seconds = pdMS_TO_TICKS(DELAY_10_SECONDS ); xil_printf( "Hello from Freertos example mainrn" ); xTaskCreate( prvTxTask, ( const char * ) "Tx", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTxTask ); xTaskCreate( prvRxTask, ( const char * ) "GB", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, &xRxTask ); Vincent Claes
  7. 7. xTaskCreate( prvTxTask, ( const char * ) "Tx", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTxTask ); /* prvTxTask : function that implements the task */ /* “TX” : Name for the task */ /* configMINIMAL_STACK_SIZE : stack allocated tot he task */ /* NULL : parameter not used */ /* tskIDLE_PRIORITY : task runs at idle priority */ /* &xTxTask : TX Taskhandler */ Vincent Claes
  8. 8. xTaskCreate( prvRxTask, ( const char * ) "GB", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, &xRxTask ); /* prvRxTask : function that implements the task */ /* “GB” : Name for the task */ /* configMINIMAL_STACK_SIZE : stack allocated tot he task */ /* NULL : parameter not used */ /* tskIDLE_PRIORITY : task runs at idle priority +1 */ /* &xRxTask : RX Taskhandler */ Vincent Claes
  9. 9. xTaskCreate( prvRxTask, ( const char * ) "GB", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, &xRxTask ); xQueue = xQueueCreate(1, sizeof( HWstring ) ); /* Check if queue was created */ configASSERT(xQueue); xTimer = xTimerCreate( (const char *) "Timer", x10seconds, pdFALSE, (void *) TIMER_ID, vTimerCallback); configASSERT(xTimer); Vincent Claes
  10. 10. xQueue = xQueueCreate(1, sizeof( HWstring ) ); /* 1 : One place in queue */ /* sizeof (HWstring) : place in queue can hold HWstring */ /* char HWstring[15] : “Hello World”; */ Vincent Claes
  11. 11. xTimer = xTimerCreate( (const char *) "Timer", x10seconds, pdFALSE, (void *) TIMER_ID, vTimerCallback); /* “Timer” : Name of Timer */ /* x10seconds : expires after 10 seconds */ /* pdFALSE : Don’t autoreload */ /* TIMER_ID : Timer identifier */ /* vTimerCallback : Timer callback function */ Vincent Claes
  12. 12. prvRxTask static void prvRxTask( void *pvParameters ) { char Recdstring[15] = ""; for( ;; ) { xQueueReceive( xQueue, Recdstring, portMAX_DELAY ); xil_printf( "Rx task received string from Tx task: %srn", Recdstring ); RxtaskCntr++; } } Vincent Claes
  13. 13. xQueueReceive( xQueue, Recdstring, portMAX_DELAY ); /* xQueue : Queue being read */ /* Recdstring : Data read intro this address */ /* portMAX_DELAY : wait without timeout for data */ Vincent Claes
  14. 14. prvTxTask static void prvTxTask( void *pvParameters ) { const TickType_t x1second = pdMS_TO_TICKS( DELAY_1_SECOND ); for( ;; ) { /* Delay for 1 second. */ vTaskDelay( x1second ); xQueueSend( xQueue, HWstring, 0UL ); } } Vincent Claes
  15. 15. xQueueSend( xQueue, HWstring, 0UL ); /* xQueue : Queue written to */ /* Hwstring : Address data being sent */ /* 0UL : block time */ Vincent Claes
  16. 16. vTimerCallback static void vTimerCallback( TimerHandle_t pxTimer ) { long lTimerId; configASSERT( pxTimer ); lTimerId = ( long ) pvTimerGetTimerID( pxTimer ); if (lTimerId != TIMER_ID) { xil_printf("FreeRTOS Hello World Example FAILED"); } if (RxtaskCntr >= TIMER_CHECK_THRESHOLD) { xil_printf("FreeRTOS Hello World Example PASSED"); } else { xil_printf("FreeRTOS Hello World Example FAILED"); } vTaskDelete( xRxTask ); vTaskDelete( xTxTask ); } Vincent Claes

×