OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [MB96350_Softune_Dice_Kit/] [main.c] - Blame information for rev 792

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.