#![no_std]
#![cfg_attr(not(doc), no_main)]
#![deny(missing_docs)]
use core::ptr::{addr_of, addr_of_mut};
use components::gpio::GpioComponent;
use kernel::capabilities;
use kernel::component::Component;
use kernel::hil::gpio::Configure;
use kernel::platform::{KernelResources, SyscallDriverLookup};
use kernel::scheduler::round_robin::RoundRobinSched;
use kernel::{create_capability, debug, static_init};
pub mod io;
const NUM_PROCS: usize = 4;
static mut PROCESSES: [Option<&'static dyn kernel::process::Process>; NUM_PROCS] =
[None; NUM_PROCS];
static mut CHIP: Option<&'static msp432::chip::Msp432<msp432::chip::Msp432DefaultPeripherals>> =
None;
static mut PROCESS_PRINTER: Option<&'static capsules_system::process_printer::ProcessPrinterText> =
None;
const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
capsules_system::process_policies::PanicFaultPolicy {};
#[no_mangle]
#[link_section = ".stack_buffer"]
pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];
struct MspExp432P401R {
led: &'static capsules_core::led::LedDriver<
'static,
kernel::hil::led::LedHigh<'static, msp432::gpio::IntPin<'static>>,
3,
>,
console: &'static capsules_core::console::Console<'static>,
button: &'static capsules_core::button::Button<'static, msp432::gpio::IntPin<'static>>,
gpio: &'static capsules_core::gpio::GPIO<'static, msp432::gpio::IntPin<'static>>,
alarm: &'static capsules_core::alarm::AlarmDriver<
'static,
capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm<
'static,
msp432::timer::TimerA<'static>,
>,
>,
ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
adc: &'static capsules_core::adc::AdcDedicated<'static, msp432::adc::Adc<'static>>,
wdt: &'static msp432::wdt::Wdt,
scheduler: &'static RoundRobinSched<'static>,
systick: cortexm4::systick::SysTick,
}
impl KernelResources<msp432::chip::Msp432<'static, msp432::chip::Msp432DefaultPeripherals<'static>>>
for MspExp432P401R
{
type SyscallDriverLookup = Self;
type SyscallFilter = ();
type ProcessFault = ();
type Scheduler = RoundRobinSched<'static>;
type SchedulerTimer = cortexm4::systick::SysTick;
type WatchDog = msp432::wdt::Wdt;
type ContextSwitchCallback = ();
fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
self
}
fn syscall_filter(&self) -> &Self::SyscallFilter {
&()
}
fn process_fault(&self) -> &Self::ProcessFault {
&()
}
fn scheduler(&self) -> &Self::Scheduler {
self.scheduler
}
fn scheduler_timer(&self) -> &Self::SchedulerTimer {
&self.systick
}
fn watchdog(&self) -> &Self::WatchDog {
self.wdt
}
fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
&()
}
}
impl SyscallDriverLookup for MspExp432P401R {
fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
where
F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
{
match driver_num {
capsules_core::led::DRIVER_NUM => f(Some(self.led)),
capsules_core::console::DRIVER_NUM => f(Some(self.console)),
capsules_core::button::DRIVER_NUM => f(Some(self.button)),
capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
_ => f(None),
}
}
}
unsafe fn startup_intilialisation() {
msp432::init();
let wdt = msp432::wdt::Wdt::new();
let sysctl = msp432::sysctl::SysCtl::new();
let flctl = msp432::flctl::FlCtl::new();
let pcm = msp432::pcm::Pcm::new();
wdt.disable();
sysctl.enable_all_sram_banks();
pcm.set_high_power();
flctl.set_waitstates(msp432::flctl::WaitStates::_1);
flctl.set_buffering(true);
}
unsafe fn setup_adc_pins(gpio: &msp432::gpio::GpioManager) {
use msp432::gpio::{IntPinNr, PinNr};
gpio.int_pins[IntPinNr::P05_5 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P05_4 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P05_3 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P05_2 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P05_1 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P05_0 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P04_7 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P04_6 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P04_5 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P04_4 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P04_3 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P04_2 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P04_1 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P04_0 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P06_1 as usize].enable_tertiary_function(); gpio.int_pins[IntPinNr::P06_0 as usize].enable_tertiary_function(); gpio.pins[PinNr::P09_1 as usize].enable_tertiary_function(); gpio.pins[PinNr::P09_0 as usize].enable_tertiary_function(); gpio.pins[PinNr::P08_7 as usize].enable_tertiary_function(); gpio.pins[PinNr::P08_6 as usize].enable_tertiary_function(); gpio.pins[PinNr::P08_5 as usize].enable_tertiary_function(); gpio.pins[PinNr::P08_4 as usize].enable_tertiary_function(); }
#[inline(never)]
unsafe fn start() -> (
&'static kernel::Kernel,
MspExp432P401R,
&'static msp432::chip::Msp432<'static, msp432::chip::Msp432DefaultPeripherals<'static>>,
) {
startup_intilialisation();
let peripherals = static_init!(
msp432::chip::Msp432DefaultPeripherals,
msp432::chip::Msp432DefaultPeripherals::new()
);
peripherals.init();
peripherals.gpio.pins[msp432::gpio::PinNr::PJ_2 as usize].enable_primary_function();
peripherals.gpio.pins[msp432::gpio::PinNr::PJ_3 as usize].enable_primary_function();
peripherals.gpio.pins[msp432::gpio::PinNr::PJ_0 as usize].enable_primary_function();
peripherals.gpio.pins[msp432::gpio::PinNr::PJ_1 as usize].enable_primary_function();
peripherals.cs.setup_clocks();
let dbg_gpio0 = &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P01_0 as usize];
let dbg_gpio1 = &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P03_5 as usize];
let dbg_gpio2 = &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P03_7 as usize];
dbg_gpio0.make_output();
dbg_gpio1.make_output();
dbg_gpio2.make_output();
debug::assign_gpios(
Some(dbg_gpio0), Some(dbg_gpio1),
Some(dbg_gpio2),
);
peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P01_2 as usize].enable_primary_function();
peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P01_3 as usize].enable_primary_function();
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));
let chip = static_init!(
msp432::chip::Msp432<msp432::chip::Msp432DefaultPeripherals>,
msp432::chip::Msp432::new(peripherals)
);
CHIP = Some(chip);
let button = components::button::ButtonComponent::new(
board_kernel,
capsules_core::button::DRIVER_NUM,
components::button_component_helper!(
msp432::gpio::IntPin,
(
&peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P01_1 as usize],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
),
(
&peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P01_4 as usize],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
)
),
)
.finalize(components::button_component_static!(msp432::gpio::IntPin));
let leds = components::led::LedsComponent::new().finalize(components::led_component_static!(
kernel::hil::led::LedHigh<'static, msp432::gpio::IntPin>,
kernel::hil::led::LedHigh::new(
&peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P02_0 as usize]
),
kernel::hil::led::LedHigh::new(
&peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P02_1 as usize]
),
kernel::hil::led::LedHigh::new(
&peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P02_2 as usize]
),
));
let gpio = GpioComponent::new(
board_kernel,
capsules_core::gpio::DRIVER_NUM,
components::gpio_component_helper!(
msp432::gpio::IntPin<'static>,
1 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P03_2 as usize],
2 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P03_3 as usize],
5 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P01_5 as usize],
7 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P06_5 as usize],
8 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P06_4 as usize],
17 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P02_7 as usize],
18 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P02_6 as usize],
19 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P02_4 as usize],
20 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P05_6 as usize],
21 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P06_6 as usize],
22 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P06_7 as usize],
23 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P02_3 as usize],
27 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P02_5 as usize],
28 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P03_0 as usize],
29 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P05_7 as usize],
30 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P01_6 as usize],
31 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P01_7 as usize],
34 => &peripherals.gpio.int_pins[msp432::gpio::IntPinNr::P03_6 as usize]
),
)
.finalize(components::gpio_component_static!(
msp432::gpio::IntPin<'static>
));
let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
let process_management_capability =
create_capability!(capabilities::ProcessManagementCapability);
let uart_mux = components::console::UartMuxComponent::new(&peripherals.uart0, 115200)
.finalize(components::uart_mux_component_static!());
let console = components::console::ConsoleComponent::new(
board_kernel,
capsules_core::console::DRIVER_NUM,
uart_mux,
)
.finalize(components::console_component_static!());
components::debug_writer::DebugWriterComponent::new(uart_mux)
.finalize(components::debug_writer_component_static!());
let timer0 = &peripherals.timer_a0;
let mux_alarm = components::alarm::AlarmMuxComponent::new(timer0).finalize(
components::alarm_mux_component_static!(msp432::timer::TimerA),
);
let alarm = components::alarm::AlarmDriverComponent::new(
board_kernel,
capsules_core::alarm::DRIVER_NUM,
mux_alarm,
)
.finalize(components::alarm_component_static!(msp432::timer::TimerA));
setup_adc_pins(&peripherals.gpio);
let adc_channels = static_init!(
[msp432::adc::Channel; 24],
[
msp432::adc::Channel::Channel0, msp432::adc::Channel::Channel1, msp432::adc::Channel::Channel2, msp432::adc::Channel::Channel3, msp432::adc::Channel::Channel4, msp432::adc::Channel::Channel5, msp432::adc::Channel::Channel6, msp432::adc::Channel::Channel7, msp432::adc::Channel::Channel8, msp432::adc::Channel::Channel9, msp432::adc::Channel::Channel10, msp432::adc::Channel::Channel11, msp432::adc::Channel::Channel12, msp432::adc::Channel::Channel13, msp432::adc::Channel::Channel14, msp432::adc::Channel::Channel15, msp432::adc::Channel::Channel16, msp432::adc::Channel::Channel17, msp432::adc::Channel::Channel18, msp432::adc::Channel::Channel19, msp432::adc::Channel::Channel20, msp432::adc::Channel::Channel21, msp432::adc::Channel::Channel22, msp432::adc::Channel::Channel23, ]
);
let adc = components::adc::AdcDedicatedComponent::new(
&peripherals.adc,
adc_channels,
board_kernel,
capsules_core::adc::DRIVER_NUM,
)
.finalize(components::adc_dedicated_component_static!(
msp432::adc::Adc
));
peripherals
.adc_ref
.select_ref_voltage(msp432::ref_module::ReferenceVoltage::Volt2_5);
peripherals.adc_ref.enable_temp_sensor(true);
let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
.finalize(components::round_robin_component_static!(NUM_PROCS));
let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
.finalize(components::process_printer_text_component_static!());
PROCESS_PRINTER = Some(process_printer);
let msp_exp432p4014 = MspExp432P401R {
led: leds,
console,
button,
gpio,
alarm,
ipc: kernel::ipc::IPC::new(
board_kernel,
kernel::ipc::DRIVER_NUM,
&memory_allocation_capability,
),
adc,
scheduler,
systick: cortexm4::systick::SysTick::new_with_calibration(48_000_000),
wdt: &peripherals.wdt,
};
debug!("Initialization complete. Entering main loop");
extern "C" {
static _sapps: u8;
static _eapps: u8;
static mut _sappmem: u8;
static _eappmem: u8;
}
kernel::process::load_processes(
board_kernel,
chip,
core::slice::from_raw_parts(
core::ptr::addr_of!(_sapps),
core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
),
core::slice::from_raw_parts_mut(
core::ptr::addr_of_mut!(_sappmem),
core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
),
&mut *addr_of_mut!(PROCESSES),
&FAULT_RESPONSE,
&process_management_capability,
)
.unwrap();
(board_kernel, msp_exp432p4014, chip)
}
#[no_mangle]
pub unsafe fn main() {
let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
let (board_kernel, board, chip) = start();
board_kernel.kernel_loop(&board, chip, Some(&board.ipc), &main_loop_capability);
}