Another problem! When the camera application is started, it needs to write the Register through the IIC bus, and there are still a lot of them. In this process, the power management IC driver also needs to read the battery voltage, current, and charge/discharge status through the iic bus. In this way, TX time out occurs. Turning off the PMU driver to read IIC, the camera module writes register each time!
After some thought, the camera write register is only started once, and is rarely written later. As long as there is no conflict during this period of time, it will be a great deal? Based on this, the PMU driver and the camera driver read/write IIC are added to the mutex protection. In this way, you need to request before accessing the IIC to obtain the opportunity before reading and writing. After modification, the camera and PMU do not conflict with each other and can be read and written normally.
# 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;
}
Usage:
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 ();
}