This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BIOSPSP I2C driver call from multiple threads

Other Parts Discussed in Thread: SYSBIOS

Hello,

Is it possible to call the I2C driver from multiple threads in SYSBIOS 6.35? At the moment it seems that I get an occasional exception on my C6748 custom board.

This is what I have in my .cfg file:

var dev1Params = new DEV.Params();
dev1Params.instance.name = "devI2c_0";
dev1Params.initFxn = "&userI2cInit";
dev1Params.deviceParams = "&g_i2cParams";
dev1Params.devid = 0;
Program.global.devI2c_0 = DEV.create("/i2c0", "&I2c_IOMFXNS", dev1Params);

And in C++ program:

I2c_Params g_i2cParams;
/*
* I2C0 init function called when creating the driver.
*/
extern "C"
{
void userI2cInit()
{
I2c_init();

g_i2cParams = I2c_PARAMS;
g_i2cParams.busFreq = TWI0_MODULE_CLOCK; //max 100kHz supported by my I2C devices

g_i2cParams.hwiNumber = 8;

/* configure I2c for interrupt mode */
g_i2cParams.opMode = I2c_OpMode_INTERRUPT;
g_i2cParams.edma3EventQueue = 1;//CC0, TC1

System_printf("I2C Driver Initialisation\n");
}

Then I called Open function in the initial thread:

void Open()

{

Error_Block eb;
I2c_ChanParams chanParams;
GIO_Params ioParams;

Error_init(&eb);
/*
* Initialise channel attributes.
*/
GIO_Params_init(&ioParams);

chanParams.hEdma = GetDMA0().GetHandle();
chanParams.masterOrSlave = I2c_CommMode_MASTER;

ioParams.chanParams = &chanParams;

System_printf("\r\nI2C Open instance\n");

/* Create the I2C Channels for the TX and RX communication */
m_i2c_outHandle = GIO_create("/i2c0", GIO_OUTPUT, &ioParams, &eb);
m_i2c_inHandle = GIO_create("/i2c0", GIO_INPUT, &ioParams, &eb);

}

My threads call the following function for same I2C device address:

uint8_t I2CDrv::Receive(uint8_t addr, uint8_t *pReadBuffer, uint16_t bufferLength, bool bRepeat)
{
I2c_DataParam dataBuffer;
UInt32 size = 0;

if(m_i2c_inHandle == NULL)
{
System_printf("I2c Read: port not opened");
return 0;
}

/* Assign data into output buffer */
/* First command word and then the data */
/* Prepare the data to be written to the port */
dataBuffer.slaveAddr = addr;
dataBuffer.buffer = pReadBuffer;
dataBuffer.bufLen = bufferLength;
dataBuffer.flags = I2c_READ | I2c_MASTER | I2c_START | I2c_STOP;

/* Write the data to I2c expander */
uint32_t error = GIO_submit(m_i2c_inHandle,
IOM_READ,
&dataBuffer,
&dataBuffer.bufLen,
NULL);

if ((error != 0) && (dataBuffer.bufLen != size))
{
System_printf("I2c Read: Data Read Failed: %d\n", error);
return 0;
}
return 1;
}

Thank you in advance,

David.