-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The code is just copied from tm4c123x-hal. See-Also: rust-embedded-community/tm4c-hal#9
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! Bit-banding access for peripheral registers | ||
//! | ||
//! The addresses for this are derived from the Cortex-M4 generic guide, but the EFM32-Cortex-M3 | ||
//! guide uses the same addresses. | ||
//! | ||
//! The implementation is copied over from the tm4c123x-hal crate, pending generalization. | ||
//! | ||
//! (The original code is licensed under the same terms and available on | ||
//! <https://github.com/thejpster/tm4c123x-hal>) | ||
use core::ptr::write_volatile; | ||
|
||
/// Sets/Clears a bit at the given address atomically, using the bit-banding | ||
/// feature. We take a const pointer and mutate it, but that's because the | ||
/// svd2rust crate will only give us const pointers. | ||
pub unsafe fn change_bit<T>(address: *const T, bit: u8, value: bool) { | ||
let address = address as u32; | ||
let bit_word = ref_to_bitband(address, bit); | ||
write_volatile(bit_word, if value { 0x01 } else { 0x00 }); | ||
} | ||
|
||
/// Address must be >= 0x2000_0000 and <= 0x2007_FFFC. Bit must be < 32. | ||
fn ref_to_bitband(address: u32, bit: u8) -> *mut u32 { | ||
let prefix = address & 0xF000_0000; | ||
let byte_offset = address & 0x0FFF_FFFF; | ||
let bit_word_offset = (byte_offset * 32) + (bit as u32 * 4); | ||
let bit_word_addr = bit_word_offset + prefix + 0x0200_0000; | ||
bit_word_addr as *mut u32 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ pub mod time_util; | |
pub mod gpio; | ||
pub mod cmu; | ||
pub mod systick; | ||
|
||
mod bitband; |