]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/T-HEAD_CB2201_CDK/RTOSDemo_CDK/RTOSDemo/main.c
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Demo / T-HEAD_CB2201_CDK / RTOSDemo_CDK / RTOSDemo / main.c
1 /*============================================================================\r
2  * Name        : main.c\r
3  * Author      : $(username)\r
4  * Version     : 0.0.0\r
5  * Copyright   : Your copyright notice\r
6  * Description : Simple function in C, Ansi-style\r
7  *============================================================================\r
8  */\r
9 \r
10 \r
11 #include "FreeRTOS.h"\r
12 #include "task.h"\r
13 #include "queue.h"\r
14 \r
15 extern void SystemInit(void);\r
16 \r
17 #define mainQUEUE_RECEIVE_TASK_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
18 \r
19 #define mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
20 \r
21 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 200 / portTICK_PERIOD_MS )\r
22 \r
23 \r
24 /* The number of items the queue can hold.  This is 1 as the receive task\r
25 \r
26 will remove items as they are added, meaning the send task should always find\r
27 \r
28 the queue empty. */\r
29 \r
30 #define mainQUEUE_LENGTH                                        ( 1 )\r
31 \r
32 static QueueHandle_t xQueue = NULL;\r
33 \r
34 static void prvQueueSendTask( void *pvParameters )\r
35 {\r
36         TickType_t xNextWakeTime;\r
37         const unsigned long ulValueToSend = 100UL;\r
38 \r
39 \r
40         /* Initialise xNextWakeTime - this only needs to be done once. */\r
41 \r
42         xNextWakeTime = xTaskGetTickCount();\r
43 \r
44         for( ;; )\r
45 \r
46         {\r
47 \r
48                 /* Place this task in the blocked state until it is time to run again.\r
49 \r
50                 The block time is specified in ticks, the constant used converts ticks\r
51 \r
52                 to ms.  While in the Blocked state this task will not consume any CPU\r
53 \r
54                 time. */\r
55 \r
56                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
57 \r
58 \r
59                 /* Send to the queue - causing the queue receive task to unblock and\r
60 \r
61                 toggle an LED.  0 is used as the block time so the sending operation\r
62 \r
63                 will not block - it shouldn't need to block as the queue should always\r
64 \r
65                 be empty at this point in the code. */\r
66 \r
67                 xQueueSend( xQueue, &ulValueToSend, 0 );\r
68 \r
69         }\r
70 \r
71 }\r
72 \r
73 static void prvQueueReceiveTask( void *pvParameters )\r
74 {\r
75         unsigned int ulReceivedValue;\r
76 \r
77         for( ;; )\r
78         {\r
79 \r
80                 /* Wait until something arrives in the queue - this task will block\r
81 \r
82                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
83 \r
84                 FreeRTOSConfig.h. */\r
85 \r
86                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
87 \r
88 \r
89 \r
90                 /*  To get here something must have been received from the queue, but\r
91 \r
92                 is it the expected value?  If it is, toggle the green LED. */\r
93 \r
94                 if( ulReceivedValue == 100UL )\r
95                 {\r
96                         printf("Recieve expected value : %d\n", ulReceivedValue);\r
97                 } \r
98                 else \r
99                 {\r
100                         printf("Recieve unexpected value : %d\n", ulReceivedValue);\r
101                 }\r
102 \r
103         }\r
104 \r
105 }\r
106  \r
107 int main()\r
108 {\r
109         SystemInit();\r
110 \r
111         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
112         if (xQueue != NULL)\r
113         {\r
114                 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
115 \r
116                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
117                 \r
118                 vTaskStartScheduler();\r
119         }\r
120         \r
121 \r
122     return 0;\r
123 }\r