Skip to content

Commit

Permalink
Support arbitrary bit in UART tx
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-xmos committed Mar 11, 2024
1 parent 94a1dca commit a324bfd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 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 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

0 comments on commit a324bfd

Please sign in to comment.