Skip to content

Commit 53cd647

Browse files
author
Bogdan Marinescu
committed
Hardware flow control implementation for LPC81X
1 parent d0b2fb6 commit 53cd647

File tree

1 file changed

+44
-0
lines changed
  • libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X

1 file changed

+44
-0
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/serial_api.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ static const SWM_Map SWM_UART_RX[] = {
3939
{2, 24},
4040
};
4141

42+
static const SWM_Map SWM_UART_RTS[] = {
43+
{0, 16},
44+
{1, 24},
45+
{3, 0},
46+
};
47+
48+
static const SWM_Map SWM_UART_CTS[] = {
49+
{0, 24},
50+
{2, 0},
51+
{3, 8}
52+
};
53+
4254
// bit flags for used UARTs
4355
static unsigned char uart_used = 0;
4456
static int get_available_uart(void) {
@@ -60,6 +72,7 @@ static int get_available_uart(void) {
6072
#define TXRDY (0x01<<2)
6173

6274
#define TXBRKEN (0x01<<1)
75+
#define CTSEN (0x01<<9)
6376

6477
static uint32_t UARTSysClk;
6578

@@ -278,3 +291,34 @@ void serial_break_clear(serial_t *obj) {
278291
obj->uart->CTRL &= ~TXBRKEN;
279292
}
280293

294+
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) {
295+
const SWM_Map *swm_rts, *swm_cts;
296+
uint32_t regVal_rts, regVal_cts;
297+
298+
swm_rts = &SWM_UART_RTS[obj->index];
299+
swm_cts = &SWM_UART_CTS[obj->index];
300+
regVal_rts = LPC_SWM->PINASSIGN[swm_rts->n] & ~(0xFF << swm_rts->offset);
301+
regVal_cts = LPC_SWM->PINASSIGN[swm_cts->n] & ~(0xFF << swm_cts->offset);
302+
303+
if (FlowControlNone == type) {
304+
LPC_SWM->PINASSIGN[swm_rts->n] = regVal_rts | (0xFF << swm_rts->offset);
305+
LPC_SWM->PINASSIGN[swm_cts->n] = regVal_cts | (0xFF << swm_cts->offset);
306+
obj->uart->CFG &= ~CTSEN;
307+
return;
308+
}
309+
if ((FlowControlRTS == type || FlowControlRTSCTS == type) && (rxflow != NC)) {
310+
LPC_SWM->PINASSIGN[swm_rts->n] = regVal_rts | (rxflow << swm_rts->offset);
311+
if (FlowControlRTS == type) {
312+
LPC_SWM->PINASSIGN[swm_cts->n] = regVal_cts | (0xFF << swm_cts->offset);
313+
obj->uart->CFG &= ~CTSEN;
314+
}
315+
}
316+
if ((FlowControlCTS == type || FlowControlRTSCTS == type) && (txflow != NC)) {
317+
LPC_SWM->PINASSIGN[swm_cts->n] = regVal_cts | (txflow << swm_cts->offset);
318+
obj->uart->CFG |= CTSEN;
319+
if (FlowControlCTS == type) {
320+
LPC_SWM->PINASSIGN[swm_rts->n] = regVal_rts | (0xFF << swm_rts->offset);
321+
}
322+
}
323+
}
324+

0 commit comments

Comments
 (0)