Skip to content

[LPC824] Add UART channel duplication check #1009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC82X/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,39 @@ static uart_irq_handler irq_handler;
int stdio_uart_inited = 0;
serial_t stdio_uart;

static int check_duplication(serial_t *obj, PinName tx, PinName rx)
{
if (uart_used == 0)
return 0;

const SWM_Map *swm;
uint32_t assigned_tx, assigned_rx;
int ch;
for (ch=0; ch<UART_NUM; ch++) {
// read assigned TX in the UART channel of switch matrix
swm = &SWM_UART_TX[ch];
assigned_tx = LPC_SWM->PINASSIGN[swm->n] & (0xFF << swm->offset);
assigned_tx = assigned_tx >> swm->offset;
// read assigned RX in the UART channel of switch matrix
swm = &SWM_UART_RX[ch];
assigned_rx = LPC_SWM->PINASSIGN[swm->n] & (0xFF << swm->offset);
assigned_rx = assigned_rx >> swm->offset;
if ((assigned_tx == (uint32_t)(tx >> PIN_SHIFT)) && (assigned_rx == (uint32_t)(rx >> PIN_SHIFT))) {
obj->index = ch;
obj->uart = (LPC_USART0_Type *)(LPC_USART0_BASE + (0x4000 * ch));
return 1;
}
}
return 0;
}

void serial_init(serial_t *obj, PinName tx, PinName rx)
{
int is_stdio_uart = 0;

if (check_duplication(obj, tx, rx) == 1)
return;

int uart_n = get_available_uart();
if (uart_n == -1) {
error("No available UART");
Expand Down Expand Up @@ -192,7 +221,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
stop_bits -= 1;
data_bits -= 7;

int paritysel;
int paritysel = 0;
switch (parity) {
case ParityNone: paritysel = 0; break;
case ParityEven: paritysel = 2; break;
Expand Down