From 9413ed9163336a982bd7eaf9d7bece203efdd33d Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Wed, 9 Jul 2014 10:52:37 +0100 Subject: [PATCH] provide default initialization of some local variables in serial_api.c:serial_format() --- .../TARGET_NXP/TARGET_LPC176X/serial_api.c | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c index 6c056730cc..7972edab33 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c @@ -84,13 +84,13 @@ static struct serial_global_data_s uart_data[UART_NUM]; void serial_init(serial_t *obj, PinName tx, PinName rx) { int is_stdio_uart = 0; - + // determine the UART to use UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); MBED_ASSERT((int)uart != NC); - + obj->uart = (LPC_UART_TypeDef *)uart; // enable power switch (uart) { @@ -110,19 +110,19 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { obj->uart->IER = 0 << 0 // Rx Data available irq enable | 0 << 1 // Tx Fifo empty irq enable | 0 << 2; // Rx Line Status irq enable - + // set default baud rate and format serial_baud (obj, 9600); serial_format(obj, 8, ParityNone, 1); - + // pinout the chosen uart pinmap_pinout(tx, PinMap_UART_TX); pinmap_pinout(rx, PinMap_UART_RX); - + // set rx/tx pins in PullUp mode pin_mode(tx, PullUp); pin_mode(rx, PullUp); - + switch (uart) { case UART_0: obj->index = 0; break; case UART_1: obj->index = 1; break; @@ -132,9 +132,9 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { uart_data[obj->index].sw_rts.pin = NC; uart_data[obj->index].sw_cts.pin = NC; serial_set_flow_control(obj, FlowControlNone, NC, NC); - + is_stdio_uart = (uart == STDIO_UART) ? (1) : (0); - + if (is_stdio_uart) { stdio_uart_inited = 1; memcpy(&stdio_uart, obj, sizeof(serial_t)); @@ -166,9 +166,9 @@ void serial_baud(serial_t *obj, int baudrate) { case UART_3: LPC_SC->PCLKSEL1 &= ~(0x3 << 18); LPC_SC->PCLKSEL1 |= (0x1 << 18); break; default: break; } - + uint32_t PCLK = SystemCoreClock; - + // First we check to see if the basic divide with no DivAddVal/MulVal // ratio gives us an integer result. If it does, we set DivAddVal = 0, // MulVal = 1. Otherwise, we search the valid ratio value range to find @@ -229,16 +229,16 @@ void serial_baud(serial_t *obj, int baudrate) { } } } - + // set LCR[DLAB] to enable writing to divider registers obj->uart->LCR |= (1 << 7); - + // set divider values obj->uart->DLM = (DL >> 8) & 0xFF; obj->uart->DLL = (DL >> 0) & 0xFF; obj->uart->FDR = (uint32_t) DivAddVal << 0 | (uint32_t) MulVal << 4; - + // clear LCR[DLAB] obj->uart->LCR &= ~(1 << 7); } @@ -260,9 +260,10 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced0: parity_enable = 1; parity_select = 3; break; default: + parity_enable = 0, parity_select = 0; break; } - + obj->uart->LCR = data_bits << 0 | stop_bits << 2 | parity_enable << 3 @@ -310,7 +311,7 @@ static void serial_irq_set_internal(serial_t *obj, SerialIrq irq, uint32_t enabl case UART_2: irq_n=UART2_IRQn; vector = (uint32_t)&uart2_irq; break; case UART_3: irq_n=UART3_IRQn; vector = (uint32_t)&uart3_irq; break; } - + if (enable) { obj->uart->IER |= 1 << irq; NVIC_SetVector(irq_n, vector);