2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 #include "FreeRTOS.h"
\r
70 /*---------------------------------------------------------------------------*/
\r
72 #define serialSTRING_DELAY_TICKS ( portMAX_DELAY )
\r
73 /*---------------------------------------------------------------------------*/
\r
75 CY_ISR_PROTO( vUartRxISR );
\r
76 CY_ISR_PROTO( vUartTxISR );
\r
77 /*---------------------------------------------------------------------------*/
\r
79 static xQueueHandle xSerialTxQueue = NULL;
\r
80 static xQueueHandle xSerialRxQueue = NULL;
\r
81 /*---------------------------------------------------------------------------*/
\r
83 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
86 xSerialRxQueue = xQueueCreate( uxQueueLength, sizeof( signed char ) );
\r
87 isr_UART1_RX_BYTE_RECEIVED_ClearPending();
\r
88 isr_UART1_RX_BYTE_RECEIVED_StartEx(vUartRxISR);
\r
91 xSerialTxQueue = xQueueCreate( uxQueueLength, sizeof( signed char ) );
\r
92 isr_UART1_TX_BYTE_COMPLETE_ClearPending() ;
\r
93 isr_UART1_TX_BYTE_COMPLETE_StartEx(vUartTxISR);
\r
95 /* Clear the interrupt modes for the Tx for the time being. */
\r
96 UART_1_SetTxInterruptMode( 0 );
\r
98 /* Both configured successfully. */
\r
99 return ( xComPortHandle )( xSerialTxQueue && xSerialRxQueue );
\r
101 /*---------------------------------------------------------------------------*/
\r
103 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
105 unsigned short usIndex = 0;
\r
107 for( usIndex = 0; usIndex < usStringLength; usIndex++ )
\r
109 /* Check for pre-mature end of line. */
\r
110 if( '\0' == pcString[ usIndex ] )
\r
115 /* Send out, one character at a time. */
\r
116 if( pdTRUE != xSerialPutChar( NULL, pcString[ usIndex ], serialSTRING_DELAY_TICKS ) )
\r
118 /* Failed to send, this will be picked up in the receive comtest task. */
\r
122 /*---------------------------------------------------------------------------*/
\r
124 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
126 portBASE_TYPE xReturn = pdFALSE;
\r
128 if( pdTRUE == xQueueReceive( xSerialRxQueue, pcRxedChar, xBlockTime ) )
\r
130 /* Picked up a character. */
\r
135 /*---------------------------------------------------------------------------*/
\r
137 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
\r
139 portBASE_TYPE xReturn = pdFALSE;
\r
141 /* The ISR is processing characters is so just add to the end of the queue. */
\r
142 if( pdTRUE == xQueueSend( xSerialTxQueue, &cOutChar, xBlockTime ) )
\r
148 /* The queue is probably full. */
\r
152 /* Make sure that the interrupt will fire in the case where:
\r
153 Currently sending so the Tx Complete will fire.
\r
154 Not sending so the Empty will fire. */
\r
155 taskENTER_CRITICAL();
\r
156 UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE | UART_1_TX_STS_FIFO_EMPTY );
\r
157 taskEXIT_CRITICAL();
\r
161 /*---------------------------------------------------------------------------*/
\r
165 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
166 volatile unsigned char ucStatus = 0;
\r
167 signed char cInChar = 0;
\r
168 unsigned long ulMask = 0;
\r
170 /* Read the status to acknowledge. */
\r
171 ucStatus = UART_1_ReadRxStatus();
\r
173 /* Only interested in a character being received. */
\r
174 if( 0 != ( ucStatus & UART_1_RX_STS_FIFO_NOTEMPTY ) )
\r
176 /* Get the character. */
\r
177 cInChar = UART_1_GetChar();
\r
179 /* Mask off the other RTOS interrupts to interact with the queue. */
\r
180 ulMask = portSET_INTERRUPT_MASK_FROM_ISR();
\r
182 /* Try to deliver the character. */
\r
183 if( pdTRUE != xQueueSendFromISR( xSerialRxQueue, &cInChar, &xHigherPriorityTaskWoken ) )
\r
185 /* Run out of space. */
\r
188 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask );
\r
191 /* If we delivered the character then a context switch might be required.
\r
192 xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry. If calling
\r
193 xQueueSendFromISR() caused a task to unblock, and the unblocked task has
\r
194 a priority equal to or higher than the currently running task (the task this
\r
195 ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and
\r
196 portEND_SWITCHING_ISR() will request a context switch to the newly unblocked
\r
198 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r
200 /*---------------------------------------------------------------------------*/
\r
204 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
205 volatile unsigned char ucStatus = 0;
\r
206 signed char cOutChar = 0;
\r
207 unsigned long ulMask = 0;
\r
209 /* Read the status to acknowledge. */
\r
210 ucStatus = UART_1_ReadTxStatus();
\r
212 /* Check to see whether this is a genuine interrupt. */
\r
213 if( ( 0 != ( ucStatus & UART_1_TX_STS_COMPLETE ) ) || ( 0 != ( ucStatus & UART_1_TX_STS_FIFO_EMPTY ) ) )
\r
215 /* Mask off the other RTOS interrupts to interact with the queue. */
\r
216 ulMask = portSET_INTERRUPT_MASK_FROM_ISR();
\r
218 if( pdTRUE == xQueueReceiveFromISR( xSerialTxQueue, &cOutChar, &xHigherPriorityTaskWoken ) )
\r
220 /* Send the next character. */
\r
221 UART_1_PutChar( cOutChar );
\r
223 /* If we are firing, then the only interrupt we are interested in
\r
224 is the Complete. The application code will add the Empty interrupt
\r
225 when there is something else to be done. */
\r
226 UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE );
\r
230 /* There is no work left so disable the interrupt until the application
\r
231 puts more into the queue. */
\r
232 UART_1_SetTxInterruptMode( 0 );
\r
235 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask );
\r
238 /* If we delivered the character then a context switch might be required.
\r
239 xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry. If calling
\r
240 xQueueSendFromISR() caused a task to unblock, and the unblocked task has
\r
241 a priority equal to or higher than the currently running task (the task this
\r
242 ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and
\r
243 portEND_SWITCHING_ISR() will request a context switch to the newly unblocked
\r
245 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r
247 /*---------------------------------------------------------------------------*/
\r