2 FreeRTOS V8.0.0:rc1 - 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 distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\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 UART0.
\r
71 /*-----------------------------------------------------------
\r
72 * Components that can be compiled to either ARM or THUMB mode are
\r
73 * contained in this file.c The ISR routines, which can only be compiled
\r
74 * to ARM mode, are contained in serialISR.c.
\r
75 *----------------------------------------------------------*/
\r
79 /* Library includes. */
\r
80 #include "75x_uart.h"
\r
81 #include "75x_gpio.h"
\r
82 #include "75x_eic.h"
\r
83 #include "75x_mrcc.h"
\r
85 /* Scheduler includes. */
\r
86 #include "FreeRTOS.h"
\r
89 /* Demo application includes. */
\r
92 #define serINVALID_QUEUE ( ( xQueueHandle ) 0 )
\r
93 #define serNO_BLOCK ( ( portTickType ) 0 )
\r
95 /*-----------------------------------------------------------*/
\r
97 /* Queues used to hold received characters, and characters waiting to be
\r
99 static xQueueHandle xRxedChars;
\r
100 static xQueueHandle xCharsForTx;
\r
102 static volatile portBASE_TYPE xQueueEmpty = pdTRUE;
\r
104 /*-----------------------------------------------------------*/
\r
106 /* The interrupt service routine - called from the assembly entry point. */
\r
107 void vSerialISR( void );
\r
108 void vConfigureQueues( xQueueHandle xQForRx, xQueueHandle xQForTx, volatile portBASE_TYPE *pxEmptyFlag );
\r
110 /*-----------------------------------------------------------*/
\r
113 * See the serial2.h header file.
\r
115 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
117 xComPortHandle xReturn;
\r
118 UART_InitTypeDef UART_InitStructure;
\r
119 GPIO_InitTypeDef GPIO_InitStructure;
\r
120 EIC_IRQInitTypeDef EIC_IRQInitStructure;
\r
122 /* Create the queues used to hold Rx and Tx characters. */
\r
123 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
124 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
126 /* If the queues were created correctly then setup the serial port
\r
128 if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
\r
131 vConfigureQueues( xRxedChars, xCharsForTx, &xQueueEmpty );
\r
133 portENTER_CRITICAL();
\r
135 /* Enable the UART0 Clock. */
\r
136 MRCC_PeripheralClockConfig( MRCC_Peripheral_UART0, ENABLE );
\r
138 /* Configure the UART0_Tx as alternate function */
\r
139 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
\r
140 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
\r
141 GPIO_Init(GPIO0, &GPIO_InitStructure);
\r
143 /* Configure the UART0_Rx as input floating */
\r
144 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
\r
145 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
\r
146 GPIO_Init(GPIO0, &GPIO_InitStructure);
\r
148 /* Configure UART0. */
\r
149 UART_InitStructure.UART_WordLength = UART_WordLength_8D;
\r
150 UART_InitStructure.UART_StopBits = UART_StopBits_1;
\r
151 UART_InitStructure.UART_Parity = UART_Parity_No;
\r
152 UART_InitStructure.UART_BaudRate = ulWantedBaud;
\r
153 UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
\r
154 UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
\r
155 UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */
\r
156 UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */
\r
157 UART_Init(UART0, &UART_InitStructure);
\r
159 /* Enable the UART0 */
\r
160 UART_Cmd(UART0, ENABLE);
\r
162 /* Configure the IEC for the UART interrupts. */
\r
163 EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE;
\r
164 EIC_IRQInitStructure.EIC_IRQChannel = UART0_IRQChannel;
\r
165 EIC_IRQInitStructure.EIC_IRQChannelPriority = 1;
\r
166 EIC_IRQInit(&EIC_IRQInitStructure);
\r
168 xQueueEmpty = pdTRUE;
\r
169 UART_ITConfig( UART0, UART_IT_Transmit | UART_IT_Receive, ENABLE );
\r
171 portEXIT_CRITICAL();
\r
175 xReturn = ( xComPortHandle ) 0;
\r
178 /* This demo file only supports a single port but we have to return
\r
179 something to comply with the standard demo header file. */
\r
182 /*-----------------------------------------------------------*/
\r
184 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
186 /* The port handle is not required as this driver only supports one port. */
\r
189 /* Get the next character from the buffer. Return false if no characters
\r
190 are available, or arrive before xBlockTime expires. */
\r
191 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
200 /*-----------------------------------------------------------*/
\r
202 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
204 signed char *pxNext;
\r
206 /* A couple of parameters that this port does not use. */
\r
207 ( void ) usStringLength;
\r
210 /* NOTE: This implementation does not handle the queue being full as no
\r
211 block time is used! */
\r
213 /* The port handle is not required as this driver only supports UART0. */
\r
216 /* Send each character in the string, one at a time. */
\r
217 pxNext = ( signed char * ) pcString;
\r
220 xSerialPutChar( pxPort, *pxNext, serNO_BLOCK );
\r
224 /*-----------------------------------------------------------*/
\r
226 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
\r
228 portBASE_TYPE xReturn;
\r
230 /* Place the character in the queue of characters to be transmitted. */
\r
231 portENTER_CRITICAL();
\r
233 if( xQueueEmpty == pdTRUE )
\r
235 UART0->DR = cOutChar;
\r
240 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
\r
250 xQueueEmpty = pdFALSE;
\r
252 portEXIT_CRITICAL();
\r
256 /*-----------------------------------------------------------*/
\r
258 void vSerialClose( xComPortHandle xPort )
\r
260 /* Not supported as not required by the demo application. */
\r
262 /*-----------------------------------------------------------*/
\r