From 1741d47546f57eef2ceb053bb20618edd19b567f Mon Sep 17 00:00:00 2001 From: Steins7 Date: Sat, 13 Jul 2024 21:35:22 +0200 Subject: [PATCH] Implement SCB module --- drv/scb.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ drv/scb.h | 32 ++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 drv/scb.c create mode 100644 drv/scb.h diff --git a/drv/scb.c b/drv/scb.c new file mode 100644 index 0000000..ba0fb96 --- /dev/null +++ b/drv/scb.c @@ -0,0 +1,64 @@ +/** @file scb.c + * Module handling the System Control Block + * + * The module provides functions to configure miscelaneous options of the cortex + * m3, including sleep behavior, event handler priorities, resets and fault + * handlers + */ + +//--includes-------------------------------------------------------------------- + +#include "scb.h" +#include "scb_regs.h" + + +//--local definitions----------------------------------------------------------- + +//--local variables------------------------------------------------------------- + +static volatile struct SCB* regs = (struct SCB*)SCB_BASE_ADDRESS; + + +//--public functions------------------------------------------------------------ + +uint16_t scb_pending_exception(void) +{ + return regs->ICSR.VECTPENDING; +} + +uint16_t scb_active_exception(void) +{ + return regs->ICSR.VECTACTIVE; +} + +void scb_configure_vector_table(uint32_t offset) +{ + //TODO check that last LSB is 0 (alignement restrictions) + regs->VTOR.TABLEOFF = offset & 0x1FFFFF; +} + +void scb_reset_system(void) +{ + regs->AIRCR.SYSRESETREQ = 1; +} + +void scb_configure_deepsleep(bool enable) +{ + regs->SCR.SLEEPDEEP = enable; +} + +void scb_configure_div0_fault(bool enable) +{ + regs->CCR.DIV_0_TRP = enable; +} + +void scb_configure_unalign_fault(bool enable) +{ + regs->CCR.UNALIGN_TRP = enable; +} + + +//--local functions------------------------------------------------------------- + +//--ISRs------------------------------------------------------------------------ + diff --git a/drv/scb.h b/drv/scb.h new file mode 100644 index 0000000..c814cde --- /dev/null +++ b/drv/scb.h @@ -0,0 +1,32 @@ +/** @file scb.h + * Module handling the System Control Block + * + * The module provides functions to configure miscelaneous options of the cortex + * m3, including sleep behavior, event handler priorities, resets and fault + * handlers + */ + +#ifndef _SCB_H_ +#define _SCB_H_ + +//--includes-------------------------------------------------------------------- + +#include "stdint.h" + + +//--type definitions------------------------------------------------------------ + +//--functions------------------------------------------------------------------- + +uint16_t scb_pending_exception(void); +uint16_t scb_active_exception(void); + +void scb_configure_vector_table(uint32_t offset); +void scb_reset_system(void); +void scb_configure_deepsleep(bool enable); +void scb_configure_div0_fault(bool enable); +void scb_configure_unalign_fault(bool enable); + + +#endif //_SCB_H_ +