Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor debug.rs to not be implemented as a kernel process #1046

Merged
merged 3 commits into from Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 35 additions & 8 deletions boards/ek-tm4c1294xl/src/main.rs
Expand Up @@ -12,6 +12,7 @@ extern crate cortexm4;
extern crate tm4c129x;

use capsules::virtual_alarm::{MuxAlarm, VirtualMuxAlarm};
use capsules::virtual_uart::{UartDevice, UartMux};
use kernel::hil;
use kernel::hil::Controller;
use kernel::Platform;
Expand Down Expand Up @@ -43,7 +44,7 @@ pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];
/// A structure representing this platform that holds references to all
/// capsules for this platform.
struct EkTm4c1294xl {
console: &'static capsules::console::Console<'static, tm4c129x::uart::UART>,
console: &'static capsules::console::Console<'static, UartDevice<'static>>,
alarm: &'static capsules::alarm::AlarmDriver<
'static,
VirtualMuxAlarm<'static, tm4c129x::gpt::AlarmTimer>,
Expand Down Expand Up @@ -80,19 +81,49 @@ pub unsafe fn reset_handler() {
tm4c129x::sysctl::PSYSCTLM
.setup_system_clock(tm4c129x::sysctl::SystemClockSource::PllPioscAt120MHz);

// Create a shared UART channel for the console and for kernel debug.
let uart_mux = static_init!(
UartMux<'static>,
UartMux::new(&tm4c129x::uart::UART0, &mut capsules::virtual_uart::RX_BUF)
);
hil::uart::UART::set_client(&tm4c129x::uart::UART0, uart_mux);

// Create a UartDevice for the console.
let console_uart = static_init!(UartDevice, UartDevice::new(uart_mux, true));
console_uart.setup();

let console = static_init!(
capsules::console::Console<tm4c129x::uart::UART>,
capsules::console::Console<UartDevice>,
capsules::console::Console::new(
&tm4c129x::uart::UART0,
console_uart,
115200,
&mut capsules::console::WRITE_BUF,
&mut capsules::console::READ_BUF,
kernel::Grant::create()
)
);
hil::uart::UART::set_client(&tm4c129x::uart::UART0, console);
hil::uart::UART::set_client(console_uart, console);
tm4c129x::uart::UART0.specify_pins(&tm4c129x::gpio::PA[0], &tm4c129x::gpio::PA[1]);

// Create virtual device for kernel debug.
let debugger_uart = static_init!(UartDevice, UartDevice::new(uart_mux, false));
debugger_uart.setup();
let debugger = static_init!(
kernel::debug::DebugWriter,
kernel::debug::DebugWriter::new(
debugger_uart,
&mut kernel::debug::OUTPUT_BUF,
&mut kernel::debug::INTERNAL_BUF,
)
);
hil::uart::UART::set_client(debugger_uart, debugger);

let debug_wrapper = static_init!(
kernel::debug::DebugWriterWrapper,
kernel::debug::DebugWriterWrapper::new(debugger)
);
kernel::debug::set_debug_writer_wrapper(debug_wrapper);

// Alarm
let alarm_timer = &tm4c129x::gpt::TIMER0;
let mux_alarm = static_init!(
Expand Down Expand Up @@ -193,10 +224,6 @@ pub unsafe fn reset_handler() {

tm4c1294.console.initialize();

// Attach the kernel debug interface to this console
let kc = static_init!(capsules::console::App, capsules::console::App::default());
kernel::debug::assign_console_driver(Some(tm4c1294.console), kc);

debug!("Initialization complete. Entering main loop...\r");

let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new());
Expand Down
44 changes: 36 additions & 8 deletions boards/hail/src/main.rs
Expand Up @@ -18,6 +18,7 @@ extern crate sam4l;
use capsules::virtual_alarm::{MuxAlarm, VirtualMuxAlarm};
use capsules::virtual_i2c::{I2CDevice, MuxI2C};
use capsules::virtual_spi::{MuxSpiMaster, VirtualSpiMasterDevice};
use capsules::virtual_uart::{UartDevice, UartMux};
use kernel::hil;
use kernel::hil::spi::SpiMaster;
use kernel::hil::Controller;
Expand Down Expand Up @@ -60,7 +61,7 @@ pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];
/// A structure representing this platform that holds references to all
/// capsules for this platform.
struct Hail {
console: &'static capsules::console::Console<'static, sam4l::usart::USART>,
console: &'static capsules::console::Console<'static, UartDevice<'static>>,
gpio: &'static capsules::gpio::GPIO<'static, sam4l::gpio::GPIOPin>,
alarm: &'static capsules::alarm::AlarmDriver<
'static,
Expand Down Expand Up @@ -202,17 +203,28 @@ pub unsafe fn reset_handler() {

// Initialize USART0 for Uart
sam4l::usart::USART0.set_mode(sam4l::usart::UsartMode::Uart);

// Create a shared UART channel for the console and for kernel debug.
let uart_mux = static_init!(
UartMux<'static>,
UartMux::new(&sam4l::usart::USART0, &mut capsules::virtual_uart::RX_BUF)
);
hil::uart::UART::set_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();
let console = static_init!(
capsules::console::Console<sam4l::usart::USART>,
capsules::console::Console<UartDevice>,
capsules::console::Console::new(
&sam4l::usart::USART0,
console_uart,
115200,
&mut capsules::console::WRITE_BUF,
&mut capsules::console::READ_BUF,
kernel::Grant::create()
)
);
hil::uart::UART::set_client(&sam4l::usart::USART0, console);
hil::uart::UART::set_client(console_uart, console);

// Initialize USART3 for Uart
sam4l::usart::USART3.set_mode(sam4l::usart::UsartMode::Uart);
Expand Down Expand Up @@ -472,9 +484,25 @@ pub unsafe fn reset_handler() {
};

hail.console.initialize();
// Attach the kernel debug interface to this console
let kc = static_init!(capsules::console::App, capsules::console::App::default());
kernel::debug::assign_console_driver(Some(hail.console), kc);

// Create virtual device for kernel debug.
let debugger_uart = static_init!(UartDevice, UartDevice::new(uart_mux, false));
debugger_uart.setup();
let debugger = static_init!(
kernel::debug::DebugWriter,
kernel::debug::DebugWriter::new(
debugger_uart,
&mut kernel::debug::OUTPUT_BUF,
&mut kernel::debug::INTERNAL_BUF,
)
);
hil::uart::UART::set_client(debugger_uart, debugger);

let debug_wrapper = static_init!(
kernel::debug::DebugWriterWrapper,
kernel::debug::DebugWriterWrapper::new(debugger)
);
kernel::debug::set_debug_writer_wrapper(debug_wrapper);

// Reset the nRF and setup the UART bus.
hail.nrf51822.reset();
Expand All @@ -483,7 +511,7 @@ pub unsafe fn reset_handler() {
// Uncomment to measure overheads for TakeCell and MapCell:
// test_take_map_cell::test_take_map_cell();

// debug!("Initialization complete. Entering main loop");
debug!("Initialization complete. Entering main loop");

let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new());

Expand Down
41 changes: 29 additions & 12 deletions boards/imix/src/components/console.rs
Expand Up @@ -18,47 +18,64 @@
#![allow(dead_code)] // Components are intended to be conditionally included

use capsules::console;
use capsules::virtual_uart::{UartDevice, UartMux};
use hil;
use kernel;
use kernel::component::Component;
use kernel::Grant;
use sam4l;

pub struct ConsoleComponent {
uart: &'static sam4l::usart::USART,
uart_mux: &'static UartMux<'static>,
baud_rate: u32,
}

impl ConsoleComponent {
pub fn new(uart: &'static sam4l::usart::USART, rate: u32) -> ConsoleComponent {
pub fn new(uart_mux: &'static UartMux, rate: u32) -> ConsoleComponent {
ConsoleComponent {
uart: uart,
uart_mux: uart_mux,
baud_rate: rate,
}
}
}

impl Component for ConsoleComponent {
type Output = &'static console::Console<'static, sam4l::usart::USART>;
type Output = &'static console::Console<'static, UartDevice<'static>>;

unsafe fn finalize(&mut self) -> Self::Output {
sam4l::usart::USART3.set_mode(sam4l::usart::UsartMode::Uart);
// Create virtual device for console.
let console_uart = static_init!(UartDevice, UartDevice::new(self.uart_mux, true));
console_uart.setup();
let console = static_init!(
console::Console<sam4l::usart::USART>,
console::Console<UartDevice>,
console::Console::new(
self.uart,
console_uart,
self.baud_rate,
&mut console::WRITE_BUF,
&mut console::READ_BUF,
Grant::create()
)
);
hil::uart::UART::set_client(self.uart, console);
hil::uart::UART::set_client(console_uart, console);
console.initialize();

// Attach the kernel debug interface to this console
let kc = static_init!(console::App, console::App::default());
kernel::debug::assign_console_driver(Some(console), kc);
// Create virtual device for kernel debug.
let debugger_uart = static_init!(UartDevice, UartDevice::new(self.uart_mux, false));
debugger_uart.setup();
let debugger = static_init!(
kernel::debug::DebugWriter,
kernel::debug::DebugWriter::new(
debugger_uart,
&mut kernel::debug::OUTPUT_BUF,
&mut kernel::debug::INTERNAL_BUF,
)
);
hil::uart::UART::set_client(debugger_uart, debugger);

let debug_wrapper = static_init!(
kernel::debug::DebugWriterWrapper,
kernel::debug::DebugWriterWrapper::new(debugger)
);
kernel::debug::set_debug_writer_wrapper(debug_wrapper);

console
}
Expand Down
13 changes: 11 additions & 2 deletions boards/imix/src/main.rs
Expand Up @@ -23,6 +23,7 @@ use capsules::alarm::AlarmDriver;
use capsules::virtual_alarm::{MuxAlarm, VirtualMuxAlarm};
use capsules::virtual_i2c::MuxI2C;
use capsules::virtual_spi::{MuxSpiMaster, VirtualSpiMasterDevice};
use capsules::virtual_uart::{UartDevice, UartMux};
use kernel::component::Component;
use kernel::hil;
use kernel::hil::radio;
Expand Down Expand Up @@ -94,7 +95,7 @@ static mut PROCESSES: [Option<&'static mut kernel::procs::Process<'static>>; NUM
pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];

struct Imix {
console: &'static capsules::console::Console<'static, sam4l::usart::USART>,
console: &'static capsules::console::Console<'static, UartDevice<'static>>,
gpio: &'static capsules::gpio::GPIO<'static, sam4l::gpio::GPIOPin>,
alarm: &'static AlarmDriver<'static, VirtualMuxAlarm<'static, sam4l::ast::Ast<'static>>>,
temp: &'static capsules::temperature::TemperatureSensor<'static>,
Expand Down Expand Up @@ -254,7 +255,15 @@ pub unsafe fn reset_handler() {
trng: true,
});

let console = ConsoleComponent::new(&sam4l::usart::USART3, 115200).finalize();
// Create a shared UART channel for the console and for kernel debug.
sam4l::usart::USART3.set_mode(sam4l::usart::UsartMode::Uart);
let uart_mux = static_init!(
UartMux<'static>,
UartMux::new(&sam4l::usart::USART3, &mut capsules::virtual_uart::RX_BUF)
);
hil::uart::UART::set_client(&sam4l::usart::USART3, uart_mux);

let console = ConsoleComponent::new(uart_mux, 115200).finalize();

// Allow processes to communicate over BLE through the nRF51822
let nrf_serialization =
Expand Down
44 changes: 37 additions & 7 deletions boards/launchxl/src/main.rs
Expand Up @@ -12,8 +12,10 @@ extern crate cc26xx;
#[macro_use(debug, debug_gpio, static_init)]
extern crate kernel;

use capsules::virtual_uart::{UartDevice, UartMux};
use cc26x2::aon;
use cc26x2::prcm;
use kernel::hil;

#[macro_use]
pub mod io;
Expand All @@ -38,7 +40,7 @@ pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];
pub struct Platform {
gpio: &'static capsules::gpio::GPIO<'static, cc26xx::gpio::GPIOPin>,
led: &'static capsules::led::LED<'static, cc26xx::gpio::GPIOPin>,
console: &'static capsules::console::Console<'static, cc26xx::uart::UART>,
console: &'static capsules::console::Console<'static, UartDevice<'static>>,
button: &'static capsules::button::Button<'static, cc26xx::gpio::GPIOPin>,
alarm: &'static capsules::alarm::AlarmDriver<
'static,
Expand Down Expand Up @@ -125,23 +127,51 @@ pub unsafe fn reset_handler() {
}

// UART

// Create a shared UART channel for the console and for kernel debug.
let uart_mux = static_init!(
UartMux<'static>,
UartMux::new(&cc26xx::uart::UART0, &mut capsules::virtual_uart::RX_BUF)
);
hil::uart::UART::set_client(&cc26xx::uart::UART0, uart_mux);

// Create a UartDevice for the console.
let console_uart = static_init!(UartDevice, UartDevice::new(uart_mux, true));
console_uart.setup();

cc26xx::uart::UART0.initialize_and_set_pins(3, 2);

let console = static_init!(
capsules::console::Console<cc26xx::uart::UART>,
capsules::console::Console<UartDevice>,
capsules::console::Console::new(
&cc26xx::uart::UART0,
console_uart,
115200,
&mut capsules::console::WRITE_BUF,
&mut capsules::console::READ_BUF,
kernel::Grant::create()
)
);
kernel::hil::uart::UART::set_client(&cc26xx::uart::UART0, console);
kernel::hil::uart::UART::set_client(console_uart, console);
console.initialize();

// Attach the kernel debug interface to this console
let kc = static_init!(capsules::console::App, capsules::console::App::default());
kernel::debug::assign_console_driver(Some(console), kc);
// Create virtual device for kernel debug.
let debugger_uart = static_init!(UartDevice, UartDevice::new(uart_mux, false));
debugger_uart.setup();
let debugger = static_init!(
kernel::debug::DebugWriter,
kernel::debug::DebugWriter::new(
debugger_uart,
&mut kernel::debug::OUTPUT_BUF,
&mut kernel::debug::INTERNAL_BUF,
)
);
hil::uart::UART::set_client(debugger_uart, debugger);

let debug_wrapper = static_init!(
kernel::debug::DebugWriterWrapper,
kernel::debug::DebugWriterWrapper::new(debugger)
);
kernel::debug::set_debug_writer_wrapper(debug_wrapper);

// Setup for remaining GPIO pins
let gpio_pins = static_init!(
Expand Down