6410 WINCE 驱动中定时器中断问题 请大家帮忙...

flyingknight 2013-08-30 02:51:14

下面是一个测试源代码. 参考了s3c6410芯片手册和别的系统驱动源码。功能很简单,将Timer0 设置成1Khz的频率,在每次定时器中断后在 IST中对g_nInterruptCount 变量+1, 这个值能被ReadFile读出来.
但是实际上发现Timer中断没起作用, 阻塞在WaitForSingleObject上了.
请帮帮忙看是不是哪步出问题了.


#include <bsp.h>
#include "ADCQueuedDrv.h"
#include <windows.h>
#include <commctrl.h>
#include <s3c6410.h>

// virtual addresses
static volatile S3C6410_PWM_REG *g_pPWMRegs = NULL;
static volatile S3C6410_VIC_REG *g_pVIC0Reg = NULL;

static HANDLE g_hTimerEvent = NULL;
static DWORD g_dwTimerSysIntr = 0;
static HANDLE g_hISTThread = NULL;
static int g_nInterruptCount = 0;

static DWORD WINAPI TimerIST(PVOID lpParams);

//
// DllMain
//
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

//
//
//
static void TimerInitialize()
{
OutputDebugString(_T("TimerInitialize"));

// virtual addresses mapping
PHYSICAL_ADDRESS physicalAddr;
physicalAddr.QuadPart = S3C6410_BASE_REG_PA_PWM;
g_pPWMRegs = (volatile S3C6410_PWM_REG*)MmMapIoSpace(physicalAddr, sizeof(S3C6410_PWM_REG), FALSE);
ASSERTMSG(_T("Failed to mapping PWM physical address."), g_pPWMRegs);

physicalAddr.QuadPart = S3C6410_BASE_REG_PA_VIC0;
g_pVIC0Reg = (volatile S3C6410_VIC_REG*)MmMapIoSpace(physicalAddr, sizeof(S3C6410_VIC_REG), FALSE);
ASSERTMSG(_T("Failed to mapping VIC physical address."), g_pVIC0Reg);

// g_pVIC0Reg->VICINTENABLE |= 1 << 23;

// prescaler = 1, divider = 1/4 : resolution = 8.25 Mhz (8250000)
// PCLK = 66Mhz: interval = 66000000 / 8 / 1000 = 8250
// PCLK / 8 / 1000 = 8250, 8250000 / 8250 = 1Khz
g_pPWMRegs->TCFG0 &= ~(0xff << 0);
g_pPWMRegs->TCFG0 |= (0x01 << 0);
g_pPWMRegs->TCFG1 &= ~(0x0f << 0);
g_pPWMRegs->TCFG1 |= (0x02 << 0);
g_pPWMRegs->TCNTB0 = (S3C6410_PCLK) / 8 / 1000;
g_pPWMRegs->TCMPB0 = g_pPWMRegs->TCNTB0 >> 1; // duty cycle: 50%
g_pPWMRegs->TCON &= ~(0xff << 8); // clear control bits.
g_pPWMRegs->TCON |= ((0x02 | 0x08) << 0);

UINT32 i = 100;
while(i--); // delay

g_pPWMRegs->TCON &= ~(0x02 << 8); // clear manual update bit

//create the timer event
g_hTimerEvent = CreateEvent(NULL, FALSE, FALSE, _T("TE6410_AQD_TIMER"));
ASSERTMSG(_T("Event TE6410_AQD_TIMER creation failed."), g_hTimerEvent);

// obtain sysintr values from the OAL for the timer interrupt.
DWORD dwTimerSysIRQ = IRQ_TIMER0;
BOOL bRetVal = KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwTimerSysIRQ, sizeof(DWORD), &g_dwTimerSysIntr, sizeof(DWORD), NULL);
ASSERTMSG(_T("Failed to request the timer sysintr"), bRetVal);

// initialize the interrupt.
bRetVal = InterruptInitialize(g_dwTimerSysIntr, g_hTimerEvent, NULL, 0);
ASSERTMSG(_T("Unable to initialize timer interrupt."), bRetVal);

// create the IST
g_hISTThread = CreateThread(NULL, 0, TimerIST, NULL, 0, NULL);
ASSERTMSG(_T("Unable to create timer IST."), g_hISTThread);

InterruptDone(g_dwTimerSysIntr);

// CeSetThreadPriority(g_hISTThread, 98); // 21-98
}

//
//
//
static void TimerDeinitialize()
{
OutputDebugString(_T("TimerDeinitialize"));

InterruptDisable(g_dwTimerSysIntr);

CloseHandle(g_hISTThread);
CloseHandle(g_hTimerEvent);

// virtual addresses unmapping
VirtualFree((PVOID)g_pPWMRegs, 0, MEM_RELEASE);
VirtualFree((PVOID)g_pVIC0Reg, 0, MEM_RELEASE);
}

