|
10 | 10 | //! defined.
|
11 | 11 | //!
|
12 | 12 | //! ```
|
| 13 | +//! # use cortex_m::ctxt::Context; |
13 | 14 | //! // This must be in a library crate
|
14 | 15 | //! /// Token unique to the TIM7 interrupt handler
|
15 | 16 | //! pub struct Tim7 { _0: () }
|
|
21 | 22 | //! `Local`.
|
22 | 23 | //!
|
23 | 24 | //! ```
|
| 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 {} |
24 | 30 | //! // omitted: how to put this handler in the vector table
|
25 | 31 | //! extern "C" fn tim7(ctxt: Tim7) {
|
26 | 32 | //! static STATE: Local<Cell<bool>, Tim7> = Local::new(Cell::new(false));
|
|
42 | 48 | //! access context local data. (Given that you got the signatures right)
|
43 | 49 | //!
|
44 | 50 | //! ```
|
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)); |
46 | 57 | //!
|
47 | 58 | //! extern "C" fn tim3(ctxt: Tim3) {
|
48 | 59 | //! let data = TIM3_DATA.borrow(&ctxt);
|
|
52 | 63 | //! //let data = TIM3_DATA.borrow(&ctxt);
|
53 | 64 | //! // ^ wouldn't work
|
54 | 65 | //! }
|
| 66 | +//! # unsafe impl Context for Tim3 {} |
| 67 | +//! # fn main() {} |
55 | 68 | //! ```
|
56 | 69 | //!
|
57 | 70 | //! To have the application use these tokenized function signatures, you can
|
58 | 71 | //! define, in a library, a `Handlers` struct that represents the vector table:
|
59 | 72 | //!
|
60 | 73 | //! ```
|
| 74 | +//! # struct Tim1; |
| 75 | +//! # struct Tim2; |
| 76 | +//! # struct Tim3; |
| 77 | +//! # struct Tim4; |
| 78 | +//! # extern "C" fn default_handler<T>(_: T) {} |
61 | 79 | //! #[repr(C)]
|
62 | 80 | //! pub struct Handlers {
|
63 | 81 | //! tim1: extern "C" fn(Tim1),
|
64 | 82 | //! tim2: extern "C" fn(Tim2),
|
65 | 83 | //! tim3: extern "C" fn(Tim3),
|
66 | 84 | //! tim4: extern "C" fn(Tim4),
|
67 |
| -//! .. |
| 85 | +//! /* .. */ |
68 | 86 | //! }
|
69 | 87 | //!
|
70 | 88 | //! pub const DEFAULT_HANDLERS: Handlers = Handlers {
|
71 | 89 | //! tim1: default_handler,
|
72 | 90 | //! tim2: default_handler,
|
73 | 91 | //! tim3: default_handler,
|
74 | 92 | //! tim4: default_handler,
|
75 |
| -//! .. |
76 |
| -//! } |
| 93 | +//! /* .. */ |
| 94 | +//! }; |
77 | 95 | //! ```
|
78 | 96 | //!
|
79 | 97 | //! Then have the user use that `struct` to register the interrupt handlers:
|
80 | 98 | //!
|
81 | 99 | //! ```
|
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) { /* .. */ } |
83 | 104 | //!
|
84 | 105 | //! // override the TIM3 interrupt handler
|
85 | 106 | //! #[no_mangle]
|
|
0 commit comments