Skip to content

Commit a3ecf5c

Browse files
authored
Merge pull request #1363 from embassy-rs/embassy-time-released
time: remove embassy-sync dep, release v0.1.1
2 parents 62ecd97 + a762929 commit a3ecf5c

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed

embassy-time/CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## 0.1.1 - 2023-04-13
9+
10+
- Update `embedded-hal-async` to `0.2.0-alpha.1` (uses `async fn` in traits).
11+
- Update `embedded-hal v1` to `1.0.0-alpha.10`. (Note: v0.2 support is kept unchanged).
12+
- Remove dep on `embassy-sync`.
13+
- Fix reentrancy issues in the `std` time driver (#1177)
14+
- Add `Duration::from_hz()`.
15+
- impl `From` conversions to/from `core::time::Duration`.
16+
- Add `#[must_use]` to all futures.
17+
- Add inherent `async fn tick()` to `Ticker`, so you can use it directly without the `Stream` trait.
18+
- Add more tick rates.
19+
- impl `Default` for `Signal`
20+
- Remove unnecessary uses of `atomic-polyfill`
21+
22+
## 0.1.0 - 2022-08-26
23+
24+
- First release

embassy-time/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "embassy-time"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
description = "Instant and Duration for embedded no-std systems, with async timer support"
66
repository = "https://github.com/embassy-rs/embassy"
@@ -156,7 +156,6 @@ embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10", option
156156
embedded-hal-async = { version = "=0.2.0-alpha.1", optional = true}
157157

158158
futures-util = { version = "0.3.17", default-features = false }
159-
embassy-sync = { version = "0.2.0", path = "../embassy-sync" }
160159
atomic-polyfill = "1.0.1"
161160
critical-section = "1.1"
162161
cfg-if = "1.0.0"

embassy-time/src/driver_std.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::time::{Duration as StdDuration, Instant as StdInstant};
55
use std::{mem, ptr, thread};
66

77
use atomic_polyfill::{AtomicU8, Ordering};
8-
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
9-
use embassy_sync::blocking_mutex::Mutex as EmbassyMutex;
8+
use critical_section::Mutex as CsMutex;
109

1110
use crate::driver::{AlarmHandle, Driver};
1211

@@ -40,7 +39,7 @@ struct TimeDriver {
4039
// The STD Driver implementation requires the alarms' mutex to be reentrant, which the STD Mutex isn't
4140
// Fortunately, mutexes based on the `critical-section` crate are reentrant, because the critical sections
4241
// themselves are reentrant
43-
alarms: UninitCell<EmbassyMutex<CriticalSectionRawMutex, RefCell<[AlarmState; ALARM_COUNT]>>>,
42+
alarms: UninitCell<CsMutex<RefCell<[AlarmState; ALARM_COUNT]>>>,
4443
zero_instant: UninitCell<StdInstant>,
4544
signaler: UninitCell<Signaler>,
4645
}
@@ -58,8 +57,7 @@ crate::time_driver_impl!(static DRIVER: TimeDriver = TimeDriver {
5857
impl TimeDriver {
5958
fn init(&self) {
6059
self.once.call_once(|| unsafe {
61-
self.alarms
62-
.write(EmbassyMutex::new(RefCell::new([ALARM_NEW; ALARM_COUNT])));
60+
self.alarms.write(CsMutex::new(RefCell::new([ALARM_NEW; ALARM_COUNT])));
6361
self.zero_instant.write(StdInstant::now());
6462
self.signaler.write(Signaler::new());
6563

@@ -72,7 +70,8 @@ impl TimeDriver {
7270
loop {
7371
let now = DRIVER.now();
7472

75-
let next_alarm = unsafe { DRIVER.alarms.as_ref() }.lock(|alarms| {
73+
let next_alarm = critical_section::with(|cs| {
74+
let alarms = unsafe { DRIVER.alarms.as_ref() }.borrow(cs);
7675
loop {
7776
let pending = alarms
7877
.borrow_mut()
@@ -139,8 +138,8 @@ impl Driver for TimeDriver {
139138

140139
fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) {
141140
self.init();
142-
unsafe { self.alarms.as_ref() }.lock(|alarms| {
143-
let mut alarms = alarms.borrow_mut();
141+
critical_section::with(|cs| {
142+
let mut alarms = unsafe { self.alarms.as_ref() }.borrow_ref_mut(cs);
144143
let alarm = &mut alarms[alarm.id() as usize];
145144
alarm.callback = callback as *const ();
146145
alarm.ctx = ctx;
@@ -149,9 +148,8 @@ impl Driver for TimeDriver {
149148

150149
fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool {
151150
self.init();
152-
unsafe { self.alarms.as_ref() }.lock(|alarms| {
153-
let mut alarms = alarms.borrow_mut();
154-
151+
critical_section::with(|cs| {
152+
let mut alarms = unsafe { self.alarms.as_ref() }.borrow_ref_mut(cs);
155153
let alarm = &mut alarms[alarm.id() as usize];
156154
alarm.timestamp = timestamp;
157155
unsafe { self.signaler.as_ref() }.signal();

embassy-time/src/queue_generic.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use core::cell::RefCell;
22
use core::cmp::{min, Ordering};
33
use core::task::Waker;
44

5-
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
6-
use embassy_sync::blocking_mutex::Mutex;
5+
use critical_section::Mutex;
76
use heapless::Vec;
87

98
use crate::driver::{allocate_alarm, set_alarm, set_alarm_callback, AlarmHandle};
@@ -129,7 +128,7 @@ impl InnerQueue {
129128
}
130129

131130
struct Queue {
132-
inner: Mutex<CriticalSectionRawMutex, RefCell<Option<InnerQueue>>>,
131+
inner: Mutex<RefCell<Option<InnerQueue>>>,
133132
}
134133

135134
impl Queue {
@@ -140,8 +139,8 @@ impl Queue {
140139
}
141140

142141
fn schedule_wake(&'static self, at: Instant, waker: &Waker) {
143-
self.inner.lock(|inner| {
144-
let mut inner = inner.borrow_mut();
142+
critical_section::with(|cs| {
143+
let mut inner = self.inner.borrow_ref_mut(cs);
145144

146145
if inner.is_none() {}
147146

@@ -159,8 +158,7 @@ impl Queue {
159158
}
160159

161160
fn handle_alarm(&self) {
162-
self.inner
163-
.lock(|inner| inner.borrow_mut().as_mut().unwrap().handle_alarm());
161+
critical_section::with(|cs| self.inner.borrow_ref_mut(cs).as_mut().unwrap().handle_alarm())
164162
}
165163

166164
fn handle_alarm_callback(ctx: *mut ()) {

0 commit comments

Comments
 (0)