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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 595 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
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
57
 * documentation provides more details of the standard demo application tasks.
58
 * In addition to the standard demo tasks, the following tasks and tests are
59
 * defined and/or created within this file:
60
 *
61
 * "LCD test" task - the LCD task writes a continually repeating series of patterns
62
 * to the LCD display.
63
 *
64
 * "LED test" task -  This is a very simple task that just turns on user LEDs
65
 * 8 to 15 in turn, before turning them off again.
66
 *
67
 * "Check task" - The check task only runs every five seconds but has the highest
68
 * priority so is guaranteed to get processing time.  Its main job is to inspect
69
 * all the other standard demo tasks to ensure they are executing without error.
70
 * The Check task will toggle LED 0 every five seconds while no errors exist,
71
 * with the toggle frequency increasing to 200ms should an error be detected in
72
 * any other task.
73
 *
74
 * Both the check task and the idle task place the processor into energy saving
75
 * mode 1, which will be exited following each tick interrupt.  The check task
76
 * is the highest priority task in the system, so while it is executing no other
77
 * task will execute.  If the check task places the processor into a low power
78
 * mode without blocking then the energy consumption as viewed on the Energy
79
 * Micro Gecko board will go down noticeably as in effect no tasks will be running.
80
 * The check task places the processor into low power mode for two out of every
81
 * five seconds.  The current use of low power modes is very basic.  Future
82
 * FreeRTOS releases will aim to make significant improvements.
83
 *
84
 */
85
 /* Scheduler includes. */
86
#include "FreeRTOS.h"
87
#include "croutine.h"
88
#include "task.h"
89
#include "queue.h"
90
#include "semphr.h"
91
 
92
/* Common demo application includes. */
93
#include "partest.h"
94
#include "GenQTest.h"
95
#include "QPeek.h"
96
#include "recmutex.h"
97
#include "semtest.h"
98
 
99
/* Demo application includes. */
100
#include "lcdcontroller.h"
101
#include "ledtest.h"
102
#include "lcdtest.h"
103
#include "chip.h"
104
 
105
/* Task priorities. */
106
#define mainLCD_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 1 )
107
#define mainLED_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 2 )
108
#define mainGEN_Q_TASK_PRIORITY                 ( tskIDLE_PRIORITY )
109
#define mainSEMAPHORE_TASK_PRIORITY             ( tskIDLE_PRIORITY + 1 )
110
#define mainCHECK_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 3 )
111
 
112
/* A period of two seconds, adjusted to use the tick frequency. */
113
#define mainTWO_SECONDS                                 ( 2000 / portTICK_RATE_MS )
114
 
115
/* The length of the delay between each cycle of the check task when an error
116
has / has not been detected. */
117
#define mainNO_ERROR_CHECK_FREQUENCY    ( 5000 / portTICK_RATE_MS )
118
#define mainERROR_CHECK_FREQUENCY               ( 200 / portTICK_RATE_MS )
119
 
120
/* The LED that is toggled by the check task.  The rate of the toggle indicates
121
whether or not an error has been found, as defined by the
122
mainNO_ERROR_CHECK_FREQUENCY and mainERROR_CHECK_FREQUENCY definitions above. */
123
#define mainCHECK_LED                                   ( 0 )
124
 
125
/*-----------------------------------------------------------*/
126
 
127
/*
128
 * Configure the hardware as required by the demo.
129
 */
130
static void prvSetupHardware( void );
131
 
132
/*
133
 * The check task as described at the top of this file.
134
 */
135
static void prvCheckTask( void *pvParameters );
136
 
137
/*
138
 * Put the CPU into the least low power low power mode.
139
 */
140
static void prvLowPowerMode1( void );
141
 
142
/*-----------------------------------------------------------*/
143
 
