diff options
author | Kévin Redon <kredon@sysmocom.de> | 2019-01-30 11:19:19 +0100 |
---|---|---|
committer | Kévin Redon <kredon@sysmocom.de> | 2019-02-07 15:56:05 +0100 |
commit | 8e5380068c130f96e97df83aeefc102bb1357fc4 (patch) | |
tree | 495821ea0cd5dec9da897af098932b0dab0352e9 | |
parent | 293c8417737625ebf5349052eb81aaf776fdfbf2 (diff) |
echo back UART input
let main run the main loop instead of the CDC ACM example.
also rename the CDC ACM example functions.
Change-Id: I44b15079672b4058de1fa08365541317d54958dc
-rw-r--r-- | sysmoOCTSIM/main.c | 18 | ||||
-rw-r--r-- | sysmoOCTSIM/usb_start.c | 14 | ||||
-rw-r--r-- | sysmoOCTSIM/usb_start.h | 2 |
3 files changed, 17 insertions, 17 deletions
diff --git a/sysmoOCTSIM/main.c b/sysmoOCTSIM/main.c index de954f4..dfe3b03 100644 --- a/sysmoOCTSIM/main.c +++ b/sysmoOCTSIM/main.c @@ -19,19 +19,19 @@ #include "atmel_start.h" #include "atmel_start_pins.h" -volatile static uint32_t data_arrived = 0; +volatile static bool data_arrived = false; static void tx_cb_UART_debug(const struct usart_async_descriptor *const io_descr) { /* Transfer completed */ - gpio_toggle_pin_level(LED_system); + //gpio_toggle_pin_level(LED_system); } static void rx_cb_UART_debug(const struct usart_async_descriptor *const io_descr) { /* Receive completed */ gpio_toggle_pin_level(LED_system); - data_arrived = 1; + data_arrived = true; } int main(void) @@ -42,5 +42,15 @@ int main(void) usart_async_register_callback(&UART_debug, USART_ASYNC_RXC_CB, rx_cb_UART_debug); usart_async_enable(&UART_debug); - cdcd_acm_example(); + usb_start(); + + while (true) { // main loop + if (data_arrived) { // input on UART debug + data_arrived = false; // clear flag + uint8_t recv_char; // to store the input + while (io_read(&UART_debug.io, &recv_char, 1) == 1) { // read input + while (io_write(&UART_debug.io, &recv_char, 1) != 1); // echo back to output + } + } + } } diff --git a/sysmoOCTSIM/usb_start.c b/sysmoOCTSIM/usb_start.c index de86172..d02edc0 100644 --- a/sysmoOCTSIM/usb_start.c +++ b/sysmoOCTSIM/usb_start.c @@ -93,25 +93,15 @@ void cdc_device_acm_init(void) } /** - * Example of using CDC ACM Function. - * \note - * In this example, we will use a PC as a USB host: - * - Connect the DEBUG USB on XPLAINED board to PC for program download. - * - Connect the TARGET USB on XPLAINED board to PC for running program. - * The application will behave as a virtual COM. - * - Open a HyperTerminal or other COM tools in PC side. - * - Send out a character or string and it will echo the content received. + * \brief Start USB stack */ -void cdcd_acm_example(void) +void usb_start(void) { while (!cdcdf_acm_is_enabled()) { // wait cdc acm to be installed }; cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c); - - while (1) { - } } void usb_init(void) diff --git a/sysmoOCTSIM/usb_start.h b/sysmoOCTSIM/usb_start.h index 48b2735..daf30cc 100644 --- a/sysmoOCTSIM/usb_start.h +++ b/sysmoOCTSIM/usb_start.h @@ -15,7 +15,7 @@ extern "C" { #include "cdcdf_acm.h" #include "cdcdf_acm_desc.h" -void cdcd_acm_example(void); +void usb_start(void); void cdc_device_acm_init(void); /** |