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
71 #include "FreeRTOS.h"
\r
75 /*---------------------------------------------------------------------------*/
\r
77 #define serialSTRING_DELAY_TICKS ( portMAX_DELAY )
\r
78 /*---------------------------------------------------------------------------*/
\r
80 CY_ISR_PROTO( vUartRxISR );
\r
81 CY_ISR_PROTO( vUartTxISR );
\r
82 /*---------------------------------------------------------------------------*/
\r
84 static QueueHandle_t xSerialTxQueue = NULL;
\r
85 static QueueHandle_t xSerialRxQueue = NULL;
\r
86 /*---------------------------------------------------------------------------*/
\r
88 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
91 xSerialRxQueue = xQueueCreate( uxQueueLength, sizeof( signed char ) );
\r
92 isr_UART1_RX_BYTE_RECEIVED_ClearPending();
\r
93 isr_UART1_RX_BYTE_RECEIVED_StartEx(vUartRxISR);
\r
96 xSerialTxQueue = xQueueCreate( uxQueueLength, sizeof( signed char ) );
\r
97 isr_UART1_TX_BYTE_COMPLETE_ClearPending() ;
\r
98 isr_UART1_TX_BYTE_COMPLETE_StartEx(vUartTxISR);
\r
100 /* Clear the interrupt modes for the Tx for the time being. */
\r
101 UART_1_SetTxInterruptMode( 0 );
\r
103 /* Both configured successfully. */
\r
104 return ( xComPortHandle )( xSerialTxQueue && xSerialRxQueue );
\r
106 /*---------------------------------------------------------------------------*/
\r
108 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
110 unsigned short usIndex = 0;
\r
112 for( usIndex = 0; usIndex < usStringLength; usIndex++ )
\r
114 /* Check for pre-mature end of line. */
\r
115 if( '\0' == pcString[ usIndex ] )
\r
120 /* Send out, one character at a time. */
\r
121 if( pdTRUE != xSerialPutChar( NULL, pcString[ usIndex ], serialSTRING_DELAY_TICKS ) )
\r
123 /* Failed to send, this will be picked up in the receive comtest task. */
\r
127 /*---------------------------------------------------------------------------*/
\r
129 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
131 portBASE_TYPE xReturn = pdFALSE;
\r
133 if( pdTRUE == xQueueReceive( xSerialRxQueue, pcRxedChar, xBlockTime ) )
\r
135 /* Picked up a character. */
\r
140 /*---------------------------------------------------------------------------*/
\r
142 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
144 portBASE_TYPE xReturn = pdFALSE;
\r
146 /* The ISR is processing characters is so just add to the end of the queue. */
\r
147 if( pdTRUE == xQueueSend( xSerialTxQueue, &cOutChar, xBlockTime ) )
\r
153 /* The queue is probably full. */
\r
157 /* Make sure that the interrupt will fire in the case where:
\r
158 Currently sending so the Tx Complete will fire.
\r
159 Not sending so the Empty will fire. */
\r
160 taskENTER_CRITICAL();
\r
161 UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE | UART_1_TX_STS_FIFO_EMPTY );
\r
162 taskEXIT_CRITICAL();
\r
166 /*---------------------------------------------------------------------------*/
\r
170 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
171 volatile unsigned char ucStatus = 0;
\r
172 signed char cInChar = 0;
\r
173 unsigned long ulMask = 0;
\r
175 /* Read the status to acknowledge. */
\r
176 ucStatus = UART_1_ReadRxStatus();
\r
178 /* Only interested in a character being received. */
\r
179 if( 0 != ( ucStatus & UART_1_RX_STS_FIFO_NOTEMPTY ) )
\r
181 /* Get the character. */
\r
182 cInChar = UART_1_GetChar();
\r
184 /* Mask off the other RTOS interrupts to interact with the queue. */
\r
185 ulMask = portSET_INTERRUPT_MASK_FROM_ISR();
\r
187 /* Try to deliver the character. */
\r
188 if( pdTRUE != xQueueSendFromISR( xSerialRxQueue, &cInChar, &xHigherPriorityTaskWoken ) )
\r
190 /* Run out of space. */
\r
193 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask );
\r
196 /* If we delivered the character then a context switch might be required.
\r
197 xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry. If calling
\r
198 xQueueSendFromISR() caused a task to unblock, and the unblocked task has
\r
199 a priority equal to or higher than the currently running task (the task this
\r
200 ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and
\r
201 portEND_SWITCHING_ISR() will request a context switch to the newly unblocked
\r
203 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r
205 /*---------------------------------------------------------------------------*/
\r
209 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
210 volatile unsigned char ucStatus = 0;
\r
211 signed char cOutChar = 0;
\r
212 unsigned long ulMask = 0;
\r
214 /* Read the status to acknowledge. */
\r
215 ucStatus = UART_1_ReadTxStatus();
\r
217 /* Check to see whether this is a genuine interrupt. */
\r
218 if( ( 0 != ( ucStatus & UART_1_TX_STS_COMPLETE ) ) || ( 0 != ( ucStatus & UART_1_TX_STS_FIFO_EMPTY ) ) )
\r
220 /* Mask off the other RTOS interrupts to interact with the queue. */
\r
221 ulMask = portSET_INTERRUPT_MASK_FROM_ISR();
\r
223 if( pdTRUE == xQueueReceiveFromISR( xSerialTxQueue, &cOutChar, &xHigherPriorityTaskWoken ) )
\r
225 /* Send the next character. */
\r
226 UART_1_PutChar( cOutChar );
\r
228 /* If we are firing, then the only interrupt we are interested in
\r
229 is the Complete. The application code will add the Empty interrupt
\r
230 when there is something else to be done. */
\r
231 UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE );
\r
235 /* There is no work left so disable the interrupt until the application
\r
236 puts more into the queue. */
\r
237 UART_1_SetTxInterruptMode( 0 );
\r
240 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask );
\r
243 /* If we delivered the character then a context switch might be required.
\r
244 xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry. If calling
\r
245 xQueueSendFromISR() caused a task to unblock, and the unblocked task has
\r
246 a priority equal to or higher than the currently running task (the task this
\r
247 ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and
\r
248 portEND_SWITCHING_ISR() will request a context switch to the newly unblocked
\r
250 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r
252 /*---------------------------------------------------------------------------*/
\r