From ff83792d5256a7590fa4223825d71de45846def4 Mon Sep 17 00:00:00 2001 From: Andrii Anpilogov Date: Mon, 6 Oct 2014 14:35:48 +0800 Subject: [PATCH] Fix NRF51822 PWM and Serial: - imlement pwmout_free() - check UART interrupt type carefully - implement serial_set_flow_control() - add serial_clear() stub --- .../TARGET_MCU_NRF51822/pwmout_api.c | 4 ++- .../TARGET_MCU_NRF51822/serial_api.c | 35 +++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/pwmout_api.c index f2e32a0d81..c58948e24c 100644 --- a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/pwmout_api.c @@ -241,7 +241,9 @@ void pwmout_init(pwmout_t *obj, PinName pin) void pwmout_free(pwmout_t *obj) { - // [TODO] + MBED_ASSERT(obj->pwm != (PWMName)NC); + PWM_taken[obj->pwm] = 0; + pwmout_write(obj, 0); } void pwmout_write(pwmout_t *obj, float value) diff --git a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/serial_api.c b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/serial_api.c index 25c7df2de6..7356b67989 100644 --- a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/serial_api.c @@ -162,9 +162,9 @@ void UART0_IRQHandler() { uint32_t irtype = 0; - if (NRF_UART0->EVENTS_TXDRDY) { + if((NRF_UART0->INTENSET & 0x80) && NRF_UART0->EVENTS_TXDRDY) { irtype = 1; - } else if (NRF_UART0->EVENTS_RXDRDY) { + } else if((NRF_UART0->INTENSET & 0x04) && NRF_UART0->EVENTS_RXDRDY) { irtype = 2; } uart_irq(irtype, 0); @@ -262,3 +262,34 @@ void serial_break_clear(serial_t *obj) obj->uart->TASKS_STARTTX = 1; obj->uart->TASKS_STARTRX = 1; } + +void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) +{ + + if (type == FlowControlRTSCTS || type == FlowControlRTS) { + NRF_GPIO->DIR |= (1<uart->PSELRTS = rxflow; + + obj->uart->CONFIG |= 0x01; // Enable HWFC + } + + if (type == FlowControlRTSCTS || type == FlowControlCTS) { + NRF_GPIO->DIR &= ~(1<uart->PSELCTS = txflow; + + obj->uart->CONFIG |= 0x01; // Enable HWFC; + } + + if (type == FlowControlNone) { + obj->uart->PSELRTS = 0xFFFFFFFF; // Disable RTS + obj->uart->PSELCTS = 0xFFFFFFFF; // Disable CTS + + obj->uart->CONFIG &= ~0x01; // Enable HWFC; + } +} + +void serial_clear(serial_t *obj) { +} +