2 FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /* Hardware specific includes. */
\r
68 #include <machine/intrinsics.h>
\r
69 #include <machine/cint.h>
\r
70 #include <machine/wdtcon.h>
\r
72 /* Scheduler Includes. */
\r
73 #include "FreeRTOS.h"
\r
77 /* Demo Includes. */
\r
80 /*****************************************************************************
\r
83 * This file is here to provide a means of generating interrupts to test the
\r
84 * FreeRTOS tricore port. First - it configures the UART into loopback mode,
\r
85 * and has only been used in loopback mode. Therefore, the baud rate
\r
86 * calculation used has never been verified for correctness. Second -
\r
87 * characters are passed into and out of the interrupt service routines using
\r
88 * character queues. This provides a good test of the interrupt interaction,
\r
89 * context switching mechanism, and kernel loading, it is however highly
\r
90 * inefficient if the UART is being used to handle even moderate amounts of
\r
95 /*---------------------------------------------------------------------------*/
\r
98 * See if the Serial Transmit Interrupt is currently activated, meaning that
\r
99 * the interrupt is working through the back log of bytes that it needs to
\r
100 * send. If the ISR is not enabled, then it will be triggered to send the first
\r
101 * byte, and it will be automatically re-triggered when that byte has been
\r
102 * sent. When the queue is exhausted, the ISR disables itself.
\r
104 static void prvCheckTransmit( void );
\r
107 * The transmit and receive interrupt handlers.
\r
109 static void prvTxBufferInterruptHandler( int iArg ) __attribute__( ( longcall ) );
\r
110 static void prvRxInterruptHandler( int iArg )__attribute__( ( longcall ) );
\r
112 /*-----------------------------------------------------------*/
\r
114 /* Queues used to pass bytes into and out of the interrupt handlers.
\r
115 NOTE: This is not intended to be an example of an efficient interrupt handler,
\r
116 but instead to load the kernel and interrupt mechanisms in order to test the
\r
117 FreeRTOS port. Using a FIFO, DMA, circular buffer, etc. architecture will
\r
118 to improve efficiency. */
\r
119 static xQueueHandle xSerialTransmitQueue = NULL;
\r
120 static xQueueHandle xSerialReceiveQueue = NULL;
\r
121 static volatile portBASE_TYPE xTransmitStatus = 0UL;
\r
123 /*-----------------------------------------------------------*/
\r
125 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
127 unsigned long ulReloadValue = 0UL;
\r
129 ulReloadValue = ( configPERIPHERAL_CLOCK_HZ / ( 48UL * ulWantedBaud ) ) - 1UL;
\r
131 if( NULL == xSerialTransmitQueue )
\r
133 xSerialTransmitQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
134 xSerialReceiveQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
137 /* Enable ASC0 Module. */
\r
140 while ( 0 != ( WDT_CON0.reg & 0x1UL ) );
\r
141 ASC0_CLC.reg = 0x0200UL;
\r
145 /* Disable the Operation. */
\r
146 ASC0_CON.reg &= 0xFFFF7FFF;
\r
148 /* Set-up the GPIO Ports. */
\r
149 P3_IOCR0.reg = 0x00009000; /* 3.0 ASC In, 3.1 Alt ASC Out */
\r
151 /* Write the baud rate. */
\r
152 ASC0_BG.reg = ulReloadValue;
\r
154 /* Reconfigure and re-initialise the Operation. */
\r
155 ASC0_PISEL.reg = 0UL;
\r
156 ASC0_CON.reg = 0UL;
\r
157 ASC0_CON.bits.M = 0x01; /* 8bit async. */
\r
158 ASC0_CON.bits.REN = 0x01; /* Receiver enabled. */
\r
159 ASC0_CON.bits.FDE = 0x01; /* Fractional divider enabled. */
\r
160 ASC0_CON.bits.BRS = 0x01; /* Divide by three. */
\r
161 ASC0_CON.bits.LB = 0x01; /* Loopback enabled. */
\r
162 ASC0_CON.bits.R = 0x01; /* Enable the baud rate generator. */
\r
164 /* Install the Tx interrupt. */
\r
165 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_TX, prvTxBufferInterruptHandler, 0 ) )
\r
167 ASC0_TBSRC.reg = configINTERRUPT_PRIORITY_TX | 0x5000UL;
\r
168 xTransmitStatus = 0UL;
\r
171 /* Install the Rx interrupt. */
\r
172 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_RX, prvRxInterruptHandler, 0 ) )
\r
174 ASC0_RSRC.reg = configINTERRUPT_PRIORITY_RX | 0x5000UL;
\r
177 /* COM Handle is never used by demo code. */
\r
178 return (xComPortHandle) pdPASS;
\r
180 /*---------------------------------------------------------------------------*/
\r
182 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
184 unsigned short usChar;
\r
186 for( usChar = 0; usChar < usStringLength; usChar++ )
\r
188 xSerialPutChar( pxPort, pcString[ usChar ], portMAX_DELAY );
\r
191 /*---------------------------------------------------------------------------*/
\r
193 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
195 /* Just to remove compiler warnings about unused parameters. */
\r
198 return xQueueReceive( xSerialReceiveQueue, pcRxedChar, xBlockTime );
\r
200 /*---------------------------------------------------------------------------*/
\r
202 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
\r
204 portBASE_TYPE xReturn = pdPASS;
\r
206 /* Just to remove compiler warnings about unused parameters. */
\r
209 /* Send the character to the interrupt handler. */
\r
210 xReturn = xQueueSend( xSerialTransmitQueue, &cOutChar, xBlockTime );
\r
212 /* Start the transmission of bytes if necessary. */
\r
213 prvCheckTransmit();
\r
217 /*---------------------------------------------------------------------------*/
\r
219 static void prvTxBufferInterruptHandler( int iArg )
\r
221 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
222 unsigned char ucTx;
\r
224 /* Just to remove compiler warnings about unused parameters. */
\r
228 ASC0_TBSRC.reg |= 0x4000UL;
\r
229 xTransmitStatus = 1UL;
\r
231 /* TBUF Can be refilled. */
\r
232 if( pdPASS == xQueueReceiveFromISR( xSerialTransmitQueue, &ucTx, &xHigherPriorityTaskWoken ) )
\r
234 ASC0_TBUF.reg = ucTx;
\r
238 /* Failed to get a character out of the Queue. No longer busy. */
\r
239 xTransmitStatus = 0UL;
\r
242 /* Finally end ISR and switch Task if necessary. */
\r
243 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
245 /*---------------------------------------------------------------------------*/
\r
247 static void prvRxInterruptHandler( int iArg )
\r
249 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
250 unsigned char ucRx;
\r
252 /* Just to remove compiler warnings about unused parameters. */
\r
255 /* Grab the character as early as possible. */
\r
256 ucRx = ( unsigned char ) ASC0_RBUF.reg;
\r
259 ASC0_RSRC.reg |= 0x4000UL;
\r
261 /* Frame available in RBUF. */
\r
262 if( pdPASS != xQueueSendFromISR( xSerialReceiveQueue, &ucRx, &xHigherPriorityTaskWoken ) )
\r
264 /* Error handling code can go here. */
\r
267 /* Finally end ISR and switch Task if necessary. */
\r
268 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
270 /*---------------------------------------------------------------------------*/
\r
272 void prvCheckTransmit( void )
\r
274 /* Check to see if the interrupt handler is working its way through the
\r
276 if( 0 == xTransmitStatus )
\r
278 /* Not currently operational so kick off the first byte. */
\r
279 ASC0_TBSRC.reg |= 0x8000UL;
\r
282 /*---------------------------------------------------------------------------*/
\r