144
int main( void )
145
{
146
        /* Perform the necessary hardware configuration. */
147
        prvSetupHardware();
148
 
149
        /* Create the task that writes various text and patterns to the LCD. */
150
        xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
151
 
152
        /* Create a task that writes to LEDs 8 to 15. */
153
        xTaskCreate( vLEDTask, "LCDTask", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );
154
 
155
        /* Create some of the standard demo tasks.  These just test the port and
156
        demonstrate how the FreeRTOS API can be used.  They do not provide any
157
        specific functionality. */
158
        vStartGenericQueueTasks( mainGEN_Q_TASK_PRIORITY );
159
        vStartQueuePeekTasks();
160
        vStartRecursiveMutexTasks();
161
        vStartSemaphoreTasks( mainSEMAPHORE_TASK_PRIORITY );
162
 
163
        /* Create the check task as described at the top of this file. */
164
        xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
165
 
166
        /* Start the scheduler. */
167
        vTaskStartScheduler();
168
 
169
        /* The scheduler should now be running the tasks so the following code should
170
        never be reached.  If it is reached then there was insufficient heap space
171
        for the idle task to be created.  In this case the heap size is set by
172
        configTOTAL_HEAP_SIZE in FreeRTOSConfig.h. */
173
        for( ;; );
174
}
175
/*-----------------------------------------------------------*/
176
 
177
void vApplicationIdleHook( void )
178
{
179
        /* Use the idle task to place the CPU into a low power mode.  Greater power
180
        saving could be achieved by not including any demo tasks that never block. */
181
        prvLowPowerMode1();
182
}
183
/*-----------------------------------------------------------*/
184
 
185
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
186
{
187
        /* This function will be called if a task overflows its stack, if
188
        configCHECK_FOR_STACK_OVERFLOW != 0.  It might be that the function
189
        parameters have been corrupted, depending on the severity of the stack
190
        overflow.  When this is the case pxCurrentTCB can be inspected in the
191
        debugger to find the offending task. */
192
        for( ;; );
193
}
194
/*-----------------------------------------------------------*/
195
 
196
static void prvCheckTask( void *pvParameters )
197
{
198
portTickType xLastExecutionTime, xFrequency = mainNO_ERROR_CHECK_FREQUENCY;
199
long lCount;
200
 
201
        /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
202
        works correctly. */
203
        xLastExecutionTime = xTaskGetTickCount();
204
 
205
        for( ;; )
206
        {
207
                /* Perform this check at a frequency that indicates whether or not an
208
                error has been found. */
209
                vTaskDelayUntil( &xLastExecutionTime, xFrequency );
210
 
211
                /* Check all the other tasks are running without error. */
212
                if( xAreGenericQueueTasksStillRunning() != pdPASS )
213
                {
214
                        xFrequency = mainERROR_CHECK_FREQUENCY;
215
                }
216
 
217
                if( xAreQueuePeekTasksStillRunning() != pdPASS )
218
                {
219
                        xFrequency = mainERROR_CHECK_FREQUENCY;
220
                }
221
 
222
                if( xAreRecursiveMutexTasksStillRunning() != pdPASS )
223
                {
224
                        xFrequency = mainERROR_CHECK_FREQUENCY;
225
                }
226
 
227
                if( xAreSemaphoreTasksStillRunning() != pdPASS )
228
                {
229
                        xFrequency = mainERROR_CHECK_FREQUENCY;
230
                }
231
 
232
                /* Toggle the LED to show that the check hook function is running.
233
                The toggle freequency will increase if an error has been found in any
234
                task. */
235
                vParTestToggleLED( mainCHECK_LED );
236
 
237
                /* Just loop around putting the processor into low power mode 1 for
238
                a while.  This is the highest priority task, and this loop does not
239
                cause it to block, so it will remain as the running task.  Each time it
240
                runs for the next two seconds it will simply put the processor to sleep.
241
                No other task will run so nothing else will happen.  This periodic two
242
                seconds of lower power should be viewable using the Advanced Energy
243
                Monitor on the Energy Micro Gecko board. */
244
                for( lCount = 0; lCount < mainTWO_SECONDS; lCount++ )
245
                {
246
                        prvLowPowerMode1();
247
                }
248
        }
249
}
250
/*-----------------------------------------------------------*/
251
 
252
static void prvSetupHardware( void )
253
{
254
        /* Initialise the LEDs. */
255
        vParTestInitialise();
256
 
257
        /* Configure the LCD. */
258
        LCD_Init( LCD );
259
}
260
/*-----------------------------------------------------------*/
261
 
262
static void prvLowPowerMode1( void )
263
{
264
        /* Clear SLEEPDEEP for EM1 */
265
        SCB->SCR &= ~( 1 << SCB_SCR_SLEEPDEEP_Pos );
266
 
267
        /* Power down. */
268
        __WFI();
269
}
270
 
271
 

powered by: WebSVN 2.1.0

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