]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_STM32L152_Discovery_IAR/main_full.c
Update license information text files for the CLI, TCP and UDP products to be correct...
[freertos] / FreeRTOS / Demo / CORTEX_STM32L152_Discovery_IAR / main_full.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  * NOTE 1:  This project provides two demo applications.  A low power tickless\r
31  * project, and a more comprehensive test and demo application.  The\r
32  * configCREATE_LOW_POWER_DEMO setting in FreeRTOSConfig.h is used to\r
33  * select between the two.  See the notes on using\r
34  * configCREATE_LOW_POWER_DEMO in FreeRTOSConfig.h.  This file implements\r
35  * the comprehensive test and demo version.\r
36  *\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
40  ******************************************************************************\r
41  *\r
42  * main_full() creates all the demo application tasks and a software timer, then\r
43  * starts the scheduler.  The web documentation provides more details of the\r
44  * standard demo application tasks, which provide no particular functionality,\r
45  * but do provide a good example of how to use the FreeRTOS API.\r
46  *\r
47  * In addition to the standard demo tasks, the following tasks and tests are\r
48  * defined and/or created within this file:\r
49  *\r
50  * "Check" timer - The check software timer period is initially set to three\r
51  * seconds.  The callback function associated with the check software timer\r
52  * checks that all the standard demo tasks are not only still executing, but\r
53  * are executing without reporting any errors.  If the check software timer\r
54  * discovers that a task has either stalled, or reported an error, then it\r
55  * changes its own execution period from the initial three seconds, to just\r
56  * 200ms.  The check software timer callback function also toggles an LED each\r
57  * time it is called.  This provides a visual indication of the system status:\r
58  * If the LED toggles every three seconds, then no issues have been discovered.\r
59  * If the LED toggles every 200ms, then an issue has been discovered with at\r
60  * least one task.\r
61  *\r
62  * See the documentation page for this demo on the FreeRTOS.org web site for\r
63  * full information, including hardware setup requirements.\r
64  */\r
65 \r
66 /* Standard includes. */\r
67 #include <stdio.h>\r
68 \r
69 /* Kernel includes. */\r
70 #include "FreeRTOS.h"\r
71 #include "task.h"\r
72 #include "timers.h"\r
73 #include "semphr.h"\r
74 \r
75 /* Standard demo application includes. */\r
76 #include "PollQ.h"\r
77 #include "semtest.h"\r
78 #include "dynamic.h"\r
79 #include "BlockQ.h"\r
80 #include "blocktim.h"\r
81 #include "countsem.h"\r
82 #include "GenQTest.h"\r
83 #include "recmutex.h"\r
84 \r
85 /* ST library functions. */\r
86 #include "stm32l1xx.h"\r
87 #include "discover_board.h"\r
88 #include "stm32l_discovery_lcd.h"\r
89 \r
90 /* Priorities for the demo application tasks. */\r
91 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2UL )\r
92 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
93 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
94 \r
95 /* A block time of zero simply means "don't block". */\r
96 #define mainDONT_BLOCK                                          ( 0UL )\r
97 \r
98 /* The period after which the check timer will expire providing no errors\r
99 have been reported by any of the standard demo tasks.  ms are converted to the\r
100 equivalent in ticks using the portTICK_PERIOD_MS constant. */\r
101 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_PERIOD_MS )\r
102 \r
103 /* The period at which the check timer will expire, in ms, if an error has been\r
104 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
105 in ticks using the portTICK_PERIOD_MS constant. */\r
106 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 200UL / portTICK_PERIOD_MS )\r
107 \r
108 /*-----------------------------------------------------------*/\r
109 \r
110 /*\r
111  * The check timer callback function, as described at the top of this file.\r
112  */\r
113 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
114 \r
115 /*\r
116  * Configure the LCD, then write welcome message.\r
117  */\r
118 static void prvConfigureLCD( void );\r
119 \r
120 /*-----------------------------------------------------------*/\r
121 \r
122 void main_full( void )\r
123 {\r
124 TimerHandle_t xCheckTimer = NULL;\r
125 \r
126         /* The LCD is only used in the Full demo. */\r
127         prvConfigureLCD();\r
128 \r
129         /* Start all the other standard demo/test tasks.  They have no particular\r
130         functionality, but do demonstrate how to use the FreeRTOS API and test the\r
131         kernel port. */\r
132         vStartDynamicPriorityTasks();\r
133         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
134         vCreateBlockTimeTasks();\r
135         vStartCountingSemaphoreTasks();\r
136         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
137         vStartRecursiveMutexTasks();\r
138         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
139         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
140 \r
141         /* Create the software timer that performs the 'check' functionality,\r
142         as described at the top of this file. */\r
143         xCheckTimer = xTimerCreate( "CheckTimer",                                       /* A text name, purely to help debugging. */\r
144                                                                 ( mainCHECK_TIMER_PERIOD_MS ),  /* The timer period, in this case 3000ms (3s). */\r
145                                                                 pdTRUE,                                                 /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
146                                                                 ( void * ) 0,                                   /* The ID is not used, so can be set to anything. */\r
147                                                                 prvCheckTimerCallback                   /* The callback function that inspects the status of all the other tasks. */\r
148                                                           );\r
149 \r
150         if( xCheckTimer != NULL )\r
151         {\r
152                 xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
153         }\r
154 \r
155         /* Start the scheduler. */\r
156         vTaskStartScheduler();\r
157 \r
158         /* If all is well, the scheduler will now be running, and the following line\r
159         will never be reached.  If the following line does execute, then there was\r
160         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
161         to be created.  See the memory management section on the FreeRTOS web site\r
162         for more details. */\r
163         for( ;; );\r
164 }\r
165 /*-----------------------------------------------------------*/\r
166 \r
167 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
168 {\r
169 static long lChangedTimerPeriodAlready = pdFALSE;\r
170 unsigned long ulErrorFound = pdFALSE;\r
171 \r
172         /* Check all the demo tasks to ensure they are all still running, and that\r
173         none have detected an error. */\r
174 \r
175         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
176         {\r
177                 ulErrorFound = pdTRUE;\r
178         }\r
179 \r
180         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
181         {\r
182                 ulErrorFound = pdTRUE;\r
183         }\r
184 \r
185         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
186         {\r
187                 ulErrorFound = pdTRUE;\r
188         }\r
189 \r
190         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
191         {\r
192                 ulErrorFound = pdTRUE;\r
193         }\r
194 \r
195         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
196         {\r
197                 ulErrorFound = pdTRUE;\r
198         }\r
199 \r
200         if( xArePollingQueuesStillRunning() != pdTRUE )\r
201         {\r
202                 ulErrorFound = pdTRUE;\r
203         }\r
204 \r
205         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
206         {\r
207                 ulErrorFound = pdTRUE;\r
208         }\r
209 \r
210         /* Toggle the check LED to give an indication of the system status.  If\r
211         the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
212         everything is ok.  A faster toggle indicates an error. */\r
213         GPIO_TOGGLE( LD_GPIO_PORT, LD_GREEN_GPIO_PIN );\r
214 \r
215         /* Have any errors been latch in ulErrorFound?  If so, shorten the\r
216         period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
217         This will result in an increase in the rate at which mainCHECK_LED\r
218         toggles. */\r
219         if( ulErrorFound != pdFALSE )\r
220         {\r
221                 if( lChangedTimerPeriodAlready == pdFALSE )\r
222                 {\r
223                         lChangedTimerPeriodAlready = pdTRUE;\r
224 \r
225                         /* This call to xTimerChangePeriod() uses a zero block time.\r
226                         Functions called from inside of a timer callback function must\r
227                         *never* attempt to block. */\r
228                         xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
229                 }\r
230         }\r
231 }\r
232 /*-----------------------------------------------------------*/\r
233 \r
234 static void prvConfigureLCD( void )\r
235 {\r
236 GPIO_InitTypeDef GPIO_InitStructure;\r
237 \r
238         /* Enable necessary clocks. */\r
239         RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE );\r
240         RCC_APB1PeriphClockCmd( RCC_APB1Periph_LCD, ENABLE );\r
241         PWR_RTCAccessCmd( ENABLE );\r
242         RCC_LSEConfig( ENABLE );\r
243         RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE );\r
244         RCC_RTCCLKCmd( ENABLE );\r
245 \r
246         /* Configure Port A LCD Output pins as alternate function. */\r
247         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
248         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\r
249         GPIO_Init( GPIOA, &GPIO_InitStructure );\r
250 \r
251         /* Select LCD alternate function for Port A LCD Output pins. */\r
252         GPIO_PinAFConfig( GPIOA, GPIO_PinSource1, GPIO_AF_LCD );\r
253         GPIO_PinAFConfig( GPIOA, GPIO_PinSource2, GPIO_AF_LCD );\r
254         GPIO_PinAFConfig( GPIOA, GPIO_PinSource3, GPIO_AF_LCD );\r
255         GPIO_PinAFConfig( GPIOA, GPIO_PinSource8, GPIO_AF_LCD );\r
256         GPIO_PinAFConfig( GPIOA, GPIO_PinSource9, GPIO_AF_LCD );\r
257         GPIO_PinAFConfig( GPIOA, GPIO_PinSource10, GPIO_AF_LCD );\r
258         GPIO_PinAFConfig( GPIOA, GPIO_PinSource15, GPIO_AF_LCD );\r
259 \r
260         /* Configure Port B LCD Output pins as alternate function */\r
261         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
262         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\r
263         GPIO_Init( GPIOB, &GPIO_InitStructure );\r
264 \r
265         /* Select LCD alternate function for Port B LCD Output pins */\r
266         GPIO_PinAFConfig( GPIOB, GPIO_PinSource3, GPIO_AF_LCD );\r
267         GPIO_PinAFConfig( GPIOB, GPIO_PinSource4, GPIO_AF_LCD );\r
268         GPIO_PinAFConfig( GPIOB, GPIO_PinSource5, GPIO_AF_LCD );\r
269         GPIO_PinAFConfig( GPIOB, GPIO_PinSource8, GPIO_AF_LCD );\r
270         GPIO_PinAFConfig( GPIOB, GPIO_PinSource9, GPIO_AF_LCD );\r
271         GPIO_PinAFConfig( GPIOB, GPIO_PinSource10, GPIO_AF_LCD );\r
272         GPIO_PinAFConfig( GPIOB, GPIO_PinSource11, GPIO_AF_LCD );\r
273         GPIO_PinAFConfig( GPIOB, GPIO_PinSource12, GPIO_AF_LCD );\r
274         GPIO_PinAFConfig( GPIOB, GPIO_PinSource13, GPIO_AF_LCD );\r
275         GPIO_PinAFConfig( GPIOB, GPIO_PinSource14, GPIO_AF_LCD );\r
276         GPIO_PinAFConfig( GPIOB, GPIO_PinSource15, GPIO_AF_LCD );\r
277 \r
278         /* Configure Port C LCD Output pins as alternate function */\r
279         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
280         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\r
281         GPIO_Init( GPIOC, &GPIO_InitStructure );\r
282 \r
283         /* Select LCD alternate function for Port B LCD Output pins */\r
284         GPIO_PinAFConfig( GPIOC, GPIO_PinSource0, GPIO_AF_LCD );\r
285         GPIO_PinAFConfig( GPIOC, GPIO_PinSource1, GPIO_AF_LCD );\r
286         GPIO_PinAFConfig( GPIOC, GPIO_PinSource2, GPIO_AF_LCD );\r
287         GPIO_PinAFConfig( GPIOC, GPIO_PinSource3, GPIO_AF_LCD );\r
288         GPIO_PinAFConfig( GPIOC, GPIO_PinSource6, GPIO_AF_LCD );\r
289         GPIO_PinAFConfig( GPIOC, GPIO_PinSource7, GPIO_AF_LCD );\r
290         GPIO_PinAFConfig( GPIOC, GPIO_PinSource8, GPIO_AF_LCD );\r
291         GPIO_PinAFConfig( GPIOC, GPIO_PinSource9, GPIO_AF_LCD );\r
292         GPIO_PinAFConfig( GPIOC, GPIO_PinSource10, GPIO_AF_LCD );\r
293         GPIO_PinAFConfig( GPIOC, GPIO_PinSource11, GPIO_AF_LCD );\r
294 \r
295         LCD_GLASS_Init();\r
296         LCD_GLASS_DisplayString( "F'RTOS" );\r
297 }\r
298 \r