You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
318 lines
12 KiB
C
318 lines
12 KiB
C
/*
|
|
FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 Richard Barry.
|
|
|
|
This file is part of the FreeRTOS.org distribution.
|
|
|
|
FreeRTOS.org is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License (version 2) as published
|
|
by the Free Software Foundation and modified by the FreeRTOS exception.
|
|
**NOTE** The exception to the GPL is included to allow you to distribute a
|
|
combined work that includes FreeRTOS.org without being obliged to provide
|
|
the source code for any proprietary components. Alternative commercial
|
|
license and support terms are also available upon request. See the
|
|
licensing section of http://www.FreeRTOS.org for full details.
|
|
|
|
FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
more details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
|
|
Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
|
|
|
|
|
***************************************************************************
|
|
* *
|
|
* Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
|
|
* *
|
|
* This is a concise, step by step, 'hands on' guide that describes both *
|
|
* general multitasking concepts and FreeRTOS specifics. It presents and *
|
|
* explains numerous examples that are written using the FreeRTOS API. *
|
|
* Full source code for all the examples is provided in an accompanying *
|
|
* .zip file. *
|
|
* *
|
|
***************************************************************************
|
|
|
|
1 tab == 4 spaces!
|
|
|
|
Please ensure to read the configuration and relevant port sections of the
|
|
online documentation.
|
|
|
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
|
contact details.
|
|
|
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
|
critical systems.
|
|
|
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
|
licensing and training services.
|
|
*/
|
|
|
|
/*
|
|
* Creates all the demo application tasks, then starts the scheduler. The WEB
|
|
* documentation provides more details of the standard demo application tasks
|
|
* (which just exist to test the kernel port and provide an example of how to use
|
|
* each FreeRTOS API function).
|
|
*
|
|
* In addition to the standard demo tasks, the following tasks and tests are
|
|
* defined and/or created within this file:
|
|
*
|
|
* "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
|
|
* is permitted to access the display directly. Other tasks wishing to write a
|
|
* message to the LCD send the message on a queue to the LCD task instead of
|
|
* accessing the LCD themselves. The LCD task just blocks on the queue waiting
|
|
* for messages - waking and displaying the messages as they arrive. The use
|
|
* of a gatekeeper in this manner permits both tasks and interrupts to write to
|
|
* the LCD without worrying about mutual exclusion. This is demonstrated by the
|
|
* check hook (see below) which sends messages to the display even though it
|
|
* executes from an interrupt context.
|
|
*
|
|
* "Check" hook - This only executes fully every five seconds from the tick
|
|
* hook. Its main function is to check that all the standard demo tasks are
|
|
* still operational. Should any unexpected behaviour be discovered within a
|
|
* demo task then the tick hook will write an error to the LCD (via the LCD task).
|
|
* If all the demo tasks are executing with their expected behaviour then the
|
|
* check task writes PASS to the LCD (again via the LCD task), as described above.
|
|
*
|
|
*/
|
|
|
|
/* Scheduler includes. */
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "queue.h"
|
|
#include "semphr.h"
|
|
|
|
/* Demo app includes. */
|
|
#include "BlockQ.h"
|
|
#include "integer.h"
|
|
#include "blocktim.h"
|
|
#include "flash.h"
|
|
#include "partest.h"
|
|
#include "semtest.h"
|
|
#include "PollQ.h"
|
|
#include "lcd_message.h"
|
|
#include "GenQTest.h"
|
|
#include "QPeek.h"
|
|
#include "recmutex.h"
|
|
#include "flash.h"
|
|
#include "comtest2.h"
|
|
|
|
/* Atmel library includes. */
|
|
#include <board.h>
|
|
#include <lcd/color.h>
|
|
#include <lcd/lcdd.h>
|
|
#include <lcd/draw.h>
|
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/* The time between cycles of the 'check' functionality (defined within the
|
|
tick hook). */
|
|
#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
|
|
|
|
/* The LCD task uses the sprintf function so requires a little more stack too. */
|
|
#define mainLCD_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
|
|
|
|
/* Task priorities. */
|
|
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
|
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
|
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
|
#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
|
#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
|
#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
|
|
#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
|
|
|
|
/* The maximum number of message that can be waiting for display at any one
|
|
time. */
|
|
#define mainLCD_QUEUE_SIZE ( 3 )
|
|
|
|
/* Constants used by the comtest tasks. There isn't a spare LED so an invalid
|
|
LED is specified. */
|
|
#define mainBAUD_RATE ( 115200 )
|
|
#define mainCOM_TEST_LED ( 10 )
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/*
|
|
* Configure the hardware for the demo.
|
|
*/
|
|
static void prvSetupHardware( void );
|
|
|
|
/*
|
|
* The LCD gatekeeper task. Tasks wishing to write to the LCD do not access
|
|
* the LCD directly, but instead send the message to the LCD gatekeeper task.
|
|
*/
|
|
static void prvLCDTask( void *pvParameters );
|
|
|
|
/*
|
|
* Hook functions that can get called by the kernel. The 'check' functionality
|
|
* is implemented within the tick hook.
|
|
*/
|
|
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );
|
|
|
|
/*
|
|
* The tick hook function as described in the comments at the top of this file.
|
|
* The tick hook is used to monitor all the standard demo tasks to look for
|
|
* errors. The tick hook is also used to demonstrate how the LCD gatekeeper
|
|
* task can be used to allow interrupts to write to the LCD.
|
|
*/
|
|
void vApplicationTickHook( void );
|
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/* The queue used to send messages to the LCD task. */
|
|
static xQueueHandle xLCDQueue;
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
int main( void )
|
|
{
|
|
/* Prepare the hardware. */
|
|
prvSetupHardware();
|
|
|
|
/* Create the queue used by the LCD task. Messages for display on the LCD
|
|
are received via this queue. */
|
|
xLCDQueue = xQueueCreate( mainLCD_QUEUE_SIZE, sizeof( xLCDMessage ) );
|
|
|
|
/* Start the standard demo tasks. These do nothing other than test the
|
|
port and provide some APU usage examples. */
|
|
vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
|
|
vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
|
|
vStartRecursiveMutexTasks();
|
|
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
|
|
vCreateBlockTimeTasks();
|
|
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
|
|
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
|
|
vStartQueuePeekTasks();
|
|
vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
|
|
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainBAUD_RATE, mainCOM_TEST_LED );
|
|
|
|
/* Start the tasks defined within this file/specific to this demo. */
|
|
xTaskCreate( prvLCDTask, ( signed char * ) "LCD", mainLCD_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
|
|
|
/* Start the scheduler. */
|
|
vTaskStartScheduler();
|
|
|
|
/* Will only get here if there was insufficient memory to create the idle
|
|
task. */
|
|
return 0;
|
|
}
|
|
/*-----------------------------------------------------------*/
|
|
|
|
void prvSetupHardware( void )
|
|
{
|
|
/* Initialise the port used for the LED outputs. */
|
|
vParTestInitialise();
|
|
}
|
|
/*-----------------------------------------------------------*/
|
|
|
|
void vApplicationTickHook( void )
|
|
{
|
|
static xLCDMessage xMessage = { "PASS" };
|
|
static unsigned portLONG ulTicksSinceLastDisplay = 0;
|
|
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
|
|
|
|
/* Called from every tick interrupt. Have enough ticks passed to make it
|
|
time to perform our health status check again? */
|
|
ulTicksSinceLastDisplay++;
|
|
if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
|
|
{
|
|
ulTicksSinceLastDisplay = 0;
|
|
|
|
/* Has an error been found in any task? */
|
|
if( xAreGenericQueueTasksStillRunning() != pdTRUE )
|
|
{
|
|
xMessage.pcMessage = "ERROR IN GEN Q";
|
|
}
|
|
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
|
|
{
|
|
xMessage.pcMessage = "ERROR IN MATH";
|
|
}
|
|
else if( xAreBlockingQueuesStillRunning() != pdTRUE )
|
|
{
|
|
xMessage.pcMessage = "ERROR IN BLOCK Q";
|
|
}
|
|
else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
|
|
{
|
|
xMessage.pcMessage = "ERROR IN BLOCK TIME";
|
|
}
|
|
else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
|
|
{
|
|
xMessage.pcMessage = "ERROR IN SEMAPHORE";
|
|
}
|
|
else if( xArePollingQueuesStillRunning() != pdTRUE )
|
|
{
|
|
xMessage.pcMessage = "ERROR IN POLL Q";
|
|
}
|
|
else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
|
|
{
|
|
xMessage.pcMessage = "ERROR IN PEEK Q";
|
|
}
|
|
else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
|
|
{
|
|
xMessage.pcMessage = "ERROR IN REC MUTEX";
|
|
}
|
|
else if( xAreComTestTasksStillRunning() != pdTRUE )
|
|
{
|
|
xMessage.pcMessage = "ERROR IN COMTEST";
|
|
}
|
|
|
|
/* Send the message to the LCD gatekeeper for display. */
|
|
xHigherPriorityTaskWoken = pdFALSE;
|
|
xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
|
|
}
|
|
}
|
|
/*-----------------------------------------------------------*/
|
|
|
|
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
|
|
{
|
|
( void ) pxTask;
|
|
( void ) pcTaskName;
|
|
|
|
/* If the parameters have been corrupted then inspect pxCurrentTCB to
|
|
identify which task has overflowed its stack. */
|
|
for( ;; );
|
|
}
|
|
/*-----------------------------------------------------------*/
|
|
|
|
static void prvLCDTask( void *pvParameters )
|
|
{
|
|
xLCDMessage xMessage;
|
|
unsigned long ulY = 0;
|
|
const unsigned long ulX = 5;
|
|
const unsigned long ulMaxY = 250, ulYIncrement = 22, ulWidth = 250, ulHeight = 20;;
|
|
|
|
/* Initialize LCD. */
|
|
LCDD_Initialize();
|
|
LCDD_Start();
|
|
LCDD_Fill( ( void * ) BOARD_LCD_BASE, COLOR_WHITE );
|
|
LCDD_DrawString( ( void * ) BOARD_LCD_BASE, 1, ulY + 3, " www.FreeRTOS.org", COLOR_BLACK );
|
|
|
|
for( ;; )
|
|
{
|
|
/* Wait for a message from the check function (which is executed in
|
|
the tick hook). */
|
|
xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY );
|
|
|
|
/* Clear the space where the old message was. */
|
|
LCDD_DrawRectangle( ( void * ) BOARD_LCD_BASE, 0, ulY, ulWidth, ulHeight, COLOR_WHITE );
|
|
|
|
/* Increment to the next drawing position. */
|
|
ulY += ulYIncrement;
|
|
|
|
/* Have the Y position moved past the end of the LCD? */
|
|
if( ulY >= ulMaxY )
|
|
{
|
|
ulY = 0;
|
|
}
|
|
|
|
/* Draw a new rectangle, in which the message will be written. */
|
|
LCDD_DrawRectangle( ( void * ) BOARD_LCD_BASE, 0, ulY, ulWidth, ulHeight, COLOR_GREEN );
|
|
|
|
/* Write the message. */
|
|
LCDD_DrawString( ( void * ) BOARD_LCD_BASE, ulX, ulY + 3, xMessage.pcMessage, COLOR_BLACK );
|
|
}
|
|
}
|