Before changing headers to V6 and changing portLONG, portSHORt and portCHAR to their standard C types.

This commit is contained in:
Richard Barry 2009-10-05 08:33:08 +00:00
parent 3dfbb349ca
commit 5c64e1fad9
4417 changed files with 1261274 additions and 0 deletions

View file

@ -0,0 +1,102 @@
/*
FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
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.
Alternative commercial license and support terms are also available upon
request. See the licensing section of http://www.FreeRTOS.org for full
license details.
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 along
with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA.
***************************************************************************
* *
* Looking for a quick start? Then check out the FreeRTOS eBook! *
* See http://www.FreeRTOS.org/Documentation for details *
* *
***************************************************************************
1 tab == 4 spaces!
Please ensure to read the configuration and relevant port sections of the
online documentation.
http://www.FreeRTOS.org - Documentation, latest information, license and
contact details.
http://www.SafeRTOS.com - A version that is certified for use in safety
critical systems.
http://www.OpenRTOS.com - Commercial support, development, porting,
licensing and training services.
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <conio.h>
/*-----------------------------------------------------------
* Application specific definitions for the x86 port.
*----------------------------------------------------------*/
/* These are the only definitions that can be modified!. */
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 10 )
#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 128 ) /* This can be made smaller if required. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 32 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* The maximum number of characters a task name can take,
including the null terminator. */
#define configMAX_TASK_NAME_LEN ( 16 )
/* Set the following definitions to 1 to include the component, or zero
to exclude the component. */
/* Include/exclude the stated API function. */
#define INCLUDE_vTaskPrioritySet 0
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
/* Use/don't use the trace visualisation. */
#define configUSE_TRACE_FACILITY 0
/*
* The tick count (and times defined in tick count units) can be either a 16bit
* or a 32 bit value. See documentation on http://www.FreeRTOS.org to decide
* which to use.
*/
#define configUSE_16_BIT_TICKS 1
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,121 @@
/*
FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
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.
Alternative commercial license and support terms are also available upon
request. See the licensing section of http://www.FreeRTOS.org for full
license details.
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 along
with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA.
***************************************************************************
* *
* Looking for a quick start? Then check out the FreeRTOS eBook! *
* See http://www.FreeRTOS.org/Documentation for details *
* *
***************************************************************************
1 tab == 4 spaces!
Please ensure to read the configuration and relevant port sections of the
online documentation.
http://www.FreeRTOS.org - Documentation, latest information, license and
contact details.
http://www.SafeRTOS.com - A version that is certified for use in safety
critical systems.
http://www.OpenRTOS.com - Commercial support, development, porting,
licensing and training services.
*/
#include <stdio.h>
#include <conio.h>
#include <string.h>
/* Scheduler include files. */
#include "FreeRTOS.h"
#include "task.h"
/* Demo program include files. */
#include "fileio.h"
void vDisplayMessage( const portCHAR * const pcMessageToPrint )
{
#ifdef USE_STDIO
taskENTER_CRITICAL();
printf( "%s", pcMessageToPrint );
fflush( stdout );
taskEXIT_CRITICAL();
#else
/* Stop warnings. */
( void ) pcMessageToPrint;
#endif
}
/*-----------------------------------------------------------*/
void vWriteMessageToDisk( const portCHAR * const pcMessage )
{
#ifdef USE_STDIO
const portCHAR * const pcFileName = "c:\\RTOSlog.txt";
const portCHAR * const pcSeparator = "\r\n-----------------------\r\n";
FILE *pf;
taskENTER_CRITICAL();
{
pf = fopen( pcFileName, "a" );
if( pf != NULL )
{
fwrite( pcMessage, strlen( pcMessage ), ( unsigned portSHORT ) 1, pf );
fwrite( pcSeparator, strlen( pcSeparator ), ( unsigned portSHORT ) 1, pf );
fclose( pf );
}
}
taskEXIT_CRITICAL();
#else
/* Stop warnings. */
( void ) pcMessage;
#endif /*USE_STDIO*/
}
/*-----------------------------------------------------------*/
void vWriteBufferToDisk( const portCHAR * const pcBuffer, unsigned portLONG ulBufferLength )
{
#ifdef USE_STDIO
const portCHAR * const pcFileName = "c:\\trace.bin";
FILE *pf;
taskENTER_CRITICAL();
{
pf = fopen( pcFileName, "wb" );
if( pf )
{
fwrite( pcBuffer, ( size_t ) ulBufferLength, ( unsigned portSHORT ) 1, pf );
fclose( pf );
}
}
taskEXIT_CRITICAL();
#else
/* Stop warnings. */
( void ) pcBuffer;
( void ) ulBufferLength;
#endif /*USE_STDIO*/
}

View file

