[Nuvoton] Fix time to init/deinit stdio_uart

With support for checking H/W UART initialized or not, we can simplify stdio management:
1. When serial_init(&stdio_uart) calls in, just set the 'stdio_uart_inited' flag.
2. When serial_free(&stdio_uart) calls in, just clear the 'stdio_uart_inited' flag.
Except above, we needn't make special handling with 'stdio_uart'.
pull/8900/head
ccli8 2018-11-28 17:58:59 +08:00
parent a937a62bff
commit a2c70f2ca4
5 changed files with 49 additions and 29 deletions

View File

@ -250,10 +250,12 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
obj->serial.dma_chn_id_rx = DMA_ERROR_OUT_OF_CHANNELS;
#endif
// For stdio management
if (obj->serial.uart == STDIO_UART) {
/* With support for checking H/W UART initialized or not, we allow serial_init(&stdio_uart)
* calls in even though H/W UART 'STDIO_UART' has initialized. When serial_init(&stdio_uart)
* calls in, we only need to set the 'stdio_uart_inited' flag. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 1;
memcpy(&stdio_uart, obj, sizeof(serial_t));
}
if (var->ref_cnt) {
@ -302,7 +304,9 @@ void serial_free(serial_t *obj)
var->obj = NULL;
}
if (obj->serial.uart == STDIO_UART) {
/* Clear the 'stdio_uart_inited' flag when serial_free(&stdio_uart) calls in. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 0;
}

View File

@ -210,12 +210,14 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
obj->serial.dma_chn_id_rx = DMA_ERROR_OUT_OF_CHANNELS;
#endif
// For stdio management
if (obj->serial.uart == STDIO_UART) {
/* With support for checking H/W UART initialized or not, we allow serial_init(&stdio_uart)
* calls in even though H/W UART 'STDIO_UART' has initialized. When serial_init(&stdio_uart)
* calls in, we only need to set the 'stdio_uart_inited' flag. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 1;
memcpy(&stdio_uart, obj, sizeof(serial_t));
}
if (var->ref_cnt) {
// Mark this module to be inited.
int i = modinit - uart_modinit_tab;
@ -256,11 +258,13 @@ void serial_free(serial_t *obj)
if (var->obj == obj) {
var->obj = NULL;
}
if (obj->serial.uart == STDIO_UART) {
/* Clear the 'stdio_uart_inited' flag when serial_free(&stdio_uart) calls in. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 0;
}
if (! var->ref_cnt) {
// Mark this module to be deinited.
int i = modinit - uart_modinit_tab;

View File

@ -240,10 +240,12 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
obj->serial.dma_chn_id_rx = DMA_ERROR_OUT_OF_CHANNELS;
#endif
// For stdio management
if (obj->serial.uart == STDIO_UART) {
/* With support for checking H/W UART initialized or not, we allow serial_init(&stdio_uart)
* calls in even though H/W UART 'STDIO_UART' has initialized. When serial_init(&stdio_uart)
* calls in, we only need to set the 'stdio_uart_inited' flag. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 1;
memcpy(&stdio_uart, obj, sizeof(serial_t));
}
if (var->ref_cnt) {
@ -289,7 +291,9 @@ void serial_free(serial_t *obj)
var->obj = NULL;
}
if (obj->serial.uart == STDIO_UART) {
/* Clear the 'stdio_uart_inited' flag when serial_free(&stdio_uart) calls in. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 0;
}

View File

@ -175,12 +175,14 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
obj->serial.dma_chn_id_rx = DMA_ERROR_OUT_OF_CHANNELS;
#endif
// For stdio management
if (obj->serial.uart == STDIO_UART) {
/* With support for checking H/W UART initialized or not, we allow serial_init(&stdio_uart)
* calls in even though H/W UART 'STDIO_UART' has initialized. When serial_init(&stdio_uart)
* calls in, we only need to set the 'stdio_uart_inited' flag. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 1;
memcpy(&stdio_uart, obj, sizeof(serial_t));
}
if (var->ref_cnt) {
// Mark this module to be inited.
int i = modinit - uart_modinit_tab;
@ -221,11 +223,13 @@ void serial_free(serial_t *obj)
if (var->obj == obj) {
var->obj = NULL;
}
if (obj->serial.uart == STDIO_UART) {
/* Clear the 'stdio_uart_inited' flag when serial_free(&stdio_uart) calls in. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 0;
}
if (! var->ref_cnt) {
// Mark this module to be deinited.
int i = modinit - uart_modinit_tab;

View File

@ -240,12 +240,14 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
obj->serial.dma_chn_id_rx = DMA_ERROR_OUT_OF_CHANNELS;
#endif
// For stdio management
if (obj->serial.uart == STDIO_UART) {
/* With support for checking H/W UART initialized or not, we allow serial_init(&stdio_uart)
* calls in even though H/W UART 'STDIO_UART' has initialized. When serial_init(&stdio_uart)
* calls in, we only need to set the 'stdio_uart_inited' flag. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 1;
memcpy(&stdio_uart, obj, sizeof(serial_t));
}
if (var->ref_cnt) {
// Mark this module to be inited.
int i = modinit - uart_modinit_tab;
@ -286,11 +288,13 @@ void serial_free(serial_t *obj)
if (var->obj == obj) {
var->obj = NULL;
}
if (obj->serial.uart == STDIO_UART) {
/* Clear the 'stdio_uart_inited' flag when serial_free(&stdio_uart) calls in. */
if (((uintptr_t) obj) == ((uintptr_t) &stdio_uart)) {
MBED_ASSERT(obj->serial.uart == STDIO_UART);
stdio_uart_inited = 0;
}
if (! var->ref_cnt) {
// Mark this module to be deinited.
int i = modinit - uart_modinit_tab;