|
请问各位高手:
这段在IIC驱动中的中断线程的作用是什么啊?
能否详细解释一下里面的重要代码??
谢谢各位啦!
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;
}
else
{
if (I2cCurSla & I2C_READ)
v_pIICPregs->IICSTAT = (2 << 6) | (0<<5) | (1<<4); // ??????
else
v_pIICPregs->IICSTAT = (3 << 6) | (0<<5) | (1<<4); // ??????
IICCON_DACK(v_pIICPregs->IICCON);
Sleep(1); // ?????á???????ú?ú?ê±?
SetEvent(gI2CEvent);
IICError = I2C_ERROR_SETADDR;
}
break;
// Send Bytes Status
case I2C_STATUS_SEND:
if((v_pIICPregs->IICSTAT & 0x09) == 0) // ????????·???
{
IICError = I2C_ERROR_NO_ERR;
SetEvent(gI2CEvent);
}
else
{
v_pIICPregs->IICSTAT = (3 << 6) | (0 << 5) | (1 << 4);
IICCON_DACK(v_pIICPregs->IICCON);
Sleep(1); // ?????á???????ú?ú?ê±?
IICError = I2C_ERROR_SEND;
SetEvent(gI2CEvent);
}
break;
// Receive Bytes
case I2C_STATUS_RECEIVE:
if((v_pIICPregs->IICSTAT & 0x08) == 0)
{
IICError = I2C_ERROR_NO_ERR;
SetEvent(gI2CEvent);
}
else
{
// ·????á??????
v_pIICPregs->IICSTAT = (2 << 6) | (0 << 5) | (1 << 4);
IICCON_DACK(v_pIICPregs->IICCON);
Sleep(1); // ?????á???????ú?ú?ê±?
IICError = I2C_ERROR_RECEIVE;
SetEvent(gI2CEvent);
}
break;
default:
break;
}
InterruptDone(g_I2CSysIntr);
}
}
|
|