2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
97 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART2.
\r
99 ***Note*** This example uses queues to send each character into an interrupt
\r
100 service routine and out of an interrupt service routine individually. This
\r
101 is done to demonstrate queues being used in an interrupt, and to deliberately
\r
102 load the system to test the FreeRTOS port. It is *NOT* meant to be an
\r
103 example of an efficient implementation. An efficient implementation should
\r
104 use the DMA, and only use FreeRTOS API functions when enough has been
\r
105 received to warrant a task being unblocked to process the data.
\r
108 /* Scheduler includes. */
\r
109 #include "FreeRTOS.h"
\r
111 #include "semphr.h"
\r
112 #include "comtest2.h"
\r
114 /* Driver includes. */
\r
115 #include "r_typedefs.h"
\r
116 #include "dev_drv.h"
\r
117 #include "devdrv_scif_uart.h"
\r
118 #include "sio_char.h"
\r
119 #include "iodefine.h"
\r
120 #include "devdrv_intc.h"
\r
122 /* Demo application includes. */
\r
123 #include "serial.h"
\r
125 /*-----------------------------------------------------------*/
\r
127 /* Misc defines. */
\r
128 #define serINVALID_QUEUE ( ( QueueHandle_t ) 0 )
\r
129 #define serNO_BLOCK ( ( TickType_t ) 0 )
\r
131 /*-----------------------------------------------------------*/
\r
133 /* Handlers for the Rx and Tx interrupts respectively. */
\r
134 static void prvRXI_Handler( uint32_t ulUnusedParameter );
\r
135 static void prvTXI_Handler( uint32_t ulUnusedParameter );
\r
137 /*-----------------------------------------------------------*/
\r
139 /* The queue used to hold received characters. */
\r
140 static QueueHandle_t xRxedChars;
\r
141 static QueueHandle_t xCharsForTx;
\r
143 /*-----------------------------------------------------------*/
\r
146 * See the serial2.h header file.
\r
148 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
150 /* Baud is set in IoInitScif2(), called in prvSetupHardware() in main.c. */
\r
151 ( void ) ulWantedBaud;
\r
153 /* Create the queues used to hold Rx/Tx characters. Note the comments at
\r
154 the top of this file regarding the use of queues in this manner. */
\r
155 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( char ) );
\r
156 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( char ) );
\r
158 /* If the queues were created correctly then setup the serial port
\r
160 if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
\r
162 /* Register RXI and TXI handlers. */
\r
163 R_INTC_RegistIntFunc( INTC_ID_RXI2, prvRXI_Handler );
\r
164 R_INTC_RegistIntFunc( INTC_ID_TXI2, prvTXI_Handler );
\r
166 /* Set both interrupts such that they can interrupt the tick. Also
\r
167 set the Rx interrupt above the Tx interrupt in the hope that (for test
\r
168 purposes) the Tx interrupt will interrupt the Rx interrupt. */
\r
169 R_INTC_SetPriority( INTC_ID_RXI2, configMAX_API_CALL_INTERRUPT_PRIORITY );
\r
170 R_INTC_SetPriority( INTC_ID_TXI2, ( configMAX_API_CALL_INTERRUPT_PRIORITY + 1 ) );
\r
172 /* This driver is intended to test interrupt interactions, and not
\r
173 intended to be efficient. Therefore set the RX trigger level to 1. */
\r
174 SCIF2.SCFCR.BIT.RTRG = 0;
\r
175 SCIF2.SCFCR.BIT.TTRG = 3;
\r
177 /* Enable Rx interrupt. Tx interrupt will be enabled when a Tx is
\r
179 SCIF2.SCSCR.BIT.RIE = 1;
\r
180 R_INTC_Enable( INTC_ID_RXI2 );
\r
181 R_INTC_Enable( INTC_ID_TXI2 );
\r
184 /* This demo file only supports a single port but we have to return
\r
185 something to comply with the standard demo header file. */
\r
186 return ( xComPortHandle ) 0;
\r
188 /*-----------------------------------------------------------*/
\r
190 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
192 /* The port handle is not required as this driver only supports one port. */
\r
195 /* Get the next character from the buffer. Return false if no characters
\r
196 are available, or arrive before xBlockTime expires. */
\r
197 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
206 /*-----------------------------------------------------------*/
\r
208 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
212 /* A couple of parameters that this port does not use. */
\r
213 ( void ) usStringLength;
\r
216 /* Send each character in the string, one at a time. */
\r
217 pxNext = ( char * ) pcString;
\r
220 xSerialPutChar( pxPort, *pxNext, portMAX_DELAY );
\r
224 /*-----------------------------------------------------------*/
\r
226 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
228 signed portBASE_TYPE xReturn;
\r
230 /* Note the comments at the top of this file regarding the use of queues in
\r
232 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdPASS )
\r
236 /* Enable the interrupt which will remove the character from the
\r
238 SCIF2.SCSCR.BIT.TIE = 1;
\r
247 /*-----------------------------------------------------------*/
\r
249 void vSerialClose( xComPortHandle xPort )
\r
251 /* Not supported as not required by the demo application. */
\r
253 /*-----------------------------------------------------------*/
\r
255 static void prvRXI_Handler( uint32_t ulUnusedParameter )
\r
257 unsigned char ucRxedByte;
\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 while( ( SCIF2.SCFDR.WORD & 0x1F ) != 0 )
\r
269 ucRxedByte = SCIF2.SCFRDR.BYTE;
\r
270 xQueueSendFromISR( xRxedChars, &ucRxedByte, &lHigherPriorityTaskWoken );
\r
273 SCIF2.SCFSR.BIT.RDF = 0;
\r
275 /* If sending to the queue has caused a task to unblock, and the unblocked
\r
276 task has a priority equal to or higher than the currently running task (the
\r
277 task this ISR interrupted), then lHigherPriorityTaskWoken will have
\r
278 automatically been set to pdTRUE within the queue send function.
\r
279 portYIELD_FROM_ISR() will then ensure that this ISR returns directly to the
\r
280 higher priority unblocked task. */
\r
281 portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
\r
283 /*-----------------------------------------------------------*/
\r
285 static void prvTXI_Handler( uint32_t ulUnusedParameter )
\r
287 unsigned char ucByte;
\r
288 long lHigherPriorityTaskWoken = pdFALSE;
\r
290 /* The parameter is not used. It is only present because Renesas drivers
\r
291 are used to install the interrupt handlers, and the drivers expect the
\r
292 parameter to be present. */
\r
293 ( void ) ulUnusedParameter;
\r
295 /* Note the comments at the top of this file regarding the use of queues in
\r
297 if( xQueueReceiveFromISR( xCharsForTx, &ucByte, &lHigherPriorityTaskWoken ) == pdPASS )
\r
299 SCIF2.SCFTDR.BYTE = ucByte;
\r
301 /* Clear TDRE and TEND flag */
\r
302 SCIF2.SCFSR.WORD &= ~0x0060;
\r
306 /* No more characters. Disable the interrupt. */
\r
307 SCIF2.SCSCR.BIT.TIE = 0;
\r
310 /* If receiving from the queue has caused a task to unblock, and the
\r
311 unblocked task has a priority equal to or higher than the currently running
\r
312 task (the task this ISR interrupted), then lHigherPriorityTaskWoken will
\r
313 have automatically been set to pdTRUE within the queue receive function.
\r
314 portYIELD_FROM_ISR() will then ensure that this ISR returns directly to the
\r
315 higher priority unblocked task. */
\r
316 portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
\r
318 /*-----------------------------------------------------------*/
\r