Skip to content
Snippets Groups Projects
Select Git revision
  • e107b53f576e49eae98c0b3c65d74115325fde2c
  • master default protected
  • stacked_borrows
  • generics_and_traits
  • crane_lift
  • spans
  • rust_syntax
  • type_check
  • expression
  • fallible
10 results

main.rs

Blame
  • Forked from Per Lindgren / D7050E_2020
    Source project has a limited visibility.
    1-yield.rs 989 B
    //! Yielding from a task
    //!
    //! Expected output:
    //!
    //! ```
    //! B: yield
    //! A: yield
    //! B: yield
    //! A: yield
    //! DONE
    //! ```
    
    #![deny(unsafe_code)]
    // #![deny(warnings)]
    #![no_main]
    #![no_std]
    
    use async_cortex_m::task;
    use cortex_m::asm;
    use cortex_m_rt::entry;
    use cortex_m_semihosting::hprintln;
    use nrf52 as _; // memory layout
    use panic_udf as _; // panic handler
    
    #[entry]
    fn main() -> ! {
        // task A
        hprintln!("here").ok();
                
        //loop { continue; }
    
        task::spawn(async {
            loop {
                hprintln!("A: yield").ok();
                // context switch to B
                task::r#yield().await;
            }
        });
    
        // task B
        task::block_on(async {
            loop {
            hprintln!("B1: yield").ok();
    
            // context switch to A
            task::r#yield().await;
    
            hprintln!("B2: yield").ok();
    
            task::r#yield().await;
    
            hprintln!("DONE").ok();
    
            // loop {
            //     asm::bkpt();
            // }
            }
        })
    }