Implement SCB module
This commit is contained in:
parent
97dad53621
commit
1741d47546
64
drv/scb.c
Normal file
64
drv/scb.c
Normal file
@ -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------------------------------------------------------------------------
|
||||
|
||||
32
drv/scb.h
Normal file
32
drv/scb.h
Normal file
@ -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_
|
||||
|
||||
Loading…
Reference in New Issue
Block a user