1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
//! The Threads module. //! //! **NOTE** This module documentation should be viewed as a continuation of //! [the `drone_core` documentation](drone_core::thr). //! //! # Vector Table //! //! ``` //! # #![feature(const_fn_fn_ptr_basics)] //! # #![feature(marker_trait_attr)] //! # fn main() {} //! use drone_cortexm::{map::thr::*, thr}; //! //! thr! { //! // See the `drone_core` documentation of `thr!` macro for details. //! thread => pub Thr {}; //! //! // See the `drone_core` documentation of `thr!` macro for details. //! local => pub ThrLocal {}; //! //! /// The vector table type. //! vtable => pub Vtable; //! //! /// Thread tokens. //! index => pub Thrs; //! //! /// Threads initialization token. //! init => pub ThrsInit; //! //! // Threads configuration. //! threads => { //! // Threads for exceptions. //! exceptions => { //! // Define a regular thread for the NMI exception. This creates a thread token //! // structure `Nmi`, a field `nmi` in the `Thrs` structure, and an element in the //! // array of `Thr`. //! /// Non maskable interrupt. //! pub nmi; //! /// All classes of fault. //! pub hard_fault; //! // Define a naked handler for the SV_CALL exception. This inserts the function //! // `sv_call_handler` directly to the vector table. //! /// System service call. //! pub naked(sv_call_handler) sv_call; //! /// System tick timer. //! pub sys_tick; //! }; //! // Threads for interrupts. //! interrupts => { //! // Define a regular thread for the interrupt #5 with name `rcc`. //! /// RCC global interrupt. //! 5: pub rcc; //! // Define an outer thread for the interrupt #18 with name `adc1`. This creates a //! // thread token structure `Adc1`, a field `adc1` in the `Thrs` structure, and an //! // element in the array of `Thr`. But unlike a regular thread, this outer thread //! // uses a custom handler `adc1_handler`. //! /// ADC1 global interrupt. //! 18: pub outer(adc1_handler) adc1; //! }; //! }; //! } //! //! // The reset handler should always be provided externally. //! unsafe extern "C" fn reset() -> ! { //! loop {} //! } //! //! // Define external handlers for the exceptions defined using `fn` or //! // `extern` keyword. //! unsafe extern "C" fn sv_call_handler() {} //! unsafe extern "C" fn adc1_handler() {} //! //! // Define and export the actual vector table with all handlers attached. //! #[no_mangle] //! pub static VTABLE: Vtable = Vtable::new(reset); //! ``` //! //! The list of all available non-interrupt exceptions: //! //! * `nmi` - Non maskable interrupt. //! * `hard_fault` - All classes of fault. //! * `mem_manage` - Memory management. //! * `bus_fault` - Pre-fetch fault, memory access fault. //! * `usage_fault` - Undefined instruction or illegal state. //! * `secure_fault` - Security check violation. (Available when //! `security-extension` feature is enabled) //! * `sv_call` - System service call via SWI instruction. //! * `debug` - Monitor. //! * `pend_sv` - Pendable request for system service. //! * `sys_tick` - System tick timer. //! ``` pub mod prelude; mod exec; mod init; mod nvic; mod root; mod wake; #[doc(no_inline)] pub use drone_core::thr::*; pub use self::{ exec::{ExecOutput, ThrExec}, init::{init, init_extended, ThrInitExtended, ThrsInitToken}, nvic::{NvicBlock, NvicIabr, NvicIcer, NvicIcpr, NvicIser, NvicIspr, ThrNvic}, root::{FutureRootExt, StreamRootExt, StreamRootWait}, }; use crate::sv::Supervisor; use drone_core::{thr::ThrToken, token::Token}; /// An interrupt token. pub trait IntToken: ThrToken { /// NVIC block the interrupt belongs to. type NvicBlock: NvicBlock; /// The number of the interrupt. const INT_NUM: usize; } /// A set of thread tokens. /// /// # Safety /// /// Must contain only thread tokens. pub unsafe trait ThrTokens: Token {} /// A trait to assign a supervisor to threads. pub trait ThrSv: ThrToken { /// The supervisor. type Sv: Supervisor; }