| 1 | //! Application Program Status Register |
| 2 | |
| 3 | /// Application Program Status Register |
| 4 | #[derive (Clone, Copy, Debug)] |
| 5 | pub struct Apsr { |
| 6 | bits: u32, |
| 7 | } |
| 8 | |
| 9 | impl Apsr { |
| 10 | /// Returns the contents of the register as raw bits |
| 11 | #[inline ] |
| 12 | pub fn bits(self) -> u32 { |
| 13 | self.bits |
| 14 | } |
| 15 | |
| 16 | /// DSP overflow and saturation flag |
| 17 | #[inline ] |
| 18 | pub fn q(self) -> bool { |
| 19 | self.bits & (1 << 27) == (1 << 27) |
| 20 | } |
| 21 | |
| 22 | /// Overflow flag |
| 23 | #[inline ] |
| 24 | pub fn v(self) -> bool { |
| 25 | self.bits & (1 << 28) == (1 << 28) |
| 26 | } |
| 27 | |
| 28 | /// Carry or borrow flag |
| 29 | #[inline ] |
| 30 | pub fn c(self) -> bool { |
| 31 | self.bits & (1 << 29) == (1 << 29) |
| 32 | } |
| 33 | |
| 34 | /// Zero flag |
| 35 | #[inline ] |
| 36 | pub fn z(self) -> bool { |
| 37 | self.bits & (1 << 30) == (1 << 30) |
| 38 | } |
| 39 | |
| 40 | /// Negative flag |
| 41 | #[inline ] |
| 42 | pub fn n(self) -> bool { |
| 43 | self.bits & (1 << 31) == (1 << 31) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /// Reads the CPU register |
| 48 | /// |
| 49 | /// **NOTE** This function is available if `cortex-m` is built with the `"inline-asm"` feature. |
| 50 | #[inline ] |
| 51 | pub fn read() -> Apsr { |
| 52 | let bits: u32 = call_asm!(__apsr_r() -> u32); |
| 53 | Apsr { bits } |
| 54 | } |
| 55 | |