I tried to write the code for PIT Timer but it is not working.can anyone modify the code so that the program can be run
#include "MKE02Z2.h"
#define FALSE 0
#define TRUE 1
#define LED0_Init() GPIOB->PDDR |= (1<<25) /*! RED Light */
#define LED0_Toggle() GPIOB->PTOR = (1<<25)
__STATIC_INLINE void PIT_Enable(void)
{
PIT->MCR &= ~PIT_MCR_MDIS_MASK;
}
__STATIC_INLINE void PIT_ChannelEnableInt(uint8_t u8channel)
{
PIT->CHANNEL[u8channel].TCTRL |= PIT_TCTRL_TIE_MASK;
}
__STATIC_INLINE void PIT_ChannelEnableChain(uint8_t u8channel)
{
PIT->CHANNEL[u8channel].TCTRL |= PIT_TCTRL_CHN_MASK;
}
__STATIC_INLINE void PIT_ChannelEnable(uint8_t u8channel)
{
PIT->CHANNEL[u8channel].TCTRL |= PIT_TCTRL_TEN_MASK;
}
enum
{
PIT_CHANNEL0=0, // PIT Channel 0
PIT_CHANNEL1 // PIT Channel 1
};
typedef struct
{
uint8_t bFreeze :1;
uint8_t bModuleDis :1;
uint8_t bReversed0 :1;
uint8_t bReversed1 :5;
uint8_t bTimerEn :1;
uint8_t bInterruptEn :1;
uint8_t bChainMode :1;
uint8_t bReversed2 :5;
uint8_t bFlag :1;
uint8_t bReversed3 :7;
uint32_t u32LoadValue ;
}PIT_ConfigType, *PIT_ConfigPtr;
#ifndef NULL
#define NULL (void *) 0
#endif
typedef void (*PIT_CallbackType)(void);
PIT_CallbackType PIT_Callback[2] = {(PIT_CallbackType)NULL};
void PIT_SetLoadVal(uint8_t u8channel, uint32_t u32LoadValue)
{
PIT->CHANNEL[u8channel].LDVAL = u32LoadValue;
}
void PIT_SetCallback(uint8_t u8channel_No, PIT_CallbackType pfnCallback)
{
PIT_Callback[u8channel_No] = pfnCallback;
}
void PIT_Init(uint8_t u8channel_No, PIT_ConfigType *pConfig)
{
SIM->SCGC |= SIM_SCGC_PIT_MASK; // enable clock to PIT
if(pConfig->bModuleDis == 0) PIT_Enable(); // enable PIT Module
PIT_SetLoadVal(u8channel_No, pConfig->u32LoadValue);
if(pConfig->bInterruptEn)
{
if(u8channel_No) NVIC_EnableIRQ(PIT_CH1_IRQn);
else NVIC_EnableIRQ(PIT_CH0_IRQn);
PIT_ChannelEnableInt(u8channel_No);
}
else NVIC_DisableIRQ(PIT_CH0_IRQn);
if(pConfig->bChainMode) PIT_ChannelEnableChain(u8channel_No);
if(pConfig->bTimerEn) PIT_ChannelEnable(u8channel_No);
}
void PIT_Task(void);
int main(void)
{
uint32_t u32LoadValue0, u32LoadValue1;
PIT_ConfigType sPITConfig0, sPITConfig1;
PIT_ConfigType *pPIT_Config1 = &sPITConfig1;
PIT_ConfigType *pPIT_Config0 = &sPITConfig0;
LED0_Init();
u32LoadValue0 = 0xF423F;
u32LoadValue1 = 0x10;
/*Configure PIT channel 1 in Chain Mode, enable interrupt and Timer*/
pPIT_Config1->u32LoadValue = u32LoadValue1;
pPIT_Config1->bFreeze = FALSE;
pPIT_Config1->bModuleDis = FALSE;
pPIT_Config1->bInterruptEn = TRUE;
pPIT_Config1->bChainMode = FALSE;
pPIT_Config1->bTimerEn = TRUE;
/*Configure PIT channel 0, only enable Timer*/
pPIT_Config0->u32LoadValue = u32LoadValue0;
pPIT_Config0->bFreeze = FALSE;
pPIT_Config0->bModuleDis = FALSE; /*!< enable PIT module */
pPIT_Config0->bInterruptEn = FALSE;
pPIT_Config0->bChainMode = FALSE;
pPIT_Config0->bTimerEn = TRUE;
PIT_Init(PIT_CHANNEL0, pPIT_Config0);
PIT_Init(PIT_CHANNEL1, pPIT_Config1);
PIT_SetCallback(PIT_CHANNEL1,PIT_Task);
/* This for loop should be replaced. By default this loop allows a single stepping. */
for (;;) {
}
/* Never leave main */
return 0;
}
void PIT_Task(void)
{
LED0_Toggle(); /*!< toggle LED1 */
}