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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 582 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
 * (which just exist to test the kernel port and provide an example of how to use
59
 * each FreeRTOS API function).
60
 *
61
 * In addition to the standard demo tasks, the following tasks and tests are
62
 * defined and/or created within this file:
63
 *
64
 * "Check" task - This only executes every five seconds but has the highest
65
 * priority so is guaranteed to get processor time.  Its main function is to
66
 * check that all the standard demo tasks are still operational. The check task
67
 * will toggle LED 3 (PB11) every five seconds so long as no errors have been
68
 * detected.  The toggle rate will increase to half a second if an error has
69
 * been found in any task.
70
 *
71
 * "Echo" task - This is a very basic task that simply echoes any characters
72
 * received on COM0 (USART1).  This can be tested by transmitting a text file
73
 * from a dumb terminal to the STM32 USART then observing or capturing the text
74
 * that is echoed back.  Missing characters will be all the more obvious if the
75
 * file contains a simple repeating string of fixed width.
76
 *
77
 * Currently this demo does not include interrupt nesting examples.  High
78
 * frequency timer and simpler nesting examples can be found in most Cortex M3
79
 * demo applications.
80
 *
81
 * The functions used to initialise, set and clear LED outputs are normally
82
 * defined in partest.c.  This demo includes two partest files, one that is
83
 * configured for use with the Keil MCBSTM32 evaluation board (called
84
 * ParTest_MCBSTM32.c) and one that is configured for use with the official
85
 * ST Eval board (called ParTest_ST_Eval.c).  One one of these files should be
86
 * included in the build at any one time, as appropriate for the hardware
87
 * actually being used.
88
 */
89
 
90
/* Standard includes. */
91
#include <string.h>
92
 
93
/* Scheduler includes. */
94
#include "FreeRTOS.h"
95
#include "task.h"
96
#include "queue.h"
97
 
98
/* Library includes. */
99
#include "stm32f10x_it.h"
100
 
101
/* Demo app includes. */
102
#include "BlockQ.h"
103
#include "integer.h"
104
#include "flash.h"
105
#include "partest.h"
106
#include "semtest.h"
107
#include "GenQTest.h"
108
#include "QPeek.h"
109
#include "recmutex.h"
110
 
111
/* Driver includes. */
112
#include "STM32_USART.h"
113
 
114
 
115
/* The time between cycles of the 'check' task - which depends on whether the
116
check task has detected an error or not. */
117
#define mainCHECK_DELAY_NO_ERROR                        ( ( portTickType ) 5000 / portTICK_RATE_MS )
118
#define mainCHECK_DELAY_ERROR                           ( ( portTickType ) 500 / portTICK_RATE_MS )
119
 
120
/* The LED controlled by the 'check' task. */
121
#define mainCHECK_LED                                           ( 3 )
122
 
123
/* Task priorities. */
124
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
125
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
126
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
127
#define mainFLASH_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
128
#define mainECHO_TASK_PRIORITY                          ( tskIDLE_PRIORITY + 1 )
129
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
130
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
131
 
132
/* COM port and baud rate used by the echo task. */
133
#define mainCOM0                                                        ( 0 )
134
#define mainBAUD_RATE                                           ( 115200 )
135
 
136
/*-----------------------------------------------------------*/
137
 
138
/*
139
 * Configure the hardware for the demo.
140
 */
141
static void prvSetupHardware( void );
142
 
143
/* The 'check' task as described at the top of this file. */
144
static void prvCheckTask( void *pvParameters );
145
 
146
/* A simple task that echoes all the characters that are received on COM0
147
(USART1). */
148
static void prvUSARTEchoTask( void *pvParameters );
149
 
150
/*-----------------------------------------------------------*/
151
 
