From a612b892ea83a30d917a207dfdd23a340477c29c Mon Sep 17 00:00:00 2001 From: richardbarry Date: Wed, 24 Mar 2010 11:24:21 +0000 Subject: [PATCH] Add Cortus demo. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1001 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- Demo/CORTUS_APS3_GCC/.cproject | 527 ++++++++++++++++++ Demo/CORTUS_APS3_GCC/.project | 81 +++ .../BSP_ProjectForDebugging.zip | Bin 0 -> 5347 bytes .../CreateProjectDirectoryStructure.bat | 45 ++ Demo/CORTUS_APS3_GCC/Demo/7seg.c | 178 ++++++ Demo/CORTUS_APS3_GCC/Demo/7seg.h | 60 ++ Demo/CORTUS_APS3_GCC/Demo/FreeRTOSConfig.h | 110 ++++ Demo/CORTUS_APS3_GCC/Demo/ParTest.c | 113 ++++ Demo/CORTUS_APS3_GCC/Demo/demoGpio.h | 97 ++++ Demo/CORTUS_APS3_GCC/Demo/main.c | 280 ++++++++++ Demo/CORTUS_APS3_GCC/Demo/serial.c | 225 ++++++++ 11 files changed, 1716 insertions(+) create mode 100644 Demo/CORTUS_APS3_GCC/.cproject create mode 100644 Demo/CORTUS_APS3_GCC/.project create mode 100644 Demo/CORTUS_APS3_GCC/BSP_ProjectForDebugging.zip create mode 100644 Demo/CORTUS_APS3_GCC/CreateProjectDirectoryStructure.bat create mode 100644 Demo/CORTUS_APS3_GCC/Demo/7seg.c create mode 100644 Demo/CORTUS_APS3_GCC/Demo/7seg.h create mode 100644 Demo/CORTUS_APS3_GCC/Demo/FreeRTOSConfig.h create mode 100644 Demo/CORTUS_APS3_GCC/Demo/ParTest.c create mode 100644 Demo/CORTUS_APS3_GCC/Demo/demoGpio.h create mode 100644 Demo/CORTUS_APS3_GCC/Demo/main.c create mode 100644 Demo/CORTUS_APS3_GCC/Demo/serial.c diff --git a/Demo/CORTUS_APS3_GCC/.cproject b/Demo/CORTUS_APS3_GCC/.cproject new file mode 100644 index 000000000..fafcfb7fc --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/.cproject @@ -0,0 +1,527 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/CORTUS_APS3_GCC/.project b/Demo/CORTUS_APS3_GCC/.project new file mode 100644 index 000000000..b7d1f0ecb --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/.project @@ -0,0 +1,81 @@ + + + FreeRTOS + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + aps3-make + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/FreeRTOS/Debug} + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.cnature + + diff --git a/Demo/CORTUS_APS3_GCC/BSP_ProjectForDebugging.zip b/Demo/CORTUS_APS3_GCC/BSP_ProjectForDebugging.zip new file mode 100644 index 0000000000000000000000000000000000000000..193eb774bb768bcd5aa9a2bef9606968df34a89f GIT binary patch literal 5347 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 H-(UX)wO*sZ literal 0 HcmV?d00001 diff --git a/Demo/CORTUS_APS3_GCC/CreateProjectDirectoryStructure.bat b/Demo/CORTUS_APS3_GCC/CreateProjectDirectoryStructure.bat new file mode 100644 index 000000000..04cddd1d1 --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/CreateProjectDirectoryStructure.bat @@ -0,0 +1,45 @@ +REM This file should be executed from the command line prior to the first +REM build. It will be necessary to refresh the Eclipse project once the +REM .bat file has been executed (normally just press F5 to refresh). + +REM Copies all the required files from their location within the standard +REM FreeRTOS directory structure to under the Eclipse project directory. +REM This permits the Eclipse project to be used in 'managed' mode and without +REM having to setup any linked resources. + +REM Have the files already been copied? +IF EXIST Source Goto END + + REM Create the required directory structure. + MD Source + MD Source\include + MD Source\portable\GCC\CORTUS_APS3 + MD Source\portable\MemMang + MD Demo\Common + MD Demo\Common\include + + REM Copy the core kernel files. + copy ..\..\Source\*.* Source + + REM Copy the common header files + copy ..\..\Source\include\*.* Source\include + + REM Copy the portable layer files + copy ..\..\Source\portable\GCC\CORTUS_APS3\*.* Source\portable\GCC\CORTUS_APS3 + + REM Copy the basic memory allocation files + copy ..\..\Source\portable\MemMang\heap_2.c Source\portable\MemMang + + REM Copy the files that define the common demo tasks. + copy ..\common\Minimal\BlockQ.c Demo\Common + copy ..\common\Minimal\comtest.c Demo\Common + copy ..\common\Minimal\dynamic.c Demo\Common + copy ..\common\Minimal\flash.c Demo\Common + copy ..\common\Minimal\integer.c Demo\Common + copy ..\common\Minimal\PollQ.c Demo\Common + copy ..\common\Minimal\semtest.c Demo\Common + + REM Copy the common demo file headers. + copy ..\common\include\*.* Demo\Common\include + +: END diff --git a/Demo/CORTUS_APS3_GCC/Demo/7seg.c b/Demo/CORTUS_APS3_GCC/Demo/7seg.c new file mode 100644 index 000000000..2d7159895 --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/Demo/7seg.c @@ -0,0 +1,178 @@ +/* + FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd. + + *************************************************************************** + * * + * If you are: * + * * + * + New to FreeRTOS, * + * + Wanting to learn FreeRTOS or multitasking in general quickly * + * + Looking for basic training, * + * + Wanting to improve your FreeRTOS skills and productivity * + * * + * then take a look at the FreeRTOS eBook * + * * + * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * + * http://www.FreeRTOS.org/Documentation * + * * + * A pdf reference manual is also available. Both are usually delivered * + * to your inbox within 20 minutes to two hours when purchased between 8am * + * and 8pm GMT (although please allow up to 24 hours in case of * + * exceptional circumstances). 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 exception 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! + + 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. +*/ + +#include + +/* Scheduler include files. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Demo program include files. */ +#include "7seg.h" +#include "demoGpio.h" + +#define x7segSTACK_SIZE configMINIMAL_STACK_SIZE + +static portTASK_FUNCTION_PROTO( vRefreshTask, pvParameters ); +static portTASK_FUNCTION_PROTO( vCountTask, pvParameters ); + +void vStart7SegTasks( unsigned portBASE_TYPE uxPriority ) +{ + xTaskCreate (vRefreshTask, ( signed char * ) "7SegRefresh", x7segSTACK_SIZE, NULL, uxPriority, ( xTaskHandle *) NULL ); + xTaskCreate (vCountTask, ( signed char * ) "7SegCount", x7segSTACK_SIZE, NULL, uxPriority, ( xTaskHandle *) NULL ); +} + +/* Value to output to 7 segment display +led_digits[0] is the right most digit */ +static signed char seg7_digits[4]; + +static portTASK_FUNCTION_PROTO( vRefreshTask, pvParameters ) +{ +/* This is table 3.3 from the Spartan-3 Starter Kit board user guide */ +const unsigned char bits[16] = { + 0x01, + 0x4f, + 0x12, + 0x06, + 0x4c, + 0x24, + 0x20, + 0x0f, + 0x00, + 0x04, + 0x08, + 0x60, + 0x31, + 0x42, + 0x30, + 0x38 +}; + +const unsigned char apsx[4] = { + 0x06, /* 3 */ + 0x24, /* S */ + 0x18, /* P */ + 0x08 /* A */ +}; + +portTickType xRefreshRate, xLastRefreshTime; + +/* Digit to scan */ +static int d = 0; + + xRefreshRate = 2; + + /* We need to initialise xLastRefreshTime prior to the first call to + vTaskDelayUntil(). */ + xLastRefreshTime = xTaskGetTickCount(); + + for (;;) + { + for (d = 0; d < 4; d++) + { + vTaskDelayUntil ( &xLastRefreshTime, xRefreshRate); + + /* Display digit */ + gpio->out.an = -1; + if (seg7_digits[1] == 4 || seg7_digits[1] == 5) { + gpio->out.digit = apsx[d]; + } else { + gpio->out.digit = bits[seg7_digits[d]]; + } + gpio->out.dp = 1; + gpio->out.an = ~(1 << d); + } + } +} + + + +static portTASK_FUNCTION_PROTO( vCountTask, pvParameters ) +{ +portTickType xCountRate, xLastCountTime; + + + /* Approximately 20HZ */ + xCountRate = configTICK_RATE_HZ/20; + + /* We need to initialise xLastCountTime prior to the first call to + vTaskDelayUntil(). */ + xLastCountTime = xTaskGetTickCount(); + + for (;;) + { + vTaskDelayUntil ( &xLastCountTime, xCountRate); + + /* Really ugly way to do BCD arithmetic.... */ + seg7_digits[0] -= 1; + if (seg7_digits[0] < 0) { + seg7_digits[0] = 9; + seg7_digits[1] -= 1; + if (seg7_digits[1] < 0) { + seg7_digits[1] = 9; + seg7_digits[2] -= 1; + if (seg7_digits[2] < 0) { + seg7_digits[2] = 9; + seg7_digits[3] -= 1; + if (seg7_digits[3] < 0) { + seg7_digits[3] = 9; + } + } + } + } + } +} + +// Local Variables: +// tab-width:4 +// End: diff --git a/Demo/CORTUS_APS3_GCC/Demo/7seg.h b/Demo/CORTUS_APS3_GCC/Demo/7seg.h new file mode 100644 index 000000000..5aa14d40e --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/Demo/7seg.h @@ -0,0 +1,60 @@ +/* + FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd. + + *************************************************************************** + * * + * If you are: * + * * + * + New to FreeRTOS, * + * + Wanting to learn FreeRTOS or multitasking in general quickly * + * + Looking for basic training, * + * + Wanting to improve your FreeRTOS skills and productivity * + * * + * then take a look at the FreeRTOS eBook * + * * + * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * + * http://www.FreeRTOS.org/Documentation * + * * + * A pdf reference manual is also available. Both are usually delivered * + * to your inbox within 20 minutes to two hours when purchased between 8am * + * and 8pm GMT (although please allow up to 24 hours in case of * + * exceptional circumstances). 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 exception 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! + + 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. +*/ + +#ifndef SEVENSEG_H +#define SEVENSEG_H + +void vStart7SegTasks( unsigned portBASE_TYPE uxPriority ); + +#endif + diff --git a/Demo/CORTUS_APS3_GCC/Demo/FreeRTOSConfig.h b/Demo/CORTUS_APS3_GCC/Demo/FreeRTOSConfig.h new file mode 100644 index 000000000..33110da7c --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/Demo/FreeRTOSConfig.h @@ -0,0 +1,110 @@ +/* + FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd. + + *************************************************************************** + * * + * If you are: * + * * + * + New to FreeRTOS, * + * + Wanting to learn FreeRTOS or multitasking in general quickly * + * + Looking for basic training, * + * + Wanting to improve your FreeRTOS skills and productivity * + * * + * then take a look at the FreeRTOS eBook * + * * + * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * + * http://www.FreeRTOS.org/Documentation * + * * + * A pdf reference manual is also available. Both are usually delivered * + * to your inbox within 20 minutes to two hours when purchased between 8am * + * and 8pm GMT (although please allow up to 24 hours in case of * + * exceptional circumstances). 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 exception 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! + + 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. +*/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include + +/*----------------------------------------------------------- + * 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 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( ( unsigned long ) CLOCK_FREQUENCY ) +#define configTICK_RATE_HZ ( ( portTickType ) 1000 ) +#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 32 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 0 +#define configUSE_MALLOC_FAILED_HOOK 1 +#define configCHECK_FOR_STACK_OVERFLOW 1 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. +We use --gc-sections when linking, so there is no harm is setting all of these to 1 */ + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 + +#define BLOCKQ_1 1 + +#endif /* FREERTOS_CONFIG_H */ + +// Local Variables: +// tab-width:4 +// End: diff --git a/Demo/CORTUS_APS3_GCC/Demo/ParTest.c b/Demo/CORTUS_APS3_GCC/Demo/ParTest.c new file mode 100644 index 000000000..5437cc133 --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/Demo/ParTest.c @@ -0,0 +1,113 @@ +/* + FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd. + + *************************************************************************** + * * + * If you are: * + * * + * + New to FreeRTOS, * + * + Wanting to learn FreeRTOS or multitasking in general quickly * + * + Looking for basic training, * + * + Wanting to improve your FreeRTOS skills and productivity * + * * + * then take a look at the FreeRTOS eBook * + * * + * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * + * http://www.FreeRTOS.org/Documentation * + * * + * A pdf reference manual is also available. Both are usually delivered * + * to your inbox within 20 minutes to two hours when purchased between 8am * + * and 8pm GMT (although please allow up to 24 hours in case of * + * exceptional circumstances). 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 exception 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! + + 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. +*/ + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "portable.h" + +/* Demo app includes. */ +#include "partest.h" +#include "demoGpio.h" + +#define partstNUM_LEDS ( 8 ) +#define partstALL_OUTPUTS_OFF ( ( unsigned long ) ~(0xFFFFFFFF << partstNUM_LEDS) ) + +static unsigned long ulLEDReg; + +/*----------------------------------------------------------- + * Simple parallel port IO routines. + *-----------------------------------------------------------*/ + +static void SetLeds (unsigned int leds) +{ + gpio->out.leds = leds; +} + +/*-----------------------------------------------------------*/ + +void vParTestInitialise( void ) +{ + gpio->dir.leds = 0xff; +} + +/*-----------------------------------------------------------*/ + +void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) +{ + /* Switch an LED on or off as requested. */ + if (uxLED < partstNUM_LEDS) + { + if( xValue ) + { + ulLEDReg &= ~( 1 << uxLED ); + } + else + { + ulLEDReg |= ( 1 << uxLED ); + } + + SetLeds( ulLEDReg ); + } +} +/*-----------------------------------------------------------*/ + +void vParTestToggleLED( unsigned portBASE_TYPE uxLED ) +{ + /* Toggle the state of the requested LED. */ + if (uxLED < partstNUM_LEDS) + { + ulLEDReg ^= ( 1 << uxLED ); + SetLeds( ulLEDReg ); + } +} + diff --git a/Demo/CORTUS_APS3_GCC/Demo/demoGpio.h b/Demo/CORTUS_APS3_GCC/Demo/demoGpio.h new file mode 100644 index 000000000..1b0afede6 --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/Demo/demoGpio.h @@ -0,0 +1,97 @@ +/* + FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd. + + *************************************************************************** + * * + * If you are: * + * * + * + New to FreeRTOS, * + * + Wanting to learn FreeRTOS or multitasking in general quickly * + * + Looking for basic training, * + * + Wanting to improve your FreeRTOS skills and productivity * + * * + * then take a look at the FreeRTOS eBook * + * * + * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * + * http://www.FreeRTOS.org/Documentation * + * * + * A pdf reference manual is also available. Both are usually delivered * + * to your inbox within 20 minutes to two hours when purchased between 8am * + * and 8pm GMT (although please allow up to 24 hours in case of * + * exceptional circumstances). 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 exception 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! + + 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. +*/ + +/* Layout of pins connected to GPIO on Xilinx FPGA evaluation board +*/ + +#include + +#ifndef DEMOGPIO_H +#define DEMOGPIO_H + +typedef struct DemoBoardGpioPins +{ + /* Leds on board */ + unsigned leds:8; + + /* 7 segment display */ + unsigned digit:7; + + /* Decimal point */ + unsigned dp:1; + + /* Select anode for digit and decimal pt to light up */ + unsigned an:4; + + /* Unused */ + unsigned _fill:12; + +} DemoBoardGpioPins; + +typedef struct DemoBoardGpio +{ + volatile DemoBoardGpioPins out; + volatile DemoBoardGpioPins in; + volatile DemoBoardGpioPins dir; + volatile unsigned _fill; +} DemoBoardGpio; + +#ifdef SFRADR_GPIO1 +#define gpio ((DemoBoardGpio*)SFRADR_GPIO1) +#endif + +#endif + +// Local Variables: +// tab-width:4 +// End: diff --git a/Demo/CORTUS_APS3_GCC/Demo/main.c b/Demo/CORTUS_APS3_GCC/Demo/main.c new file mode 100644 index 000000000..f03f659be --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/Demo/main.c @@ -0,0 +1,280 @@ +/* + FreeRTOS V6.0.4 - Copyright (C) 2010 Real Time Engineers Ltd. + + *************************************************************************** + * * + * If you are: * + * * + * + New to FreeRTOS, * + * + Wanting to learn FreeRTOS or multitasking in general quickly * + * + Looking for basic training, * + * + Wanting to improve your FreeRTOS skills and productivity * + * * + * then take a look at the FreeRTOS eBook * + * * + * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * + * http://www.FreeRTOS.org/Documentation * + * * + * A pdf reference manual is also available. Both are usually delivered * + * to your inbox within 20 minutes to two hours when purchased between 8am * + * and 8pm GMT (although please allow up to 24 hours in case of * + * exceptional circumstances). 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 exception 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! + + 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. + * + * Main.c also creates a task called "Check". 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 other tasks are still operational. + * Each task (other than the "flash" tasks) maintains a unique count that is + * incremented each time the task successfully completes its function. Should + * any error occur within such a task the count is permanently halted. The + * check task inspects the count of each task to ensure it has changed since + * the last time the check task executed. If all the count variables have + * changed all the tasks are still executing error free, and the check task + * toggles the on board LED. Should any task contain an error at any time + * the LED toggle rate will change from 3 seconds to 500ms. + * + * NOTE: The demo application includes tasks that send and receive characters + * over the UART. The characters sent by one task are received by another - + * with an error condition being flagged should any characters be missed or + * received out of order. A loopback connector is required on the 9way D socket + * for this mechanism to operation (pins 2 and 3 the socket should be connected + * together - a paper clip is normally sufficient). + * + */ + +/* Standard includes. */ +#include +#include + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Demo application includes. */ +#include "partest.h" +#include "flash.h" +#include "integer.h" +#include "PollQ.h" +#include "comtest2.h" +#include "semtest.h" +#include "flop.h" +#include "dynamic.h" +#include "BlockQ.h" +#include "serial.h" +#include "demoGpio.h" +#include "7seg.h" + +/*-----------------------------------------------------------*/ + +/* Constants for the ComTest tasks. */ +#define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 ) +#define mainCOM_TEST_LED ( 5 ) + +/* Priorities for the demo application tasks. */ +#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) +#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 ) +#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 ) +#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define main7SEG_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 ) + +/* The rate at which the on board LED will toggle when there is/is not an +error. */ +#define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS ) +#define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS ) +#define mainON_BOARD_LED_BIT ( ( unsigned long ) 7 ) + +/* The size of the memory blocks allocated by the vMemCheckTask() task. */ +#define mainMEM_CHECK_SIZE_1 ( ( size_t ) 51 ) +#define mainMEM_CHECK_SIZE_2 ( ( size_t ) 52 ) +#define mainMEM_CHECK_SIZE_3 ( ( size_t ) 151 ) + +/*-----------------------------------------------------------*/ + +/* + * Checks that all the demo application tasks are still executing without error + * - as described at the top of the file. + */ +static long prvCheckOtherTasksAreStillRunning( void ); + +/* + * The task that executes at the highest priority and calls + * prvCheckOtherTasksAreStillRunning(). See the description at the top + * of the file. + */ +static void vErrorChecks( void *pvParameters ); + +/* + * Configure the processor for use with the Olimex demo board. This includes + * setup for the I/O, system clock, and access timings. + */ +static void prvSetupHardware( void ); + +/*-----------------------------------------------------------*/ + +/* + * Starts all the other tasks, then starts the scheduler. + */ +int main( void ) +{ + /* Setup the hardware for use with the Xilinx evaluation board. */ + prvSetupHardware(); + + /* Start the demo/test application tasks. */ + vStartIntegerMathTasks( tskIDLE_PRIORITY ); + vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED ); + vStartLEDFlashTasks( mainLED_TASK_PRIORITY ); + vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); + vStartSemaphoreTasks( mainSEM_TEST_PRIORITY ); + vStartDynamicPriorityTasks(); + vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); + vStart7SegTasks( main7SEG_TASK_PRIORITY ); + + /* Start the check task - which is defined in this file. */ + xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); + + /* Now all the tasks have been started - start the scheduler. */ + vTaskStartScheduler(); + + /* Should never reach here! */ + for( ;; ); +} +/*-----------------------------------------------------------*/ + +static void vErrorChecks( void *pvParameters ) +{ +portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD; + + /* Just to stop compiler warnings. */ + ( void ) pvParameters; + + /* Cycle for ever, delaying then checking all the other tasks are still + operating without error. If an error is detected then the delay period + is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so + the on board LED flash rate will increase. */ + + for( ;; ) + { + /* Delay until it is time to execute again. */ + vTaskDelay( xDelayPeriod ); + + /* Check all the standard demo application tasks are executing without + error. */ + if( prvCheckOtherTasksAreStillRunning() != pdPASS ) + { + /* An error has been detected in one of the tasks - flash faster. */ + xDelayPeriod = mainERROR_FLASH_PERIOD; + } + + /* The toggle rate of the LED depends on how long this task delays for. + An error reduces the delay period and so increases the toggle rate. */ + vParTestToggleLED( mainON_BOARD_LED_BIT ); + } +} +/*-----------------------------------------------------------*/ + +static void prvSetupHardware( void ) +{ + /* Initialise LED outputs. */ + vParTestInitialise(); +} +/*-----------------------------------------------------------*/ + +static long prvCheckOtherTasksAreStillRunning( void ) +{ +long lReturn = pdPASS; + + /* Check all the demo tasks (other than the flash tasks) to ensure + that they are all still running, and that none of them have detected + an error. */ + + if( xAreIntegerMathsTaskStillRunning() != pdTRUE ) + { + lReturn = pdFAIL; + } + + if( xAreComTestTasksStillRunning() != pdTRUE ) + { + lReturn = pdFAIL; + } + + if( xArePollingQueuesStillRunning() != pdTRUE ) + { + lReturn = pdFAIL; + } + + if( xAreSemaphoreTasksStillRunning() != pdTRUE ) + { + lReturn = pdFAIL; + } + + if( xAreDynamicPriorityTasksStillRunning() != pdTRUE ) + { + lReturn = pdFAIL; + } + + if( xAreBlockingQueuesStillRunning() != pdTRUE ) + { + lReturn = pdFAIL; + } + + return lReturn; +} +/*-----------------------------------------------------------*/ + +void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName ) +{ + /* This function will be called if a task overflows its stack. Inspect + pxCurrentTCB to find the offending task if the overflow was sever enough + to corrupt the pcTaskName parameter. */ + vParTestSetLED( 4, 1 ); + for( ;; ); +} +/*-----------------------------------------------------------*/ + +void vApplicationMallocFailedHook( void ) +{ + /* This function will be called if a call to pvPortMalloc() fails to return + the requested memory. pvPortMalloc() is called internally by the scheduler + whenever a task, queue or semaphore is created. */ + vParTestSetLED( 4, 1 ); + for( ;; ); +} +/*-----------------------------------------------------------*/ + + + diff --git a/Demo/CORTUS_APS3_GCC/Demo/serial.c b/Demo/CORTUS_APS3_GCC/Demo/serial.c new file mode 100644 index 000000000..0fe1b9482 --- /dev/null +++ b/Demo/CORTUS_APS3_GCC/Demo/serial.c @@ -0,0 +1,225 @@ +/* + FreeRTOS V6.0.3 - Copyright (C) 2010 Real Time Engineers Ltd. + + *************************************************************************** + * * + * If you are: * + * * + * + New to FreeRTOS, * + * + Wanting to learn FreeRTOS or multitasking in general quickly * + * + Looking for basic training, * + * + Wanting to improve your FreeRTOS skills and productivity * + * * + * then take a look at the FreeRTOS eBook * + * * + * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * + * http://www.FreeRTOS.org/Documentation * + * * + * A pdf reference manual is also available. Both are usually delivered * + * to your inbox within 20 minutes to two hours when purchased between 8am * + * and 8pm GMT (although please allow up to 24 hours in case of * + * exceptional circumstances). 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 exception 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! + + 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. +*/ + +/* Basic interrupt driven serial port driver for uart1. +*/ + +/* Standard includes. */ +#include + +/* Kernel includes. */ +#include "FreeRTOS.h" +#include "queue.h" +#include "task.h" + +/* Demo application includes. */ +#include +#include +#include "serial.h" +/*-----------------------------------------------------------*/ + +#define COM_BLOCK_RETRYTIME 10 +/*-----------------------------------------------------------*/ + +void vUARTInterruptHandlerTxWrapper(void) __attribute((naked)); +void vUARTInterruptHandlerRxWrapper(void) __attribute((naked)); +/*-----------------------------------------------------------*/ + +/* Queues used to hold received characters, and characters waiting to be +transmitted. */ +static xQueueHandle xRxedChars; +static xQueueHandle xCharsForTx; +extern unsigned portBASE_TYPE *pxVectorTable; +/*-----------------------------------------------------------*/ + +xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) +{ + /* Create the queues used to hold Rx and Tx characters. */ + xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); + xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); + + if( ( xRxedChars ) && ( xCharsForTx ) ) + { + /* Set up interrupts */ + /* tx interrupt will be enabled when we need to send something */ + uart1->tx_mask = 0; + uart1->rx_mask = 1; + irq[IRQ_UART1_TX].ien = 1; + irq[IRQ_UART1_TX].ipl = portSYSTEM_INTERRUPT_PRIORITY_LEVEL; + irq[IRQ_UART1_RX].ien = 1; + irq[IRQ_UART1_RX].ipl = portSYSTEM_INTERRUPT_PRIORITY_LEVEL; + } + return ( xComPortHandle ) 0; +} +/*-----------------------------------------------------------*/ + +signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime ) +{ + /* The port handle is not required as this driver only supports uart1. */ + (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; + } +} + +/*-----------------------------------------------------------*/ + +void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength ) +{ + int i; + signed char *pChNext; + + /* Send each character in the string, one at a time. */ + pChNext = ( signed char * )pcString; + for( i = 0; i < usStringLength; i++ ) + { + /* Block until character has been transmitted. */ + while( xSerialPutChar( pxPort, *pChNext, COM_BLOCK_RETRYTIME ) != pdTRUE ); pChNext++; + } +} + +/*-----------------------------------------------------------*/ + +signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime ) +{ + ( void ) pxPort; + + /* Place the character in the queue of characters to be transmitted. */ + if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS ) + { + return pdFAIL; + } + + /* Turn on the Tx interrupt so the ISR will remove the character from the + queue and send it. This does not need to be in a critical section as + if the interrupt has already removed the character the next interrupt + will simply turn off the Tx interrupt again. */ + uart1->tx_mask = 1; + + return pdPASS; +} +/*-----------------------------------------------------------*/ + +void vSerialClose( xComPortHandle xPort ) +{ + /* Not supported as not required by the demo application. */ + ( void ) xPort; +} +/*-----------------------------------------------------------*/ + +void interrupt_handler( IRQ_UART1_TX ) +{ +static signed char cChar; +static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; + + portSAVE_CONTEXT_REDUCED(); + + /* The interrupt was caused by the transmit fifo having space for at least one + character. Are there any more characters to transmit? */ + if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE ) + { + /* A character was retrieved from the queue so can be sent to the uart now. */ + uart1->tx_data = cChar; + } + else + { + /* Queue empty, nothing to send so turn off the Tx interrupt. */ + uart1->tx_mask = 0; + } + + /* If an event caused a task to unblock then we call "Yield from ISR" to + ensure that the unblocked task is the task that executes when the interrupt + completes if the unblocked task has a priority higher than the interrupted + task. */ + if( xHigherPriorityTaskWoken ) + { + portYIELD_FROM_ISR(); + } + portRESTORE_CONTEXT_REDUCED(); +} +/*-----------------------------------------------------------*/ + +void interrupt_handler( IRQ_UART1_RX ) +{ +static signed char cChar; +static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; + + portSAVE_CONTEXT_REDUCED(); + + /* The interrupt was caused by the receiver getting data. */ + cChar = uart1->rx_data; + + (void)xQueueSendFromISR(xRxedChars, &cChar, &xHigherPriorityTaskWoken); + + /* If an event caused a task to unblock then we call "Yield from ISR" to + ensure that the unblocked task is the task that executes when the interrupt + completes if the unblocked task has a priority higher than the interrupted + task. */ + if( xHigherPriorityTaskWoken ) + { + portYIELD_FROM_ISR(); + } + + portRESTORE_CONTEXT_REDUCED(); +} +/*-----------------------------------------------------------*/ + + -- 2.39.5