Skip to content

make 'fn ptr()' APIs to be 'const fn ptr()' #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- New `InterruptNumber` trait is now required on interrupt arguments to the
various NVIC functions, replacing the previous use of `Nr` from bare-metal.
- Associated const `PTR` is introduced to Core Peripherals to
eventually replace the existing `ptr()` API.

## [v0.6.2] - 2020-01-12

Expand Down
160 changes: 101 additions & 59 deletions src/peripheral/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,19 @@ unsafe impl Send for CBP {}
#[cfg(not(armv6m))]
impl CBP {
#[inline(always)]
pub(crate) unsafe fn new() -> Self {
pub(crate) const unsafe fn new() -> Self {
CBP {
_marker: PhantomData,
}
}

/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const self::cbp::RegisterBlock = 0xE000_EF50 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const self::cbp::RegisterBlock {
0xE000_EF50 as *const _
pub const fn ptr() -> *const self::cbp::RegisterBlock {
Self::PTR
}
}

Expand All @@ -250,7 +253,7 @@ impl ops::Deref for CBP {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -262,10 +265,13 @@ pub struct CPUID {
unsafe impl Send for CPUID {}

impl CPUID {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const self::cpuid::RegisterBlock = 0xE000_ED00 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const self::cpuid::RegisterBlock {
0xE000_ED00 as *const _
pub const fn ptr() -> *const self::cpuid::RegisterBlock {
Self::PTR
}
}

Expand All @@ -274,7 +280,7 @@ impl ops::Deref for CPUID {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -286,10 +292,13 @@ pub struct DCB {
unsafe impl Send for DCB {}

impl DCB {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const dcb::RegisterBlock = 0xE000_EDF0 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const dcb::RegisterBlock {
0xE000_EDF0 as *const _
pub const fn ptr() -> *const dcb::RegisterBlock {
Self::PTR
}
}

Expand All @@ -298,7 +307,7 @@ impl ops::Deref for DCB {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*DCB::ptr() }
unsafe { &*DCB::PTR }
}
}

Expand All @@ -310,10 +319,13 @@ pub struct DWT {
unsafe impl Send for DWT {}

impl DWT {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const dwt::RegisterBlock = 0xE000_1000 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const dwt::RegisterBlock {
0xE000_1000 as *const _
pub const fn ptr() -> *const dwt::RegisterBlock {
Self::PTR
}
}

Expand All @@ -322,7 +334,7 @@ impl ops::Deref for DWT {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -335,10 +347,13 @@ unsafe impl Send for FPB {}

#[cfg(not(armv6m))]
impl FPB {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const fpb::RegisterBlock = 0xE000_2000 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const fpb::RegisterBlock {
0xE000_2000 as *const _
pub const fn ptr() -> *const fpb::RegisterBlock {
Self::PTR
}
}

Expand All @@ -348,7 +363,7 @@ impl ops::Deref for FPB {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -361,10 +376,13 @@ unsafe impl Send for FPU {}

#[cfg(any(has_fpu, target_arch = "x86_64"))]
impl FPU {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const fpu::RegisterBlock = 0xE000_EF30 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const fpu::RegisterBlock {
0xE000_EF30 as *const _
pub const fn ptr() -> *const fpu::RegisterBlock {
Self::PTR
}
}

Expand All @@ -374,7 +392,7 @@ impl ops::Deref for FPU {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -391,10 +409,13 @@ pub struct ICB {
unsafe impl Send for ICB {}

impl ICB {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *mut icb::RegisterBlock = 0xE000_E004 as *mut _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *mut icb::RegisterBlock {
0xE000_E004 as *mut _
pub const fn ptr() -> *mut icb::RegisterBlock {
Self::PTR
}
}

Expand All @@ -403,14 +424,14 @@ impl ops::Deref for ICB {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

impl ops::DerefMut for ICB {
#[inline(always)]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *Self::ptr() }
unsafe { &mut *Self::PTR }
}
}

Expand All @@ -423,10 +444,13 @@ unsafe impl Send for ITM {}

#[cfg(all(not(armv6m), not(armv8m_base)))]
impl ITM {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *mut itm::RegisterBlock = 0xE000_0000 as *mut _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *mut itm::RegisterBlock {
0xE000_0000 as *mut _
pub const fn ptr() -> *mut itm::RegisterBlock {
Self::PTR
}
}

Expand All @@ -436,15 +460,15 @@ impl ops::Deref for ITM {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

#[cfg(all(not(armv6m), not(armv8m_base)))]
impl ops::DerefMut for ITM {
#[inline(always)]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *Self::ptr() }
unsafe { &mut *Self::PTR }
}
}

Expand All @@ -456,10 +480,13 @@ pub struct MPU {
unsafe impl Send for MPU {}

impl MPU {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const mpu::RegisterBlock = 0xE000_ED90 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const mpu::RegisterBlock {
0xE000_ED90 as *const _
pub const fn ptr() -> *const mpu::RegisterBlock {
Self::PTR
}
}

Expand All @@ -468,7 +495,7 @@ impl ops::Deref for MPU {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -480,10 +507,13 @@ pub struct NVIC {
unsafe impl Send for NVIC {}

impl NVIC {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const nvic::RegisterBlock = 0xE000_E100 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const nvic::RegisterBlock {
0xE000_E100 as *const _
pub const fn ptr() -> *const nvic::RegisterBlock {
Self::PTR
}
}

Expand All @@ -492,7 +522,7 @@ impl ops::Deref for NVIC {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -505,10 +535,13 @@ unsafe impl Send for SAU {}

#[cfg(armv8m)]
impl SAU {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const sau::RegisterBlock = 0xE000_EDD0 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const sau::RegisterBlock {
0xE000_EDD0 as *const _
pub const fn ptr() -> *const sau::RegisterBlock {
Self::PTR
}
}

Expand All @@ -518,7 +551,7 @@ impl ops::Deref for SAU {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -530,10 +563,13 @@ pub struct SCB {
unsafe impl Send for SCB {}

impl SCB {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const scb::RegisterBlock = 0xE000_ED04 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const scb::RegisterBlock {
0xE000_ED04 as *const _
pub const fn ptr() -> *const scb::RegisterBlock {
Self::PTR
}
}

Expand All @@ -542,7 +578,7 @@ impl ops::Deref for SCB {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -554,10 +590,13 @@ pub struct SYST {
unsafe impl Send for SYST {}

impl SYST {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const syst::RegisterBlock = 0xE000_E010 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const syst::RegisterBlock {
0xE000_E010 as *const _
pub const fn ptr() -> *const syst::RegisterBlock {
Self::PTR
}
}

Expand All @@ -566,7 +605,7 @@ impl ops::Deref for SYST {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}

Expand All @@ -579,10 +618,13 @@ unsafe impl Send for TPIU {}

#[cfg(not(armv6m))]
impl TPIU {
/// Returns a pointer to the register block
/// Pointer to the register block
pub const PTR: *const tpiu::RegisterBlock = 0xE004_0000 as *const _;

/// Returns a pointer to the register block (to be deprecated in 0.7)
#[inline(always)]
pub fn ptr() -> *const tpiu::RegisterBlock {
0xE004_0000 as *const _
pub const fn ptr() -> *const tpiu::RegisterBlock {
Self::PTR
}
}

Expand All @@ -592,6 +634,6 @@ impl ops::Deref for TPIU {

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::ptr() }
unsafe { &*Self::PTR }
}
}