@ -0,0 +1,96 @@
/*
FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
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.
Alternative commercial license and support terms are also available upon
request. See the licensing section of http://www.FreeRTOS.org for full
license details.
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 along
with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA.
***************************************************************************
* *
* Looking for a quick start? Then check out the FreeRTOS eBook! *
* See http://www.FreeRTOS.org/Documentation for details *
* *
***************************************************************************
1 tab == 4 spaces!
Please ensure to read the configuration and relevant port sections of the
online documentation.
http://www.FreeRTOS.org - Documentation, latest information, license and
contact details.
http://www.SafeRTOS.com - A version that is certified for use in safety
critical systems.
http://www.OpenRTOS.com - Commercial support, development, porting,
licensing and training services.
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <i86.h>
#include <conio.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 configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 10 )
#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 128 ) /* This can be made smaller if required. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 32 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 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. */
#define INCLUDE_vTaskPrioritySet 0
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,145 @@
/*
FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
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.
Alternative commercial license and support terms are also available upon
request. See the licensing section of http://www.FreeRTOS.org for full
license details.
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 along
with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA.
***************************************************************************
* *
* Looking for a quick start? Then check out the FreeRTOS eBook! *
* See http://www.FreeRTOS.org/Documentation for details *
* *
***************************************************************************
1 tab == 4 spaces!
Please ensure to read the configuration and relevant port sections of the
online documentation.
http://www.FreeRTOS.org - Documentation, latest information, license and
contact details.
http://www.SafeRTOS.com - A version that is certified for use in safety
critical systems.
http://www.OpenRTOS.com - Commercial support, development, porting,
licensing and training services.
*/
/*
Changes from V1.01:
+ Types used updated.
+ Add vParTestToggleLED();
Changes from V2.0.0
+ Use scheduler suspends in place of critical sections.
*/
#include "FreeRTOS.h"
#include "task.h"
#include "partest.h"
#define partstALL_OUTPUTS_OFF ( ( unsigned portSHORT) 0x00 )
#define partstMAX_OUTPUT_LED ( ( unsigned portCHAR ) 7 )
#define partstPORT_F_ADDR ( ( unsigned portSHORT ) 0x605 )
#define partstPORT_DIRECTION_REG ( ( unsigned portSHORT ) 0x606 )
#define partstPORT_F_DIR_BIT ( ( unsigned portSHORT ) 0x20 )
/*lint -e956 File scope parameters okay here. */
static volatile unsigned portCHAR ucCurrentOutputValue = partstALL_OUTPUTS_OFF;
/*lint +e956 */
/*-----------------------------------------------------------
* Simple parallel port IO routines.
*-----------------------------------------------------------*/
void vParTestInitialise( void )
{
unsigned portSHORT usInput;
ucCurrentOutputValue = partstALL_OUTPUTS_OFF;
/* Set the direction to output for port F. */
usInput = portINPUT_BYTE( partstPORT_DIRECTION_REG );
usInput |= partstPORT_F_DIR_BIT;
portOUTPUT_BYTE( partstPORT_DIRECTION_REG, usInput );
/* Start with all outputs off. */
portOUTPUT_BYTE( partstPORT_F_ADDR, partstALL_OUTPUTS_OFF );
}
/*-----------------------------------------------------------*/
void vParTestSetLED( unsigned portBASE_TYPE uxLED, portBASE_TYPE xValue )
{
unsigned portCHAR ucBit = ( unsigned portCHAR ) 1;
if( uxLED <= partstMAX_OUTPUT_LED )
{
ucBit <<= uxLED;
}
vTaskSuspendAll();
{
if( xValue == pdTRUE )
{
ucBit ^= ( unsigned portCHAR ) 0xff;
ucCurrentOutputValue &= ucBit;
}
else
{
ucCurrentOutputValue |= ucBit;
}
portOUTPUT_BYTE( partstPORT_F_ADDR, ( unsigned ) ucCurrentOutputValue );
}
xTaskResumeAll();
}
/*-----------------------------------------------------------*/
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{
unsigned portCHAR ucBit;
if( uxLED <= partstMAX_OUTPUT_LED )
{
ucBit = ( ( unsigned portCHAR ) 1 ) << uxLED;
vTaskSuspendAll();
{
if( ucCurrentOutputValue & ucBit )
{
ucCurrentOutputValue &= ~ucBit;
}
else
{
ucCurrentOutputValue |= ucBit;
}
portOUTPUT_BYTE( partstPORT_F_ADDR, ( unsigned ) ucCurrentOutputValue );
}
xTaskResumeAll();
}
}

Binary file not shown.

View file