152
int main( void )
153
{
154
#ifdef DEBUG
155
  debug();
156
#endif
157
 
158
        /* Set up the clocks and memory interface. */
159
        prvSetupHardware();
160
 
161
        /* Start the standard demo tasks.  These are just here to exercise the
162
        kernel port and provide examples of how the FreeRTOS API can be used. */
163
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
164
    vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
165
    vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
166
    vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
167
        vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
168
    vStartQueuePeekTasks();
169
    vStartRecursiveMutexTasks();
170
 
171
        /* Create the 'echo' task, which is also defined within this file. */
172
        xTaskCreate( prvUSARTEchoTask, ( signed char * ) "Echo", configMINIMAL_STACK_SIZE, NULL, mainECHO_TASK_PRIORITY, NULL );
173
 
174
        /* Create the 'check' task, which is also defined within this file. */
175
        xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
176
 
177
    /* Start the scheduler. */
178
        vTaskStartScheduler();
179
 
180
    /* Will only get here if there was insufficient memory to create the idle
181
    task.  The idle task is created within vTaskStartScheduler(). */
182
        for( ;; );
183
}
184
/*-----------------------------------------------------------*/
185
 
186
/* Described at the top of this file. */
187
static void prvCheckTask( void *pvParameters )
188
{
189
portTickType xLastExecutionTime;
190
unsigned long ulTicksToWait = mainCHECK_DELAY_NO_ERROR;
191
 
192
        /* Just to remove the compiler warning about the unused parameter. */
193
        ( void ) pvParameters;
194
 
195
        /* Initialise the variable used to control our iteration rate prior to
196
        its first use. */
197
        xLastExecutionTime = xTaskGetTickCount();
198
 
199
        for( ;; )
200
        {
201
                /* Wait until it is time to run the tests again. */
202
                vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
203
 
204
                /* Has an error been found in any task? */
205
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
206
                {
207
                        /* Reduce the time between cycles of this task - which has the
208
                        effect of increasing the rate at which the 'check' LED toggles to
209
                        indicate the existence of an error to an observer. */
210
                        ulTicksToWait = mainCHECK_DELAY_ERROR;
211
                }
212
                else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
213
                {
214
                        ulTicksToWait = mainCHECK_DELAY_ERROR;
215
                }
216
                else if( xAreBlockingQueuesStillRunning() != pdTRUE )
217
                {
218
                        ulTicksToWait = mainCHECK_DELAY_ERROR;
219
                }
220
            else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
221
            {
222
                ulTicksToWait = mainCHECK_DELAY_ERROR;
223
            }
224
            else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
225
            {
226
                ulTicksToWait = mainCHECK_DELAY_ERROR;
227
            }
228
            else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
229
            {
230
                ulTicksToWait = mainCHECK_DELAY_ERROR;
231
            }
232
 
233
                vParTestToggleLED( mainCHECK_LED );
234
        }
235
}
236
/*-----------------------------------------------------------*/
237
 
238
/* Described at the top of this file. */
239
static void prvUSARTEchoTask( void *pvParameters )
240
{
241
signed char cChar;
242
 
243
/* String declared static to ensure it does not end up on the stack, no matter
244
what the optimisation level. */
245
static const char *pcLongishString =
246
"ABBA was a Swedish pop music group formed in Stockholm in 1972, consisting of Anni-Frid Frida Lyngstad, "
247
"Björn Ulvaeus, Benny Andersson and Agnetha Fältskog. Throughout the band's existence, Fältskog and Ulvaeus "
248
"were a married couple, as were Lyngstad and Andersson - although both couples later divorced. They became one "
249
"of the most commercially successful acts in the history of popular music, and they topped the charts worldwide "
250
"from 1972 to 1983.  ABBA gained international popularity employing catchy song hooks, simple lyrics, sound "
251
"effects (reverb, phasing) and a Wall of Sound achieved by overdubbing the female singers' voices in multiple "
252
"harmonies. As their popularity grew, they were sought after to tour Europe, Australia, and North America, drawing "
253
"crowds of ardent fans, notably in Australia. Touring became a contentious issue, being particularly cumbersome for "
254
"Fältskog, but they continued to release studio albums to widespread commercial success. At the height of their "
255
"popularity, however, both relationships began suffering strain that led ultimately to the collapse of first the "
256
"Ulvaeus-Fältskog marriage (in 1979) and then of the Andersson-Lyngstad marriage in 1981. In the late 1970s and early "
257
"1980s these relationship changes began manifesting in the group's music, as they produced more thoughtful, "
258
"introspective lyrics with different compositions.";
259
 
260
        /* Just to avoid compiler warnings. */
261
        ( void ) pvParameters;
262
 
263
        /* Initialise COM0, which is USART1 according to the STM32 libraries. */
264
        lCOMPortInit( mainCOM0, mainBAUD_RATE );
265
 
266
        /* Try sending out a string all in one go, as a very basic test of the
267
    lSerialPutString() function. */
268
    lSerialPutString( mainCOM0, pcLongishString, strlen( pcLongishString ) );
269
 
270
        for( ;; )
271
        {
272
                /* Block to wait for a character to be received on COM0. */
273
                xSerialGetChar( mainCOM0, &cChar, portMAX_DELAY );
274
 
275
                /* Write the received character back to COM0. */
276
                xSerialPutChar( mainCOM0, cChar, 0 );
277
        }
278
}
279
/*-----------------------------------------------------------*/
280
 
