#include
#include
#include "nkintr.h"
#include "pkfuncs.h"
#include "s3c2440a_intr.h"
#include "s3c2440a_base_regs.h"
#include "s3c2440a_ioport.h"
#include "s3c2440a_pwm.h"
//#include "oal_io.h"
#define BUFSIZE 256
static DWORD INTIrq = IRQ_TIMER1; // Determined by SMDK2410 board layout.
static DWORD INTIntr = SYSINTR_UNDEFINED;
volatile S3C2440A_IOPORT_REG *v_pIOPregs;
volatile S3C2440A_PWM_REG *v_pPWMregs;
volatile S3C2440A_INTR_REG *v_pINTregs;
static HANDLE Timer_Event;
static HANDLE Timer_Thread;
int i1 = 0;
int dat = 1;
WCHAR achBuffer[BUFSIZE];
BOOL WINAPI
DllEntryPoint(HANDLE hinstDLL,
DWORD dwReason,
LPVOID lpvReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
RETAILMSG(1,(TEXT("timer:::::*******DLL_PROCESS_ATTACH******\n")));
break;
case DLL_THREAD_ATTACH:
RETAILMSG(1,(TEXT("timer:::::******DLL_THREAD_ATTACH*******\n")));
break;
case DLL_THREAD_DETACH:
RETAILMSG(1,(TEXT("timer:::::******DLL_THREAD_DETACH******\n")));
break;
case DLL_PROCESS_DETACH:
RETAILMSG(1,(TEXT("timer:::::******DLL_PROCESS_DETACH******\n")));
break;
}
return true;
}
BOOL TimerINTInit()
{
RETAILMSG(1,(TEXT("timer1::::**********KeyInt_Setting***********\r\n")));
//GPIO
v_pIOPregs->GPGCON &=~(0x3<<(2*8)); //set led port
v_pIOPregs->GPGCON |= (0x2<<(2*8));
//INTR
v_pINTregs->INTMSK &=~(0x00000001<<11); //0 打开timer1 中断
v_pINTregs->INTMOD &=~(0x00000001<<11); //0 timer1 irq中断
//Timer2
v_pPWMregs->TCNTB1 = 0x00004e20;
v_pPWMregs->TCMPB1 = 0x00000000;
// v_pPWMregs->TCFG0
v_pPWMregs->TCFG1 &= 0xff0fff0f; //timer1 2分频
v_pPWMregs->TCON |=(0x00000001<<9); //手动更新
v_pPWMregs->TCON |=(0x00000001<<11); //自动装载
v_pPWMregs->TCON |=(0x00000001<<8); //启动
v_pPWMregs->TCON &=~(0x00000001<<9); //清手动更新
return TRUE;
}
void InitializeAddresses()
{
///////////////////GPIO
v_pIOPregs = (volatile S3C2440A_IOPORT_REG *) VirtualAlloc(0,sizeof(S3C2440A_IOPORT_REG),MEM_RESERVE, PAGE_NOACCESS);
if(v_pIOPregs == NULL)
{
RETAILMSG(1,(TEXT("timer1::::For S2440IOP: VirtualAlloc v_pIOPregs failed!\r\n")));
}
else
{
RETAILMSG(1,(TEXT("timer1:::: :v_pIOPregs == %d\r\n"),v_pIOPregs));
if(!VirtualCopy((PVOID)v_pIOPregs,(PVOID)(S3C2440A_BASE_REG_PA_IOPORT>>8),sizeof(S3C2440A_IOPORT_REG),PAGE_PHYSICAL|PAGE_READWRITE|PAGE_NOCACHE ))
{
RETAILMSG(1,(TEXT("timer1::::For S2440IOP: VirtualCopy v_pIOPregs failed!\r\n")));
}
}
////////////////////PWM
v_pPWMregs = (volatile S3C2440A_PWM_REG *) VirtualAlloc(0,sizeof(S3C2440A_PWM_REG),MEM_RESERVE, PAGE_NOACCESS);
if(v_pPWMregs == NULL)
{
RETAILMSG(1,(TEXT("timer1::::For S2440IOP: VirtualAlloc v_pPWMregs failed!\r\n")));
}
else
{
RETAILMSG(1,(TEXT("timer1:::: :v_pPWMregs == %d\r\n"),v_pPWMregs));
if(!VirtualCopy((PVOID)v_pPWMregs,(PVOID)(S3C2440A_BASE_REG_PA_PWM>>8),sizeof(S3C2440A_PWM_REG),PAGE_PHYSICAL|PAGE_READWRITE|PAGE_NOCACHE ))
{
RETAILMSG(1,(TEXT("timer1::::For S2440IOP: VirtualCopy v_pPWMregs failed!\r\n")));
}
}
////////////////////INTR
v_pINTregs = (volatile S3C2440A_INTR_REG *) VirtualAlloc(0,sizeof(S3C2440A_INTR_REG),MEM_RESERVE, PAGE_NOACCESS);
if(v_pINTregs == NULL)
{
RETAILMSG(1,(TEXT("timer1::::For S2440IOP: VirtualAlloc v_pINTregs failed!\r\n")));
}
else
{
RETAILMSG(1,(TEXT("timer1:::: :v_pINTregs == %d\r\n"),v_pINTregs));
if(!VirtualCopy((PVOID)v_pINTregs,(PVOID)(S3C2440A_BASE_REG_PA_INTR>>8),sizeof(S3C2440A_INTR_REG),PAGE_PHYSICAL|PAGE_READWRITE|PAGE_NOCACHE ))
{
RETAILMSG(1,(TEXT("timer1::::For S2440IOP: VirtualCopy v_pINTregs failed!\r\n")));
}
}
}
static DWORD Timer1_Thread_Fun()
{
while(1)
{
WaitForSingleObject(Timer_Event,INFINITE);
RETAILMSG(1,(TEXT("timer1::::Thread id running :times == %d\r\n"),i1));
i1++;
if(dat==1)
{
v_pIOPregs->GPGDAT |= 0x0100;
dat = 0;
}
else
{
v_pIOPregs->GPGDAT &=0xfeff;
dat =1;
}
// v_pINTregs->INTPND |=(0x00000001<<11); //
// v_pINTregs->SRCPND &=~(0x00000001<<11); //
InterruptDone(INTIntr);
}
}
//char achBuffer[sizeof(WCHAR)];
DWORD TIM_Init(DWORD dwContext)
{ // if you drive a idiographic device,add oter code ep: int,hardwareinit and so on
DWORD IDINTThread;
RETAILMSG(1,(TEXT("timer:::::*********InitKey_Init***********\n")));
//clear the ram which is used for this dll
InitializeAddresses();
TimerINTInit();
RETAILMSG(1,(TEXT("timer1::::before CreateThread \r\n")));
Timer_Thread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)Timer1_Thread_Fun,0,0,&IDINTThread);
if(!Timer_Thread)
{
RETAILMSG(1,(TEXT("timer1::::CreateThread faile \r\n")));
return FALSE;
}
else
{
RETAILMSG(1,(TEXT("timer1::::CreateThread OK \r\n")));
}
Timer_Event = CreateEvent(NULL,false,false,NULL);
if(!Timer_Event)
{
RETAILMSG(1,(TEXT("timer1::::CreateEvent faile \r\n")));
return FALSE;
}
else
{
RETAILMSG(1,(TEXT("timer1::::CreateEvent OK \r\n")));
}
if(!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR,&INTIrq,sizeof(INTIrq),&INTIntr,sizeof(INTIntr),NULL))
{
RETAILMSG(1,(TEXT("timer1::::ERROR:kerneliocontrol.\r\n")));
return(FALSE);
}
else
{
RETAILMSG(1,(TEXT("timer1::::KernelioControl OK\r\n")));
}
if(!InterruptInitialize(INTIntr,Timer_Event,NULL,0))
{
RETAILMSG(1,(TEXT("timer1::::Interruptinitialize failed \r\n")));
return FALSE;
}
else
{
RETAILMSG(1,(TEXT("timer1::::Interruptinitialize OK \r\n")));
}
return TRUE;
}