diff options
author | Marc Zyngier <maz@kernel.org> | 2023-08-27 10:23:00 +0100 |
---|---|---|
committer | Marc Zyngier <maz@kernel.org> | 2023-08-27 10:32:57 +0100 |
commit | 0a4652cd6fff2bfdfc223f2a0ef4d6e4d1bdb3ad (patch) | |
tree | f5fac3dfb627c8f5564c2f0f25c0ac287a96c143 | |
parent | 90c13f31082d7641d6b7639ef6fc04a0602764e5 (diff) | |
download | cs-sw-0a4652cd6fff2bfdfc223f2a0ef4d6e4d1bdb3ad.tar.gz |
Indirect access to upstream port
Signed-off-by: Marc Zyngier <maz@kernel.org>
-rw-r--r-- | m1-pd-bmc.h | 16 | ||||
-rw-r--r-- | start.c | 44 | ||||
-rw-r--r-- | vdmtool.c | 4 |
3 files changed, 40 insertions, 24 deletions
diff --git a/m1-pd-bmc.h b/m1-pd-bmc.h index 9c56f41..6edc509 100644 --- a/m1-pd-bmc.h +++ b/m1-pd-bmc.h @@ -45,17 +45,23 @@ void m1_pd_bmc_fusb_setup(unsigned int port, const struct hw_context *hw); void m1_pd_bmc_run(void); -void usb_tx_bytes(int32_t port, const char *ptr, int len); -void usb_tx_str(int32_t port, char *ptr); -int32_t usb_rx_byte(int32_t port); +struct upstream_ops { + void (*tx_bytes)(int32_t port, const char *ptr, int len); + int32_t (*rx_byte)(int32_t port); + void (*flush)(void); +}; + +extern const struct upstream_ops *upstream_ops; + +void upstream_tx_str(int32_t port, const char *ptr); #define PRINTF_SIZE 512 #define __printf(__p, __f, ...) do { \ char __str[PRINTF_SIZE]; \ snprintf(__str, PRINTF_SIZE, __f, ##__VA_ARGS__); \ - usb_tx_str(__p, __str); \ - tud_task(); \ + upstream_tx_str(__p, __str); \ + upstream_ops->flush(); \ } while(0) #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -101,7 +101,7 @@ static void __not_in_flash_func(uart_irq_fn)(int port, { while (uart_is_readable(hw->uart)) { char c = uart_getc(hw->uart); - usb_tx_bytes(port, &c, 1); + upstream_ops->tx_bytes(port, &c, 1); } } @@ -178,7 +178,7 @@ static void m1_pd_bmc_system_init(const struct hw_context *hw) m1_pd_bmc_gpio_setup_one(&hw->pins[i]); } -void usb_tx_bytes(int32_t port, const char *ptr, int len) +static void usb_tx_bytes(int32_t port, const char *ptr, int len) { if (!tud_cdc_n_connected(port)) return; @@ -200,41 +200,51 @@ void usb_tx_bytes(int32_t port, const char *ptr, int len) } } -void usb_tx_str(int32_t port, char *str) +static int32_t usb_rx_byte(int32_t port) +{ + uint8_t c; + + if (!tud_cdc_n_connected(port) || !tud_cdc_n_available(port)) + return -1; + + tud_cdc_n_read(port, &c, 1); + return c; +} + +static const struct upstream_ops usb_upstream_ops = { + .tx_bytes = usb_tx_bytes, + .rx_byte = usb_rx_byte, + .flush = tud_task, +}; + +const struct upstream_ops *upstream_ops; + +void upstream_tx_str(int32_t port, const char *str) { do { - char *cursor = str; + const char *cursor = str; while (*cursor && *cursor != '\n') cursor++; - usb_tx_bytes(port, str, cursor - str); + upstream_ops->tx_bytes(port, str, cursor - str); if (!*cursor) return; - usb_tx_bytes(port, "\n\r", 2); + upstream_ops->tx_bytes(port, "\n\r", 2); str = cursor + 1; } while (*str); } -int32_t usb_rx_byte(int32_t port) -{ - uint8_t c; - - if (!tud_cdc_n_connected(port) || !tud_cdc_n_available(port)) - return -1; - - tud_cdc_n_read(port, &c, 1); - return c; -} - int main(void) { bool success; int port; + upstream_ops = &usb_upstream_ops; + success = set_sys_clock_khz(133000, false); board_init(); @@ -517,7 +517,7 @@ static bool serial_handler(struct vdm_context *cxt) bool uart_active = false; int32_t c; - while ((c = usb_rx_byte(PORT(cxt))) != -1) { + while ((c = upstream_ops->rx_byte(PORT(cxt))) != -1) { uart_active = true; if ((!cxt->vdm_escape && c != 0x1f)) { @@ -742,7 +742,7 @@ void m1_pd_bmc_run(void) irq_set_enabled(cxt->hw->uart_irq, false); } - tud_task(); + upstream_ops->flush(); for_each_cxt(cxt) irq_set_enabled(cxt->hw->uart_irq, true); |