time.h
#ifndef _S3C2451_TIMER_H
#define _S3C2451_TIMER_H
#include "typedef.h"
typedef struct{
U32 TCFG0;
U32 TCFG1;
U32 TCON;
U32 TCNTB0;
U32 TCMPB0;
U32 TCNTO0;
U32 TCNTB1;
U32 TCMPB1;
U32 TCNTO1;
U32 TCNTB2;
U32 TCMPB2;
U32 TCNTO2;
U32 TCNTB3;
U32 TCMPB3;
U32 TCNTO3;
U32 TCNTB4;
U32 TCNTO4;
}volatile *TIM_MemMapPtr;
#define TIM_BASE_PTR ((TIM_MemMapPtr)0x51000000)
typedef enum{
time_ch0=0,
time_ch1,
time_ch2,
time_ch3,
time_ch4
}TIM_typedef;
typedef struct{
unsigned int TIM_Scale;
unsigned int TIM_Prescale;
unsigned int TIM_Countval;
unsigned int TIM_Compareval;
}TIM_basetypedef;
extern void TIM_init(TIM_typedef timx,TIM_basetypedef tim_basetypedef);
extern void TIM_Interrupt_init(TIM_typedef timx,U32 addr);
extern U16 TIM_getcount(TIM_typedef timx);
#endif
timer.c
#include "s3c2451_timer.h"
#include "s3c2451_vector.h"
void TIM_init(TIM_typedef timx,TIM_basetypedef tim_basetypedef)
{
TIM_BASE_PTR->TCFG0 &=~0xff;
TIM_BASE_PTR->TCFG0 |=199;
TIM_BASE_PTR->TCFG1 &=~0X0F;
TIM_BASE_PTR->TCFG1 |=0X2;
TIM_BASE_PTR->TCNTB0=41250;
TIM_BASE_PTR->TCMPB0=20625;
TIM_BASE_PTR->TCON |=(1<<3);
TIM_BASE_PTR->TCON |=(1<<1);
TIM_BASE_PTR->TCON |=(1<<0);
TIM_BASE_PTR->TCON &=~(1<<1);
}
U16 TIM_getcount(TIM_typedef timx)
{
return TIM_BASE_PTR->TCNTO0;
}
void TIM_Interrupt_init(TIM_typedef timx,U32 addr)
{
if(timx==time_ch0)
{
pISR_TIMER0=addr;
}
}