*\r
* main-full.c (this file) defines a comprehensive demo that creates many\r
* tasks, queues, semaphores and timers. It also demonstrates how Cortex-M3\r
- * interrupts can interact with FreeRTOS tasks/timers.\r
+ * interrupts can interact with FreeRTOS tasks/timers, a simple web server, and\r
+ * run time statistics gathering functionality. ***IF YOU ARE LOOKING FOR A \r
+ * SIMPLER STARTING POINT THEN USE THE "BLINKY" BUILD CONFIGURATION FIRST.***\r
*\r
- * This project runs on the SK-FM3-100PMC evaluation board, which is populated\r
- * with an MB9BF5006N Cortex-M3 based microcontroller.\r
+ * If the Ethernet functionality is excluded, then this demo will run 'stand \r
+ * alone' (without the rest of the tower system) on the TWR-K60N512 tower \r
+ * module. If the Ethernet functionality is included, then the full Freescale\r
+ * K60 tower kit, including both the TWR-K60N512 and TWR-SER modules, is \r
+ * required (as the Ethernet connector is on the TWR-SER). The TWR-K60N512 is \r
+ * populated with a K60N512 Cortex-M4 microcontroller.\r
*\r
* The main() Function:\r
- * main() creates three demo specific software timers, one demo specific queue,\r
- * and two demo specific tasks. It then creates a whole host of 'standard\r
- * demo' tasks/queues/semaphores, before starting the scheduler. The demo\r
- * specific tasks and timers are described in the comments here. The standard\r
- * demo tasks are described on the FreeRTOS.org web site.\r
+ * main() creates four demo specific software timers, and one demo specific\r
+ * task (the web server task). It also creates a whole host of 'standard\r
+ * demo' tasks/queues/semaphores/timers, before starting the scheduler. The \r
+ * demo specific tasks and timers are described in the comments here. The \r
+ * standard demo tasks are described on the FreeRTOS.org web site.\r
*\r
* The standard demo tasks provide no specific functionality. They are\r
* included to both test the FreeRTOS port, and provide examples of how the\r
* various FreeRTOS API functions can be used.\r
*\r
- * This demo creates 43 tasks in total. If you want a simpler demo, use the\r
- * Blinky build configuration.\r
+ * This demo creates 37 persistent tasks, then dynamically creates and destroys\r
+ * another two tasks as the demo executes.\r
*\r
- * The Demo Specific LED Software Timer and the Button Interrupt:\r
+ *\r
+ * The Demo Specific "LED" Timers and Callback Function:\r
+ * Two very simple LED timers are created. All they do is toggle and LED timer\r
+ * callback function is executed. The two timers share a callback function, so \r
+ * the callback function parameter is used to determine which timer actually \r
+ * expired, and therefore, which LED to toggle. Both timers use a different \r
+ * frequency, one toggles the blue LED and the other the green LED.\r
+ *\r
+ * The LED/Button Software Timer and the Button Interrupt:\r
* The user button SW2 is configured to generate an interrupt each time it is\r
- * pressed. The interrupt service routine switches an LED on, and resets the\r
- * LED software timer. The LED timer has a 5000 millisecond (5 second) period,\r
- * and uses a callback function that is defined to just turn the LED off again.\r
- * Therefore, pressing the user button will turn the LED on, and the LED will\r
- * remain on until a full five seconds pass without the button being pressed.\r
- * See the documentation page for this demo on the FreeRTOS.org web site to see\r
- * which LED is used.\r
+ * pressed. The interrupt service routine switches the orange/yellow LED on, \r
+ * and resets the LED software timer. The LED timer has a 5000 millisecond (5 \r
+ * second) period, and uses a callback function that is defined to just turn the \r
+ * LED off again. Therefore, pressing the user button will turn the LED on, and \r
+ * the LED will remain on until a full five seconds pass without the button \r
+ * being pressed.\r
+ *\r
+ * The Demo Specific "Check" Timer and Callback Function:\r
+ * The check timer period is initially set to three seconds. The check timer \r
+ * callback function checks that all the standard demo tasks are not only still \r
+ * executing, but are executing without reporting any errors. If the check \r
+ * timer discovers that a task has either stalled, or reported an error, then it \r
+ * changes its own period from the initial three seconds, to just 200ms. The \r
+ * check timer callback function also toggles the orange/red LED each time it is \r
+ * called. This provides a visual indication of the system status: If the LED \r
+ * toggles every three seconds, then no issues have been discovered. If the LED \r
+ * toggles every 200ms, then an issue has been discovered with at least one \r
+ * task. The last reported issue is latched into the pcStatusMessage variable, \r
+ * and displayed at the bottom of the "task stats" web page served by the \r
+ * embedded web server task.\r
*\r
- * The Demo Specific "Check" Callback Function:\r
- * This is called each time the 'check' timer expires. The check timer\r
- * callback function inspects all the standard demo tasks to see if they are\r
- * all executing as expected. The check timer is initially configured to\r
- * expire every three seconds, but will shorted this to every 500ms if an error\r
- * is ever discovered. The check timer callback toggles the LED defined by\r
- * the mainCHECK_LED definition each time it executes. Therefore, if LED\r
- * mainCHECK_LED is toggling every three seconds, then no error have been found.\r
- * If LED mainCHECK_LED is toggling every 500ms, then at least one errors has\r
- * been found. The variable pcStatusMessage is set to a string that indicates\r
- * which task reported an error. See the documentation page for this demo on\r
- * the FreeRTOS.org web site to see which LED in the 7 segment display is used.\r
+ * The web server task:\r
+ * The web server task implements a simple embedded web server that includes\r
+ * CGI scripting. Pages are provided that allow task statistics, network\r
+ * statistics and run time statistics to be viewed. In addition, an IO page is\r
+ * served that allows the orange/yellow LED to be turned on and off. Finally,\r
+ * a page is included that serves a large jpg file. See the documentation page\r
+ * for this demo on the http://www.FreeRTOS.org web site for web server\r
+ * configuration and usage instructions.\r
*\r
* The Demo Specific Idle Hook Function:\r
* The idle hook function demonstrates how to query the amount of FreeRTOS heap\r
* The Demo Specific Tick Hook Function:\r
* The tick hook function is used to test the interrupt safe software timer\r
* functionality.\r
+ * \r
*/\r
\r
/* Kernel includes. */\r
#include "countsem.h"\r
#include "dynamic.h"\r
\r
-/* The rate at which data is sent to the queue, specified in milliseconds, and\r
-converted to ticks using the portTICK_RATE_MS constant. */\r
-#define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_RATE_MS )\r
-\r
-/* The number of items the queue can hold. This is 1 as the receive task\r
-will remove items as they are added, meaning the send task should always find\r
-the queue empty. */\r
-#define mainQUEUE_LENGTH ( 1 )\r
-\r
/* The LED toggled by the check timer callback function. */\r
#define mainCHECK_LED 3UL\r
\r
#define mainTIMER_TEST_PERIOD ( 50 )\r
\r
/* Priorities used by the various different standard demo tasks. */\r
-#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )\r
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
-#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
-#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
#define mainuIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
\r
/* The WEB server uses string handling functions, which in turn use a bit more\r
stack than most of the other tasks. */\r
#define mainuIP_STACK_SIZE ( configMINIMAL_STACK_SIZE * 3 )\r
\r
-/* Priorities defined in this main-full.c file. */\r
-#define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
-#define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
-\r
/* The period at which the check timer will expire, in ms, provided no errors\r
have been reported by any of the standard demo tasks. ms are converted to the\r
equivalent in ticks using the portTICK_RATE_MS constant. */\r
/* The period at which the check timer will expire, in ms, if an error has been\r
reported in one of the standard demo tasks. ms are converted to the equivalent\r
in ticks using the portTICK_RATE_MS constant. */\r
-#define mainERROR_CHECK_TIMER_PERIOD_MS ( 500UL / portTICK_RATE_MS )\r
+#define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )\r
\r
-/* The LED will remain on until the button has not been pushed for a full\r
-5000ms. */\r
+/* The LED that is turned on by pressing SW2 remains on until the button has not \r
+been pushed for a full 5000ms. */\r
#define mainBUTTON_LED_TIMER_PERIOD_MS ( 5000UL / portTICK_RATE_MS )\r
\r
/* The period at which the two simple LED flash timers will execute their\r
callback functions. */\r
-#define mainLED1_TIMER_PERIOD_MS ( 200 / portTICK_RATE_MS )\r
-#define mainLED2_TIMER_PERIOD_MS ( 600 / portTICK_RATE_MS )\r
+#define mainLED1_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )\r
+#define mainLED2_TIMER_PERIOD_MS ( 600UL / portTICK_RATE_MS )\r
\r
/* A block time of zero simply means "don't block". */\r
#define mainDONT_BLOCK ( 0UL )\r
\r
/* The vector used by the GPIO port E. Button SW2 is configured to generate\r
-an interrput on this port. */\r
-#define mainGPIO_E_VECTOR ( 107 - 16 )\r
+an interrupt on this port. */\r
+#define mainGPIO_E_VECTOR ( 91 )\r
\r
/*-----------------------------------------------------------*/\r
\r
static void prvCreateDemoSpecificTimers( void );\r
\r
/*\r
- * The LED timer callback function. This does nothing but switch an LED off.\r
+ * The LED/button timer callback function. This does nothing but switch an LED \r
+ * off.\r
*/\r
static void prvButtonLEDTimerCallback( xTimerHandle xTimer );\r
\r
/*\r
* The callback function used by both simple LED flash timers. Both timers use\r
* the same callback, so the function parameter is used to determine which LED\r
- * should be flashed (effectively to determine which timer has expired.\r
+ * should be flashed (effectively to determine which timer has expired).\r
*/\r
static void prvLEDTimerCallback( xTimerHandle xTimer );\r
\r
static void prvCheckTimerCallback( xTimerHandle xTimer );\r
\r
/*\r
- * This is not a 'standard' partest function, so the prototype is not in\r
- * partest.h, and is instead included here.\r
- */\r
-void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue );\r
-\r
-/*\r
- * Contains the implementation of the WEB server.\r
+ * Contains the implementation of the web server.\r
*/\r
extern void vuIP_Task( void *pvParameters );\r
\r
/*-----------------------------------------------------------*/\r
\r
-/* The queue used by both application specific demo tasks defined in this file. */\r
-static xQueueHandle xQueue = NULL;\r
-\r
-/* The LED software timer. This uses prvButtonLEDTimerCallback() as it's callback\r
-function. */\r
-static xTimerHandle xLEDTimer = NULL;\r
+/* The LED/Button software timer. This uses prvButtonLEDTimerCallback() as it's \r
+callback function. */\r
+static xTimerHandle xLEDButtonTimer = NULL;\r
\r
/* The check timer. This uses prvCheckTimerCallback() as its callback\r
function. */\r
static xTimerHandle xCheckTimer = NULL;\r
\r
-/* LED timers - these simply flash LEDs, each using a different frequency. */\r
+/* LED timers - these simply flash LEDs, each using a different frequency. Both\r
+use the same prvLEDTimerCallback() callback function. */\r
static xTimerHandle xLED1Timer = NULL, xLED2Timer = NULL;\r
\r
/* If an error is detected in a standard demo task, then pcStatusMessage will\r
to make debugging easier. */\r
static const char *pcStatusMessage = NULL;\r
\r
-/* Used in the run time stats calculation. */\r
+/* Used in the run time stats calculations. */\r
static unsigned long ulClocksPer10thOfAMilliSecond = 0UL;\r
+\r
/*-----------------------------------------------------------*/\r
\r
void main( void )\r
/* Configure the NVIC, LED outputs and button inputs. */\r
prvSetupHardware();\r
\r
- /* Create the queue. */\r
- xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
-\r
- if( xQueue != NULL )\r
- {\r
- /* Create the timers that are specific to this demo - other timers are\r
- created as part of the standard demo within vStartTimerDemoTask. */\r
- prvCreateDemoSpecificTimers();\r
-\r
- /* Create a lot of 'standard demo' tasks. Over 40 tasks are created in\r
- this demo. For a much simpler demo, select the 'blinky' build\r
- configuration. */\r
- vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
- vCreateBlockTimeTasks();\r
- vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
- vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
- vStartQueuePeekTasks();\r
- vStartRecursiveMutexTasks();\r
- vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
- vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
- vStartCountingSemaphoreTasks();\r
- vStartDynamicPriorityTasks();\r
- \r
- /* The web server task. */\r
- xTaskCreate( vuIP_Task, "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
+ /* Create the timers that are specific to this demo - other timers are\r
+ created as part of the standard demo within vStartTimerDemoTask. */\r
+ prvCreateDemoSpecificTimers();\r
+\r
+ /* Create a lot of 'standard demo' tasks. Nearly 40 tasks are created in\r
+ this demo. For a much simpler demo, select the 'blinky' build\r
+ configuration. */\r
+ vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
+ vCreateBlockTimeTasks();\r
+ vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
+ vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
+ vStartQueuePeekTasks();\r
+ vStartRecursiveMutexTasks();\r
+ vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
+ vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
+ vStartCountingSemaphoreTasks();\r
+ vStartDynamicPriorityTasks();\r
+ \r
+ /* The web server task. */\r
+ xTaskCreate( vuIP_Task, "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
\r
- /* The suicide tasks must be created last, as they need to know how many\r
- tasks were running prior to their creation in order to ascertain whether\r
- or not the correct/expected number of tasks are running at any given\r
- time. */\r
- vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
+ /* The suicide tasks must be created last, as they need to know how many\r
+ tasks were running prior to their creation in order to ascertain whether\r
+ or not the correct/expected number of tasks are running at any given\r
+ time. */\r
+ vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
\r
- /* Start the tasks and timer running. */\r
- vTaskStartScheduler();\r
- }\r
+ /* Start the tasks and timers running. */\r
+ vTaskStartScheduler();\r
\r
/* If all is well, the scheduler will now be running, and the following line\r
will never be reached. If the following line does execute, then there was\r
static long lChangedTimerPeriodAlready = pdFALSE;\r
\r
/* Check the standard demo tasks are running without error. Latch the\r
- latest reported error in the pcStatusMessage character pointer. */\r
+ latest reported error in the pcStatusMessage character pointer. The latched\r
+ string can be viewed using the embedded web server - it is displayed at\r
+ the bottom of the served "task stats" page. */\r
if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
{\r
pcStatusMessage = "Error: GenQueue";\r
lChangedTimerPeriodAlready = pdTRUE;\r
printf( "%s", pcStatusMessage );\r
\r
- /* This call to xTimerChangePeriod() uses a zero block time. Functions\r
- called from inside of a timer callback function must *never* attempt\r
- to block. */\r
+ /* This call to xTimerChangePeriod() uses a zero block time. \r
+ Functions called from inside of a timer callback function must \r
+ *never* attempt to block. */\r
xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
}\r
}\r
vParTestSetLED( mainTIMER_CONTROLLED_LED, pdTRUE );\r
\r
/* This interrupt safe FreeRTOS function can be called from this interrupt\r
- because the interrupt priority is below the\r
- configMAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
- xTimerResetFromISR( xLEDTimer, &xHigherPriorityTaskWoken );\r
+ because the interrupt priority is equal to or below the\r
+ configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
+ xTimerResetFromISR( xLEDButtonTimer, &xHigherPriorityTaskWoken );\r
\r
- /* Clear the interrupt before leaving. This just clears all the interrupts\r
- for simplicity, as only one is actually used in this simple demo anyway. */\r
+ /* Clear the interrupt before leaving. */\r
PORTE_ISFR = 0xFFFFFFFFUL;\r
\r
/* If calling xTimerResetFromISR() caused a task (in this case the timer\r
taskDISABLE_INTERRUPTS();\r
PORTE_PCR26 = PORT_PCR_MUX( 1 ) | PORT_PCR_IRQC( 0xA ) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;\r
enable_irq( mainGPIO_E_VECTOR );\r
+ \r
+ /* The interrupt calls an interrupt safe API function - so its priority must\r
+ be equal to or lower than configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY. */\r
set_irq_priority( mainGPIO_E_VECTOR, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );\r
\r
/* Configure the LED outputs. */\r
static void prvCreateDemoSpecificTimers( void )\r
{\r
/* This function creates the timers, but does not start them. This is\r
- because the standard demo timer test is started after this function is\r
- called. The standard demo timer test will deliberatly fill the timer\r
- command queue - and will fail the test if the command queue already holds\r
- start commands for the timers created here. Instead, the timers created in\r
- this function are started from the idle task, at which time, the timer\r
- service/daemon task will be running, and will have drained the timer command\r
- queue. */\r
+ because the standard demo timer test is started from main(), after this \r
+ function is called. The standard demo timer test will deliberately fill the \r
+ timer command queue - and will fail the test if the command queue already \r
+ holds start commands for the timers created here. Instead, the timers \r
+ created in this function are started from the idle task, at which time, the \r
+ timer service/daemon task will be running, and will have drained the timer \r
+ command queue. */\r
\r
/* Create the software timer that is responsible for turning off the LED\r
if the button is not pushed within 5000ms, as described at the top of\r
this file. */\r
- xLEDTimer = xTimerCreate( ( const signed char * ) "ButtonLEDTimer", /* A text name, purely to help debugging. */\r
+ xLEDButtonTimer = xTimerCreate( ( const signed char * ) "ButtonLEDTimer", /* A text name, purely to help debugging. */\r
( mainBUTTON_LED_TIMER_PERIOD_MS ), /* The timer period, in this case 5000ms (5s). */\r
pdFALSE, /* This is a one shot timer, so xAutoReload is set to pdFALSE. */\r
( void * ) 0, /* The ID is not used, so can be set to anything. */\r
( void ) pxTask;\r
\r
/* Run time stack overflow checking is performed if\r
- configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook\r
+ configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook\r
function is called if a stack overflow is detected. */\r
taskDISABLE_INTERRUPTS();\r
for( ;; );\r
tasks were created in main() (this is part of the test they perform).\r
Therefore, while the check and LED timers can be created in main(), they\r
cannot be started from main(). Once the scheduler has started, the timer\r
- service task will drain the command queue, and now the check and digit\r
- counter timers can be started successfully. */\r
+ service task will drain the command queue, and now the check and LED\r
+ timers can be started successfully. Normally the idle task must not\r
+ call a function that could cause it to block in case there are no tasks\r
+ that are able to run. In this case, however, it is ok as posting to the\r
+ timer command queue guarantees that at least the timer service/daemon\r
+ task will be able to execute. */\r
xTimerStart( xCheckTimer, portMAX_DELAY );\r
xTimerStart( xLED1Timer, portMAX_DELAY );\r
xTimerStart( xLED2Timer, portMAX_DELAY );\r
\r
char *pcGetTaskStatusMessage( void )\r
{\r
- /* Not bothered about a critical section here although technically because\r
- of the task priorities the pointer could change it will be atomic if not\r
- near atomic and its not critical. */\r
+ /* A simple GET function used by a CGI script so it can display the \r
+ execution status at the bottom of the task stats web page served by the\r
+ embedded web server. */\r
if( pcStatusMessage == NULL )\r
{\r
return "All tasks running without error";\r
volatile unsigned long * const pulInterruptCTRLState = ( ( volatile unsigned long *) 0xe000ed04 );\r
const unsigned long ulSysTickPendingBit = 0x04000000UL;\r
\r
- /* NOTE: There are potentially race conditions here. It is ok to keep\r
- things simple, without using any additional timer peripherals. */\r
+ /* NOTE: There are potentially race conditions here. However, it is used\r
+ anyway to keep the examples simple, and to avoid reliance on a separate\r
+ timer peripheral. */\r
\r
\r
/* The SysTick is a down counter. How many clocks have passed since it was\r
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;\r
} \r
\r
- /* Convert the tick count into tenths of a millisecond. */\r
+ /* Convert the tick count into tenths of a millisecond. THIS ASSUMES\r
+ configTICK_RATE_HZ is 1000! */\r
ulReturn = ( ulTickCount * 10UL ) ;\r
\r
/* Add on the number of tenths of a millisecond that have passed since the\r
* one queue, and one timer. It also demonstrates how Cortex-M3 interrupts can\r
* interact with FreeRTOS tasks/timers.\r
*\r
- * This simple demo project runs on the SK-FM3-100PMC evaluation board, which\r
- * is populated with an MB9B500 microcontroller.\r
+ * This simple demo project runs 'stand alone' (without the rest of the tower\r
+ * system) on the TWR-K60N512 tower module, which is populated with a K60N512\r
+ * Cortex-M4 microcontroller.\r
*\r
* The idle hook function:\r
* The idle hook function demonstrates how to query the amount of FreeRTOS heap\r
* in this file. prvQueueReceiveTask() sits in a loop that causes it to\r
* repeatedly attempt to read data from the queue that was created within\r
* main(). When data is received, the task checks the value of the data, and\r
- * if the value equals the expected 100, toggles an LED on the 7 segment\r
- * display. The 'block time' parameter passed to the queue receive function\r
- * specifies that the task should be held in the Blocked state indefinitely to\r
- * wait for data to be available on the queue. The queue receive task will only\r
- * leave the Blocked state when the queue send task writes to the queue. As the\r
- * queue send task writes to the queue every 200 milliseconds, the queue receive\r
- * task leaves the Blocked state every 200 milliseconds, and therefore toggles\r
- * the LED every 200 milliseconds.\r
+ * if the value equals the expected 100, toggles the blue LED. The 'block \r
+ * time' parameter passed to the queue receive function specifies that the task \r
+ * should be held in the Blocked state indefinitely to wait for data to be \r
+ * available on the queue. The queue receive task will only leave the Blocked \r
+ * state when the queue send task writes to the queue. As the queue send task \r
+ * writes to the queue every 200 milliseconds, the queue receive task leaves the \r
+ * Blocked state every 200 milliseconds, and therefore toggles the blue LED \r
+ * every 200 milliseconds.\r
*\r
* The LED Software Timer and the Button Interrupt:\r
* The user button SW2 is configured to generate an interrupt each time it is\r
- * pressed. The interrupt service routine switches an LED in the 7 segment\r
- * display on, and resets the LED software timer. The LED timer has a 5000\r
- * millisecond (5 second) period, and uses a callback function that is defined\r
- * to just turn the LED off again. Therefore, pressing the user button will\r
- * turn the LED on, and the LED will remain on until a full five seconds pass\r
- * without the button being pressed.\r
+ * pressed. The interrupt service routine switches the green LED on, and \r
+ * resets the LED software timer. The LED timer has a 5000 millisecond (5 \r
+ * second) period, and uses a callback function that is defined to just turn the \r
+ * LED off again. Therefore, pressing the user button will turn the LED on, and \r
+ * the LED will remain on until a full five seconds pass without the button \r
+ * being pressed.\r
*/\r
\r
/* Kernel includes. */\r
/* The LED toggle by the queue receive task (blue). */\r
#define mainTASK_CONTROLLED_LED ( 1UL << 10UL )\r
\r
-/* The LED turned on by the button interrupt, and turned off by the LED timer. */\r
+/* The LED turned on by the button interrupt, and turned off by the LED timer\r
+(green). */\r
#define mainTIMER_CONTROLLED_LED ( 1UL << 29UL )\r
\r
/* The vector used by the GPIO port E. Button SW2 is configured to generate\r
-an interrput on this port. */\r
-#define mainGPIO_E_VECTOR ( 107 - 16 )\r
+an interrupt on this port. */\r
+#define mainGPIO_E_VECTOR ( 91 )\r
\r
/* A block time of zero simply means "don't block". */\r
#define mainDONT_BLOCK ( 0UL )\r
static void prvButtonLEDTimerCallback( xTimerHandle xTimer )\r
{\r
/* The timer has expired - so no button pushes have occurred in the last\r
- five seconds - turn the LED off. NOTE - accessing the LED port should use\r
- a critical section because it is accessed from multiple tasks, and the\r
- button interrupt - in this trivial case, for simplicity, the critical\r
- section is omitted. */\r
+ five seconds - turn the LED off. */\r
GPIOA_PSOR = mainTIMER_CONTROLLED_LED;\r
}\r
/*-----------------------------------------------------------*/\r
\r
/* This interrupt safe FreeRTOS function can be called from this interrupt\r
because the interrupt priority is below the\r
- configMAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
+ configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
xTimerResetFromISR( xButtonLEDTimer, &xHigherPriorityTaskWoken );\r
\r
- /* Clear the interrupt before leaving. This just clears all the interrupts\r
- for simplicity, as only one is actually used in this simple demo anyway. */\r
+ /* Clear the interrupt before leaving. */\r
PORTE_ISFR = 0xFFFFFFFFUL;\r
\r
/* If calling xTimerResetFromISR() caused a task (in this case the timer\r
{\r
/* Enable the interrupt on SW1. */\r
PORTE_PCR26 = PORT_PCR_MUX( 1 ) | PORT_PCR_IRQC( 0xA ) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;\r
-\r
enable_irq( mainGPIO_E_VECTOR );\r
+ \r
+ /* The interrupt calls an interrupt safe API function - so its priority must\r
+ be equal to or lower than configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY. */\r
set_irq_priority( mainGPIO_E_VECTOR, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );\r
\r
/* Set PTA10, PTA11, PTA28, and PTA29 (connected to LED's) for GPIO\r
( void ) pxTask;\r
\r
/* Run time stack overflow checking is performed if\r
- configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook\r
+ configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook\r
function is called if a stack overflow is detected. */\r
taskDISABLE_INTERRUPTS();\r
for( ;; );\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vApplicationTickHook( void )\r
-{\r
- /* A tick hook is used by the "Full" build configuration. The Full and\r
- blinky build configurations share a FreeRTOSConfig.h header file, so this\r
- simple build configuration also has to define a tick hook - even though it\r
- does not actually use it for anything. */\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
void vApplicationIdleHook( void )\r
{\r
volatile size_t xFreeHeapSpace;\r
void vMainConfigureTimerForRunTimeStats( void ) {}\r
unsigned long ulMainGetRunTimeCounterValue( void ) { return 0UL; }\r
\r
+/* A tick hook is used by the "Full" build configuration. The Full and blinky \r
+build configurations share a FreeRTOSConfig.h header file, so this simple build \r
+configuration also has to define a tick hook - even though it does not actually \r
+use it for anything. */\r
+void vApplicationTickHook( void ) {}\r
+\r
+\r
+\r
\r
\r
\r