Skip to content

Commit

Permalink
Merge pull request #4 from RusPiRo/mailbox_and_console
Browse files Browse the repository at this point in the history
Mailbox and console
  • Loading branch information
2ndTaleStudio authored Jul 30, 2019
2 parents f1a3ff8 + ddddd32 commit 3f1c94f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 37 deletions.
86 changes: 83 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "ruspiro-kernel"
authors = ["André Borrmann <[email protected]>"]
version = "0.0.3" # remember to update html_root_url
version = "0.1.0" # remember to update html_root_url
description = "This crate showcases the usage of the different RusPiRo crates to build a baremetal kernel for Raspberry Pi 3"
license = "Apache-2.0"
repository = "https://github.com/RusPiRo/ruspiro-kernel/tree/v0.0.3"
documentation = "https://docs.rs/ruspiro-kernel/0.0.3"
repository = "https://github.com/RusPiRo/ruspiro-kernel/tree/v0.1.0"
documentation = "https://docs.rs/ruspiro-kernel/0.1.0"
readme = "README.md"
keywords = ["RusPiRo", "raspberrypi", "baremetal", "kernel", "32bit"]
categories = ["no-std", "embedded"]
Expand All @@ -22,6 +22,6 @@ path = "src/kernel.rs"
[dependencies]
ruspiro-boot = { version = "0.0.3", features = ["with_panic", "with_exception"] }
ruspiro-gpio = "0.0.2"
ruspiro-mailbox = "0.0.2"
ruspiro-uart = "0.0.3"
ruspiro-singleton = "0.0.2"
ruspiro-allocator = "0.0.2"
ruspiro-console = { version = "0.0.2", features = ["with_allocator"] }
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The master branch of this repository always contains the latest version of the R

| Version | Description / Features |
|---------|-------------------------------------|
|[v0.1.0](https://github.com/RusPiRo/ruspiro-kernel/tree/v0.1.0)|This version utilizes further crates:<ul><li>``ruspiro-mailbox``</li><li>``ruspiro-uart``</li><li>``ruspiro-console``</li></ul> This could be seen as a new baseline version as it no longer assumes a fix core rate when initializing the miniUART, but gets the real clock rate using the mailbox property tag interface.|
|[v0.0.3](https://github.com/RusPiRo/ruspiro-kernel/tree/v0.0.3)|Having LED's signaling that the bare metal kernel is running might not be enough, so this version is using the UART to output debug information to a connected terminal console|
|[v0.0.2](https://github.com/RusPiRo/ruspiro-kernel/tree/v0.0.2)|This version demonstrates how to use the GPIO abstraction crate ``ruspiro-gpio`` for easy access to the GPIO Pins of the Raspberry Pi 3. This hides the register dangling away from the implementation and reduces the actual lines of code to implement the same feature as in v0.0.1. There are still 4 LED lit - one for each core - but in the kernel file with less code compared to the previous version.|
|[v0.0.1](https://github.com/RusPiRo/ruspiro-kernel/tree/v0.0.1)|The first kind of feature release introducing the usage of MMIO register access with ``ruspiro-register`` crate. It shows how to access GPIO pins to lit a LED for each core being kicked off on Raspberry Pi.|
Expand Down
49 changes: 20 additions & 29 deletions src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Author: André Borrmann
* License: MIT
**********************************************************************************************************************/
#![doc(html_root_url = "https://docs.rs/ruspiro-kernel/0.0.3")]
#![doc(html_root_url = "https://docs.rs/ruspiro-kernel/0.1.0")]
#![no_std]
#![no_main]

Expand All @@ -27,62 +27,53 @@
//! the following:
//! ```
//! UART ready for use from core 0...
//! hello from core 0
//! hello from core 1
//! hello from core 2
//! hello from core 3
//! ```
//!
#[macro_use]
extern crate ruspiro_boot;
extern crate ruspiro_allocator; // needed due to the uart dependency to the [ruspiro-console] crate.

// use GPIO abstraction
use ruspiro_gpio::GPIO;
// use UART0 (miniUART) abstraction
use ruspiro_uart::Uart0;
// use singleton to encapsulate the Uart0 for cross core safe access
use ruspiro_singleton::Singleton;

static UART: Singleton<Uart0> = Singleton::new(Uart0::new());
// use console to attach the uart0 as the output channel
use ruspiro_console::*;
// use the mailbox interface to get the real core clock rate
use ruspiro_mailbox::{MAILBOX, ArmClockId};

come_alive_with!(being_alive);
run_with!(thinking);

fn being_alive(core: u32) {
// on the first core coming alive we initialize the Uart
if core == 0 {
if UART.take_for(|uart| uart.initialize(250_000_000, 115_200)).is_ok() {
// if uart could be initialized lit the core 0 LED
GPIO.take_for(|gpio| gpio.get_pin(17).unwrap().to_output().high() );
// and also write a test string
print("UART ready for use from core 0...\r\n");
if let Ok(core_rate) = MAILBOX.take_for(|mb| mb.get_clockrate(ArmClockId::Core)) {
let mut uart = Uart0::new();
if uart.initialize(core_rate, 115_200).is_ok() {
CONSOLE.take_for(|console| console.replace(uart));
// if uart and console could be initialized lit the core 0 LED
GPIO.take_for(|gpio| gpio.get_pin(17).unwrap().to_output().high() );
// and also write a test string
println!("UART ready for use from core 0...");
}
}
}
// based on the core coming alive we would lit a different LED to see all 4 are kicked-off
// we do assume that there will be no issue in getting the pin's, so unwrap should never fail ;)
match core {
1 => {
GPIO.take_for(|gpio| gpio.get_pin(18).unwrap().to_output().high() );
print("hello from core 1\r\n")
},
2 => {
GPIO.take_for(|gpio| gpio.get_pin(20).unwrap().to_output().high() );
print("hello from core 2\r\n")
},
3 => {
GPIO.take_for(|gpio| gpio.get_pin(21).unwrap().to_output().high() );
print("hello from core 3\r\n")
},
1 => GPIO.take_for(|gpio| gpio.get_pin(18).unwrap().to_output().high() ),
2 => GPIO.take_for(|gpio| gpio.get_pin(20).unwrap().to_output().high() ),
3 => GPIO.take_for(|gpio| gpio.get_pin(21).unwrap().to_output().high() ),
_ => (), // nothing to do in case there is a core number higher than 3 running - RPi has only 4 cores ;)
}

println!("hello from core {}", core);
}

fn thinking(_: u32) -> ! {
loop { }
}

/// Function to write a text to the Uart.
fn print(s: &'static str) {
// in case the UART could not be successfully initializes this will do nothing...
UART.take_for(|uart| uart.send_string(s));
}

0 comments on commit 3f1c94f

Please sign in to comment.