Started working on pin interrupt, working example on main.c. transfering it to pin.c

master
Kerem Yollu 2 years ago
parent bbb2fefe71
commit e3c1298f55

@ -23,7 +23,59 @@ extern "C" {
#include "hardwareDescription.h"
/*! interrupt types. These act as indexes for the */
typedef enum {
PINX0_RISING_EDGE,
PINX0_FALLING_EDGE,
PINX0_BOTH_EDGE,
PINX1_RISING_EDGE,
PINX1_FALLING_EDGE,
PINX1_BOTH_EDGE,
PINX2_RISING_EDGE,
PINX2_FALLING_EDGE,
PINX2_BOTH_EDGE,
PINX3_RISING_EDGE,
PINX3_FALLING_EDGE,
PINX3_BOTH_EDGE,
PINX4_RISING_EDGE,
PINX4_FALLING_EDGE,
PINX4_BOTH_EDGE,
PINX5_RISING_EDGE,
PINX5_FALLING_EDGE,
PINX5_BOTH_EDGE,
PINX6_RISING_EDGE,
PINX6_FALLING_EDGE,
PINX6_BOTH_EDGE,
PINX6_BOTH_EDGE,
PINX7_RISING_EDGE,
PINX7_FALLING_EDGE,
PINX7_BOTH_EDGE,
PINX8_RISING_EDGE,
PINX8_FALLING_EDGE,
PINX8_BOTH_EDGE,
PINX9_RISING_EDGE,
PINX9_FALLING_EDGE,
PINX9_BOTH_EDGE,
PINX10_RISING_EDGE,
PINX10_FALLING_EDGE,
PINX10_BOTH_EDGE,
PINX11_RISING_EDGE,
PINX11_FALLING_EDGE,
PINX11_BOTH_EDGE,
PINX12_RISING_EDGE,
PINX12_FALLING_EDGE,
PINX12_BOTH_EDGE,
PINX13_RISING_EDGE,
PINX13_FALLING_EDGE,
PINX13_BOTH_EDGE,
PINX14_RISING_EDGE,
PINX14_FALLING_EDGE,
PINX14_BOTH_EDGE,
PINX15_RISING_EDGE,
PINX15_FALLING_EDGE,
PINX15_BOTH_EDGE,
TIM1_BREAK,
TIM1_UPDATE,
TIM1_TRIGGER,
@ -85,9 +137,6 @@ typedef enum {
intTypeEND
}intrType_t;
//static uint32_t intHandlerList[intTypeEND]={0};
extern volatile void (*intHandlerArray[intTypeEND])();
extern const uint8_t interruptTypeIndexList[intTypeEND];
#ifdef __cplusplus
}

@ -2,17 +2,60 @@
#include "hwd_interrupt.h"
#include "pin.h"
/**
* @brief Default Handler
*
* This handler is called when no interrupt handler was set
*/
static void defaultHandler(){};
volatile void (*intHandlerArray[intTypeEND])() = {NULL};
const uint8_t interruptTypeIndexList[intTypeEND] =
{
EXTI0_1_IRQn,
EXTI0_1_IRQn,
EXTI0_1_IRQn,
EXTI0_1_IRQn,
EXTI0_1_IRQn,
EXTI0_1_IRQn,
EXTI2_3_IRQn,
EXTI2_3_IRQn,
EXTI2_3_IRQn,
EXTI2_3_IRQn,
EXTI2_3_IRQn,
EXTI2_3_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
EXTI4_15_IRQn,
TIM1_BRK_UP_TRG_COM_IRQn,
TIM1_BRK_UP_TRG_COM_IRQn,
TIM1_BRK_UP_TRG_COM_IRQn,
@ -78,13 +121,14 @@ void intInit(
intHandler_t handler,
uint8_t priority)
{
NVIC_SetPriority(interruptTypeIndexList[intType], priority);
// check if index is correct
if(intType >= intTypeEND) return;
//intHandlerList[intType] = handler;
intDisableGlobal();
NVIC_SetPriority(interruptTypeIndexList[intType], priority);
intHandlerArray[intType] = handler;
}
void intEnableGlobal()

@ -0,0 +1,68 @@
#include "delay.h"
#include "pin.h"
#include "deviceSetup.h"
#include "interrupt.h"
#include "timer.h"
void blinkiTask()
{
//pinToggle(pinB3);
}
void EXTI4_15_IRQHandler(void)
{
if(EXTI->PR & EXTI_PR_PR4)
{
EXTI->PR |= EXTI_PR_PR4;
pinToggle(pinB3);
}
}
void pinB4IntSetup()
{
SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI4_PB;
EXTI->FTSR |= EXTI_FTSR_TR4;
EXTI->RTSR |= EXTI_FTSR_TR4;
EXTI->IMR |= EXTI_IMR_IM4;
NVIC_EnableIRQ(EXTI4_15_IRQn);
NVIC_SetPriority(EXTI4_15_IRQn,1);
}
void declareInterrupts()
{
/*
timerInitCounter(timer_2,(8E6/40E3)-1, 5000-1, upCounting);
timerEnableInterrupt(timer_2,TIM2_UPDATE);
timerStart(timer_2);
intInit(TIM2_UPDATE, blinkiTask, 1);
intEnable(TIM2_UPDATE);
*/
intDisableGlobal();
pinB4IntSetup();
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);
pinConfig(pinB4, input, floating, none, def_speed);
declareInterrupts();
while(1);
return 1;
}

@ -0,0 +1,15 @@
#ifndef MAIN_H
#define MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#ifdef __cplusplus
}
#endif
#endif /* MAIN_H */

@ -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)

@ -183,6 +183,17 @@ void pinHardwareInfo(pinNo_t pinNo);
*/
void pinThrowError(pinErrors_t error);
/**
* @brief Initiates the interrupt functionality for the given pin. thjis function alone is not
*
*
*/
void pinEnableInterrupt(pinNo_t pin, intrType_t pinInterrupt);
#ifdef __cplusplus
}
#endif

@ -33,18 +33,11 @@ extern "C" {
}
/* 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);
//void (*intHandlerArray[intTypeEND])()={NULL};
extern volatile void (*intHandlerArray[intTypeEND])();
extern const uint8_t interruptTypeIndexList[intTypeEND];
/**
* @brief Initialize Interrupt

Loading…
Cancel
Save