2 FreeRTOS V8.2.1 - 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
72 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART
\r
75 /* Scheduler includes. */
\r
76 #include "FreeRTOS.h"
\r
80 /* Demo application includes. */
\r
83 /* Microblaze driver includes. */
\r
84 #include "xuartlite_l.h"
\r
85 #include "xintc_l.h"
\r
87 /*-----------------------------------------------------------*/
\r
89 /* Queues used to hold received characters, and characters waiting to be
\r
91 static QueueHandle_t xRxedChars;
\r
92 static QueueHandle_t xCharsForTx;
\r
94 /*-----------------------------------------------------------*/
\r
96 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
98 unsigned long ulControlReg, ulMask;
\r
100 /* NOTE: The baud rate used by this driver is determined by the hardware
\r
101 parameterization of the UART Lite peripheral, and the baud value passed to
\r
102 this function has no effect. */
\r
104 /* Create the queues used to hold Rx and Tx characters. */
\r
105 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
106 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
108 if( ( xRxedChars ) && ( xCharsForTx ) )
\r
110 /* Disable the interrupt. */
\r
111 XUartLite_mDisableIntr( XPAR_RS232_UART_BASEADDR );
\r
113 /* Flush the fifos. */
\r
114 ulControlReg = XIo_In32( XPAR_RS232_UART_BASEADDR + XUL_STATUS_REG_OFFSET );
\r
115 XIo_Out32( XPAR_RS232_UART_BASEADDR + XUL_CONTROL_REG_OFFSET, ulControlReg | XUL_CR_FIFO_TX_RESET | XUL_CR_FIFO_RX_RESET );
\r
117 /* Enable the interrupt again. The interrupt controller has not yet been
\r
118 initialised so there is no chance of receiving an interrupt until the
\r
119 scheduler has been started. */
\r
120 XUartLite_mEnableIntr( XPAR_RS232_UART_BASEADDR );
\r
122 /* Enable the interrupt in the interrupt controller while maintaining
\r
123 all the other bit settings. */
\r
124 ulMask = XIntc_In32( ( XPAR_OPB_INTC_0_BASEADDR + XIN_IER_OFFSET ) );
\r
125 ulMask |= XPAR_RS232_UART_INTERRUPT_MASK;
\r
126 XIntc_Out32( ( XPAR_OPB_INTC_0_BASEADDR + XIN_IER_OFFSET ), ( ulMask ) );
\r
127 XIntc_mAckIntr( XPAR_INTC_SINGLE_BASEADDR, 2 );
\r
130 return ( xComPortHandle ) 0;
\r
132 /*-----------------------------------------------------------*/
\r
134 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
136 /* The port handle is not required as this driver only supports one UART. */
\r
139 /* Get the next character from the buffer. Return false if no characters
\r
140 are available, or arrive before xBlockTime expires. */
\r
141 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
150 /*-----------------------------------------------------------*/
\r
152 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
154 portBASE_TYPE xReturn = pdTRUE;
\r
156 portENTER_CRITICAL();
\r
158 /* If the UART FIFO is full we can block posting the new data on the
\r
160 if( XUartLite_mIsTransmitFull( XPAR_RS232_UART_BASEADDR ) )
\r
162 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
\r
167 /* Otherwise, if there is data already in the queue we should add the
\r
168 new data to the back of the queue to ensure the sequencing is
\r
170 else if( uxQueueMessagesWaiting( xCharsForTx ) )
\r
172 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
\r
177 /* If the UART FIFO is not full and there is no data already in the
\r
178 queue we can write directly to the FIFO without disrupting the
\r
182 XIo_Out32( XPAR_RS232_UART_BASEADDR + XUL_TX_FIFO_OFFSET, cOutChar );
\r
185 portEXIT_CRITICAL();
\r
189 /*-----------------------------------------------------------*/
\r
191 void vSerialClose( xComPortHandle xPort )
\r
193 /* Not supported as not required by the demo application. */
\r
196 /*-----------------------------------------------------------*/
\r
198 void vSerialISR( void *pvBaseAddress )
\r
200 unsigned long ulISRStatus;
\r
201 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
204 /* Determine the cause of the interrupt. */
\r
205 ulISRStatus = XIo_In32( XPAR_RS232_UART_BASEADDR + XUL_STATUS_REG_OFFSET );
\r
207 if( ( ulISRStatus & ( XUL_SR_RX_FIFO_FULL | XUL_SR_RX_FIFO_VALID_DATA ) ) != 0 )
\r
209 /* A character is available - place it in the queue of received
\r
210 characters. This might wake a task that was blocked waiting for
\r
212 cChar = ( char )XIo_In32( XPAR_RS232_UART_BASEADDR + XUL_RX_FIFO_OFFSET );
\r
213 xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
\r
216 if( ( ulISRStatus & XUL_SR_TX_FIFO_EMPTY ) != 0 )
\r
218 /* There is space in the FIFO - if there are any characters queue for
\r
219 transmission they can be send to the UART now. This might unblock a
\r
220 task that was waiting for space to become available on the Tx queue. */
\r
221 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
\r
223 XIo_Out32( XPAR_RS232_UART_BASEADDR + XUL_TX_FIFO_OFFSET, cChar );
\r
227 /* If we woke any tasks we may require a context switch. */
\r
228 if( xHigherPriorityTaskWoken )
\r
230 portYIELD_FROM_ISR();
\r