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/TM4C123GH6PM: Task blocking and Terminating other Tasks

Part Number: TM4C123GH6PM

Tool/software: TI-RTOS

Hi all,

I am new to TI-RTOS. 

I'm using following configurations for my project

CCSv8.1.0 , TI-RTOS- 2.16.00.08, TIVA Ware: 2.1.4.178;xdc : 3.32.00.06Laptop OS: Windows 10


I have 4 Tasks in my system. In one of those tasks. I want to get IMU Sensor Data when ever a button is pressed. To acheive this I configured to post Semaphore when ever the button is pressed

Code snippets as follows:

/* Callback function for the GPIO interrupt on up Button.*/
void gpioButtonFxn1(unsigned int index)
{
Semaphore_post(IMUSem);

}

The Task implementation is as follows:

void get_imu()
{
// GPIO_toggle(Board_LED_BLUE);

I2C_Handle i2c;
I2C_Params i2cParams;
uint8_t pwr;
pwr = 0x00;

//Create I2C for usage
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(IMU_SENSOR, &i2cParams);
if (i2c == NULL)
{
System_abort("Error Initializing I2C\n");
}
else
{
System_printf("I2C Initialized!\n");
}

// Initialize the MPU6050
signal.writeRegister(i2c,0x6B, 0x80);    // This line making the this Task to go into blocked state and other tasks to terminate state 
signal.readRegister(i2c, 0x6B, &pwr, 1);
do {
signal.readRegister(i2c, 0x6B, &pwr, 1);
} while (pwr & 0x40 != 0x40);

// Use PLL with X axis gyroscope reference
signal.writeRegister(i2c,0x6B, 0x01);
// Enable I2C Master mode
signal.writeRegister(i2c,0x6A, 0x20);
// Set sample rate divider
signal.writeRegister(i2c,0x19, 0x13);
signal.writeRegister(i2c,0x67, 0x11);

GPIO_write(Board_LED_RED, Board_LED_OFF);

while(1)
{
Semaphore_pend(IMUSem, BIOS_WAIT_FOREVER);
while (GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_2) == GPIO_PIN_2);
signal.readRegister(i2c, 0x3B, (uint8_t *) &signal.imu.mpu6050, 14);
}

//Deinitialized I2C
I2C_close(i2c);
System_printf("I2C closed!\n");
System_flush();
}

My WriteRegister() as follows:
void writeRegister(I2C_Handle handle, uint16_t regAddr, uint16_t value)
{
    uint8_t             txBuffer[4];
    I2C_Transaction     i2cTransaction;

    i2cTransaction.slaveAddress = MPU6050_I2C_ADDRESS;

     //Write to a 16-bit status register
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 2;
    i2cTransaction.readCount = 0;

    txBuffer[0] = regAddr & 0xFF; //LB Addr
    txBuffer[1] = value   & 0xFF;

    if (!I2C_transfer(handle, &i2cTransaction)) {
        GPIO_write(Board_LED_RED, Board_LED_ON);
        System_abort("Bad I2C transfer!");
    }
}

and readRegister() as follows:

void readRegister(I2C_Handle handle,
                  uint16_t regAddr,
                  uint8_t *data,
                  size_t   length)
{
    uint8_t             txBuffer[2];
    I2C_Transaction     i2cTransaction;

    i2cTransaction.slaveAddress = MPU6050_I2C_ADDRESS;

     //Write to a 16-bit status register
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.readBuf = data;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readCount = length;

    txBuffer[0] = regAddr & 0xFF; //LB Addr

    if (!I2C_transfer(handle, &i2cTransaction)) {
        GPIO_write(Board_LED_RED, Board_LED_ON);
        System_abort("Bad I2C transfer!");
    }
}

My .cfg file configuration for Imu task and semaphore as follows:

var task3Params = new Task.Params();
task3Params.instance.name = "imu";
task3Params.priority = 2;
Program.global.imu = Task.create("&get_imu", task3Params);
var semaphore0Params = new Semaphore.Params();
semaphore0Params.instance.name = "IMUSem";
Program.global.IMUSem = Semaphore.create(null, semaphore0Params);

Below is the screen shot of the ROV:

when debugger in main():



After the line in get_imu() task

signal.writeRegister(i2c,0x6B, 0x80); 

Kindly some one help me in this.

Thanks in Advance.

Regards,

Yashwanth Gandeti.

  • Hi,
    So what is the problem? After you take the interrupt and the semaphore_post is executed, what happened to the get_imu? Didn't it run the signal.readRegister?
  • Hi  Charles,

    If my understanding is not wrong.  

    1.Here for my project I'm using Static way of configuration.All the task are ready to run when BIOS_Init(); is called. So before calling the  main() Tasks are ready to run is it?

    2.

    void taskfxn(){
    
    /*Prolog*/
    ....
    ....
    ....
    while(1){
    semaphore_pend();
    ....
    ...
    ...
    ...
    }
    /*Epilog*/
    }

    In the above pseudo code  prolog would have been ran before its wait for semaphore. Comparing the above code to my code I'm going into blocked state when i'm in a "prolog" part of the code not in the while(1) part of the code. Before posting the semaphore  get_imu task is going into blocked state and remaining tasks into terminated states.

    While debugging I came to know that  I2C_transfer(handle, &i2cTransaction) in writeRegister() is creating this problem. Can you help me in this.

    Regards,

    Yashwanth Kumar

  • Hi,

    I implemented above code in newly created project, its running smoothly. But I don't know where i did mistake.
    Regards,
    Yashwanth.
  • Yashwanth Gandeti said:
    In the above pseudo code  prolog would have been ran before its wait for semaphore. Comparing the above code to my code I'm going into blocked state when i'm in a "prolog" part of the code not in the while(1) part of the code. Before posting the semaphore  get_imu task is going into blocked state and remaining tasks into terminated states.

    Your understanding about the semaphore is correct. Once the semaphore_pend is executed it will not execute any more code further until semaphore_post is issued. 

  • Yashwanth Gandeti said:
    I implemented above code in newly created project, its running smoothly. But I don't know where i did mistake.

    Glad that your problem is somehow resolved. What other things did you do other than creating a new project? Unless you can reproduce the problem again in this newly created project, I don't see problem with your understanding of using semaphore. I will close this thread for now. If you have new questions or see problems again you can create a new thread.