]> begriffs open source - cmsis-freertos/blob - Demo/ARM7_STR75x_GCC/serial/serialISR.c
Updated pack to FreeRTOS 10.4.4
[cmsis-freertos] / Demo / ARM7_STR75x_GCC / serial / serialISR.c
1 /*
2  * FreeRTOS V202107.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
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.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
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  *----------------------------------------------------------*/
33
34
35
36 /* Library includes. */
37 #include "75x_uart.h"
38
39 /* Scheduler includes. */
40 #include "FreeRTOS.h"
41 #include "queue.h"
42
43 static QueueHandle_t xRxedChars;
44 static QueueHandle_t xCharsForTx;
45 static portBASE_TYPE volatile *pxQueueEmpty;
46
47 void vConfigureQueues( QueueHandle_t xQForRx, QueueHandle_t xQForTx, portBASE_TYPE volatile *pxEmptyFlag )
48 {
49         xRxedChars = xQForRx;
50         xCharsForTx = xQForTx;
51         pxQueueEmpty = pxEmptyFlag;
52 }
53 /*-----------------------------------------------------------*/
54
55 void vSerialISR( void )
56 {
57 signed char cChar;
58 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
59
60         do
61         {
62                 if( UART0->MIS & UART_IT_Transmit )
63                 {
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 )
67                         {
68                                 /* A character was retrieved from the queue so can be sent to the
69                                 THR now. */
70                                 UART0->DR = cChar;
71                         }
72                         else
73                         {
74                                 *pxQueueEmpty = pdTRUE;         
75                         }               
76
77                         UART_ClearITPendingBit( UART0, UART_IT_Transmit );
78                 }
79         
80                 if( UART0->MIS & UART_IT_Receive )
81                 {
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
84                         characters. */
85                         cChar = UART0->DR;
86                         xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
87                         UART_ClearITPendingBit( UART0, UART_IT_Receive );
88                 }
89         } while( UART0->MIS );
90
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 );
94 }
95
96