Skip to content
Snippets Groups Projects
Commit 0151aa9f authored by Ben Stuart's avatar Ben Stuart
Browse files

Fixed up compiling with alloc and custom atomic width build prozess

parent f591718b
No related branches found
No related tags found
No related merge requests found
[package]
name = "os-glue"
version = "0.1.0"
version = "0.0.0"
authors = ["Ben Stuart <mail@bstuart.de>"]
[dependencies]
embedded_types = "0.3.2"
[dependencies.riot-sys]
git = "https://www.bstuart.de/git/bendst/riot-sys.git"
optional = true
[target.'cfg(target_os="riot")'.dependencies]
riot-sys = { git = "https://bstuart.de/git/bendst/riot-sys.git", path = "../riot-sys" }
[features]
default = []
std = []
riot = ["riot-sys"]
riot_samr21-xpro = ["riot-sys/samr21-xpro", "riot"]
samr21-xpro = ["riot-sys/samr21-xpro"]
[dependencies.alloc]
nightly-2018-04-19
#![no_std]
//! Provide obstractions for embedded OS.
#![feature(alloc)]
......@@ -7,23 +5,26 @@
#![feature(used)]
#![feature(const_fn)]
#![feature(box_syntax)]
extern crate alloc;
#![no_std]
extern crate embedded_types;
#[cfg(feature = "riot")]
#[cfg(target_os="none")]
compile_error!(r#"No operating system detected."#);
extern crate embedded_types;
#[cfg(target_os = "riot")]
extern crate riot_sys;
extern crate alloc;
/// Re-export of the underlying bindings.
///
/// Expose constants and bindings.
pub mod raw {
#[cfg(feature = "riot")]
#[cfg(target_os = "riot")]
pub use riot_sys::ffi::*;
}
mod sys;
/// Threading abstraction for different os.
......@@ -32,28 +33,16 @@ mod sys;
/// * RIOT
/// * Every OS supported by rust
///
#[cfg(any(feature = "riot", feature = "std"))]
pub mod thread;
/// Provide syncronizations primitives of the underlying OS.
#[cfg(any(feature = "riot", feature = "std"))]
pub mod sync;
/// Temporal quantification.
#[cfg(any(feature = "std", feature = "riot"))]
pub mod time;
//#[cfg(any(feature = "riot", feature = "std"))]
//pub mod net;
#[macro_use]
mod io;
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
......@@ -82,3 +82,26 @@ impl Write for IoVec {
Ok(amt)
}
}
struct Error;
trait SoSocketAddrs {}
enum SocketAddr {
V4(),
V6(),
}
pub struct UdpSocket(sys::UdpSocket);
impl UdpSocket {
pub fn bind<A: ToSocketAddrs>(addr: A) -> Result<UdpSocket, Error> {
unimplemented!()
}
pub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)> {
unimplemented!()
}
pub fn send_to<A: ToSocketAddrs>(&self, buf: &[u8], addr: A) -> Result<usize> {
unimplemented!()
}
}
#[cfg(all(target_arch = "arm", not(feature = "std"), any(feature = "riot")))]
// Only provide mutex for 'embedded'. In any other case just use the mutexes provided by rust.
#[cfg(target_os="riot")]
mod mutex;
#[cfg(all(not(target_arch = "arm"), feature = "std"))]
pub use sys::*;
#[cfg(all(target_arch = "arm", not(feature = "std"), any(feature = "riot")))]
#[cfg(target_os="riot")]
pub use self::mutex::*;
......@@ -40,7 +40,7 @@ impl<T> Mutex<T> {
/// Create a new unlocked mutex.
pub const fn new(data: T) -> Self {
Mutex {
lock: unsafe {sys::Mutex::new()},
lock: unsafe { sys::Mutex::new() },
data: UnsafeCell::new(data),
}
}
......
#[cfg(all(target_arch = "arm", feature = "riot"))]
mod riot;
#[cfg(all(not(target_arch = "arm"), feature = "std"))]
mod std_x86_64 {
......@@ -48,7 +46,7 @@ mod std_x86_64 {
use self::std::fmt;
#[allow(dead_code)]
pub(crate) fn print(args: fmt::Arguments) {
pub(crate) fn print(args: fmt::Arguments) {
use self::std::io::Write;
use self::std::io;
......@@ -59,20 +57,24 @@ mod std_x86_64 {
}
}
#[cfg(all(target_arch = "arm", feature = "riot"))]
#[cfg(all(not(target_arch = "arm"), feature = "std"))]
pub use self::std_x86_64::*;
#[cfg(all(not(target_arch = "arm"), feature = "std"))]
#[allow(unused_imports)]
pub(crate) use self::std_x86_64::print;
#[cfg(target_os="riot")]
mod riot;
#[cfg(target_os = "riot")]
pub use self::riot::thread::*;
#[cfg(all(target_arch = "arm", feature = "riot"))]
#[cfg(target_os="riot")]
pub use self::riot::mutex::*;
#[cfg(all(target_arch = "arm", feature = "riot"))]
#[cfg(target_os="riot")]
pub use self::riot::time::*;
#[cfg(all(target_arch = "arm", feature = "riot"))]
#[cfg(target_os="riot")]
#[allow(unused_imports)]
pub(crate) use self::riot::io::print;
#[cfg(all(not(target_arch = "arm"), feature = "std"))]
pub use self::std_x86_64::*;
#[cfg(all(not(target_arch = "arm"), feature = "std"))]
#[allow(unused_imports)]
pub(crate) use self::std_x86_64::print;
......@@ -9,6 +9,7 @@ struct SyncWriter(Mutex<Writer>);
static WRITER: SyncWriter = SyncWriter(Mutex::new(Writer));
impl fmt::Write for Writer {
#[inline(always)]
fn write_str(&mut self, s: &str) -> fmt::Result {
unsafe {
ffi::print(s.as_ptr(), s.len());
......
......@@ -3,3 +3,4 @@ pub mod mutex;
pub mod time;
#[allow(dead_code)]
pub mod io;
//pub mod net;
......@@ -15,7 +15,7 @@ impl Mutex {
#[allow(unused)]
pub unsafe fn init(&mut self) {
//ffi::mutex_init(self.0.get())
ffi::mutex_init(self.0.get())
}
pub unsafe fn lock(&self) {
......
use riot_sys::ffi;
struct UdpSocket {
inner: ffi::socket_udp_t,
}
impl UdpSocket {
pub fn new() -> Self {
let mut sock_udp : ffi::sock_udp_t = mem::zeroed();
ffi::socket_udp_create(&mut socket_udp as *mut _);
UdpSocket {
inner
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment