2 FreeRTOS V8.1.0 - Copyright (C) 2014 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 !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\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
67 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART2.
\r
69 ***Note*** This example uses queues to send each character into an interrupt
\r
70 service routine and out of an interrupt service routine individually. This
\r
71 is done to demonstrate queues being used in an interrupt, and to deliberately
\r
72 load the system to test the FreeRTOS port. It is *NOT* meant to be an
\r
73 example of an efficient implementation. An efficient implementation should
\r
74 use the DMA, and only use FreeRTOS API functions when enough has been
\r
75 received to warrant a task being unblocked to process the data.
\r
78 /* Scheduler includes. */
\r
79 #include "FreeRTOS.h"
\r
82 #include "comtest2.h"
\r
84 /* Driver includes. */
\r
85 #include "r_typedefs.h"
\r
86 #include "dev_drv.h"
\r
87 #include "devdrv_scif_uart.h"
\r
88 #include "sio_char.h"
\r
89 #include "iodefine.h"
\r
90 #include "devdrv_intc.h"
\r
92 /* Demo application includes. */
\r
95 /*-----------------------------------------------------------*/
\r
98 #define serINVALID_QUEUE ( ( QueueHandle_t ) 0 )
\r
99 #define serNO_BLOCK ( ( TickType_t ) 0 )
\r
101 /*-----------------------------------------------------------*/
\r
103 /* Handlers for the Rx and Tx interrupts respectively. */
\r
104 static void prvRXI_Handler( uint32_t ulUnusedParameter );
\r
105 static void prvTXI_Handler( uint32_t ulUnusedParameter );
\r
107 /*-----------------------------------------------------------*/
\r
109 /* The queue used to hold received characters. */
\r
110 static QueueHandle_t xRxedChars;
\r
111 static QueueHandle_t xCharsForTx;
\r
113 /*-----------------------------------------------------------*/
\r
116 * See the serial2.h header file.
\r
118 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
120 /* Baud is set in IoInitScif2(), called in prvSetupHardware() in main.c. */
\r
121 ( void ) ulWantedBaud;
\r
123 /* Create the queues used to hold Rx/Tx characters. Note the comments at
\r
124 the top of this file regarding the use of queues in this manner. */
\r
125 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( char ) );
\r
126 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( char ) );
\r
128 /* If the queues were created correctly then setup the serial port
\r
130 if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
\r
132 /* Register RXI and TXI handlers. */
\r
133 R_INTC_RegistIntFunc( INTC_ID_RXI2, prvRXI_Handler );
\r
134 R_INTC_RegistIntFunc( INTC_ID_TXI2, prvTXI_Handler );
\r
136 /* Set both interrupts such that they can interrupt the tick. Also
\r
137 set the Rx interrupt above the Tx interrupt in the hope that (for test
\r
138 purposes) the Tx interrupt will interrupt the Rx interrupt. */
\r
139 R_INTC_SetPriority( INTC_ID_RXI2, configMAX_API_CALL_INTERRUPT_PRIORITY );
\r
140 R_INTC_SetPriority( INTC_ID_TXI2, ( configMAX_API_CALL_INTERRUPT_PRIORITY + 1 ) );
\r
142 /* This driver is intended to test interrupt interactions, and not
\r
143 intended to be efficient. Therefore set the RX trigger level to 1. */
\r
144 SCIF2.SCFCR.BIT.RTRG = 0;
\r
145 SCIF2.SCFCR.BIT.TTRG = 3;
\r
147 /* Enable Rx interrupt. Tx interrupt will be enabled when a Tx is
\r
149 SCIF2.SCSCR.BIT.RIE = 1;
\r
150 R_INTC_Enable( INTC_ID_RXI2 );
\r
151 R_INTC_Enable( INTC_ID_TXI2 );
\r
154 /* This demo file only supports a single port but we have to return
\r
155 something to comply with the standard demo header file. */
\r
156 return ( xComPortHandle ) 0;
\r
158 /*-----------------------------------------------------------*/
\r
160 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
162 /* The port handle is not required as this driver only supports one port. */
\r
165 /* Get the next character from the buffer. Return false if no characters
\r
166 are available, or arrive before xBlockTime expires. */
\r
167 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
176 /*-----------------------------------------------------------*/
\r
178 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
182 /* A couple of parameters that this port does not use. */
\r
183 ( void ) usStringLength;
\r
186 /* Send each character in the string, one at a time. */
\r
187 pxNext = ( char * ) pcString;
\r
190 xSerialPutChar( pxPort, *pxNext, portMAX_DELAY );
\r
194 /*-----------------------------------------------------------*/
\r
196 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
198 signed portBASE_TYPE xReturn;
\r
200 /* Note the comments at the top of this file regarding the use of queues in
\r
202 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdPASS )
\r
206 /* Enable the interrupt which will remove the character from the
\r
208 SCIF2.SCSCR.BIT.TIE = 1;
\r
217 /*-----------------------------------------------------------*/
\r
219 void vSerialClose( xComPortHandle xPort )
\r
221 /* Not supported as not required by the demo application. */
\r
223 /*-----------------------------------------------------------*/
\r
225 static void prvRXI_Handler( uint32_t ulUnusedParameter )
\r
227 unsigned char ucRxedByte;
\r
228 long lHigherPriorityTaskWoken = pdFALSE;
\r
230 /* The parameter is not used. It is only present because Renesas drivers
\r
231 are used to install the interrupt handlers, and the drivers expect the
\r
232 parameter to be present. */
\r
233 ( void ) ulUnusedParameter;
\r
235 /* Note the comments at the top of this file regarding the use of queues in
\r
237 while( ( SCIF2.SCFDR.WORD & 0x1F ) != 0 )
\r
239 ucRxedByte = SCIF2.SCFRDR.BYTE;
\r
240 xQueueSendFromISR( xRxedChars, &ucRxedByte, &lHigherPriorityTaskWoken );
\r
243 SCIF2.SCFSR.BIT.RDF = 0;
\r
245 /* If sending to the queue has caused a task to unblock, and the unblocked
\r
246 task has a priority equal to or higher than the currently running task (the
\r
247 task this ISR interrupted), then lHigherPriorityTaskWoken will have
\r
248 automatically been set to pdTRUE within the queue send function.
\r
249 portYIELD_FROM_ISR() will then ensure that this ISR returns directly to the
\r
250 higher priority unblocked task. */
\r
251 portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
\r
253 /*-----------------------------------------------------------*/
\r
255 static void prvTXI_Handler( uint32_t ulUnusedParameter )
\r
257 unsigned char ucByte;
\r
258 long lHigherPriorityTaskWoken = pdFALSE;
\r
260 /* The parameter is not used. It is only present because Renesas drivers
\r
261 are used to install the interrupt handlers, and the drivers expect the
\r
262 parameter to be present. */
\r
263 ( void ) ulUnusedParameter;
\r
265 /* Note the comments at the top of this file regarding the use of queues in
\r
267 if( xQueueReceiveFromISR( xCharsForTx, &ucByte, &lHigherPriorityTaskWoken ) == pdPASS )
\r
269 SCIF2.SCFTDR.BYTE = ucByte;
\r
271 /* Clear TDRE and TEND flag */
\r
272 SCIF2.SCFSR.WORD &= ~0x0060;
\r
276 /* No more characters. Disable the interrupt. */
\r
277 SCIF2.SCSCR.BIT.TIE = 0;
\r
280 /* If receiving from the queue has caused a task to unblock, and the
\r
281 unblocked task has a priority equal to or higher than the currently running
\r
282 task (the task this ISR interrupted), then lHigherPriorityTaskWoken will
\r
283 have automatically been set to pdTRUE within the queue receive function.
\r
284 portYIELD_FROM_ISR() will then ensure that this ISR returns directly to the
\r
285 higher priority unblocked task. */
\r
286 portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
\r
288 /*-----------------------------------------------------------*/
\r