@ -0,0 +1,400 @@
/*
FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
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.
Alternative commercial license and support terms are also available upon
request. See the licensing section of http://www.FreeRTOS.org for full
license details.
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 along
with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA.
***************************************************************************
* *
* Looking for a quick start? Then check out the FreeRTOS eBook! *
* See http://www.FreeRTOS.org/Documentation for details *
* *
***************************************************************************
1 tab == 4 spaces!
Please ensure to read the configuration and relevant port sections of the
online documentation.
http://www.FreeRTOS.org - Documentation, latest information, license and
contact details.
http://www.SafeRTOS.com - A version that is certified for use in safety
critical systems.
http://www.OpenRTOS.com - Commercial support, development, porting,
licensing and training services.
*/
/*
* Creates all the demo application tasks, then starts the scheduler.
*
* Main. c also creates a task called "Print". This only executes every five
* 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.
* Nearly all the tasks in the demo application maintain a unique count that is
* incremented each time the task successfully completes its function. Should any
* error occur within the task the count is permanently halted. The print task
* checks the count of each task to ensure it has changed since the last time the
* print task executed. If any count is found not to have changed the print task
* displays an appropriate message, halts, and flashes the on board LED rapidly.
* If all the tasks are still incrementing their unique counts the print task
* displays an "OK" message.
*
* The LED flash tasks do not maintain a count as they already provide visual
* feedback of their status.
*
* The print task blocks on the queue into which messages that require displaying
* are posted. It will therefore only block for the full 5 seconds if no messages
* are posted onto the queue.
*
* Main. c also provides a demonstration of how the trace visualisation utility can
* be used, and how the scheduler can be stopped.
*
* On the Flashlite it is preferable not to try to write to the console during
* real time operation. The built in LED is toggled every cycle of the print task
* that does not encounter any errors, so the console IO may be removed if required.
* The build in LED will start flashing rapidly if any task reports an error.
*/
/*
Changes from V1.01:
+ Previously, if an error occurred in a task the on board LED was stopped from
toggling. Now if an error occurs the check task enters an infinite loop,
toggling the LED rapidly.
Changes from V1.2.3
+ The integer and comtest tasks are now used when the cooperative scheduler
is being used. Previously they were only used with the preemptive
scheduler.
Changes from V1.2.5
+ Made the communications RX task a higher priority.
Changes from V2.0.0
+ Delay periods are now specified using variables and constants of
portTickType rather than unsigned portLONG.
*/
#include <stdlib.h>
#include <conio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "partest.h"
#include "serial.h"
/* Demo file headers. */
#include "BlockQ.h"
#include "PollQ.h"
#include "death.h"
#include "flash.h"
#include "integer.h"
#include "print.h"
#include "comtest.h"
#include "fileio.h"
#include "semtest.h"
/* Priority definitions for all the tasks in the demo application. */
#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define mainPRINT_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define mainSEMAPHORE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainPRINT_STACK_SIZE ( ( unsigned portSHORT ) 256 )
#define mainDEBUG_LOG_BUFFER_SIZE ( ( unsigned portSHORT ) 20480 )
/* Constant definitions for accessing the build in LED on the Flashlite 186. */
#define mainLED_REG_DIR ( ( unsigned portSHORT ) 0xff78 )
#define mainLED_REG ( ( unsigned portSHORT ) 0xff7a )
/* If an error is detected in a task then the vErrorChecks() task will enter
an infinite loop flashing the LED at this rate. */
#define mainERROR_FLASH_RATE ( ( portTickType ) 100 / portTICK_RATE_MS )
/* Task function for the "Print" task as described at the top of the file. */
static void vErrorChecks( void *pvParameters );
/* Function that checks the unique count of all the other tasks as described at
the top of the file. */
static void prvCheckOtherTasksAreStillRunning( void );
/* Functions to setup and use the built in LED on the Flashlite 186 board. */
static void prvToggleLED( void );
static void prvInitLED( void );
/* Key presses can be used to start/stop the trace visualisation utility or stop
the scheduler. */
static void prvCheckForKeyPresses( void );
/* Buffer used by the trace visualisation utility. */
static portCHAR pcWriteBuffer[ mainDEBUG_LOG_BUFFER_SIZE ];
/*-----------------------------------------------------------*/
portSHORT main( void )
{
/* Initialise hardware and utilities. */
vParTestInitialise();
vPrintInitialise();
prvInitLED();
/* CREATE ALL THE DEMO APPLICATION TASKS. */
vStartComTestTasks( mainCOM_TEST_PRIORITY, serCOM2, ser38400 );
vStartIntegerMathTasks( tskIDLE_PRIORITY );
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
vStartSemaphoreTasks( mainSEMAPHORE_TASK_PRIORITY );
/* Create the "Print" task as described at the top of the file. */
xTaskCreate( vErrorChecks, "Print", mainPRINT_STACK_SIZE, NULL, mainPRINT_TASK_PRIORITY, NULL );
/* This task has to be created last as it keeps account of the number of tasks
it expects to see running. */
vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
/* Set the scheduler running. This function will not return unless a task
calls vTaskEndScheduler(). */
vTaskStartScheduler();
return 1;
}
/*-----------------------------------------------------------*/
static void vErrorChecks( void *pvParameters )
{
portTickType xExpectedWakeTime;
const portTickType xPrintRate = ( portTickType ) 5000 / portTICK_RATE_MS;
const portLONG lMaxAllowableTimeDifference = ( portLONG ) 0;
portTickType xWakeTime;
portLONG lTimeDifference;
const portCHAR *pcReceivedMessage;
const portCHAR * const pcTaskBlockedTooLongMsg = "Print task blocked too long!\r\n";
/* Stop warnings. */
( void ) pvParameters;
/* Loop continuously, blocking, then checking all the other tasks are still
running, before blocking once again. This task blocks on the queue of messages
that require displaying so will wake either by its time out expiring, or a
message becoming available. */
for( ;; )
{
/* Calculate the time we will unblock if no messages are received
on the queue. This is used to check that we have not blocked for too long. */
xExpectedWakeTime = xTaskGetTickCount();
xExpectedWakeTime += xPrintRate;
/* Block waiting for either a time out or a message to be posted that
required displaying. */
pcReceivedMessage = pcPrintGetNextMessage( xPrintRate );
/* Was a message received? */
if( pcReceivedMessage == NULL )
{
/* A message was not received so we timed out, did we unblock at the
expected time? */
xWakeTime = xTaskGetTickCount();
/* Calculate the difference between the time we unblocked and the
time we should have unblocked. */
if( xWakeTime > xExpectedWakeTime )
{
lTimeDifference = ( portLONG ) ( xWakeTime - xExpectedWakeTime );
}
else
{
lTimeDifference = ( portLONG ) ( xExpectedWakeTime - xWakeTime );
}
if( lTimeDifference > lMaxAllowableTimeDifference )
{
/* We blocked too long - create a message that will get
printed out the next time around. */
vPrintDisplayMessage( &pcTaskBlockedTooLongMsg );
}
/* Check the other tasks are still running, just in case. */
prvCheckOtherTasksAreStillRunning();
}
else
{
/* We unblocked due to a message becoming available. Send the message
for printing. */
vDisplayMessage( pcReceivedMessage );
}
/* Key presses are used to invoke the trace visualisation utility, or
end the program. */
prvCheckForKeyPresses();
}
} /*lint !e715 !e818 pvParameters is not used but all task functions must take this form. */
/*-----------------------------------------------------------*/
static void prvCheckForKeyPresses( void )
{
#ifdef USE_STDIO
portSHORT sIn;
taskENTER_CRITICAL();
sIn = kbhit();
taskEXIT_CRITICAL();
if( sIn )
{
unsigned portLONG ulBufferLength;
/* Key presses can be used to start/stop the trace utility, or end the
program. */
sIn = getch();
switch( sIn )
{
/* Only define keys for turning on and off the trace if the trace
is being used. */
#if configUSE_TRACE_FACILITY == 1
case 't' : vTaskList( pcWriteBuffer );
vWriteMessageToDisk( pcWriteBuffer );
break;
case 's' : vTaskStartTrace( pcWriteBuffer, mainDEBUG_LOG_BUFFER_SIZE );
break;
case 'e' : ulBufferLength = ulTaskEndTrace();
vWriteBufferToDisk( pcWriteBuffer, ulBufferLength );
break;
#endif
default : vTaskEndScheduler();
break;
}
}
#else
( void ) pcWriteBuffer;
#endif
}
/*-----------------------------------------------------------*/
static void prvCheckOtherTasksAreStillRunning( void )
{
portSHORT sErrorHasOccurred = pdFALSE;
if( xAreComTestTasksStillRunning() != pdTRUE )
{
vDisplayMessage( "Com test count unchanged!\r\n" );
sErrorHasOccurred = pdTRUE;
}
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
{
vDisplayMessage( "Integer maths task count unchanged!\r\n" );
sErrorHasOccurred = pdTRUE;
}
if( xAreBlockingQueuesStillRunning() != pdTRUE )
{
vDisplayMessage( "Blocking queues count unchanged!\r\n" );
sErrorHasOccurred = pdTRUE;
}
if( xArePollingQueuesStillRunning() != pdTRUE )
{
vDisplayMessage( "Polling queue count unchanged!\r\n" );
sErrorHasOccurred = pdTRUE;
}
if( xIsCreateTaskStillRunning() != pdTRUE )
{
vDisplayMessage( "Incorrect number of tasks running!\r\n" );
sErrorHasOccurred = pdTRUE;
}
if( xAreSemaphoreTasksStillRunning() != pdTRUE )
{
vDisplayMessage( "Semaphore take count unchanged!\r\n" );
sErrorHasOccurred = pdTRUE;
}
if( sErrorHasOccurred == pdFALSE )
{
vDisplayMessage( "OK " );
/* Toggle the LED if everything is okay so we know if an error occurs even if not
using console IO. */
prvToggleLED();
}
else
{
for( ;; )
{
/* An error has occurred in one of the tasks. Don't go any further and
flash the LED rapidly in case console IO is not being used. */
prvToggleLED();
vTaskDelay( mainERROR_FLASH_RATE );
}
}
}
/*-----------------------------------------------------------*/
static void prvInitLED( void )
{
unsigned portSHORT usPortDirection;
const unsigned portSHORT usLEDOut = 0x400;
/* Set the LED bit to an output. */
usPortDirection = inpw( mainLED_REG_DIR );
usPortDirection &= ~usLEDOut;
outpw( mainLED_REG_DIR, usPortDirection );
}
/*-----------------------------------------------------------*/
static void prvToggleLED( void )
{
static portSHORT sLED = pdTRUE;
unsigned portSHORT usLEDState;
const unsigned portSHORT usLEDBit = 0x400;
/* Flip the state of the LED. */
usLEDState = inpw( mainLED_REG );
if( sLED )
{
usLEDState &= ~usLEDBit;
}
else
{
usLEDState |= usLEDBit;
}
outpw( mainLED_REG, usLEDState );
sLED = !sLED;
}

