__task void serial_process() { UART_Configuration config; int32_t len_data = 0; void *msg; while (1) { // Check our mailbox to see if we need to set anything up with the UART // before we do any sending or receiving if (os_mbx_wait(&serial_mailbox, &msg, 0) == OS_R_OK) { switch((SERIAL_MSG)(unsigned)msg) { case SERIAL_INITIALIZE: uart_initialize(); break; case SERIAL_UNINITIALIZE: uart_uninitialize(); break; case SERIAL_RESET: uart_reset(); break; case SERIAL_SET_CONFIGURATION: serial_get_configuration(&config); uart_set_configuration(&config); break; default: break; } } len_data = USBD_CDC_ACM_DataFree(); if (len_data > SIZE_DATA) { len_data = SIZE_DATA; } if (len_data) { len_data = uart_read_data(data, len_data); } if (len_data) { if(USBD_CDC_ACM_DataSend(data , len_data)) { main_blink_cdc_led(MAIN_LED_OFF); } } len_data = uart_write_free(); if (len_data > SIZE_DATA) { len_data = SIZE_DATA; } if (len_data) { len_data = USBD_CDC_ACM_DataRead(data, len_data); } if (len_data) { if (uart_write_data(data, len_data)) { main_blink_cdc_led(MAIN_LED_OFF); } } } }
__task void serial_process() { uint8_t data[SIZE_DATA]; int32_t len_data = 0; while (1) { len_data = USBD_CDC_ACM_DataFree(); if (len_data > SIZE_DATA) len_data = SIZE_DATA; if (len_data) len_data = uart_read_data(data, len_data); if (len_data) { if(USBD_CDC_ACM_DataSend(data , len_data)) main_blink_cdc_led(0); } len_data = uart_write_free(); if (len_data > SIZE_DATA) len_data = SIZE_DATA; if (len_data) len_data = USBD_CDC_ACM_DataRead(data, len_data); if (len_data) { if (uart_write_data(data, len_data)) main_blink_cdc_led(0); } } }
unsigned int uart_print_str(const char *str) { unsigned int length; for (length = 0; str[length] != '\0'; length++); return uart_write_data(str, length); }
void cdc_process_event() { int32_t len_data = 0; uint8_t data[64]; len_data = USBD_CDC_ACM_DataFree(); if (len_data > sizeof(data)) { len_data = sizeof(data); } if (len_data) { len_data = uart_read_data(data, len_data); } if (len_data) { if (USBD_CDC_ACM_DataSend(data , len_data)) { main_blink_cdc_led(MAIN_LED_FLASH); } } len_data = uart_write_free(); if (len_data > sizeof(data)) { len_data = sizeof(data); } if (len_data) { len_data = USBD_CDC_ACM_DataRead(data, len_data); } if (len_data) { if (uart_write_data(data, len_data)) { main_blink_cdc_led(MAIN_LED_FLASH); } } // Always process events main_cdc_send_event(); }