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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 583 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
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
56
 * documentation provides more details of the demo application tasks.
57
 *
58
 * This demo is configured to execute on the ES449 prototyping board from
59
 * SoftBaugh. The ES449 has a built in LCD display and a single built in user
60
 * LED.  Therefore, in place of flashing an LED, the 'flash' and 'check' tasks
61
 * toggle '*' characters on the LCD.  The left most '*' represents LED 0, the
62
 * next LED 1, etc.
63
 *
64
 * Main. c also creates a task called 'Check'.  This only executes every three
65
 * seconds but has the highest priority so is guaranteed to get processor time.
66
 * Its main function is to check that all the other tasks are still operational.
67
 * Each task that does not flash an LED maintains a unique count that is
68
 * incremented each time the task successfully completes its function.  Should
69
 * any error occur within such a task the count is permanently halted.  The
70
 * 'check' task inspects the count of each task to ensure it has changed since
71
 * the last time the check task executed.  If all the count variables have
72
 * changed all the tasks are still executing error free, and the check task
73
 * toggles an LED with a three second period.  Should any task contain an error
74
 * at any time the LED toggle rate will increase to 500ms.
75
 *
76
 * Please read the documentation for the MSP430 port available on
77
 * http://www.FreeRTOS.org.
78
 */
79
 
80
/* Standard includes. */
81
#include <stdlib.h>
82
#include <signal.h>
83
 
84
/* Scheduler includes. */
85
#include "FreeRTOS.h"
86
#include "task.h"
87
 
88
/* Demo application includes. */
89
#include "partest.h"
90
#include "flash.h"
91
#include "integer.h"
92
#include "comtest2.h"
93
#include "PollQ.h"
94
 
95
/* Constants required for hardware setup. */
96
#define mainALL_BITS_OUTPUT             ( ( unsigned char ) 0xff )
97
#define mainMAX_FREQUENCY               ( ( unsigned char ) 121 )
98
 
99
/* Constants that define the LED's used by the various tasks. [in this case
100
the '*' characters on the LCD represent LED's] */
101
#define mainCHECK_LED                   ( 4 )
102
#define mainCOM_TEST_LED                ( 10 )
103
 
104
/* Demo task priorities. */
105
#define mainCHECK_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 3 )
106
#define mainCOM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 2 )
107
#define mainQUEUE_POLL_PRIORITY                 ( tskIDLE_PRIORITY + 2 )
108
#define mainLED_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 1 )
109
 
110
/* Baud rate used by the COM test tasks. */
111
#define mainCOM_TEST_BAUD_RATE                  ( ( unsigned long ) 19200 )
112
 
113
/* The frequency at which the 'Check' tasks executes.  See the comments at the
114
top of the page.  When the system is operating error free the 'Check' task
115
toggles an LED every three seconds.  If an error is discovered in any task the
116
rate is increased to 500 milliseconds.  [in this case the '*' characters on the
117
LCD represent LED's]*/
118
#define mainNO_ERROR_CHECK_DELAY                ( ( portTickType ) 3000 / portTICK_RATE_MS  )
119
#define mainERROR_CHECK_DELAY                   ( ( portTickType ) 500 / portTICK_RATE_MS  )
120
 
121
/*
122
 * The function that implements the Check task.  See the comments at the head
123
 * of the page for implementation details.
124
 */
125
static void vErrorChecks( void *pvParameters );
126
 
127
/*
128
 * Called by the Check task.  Returns pdPASS if all the other tasks are found
129
 * to be operating without error - otherwise returns pdFAIL.
130
 */
131
static short prvCheckOtherTasksAreStillRunning( void );
132
 
133
/*
134
 * Perform the hardware setup required by the ES449 in order to run the demo
135
 * application.
136
 */
137
static void prvSetupHardware( void );
138
 
139
/* Used to detect the idle hook function stalling. */
140
static volatile unsigned long ulIdleLoops = 0UL;
141
 
142
/*-----------------------------------------------------------*/
143
 
144
/*
145
 * Start the demo application tasks - then start the real time scheduler.
146
 */
147
int main( void )
148
{
149
        /* Setup the hardware ready for the demo. */
150
        prvSetupHardware();
151
        vParTestInitialise();
152
 
153
        /* Start the standard demo application tasks. */
154
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
155
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
156
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
157
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
158
 
159
        /* Start the 'Check' task which is defined in this file. */
160
        xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
161
 
162
        /* Start the scheduler. */
163
        vTaskStartScheduler();
164
 
165
        /* As the scheduler has been started the demo applications tasks will be
166
        executing and we should never get here! */
167
        return 0;
168
}
169
/*-----------------------------------------------------------*/
170
 
