Add FreeRTOS-Plus directory.

This commit is contained in:
Richard Barry 2012-08-11 21:34:11 +00:00
parent 7bd5f21ad5
commit f508a5f653
6798 changed files with 134949 additions and 19 deletions

View file

@ -0,0 +1,115 @@
/*
FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
***************************************************************************
* *
* FreeRTOS tutorial books are available in pdf and paperback. *
* Complete, revised, and edited pdf reference manuals are also *
* available. *
* *
* Purchasing FreeRTOS documentation will not only help you, by *
* ensuring you get running as quickly as possible and with an *
* in-depth knowledge of how to use FreeRTOS, it will also help *
* the FreeRTOS project to continue with its mission of providing *
* professional grade, cross platform, de facto standard solutions *
* for microcontrollers - completely free of charge! *
* *
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
* *
* Thank you for using FreeRTOS, and thank you for your support! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS 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 modification to the GPL is included to allow you to
distribute a combined work that includes FreeRTOS without being obliged to
provide the source code for proprietary components outside of the FreeRTOS
kernel. FreeRTOS 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 and the FreeRTOS license exception along with FreeRTOS; if not it
can be viewed here: http://www.freertos.org/a00114.html and also obtained
by writing to Richard Barry, contact details for whom are available on the
FreeRTOS WEB site.
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong? *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, training, latest information,
license and contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool.
Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
the code with commercial support, indemnification, and middleware, under
the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
provide a safety engineered and independently SIL3 certified version under
the SafeRTOS brand: http://www.SafeRTOS.com.
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <p33FJ256GP710.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configCPU_CLOCK_HZ ( ( unsigned long ) 25000000 ) /* Fosc / 2 */
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 4 )
#define configMINIMAL_STACK_SIZE ( 105 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) 5120 )
#define configMAX_TASK_NAME_LEN ( 4 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 1
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 0
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define configKERNEL_INTERRUPT_PRIORITY 0x01
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,147 @@
/*
FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
***************************************************************************
* *
* FreeRTOS tutorial books are available in pdf and paperback. *
* Complete, revised, and edited pdf reference manuals are also *
* available. *
* *
* Purchasing FreeRTOS documentation will not only help you, by *
* ensuring you get running as quickly as possible and with an *
* in-depth knowledge of how to use FreeRTOS, it will also help *
* the FreeRTOS project to continue with its mission of providing *
* professional grade, cross platform, de facto standard solutions *
* for microcontrollers - completely free of charge! *
* *
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
* *
* Thank you for using FreeRTOS, and thank you for your support! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS 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 modification to the GPL is included to allow you to
distribute a combined work that includes FreeRTOS without being obliged to
provide the source code for proprietary components outside of the FreeRTOS
kernel. FreeRTOS 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 and the FreeRTOS license exception along with FreeRTOS; if not it
can be viewed here: http://www.freertos.org/a00114.html and also obtained
by writing to Richard Barry, contact details for whom are available on the
FreeRTOS WEB site.
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong? *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, training, latest information,
license and contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool.
Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
the code with commercial support, indemnification, and middleware, under
the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
provide a safety engineered and independently SIL3 certified version under
the SafeRTOS brand: http://www.SafeRTOS.com.
*/
/* Scheduler includes. */
#include "FreeRTOS.h"
/* Demo app includes. */
#include "partest.h"
#define ptOUTPUT 0
#define ptALL_OFF 0
unsigned portBASE_TYPE uxOutput;
/*-----------------------------------------------------------
* Simple parallel port IO routines.
*-----------------------------------------------------------*/
void vParTestInitialise( void )
{
/* The explorer 16 board has LED's on port A. All bits are set as output
so PORTA is read-modified-written directly. Two pins have change
notification pullups that need disabling. */
CNPU2bits.CN22PUE = 0;
CNPU2bits.CN23PUE = 0;
TRISA = ptOUTPUT;
PORTA = ptALL_OFF;
uxOutput = ptALL_OFF;
}
/*-----------------------------------------------------------*/
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
{
unsigned portBASE_TYPE uxLEDBit;
/* Which port A bit is being modified? */
uxLEDBit = 1 << uxLED;
if( xValue )
{
/* Turn the LED on. */
portENTER_CRITICAL();
{
uxOutput |= uxLEDBit;
PORTA = uxOutput;
}
portEXIT_CRITICAL();
}
else
{
/* Turn the LED off. */
portENTER_CRITICAL();
{
uxOutput &= ~uxLEDBit;
PORTA = uxOutput;
}
portEXIT_CRITICAL();
}
}
/*-----------------------------------------------------------*/
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{
unsigned portBASE_TYPE uxLEDBit;
uxLEDBit = 1 << uxLED;
portENTER_CRITICAL();
{
/* If the LED is already on - turn it off. If the LED is already
off, turn it on. */
if( uxOutput & uxLEDBit )
{
uxOutput &= ~uxLEDBit;
PORTA = uxOutput;
}
else
{
uxOutput |= uxLEDBit;
PORTA = uxOutput;
}
}
portEXIT_CRITICAL();
}

View file

@ -0,0 +1,3 @@
[Header]
MagicCookie={0b13fe8c-dfe0-40eb-8900-6712719559a7}
Version=1.0

Binary file not shown.

View file

