Compare commits

...

4 Commits

Author SHA1 Message Date
Thomas Klaehn
605c422c39 Remove hal 2020-04-09 09:43:12 +02:00
Thomas Klaehn
3555593c31 Add Sys_Tick example application 2020-04-09 09:42:39 +02:00
Thomas Klaehn
6e7b955d71 Add SysTick handler 2020-04-09 09:42:39 +02:00
Thomas Klaehn
b93152db8f Add interrupt handling 2020-04-09 09:35:22 +02:00
15 changed files with 385 additions and 41 deletions

26
.vscode/tasks.json vendored
View File

@ -1,21 +1,25 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"env": {
"PLATFORM": "nrf52",
// "PLATFORM": "posix",
"APPLICATION": "blinky",
// "APPLICATION": "spi",
// "APPLICATION": "st7789_lcd",
// "APPLICATION": "sys_tick",
"${BUILD_CMD}": "eval docker run --env PLATFORM=${PLATFORM} --env APPLICATION=${APPLICATION} -t --rm -v '${workspaceFolder}':/work --user $(id -u):$(id -g) arm-none-eabi.buildenv",
},
},
"presentation": {
"focus": true,
"reveal": "always",
"panel": "shared",
"clear": true,
},
"tasks": [
{
"label": "all",
"type":"shell",
"command": "make all -j8",
"command": "${BUILD_CMD} make all -j8",
"problemMatcher": {
"base": "$gcc",
"owner": "gcc",
@ -49,7 +53,7 @@
{
"label": "clean",
"type":"shell",
"command": "make clean -j8",
"command": "${BUILD_CMD} make clean -j8",
"problemMatcher": {
"base": "$gcc",
"owner": "gcc",
@ -66,7 +70,7 @@
{
"label": "distclean",
"type":"shell",
"command": "make distclean",
"command": "${BUILD_CMD} make distclean",
"problemMatcher": {
"base": "$gcc",
"owner": "gcc",
@ -97,11 +101,5 @@
"isDefault": true
}
}
],
"presentation": {
"focus": true,
"reveal": "always",
"panel": "shared",
"clear": true,
}
]
}

View File

@ -3,6 +3,11 @@
APPLICATION ?= blinky
PLATFORM ?= nrf52
ifneq "$(findstring $(PLATFORM), nrf52)" ""
CORE = cm4
endif
TARGET_FILE ?= $(APPLICATION).elf
CC = $(CROSS_COMPILE)gcc
@ -25,6 +30,7 @@ C_SRCS += $(wildcard $(SRC_DIR)/application/$(APPLICATION)/*.c)
C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.c.o,$(C_SRCS)))
CC_SRCS = $(wildcard $(SRC_DIR)/*.cc)
CC_SRCS += $(wildcard $(SRC_DIR)/platform/$(CORE)/*.cc)
CC_SRCS += $(wildcard $(SRC_DIR)/platform/$(PLATFORM)/*.cc)
CC_SRCS += $(wildcard $(SRC_DIR)/application/$(APPLICATION)/*.cc)
CC_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.cc,%.cc.o,$(CC_SRCS)))

View File

@ -0,0 +1,16 @@
#ifndef __INTERFACES_INTERRUPT_INTERFACE_H__
#define __INTERFACES_INTERRUPT_INTERFACE_H__
namespace pinetime::interfaces {
class InterruptInterface
{
public:
virtual void handle() = 0;
virtual void enable() = 0;
virtual void disable() = 0;
};
}
#endif

View File

@ -1,7 +1,12 @@
#include <array>
#include "delay.h"
#include "platform/hal.h"
#include "platform/nrf52/gpio.h"
#include "platform/nrf52/InterruptHandler.h"
#include "platform/nrf52/InterruptGuardian.h"
using namespace pinetime::platform::nrf52;
enum {
PIN_NUMBER_LED_1 = 17,
@ -10,18 +15,20 @@ enum {
PIN_NUMBER_LED_4 = 20
};
hal::Gpio led_1(PIN_NUMBER_LED_1);
hal::Gpio led_2(PIN_NUMBER_LED_2);
hal::Gpio led_3(PIN_NUMBER_LED_3);
hal::Gpio led_4(PIN_NUMBER_LED_4);
Gpio led_1(PIN_NUMBER_LED_1);
Gpio led_2(PIN_NUMBER_LED_2);
Gpio led_3(PIN_NUMBER_LED_3);
Gpio led_4(PIN_NUMBER_LED_4);
std::array<hal::Gpio *, 4> leds = {&led_1, &led_2, &led_3, &led_4};
std::array<Gpio *, 4> leds = {&led_1, &led_2, &led_3, &led_4};
InterruptGuardian InterruptGuardian::instance;
int main(void)
{
while(true) {
for(auto it = std::begin(leds); it != std::end(leds); ++it) {
hal::Gpio * tmp = *it;
Gpio * tmp = *it;
tmp->toggle();
delay_ms(500);
}

View File

@ -1,11 +1,17 @@
#include "delay.h"
#include "platform/hal.h"
using namespace hal;
#include "platform/nrf52/gpio.h"
#include "platform/nrf52/spi.h"
#include "platform/nrf52/InterruptHandler.h"
#include "platform/nrf52/InterruptGuardian.h"
using namespace pinetime::platform::nrf52;
const uint8_t buf[] = "Test";
InterruptGuardian InterruptGuardian::instance;
int main(void)
{
Gpio led_1(17);

View File

@ -1,18 +1,25 @@
#include "delay.h"
#include "platform/hal.h"
#include "platform/nrf52/gpio.h"
#include "platform/nrf52/spi.h"
#include "platform/nrf52/InterruptHandler.h"
#include "platform/nrf52/InterruptGuardian.h"
#include "st7789.h"
hal::Gpio led_1(17);
using namespace pinetime::platform::nrf52;
hal::Gpio lcd_reset(26);
hal::Gpio lcd_data_command(18);
hal::Gpio lcd_backlight(23);
hal::Gpio lcd_chip_select(25);
hal::Spi lcd_spi(0, 2, 3, 4, lcd_chip_select);
Gpio led_1(17);
Gpio lcd_reset(26);
Gpio lcd_data_command(18);
Gpio lcd_backlight(23);
Gpio lcd_chip_select(25);
Spi lcd_spi(0, 2, 3, 4, lcd_chip_select);
St7789 lcd(lcd_spi, lcd_reset, lcd_data_command, lcd_backlight);
InterruptGuardian InterruptGuardian::instance;
int main(void)
{
lcd.init();

View File

@ -0,0 +1,47 @@
#include <array>
extern "C" {
#include "nrf52.h"
}
#include "platform/nrf52/gpio.h"
#include "platform/nrf52/InterruptHandler.h"
#include "platform/nrf52/InterruptGuardian.h"
#include "platform/cm4/SystemTick.h"
using namespace pinetime::platform::nrf52;
enum {
PIN_NUMBER_LED_1 = 17,
PIN_NUMBER_LED_2 = 18,
PIN_NUMBER_LED_3 = 19,
PIN_NUMBER_LED_4 = 20
};
Gpio led_1(PIN_NUMBER_LED_1);
Gpio led_2(PIN_NUMBER_LED_2);
Gpio led_3(PIN_NUMBER_LED_3);
Gpio led_4(PIN_NUMBER_LED_4);
std::array<Gpio *, 4> leds = {&led_1, &led_2, &led_3, &led_4};
InterruptGuardian InterruptGuardian::instance;
pinetime::platform::cm4::SystemTick ticker;
int main(void)
{
ticker.enable();
uint32_t last_tick = 0;
while(true) {
for(auto it = std::begin(leds); it != std::end(leds); ++it) {
uint32_t tick = ticker.tick() / 1000;
if(tick != last_tick) {
Gpio * tmp = *it;
tmp->toggle();
}
last_tick = tick;
}
}
return 0;
}

View File

@ -0,0 +1,35 @@
extern "C" {
#include "nrf52.h"
}
#include "platform/cm4/SystemTick.h"
#include "platform/nrf52/InterruptGuardian.h"
using namespace pinetime::platform::cm4;
using namespace pinetime::platform::nrf52;
SystemTick::SystemTick()
: InterruptHandler(InterruptGuardian::Nrf52IrqN::SYS_TICK_IRQ)
, sys_tick(0)
{
}
void SystemTick::handle()
{
this->sys_tick++;
}
void SystemTick::enable()
{
SysTick_Config(SystemCoreClock / 1000);
}
void SystemTick::disable()
{
SysTick->CTRL = 0;
}
uint32_t SystemTick::tick()
{
return this->sys_tick;
}

View File

@ -0,0 +1,23 @@
#ifndef __PLATFORM_CM4_SYSTEMTICK_H__
#define __PLATFORM_CM4_SYSTEMTICK_H__
#include "platform/nrf52/InterruptHandler.h"
namespace pinetime::platform::cm4 {
class SystemTick : public pinetime::platform::nrf52::InterruptHandler
{
public:
SystemTick();
void handle();
void enable();
void disable();
uint32_t tick();
private:
uint32_t sys_tick;
};
}
#endif

View File

@ -1,11 +0,0 @@
#ifndef __PLATFORM_GPIO_H__
#define __PLATFORM_GPIO_H__
#if defined(PLATFORM_nrf52)
#include "platform/nrf52/gpio.h"
#include "platform/nrf52/spi.h"
namespace hal = pinetime::platform::nrf52;
#endif
#endif

View File

@ -0,0 +1,13 @@
#include "platform/nrf52/InterruptHandler.h"
#include "platform/nrf52/InterruptGuardian.h"
using namespace pinetime::platform::nrf52;
InterruptGuardian::InterruptGuardian()
{
}
void InterruptGuardian::register_handler(Nrf52IrqN irq_nr, InterruptHandler &handler)
{
this->nrf52_vector[irq_nr] = &handler;
}

View File

@ -0,0 +1,82 @@
#ifndef __PINETIME_PLATFORM_NRF52_INTERRUPTGUARDIAN_H__
#define __PINETIME_PLATFORM_NRF52_INTERRUPTGUARDIAN_H__
#include <array>
extern "C" {
#include "nrf52.h"
}
namespace pinetime::platform::nrf52 {
class InterruptGuardian
{
public:
InterruptGuardian();
enum Nrf52IrqN {
// CM4 interrupts
RESET_IRQ = 0, //!< -15 Reset Vector, invoked on Power up and warm reset
NON_MASKABLE_INT_IRQ, //!< -14 Non maskable Interrupt, cannot be stopped or preempted
HARD_FAULT_IRQ, //!< -13 Hard Fault, all classes of Fault
MEMORY_MANAGEMENT_IRQ, //!< -12 Memory Management, MPU mismatch, including Access Violation and No Match
BUS_FAULT_IRQ, //!< -11 Bus Fault, Pre-Fetch-, Memory Access Fault, other address/memory related Fault
USAGE_FAULT_IRQ, //!< -10 Usage Fault, i.e. Undef Instruction, Illegal State Transition
SV_CALL_IRQ, //!< -5 System Service Call via SVC instruction
DEBUG_MONITOR_IRQ, //!< -4 Debug Monitor
PEND_SV_IRQ, //!< -2 Pendable request for system service
SYS_TICK_IRQ, //!< -1 System Tick Timer
// nrf52 interrupts
POWER_CLOCK_IRQn, //!< 0 POWER_CLOCK
RADIO_IRQn, //!< 1 RADIO
UARTE0_UART0_IRQn, //!< 2 UARTE0_UART0
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, //!< 3 SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, //!< 4 SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1
NFCT_IRQn, //!< 5 NFCT
GPIOTE_IRQn, //!< 6 GPIOTE
SAADC_IRQn, //!< 7 SAADC
TIMER0_IRQn, //!< 8 TIMER0
TIMER1_IRQn, //!< 9 TIMER1
TIMER2_IRQn, //!< 10 TIMER2
RTC0_IRQn, //!< 11 RTC0
TEMP_IRQn, //!< 12 TEMP
RNG_IRQn, //!< 13 RNG
ECB_IRQn, //!< 14 ECB
CCM_AAR_IRQn, //!< 15 CCM_AAR
WDT_IRQn, //!< 16 WDT
RTC1_IRQn, //!< 17 RTC1
QDEC_IRQn, //!< 18 QDEC
COMP_LPCOMP_IRQn, //!< 19 COMP_LPCOMP
SWI0_EGU0_IRQn, //!< 20 SWI0_EGU0
SWI1_EGU1_IRQn, //!< 21 SWI1_EGU1
SWI2_EGU2_IRQn, //!< 22 SWI2_EGU2
SWI3_EGU3_IRQn, //!< 23 SWI3_EGU3
SWI4_EGU4_IRQn, //!< 24 SWI4_EGU4
SWI5_EGU5_IRQn, //!< 25 SWI5_EGU5
TIMER3_IRQn, //!< 26 TIMER3
TIMER4_IRQn, //!< 27 TIMER4
PWM0_IRQn, //!< 28 PWM0
PDM_IRQn, //!< 29 PDM
MWU_IRQn, //!< 32 MWU
PWM1_IRQn, //!< 33 PWM1
PWM2_IRQn, //!< 34 PWM2
SPIM2_SPIS2_SPI2_IRQn, //!< 35 SPIM2_SPIS2_SPI2
RTC2_IRQn, //!< 36 RTC2
I2S_IRQn, //!< 37 I2S
FPU_IRQn //!< 38 FPU
};
enum {
NRF52_HANDLER_COUNT = FPU_IRQn + 1,
};
void register_handler(Nrf52IrqN irq_nr, InterruptHandler &);
static InterruptGuardian instance;
std::array<InterruptHandler *, NRF52_HANDLER_COUNT> nrf52_vector;
};
}
#endif

View File

@ -0,0 +1,27 @@
#include <assert.h>
#include "platform/nrf52/InterruptHandler.h"
#include "platform/nrf52/InterruptGuardian.h"
using namespace pinetime::platform::nrf52;
InterruptHandler::InterruptHandler(uint32_t irq_nr)
{
InterruptGuardian::instance.register_handler(static_cast<InterruptGuardian::Nrf52IrqN>(irq_nr), *this);
}
void InterruptHandler::handle()
{
asm volatile("nop");
assert(false);
}
void InterruptHandler::enable()
{
assert(false);
}
void InterruptHandler::disable()
{
assert(false);
}

View File

@ -0,0 +1,22 @@
#ifndef __PINETIME_PLATFORM_NRF52_INTERRUPTHANDLER_H__
#define __PINETIME_PLATFORM_NRF52_INTERRUPTHANDLER_H__
#include <cstdint>
#include "interrupt_interface.h"
namespace pinetime::platform::nrf52 {
class InterruptHandler : public pinetime::interfaces::InterruptInterface
{
public:
InterruptHandler(uint32_t);
void handle() override;
void enable() override;
void disable() override;
};
}
#endif

View File

@ -0,0 +1,66 @@
#include <cassert>
#include "platform/nrf52/InterruptHandler.h"
#include "platform/nrf52/InterruptGuardian.h"
extern "C" {
void NMI_Handler(void);
void HardFault_Handler(void);
void MemoryManagement_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void POWER_CLOCK_IRQHandler(void);
void RADIO_IRQHandler(void);
void UARTE0_UART0_IRQHandler(void);
void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void);
void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler(void);
void NFCT_IRQHandler(void);
void GPIOTE_IRQHandler(void);
void SAADC_IRQHandler(void);
void TIMER0_IRQHandler(void);
void TIMER1_IRQHandler(void);
void TIMER2_IRQHandler(void);
void RTC0_IRQHandler(void);
void TEMP_IRQHandler(void);
void RNG_IRQHandler(void);
void ECB_IRQHandler(void);
void CCM_AAR_IRQHandler(void);
void WDT_IRQHandler(void);
void RTC1_IRQHandler(void);
void QDEC_IRQHandler(void);
void COMP_LPCOMP_IRQHandler(void);
void SWI0_EGU0_IRQHandler(void);
void SWI1_EGU1_IRQHandler(void);
void SWI2_EGU2_IRQHandler(void);
void SWI3_EGU3_IRQHandler(void);
void SWI4_EGU4_IRQHandler(void);
void SWI5_EGU5_IRQHandler(void);
void TIMER3_IRQHandler(void);
void TIMER4_IRQHandler(void);
void PWM0_IRQHandler(void);
void PDM_IRQHandler(void);
void MWU_IRQHandler(void);
void PWM1_IRQHandler(void);
void PWM2_IRQHandler(void);
void SPIM2_SPIS2_SPI2_IRQHandler(void);
void RTC2_IRQHandler(void);
void I2S_IRQHandler(void);
void FPU_IRQHandler(void);
}
using namespace pinetime::platform::nrf52;
void SysTick_Handler(void)
{
uint32_t irq_nr = InterruptGuardian::Nrf52IrqN::SYS_TICK_IRQ;
InterruptHandler *h = InterruptGuardian::instance.nrf52_vector[irq_nr];
assert(h != nullptr);
h->handle();
}