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

Subversion Repositories openrisc

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

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
 * The documentation page for this demo available on http://www.FreeRTOS.org
56
 * documents the hardware configuration required to run this demo.  It also
57
 * provides more information on the expected demo application behaviour.
58
 *
59
 * main() creates all the demo application tasks, then starts the scheduler.
60
 * A lot of the created tasks are from the pool of "standard demo" tasks.  The
61
 * web documentation provides more details of the standard demo tasks, which
62
 * provide no particular functionality but do provide good examples of how to
63
 * use the FreeRTOS API.
64
 *
65
 * In addition to the standard demo tasks, the following tasks, interrupts and
66
 * tests are defined and/or created within this file:
67
 *
68
 * "LCD" task - The LCD task is a 'gatekeeper' task.  It is the only task that
69
 * is permitted to access the LCD and therefore ensures access to the LCD is
70
 * always serialised and there are no mutual exclusion issues.  When a task or
71
 * an interrupt wants to write to the LCD, it does not access the LCD directly
72
 * but instead sends the message to the LCD task.  The LCD task then performs
73
 * the actual LCD output.  This mechanism also allows interrupts to, in effect,
74
 * write to the LCD by sending messages to the LCD task.
75
 *
76
 * The LCD task is also a demonstration of a 'controller' task design pattern.
77
 * Some tasks do not actually send a string to the LCD task directly, but
78
 * instead send a command that is interpreted by the LCD task.  In a normal
79
 * application these commands can be control values or set points, in this
80
 * simple example the commands just result in messages being displayed on the
81
 * LCD.
82
 *
83
 * "Button Poll" task - This task polls the state of the 'up' key on the
84
 * joystick input device.  It uses the vTaskDelay() API function to control
85
 * the poll rate to ensure debouncing is not necessary and that the task does
86
 * not use all the available CPU processing time.
87
 *
88
 * Button Interrupt and run time stats display - The select button on the
89
 * joystick input device is configured to generate an external interrupt.  The
90
 * handler for this interrupt sends a message to LCD task, which interprets the
91
 * message to mean, firstly write a message to the LCD, and secondly, generate
92
 * a table of run time statistics.  The run time statistics are displayed as a
93
 * table that contains information on how much processing time each task has
94
 * been allocated since the application started to execute.  This information
95
 * is provided both as an absolute time, and as a percentage of the total run
96
 * time.  The information is displayed in the terminal IO window of the IAR
97
 * embedded workbench.  The online documentation for this demo shows a screen
98
 * shot demonstrating where the run time stats can be viewed.
99
 *
100
 * Idle Hook - The idle hook is a function that is called on each iteration of
101
 * the idle task.  In this case it is used to place the processor into a low
102
 * power mode.  Note however that this application is implemented using standard
103
 * components, and is therefore not optimised for low power operation.  Lower
104
 * power consumption would be achieved by converting polling tasks into event
105
 * driven tasks, and slowing the tick interrupt frequency.
106
 *
107
 * "Check" function called from the tick hook - The tick hook is called during
108
 * each tick interrupt.  It is called from an interrupt context so must execute
109
 * quickly, not attempt to block, and not call any FreeRTOS API functions that
110
 * do not end in "FromISR".  In this case the tick hook executes a 'check'
111
 * function.  This only executes every five seconds.  Its main function is to
112
 * check that all the standard demo tasks are still operational.  Each time it
113
 * executes it sends a status code to the LCD task.  The LCD task interprets the
114
 * code and displays an appropriate message - which will be PASS if no tasks
115
 * have reported any errors, or a message stating which task has reported an
116
 * error.
117
*/
118
 
119
/* Standard includes. */
120
#include <stdio.h>
121
 
122
/* Kernel includes. */
123
#include "FreeRTOS.h"
124
#include "task.h"
125
#include "queue.h"
126
 
127
/* Demo application includes. */
128
#include "partest.h"
129
#include "flash.h"
130
#include "dynamic.h"
131
#include "comtest2.h"
132
#include "GenQTest.h"
133
 
