Updated TriCore demo application.

This commit is contained in:
Richard Barry 2011-10-27 10:45:27 +00:00
parent 41ef155824
commit 8d748af95c
4 changed files with 285 additions and 289 deletions

File diff suppressed because one or more lines are too long

View file

@ -121,5 +121,11 @@ runs from RAM. */
#define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1 #define INCLUDE_vTaskDelay 1
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 64
#define configKERNEL_INTERRUPT_PRIORITY 1
/* Default definition of configASSERT(). */
//#define configASSERT( x ) if( ( x ) == 0 ) { portDISABLE_INTERRUPTS(); for( ;; ); }
#endif /* FREERTOS_CONFIG_H */ #endif /* FREERTOS_CONFIG_H */

View file

@ -57,32 +57,32 @@
/* Demo Includes. */ /* Demo Includes. */
#include "partest.h" #include "partest.h"
/* Machine Includes. */ /* Hardware specific includes. */
#include <tc1782.h> #include <tc1782.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void vParTestInitialise( void ) void vParTestInitialise( void )
{ {
/* The TriBoard TC1782 v2.1 has 8 LEDs connected to GPIO5. */ /* The TriBoard TC1782 v2.1 has 8 LEDs connected to GPIO5. */
P5_IOCR0.reg = 0xC0C0C0C0; P5_IOCR0.reg = 0xC0C0C0C0UL;
P5_IOCR4.reg = 0xC0C0C0C0; P5_IOCR4.reg = 0xC0C0C0C0UL;
P5_PDR.reg = 0x00000000UL;
P5_PDR.reg = 0x00000000; P5_OMR.reg = 0x0000FFFFUL;
P5_OMR.reg = 0x0000FFFF;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
{ {
unsigned long ulBitPattern = 1UL << uxLED; unsigned long ulBitPattern = 1UL << uxLED;
if ( xValue != 0 )
if( xValue != 0 )
{ {
P5_OMR.reg = ulBitPattern; P5_OMR.reg = ulBitPattern;
} }
else else
{ {
P5_OMR.reg = ulBitPattern << 16; P5_OMR.reg = ulBitPattern << 16UL;
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -90,6 +90,7 @@ unsigned long ulBitPattern = 1UL << uxLED;
void vParTestToggleLED( unsigned portBASE_TYPE uxLED ) void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{ {
unsigned long ulBitPattern = 1UL << uxLED; unsigned long ulBitPattern = 1UL << uxLED;
P5_OMR.reg = ( ulBitPattern << 16 ) | ulBitPattern; P5_OMR.reg = ( ulBitPattern << 16 ) | ulBitPattern;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -51,6 +51,7 @@
licensing and training services. licensing and training services.
*/ */
/* Hardware specific includes. */
#include <tc1782.h> #include <tc1782.h>
#include <machine/intrinsics.h> #include <machine/intrinsics.h>
#include <machine/cint.h> #include <machine/cint.h>
@ -63,44 +64,53 @@
/* Demo Includes. */ /* Demo Includes. */
#include "serial.h" #include "serial.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Interrupt priorities. */
#define serialINTERRUPT_PRIORITY_TX 16 #define serialINTERRUPT_PRIORITY_TX 16
#define serialINTERRUPT_PRIORITY_RX 18 #define serialINTERRUPT_PRIORITY_RX 18
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* /*
* This reference is required by the Save/Restore Context Macros. * See if the Serial Transmit Interrupt is currently activated, meaning that
*/ * the interrupt is working through the back log of bytes that it needs to
extern volatile unsigned portBASE_TYPE * pxCurrentTCB; * send. If the ISR is not enabled, then it will be triggered to send the first
/*-----------------------------------------------------------*/ * byte, and it will be automatically re-triggered when that byte has been
/**
* This function will check to see whether the Serial Transmit Interrupt is currently
* activated, meaning that the interrupt is working through the back log of bytes
* that it needs to send. If the ISR is not enabled, then it will be triggered to send
* the first byte and it will be automatically re-triggered when that byte has been
* sent. When the queue is exhausted, the ISR disables itself. * sent. When the queue is exhausted, the ISR disables itself.
* This function is privileged because it will trigger an interrupt.
*/ */
static void prvCheckTransmit( void ) PRIVILEGED_FUNCTION; static void prvCheckTransmit( void );
/*-----------------------------------------------------------*/
/*
void vSerialTransmitBufferInterrupt( int iArg ) __attribute__((longcall)); * The transmit and receive interrupt handlers.
void vSerialReceiveInterrupt( int iArg )__attribute__((longcall)); */
static void prvTxBufferInterruptHandler( int iArg ) __attribute__( ( longcall ) );
static void prvRxInterruptHandler( int iArg )__attribute__( ( longcall ) );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Queues used to pass bytes into and out of the interrupt handlers.
NOTE: This is not intended to be an example of an efficient interrupt handler,
but instead to load the kernel and interrupt mechanisms in order to test the
FreeRTOS port. Using a FIFO, DMA, circular buffer, etc. architecture will
to improve efficiency. */
static xQueueHandle xSerialTransmitQueue = NULL; static xQueueHandle xSerialTransmitQueue = NULL;
static xQueueHandle xSerialReceiveQueue = NULL; static xQueueHandle xSerialReceiveQueue = NULL;
static volatile portBASE_TYPE xTransmitStatus = 0UL; static volatile portBASE_TYPE xTransmitStatus = 0UL;
/*---------------------------------------------------------------------------*/
/* This reference is required by the Save/Restore Context Macros. */
extern volatile unsigned portBASE_TYPE * pxCurrentTCB;
/*-----------------------------------------------------------*/
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{ {
unsigned long ulReloadValue = 0UL; unsigned long ulReloadValue = 0UL;
ulReloadValue = ( configPERIPHERAL_CLOCK_HZ / ( 32 * ulWantedBaud ) ) - 1; ulReloadValue = ( configPERIPHERAL_CLOCK_HZ / ( 32 * ulWantedBaud ) ) - 1;
if ( NULL == xSerialTransmitQueue ) if( NULL == xSerialTransmitQueue )
{ {
xSerialTransmitQueue = xQueueCreate( uxQueueLength, sizeof( char ) ); xSerialTransmitQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
xSerialReceiveQueue = xQueueCreate( uxQueueLength, sizeof( char ) ); xSerialReceiveQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
@ -108,8 +118,10 @@ unsigned long ulReloadValue = 0UL;
/* Enable ASC0 Module. */ /* Enable ASC0 Module. */
unlock_wdtcon(); unlock_wdtcon();
{
while ( 0 != ( WDT_CON0.reg & 0x1UL ) ); while ( 0 != ( WDT_CON0.reg & 0x1UL ) );
ASC0_CLC.reg = 0x0200UL; ASC0_CLC.reg = 0x0200UL;
}
lock_wdtcon(); lock_wdtcon();
/* Disable the Operation. */ /* Disable the Operation. */
@ -117,9 +129,8 @@ unsigned long ulReloadValue = 0UL;
/* Set-up the GPIO Ports. */ /* Set-up the GPIO Ports. */
P3_IOCR0.reg = 0x00009000; /* 3.0 ASC In, 3.1 Alt ASC Out */ P3_IOCR0.reg = 0x00009000; /* 3.0 ASC In, 3.1 Alt ASC Out */
/* Do we need to set 3.1 high? OMR.PS1 = 1??? */
/* Write the Baudrate. */ /* Write the baud rate. */
ASC0_BG.reg = ulReloadValue; ASC0_BG.reg = ulReloadValue;
/* Reconfigure and re-initialise the Operation. */ /* Reconfigure and re-initialise the Operation. */
@ -127,14 +138,14 @@ unsigned long ulReloadValue = 0UL;
ASC0_CON.reg = 0x00008011; /* 1 Start, 1 Stop, 8 Data, No Parity, No Error Checking, Receive On, Module On. */ ASC0_CON.reg = 0x00008011; /* 1 Start, 1 Stop, 8 Data, No Parity, No Error Checking, Receive On, Module On. */
/* Install the Tx interrupt. */ /* Install the Tx interrupt. */
if ( 0 != _install_int_handler( serialINTERRUPT_PRIORITY_TX, vSerialTransmitBufferInterrupt, 0 ) ) if( 0 != _install_int_handler( serialINTERRUPT_PRIORITY_TX, prvTxBufferInterruptHandler, 0 ) )
{ {
ASC0_TBSRC.reg = serialINTERRUPT_PRIORITY_TX | 0x5000UL; ASC0_TBSRC.reg = serialINTERRUPT_PRIORITY_TX | 0x5000UL;
xTransmitStatus = 0UL; xTransmitStatus = 0UL;
} }
/* Install the Rx interrupt. */ /* Install the Rx interrupt. */
if ( 0 != _install_int_handler( serialINTERRUPT_PRIORITY_RX, vSerialReceiveInterrupt, 0 ) ) if( 0 != _install_int_handler( serialINTERRUPT_PRIORITY_RX, prvRxInterruptHandler, 0 ) )
{ {
ASC0_RSRC.reg = serialINTERRUPT_PRIORITY_RX | 0x5000UL; ASC0_RSRC.reg = serialINTERRUPT_PRIORITY_RX | 0x5000UL;
} }
@ -147,17 +158,20 @@ unsigned long ulReloadValue = 0UL;
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength ) void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
{ {
unsigned short usChar; unsigned short usChar;
for ( usChar = 0; usChar < usStringLength; usChar++ )
for( usChar = 0; usChar < usStringLength; usChar++ )
{ {
(void)xSerialPutChar( pxPort, pcString[ usChar ], portMAX_DELAY ); xSerialPutChar( pxPort, pcString[ usChar ], portMAX_DELAY );
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime ) signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
{ {
/* Just to remove compiler warnings about unused parameters. */
( void )pxPort;
return xQueueReceive( xSerialReceiveQueue, pcRxedChar, xBlockTime ); return xQueueReceive( xSerialReceiveQueue, pcRxedChar, xBlockTime );
(void)pxPort;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -165,6 +179,9 @@ signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar
{ {
portBASE_TYPE xReturn = pdPASS; portBASE_TYPE xReturn = pdPASS;
/* Just to remove compiler warnings about unused parameters. */
( void )pxPort;
/* Send the character to the interrupt handler. */ /* Send the character to the interrupt handler. */
xReturn = xQueueSend( xSerialTransmitQueue, &cOutChar, xBlockTime ); xReturn = xQueueSend( xSerialTransmitQueue, &cOutChar, xBlockTime );
@ -172,25 +189,23 @@ portBASE_TYPE xReturn = pdPASS;
prvCheckTransmit(); prvCheckTransmit();
return xReturn; return xReturn;
(void)pxPort;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void vSerialTransmitBufferInterrupt( int iArg ) static void prvTxBufferInterruptHandler( int iArg )
{ {
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
unsigned char ucTx; unsigned char ucTx;
/* Just to remove compiler warnings about unused parameters. */
( void ) iArg;
/* ACK. */ /* ACK. */
ASC0_TBSRC.reg |= 0x4000UL; ASC0_TBSRC.reg |= 0x4000UL;
xTransmitStatus = 1UL; xTransmitStatus = 1UL;
/* Enter the Critical Section. */
portINTERRUPT_ENTER_CRITICAL();
{
/* TBUF Can be refilled. */ /* TBUF Can be refilled. */
if ( pdPASS == xQueueReceiveFromISR( xSerialTransmitQueue, &ucTx, &xHigherPriorityTaskWoken ) ) if( pdPASS == xQueueReceiveFromISR( xSerialTransmitQueue, &ucTx, &xHigherPriorityTaskWoken ) )
{ {
ASC0_TBUF.reg = ucTx; ASC0_TBUF.reg = ucTx;
} }
@ -199,48 +214,41 @@ unsigned char ucTx;
/* Failed to get a character out of the Queue. No longer busy. */ /* Failed to get a character out of the Queue. No longer busy. */
xTransmitStatus = 0UL; xTransmitStatus = 0UL;
} }
}
portINTERRUPT_EXIT_CRITICAL();
/* Finally end ISR and switch Task. */ /* Finally end ISR and switch Task. */
portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
(void)iArg;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void vSerialReceiveInterrupt( int iArg ) static void prvRxInterruptHandler( int iArg )
{ {
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
unsigned char ucRx; unsigned char ucRx;
/* Just to remove compiler warnings about unused parameters. */
( void ) iArg;
/* Grab the character as early as possible. */ /* Grab the character as early as possible. */
ucRx = (unsigned char)ASC0_RBUF.reg; ucRx = ( unsigned char ) ASC0_RBUF.reg;
/* ACK. */ /* ACK. */
ASC0_RSRC.reg |= 0x4000UL; ASC0_RSRC.reg |= 0x4000UL;
/* Enter the Critical Section. */
portINTERRUPT_ENTER_CRITICAL();
{
/* Frame available in RBUF. */ /* Frame available in RBUF. */
if ( pdPASS != xQueueSendFromISR( xSerialReceiveQueue, &ucRx, &xHigherPriorityTaskWoken ) ) if( pdPASS != xQueueSendFromISR( xSerialReceiveQueue, &ucRx, &xHigherPriorityTaskWoken ) )
{ {
/* Need some error handling code. */ /* Error handling code can go here. */
} }
}
portINTERRUPT_EXIT_CRITICAL();
/* Finally end ISR and switch Task. */ /* Finally end ISR and switch Task. */
portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
(void)iArg;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void prvCheckTransmit( void ) void prvCheckTransmit( void )
{ {
/* Check to see if the interrupt handler is working its way through the buffer. */ /* Check to see if the interrupt handler is working its way through the
buffer. */
if ( 0 == xTransmitStatus ) if ( 0 == xTransmitStatus )
{ {
/* Not currently operational so kick off the first byte. */ /* Not currently operational so kick off the first byte. */