@ -0,0 +1,139 @@
[HEADER]
magic_cookie={66E99B07-E706-4689-9E80-9B2582898A13}
file_version=1.0
device=dsPIC33FJ256GP710
[PATH_INFO]
BuildDirPolicy=BuildDirIsSourceDir
dir_src=
dir_bin=
dir_tmp=
dir_sin=
dir_inc=.;.\include;..\include;..\..\include;..\..\..\include;..\..\Source\include;..\..\..\Source\include;..\Demo\dsPIC_MPLAB;..\..\..\Demo\dsPIC_MPLAB;..\..\..\..\Demo\dsPIC_MPLAB;.\FileSystem;..\Common\include;..\..\Common\include
dir_lib=
dir_lkr=
[CAT_FILTERS]
filter_src=*.s;*.c
filter_inc=*.h;*.inc
filter_obj=*.o
filter_lib=*.a
filter_lkr=*.gld
[CAT_SUBFOLDERS]
subfolder_src=FreeRTOS Source;Standard Demo Source
subfolder_inc=
subfolder_obj=
subfolder_lib=
subfolder_lkr=
[FILE_SUBFOLDERS]
file_000=.
file_001=.
file_002=.
file_003=.
file_004=.
file_005=Standard Demo Source
file_006=Standard Demo Source
file_007=Standard Demo Source
file_008=Standard Demo Source
file_009=FreeRTOS Source
file_010=FreeRTOS Source
file_011=Standard Demo Source
file_012=FreeRTOS Source
file_013=FreeRTOS Source
file_014=FreeRTOS Source
file_015=FreeRTOS Source
file_016=FreeRTOS Source
file_017=.
file_018=.
file_019=.
file_020=.
file_021=.
file_022=.
[GENERATED_FILES]
file_000=no
file_001=no
file_002=no
file_003=no
file_004=no
file_005=no
file_006=no
file_007=no
file_008=no
file_009=no
file_010=no
file_011=no
file_012=no
file_013=no
file_014=no
file_015=no
file_016=no
file_017=no
file_018=no
file_019=no
file_020=no
file_021=no
file_022=no
[OTHER_FILES]
file_000=no
file_001=no
file_002=no
file_003=no
file_004=no
file_005=no
file_006=no
file_007=no
file_008=no
file_009=no
file_010=no
file_011=no
file_012=no
file_013=no
file_014=no
file_015=no
file_016=no
file_017=no
file_018=no
file_019=no
file_020=no
file_021=no
file_022=no
[FILE_INFO]
file_000=main.c
file_001=ParTest\ParTest.c
file_002=serial\serial.c
file_003=timertest.c
file_004=lcd.c
file_005=..\Common\Minimal\BlockQ.c
file_006=..\Common\Minimal\blocktim.c
file_007=..\Common\Minimal\comtest.c
file_008=..\Common\Minimal\crflash.c
file_009=..\..\source\croutine.c
file_010=..\..\source\portable\MemMang\heap_1.c
file_011=..\Common\Minimal\integer.c
file_012=..\..\source\list.c
file_013=..\..\source\portable\MPLAB\PIC24_dsPIC\port.c
file_014=..\..\Source\portable\MPLAB\PIC24_dsPIC\portasm_dsPIC.S
file_015=..\..\source\queue.c
file_016=..\..\source\tasks.c
file_017=..\..\source\include\semphr.h
file_018=..\..\source\include\task.h
file_019=..\..\source\include\croutine.h
file_020=..\..\source\include\queue.h
file_021=FreeRTOSConfig.h
file_022=p33FJ256GP710.gld
[SUITE_INFO]
suite_guid={479DDE59-4D56-455E-855E-FFF59A3DB57E}
suite_state=
[TOOL_SETTINGS]
TS{7D9C6ECE-785D-44CB-BA22-17BF2E119622}=-g
TS{25AC22BD-2378-4FDB-BFB6-7345A15512D3}=-fno-omit-frame-pointer -g -Wall -DMPLAB_DSPIC_PORT -O2 -fno-schedule-insns -fno-schedule-insns2
TS{25AC22BD-2378-4FDB-BFB6-7345A15512D3}_alt=yes
TS{7DAC9A1D-4C45-45D6-B25A-D117C74E8F5A}=--heap=0 --defsym=__ICD2RAM=1 -o"$(BINDIR_)$(TARGETBASE).$(TARGETSUFFIX)"
TS{509E5861-1E2A-483B-8B6B-CA8DB7F2DD78}=
[INSTRUMENTED_TRACE]
enable=0
transport=0
format=0
[CUSTOM_BUILD]
Pre-Build=
Pre-BuildEnabled=1
Post-Build=
Post-BuildEnabled=1

View file

@ -0,0 +1,7 @@
[Header]
MagicCookie={0b13fe8c-dfe0-40eb-8900-6712719559a7}
Version=1.0
[TOOL_LOC_STAMPS]
tool_loc{DE18EB1A-B46B-486B-B96F-A811A635DFAC}=C:\devtools\Microchip\mplabc30\v3.25\bin\pic30-as.exe
tool_loc{069BD372-6CA0-40D4-BF2F-5DC806D05083}=C:\devtools\Microchip\mplabc30\v3.25\bin\pic30-gcc.exe
tool_loc{433C3D55-811D-409D-A6BF-159CF9355B42}=C:\devtools\Microchip\mplabc30\v3.25\bin\pic30-ld.exe

