Compare commits
2 Commits
4f1067da04
...
5447ac1d2f
Author | SHA1 | Date | |
---|---|---|---|
|
5447ac1d2f | ||
|
6279f7c05d |
22
Makefile
22
Makefile
@ -35,7 +35,7 @@ CC_SRCS += $(wildcard $(SRC_DIR)/platform/$(PLATFORM)/*.cc)
|
|||||||
CC_SRCS += $(wildcard $(SRC_DIR)/application/$(APPLICATION)/*.cc)
|
CC_SRCS += $(wildcard $(SRC_DIR)/application/$(APPLICATION)/*.cc)
|
||||||
CC_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.cc,%.cc.o,$(CC_SRCS)))
|
CC_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.cc,%.cc.o,$(CC_SRCS)))
|
||||||
|
|
||||||
OBJS = $(NRF_A_OBJS) $(NRF_C_OBJS) $(C_OBJS) $(CC_OBJS)
|
OBJS = $(A_OBJS) $(C_OBJS) $(CC_OBJS)
|
||||||
|
|
||||||
TARGET = $(BIN_DIR)/$(TARGET_FILE)
|
TARGET = $(BIN_DIR)/$(TARGET_FILE)
|
||||||
TARGET_HEX = $(patsubst %.elf,%.hex,$(TARGET))
|
TARGET_HEX = $(patsubst %.elf,%.hex,$(TARGET))
|
||||||
@ -92,13 +92,17 @@ $(TARGET_HEX): $(TARGET) $(THIS_MAKEFILE)
|
|||||||
$(OBJCOPY) -O ihex $(TARGET) $(TARGET_HEX)
|
$(OBJCOPY) -O ihex $(TARGET) $(TARGET_HEX)
|
||||||
ln -sf $(shell pwd)/$@ $(shell pwd)/bin/firmware.hex
|
ln -sf $(shell pwd)/$@ $(shell pwd)/bin/firmware.hex
|
||||||
|
|
||||||
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c $(THIS_MAKEFILE)
|
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.S $(THIS_MAKEFILE)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.c,$@)
|
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.S,$@)
|
||||||
|
|
||||||
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.cc $(THIS_MAKEFILE)
|
$(OBJ_DIR)/%.c.d: $(SRC_DIR)/%.c $(THIS_MAKEFILE)
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.c.d,%.c.o,$@) $(C_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.c.d,$(SRC_DIR)/%.c,$@)
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.cc.d: $(SRC_DIR)/%.cc $(THIS_MAKEFILE)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(CXX_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.cc,$@)
|
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.cc.d,%.cc.o,$@) $(CXX_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.cc.d,$(SRC_DIR)/%.cc,$@)
|
||||||
|
|
||||||
$(OBJ_DIR)/%.cc.o: $(SRC_DIR)/%.cc $(THIS_MAKEFILE)
|
$(OBJ_DIR)/%.cc.o: $(SRC_DIR)/%.cc $(THIS_MAKEFILE)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
@ -108,6 +112,12 @@ $(OBJ_DIR)/%.c.o: $(SRC_DIR)/%.c $(THIS_MAKEFILE)
|
|||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@
|
$(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.S $(THIS_MAKEFILE)
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CC) -c $(ASMFLAGS) $< -o $@
|
||||||
|
|
||||||
ifeq "$(findstring $(MAKECMDGOALS), clean distclean)" ""
|
ifeq "$(findstring $(MAKECMDGOALS), clean distclean)" ""
|
||||||
-include $(patsubst %.o,%.d,$(OBJS))
|
include $(patsubst %.o,%.d,$(A_OBJS))
|
||||||
|
include $(patsubst %.c.o,%.c.d,$(C_OBJS))
|
||||||
|
include $(patsubst %.cc.o,%.cc.d,$(CC_OBJS))
|
||||||
endif
|
endif
|
||||||
|
@ -7,10 +7,10 @@ INCLUDES += src/platform/nrf52/sdk
|
|||||||
INCLUDES += src/platform/cm4/cmsis/include
|
INCLUDES += src/platform/cm4/cmsis/include
|
||||||
|
|
||||||
NRF_C_SRCS += src/platform/nrf52/sdk/system_nrf52.c
|
NRF_C_SRCS += src/platform/nrf52/sdk/system_nrf52.c
|
||||||
NRF_C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.c.o,$(NRF_C_SRCS)))
|
C_OBJS += $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.c.o,$(NRF_C_SRCS)))
|
||||||
|
|
||||||
NRF_A_SRCS = src/platform/nrf52/sdk/gcc_startup_nrf52.S
|
NRF_A_SRCS = src/platform/nrf52/sdk/gcc_startup_nrf52.S
|
||||||
NRF_A_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)/%,$(patsubst %.S,%.o,$(NRF_A_SRCS)))
|
A_OBJS += $(patsubst $(SRC_DIR)%,$(OBJ_DIR)/%,$(patsubst %.S,%.o,$(NRF_A_SRCS)))
|
||||||
|
|
||||||
C_FLAGS += -DBOARD_PCA10040
|
C_FLAGS += -DBOARD_PCA10040
|
||||||
C_FLAGS += -DBSP_DEFINES_ONLY
|
C_FLAGS += -DBSP_DEFINES_ONLY
|
||||||
@ -93,15 +93,3 @@ flash_softdevice: $(THIS_MAKEFILE)
|
|||||||
|
|
||||||
erase:
|
erase:
|
||||||
nrfjprog -f nrf52 --eraseall
|
nrfjprog -f nrf52 --eraseall
|
||||||
|
|
||||||
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.S $(THIS_MAKEFILE)
|
|
||||||
@mkdir -p $(dir $@)
|
|
||||||
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.S,$@)
|
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(THIS_MAKEFILE)
|
|
||||||
@mkdir -p $(dir $@)
|
|
||||||
$(CC) -std=c99 -MP -MD -c -o $@ $< $(C_FLAGS) $(CPP_FLAGS)
|
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.S $(THIS_MAKEFILE)
|
|
||||||
@mkdir -p $(dir $@)
|
|
||||||
$(CC) -c $(ASMFLAGS) $< -o $@
|
|
||||||
|
@ -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