capsules_core::virtualizers

Module virtual_uart

Source
Expand description

Virtualize a UART bus.

This allows multiple Tock capsules to use the same UART bus. This is likely most useful for printf() like applications where multiple things want to write to the same UART channel.

Clients can choose if they want to receive. Incoming messages will be sent to all clients that have enabled receiving.

MuxUart provides shared access to a single UART bus for multiple users. UartDevice provides access for a single client.

§Usage


// Create a shared UART channel for the console and for kernel debug.
let uart_mux = static_init!(
    MuxUart<'static>,
    MuxUart::new(&sam4l::usart::USART0, &mut capsules_core::virtual_uart::RX_BUF)
);
hil::uart::UART::set_receive_client(&sam4l::usart::USART0, uart_mux);
hil::uart::UART::set_transmit_client(&sam4l::usart::USART0, uart_mux);

// Create a UartDevice for the console.
let console_uart = static_init!(UartDevice, UartDevice::new(uart_mux, true));
console_uart.setup(); // This is important!
let console = static_init!(
    capsules_core::console::Console<'static>,
    capsules_core::console::Console::new(
        console_uart,
        &mut capsules_core::console::WRITE_BUF,
        &mut capsules_core::console::READ_BUF,
        board_kernel.create_grant(&grant_cap)
    )
);
hil::uart::UART::set_transmit_client(console_uart, console);
hil::uart::UART::set_receive_client(console_uart, console);

Structs§

Constants§