aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorStephane D'Alu <sdalu@sdalu.com>2016-02-02 13:34:47 +0100
committerStephane D'Alu <sdalu@sdalu.com>2016-02-02 13:34:47 +0100
commit137836fb19623735351e411f30d7d6bd29e28012 (patch)
treeb46de087dd448854305fe1b075fce39763d4066b /os
parenta8592bb3b15e1392bd1e2a0239d7f2b1f1f69d6e (diff)
downloadChibiOS-Contrib-137836fb19623735351e411f30d7d6bd29e28012.tar.gz
ChibiOS-Contrib-137836fb19623735351e411f30d7d6bd29e28012.tar.bz2
ChibiOS-Contrib-137836fb19623735351e411f30d7d6bd29e28012.zip
hardware flow control from nRF51
Diffstat (limited to 'os')
-rw-r--r--os/hal/ports/NRF51/NRF51822/serial_lld.c38
-rw-r--r--os/hal/ports/NRF51/NRF51822/serial_lld.h14
2 files changed, 45 insertions, 7 deletions
diff --git a/os/hal/ports/NRF51/NRF51822/serial_lld.c b/os/hal/ports/NRF51/NRF51822/serial_lld.c
index bc4a9b6..bddc4c3 100644
--- a/os/hal/ports/NRF51/NRF51822/serial_lld.c
+++ b/os/hal/ports/NRF51/NRF51822/serial_lld.c
@@ -49,9 +49,13 @@ SerialDriver SD1;
* @brief Driver default configuration.
*/
static const SerialConfig default_config = {
- .speed = 38400,
- .tx_pad = NRF51_SERIAL_PAD_DISCONNECTED,
- .rx_pad = NRF51_SERIAL_PAD_DISCONNECTED,
+ .speed = 38400,
+ .tx_pad = NRF51_SERIAL_PAD_DISCONNECTED,
+ .rx_pad = NRF51_SERIAL_PAD_DISCONNECTED,
+#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
+ .rts_pad = NRF51_SERIAL_PAD_DISCONNECTED,
+ .cts_pad = NRF51_SERIAL_PAD_DISCONNECTED,
+#endif
};
/*===========================================================================*/
@@ -68,7 +72,6 @@ static const SerialConfig default_config = {
*/
static void configure_uart(const SerialConfig *config)
{
- /* TODO: Add support for CTS/RTS! */
uint32_t speed = UART_BAUDRATE_BAUDRATE_Baud250000;
switch (config->speed) {
@@ -100,6 +103,16 @@ static void configure_uart(const SerialConfig *config)
palSetPadMode(IOPORT1, config->rx_pad, PAL_MODE_INPUT);
NRF_UART0->PSELRXD = config->rx_pad;
}
+#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
+ if (config->rts_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
+ palSetPadMode(IOPORT1, config->rts_pad, PAL_MODE_OUTPUT_PUSHPULL);
+ NRF_UART0->PSELRTS = config->rts_pad;
+ }
+ if (config->cts_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
+ palSetPadMode(IOPORT1, config->cts_pad, PAL_MODE_INPUT);
+ NRF_UART0->PSELCTS = config->cts_pad;
+ }
+#endif
NRF_UART0->BAUDRATE = speed;
NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos);
@@ -107,10 +120,21 @@ static void configure_uart(const SerialConfig *config)
NRF_UART0->EVENTS_RXDRDY = 0;
NRF_UART0->EVENTS_TXDRDY = 0;
- NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
+#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
+ if ((config->rts_pad < TOTAL_GPIO_PADS) ||
+ (config->cts_pad < TOTAL_GPIO_PADS)) {
+ NRF_UART0->CONFIG |= UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos;
+ } else {
+ NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
+ }
+ NRF_UART0->PSELRTS = config->rts_pad;
+ NRF_UART0->PSELCTS = config->cts_pad;
+#else
+ NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
- NRF_UART0->PSELRTS = NRF51_SERIAL_PAD_DISCONNECTED;
- NRF_UART0->PSELCTS = NRF51_SERIAL_PAD_DISCONNECTED;
+ NRF_UART0->PSELRTS = NRF51_SERIAL_PAD_DISCONNECTED;
+ NRF_UART0->PSELCTS = NRF51_SERIAL_PAD_DISCONNECTED;
+#endif
if (config->rx_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
while (NRF_UART0->EVENTS_RXDRDY != 0) {
diff --git a/os/hal/ports/NRF51/NRF51822/serial_lld.h b/os/hal/ports/NRF51/NRF51822/serial_lld.h
index 8da3998..5fc5e87 100644
--- a/os/hal/ports/NRF51/NRF51822/serial_lld.h
+++ b/os/hal/ports/NRF51/NRF51822/serial_lld.h
@@ -40,6 +40,16 @@
* @{
*/
/**
+ * @brief SD flow control enable switch.
+ * @details If set to @p TRUE the support for hardware flow control
+ * is included.
+ * @note The default is @p FALSE.
+ */
+#if !defined(NRF51_SERIAL_USE_HWFLOWCTRL) || defined(__DOXYGEN__)
+#define NRF51_SERIAL_USE_HWFLOWCTRL FALSE
+#endif
+
+/**
* @brief SD1 driver enable switch.
* @details If set to @p TRUE the support for SD1 is included.
* @note The default is @p FALSE.
@@ -85,6 +95,10 @@ typedef struct {
/* End of the mandatory fields.*/
uint32_t tx_pad;
uint32_t rx_pad;
+#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
+ uint32_t rts_pad;
+ uint32_t cts_pad;
+#endif
} SerialConfig;
/**