134
/* Eval board includes. */
135
#include "stm32_eval.h"
136
#include "stm32l152_eval_lcd.h"
137
 
138
/* The priorities assigned to the tasks. */
139
#define mainFLASH_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 1 )
140
#define mainLCD_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 1 )
141
#define mainCOM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 2 )
142
#define mainGENERIC_QUEUE_TEST_PRIORITY ( tskIDLE_PRIORITY )
143
 
144
/* The length of the queue (the number of items the queue can hold) that is used
145
to send messages from tasks and interrupts the the LCD task. */
146
#define mainQUEUE_LENGTH                                ( 5 )
147
 
148
/* Codes sent within messages to the LCD task so the LCD task can interpret
149
exactly what the message it just received was.  These are sent in the
150
cMessageID member of the message structure (defined below). */
151
#define mainMESSAGE_BUTTON_UP                   ( 1 )
152
#define mainMESSAGE_BUTTON_SEL                  ( 2 )
153
#define mainMESSAGE_STATUS                              ( 3 )
154
 
155
/* When the cMessageID member of the message sent to the LCD task is
156
mainMESSAGE_STATUS then these definitions are sent in the lMessageValue member
157
of the same message and indicate what the status actually is. */
158
#define mainERROR_DYNAMIC_TASKS                 ( pdPASS + 1 )
159
#define mainERROR_COM_TEST                              ( pdPASS + 2 )
160
#define mainERROR_GEN_QUEUE_TEST                ( pdPASS + 3 )
161
 
162
/* Baud rate used by the comtest tasks. */
163
#define mainCOM_TEST_BAUD_RATE                  ( 115200 )
164
 
165
/* The LED used by the comtest tasks. See the comtest.c file for more
166
information. */
167
#define mainCOM_TEST_LED                                ( 3 )
168
 
169
/* The LCD task uses printf() so requires more stack than most of the other
170
tasks. */
171
#define mainLCD_TASK_STACK_SIZE                 ( configMINIMAL_STACK_SIZE * 2 )
172
 
173
/*-----------------------------------------------------------*/
174
 
175
/*
176
 * System configuration is performed prior to main() being called, this function
177
 * configures the peripherals used by the demo application.
178
 */
179
static void prvSetupHardware( void );
180
 
181
/*
182
 * Definition of the LCD/controller task described in the comments at the top
183
 * of this file.
184
 */
185
static void prvLCDTask( void *pvParameters );
186
 
187
/*
188
 * Definition of the button poll task described in the comments at the top of
189
 * this file.
190
 */
191
static void prvButtonPollTask( void *pvParameters );
192
 
193
/*
194
 * Converts a status message value into an appropriate string for display on
195
 * the LCD.  The string is written to pcBuffer.
196
 */
197
static void prvGenerateStatusMessage( char *pcBuffer, long lStatusValue );
198
 
199
/*-----------------------------------------------------------*/
200
 
201
/* The time base for the run time stats is generated by the 16 bit timer 6.
202
Each time the timer overflows ulTIM6_OverflowCount is incremented.  Therefore,
203
when converting the total run time to a 32 bit number, the most significant two
204
bytes are given by ulTIM6_OverflowCount and the least significant two bytes are
205
given by the current TIM6 counter value.  Care must be taken with data
206
consistency when combining the two in case a timer overflow occurs as the
207
value is being read. */
208
unsigned long ulTIM6_OverflowCount = 0UL;
209
 
210
/* The handle of the queue used to send messages from tasks and interrupts to
211
the LCD task. */
212
static xQueueHandle xLCDQueue = NULL;
213
 
214
/* The definition of each message sent from tasks and interrupts to the LCD
215
task. */
216
typedef struct
217
{
218
        char cMessageID;        /* << States what the message is. */
219
        long lMessageValue; /* << States the message value (can be an integer, string pointer, etc. depending on the value of cMessageID). */
220
} xQueueMessage;
221
 
222
/*-----------------------------------------------------------*/
223
 