View file

@ -0,0 +1,363 @@
/*
FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
***************************************************************************
* *
* FreeRTOS tutorial books are available in pdf and paperback. *
* Complete, revised, and edited pdf reference manuals are also *
* available. *
* *
* Purchasing FreeRTOS documentation will not only help you, by *
* ensuring you get running as quickly as possible and with an *
* in-depth knowledge of how to use FreeRTOS, it will also help *
* the FreeRTOS project to continue with its mission of providing *
* professional grade, cross platform, de facto standard solutions *
* for microcontrollers - completely free of charge! *
* *
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
* *
* Thank you for using FreeRTOS, and thank you for your support! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS 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 modification to the GPL is included to allow you to
distribute a combined work that includes FreeRTOS without being obliged to
provide the source code for proprietary components outside of the FreeRTOS
kernel. FreeRTOS 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 and the FreeRTOS license exception along with FreeRTOS; if not it
can be viewed here: http://www.freertos.org/a00114.html and also obtained
by writing to Richard Barry, contact details for whom are available on the
FreeRTOS WEB site.
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong? *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, training, latest information,
license and contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool.
Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
the code with commercial support, indemnification, and middleware, under
the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
provide a safety engineered and independently SIL3 certified version under
the SafeRTOS brand: http://www.SafeRTOS.com.
*/
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
/* Demo includes. */
#include "lcd.h"
/*
* The LCD is written to by more than one task so is controlled by this
* 'gatekeeper' task. This is the only task that is actually permitted to
* access the LCD directly. Other tasks wanting to display a message send
* the message to the gatekeeper.
*/
static void vLCDTask( void *pvParameters );
/*
* Setup the peripherals required to communicate with the LCD.
*/
static void prvSetupLCD( void );
/*
* Move to the first (0) or second (1) row of the LCD.
*/
static void prvLCDGotoRow( unsigned portSHORT usRow );
/*
* Write a string of text to the LCD.
*/
static void prvLCDPutString( portCHAR *pcString );
/*
* Clear the LCD.
*/
static void prvLCDClear( void );
/*-----------------------------------------------------------*/
/* Brief delay to permit the LCD to catch up with commands. */
#define lcdVERY_SHORT_DELAY ( 1 )
#define lcdSHORT_DELAY ( 4 / portTICK_RATE_MS )
#define lcdLONG_DELAY ( 15 / portTICK_RATE_MS )
/* LCD commands. */
#define lcdCLEAR ( 0x01 )
#define lcdHOME ( 0x02 )
#define lcdLINE2 ( 0xc0 )
/* SFR that seems to be missing from the standard header files. */
#define PMAEN *( ( unsigned short * ) 0x60c )
/* LCD R/W signal. */
#define lcdRW LATDbits.LATD5
/* LCD lcdRS signal. */
#define lcdRS LATBbits.LATB15
/* LCD lcdE signal . */
#define lcdE LATDbits.LATD4
/* Control signal pin direction. */
#define RW_TRIS TRISDbits.TRISD5
#define RS_TRIS TRISBbits.TRISB15
#define E_TRIS TRISDbits.TRISD4
/* Port for LCD data */
#define lcdDATA LATE
#define lcdDATAPORT PORTE
/* I/O setup for data Port. */
#define TRISDATA TRISE
/* The length of the queue used to send messages to the LCD gatekeeper task. */
#define lcdQUEUE_SIZE 3
/*-----------------------------------------------------------*/
/* The queue used to send messages to the LCD task. */
xQueueHandle xLCDQueue;
static void prvLCDCommand( portCHAR cCommand );
static void prvLCDData( portCHAR cChar );
/*-----------------------------------------------------------*/
xQueueHandle xStartLCDTask( void )
{
/* Create the queue used by the LCD task. Messages for display on the LCD
are received via this queue. */
xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );
/* Start the task that will write to the LCD. The LCD hardware is
initialised from within the task itself so delays can be used. */
xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
return xLCDQueue;
}
/*-----------------------------------------------------------*/
static void prvLCDGotoRow( unsigned portSHORT usRow )
{
if( usRow == 0 )
{
prvLCDCommand( lcdHOME );
}
else
{
prvLCDCommand( lcdLINE2 );
}
}
/*-----------------------------------------------------------*/
static void prvLCDCommand( portCHAR cCommand )
{
/* Prepare RD0 - RD7. */
lcdDATA &= 0xFF00;
/* Command byte to lcd. */
lcdDATA |= cCommand;
/* Ensure lcdRW is 0. */
lcdRW = 0;
lcdRS = 0;
/* Toggle lcdE line. */
lcdE = 1;
vTaskDelay( lcdVERY_SHORT_DELAY );
lcdE = 0;
vTaskDelay( lcdSHORT_DELAY );
}
/*-----------------------------------------------------------*/
static void prvLCDData( portCHAR cChar )
{
/* ensure lcdRW is 0. */
lcdRW = 0;
/* Assert register select to 1. */
lcdRS = 1;
/* Prepare RD0 - RD7. */
lcdDATA &= 0xFF00;
/* Data byte to lcd. */
lcdDATA |= cChar;
lcdE = 1;
Nop();
Nop();
Nop();
/* Toggle lcdE signal. */
lcdE = 0;
/* Negate register select to 0. */
lcdRS = 0;
vTaskDelay( lcdVERY_SHORT_DELAY );
}
/*-----------------------------------------------------------*/
static void prvLCDPutString( portCHAR *pcString )
{
/* Write out each character with appropriate delay between each. */
while( *pcString )
{
prvLCDData( *pcString );
pcString++;
vTaskDelay( lcdSHORT_DELAY );
}
}
/*-----------------------------------------------------------*/
static void prvLCDClear( void )
{
prvLCDCommand( lcdCLEAR );
}
/*-----------------------------------------------------------*/
static void prvSetupLCD( void )
{
/* Wait for proper power up. */
vTaskDelay( lcdLONG_DELAY );
/* Set initial states for the data and control pins */
LATE &= 0xFF00;
/* R/W state set low. */
lcdRW = 0;
/* lcdRS state set low. */
lcdRS = 0;
/* lcdE state set low. */
lcdE = 0;
/* Set data and control pins to outputs */
TRISE &= 0xFF00;
/* lcdRW pin set as output. */
RW_TRIS = 0;
/* lcdRS pin set as output. */
RS_TRIS = 0;
/* lcdE pin set as output. */
E_TRIS = 0;
/* 1st LCD initialization sequence */
lcdDATA &= 0xFF00;
lcdDATA |= 0x0038;
lcdE = 1;
Nop();
Nop();
Nop();
/* Toggle lcdE signal. */
lcdE = 0;
vTaskDelay( lcdSHORT_DELAY );
vTaskDelay( lcdSHORT_DELAY );
vTaskDelay( lcdSHORT_DELAY );
/* 2nd LCD initialization sequence */
lcdDATA &= 0xFF00;
lcdDATA |= 0x0038;
lcdE = 1;
Nop();
Nop();
Nop();
/* Toggle lcdE signal. */
lcdE = 0;
vTaskDelay( lcdSHORT_DELAY );
/* 3rd LCD initialization sequence */
lcdDATA &= 0xFF00;
lcdDATA |= 0x0038;
lcdE = 1;
Nop();
Nop();
Nop();
/* Toggle lcdE signal. */
lcdE = 0;
vTaskDelay( lcdSHORT_DELAY );
/* Function set. */
prvLCDCommand( 0x38 );
/* Display on/off control, cursor blink off (0x0C). */
prvLCDCommand( 0x0C );
/* Entry mode set (0x06). */
prvLCDCommand( 0x06 );
prvLCDCommand( lcdCLEAR );
}
/*-----------------------------------------------------------*/
static void vLCDTask( void *pvParameters )
{
xLCDMessage xMessage;
unsigned portSHORT usRow = 0;
/* Initialise the hardware. This uses delays so must not be called prior
to the scheduler being started. */
prvSetupLCD();
/* Welcome message. */
prvLCDPutString( "www.FreeRTOS.org" );
for( ;; )
{
/* Wait for a message to arrive that requires displaying. */
while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
/* Clear the current display value. */
prvLCDClear();
/* Switch rows each time so we can see that the display is still being
updated. */
prvLCDGotoRow( usRow & 0x01 );
usRow++;
prvLCDPutString( xMessage.pcMessage );
/* Delay the requested amount of time to ensure the text just written
to the LCD is not overwritten. */
vTaskDelay( xMessage.xMinDisplayTime );
}
}

