]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R4_RM48_TMS570_CCS5/main_blinky.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_R4_RM48_TMS570_CCS5 / main_blinky.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * NOTE 1:  This project provides two demo applications.  A simple blinky style\r
30  * project, and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
32  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
33  * in main.c.  This file implements the simply blinky style version.\r
34  *\r
35  * NOTE 2:  This file only contains the source code that is specific to the\r
36  * basic demo.  Generic functions, such FreeRTOS hook functions, and functions\r
37  * required to configure the hardware, are defined in main.c.\r
38  ******************************************************************************\r
39  *\r
40  * main_blinky() creates one queue, and two tasks.  It then starts the\r
41  * scheduler.\r
42  *\r
43  * The Queue Send Task:\r
44  * The queue send task is implemented by the prvQueueSendTask() function in\r
45  * this file.  prvQueueSendTask() sits in a loop that causes it to repeatedly\r
46  * block for 200 milliseconds, before sending the value 100 to the queue that\r
47  * was created within main_blinky().  Once the value is sent, the task loops\r
48  * back around to block for another 200 milliseconds.\r
49  *\r
50  * The Queue Receive Task:\r
51  * The queue receive task is implemented by the prvQueueReceiveTask() function\r
52  * in this file.  prvQueueReceiveTask() sits in a loop where it repeatedly\r
53  * blocks on attempts to read data from the queue that was created within\r
54  * main_blinky().  When data is received, the task checks the value of the\r
55  * data, and if the value equals the expected 100, toggles an LED.  The 'block\r
56  * time' parameter passed to the queue receive function specifies that the\r
57  * task should be held in the Blocked state indefinitely to wait for data to\r
58  * be available on the queue.  The queue receive task will only leave the\r
59  * Blocked state when the queue send task writes to the queue.  As the queue\r
60  * send task writes to the queue every 200 milliseconds, the queue receive\r
61  * task leaves the Blocked state every 200 milliseconds, and therefore toggles\r
62  * the LED every 200 milliseconds.\r
63  */\r
64 \r
65 /* Standard includes. */\r
66 #include <stdio.h>\r
67 \r
68 /* Kernel includes. */\r
69 #include "FreeRTOS.h"\r
70 #include "task.h"\r
71 #include "semphr.h"\r
72 \r
73 /* Common demo includes. */\r
74 #include "partest.h"\r
75 \r
76 /* Priorities at which the tasks are created. */\r
77 #define mainQUEUE_RECEIVE_TASK_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
78 #define mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
79 \r
80 /* The rate at which data is sent to the queue.  The 200ms value is converted\r
81 to ticks using the portTICK_PERIOD_MS constant. */\r
82 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 200 / portTICK_PERIOD_MS )\r
83 \r
84 /* The number of items the queue can hold.  This is 1 as the receive task\r
85 will remove items as they are added, meaning the send task should always find\r
86 the queue empty. */\r
87 #define mainQUEUE_LENGTH                                        ( 1 )\r
88 \r
89 /* Values passed to the two tasks just to check the task parameter\r
90 functionality. */\r
91 #define mainQUEUE_SEND_PARAMETER                        ( 0x1111UL )\r
92 #define mainQUEUE_RECEIVE_PARAMETER                     ( 0x22UL )\r
93 \r
94 /*-----------------------------------------------------------*/\r
95 \r
96 /*\r
97  * The tasks as described in the comments at the top of this file.\r
98  */\r
99 static void prvQueueReceiveTask( void *pvParameters );\r
100 static void prvQueueSendTask( void *pvParameters );\r
101 \r
102 /*\r
103  * Called by main() to create the simply blinky style application if\r
104  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
105  */\r
106 void main_blinky( void );\r
107 \r
108 /*-----------------------------------------------------------*/\r
109 \r
110 /* The queue used by both tasks. */\r
111 static QueueHandle_t xQueue = NULL;\r
112 \r
113 /*-----------------------------------------------------------*/\r
114 \r
115 void main_blinky( void )\r
116 {\r
117         /* Create the queue. */\r
118         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
119 \r
120         if( xQueue != NULL )\r
121         {\r
122                 /* Start the two tasks as described in the comments at the top of this\r
123                 file. */\r
124                 xTaskCreate( prvQueueReceiveTask,                                       /* The function that implements the task. */\r
125                                         "Rx",                                                                   /* The text name assigned to the task - for debug only as it is not used by the kernel. */\r
126                                         configMINIMAL_STACK_SIZE,                               /* The size of the stack to allocate to the task. */\r
127                                         ( void * ) mainQUEUE_RECEIVE_PARAMETER, /* The parameter passed to the task - just to check the functionality. */\r
128                                         mainQUEUE_RECEIVE_TASK_PRIORITY,                /* The priority assigned to the task. */\r
129                                         NULL );                                                                 /* The task handle is not required, so NULL is passed. */\r
130 \r
131                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, ( void * ) mainQUEUE_SEND_PARAMETER, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
132 \r
133                 /* Start the tasks and timer running. */\r
134                 vTaskStartScheduler();\r
135         }\r
136 \r
137         /* If all is well, the scheduler will now be running, and the following\r
138         line will never be reached.  If the following line does execute, then\r
139         there was insufficient FreeRTOS heap memory available for the idle and/or\r
140         timer tasks     to be created.  See the memory management section on the\r
141         FreeRTOS web site for more details. */\r
142         for( ;; );\r
143 }\r
144 /*-----------------------------------------------------------*/\r
145 \r
146 static void prvQueueSendTask( void *pvParameters )\r
147 {\r
148 TickType_t xNextWakeTime;\r
149 const unsigned long ulValueToSend = 100UL;\r
150 \r
151         /* Check the task parameter is as expected. */\r
152         configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_SEND_PARAMETER );\r
153 \r
154         /* Initialise xNextWakeTime - this only needs to be done once. */\r
155         xNextWakeTime = xTaskGetTickCount();\r
156 \r
157         for( ;; )\r
158         {\r
159                 /* Place this task in the blocked state until it is time to run again.\r
160                 The block time is specified in ticks, the constant used converts ticks\r
161                 to ms.  While in the Blocked state this task will not consume any CPU\r
162                 time. */\r
163                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
164 \r
165                 /* Send to the queue - causing the queue receive task to unblock and\r
166                 toggle the LED.  0 is used as the block time so the sending operation\r
167                 will not block - it shouldn't need to block as the queue should always\r
168                 be empty at this point in the code. */\r
169                 xQueueSend( xQueue, &ulValueToSend, 0U );\r
170         }\r
171 }\r
172 /*-----------------------------------------------------------*/\r
173 \r
174 static void prvQueueReceiveTask( void *pvParameters )\r
175 {\r
176 unsigned long ulReceivedValue;\r
177 \r
178         /* Check the task parameter is as expected. */\r
179         configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_RECEIVE_PARAMETER );\r
180 \r
181         for( ;; )\r
182         {\r
183                 /* Wait until something arrives in the queue - this task will block\r
184                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
185                 FreeRTOSConfig.h. */\r
186                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
187 \r
188                 /*  To get here something must have been received from the queue, but\r
189                 is it the expected value?  If it is, toggle the LED. */\r
190                 if( ulReceivedValue == 100UL )\r
191                 {\r
192                         vParTestToggleLED( 0 );\r
193                         ulReceivedValue = 0U;\r
194                 }\r
195         }\r
196 }\r
197 /*-----------------------------------------------------------*/\r
198 \r