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: Task Issues

Part Number: TM4C1294NCPDT

Tool/software: TI-RTOS

I used CFG to create two tasks. The priority of Task0 is 2, and another(Task1) is 1.  But the Task1 is not working, i think the mcu does not go to the Task1. When i set the same priority, the system work fine.

How to solve the problem, when i set the different priority.

  • Hello,

    Can you please post your source code? It would be helpful to see what each task does.

    You can do so by clicking 'Use Rich Formatting' and then using the Syntax Highlighter on the toolbar which is symboled '< / >'.

    Are you able to get into both Task0 and Task1 when the priority is the same?

    Do you know if Task0 takes longer to process than it does to re-trigger? If this is the case, because it is higher priority, then every time it finishes processing, it would be re-entered before Task1 can process.
  • My task0 code:

    void UARTPort_Params_Setting(void)
    {
        /* Create a UART with data processing off. */
        UART_Params_init(&uartParams);
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.readTimeout = 10;
        uartParams.readReturnMode = UART_RETURN_FULL;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 9600;
        uart = UART_open(Board_UART0, &uartParams);
    }
    void UART_echoFxn(UArg arg0, UArg arg1)
    {
        char arg; // the command argument
        unsigned int count; // the count of UART RX reading data
        unsigned char input[256] = {0};
        const char echoPrompt[] = "\fConnecting MCU is success.\r\n";
    
        /* Create a UART with data processing off. */
        UARTPort_Params_Setting();
    
        UART_write(uart, echoPrompt, sizeof(echoPrompt));
    
        /* Loop forever echoing */
        while (1)
        {
            UART_control(uart, UART_CMD_ISAVAILABLE, &arg); // read RX buffer, true if data is available, else false
    	if(arg != 0)
    	{
                count = UART_read(uart, input, 256);
    	    UART_Command(uart, input, count);
    	}
        }
    }

    My task1 code:

    void System_taskFxn(UArg arg0, UArg arg1)
    {
        while(1)
        {
    	Mapping_Update();
        }
    }

    When the priorities are the same, the UART can use and i can also set some value by I2C etc.

  • Hello,

    I think what is occurring is that your UART task is not allowing the I2C task to finish processing before preempting it.

    For TI-RTOS the following is true: When you configure tasks to have equal priority, they are scheduled in the order in which they are created
    in the configuration script. (Page 82 from www.ti.com/.../spruex3q.pdf )

    This means the tasks will run back to back when their priority is the same.

    However when a task has a higher priority than another task, it is allow to preempt the lower priority task. This is because "Unlike many time-sharing operating systems that give each task its “fair share” of the processor, SYS/BIOS immediately preempts the current task whenever a task of higher priority becomes ready to run." (also found on Page 82 of aforementioned document).

    One solution would be to allow the UART task to be blocked for a period of time to let the I2C task run using either Semaphores or even just a Task_sleep(); function. The latter may be a good quick test to see if the UART task is blocked, that the I2C task could then run as you need.

    That would indicate if you need to further investigate how long each task takes to process, and if the UART task is being triggered to be ready to be executed before the I2C task finishes.
  • Hello,

    I take your advise, and i add Task_sleep(1) in the UART_echoFxn function with the different priority. The system looks fine, it's work.

    How i use semaphores, l can not understand how it works. Do the TI has some examples?

    thanks

    BR,

    Louis 

  • Hello Louis,

    We have a whole training video series for TI-RTOS: training.ti.com/ti-rtos-workshop-series

    I certainly would recommend going through at least Chapters 3-8, but for tasks and semaphores specifically that is covered in Chapter 8. Just understand these videos were done sequentially and will refer to info from prior chapters.

    These videos are the best resource to learn about TI-RTOS and RTOS concepts that we have available.

    Chapter 1 just gives an overview of TI portfolio and devices for TI-RTOS, you seem to know which device you want to use so you probably don't need that. Chapter 2 is just on CCS, but if you are new to CCS you may learn about how to use it better.
  • Dear Ralph,

    Thanks.

    BR,

    Louis