171
static void vErrorChecks( void *pvParameters )
172
{
173
static volatile unsigned long ulDummyVariable = 3UL;
174
portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
175
 
176
        /* Cycle for ever, delaying then checking all the other tasks are still
177
        operating without error. */
178
        for( ;; )
179
        {
180
                /* Wait until it is time to check again.  The time we wait here depends
181
                on whether an error has been detected or not.  When an error is
182
                detected the time is shortened resulting in a faster LED flash rate. */
183
                vTaskDelay( xDelayPeriod );
184
 
185
                /* Perform a bit of 32bit maths to ensure the registers used by the
186
                integer tasks get some exercise outside of the integer tasks
187
                themselves. The result here is not important we are just deliberately
188
                changing registers used by other tasks to ensure that their context
189
                switch is operating as required. - see the demo application
190
                documentation for more info. */
191
                ulDummyVariable *= 3UL;
192
 
193
                /* See if the other tasks are all ok. */
194
                if( prvCheckOtherTasksAreStillRunning() != pdPASS )
195
                {
196
                        /* An error occurred in one of the tasks so shorten the delay
197
                        period - which has the effect of increasing the frequency of the
198
                        LED toggle. */
199
                        xDelayPeriod = mainERROR_CHECK_DELAY;
200
                }
201
 
202
                /* Flash! */
203
                vParTestToggleLED( mainCHECK_LED );
204
        }
205
}
206
/*-----------------------------------------------------------*/
207
 
208
static short prvCheckOtherTasksAreStillRunning( void )
209
{
210
static short sNoErrorFound = pdTRUE;
211
static unsigned long ulLastIdleLoops = 0UL;
212
 
213
        /* The demo tasks maintain a count that increments every cycle of the task
214
        provided that the task has never encountered an error.  This function
215
        checks the counts maintained by the tasks to ensure they are still being
216
        incremented.  A count remaining at the same value between calls therefore
217
        indicates that an error has been detected.  Only tasks that do not flash
218
        an LED are checked. */
219
 
220
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
221
        {
222
                sNoErrorFound = pdFALSE;
223
        }
224
 
225
        if( xAreComTestTasksStillRunning() != pdTRUE )
226
        {
227
                sNoErrorFound = pdFALSE;
228
        }
229
 
230
        if( xArePollingQueuesStillRunning() != pdTRUE )
231
        {
232
                sNoErrorFound = pdFALSE;
233
        }
234
 
235
        if( ulLastIdleLoops == ulIdleLoops )
236
        {
237
                sNoErrorFound = pdFALSE;
238
        }
239
 
240
        ulLastIdleLoops = ulIdleLoops;
241
 
242
        return sNoErrorFound;
243
}
244
/*-----------------------------------------------------------*/
245
 
246
static void prvSetupHardware( void )
247
{
248
        /* Stop the watchdog. */
249
        WDTCTL = WDTPW + WDTHOLD;
250
 
251
        /* Setup DCO+ for ( xtal * D * (N + 1) ) operation. */
252
        FLL_CTL0 |= DCOPLUS + XCAP18PF;
253
 
254
        /* X2 DCO frequency, 8MHz nominal DCO */
255
        SCFI0 |= FN_4;
256
 
257
        /* (121+1) x 32768 x 2 = 7.99 Mhz */
258
        SCFQCTL = mainMAX_FREQUENCY;
259
 
260
        /* Setup the IO as per the SoftBaugh demo for the same target hardware. */
261
        P1SEL = 0x32;
262
        P2SEL = 0x00;
263
        P3SEL = 0x00;
264
        P4SEL = 0xFC;
265
        P5SEL = 0xFF;
266
}
267
/*-----------------------------------------------------------*/
268
 
269
void vApplicationIdleHook( void );
270
void vApplicationIdleHook( void )
271
{
272
        /* Simple put the CPU into lowpower mode. */
273
        _BIS_SR( LPM3_bits );
274
        ulIdleLoops++;
275
}
276
/*-----------------------------------------------------------*/
277
 
278
 
279
 
280
 
281
 
282
 
283
 

powered by: WebSVN 2.1.0

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