@@ -16,63 +16,6 @@ use syn::{
1616 ItemStatic , ReturnType , Stmt , Type , Visibility ,
1717} ;
1818
19- /// Attribute to declare the entry point of the program
20- ///
21- /// **IMPORTANT**: This attribute must appear exactly *once* in the dependency graph. Also, if you
22- /// are using Rust 1.30 the attribute must be used on a reachable item (i.e. there must be no
23- /// private modules between the item and the root of the crate); if the item is in the root of the
24- /// crate you'll be fine. This reachability restriction doesn't apply to Rust 1.31 and newer releases.
25- ///
26- /// The specified function will be called by the reset handler *after* RAM has been initialized. In
27- /// the case of the `thumbv7em-none-eabihf` target the FPU will also be enabled before the function
28- /// is called.
29- ///
30- /// The type of the specified function must be `[unsafe] fn() -> !` (never ending function)
31- ///
32- /// # Properties
33- ///
34- /// The entry point will be called by the reset handler. The program can't reference to the entry
35- /// point, much less invoke it.
36- ///
37- /// `static mut` variables declared within the entry point are safe to access. The compiler can't
38- /// prove this is safe so the attribute will help by making a transformation to the source code: for
39- /// this reason a variable like `static mut FOO: u32` will become `let FOO: &'static mut u32;`. Note
40- /// that `&'static mut` references have move semantics.
41- ///
42- /// # Examples
43- ///
44- /// - Simple entry point
45- ///
46- /// ``` no_run
47- /// # #![no_main]
48- /// # use cortex_m_rt_macros::entry;
49- /// #[entry]
50- /// fn main() -> ! {
51- /// loop {
52- /// /* .. */
53- /// }
54- /// }
55- /// ```
56- ///
57- /// - `static mut` variables local to the entry point are safe to modify.
58- ///
59- /// ``` no_run
60- /// # #![no_main]
61- /// # use cortex_m_rt_macros::entry;
62- /// #[entry]
63- /// fn main() -> ! {
64- /// static mut FOO: u32 = 0;
65- ///
66- /// let foo: &'static mut u32 = FOO;
67- /// assert_eq!(*foo, 0);
68- /// *foo = 1;
69- /// assert_eq!(*foo, 1);
70- ///
71- /// loop {
72- /// /* .. */
73- /// }
74- /// }
75- /// ```
7619#[ proc_macro_attribute]
7720pub fn entry ( args : TokenStream , input : TokenStream ) -> TokenStream {
7821 let mut f = parse_macro_input ! ( input as ItemFn ) ;
@@ -172,118 +115,6 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
172115 . into ( )
173116}
174117
175- /// Attribute to declare an exception handler
176- ///
177- /// **IMPORTANT**: If you are using Rust 1.30 this attribute must be used on reachable items (i.e.
178- /// there must be no private modules between the item and the root of the crate); if the item is in
179- /// the root of the crate you'll be fine. This reachability restriction doesn't apply to Rust 1.31
180- /// and newer releases.
181- ///
182- /// # Syntax
183- ///
184- /// ```
185- /// # use cortex_m_rt::exception;
186- /// #[exception]
187- /// fn SysTick() {
188- /// // ..
189- /// }
190- ///
191- /// # fn main() {}
192- /// ```
193- ///
194- /// where the name of the function must be one of:
195- ///
196- /// - `DefaultHandler`
197- /// - `NonMaskableInt`
198- /// - `HardFault`
199- /// - `MemoryManagement` (a)
200- /// - `BusFault` (a)
201- /// - `UsageFault` (a)
202- /// - `SecureFault` (b)
203- /// - `SVCall`
204- /// - `DebugMonitor` (a)
205- /// - `PendSV`
206- /// - `SysTick`
207- ///
208- /// (a) Not available on Cortex-M0 variants (`thumbv6m-none-eabi`)
209- ///
210- /// (b) Only available on ARMv8-M
211- ///
212- /// # Usage
213- ///
214- /// `#[exception] fn HardFault(..` sets the hard fault handler. The handler must have signature
215- /// `[unsafe] fn(&ExceptionFrame) -> !`. This handler is not allowed to return as that can cause
216- /// undefined behavior.
217- ///
218- /// `#[exception] fn DefaultHandler(..` sets the *default* handler. All exceptions which have not
219- /// been assigned a handler will be serviced by this handler. This handler must have signature
220- /// `[unsafe] fn(irqn: i16) [-> !]`. `irqn` is the IRQ number (See CMSIS); `irqn` will be a negative
221- /// number when the handler is servicing a core exception; `irqn` will be a positive number when the
222- /// handler is servicing a device specific exception (interrupt).
223- ///
224- /// `#[exception] fn Name(..` overrides the default handler for the exception with the given `Name`.
225- /// These handlers must have signature `[unsafe] fn() [-> !]`. When overriding these other exception
226- /// it's possible to add state to them by declaring `static mut` variables at the beginning of the
227- /// body of the function. These variables will be safe to access from the function body.
228- ///
229- /// # Properties
230- ///
231- /// Exception handlers can only be called by the hardware. Other parts of the program can't refer to
232- /// the exception handlers, much less invoke them as if they were functions.
233- ///
234- /// `static mut` variables declared within an exception handler are safe to access and can be used
235- /// to preserve state across invocations of the handler. The compiler can't prove this is safe so
236- /// the attribute will help by making a transformation to the source code: for this reason a
237- /// variable like `static mut FOO: u32` will become `let FOO: &mut u32;`.
238- ///
239- /// # Examples
240- ///
241- /// - Setting the `HardFault` handler
242- ///
243- /// ```
244- /// # extern crate cortex_m_rt;
245- /// # extern crate cortex_m_rt_macros;
246- /// # use cortex_m_rt_macros::exception;
247- /// #[exception]
248- /// fn HardFault(ef: &cortex_m_rt::ExceptionFrame) -> ! {
249- /// // prints the exception frame as a panic message
250- /// panic!("{:#?}", ef);
251- /// }
252- ///
253- /// # fn main() {}
254- /// ```
255- ///
256- /// - Setting the default handler
257- ///
258- /// ```
259- /// # use cortex_m_rt_macros::exception;
260- /// #[exception]
261- /// fn DefaultHandler(irqn: i16) {
262- /// println!("IRQn = {}", irqn);
263- /// }
264- ///
265- /// # fn main() {}
266- /// ```
267- ///
268- /// - Overriding the `SysTick` handler
269- ///
270- /// ```
271- /// extern crate cortex_m_rt as rt;
272- ///
273- /// use rt::exception;
274- ///
275- /// #[exception]
276- /// fn SysTick() {
277- /// static mut COUNT: i32 = 0;
278- ///
279- /// // `COUNT` is safe to access and has type `&mut i32`
280- /// *COUNT += 1;
281- ///
282- /// println!("{}", COUNT);
283- /// }
284- ///
285- /// # fn main() {}
286- /// ```
287118#[ proc_macro_attribute]
288119pub fn exception ( args : TokenStream , input : TokenStream ) -> TokenStream {
289120 let mut f = parse_macro_input ! ( input as ItemFn ) ;
@@ -521,74 +352,6 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
521352 }
522353}
523354
524- /// Attribute to declare an interrupt (AKA device-specific exception) handler
525- ///
526- /// **IMPORTANT**: If you are using Rust 1.30 this attribute must be used on reachable items (i.e.
527- /// there must be no private modules between the item and the root of the crate); if the item is in
528- /// the root of the crate you'll be fine. This reachability restriction doesn't apply to Rust 1.31
529- /// and newer releases.
530- ///
531- /// **NOTE**: This attribute is exposed by `cortex-m-rt` only when the `device` feature is enabled.
532- /// However, that export is not meant to be used directly -- using it will result in a compilation
533- /// error. You should instead use the device crate (usually generated using `svd2rust`) re-export of
534- /// that attribute. You need to use the re-export to have the compiler check that the interrupt
535- /// exists on the target device.
536- ///
537- /// # Syntax
538- ///
539- /// ``` ignore
540- /// extern crate device;
541- ///
542- /// // the attribute comes from the device crate not from cortex-m-rt
543- /// use device::interrupt;
544- ///
545- /// #[interrupt]
546- /// fn USART1() {
547- /// // ..
548- /// }
549- /// ```
550- ///
551- /// where the name of the function must be one of the device interrupts.
552- ///
553- /// # Usage
554- ///
555- /// `#[interrupt] fn Name(..` overrides the default handler for the interrupt with the given `Name`.
556- /// These handlers must have signature `[unsafe] fn() [-> !]`. It's possible to add state to these
557- /// handlers by declaring `static mut` variables at the beginning of the body of the function. These
558- /// variables will be safe to access from the function body.
559- ///
560- /// If the interrupt handler has not been overridden it will be dispatched by the default exception
561- /// handler (`DefaultHandler`).
562- ///
563- /// # Properties
564- ///
565- /// Interrupts handlers can only be called by the hardware. Other parts of the program can't refer
566- /// to the interrupt handlers, much less invoke them as if they were functions.
567- ///
568- /// `static mut` variables declared within an interrupt handler are safe to access and can be used
569- /// to preserve state across invocations of the handler. The compiler can't prove this is safe so
570- /// the attribute will help by making a transformation to the source code: for this reason a
571- /// variable like `static mut FOO: u32` will become `let FOO: &mut u32;`.
572- ///
573- /// # Examples
574- ///
575- /// - Using state within an interrupt handler
576- ///
577- /// ``` ignore
578- /// extern crate device;
579- ///
580- /// use device::interrupt;
581- ///
582- /// #[interrupt]
583- /// fn TIM2() {
584- /// static mut COUNT: i32 = 0;
585- ///
586- /// // `COUNT` is safe to access and has type `&mut i32`
587- /// *COUNT += 1;
588- ///
589- /// println!("{}", COUNT);
590- /// }
591- /// ```
592355#[ proc_macro_attribute]
593356pub fn interrupt ( args : TokenStream , input : TokenStream ) -> TokenStream {
594357 let mut f: ItemFn = syn:: parse ( input) . expect ( "`#[interrupt]` must be applied to a function" ) ;
@@ -696,30 +459,6 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream {
696459 . into ( )
697460}
698461
699- /// Attribute to mark which function will be called at the beginning of the reset handler.
700- ///
701- /// **IMPORTANT**: This attribute can appear at most *once* in the dependency graph. Also, if you
702- /// are using Rust 1.30 the attribute must be used on a reachable item (i.e. there must be no
703- /// private modules between the item and the root of the crate); if the item is in the root of the
704- /// crate you'll be fine. This reachability restriction doesn't apply to Rust 1.31 and newer
705- /// releases.
706- ///
707- /// The function must have the signature of `unsafe fn()`.
708- ///
709- /// The function passed will be called before static variables are initialized. Any access of static
710- /// variables will result in undefined behavior.
711- ///
712- /// # Examples
713- ///
714- /// ```
715- /// # use cortex_m_rt_macros::pre_init;
716- /// #[pre_init]
717- /// unsafe fn before_main() {
718- /// // do something here
719- /// }
720- ///
721- /// # fn main() {}
722- /// ```
723462#[ proc_macro_attribute]
724463pub fn pre_init ( args : TokenStream , input : TokenStream ) -> TokenStream {
725464 let f = parse_macro_input ! ( input as ItemFn ) ;
0 commit comments