Binary file not shown.

View file

@ -0,0 +1,2 @@
FIL list.obj,heap_2.obj,portcomn.obj,port.obj,queue.obj,tasks.obj,blockq.obj,comtest.obj,death.obj,flash.obj,integer.obj,pollq.obj,print.obj,semtest.obj,fileio.obj,main.obj,partest.obj,serial.obj

View file

@ -0,0 +1,3 @@
project : E:\Dev\FreeRTOS\Demo\Flshlite\rtosdemo.exe .SYMBOLIC
!include E:\Dev\FreeRTOS\Demo\Flshlite\rtosdemo.mk1

View file

@ -0,0 +1,191 @@
!define BLANK ""
E:\Dev\FreeRTOS\Demo\Flshlite\list.obj : E:\Dev\FreeRTOS\source\list.c .AUTO&
DEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\..\source\list.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\..\&
source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za -s&
-dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos -m&
l
E:\Dev\FreeRTOS\Demo\Flshlite\heap_2.obj : E:\Dev\FreeRTOS\SOURCE\PORTABLE\M&
EMMANG\heap_2.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\..\SOURCE\PORTABLE\MEMMANG\heap_2.c -i=D:\DEVTOOLS\OPENWA~1\h;..\co&
mmon\include;..\..\source\include;..\..\source\portable\owatcom\16bitdos\com&
mon -w4 -e25 -za -s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fp&
c -zu -1 -bt=dos -ml
E:\Dev\FreeRTOS\Demo\Flshlite\portcomn.obj : E:\Dev\FreeRTOS\source\portable&
\owatcom\16bitdos\common\portcomn.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\..\source\portable\owatcom\16bitdos\common\portcomn.c -i=D:\DEVTOOL&
S\OPENWA~1\h;..\common\include;..\..\source\include;..\..\source\portable\ow&
atcom\16bitdos\common -w4 -e25 -za -s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -&
zq -otexan -of -fpc -zu -1 -bt=dos -ml
E:\Dev\FreeRTOS\Demo\Flshlite\port.obj : E:\Dev\FreeRTOS\source\portable\owa&
tcom\16bitdos\flsh186\port.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\..\source\portable\owatcom\16bitdos\flsh186\port.c -i=D:\DEVTOOLS\O&
PENWA~1\h;..\common\include;..\..\source\include;..\..\source\portable\owatc&
om\16bitdos\common -w4 -e25 -za -s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq &
-otexan -of -fpc -zu -1 -bt=dos -ml
E:\Dev\FreeRTOS\Demo\Flshlite\queue.obj : E:\Dev\FreeRTOS\source\queue.c .AU&
TODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\..\source\queue.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\..&
\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za -&
s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos -&
ml
E:\Dev\FreeRTOS\Demo\Flshlite\tasks.obj : E:\Dev\FreeRTOS\source\tasks.c .AU&
TODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\..\source\tasks.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\..&
\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za -&
s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos -&
ml
E:\Dev\FreeRTOS\Demo\Flshlite\blockq.obj : E:\Dev\FreeRTOS\Demo\common\full\&
blockq.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\common\full\blockq.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..&
\..\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -z&
a -s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=do&
s -ml
E:\Dev\FreeRTOS\Demo\Flshlite\comtest.obj : E:\Dev\FreeRTOS\Demo\common\full&
\comtest.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\common\full\comtest.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;.&
.\..\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -&
za -s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=d&
os -ml
E:\Dev\FreeRTOS\Demo\Flshlite\death.obj : E:\Dev\FreeRTOS\Demo\common\full\d&
eath.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\common\full\death.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\&
..\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za&
-s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos&
-ml
E:\Dev\FreeRTOS\Demo\Flshlite\flash.obj : E:\Dev\FreeRTOS\Demo\common\full\f&
lash.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\common\full\flash.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\&
..\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za&
-s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos&
-ml
E:\Dev\FreeRTOS\Demo\Flshlite\integer.obj : E:\Dev\FreeRTOS\Demo\common\full&
\integer.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\common\full\integer.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;.&
.\..\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -&
za -s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=d&
os -ml
E:\Dev\FreeRTOS\Demo\Flshlite\pollq.obj : E:\Dev\FreeRTOS\Demo\common\full\p&
ollq.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\common\full\pollq.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\&
..\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za&
-s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos&
-ml
E:\Dev\FreeRTOS\Demo\Flshlite\print.obj : E:\Dev\FreeRTOS\Demo\common\full\p&
rint.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\common\full\print.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\&
..\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za&
-s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos&
-ml
E:\Dev\FreeRTOS\Demo\Flshlite\semtest.obj : E:\Dev\FreeRTOS\Demo\common\full&
\semtest.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc ..\common\full\semtest.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;.&
.\..\source\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -&
za -s -dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=d&
os -ml
E:\Dev\FreeRTOS\Demo\Flshlite\fileio.obj : E:\Dev\FreeRTOS\Demo\Flshlite\fil&
eio\fileio.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc fileio\fileio.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\..\sour&
ce\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za -s -dO&
PEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos -ml
E:\Dev\FreeRTOS\Demo\Flshlite\main.obj : E:\Dev\FreeRTOS\Demo\Flshlite\main.&
c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc main.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\..\source\includ&
e;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za -s -dOPEN_WATCO&
M_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos -ml
E:\Dev\FreeRTOS\Demo\Flshlite\partest.obj : E:\Dev\FreeRTOS\Demo\Flshlite\pa&
rtest\partest.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc partest\partest.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\..\so&
urce\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za -s -&
dOPEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos -ml
E:\Dev\FreeRTOS\Demo\Flshlite\serial.obj : E:\Dev\FreeRTOS\Demo\Flshlite\ser&
ial\serial.c .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
*wcc serial\serial.c -i=D:\DEVTOOLS\OPENWA~1\h;..\common\include;..\..\sour&
ce\include;..\..\source\portable\owatcom\16bitdos\common -w4 -e25 -za -s -dO&
PEN_WATCOM_FLASH_LITE_186_PORT -j -zq -otexan -of -fpc -zu -1 -bt=dos -ml
E:\Dev\FreeRTOS\Demo\Flshlite\rtosdemo.exe : E:\Dev\FreeRTOS\Demo\Flshlite\l&
ist.obj E:\Dev\FreeRTOS\Demo\Flshlite\heap_2.obj E:\Dev\FreeRTOS\Demo\Flshli&
te\portcomn.obj E:\Dev\FreeRTOS\Demo\Flshlite\port.obj E:\Dev\FreeRTOS\Demo\&
Flshlite\queue.obj E:\Dev\FreeRTOS\Demo\Flshlite\tasks.obj E:\Dev\FreeRTOS\D&
emo\Flshlite\blockq.obj E:\Dev\FreeRTOS\Demo\Flshlite\comtest.obj E:\Dev\Fre&
eRTOS\Demo\Flshlite\death.obj E:\Dev\FreeRTOS\Demo\Flshlite\flash.obj E:\Dev&
\FreeRTOS\Demo\Flshlite\integer.obj E:\Dev\FreeRTOS\Demo\Flshlite\pollq.obj &
E:\Dev\FreeRTOS\Demo\Flshlite\print.obj E:\Dev\FreeRTOS\Demo\Flshlite\semtes&
t.obj E:\Dev\FreeRTOS\Demo\Flshlite\fileio.obj E:\Dev\FreeRTOS\Demo\Flshlite&
\main.obj E:\Dev\FreeRTOS\Demo\Flshlite\partest.obj E:\Dev\FreeRTOS\Demo\Fls&
hlite\serial.obj E:\Dev\FreeRTOS\source\include\list.h E:\Dev\FreeRTOS\sourc&
e\include\portable.h E:\Dev\FreeRTOS\source\include\projdefs.h E:\Dev\FreeRT&
OS\source\include\queue.h E:\Dev\FreeRTOS\source\include\semphr.h E:\Dev\Fre&
eRTOS\source\include\task.h E:\Dev\FreeRTOS\source\portable\owatcom\16bitdos&
\common\portasm.h E:\Dev\FreeRTOS\source\portable\owatcom\16bitdos\flsh186\p&
ortmacro.h E:\Dev\FreeRTOS\Demo\common\include\blockq.h E:\Dev\FreeRTOS\Demo&
\common\include\comtest.h E:\Dev\FreeRTOS\Demo\common\include\death.h E:\Dev&
\FreeRTOS\Demo\common\include\fileio.h E:\Dev\FreeRTOS\Demo\common\include\f&
lash.h E:\Dev\FreeRTOS\Demo\common\include\flop.h E:\Dev\FreeRTOS\Demo\commo&
n\include\partest.h E:\Dev\FreeRTOS\Demo\common\include\pollq.h E:\Dev\FreeR&
TOS\Demo\common\include\print.h E:\Dev\FreeRTOS\Demo\common\include\semtest.&
h E:\Dev\FreeRTOS\Demo\common\include\serial.h E:\Dev\FreeRTOS\Demo\Flshlite&
\FreeRTOSConfig.h .AUTODEPEND
@E:
cd E:\Dev\FreeRTOS\Demo\Flshlite
@%write rtosdemo.lk1 FIL list.obj,heap_2.obj,portcomn.obj,port.obj,queue.ob&
j,tasks.obj,blockq.obj,comtest.obj,death.obj,flash.obj,integer.obj,pollq.obj&
,print.obj,semtest.obj,fileio.obj,main.obj,partest.obj,serial.obj
@%append rtosdemo.lk1
*wlink name rtosdemo SYS dos op m op maxe=25 op d op q op symf op el @rtosd&
emo.lk1

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,43 @@
40
projectIdent
0
VpeMain
1
WRect
-25
-34
10291
10026
2
MProject
3
MCommand
0
4
MCommand
0
1
5
WFileName
12
rtosdemo.tgt
6
WVList
1
7
VComponent
8
WRect
0
0
7200
5888
0
0
9
WFileName
12
rtosdemo.tgt
0
19
7

