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/TM4C1292NCPDT: SPI and I2C TI RTOS Driver Calls need locking Mechanism

Part Number: TM4C1292NCPDT

Tool/software: TI-RTOS

Hi,

I have created a driver file with the available TI RTOS driver calls for SPI and I2C as Below,

SPI.c File

spi_call()

{

SPI_HANDLE = SPI_open(SPI_BASEADDRESS, &SPI_PARAMETER);
SPI_transfer(SPI_HANDLE, &SPI_TRANSACTION);
SPI_close(SPI_HANDLE);

}

I2C.c FIle

i2c_call()

{

I2C_HANDLE = I2C_open(I2C_BASEADDRESS, I2C_PARAMETER);
I2C_transfer(I2C_HANDLE, I2C_TRANSACTION)
I2C_close(I2C_HANDLE);

}

My question:

1. Can I pass different base addresses like SPI0_BASE, SPI1_BASE to access both the SPI simultaneously with the single spi_call() function. Same for I2C.

2. Is it internally taken care for locking mechanism? or I need to implement Semaphore inside the spi_call() and i2c_call() functions.

Regards,

Manohar

  • Hi Manohar,

    Manohar B said:
    1. Can I pass different base addresses like SPI0_BASE, SPI1_BASE to access both the SPI simultaneously with the single spi_call() function. Same for I2C.

    No. You need to call SPI_open on each peripheral instance you want to talk to. The SPI_Config structure needs to have 2 separate entries. Same for I2C.

    Manohar B said:
    2. Is it internally taken care for locking mechanism? or I need to implement Semaphore inside the spi_call() and i2c_call() functions.

    Internally, each driver instance has it's own semaphore for thread-safety. For example, say you do

    spiHandle0 = SPI_open(Board_SPI0, &params);

    Two different tasks can call SPI_transfer(spiHandle0,...) and not have to worry about thread-safety. Note though, it you need to make two or more SPI_transfer calls to a SPI peripheral be made atomically (e.g. first message readies the peripheral and the second gives the data), you must supply that logic. 

    Todd