224
void main( void )
225
{
226
        /* Configure the peripherals used by this demo application.  This includes
227
        configuring the joystick input select button to generate interrupts. */
228
        prvSetupHardware();
229
 
230
        /* Create the queue used by tasks and interrupts to send strings to the LCD
231
        task. */
232
        xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );
233
 
234
        /* If the queue could not be created then don't create any tasks that might
235
        attempt to use the queue. */
236
        if( xLCDQueue != NULL )
237
        {
238
                /* Add the created queue to the queue registry so it can be viewed in
239
                the IAR FreeRTOS state viewer plug-in. */
240
                vQueueAddToRegistry( xLCDQueue, "LCDQueue" );
241
 
242
                /* Create the LCD and button poll tasks, as described at the top of this
243
                file. */
244
                xTaskCreate( prvLCDTask, ( signed char * ) "LCD", mainLCD_TASK_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
245
                xTaskCreate( prvButtonPollTask, ( signed char * ) "ButPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
246
 
247
                /* Create a subset of the standard demo tasks. */
248
                vStartDynamicPriorityTasks();
249
                vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
250
                vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
251
                vStartGenericQueueTasks( mainGENERIC_QUEUE_TEST_PRIORITY );
252
 
253
                /* Start the scheduler. */
254
                vTaskStartScheduler();
255
        }
256
 
257
        /* If all is well then this line will never be reached.  If it is reached
258
        then it is likely that there was insufficient (FreeRTOS) heap memory space
259
        to create the idle task.  This may have been trapped by the malloc() failed
260
        hook function, if one is configured. */
261
        for( ;; );
262
}
263
/*-----------------------------------------------------------*/
264
 
265
static void prvLCDTask( void *pvParameters )
266
{
267
xQueueMessage xReceivedMessage;
268
long lLine = Line1;
269
const long lFontHeight = (((sFONT *)LCD_GetFont())->Height);
270
 
271
/* Buffer into which strings are formatted and placed ready for display on the
272
LCD.  Note this is a static variable to prevent it being allocated on the task
273
stack, which is too small to hold such a variable.  The stack size is configured
274
when the task is created. */
275
static char cBuffer[ 512 ];
276
 
277
        /* This function is the only function that uses printf().  If printf() is
278
        used from any other function then some sort of mutual exclusion on stdout
279
        will be necessary.
280
 
281
        This is also the only function that is permitted to access the LCD.
282
 
283
        First print out the number of bytes that remain in the FreeRTOS heap.  This
284
        can be viewed in the terminal IO window within the IAR Embedded Workbench. */
285
        printf( "%d bytes of heap space remain unallocated\n", xPortGetFreeHeapSize() );
286
 
287
        for( ;; )
288
        {
289
                /* Wait for a message to be received.  Using portMAX_DELAY as the block
290
                time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
291
                set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
292
                function return value and the function will only return when a value
293
                has been received. */
294
                xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );
295
 
296
                /* Clear the LCD if no room remains for any more text output. */
297
                if( lLine > Line9 )
298
                {
299
                        LCD_Clear( Blue );
300
                        lLine = 0;
301
                }
302
 
303
                /* What is this message?  What does it contain? */
304
                switch( xReceivedMessage.cMessageID )
305
                {
306
                        case mainMESSAGE_BUTTON_UP              :       /* The button poll task has just
307
                                                                                                informed this task that the up
308
                                                                                                button on the joystick input has
309
                                                                                                been pressed or released. */
310
                                                                                                sprintf( cBuffer, "Button up = %d", xReceivedMessage.lMessageValue );
311
                                                                                                break;
312
 
313
                        case mainMESSAGE_BUTTON_SEL             :       /* The select button interrupt
314
                                                                                                just informed this task that the
315
                                                                                                select button was pressed.
316
                                                                                                Generate a table of task run time
317
                                                                                                statistics and output this to
318
                                                                                                the terminal IO window in the IAR
319
                                                                                                embedded workbench. */
320
                                                                                                printf( "\nTask\t     Abs Time\t     %%Time\n*****************************************" );
321
                                                                                                vTaskGetRunTimeStats( ( signed char * ) cBuffer );
322
                                                                                                printf( cBuffer );
323
 
324
                                                                                                /* Also print out a message to
325
                                                                                                the LCD - in this case the
326
                                                                                                pointer to the string to print
327
                                                                                                is sent directly in the
328
                                                                                                lMessageValue member of the
329
                                                                                                message.  This just demonstrates
330
                                                                                                a different communication
331
                                                                                                technique. */
332
                                                                                                sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.lMessageValue );
333
                                                                                                break;
334
 
335
                        case mainMESSAGE_STATUS                 :       /* The tick interrupt hook
336
                                                                                                function has just informed this
337
                                                                                                task of the system status.
338
                                                                                                Generate a string in accordance
339
                                                                                                with the status value. */
340
                                                                                                prvGenerateStatusMessage( cBuffer, xReceivedMessage.lMessageValue );
341
                                                                                                break;
342
 
343
                        default                                                 :       sprintf( cBuffer, "Unknown message" );
344
                                                                                                break;
345
                }
346
 
347
                /* Output the message that was placed into the cBuffer array within the
348
                switch statement above. */
349
                LCD_DisplayStringLine( lLine, ( uint8_t * ) cBuffer );
350
 
351
                /* Move onto the next LCD line, ready for the next iteration of this
352
                loop. */
353
                lLine += lFontHeight;
354
        }
