Add interrupt lock
This commit is contained in:
parent
4f1067da04
commit
6279f7c05d
@ -33,9 +33,11 @@ int main(void)
|
|||||||
cm4::SystemTick ticker;
|
cm4::SystemTick ticker;
|
||||||
ticker.enable();
|
ticker.enable();
|
||||||
uint32_t last_tick = 0;
|
uint32_t last_tick = 0;
|
||||||
|
|
||||||
|
cm4::InterruptGuardian::enable_interrupts();
|
||||||
while(true) {
|
while(true) {
|
||||||
for(auto it = std::begin(leds); it != std::end(leds); ++it) {
|
for(auto it = std::begin(leds); it != std::end(leds); ++it) {
|
||||||
uint32_t tick = ticker.tick() / 1000;
|
volatile uint32_t tick = ticker.tick() / 1000;
|
||||||
if(tick != last_tick) {
|
if(tick != last_tick) {
|
||||||
nrf52::Gpio * tmp = *it;
|
nrf52::Gpio * tmp = *it;
|
||||||
tmp->toggle();
|
tmp->toggle();
|
||||||
|
@ -5,6 +5,7 @@ using namespace pinetime::platform::cm4;
|
|||||||
|
|
||||||
InterruptGuardian::InterruptGuardian()
|
InterruptGuardian::InterruptGuardian()
|
||||||
{
|
{
|
||||||
|
disable_interrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterruptGuardian::register_handler(Cm4IrqN irq_nr, InterruptHandler &handler)
|
void InterruptGuardian::register_handler(Cm4IrqN irq_nr, InterruptHandler &handler)
|
||||||
|
@ -33,6 +33,20 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static inline void enable_interrupts() { asm volatile("cpsie i"); }
|
||||||
|
static inline void disable_interrupts() { asm volatile("cpsid i"); }
|
||||||
|
static inline bool suspend_interrupts()
|
||||||
|
{
|
||||||
|
uint32_t mask;
|
||||||
|
asm volatile("mrs %0, primask" : "=r" (mask));
|
||||||
|
asm volatile("cpsid i");
|
||||||
|
return(mask & 0x01);
|
||||||
|
}
|
||||||
|
static inline void resume_interrupts(bool status)
|
||||||
|
{
|
||||||
|
asm volatile ("msr primask, %0" : : "r" (status) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
void register_handler(Cm4IrqN irq_nr, InterruptHandler &);
|
void register_handler(Cm4IrqN irq_nr, InterruptHandler &);
|
||||||
|
|
||||||
static InterruptGuardian instance;
|
static InterruptGuardian instance;
|
||||||
|
15
src/platform/cm4/InterruptLock.cc
Normal file
15
src/platform/cm4/InterruptLock.cc
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "platform/cm4/InterruptHandler.h"
|
||||||
|
#include "platform/cm4/InterruptGuardian.h"
|
||||||
|
#include "platform/cm4/InterruptLock.h"
|
||||||
|
|
||||||
|
using namespace pinetime::platform::cm4;
|
||||||
|
|
||||||
|
InterruptLock::InterruptLock()
|
||||||
|
{
|
||||||
|
this->state = InterruptGuardian::suspend_interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
InterruptLock::~InterruptLock()
|
||||||
|
{
|
||||||
|
InterruptGuardian::resume_interrupts(this->state);
|
||||||
|
}
|
18
src/platform/cm4/InterruptLock.h
Normal file
18
src/platform/cm4/InterruptLock.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef __PLATFORM_CM$_INTERRUPTLOCK_H__
|
||||||
|
#define __PLATFORM_CM$_INTERRUPTLOCK_H__
|
||||||
|
|
||||||
|
namespace pinetime::platform::cm4 {
|
||||||
|
|
||||||
|
class InterruptLock
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InterruptLock();
|
||||||
|
~InterruptLock();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool state;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user