Skip to content
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: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
rustup target add ${{ matrix.target }}
- name: Build
run: |
cargo build --target ${{ matrix.target }}
cargo build --target ${{ matrix.target }} --features "serde, defmt"
cargo build --target ${{ matrix.target }} --no-default-features

build-versatileab:
Expand Down
2 changes: 2 additions & 0 deletions cortex-ar/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
maintenance by MVA (specific address).
- Added new `L1Section::set_section_attrs` and `L1Section::section_attrs` method. Also added
low-level `L1Section::new_with_addr_upper_bits_and_attrs` constructor.
- optional `serde` derives behind a `serde` feature gate
- lots of missing `Debug`, `Copy`, `Clone`, `defmt::Format` derives.

### Changed

Expand Down
6 changes: 4 additions & 2 deletions cortex-ar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ version = "0.2.0"

[dependencies]
arbitrary-int = "2"
bitbybit = "1.3.3"
bitbybit = "1.4"
num_enum = { version = "0.7", default-features = false }
critical-section = {version = "1.2.0", features = ["restore-state-u8"], optional = true}
thiserror = { version = "2", default-features = false }
defmt = {version = "1", optional = true}
defmt = { version = "1", optional = true }
serde = { version = "1", features = ["derive"], default-features = false, optional = true }

[build-dependencies]
arm-targets = {version = "0.2.0", path = "../arm-targets"}
Expand All @@ -44,6 +45,7 @@ critical-section-single-core = ["critical-section"]
critical-section-multi-core = ["critical-section"]
# Adds defmt::Format implementation for the register types
defmt = ["dep:defmt", "arbitrary-int/defmt"]
serde = ["dep:serde", "arbitrary-int/serde"]

[package.metadata.docs.rs]
targets = ["armv7r-none-eabihf", "armv7r-none-eabi", "armv7a-none-eabihf"]
10 changes: 9 additions & 1 deletion cortex-ar/src/mmu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use arbitrary_int::{u12, u2, u3, u4};

#[derive(Debug, thiserror::Error)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[error("invalid L1 entry type {0:?}")]
pub struct InvalidL1EntryType(pub L1EntryType);

