File tree Expand file tree Collapse file tree 5 files changed +54
-1
lines changed Expand file tree Collapse file tree 5 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 38
38
run : cargo check --target riscv64imac-unknown-none-elf
39
39
- name : Run CI script for riscv64gc-unknown-none-elf under ${{ matrix.rust }}
40
40
run : cargo check --target riscv64gc-unknown-none-elf
41
+ - name : Run CI script for x86_64-unknown-linux-gnu under ${{ matrix.rust }} with critical-section-single-hart
42
+ run : cargo check --target x86_64-unknown-linux-gnu --features critical-section-single-hart
43
+ - name : Run CI script for riscv32imac-unknown-none-elf under ${{ matrix.rust }} with critical-section-single-hart
44
+ run : cargo check --target riscv32imac-unknown-none-elf --features critical-section-single-hart
45
+ - name : Run CI script for riscv64imac-unknown-none-elf under ${{ matrix.rust }} with critical-section-single-hart
46
+ run : cargo check --target riscv64imac-unknown-none-elf --features critical-section-single-hart
47
+ - name : Run CI script for riscv64gc-unknown-none-elf under ${{ matrix.rust }} with critical-section-single-hart
48
+ run : cargo check --target riscv64gc-unknown-none-elf --features critical-section-single-hart
41
49
42
50
# On macOS and Windows, we at least make sure that the crate builds and links.
43
51
build-other :
56
64
toolchain : stable
57
65
override : true
58
66
- name : Build crate for host OS
59
- run : cargo build
67
+ run : cargo build --features critical-section-single-hart
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
8
8
## [ Unreleased]
9
9
10
+ ### Added
11
+
12
+ - Added ` critical-section-single-hart ` feature which provides an implementation for the ` critical_section ` crate for single-hart systems, based on disabling all interrupts.
13
+
10
14
## [ v0.9.0] - 2022-10-06
11
15
12
16
### Fixed
Original file line number Diff line number Diff line change @@ -17,7 +17,11 @@ targets = [
17
17
" riscv64imac-unknown-none-elf" , " riscv64gc-unknown-none-elf" ,
18
18
]
19
19
20
+ [features ]
21
+ critical-section-single-hart = [" critical-section/restore-state-bool" ]
22
+
20
23
[dependencies ]
21
24
bare-metal = " 1.0.0"
22
25
bit_field = " 0.10.0"
26
+ critical-section = " 1.1.0"
23
27
embedded-hal = " 0.2.6"
Original file line number Diff line number Diff line change
1
+ use critical_section:: { set_impl, Impl , RawRestoreState } ;
2
+
3
+ use crate :: interrupt;
4
+ use crate :: register:: mstatus;
5
+
6
+ struct SingleHartCriticalSection ;
7
+ set_impl ! ( SingleHartCriticalSection ) ;
8
+
9
+ unsafe impl Impl for SingleHartCriticalSection {
10
+ unsafe fn acquire ( ) -> RawRestoreState {
11
+ let was_active = mstatus:: read ( ) . mie ( ) ;
12
+ interrupt:: disable ( ) ;
13
+ was_active
14
+ }
15
+
16
+ unsafe fn release ( was_active : RawRestoreState ) {
17
+ // Only re-enable interrupts if they were enabled before the critical section.
18
+ if was_active {
19
+ interrupt:: enable ( )
20
+ }
21
+ }
22
+ }
Original file line number Diff line number Diff line change 12
12
//! - Access to core registers like `mstatus` or `mcause`.
13
13
//! - Interrupt manipulation mechanisms.
14
14
//! - Wrappers around assembly instructions like `WFI`.
15
+ //!
16
+ //! # Optional features
17
+ //!
18
+ //! ## `critical-section-single-hart`
19
+ //!
20
+ //! This feature enables a [`critical-section`](https://github.com/rust-embedded/critical-section)
21
+ //! implementation suitable for single-hart targets, based on disabling interrupts globally.
22
+ //!
23
+ //! It is **unsound** to enable it on multi-hart targets,
24
+ //! and may cause functional problems in systems where some interrupts must be not be disabled
25
+ //! or critical sections are managed as part of an RTOS. In these cases, you should use
26
+ //! a target-specific implementation instead, typically provided by a HAL or RTOS crate.
15
27
16
28
#![ no_std]
17
29
@@ -22,3 +34,6 @@ pub mod register;
22
34
23
35
#[ macro_use]
24
36
mod macros;
37
+
38
+ #[ cfg( all( riscv, feature = "critical-section-single-hart" ) ) ]
39
+ mod critical_section;
You can’t perform that action at this time.
0 commit comments