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.

RTOS/TM4C1294NCPDT: RTOS drivers are thread safe or not

Part Number: TM4C1294NCPDT

Tool/software: TI-RTOS

Hi,

I am using driver calls from the location <tirtos_install>/products/tidrivers_<version>/packages/ti/drivers, Its mention in TI RTOS user guide that the driver calls are thread safe.

I am using a function like below which calls I2C driver function calls,

i2cWrite()

{

I2C_Params_init(&stI2cParams);

 stI2cHandle = I2C_open(stI2cConfig->vui8I2cBus, &stI2cParams);

I2C_transfer(stI2cHandle, &stI2cTransaction)

I2C_close(stI2cHandle);

}

Question:

1.Is the safe thread mechanism is implemented for each function individually or a single safe thread for all the function in I2C driver.

2.What will happen if I again create a safe thread for i2cWrite function.

Regards,

Manohar

  • Hi Manohar,

    The usage of each I2C instance is thread-safe. For example if you call I2C_open with the Board_I2C0 (which is really EK_TM4C129EXL_I2C7) index, you'll get back an I2C_Handle. Let's call that i2cHandle0.

    Multiple tasks can use the i2cHandle0 to initiate transfers. Internally in I2C_transfer (actually in the lower level i2c driver), a semaphore is used as a mutex to make sure only one task is setting up the transfer at once. Here is the line of code in the i2cTiva.c file

    Semaphore_pend(Semaphore_handle(&(object->mutex)), BIOS_WAIT_FOREVER);

    Now the driver sets up the transfer and calls Semaphore_pend on a separate semaphore (call it the transfer complete semaphore). When the transfer is complete, the Hwi calls Semaphore_post on the transfer complete semaphore. This releases the task that was blocked. Now it calls the following 

    Semaphore_post(Semaphore_handle(&(object->mutex)));

    to allow any other task to do the a transfer (if one was blocked on the Semaphore_pend listed above.

    If you had a different I2C instance (call it i2cHandle1). If there is a transfer going on for i2cHandle0, you can still do a transfer for i2cHandle1 since they have different semaphores to provide thread-safety.

    Todd