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

Board-based instantiation of chip drivers and interrupt --> driver mapping for Apollo3 + SAM4L #2069

Merged
merged 2 commits into from Nov 4, 2020
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
12 changes: 8 additions & 4 deletions boards/hail/src/io.rs
Expand Up @@ -25,7 +25,10 @@ impl Write for Writer {

impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) {
let uart = unsafe { &mut sam4l::usart::USART0 };
// Here, we create a second instance of the USART0 struct.
// This is okay because we only call this during a panic, and
// we will never actually process the interrupts
let uart = unsafe { sam4l::usart::USART::new_usart0(CHIP.unwrap().pm) };
let regs_manager = &sam4l::usart::USARTRegManager::panic_new(&uart);
if !self.initialized {
self.initialized = true;
Expand All @@ -52,14 +55,15 @@ impl IoWrite for Writer {
#[panic_handler]
pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
// turn off the non panic leds, just in case
let led_green = &sam4l::gpio::PA[14];
let led_green = sam4l::gpio::GPIOPin::new(sam4l::gpio::Pin::PA14);
led_green.enable_output();
led_green.set();
let led_blue = &sam4l::gpio::PA[15];
let led_blue = sam4l::gpio::GPIOPin::new(sam4l::gpio::Pin::PA15);
led_blue.enable_output();
led_blue.set();

let led_red = &mut led::LedLow::new(&mut sam4l::gpio::PA[13]);
let mut red_pin = sam4l::gpio::GPIOPin::new(sam4l::gpio::Pin::PA13);
let led_red = &mut led::LedLow::new(&mut red_pin);
let writer = &mut WRITER;
debug::panic(
&mut [led_red],
Expand Down
266 changes: 144 additions & 122 deletions boards/hail/src/main.rs

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions boards/imix/src/alarm_test.rs
Expand Up @@ -16,19 +16,21 @@ use capsules::test::alarm_edge_cases::TestAlarmEdgeCases;
use kernel::debug;
use kernel::hil::time::Alarm;
use kernel::static_init;
use sam4l::ast::{Ast, AST};
use sam4l::ast::Ast;

pub unsafe fn run_alarm() {
pub unsafe fn run_alarm(ast: &'static Ast) {
debug!("Starting alarm test.");
let test = static_init_alarm_test();
let test = static_init_alarm_test(ast);
test.run();
}

unsafe fn static_init_alarm_test() -> &'static TestAlarmEdgeCases<'static, Ast<'static>> {
unsafe fn static_init_alarm_test(
ast: &'static Ast,
) -> &'static TestAlarmEdgeCases<'static, Ast<'static>> {
let test = static_init!(
TestAlarmEdgeCases<'static, Ast<'static>>,
TestAlarmEdgeCases::new(&AST)
TestAlarmEdgeCases::new(ast)
);
AST.set_alarm_client(test);
ast.set_alarm_client(test);
test
}
44 changes: 30 additions & 14 deletions boards/imix/src/imix_components/adc.rs
Expand Up @@ -20,16 +20,19 @@ use kernel::capabilities;
use kernel::component::Component;
use kernel::create_capability;
use kernel::static_init;
use sam4l::adc::Channel;

pub struct AdcComponent {
board_kernel: &'static kernel::Kernel,
adc: &'static sam4l::adc::Adc,
}

impl AdcComponent {
pub fn new(board_kernel: &'static kernel::Kernel) -> AdcComponent {
AdcComponent {
board_kernel: board_kernel,
}
pub fn new(
board_kernel: &'static kernel::Kernel,
adc: &'static sam4l::adc::Adc,
) -> AdcComponent {
AdcComponent { board_kernel, adc }
}
}

Expand All @@ -40,28 +43,41 @@ impl Component for AdcComponent {
unsafe fn finalize(self, _s: Self::StaticInput) -> Self::Output {
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
let adc_channels = static_init!(
[&'static sam4l::adc::AdcChannel; 6],
[sam4l::adc::AdcChannel; 6],
[
&sam4l::adc::CHANNEL_AD1, // AD0
&sam4l::adc::CHANNEL_AD2, // AD1
&sam4l::adc::CHANNEL_AD3, // AD2
&sam4l::adc::CHANNEL_AD4, // AD3
&sam4l::adc::CHANNEL_AD5, // AD4
&sam4l::adc::CHANNEL_AD6, // AD5
sam4l::adc::AdcChannel::new(Channel::AD1), // AD0
sam4l::adc::AdcChannel::new(Channel::AD2), // AD1
sam4l::adc::AdcChannel::new(Channel::AD3), // AD2
sam4l::adc::AdcChannel::new(Channel::AD4), // AD3
sam4l::adc::AdcChannel::new(Channel::AD5), // AD4
sam4l::adc::AdcChannel::new(Channel::AD6), // AD5
]
);
// Capsule expects references inside array bc it was built assuming model in which
// global structs are used, so this is a bit of a hack to pass it what it wants.
let ref_channels = static_init!(
[&sam4l::adc::AdcChannel; 6],
[
&adc_channels[0],
&adc_channels[1],
&adc_channels[2],
&adc_channels[3],
&adc_channels[4],
&adc_channels[5],
]
);
let adc = static_init!(
adc::AdcDedicated<'static, sam4l::adc::Adc>,
adc::AdcDedicated::new(
&sam4l::adc::ADC0,
&self.adc,
self.board_kernel.create_grant(&grant_cap),
adc_channels,
ref_channels,
&mut adc::ADC_BUFFER1,
&mut adc::ADC_BUFFER2,
&mut adc::ADC_BUFFER3
)
);
sam4l::adc::ADC0.set_client(adc);
self.adc.set_client(adc);

adc
}
Expand Down
14 changes: 8 additions & 6 deletions boards/imix/src/imix_components/usb.rs
Expand Up @@ -22,6 +22,7 @@ use kernel::static_init;

pub struct UsbComponent {
board_kernel: &'static kernel::Kernel,
usbc: &'static sam4l::usbc::Usbc<'static>,
}

type UsbDevice = capsules::usb::usb_user::UsbSyscallDriver<
Expand All @@ -30,10 +31,11 @@ type UsbDevice = capsules::usb::usb_user::UsbSyscallDriver<
>;

impl UsbComponent {
pub fn new(board_kernel: &'static kernel::Kernel) -> UsbComponent {
UsbComponent {
board_kernel: board_kernel,
}
pub fn new(
board_kernel: &'static kernel::Kernel,
usbc: &'static sam4l::usbc::Usbc<'static>,
) -> UsbComponent {
UsbComponent { board_kernel, usbc }
}
}

Expand All @@ -48,11 +50,11 @@ impl Component for UsbComponent {
let usb_client = static_init!(
capsules::usb::usbc_client::Client<'static, sam4l::usbc::Usbc<'static>>,
capsules::usb::usbc_client::Client::new(
&sam4l::usbc::USBC,
&self.usbc,
capsules::usb::usbc_client::MAX_CTRL_PACKET_SIZE_SAM4L
)
);
sam4l::usbc::USBC.set_client(usb_client);
self.usbc.set_client(usb_client);

// Configure the USB userspace driver
let usb_driver = static_init!(
Expand Down
8 changes: 6 additions & 2 deletions boards/imix/src/io.rs
Expand Up @@ -25,7 +25,10 @@ impl Write for Writer {

impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) {
let uart = unsafe { &mut sam4l::usart::USART3 };
// Here, we create a second instance of the USART3 struct.
// This is okay because we only call this during a panic, and
// we will never actually process the interrupts
let uart = unsafe { sam4l::usart::USART::new_usart3(CHIP.unwrap().pm) };
let regs_manager = &sam4l::usart::USARTRegManager::panic_new(&uart);
if !self.initialized {
self.initialized = true;
Expand All @@ -51,7 +54,8 @@ impl IoWrite for Writer {
#[no_mangle]
#[panic_handler]
pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
let led = &mut led::LedLow::new(&mut sam4l::gpio::PC[22]);
let mut led_pin = sam4l::gpio::GPIOPin::new(sam4l::gpio::Pin::PC22);
let led = &mut led::LedLow::new(&mut led_pin);
let writer = &mut WRITER;
debug::panic(
&mut [led],
Expand Down