]> 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 V6.0.0 - 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     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 \r
50 /*****\r
51  *\r
52  * See http://www.freertos.org/Documentation/FreeRTOS-documentation-and-book.html\r
53  * for an introductory guide to using real time kernels, and FreeRTOS in \r
54  * particular. \r
55  *\r
56  *****\r
57  *  \r
58  * The DICE-KIT-16FX has two 7 segment displays and two buttons that can\r
59  * generate interrupts.  This example uses this IO as follows:\r
60  *\r
61  *\r
62  * - Left 7 segment display - \r
63  *\r
64  * 7 'flash' tasks are created, each of which toggles a single segment of the \r
65  * left display.  Each task executes at a fixed frequency, with a different \r
66  * frequency being used by each task.\r
67  *\r
68  * When button SW2 is pressed an interrupt is generated that wakes up a 'dice'\r
69  * task.  The dice task suspends the 7 tasks that are accessing the left display\r
70  * before simulating a dice being thrown by generating a random number between\r
71  * 1 and 6.  After the number has been generated the task sleeps for 5 seconds,\r
72  * if SW2 is pressed again within the 5 seconds another random number is \r
73  * generated, if SW2 is not pressed within the 5 seconds then the 7 tasks are\r
74  * un-suspended and will once again toggle the segments of the left hand display.\r
75  *\r
76  *\r
77  * - Right 7 segment display -\r
78  *\r
79  * Control of the right side 7 segment display is very similar to that of the\r
80  * left, except co-routines are used to toggle the segments instead of tasks,\r
81  * and button SW3 is used instead of SW2.\r
82  *\r
83  *\r
84  * - Notes -\r
85  *\r
86  * Only one dice task is actually defined.  Two instances of this single\r
87  * definition are created, the first to simulate a dice being thrown on the left\r
88  * display, and the other to simulate a dice being thrown on the right display.\r
89  * The task parameter is used to let the dice tasks know which display to \r
90  * control.\r
91  *\r
92  * Both dice tasks and the flash tasks operate completely independently under\r
93  * the control of FreeRTOS.  11 tasks and 7 co-routines are created in total,\r
94  * including the idle task. \r
95  *\r
96  * The co-routines all execute within a single low priority task.\r
97  *\r
98  *\r
99  *\r
100  * When this demo is executing as expected:\r
101  *\r
102  * + Every segment of both displays will toggle at a fixed frequency - with each\r
103  *   segment using a different frequency.\r
104  * + When a button is pushed the segment toggling will temporarily stop and the\r
105  *   dice 'throw' will start whereby the display will show a fast changing random\r
106  *   number for a few seconds before the dice value is chosen and displayed.\r
107  * + If the button is not pushed again within five seconds of the dice value being\r
108  *   displayed the segment toggling will commence again.\r
109  *\r
110  *****/\r
111 \r
112 /* Kernel includes. */\r
113 #include "FreeRTOS.h"\r
114 #include "Task.h"\r
115 \r
116 /* Demo includes. */\r
117 #include "DiceTask.h"\r
118 #include "ParTest.h"\r
119 #include "Flash.h"\r
120 \r
121 /* The priority at which the dice task execute. */\r
122 #define mainDICE_PRIORITY                       ( tskIDLE_PRIORITY + 2 )\r
123 \r
124 /*\r
125  * Sets up the MCU IO for the 7 segment displays and the button inputs.\r
126  */\r
127 static void prvSetupHardware( void );\r
128 \r
129 /*\r
130  * The function that creates the flash tasks and co-routines (the tasks and\r
131  * co-routines that toggle the 7 segment display segments.\r
132  */\r
133 extern vCreateFlashTasksAndCoRoutines( void );\r
134 \r
135 /*-----------------------------------------------------------*/\r
136 \r
137 void main( void )\r
138 {\r
139         /* Setup the MCU IO. */\r
140         prvSetupHardware();\r
141 \r
142         /* Create the tasks and co-routines that toggle the display segments. */\r
143         vCreateFlashTasksAndCoRoutines();\r
144 \r
145         /* Create a 'dice' task to control the left hand display. */\r
146         xTaskCreate( vDiceTask, ( signed char * ) "Dice1", configMINIMAL_STACK_SIZE, ( void * ) configLEFT_DISPLAY, mainDICE_PRIORITY, NULL );\r
147 \r
148         /* Create a 'dice' task to control the right hand display. */\r
149         xTaskCreate( vDiceTask, ( signed char * ) "Dice2", configMINIMAL_STACK_SIZE, ( void * ) configRIGHT_DISPLAY, mainDICE_PRIORITY, NULL );\r
150 \r
151         /* Start the scheduler running. */\r
152         vTaskStartScheduler();\r
153 \r
154         /* If this loop is executed then there was insufficient heap memory for the\r
155         idle task to be created - causing vTaskStartScheduler() to return. */\r
156         while( 1 );\r
157 }\r
158 /*-----------------------------------------------------------*/\r
159 \r
160 static void prvSetupHardware( void )\r
161 {\r
162         /* Setup interrupt hardware - interrupts are kept disabled for now to\r
163         prevent any interrupts attempting to cause a context switch before the\r
164         scheduler has been started. */\r
165         InitIrqLevels();\r
166         portDISABLE_INTERRUPTS();\r
167         __set_il( 7 );  \r
168 \r
169         /* Set Port3 as output (7Segment Display). */\r
170         DDR03  = 0xff;\r
171 \r
172         /* Use Port 5 as I/O-Port. */\r
173         ADER1  = 0;\r
174         PDR05  = 0x7f;\r
175 \r
176         /* Set Port5 as output (7Segment Display). */\r
177         DDR05  = 0xff;\r
178 \r
179         /* Disable inputs on the following ports. */\r
180         PIER02 = 0x00;\r
181         PDR02  = 0x00;\r
182         DDR02  = 0xff;\r
183         PIER03 = 0x00;\r
184         PDR03  = 0xff;\r
185         PIER05 = 0x00;\r
186         PDR05  = 0x00;\r
187         PIER06 = 0x00;\r
188         PDR06  = 0x00;\r
189         DDR06  = 0xff;\r
190 \r
191         /* Enable P00_0/INT8 and P00_1/INT9 as input. */\r
192         PIER00 = 0x03;\r
193 \r
194         /* Enable external interrupt 8. */\r
195         PIER00_IE0 = 1;\r
196         \r
197         /* LB0, LA0 = 11 -> falling edge. */\r
198         ELVRL1_LB8 = 1;\r
199         ELVRL1_LA8 = 1;\r
200 \r
201         /* Reset and enable the interrupt request. */\r
202         EIRR1_ER8 = 0;\r
203         ENIR1_EN8 = 1;\r
204 \r
205         /* Enable external interrupt 9. */\r
206         PIER00_IE1 = 1;\r
207         \r
208         /* LB1, LA1 = 11 -> falling edge. */\r
209         ELVRL1_LB9 = 1;\r
210         ELVRL1_LA9 = 1;\r
211 \r
212         /* Reset and enable the interrupt request. */\r
213         EIRR1_ER9 = 0;\r
214         ENIR1_EN9 = 1;  \r
215 }\r
216 \r