View file

@ -0,0 +1,88 @@
/*
FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
***************************************************************************
* *
* FreeRTOS tutorial books are available in pdf and paperback. *
* Complete, revised, and edited pdf reference manuals are also *
* available. *
* *
* Purchasing FreeRTOS documentation will not only help you, by *
* ensuring you get running as quickly as possible and with an *
* in-depth knowledge of how to use FreeRTOS, it will also help *
* the FreeRTOS project to continue with its mission of providing *
* professional grade, cross platform, de facto standard solutions *
* for microcontrollers - completely free of charge! *
* *
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
* *
* Thank you for using FreeRTOS, and thank you for your support! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS 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 modification to the GPL is included to allow you to
distribute a combined work that includes FreeRTOS without being obliged to
provide the source code for proprietary components outside of the FreeRTOS
kernel. FreeRTOS 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 and the FreeRTOS license exception along with FreeRTOS; if not it
can be viewed here: http://www.freertos.org/a00114.html and also obtained
by writing to Richard Barry, contact details for whom are available on the
FreeRTOS WEB site.
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong? *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, training, latest information,
license and contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool.
Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
the code with commercial support, indemnification, and middleware, under
the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
provide a safety engineered and independently SIL3 certified version under
the SafeRTOS brand: http://www.SafeRTOS.com.
*/
#ifndef LCD_INC_H
#define LCD_INC_H
/* Create the task that will control the LCD. Returned is a handle to the queue
on which messages to get written to the LCD should be written. */
xQueueHandle xStartLCDTask( void );
typedef struct
{
/* The minimum amount of time the message should remain on the LCD without
being overwritten. */
portTickType xMinDisplayTime;
/* A pointer to the string to be displayed. */
char *pcMessage;
} xLCDMessage;
#endif /* LCD_INC_H */

View file

