Exemplo n.º 1
0
__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);
            }
        }
    }
}
Exemplo n.º 2
0
/** \brief  Vitual COM Port retrieve communication settings

    The function retrieves communication settings of the port used as the
    Virtual COM Port.

    \param [in]         line_coding  Pointer to the CDC_LINE_CODING structure.
    \return             0        Function failed.
    \return             1        Function succeeded.
 */
int32_t USBD_CDC_ACM_PortGetLineCoding (CDC_LINE_CODING *line_coding) {
    if (serial_get_configuration (&UART_Config)) {
        line_coding->dwDTERate   = UART_Config.Baudrate;
        line_coding->bDataBits   = UART_Config.DataBits;
        line_coding->bParityType = UART_Config.Parity;
        line_coding->bCharFormat = UART_Config.StopBits;
        return (1);
    }

    return (0);
}