2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /* Hardware specific includes. */
\r
31 #include <machine/intrinsics.h>
\r
32 #include <machine/cint.h>
\r
33 #include <machine/wdtcon.h>
\r
35 /* Scheduler Includes. */
\r
36 #include "FreeRTOS.h"
\r
40 /* Demo Includes. */
\r
43 /*****************************************************************************
\r
46 * This file is here to provide a means of generating interrupts to test the
\r
47 * FreeRTOS tricore port. First - it configures the UART into loopback mode,
\r
48 * and has only been used in loopback mode. Therefore, the baud rate
\r
49 * calculation used has never been verified for correctness. Second -
\r
50 * characters are passed into and out of the interrupt service routines using
\r
51 * character queues. This provides a good test of the interrupt interaction,
\r
52 * context switching mechanism, and kernel loading, it is however highly
\r
53 * inefficient if the UART is being used to handle even moderate amounts of
\r
58 /*---------------------------------------------------------------------------*/
\r
61 * See if the Serial Transmit Interrupt is currently activated, meaning that
\r
62 * the interrupt is working through the back log of bytes that it needs to
\r
63 * send. If the ISR is not enabled, then it will be triggered to send the first
\r
64 * byte, and it will be automatically re-triggered when that byte has been
\r
65 * sent. When the queue is exhausted, the ISR disables itself.
\r
67 static void prvCheckTransmit( void );
\r
70 * The transmit and receive interrupt handlers.
\r
72 static void prvTxBufferInterruptHandler( int iArg ) __attribute__( ( longcall ) );
\r
73 static void prvRxInterruptHandler( int iArg )__attribute__( ( longcall ) );
\r
75 /*-----------------------------------------------------------*/
\r
77 /* Queues used to pass bytes into and out of the interrupt handlers.
\r
78 NOTE: This is not intended to be an example of an efficient interrupt handler,
\r
79 but instead to load the kernel and interrupt mechanisms in order to test the
\r
80 FreeRTOS port. Using a FIFO, DMA, circular buffer, etc. architecture will
\r
81 to improve efficiency. */
\r
82 static QueueHandle_t xSerialTransmitQueue = NULL;
\r
83 static QueueHandle_t xSerialReceiveQueue = NULL;
\r
84 static volatile portBASE_TYPE xTransmitStatus = 0UL;
\r
86 /*-----------------------------------------------------------*/
\r
88 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
90 unsigned long ulReloadValue = 0UL;
\r
92 ulReloadValue = ( configPERIPHERAL_CLOCK_HZ / ( 48UL * ulWantedBaud ) ) - 1UL;
\r
94 if( NULL == xSerialTransmitQueue )
\r
96 xSerialTransmitQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
97 xSerialReceiveQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
100 /* Enable ASC0 Module. */
\r
103 while ( 0 != ( WDT_CON0.reg & 0x1UL ) );
\r
104 ASC0_CLC.reg = 0x0200UL;
\r
108 /* Disable the Operation. */
\r
109 ASC0_CON.reg &= 0xFFFF7FFF;
\r
111 /* Set-up the GPIO Ports. */
\r
112 P3_IOCR0.reg = 0x00009000; /* 3.0 ASC In, 3.1 Alt ASC Out */
\r
114 /* Write the baud rate. */
\r
115 ASC0_BG.reg = ulReloadValue;
\r
117 /* Reconfigure and re-initialise the Operation. */
\r
118 ASC0_PISEL.reg = 0UL;
\r
119 ASC0_CON.reg = 0UL;
\r
120 ASC0_CON.bits.M = 0x01; /* 8bit async. */
\r
121 ASC0_CON.bits.REN = 0x01; /* Receiver enabled. */
\r
122 ASC0_CON.bits.FDE = 0x01; /* Fractional divider enabled. */
\r
123 ASC0_CON.bits.BRS = 0x01; /* Divide by three. */
\r
124 ASC0_CON.bits.LB = 0x01; /* Loopback enabled. */
\r
125 ASC0_CON.bits.R = 0x01; /* Enable the baud rate generator. */
\r
127 /* Install the Tx interrupt. */
\r
128 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_TX, prvTxBufferInterruptHandler, 0 ) )
\r
130 ASC0_TBSRC.reg = configINTERRUPT_PRIORITY_TX | 0x5000UL;
\r
131 xTransmitStatus = 0UL;
\r
134 /* Install the Rx interrupt. */
\r
135 if( 0 != _install_int_handler( configINTERRUPT_PRIORITY_RX, prvRxInterruptHandler, 0 ) )
\r
137 ASC0_RSRC.reg = configINTERRUPT_PRIORITY_RX | 0x5000UL;
\r
140 /* COM Handle is never used by demo code. */
\r
141 return (xComPortHandle) pdPASS;
\r
143 /*---------------------------------------------------------------------------*/
\r
145 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
147 unsigned short usChar;
\r
149 for( usChar = 0; usChar < usStringLength; usChar++ )
\r
151 xSerialPutChar( pxPort, pcString[ usChar ], portMAX_DELAY );
\r
154 /*---------------------------------------------------------------------------*/
\r
156 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
158 /* Just to remove compiler warnings about unused parameters. */
\r
161 return xQueueReceive( xSerialReceiveQueue, pcRxedChar, xBlockTime );
\r
163 /*---------------------------------------------------------------------------*/
\r
165 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
167 portBASE_TYPE xReturn = pdPASS;
\r
169 /* Just to remove compiler warnings about unused parameters. */
\r
172 /* Send the character to the interrupt handler. */
\r
173 xReturn = xQueueSend( xSerialTransmitQueue, &cOutChar, xBlockTime );
\r
175 /* Start the transmission of bytes if necessary. */
\r
176 prvCheckTransmit();
\r
180 /*---------------------------------------------------------------------------*/
\r
182 static void prvTxBufferInterruptHandler( int iArg )
\r
184 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
185 unsigned char ucTx;
\r
187 /* Just to remove compiler warnings about unused parameters. */
\r
191 ASC0_TBSRC.reg |= 0x4000UL;
\r
192 xTransmitStatus = 1UL;
\r
194 /* TBUF Can be refilled. */
\r
195 if( pdPASS == xQueueReceiveFromISR( xSerialTransmitQueue, &ucTx, &xHigherPriorityTaskWoken ) )
\r
197 ASC0_TBUF.reg = ucTx;
\r
201 /* Failed to get a character out of the Queue. No longer busy. */
\r
202 xTransmitStatus = 0UL;
\r
205 /* Finally end ISR and switch Task if necessary. */
\r
206 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
208 /*---------------------------------------------------------------------------*/
\r
210 static void prvRxInterruptHandler( int iArg )
\r
212 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
213 unsigned char ucRx;
\r
215 /* Just to remove compiler warnings about unused parameters. */
\r
218 /* Grab the character as early as possible. */
\r
219 ucRx = ( unsigned char ) ASC0_RBUF.reg;
\r
222 ASC0_RSRC.reg |= 0x4000UL;
\r
224 /* Frame available in RBUF. */
\r
225 if( pdPASS != xQueueSendFromISR( xSerialReceiveQueue, &ucRx, &xHigherPriorityTaskWoken ) )
\r
227 /* Error handling code can go here. */
\r
230 /* Finally end ISR and switch Task if necessary. */
\r
231 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
233 /*---------------------------------------------------------------------------*/
\r
235 void prvCheckTransmit( void )
\r
237 /* Check to see if the interrupt handler is working its way through the
\r
239 if( 0 == xTransmitStatus )
\r
241 /* Not currently operational so kick off the first byte. */
\r
242 ASC0_TBSRC.reg |= 0x8000UL;
\r
245 /*---------------------------------------------------------------------------*/
\r