-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
External interrupt/event controller -fixes #35
- Loading branch information
1 parent
5d423a2
commit 1a92c38
Showing
5 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/**********************************************************/ | ||
/* Author : Gehad Elkoumy */ | ||
/* Date : 6 DEC 2022 */ | ||
/* Version : V01 */ | ||
/**********************************************************/ | ||
#ifndef EXTI_CONFIG_H | ||
#define EXTI_CONFIG_H | ||
|
||
|
||
/*options : from LINE0 to LINE15*/ | ||
#define EXTI_LINE LINE0 | ||
|
||
|
||
|
||
/*options : RISING | ||
FALLING | ||
ON_CHANGE */ | ||
#define EXTI_MODE FALLING | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/**********************************************************/ | ||
/* Author : Gehad Elkoumy */ | ||
/* Date : 6 DEC 2022 */ | ||
/* Version : V01 */ | ||
/**********************************************************/ | ||
#ifndef EXTI_INTERFACE_H | ||
#define EXTI_INTERFACE_H | ||
|
||
|
||
void MEXTI_voidInit(); | ||
void MEXTI_voidEnableEXTI(u8 Copy_u8EXTILine); | ||
void MEXTI_voidDisableEXTI(u8 Copy_u8EXTILine); | ||
void MEXTI_voidSoftwareTrigger(u8 Copy_u8EXTILine); | ||
void MEXTI_voidSetSignalLatch(u8 Copy_u8EXTILine , u8 Copy_u8EXTIMode); | ||
|
||
/*pointer to function*/ | ||
void EXTI_voidSetCallBack(void (*ptr) (void) , u8 Copy_u8EXTILine); | ||
|
||
|
||
#define LINE0 0 | ||
#define LINE1 1 | ||
#define LINE2 2 | ||
#define LINE3 3 | ||
#define LINE4 4 | ||
#define LINE5 5 | ||
#define LINE6 6 | ||
#define LINE7 7 | ||
#define LINE8 8 | ||
#define LINE9 9 | ||
#define LINE10 10 | ||
#define LINE11 11 | ||
#define LINE12 12 | ||
#define LINE13 13 | ||
#define LINE14 14 | ||
#define LINE15 15 | ||
|
||
|
||
|
||
#define RISING 0 | ||
#define FALLING 1 | ||
#define ON_CHANGE 2 /*any change (rising & falling)*/ | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/**********************************************************/ | ||
/* Author : Gehad Elkoumy */ | ||
/* Date : 6 DEC 2022 */ | ||
/* Version : V01 */ | ||
/**********************************************************/ | ||
#ifndef EXTI_PRIVATE_H | ||
#define EXTI_PRIVATE_H | ||
|
||
/*must be ordered*/ | ||
typedef struct{ | ||
volatile u32 IMR; | ||
volatile u32 EMR; | ||
volatile u32 RTSR; | ||
volatile u32 FTSR; | ||
volatile u32 SWIER; | ||
volatile u32 PR; | ||
|
||
}EXTI_t; | ||
|
||
/*without dereference as it act as pointer*/ | ||
#define EXTI ((volatile EXTI_t *) 0x40010400 ) | ||
|
||
static void (*EXTI_GlobalPtr[16]) (void) ; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
/**********************************************************/ | ||
/* Author : Gehad Elkoumy */ | ||
/* Date : 6 DEC 2022 */ | ||
/* Version : V01 */ | ||
/**********************************************************/ | ||
|
||
#include "STD_TYPES.h" | ||
#include "BIT_MATH.h" | ||
|
||
#include "EXTI_interface.h" | ||
#include "EXTI_config.h" | ||
#include "EXTI_private.h" | ||
|
||
|
||
|
||
void MEXTI_voidInit() | ||
{ | ||
#if EXTI_MODE == RISING | ||
SET_BIT(EXTI -> RTSR , EXTI_LINE); | ||
#elif EXTI_MODE == FALLING | ||
SET_BIT(EXTI -> FTSR , EXTI_LINE); | ||
#elif EXTI_MODE == ON_CHANGE | ||
SET_BIT(EXTI -> RTSR , EXTI_LINE); | ||
SET_BIT(EXTI -> FTSR , EXTI_LINE); | ||
#else | ||
#error "Wrong Mode" | ||
#endif | ||
|
||
/*Disable interrupt*/ | ||
CLR_BIT(EXTI -> IMR , EXTI_LINE); | ||
} | ||
|
||
|
||
void MEXTI_voidEnableEXTI(u8 Copy_u8EXTILine) | ||
{ | ||
SET_BIT(EXTI -> IMR , Copy_u8EXTILine); | ||
} | ||
|
||
|
||
void MEXTI_voidDisableEXTI(u8 Copy_u8EXTILine) | ||
{ | ||
CLR_BIT(EXTI -> IMR , Copy_u8EXTILine); | ||
} | ||
|
||
|
||
void MEXTI_voidSoftwareTrigger(u8 Copy_u8EXTILine) | ||
{ | ||
SET_BIT(EXTI -> IMR , Copy_u8EXTILine); | ||
CLR_BIT(EXTI -> PR , Copy_u8EXTILine); | ||
SET_BIT(EXTI -> SWIER , Copy_u8EXTILine); | ||
} | ||
|
||
|
||
/*changing mode & line in run time*/ | ||
void MEXTI_voidSetSignalLatch(u8 Copy_u8EXTILine , u8 Copy_u8EXTIMode) | ||
{ | ||
switch(Copy_u8EXTIMode) | ||
{ | ||
case RISING : | ||
SET_BIT(EXTI -> RTSR , Copy_u8EXTILine); | ||
break; | ||
|
||
case FALLING : | ||
SET_BIT(EXTI -> FTSR , Copy_u8EXTILine); | ||
break; | ||
|
||
case ON_CHANGE : | ||
SET_BIT(EXTI -> RTSR , Copy_u8EXTILine); | ||
SET_BIT(EXTI -> FTSR , Copy_u8EXTILine); | ||
break; | ||
} | ||
SET_BIT(EXTI -> IMR , Copy_u8EXTILine); | ||
} | ||
|
||
|
||
void EXTI_voidSetCallBack(void (*ptr) (void) , u8 Copy_u8EXTILine) | ||
{ | ||
EXTI_GlobalPtr[Copy_u8EXTILine] = ptr; | ||
} | ||
|
||
|
||
void EXTI0_IRQHandler(void) | ||
{ | ||
EXTI_GlobalPtr[0](); | ||
/*clear pending bit*/ | ||
SET_BIT(EXTI -> PR , 0); | ||
} | ||
|
||
void EXTI1_IRQHandler(void) | ||
{ | ||
EXTI_GlobalPtr[1](); | ||
/*clear pending bit*/ | ||
SET_BIT(EXTI -> PR , 1); | ||
} | ||
|
||
void EXTI2_IRQHandler(void) | ||
{ | ||
EXTI_GlobalPtr[2](); | ||
/*clear pending bit*/ | ||
SET_BIT(EXTI -> PR , 2); | ||
} | ||
|
||
void EXTI3_IRQHandler(void) | ||
{ | ||
EXTI_GlobalPtr[3](); | ||
/*clear pending bit*/ | ||
SET_BIT(EXTI -> PR , 3); | ||
} | ||
|
||
void EXTI4_IRQHandler(void) | ||
{ | ||
EXTI_GlobalPtr[4](); | ||
/*clear pending bit*/ | ||
SET_BIT(EXTI -> PR , 4); | ||
} | ||
|
||
void EXTI9_5_IRQHandler(void) | ||
{ | ||
u8 PinValue_5 , PinValue_6 , PinValue_7 , PinValue_8 , PinValue_9; | ||
|
||
PinValue_5 = GET_BIT(EXTI->PR,5); | ||
PinValue_6 = GET_BIT(EXTI->PR,6); | ||
PinValue_7 = GET_BIT(EXTI->PR,7); | ||
PinValue_8 = GET_BIT(EXTI->PR,8); | ||
PinValue_9 = GET_BIT(EXTI->PR,9); | ||
|
||
if (PinValue_5 == 1) | ||
{ | ||
EXTI_GlobalPtr[5](); | ||
SET_BIT(EXTI -> PR , 5); | ||
} | ||
|
||
if (PinValue_6 == 1) | ||
{ | ||
EXTI_GlobalPtr[6](); | ||
SET_BIT(EXTI -> PR , 6); | ||
} | ||
|
||
if (PinValue_7 == 1) | ||
{ | ||
EXTI_GlobalPtr[7](); | ||
SET_BIT(EXTI -> PR , 7); | ||
} | ||
|
||
if (PinValue_8 == 1) | ||
{ | ||
EXTI_GlobalPtr[8](); | ||
SET_BIT(EXTI -> PR , 8); | ||
} | ||
|
||
if (PinValue_9 == 1) | ||
{ | ||
EXTI_GlobalPtr[9](); | ||
SET_BIT(EXTI -> PR , 9); | ||
} | ||
|
||
} | ||
|
||
void EXTI15_10_IRQHandler(void) | ||
{ | ||
u8 PinValue_10 , PinValue_11 , PinValue_12 , PinValue_13 , PinValue_14 , PinValue_15; | ||
|
||
PinValue_10 = GET_BIT(EXTI->PR,10); | ||
PinValue_11 = GET_BIT(EXTI->PR,11); | ||
PinValue_12 = GET_BIT(EXTI->PR,12); | ||
PinValue_13 = GET_BIT(EXTI->PR,13); | ||
PinValue_14 = GET_BIT(EXTI->PR,14); | ||
PinValue_15 = GET_BIT(EXTI->PR,14); | ||
|
||
if (PinValue_10 == 1) | ||
{ | ||
EXTI_GlobalPtr[10](); | ||
SET_BIT(EXTI -> PR , 10); | ||
} | ||
|
||
if (PinValue_11 == 1) | ||
{ | ||
EXTI_GlobalPtr[11](); | ||
SET_BIT(EXTI -> PR , 11); | ||
} | ||
|
||
if (PinValue_12 == 1) | ||
{ | ||
EXTI_GlobalPtr[12](); | ||
SET_BIT(EXTI -> PR , 12); | ||
} | ||
|
||
if (PinValue_13 == 1) | ||
{ | ||
EXTI_GlobalPtr[13](); | ||
SET_BIT(EXTI -> PR , 13); | ||
} | ||
|
||
if (PinValue_14 == 1) | ||
{ | ||
EXTI_GlobalPtr[14](); | ||
SET_BIT(EXTI -> PR , 14); | ||
} | ||
|
||
if (PinValue_15 == 1) | ||
{ | ||
EXTI_GlobalPtr[15](); | ||
SET_BIT(EXTI -> PR , 15); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* main.c | ||
* | ||
* Created on: Feb 18, 2023 | ||
* Author: HP | ||
*/ | ||
|
||
#include"STD_TYPES.h" | ||
#include"BIT_MATH.h" | ||
|
||
#include"RCC_interface.h" | ||
#include"DIO_interface.h" | ||
#include"NVIC_interface.h" | ||
#include"AFIO_interface.h" | ||
#include"EXTI_interface.h" | ||
|
||
void TakeAction8(void) | ||
{ | ||
MGPIO_VoidSetPinValue(GPIOA,PIN0,HIGH); | ||
} | ||
|
||
void TakeAction9(void) | ||
{ | ||
MGPIO_VoidSetPinValue(GPIOA,PIN1,HIGH); | ||
} | ||
|
||
|
||
void main (void) | ||
{ | ||
/*initialize clocks*/ | ||
RCC_voidInitSysClock(); | ||
/*Enable GPIOA clock */ | ||
RCC_voidEnableClock(RCC_APB2,2); | ||
//RCC_voidEnableClock(RCC_APB2,3); | ||
/*Enable AFIO clock */ | ||
RCC_voidEnableClock(RCC_APB2,0); | ||
|
||
/*AFIO*//**/ | ||
MAFIO_voidSetEXTIConfiguration(LINE8 , AFIOA); | ||
MAFIO_voidSetEXTIConfiguration(LINE9 , AFIOA); | ||
|
||
|
||
EXTI_voidSetCallBack(TakeAction9 , LINE9); | ||
EXTI_voidSetCallBack(TakeAction8 , LINE8); | ||
|
||
/*pin modes*/ | ||
MGPIO_VoidSetPinDirection(GPIOA,PIN8,INPUT_PULLUP_PULLDOWN); | ||
MGPIO_VoidSetPinDirection(GPIOA,PIN9,INPUT_PULLUP_PULLDOWN); | ||
|
||
MGPIO_VoidSetPinDirection(GPIOA,PIN0,OUTPUT_2MHZ_PP); | ||
MGPIO_VoidSetPinDirection(GPIOA,PIN1,OUTPUT_2MHZ_PP); | ||
|
||
MGPIO_VoidSetPinValue(GPIOA,PIN8,HIGH); | ||
MGPIO_VoidSetPinValue(GPIOA,PIN9,HIGH); | ||
|
||
/*initialize EXTI*/ | ||
MEXTI_voidInit(); | ||
MEXTI_voidSetSignalLatch(LINE8 , FALLING); | ||
MEXTI_voidSetSignalLatch(LINE9 , FALLING); | ||
|
||
|
||
/*Enable EXTI0 interrupt from NVIC*/ | ||
MNVIC_voidEnableInterrupt(23); | ||
/*set priority for EXT0*/ | ||
//MNVIC_voidSetPriority(23,1,0); | ||
|
||
|
||
|
||
while(1) | ||
{ | ||
|
||
} | ||
} | ||
|