Read/write conflict between the image driver and the image driver

Source: Internet
Author: User

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 ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.