@ -0,0 +1,286 @@
/*
FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
***************************************************************************
* *
* FreeRTOS tutorial books are available in pdf and paperback. *
* Complete, revised, and edited pdf reference manuals are also *
* available. *
* *
* Purchasing FreeRTOS documentation will not only help you, by *
* ensuring you get running as quickly as possible and with an *
* in-depth knowledge of how to use FreeRTOS, it will also help *
* the FreeRTOS project to continue with its mission of providing *
* professional grade, cross platform, de facto standard solutions *
* for microcontrollers - completely free of charge! *
* *
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
* *
* Thank you for using FreeRTOS, and thank you for your support! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS 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 modification to the GPL is included to allow you to
distribute a combined work that includes FreeRTOS without being obliged to
provide the source code for proprietary components outside of the FreeRTOS
kernel. FreeRTOS 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 and the FreeRTOS license exception along with FreeRTOS; if not it
can be viewed here: http://www.freertos.org/a00114.html and also obtained
by writing to Richard Barry, contact details for whom are available on the
FreeRTOS WEB site.
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong? *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, training, latest information,
license and contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool.
Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
the code with commercial support, indemnification, and middleware, under
the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
provide a safety engineered and independently SIL3 certified version under
the SafeRTOS brand: http://www.SafeRTOS.com.
*/
/*
* Creates all the demo application tasks, then starts the scheduler. The WEB
* documentation provides more details of the standard demo application tasks.
* In addition to the standard demo tasks, the following tasks and tests are
* defined and/or created within this file:
*
* "Fast Interrupt Test" - A high frequency periodic interrupt is generated
* using a free running timer to demonstrate the use of the
* configKERNEL_INTERRUPT_PRIORITY configuration constant. The interrupt
* service routine measures the number of processor clocks that occur between
* each interrupt - and in so doing measures the jitter in the interrupt
* timing. The maximum measured jitter time is latched in the usMaxJitter
* variable, and displayed on the LCD by the 'Check' as described below.
* The fast interrupt is configured and handled in the timer_test.c source
* file.
*
* "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
* is permitted to access the LCD 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 LCD
* task is defined in lcd.c.
*
* "Check" task - This only executes every three seconds but has the highest
* priority so is guaranteed to get processor time. Its main function is to
* check that all the standard demo tasks are still operational. Should any
* unexpected behaviour within a demo task be discovered the 'check' task will
* write "FAIL #n" to the LCD (via the LCD task). If all the demo tasks are
* executing with their expected behaviour then the check task writes the max
* jitter time to the LCD (again via the LCD task), as described above.
*/
/* Standard includes. */
#include <stdio.h>
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "croutine.h"
/* Demo application includes. */
#include "BlockQ.h"
#include "crflash.h"
#include "blocktim.h"
#include "integer.h"
#include "comtest2.h"
#include "partest.h"
#include "lcd.h"
#include "timertest.h"
/* Demo task priorities. */
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define mainCOM_TEST_PRIORITY ( 2 )
/* The check task may require a bit more stack as it calls sprintf(). */
#define mainCHECK_TAKS_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
/* The execution period of the check task. */
#define mainCHECK_TASK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
/* The number of flash co-routines to create. */
#define mainNUM_FLASH_COROUTINES ( 5 )
/* Baud rate used by the comtest tasks. */
#define mainCOM_TEST_BAUD_RATE ( 19200 )
/* The LED used by the comtest tasks. mainCOM_TEST_LED + 1 is also used.
See the comtest.c file for more information. */
#define mainCOM_TEST_LED ( 6 )
/* The frequency at which the "fast interrupt test" interrupt will occur. */
#define mainTEST_INTERRUPT_FREQUENCY ( 20000 )
/* The number of processor clocks we expect to occur between each "fast
interrupt test" interrupt. */
#define mainEXPECTED_CLOCKS_BETWEEN_INTERRUPTS ( configCPU_CLOCK_HZ / mainTEST_INTERRUPT_FREQUENCY )
/* The number of nano seconds between each processor clock. */
#define mainNS_PER_CLOCK ( ( unsigned short ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
/* Dimension the buffer used to hold the value of the maximum jitter time when
it is converted to a string. */
#define mainMAX_STRING_LENGTH ( 20 )
/*-----------------------------------------------------------*/
/*
* The check task as described at the top of this file.
*/
static void vCheckTask( void *pvParameters );
/*
* Setup the processor ready for the demo.
*/
static void prvSetupHardware( void );
/*-----------------------------------------------------------*/
/* The queue used to send messages to the LCD task. */
static xQueueHandle xLCDQueue;
/*-----------------------------------------------------------*/
/*
* Create the demo tasks then start the scheduler.
*/
int main( void )
{
/* Configure any hardware required for this demo. */
prvSetupHardware();
/* Create the standard demo tasks. */
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
vStartIntegerMathTasks( tskIDLE_PRIORITY );
vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
vCreateBlockTimeTasks();
/* Create the test tasks defined within this file. */
xTaskCreate( vCheckTask, ( signed char * ) "Check", mainCHECK_TAKS_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
/* Start the task that will control the LCD. This returns the handle
to the queue used to write text out to the task. */
xLCDQueue = xStartLCDTask();
/* Start the high frequency interrupt test. */
vSetupTimerTest( mainTEST_INTERRUPT_FREQUENCY );
/* Finally start the scheduler. */
vTaskStartScheduler();
/* Will only reach here if there is insufficient heap available to start
the scheduler. */
return 0;
}
/*-----------------------------------------------------------*/
static void prvSetupHardware( void )
{
vParTestInitialise();
}
/*-----------------------------------------------------------*/
static void vCheckTask( void *pvParameters )
{
/* Used to wake the task at the correct frequency. */
portTickType xLastExecutionTime;
/* The maximum jitter time measured by the fast interrupt test. */
extern unsigned short usMaxJitter ;
/* Buffer into which the maximum jitter time is written as a string. */
static char cStringBuffer[ mainMAX_STRING_LENGTH ];
/* The message that is sent on the queue to the LCD task. The first
parameter is the minimum time (in ticks) that the message should be
left on the LCD without being overwritten. The second parameter is a pointer
to the message to display itself. */
xLCDMessage xMessage = { 0, cStringBuffer };
/* Set to pdTRUE should an error be detected in any of the standard demo tasks. */
unsigned short usErrorDetected = pdFALSE;
/* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
works correctly. */
xLastExecutionTime = xTaskGetTickCount();
for( ;; )
{
/* Wait until it is time for the next cycle. */
vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_PERIOD );
/* Has an error been found in any of the standard demo tasks? */
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
{
usErrorDetected = pdTRUE;
sprintf( cStringBuffer, "FAIL #1" );
}
if( xAreComTestTasksStillRunning() != pdTRUE )
{
usErrorDetected = pdTRUE;
sprintf( cStringBuffer, "FAIL #2" );
}
if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
{
usErrorDetected = pdTRUE;
sprintf( cStringBuffer, "FAIL #3" );
}
if( xAreBlockingQueuesStillRunning() != pdTRUE )
{
usErrorDetected = pdTRUE;
sprintf( cStringBuffer, "FAIL #4" );
}
if( usErrorDetected == pdFALSE )
{
/* No errors have been discovered, so display the maximum jitter
timer discovered by the "fast interrupt test". */
sprintf( cStringBuffer, "%dns max jitter", ( short ) ( usMaxJitter - mainEXPECTED_CLOCKS_BETWEEN_INTERRUPTS ) * mainNS_PER_CLOCK );
}
/* Send the message to the LCD gatekeeper for display. */
xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
}
}
/*-----------------------------------------------------------*/
void vApplicationIdleHook( void )
{
/* Schedule the co-routines from within the idle task hook. */
vCoRoutineSchedule();
}
/*-----------------------------------------------------------*/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,265 @@
/*
FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
***************************************************************************
* *
* FreeRTOS tutorial books are available in pdf and paperback. *
* Complete, revised, and edited pdf reference manuals are also *
* available. *
* *
* Purchasing FreeRTOS documentation will not only help you, by *
* ensuring you get running as quickly as possible and with an *
* in-depth knowledge of how to use FreeRTOS, it will also help *
* the FreeRTOS project to continue with its mission of providing *
* professional grade, cross platform, de facto standard solutions *
* for microcontrollers - completely free of charge! *
* *
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
* *
* Thank you for using FreeRTOS, and thank you for your support! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS 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 modification to the GPL is included to allow you to
distribute a combined work that includes FreeRTOS without being obliged to
provide the source code for proprietary components outside of the FreeRTOS
kernel. FreeRTOS 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 and the FreeRTOS license exception along with FreeRTOS; if not it
can be viewed here: http://www.freertos.org/a00114.html and also obtained
by writing to Richard Barry, contact details for whom are available on the
FreeRTOS WEB site.
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong? *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, training, latest information,
license and contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool.
Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
the code with commercial support, indemnification, and middleware, under
the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
provide a safety engineered and independently SIL3 certified version under
the SafeRTOS brand: http://www.SafeRTOS.com.
*/
/* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
NOTE: This driver is primarily to test the scheduler functionality. It does
not effectively use the buffers or DMA and is therefore not intended to be
an example of an efficient driver. */
/* Standard include file. */
#include <stdlib.h>
/* Scheduler include files. */
#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
/* Demo app include files. */
#include "serial.h"
/* Hardware setup. */
#define serOUTPUT 0
#define serINPUT 1
#define serLOW_SPEED 0
#define serONE_STOP_BIT 0
#define serEIGHT_DATA_BITS_NO_PARITY 0
#define serNORMAL_IDLE_STATE 0
#define serAUTO_BAUD_OFF 0
#define serLOOPBACK_OFF 0
#define serWAKE_UP_DISABLE 0
#define serNO_HARDWARE_FLOW_CONTROL 0
#define serSTANDARD_IO 0
#define serNO_IRDA 0
#define serCONTINUE_IN_IDLE_MODE 0
#define serUART_ENABLED 1
#define serINTERRUPT_ON_SINGLE_CHAR 0
#define serTX_ENABLE 1
#define serINTERRUPT_ENABLE 1
#define serINTERRUPT_DISABLE 0
#define serCLEAR_FLAG 0
#define serSET_FLAG 1
/* The queues used to communicate between tasks and ISR's. */
static xQueueHandle xRxedChars;
static xQueueHandle xCharsForTx;
static portBASE_TYPE xTxHasEnded;
/*-----------------------------------------------------------*/
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{
char cChar;
/* Create the queues used by the com test task. */
xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
/* Setup the UART. */
U2MODEbits.BRGH = serLOW_SPEED;
U2MODEbits.STSEL = serONE_STOP_BIT;
U2MODEbits.PDSEL = serEIGHT_DATA_BITS_NO_PARITY;
U2MODEbits.ABAUD = serAUTO_BAUD_OFF;
U2MODEbits.LPBACK = serLOOPBACK_OFF;
U2MODEbits.WAKE = serWAKE_UP_DISABLE;
U2MODEbits.UEN = serNO_HARDWARE_FLOW_CONTROL;
U2MODEbits.IREN = serNO_IRDA;
U2MODEbits.USIDL = serCONTINUE_IN_IDLE_MODE;
U2MODEbits.UARTEN = serUART_ENABLED;
U2BRG = (unsigned short)(( (float)configCPU_CLOCK_HZ / ( (float)16 * (float)ulWantedBaud ) ) - (float)0.5);
U2STAbits.URXISEL = serINTERRUPT_ON_SINGLE_CHAR;
U2STAbits.UTXEN = serTX_ENABLE;
U2STAbits.UTXINV = serNORMAL_IDLE_STATE;
U2STAbits.UTXISEL0 = serINTERRUPT_ON_SINGLE_CHAR;
U2STAbits.UTXISEL1 = serINTERRUPT_ON_SINGLE_CHAR;
/* It is assumed that this function is called prior to the scheduler being
started. Therefore interrupts must not be allowed to occur yet as they
may attempt to perform a context switch. */
portDISABLE_INTERRUPTS();
IFS1bits.U2RXIF = serCLEAR_FLAG;
IFS1bits.U2TXIF = serCLEAR_FLAG;
IPC7bits.U2RXIP = configKERNEL_INTERRUPT_PRIORITY;
IPC7bits.U2TXIP = configKERNEL_INTERRUPT_PRIORITY;
IEC1bits.U2TXIE = serINTERRUPT_ENABLE;
IEC1bits.U2RXIE = serINTERRUPT_ENABLE;
/* Clear the Rx buffer. */
while( U2STAbits.URXDA == serSET_FLAG )
{
cChar = U2RXREG;
}
xTxHasEnded = pdTRUE;
return NULL;
}
/*-----------------------------------------------------------*/
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
{
/* Only one port is supported. */
( void ) pxPort;
/* Get the next character from the buffer. Return false if no characters
are available or arrive before xBlockTime expires. */
if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
{
return pdTRUE;
}
else
{
return pdFALSE;
}
}
/*-----------------------------------------------------------*/
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
{
/* Only one port is supported. */
( void ) pxPort;
/* Return false if after the block time there is no room on the Tx queue. */
if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
{
return pdFAIL;
}
/* A critical section should not be required as xTxHasEnded will not be
written to by the ISR if it is already 0 (is this correct?). */
if( xTxHasEnded )
{
xTxHasEnded = pdFALSE;
IFS1bits.U2TXIF = serSET_FLAG;
}
return pdPASS;
}
/*-----------------------------------------------------------*/
void vSerialClose( xComPortHandle xPort )
{
}
/*-----------------------------------------------------------*/
void __attribute__((__interrupt__, auto_psv)) _U2RXInterrupt( void )
{
char cChar;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
/* Get the character and post it on the queue of Rxed characters.
If the post causes a task to wake force a context switch as the woken task
may have a higher priority than the task we have interrupted. */
IFS1bits.U2RXIF = serCLEAR_FLAG;
while( U2STAbits.URXDA )
{
cChar = U2RXREG;
xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
}
if( xHigherPriorityTaskWoken != pdFALSE )
{
taskYIELD();
}
}
/*-----------------------------------------------------------*/
void __attribute__((__interrupt__, auto_psv)) _U2TXInterrupt( void )
{
signed char cChar;
portBASE_TYPE xTaskWoken = pdFALSE;
/* If the transmit buffer is full we cannot get the next character.
Another interrupt will occur the next time there is space so this does
not matter. */
IFS1bits.U2TXIF = serCLEAR_FLAG;
while( !( U2STAbits.UTXBF ) )
{
if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xTaskWoken ) == pdTRUE )
{
/* Send the next character queued for Tx. */
U2TXREG = cChar;
}
else
{
/* Queue empty, nothing to send. */
xTxHasEnded = pdTRUE;
break;
}
}
if( xTaskWoken != pdFALSE )
{
taskYIELD();
}
}