#[bitbybit::bitenum(u3, exhaustive = true)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, PartialEq, Eq)]
pub enum AccessPermissions {
PermissionFault = 0b000,
Expand Down Expand Up @@ -40,6 +42,7 @@ impl AccessPermissions {

#[bitbybit::bitenum(u2, exhaustive = true)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum L1EntryType {
Expand All @@ -60,6 +63,7 @@ pub enum L1EntryType {
/// of the B, C, and TEX bits.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MemoryRegionAttributesRaw {
/// TEX bits
type_extensions: u3,
Expand All @@ -80,6 +84,7 @@ impl MemoryRegionAttributesRaw {

#[bitbybit::bitenum(u2, exhaustive = true)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug)]
pub enum CacheableMemoryAttribute {
NonCacheable = 0b00,
Expand All @@ -90,6 +95,7 @@ pub enum CacheableMemoryAttribute {

#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MemoryRegionAttributes {
StronglyOrdered,
ShareableDevice,
Expand Down Expand Up @@ -142,6 +148,7 @@ impl MemoryRegionAttributes {
/// Individual section attributes for a L1 section.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SectionAttributes {
/// NG bit
pub non_global: bool,
Expand Down Expand Up @@ -205,7 +212,8 @@ impl SectionAttributes {
///
/// The ARM Cortex-A architecture programmers manual chapter 9.4 (p.163) or the ARMv7-A and ArmV7-R
/// architecture reference manual p.1323 specify these attributes in more detail.
#[bitbybit::bitfield(u32, default = 0x00)]
#[bitbybit::bitfield(u32, default = 0, defmt_fields(feature = "defmt"))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Eq)]
pub struct L1Section {
/// Section base address upper bits.
Expand Down
1 change: 1 addition & 0 deletions cortex-ar/src/pmsav7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub use register::drsr::RegionSize;

/// Ways this API can fail
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
/// Found too many regions
TooManyRegions,
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/actlr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// ACTLR (*Auxiliary Control Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Actlr(pub u32);
impl SysReg for Actlr {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/actlr2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// ACTLR2 (*Auxiliary Control Register 2*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Actlr2(pub u32);
impl SysReg for Actlr2 {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/adfsr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// ADFSR (*Auxiliary Data Fault Status Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Adfsr(pub u32);
impl SysReg for Adfsr {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/aidr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead};

/// AIDR (*Auxiliary ID Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Aidr(pub u32);
impl SysReg for Aidr {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/aifsr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// AIFSR (*Auxiliary Instruction Fault Status Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Aifsr(pub u32);
impl SysReg for Aifsr {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/amair0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// AMAIR0 (*Auxiliary Memory Attribute Indirection Register 0*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Amair0(pub u32);
impl SysReg for Amair0 {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/amair1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// AMAIR1 (*Auxiliary Memory Attribute Indirection Register 1*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Amair1(pub u32);
impl SysReg for Amair1 {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cntfrq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// CNTFRQ (*Counter-timer Frequency Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Cntfrq(pub u32);
impl SysReg for Cntfrq {
const CP: u32 = 15;
Expand Down
3 changes: 2 additions & 1 deletion cortex-ar/src/register/armv8r/cnthctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use arbitrary_int::u4;
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// CNTHCTL (*Hyp Counter-timer Control Register*)
#[bitbybit::bitfield(u32)]
#[bitbybit::bitfield(u32, debug, defmt_bitfields(feature = "defmt"))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Cnthctl {
#[bits(19..=19, rw)]
cntpmask: bool,
Expand Down
9 changes: 5 additions & 4 deletions cortex-ar/src/register/armv8r/cnthp_ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// CNTHP_CTL (*Hyp Physical Counter-timer Control Register (EL2)*)
#[bitbybit::bitfield(u32)]
#[bitbybit::bitfield(u32, debug, defmt_bitfields(feature = "defmt"))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CnthpCtl {
/// The status of the timer interrupt.
#[bits(2..=2, r)]
#[bit(2, r)]
istatus: bool,
/// Timer interrupt mask bit.
///
/// * true: masked
/// * false: not masked
#[bits(1..=1, rw)]
#[bit(1, rw)]
imask: bool,
/// Enables the timer.
#[bits(0..=0, rw)]
#[bit(0, rw)]
enable: bool,
}

Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cnthp_cval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg64, SysRegRead64, SysRegWrite64};

/// CNTHP_CVAL (*Hyp Physical Counter-timer CompareValue Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CnthpCval(pub u64);

impl SysReg64 for CnthpCval {
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cnthp_tval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// CNTHP_TVAL (*Hyp Physical Counter-timer TimerValue Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CnthpTval(pub u32);

impl SysReg for CnthpTval {
Expand Down
3 changes: 2 additions & 1 deletion cortex-ar/src/register/armv8r/cntkctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use arbitrary_int::u4;
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// CNTKCTL (*Counter-timer Kernel Control Register*)
#[bitbybit::bitfield(u32)]
#[bitbybit::bitfield(u32, defmt_bitfields(feature = "defmt"))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Cntkctl {
/// Controls whether the physical timer registers are accessible from EL0
/// modes.
Expand Down
3 changes: 2 additions & 1 deletion cortex-ar/src/register/armv8r/cntp_ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// CNTP_CTL (*Physical Counter-timer Control Register*)
#[bitbybit::bitfield(u32)]
#[bitbybit::bitfield(u32, defmt_bitfields(feature = "defmt"))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CntpCtl {
/// The status of the timer interrupt.
#[bits(2..=2, r)]
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cntp_cval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg64, SysRegRead64, SysRegWrite64};

/// CNTP_CVAL (*Physical Counter-timer CompareValue Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CntpCval(pub u64);

impl SysReg64 for CntpCval {
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cntp_tval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// CNTP_TVAL (*Physical Counter-timer TimerValue Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CntpTval(pub u32);
impl SysReg for CntpTval {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cntpct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg64, SysRegRead64};

/// CNTPCT (*Physical Counter-timer Count Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CntPct(pub u64);

impl SysReg64 for CntPct {
Expand Down
3 changes: 2 additions & 1 deletion cortex-ar/src/register/armv8r/cntv_ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// CNTV_CTL (*Virtual Counter-timer Control Register*)
#[bitbybit::bitfield(u32)]
#[bitbybit::bitfield(u32, defmt_bitfields(feature = "defmt"))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CntvCtl {
/// The status of the timer interrupt.
#[bits(2..=2, r)]
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cntv_cval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg64, SysRegRead64, SysRegWrite64};

/// CNTV_CVAL (*Virtual Counter-timer CompareValue Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CntvCval(pub u64);

impl SysReg64 for CntvCval {
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cntv_tval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// CNTV_TVAL (*Virtual Counter-timer TimerValue Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CntvTval(pub u32);
impl SysReg for CntvTval {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cntvct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg64, SysRegRead64};

/// CNTVCT (*Virtual Counter-timer Count Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CntVct(pub u64);

impl SysReg64 for CntVct {
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/cntvoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg64, SysRegRead64, SysRegWrite64};

/// CNTVOFF (*Virtual Counter-timer Offset Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CntVoff(pub u64);

impl SysReg64 for CntVoff {
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/hacr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// HACR (*Hyp Auxiliary Configuration Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Hacr(pub u32);
impl SysReg for Hacr {
const CP: u32 = 15;
Expand Down
1 change: 1 addition & 0 deletions cortex-ar/src/register/armv8r/hactlr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// HACTRL (*Hyp Auxiliary Control Register*)
#[bitbybit::bitfield(u32)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Hactlr {
/// Controls access to IMP_TESTR1 at EL0 and EL1
#[bits(15..=15, rw)]
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/hactlr2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// HACTLR2 (*Hyp Auxiliary Control Register 2*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Hactlr2(pub u32);
impl SysReg for Hactlr2 {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/hadfsr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// HADFSR (*Hyp Auxiliary Data Fault Status Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Hadfsr(pub u32);
impl SysReg for Hadfsr {
const CP: u32 = 15;
Expand Down
3 changes: 3 additions & 0 deletions cortex-ar/src/register/armv8r/haifsr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use crate::register::{SysReg, SysRegRead, SysRegWrite};

/// HAIFSR (*Hyp Auxiliary Instruction Fault Status Register*)
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Haifsr(pub u32);
impl SysReg for Haifsr {
const CP: u32 = 15;
Expand Down
Loading