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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_CY8C5588_PSoC_Creator_Keil/] [FreeRTOS_Demo.cydsn/] [main.c] - Blame information for rev 580

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 580 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
#include <device.h>
55
 
56
/* RTOS includes. */
57
#include "FreeRTOS.h"
58
#include "task.h"
59
#include "queue.h"
60
#include "semphr.h"
61
 
62
/* Common Demo includes. */
63
#include "serial.h"
64
#include "BlockQ.h"
65
#include "blocktim.h"
66
#include "comtest.h"
67
#include "countsem.h"
68
#include "death.h"
69
#include "dynamic.h"
70
#include "flash.h"
71
#include "flop.h"
72
#include "GenQTest.h"
73
#include "integer.h"
74
#include "IntQueue.h"
75
#include "mevents.h"
76
#include "partest.h"
77
#include "PollQ.h"
78
#include "print.h"
79
#include "QPeek.h"
80
#include "semtest.h"
81
/*---------------------------------------------------------------------------*/
82
 
83
/* The time between cycles of the 'check' functionality (defined within the
84
tick hook. */
85
#define mainCHECK_DELAY                                         ( ( portTickType ) 5000 / portTICK_RATE_MS )
86
#define mainCOM_LED                                                     ( 3 )
87
 
88
/* The number of nano seconds between each processor clock. */
89
#define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
90
 
91
/* Task priorities. */
92
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
93
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
94
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
95
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
96
#define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
97
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
98
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
99
#define mainCOM_TEST_TASK_PRIORITY                      ( tskIDLE_PRIORITY + 1 )
100
#define mainFLASH_TEST_TASK_PRIORITY            ( tskIDLE_PRIORITY + 2 )
101
/*---------------------------------------------------------------------------*/
102
 
103
/*
104
 * Configures the timers and interrupts for the fast interrupt test as
105
 * described at the top of this file.
106
 */
107
extern void vSetupTimerTest( void );
108
/*---------------------------------------------------------------------------*/
109
 
110
/*
111
 * The Check task periodical interrogates each of the running tests to
112
 * ensure that they are still executing correctly.
113
 * If all the tests pass, then the LCD is updated with Pass, the number of
114
 * iterations and the Jitter time calculated but the Fast Interrupt Test.
115
 * If any one of the tests fail, it is indicated with an error code printed on
116
 * the display. This indicator won't disappear until the device is reset.
117
 */
118
void vCheckTask( void *pvParameters );
119
 
120
/*
121
 * Installs the RTOS interrupt handlers and starts the peripherals.
122
 */
123
static void prvHardwareSetup( void );
124
/*---------------------------------------------------------------------------*/
125
 
126
void main( void )
127
{
128
unsigned long ulLed = 0;
129
unsigned long ulIteration = 0;
130
 
131
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
132
        prvHardwareSetup();
133
 
134
        /* Start the standard demo tasks.  These are just here to exercise the
135
        kernel port and provide examples of how the FreeRTOS API can be used. */
136
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
137
        vCreateBlockTimeTasks();
138
        vStartCountingSemaphoreTasks();
139
        vStartDynamicPriorityTasks();
140
        vStartMathTasks( mainINTEGER_TASK_PRIORITY );
141
        vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
142
        vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
143
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
144
        vStartQueuePeekTasks();
145
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
146
        vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
147
        vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
148
        vStartInterruptQueueTasks();
149
 
150
        /* Start the error checking task. */
151
        ( void ) xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
152
 
153
        /* Configure the timers used by the fast interrupt timer test. */
154
        vSetupTimerTest();
155
 
156
        /* The suicide tasks must be created last as they need to know how many
157
        tasks were running prior to their creation in order to ascertain whether
158
        or not the correct/expected number of tasks are running at any given time. */
159
        vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
160
 
161
        /* Will only get here if there was insufficient memory to create the idle
162
    task.  The idle task is created within vTaskStartScheduler(). */
163
        vTaskStartScheduler();
164
 
165
        /* Should never reach here as the kernel will now be running.  If
166
        vTaskStartScheduler() does return then it is very likely that there was
167
        insufficient (FreeRTOS) heap space available to create all the tasks,
168
        including the idle task that is created within vTaskStartScheduler() itself. */
169
        for( ;; );
170
}
171
/*---------------------------------------------------------------------------*/
172
 