//
//
//
static DWORD WINAPI TimerIST(PVOID lpParams)
{
OutputDebugString(_T("TimerIST"));

for (;;)
{
DWORD dwStatus = WaitForSingleObject(g_hTimerEvent, INFINITE);

// TODO: our jobs
g_nInterruptCount ++;

InterruptDone(g_dwTimerSysIntr);
}

return 1;
}

//
//
//
static void TimerStart()
{
g_pPWMRegs->TCON |= (0x01 << 0);
}

//
//
//
static void TimerStop()
{
g_pPWMRegs->TCON &= ~(0x01 << 0);
}

/**
*
*/
DWORD AQD_Init(LPCTSTR pContext, LPCVOID lpvBusContext)
{
OutputDebugString(L"AQD - AQD Init\n");

TimerInitialize();

return 1;
}

/**
*
*/
BOOL AQD_Deinit(DWORD hDeviceContext)
{
OutputDebugString(L"AQD - AQD Deinit\n");

TimerDeinitialize();

return TRUE;
}

/**
*
*/
DWORD AQD_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
return 1;
}

/**
*
*/
BOOL AQD_Close(DWORD hOpenContext)
{
OutputDebugString(L"AQD - AQD Close\n");

TimerStop();

return TRUE;
}

/**
*
*/
DWORD AQD_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
if (Count < 4)
return 0;

*(DWORD*)pBuffer = g_nInterruptCount;

return 4;
}

/**
*
*/
DWORD AQD_Write(DWORD hOpenContext, LPCVOID pBuffer, DWORD Count)
{
return 1;
}

/**
*
*/
VOID AQD_PowerUp(DWORD hDeviceContext)
{
}

/**
*
*/
VOID AQD_PowerDown(DWORD hDeviceContext)
{
}

/**
*
*/
DWORD AQD_Seek(DWORD hOpenContext, long Amount, DWORD Type)
{
return 0;
}

/**
*
*/
BOOL AQD_IOControl(DWORD Handle,
DWORD dwIoControlCode,
PBYTE pInBuf,
DWORD nInBufSize,
PBYTE pOutBuf,
DWORD nOutBufSize,
PDWORD pBytesReturned)
{
switch (dwIoControlCode)
{
case IOCTL_AQD_START:
TimerStart();
break;
case IOCTL_AQD_STOP:
TimerStop();
break;
default:
break;
}
return TRUE;
}
...全文
507 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyingknight 2013-09-18
  • 打赏
  • 举报
回复
请问下有相关的代码例子启用中断的吗?谢谢...
paul_chao 2013-09-09
  • 打赏
  • 举报
回复
Timer 沒有 Enable. Paul, Chao @ Techware
  • 打赏
  • 举报
回复
硬件是否能看到中断信号?
flyingknight 2013-09-02
  • 打赏
  • 举报
回复
在第83行 bRetVal = InterruptInitialize(g_dwTimerSysIntr, g_hTimerEvent, NULL, 0); 将该event对象和IRQ_TIMER0中断进行关联.
91program 2013-09-02
  • 打赏
  • 举报
回复
事件 g_hTimerEvent 是在哪里被触发的呢?
嵌入式ARM9-2440实战手册 嵌入式ARM9-2440实战手册 嵌入式ARM9-2440实战手册 实验1 ARM 汇编指令编程实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 实验2 C 和ARM 汇编混合编程实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 实验3 C 语言实现LED 控制实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 实验4 外部断应用实验 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 实验5 看门狗定时器应用实验 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 实验6 DMA 控制器实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 实验7 PWM 控制蜂鸣器实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 实验8 UART 通信实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 实验9 红外模块控制实验 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 实验10 实时时钟设计实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 实验11 IIC 总线应用实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 实验12 Nor flash 应用实验 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 实验13 Nand flash 应用实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 实验14 TFT LCD 显示实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 实验15 触摸屏控制实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 实验16 ADC 应用实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 实验17 IIS 音频总线实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 实验18 USB 设备实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 实验19 SD 卡接口实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 实验20 TFTP 以太网通讯 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 实验21 Camera 应用实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 实验22 BootLoader 实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 实验23 Linux-2.6 内核移植实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 实验24 Linux 驱动程序开发实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 实验25 QT/Embedded 实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 实验26 WinCE5.0 开发实验. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 附录一 S3C2440A 启动代码. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 附录二 GEC2440 核心板电路图. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 附录三 GEC2440 主板电路图. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335

19,500

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