2 FreeRTOS V8.2.3 - Copyright (C) 2015 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
71 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART2.
\r
73 ***Note*** This example uses queues to send each character into an interrupt
\r
74 service routine and out of an interrupt service routine individually. This
\r
75 is done to demonstrate queues being used in an interrupt, and to deliberately
\r
76 load the system to test the FreeRTOS port. It is *NOT* meant to be an
\r
77 example of an efficient implementation. An efficient implementation should
\r
78 use the DMA, and only use FreeRTOS API functions when enough has been
\r
79 received to warrant a task being unblocked to process the data.
\r
82 /* Scheduler includes. */
\r
83 #include "FreeRTOS.h"
\r
86 #include "comtest2.h"
\r
88 /* Driver includes. */
\r
89 #include "r_typedefs.h"
\r
90 #include "dev_drv.h"
\r
91 #include "devdrv_scif_uart.h"
\r
92 #include "sio_char.h"
\r
93 #include "iodefine.h"
\r
94 #include "devdrv_intc.h"
\r
96 /* Demo application includes. */
\r
99 /*-----------------------------------------------------------*/
\r
101 /* Misc defines. */
\r
102 #define serINVALID_QUEUE ( ( QueueHandle_t ) 0 )
\r
103 #define serNO_BLOCK ( ( TickType_t ) 0 )
\r
105 /*-----------------------------------------------------------*/
\r
107 /* Handlers for the Rx and Tx interrupts respectively. */
\r
108 static void prvRXI_Handler( uint32_t ulUnusedParameter );
\r
109 static void prvTXI_Handler( uint32_t ulUnusedParameter );
\r
111 /*-----------------------------------------------------------*/
\r
113 /* The queue used to hold received characters. */
\r
114 static QueueHandle_t xRxedChars;
\r
115 static QueueHandle_t xCharsForTx;
\r
117 /*-----------------------------------------------------------*/
\r
120 * See the serial2.h header file.
\r
122 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
124 /* Baud is set in IoInitScif2(), called in prvSetupHardware() in main.c. */
\r
125 ( void ) ulWantedBaud;
\r
127 /* Create the queues used to hold Rx/Tx characters. Note the comments at
\r
128 the top of this file regarding the use of queues in this manner. */
\r
129 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( char ) );
\r
130 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( char ) );
\r
132 /* If the queues were created correctly then setup the serial port
\r
134 if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
\r
136 /* Register RXI and TXI handlers. */
\r
137 R_INTC_RegistIntFunc( INTC_ID_RXI2, prvRXI_Handler );
\r
138 R_INTC_RegistIntFunc( INTC_ID_TXI2, prvTXI_Handler );
\r
140 /* Set both interrupts such that they can interrupt the tick. Also
\r
141 set the Rx interrupt above the Tx interrupt in the hope that (for test
\r
142 purposes) the Tx interrupt will interrupt the Rx interrupt. */
\r
143 R_INTC_SetPriority( INTC_ID_RXI2, configMAX_API_CALL_INTERRUPT_PRIORITY );
\r
144 R_INTC_SetPriority( INTC_ID_TXI2, ( configMAX_API_CALL_INTERRUPT_PRIORITY + 1 ) );
\r
146 /* This driver is intended to test interrupt interactions, and not
\r
147 intended to be efficient. Therefore set the RX trigger level to 1. */
\r
148 SCIF2.SCFCR.BIT.RTRG = 0;
\r
149 SCIF2.SCFCR.BIT.TTRG = 3;
\r
151 /* Enable Rx interrupt. Tx interrupt will be enabled when a Tx is
\r
153 SCIF2.SCSCR.BIT.RIE = 1;
\r
154 R_INTC_Enable( INTC_ID_RXI2 );
\r
155 R_INTC_Enable( INTC_ID_TXI2 );
\r
158 /* This demo file only supports a single port but we have to return
\r
159 something to comply with the standard demo header file. */
\r
160 return ( xComPortHandle ) 0;
\r
162 /*-----------------------------------------------------------*/
\r
164 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
166 /* The port handle is not required as this driver only supports one port. */
\r
169 /* Get the next character from the buffer. Return false if no characters
\r
170 are available, or arrive before xBlockTime expires. */
\r
171 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
180 /*-----------------------------------------------------------*/
\r
182 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
186 /* A couple of parameters that this port does not use. */
\r
187 ( void ) usStringLength;
\r
190 /* Send each character in the string, one at a time. */
\r
191 pxNext = ( char * ) pcString;
\r
194 xSerialPutChar( pxPort, *pxNext, portMAX_DELAY );
\r
198 /*-----------------------------------------------------------*/
\r
200 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
202 signed portBASE_TYPE xReturn;
\r
204 /* Note the comments at the top of this file regarding the use of queues in
\r
206 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdPASS )
\r
210 /* Enable the interrupt which will remove the character from the
\r
212 SCIF2.SCSCR.BIT.TIE = 1;
\r
221 /*-----------------------------------------------------------*/
\r
223 void vSerialClose( xComPortHandle xPort )
\r
225 /* Not supported as not required by the demo application. */
\r
227 /*-----------------------------------------------------------*/
\r
229 static void prvRXI_Handler( uint32_t ulUnusedParameter )
\r
231 unsigned char ucRxedByte;
\r
232 long lHigherPriorityTaskWoken = pdFALSE;
\r
234 /* The parameter is not used. It is only present because Renesas drivers
\r
235 are used to install the interrupt handlers, and the drivers expect the
\r
236 parameter to be present. */
\r
237 ( void ) ulUnusedParameter;
\r
239 /* Note the comments at the top of this file regarding the use of queues in
\r
241 while( ( SCIF2.SCFDR.WORD & 0x1F ) != 0 )
\r
243 ucRxedByte = SCIF2.SCFRDR.BYTE;
\r
244 xQueueSendFromISR( xRxedChars, &ucRxedByte, &lHigherPriorityTaskWoken );
\r
247 SCIF2.SCFSR.BIT.RDF = 0;
\r
249 /* If sending to the queue has caused a task to unblock, and the unblocked
\r
250 task has a priority equal to or higher than the currently running task (the
\r
251 task this ISR interrupted), then lHigherPriorityTaskWoken will have
\r
252 automatically been set to pdTRUE within the queue send function.
\r
253 portYIELD_FROM_ISR() will then ensure that this ISR returns directly to the
\r
254 higher priority unblocked task. */
\r
255 portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
\r
257 /*-----------------------------------------------------------*/
\r
259 static void prvTXI_Handler( uint32_t ulUnusedParameter )
\r
261 unsigned char ucByte;
\r
262 long lHigherPriorityTaskWoken = pdFALSE;
\r
264 /* The parameter is not used. It is only present because Renesas drivers
\r
265 are used to install the interrupt handlers, and the drivers expect the
\r
266 parameter to be present. */
\r
267 ( void ) ulUnusedParameter;
\r
269 /* Note the comments at the top of this file regarding the use of queues in
\r
271 if( xQueueReceiveFromISR( xCharsForTx, &ucByte, &lHigherPriorityTaskWoken ) == pdPASS )
\r
273 SCIF2.SCFTDR.BYTE = ucByte;
\r
275 /* Clear TDRE and TEND flag */
\r
276 SCIF2.SCFSR.WORD &= ~0x0060;
\r
280 /* No more characters. Disable the interrupt. */
\r
281 SCIF2.SCSCR.BIT.TIE = 0;
\r
284 /* If receiving from the queue has caused a task to unblock, and the
\r
285 unblocked task has a priority equal to or higher than the currently running
\r
286 task (the task this ISR interrupted), then lHigherPriorityTaskWoken will
\r
287 have automatically been set to pdTRUE within the queue receive function.
\r
288 portYIELD_FROM_ISR() will then ensure that this ISR returns directly to the
\r
289 higher priority unblocked task. */
\r
290 portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
\r
292 /*-----------------------------------------------------------*/
\r