diff options
author | Tomas Vanek <vanekt@fbl.cz> | 2021-11-25 06:13:31 +0100 |
---|---|---|
committer | Tomas Vanek <vanekt@fbl.cz> | 2022-02-25 20:26:56 +0000 |
commit | b53f5c257185e5410622ed72790affb1bda88248 (patch) | |
tree | 912ffb08ebcd78dfb5411ddf4a311c7ffbd4913e | |
parent | e4ba76a003ce4a2336eade806a04a278c376d0b6 (diff) | |
download | riscv-openocd-b53f5c257185e5410622ed72790affb1bda88248.zip riscv-openocd-b53f5c257185e5410622ed72790affb1bda88248.tar.gz riscv-openocd-b53f5c257185e5410622ed72790affb1bda88248.tar.bz2 |
target/cortex_m: add Cortex-M part number getter
The getter checks the magic numbers in arch_info to detect eventual
type mismatch.
Change-Id: I61134b05310a97ae9831517d0516c7b4240d35a5
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6751
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
-rw-r--r-- | src/target/cortex_m.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/target/cortex_m.h b/src/target/cortex_m.h index 8fb34f4..5554014 100644 --- a/src/target/cortex_m.h +++ b/src/target/cortex_m.h @@ -46,6 +46,7 @@ #define ARM_CPUID_PARTNO_MASK (0xFFF << ARM_CPUID_PARTNO_POS) enum cortex_m_partno { + CORTEX_M_PARTNO_INVALID, CORTEX_M0_PARTNO = 0xC20, CORTEX_M1_PARTNO = 0xC21, CORTEX_M3_PARTNO = 0xC23, @@ -294,6 +295,23 @@ target_to_cortex_m_safe(struct target *target) return cortex_m; } +/** + * @returns cached value of Cortex-M part number + * or CORTEX_M_PARTNO_INVALID if the magic number does not match + * or core_info is not initialised. + */ +static inline enum cortex_m_partno cortex_m_get_partno_safe(struct target *target) +{ + struct cortex_m_common *cortex_m = target_to_cortex_m_safe(target); + if (!cortex_m) + return CORTEX_M_PARTNO_INVALID; + + if (!cortex_m->core_info) + return CORTEX_M_PARTNO_INVALID; + + return cortex_m->core_info->partno; +} + int cortex_m_examine(struct target *target); int cortex_m_set_breakpoint(struct target *target, struct breakpoint *breakpoint); int cortex_m_unset_breakpoint(struct target *target, struct breakpoint *breakpoint); |