355
}
356
/*-----------------------------------------------------------*/
357
 
358
static void prvGenerateStatusMessage( char *pcBuffer, long lStatusValue )
359
{
360
        /* Just a utility function to convert a status value into a meaningful
361
        string for output onto the LCD. */
362
        switch( lStatusValue )
363
        {
364
                case pdPASS                                             :       sprintf( pcBuffer, "Task status = PASS" );
365
                                                                                        break;
366
                case mainERROR_DYNAMIC_TASKS    :       sprintf( pcBuffer, "Error: Dynamic tasks" );
367
                                                                                        break;
368
                case mainERROR_COM_TEST                 :       sprintf( pcBuffer, "Err: loop connected?" ); /* Error in COM test - is the Loopback connector connected? */
369
                                                                                        break;
370
                case mainERROR_GEN_QUEUE_TEST   :       sprintf( pcBuffer, "Error: Gen Q test" );
371
                                                                                        break;
372
                default                                                 :       sprintf( pcBuffer, "Unknown status" );
373
                                                                                        break;
374
        }
375
}
376
/*-----------------------------------------------------------*/
377
 
378
void EXTI9_5_IRQHandler( void )
379
{
380
/* Define the message sent to the LCD task from this interrupt. */
381
const xQueueMessage xMessage = { mainMESSAGE_BUTTON_SEL, ( unsigned long ) "Select Interrupt!" };
382
long lHigherPriorityTaskWoken = pdFALSE;
383
 
384
        /* This is the interrupt handler for the joystick select button input.
385
        The button has been pushed, write a message to the LCD via the LCD task. */
386
        xQueueSendFromISR( xLCDQueue, &xMessage, &lHigherPriorityTaskWoken );
387
 
388
        EXTI_ClearITPendingBit( SEL_BUTTON_EXTI_LINE );
389
 
390
        /* If writing to xLCDQueue caused a task to unblock, and the unblocked task
391
        has a priority equal to or above the task that this interrupt interrupted,
392
        then lHigherPriorityTaskWoken will have been set to pdTRUE internally within
393
        xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this
394
        interrupt returns directly to the higher priority unblocked task. */
395
        portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
396
}
397
/*-----------------------------------------------------------*/
398
 
399
void vApplicationTickHook( void )
400
{
401
static unsigned long ulCounter = 0;
402
static const unsigned long ulCheckFrequency = 5000UL / portTICK_RATE_MS;
403
long lHigherPriorityTaskWoken = pdFALSE;
404
 
405
/* Define the status message that is sent to the LCD task.  By default the
406
status is PASS. */
407
static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS };
408
 
