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
28 /******************************************************************************
\r
29 * NOTE 1: This project provides two demo applications. A low power tickless
\r
30 * project, and a more comprehensive test and demo application. The
\r
31 * configCREATE_LOW_POWER_DEMO setting in FreeRTOSConfig.h is used to
\r
32 * select between the two. See the notes on using
\r
33 * configCREATE_LOW_POWER_DEMO in FreeRTOSConfig.h. This file implements
\r
34 * the comprehensive test and demo version.
\r
36 * NOTE 2: This file only contains the source code that is specific to the
\r
37 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
38 * required to configure the hardware, are defined in main.c.
\r
39 ******************************************************************************
\r
41 * main_full() creates all the demo application tasks and a software timer, then
\r
42 * starts the scheduler. The web documentation provides more details of the
\r
43 * standard demo application tasks, which provide no particular functionality,
\r
44 * but do provide a good example of how to use the FreeRTOS API.
\r
46 * In addition to the standard demo tasks, the following tasks and tests are
\r
47 * defined and/or created within this file:
\r
49 * "Check" timer - The check software timer period is initially set to three
\r
50 * seconds. The callback function associated with the check software timer
\r
51 * checks that all the standard demo tasks are not only still executing, but
\r
52 * are executing without reporting any errors. If the check software timer
\r
53 * discovers that a task has either stalled, or reported an error, then it
\r
54 * changes its own execution period from the initial three seconds, to just
\r
55 * 200ms. The check software timer callback function also toggles an LED each
\r
56 * time it is called. This provides a visual indication of the system status:
\r
57 * If the LED toggles every three seconds, then no issues have been discovered.
\r
58 * If the LED toggles every 200ms, then an issue has been discovered with at
\r
61 * See the documentation page for this demo on the FreeRTOS.org web site for
\r
62 * full information, including hardware setup requirements.
\r
65 /* Standard includes. */
\r
68 /* Kernel includes. */
\r
69 #include "FreeRTOS.h"
\r
74 /* Standard demo application includes. */
\r
76 #include "semtest.h"
\r
77 #include "dynamic.h"
\r
79 #include "blocktim.h"
\r
80 #include "countsem.h"
\r
81 #include "GenQTest.h"
\r
82 #include "recmutex.h"
\r
84 /* ST library functions. */
\r
85 #include "stm32l1xx.h"
\r
86 #include "discover_board.h"
\r
87 #include "stm32l_discovery_lcd.h"
\r
89 /* Priorities for the demo application tasks. */
\r
90 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
91 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
92 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
94 /* A block time of zero simply means "don't block". */
\r
95 #define mainDONT_BLOCK ( 0UL )
\r
97 /* The period after which the check timer will expire providing no errors
\r
98 have been reported by any of the standard demo tasks. ms are converted to the
\r
99 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
100 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
102 /* The period at which the check timer will expire, in ms, if an error has been
\r
103 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
104 in ticks using the portTICK_PERIOD_MS constant. */
\r
105 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
107 /*-----------------------------------------------------------*/
\r
110 * The check timer callback function, as described at the top of this file.
\r
112 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
115 * Configure the LCD, then write welcome message.
\r
117 static void prvConfigureLCD( void );
\r
119 /*-----------------------------------------------------------*/
\r
121 void main_full( void )
\r
123 TimerHandle_t xCheckTimer = NULL;
\r
125 /* The LCD is only used in the Full demo. */
\r
128 /* Start all the other standard demo/test tasks. They have no particular
\r
129 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
131 vStartDynamicPriorityTasks();
\r
132 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
133 vCreateBlockTimeTasks();
\r
134 vStartCountingSemaphoreTasks();
\r
135 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
136 vStartRecursiveMutexTasks();
\r
137 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
138 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
140 /* Create the software timer that performs the 'check' functionality,
\r
141 as described at the top of this file. */
\r
142 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
143 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
144 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
145 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
146 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
149 if( xCheckTimer != NULL )
\r
151 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
154 /* Start the scheduler. */
\r
155 vTaskStartScheduler();
\r
157 /* If all is well, the scheduler will now be running, and the following line
\r
158 will never be reached. If the following line does execute, then there was
\r
159 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
160 to be created. See the memory management section on the FreeRTOS web site
\r
161 for more details. */
\r
164 /*-----------------------------------------------------------*/
\r
166 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
168 static long lChangedTimerPeriodAlready = pdFALSE;
\r
169 unsigned long ulErrorFound = pdFALSE;
\r
171 /* Check all the demo tasks to ensure they are all still running, and that
\r
172 none have detected an error. */
\r
174 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
176 ulErrorFound = pdTRUE;
\r
179 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
181 ulErrorFound = pdTRUE;
\r
184 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
186 ulErrorFound = pdTRUE;
\r
189 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
191 ulErrorFound = pdTRUE;
\r
194 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
196 ulErrorFound = pdTRUE;
\r
199 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
201 ulErrorFound = pdTRUE;
\r
204 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
206 ulErrorFound = pdTRUE;
\r
209 /* Toggle the check LED to give an indication of the system status. If
\r
210 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
211 everything is ok. A faster toggle indicates an error. */
\r
212 GPIO_TOGGLE( LD_GPIO_PORT, LD_GREEN_GPIO_PIN );
\r
214 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
215 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
216 This will result in an increase in the rate at which mainCHECK_LED
\r
218 if( ulErrorFound != pdFALSE )
\r
220 if( lChangedTimerPeriodAlready == pdFALSE )
\r
222 lChangedTimerPeriodAlready = pdTRUE;
\r
224 /* This call to xTimerChangePeriod() uses a zero block time.
\r
225 Functions called from inside of a timer callback function must
\r
226 *never* attempt to block. */
\r
227 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
231 /*-----------------------------------------------------------*/
\r
233 static void prvConfigureLCD( void )
\r
235 GPIO_InitTypeDef GPIO_InitStructure;
\r
237 /* Enable necessary clocks. */
\r
238 RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE );
\r
239 RCC_APB1PeriphClockCmd( RCC_APB1Periph_LCD, ENABLE );
\r
240 PWR_RTCAccessCmd( ENABLE );
\r
241 RCC_LSEConfig( ENABLE );
\r
242 RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE );
\r
243 RCC_RTCCLKCmd( ENABLE );
\r
245 /* Configure Port A LCD Output pins as alternate function. */
\r
246 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_8 | GPIO_Pin_9 |GPIO_Pin_10 |GPIO_Pin_15;
\r
247 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
\r
248 GPIO_Init( GPIOA, &GPIO_InitStructure );
\r
250 /* Select LCD alternate function for Port A LCD Output pins. */
\r
251 GPIO_PinAFConfig( GPIOA, GPIO_PinSource1, GPIO_AF_LCD );
\r
252 GPIO_PinAFConfig( GPIOA, GPIO_PinSource2, GPIO_AF_LCD );
\r
253 GPIO_PinAFConfig( GPIOA, GPIO_PinSource3, GPIO_AF_LCD );
\r
254 GPIO_PinAFConfig( GPIOA, GPIO_PinSource8, GPIO_AF_LCD );
\r
255 GPIO_PinAFConfig( GPIOA, GPIO_PinSource9, GPIO_AF_LCD );
\r
256 GPIO_PinAFConfig( GPIOA, GPIO_PinSource10, GPIO_AF_LCD );
\r
257 GPIO_PinAFConfig( GPIOA, GPIO_PinSource15, GPIO_AF_LCD );
\r
259 /* Configure Port B LCD Output pins as alternate function */
\r
260 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
\r
261 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
\r
262 GPIO_Init( GPIOB, &GPIO_InitStructure );
\r
264 /* Select LCD alternate function for Port B LCD Output pins */
\r
265 GPIO_PinAFConfig( GPIOB, GPIO_PinSource3, GPIO_AF_LCD );
\r
266 GPIO_PinAFConfig( GPIOB, GPIO_PinSource4, GPIO_AF_LCD );
\r
267 GPIO_PinAFConfig( GPIOB, GPIO_PinSource5, GPIO_AF_LCD );
\r
268 GPIO_PinAFConfig( GPIOB, GPIO_PinSource8, GPIO_AF_LCD );
\r
269 GPIO_PinAFConfig( GPIOB, GPIO_PinSource9, GPIO_AF_LCD );
\r
270 GPIO_PinAFConfig( GPIOB, GPIO_PinSource10, GPIO_AF_LCD );
\r
271 GPIO_PinAFConfig( GPIOB, GPIO_PinSource11, GPIO_AF_LCD );
\r
272 GPIO_PinAFConfig( GPIOB, GPIO_PinSource12, GPIO_AF_LCD );
\r
273 GPIO_PinAFConfig( GPIOB, GPIO_PinSource13, GPIO_AF_LCD );
\r
274 GPIO_PinAFConfig( GPIOB, GPIO_PinSource14, GPIO_AF_LCD );
\r
275 GPIO_PinAFConfig( GPIOB, GPIO_PinSource15, GPIO_AF_LCD );
\r
277 /* Configure Port C LCD Output pins as alternate function */
\r
278 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |GPIO_Pin_11 ;
\r
279 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
\r
280 GPIO_Init( GPIOC, &GPIO_InitStructure );
\r
282 /* Select LCD alternate function for Port B LCD Output pins */
\r
283 GPIO_PinAFConfig( GPIOC, GPIO_PinSource0, GPIO_AF_LCD );
\r
284 GPIO_PinAFConfig( GPIOC, GPIO_PinSource1, GPIO_AF_LCD );
\r
285 GPIO_PinAFConfig( GPIOC, GPIO_PinSource2, GPIO_AF_LCD );
\r
286 GPIO_PinAFConfig( GPIOC, GPIO_PinSource3, GPIO_AF_LCD );
\r
287 GPIO_PinAFConfig( GPIOC, GPIO_PinSource6, GPIO_AF_LCD );
\r
288 GPIO_PinAFConfig( GPIOC, GPIO_PinSource7, GPIO_AF_LCD );
\r
289 GPIO_PinAFConfig( GPIOC, GPIO_PinSource8, GPIO_AF_LCD );
\r
290 GPIO_PinAFConfig( GPIOC, GPIO_PinSource9, GPIO_AF_LCD );
\r
291 GPIO_PinAFConfig( GPIOC, GPIO_PinSource10, GPIO_AF_LCD );
\r
292 GPIO_PinAFConfig( GPIOC, GPIO_PinSource11, GPIO_AF_LCD );
\r
295 LCD_GLASS_DisplayString( "F'RTOS" );
\r