@@ -72,13 +72,15 @@ struct uart_
72
72
struct uart_rx_buffer_ * rx_buffer ;
73
73
};
74
74
75
- struct uartIntContext_t
75
+ struct uartIsrContext_t
76
76
{
77
77
uartInterruptHandler callback ;
78
78
void * arg ;
79
79
};
80
80
81
- static volatile struct uartIntContext_t s_uartInterruptContext [2 ];
81
+ // NOTE: GCC will generated an invalid warning for the following line
82
+ // see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
83
+ static volatile struct uartIsrContext_t s_uartInterruptContext [2 ] = { 0 };
82
84
83
85
/*
84
86
In the context of the naming conventions in this file, "_unsafe" means two things:
@@ -91,16 +93,13 @@ static volatile struct uartIntContext_t s_uartInterruptContext[2];
91
93
wrap the unsafe ones with disabling/enabling of the uart interrupt for safe public use.
92
94
*/
93
95
94
-
95
-
96
96
// called by ISR
97
97
inline size_t ICACHE_RAM_ATTR
98
98
uart_rx_fifo_available (const int uart_nr )
99
99
{
100
100
return (USS (uart_nr ) >> USRXC ) & 0xFF ;
101
101
}
102
102
103
-
104
103
/**********************************************************/
105
104
/************ UNSAFE FUNCTIONS ****************************/
106
105
/**********************************************************/
@@ -312,7 +311,8 @@ uart_isr(void* arg)
312
311
}
313
312
else
314
313
{
315
- // Clear all interrupts flags (just in case)
314
+ // No registered handler, so
315
+ // clear all interrupts flags (just in case)
316
316
USIE (uartNum ) = 0 ;
317
317
USIC (uartNum ) = 0xffff ;
318
318
}
@@ -355,11 +355,9 @@ uart_subscribeInterrupt(int uart_nr, uartInterruptHandler callback, void* param)
355
355
}
356
356
}
357
357
358
- void
358
+ bool
359
359
uart_unsubscribeInterrupt (int uart_nr , uartInterruptHandler callback )
360
360
{
361
- ETS_UART_INTR_DISABLE ();
362
-
363
361
if (s_uartInterruptContext [uart_nr ].callback == callback )
364
362
{
365
363
// turn off uart
@@ -376,12 +374,13 @@ uart_unsubscribeInterrupt(int uart_nr, uartInterruptHandler callback)
376
374
// detach our ISR
377
375
ETS_UART_INTR_ATTACH (NULL , NULL );
378
376
379
- // return so we don't enable interrupts since there is no ISR anymore
380
- return ;
377
+ // return false so we don't enable interrupts
378
+ // since there is no need for the ISR anymore
379
+ return false;
381
380
}
382
381
}
383
382
384
- ETS_UART_INTR_ENABLE () ;
383
+ return true ;
385
384
}
386
385
387
386
@@ -485,7 +484,6 @@ uart_wait_tx_empty(uart_t* uart)
485
484
486
485
while (uart_tx_fifo_available (uart -> uart_nr ) > 0 )
487
486
delay (0 );
488
-
489
487
}
490
488
491
489
void
@@ -652,7 +650,11 @@ uart_uninit(uart_t* uart)
652
650
653
651
if (uart -> rx_enabled )
654
652
{
655
- uart_unsubscribeInterrupt (uart -> uart_nr , uart_isrDefault );
653
+ ETS_UART_INTR_DISABLE ();
654
+ if (uart_unsubscribeInterrupt (uart -> uart_nr , uart_isrDefault ))
655
+ {
656
+ ETS_UART_INTR_ENABLE ();
657
+ }
656
658
free (uart -> rx_buffer -> buffer );
657
659
free (uart -> rx_buffer );
658
660
}
0 commit comments