2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
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
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
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
30 /******************************************************************************
\r
31 * NOTE 1: This project provides two demo applications. A simple blinky
\r
32 * style project, and a more comprehensive test and demo application. The
\r
33 * configCREATE_SIMPLE_TICKLESS_DEMO setting in FreeRTOSConfig.h is used to
\r
34 * select between the two. See the notes on using
\r
35 * configCREATE_SIMPLY_BLINKY_DEMO_ONLY in main.c. This file implements the
\r
36 * comprehensive version.
\r
38 * NOTE 2: This file only contains the source code that is specific to the
\r
39 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
40 * required to configure the hardware, are defined in main.c.
\r
42 * See http://www.FreeRTOS.org/TI_MSP432_Free_RTOS_Demo.html for instructions.
\r
44 ******************************************************************************
\r
46 * main_full() creates all the demo application tasks and software timers, then
\r
47 * starts the scheduler. The web documentation provides more details of the
\r
48 * standard demo application tasks, which provide no particular functionality,
\r
49 * but do provide a good example of how to use the FreeRTOS API.
\r
51 * In addition to the standard demo tasks, the following tasks and tests are
\r
52 * defined and/or created within this file:
\r
54 * FreeRTOS+CLI command console. The command console is access through the
\r
55 * UART at 19200 baud. For reasons of robustness testing the UART driver is
\r
56 * deliberately written to be inefficient and should not be used as a template
\r
57 * for a production driver. Type "help" to see a list of registered commands.
\r
58 * The FreeRTOS+CLI license is different to the FreeRTOS license, see
\r
59 * http://www.FreeRTOS.org/cli for license and usage details.
\r
61 * "Reg test" tasks - These fill both the core and floating point registers with
\r
62 * known values, then check that each register maintains its expected value for
\r
63 * the lifetime of the task. Each task uses a different set of values. The reg
\r
64 * test tasks execute with a very low priority, so get preempted very
\r
65 * frequently. A register containing an unexpected value is indicative of an
\r
66 * error in the context switching mechanism.
\r
68 * "Check" task - The check task period is initially set to three seconds. The
\r
69 * task checks that all the standard demo tasks, and the register check tasks,
\r
70 * are not only still executing, but are executing without reporting any errors.
\r
71 * If the check task discovers that a task has either stalled, or reported an
\r
72 * error, then it changes its own execution period from the initial three
\r
73 * seconds, to just 200ms. The check task also toggles an LED each time it is
\r
74 * called. This provides a visual indication of the system status: If the LED
\r
75 * toggles every three seconds, then no issues have been discovered. If the LED
\r
76 * toggles every 200ms, then an issue has been discovered with at least one
\r
80 /* Standard includes. */
\r
83 /* Kernel includes. */
\r
84 #include "FreeRTOS.h"
\r
89 /* Standard demo application includes. */
\r
91 #include "semtest.h"
\r
92 #include "countsem.h"
\r
93 #include "GenQTest.h"
\r
94 #include "recmutex.h"
\r
95 #include "partest.h"
\r
97 #include "TimerDemo.h"
\r
98 #include "IntQueue.h"
\r
99 #include "EventGroupsDemo.h"
\r
100 #include "TaskNotify.h"
\r
101 #include "IntSemTest.h"
\r
103 /* Priorities for the demo application tasks. */
\r
104 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
105 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
106 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
107 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
108 #define mainUART_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2UL )
\r
109 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
110 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
111 #define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )
\r
113 /* The priority used by the UART command console task. */
\r
114 #define mainUART_COMMAND_CONSOLE_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
116 /* A block time of zero simply means "don't block". */
\r
117 #define mainDONT_BLOCK ( 0UL )
\r
119 /* The period of the check task, in ms, provided no errors have been reported by
\r
120 any of the standard demo tasks. ms are converted to the equivalent in ticks
\r
121 using the pdMS_TO_TICKS() macro constant. */
\r
122 #define mainNO_ERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 3000UL ) )
\r
124 /* The period of the check task, in ms, if an error has been reported in one of
\r
125 the standard demo tasks. ms are converted to the equivalent in ticks using the
\r
126 pdMS_TO_TICKS() macro. */
\r
127 #define mainERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 200UL ) )
\r
129 /* Parameters that are passed into the register check tasks solely for the
\r
130 purpose of ensuring parameters are passed into tasks correctly. */
\r
131 #define mainREG_TEST_TASK_1_PARAMETER ( ( void * ) 0x12345678 )
\r
132 #define mainREG_TEST_TASK_2_PARAMETER ( ( void * ) 0x87654321 )
\r
134 /* The base period used by the timer test tasks. */
\r
135 #define mainTIMER_TEST_PERIOD ( 50 )
\r
137 /* Dimensions the queue in which characters received from the UART are
\r
139 #define mainRX_QUEUE_LENGTH 10
\r
141 /*-----------------------------------------------------------*/
\r
145 * The check task, as described at the top of this file.
\r
147 static void prvCheckTask( void *pvParameters );
\r
150 * Register check tasks, and the tasks used to write over and check the contents
\r
151 * of the FPU registers, as described at the top of this file. The nature of
\r
152 * these files necessitates that they are written in an assembly file, but the
\r
153 * entry points are kept in the C file for the convenience of checking the task
\r
156 static void prvRegTestTaskEntry1( void *pvParameters );
\r
157 extern void vRegTest1Implementation( void );
\r
158 static void prvRegTestTaskEntry2( void *pvParameters );
\r
159 extern void vRegTest2Implementation( void );
\r
162 * Register commands that can be used with FreeRTOS+CLI. The commands are
\r
163 * defined in CLI-Commands.c and File-Related-CLI-Command.c respectively.
\r
165 extern void vRegisterSampleCLICommands( void );
\r
168 * The task that manages the FreeRTOS+CLI input and output.
\r
170 extern void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );
\r
173 * When the full demo is build the idle hook is used to create some timers that
\r
174 * cannot be created in main() because the timer demo tasks need the entire
\r
177 void vFullDemoIdleHook( void );
\r
180 * The full demo configures the clocks for maximum frequency, wheras the blinky
\r
181 * demo uses a slower clock as it also uses low power features.
\r
183 static void prvConfigureClocks( void );
\r
185 /*-----------------------------------------------------------*/
\r
187 /* The following two variables are used to communicate the status of the
\r
188 register check tasks to the check task. If the variables keep incrementing,
\r
189 then the register check tasks have not discovered any errors. If a variable
\r
190 stops incrementing, then an error has been found. */
\r
191 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
193 /*-----------------------------------------------------------*/
\r
195 void main_full( void )
\r
197 /* This demo sets the clock to its maximum. The blinky demo uses as slower
\r
198 clock as it uses low power features. */
\r
199 prvConfigureClocks();
\r
201 /* Init the serial port for use by the CLI. The baud rate parameter is not
\r
202 used so set to 0 to make this obvious. */
\r
203 xSerialPortInitMinimal( 0, mainRX_QUEUE_LENGTH );
\r
205 /* Start all the other standard demo/test tasks. They have no particular
\r
206 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
208 vStartInterruptQueueTasks();
\r
210 vStartCountingSemaphoreTasks();
\r
211 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
212 vStartRecursiveMutexTasks();
\r
213 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
214 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
215 vStartEventGroupTasks();
\r
216 vStartTaskNotifyTask();
\r
217 vStartInterruptSemaphoreTasks();
\r
219 /* Note - the set of standard demo tasks contains two versions of
\r
220 vStartMathTasks.c. One is defined in flop.c, and uses double precision
\r
221 floating point numbers and variables. The other is defined in sp_flop.c,
\r
222 and uses single precision floating point numbers and variables. sp_flop.
\r
223 c should be included in this project. */
\r
224 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
226 /* Start the tasks that implements the command console on the UART, as
\r
227 described above. */
\r
228 vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY );
\r
230 /* Register the standard CLI commands. */
\r
231 vRegisterSampleCLICommands();
\r
233 /* Create the register check tasks, as described at the top of this file */
\r
234 xTaskCreate( prvRegTestTaskEntry1, "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
235 xTaskCreate( prvRegTestTaskEntry2, "Reg2", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
237 /* Create the task that performs the 'check' functionality, as described at
\r
238 the top of this file. */
\r
239 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
241 /* Start the scheduler. */
\r
242 vTaskStartScheduler();
\r
244 /* If all is well, the scheduler will now be running, and the following
\r
245 line will never be reached. If the following line does execute, then
\r
246 there was insufficient FreeRTOS heap memory available for the Idle and/or
\r
247 timer tasks to be created. See the memory management section on the
\r
248 FreeRTOS web site for more details on the FreeRTOS heap
\r
249 http://www.freertos.org/a00111.html. */
\r
252 /*-----------------------------------------------------------*/
\r
254 static void prvCheckTask( void *pvParameters )
\r
256 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_TASK_PERIOD;
\r
257 TickType_t xLastExecutionTime;
\r
258 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
259 unsigned long ulErrorFound = pdFALSE;
\r
261 /* Just to stop compiler warnings. */
\r
262 ( void ) pvParameters;
\r
264 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
265 works correctly. */
\r
266 xLastExecutionTime = xTaskGetTickCount();
\r
268 /* Cycle for ever, delaying then checking all the other tasks are still
\r
269 operating without error. The onboard LED is toggled on each iteration.
\r
270 If an error is detected then the delay period is decreased from
\r
271 mainNO_ERROR_CHECK_TASK_PERIOD to mainERROR_CHECK_TASK_PERIOD. This has the
\r
272 effect of increasing the rate at which the onboard LED toggles, and in so
\r
273 doing gives visual feedback of the system status. */
\r
276 /* Delay until it is time to execute again. */
\r
277 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
279 /* Check all the demo tasks to ensure that they are all still running,
\r
280 and that none have detected an error. */
\r
281 if( xAreIntQueueTasksStillRunning() != pdTRUE )
\r
283 ulErrorFound |= 1UL << 0UL;
\r
286 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
288 ulErrorFound |= 1UL << 1UL;
\r
291 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
293 ulErrorFound |= 1UL << 5UL;
\r
296 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
298 ulErrorFound |= 1UL << 6UL;
\r
301 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
303 ulErrorFound |= 1UL << 8UL;
\r
306 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
308 ulErrorFound |= 1UL << 10UL;
\r
311 if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
\r
313 ulErrorFound |= 1UL << 14UL;
\r
316 if( xAreTimerDemoTasksStillRunning( ( TickType_t ) mainNO_ERROR_CHECK_TASK_PERIOD ) != pdPASS )
\r
318 ulErrorFound |= 1UL << 9UL;
\r
321 if( xAreEventGroupTasksStillRunning() != pdPASS )
\r
323 ulErrorFound |= 1UL << 12UL;
\r
326 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
328 ulErrorFound |= 1UL << 13UL;
\r
331 /* Check that the register test 1 task is still running. */
\r
332 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
334 ulErrorFound |= 1UL << 15UL;
\r
336 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
338 /* Check that the register test 2 task is still running. */
\r
339 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
341 ulErrorFound |= 1UL << 16UL;
\r
343 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
345 /* Toggle the check LED to give an indication of the system status. If
\r
346 the LED toggles every mainNO_ERROR_CHECK_TASK_PERIOD milliseconds then
\r
347 everything is ok. A faster toggle indicates an error. */
\r
348 configTOGGLE_LED();
\r
350 if( ulErrorFound != pdFALSE )
\r
352 /* An error has been detected in one of the tasks - flash the LED
\r
353 at a higher frequency to give visible feedback that something has
\r
354 gone wrong (it might just be that the loop back connector required
\r
355 by the comtest tasks has not been fitted). */
\r
356 xDelayPeriod = mainERROR_CHECK_TASK_PERIOD;
\r
360 /*-----------------------------------------------------------*/
\r
362 static void prvRegTestTaskEntry1( void *pvParameters )
\r
364 /* Although the regtest task is written in assembler, its entry point is
\r
365 written in C for convenience of checking the task parameter is being passed
\r
367 if( pvParameters == mainREG_TEST_TASK_1_PARAMETER )
\r
369 /* Start the part of the test that is written in assembler. */
\r
370 vRegTest1Implementation();
\r
373 /* The following line will only execute if the task parameter is found to
\r
374 be incorrect. The check task will detect that the regtest loop counter is
\r
375 not being incremented and flag an error. */
\r
376 vTaskDelete( NULL );
\r
378 /*-----------------------------------------------------------*/
\r
380 static void prvRegTestTaskEntry2( void *pvParameters )
\r
382 /* Although the regtest task is written in assembler, its entry point is
\r
383 written in C for convenience of checking the task parameter is being passed
\r
385 if( pvParameters == mainREG_TEST_TASK_2_PARAMETER )
\r
387 /* Start the part of the test that is written in assembler. */
\r
388 vRegTest2Implementation();
\r
391 /* The following line will only execute if the task parameter is found to
\r
392 be incorrect. The check task will detect that the regtest loop counter is
\r
393 not being incremented and flag an error. */
\r
394 vTaskDelete( NULL );
\r
396 /*-----------------------------------------------------------*/
\r
398 static void prvConfigureClocks( void )
\r
400 /* Set Flash wait state for high clock frequency. Refer to datasheet for
\r
402 FlashCtl_setWaitState( FLASH_BANK0, 2 );
\r
403 FlashCtl_setWaitState( FLASH_BANK1, 2 );
\r
405 /* The full demo configures the clocks for maximum frequency, wheras the
\r
406 blinky demo uses a slower clock as it also uses low power features. Maximum
\r
407 freqency also needs more voltage.
\r
409 From the datashee: For AM_LDO_VCORE1 and AM_DCDC_VCORE1 modes, the maximum
\r
410 CPU operating frequency is 48 MHz and maximum input clock frequency for
\r
411 peripherals is 24 MHz. */
\r
412 PCM_setCoreVoltageLevel( PCM_VCORE1 );
\r
413 CS_setDCOCenteredFrequency( CS_DCO_FREQUENCY_48 );
\r
414 CS_initClockSignal( CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
415 CS_initClockSignal( CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
416 CS_initClockSignal( CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
417 CS_initClockSignal( CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
419 /*-----------------------------------------------------------*/
\r
421 #if( configCREATE_SIMPLE_TICKLESS_DEMO == 0 )
\r
423 void vApplicationTickHook( void )
\r
425 /* This function will be called by each tick interrupt if
\r
426 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
427 added here, but the tick hook is called from an interrupt context, so
\r
428 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
429 functions can be used (those that end in FromISR()). */
\r
431 /* The full demo includes a software timer demo/test that requires
\r
432 prodding periodically from the tick interrupt. */
\r
433 vTimerPeriodicISRTests();
\r
435 /* Call the periodic event group from ISR demo. */
\r
436 vPeriodicEventGroupsProcessing();
\r
438 /* Use task notifications from an interrupt. */
\r
439 xNotifyTaskFromISR();
\r
441 /* Use mutexes from interrupts. */
\r
442 vInterruptSemaphorePeriodicTest();
\r
446 /*-----------------------------------------------------------*/
\r