View file

@ -0,0 +1,175 @@
/*
FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
***************************************************************************
* *
* FreeRTOS tutorial books are available in pdf and paperback. *
* Complete, revised, and edited pdf reference manuals are also *
* available. *
* *
* Purchasing FreeRTOS documentation will not only help you, by *
* ensuring you get running as quickly as possible and with an *
* in-depth knowledge of how to use FreeRTOS, it will also help *
* the FreeRTOS project to continue with its mission of providing *
* professional grade, cross platform, de facto standard solutions *
* for microcontrollers - completely free of charge! *
* *
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
* *
* Thank you for using FreeRTOS, and thank you for your support! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS 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 modification to the GPL is included to allow you to
distribute a combined work that includes FreeRTOS without being obliged to
provide the source code for proprietary components outside of the FreeRTOS
kernel. FreeRTOS 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 and the FreeRTOS license exception along with FreeRTOS; if not it
can be viewed here: http://www.freertos.org/a00114.html and also obtained
by writing to Richard Barry, contact details for whom are available on the
FreeRTOS WEB site.
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong? *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, training, latest information,
license and contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool.
Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
the code with commercial support, indemnification, and middleware, under
the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
provide a safety engineered and independently SIL3 certified version under
the SafeRTOS brand: http://www.SafeRTOS.com.
*/
/* High speed timer test as described in main.c. */
/* Scheduler includes. */
#include "FreeRTOS.h"
/* Demo includes. */
#include "partest.h"
/* The number of interrupts to pass before we start looking at the jitter. */
#define timerSETTLE_TIME 5
/* The maximum value the 16bit timer can contain. */
#define timerMAX_COUNT 0xffff
/*-----------------------------------------------------------*/
/*
* Measure the time between this interrupt and the previous interrupt to
* calculate the timing jitter. Remember the maximum value the jitter has
* ever been calculated to be.
*/
static void prvCalculateAndStoreJitter( void );
/*-----------------------------------------------------------*/
/* The maximum time (in processor clocks) between two consecutive timer
interrupts so far. */
unsigned portSHORT usMaxJitter = 0;
/*-----------------------------------------------------------*/
void vSetupTimerTest( unsigned portSHORT usFrequencyHz )
{
/* T2 is used to generate interrupts. T4 is used to provide an accurate
time measurement. */
T2CON = 0;
T4CON = 0;
TMR2 = 0;
TMR4 = 0;
/* Timer 2 is going to interrupt at usFrequencyHz Hz. */
PR2 = ( unsigned portSHORT ) ( configCPU_CLOCK_HZ / ( unsigned portLONG ) usFrequencyHz );
/* Timer 4 is going to free run from minimum to maximum value. */
PR4 = ( unsigned portSHORT ) timerMAX_COUNT;
/* Setup timer 2 interrupt priority to be above the kernel priority so
the timer jitter is not effected by the kernel activity. */
IPC1bits.T2IP = configKERNEL_INTERRUPT_PRIORITY + 1;
/* Clear the interrupt as a starting condition. */
IFS0bits.T2IF = 0;
/* Enable the interrupt. */
IEC0bits.T2IE = 1;
/* Start both timers. */
T2CONbits.TON = 1;
T4CONbits.TON = 1;
}
/*-----------------------------------------------------------*/
static void prvCalculateAndStoreJitter( void )
{
static unsigned portSHORT usLastCount = 0, usSettleCount = 0;
unsigned portSHORT usThisCount, usDifference;
/* Capture the timer value as we enter the interrupt. */
usThisCount = TMR4;
if( usSettleCount >= timerSETTLE_TIME )
{
/* What is the difference between the timer value in this interrupt
and the value from the last interrupt. */
usDifference = usThisCount - usLastCount;
/* Store the difference in the timer values if it is larger than the
currently stored largest value. The difference over and above the
expected difference will give the 'jitter' in the processing of these
interrupts. */
if( usDifference > usMaxJitter )
{
usMaxJitter = usDifference;
}
}
else
{
/* Don't bother storing any values for the first couple of
interrupts. */
usSettleCount++;
}
/* Remember what the timer value was this time through, so we can calculate
the difference the next time through. */
usLastCount = usThisCount;
}
/*-----------------------------------------------------------*/
void __attribute__((__interrupt__, auto_psv)) _T2Interrupt( void )
{
/* Work out the time between this and the previous interrupt. */
prvCalculateAndStoreJitter();
/* Clear the timer interrupt. */
IFS0bits.T2IF = 0;
}