281
static void prvSetupHardware( void )
282
{
283
        /* RCC system reset(for debug purpose). */
284
        RCC_DeInit ();
285
 
286
    /* Enable HSE. */
287
        RCC_HSEConfig( RCC_HSE_ON );
288
 
289
        /* Wait till HSE is ready. */
290
        while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
291
 
292
    /* HCLK = SYSCLK. */
293
        RCC_HCLKConfig( RCC_SYSCLK_Div1 );
294
 
295
    /* PCLK2  = HCLK. */
296
        RCC_PCLK2Config( RCC_HCLK_Div1 );
297
 
298
    /* PCLK1  = HCLK/2. */
299
        RCC_PCLK1Config( RCC_HCLK_Div2 );
300
 
301
        /* ADCCLK = PCLK2/4. */
302
        RCC_ADCCLKConfig( RCC_PCLK2_Div4 );
303
 
304
    /* Flash 2 wait state. */
305
        *( volatile unsigned long  * )0x40022000 = 0x01;
306
 
307
        /* PLLCLK = 8MHz * 9 = 72 MHz */
308
        RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_9 );
309
 
310
    /* Enable PLL. */
311
        RCC_PLLCmd( ENABLE );
312
 
313
        /* Wait till PLL is ready. */
314
        while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
315
 
316
        /* Select PLL as system clock source. */
317
        RCC_SYSCLKConfig (RCC_SYSCLKSource_PLLCLK);
318
 
319
        /* Wait till PLL is used as system clock source. */
320
        while (RCC_GetSYSCLKSource() != 0x08);
321
 
322
        /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
323
        RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
324
                                                        | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE );
325
 
326
        /* Set the Vector Table base address at 0x08000000. */
327
        NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 );
328
 
329
        NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
330
 
331
        /* Configure HCLK clock as SysTick clock source. */
332
        SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK );
333
 
334
        /* Initialise the IO used for the LED outputs. */
335
        vParTestInitialise();
336
 
337
        /* SPI2 Periph clock enable */
338
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );
339
}
340
/*-----------------------------------------------------------*/
341
 
342
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
343
{
344
        /* This function will get called if a task overflows its stack.   If the
345
        parameters are corrupt then inspect pxCurrentTCB to find which was the
346
        offending task. */
347
 
348
        ( void ) pxTask;
349
        ( void ) pcTaskName;
350
 
351
        for( ;; );
352
}
353
/*-----------------------------------------------------------*/
354
 
355
void assert_failed( unsigned char *pucFile, unsigned long ulLine )
356
{
357
        ( void ) pucFile;
358
        ( void ) ulLine;
359
 
360
        for( ;; );
361
}
362
 

powered by: WebSVN 2.1.0

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