]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_STM32L152_Discovery_IAR/main_full.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / CORTEX_STM32L152_Discovery_IAR / main_full.c
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 /******************************************************************************\r
97  * NOTE 1:  This project provides two demo applications.  A low power tickless\r
98  * project, and a more comprehensive test and demo application.  The\r
99  * configCREATE_LOW_POWER_DEMO setting in FreeRTOSConfig.h is used to\r
100  * select between the two.  See the notes on using\r
101  * configCREATE_LOW_POWER_DEMO in FreeRTOSConfig.h.  This file implements\r
102  * the comprehensive test and demo version.\r
103  *\r
104  * NOTE 2:  This file only contains the source code that is specific to the\r
105  * full demo.  Generic functions, such FreeRTOS hook functions, and functions\r
106  * required to configure the hardware, are defined in main.c.\r
107  ******************************************************************************\r
108  *\r
109  * main_full() creates all the demo application tasks and a software timer, then\r
110  * starts the scheduler.  The web documentation provides more details of the\r
111  * standard demo application tasks, which provide no particular functionality,\r
112  * but do provide a good example of how to use the FreeRTOS API.\r
113  *\r
114  * In addition to the standard demo tasks, the following tasks and tests are\r
115  * defined and/or created within this file:\r
116  *\r
117  * "Check" timer - The check software timer period is initially set to three\r
118  * seconds.  The callback function associated with the check software timer\r
119  * checks that all the standard demo tasks are not only still executing, but\r
120  * are executing without reporting any errors.  If the check software timer\r
121  * discovers that a task has either stalled, or reported an error, then it\r
122  * changes its own execution period from the initial three seconds, to just\r
123  * 200ms.  The check software timer callback function also toggles an LED each\r
124  * time it is called.  This provides a visual indication of the system status:\r
125  * If the LED toggles every three seconds, then no issues have been discovered.\r
126  * If the LED toggles every 200ms, then an issue has been discovered with at\r
127  * least one task.\r
128  *\r
129  * See the documentation page for this demo on the FreeRTOS.org web site for\r
130  * full information, including hardware setup requirements.\r
131  */\r
132 \r
133 /* Standard includes. */\r
134 #include <stdio.h>\r
135 \r
136 /* Kernel includes. */\r
137 #include "FreeRTOS.h"\r
138 #include "task.h"\r
139 #include "timers.h"\r
140 #include "semphr.h"\r
141 \r
142 /* Standard demo application includes. */\r
143 #include "PollQ.h"\r
144 #include "semtest.h"\r
145 #include "dynamic.h"\r
146 #include "BlockQ.h"\r
147 #include "blocktim.h"\r
148 #include "countsem.h"\r
149 #include "GenQTest.h"\r
150 #include "recmutex.h"\r
151 \r
152 /* ST library functions. */\r
153 #include "stm32l1xx.h"\r
154 #include "discover_board.h"\r
155 #include "stm32l_discovery_lcd.h"\r
156 \r
157 /* Priorities for the demo application tasks. */\r
158 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2UL )\r
159 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
160 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
161 \r
162 /* A block time of zero simply means "don't block". */\r
163 #define mainDONT_BLOCK                                          ( 0UL )\r
164 \r
165 /* The period after which the check timer will expire providing no errors\r
166 have been reported by any of the standard demo tasks.  ms are converted to the\r
167 equivalent in ticks using the portTICK_PERIOD_MS constant. */\r
168 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_PERIOD_MS )\r
169 \r
170 /* The period at which the check timer will expire, in ms, if an error has been\r
171 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
172 in ticks using the portTICK_PERIOD_MS constant. */\r
173 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 200UL / portTICK_PERIOD_MS )\r
174 \r
175 /*-----------------------------------------------------------*/\r
176 \r
177 /*\r
178  * The check timer callback function, as described at the top of this file.\r
179  */\r
180 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
181 \r
182 /*\r
183  * Configure the LCD, then write welcome message.\r
184  */\r
185 static void prvConfigureLCD( void );\r
186 \r
187 /*-----------------------------------------------------------*/\r
188 \r
189 void main_full( void )\r
190 {\r
191 TimerHandle_t xCheckTimer = NULL;\r
192 \r
193         /* The LCD is only used in the Full demo. */\r
194         prvConfigureLCD();\r
195 \r
196         /* Start all the other standard demo/test tasks.  They have not particular\r
197         functionality, but do demonstrate how to use the FreeRTOS API and test the\r
198         kernel port. */\r
199         vStartDynamicPriorityTasks();\r
200         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
201         vCreateBlockTimeTasks();\r
202         vStartCountingSemaphoreTasks();\r
203         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
204         vStartRecursiveMutexTasks();\r
205         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
206         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
207 \r
208         /* Create the software timer that performs the 'check' functionality,\r
209         as described at the top of this file. */\r
210         xCheckTimer = xTimerCreate( "CheckTimer",                                       /* A text name, purely to help debugging. */\r
211                                                                 ( mainCHECK_TIMER_PERIOD_MS ),  /* The timer period, in this case 3000ms (3s). */\r
212                                                                 pdTRUE,                                                 /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
213                                                                 ( void * ) 0,                                   /* The ID is not used, so can be set to anything. */\r
214                                                                 prvCheckTimerCallback                   /* The callback function that inspects the status of all the other tasks. */\r
215                                                           );\r
216 \r
217         if( xCheckTimer != NULL )\r
218         {\r
219                 xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
220         }\r
221 \r
222         /* Start the scheduler. */\r
223         vTaskStartScheduler();\r
224 \r
225         /* If all is well, the scheduler will now be running, and the following line\r
226         will never be reached.  If the following line does execute, then there was\r
227         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
228         to be created.  See the memory management section on the FreeRTOS web site\r
229         for more details. */\r
230         for( ;; );\r
231 }\r
232 /*-----------------------------------------------------------*/\r
233 \r
234 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
235 {\r
236 static long lChangedTimerPeriodAlready = pdFALSE;\r
237 unsigned long ulErrorFound = pdFALSE;\r
238 \r
239         /* Check all the demo tasks to ensure they are all still running, and that\r
240         none have detected an error. */\r
241 \r
242         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
243         {\r
244                 ulErrorFound = pdTRUE;\r
245         }\r
246 \r
247         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
248         {\r
249                 ulErrorFound = pdTRUE;\r
250         }\r
251 \r
252         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
253         {\r
254                 ulErrorFound = pdTRUE;\r
255         }\r
256 \r
257         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
258         {\r
259                 ulErrorFound = pdTRUE;\r
260         }\r
261 \r
262         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
263         {\r
264                 ulErrorFound = pdTRUE;\r
265         }\r
266 \r
267         if( xArePollingQueuesStillRunning() != pdTRUE )\r
268         {\r
269                 ulErrorFound = pdTRUE;\r
270         }\r
271 \r
272         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
273         {\r
274                 ulErrorFound = pdTRUE;\r
275         }\r
276 \r
277         /* Toggle the check LED to give an indication of the system status.  If\r
278         the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
279         everything is ok.  A faster toggle indicates an error. */\r
280         GPIO_TOGGLE( LD_GPIO_PORT, LD_GREEN_GPIO_PIN );\r
281 \r
282         /* Have any errors been latch in ulErrorFound?  If so, shorten the\r
283         period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
284         This will result in an increase in the rate at which mainCHECK_LED\r
285         toggles. */\r
286         if( ulErrorFound != pdFALSE )\r
287         {\r
288                 if( lChangedTimerPeriodAlready == pdFALSE )\r
289                 {\r
290                         lChangedTimerPeriodAlready = pdTRUE;\r
291 \r
292                         /* This call to xTimerChangePeriod() uses a zero block time.\r
293                         Functions called from inside of a timer callback function must\r
294                         *never* attempt to block. */\r
295                         xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
296                 }\r
297         }\r
298 }\r
299 /*-----------------------------------------------------------*/\r
300 \r
301 static void prvConfigureLCD( void )\r
302 {\r
303 GPIO_InitTypeDef GPIO_InitStructure;\r
304 \r
305         /* Enable necessary clocks. */\r
306         RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE );\r
307         RCC_APB1PeriphClockCmd( RCC_APB1Periph_LCD, ENABLE );\r
308         PWR_RTCAccessCmd( ENABLE );\r
309         RCC_LSEConfig( ENABLE );\r
310         RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE );\r
311         RCC_RTCCLKCmd( ENABLE );\r
312 \r
313         /* Configure Port A LCD Output pins as alternate function. */\r
314         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
315         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\r
316         GPIO_Init( GPIOA, &GPIO_InitStructure );\r
317 \r
318         /* Select LCD alternate function for Port A LCD Output pins. */\r
319         GPIO_PinAFConfig( GPIOA, GPIO_PinSource1, GPIO_AF_LCD );\r
320         GPIO_PinAFConfig( GPIOA, GPIO_PinSource2, GPIO_AF_LCD );\r
321         GPIO_PinAFConfig( GPIOA, GPIO_PinSource3, GPIO_AF_LCD );\r
322         GPIO_PinAFConfig( GPIOA, GPIO_PinSource8, GPIO_AF_LCD );\r
323         GPIO_PinAFConfig( GPIOA, GPIO_PinSource9, GPIO_AF_LCD );\r
324         GPIO_PinAFConfig( GPIOA, GPIO_PinSource10, GPIO_AF_LCD );\r
325         GPIO_PinAFConfig( GPIOA, GPIO_PinSource15, GPIO_AF_LCD );\r
326 \r
327         /* Configure Port B LCD Output pins as alternate function */\r
328         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
329         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\r
330         GPIO_Init( GPIOB, &GPIO_InitStructure );\r
331 \r
332         /* Select LCD alternate function for Port B LCD Output pins */\r
333         GPIO_PinAFConfig( GPIOB, GPIO_PinSource3, GPIO_AF_LCD );\r
334         GPIO_PinAFConfig( GPIOB, GPIO_PinSource4, GPIO_AF_LCD );\r
335         GPIO_PinAFConfig( GPIOB, GPIO_PinSource5, GPIO_AF_LCD );\r
336         GPIO_PinAFConfig( GPIOB, GPIO_PinSource8, GPIO_AF_LCD );\r
337         GPIO_PinAFConfig( GPIOB, GPIO_PinSource9, GPIO_AF_LCD );\r
338         GPIO_PinAFConfig( GPIOB, GPIO_PinSource10, GPIO_AF_LCD );\r
339         GPIO_PinAFConfig( GPIOB, GPIO_PinSource11, GPIO_AF_LCD );\r
340         GPIO_PinAFConfig( GPIOB, GPIO_PinSource12, GPIO_AF_LCD );\r
341         GPIO_PinAFConfig( GPIOB, GPIO_PinSource13, GPIO_AF_LCD );\r
342         GPIO_PinAFConfig( GPIOB, GPIO_PinSource14, GPIO_AF_LCD );\r
343         GPIO_PinAFConfig( GPIOB, GPIO_PinSource15, GPIO_AF_LCD );\r
344 \r
345         /* Configure Port C LCD Output pins as alternate function */\r
346         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
347         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\r
348         GPIO_Init( GPIOC, &GPIO_InitStructure );\r
349 \r
350         /* Select LCD alternate function for Port B LCD Output pins */\r
351         GPIO_PinAFConfig( GPIOC, GPIO_PinSource0, GPIO_AF_LCD );\r
352         GPIO_PinAFConfig( GPIOC, GPIO_PinSource1, GPIO_AF_LCD );\r
353         GPIO_PinAFConfig( GPIOC, GPIO_PinSource2, GPIO_AF_LCD );\r
354         GPIO_PinAFConfig( GPIOC, GPIO_PinSource3, GPIO_AF_LCD );\r
355         GPIO_PinAFConfig( GPIOC, GPIO_PinSource6, GPIO_AF_LCD );\r
356         GPIO_PinAFConfig( GPIOC, GPIO_PinSource7, GPIO_AF_LCD );\r
357         GPIO_PinAFConfig( GPIOC, GPIO_PinSource8, GPIO_AF_LCD );\r
358         GPIO_PinAFConfig( GPIOC, GPIO_PinSource9, GPIO_AF_LCD );\r
359         GPIO_PinAFConfig( GPIOC, GPIO_PinSource10, GPIO_AF_LCD );\r
360         GPIO_PinAFConfig( GPIOC, GPIO_PinSource11, GPIO_AF_LCD );\r
361 \r
362         LCD_GLASS_Init();\r
363         LCD_GLASS_DisplayString( "F'RTOS" );\r
364 }\r
365 \r