2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /* Hardware specific includes. */
\r
67 #include <machine/intrinsics.h>
\r
68 #include <machine/cint.h>
\r
69 #include <machine/wdtcon.h>
\r
71 /* Scheduler Includes. */
\r
72 #include "FreeRTOS.h"
\r
76 /* Demo Includes. */
\r
79 /*****************************************************************************
\r
82 * This file is here to provide a means of generating interrupts to test the
\r
83 * FreeRTOS tricore port. First - it configures the UART into loopback mode,
\r
84 * and has only been used in loopback mode. Therefore, the baud rate
\r
85 * calculation used has never been verified for correctness. Second -
\r
86 * characters are passed into and out of the interrupt service routines using
\r
87 * character queues. This provides a good test of the interrupt interaction,
\r
88 * context switching mechanism, and kernel loading, it is however highly
\r
89 * inefficient if the UART is being used to handle even moderate amounts of
\r
94 /*---------------------------------------------------------------------------*/
\r
97 * See if the Serial Transmit Interrupt is currently activated, meaning that
\r
98 * the interrupt is working through the back log of bytes that it needs to
\r
99 * send. If the ISR is not enabled, then it will be triggered to send the first
\r
100 * byte, and it will be automatically re-triggered when that byte has been
\r
101 * sent. When the queue is exhausted, the ISR disables itself.
\r
103 static void prvCheckTransmit( void );
\r
106 * The transmit and receive interrupt handlers.
\r
108 static void prvTxBufferInterruptHandler( int iArg ) __attribute__( ( longcall ) );
\r
109 static void prvRxInterruptHandler( int iArg )__attribute__( ( longcall ) );
\r
111 /*-----------------------------------------------------------*/
\r
113 /* Queues used to pass bytes into and out of the interrupt handlers.
\r
114 NOTE: This is not intended to be an example of an efficient interrupt handler,
\r
115 but instead to load the kernel and interrupt mechanisms in order to test the
\r
116 FreeRTOS port. Using a FIFO, DMA, circular buffer, etc. architecture will
\r
117 to improve efficiency. */
\r
118 static xQueueHandle xSerialTransmitQueue = NULL;
\r
119 static xQueueHandle xSerialReceiveQueue = NULL;
\r
120 static volatile portBASE_TYPE xTransmitStatus = 0UL;
\r
122 /*-----------------------------------------------------------*/
\r
124 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
126 unsigned long ulReloadValue = 0UL;
\r
128 ulReloadValue = ( configPERIPHERAL_CLOCK_HZ / ( 48UL * ulWantedBaud ) ) - 1UL;
\r
130 if( NULL == xSerialTransmitQueue )
\r
132 xSerialTransmitQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
133 xSerialReceiveQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
136 /* Enable ASC0 Module. */
\r
139 while ( 0 != ( WDT_CON0.reg & 0x1UL ) );
\r
140 ASC0_CLC.reg = 0x0200UL;
\r
144 /* Disable the Operation. */
\r
145 ASC0_CON.reg &= 0xFFFF7FFF;
\r
147 /* Set-up the GPIO Ports. */
\r
148 P3_IOCR0.reg = 0x00009000; /* 3.0 ASC In, 3.1 Alt ASC Out */
\r
150 /* Write the baud rate. */
\r
151 ASC0_BG.reg = ulReloadValue;
\r
153 /* Reconfigure and re-initialise the Operation. */
\r
154 ASC0_PISEL.reg = 0UL;
\r
155 ASC0_CON.reg = 0UL;
\r
156 ASC0_CON.bits.M = 0x01; /* 8bit async. */
\r
157 ASC0_CON.bits.REN = 0x01; /* Receiver enabled. */
\r
158 ASC0_CON.bits.FDE = 0x01; /* Fractional divider enabled. */
\r
159 ASC0_CON.bits.BRS = 0x01; /* Divide by three. */
\r
160 ASC0_CON.bits.LB = 0x01; /* Loopback enabled. */
\r
161 ASC0_CON.bits.R = 0x01; /* Enable the baud rate generator. */
\r
163 /* Install the Tx interrupt. */
\r
164 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_TX, prvTxBufferInterruptHandler, 0 ) )
\r
166 ASC0_TBSRC.reg = configINTERRUPT_PRIORITY_TX | 0x5000UL;
\r
167 xTransmitStatus = 0UL;
\r
170 /* Install the Rx interrupt. */
\r
171 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_RX, prvRxInterruptHandler, 0 ) )
\r
173 ASC0_RSRC.reg = configINTERRUPT_PRIORITY_RX | 0x5000UL;
\r
176 /* COM Handle is never used by demo code. */
\r
177 return (xComPortHandle) pdPASS;
\r
179 /*---------------------------------------------------------------------------*/
\r
181 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
183 unsigned short usChar;
\r
185 for( usChar = 0; usChar < usStringLength; usChar++ )
\r
187 xSerialPutChar( pxPort, pcString[ usChar ], portMAX_DELAY );
\r
190 /*---------------------------------------------------------------------------*/
\r
192 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
194 /* Just to remove compiler warnings about unused parameters. */
\r
197 return xQueueReceive( xSerialReceiveQueue, pcRxedChar, xBlockTime );
\r
199 /*---------------------------------------------------------------------------*/
\r
201 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
\r
203 portBASE_TYPE xReturn = pdPASS;
\r
205 /* Just to remove compiler warnings about unused parameters. */
\r
208 /* Send the character to the interrupt handler. */
\r
209 xReturn = xQueueSend( xSerialTransmitQueue, &cOutChar, xBlockTime );
\r
211 /* Start the transmission of bytes if necessary. */
\r
212 prvCheckTransmit();
\r
216 /*---------------------------------------------------------------------------*/
\r
218 static void prvTxBufferInterruptHandler( int iArg )
\r
220 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
221 unsigned char ucTx;
\r
223 /* Just to remove compiler warnings about unused parameters. */
\r
227 ASC0_TBSRC.reg |= 0x4000UL;
\r
228 xTransmitStatus = 1UL;
\r
230 /* TBUF Can be refilled. */
\r
231 if( pdPASS == xQueueReceiveFromISR( xSerialTransmitQueue, &ucTx, &xHigherPriorityTaskWoken ) )
\r
233 ASC0_TBUF.reg = ucTx;
\r
237 /* Failed to get a character out of the Queue. No longer busy. */
\r
238 xTransmitStatus = 0UL;
\r
241 /* Finally end ISR and switch Task if necessary. */
\r
242 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
244 /*---------------------------------------------------------------------------*/
\r
246 static void prvRxInterruptHandler( int iArg )
\r
248 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
249 unsigned char ucRx;
\r
251 /* Just to remove compiler warnings about unused parameters. */
\r
254 /* Grab the character as early as possible. */
\r
255 ucRx = ( unsigned char ) ASC0_RBUF.reg;
\r
258 ASC0_RSRC.reg |= 0x4000UL;
\r
260 /* Frame available in RBUF. */
\r
261 if( pdPASS != xQueueSendFromISR( xSerialReceiveQueue, &ucRx, &xHigherPriorityTaskWoken ) )
\r
263 /* Error handling code can go here. */
\r
266 /* Finally end ISR and switch Task if necessary. */
\r
267 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
269 /*---------------------------------------------------------------------------*/
\r
271 void prvCheckTransmit( void )
\r
273 /* Check to see if the interrupt handler is working its way through the
\r
275 if( 0 == xTransmitStatus )
\r
277 /* Not currently operational so kick off the first byte. */
\r
278 ASC0_TBSRC.reg |= 0x8000UL;
\r
281 /*---------------------------------------------------------------------------*/
\r