mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-01 08:54:14 -04:00
Add FreeRTOS-Plus directory.
This commit is contained in:
parent
7bd5f21ad5
commit
f508a5f653
6798 changed files with 134949 additions and 19 deletions
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
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 <xparameters.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 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 250 )
|
||||
#define configCPU_CLOCK_HZ ( ( unsigned long ) XPAR_CPU_PPC440_CORE_CLOCK_FREQ_HZ ) /* Clock setup from start.asm in the demo application. */
|
||||
#define configTICK_RATE_HZ ( (portTickType) 1000 )
|
||||
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 6 )
|
||||
#define configTOTAL_HEAP_SIZE ( (size_t) (80 * 1024) )
|
||||
#define configMAX_TASK_NAME_LEN ( 20 )
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configIDLE_SHOULD_YIELD 1
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configUSE_TRACE_FACILITY 0
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configUSE_APPLICATION_TASK_TAG 1
|
||||
#define configUSE_FPU 1
|
||||
|
||||
|
||||
/* Co-routine definitions. */
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
#define configMAX_CO_ROUTINE_PRIORITIES ( 4 )
|
||||
|
||||
/* 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 1
|
||||
#define INCLUDE_vTaskDelete 1
|
||||
#define INCLUDE_vTaskCleanUpResources 1
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_vResumeFromISR 1
|
||||
#define INCLUDE_vTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_xTaskGetSchedulerState 1
|
||||
#define INCLUDE_xTaskGetCurrentTaskHandle 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 1
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
|
||||
|
||||
#if configUSE_FPU == 1
|
||||
/* Include the header that define the traceTASK_SWITCHED_IN() and
|
||||
traceTASK_SWITCHED_OUT() macros to save and restore the floating
|
||||
point registers for tasks that have requested this behaviour. */
|
||||
#include "FPU_Macros.h"
|
||||
#endif
|
||||
|
||||
#endif /* FREERTOS_CONFIG_H */
|
||||
|
||||
|
|
@ -0,0 +1,226 @@
|
|||
/*******************************************************************/
|
||||
/* */
|
||||
/* This file is automatically generated by linker script generator.*/
|
||||
/* */
|
||||
/* Version: Xilinx EDK 11.1 EDK_L.29.1 */
|
||||
/* */
|
||||
/* Copyright (c) 2004 Xilinx, Inc. All rights reserved. */
|
||||
/* */
|
||||
/* Description : PowerPC440 Linker Script */
|
||||
/* */
|
||||
/*******************************************************************/
|
||||
|
||||
_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x400;
|
||||
_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x400;
|
||||
|
||||
/* Define Memories in the system */
|
||||
|
||||
MEMORY
|
||||
{
|
||||
DDR2_SDRAM_C_MEM_BASEADDR : ORIGIN = 0x00000000, LENGTH = 0x10000000
|
||||
SRAM_C_MEM0_BASEADDR : ORIGIN = 0xF8000000, LENGTH = 0x00100000
|
||||
xps_bram_if_cntlr_1 : ORIGIN = 0xFFFFE000, LENGTH = 0x00001F00
|
||||
}
|
||||
|
||||
/* Specify the default entry point to the program */
|
||||
|
||||
ENTRY(_boot)
|
||||
STARTUP(boot.o)
|
||||
|
||||
/* Define the sections, and where they are mapped in memory */
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.vectors : {
|
||||
__vectors_start = .;
|
||||
*(.vectors)
|
||||
__vectors_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.text : {
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.gnu.linkonce.t.*)
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.init : {
|
||||
KEEP (*(.init))
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.fini : {
|
||||
KEEP (*(.fini))
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.rodata : {
|
||||
__rodata_start = .;
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
*(.gnu.linkonce.r.*)
|
||||
__rodata_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.rodata1 : {
|
||||
__rodata1_start = .;
|
||||
*(.rodata1)
|
||||
*(.rodata1.*)
|
||||
__rodata1_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.sdata2 : {
|
||||
__sdata2_start = .;
|
||||
*(.sdata2)
|
||||
*(.sdata2.*)
|
||||
*(.gnu.linkonce.s2.*)
|
||||
__sdata2_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.sbss2 : {
|
||||
__sbss2_start = .;
|
||||
*(.sbss2)
|
||||
*(.sbss2.*)
|
||||
*(.gnu.linkonce.sb2.*)
|
||||
__sbss2_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.data : {
|
||||
__data_start = .;
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
*(.gnu.linkonce.d.*)
|
||||
__data_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.data1 : {
|
||||
__data1_start = .;
|
||||
*(.data1)
|
||||
*(.data1.*)
|
||||
__data1_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.got : {
|
||||
*(.got)
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.got1 : {
|
||||
*(.got1)
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.got2 : {
|
||||
*(.got2)
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.ctors : {
|
||||
__CTOR_LIST__ = .;
|
||||
___CTORS_LIST___ = .;
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE(*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
__CTOR_END__ = .;
|
||||
___CTORS_END___ = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.dtors : {
|
||||
__DTOR_LIST__ = .;
|
||||
___DTORS_LIST___ = .;
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE(*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
__DTOR_END__ = .;
|
||||
___DTORS_END___ = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.fixup : {
|
||||
__fixup_start = .;
|
||||
*(.fixup)
|
||||
__fixup_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.eh_frame : {
|
||||
*(.eh_frame)
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.jcr : {
|
||||
*(.jcr)
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.gcc_except_table : {
|
||||
*(.gcc_except_table)
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.sdata : {
|
||||
__sdata_start = .;
|
||||
*(.sdata)
|
||||
*(.sdata.*)
|
||||
*(.gnu.linkonce.s.*)
|
||||
__sdata_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.sbss : {
|
||||
__sbss_start = .;
|
||||
*(.sbss)
|
||||
*(.sbss.*)
|
||||
*(.gnu.linkonce.sb.*)
|
||||
*(.scommon)
|
||||
__sbss_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.tdata : {
|
||||
__tdata_start = .;
|
||||
*(.tdata)
|
||||
*(.tdata.*)
|
||||
*(.gnu.linkonce.td.*)
|
||||
__tdata_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.tbss : {
|
||||
__tbss_start = .;
|
||||
*(.tbss)
|
||||
*(.tbss.*)
|
||||
*(.gnu.linkonce.tb.*)
|
||||
__tbss_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.bss : {
|
||||
__bss_start = .;
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
__bss_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.boot0 0xFFFFFF00 : {
|
||||
__boot0_start = .;
|
||||
*(.boot0)
|
||||
__boot0_end = .;
|
||||
}
|
||||
|
||||
.boot 0xFFFFFFFC : {
|
||||
__boot_start = .;
|
||||
*(.boot)
|
||||
__boot_end = .;
|
||||
}
|
||||
|
||||
/* Generate Stack and Heap Sections */
|
||||
|
||||
.stack : {
|
||||
_stack_end = .;
|
||||
. += _STACK_SIZE;
|
||||
. = ALIGN(16);
|
||||
__stack = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
.heap : {
|
||||
. = ALIGN(16);
|
||||
_heap_start = .;
|
||||
. += _HEAP_SIZE;
|
||||
. = ALIGN(16);
|
||||
_heap_end = .;
|
||||
_end = .;
|
||||
} > SRAM_C_MEM0_BASEADDR
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,261 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tests the floating point context save and restore mechanism.
|
||||
*
|
||||
* Two tasks are created - each of which is allocated a buffer of
|
||||
* portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context
|
||||
* of the task is saved when the task is switched out, and from which the
|
||||
* flop context of the task is restored when the task is switch in. Prior to
|
||||
* the tasks being created each position in the two buffers is filled with a
|
||||
* unique value - this way the flop context of each task is different.
|
||||
*
|
||||
* The two test tasks never block so are always in either the Running or
|
||||
* Ready state. They execute at the lowest priority so will get pre-empted
|
||||
* regularly, although the yield frequently so will not get much execution
|
||||
* time. The lack of execution time is not a problem as its only the
|
||||
* switching in and out that is being tested.
|
||||
*
|
||||
* Whenever a task is moved from the Ready to the Running state its flop
|
||||
* context will be loaded from the buffer, but while the task is in the
|
||||
* Running state the buffer is not used and can contain any value - in this
|
||||
* case and for test purposes the task itself clears the buffer to zero.
|
||||
* The next time the task is moved out of the Running state into the
|
||||
* Ready state the flop context will once more get saved to the buffer -
|
||||
* overwriting the zeros.
|
||||
*
|
||||
* Therefore whenever the task is not in the Running state its buffer contains
|
||||
* the most recent values of its floating point registers - the zeroing out
|
||||
* of the buffer while the task was executing being used to ensure the values
|
||||
* the buffer contains are not stale.
|
||||
*
|
||||
* When neither test task is in the Running state the buffers should contain
|
||||
* the unique values allocated before the tasks were created. If so then
|
||||
* the floating point context has been maintained. This check is performed
|
||||
* by the 'check' task (defined in main.c) by calling
|
||||
* xAreFlopRegisterTestsStillRunning().
|
||||
*
|
||||
* The test tasks also increment a value each time they execute.
|
||||
* xAreFlopRegisterTestsStillRunning() also checks that this value has changed
|
||||
* since it last ran to ensure the test tasks are still getting processing time.
|
||||
*/
|
||||
|
||||
/* Standard includes files. */
|
||||
#include <string.h>
|
||||
|
||||
/* Scheduler include files. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#define flopNUMBER_OF_TASKS 2
|
||||
#define flopSTART_VALUE ( 0x1 )
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* The two test tasks as described at the top of this file. */
|
||||
static void vFlopTest1( void *pvParameters );
|
||||
static void vFlopTest2( void *pvParameters );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Buffers into which the flop registers will be saved. There is a buffer for
|
||||
both tasks. */
|
||||
static volatile unsigned long ulFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];
|
||||
|
||||
/* Variables that are incremented by the tasks to indicate that they are still
|
||||
running. */
|
||||
static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartFlopRegTests( void )
|
||||
{
|
||||
xTaskHandle xTaskJustCreated;
|
||||
unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;
|
||||
|
||||
/* Fill the arrays into which the flop registers are to be saved with
|
||||
known values. These are the values that will be written to the flop
|
||||
registers when the tasks start, and as the tasks do not perform any
|
||||
flop operations the values should never change. Each position in the
|
||||
buffer contains a different value so the flop context of each task
|
||||
will be different. */
|
||||
for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
|
||||
{
|
||||
for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )
|
||||
{
|
||||
ulFlopRegisters[ x ][ y ] = z;
|
||||
z++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Create the first task. */
|
||||
xTaskCreate( vFlopTest1, ( signed char * ) "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
|
||||
|
||||
/* The task tag value is a value that can be associated with a task, but
|
||||
is not used by the scheduler itself. Its use is down to the application so
|
||||
it makes a convenient place in this case to store the pointer to the buffer
|
||||
into which the flop context of the task will be stored. The first created
|
||||
task uses ulFlopRegisters[ 0 ], the second ulFlopRegisters[ 1 ]. */
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 0 ][ 0 ] ) );
|
||||
|
||||
/* Do the same for the second task. */
|
||||
xTaskCreate( vFlopTest2, ( signed char * ) "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 1 ][ 0 ] ) );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vFlopTest1( void *pvParameters )
|
||||
{
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* The values from the buffer should have now been written to the flop
|
||||
registers. Clear the buffer to ensure the same values then get written
|
||||
back the next time the task runs. Being preempted during this memset
|
||||
could cause the test to fail, hence the critical section. */
|
||||
portENTER_CRITICAL();
|
||||
memset( ( void * ) ulFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
|
||||
portEXIT_CRITICAL();
|
||||
|
||||
/* We don't have to do anything other than indicate that we are
|
||||
still running. */
|
||||
ulFlop1CycleCount++;
|
||||
taskYIELD();
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vFlopTest2( void *pvParameters )
|
||||
{
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* The values from the buffer should have now been written to the flop
|
||||
registers. Clear the buffer to ensure the same values then get written
|
||||
back the next time the task runs. */
|
||||
portENTER_CRITICAL();
|
||||
memset( ( void * ) ulFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
|
||||
portEXIT_CRITICAL();
|
||||
|
||||
/* We don't have to do anything other than indicate that we are
|
||||
still running. */
|
||||
ulFlop2CycleCount++;
|
||||
taskYIELD();
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )
|
||||
{
|
||||
portBASE_TYPE xReturn = pdPASS;
|
||||
unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;
|
||||
static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;
|
||||
|
||||
/* Called from the 'check' task.
|
||||
|
||||
The flop tasks cannot be currently running, check their saved registers
|
||||
are as expected. The tests tasks do not perform any flop operations so
|
||||
their registers should be as per their initial setting. */
|
||||
for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
|
||||
{
|
||||
for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )
|
||||
{
|
||||
if( ulFlopRegisters[ x ][ y ] != z )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
z++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check both tasks have actually been swapped in and out since this function
|
||||
last executed. */
|
||||
if( ulFlop1CycleCount == ulLastFlop1CycleCount )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( ulFlop2CycleCount == ulLastFlop2CycleCount )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
}
|
||||
|
||||
ulLastFlop1CycleCount = ulFlop1CycleCount;
|
||||
ulLastFlop2CycleCount = ulFlop2CycleCount;
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
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 FLOP_REG_TEST_H
|
||||
#define FLOP_REG_TEST_H
|
||||
|
||||
void vStartFlopRegTests( void );
|
||||
portBASE_TYPE xAreFlopRegisterTestsStillRunning( void );
|
||||
|
||||
#endif
|
|
@ -0,0 +1,417 @@
|
|||
/*
|
||||
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 eight tasks, each of which loops continuously performing a
|
||||
* floating point calculation.
|
||||
*
|
||||
* All the tasks run at the idle priority and never block or yield. This causes
|
||||
* all eight tasks to time slice with the idle task. Running at the idle priority
|
||||
* means that these tasks will get pre-empted any time another task is ready to run
|
||||
* or a time slice occurs. More often than not the pre-emption will occur mid
|
||||
* calculation, creating a good test of the schedulers context switch mechanism - a
|
||||
* calculation producing an unexpected result could be a symptom of a corruption in
|
||||
* the context of a task.
|
||||
*
|
||||
* This file demonstrates the use of the task tag and traceTASK_SWITCHED_IN and
|
||||
* traceTASK_SWITCHED_OUT macros to save and restore the floating point context.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
/* Scheduler include files. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Demo program include files. */
|
||||
#include "flop.h"
|
||||
|
||||
/* Misc. definitions. */
|
||||
#define mathSTACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define mathNUMBER_OF_TASKS ( 8 )
|
||||
|
||||
/* Four tasks, each of which performs a different floating point calculation.
|
||||
Each of the four is created twice. */
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );
|
||||
|
||||
/* These variables are used to check that all the tasks are still running. If a
|
||||
task gets a calculation wrong it will stop incrementing its check variable. */
|
||||
static volatile unsigned short usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
|
||||
|
||||
/* Buffers into which the flop registers will be saved. There is a buffer for
|
||||
each task created within this file. Zeroing out this array is the normal and
|
||||
safe option as this will cause the task to start with all zeros in its flop
|
||||
context. */
|
||||
static unsigned long ulFlopRegisters[ mathNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartMathTasks( unsigned portBASE_TYPE uxPriority )
|
||||
{
|
||||
xTaskHandle xTaskJustCreated;
|
||||
portBASE_TYPE x, y;
|
||||
|
||||
/* Place known values into the buffers into which the flop registers are
|
||||
to be saved. This is for debug purposes only, it is not normally
|
||||
required. The last position in each array is left at zero as the status
|
||||
register will be loaded from there.
|
||||
|
||||
It is intended that these values can be viewed being loaded into the
|
||||
flop registers when a task is started - however the Insight debugger
|
||||
does not seem to want to show the flop register values. */
|
||||
for( x = 0; x < mathNUMBER_OF_TASKS; x++ )
|
||||
{
|
||||
for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )
|
||||
{
|
||||
ulFlopRegisters[ x ][ y ] = ( x + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the first task - passing it the address of the check variable
|
||||
that it is going to increment. This check variable is used as an
|
||||
indication that the task is still running. */
|
||||
xTaskCreate( vCompetingMathTask1, ( signed char * ) "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, &xTaskJustCreated );
|
||||
|
||||
/* The task tag value is a value that can be associated with a task, but
|
||||
is not used by the scheduler itself. Its use is down to the application so
|
||||
it makes a convenient place in this case to store the pointer to the buffer
|
||||
into which the flop context of the task will be stored. The first created
|
||||
task uses ulFlopRegisters[ 0 ], the second ulFlopRegisters[ 1 ], etc. */
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 0 ][ 0 ] ) );
|
||||
|
||||
/* Create another 7 tasks, allocating a buffer for each. */
|
||||
xTaskCreate( vCompetingMathTask2, ( signed char * ) "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, &xTaskJustCreated );
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 1 ][ 0 ] ) );
|
||||
|
||||
xTaskCreate( vCompetingMathTask3, ( signed char * ) "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, &xTaskJustCreated );
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 2 ][ 0 ] ) );
|
||||
|
||||
xTaskCreate( vCompetingMathTask4, ( signed char * ) "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, &xTaskJustCreated );
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 3 ][ 0 ] ) );
|
||||
|
||||
xTaskCreate( vCompetingMathTask1, ( signed char * ) "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, &xTaskJustCreated );
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 4 ][ 0 ] ) );
|
||||
|
||||
xTaskCreate( vCompetingMathTask2, ( signed char * ) "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, &xTaskJustCreated );
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 5 ][ 0 ] ) );
|
||||
|
||||
xTaskCreate( vCompetingMathTask3, ( signed char * ) "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, &xTaskJustCreated );
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 6 ][ 0 ] ) );
|
||||
|
||||
xTaskCreate( vCompetingMathTask4, ( signed char * ) "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, &xTaskJustCreated );
|
||||
vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 7 ][ 0 ] ) );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
|
||||
{
|
||||
volatile portFLOAT ff1, ff2, ff3, ff4;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
volatile portFLOAT fAnswer;
|
||||
short sError = pdFALSE;
|
||||
|
||||
ff1 = 123.4567F;
|
||||
ff2 = 2345.6789F;
|
||||
ff3 = -918.222F;
|
||||
|
||||
fAnswer = ( ff1 + ff2 ) * ff3;
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for(;;)
|
||||
{
|
||||
ff1 = 123.4567F;
|
||||
ff2 = 2345.6789F;
|
||||
ff3 = -918.222F;
|
||||
|
||||
ff4 = ( ff1 + ff2 ) * ff3;
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
if( fabs( ff4 - fAnswer ) > 0.001F )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
}
|
||||
|
||||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
|
||||
{
|
||||
volatile portFLOAT ff1, ff2, ff3, ff4;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
volatile portFLOAT fAnswer;
|
||||
short sError = pdFALSE;
|
||||
|
||||
ff1 = -389.38F;
|
||||
ff2 = 32498.2F;
|
||||
ff3 = -2.0001F;
|
||||
|
||||
fAnswer = ( ff1 / ff2 ) * ff3;
|
||||
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for( ;; )
|
||||
{
|
||||
ff1 = -389.38F;
|
||||
ff2 = 32498.2F;
|
||||
ff3 = -2.0001F;
|
||||
|
||||
ff4 = ( ff1 / ff2 ) * ff3;
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
if( fabs( ff4 - fAnswer ) > 0.001F )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
}
|
||||
|
||||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know
|
||||
this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
|
||||
{
|
||||
volatile portFLOAT *pfArray, fTotal1, fTotal2, fDifference;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
pfArray = ( portFLOAT * ) pvPortMalloc( xArraySize * sizeof( portFLOAT ) );
|
||||
|
||||
/* Keep filling an array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
{
|
||||
fTotal1 = 0.0F;
|
||||
fTotal2 = 0.0F;
|
||||
|
||||
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
|
||||
{
|
||||
pfArray[ xPosition ] = ( portFLOAT ) xPosition + 5.5F;
|
||||
fTotal1 += ( portFLOAT ) xPosition + 5.5F;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
|
||||
{
|
||||
fTotal2 += pfArray[ xPosition ];
|
||||
}
|
||||
|
||||
fDifference = fTotal1 - fTotal2;
|
||||
if( fabs( fDifference ) > 0.001F )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
|
||||
{
|
||||
volatile portFLOAT *pfArray, fTotal1, fTotal2, fDifference;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
pfArray = ( portFLOAT * ) pvPortMalloc( xArraySize * sizeof( portFLOAT ) );
|
||||
|
||||
/* Keep filling an array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
{
|
||||
fTotal1 = 0.0F;
|
||||
fTotal2 = 0.0F;
|
||||
|
||||
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
|
||||
{
|
||||
pfArray[ xPosition ] = ( portFLOAT ) xPosition * 12.123F;
|
||||
fTotal1 += ( portFLOAT ) xPosition * 12.123F;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
|
||||
{
|
||||
fTotal2 += pfArray[ xPosition ];
|
||||
}
|
||||
|
||||
fDifference = fTotal1 - fTotal2;
|
||||
if( fabs( fDifference ) > 0.001F )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* This is called to check that all the created tasks are still running. */
|
||||
portBASE_TYPE xAreMathsTaskStillRunning( void )
|
||||
{
|
||||
/* Keep a history of the check variables so we know if they have been incremented
|
||||
since the last call. */
|
||||
static unsigned short usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
|
||||
portBASE_TYPE xReturn = pdTRUE, xTask;
|
||||
|
||||
/* Check the maths tasks are still running by ensuring their check variables
|
||||
are still incrementing. */
|
||||
for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
|
||||
{
|
||||
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
|
||||
{
|
||||
/* The check has not incremented so an error exists. */
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
|
||||
usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
716
FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c
Normal file
716
FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c
Normal file
|
@ -0,0 +1,716 @@
|
|||
/*
|
||||
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 demo application tasks.
|
||||
*
|
||||
* In addition to the standard demo tasks, the follow demo specific tasks are
|
||||
* create:
|
||||
*
|
||||
* The "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 other tasks are still operational. Most tasks maintain
|
||||
* 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 onboard LED. Should any task contain an error at any time
|
||||
* the LED toggle rate will change from 3 seconds to 500ms.
|
||||
*
|
||||
* The "Register Check" tasks. These tasks fill the CPU registers with known
|
||||
* values, then check that each register still contains the expected value, the
|
||||
* discovery of an unexpected value being indicative of an error in the RTOS
|
||||
* context switch mechanism. The register check tasks operate at low priority
|
||||
* so are switched in and out frequently.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Scheduler includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Xilinx library includes. */
|
||||
#include "xcache_l.h"
|
||||
#include "xintc.h"
|
||||
|
||||
/* Demo application includes. */
|
||||
#include "flash.h"
|
||||
#include "integer.h"
|
||||
#include "comtest2.h"
|
||||
#include "semtest.h"
|
||||
#include "BlockQ.h"
|
||||
#include "dynamic.h"
|
||||
#include "GenQTest.h"
|
||||
#include "QPeek.h"
|
||||
#include "blocktim.h"
|
||||
#include "death.h"
|
||||
#include "partest.h"
|
||||
#include "countsem.h"
|
||||
#include "recmutex.h"
|
||||
#include "flop.h"
|
||||
#include "flop-reg-test.h"
|
||||
|
||||
/* Priorities assigned to the demo tasks. */
|
||||
#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
|
||||
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
||||
#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||
#define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||
#define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||
#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||
#define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
|
||||
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||
#define mainFLOP_PRIORITY ( tskIDLE_PRIORITY )
|
||||
|
||||
/* The first LED used by the COM test and check tasks respectively. */
|
||||
#define mainCOM_TEST_LED ( 4 )
|
||||
#define mainCHECK_TEST_LED ( 3 )
|
||||
|
||||
/* The baud rate used by the comtest tasks is set by the hardware, so the
|
||||
baud rate parameters passed into the comtest initialisation has no effect. */
|
||||
#define mainBAUD_SET_IN_HARDWARE ( 0 )
|
||||
|
||||
/* Delay periods used by the check task. If no errors have been found then
|
||||
the check LED will toggle every mainNO_ERROR_CHECK_DELAY milliseconds. If an
|
||||
error has been found at any time then the toggle rate will increase to
|
||||
mainERROR_CHECK_DELAY milliseconds. */
|
||||
#define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
|
||||
#define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
|
||||
|
||||
|
||||
/*
|
||||
* The tasks defined within this file - described within the comments at the
|
||||
* head of this page.
|
||||
*/
|
||||
static void prvRegTestTask1( void *pvParameters );
|
||||
static void prvRegTestTask2( void *pvParameters );
|
||||
static void prvErrorChecks( void *pvParameters );
|
||||
|
||||
/*
|
||||
* Called by the 'check' task to inspect all the standard demo tasks within
|
||||
* the system, as described within the comments at the head of this page.
|
||||
*/
|
||||
static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void );
|
||||
|
||||
/*
|
||||
* Perform any hardware initialisation required by the demo application.
|
||||
*/
|
||||
static void prvSetupHardware( void );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* xRegTestStatus will get set to pdFAIL by the regtest tasks if they
|
||||
discover an unexpected value. */
|
||||
static volatile unsigned portBASE_TYPE xRegTestStatus = pdPASS;
|
||||
|
||||
/* Counters used to ensure the regtest tasks are still running. */
|
||||
static volatile unsigned long ulRegTest1Counter = 0UL, ulRegTest2Counter = 0UL;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
int main( void )
|
||||
{
|
||||
|
||||
/* Must be called prior to installing any interrupt handlers! */
|
||||
vPortSetupInterruptController();
|
||||
|
||||
/* In this case prvSetupHardware() just enables the caches and and
|
||||
configures the IO ports for the LED outputs. */
|
||||
prvSetupHardware();
|
||||
|
||||
/* Start the standard demo application tasks. Note that the baud rate used
|
||||
by the comtest tasks is set by the hardware, so the baud rate parameter
|
||||
passed has no effect. */
|
||||
vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
|
||||
vStartIntegerMathTasks( tskIDLE_PRIORITY );
|
||||
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainBAUD_SET_IN_HARDWARE, mainCOM_TEST_LED );
|
||||
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
|
||||
vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
|
||||
vStartDynamicPriorityTasks();
|
||||
vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
|
||||
vStartQueuePeekTasks();
|
||||
vCreateBlockTimeTasks();
|
||||
vStartCountingSemaphoreTasks();
|
||||
vStartRecursiveMutexTasks();
|
||||
|
||||
#if ( configUSE_FPU == 1 )
|
||||
vStartMathTasks( mainFLOP_PRIORITY );
|
||||
vStartFlopRegTests();
|
||||
#endif
|
||||
|
||||
/* Create the tasks defined within this file. */
|
||||
xTaskCreate( prvRegTestTask1, ( signed char * ) "Regtest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||
xTaskCreate( prvRegTestTask2, ( signed char * ) "Regtest2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||
xTaskCreate( prvErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
|
||||
|
||||
/* The suicide tasks must be started last as they record the number of other
|
||||
tasks that exist within the system. The value is then used to ensure at run
|
||||
time the number of tasks that exists is within expected bounds. */
|
||||
vCreateSuicidalTasks( mainDEATH_PRIORITY );
|
||||
|
||||
/* Now start the scheduler. Following this call the created tasks should
|
||||
be executing. */
|
||||
vTaskStartScheduler();
|
||||
|
||||
/* vTaskStartScheduler() will only return if an error occurs while the
|
||||
idle task is being created. */
|
||||
for( ;; );
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void )
|
||||
{
|
||||
portBASE_TYPE lReturn = pdPASS;
|
||||
static unsigned long ulLastRegTest1Counter= 0UL, ulLastRegTest2Counter = 0UL;
|
||||
|
||||
/* The demo tasks maintain a count that increments every cycle of the task
|
||||
provided that the task has never encountered an error. This function
|
||||
checks the counts maintained by the tasks to ensure they are still being
|
||||
incremented. A count remaining at the same value between calls therefore
|
||||
indicates that an error has been detected. */
|
||||
|
||||
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreComTestTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreSemaphoreTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreBlockingQueuesStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xIsCreateTaskStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreGenericQueueTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreQueuePeekTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
#if ( configUSE_FPU == 1 )
|
||||
if( xAreMathsTaskStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
if( xAreFlopRegisterTestsStillRunning() != pdTRUE )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Have the register test tasks found any errors? */
|
||||
if( xRegTestStatus != pdPASS )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
|
||||
/* Are the register test tasks still looping? */
|
||||
if( ulLastRegTest1Counter == ulRegTest1Counter )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ulLastRegTest1Counter = ulRegTest1Counter;
|
||||
}
|
||||
|
||||
if( ulLastRegTest2Counter == ulRegTest2Counter )
|
||||
{
|
||||
lReturn = pdFAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ulLastRegTest2Counter = ulRegTest2Counter;
|
||||
}
|
||||
|
||||
return lReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvErrorChecks( void *pvParameters )
|
||||
{
|
||||
portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
|
||||
volatile unsigned portBASE_TYPE uxFreeStack;
|
||||
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* This call is just to demonstrate the use of the function - nothing is
|
||||
done with the value. You would expect the stack high water mark to be
|
||||
lower (the function to return a larger value) here at function entry than
|
||||
later following calls to other functions. */
|
||||
uxFreeStack = uxTaskGetStackHighWaterMark( NULL );
|
||||
|
||||
/* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
|
||||
works correctly. */
|
||||
xLastExecutionTime = xTaskGetTickCount();
|
||||
|
||||
/* Cycle for ever, delaying then checking all the other tasks are still
|
||||
operating without error. */
|
||||
for( ;; )
|
||||
{
|
||||
/* Again just for demo purposes - uxFreeStack should have a lower value
|
||||
here than following the call to uxTaskGetStackHighWaterMark() on the
|
||||
task entry. */
|
||||
uxFreeStack = uxTaskGetStackHighWaterMark( NULL );
|
||||
|
||||
/* Wait until it is time to check again. The time we wait here depends
|
||||
on whether an error has been detected or not. When an error is
|
||||
detected the time is shortened resulting in a faster LED flash rate. */
|
||||
vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
|
||||
|
||||
/* See if the other tasks are all ok. */
|
||||
if( prvCheckOtherTasksAreStillRunning() != pdPASS )
|
||||
{
|
||||
/* An error occurred in one of the tasks so shorten the delay
|
||||
period - which has the effect of increasing the frequency of the
|
||||
LED toggle. */
|
||||
xDelayPeriod = mainERROR_CHECK_DELAY;
|
||||
}
|
||||
|
||||
/* Flash! */
|
||||
vParTestToggleLED( mainCHECK_TEST_LED );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSetupHardware( void )
|
||||
{
|
||||
XCache_EnableICache( 0x80000000 );
|
||||
XCache_EnableDCache( 0x80000000 );
|
||||
|
||||
/* Setup the IO port for use with the LED outputs. */
|
||||
vParTestInitialise();
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void prvRegTest1Pass( void )
|
||||
{
|
||||
/* Called from the inline assembler - this cannot be static
|
||||
otherwise it can get optimised away. */
|
||||
ulRegTest1Counter++;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void prvRegTest2Pass( void )
|
||||
{
|
||||
/* Called from the inline assembler - this cannot be static
|
||||
otherwise it can get optimised away. */
|
||||
ulRegTest2Counter++;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void prvRegTestFail( void )
|
||||
{
|
||||
/* Called from the inline assembler - this cannot be static
|
||||
otherwise it can get optimised away. */
|
||||
xRegTestStatus = pdFAIL;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRegTestTask1( void *pvParameters )
|
||||
{
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* The first register test task as described at the top of this file. The
|
||||
values used in the registers are different to those use in the second
|
||||
register test task. Also, unlike the second register test task, this task
|
||||
yields between setting the register values and subsequently checking the
|
||||
register values. */
|
||||
asm volatile
|
||||
(
|
||||
"RegTest1Start: \n\t" \
|
||||
" \n\t" \
|
||||
" li 0, 301 \n\t" \
|
||||
" mtspr 256, 0 #USPRG0 \n\t" \
|
||||
" li 0, 501 \n\t" \
|
||||
" mtspr 8, 0 #LR \n\t" \
|
||||
" li 0, 4 \n\t" \
|
||||
" mtspr 1, 0 #XER \n\t" \
|
||||
" \n\t" \
|
||||
" li 0, 1 \n\t" \
|
||||
" li 2, 2 \n\t" \
|
||||
" li 3, 3 \n\t" \
|
||||
" li 4, 4 \n\t" \
|
||||
" li 5, 5 \n\t" \
|
||||
" li 6, 6 \n\t" \
|
||||
" li 7, 7 \n\t" \
|
||||
" li 8, 8 \n\t" \
|
||||
" li 9, 9 \n\t" \
|
||||
" li 10, 10 \n\t" \
|
||||
" li 11, 11 \n\t" \
|
||||
" li 12, 12 \n\t" \
|
||||
" li 13, 13 \n\t" \
|
||||
" li 14, 14 \n\t" \
|
||||
" li 15, 15 \n\t" \
|
||||
" li 16, 16 \n\t" \
|
||||
" li 17, 17 \n\t" \
|
||||
" li 18, 18 \n\t" \
|
||||
" li 19, 19 \n\t" \
|
||||
" li 20, 20 \n\t" \
|
||||
" li 21, 21 \n\t" \
|
||||
" li 22, 22 \n\t" \
|
||||
" li 23, 23 \n\t" \
|
||||
" li 24, 24 \n\t" \
|
||||
" li 25, 25 \n\t" \
|
||||
" li 26, 26 \n\t" \
|
||||
" li 27, 27 \n\t" \
|
||||
" li 28, 28 \n\t" \
|
||||
" li 29, 29 \n\t" \
|
||||
" li 30, 30 \n\t" \
|
||||
" li 31, 31 \n\t" \
|
||||
" \n\t" \
|
||||
" sc \n\t" \
|
||||
" nop \n\t" \
|
||||
" \n\t" \
|
||||
" cmpwi 0, 1 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 2, 2 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 3, 3 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 4, 4 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 5, 5 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 6, 6 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 7, 7 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 8, 8 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 9, 9 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 10, 10 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 11, 11 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 12, 12 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 13, 13 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 14, 14 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 15, 15 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 16, 16 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 17, 17 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 18, 18 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 19, 19 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 20, 20 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 21, 21 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 22, 22 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 23, 23 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 24, 24 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 25, 25 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 26, 26 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 27, 27 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 28, 28 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 29, 29 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 30, 30 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" cmpwi 31, 31 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" \n\t" \
|
||||
" mfspr 0, 256 #USPRG0 \n\t" \
|
||||
" cmpwi 0, 301 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" mfspr 0, 8 #LR \n\t" \
|
||||
" cmpwi 0, 501 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" mfspr 0, 1 #XER \n\t" \
|
||||
" cmpwi 0, 4 \n\t" \
|
||||
" bne RegTest1Fail \n\t" \
|
||||
" \n\t" \
|
||||
" bl prvRegTest1Pass \n\t" \
|
||||
" b RegTest1Start \n\t" \
|
||||
" \n\t" \
|
||||
"RegTest1Fail: \n\t" \
|
||||
" \n\t" \
|
||||
" \n\t" \
|
||||
" bl prvRegTestFail \n\t" \
|
||||
" b RegTest1Start \n\t" \
|
||||
);
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRegTestTask2( void *pvParameters )
|
||||
{
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* The second register test task as described at the top of this file.
|
||||
Note that this task fills the registers with different values to the
|
||||
first register test task. */
|
||||
asm volatile
|
||||
(
|
||||
"RegTest2Start: \n\t" \
|
||||
" \n\t" \
|
||||
" li 0, 300 \n\t" \
|
||||
" mtspr 256, 0 #USPRG0 \n\t" \
|
||||
" li 0, 500 \n\t" \
|
||||
" mtspr 8, 0 #LR \n\t" \
|
||||
" li 0, 4 \n\t" \
|
||||
" mtspr 1, 0 #XER \n\t" \
|
||||
" \n\t" \
|
||||
" li 0, 11 \n\t" \
|
||||
" li 2, 12 \n\t" \
|
||||
" li 3, 13 \n\t" \
|
||||
" li 4, 14 \n\t" \
|
||||
" li 5, 15 \n\t" \
|
||||
" li 6, 16 \n\t" \
|
||||
" li 7, 17 \n\t" \
|
||||
" li 8, 18 \n\t" \
|
||||
" li 9, 19 \n\t" \
|
||||
" li 10, 110 \n\t" \
|
||||
" li 11, 111 \n\t" \
|
||||
" li 12, 112 \n\t" \
|
||||
" li 13, 113 \n\t" \
|
||||
" li 14, 114 \n\t" \
|
||||
" li 15, 115 \n\t" \
|
||||
" li 16, 116 \n\t" \
|
||||
" li 17, 117 \n\t" \
|
||||
" li 18, 118 \n\t" \
|
||||
" li 19, 119 \n\t" \
|
||||
" li 20, 120 \n\t" \
|
||||
" li 21, 121 \n\t" \
|
||||
" li 22, 122 \n\t" \
|
||||
" li 23, 123 \n\t" \
|
||||
" li 24, 124 \n\t" \
|
||||
" li 25, 125 \n\t" \
|
||||
" li 26, 126 \n\t" \
|
||||
" li 27, 127 \n\t" \
|
||||
" li 28, 128 \n\t" \
|
||||
" li 29, 129 \n\t" \
|
||||
" li 30, 130 \n\t" \
|
||||
" li 31, 131 \n\t" \
|
||||
" \n\t" \
|
||||
" cmpwi 0, 11 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 2, 12 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 3, 13 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 4, 14 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 5, 15 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 6, 16 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 7, 17 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 8, 18 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 9, 19 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 10, 110 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 11, 111 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 12, 112 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 13, 113 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 14, 114 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 15, 115 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 16, 116 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 17, 117 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 18, 118 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 19, 119 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 20, 120 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 21, 121 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 22, 122 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 23, 123 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 24, 124 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 25, 125 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 26, 126 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 27, 127 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 28, 128 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 29, 129 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 30, 130 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" cmpwi 31, 131 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" \n\t" \
|
||||
" mfspr 0, 256 #USPRG0 \n\t" \
|
||||
" cmpwi 0, 300 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" mfspr 0, 8 #LR \n\t" \
|
||||
" cmpwi 0, 500 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" mfspr 0, 1 #XER \n\t" \
|
||||
" cmpwi 0, 4 \n\t" \
|
||||
" bne RegTest2Fail \n\t" \
|
||||
" \n\t" \
|
||||
" bl prvRegTest2Pass \n\t" \
|
||||
" b RegTest2Start \n\t" \
|
||||
" \n\t" \
|
||||
"RegTest2Fail: \n\t" \
|
||||
" \n\t" \
|
||||
" \n\t" \
|
||||
" bl prvRegTestFail \n\t" \
|
||||
" b RegTest2Start \n\t" \
|
||||
);
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* This hook function will get called if there is a suspected stack overflow.
|
||||
An overflow can cause the task name to be corrupted, in which case the task
|
||||
handle needs to be used to determine the offending task. */
|
||||
void vApplicationStackOverflowHook( xTaskHandle xTask, signed char *pcTaskName );
|
||||
void vApplicationStackOverflowHook( xTaskHandle xTask, signed char *pcTaskName )
|
||||
{
|
||||
/* To prevent the optimiser removing the variables. */
|
||||
volatile xTaskHandle xTaskIn = xTask;
|
||||
volatile signed char *pcTaskNameIn = pcTaskName;
|
||||
|
||||
/* Remove compiler warnings. */
|
||||
( void ) xTaskIn;
|
||||
( void ) pcTaskNameIn;
|
||||
|
||||
/* The following three calls are simply to stop compiler warnings about the
|
||||
functions not being used - they are called from the inline assembly. */
|
||||
prvRegTest1Pass();
|
||||
prvRegTest2Pass();
|
||||
prvRegTestFail();
|
||||
|
||||
for( ;; );
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
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 application includes. */
|
||||
#include "partest.h"
|
||||
|
||||
/* Library includes. */
|
||||
#include "xparameters.h"
|
||||
#include "xgpio_l.h"
|
||||
|
||||
/* Misc hardware specific definitions. */
|
||||
#define partstALL_AS_OUTPUT 0x00
|
||||
#define partstCHANNEL_1 0x01
|
||||
#define partstMAX_8BIT_LED 0x07
|
||||
|
||||
/* The outputs are split into two IO sections, these variables maintain the
|
||||
current value of either section. */
|
||||
static unsigned portBASE_TYPE uxCurrentOutput8Bit, uxCurrentOutput5Bit;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/*
|
||||
* Setup the IO for the LED outputs.
|
||||
*/
|
||||
void vParTestInitialise( void )
|
||||
{
|
||||
/* Set both sets of LED's on the demo board to outputs. */
|
||||
XGpio_mSetDataDirection( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );
|
||||
XGpio_mSetDataDirection( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );
|
||||
|
||||
/* Start with all outputs off. */
|
||||
uxCurrentOutput8Bit = 0;
|
||||
XGpio_mSetDataReg( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, 0x00 );
|
||||
uxCurrentOutput5Bit = 0;
|
||||
XGpio_mSetDataReg( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, 0x00 );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
|
||||
{
|
||||
unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;
|
||||
|
||||
portENTER_CRITICAL();
|
||||
{
|
||||
/* Which IO section does the LED being set/cleared belong to? The
|
||||
4 bit or 5 bit outputs? */
|
||||
if( uxLED <= partstMAX_8BIT_LED )
|
||||
{
|
||||
uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;
|
||||
puxCurrentValue = &uxCurrentOutput5Bit;
|
||||
}
|
||||
else
|
||||
{
|
||||
uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;
|
||||
puxCurrentValue = &uxCurrentOutput8Bit;
|
||||
uxLED -= partstMAX_8BIT_LED;
|
||||
}
|
||||
|
||||
/* Setup the bit mask accordingly. */
|
||||
uxLED = 0x01 << uxLED;
|
||||
|
||||
/* Maintain the current output value. */
|
||||
if( xValue )
|
||||
{
|
||||
*puxCurrentValue |= uxLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
*puxCurrentValue &= ~uxLED;
|
||||
}
|
||||
|
||||
/* Write the value to the port. */
|
||||
XGpio_mSetDataReg( uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );
|
||||
}
|
||||
portEXIT_CRITICAL();
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
|
||||
{
|
||||
unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;
|
||||
|
||||
portENTER_CRITICAL();
|
||||
{
|
||||
/* Which IO section does the LED being toggled belong to? The
|
||||
4 bit or 5 bit outputs? */
|
||||
if( uxLED <= partstMAX_8BIT_LED )
|
||||
{
|
||||
|
||||
uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;
|
||||
puxCurrentValue = &uxCurrentOutput5Bit;
|
||||
}
|
||||
else
|
||||
{
|
||||
uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;
|
||||
puxCurrentValue = &uxCurrentOutput8Bit;
|
||||
uxLED -= partstMAX_8BIT_LED;
|
||||
}
|
||||
|
||||
/* Setup the bit mask accordingly. */
|
||||
uxLED = 0x01 << uxLED;
|
||||
|
||||
/* Maintain the current output value. */
|
||||
if( *puxCurrentValue & uxLED )
|
||||
{
|
||||
*puxCurrentValue &= ~uxLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
*puxCurrentValue |= uxLED;
|
||||
}
|
||||
|
||||
/* Write the value to the port. */
|
||||
XGpio_mSetDataReg(uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );
|
||||
}
|
||||
portEXIT_CRITICAL();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,250 @@
|
|||
/*
|
||||
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 FOR UART
|
||||
*/
|
||||
|
||||
/* Scheduler includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Demo application includes. */
|
||||
#include "serial.h"
|
||||
|
||||
/* Library includes. */
|
||||
#include "xparameters.h"
|
||||
#include "xuartlite.h"
|
||||
#include "xuartlite_l.h"
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Queues used to hold received characters, and characters waiting to be
|
||||
transmitted. */
|
||||
static xQueueHandle xRxedChars;
|
||||
static xQueueHandle xCharsForTx;
|
||||
|
||||
/* Structure that maintains information on the UART being used. */
|
||||
static XUartLite xUART;
|
||||
|
||||
/*
|
||||
* Sample UART interrupt handler. Note this is used to demonstrate the kernel
|
||||
* features and test the port - it is not intended to represent an efficient
|
||||
* implementation.
|
||||
*/
|
||||
static void vSerialISR( XUartLite *pxUART );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
|
||||
{
|
||||
/* NOTE: The baud rate used by this driver is determined by the hardware
|
||||
parameterization of the UART Lite peripheral, and the baud value passed to
|
||||
this function has no effect. */
|
||||
( void ) ulWantedBaud;
|
||||
|
||||
/* 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 ) );
|
||||
|
||||
/* Only initialise the UART if the queues were created correctly. */
|
||||
if( ( xRxedChars != NULL ) && ( xCharsForTx != NULL ) )
|
||||
{
|
||||
|
||||
XUartLite_Initialize( &xUART, XPAR_RS232_UART_1_DEVICE_ID );
|
||||
XUartLite_ResetFifos( &xUART );
|
||||
XUartLite_DisableInterrupt( &xUART );
|
||||
|
||||
if( xPortInstallInterruptHandler( XPAR_XPS_INTC_0_RS232_UART_1_INTERRUPT_INTR, ( XInterruptHandler )vSerialISR, (void *)&xUART ) == pdPASS )
|
||||
{
|
||||
/* xPortInstallInterruptHandler() could fail if
|
||||
vPortSetupInterruptController() has not been called prior to this
|
||||
function. */
|
||||
XUartLite_EnableInterrupt( &xUART );
|
||||
}
|
||||
}
|
||||
|
||||
/* There is only one port so the handle is not used. */
|
||||
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 one UART. */
|
||||
( 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 )
|
||||
{
|
||||
portBASE_TYPE xReturn = pdTRUE;
|
||||
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pxPort;
|
||||
|
||||
portENTER_CRITICAL();
|
||||
{
|
||||
/* If the UART FIFO is full we can block posting the new data on the
|
||||
Tx queue. */
|
||||
if( XUartLite_mIsTransmitFull( XPAR_RS232_UART_1_BASEADDR ) )
|
||||
{
|
||||
if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
}
|
||||
}
|
||||
/* Otherwise, if there is data already in the queue we should add the
|
||||
new data to the back of the queue to ensure the sequencing is
|
||||
maintained. */
|
||||
else if( uxQueueMessagesWaiting( xCharsForTx ) )
|
||||
{
|
||||
if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
}
|
||||
}
|
||||
/* If the UART FIFO is not full and there is no data already in the
|
||||
queue we can write directly to the FIFO without disrupting the
|
||||
sequence. */
|
||||
else
|
||||
{
|
||||
XIo_Out32( XPAR_RS232_UART_1_BASEADDR + XUL_TX_FIFO_OFFSET, cOutChar );
|
||||
}
|
||||
}
|
||||
portEXIT_CRITICAL();
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vSerialClose( xComPortHandle xPort )
|
||||
{
|
||||
/* Not supported as not required by the demo application. */
|
||||
( void ) xPort;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vSerialISR( XUartLite *pxUART )
|
||||
{
|
||||
unsigned long ulISRStatus;
|
||||
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE, lDidSomething;
|
||||
char cChar;
|
||||
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pxUART;
|
||||
|
||||
do
|
||||
{
|
||||
lDidSomething = pdFALSE;
|
||||
|
||||
ulISRStatus = XIo_In32( XPAR_RS232_UART_1_BASEADDR + XUL_STATUS_REG_OFFSET );
|
||||
|
||||
if( ( ulISRStatus & XUL_SR_RX_FIFO_VALID_DATA ) != 0 )
|
||||
{
|
||||
/* A character is available - place it in the queue of received
|
||||
characters. This might wake a task that was blocked waiting for
|
||||
data. */
|
||||
cChar = ( char ) XIo_In32( XPAR_RS232_UART_1_BASEADDR + XUL_RX_FIFO_OFFSET );
|
||||
xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
|
||||
lDidSomething = pdTRUE;
|
||||
}
|
||||
|
||||
if( ( ulISRStatus & XUL_SR_TX_FIFO_EMPTY ) != 0 )
|
||||
{
|
||||
/* There is space in the FIFO - if there are any characters queue for
|
||||
transmission they can be sent to the UART now. This might unblock a
|
||||
task that was waiting for space to become available on the Tx queue. */
|
||||
if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
|
||||
{
|
||||
XIo_Out32( XPAR_RS232_UART_1_BASEADDR + XUL_TX_FIFO_OFFSET, cChar );
|
||||
lDidSomething = pdTRUE;
|
||||
}
|
||||
}
|
||||
} while( lDidSomething == pdTRUE );
|
||||
|
||||
/* If we woke any tasks we may require a context switch. */
|
||||
if( xHigherPriorityTaskWoken )
|
||||
{
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue