diff options
Diffstat (limited to 'os/hal')
| -rw-r--r-- | os/hal/ports/NRF51/NRF51822/serial_lld.c | 55 | ||||
| -rw-r--r-- | os/hal/ports/NRF51/NRF51822/serial_lld.h | 14 | 
2 files changed, 58 insertions, 11 deletions
diff --git a/os/hal/ports/NRF51/NRF51822/serial_lld.c b/os/hal/ports/NRF51/NRF51822/serial_lld.c index bc4a9b6..550a070 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) {
 @@ -91,26 +94,56 @@ static void configure_uart(const SerialConfig *config)      default: osalDbgAssert(0, "invalid baudrate"); break;
    };
 -  /* Configure PINs */
 +  /* Configure PINs mode */
    if (config->tx_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
      palSetPadMode(IOPORT1, config->tx_pad, PAL_MODE_OUTPUT_PUSHPULL);
 -    NRF_UART0->PSELTXD = config->tx_pad;
    }
    if (config->rx_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
      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);
 +  }
 +  if (config->cts_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
 +    palSetPadMode(IOPORT1, config->cts_pad, PAL_MODE_INPUT);
 +  }
 +#endif
 +  
 +  /* Select PINs used by UART */
 +  NRF_UART0->PSELTXD = config->tx_pad;
 +  NRF_UART0->PSELRXD = config->rx_pad;
 +#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
 +  NRF_UART0->PSELRTS = config->rts_pad;
 +  NRF_UART0->PSELCTS = config->cts_pad;
 +#else
 +  NRF_UART0->PSELRTS = NRF51_SERIAL_PAD_DISCONNECTED;
 +  NRF_UART0->PSELCTS = NRF51_SERIAL_PAD_DISCONNECTED;
 +#endif
 +  /* Set baud rate */
    NRF_UART0->BAUDRATE = speed;
 +
 +  /* Set config */
    NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos);
 +
 +  /* Adjust flow control */
 +#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);
 +  }
 +#else
 +  NRF_UART0->CONFIG   &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
 +#endif
 +  
 +  /* Enable UART and clear events */
    NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled;
    NRF_UART0->EVENTS_RXDRDY = 0;
    NRF_UART0->EVENTS_TXDRDY = 0;
 -  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;
    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;
  /**
  | 
