Skip to content

Commit

Permalink
Fix bug that convoluted the file mode for the UART hardware mode (#706)
Browse files Browse the repository at this point in the history
* Fix bug that convoluted the file mode for the UART hardware mode.

* Rename uartMode_ in Tiva UART driver for consistency with the updated CC32xx UART driver.
  • Loading branch information
bakerstu authored Apr 29, 2023
1 parent db89362 commit 00171fb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 36 deletions.
38 changes: 20 additions & 18 deletions src/freertos_drivers/ti/CC32xxUart.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ CC32xxUart::CC32xxUart(const char *name, unsigned long base, uint32_t interrupt,
, base_(base)
, interrupt_(interrupt)
, baud_(baud)
, uartMode_(mode | UART_CONFIG_PAR_NONE)
, txPending_(false)
, hwFIFO_(hw_fifo)
{
static_assert(
UART_CONFIG_PAR_NONE == 0, "driverlib changed against our assumptions");
static_assert(
UART_CONFIG_STOP_ONE == 0, "driverlib changed against our assumptions");
HASSERT(mode <= 0xFFu);
HASSERT(uartMode_ <= 0xFFu);

switch (base)
{
Expand All @@ -95,8 +96,7 @@ CC32xxUart::CC32xxUart(const char *name, unsigned long base, uint32_t interrupt,
break;
}

MAP_UARTConfigSetExpClk(base_, cm3_cpu_clock_hz, baud,
mode | UART_CONFIG_PAR_NONE);
MAP_UARTConfigSetExpClk(base_, cm3_cpu_clock_hz, baud, uartMode_);
MAP_IntDisable(interrupt_);
/* We set the priority so that it is slightly lower than the highest needed
* for FreeRTOS compatibility. This will ensure that CAN interrupts take
Expand Down Expand Up @@ -150,38 +150,38 @@ int CC32xxUart::ioctl(File *file, unsigned long int key, unsigned long data)
MAP_UtilsDelay(12 * 26);
break;
case TCPARNONE:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_NONE;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_NONE;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_NONE);
break;
case TCPARODD:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_ODD;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_ODD;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_ODD);
break;
case TCPAREVEN:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_EVEN;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_EVEN;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_EVEN);
break;
case TCPARONE:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_ONE;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_ONE;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_ONE);
break;
case TCPARZERO:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_ZERO;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_ZERO;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_ZERO);
break;
case TCSTOPONE:
mode_ &= ~UART_CONFIG_STOP_MASK;
mode_ |= UART_CONFIG_STOP_ONE;
uartMode_ &= ~UART_CONFIG_STOP_MASK;
uartMode_ |= UART_CONFIG_STOP_ONE;
set_mode();
break;
case TCSTOPTWO:
mode_ &= ~UART_CONFIG_STOP_MASK;
mode_ |= UART_CONFIG_STOP_TWO;
uartMode_ &= ~UART_CONFIG_STOP_MASK;
uartMode_ |= UART_CONFIG_STOP_TWO;
set_mode();
break;
case TCBAUDRATE:
Expand Down Expand Up @@ -217,7 +217,9 @@ int CC32xxUart::ioctl(File *file, unsigned long int key, unsigned long data)
/** Sets the port baud rate and mode from the class variables. */
void CC32xxUart::set_mode()
{
MAP_UARTConfigSetExpClk(base_, cm3_cpu_clock_hz, baud_, mode_);
disable();
MAP_UARTConfigSetExpClk(base_, cm3_cpu_clock_hz, baud_, uartMode_);
enable();
}

/** Send data until there is no more space left.
Expand Down
1 change: 1 addition & 0 deletions src/freertos_drivers/ti/CC32xxUart.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private:
unsigned long base_; /**< base address of this device */
uint32_t interrupt_ : 8; /**< interrupt of this device */
uint32_t baud_ : 24; /**< desired baud rate */
uint32_t uartMode_; /**< mode of the UART, 8 or 9 bit, 1 or 2 stop... */
uint8_t txPending_; /**< transmission currently pending */
uint8_t hwFIFO_; /**< true if hardware fifo is to be enabled, else false */

Expand Down
2 changes: 1 addition & 1 deletion src/freertos_drivers/ti/TivaDev.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private:
uint32_t interrupt_ : 8; /**< interrupt of this device */
uint32_t baud_ : 24; /**< desired baud rate */
uint8_t hwFIFO_; /**< enable HW FIFO */
uint8_t mode_; /**< uart config (mode) flags */
uint8_t uartMode_; /**< uart config (mode) flags */
uint8_t txPending_; /**< transmission currently pending */

/** Default constructor.
Expand Down
34 changes: 17 additions & 17 deletions src/freertos_drivers/ti/TivaUart.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ TivaUart::TivaUart(const char *name, unsigned long base, uint32_t interrupt,
, interrupt_(interrupt)
, baud_(baud)
, hwFIFO_(hw_fifo)
, mode_(mode)
, uartMode_(mode)
, txPending_(false)
{
static_assert(
Expand Down Expand Up @@ -116,7 +116,7 @@ TivaUart::TivaUart(const char *name, unsigned long base, uint32_t interrupt,
break;
}

MAP_UARTConfigSetExpClk(base_, cm3_cpu_clock_hz, baud_, mode_);
MAP_UARTConfigSetExpClk(base_, cm3_cpu_clock_hz, baud_, uartMode_);
MAP_UARTTxIntModeSet(base_, UART_TXINT_MODE_EOT);
MAP_IntDisable(interrupt_);
/* We set the priority so that it is slightly lower than the highest needed
Expand Down Expand Up @@ -260,7 +260,7 @@ void TivaUart::interrupt_handler()
/** Sets the port baud rate and mode from the class variables. */
void TivaUart::set_mode()
{
MAP_UARTConfigSetExpClk(base_, cm3_cpu_clock_hz, baud_, mode_);
MAP_UARTConfigSetExpClk(base_, cm3_cpu_clock_hz, baud_, uartMode_);
}

/** Request an ioctl transaction
Expand All @@ -283,38 +283,38 @@ int TivaUart::ioctl(File *file, unsigned long int key, unsigned long data)
MAP_SysCtlDelay(12 * 26);
break;
case TCPARNONE:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_NONE;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_NONE;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_NONE);
break;
case TCPARODD:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_ODD;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_ODD;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_ODD);
break;
case TCPAREVEN:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_EVEN;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_EVEN;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_EVEN);
break;
case TCPARONE:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_ONE;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_ONE;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_ONE);
break;
case TCPARZERO:
mode_ &= ~UART_CONFIG_PAR_MASK;
mode_ |= UART_CONFIG_PAR_ZERO;
uartMode_ &= ~UART_CONFIG_PAR_MASK;
uartMode_ |= UART_CONFIG_PAR_ZERO;
MAP_UARTParityModeSet(base_, UART_CONFIG_PAR_ZERO);
break;
case TCSTOPONE:
mode_ &= ~UART_CONFIG_STOP_MASK;
mode_ |= UART_CONFIG_STOP_ONE;
uartMode_ &= ~UART_CONFIG_STOP_MASK;
uartMode_ |= UART_CONFIG_STOP_ONE;
set_mode();
break;
case TCSTOPTWO:
mode_ &= ~UART_CONFIG_STOP_MASK;
mode_ |= UART_CONFIG_STOP_TWO;
uartMode_ &= ~UART_CONFIG_STOP_MASK;
uartMode_ |= UART_CONFIG_STOP_TWO;
set_mode();
break;
case TCBAUDRATE:
Expand Down

0 comments on commit 00171fb

Please sign in to comment.