409
        /* This is called from within the tick interrupt and performs the 'check'
410
        functionality as described in the comments at the top of this file.
411
 
412
        Is it time to perform the 'check' functionality again? */
413
        ulCounter++;
414
        if( ulCounter >= ulCheckFrequency )
415
        {
416
                /* See if the standard demo tasks are executing as expected, changing
417
                the message that is sent to the LCD task from PASS to an error code if
418
                any tasks set reports an error. */
419
                if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
420
                {
421
                        xStatusMessage.lMessageValue = mainERROR_DYNAMIC_TASKS;
422
                }
423
 
424
                if( xAreComTestTasksStillRunning() != pdPASS )
425
                {
426
                        xStatusMessage.lMessageValue = mainERROR_COM_TEST;
427
                }
428
 
429
                if( xAreGenericQueueTasksStillRunning() != pdPASS )
430
                {
431
                        xStatusMessage.lMessageValue = mainERROR_GEN_QUEUE_TEST;
432
                }
433
 
434
                /* As this is the tick hook the lHigherPriorityTaskWoken parameter is not
435
                needed (a context switch is going to be performed anyway), but it must
436
                still be provided. */
437
                xQueueSendFromISR( xLCDQueue, &xStatusMessage, &lHigherPriorityTaskWoken );
438
                ulCounter = 0;
439
        }
440
}
441
/*-----------------------------------------------------------*/
442
 
443
static void prvButtonPollTask( void *pvParameters )
444
{
445
long lLastState = pdTRUE;
446
long lState;
447
xQueueMessage xMessage;
448
 
449
        /* This tasks performs the button polling functionality as described at the
450
        top of this file. */
451
        for( ;; )
452
        {
453
                /* Check the button state. */
454
                lState = STM_EVAL_PBGetState( BUTTON_UP );
455
                if( lState != lLastState )
456
                {
457
                        /* The state has changed, send a message to the LCD task. */
458
                        xMessage.cMessageID = mainMESSAGE_BUTTON_UP;
459
                        xMessage.lMessageValue = lState;
460
                        lLastState = lState;
461
                        xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
462
                }
463
 
464
                /* Block for 10 milliseconds so this task does not utilise all the CPU
465
                time and debouncing of the button is not necessary. */
466
                vTaskDelay( 10 / portTICK_RATE_MS );
467
        }
468
}
469
/*-----------------------------------------------------------*/
470
 
471
static void prvSetupHardware( void )
472
{
473
        /* Ensure that all 4 interrupt priority bits are used as the pre-emption
474
        priority. */
475
        NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
476
 
477
        /* Initialise the LEDs. */
478
        vParTestInitialise();
479
 
480
        /* Initialise the joystick inputs. */
481
        STM_EVAL_PBInit( BUTTON_UP, BUTTON_MODE_GPIO );
482
        STM_EVAL_PBInit( BUTTON_DOWN, BUTTON_MODE_GPIO );
483
        STM_EVAL_PBInit( BUTTON_LEFT, BUTTON_MODE_GPIO );
484
        STM_EVAL_PBInit( BUTTON_RIGHT, BUTTON_MODE_GPIO );
485
 
486
        /* The select button in the middle of the joystick is configured to generate
487
        an interrupt.  The Eval board library will configure the interrupt
488
        priority to be the lowest priority available so the priority need not be
489
        set here explicitly.  It is important that the priority is equal to or
490
        below that set by the configMAX_SYSCALL_INTERRUPT_PRIORITY value set in
491
        FreeRTOSConfig.h. */
492
        STM_EVAL_PBInit( BUTTON_SEL, BUTTON_MODE_EXTI );
493
 
494
        /* Initialize the LCD */
495
        STM32L152_LCD_Init();
496
        LCD_Clear( Blue );
497
        LCD_SetBackColor( Blue );
498
        LCD_SetTextColor( White );
499
        LCD_DisplayStringLine( Line0, "  www.FreeRTOS.org" );
500
}
501
/*-----------------------------------------------------------*/
502
 