View file

@ -0,0 +1,76 @@
/*
FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
***************************************************************************
* *
* FreeRTOS tutorial books are available in pdf and paperback. *
* Complete, revised, and edited pdf reference manuals are also *
* available. *
* *
* Purchasing FreeRTOS documentation will not only help you, by *
* ensuring you get running as quickly as possible and with an *
* in-depth knowledge of how to use FreeRTOS, it will also help *
* the FreeRTOS project to continue with its mission of providing *
* professional grade, cross platform, de facto standard solutions *
* for microcontrollers - completely free of charge! *
* *
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
* *
* Thank you for using FreeRTOS, and thank you for your support! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS 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 modification to the GPL is included to allow you to
distribute a combined work that includes FreeRTOS without being obliged to
provide the source code for proprietary components outside of the FreeRTOS
kernel. FreeRTOS 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 and the FreeRTOS license exception along with FreeRTOS; if not it
can be viewed here: http://www.freertos.org/a00114.html and also obtained
by writing to Richard Barry, contact details for whom are available on the
FreeRTOS WEB site.
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong? *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, training, latest information,
license and contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool.
Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
the code with commercial support, indemnification, and middleware, under
the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
provide a safety engineered and independently SIL3 certified version under
the SafeRTOS brand: http://www.SafeRTOS.com.
*/
#ifndef TIMER_TEST_H
#define TIMER_TEST_H
/* Setup the high frequency timer interrupt. */
void vSetupTimerTest( unsigned short usFrequencyHz );
#endif /* TIMER_TEST_H */