2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
75 /* Hardware specific includes. */
\r
77 #include <machine/intrinsics.h>
\r
78 #include <machine/cint.h>
\r
79 #include <machine/wdtcon.h>
\r
81 /* Scheduler Includes. */
\r
82 #include "FreeRTOS.h"
\r
86 /* Demo Includes. */
\r
89 /*****************************************************************************
\r
92 * This file is here to provide a means of generating interrupts to test the
\r
93 * FreeRTOS tricore port. First - it configures the UART into loopback mode,
\r
94 * and has only been used in loopback mode. Therefore, the baud rate
\r
95 * calculation used has never been verified for correctness. Second -
\r
96 * characters are passed into and out of the interrupt service routines using
\r
97 * character queues. This provides a good test of the interrupt interaction,
\r
98 * context switching mechanism, and kernel loading, it is however highly
\r
99 * inefficient if the UART is being used to handle even moderate amounts of
\r
104 /*---------------------------------------------------------------------------*/
\r
107 * See if the Serial Transmit Interrupt is currently activated, meaning that
\r
108 * the interrupt is working through the back log of bytes that it needs to
\r
109 * send. If the ISR is not enabled, then it will be triggered to send the first
\r
110 * byte, and it will be automatically re-triggered when that byte has been
\r
111 * sent. When the queue is exhausted, the ISR disables itself.
\r
113 static void prvCheckTransmit( void );
\r
116 * The transmit and receive interrupt handlers.
\r
118 static void prvTxBufferInterruptHandler( int iArg ) __attribute__( ( longcall ) );
\r
119 static void prvRxInterruptHandler( int iArg )__attribute__( ( longcall ) );
\r
121 /*-----------------------------------------------------------*/
\r
123 /* Queues used to pass bytes into and out of the interrupt handlers.
\r
124 NOTE: This is not intended to be an example of an efficient interrupt handler,
\r
125 but instead to load the kernel and interrupt mechanisms in order to test the
\r
126 FreeRTOS port. Using a FIFO, DMA, circular buffer, etc. architecture will
\r
127 to improve efficiency. */
\r
128 static xQueueHandle xSerialTransmitQueue = NULL;
\r
129 static xQueueHandle xSerialReceiveQueue = NULL;
\r
130 static volatile portBASE_TYPE xTransmitStatus = 0UL;
\r
132 /*-----------------------------------------------------------*/
\r
134 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
136 unsigned long ulReloadValue = 0UL;
\r
138 ulReloadValue = ( configPERIPHERAL_CLOCK_HZ / ( 48UL * ulWantedBaud ) ) - 1UL;
\r
140 if( NULL == xSerialTransmitQueue )
\r
142 xSerialTransmitQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
143 xSerialReceiveQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
146 /* Enable ASC0 Module. */
\r
149 while ( 0 != ( WDT_CON0.reg & 0x1UL ) );
\r
150 ASC0_CLC.reg = 0x0200UL;
\r
154 /* Disable the Operation. */
\r
155 ASC0_CON.reg &= 0xFFFF7FFF;
\r
157 /* Set-up the GPIO Ports. */
\r
158 P3_IOCR0.reg = 0x00009000; /* 3.0 ASC In, 3.1 Alt ASC Out */
\r
160 /* Write the baud rate. */
\r
161 ASC0_BG.reg = ulReloadValue;
\r
163 /* Reconfigure and re-initialise the Operation. */
\r
164 ASC0_PISEL.reg = 0UL;
\r
165 ASC0_CON.reg = 0UL;
\r
166 ASC0_CON.bits.M = 0x01; /* 8bit async. */
\r
167 ASC0_CON.bits.REN = 0x01; /* Receiver enabled. */
\r
168 ASC0_CON.bits.FDE = 0x01; /* Fractional divider enabled. */
\r
169 ASC0_CON.bits.BRS = 0x01; /* Divide by three. */
\r
170 ASC0_CON.bits.LB = 0x01; /* Loopback enabled. */
\r
171 ASC0_CON.bits.R = 0x01; /* Enable the baud rate generator. */
\r
173 /* Install the Tx interrupt. */
\r
174 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_TX, prvTxBufferInterruptHandler, 0 ) )
\r
176 ASC0_TBSRC.reg = configINTERRUPT_PRIORITY_TX | 0x5000UL;
\r
177 xTransmitStatus = 0UL;
\r
180 /* Install the Rx interrupt. */
\r
181 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_RX, prvRxInterruptHandler, 0 ) )
\r
183 ASC0_RSRC.reg = configINTERRUPT_PRIORITY_RX | 0x5000UL;
\r
186 /* COM Handle is never used by demo code. */
\r
187 return (xComPortHandle) pdPASS;
\r
189 /*---------------------------------------------------------------------------*/
\r
191 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
193 unsigned short usChar;
\r
195 for( usChar = 0; usChar < usStringLength; usChar++ )
\r
197 xSerialPutChar( pxPort, pcString[ usChar ], portMAX_DELAY );
\r
200 /*---------------------------------------------------------------------------*/
\r
202 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
204 /* Just to remove compiler warnings about unused parameters. */
\r
207 return xQueueReceive( xSerialReceiveQueue, pcRxedChar, xBlockTime );
\r
209 /*---------------------------------------------------------------------------*/
\r
211 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
\r
213 portBASE_TYPE xReturn = pdPASS;
\r
215 /* Just to remove compiler warnings about unused parameters. */
\r
218 /* Send the character to the interrupt handler. */
\r
219 xReturn = xQueueSend( xSerialTransmitQueue, &cOutChar, xBlockTime );
\r
221 /* Start the transmission of bytes if necessary. */
\r
222 prvCheckTransmit();
\r
226 /*---------------------------------------------------------------------------*/
\r
228 static void prvTxBufferInterruptHandler( int iArg )
\r
230 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
231 unsigned char ucTx;
\r
233 /* Just to remove compiler warnings about unused parameters. */
\r
237 ASC0_TBSRC.reg |= 0x4000UL;
\r
238 xTransmitStatus = 1UL;
\r
240 /* TBUF Can be refilled. */
\r
241 if( pdPASS == xQueueReceiveFromISR( xSerialTransmitQueue, &ucTx, &xHigherPriorityTaskWoken ) )
\r
243 ASC0_TBUF.reg = ucTx;
\r
247 /* Failed to get a character out of the Queue. No longer busy. */
\r
248 xTransmitStatus = 0UL;
\r
251 /* Finally end ISR and switch Task if necessary. */
\r
252 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
254 /*---------------------------------------------------------------------------*/
\r
256 static void prvRxInterruptHandler( int iArg )
\r
258 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
259 unsigned char ucRx;
\r
261 /* Just to remove compiler warnings about unused parameters. */
\r
264 /* Grab the character as early as possible. */
\r
265 ucRx = ( unsigned char ) ASC0_RBUF.reg;
\r
268 ASC0_RSRC.reg |= 0x4000UL;
\r
270 /* Frame available in RBUF. */
\r
271 if( pdPASS != xQueueSendFromISR( xSerialReceiveQueue, &ucRx, &xHigherPriorityTaskWoken ) )
\r
273 /* Error handling code can go here. */
\r
276 /* Finally end ISR and switch Task if necessary. */
\r
277 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
279 /*---------------------------------------------------------------------------*/
\r
281 void prvCheckTransmit( void )
\r
283 /* Check to see if the interrupt handler is working its way through the
\r
285 if( 0 == xTransmitStatus )
\r
287 /* Not currently operational so kick off the first byte. */
\r
288 ASC0_TBSRC.reg |= 0x8000UL;
\r
291 /*---------------------------------------------------------------------------*/
\r