173
void prvHardwareSetup( void )
174
{
175
/* Port layer functions that need to be copied into the vector table. */
176
extern void xPortPendSVHandler( void );
177
extern void xPortSysTickHandler( void );
178
extern void vPortSVCHandler( void );
179
extern cyisraddress CyRamVectors[];
180
 
181
        /* Install the OS Interrupt Handlers. */
182
        CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
183
        CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
184
        CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
185
 
186
        /* Start-up the peripherals. */
187
 
188
        /* Enable and clear the LCD Display. */
189
        LCD_Character_Display_Start();
190
        LCD_Character_Display_ClearDisplay();
191
        LCD_Character_Display_Position( 0, 0 );
192
        LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
193
        LCD_Character_Display_Position( 1, 0 );
194
        LCD_Character_Display_PrintString("CY8C5588AX-060  ");
195
 
196
        /* Start the UART. */
197
        UART_1_Start();
198
 
199
        /* Initialise the LEDs. */
200
        vParTestInitialise();
201
 
202
        /* Start the PWM modules that drive the IntQueue tests. */
203
        High_Frequency_PWM_0_Start();
204
        High_Frequency_PWM_1_Start();
205
 
206
        /* Start the timers for the Jitter test. */
207
        Timer_20KHz_Start();
208
        Timer_48MHz_Start();
209
}
210
/*---------------------------------------------------------------------------*/
211
 
212
void vCheckTask( void *pvParameters )
213
{
214
unsigned long ulRow = 0;
215
portTickType xDelay = 0;
216
unsigned short usErrorCode = 0;
217
unsigned long ulIteration = 0;
218
extern unsigned portSHORT usMaxJitter;
219
 
220
        /* Intialise the sleeper. */
221
        xDelay = xTaskGetTickCount();
222
 
223
        for( ;; )
224
        {
225
                /* Perform this check every mainCHECK_DELAY milliseconds. */
226
                vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
227
 
228
                /* Check that all of the Demo tasks are still running. */
229
                if( pdTRUE != xAreBlockingQueuesStillRunning() )
230
                {
231
                        usErrorCode |= 0x1;
232
                }
233
 
234
                if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
235
                {
236
                        usErrorCode |= 0x2;
237
                }
238
 
239
                if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
240
                {
241
                        usErrorCode |= 0x4;
242
                }
243
 
244
                if( pdTRUE != xIsCreateTaskStillRunning() )
245
                {
246
                        usErrorCode |= 0x8;
247
                }
248
 
249
                if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
250
                {
251
                        usErrorCode |= 0x10;
252
                }
253
 
254
                if( pdTRUE != xAreMathsTaskStillRunning() )
255
                {
256
                        usErrorCode |= 0x20;
257
                }
258
 
259
                if( pdTRUE != xAreGenericQueueTasksStillRunning() )
260
                {
261
                        usErrorCode |= 0x40;
262
                }
263
 
264
                if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
265
                {
266
                        usErrorCode |= 0x80;
267
                }
268
 
269
                if( pdTRUE != xArePollingQueuesStillRunning() )
270
                {
271
                        usErrorCode |= 0x100;
272
                }
273
 
274
                if( pdTRUE != xAreQueuePeekTasksStillRunning() )
275
                {
276
                        usErrorCode |= 0x200;
277
                }
278
 
279
                if( pdTRUE != xAreSemaphoreTasksStillRunning() )
280
                {
281
                        usErrorCode |= 0x400;
282
                }
283
 
284
                if( pdTRUE != xAreComTestTasksStillRunning() )
285
                {
286
                        usErrorCode |= 0x800;
287
                }
288
 
289
                if( pdTRUE != xAreIntQueueTasksStillRunning() )
290
                {
291
                        usErrorCode |= 0x1000;
292
                }
293
 
294
                /* Clear the display. */
295
                LCD_Character_Display_ClearDisplay();
296
                if( 0 == usErrorCode )
297
                {
298
                        LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
299
                        LCD_Character_Display_PrintString( "Pass: " );
300
                        LCD_Character_Display_PrintNumber( ulIteration++ );
301
                        LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
302
                        LCD_Character_Display_PrintString( "Jitter(ns):" );
303
                        LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
304
                }
305
                else
306
                {
307
                        /* Do something to indicate the failure. */
308
                        LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
309
                        LCD_Character_Display_PrintString( "Fail at: " );
310
                        LCD_Character_Display_PrintNumber( ulIteration );
311
                        LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
312
                        LCD_Character_Display_PrintString( "Error: 0x" );
313
                        LCD_Character_Display_PrintHexUint16( usErrorCode );
314
                }
315
        }
316
}
317
/*---------------------------------------------------------------------------*/
318
 
319
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
320
{
321
        /* The stack space has been execeeded for a task, considering allocating more. */
322
        taskDISABLE_INTERRUPTS();
323
        for( ;; );
324
}
325
/*---------------------------------------------------------------------------*/
326
 
327
void vApplicationMallocFailedHook( void )
328
{
329
        /* The heap space has been execeeded. */
330
        taskDISABLE_INTERRUPTS();
331
        for( ;; );
332
}
333
/*---------------------------------------------------------------------------*/

powered by: WebSVN 2.1.0

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