Skip to content

Commit 0856d2c

Browse files
author
Jorge Aparicio
committed
fix doctests
1 parent d6f9534 commit 0856d2c

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/ctxt.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! defined.
1111
//!
1212
//! ```
13+
//! # use cortex_m::ctxt::Context;
1314
//! // This must be in a library crate
1415
//! /// Token unique to the TIM7 interrupt handler
1516
//! pub struct Tim7 { _0: () }
@@ -21,6 +22,11 @@
2122
//! `Local`.
2223
//!
2324
//! ```
25+
//! # #![feature(const_fn)]
26+
//! # use std::cell::Cell;
27+
//! # use cortex_m::ctxt::{Context, Local};
28+
//! # struct Tim7;
29+
//! # unsafe impl Context for Tim7 {}
2430
//! // omitted: how to put this handler in the vector table
2531
//! extern "C" fn tim7(ctxt: Tim7) {
2632
//! static STATE: Local<Cell<bool>, Tim7> = Local::new(Cell::new(false));
@@ -42,7 +48,12 @@
4248
//! access context local data. (Given that you got the signatures right)
4349
//!
4450
//! ```
45-
//! static TIM3_DATA: Local<Cell<bool>, Tim3>
51+
//! # #![feature(const_fn)]
52+
//! # use std::cell::Cell;
53+
//! # use cortex_m::ctxt::{Context, Local};
54+
//! # struct Tim3;
55+
//! # struct Tim4;
56+
//! static TIM3_DATA: Local<Cell<bool>, Tim3> = Local::new(Cell::new(false));
4657
//!
4758
//! extern "C" fn tim3(ctxt: Tim3) {
4859
//! let data = TIM3_DATA.borrow(&ctxt);
@@ -52,34 +63,44 @@
5263
//! //let data = TIM3_DATA.borrow(&ctxt);
5364
//! // ^ wouldn't work
5465
//! }
66+
//! # unsafe impl Context for Tim3 {}
67+
//! # fn main() {}
5568
//! ```
5669
//!
5770
//! To have the application use these tokenized function signatures, you can
5871
//! define, in a library, a `Handlers` struct that represents the vector table:
5972
//!
6073
//! ```
74+
//! # struct Tim1;
75+
//! # struct Tim2;
76+
//! # struct Tim3;
77+
//! # struct Tim4;
78+
//! # extern "C" fn default_handler<T>(_: T) {}
6179
//! #[repr(C)]
6280
//! pub struct Handlers {
6381
//! tim1: extern "C" fn(Tim1),
6482
//! tim2: extern "C" fn(Tim2),
6583
//! tim3: extern "C" fn(Tim3),
6684
//! tim4: extern "C" fn(Tim4),
67-
//! ..
85+
//! /* .. */
6886
//! }
6987
//!
7088
//! pub const DEFAULT_HANDLERS: Handlers = Handlers {
7189
//! tim1: default_handler,
7290
//! tim2: default_handler,
7391
//! tim3: default_handler,
7492
//! tim4: default_handler,
75-
//! ..
76-
//! }
93+
//! /* .. */
94+
//! };
7795
//! ```
7896
//!
7997
//! Then have the user use that `struct` to register the interrupt handlers:
8098
//!
8199
//! ```
82-
//! extern "C" fn tim3(ctxt: Tim3) { .. }
100+
//! # struct Tim3;
101+
//! # struct Handlers { tim3: extern "C" fn(Tim3), tim4: extern "C" fn(Tim3) }
102+
//! # const DEFAULT_HANDLERS: Handlers = Handlers { tim3: tim3, tim4: tim3 };
103+
//! extern "C" fn tim3(ctxt: Tim3) { /* .. */ }
83104
//!
84105
//! // override the TIM3 interrupt handler
85106
//! #[no_mangle]

0 commit comments

Comments
 (0)