fixed stuff
This commit is contained in:
@@ -27,7 +27,7 @@ struct uart_pti_bridge_data {
|
||||
union {
|
||||
struct {
|
||||
const uint8_t irq_triggered : 4;
|
||||
const uint8_t irq_enabled : 4;
|
||||
const uint8_t irq_enabled : 3;
|
||||
};
|
||||
struct {
|
||||
bool irq_tx_ready_triggered : 1;
|
||||
@@ -35,10 +35,9 @@ struct uart_pti_bridge_data {
|
||||
bool irq_rx_ready_triggered : 1;
|
||||
bool irq_err_triggered : 1;
|
||||
bool irq_tx_enabled : 1;
|
||||
bool : 1;
|
||||
bool irq_rx_enabled : 1;
|
||||
bool irq_err_enabled : 1;
|
||||
|
||||
bool tx_busy : 1;
|
||||
};
|
||||
};
|
||||
#endif
|
||||
@@ -107,9 +106,11 @@ int uart_pti_bridge_fifo_read(const struct device *dev, uint8_t *msg, const int
|
||||
|
||||
|
||||
void uart_pti_bridge_irq_tx_enable(const struct device *dev) {
|
||||
const struct uart_pti_bridge_config *config = dev->config;
|
||||
struct uart_pti_bridge_data *data = dev->data;
|
||||
|
||||
data->irq_tx_enabled = true;
|
||||
counter_start(config->counter);
|
||||
}
|
||||
|
||||
|
||||
@@ -135,9 +136,11 @@ int uart_pti_bridge_irq_tx_complete(const struct device *dev) {
|
||||
|
||||
|
||||
void uart_pti_bridge_irq_rx_enable(const struct device *dev) {
|
||||
const struct uart_pti_bridge_config *config = dev->config;
|
||||
struct uart_pti_bridge_data *data = dev->data;
|
||||
|
||||
data->irq_rx_enabled = true;
|
||||
counter_start(config->counter);
|
||||
}
|
||||
|
||||
|
||||
@@ -178,6 +181,7 @@ int uart_pti_bridge_irq_is_pending(const struct device *dev) {
|
||||
|
||||
int uart_pti_bridge_irq_update(const struct device *dev) {
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
return 1; // success
|
||||
}
|
||||
|
||||
@@ -192,45 +196,70 @@ void uart_pti_bridge_callback_set(const struct device *dev, uart_irq_callback_us
|
||||
}
|
||||
|
||||
|
||||
void uart_pti_bridge_timer_irq_sync(const struct device *dev) {
|
||||
struct uart_pti_bridge_data *data = dev->data;
|
||||
|
||||
data->irq_tx_ready_triggered = data->irq_tx_enabled ? REDUCE_TO_BIT(ring_buf_space_get(data->tx_buf)) : 0;
|
||||
data->irq_tx_complete_triggered = data->irq_tx_enabled ? REDUCE_TO_BIT(ring_buf_is_empty(data->tx_buf)) : 0;
|
||||
data->irq_rx_ready_triggered = data->irq_rx_enabled ? REDUCE_TO_BIT(!ring_buf_is_empty(data->rx_buf)) : 0;
|
||||
data->irq_err_triggered = data->irq_err_enabled ? REDUCE_TO_BIT(uart_pti_bridge_err_check(dev)) : 0;
|
||||
}
|
||||
|
||||
|
||||
void uart_pti_bridge_timer_irq_rx(const struct device *dev) {
|
||||
const struct uart_pti_bridge_config *config = dev->config;
|
||||
struct uart_pti_bridge_data *data = dev->data;
|
||||
|
||||
|
||||
uint8_t *rx_data;
|
||||
uint32_t available_space = ring_buf_put_claim(data->rx_buf, &rx_data, UINT32_MAX);
|
||||
uint32_t bytes_read = 0;
|
||||
|
||||
while (bytes_read < available_space && uart_poll_in(config->uart, rx_data++) == 0) {
|
||||
bytes_read += 1;
|
||||
}
|
||||
|
||||
ring_buf_put_finish(data->rx_buf, bytes_read);
|
||||
}
|
||||
|
||||
|
||||
void uart_pti_bridge_timer_irq_tx(const struct device *dev) {
|
||||
const struct uart_pti_bridge_config *config = dev->config;
|
||||
struct uart_pti_bridge_data *data = dev->data;
|
||||
|
||||
uint8_t tx_data;
|
||||
if (ring_buf_get(data->tx_buf, &tx_data, 1)) {
|
||||
data->tx_busy = 1;
|
||||
uart_poll_out(config->uart, tx_data);
|
||||
} else {
|
||||
data->tx_busy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void uart_pti_bridge_timer_irq(const struct device *timer_dev, void *user_data) {
|
||||
ARG_UNUSED(timer_dev);
|
||||
|
||||
const struct device *dev = user_data;
|
||||
struct uart_pti_bridge_data *data = dev->data;
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
data->irq_tx_ready_triggered = REDUCE_TO_BIT(ring_buf_space_get(data->tx_buf));
|
||||
data->irq_tx_complete_triggered = REDUCE_TO_BIT(ring_buf_is_empty(data->tx_buf));
|
||||
data->irq_rx_ready_triggered = REDUCE_TO_BIT(!ring_buf_is_empty(data->rx_buf));
|
||||
data->irq_err_triggered = REDUCE_TO_BIT(uart_pti_bridge_err_check(dev));
|
||||
|
||||
if (data->irq_tx_ready_triggered && !data->irq_tx_complete_triggered) {
|
||||
uint8_t chunk;
|
||||
if (ring_buf_get(data->tx_buf, &chunk, 1)) {
|
||||
uart_poll_out(dev, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if (data->irq_rx_enabled) {
|
||||
uint32_t rx_buf_free_space = ring_buf_space_get(data->rx_buf);
|
||||
uint8_t chunk;
|
||||
|
||||
for (uint32_t bytes_read = 0; bytes_read <= rx_buf_free_space; bytes_read++) {
|
||||
if (uart_poll_in(dev, &chunk) < 0) {
|
||||
break;
|
||||
}
|
||||
ring_buf_put(data->rx_buf, &chunk, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
k_spin_unlock(&data->lock, key);
|
||||
uart_pti_bridge_timer_irq_sync(dev);
|
||||
|
||||
if (data->cb && data->irq_triggered) {
|
||||
data->cb(dev, data->user_data);
|
||||
}
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
uart_pti_bridge_timer_irq_tx(dev);
|
||||
uart_pti_bridge_timer_irq_rx(dev);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
if (!data->irq_enabled && !data->tx_busy) {
|
||||
const struct uart_pti_bridge_config *config = dev->config;
|
||||
counter_stop(config->counter);
|
||||
counter_reset(config->counter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint32_t uart_pti_bridge_us_per_byte(const struct uart_config *cfg)
|
||||
{
|
||||
@@ -281,7 +310,6 @@ int uart_pti_bridge_init(const struct device *dev) {
|
||||
};
|
||||
|
||||
counter_set_top_value(config->counter, &top_cfg);
|
||||
counter_start(config->counter);
|
||||
#else
|
||||
ARG_UNUSED(dev);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user