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