]> git.sur5r.net Git - freertos/blob - Demo/MB96350_Softune_Dice_Kit/main.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / MB96350_Softune_Dice_Kit / main.c
1 /*\r
2         FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4         This file is part of the FreeRTOS distribution.\r
5 \r
6         FreeRTOS is free software; you can redistribute it and/or modify it     under \r
7         the terms of the GNU General Public License (version 2) as published by the \r
8         Free Software Foundation and modified by the FreeRTOS exception.\r
9         **NOTE** The exception to the GPL is included to allow you to distribute a\r
10         combined work that includes FreeRTOS without being obliged to provide the \r
11         source code for proprietary components outside of the FreeRTOS kernel.  \r
12         Alternative commercial license and support terms are also available upon \r
13         request.  See the licensing section of http://www.FreeRTOS.org for full \r
14         license details.\r
15 \r
16         FreeRTOS is distributed in the hope that it will be useful,     but WITHOUT\r
17         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19         more details.\r
20 \r
21         You should have received a copy of the GNU General Public License along\r
22         with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26         ***************************************************************************\r
27         *                                                                         *\r
28         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *\r
29         * See http://www.FreeRTOS.org/Documentation for details                   *\r
30         *                                                                         *\r
31         ***************************************************************************\r
32 \r
33         1 tab == 4 spaces!\r
34 \r
35         Please ensure to read the configuration and relevant port sections of the\r
36         online documentation.\r
37 \r
38         http://www.FreeRTOS.org - Documentation, latest information, license and\r
39         contact details.\r
40 \r
41         http://www.SafeRTOS.com - A version that is certified for use in safety\r
42         critical systems.\r
43 \r
44         http://www.OpenRTOS.com - Commercial support, development, porting,\r
45         licensing and training services.\r
46 */\r
47 \r
48 \r
49 /*****\r
50  *\r
51  * See http://www.freertos.org/Documentation/FreeRTOS-documentation-and-book.html\r
52  * for an introductory guide to using real time kernels, and FreeRTOS in \r
53  * particular. \r
54  *\r
55  *****\r
56  *  \r
57  * The DICE-KIT-16FX has two 7 segment displays and two buttons that can\r
58  * generate interrupts.  This example uses this IO as follows:\r
59  *\r
60  *\r
61  * - Left 7 segment display - \r
62  *\r
63  * 7 'flash' tasks are created, each of which toggles a single segment of the \r
64  * left display.  Each task executes at a fixed frequency, with a different \r
65  * frequency being used by each task.\r
66  *\r
67  * When button SW2 is pressed an interrupt is generated that wakes up a 'dice'\r
68  * task.  The dice task suspends the 7 tasks that are accessing the left display\r
69  * before simulating a dice being thrown by generating a random number between\r
70  * 1 and 6.  After the number has been generated the task sleeps for 5 seconds,\r
71  * if SW2 is pressed again within the 5 seconds another random number is \r
72  * generated, if SW2 is not pressed within the 5 seconds then the 7 tasks are\r
73  * un-suspended and will once again toggle the segments of the left hand display.\r
74  *\r
75  *\r
76  * - Right 7 segment display -\r
77  *\r
78  * Control of the right side 7 segment display is very similar to that of the\r
79  * left, except co-routines are used to toggle the segments instead of tasks,\r
80  * and button SW3 is used instead of SW2.\r
81  *\r
82  *\r
83  * - Notes -\r
84  *\r
85  * Only one dice task is actually defined.  Two instances of this single\r
86  * definition are created, the first to simulate a dice being thrown on the left\r
87  * display, and the other to simulate a dice being thrown on the right display.\r
88  * The task parameter is used to let the dice tasks know which display to \r
89  * control.\r
90  *\r
91  * Both dice tasks and the flash tasks operate completely independently under\r
92  * the control of FreeRTOS.  11 tasks and 7 co-routines are created in total,\r
93  * including the idle task. \r
94  *\r
95  * The co-routines all execute within a single low priority task.\r
96  *\r
97  *\r
98  *\r
99  * When this demo is executing as expected:\r
100  *\r
101  * + Every segment of both displays will toggle at a fixed frequency - with each\r
102  *   segment using a different frequency.\r
103  * + When a button is pushed the segment toggling will temporarily stop and the\r
104  *   dice 'throw' will start whereby the display will show a fast changing random\r
105  *   number for a few seconds before the dice value is chosen and displayed.\r
106  * + If the button is not pushed again within five seconds of the dice value being\r
107  *   displayed the segment toggling will commence again.\r
108  *\r
109  *****/\r
110 \r
111 /* Kernel includes. */\r
112 #include "FreeRTOS.h"\r
113 #include "Task.h"\r
114 \r
115 /* Demo includes. */\r
116 #include "DiceTask.h"\r
117 #include "ParTest.h"\r
118 #include "Flash.h"\r
119 \r
120 /* The priority at which the dice task execute. */\r
121 #define mainDICE_PRIORITY                       ( tskIDLE_PRIORITY + 2 )\r
122 \r
123 /*\r
124  * Sets up the MCU IO for the 7 segment displays and the button inputs.\r
125  */\r
126 static void prvSetupHardware( void );\r
127 \r
128 /*\r
129  * The function that creates the flash tasks and co-routines (the tasks and\r
130  * co-routines that toggle the 7 segment display segments.\r
131  */\r
132 extern vCreateFlashTasksAndCoRoutines( void );\r
133 \r
134 /*-----------------------------------------------------------*/\r
135 \r
136 void main( void )\r
137 {\r
138         /* Setup the MCU IO. */\r
139         prvSetupHardware();\r
140 \r
141         /* Create the tasks and co-routines that toggle the display segments. */\r
142         vCreateFlashTasksAndCoRoutines();\r
143 \r
144         /* Create a 'dice' task to control the left hand display. */\r
145         xTaskCreate( vDiceTask, ( signed char * ) "Dice1", configMINIMAL_STACK_SIZE, ( void * ) configLEFT_DISPLAY, mainDICE_PRIORITY, NULL );\r
146 \r
147         /* Create a 'dice' task to control the right hand display. */\r
148         xTaskCreate( vDiceTask, ( signed char * ) "Dice2", configMINIMAL_STACK_SIZE, ( void * ) configRIGHT_DISPLAY, mainDICE_PRIORITY, NULL );\r
149 \r
150         /* Start the scheduler running. */\r
151         vTaskStartScheduler();\r
152 \r
153         /* If this loop is executed then there was insufficient heap memory for the\r
154         idle task to be created - causing vTaskStartScheduler() to return. */\r
155         while( 1 );\r
156 }\r
157 /*-----------------------------------------------------------*/\r
158 \r
159 static void prvSetupHardware( void )\r
160 {\r
161         /* Setup interrupt hardware - interrupts are kept disabled for now to\r
162         prevent any interrupts attempting to cause a context switch before the\r
163         scheduler has been started. */\r
164         InitIrqLevels();\r
165         portDISABLE_INTERRUPTS();\r
166         __set_il( 7 );  \r
167 \r
168         /* Set Port3 as output (7Segment Display). */\r
169         DDR03  = 0xff;\r
170 \r
171         /* Use Port 5 as I/O-Port. */\r
172         ADER1  = 0;\r
173         PDR05  = 0x7f;\r
174 \r
175         /* Set Port5 as output (7Segment Display). */\r
176         DDR05  = 0xff;\r
177 \r
178         /* Disable inputs on the following ports. */\r
179         PIER02 = 0x00;\r
180         PDR02  = 0x00;\r
181         DDR02  = 0xff;\r
182         PIER03 = 0x00;\r
183         PDR03  = 0xff;\r
184         PIER05 = 0x00;\r
185         PDR05  = 0x00;\r
186         PIER06 = 0x00;\r
187         PDR06  = 0x00;\r
188         DDR06  = 0xff;\r
189 \r
190         /* Enable P00_0/INT8 and P00_1/INT9 as input. */\r
191         PIER00 = 0x03;\r
192 \r
193         /* Enable external interrupt 8. */\r
194         PIER00_IE0 = 1;\r
195         \r
196         /* LB0, LA0 = 11 -> falling edge. */\r
197         ELVRL1_LB8 = 1;\r
198         ELVRL1_LA8 = 1;\r
199 \r
200         /* Reset and enable the interrupt request. */\r
201         EIRR1_ER8 = 0;\r
202         ENIR1_EN8 = 1;\r
203 \r
204         /* Enable external interrupt 9. */\r
205         PIER00_IE1 = 1;\r
206         \r
207         /* LB1, LA1 = 11 -> falling edge. */\r
208         ELVRL1_LB9 = 1;\r
209         ELVRL1_LA9 = 1;\r
210 \r
211         /* Reset and enable the interrupt request. */\r
212         EIRR1_ER9 = 0;\r
213         ENIR1_EN9 = 1;  \r
214 }\r
215 \r