Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/uart tx user bit in wide port #107

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions modules/uart/api/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef enum {
typedef struct {
uart_state_t state;
port_t tx_port;
uint32_t tx_port_high_val;
uint32_t bit_time_ticks;
uint32_t next_event_time_ticks;
uart_parity_t parity;
Expand All @@ -109,7 +110,9 @@ typedef struct {
* buffered mode with ISR for use in bare-metal applications.
*
* \param uart The uart_tx_t context to initialise.
* \param tx_port The port used transmit the UART frames.
* \param tx_port The port used transmit the UART frames. May be a one or
* multi bit port. Please set uart.tx_port_high_val post init
* to the idle value if any other than bit 0 is the UART Tx port.
* \param baud_rate The baud rate of the UART in bits per second.
* \param data_bits The number of data bits per frame sent.
* \param parity The type of parity used. See uart_parity_t above.
Expand Down Expand Up @@ -231,7 +234,7 @@ typedef struct {
* buffered mode with ISR for use in bare-metal applications.
*
* \param uart The uart_rx_t context to initialise.
* \param rx_port The port used receive the UART frames.
* \param rx_port The port used receive the UART frames. Must be a one bit port.
* \param baud_rate The baud rate of the UART in bits per second.
* \param data_bits The number of data bits per frame sent.
* \param parity The type of parity used. See uart_parity_t above.
Expand Down
9 changes: 5 additions & 4 deletions modules/uart/src/uart_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void uart_tx_init(
){

uart_cfg->tx_port = tx_port;
uart_cfg->tx_port_high_val = 0x01; // Default value. May be overridden post-init
uart_cfg->bit_time_ticks = XS1_TIMER_HZ / baud_rate;

uart_cfg->next_event_time_ticks = 0;
Expand Down Expand Up @@ -73,7 +74,7 @@ void uart_tx_init(
}

port_enable(tx_port);
port_out(tx_port, 1); //Set to idle
port_out(tx_port, uart_cfg->tx_port_high_val); //Set to idle
}


Expand Down Expand Up @@ -144,7 +145,7 @@ DEFINE_INTERRUPT_CALLBACK(UART_TX_INTERRUPTABLE_FUNCTIONS, uart_tx_handle_event,

case UART_DATA: {
uint32_t port_val = (uart_cfg->uart_data >> uart_cfg->current_data_bit) & 0x1;
port_out(uart_cfg->tx_port, port_val);
port_out(uart_cfg->tx_port, port_val ? uart_cfg->tx_port_high_val : 0);
uart_cfg->current_data_bit++;
uart_cfg->next_event_time_ticks += uart_cfg->bit_time_ticks;
if(uart_cfg->current_data_bit == uart_cfg->num_data_bits){
Expand All @@ -162,14 +163,14 @@ DEFINE_INTERRUPT_CALLBACK(UART_TX_INTERRUPTABLE_FUNCTIONS, uart_tx_handle_event,
uint32_t parity = (unsigned)uart_cfg->uart_data;
// crc32(parity, parity_setting, 1); //http://bugzilla/show_bug.cgi?id=18663
asm volatile("crc32 %0, %2, %3" : "=r" (parity) : "0" (parity), "r" (parity_setting), "r" (1));
port_out(uart_cfg->tx_port, parity);
port_out(uart_cfg->tx_port, parity ? uart_cfg->tx_port_high_val : 0);
uart_cfg->state = UART_STOP;
uart_cfg->next_event_time_ticks += uart_cfg->bit_time_ticks;
break;
}

case UART_STOP: {
port_out(uart_cfg->tx_port, 1);
port_out(uart_cfg->tx_port, uart_cfg->tx_port_high_val);
uart_cfg->current_stop_bit += 1;
uart_cfg->next_event_time_ticks += uart_cfg->bit_time_ticks; //do before buffered_uart_tx_char_finished

Expand Down
Loading