2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 /******************************************************************************
\r
30 * NOTE 1: This project provides two demo applications. A simple blinky
\r
31 * style project, and a more comprehensive test and demo application. The
\r
32 * configCREATE_SIMPLE_TICKLESS_DEMO setting in FreeRTOSConfig.h is used to
\r
33 * select between the two. See the notes on using
\r
34 * configCREATE_SIMPLY_BLINKY_DEMO_ONLY in main.c. This file implements the
\r
35 * comprehensive version.
\r
37 * NOTE 2: This file only contains the source code that is specific to the
\r
38 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
39 * required to configure the hardware, are defined in main.c.
\r
41 * See http://www.FreeRTOS.org/TI_MSP432_Free_RTOS_Demo.html for instructions.
\r
43 ******************************************************************************
\r
45 * main_full() creates all the demo application tasks and software timers, then
\r
46 * starts the scheduler. The web documentation provides more details of the
\r
47 * standard demo application tasks, which provide no particular functionality,
\r
48 * but do provide a good example of how to use the FreeRTOS API.
\r
50 * In addition to the standard demo tasks, the following tasks and tests are
\r
51 * defined and/or created within this file:
\r
53 * FreeRTOS+CLI command console. The command console is access through the
\r
54 * UART at 19200 baud. For reasons of robustness testing the UART driver is
\r
55 * deliberately written to be inefficient and should not be used as a template
\r
56 * for a production driver. Type "help" to see a list of registered commands.
\r
57 * The FreeRTOS+CLI license is different to the FreeRTOS license, see
\r
58 * http://www.FreeRTOS.org/cli for license and usage details.
\r
60 * "Reg test" tasks - These fill both the core and floating point registers with
\r
61 * known values, then check that each register maintains its expected value for
\r
62 * the lifetime of the task. Each task uses a different set of values. The reg
\r
63 * test tasks execute with a very low priority, so get preempted very
\r
64 * frequently. A register containing an unexpected value is indicative of an
\r
65 * error in the context switching mechanism.
\r
67 * "Check" task - The check task period is initially set to three seconds. The
\r
68 * task checks that all the standard demo tasks, and the register check tasks,
\r
69 * are not only still executing, but are executing without reporting any errors.
\r
70 * If the check task discovers that a task has either stalled, or reported an
\r
71 * error, then it changes its own execution period from the initial three
\r
72 * seconds, to just 200ms. The check task also toggles an LED each time it is
\r
73 * called. This provides a visual indication of the system status: If the LED
\r
74 * toggles every three seconds, then no issues have been discovered. If the LED
\r
75 * toggles every 200ms, then an issue has been discovered with at least one
\r
79 /* Standard includes. */
\r
82 /* Kernel includes. */
\r
83 #include "FreeRTOS.h"
\r
88 /* Standard demo application includes. */
\r
90 #include "semtest.h"
\r
91 #include "countsem.h"
\r
92 #include "GenQTest.h"
\r
93 #include "recmutex.h"
\r
94 #include "partest.h"
\r
96 #include "TimerDemo.h"
\r
97 #include "IntQueue.h"
\r
98 #include "EventGroupsDemo.h"
\r
99 #include "TaskNotify.h"
\r
100 #include "IntSemTest.h"
\r
102 /* Priorities for the demo application tasks. */
\r
103 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
104 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
105 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
106 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
107 #define mainUART_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2UL )
\r
108 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
110 #define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )
\r
112 /* The priority used by the UART command console task. */
\r
113 #define mainUART_COMMAND_CONSOLE_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
115 /* A block time of zero simply means "don't block". */
\r
116 #define mainDONT_BLOCK ( 0UL )
\r
118 /* The period of the check task, in ms, provided no errors have been reported by
\r
119 any of the standard demo tasks. ms are converted to the equivalent in ticks
\r
120 using the pdMS_TO_TICKS() macro constant. */
\r
121 #define mainNO_ERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 3000UL ) )
\r
123 /* The period of the check task, in ms, if an error has been reported in one of
\r
124 the standard demo tasks. ms are converted to the equivalent in ticks using the
\r
125 pdMS_TO_TICKS() macro. */
\r
126 #define mainERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 200UL ) )
\r
128 /* Parameters that are passed into the register check tasks solely for the
\r
129 purpose of ensuring parameters are passed into tasks correctly. */
\r
130 #define mainREG_TEST_TASK_1_PARAMETER ( ( void * ) 0x12345678 )
\r
131 #define mainREG_TEST_TASK_2_PARAMETER ( ( void * ) 0x87654321 )
\r
133 /* The base period used by the timer test tasks. */
\r
134 #define mainTIMER_TEST_PERIOD ( 50 )
\r
136 /* Dimensions the queue in which characters received from the UART are
\r
138 #define mainRX_QUEUE_LENGTH 10
\r
140 /*-----------------------------------------------------------*/
\r
144 * The check task, as described at the top of this file.
\r
146 static void prvCheckTask( void *pvParameters );
\r
149 * Register check tasks, and the tasks used to write over and check the contents
\r
150 * of the FPU registers, as described at the top of this file. The nature of
\r
151 * these files necessitates that they are written in an assembly file, but the
\r
152 * entry points are kept in the C file for the convenience of checking the task
\r
155 static void prvRegTestTaskEntry1( void *pvParameters );
\r
156 extern void vRegTest1Implementation( void );
\r
157 static void prvRegTestTaskEntry2( void *pvParameters );
\r
158 extern void vRegTest2Implementation( void );
\r
161 * Register commands that can be used with FreeRTOS+CLI. The commands are
\r
162 * defined in CLI-Commands.c and File-Related-CLI-Command.c respectively.
\r
164 extern void vRegisterSampleCLICommands( void );
\r
167 * The task that manages the FreeRTOS+CLI input and output.
\r
169 extern void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );
\r
172 * When the full demo is build the idle hook is used to create some timers that
\r
173 * cannot be created in main() because the timer demo tasks need the entire
\r
176 void vFullDemoIdleHook( void );
\r
179 * The full demo configures the clocks for maximum frequency, wheras the blinky
\r
180 * demo uses a slower clock as it also uses low power features.
\r
182 static void prvConfigureClocks( void );
\r
184 /*-----------------------------------------------------------*/
\r
186 /* The following two variables are used to communicate the status of the
\r
187 register check tasks to the check task. If the variables keep incrementing,
\r
188 then the register check tasks have not discovered any errors. If a variable
\r
189 stops incrementing, then an error has been found. */
\r
190 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
192 /*-----------------------------------------------------------*/
\r
194 void main_full( void )
\r
196 /* This demo sets the clock to its maximum. The blinky demo uses as slower
\r
197 clock as it uses low power features. */
\r
198 prvConfigureClocks();
\r
200 /* Init the serial port for use by the CLI. The baud rate parameter is not
\r
201 used so set to 0 to make this obvious. */
\r
202 xSerialPortInitMinimal( 0, mainRX_QUEUE_LENGTH );
\r
204 /* Start all the other standard demo/test tasks. They have no particular
\r
205 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
207 vStartInterruptQueueTasks();
\r
209 vStartCountingSemaphoreTasks();
\r
210 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
211 vStartRecursiveMutexTasks();
\r
212 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
213 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
214 vStartEventGroupTasks();
\r
215 vStartTaskNotifyTask();
\r
216 vStartInterruptSemaphoreTasks();
\r
218 /* Note - the set of standard demo tasks contains two versions of
\r
219 vStartMathTasks.c. One is defined in flop.c, and uses double precision
\r
220 floating point numbers and variables. The other is defined in sp_flop.c,
\r
221 and uses single precision floating point numbers and variables. sp_flop.
\r
222 c should be included in this project. */
\r
223 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
225 /* Start the tasks that implements the command console on the UART, as
\r
226 described above. */
\r
227 vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY );
\r
229 /* Register the standard CLI commands. */
\r
230 vRegisterSampleCLICommands();
\r
232 /* Create the register check tasks, as described at the top of this file */
\r
233 xTaskCreate( prvRegTestTaskEntry1, "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
234 xTaskCreate( prvRegTestTaskEntry2, "Reg2", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
236 /* Create the task that performs the 'check' functionality, as described at
\r
237 the top of this file. */
\r
238 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
240 /* Start the scheduler. */
\r
241 vTaskStartScheduler();
\r
243 /* If all is well, the scheduler will now be running, and the following
\r
244 line will never be reached. If the following line does execute, then
\r
245 there was insufficient FreeRTOS heap memory available for the Idle and/or
\r
246 timer tasks to be created. See the memory management section on the
\r
247 FreeRTOS web site for more details on the FreeRTOS heap
\r
248 http://www.freertos.org/a00111.html. */
\r
251 /*-----------------------------------------------------------*/
\r
253 static void prvCheckTask( void *pvParameters )
\r
255 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_TASK_PERIOD;
\r
256 TickType_t xLastExecutionTime;
\r
257 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
258 unsigned long ulErrorFound = pdFALSE;
\r
260 /* Just to stop compiler warnings. */
\r
261 ( void ) pvParameters;
\r
263 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
264 works correctly. */
\r
265 xLastExecutionTime = xTaskGetTickCount();
\r
267 /* Cycle for ever, delaying then checking all the other tasks are still
\r
268 operating without error. The onboard LED is toggled on each iteration.
\r
269 If an error is detected then the delay period is decreased from
\r
270 mainNO_ERROR_CHECK_TASK_PERIOD to mainERROR_CHECK_TASK_PERIOD. This has the
\r
271 effect of increasing the rate at which the onboard LED toggles, and in so
\r
272 doing gives visual feedback of the system status. */
\r
275 /* Delay until it is time to execute again. */
\r
276 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
278 /* Check all the demo tasks to ensure that they are all still running,
\r
279 and that none have detected an error. */
\r
280 if( xAreIntQueueTasksStillRunning() != pdTRUE )
\r
282 ulErrorFound |= 1UL << 0UL;
\r
285 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
287 ulErrorFound |= 1UL << 1UL;
\r
290 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
292 ulErrorFound |= 1UL << 5UL;
\r
295 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
297 ulErrorFound |= 1UL << 6UL;
\r
300 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
302 ulErrorFound |= 1UL << 8UL;
\r
305 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
307 ulErrorFound |= 1UL << 10UL;
\r
310 if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
\r
312 ulErrorFound |= 1UL << 14UL;
\r
315 if( xAreTimerDemoTasksStillRunning( ( TickType_t ) mainNO_ERROR_CHECK_TASK_PERIOD ) != pdPASS )
\r
317 ulErrorFound |= 1UL << 9UL;
\r
320 if( xAreEventGroupTasksStillRunning() != pdPASS )
\r
322 ulErrorFound |= 1UL << 12UL;
\r
325 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
327 ulErrorFound |= 1UL << 13UL;
\r
330 /* Check that the register test 1 task is still running. */
\r
331 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
333 ulErrorFound |= 1UL << 15UL;
\r
335 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
337 /* Check that the register test 2 task is still running. */
\r
338 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
340 ulErrorFound |= 1UL << 16UL;
\r
342 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
344 /* Toggle the check LED to give an indication of the system status. If
\r
345 the LED toggles every mainNO_ERROR_CHECK_TASK_PERIOD milliseconds then
\r
346 everything is ok. A faster toggle indicates an error. */
\r
347 configTOGGLE_LED();
\r
349 if( ulErrorFound != pdFALSE )
\r
351 /* An error has been detected in one of the tasks - flash the LED
\r
352 at a higher frequency to give visible feedback that something has
\r
353 gone wrong (it might just be that the loop back connector required
\r
354 by the comtest tasks has not been fitted). */
\r
355 xDelayPeriod = mainERROR_CHECK_TASK_PERIOD;
\r
359 /*-----------------------------------------------------------*/
\r
361 static void prvRegTestTaskEntry1( void *pvParameters )
\r
363 /* Although the regtest task is written in assembler, its entry point is
\r
364 written in C for convenience of checking the task parameter is being passed
\r
366 if( pvParameters == mainREG_TEST_TASK_1_PARAMETER )
\r
368 /* Start the part of the test that is written in assembler. */
\r
369 vRegTest1Implementation();
\r
372 /* The following line will only execute if the task parameter is found to
\r
373 be incorrect. The check task will detect that the regtest loop counter is
\r
374 not being incremented and flag an error. */
\r
375 vTaskDelete( NULL );
\r
377 /*-----------------------------------------------------------*/
\r
379 static void prvRegTestTaskEntry2( void *pvParameters )
\r
381 /* Although the regtest task is written in assembler, its entry point is
\r
382 written in C for convenience of checking the task parameter is being passed
\r
384 if( pvParameters == mainREG_TEST_TASK_2_PARAMETER )
\r
386 /* Start the part of the test that is written in assembler. */
\r
387 vRegTest2Implementation();
\r
390 /* The following line will only execute if the task parameter is found to
\r
391 be incorrect. The check task will detect that the regtest loop counter is
\r
392 not being incremented and flag an error. */
\r
393 vTaskDelete( NULL );
\r
395 /*-----------------------------------------------------------*/
\r
397 static void prvConfigureClocks( void )
\r
399 /* Set Flash wait state for high clock frequency. Refer to datasheet for
\r
401 FlashCtl_setWaitState( FLASH_BANK0, 2 );
\r
402 FlashCtl_setWaitState( FLASH_BANK1, 2 );
\r
404 /* The full demo configures the clocks for maximum frequency, wheras the
\r
405 blinky demo uses a slower clock as it also uses low power features. Maximum
\r
406 freqency also needs more voltage.
\r
408 From the datashee: For AM_LDO_VCORE1 and AM_DCDC_VCORE1 modes, the maximum
\r
409 CPU operating frequency is 48 MHz and maximum input clock frequency for
\r
410 peripherals is 24 MHz. */
\r
411 PCM_setCoreVoltageLevel( PCM_VCORE1 );
\r
412 CS_setDCOCenteredFrequency( CS_DCO_FREQUENCY_48 );
\r
413 CS_initClockSignal( CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
414 CS_initClockSignal( CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
415 CS_initClockSignal( CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
416 CS_initClockSignal( CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
\r
418 /*-----------------------------------------------------------*/
\r
420 #if( configCREATE_SIMPLE_TICKLESS_DEMO == 0 )
\r
422 void vApplicationTickHook( void )
\r
424 /* This function will be called by each tick interrupt if
\r
425 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
426 added here, but the tick hook is called from an interrupt context, so
\r
427 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
428 functions can be used (those that end in FromISR()). */
\r
430 /* The full demo includes a software timer demo/test that requires
\r
431 prodding periodically from the tick interrupt. */
\r
432 vTimerPeriodicISRTests();
\r
434 /* Call the periodic event group from ISR demo. */
\r
435 vPeriodicEventGroupsProcessing();
\r
437 /* Use task notifications from an interrupt. */
\r
438 xNotifyTaskFromISR();
\r
440 /* Use mutexes from interrupts. */
\r
441 vInterruptSemaphorePeriodicTest();
\r
445 /*-----------------------------------------------------------*/
\r