Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ae61ef

Browse files
committed
memory lane, first wip
1 parent 4d767fb commit 8ae61ef

File tree

6 files changed

+90
-5
lines changed

6 files changed

+90
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = [
33
"The Real Time For the Masses developers",
44
"Jorge Aparicio <[email protected]>",
5+
"Per Lindgren <[email protected]>",
56
]
67
categories = ["concurrency", "embedded", "no-std"]
78
description = "The Real Time for The Masses (RTFM) meta language"
@@ -11,7 +12,7 @@ keywords = []
1112
license = "MIT OR Apache-2.0"
1213
name = "rtfm-syntax"
1314
repository = "https://github.com/rtfm-rs/rtfm-syntax"
14-
version = "0.4.0"
15+
version = "0.4.1"
1516

1617
[dependencies]
1718
indexmap = "1.0.2"

examples/memory_lane.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//! Full syntax for single core
2+
3+
#[mock::app]
4+
const APP: () = {
5+
struct Resources {
6+
a: u32,
7+
b: u32,
8+
#[init(0)]
9+
c: u32,
10+
#[init(0)]
11+
d: u32,
12+
}
13+
14+
#[init(
15+
resources = [c],
16+
spawn = [foo],
17+
)]
18+
fn init(_: init::Context) -> init::LateResources {
19+
#[cfg(debug_assertions)]
20+
static mut X: u32 = 0;
21+
22+
init::LateResources { a: 0, b: 0 }
23+
}
24+
25+
#[idle(
26+
resources = [&a, d],
27+
spawn = [foo],
28+
)]
29+
fn idle(_: idle::Context) -> ! {
30+
static mut X: u32 = 0;
31+
32+
loop {}
33+
}
34+
35+
#[task(
36+
resources = [b, &c],
37+
spawn = [bar],
38+
log = ,
39+
)]
40+
fn foo(_: foo::Context) {
41+
static mut X: u32 = 0;
42+
43+
*X += 1;
44+
}
45+
46+
#[task(
47+
capacity = 2,
48+
priority = 2,
49+
resources = [d],
50+
spawn = [foo],
51+
)]
52+
fn bar(_: bar::Context, _: u32) {
53+
static mut X: u32 = 0;
54+
55+
*X += 1;
56+
}
57+
};

mock/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![deny(rust_2018_compatibility)]
2-
#![deny(rust_2018_idioms)]
3-
#![deny(warnings)]
2+
//#![deny(rust_2018_idioms)]
3+
//#![deny(warnings)]
44

55
extern crate proc_macro;
66

src/ast.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use core::ops::Deref;
44
use std::collections::BTreeMap;
55

6-
use syn::{Attribute, Expr, Ident, Pat, PatType, Path, Stmt, Type};
6+
use syn::{Attribute, Expr, Ident, Pat, PatType, Path, Stmt, Type, TypeArray};
77

88
use crate::{Core, Map, Set};
99

@@ -244,6 +244,9 @@ pub struct SoftwareTaskArgs {
244244
/// Software tasks that can be scheduled from this context
245245
pub schedule: Set<Ident>,
246246

247+
/// Log
248+
pub log: Vec<LogMsg>,
249+
247250
pub(crate) _extensible: (),
248251
}
249252

@@ -256,11 +259,21 @@ impl Default for SoftwareTaskArgs {
256259
resources: Resources::new(),
257260
spawn: Set::new(),
258261
schedule: Set::new(),
262+
log: Vec::new(),
259263
_extensible: (),
260264
}
261265
}
262266
}
263267

268+
/// Memory Lane
269+
#[derive(Debug)]
270+
pub struct LogMsg {
271+
/// The identifier of the Log message
272+
pub log_ident: Ident,
273+
/// The array type [T; n] of the Log buffer
274+
pub log_type: TypeArray,
275+
}
276+
264277
/// A hardware task
265278
#[derive(Debug)]
266279
pub struct HardwareTask {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![deny(missing_docs)]
44
#![deny(rust_2018_compatibility)]
55
#![deny(rust_2018_idioms)]
6-
#![deny(warnings)]
6+
// #![deny(warnings)]
77

88
#[allow(unused_extern_crates)]
99
extern crate proc_macro;

src/parse.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ fn task_args(
241241
let mut resources = None;
242242
let mut schedule = None;
243243
let mut spawn = None;
244+
let mut log = None;
244245

245246
let content;
246247
parenthesized!(content in input);
@@ -276,6 +277,17 @@ fn task_args(
276277
binds = Some(ident);
277278
}
278279

280+
"log" => {
281+
if log.is_some() {
282+
return Err(parse::Error::new(
283+
ident.span(),
284+
"argument appears more than once",
285+
));
286+
}
287+
288+
log = Some(Vec::new());
289+
}
290+
279291
"capacity" => {
280292
if capacity.is_some() {
281293
return Err(parse::Error::new(
@@ -428,6 +440,7 @@ fn task_args(
428440
let resources = resources.unwrap_or(Resources::new());
429441
let schedule = schedule.unwrap_or(Set::new());
430442
let spawn = spawn.unwrap_or(Set::new());
443+
let log = log.unwrap_or(Vec::new());
431444

432445
Ok(if let Some(binds) = binds {
433446
Either::Left(HardwareTaskArgs {
@@ -447,6 +460,7 @@ fn task_args(
447460
resources,
448461
schedule,
449462
spawn,
463+
log,
450464
_extensible: (),
451465
})
452466
})

0 commit comments

Comments
 (0)