Wince + 6410 IIC driver problems
I recently debugged the 6410 IIC driver and asked the upper layer to write data to the EEPROM for permanent storage. Since the camera driver in the BSP package contains an example of IIC operation, naturally, you just need to refer to the gourd-based painting in the camera driver,
// Initialize iic1
Hi2c = createfile (_ T ("iic0:"), generic_read | generic_write,
File_cmd_read | file_cmd_write, null, open_existing, 0, 0 );
If (invalid_handle_value = hi2c)
{
MessageBox (L "I2C cannot be enabled ");
Dwerr = getlasterror ();
Return false;
}
If (! Deviceiocontrol (hi2c,
Ioctl_iic_set_clock,
& Iicclock, sizeof (uint32 ),
Null, 0,
& Bytes, null ))
{
Dwerr = getlasterror ();
MessageBox (L "unable to set I2C Clock ");
Return false;
}
Uiiicdelay = 0;
If (! Deviceiocontrol (hi2c,
Ioctl_iic_set_delay,
& Uiiicdelay, sizeof (uint32 ),
Null, 0,
& Bytes, null ))
{
Dwerr = getlasterror ();
MessageBox (L "unable to set I2C delay ");
Return false;
}
There is no problem to enable IIC. When the clock and delay time are set, the IIC does not respond at all, and then the debugging information is turned on. After Entering iic_iocontrol
If (getdirectcallerprocessid ()! = Getcurrentprocessid ()){
Retailmsg (1, (text ("Mao iic_iocontrol 1: \ r \ n"); // Add Mao
Return error_access_denied;
}
Then I did not go down,
Later, I checked the information on the Internet to know that the driver itself does not support application calling and is called for other drivers. This is because a judgment is added before iic_iocontrol.
If (getdirectcallerprocessid ()! = Getcurrentprocessid ()){
Retailmsg (1, (text ("Mao iic_iocontrol 1: \ r \ n"); // Add Mao
Return error_access_denied;
}
During application calling, you need to comment out the above judgment. After commenting out the judgment, you can read and write it. If you can read data several times consecutively, an error is returned,
Exception 'data abort '(4): thread-id = 01970006 (PTH = 8617c2ec), proc-id = 00400002 (PPRC = 82ab9308) 'nk. EXE ', Vm-active = 058b0006 (PPRC = 84954618) 'assumer.exe'
PC = c0e32b98 (cloud6410_iic.dll + 0x00002b98) Ra = c0e32b10 (cloud6410_iic.dll + 0x00002b10) sp = d285fe64, BVA = 001aeee8
I have been wondering why I didn't find the root cause of the source code. I accidentally saw an article saying that the iic_io_desc parameter contains pointers, which need to be mapped to pointers, as shown below:
Bool hw_read (phw_open_info popencontext, piic_io_desc pindata, piic_io_desc poutdata)
{
Hresult hr; // Add Mao for IIC
Bool retval = true; // initialize to success
Pbyte mappedembedded;
Pbyte financialled;
Debugmsg (zone_function,
(Text ("+ hw_read (0x % x) \ r \ n "),
Popencontext ));
Hw_setregister (popencontext );
Hw_write (popencontext, pindata );
Resetevent (g_htransferdone );
// Wait until iic bus is free.
If (! Waitforreg (pvoid) & (g_piicreg-> iicstat), (1 <5), 0x0, timeout_ms_rx ))
{
Debugmsg (zone_error, (text ("[IIC Error] IIS Bus is busy. \ r \ n ")));
Retval = false;
Goto cleanup;
}
// Kernel address ing
HR = ceopencallerbuffer (pvoid *) & mappedembedded, poutdata-> data, poutdata-> count, arg_o_ptr, false );
HR = ceallocasynchronousbuffer (pvoid *) & financialled, mappedembedded, poutdata-> count, arg_o_ptr );
G_pciic_buffer = financialled; // poutdata-> data;
G_uiic_pt = 0;
G_uiic_datalen = poutdata-> count;
G_piicreg-> iiccon | = (1 <7); // ack generation enable
G_piicreg-> iicds = pindata-> slaveaddress;
G_piicreg-> iicstat = mrx_start;
// Retailmsg (1, (text ("Mao g_piicreg-> iicds slave address is 0x % 02x \ n"), pindata-> slaveaddress); // Add Mao
If (waitforsingleobject (g_htransferdone, timeout_ms_rx) = wait_timeout)
{
Debugmsg (zone_error, (text ("[IIC Error] RX time out. \ r \ n ")));
Retval = false;
}
// Release the kernel address
HR = cefreeasynchronousbuffer (pvoid) financialled, mappedembedded, poutdata-> count, arg_o_ptr );
HR = ceclosecallerbuffer (pvoid) mappedembedded, poutdata-> data, poutdata-> count, arg_o_ptr );
Cleanup:
Debugmsg (zone_function,
(Text ("+ hw_read (0x % x) \ r \ n "),
Popencontext ));
Return retval;
}
Bool hw_write (phw_open_info popencontext, piic_io_desc pindata)
{
Bool retval = true; // initialize to success
Pbyte mappedembedded;
Pbyte financialled;
Hresult hr; // Add Mao for IIC
Debugmsg (zone_function,
(Text ("+ hw_write (0x % x) \ r \ n "),
Popencontext ));
Hw_setregister (popencontext );
Resetevent (g_htransferdone );
// Wait until iic bus is free.
If (! Waitforreg (pvoid) & (g_piicreg-> iicstat), (1 <5), 0x0, timeout_ms_tx ))
{
Debugmsg (zone_error, (text ("[IIC Error] iic bus is busy. \ r \ n ")));
Return false;
}
// Add Mao
HR = ceopencallerbuffer (pvoid *) & mappedembedded, pindata-> data, pindata-> count, arg_ I _ptr, false );
HR = ceallocasynchronousbuffer (pvoid *) & financialled, mappedembedded, pindata-> count, arg_ I _ptr );
G_pciic_buffer = financialled; // pindata-> data;
G_uiic_pt = 0;
G_uiic_datalen = pindata-> count;
G_piicreg-> iiccon | = (1 <7); // ack generation enable
G_piicreg-> iicds = pindata-> slaveaddress;
// Retailmsg (1, (text ("Mao [iic tx] slave address is 0x % 02x \ n"), pindata-> slaveaddress); // Add Mao
Debugmsg (zone_info, (text ("[iic tx] slave address is 0x % 02x \ n"), pindata-> slaveaddress ));
G_piicreg-> iicstat = mtx_start;
If (waitforsingleobject (g_htransferdone, 500) = wait_timeout)
{
Debugmsg (zone_error, (text ("[IIC Error] TX time out. \ r \ n ")));
Retval = false;
}
HR = cefreeasynchronousbuffer (pvoid) financialled, mappedembedded, pindata-> count, arg_ I _ptr );
HR = ceclosecallerbuffer (pvoid) mappedembedded, pindata-> data, pindata-> count, arg_ I _ptr );
Debugmsg (zone_function,
(Text ("-hw_write (0x % x) \ r \ n "),
Popencontext ));
Return retval;
}
After re-compilation, the read and write operations are normal.
Reference: http://bbs.csdn.net/topics/310115283
Http://blog.csdn.net/knock/article/details/4770325
Http://jazka.blog.51cto.com/809003/702584
Http://blog.csdn.net/fgwntg/article/details/6798420