又出问题了! camera应用程序启动的时候要通过IIC总线写register,而且还是一大堆,就在这个过程中,电源管理IC驱动也要通过IIC总线去读取电池电压和电流及充放电状态,这样混在一起,就出现了TX Time Out的现象。而关掉PMU驱动读IIC部分则camera模块写register每次都成功!
经过一番思索,camera写寄存器只有启动时一次,后面几乎都不怎么写,只要这段时间不发生冲突不就完事大吉了? 基于此,将PMU驱动和camera驱动读写IIC部分加入了互斥元保护,这样,访问IIC之前先要请求,得到机会后才能读写。 修改后,camera和PMU不再冲突,可以正常的读写了。
#define IIC_MUTEX TEXT("IIC_MUTEX")
static HANDLE g_hIICMutex = NULL;
g_hIICMutex = CreateMutex(NULL, FALSE, IIC_MUTEX);
DWORD
AcqIICMutex(void)
{
// ASSERT(g_hBatteryFileMutex != NULL);
DWORD dwWaitResult = WaitForSingleObject(g_hIICMutex, 3000); //MUTEX_TIMEOUT
if(WAIT_OBJECT_0!=dwWaitResult) {
RETAILMSG(1,(TEXT("[CAM]WaitForSingleObject did not return WAIT_OBJECT_0 returned %d, Get last error:%d/n"),
dwWaitResult, GetLastError()));
}
return dwWaitResult;
}
DWORD
RelIICMutex(void)
{
DWORD retval=-1;
ASSERT(g_hIICMutex!=NULL);
retval=ReleaseMutex(g_hIICMutex);
if(!retval){
retval=GetLastError();
RETAILMSG(1,(TEXT("[CAM]Release Mutex failed with error %d. /n"),retval));
}
return retval;
}
使用:
DWORD dwWaitResults=-1;
dwWaitResults=AcqIICMutex();
if (WAIT_OBJECT_0 != dwWaitResults)
{
RETAILMSG(1,(TEXT("[CAM]Timeout on acquiring mutex for IIC/n")));
}
else
{
//write value to register.
。。。。。。。。。
dwWaitResults=RelIICMutex();
}