2 FreeRTOS V7.6.0 - Copyright (C) 2013 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 #include "FreeRTOS.h"
\r
71 /*---------------------------------------------------------------------------*/
\r
73 #define serialSTRING_DELAY_TICKS ( portMAX_DELAY )
\r
74 /*---------------------------------------------------------------------------*/
\r
76 CY_ISR_PROTO( vUartRxISR );
\r
77 CY_ISR_PROTO( vUartTxISR );
\r
78 /*---------------------------------------------------------------------------*/
\r
80 static xQueueHandle xSerialTxQueue = NULL;
\r
81 static xQueueHandle xSerialRxQueue = NULL;
\r
82 /*---------------------------------------------------------------------------*/
\r
84 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
87 xSerialRxQueue = xQueueCreate( uxQueueLength, sizeof( signed char ) );
\r
88 isr_UART1_RX_BYTE_RECEIVED_ClearPending();
\r
89 isr_UART1_RX_BYTE_RECEIVED_StartEx(vUartRxISR);
\r
92 xSerialTxQueue = xQueueCreate( uxQueueLength, sizeof( signed char ) );
\r
93 isr_UART1_TX_BYTE_COMPLETE_ClearPending() ;
\r
94 isr_UART1_TX_BYTE_COMPLETE_StartEx(vUartTxISR);
\r
96 /* Clear the interrupt modes for the Tx for the time being. */
\r
97 UART_1_SetTxInterruptMode( 0 );
\r
99 /* Both configured successfully. */
\r
100 return ( xComPortHandle )( xSerialTxQueue && xSerialRxQueue );
\r
102 /*---------------------------------------------------------------------------*/
\r
104 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
106 unsigned short usIndex = 0;
\r
108 for( usIndex = 0; usIndex < usStringLength; usIndex++ )
\r
110 /* Check for pre-mature end of line. */
\r
111 if( '\0' == pcString[ usIndex ] )
\r
116 /* Send out, one character at a time. */
\r
117 if( pdTRUE != xSerialPutChar( NULL, pcString[ usIndex ], serialSTRING_DELAY_TICKS ) )
\r
119 /* Failed to send, this will be picked up in the receive comtest task. */
\r
123 /*---------------------------------------------------------------------------*/
\r
125 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
127 portBASE_TYPE xReturn = pdFALSE;
\r
129 if( pdTRUE == xQueueReceive( xSerialRxQueue, pcRxedChar, xBlockTime ) )
\r
131 /* Picked up a character. */
\r
136 /*---------------------------------------------------------------------------*/
\r
138 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
\r
140 portBASE_TYPE xReturn = pdFALSE;
\r
142 /* The ISR is processing characters is so just add to the end of the queue. */
\r
143 if( pdTRUE == xQueueSend( xSerialTxQueue, &cOutChar, xBlockTime ) )
\r
149 /* The queue is probably full. */
\r
153 /* Make sure that the interrupt will fire in the case where:
\r
154 Currently sending so the Tx Complete will fire.
\r
155 Not sending so the Empty will fire. */
\r
156 taskENTER_CRITICAL();
\r
157 UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE | UART_1_TX_STS_FIFO_EMPTY );
\r
158 taskEXIT_CRITICAL();
\r
162 /*---------------------------------------------------------------------------*/
\r
166 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
167 volatile unsigned char ucStatus = 0;
\r
168 signed char cInChar = 0;
\r
169 unsigned long ulMask = 0;
\r
171 /* Read the status to acknowledge. */
\r
172 ucStatus = UART_1_ReadRxStatus();
\r
174 /* Only interested in a character being received. */
\r
175 if( 0 != ( ucStatus & UART_1_RX_STS_FIFO_NOTEMPTY ) )
\r
177 /* Get the character. */
\r
178 cInChar = UART_1_GetChar();
\r
180 /* Mask off the other RTOS interrupts to interact with the queue. */
\r
181 ulMask = portSET_INTERRUPT_MASK_FROM_ISR();
\r
183 /* Try to deliver the character. */
\r
184 if( pdTRUE != xQueueSendFromISR( xSerialRxQueue, &cInChar, &xHigherPriorityTaskWoken ) )
\r
186 /* Run out of space. */
\r
189 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask );
\r
192 /* If we delivered the character then a context switch might be required.
\r
193 xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry. If calling
\r
194 xQueueSendFromISR() caused a task to unblock, and the unblocked task has
\r
195 a priority equal to or higher than the currently running task (the task this
\r
196 ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and
\r
197 portEND_SWITCHING_ISR() will request a context switch to the newly unblocked
\r
199 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r
201 /*---------------------------------------------------------------------------*/
\r
205 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
206 volatile unsigned char ucStatus = 0;
\r
207 signed char cOutChar = 0;
\r
208 unsigned long ulMask = 0;
\r
210 /* Read the status to acknowledge. */
\r
211 ucStatus = UART_1_ReadTxStatus();
\r
213 /* Check to see whether this is a genuine interrupt. */
\r
214 if( ( 0 != ( ucStatus & UART_1_TX_STS_COMPLETE ) ) || ( 0 != ( ucStatus & UART_1_TX_STS_FIFO_EMPTY ) ) )
\r
216 /* Mask off the other RTOS interrupts to interact with the queue. */
\r
217 ulMask = portSET_INTERRUPT_MASK_FROM_ISR();
\r
219 if( pdTRUE == xQueueReceiveFromISR( xSerialTxQueue, &cOutChar, &xHigherPriorityTaskWoken ) )
\r
221 /* Send the next character. */
\r
222 UART_1_PutChar( cOutChar );
\r
224 /* If we are firing, then the only interrupt we are interested in
\r
225 is the Complete. The application code will add the Empty interrupt
\r
226 when there is something else to be done. */
\r
227 UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE );
\r
231 /* There is no work left so disable the interrupt until the application
\r
232 puts more into the queue. */
\r
233 UART_1_SetTxInterruptMode( 0 );
\r
236 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask );
\r
239 /* If we delivered the character then a context switch might be required.
\r
240 xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry. If calling
\r
241 xQueueSendFromISR() caused a task to unblock, and the unblocked task has
\r
242 a priority equal to or higher than the currently running task (the task this
\r
243 ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and
\r
244 portEND_SWITCHING_ISR() will request a context switch to the newly unblocked
\r
246 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r
248 /*---------------------------------------------------------------------------*/
\r