Compare commits

...

9 Commits

@ -297,6 +297,41 @@ static const uint8_t i2cBus_Rst_bitPos[MAX_I2C_CHANNEL_COUNT] = {
};
// Interrupts
/*! interrupt types. These act as indexes for the */
typedef enum {
TIM2_UPDATE,
TIM2_COUNTERCOMPARE_1,
TIM2_COUNTERCOMPARE_2,
TIM2_COUNTERCOMPARE_3,
TIM2_COUNTERCOMPARE_4,
TIM2_TRIGGER,
TIM2_CAPTURECOMPARE_1,
TIM2_CAPTURECOMPARE_2,
TIM2_CAPTURECOMPARE_3,
TIM2_CAPTURECOMAPRE_4,
intTypeEND
}intrType_t;
uint32_t intHandlerList[intTypeEND]={
0,0,0,0,0,0,0,0,0,0};
static const uint8_t interruptTypeIndexList[intTypeEND] =
{
TIM2_IRQn,
TIM2_IRQn,
TIM2_IRQn,
TIM2_IRQn,
TIM2_IRQn,
TIM2_IRQn,
TIM2_IRQn,
TIM2_IRQn,
TIM2_IRQn,
TIM2_IRQn
};
#ifdef __cplusplus
}
#endif

@ -0,0 +1,97 @@
#include "interrupt.h"
static void defaultHandler(){};
// pointers to dedicated interrupt handlers
void intInit(
intrType_t intType,
intHandler_t handler,
uint8_t priority)
{
NVIC_SetPriority(interruptTypeIndexList[intType], priority);
// TODO: add index ceck!
intHandlerList[intType] = (uint32_t)handler;
}
void intEnableAll()
{
__enable_irq();
}
void intDissableAll()
{
__disable_irq();
}
void intEnable(
intrType_t intType)
{
NVIC_EnableIRQ(interruptTypeIndexList[intType]);
}
void intDissable(
intrType_t intType)
{
NVIC_DisableIRQ(interruptTypeIndexList[intType]);
}
// Interrupt service routines
void TIM2_IRQHandler()
{
if(TIM2->SR & TIM_SR_UIF) {
// clear flag
TIM2-> SR &= ~TIM_SR_UIF;
//TODO: call handler here
((intHandler_t)(intHandlerList[TIM2_UPDATE]))();
}
if(TIM2->SR & TIM_SR_CC1IF) {
TIM2-> SR &= ~TIM_SR_CC1IF;
}
if(TIM2->SR & TIM_SR_CC2IF) {
TIM2-> SR &= ~TIM_SR_CC2IF;
}
if(TIM2->SR & TIM_SR_CC3IF) {
TIM2-> SR &= ~TIM_SR_CC3IF;
}
if(TIM2->SR & TIM_SR_CC4IF) {
TIM2-> SR &= ~TIM_SR_CC4IF;
}
if(TIM2->SR & TIM_SR_TIF) {
TIM2-> SR &= ~TIM_SR_TIF;
}
if(TIM2->SR & TIM_SR_CC1OF) {
TIM2-> SR &= ~TIM_SR_CC1OF;
}
if(TIM2->SR & TIM_SR_CC2OF) {
TIM2-> SR &= ~TIM_SR_CC2OF;
}
if(TIM2->SR & TIM_SR_CC3OF) {
TIM2-> SR &= ~TIM_SR_CC3OF;
}
if(TIM2->SR & TIM_SR_CC4OF) {
TIM2-> SR &= ~TIM_SR_CC4OF;
}
}

@ -75,3 +75,4 @@ list(APPEND EXTRA_LIBS sub::max7219)
list(APPEND EXTRA_LIBS sub::spi)
list(APPEND EXTRA_LIBS sub::i2c)
list(APPEND EXTRA_LIBS sub::pin)
list(APPEND EXTRA LIBS sub::interrupt)

