]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM9_AT91SAM9XE_IAR/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / ARM9_AT91SAM9XE_IAR / main.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  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
30  * documentation provides more details of the standard demo application tasks.\r
31  *\r
32  * A "Check" task is created in addition to the standard demo tasks.    This\r
33  * only executes every three seconds but has a high priority to ensure it gets\r
34  * processor time.  Its main function is to check that all the standard demo\r
35  * tasks are still operational.  If everything is running as expected then the\r
36  * check task will toggle an LED every 3 seconds.  An error being discovered in\r
37  * any task will cause the toggle rate to increase to 500ms.\r
38  *\r
39  */\r
40 \r
41 /* FreeRTOS includes. */\r
42 #include "FreeRTOS.h"\r
43 #include "task.h"\r
44 \r
45 /* Standard demo includes. */\r
46 #include "BlockQ.h"\r
47 #include "blocktim.h"\r
48 #include "countsem.h"\r
49 #include "death.h"\r
50 #include "dynamic.h"\r
51 #include "GenQTest.h"\r
52 #include "integer.h"\r
53 #include "PollQ.h"\r
54 #include "QPeek.h"\r
55 #include "recmutex.h"\r
56 #include "semtest.h"\r
57 #include "ParTest.h"\r
58 #include "comtest2.h"\r
59 \r
60 /* Standard includes. */\r
61 #include <stdio.h>\r
62 \r
63 /* Atmel library includes. */\r
64 #include <pio/pio.h>\r
65 \r
66 /* Priorities for the demo application tasks. */\r
67 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
68 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 0 )\r
69 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
70 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 0 )\r
71 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
72 #define mainCREATOR_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
73 #define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )\r
74 \r
75 /* The period of the check task both in and out of the presense of an error. */\r
76 #define mainNO_ERROR_PERIOD                     ( 5000 / portTICK_PERIOD_MS )\r
77 #define mainERROR_PERIOD                        ( 500 / portTICK_PERIOD_MS );\r
78 \r
79 /* Constants used by the ComTest task. */\r
80 #define mainCOM_TEST_BAUD_RATE          ( 38400 )\r
81 #define mainCOM_TEST_LED                        ( LED_DS1 )\r
82 \r
83 /*-----------------------------------------------------------*/\r
84 \r
85 /* Simple hardware setup required by the demo. */\r
86 static void prvSetupHardware( void );\r
87 \r
88 /* The check task as described at the top of this file. */\r
89 static void prvCheckTask( void *pvParameters );\r
90 \r
91 /*-----------------------------------------------------------*/\r
92 int main()\r
93 {\r
94         /* Perform any hardware setup necessary to run the demo. */\r
95         prvSetupHardware();\r
96         \r
97         /* First create the 'standard demo' tasks.  These exist just to to\r
98         demonstrate API functions being used and test the kernel port.  More\r
99         information is provided on the FreeRTOS.org WEB site. */\r
100         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
101         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
102         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
103         vStartDynamicPriorityTasks();\r
104         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
105         vCreateBlockTimeTasks();\r
106         vStartCountingSemaphoreTasks();\r
107         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
108         vStartQueuePeekTasks();\r
109         vStartRecursiveMutexTasks();\r
110         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
111         \r
112         /* Create the check task - this is the task that checks all the other tasks\r
113         are executing as expected and without reporting any errors. */\r
114         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
115         \r
116         /* The death demo tasks must be started last as the sanity checks performed\r
117         require knowledge of the number of other tasks in the system. */\r
118         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
119         \r
120         /* Start the scheduler.  From this point on the execution will be under\r
121         the control of the kernel. */\r
122         vTaskStartScheduler();\r
123         \r
124         /* Will only get here if there was insufficient heap availale for the\r
125         idle task to be created. */\r
126         for( ;; );\r
127 }\r
128 /*-----------------------------------------------------------*/\r
129 \r
130 static void prvCheckTask( void * pvParameters )\r
131 {\r
132 TickType_t xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;\r
133 static volatile unsigned long ulErrorCode = 0UL;\r
134 \r
135         /* Just to remove the compiler warning. */\r
136         ( void ) pvParameters;\r
137 \r
138         /* Initialise xNextWakeTime prior to its first use.  From this point on\r
139         the value of the variable is handled automatically by the kernel. */\r
140         xNextWakeTime = xTaskGetTickCount();\r
141         \r
142         for( ;; )\r
143         {\r
144                 /* Delay until it is time for this task to execute again. */\r
145                 vTaskDelayUntil( &xNextWakeTime, xPeriod );\r
146                 \r
147                 /* Check all the other tasks in the system - latch any reported errors\r
148                 into the ulErrorCode variable. */\r
149                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
150                 {\r
151                         ulErrorCode |= 0x01UL;\r
152                 }\r
153 \r
154                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
155                 {\r
156                         ulErrorCode |= 0x02UL;\r
157                 }\r
158 \r
159                 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
160                 {\r
161                         ulErrorCode |= 0x04UL;\r
162                 }\r
163 \r
164                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
165                 {\r
166                         ulErrorCode |= 0x08UL;\r
167                 }\r
168 \r
169                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
170                 {\r
171                         ulErrorCode |= 0x10UL;\r
172                 }\r
173 \r
174                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
175                 {\r
176                         ulErrorCode |= 0x20UL;\r
177                 }\r
178 \r
179                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
180                 {\r
181                         ulErrorCode |= 0x40UL;\r
182                 }\r
183 \r
184                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
185                 {\r
186                         ulErrorCode |= 0x80UL;\r
187                 }\r
188 \r
189                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
190                 {\r
191                         ulErrorCode |= 0x100UL;\r
192                 }\r
193 \r
194                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
195                 {\r
196                         ulErrorCode |= 0x200UL;\r
197                 }\r
198 \r
199                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
200                 {\r
201                         ulErrorCode |= 0x400UL;\r
202                 }\r
203                 \r
204                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
205                 {\r
206                         ulErrorCode |= 0x800UL;\r
207                 }\r
208                 \r
209                 /* Reduce the block period and in so doing increase the frequency at\r
210                 which this task executes if any errors have been latched.  The increased\r
211                 frequency causes the LED toggle rate to increase and so gives some\r
212                 visual feedback that an error has occurred. */\r
213                 if( ulErrorCode != 0x00 )\r
214                 {\r
215                         xPeriod = mainERROR_PERIOD;\r
216                 }\r
217                 \r
218                 /* Finally toggle the LED. */\r
219                 vParTestToggleLED( LED_POWER );\r
220         }\r
221 }\r
222 /*-----------------------------------------------------------*/\r
223 \r
224 static void prvSetupHardware( void )\r
225 {\r
226 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };\r
227 \r
228         /* Setup the LED outputs. */\r
229         vParTestInitialise();\r
230         \r
231         /* Setup the pins for the UART. */\r
232         PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );  \r
233 }\r