2 FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 /* Hardware specific includes. */
\r
56 #include <machine/intrinsics.h>
\r
57 #include <machine/cint.h>
\r
58 #include <machine/wdtcon.h>
\r
60 /* Scheduler Includes. */
\r
61 #include "FreeRTOS.h"
\r
65 /* Demo Includes. */
\r
68 /*****************************************************************************
\r
71 * This file is here to provide a means of generating interrupts to test the
\r
72 * FreeRTOS tricore port. First - it configures the UART into loopback mode,
\r
73 * and has only been used in loopback mode. Therefore, the baud rate
\r
74 * calculation used has never been verified for correctness. Second -
\r
75 * characters are passed into and out of the interrupt service routines using
\r
76 * character queues. This provides a good test of the interrupt interaction,
\r
77 * context switching mechanism, and kernel loading, it is however highly
\r
78 * inefficient if the UART is being used to handle even moderate amounts of
\r
83 /*---------------------------------------------------------------------------*/
\r
86 * See if the Serial Transmit Interrupt is currently activated, meaning that
\r
87 * the interrupt is working through the back log of bytes that it needs to
\r
88 * send. If the ISR is not enabled, then it will be triggered to send the first
\r
89 * byte, and it will be automatically re-triggered when that byte has been
\r
90 * sent. When the queue is exhausted, the ISR disables itself.
92 static void prvCheckTransmit( void );
\r
95 * The transmit and receive interrupt handlers.
\r
97 static void prvTxBufferInterruptHandler( int iArg ) __attribute__( ( longcall ) );
\r
98 static void prvRxInterruptHandler( int iArg )__attribute__( ( longcall ) );
\r
100 /*-----------------------------------------------------------*/
\r
102 /* Queues used to pass bytes into and out of the interrupt handlers.
\r
103 NOTE: This is not intended to be an example of an efficient interrupt handler,
\r
104 but instead to load the kernel and interrupt mechanisms in order to test the
\r
105 FreeRTOS port. Using a FIFO, DMA, circular buffer, etc. architecture will
\r
106 to improve efficiency. */
\r
107 static xQueueHandle xSerialTransmitQueue = NULL;
\r
108 static xQueueHandle xSerialReceiveQueue = NULL;
\r
109 static volatile portBASE_TYPE xTransmitStatus = 0UL;
\r
111 /*-----------------------------------------------------------*/
\r
113 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
115 unsigned long ulReloadValue = 0UL;
\r
117 ulReloadValue = ( configPERIPHERAL_CLOCK_HZ / ( 48UL * ulWantedBaud ) ) - 1UL;
\r
119 if( NULL == xSerialTransmitQueue )
\r
121 xSerialTransmitQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
122 xSerialReceiveQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
125 /* Enable ASC0 Module. */
\r
128 while ( 0 != ( WDT_CON0.reg & 0x1UL ) );
\r
129 ASC0_CLC.reg = 0x0200UL;
\r
133 /* Disable the Operation. */
\r
134 ASC0_CON.reg &= 0xFFFF7FFF;
\r
136 /* Set-up the GPIO Ports. */
\r
137 P3_IOCR0.reg = 0x00009000; /* 3.0 ASC In, 3.1 Alt ASC Out */
\r
139 /* Write the baud rate. */
\r
140 ASC0_BG.reg = ulReloadValue;
\r
142 /* Reconfigure and re-initialise the Operation. */
\r
143 ASC0_PISEL.reg = 0UL;
\r
144 ASC0_CON.reg = 0UL;
\r
145 ASC0_CON.bits.M = 0x01; /* 8bit async. */
\r
146 ASC0_CON.bits.REN = 0x01; /* Receiver enabled. */
\r
147 ASC0_CON.bits.FDE = 0x01; /* Fractional divider enabled. */
\r
148 ASC0_CON.bits.BRS = 0x01; /* Divide by three. */
\r
149 ASC0_CON.bits.LB = 0x01; /* Loopback enabled. */
\r
150 ASC0_CON.bits.R = 0x01; /* Enable the baud rate generator. */
\r
152 /* Install the Tx interrupt. */
\r
153 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_TX, prvTxBufferInterruptHandler, 0 ) )
\r
155 ASC0_TBSRC.reg = configINTERRUPT_PRIORITY_TX | 0x5000UL;
\r
156 xTransmitStatus = 0UL;
\r
159 /* Install the Rx interrupt. */
\r
160 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_RX, prvRxInterruptHandler, 0 ) )
\r
162 ASC0_RSRC.reg = configINTERRUPT_PRIORITY_RX | 0x5000UL;
\r
165 /* COM Handle is never used by demo code. */
\r
166 return (xComPortHandle) pdPASS;
\r
168 /*---------------------------------------------------------------------------*/
\r
170 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
172 unsigned short usChar;
\r
174 for( usChar = 0; usChar < usStringLength; usChar++ )
\r
176 xSerialPutChar( pxPort, pcString[ usChar ], portMAX_DELAY );
\r
179 /*---------------------------------------------------------------------------*/
\r
181 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
183 /* Just to remove compiler warnings about unused parameters. */
\r
186 return xQueueReceive( xSerialReceiveQueue, pcRxedChar, xBlockTime );
\r
188 /*---------------------------------------------------------------------------*/
\r
190 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
\r
192 portBASE_TYPE xReturn = pdPASS;
\r
194 /* Just to remove compiler warnings about unused parameters. */
\r
197 /* Send the character to the interrupt handler. */
\r
198 xReturn = xQueueSend( xSerialTransmitQueue, &cOutChar, xBlockTime );
\r
200 /* Start the transmission of bytes if necessary. */
\r
201 prvCheckTransmit();
\r
205 /*---------------------------------------------------------------------------*/
\r
207 static void prvTxBufferInterruptHandler( int iArg )
\r
209 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
210 unsigned char ucTx;
\r
212 /* Just to remove compiler warnings about unused parameters. */
\r
216 ASC0_TBSRC.reg |= 0x4000UL;
\r
217 xTransmitStatus = 1UL;
\r
219 /* TBUF Can be refilled. */
\r
220 if( pdPASS == xQueueReceiveFromISR( xSerialTransmitQueue, &ucTx, &xHigherPriorityTaskWoken ) )
\r
222 ASC0_TBUF.reg = ucTx;
\r
226 /* Failed to get a character out of the Queue. No longer busy. */
\r
227 xTransmitStatus = 0UL;
\r
230 /* Finally end ISR and switch Task if necessary. */
\r
231 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
233 /*---------------------------------------------------------------------------*/
\r
235 static void prvRxInterruptHandler( int iArg )
\r
237 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
238 unsigned char ucRx;
\r
240 /* Just to remove compiler warnings about unused parameters. */
\r
243 /* Grab the character as early as possible. */
\r
244 ucRx = ( unsigned char ) ASC0_RBUF.reg;
\r
247 ASC0_RSRC.reg |= 0x4000UL;
\r
249 /* Frame available in RBUF. */
\r
250 if( pdPASS != xQueueSendFromISR( xSerialReceiveQueue, &ucRx, &xHigherPriorityTaskWoken ) )
\r
252 /* Error handling code can go here. */
\r
255 /* Finally end ISR and switch Task if necessary. */
\r
256 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
258 /*---------------------------------------------------------------------------*/
\r
260 void prvCheckTransmit( void )
\r
262 /* Check to see if the interrupt handler is working its way through the
\r
264 if( 0 == xTransmitStatus )
\r
266 /* Not currently operational so kick off the first byte. */
\r
267 ASC0_TBSRC.reg |= 0x8000UL;
\r
270 /*---------------------------------------------------------------------------*/
\r