503
void vConfigureTimerForRunTimeStats( void )
504
{
505
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
506
NVIC_InitTypeDef NVIC_InitStructure;
507
 
508
        /* The time base for the run time stats is generated by the 16 bit timer 6.
509
        Each time the timer overflows ulTIM6_OverflowCount is incremented.
510
        Therefore, when converting the total run time to a 32 bit number, the most
511
        significant two bytes are given by ulTIM6_OverflowCount and the least
512
        significant two bytes are given by the current TIM6 counter value.  Care
513
        must be taken with data consistency when combining the two in case a timer
514
        overflow occurs as the value is being read.
515
 
516
        The portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro (in FreeRTOSConfig.h) is
517
        defined to call this function, so the kernel will call this function
518
        automatically at the appropriate time. */
519
 
520
        /* TIM6 clock enable */
521
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM6, ENABLE );
522
 
523
        /* The 32MHz clock divided by 5000 should tick (very) approximately every
524
        150uS and overflow a 16bit timer (very) approximately every 10 seconds. */
525
        TIM_TimeBaseStructure.TIM_Period = 65535;
526
        TIM_TimeBaseStructure.TIM_Prescaler = 5000;
527
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
528
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
529
 
530
        TIM_TimeBaseInit( TIM6, &TIM_TimeBaseStructure );
531
 
532
        /* Only interrupt on overflow events. */
533
        TIM6->CR1 |= TIM_CR1_URS;
534
 
535
        /* Enable the interrupt. */
536
        TIM_ITConfig( TIM6, TIM_IT_Update, ENABLE );
537
 
538
        /* Enable the TIM6 global Interrupt */
539
        NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
540
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY;
541
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00; /* Not used as 4 bits are used for the pre-emption priority. */
542
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
543
        NVIC_Init(&NVIC_InitStructure);
544
 
545
        TIM_ClearITPendingBit( TIM6, TIM_IT_Update );
546
        TIM_Cmd( TIM6, ENABLE );
547
}
548
/*-----------------------------------------------------------*/
549
 
550
void TIM6_IRQHandler( void )
551
{
552
        /* Interrupt handler for TIM 6
553
 
554
        The time base for the run time stats is generated by the 16 bit timer 6.
555
        Each time the timer overflows ulTIM6_OverflowCount is incremented.
556
        Therefore, when converting the total run time to a 32 bit number, the most
557
        significant two bytes are given by ulTIM6_OverflowCount and the least
558
        significant two bytes are given by the current TIM6 counter value.  Care
559
        must be taken with data consistency when combining the two in case a timer
560
        overflow occurs as the value is being read. */
561
        if( TIM_GetITStatus( TIM6, TIM_IT_Update) != RESET)
562
        {
563
                ulTIM6_OverflowCount++;
564
                TIM_ClearITPendingBit( TIM6, TIM_IT_Update );
565
        }
566
}
567
/*-----------------------------------------------------------*/
568
 
569
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
570
{
571
        ( void ) pcTaskName;
572
        ( void ) pxTask;
573
 
574
        /* Run time stack overflow checking is performed if
575
        configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
576
        function is called if a stack overflow is detected. */
577
        for( ;; );
578
}
579
/*-----------------------------------------------------------*/
580
 
581
void vApplicationMallocFailedHook( void )
582
{
583
        /* Called if a call to pvPortMalloc() fails because there is insufficient
584
        free memory available in the FreeRTOS heap.  pvPortMalloc() is called
585
        internally by FreeRTOS API functions that create tasks, queues or
586
        semaphores. */
587
        for( ;; );
588
}
589
/*-----------------------------------------------------------*/
590
 
591
void vApplicationIdleHook( void )
592
{
593
        /* Called on each iteration of the idle task.  In this case the idle task
594
        just enters a low(ish) power mode. */
595
        PWR_EnterSleepMode( PWR_Regulator_ON, PWR_SLEEPEntry_WFI );
596
}
597
 
598
 
599
 

powered by: WebSVN 2.1.0

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