@ -41,5 +41,12 @@ target_compile_definitions(TIMER PRIVATE ${C_DEFS})
target_include_directories(TIMER PUBLIC ${PERIFERALS_DIR} ${CSL_INCLUDES})
add_library(sub::timer ALIAS TIMER)
add_library(INTERRUPT ${CSL_SOURCES}/imp_interrupt.c)
target_compile_options(INTERRUPT PRIVATE ${C_FLAGS})
target_compile_definitions(INTERRUPT PRIVATE ${C_DEFS})
target_include_directories(INTERRUPT PUBLIC ${PERIFERALS_DIR} ${CSL_INCLUDES})
add_library(sub::interrupt ALIAS INTERRUPT)

@ -0,0 +1,2 @@
#include "interrupt.h"

@ -0,0 +1,100 @@
/**
**************************************************************************************************
* @file interrupt.h
* @author Kerem Yollu & Edwin Koch
* @date 30.10.2022
* @version 1.0
**************************************************************************************************
* @brief This is the genral interface for interrupts.
*
* **Detailed Description :**
* This the spi interface and belongs to the interface layer.
*
**************************************************************************************************
*/
#ifndef _INTERRUPT_H_
#define _INTERRUPT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "hardwareDescription.h"
/*! interrupt callback type for the handler */
typedef void (*intHandler_t)(void);
/**
* @brief Initialize Interrupt
*
* Initialize Interrupt by choosing the interrupt type, passing the functionpointer to the handler
* and selecting the priority.
* The interrupt will be automatically enabled and will be able to run after intEnableAll is
* called. If the interrupt should only run at a specific even one can controll it by calling
* intDissable prior to calling intEnableAll and calling intEnbale at a specific point and
* dissabling it again with intDisable
* When the desired interrupt occures the handler will be called.
* The interrupt type and priority level is dependent on the architecture of the target MCU.
* To find more information on what can be done one must read the documentation specific to the
* target MCU.
*
* @param intType interrupt type
* @param handler the interrupthandler
* @param priority the interrupt priority
*/
void intInit(
intrType_t intType,
intHandler_t handler,
uint8_t priority);
/**
* @brief Enable all Interrupts
*
* Enables all interrupts globally.
*
*/
void intEnableAll();
/**
* @brief Disable all Interrups
*
* Dissables all interrupts globally exept the non maskable ones given by the architecture of the
* MCU.
*/
void intDisableAll();
/**
* @brief Enable one interrupt type
*
* The Interrupt for the desired interrupt will be enabled. This means that interrupt of that
* type will occure. To revert this intDisable musst be called.
* It can be called when interrupts are are globally allowed or when disabled.
*
* @param intType interrupt type
*/
void intEnable(
intrType_t intType);
/**
* @brief Dissable one interrupt type
*
* The Interrupt for the desired interrupt will be disabled. This means that no interrupt of that
* type will occure. To revert this intEnable musst be called.
* It can be called when interrupts are are globally allowed or when dissabled.
* It will not stop other all interrupts in contrast to intDissableAll.
*
* @param intType interrupt type
*/
void intDisable(
intrType_t intType);
#ifdef __cplusplus
}
#endif
#endif

@ -3,6 +3,14 @@
#include "deviceSetup.h"
#include "usart.h"
#include "ascii.h"
#include "interrupt.h"
#include "timer.h"
void toggleLED()
{
pinToggle(pinB3);
}
int main(int argc, char *argv[])
{
@ -43,6 +51,33 @@ int main(int argc, char *argv[])
print_Usart(usart2, "\n\r");
print_Usart(usart2, "All is working fine\n\r");
for(i = 0 ; i < 10 ; i++) {
delayMs(100);
pinToggle(pinB3);
delayMs(200);
pinToggle(pinB3);
delayMs(300);
pinToggle(pinB3);
delayMs(400);
pinToggle(pinB3);
delayMs(500);
}
pinWrite(pinB3,0);
timerInitCounter(timer_2,(8E6/20E3)-1,10000-1,upCounting);
// TODO: Needs to be implemented into imp_interrupt.c
//TIM2->EGR = TIM_EGR_UG;
TIM2->DIER = TIM_DIER_UIE;
intInit(TIM2_UPDATE,toggleLED,2);
intEnable(TIM2_UPDATE);
timerSart(timer_2);
while(1);
while(1)
{
delayMs(100);

Loading…
Cancel
Save