diff --git a/csl/stm32f042k6t6/HardwareDescription/hwd_interrupt.h b/csl/stm32f042k6t6/HardwareDescription/hwd_interrupt.h index b002cfb..9eec351 100644 --- a/csl/stm32f042k6t6/HardwareDescription/hwd_interrupt.h +++ b/csl/stm32f042k6t6/HardwareDescription/hwd_interrupt.h @@ -86,9 +86,7 @@ typedef enum { }intrType_t; //static uint32_t intHandlerList[intTypeEND]={0}; - extern volatile void (*intHandlerArray[intTypeEND])(); - extern const uint8_t interruptTypeIndexList[intTypeEND]; #ifdef __cplusplus diff --git a/csl/stm32f042k6t6/implementation/imp_deviceSetup.c b/csl/stm32f042k6t6/implementation/imp_deviceSetup.c index bd01106..26cbf4e 100644 --- a/csl/stm32f042k6t6/implementation/imp_deviceSetup.c +++ b/csl/stm32f042k6t6/implementation/imp_deviceSetup.c @@ -8,6 +8,7 @@ #define CLEAR_REG(REG) ((REG) = (0x0)) #define WRITE_REG(REG, VAL) ((REG) = (VAL)) #define READ_REG(REG) ((REG)) + #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) // FLASH->ACR = (((FLASH->ACR) & (~(FLASH_ACR_LATENCY))) | 0) #define SYS_CLK 8000000 @@ -18,6 +19,7 @@ void setupInit() setupBus(); setupMemory(); setupClock(); + __disable_irq(); setupPower(); delayInitMs(SYS_CLK, 1000); } diff --git a/csl/stm32f042k6t6/implementation/imp_interrupt.c b/csl/stm32f042k6t6/implementation/imp_interrupt.c index 805de05..1417b11 100644 --- a/csl/stm32f042k6t6/implementation/imp_interrupt.c +++ b/csl/stm32f042k6t6/implementation/imp_interrupt.c @@ -87,12 +87,12 @@ void intInit( intHandlerArray[intType] = handler; } -void intEnableAll() +void intEnableGlobal() { __enable_irq(); } -void intDisableAll() +void intDisableGlobal() { __disable_irq(); } diff --git a/csl/stm32f042k6t6/implementation/imp_timer.c b/csl/stm32f042k6t6/implementation/imp_timer.c index cd37fe8..44a1eb3 100644 --- a/csl/stm32f042k6t6/implementation/imp_timer.c +++ b/csl/stm32f042k6t6/implementation/imp_timer.c @@ -38,12 +38,12 @@ static const uint32_t DIER_list[41] = { TIM_DIER_CC1IE,// timer 14 TIM_DIER_CC1IE, TIM_DIER_UIE, - TIM_DIER_CC1IE,// tiemr 16 + TIM_DIER_CC1IE,// timer 16 TIM_DIER_BIE, TIM_DIER_COMIE, TIM_DIER_CC1IE, TIM_DIER_UIE, - TIM_DIER_CC1IE,// tiemr 17 + TIM_DIER_CC1IE,// timer 17 TIM_DIER_BIE, TIM_DIER_COMIE, TIM_DIER_CC1IE, @@ -91,7 +91,6 @@ void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction) { if(direction == upCounting) { - BASE->CR1 &=~ TIM_CR1_DIR; return; } @@ -295,7 +294,7 @@ void timerEnableInterrupt( { // check for the correct interrupt index if(timerInterrupt < TIM1_BREAK) return; - if(timerInterrupt >TIM17_UPDATE) return; + if(timerInterrupt > TIM17_UPDATE) return; // set the corresponding bit in the corresponding timers DIER register BASE->DIER |= DIER_list[timerInterrupt - TIM1_BREAK]; } @@ -347,6 +346,7 @@ void TIM2_IRQHandler() HANDLE_INT_FLAG(TIM2->SR,TIM_SR_CC4OF,TIM2_CAPTURECOMAPRE_4); } + void TIM3_IRQHandler() { HANDLE_INT_FLAG(TIM3->SR,TIM_SR_UIF,TIM3_UPDATE); diff --git a/csl/stm32f042k6t6/startup/STM32F042K6Tx_FLASH.ld b/csl/stm32f042k6t6/startup/STM32F042K6Tx_FLASH.ld index 3dd25d2..d703f1d 100644 --- a/csl/stm32f042k6t6/startup/STM32F042K6Tx_FLASH.ld +++ b/csl/stm32f042k6t6/startup/STM32F042K6Tx_FLASH.ld @@ -185,5 +185,3 @@ SECTIONS .ARM.attributes 0 : { *(.ARM.attributes) } } - - diff --git a/libraries/examples/timer2_Interrupt_Blinki_v2/main.c b/libraries/examples/timer2_Interrupt_Blinki_v2/main.c new file mode 100644 index 0000000..f1e24c9 --- /dev/null +++ b/libraries/examples/timer2_Interrupt_Blinki_v2/main.c @@ -0,0 +1,42 @@ +#include "delay.h" +#include "pin.h" +#include "deviceSetup.h" +#include "interrupt.h" +#include "timer.h" + + +void blinkiTask() +{ + pinToggle(pinB3); +} + +void declareInterrupts() +{ + intDisableGlobal(); + + timerInitCounter(timer_2,(8E6/16E3)-1, 5000-1, upCounting); + timerEnableInterrupt(timer_2,TIM2_UPDATE); + timerStart(timer_2); + + intInit(TIM2_UPDATE, blinkiTask, 1); + intEnable(TIM2_UPDATE); + + intEnableGlobal(); +} + +int main(int argc, char *argv[]) +{ + uint8_t i = 0; + + pinConfig(pinA0, input, def_stage, pullDown, def_speed); + pinConfig(pinB3, output, pushPull, def_res, def_speed); + + pinWrite(pinB3, 0); + + declareInterrupts(); + + while(1); + + return 1; +} + diff --git a/libraries/examples/timer2_Interrupt_Blinki_v2/main.h b/libraries/examples/timer2_Interrupt_Blinki_v2/main.h new file mode 100644 index 0000000..4a3e41b --- /dev/null +++ b/libraries/examples/timer2_Interrupt_Blinki_v2/main.h @@ -0,0 +1,15 @@ +#ifndef MAIN_H +#define MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + +#ifdef __cplusplus +} +#endif + +#endif /* MAIN_H */ diff --git a/libraries/examples/timer2_Interrupt_Blinki_v2/projectDefinitions.cmake b/libraries/examples/timer2_Interrupt_Blinki_v2/projectDefinitions.cmake new file mode 100644 index 0000000..3b73a36 --- /dev/null +++ b/libraries/examples/timer2_Interrupt_Blinki_v2/projectDefinitions.cmake @@ -0,0 +1,21 @@ +#Declareing header directory for the project +#To add a new directory +# -> list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR}/YOUR_DESIRED_DIRECTORY) +# list() = List declaration "DON'T CHANGE" +# PROJECT_HEADERS_DIR = Variable containing the listed direcotries "DON'T CHANCE +# ${PROJECT_DIR} = Direcotry of the main project this is per default the current direcotry it is defined in ked/CMakeLists.txt +#list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR}/headers) + +#Declaring sources directory for the project +#To add a new directory +# -> list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/YOUR_DESIRED_DIRECTORY) +# list() = List declaration "DON'T CHANGE" +# PROJECT_SOURCES_DIR = Variable containing the listed direcotries "DON'T CHANCE +# ${PROJECT_DIR} = Direcotry of the main project this is per default the current direcotry it is defined in ked/CMakeLists.txt +#list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/src) +#list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/sensors) + +#Declaring sources to be compiled for the project. +#CMake will look in each previsouly declarec sources directory until to find this files. +set(PROJECT_SOURCES_DIR_LIST) + diff --git a/system/interrupt/interrupt.h b/system/interrupt/interrupt.h index 1d6f92d..2727540 100644 --- a/system/interrupt/interrupt.h +++ b/system/interrupt/interrupt.h @@ -25,12 +25,22 @@ extern "C" { #include "hwd_interrupt.h" #define HANDLE_INT_FLAG(flagReg, flagMask, intType) \ + if ((flagReg) & (flagMask)) { \ + (flagReg) &= ~(flagMask); \ + if(intHandlerArray[(intType)]){ \ + intHandlerArray[(intType)](); \ + } \ + } + + +/* OLD VERSION : Why did we need the do whlie loop ? + #define HANDLE_INT_FLAG(flagReg, flagMask, intType) \ do {if ((flagReg) & (flagMask)) { \ (flagReg) &= ~(flagMask); \ if(intHandlerArray[(intType)] == NULL){ continue;} \ intHandlerArray[(intType)](); \ }} while (0) - +*/ /*! interrupt callback type for the handler */ typedef void (*intHandler_t)(void); @@ -65,7 +75,7 @@ void intInit( * Enables all interrupts globally. * */ -void intEnableAll(); +void intEnableGlobal(); /** * @brief Disable all Interrups @@ -73,7 +83,7 @@ void intEnableAll(); * Dissables all interrupts globally exept the non maskable ones given by the architecture of the * MCU. */ -void intDisableAll(); +void intDisableGlobal(); /** * @brief Enable one interrupt type