]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MB96350_Softune_Dice_Kit/main.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / MB96350_Softune_Dice_Kit / main.c
1 /*\r
2     FreeRTOS V8.1.2 - 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     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 \r
67 /*****\r
68  *\r
69  * See http://www.freertos.org/Documentation/FreeRTOS-documentation-and-book.html\r
70  * for an introductory guide to using real time kernels, and FreeRTOS in\r
71  * particular.\r
72  *\r
73  *****\r
74  *\r
75  * The DICE-KIT-16FX has two 7 segment displays and two buttons that can\r
76  * generate interrupts.  This example uses this IO as follows:\r
77  *\r
78  *\r
79  * - Left 7 segment display -\r
80  *\r
81  * 7 'flash' tasks are created, each of which toggles a single segment of the\r
82  * left display.  Each task executes at a fixed frequency, with a different\r
83  * frequency being used by each task.\r
84  *\r
85  * When button SW2 is pressed an interrupt is generated that wakes up a 'dice'\r
86  * task.  The dice task suspends the 7 tasks that are accessing the left display\r
87  * before simulating a dice being thrown by generating a random number between\r
88  * 1 and 6.  After the number has been generated the task sleeps for 5 seconds,\r
89  * if SW2 is pressed again within the 5 seconds another random number is\r
90  * generated, if SW2 is not pressed within the 5 seconds then the 7 tasks are\r
91  * un-suspended and will once again toggle the segments of the left hand display.\r
92  *\r
93  *\r
94  * - Right 7 segment display -\r
95  *\r
96  * Control of the right side 7 segment display is very similar to that of the\r
97  * left, except co-routines are used to toggle the segments instead of tasks,\r
98  * and button SW3 is used instead of SW2.\r
99  *\r
100  *\r
101  * - Notes -\r
102  *\r
103  * Only one dice task is actually defined.  Two instances of this single\r
104  * definition are created, the first to simulate a dice being thrown on the left\r
105  * display, and the other to simulate a dice being thrown on the right display.\r
106  * The task parameter is used to let the dice tasks know which display to\r
107  * control.\r
108  *\r
109  * Both dice tasks and the flash tasks operate completely independently under\r
110  * the control of FreeRTOS.  11 tasks and 7 co-routines are created in total,\r
111  * including the idle task.\r
112  *\r
113  * The co-routines all execute within a single low priority task.\r
114  *\r
115  *\r
116  *\r
117  * When this demo is executing as expected:\r
118  *\r
119  * + Every segment of both displays will toggle at a fixed frequency - with each\r
120  *   segment using a different frequency.\r
121  * + When a button is pushed the segment toggling will temporarily stop and the\r
122  *   dice 'throw' will start whereby the display will show a fast changing random\r
123  *   number for a few seconds before the dice value is chosen and displayed.\r
124  * + If the button is not pushed again within five seconds of the dice value being\r
125  *   displayed the segment toggling will commence again.\r
126  *\r
127  *****/\r
128 \r
129 /* Kernel includes. */\r
130 #include "FreeRTOS.h"\r
131 #include "Task.h"\r
132 \r
133 /* Demo includes. */\r
134 #include "DiceTask.h"\r
135 #include "ParTest.h"\r
136 #include "Flash.h"\r
137 \r
138 /* The priority at which the dice task execute. */\r
139 #define mainDICE_PRIORITY                       ( tskIDLE_PRIORITY + 2 )\r
140 \r
141 /*\r
142  * Sets up the MCU IO for the 7 segment displays and the button inputs.\r
143  */\r
144 static void prvSetupHardware( void );\r
145 \r
146 /*\r
147  * The function that creates the flash tasks and co-routines (the tasks and\r
148  * co-routines that toggle the 7 segment display segments.\r
149  */\r
150 extern vCreateFlashTasksAndCoRoutines( void );\r
151 \r
152 /*-----------------------------------------------------------*/\r
153 \r
154 void main( void )\r
155 {\r
156         /* Setup the MCU IO. */\r
157         prvSetupHardware();\r
158 \r
159         /* Create the tasks and co-routines that toggle the display segments. */\r
160         vCreateFlashTasksAndCoRoutines();\r
161 \r
162         /* Create a 'dice' task to control the left hand display. */\r
163         xTaskCreate( vDiceTask, "Dice1", configMINIMAL_STACK_SIZE, ( void * ) configLEFT_DISPLAY, mainDICE_PRIORITY, NULL );\r
164 \r
165         /* Create a 'dice' task to control the right hand display. */\r
166         xTaskCreate( vDiceTask, "Dice2", configMINIMAL_STACK_SIZE, ( void * ) configRIGHT_DISPLAY, mainDICE_PRIORITY, NULL );\r
167 \r
168         /* Start the scheduler running. */\r
169         vTaskStartScheduler();\r
170 \r
171         /* If this loop is executed then there was insufficient heap memory for the\r
172         idle task to be created - causing vTaskStartScheduler() to return. */\r
173         while( 1 );\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r
177 static void prvSetupHardware( void )\r
178 {\r
179         /* Setup interrupt hardware - interrupts are kept disabled for now to\r
180         prevent any interrupts attempting to cause a context switch before the\r
181         scheduler has been started. */\r
182         InitIrqLevels();\r
183         portDISABLE_INTERRUPTS();\r
184         __set_il( 7 );\r
185 \r
186         /* Set Port3 as output (7Segment Display). */\r
187         DDR03  = 0xff;\r
188 \r
189         /* Use Port 5 as I/O-Port. */\r
190         ADER1  = 0;\r
191         PDR05  = 0x7f;\r
192 \r
193         /* Set Port5 as output (7Segment Display). */\r
194         DDR05  = 0xff;\r
195 \r
196         /* Disable inputs on the following ports. */\r
197         PIER02 = 0x00;\r
198         PDR02  = 0x00;\r
199         DDR02  = 0xff;\r
200         PIER03 = 0x00;\r
201         PDR03  = 0xff;\r
202         PIER05 = 0x00;\r
203         PDR05  = 0x00;\r
204         PIER06 = 0x00;\r
205         PDR06  = 0x00;\r
206         DDR06  = 0xff;\r
207 \r
208         /* Enable P00_0/INT8 and P00_1/INT9 as input. */\r
209         PIER00 = 0x03;\r
210 \r
211         /* Enable external interrupt 8. */\r
212         PIER00_IE0 = 1;\r
213 \r
214         /* LB0, LA0 = 11 -> falling edge. */\r
215         ELVRL1_LB8 = 1;\r
216         ELVRL1_LA8 = 1;\r
217 \r
218         /* Reset and enable the interrupt request. */\r
219         EIRR1_ER8 = 0;\r
220         ENIR1_EN8 = 1;\r
221 \r
222         /* Enable external interrupt 9. */\r
223         PIER00_IE1 = 1;\r
224 \r
225         /* LB1, LA1 = 11 -> falling edge. */\r
226         ELVRL1_LB9 = 1;\r
227         ELVRL1_LA9 = 1;\r
228 \r
229         /* Reset and enable the interrupt request. */\r
230         EIRR1_ER9 = 0;\r
231         ENIR1_EN9 = 1;\r
232 }\r
233 \r