|
各位兄弟关于中断有几个问题,请各位高手指导一下!先谢谢啦!
问题:1、InterruptInitialize(g_I2CSysIntr, gI2CIntrEvent, 0, 0)这个函数是把逻辑中断号与事件gI2CIntrEvent相关联,但是
我看g_I2CSysIntr的初始化定义是UINT32 g_I2CSysIntr = SYSINTR_UNDEFINED;
个人理解:是不是KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &g_I2CIrq, sizeof(UINT32), &g_I2CSysIntr, sizeof(UINT32), NULL)NULL)中对g_I2CSysIntr重新附值为SYSINTR_IIC??
问题:2、在IIC_Read函数中
DWORD IIC_Read(DWORD Handle, LPVOID pBuffer, DWORD dwNumBytes)
{
UINT32 count, ret;
uchar *pReadBuffer;
if ((pBuffer == NULL) || (dwNumBytes <= 0))
return 0;
pReadBuffer = MapPtrToProcess(pBuffer, GetCallerProcess());
// 设置从机地址及当前状态
I2cCurSla = I2cSla | 0x01;
I2cStatus = I2C_STATUS_SETADDR;
StartI2C(I2cCurSla);
ret = WaitForSingleObject(gI2CEvent, I2C_RW_TIMEOUT); /* 挂起当前线程,直到IIC中断的产生 */
ResetEvent(gI2CEvent);
其中ret = WaitForSingleObject(gI2CEvent, I2C_RW_TIMEOUT);等待事件gI2CEvent发生,然后进入中断??这个事件是系统触发还是中断函数中通过
SetEvent(gI2CEvent);触发的??如果是系统触发,然后进入中断线程处理,那么为什么
中断中的处理也是case I2C_STATUS_SETADDR:
if((v_pIICPregs->IICSTAT & 0x09) == 0) // 发送地址成功
{
SetEvent(gI2CEvent);
IICError = I2C_ERROR_NO_ERR;
}
在中断中再次SetEvent(gI2CEvent)的作用是什么呢?
问题:3、在中断线程中同样有ret = WaitForSingleObject(gI2CIntrEvent, INFINITE);
这个WaitForSingleObject是谁触发的事件呢??是操作系统吗?如果是的话,那么在IIC_Read中的WaitForSingleObject是谁在触发这个事件?
这两个函数中(I2C_IntrThread和IIC_Read)WaitForSingleObject的事件触发的先后顺序是什么样的?? DWORD I2C_IntrThread(PVOID pArg)
{
DWORD ret;
// 创建I2C中断中断事件
gI2CIntrEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// 初始化 I2C 中断: 注册中断事件, 允许 I2C 中断
if (!(InterruptInitialize(g_I2CSysIntr, gI2CIntrEvent, 0, 0)))
{
CloseHandle(gI2CIntrEvent);
RETAILMSG(1, (TEXT("ERROR: I2C Bus: Interrupt initialize failed.\r\n")));
return 0;
}
// IIC 中断线程开始运行
while (1)
{
ret = WaitForSingleObject(gI2CIntrEvent, INFINITE);
if ((ret != WAIT_OBJECT_0) || (g_bKillIST == TRUE)) /* 驱动卸载或错误发生 */
{
CloseHandle(gI2CIntrEvent);
RETAILMSG(1, (TEXT("INFO: I2C Bus Driver DeInit or Error Occur. \r\n")));
return 0; /* 线程退出 */
}
switch(I2cStatus)
{
// Start IIC Status
case I2C_STATUS_SETADDR:
if((v_pIICPregs->IICSTAT & 0x09) == 0) // 发送地址成功
{
SetEvent(gI2CEvent);
IICError = I2C_ERROR_NO_ERR;
}
.................
问题:4、ret = WaitForSingleObject(gI2CIntrEvent, INFINITE);无论成功或者失败都有返回值给ret ,然后是向下继续执行吧??
|
|