@@ -115,14 +115,16 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
115
115
/******************************************************************************
116
116
* INTERRUPTS HANDLING
117
117
******************************************************************************/
118
- static inline void uart_irq (uint32_t transmit_empty , uint32_t receive_full , uint32_t index ) {
118
+ static inline void uart_irq (uint32_t transmit_empty , uint32_t receive_full , uint32_t error , uint32_t index ) {
119
119
UART_Type * base = uart_addrs [index ];
120
120
121
121
/* If RX overrun. */
122
- if (UART_S1_OR_MASK & base -> S1 )
122
+ if (error )
123
123
{
124
124
/* Read base->D, otherwise the RX does not work. */
125
125
(void )base -> D ;
126
+
127
+ irq_handler (serial_irq_ids [index ], ErIrq );
126
128
}
127
129
128
130
if (serial_irq_ids [index ] != 0 ) {
@@ -136,32 +138,44 @@ static inline void uart_irq(uint32_t transmit_empty, uint32_t receive_full, uint
136
138
137
139
void uart0_irq () {
138
140
uint32_t status_flags = UART0 -> S1 ;
139
- uart_irq ((status_flags & kUART_TxDataRegEmptyFlag ), (status_flags & kUART_RxDataRegFullFlag ), 0 );
141
+ uart_irq ((status_flags & kUART_TxDataRegEmptyFlag ),
142
+ (status_flags & kUART_RxDataRegFullFlag ),
143
+ (status_flags & kUART_RxOverrunFlag ), 0 );
140
144
}
141
145
142
146
void uart1_irq () {
143
147
uint32_t status_flags = UART1 -> S1 ;
144
- uart_irq ((status_flags & UART_S1_TDRE_MASK ), (status_flags & UART_S1_RDRF_MASK ), 1 );
148
+ uart_irq ((status_flags & UART_S1_TDRE_MASK ),
149
+ (status_flags & UART_S1_RDRF_MASK ),
150
+ (status_flags & UART_S1_OR_MASK ), 1 );
145
151
}
146
152
147
153
void uart2_irq () {
148
154
uint32_t status_flags = UART2 -> S1 ;
149
- uart_irq ((status_flags & UART_S1_TDRE_MASK ), (status_flags & UART_S1_RDRF_MASK ), 2 );
155
+ uart_irq ((status_flags & UART_S1_TDRE_MASK ),
156
+ (status_flags & UART_S1_RDRF_MASK ),
157
+ (status_flags & UART_S1_OR_MASK ), 2 );
150
158
}
151
159
152
160
void uart3_irq () {
153
161
uint32_t status_flags = UART3 -> S1 ;
154
- uart_irq ((status_flags & UART_S1_TDRE_MASK ), (status_flags & UART_S1_RDRF_MASK ), 3 );
162
+ uart_irq ((status_flags & UART_S1_TDRE_MASK ),
163
+ (status_flags & UART_S1_RDRF_MASK ),
164
+ (status_flags & UART_S1_OR_MASK ), 3 );
155
165
}
156
166
157
167
void uart4_irq () {
158
168
uint32_t status_flags = UART4 -> S1 ;
159
- uart_irq ((status_flags & UART_S1_TDRE_MASK ), (status_flags & UART_S1_RDRF_MASK ), 4 );
169
+ uart_irq ((status_flags & UART_S1_TDRE_MASK ),
170
+ (status_flags & UART_S1_RDRF_MASK ),
171
+ (status_flags & UART_S1_OR_MASK ), 4 );
160
172
}
161
173
162
174
void uart5_irq () {
163
175
uint32_t status_flags = UART5 -> S1 ;
164
- uart_irq ((status_flags & UART_S1_TDRE_MASK ), (status_flags & UART_S1_RDRF_MASK ), 5 );
176
+ uart_irq ((status_flags & UART_S1_TDRE_MASK ),
177
+ (status_flags & UART_S1_RDRF_MASK ),
178
+ (status_flags & UART_S1_OR_MASK ), 5 );
165
179
}
166
180
167
181
void serial_irq_handler (serial_t * obj , uart_irq_handler handler , uint32_t id ) {
@@ -212,24 +226,15 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
212
226
213
227
} else { // disable
214
228
int all_disabled = 0 ;
215
- SerialIrq other_irq = (irq == RxIrq ) ? (TxIrq ) : (RxIrq );
216
229
switch (irq ) {
217
230
case RxIrq :
218
231
UART_DisableInterrupts (uart_addrs [obj -> index ], kUART_RxDataRegFullInterruptEnable );
232
+ all_disabled = ((UART_GetEnabledInterrupts (uart_addrs [obj -> index ]) & kUART_TxDataRegEmptyInterruptEnable ) == 0 );
219
233
break ;
220
234
case TxIrq :
221
235
UART_DisableInterrupts (uart_addrs [obj -> index ], kUART_TxDataRegEmptyInterruptEnable );
222
- break ;
223
- default :
224
- break ;
225
- }
226
- switch (other_irq ) {
227
- case RxIrq :
228
236
all_disabled = ((UART_GetEnabledInterrupts (uart_addrs [obj -> index ]) & kUART_RxDataRegFullInterruptEnable ) == 0 );
229
237
break ;
230
- case TxIrq :
231
- all_disabled = ((UART_GetEnabledInterrupts (uart_addrs [obj -> index ]) & kUART_TxDataRegEmptyInterruptEnable ) == 0 );
232
- break ;
233
238
default :
234
239
break ;
235
240
}
0 commit comments