3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
28 /*-----------------------------------------------------------
29 * Components that can be compiled to either ARM or THUMB mode are
30 * contained in serial.c The ISR routines, which can only be compiled
31 * to ARM mode, are contained in this file.
32 *----------------------------------------------------------*/
36 /* Library includes. */
39 /* Scheduler includes. */
43 static QueueHandle_t xRxedChars;
44 static QueueHandle_t xCharsForTx;
45 static portBASE_TYPE volatile *pxQueueEmpty;
47 void vConfigureQueues( QueueHandle_t xQForRx, QueueHandle_t xQForTx, portBASE_TYPE volatile *pxEmptyFlag )
50 xCharsForTx = xQForTx;
51 pxQueueEmpty = pxEmptyFlag;
53 /*-----------------------------------------------------------*/
55 void vSerialISR( void )
58 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
62 if( UART0->MIS & UART_IT_Transmit )
64 /* The interrupt was caused by the THR becoming empty. Are there any
65 more characters to transmit? */
66 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
68 /* A character was retrieved from the queue so can be sent to the
74 *pxQueueEmpty = pdTRUE;
77 UART_ClearITPendingBit( UART0, UART_IT_Transmit );
80 if( UART0->MIS & UART_IT_Receive )
82 /* The interrupt was caused by a character being received. Grab the
83 character from the RHR and place it in the queue of received
86 xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
87 UART_ClearITPendingBit( UART0, UART_IT_Receive );
89 } while( UART0->MIS );
91 /* If a task was woken by either a character being received or a character
92 being transmitted then we may need to switch to another task. */
93 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );