|
2 | 2 | //!
|
3 | 3 | //! Implements the time driver for Embassy using a `k_timer` in Zephyr.
|
4 | 4 |
|
5 |
| -use core::{cell::{RefCell, UnsafeCell}, mem}; |
| 5 | +use core::{ |
| 6 | + cell::{RefCell, UnsafeCell}, |
| 7 | + mem, |
| 8 | +}; |
6 | 9 |
|
7 | 10 | use embassy_sync::blocking_mutex::{raw::CriticalSectionRawMutex, Mutex};
|
8 | 11 | use embassy_time_driver::Driver;
|
9 | 12 | use embassy_time_queue_utils::Queue;
|
10 | 13 |
|
11 |
| -use crate::raw::{ |
12 |
| - k_timer, |
13 |
| - k_timer_init, |
14 |
| - k_timer_start, |
15 |
| - k_timeout_t, |
16 |
| -}; |
| 14 | +use crate::raw::{k_timeout_t, k_timer, k_timer_init, k_timer_start}; |
17 | 15 | use crate::sys::K_FOREVER;
|
18 | 16 |
|
19 | 17 | embassy_time_driver::time_driver_impl!(static DRIVER: ZephyrTimeDriver = ZephyrTimeDriver {
|
@@ -41,15 +39,21 @@ impl ZTimer {
|
41 | 39 |
|
42 | 40 | // Otherwise, initialize our timer, and handle it.
|
43 | 41 | if !self.initialized {
|
44 |
| - unsafe { k_timer_init(self.item.get(), Some(Self::timer_tick), None); } |
| 42 | + unsafe { |
| 43 | + k_timer_init(self.item.get(), Some(Self::timer_tick), None); |
| 44 | + } |
45 | 45 | self.initialized = true;
|
46 | 46 | }
|
47 | 47 |
|
48 | 48 | // There is a +1 here as the `k_timer_start()` for historical reasons, subtracts one from
|
49 | 49 | // the time, effectively rounding down, whereas we want to wait at least long enough.
|
50 |
| - let delta = k_timeout_t { ticks: (next - now + 1) as i64 }; |
| 50 | + let delta = k_timeout_t { |
| 51 | + ticks: (next - now + 1) as i64, |
| 52 | + }; |
51 | 53 | let period = K_FOREVER;
|
52 |
| - unsafe { k_timer_start(self.item.get(), delta, period); } |
| 54 | + unsafe { |
| 55 | + k_timer_start(self.item.get(), delta, period); |
| 56 | + } |
53 | 57 |
|
54 | 58 | true
|
55 | 59 | }
|
@@ -94,4 +98,4 @@ impl ZephyrTimeDriver {
|
94 | 98 | }
|
95 | 99 |
|
96 | 100 | // SAFETY: The timer access is always coordinated through a critical section.
|
97 |
| -unsafe impl Send for ZTimer { } |
| 101 | +unsafe impl Send for ZTimer {} |
0 commit comments