View file

@ -0,0 +1,489 @@
/*
FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
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.
Alternative commercial license and support terms are also available upon
request. See the licensing section of http://www.FreeRTOS.org for full
license details.
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 along
with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA.
***************************************************************************
* *
* Looking for a quick start? Then check out the FreeRTOS eBook! *
* See http://www.FreeRTOS.org/Documentation for details *
* *
***************************************************************************
1 tab == 4 spaces!
Please ensure to read the configuration and relevant port sections of the
online documentation.
http://www.FreeRTOS.org - Documentation, latest information, license and
contact details.
http://www.SafeRTOS.com - A version that is certified for use in safety
critical systems.
http://www.OpenRTOS.com - Commercial support, development, porting,
licensing and training services.
*/
/*
Changes from V1.00:
+ Call to the more efficient portSWITCH_CONTEXT() replaces the call to
taskYIELD() in the ISR.
Changes from V1.01:
+ The semaphore task is not operational. This does nothing but check
the semaphore from ISR functionality.
+ ISR modified slightly so only Rx or Tx is serviced per ISR - not both.
Changes from V1.2.0:
+ Change so Tx uses a DMA channel, and Rx uses an interrupt.
Changes from V1.2.3
+ The function xPortInitMinimal() has been renamed to
xSerialPortInitMinimal() and the function xPortInit() has been renamed
to xSerialPortInit().
Changes from V1.2.5
+ Reverted back to the non-DMA serial port driver, with a slightly modified
ISR. This is a better test of the scheduler mechanisms.
+ A critical section is now used in vInterruptOn().
+ Flag sTxInterruptOn has been added to the port structure. This allows
checking of the interrupt enable status without performing any IO.
Changes from V2.0.0
+ Use portTickType in place of unsigned pdLONG for delay periods.
+ Slightly more efficient vSerialSendString() implementation.
+ cQueueReieveFromISR() used in place of xQueueReceive() in ISR.
*/
#include <stdlib.h>
#include <dos.h>
#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
#include "portasm.h"
#include "semphr.h"
#define serMAX_PORTS ( ( unsigned portSHORT ) 2 )
#define serPORT_0_INT_REG ( 0xff44 )
#define serPORT_0_BAUD_REG ( 0xff88 )
#define serPORT_0_RX_REG ( 0xff86 )
#define serPORT_0_TX_REG ( 0xff84 )
#define serPORT_0_STATUS_REG ( 0xff82 )
#define serPORT_0_CTRL_REG ( 0xff80 )
#define serPORT_0_IRQ ( 0x14 )
#define serPORT_1_INT_REG ( 0xff42 )
#define serPORT_1_BAUD_REG ( 0xff18 )
#define serPORT_1_RX_REG ( 0xff16 )
#define serPORT_1_TX_REG ( 0xff14 )
#define serPORT_1_STATUS_REG ( 0xff12 )
#define serPORT_1_CTRL_REG ( 0xff10 )
#define serPORT_1_IRQ ( 0x11 )
#define serTX_EMPTY ( ( unsigned portSHORT ) 0x40 )
#define serRX_READY ( ( unsigned portSHORT ) 0x80 )
#define serRESET_PIC( usEOI_TYPE ) portOUTPUT_WORD( ( unsigned portSHORT ) 0xff22, usEOI_TYPE )
#define serTX_HOLD_EMPTY_INT ( ( unsigned portSHORT ) 0x100 )
#define serENABLE_INTERRUPTS ( ( unsigned portSHORT ) 0x80 )
#define serMODE ( ( unsigned portSHORT ) 0x01 )
#define serENABLE_TX_MACHINES ( ( unsigned portSHORT ) 0x40 )
#define serENABLE_RX_MACHINES ( ( unsigned portSHORT ) 0x20 )
#define serINTERRUPT_MASK ( ( unsigned portSHORT ) 0x08 )
#define serCLEAR_ALL_STATUS_BITS ( ( unsigned portSHORT ) 0x00 )
#define serINTERRUPT_PRIORITY ( ( unsigned portSHORT ) 0x01 ) /*< Just below the scheduler priority. */
#define serDONT_BLOCK ( ( portTickType ) 0 )
typedef enum
{
serCOM1 = 0,
serCOM2,
serCOM3,
serCOM4,
serCOM5,
serCOM6,
serCOM7,
serCOM8
} eCOMPort;
typedef enum
{
serNO_PARITY,
serODD_PARITY,
serEVEN_PARITY,
serMARK_PARITY,
serSPACE_PARITY
} eParity;
typedef enum
{
serSTOP_1,
serSTOP_2
} eStopBits;
typedef enum
{
serBITS_5,
serBITS_6,
serBITS_7,
serBITS_8
} eDataBits;
typedef enum
{
ser50 = 0,
ser75,
ser110,
ser134,
ser150,
ser200,
ser300,
ser600,
ser1200,
ser1800,
ser2400,
ser4800,
ser9600,
ser19200,
ser38400,
ser57600,
ser115200
} eBaud;
/* Must be same order as eBaud definitions. */
static const unsigned portSHORT usBaudRateDivisor[] =
{
0, /* Not sure if the first 6 are correct. First cannot be used. */
29127,
19859,
16302,
14564,
10923,
6879,
3437,
1718,
1145,
859,
429,
214,
107,
54,
35,
18
};
typedef struct xCOM_PORT
{
/* Hardware parameters for this port. */
portSHORT sTxInterruptOn;
unsigned portSHORT usIntReg;
unsigned portSHORT usBaudReg;
unsigned portSHORT usRxReg;
unsigned portSHORT usTxReg;
unsigned portSHORT usStatusReg;
unsigned portSHORT usCtrlReg;
unsigned portSHORT usIRQVector;
/* Queues used for communications with com test task. */
xQueueHandle xRxedChars;
xQueueHandle xCharsForTx;
/* This semaphore does nothing useful except test a feature of the
scheduler. */
xSemaphoreHandle xTestSem;
} xComPort;
static xComPort xPorts[ serMAX_PORTS ] =
{
{ pdFALSE, serPORT_0_INT_REG, serPORT_0_BAUD_REG, serPORT_0_RX_REG, serPORT_0_TX_REG, serPORT_0_STATUS_REG, serPORT_0_CTRL_REG, serPORT_0_IRQ, NULL, NULL, NULL },
{ pdFALSE, serPORT_1_INT_REG, serPORT_1_BAUD_REG, serPORT_1_RX_REG, serPORT_1_TX_REG, serPORT_1_STATUS_REG, serPORT_1_CTRL_REG, serPORT_1_IRQ, NULL, NULL, NULL }
};
typedef xComPort * xComPortHandle;
/* These prototypes are repeated here so we don't have to include the serial header. This allows
the xComPortHandle structure details to be private to this file. */
xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength );
portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, portCHAR *pcRxedChar, portTickType xBlockTime );
portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, portCHAR cOutChar, portTickType xBlockTime );
void vSerialClose( xComPortHandle xPort );
portSHORT sSerialWaitForSemaphore( xComPortHandle xPort );
/*-----------------------------------------------------------*/
static portSHORT xComPortISR( xComPort * const pxPort );
#define vInterruptOn( pxPort, usInterrupt ) \
{ \
unsigned portSHORT usIn; \
\
portENTER_CRITICAL(); \
{ \
if( pxPort->sTxInterruptOn == pdFALSE ) \
{ \
usIn = portINPUT_WORD( pxPort->usCtrlReg ); \
portOUTPUT_WORD( pxPort->usCtrlReg, usIn | usInterrupt ); \
\
pxPort->sTxInterruptOn = pdTRUE; \
} \
} \
portEXIT_CRITICAL(); \
}
/*-----------------------------------------------------------*/
#define vInterruptOff( pxPort, usInterrupt ) \
{ \
unsigned portSHORT usIn = portINPUT_WORD( pxPort->usCtrlReg ); \
if( usIn & usInterrupt ) \
{ \
portOUTPUT_WORD( pxPort->usCtrlReg, usIn & ~usInterrupt); \
pxPort->sTxInterruptOn = pdFALSE; \
} \
}
/*-----------------------------------------------------------*/
/* Define an interrupt handler for each port */
#define COM_IRQ_WRAPPER(N) \
static void __interrupt COM_IRQ##N##_WRAPPER( void ) \
{ \
if( xComPortISR( &( xPorts[##N##] ) ) ) \
{ \
portSWITCH_CONTEXT(); \
} \
}
COM_IRQ_WRAPPER( 0 )
COM_IRQ_WRAPPER( 1 )
static pxISR xISRs[ serMAX_PORTS ] =
{
COM_IRQ0_WRAPPER,
COM_IRQ1_WRAPPER
};
/*-----------------------------------------------------------*/
xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength )
{
unsigned portSHORT usPort;
xComPortHandle pxPort = NULL;
/* BAUDDIV = ( Microprocessor Clock / Baud Rate ) / 16 */
/* Only n, 8, 1 is supported so these parameters are not required for this
port. */
( void ) eWantedParity;
( void ) eWantedDataBits;
( void ) eWantedStopBits;
/* Currently only n,8,1 is supported. */
usPort = ( unsigned portSHORT ) ePort;
if( usPort < serMAX_PORTS )
{
pxPort = &( xPorts[ usPort ] );
portENTER_CRITICAL();
{
unsigned portSHORT usInWord;
/* Create the queues used by the com test task. */
pxPort->xRxedChars = xQueueCreate( uxBufferLength, ( unsigned portBASE_TYPE ) sizeof( portCHAR ) );
pxPort->xCharsForTx = xQueueCreate( uxBufferLength, ( unsigned portBASE_TYPE ) sizeof( portCHAR ) );
/* Create the test semaphore. This does nothing useful except test a feature of the scheduler. */
vSemaphoreCreateBinary( pxPort->xTestSem );
/* There is no ISR here already to restore later. */
_dos_setvect( ( portSHORT ) pxPort->usIRQVector, xISRs[ usPort ] );
usInWord = portINPUT_WORD( pxPort->usIntReg );
usInWord &= ~serINTERRUPT_MASK;
usInWord |= serINTERRUPT_PRIORITY;
portOUTPUT_WORD( pxPort->usIntReg, usInWord );
portOUTPUT_WORD( pxPort->usBaudReg, usBaudRateDivisor[ eWantedBaud ] );
portOUTPUT_WORD( pxPort->usCtrlReg, serENABLE_INTERRUPTS | serMODE | serENABLE_TX_MACHINES | serENABLE_RX_MACHINES );
portOUTPUT_WORD( pxPort->usStatusReg, serCLEAR_ALL_STATUS_BITS );
}
portEXIT_CRITICAL();
}
return pxPort;
} /*lint !e715 Some parameters are not used as only a subset of the serial port functionality is currently implemented. */
/*-----------------------------------------------------------*/
void vSerialPutString( xComPortHandle pxPort, const portCHAR * const pcString, unsigned portSHORT usStringLength )
{
unsigned portSHORT usByte;
portCHAR *pcNextChar;
pcNextChar = ( portCHAR * ) pcString;
for( usByte = 0; usByte < usStringLength; usByte++ )
{
xQueueSend( pxPort->xCharsForTx, pcNextChar, serDONT_BLOCK );
pcNextChar++;
}
vInterruptOn( pxPort, serTX_HOLD_EMPTY_INT );
}
/*-----------------------------------------------------------*/
portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, portCHAR *pcRxedChar, portTickType xBlockTime )
{
/* Get the next character from the buffer, note that this routine is only
called having checked that the is (at least) one to get */
if( xQueueReceive( pxPort->xRxedChars, pcRxedChar, xBlockTime ) )
{
return pdTRUE;
}
else
{
return pdFALSE;
}
}
/*-----------------------------------------------------------*/
portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, portCHAR cOutChar, portTickType xBlockTime )
{
if( xQueueSend( pxPort->xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
{
return pdFAIL;
}
vInterruptOn( pxPort, serTX_HOLD_EMPTY_INT );
return pdPASS;
}
/*-----------------------------------------------------------*/
portBASE_TYPE xSerialWaitForSemaphore( xComPortHandle xPort )
{
const portTickType xBlockTime = ( portTickType ) 0xffff;
/* This function does nothing interesting, but test the
semaphore from ISR mechanism. */
return xSemaphoreTake( xPort->xTestSem, xBlockTime );
}
/*-----------------------------------------------------------*/
void vSerialClose( xComPortHandle xPort )
{
unsigned portSHORT usOutput;
/* Turn off the interrupts. We may also want to delete the queues and/or
re-install the original ISR. */
portENTER_CRITICAL();
{
usOutput = portINPUT_WORD( xPort->usCtrlReg );
usOutput &= ~serENABLE_INTERRUPTS;
usOutput &= ~serENABLE_TX_MACHINES;
usOutput &= ~serENABLE_RX_MACHINES;
portOUTPUT_WORD( xPort->usCtrlReg, usOutput );
usOutput = portINPUT_WORD( xPort->usIntReg );
usOutput |= serINTERRUPT_MASK;
portOUTPUT_WORD( xPort->usIntReg, usOutput );
}
portEXIT_CRITICAL();
}
/*-----------------------------------------------------------*/
static portBASE_TYPE xComPortISR( xComPort * const pxPort )
{
unsigned portSHORT usStatusRegister;
portCHAR cChar;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE, xContinue = pdTRUE;
/* NOTE: THIS IS NOT AN EFFICIENT ISR AS IT IS DESIGNED SOLELY TO TEST
THE SCHEDULER FUNCTIONALITY. REAL APPLICATIONS SHOULD NOT USE THIS
FUNCTION. */
while( xContinue == pdTRUE )
{
xContinue = pdFALSE;
usStatusRegister = portINPUT_WORD( pxPort->usStatusReg );
if( usStatusRegister & serRX_READY )
{
cChar = ( portCHAR ) portINPUT_WORD( pxPort->usRxReg );
xQueueSendFromISR( pxPort->xRxedChars, &cChar, &xHigherPriorityTaskWoken );
/* Also release the semaphore - this does nothing interesting and is just a test. */
xSemaphoreGiveFromISR( pxPort->xTestSem, &xHigherPriorityTaskWoken );
/* We have performed an action this cycle - there may be other to perform. */
xContinue = pdTRUE;
}
if( pxPort->sTxInterruptOn && ( usStatusRegister & serTX_EMPTY ) )
{
if( xQueueReceiveFromISR( pxPort->xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
{
portOUTPUT_WORD( pxPort->usTxReg, ( unsigned portSHORT ) cChar );
/* We have performed an action this cycle - there may be others to perform. */
xContinue = pdTRUE;
}
else
{
/* Queue empty, nothing to send */
vInterruptOff( pxPort, serTX_HOLD_EMPTY_INT );
}
}
}
serRESET_PIC( pxPort->usIRQVector );
/* If posting to the queue woke a task that was blocked on the queue we may
want to switch to the woken task - depending on its priority relative to
the task interrupted by this ISR. */
return xHigherPriorityTaskWoken;
}