2 FreeRTOS V9.0.0rc1 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /* Hardware specific includes. */
\r
72 #include <machine/intrinsics.h>
\r
73 #include <machine/cint.h>
\r
74 #include <machine/wdtcon.h>
\r
76 /* Scheduler Includes. */
\r
77 #include "FreeRTOS.h"
\r
81 /* Demo Includes. */
\r
84 /*****************************************************************************
\r
87 * This file is here to provide a means of generating interrupts to test the
\r
88 * FreeRTOS tricore port. First - it configures the UART into loopback mode,
\r
89 * and has only been used in loopback mode. Therefore, the baud rate
\r
90 * calculation used has never been verified for correctness. Second -
\r
91 * characters are passed into and out of the interrupt service routines using
\r
92 * character queues. This provides a good test of the interrupt interaction,
\r
93 * context switching mechanism, and kernel loading, it is however highly
\r
94 * inefficient if the UART is being used to handle even moderate amounts of
\r
99 /*---------------------------------------------------------------------------*/
\r
102 * See if the Serial Transmit Interrupt is currently activated, meaning that
\r
103 * the interrupt is working through the back log of bytes that it needs to
\r
104 * send. If the ISR is not enabled, then it will be triggered to send the first
\r
105 * byte, and it will be automatically re-triggered when that byte has been
\r
106 * sent. When the queue is exhausted, the ISR disables itself.
\r
108 static void prvCheckTransmit( void );
\r
111 * The transmit and receive interrupt handlers.
\r
113 static void prvTxBufferInterruptHandler( int iArg ) __attribute__( ( longcall ) );
\r
114 static void prvRxInterruptHandler( int iArg )__attribute__( ( longcall ) );
\r
116 /*-----------------------------------------------------------*/
\r
118 /* Queues used to pass bytes into and out of the interrupt handlers.
\r
119 NOTE: This is not intended to be an example of an efficient interrupt handler,
\r
120 but instead to load the kernel and interrupt mechanisms in order to test the
\r
121 FreeRTOS port. Using a FIFO, DMA, circular buffer, etc. architecture will
\r
122 to improve efficiency. */
\r
123 static QueueHandle_t xSerialTransmitQueue = NULL;
\r
124 static QueueHandle_t xSerialReceiveQueue = NULL;
\r
125 static volatile portBASE_TYPE xTransmitStatus = 0UL;
\r
127 /*-----------------------------------------------------------*/
\r
129 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
131 unsigned long ulReloadValue = 0UL;
\r
133 ulReloadValue = ( configPERIPHERAL_CLOCK_HZ / ( 48UL * ulWantedBaud ) ) - 1UL;
\r
135 if( NULL == xSerialTransmitQueue )
\r
137 xSerialTransmitQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
138 xSerialReceiveQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
141 /* Enable ASC0 Module. */
\r
144 while ( 0 != ( WDT_CON0.reg & 0x1UL ) );
\r
145 ASC0_CLC.reg = 0x0200UL;
\r
149 /* Disable the Operation. */
\r
150 ASC0_CON.reg &= 0xFFFF7FFF;
\r
152 /* Set-up the GPIO Ports. */
\r
153 P3_IOCR0.reg = 0x00009000; /* 3.0 ASC In, 3.1 Alt ASC Out */
\r
155 /* Write the baud rate. */
\r
156 ASC0_BG.reg = ulReloadValue;
\r
158 /* Reconfigure and re-initialise the Operation. */
\r
159 ASC0_PISEL.reg = 0UL;
\r
160 ASC0_CON.reg = 0UL;
\r
161 ASC0_CON.bits.M = 0x01; /* 8bit async. */
\r
162 ASC0_CON.bits.REN = 0x01; /* Receiver enabled. */
\r
163 ASC0_CON.bits.FDE = 0x01; /* Fractional divider enabled. */
\r
164 ASC0_CON.bits.BRS = 0x01; /* Divide by three. */
\r
165 ASC0_CON.bits.LB = 0x01; /* Loopback enabled. */
\r
166 ASC0_CON.bits.R = 0x01; /* Enable the baud rate generator. */
\r
168 /* Install the Tx interrupt. */
\r
169 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_TX, prvTxBufferInterruptHandler, 0 ) )
\r
171 ASC0_TBSRC.reg = configINTERRUPT_PRIORITY_TX | 0x5000UL;
\r
172 xTransmitStatus = 0UL;
\r
175 /* Install the Rx interrupt. */
\r
176 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_RX, prvRxInterruptHandler, 0 ) )
\r
178 ASC0_RSRC.reg = configINTERRUPT_PRIORITY_RX | 0x5000UL;
\r
181 /* COM Handle is never used by demo code. */
\r
182 return (xComPortHandle) pdPASS;
\r
184 /*---------------------------------------------------------------------------*/
\r
186 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
188 unsigned short usChar;
\r
190 for( usChar = 0; usChar < usStringLength; usChar++ )
\r
192 xSerialPutChar( pxPort, pcString[ usChar ], portMAX_DELAY );
\r
195 /*---------------------------------------------------------------------------*/
\r
197 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
199 /* Just to remove compiler warnings about unused parameters. */
\r
202 return xQueueReceive( xSerialReceiveQueue, pcRxedChar, xBlockTime );
\r
204 /*---------------------------------------------------------------------------*/
\r
206 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
208 portBASE_TYPE xReturn = pdPASS;
\r
210 /* Just to remove compiler warnings about unused parameters. */
\r
213 /* Send the character to the interrupt handler. */
\r
214 xReturn = xQueueSend( xSerialTransmitQueue, &cOutChar, xBlockTime );
\r
216 /* Start the transmission of bytes if necessary. */
\r
217 prvCheckTransmit();
\r
221 /*---------------------------------------------------------------------------*/
\r
223 static void prvTxBufferInterruptHandler( int iArg )
\r
225 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
226 unsigned char ucTx;
\r
228 /* Just to remove compiler warnings about unused parameters. */
\r
232 ASC0_TBSRC.reg |= 0x4000UL;
\r
233 xTransmitStatus = 1UL;
\r
235 /* TBUF Can be refilled. */
\r
236 if( pdPASS == xQueueReceiveFromISR( xSerialTransmitQueue, &ucTx, &xHigherPriorityTaskWoken ) )
\r
238 ASC0_TBUF.reg = ucTx;
\r
242 /* Failed to get a character out of the Queue. No longer busy. */
\r
243 xTransmitStatus = 0UL;
\r
246 /* Finally end ISR and switch Task if necessary. */
\r
247 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
249 /*---------------------------------------------------------------------------*/
\r
251 static void prvRxInterruptHandler( int iArg )
\r
253 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
254 unsigned char ucRx;
\r
256 /* Just to remove compiler warnings about unused parameters. */
\r
259 /* Grab the character as early as possible. */
\r
260 ucRx = ( unsigned char ) ASC0_RBUF.reg;
\r
263 ASC0_RSRC.reg |= 0x4000UL;
\r
265 /* Frame available in RBUF. */
\r
266 if( pdPASS != xQueueSendFromISR( xSerialReceiveQueue, &ucRx, &xHigherPriorityTaskWoken ) )
\r
268 /* Error handling code can go here. */
\r
271 /* Finally end ISR and switch Task if necessary. */
\r
272 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
274 /*---------------------------------------------------------------------------*/
\r
276 void prvCheckTransmit( void )
\r
278 /* Check to see if the interrupt handler is working its way through the
\r
280 if( 0 == xTransmitStatus )
\r
282 /* Not currently operational so kick off the first byte. */
\r
283 ASC0_TBSRC.reg |= 0x8000UL;
\r
286 /*---------------------------------------------------------------------------*/
\r