1 /*============================================================================
\r
3 * Author : $(username)
\r
5 * Copyright : Your copyright notice
\r
6 * Description : Simple function in C, Ansi-style
\r
7 *============================================================================
\r
11 #include "FreeRTOS.h"
\r
15 extern void SystemInit(void);
\r
17 #define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
19 #define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
21 #define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_PERIOD_MS )
\r
24 /* The number of items the queue can hold. This is 1 as the receive task
\r
26 will remove items as they are added, meaning the send task should always find
\r
30 #define mainQUEUE_LENGTH ( 1 )
\r
32 static QueueHandle_t xQueue = NULL;
\r
34 static void prvQueueSendTask( void *pvParameters )
\r
36 TickType_t xNextWakeTime;
\r
37 const unsigned long ulValueToSend = 100UL;
\r
40 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
42 xNextWakeTime = xTaskGetTickCount();
\r
48 /* Place this task in the blocked state until it is time to run again.
\r
50 The block time is specified in ticks, the constant used converts ticks
\r
52 to ms. While in the Blocked state this task will not consume any CPU
\r
56 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
59 /* Send to the queue - causing the queue receive task to unblock and
\r
61 toggle an LED. 0 is used as the block time so the sending operation
\r
63 will not block - it shouldn't need to block as the queue should always
\r
65 be empty at this point in the code. */
\r
67 xQueueSend( xQueue, &ulValueToSend, 0 );
\r
73 static void prvQueueReceiveTask( void *pvParameters )
\r
75 unsigned int ulReceivedValue;
\r
80 /* Wait until something arrives in the queue - this task will block
\r
82 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
84 FreeRTOSConfig.h. */
\r
86 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
90 /* To get here something must have been received from the queue, but
\r
92 is it the expected value? If it is, toggle the green LED. */
\r
94 if( ulReceivedValue == 100UL )
\r
96 printf("Recieve expected value : %d\n", ulReceivedValue);
\r
100 printf("Recieve unexpected value : %d\n", ulReceivedValue);
\r
111 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
112 if (xQueue != NULL)
\r
114 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
116 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
\r
118 vTaskStartScheduler();
\r