FreeRTOS Real Time Operating System, Modified from Kenji Arai's initial port. See freertos.org for full documentation.

Fork of FreeRTOS_on_mbed_v1 by Kenji Arai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers flash.c Source File

flash.c

00001 /*
00002     FreeRTOS V6.0.3 - Copyright (C) 2010 Real Time Engineers Ltd.
00003 
00004     ***************************************************************************
00005     *                                                                         *
00006     * If you are:                                                             *
00007     *                                                                         *
00008     *    + New to FreeRTOS,                                                   *
00009     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
00010     *    + Looking for basic training,                                        *
00011     *    + Wanting to improve your FreeRTOS skills and productivity           *
00012     *                                                                         *
00013     * then take a look at the FreeRTOS eBook                                  *
00014     *                                                                         *
00015     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
00016     *                  http://www.FreeRTOS.org/Documentation                  *
00017     *                                                                         *
00018     * A pdf reference manual is also available.  Both are usually delivered   *
00019     * to your inbox within 20 minutes to two hours when purchased between 8am *
00020     * and 8pm GMT (although please allow up to 24 hours in case of            *
00021     * exceptional circumstances).  Thank you for your support!                *
00022     *                                                                         *
00023     ***************************************************************************
00024 
00025     This file is part of the FreeRTOS distribution.
00026 
00027     FreeRTOS is free software; you can redistribute it and/or modify it under
00028     the terms of the GNU General Public License (version 2) as published by the
00029     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
00030     ***NOTE*** The exception to the GPL is included to allow you to distribute
00031     a combined work that includes FreeRTOS without being obliged to provide the
00032     source code for proprietary components outside of the FreeRTOS kernel.
00033     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
00034     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00035     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00036     more details. You should have received a copy of the GNU General Public 
00037     License and the FreeRTOS license exception along with FreeRTOS; if not it 
00038     can be viewed here: http://www.freertos.org/a00114.html and also obtained 
00039     by writing to Richard Barry, contact details for whom are available on the
00040     FreeRTOS WEB site.
00041 
00042     1 tab == 4 spaces!
00043 
00044     http://www.FreeRTOS.org - Documentation, latest information, license and
00045     contact details.
00046 
00047     http://www.SafeRTOS.com - A version that is certified for use in safety
00048     critical systems.
00049 
00050     http://www.OpenRTOS.com - Commercial support, development, porting,
00051     licensing and training services.
00052 */
00053 
00054 /**
00055  * This version of flash .c is for use on systems that have limited stack space
00056  * and no display facilities.  The complete version can be found in the 
00057  * Demo/Common/Full directory.
00058  * 
00059  * Three tasks are created, each of which flash an LED at a different rate.  The first 
00060  * LED flashes every 200ms, the second every 400ms, the third every 600ms.
00061  *
00062  * The LED flash tasks provide instant visual feedback.  They show that the scheduler 
00063  * is still operational.
00064  *
00065  */
00066 
00067 
00068 #include <stdlib.h>
00069 
00070 /* Scheduler include files. */
00071 #include "FreeRTOS.h"
00072 #include "task.h"
00073 
00074 /* Demo program include files. */
00075 #include "partest.h"
00076 #include "flash.h"
00077 
00078 #define ledSTACK_SIZE        configMINIMAL_STACK_SIZE
00079 #define ledNUMBER_OF_LEDS    ( 3 )
00080 #define ledFLASH_RATE_BASE    ( ( portTickType ) 333 )
00081 
00082 /* Variable used by the created tasks to calculate the LED number to use, and
00083 the rate at which they should flash the LED. */
00084 static volatile unsigned portBASE_TYPE uxFlashTaskNumber = 0;
00085 
00086 /* The task that is created three times. */
00087 static portTASK_FUNCTION_PROTO( vLEDFlashTask, pvParameters );
00088 
00089 /*-----------------------------------------------------------*/
00090 
00091 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
00092 {
00093 signed portBASE_TYPE xLEDTask;
00094 
00095     /* Create the three tasks. */
00096     for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
00097     {
00098         /* Spawn the task. */
00099         xTaskCreate( vLEDFlashTask, ( signed char * ) "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
00100     }
00101 }
00102 /*-----------------------------------------------------------*/
00103 
00104 static portTASK_FUNCTION( vLEDFlashTask, pvParameters )
00105 {
00106 portTickType xFlashRate, xLastFlashTime;
00107 unsigned portBASE_TYPE uxLED;
00108 
00109     /* The parameters are not used. */
00110     ( void ) pvParameters;
00111 
00112     /* Calculate the LED and flash rate. */
00113     portENTER_CRITICAL();
00114     {
00115         /* See which of the eight LED's we should use. */
00116         uxLED = uxFlashTaskNumber;
00117 
00118         /* Update so the next task uses the next LED. */
00119         uxFlashTaskNumber++;
00120     }
00121     portEXIT_CRITICAL();
00122 
00123     xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( portTickType ) uxLED );
00124     xFlashRate /= portTICK_RATE_MS;
00125 
00126     /* We will turn the LED on and off again in the delay period, so each
00127     delay is only half the total period. */
00128     xFlashRate /= ( portTickType ) 2;
00129 
00130     /* We need to initialise xLastFlashTime prior to the first call to 
00131     vTaskDelayUntil(). */
00132     xLastFlashTime = xTaskGetTickCount();
00133 
00134     for(;;)
00135     {
00136         /* Delay for half the flash period then turn the LED on. */
00137         vTaskDelayUntil( &xLastFlashTime, xFlashRate );
00138         vParTestToggleLED( uxLED );
00139 
00140         /* Delay for half the flash period then turn the LED off. */
00141         vTaskDelayUntil( &xLastFlashTime, xFlashRate );
00142         vParTestToggleLED( uxLED );
00143     }
00144 } /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
00145