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.

TI RTOS task handling for TIRTOS based MSP430F5659 controller

Other Parts Discussed in Thread: MSP430F5659

Hi,

I am facing some problem with my integration of tasks in TI RTOS based MSP430F5659 controller.

I have two task USB and ADC.

On receiving data over USB i am invoking ADC task. Now on ADC task needed only when i have new data arrives. For this i have created Events using semaphore to handle, so on first reception and it works but how to stop this task from running after sending data using USB?

In my case ADC task runs continuous, i don't to know how to make it invoked or executed on USB data reception on next time. Please guide.

One more thing if USB task is running and my board is connected to PC application, Whether disconnection of cable is handled in USB CDC application of "usbserialdevice_MSP_EXP430F5529LP_TI_MSP430F5529" . If  not how i can achieve this?

Nitesh

  • Hi Nitesh,

    Nitesh Padiyar52 said:

    On receiving data over USB i am invoking ADC task. Now on ADC task needed only when i have new data arrives. For this i have created Events using semaphore to handle, so on first reception and it works but how to stop this task from running after sending data using USB?

    Could you provide more details on how you are using Events here ? Maybe share some code excerpts ?

    Nitesh Padiyar52 said:

    One more thing if USB task is running and my board is connected to PC application, Whether disconnection of cable is handled in USB CDC application of "usbserialdevice_MSP_EXP430F5529LP_TI_MSP430F5529" . If  not how i can achieve this?

    If you are using a TI launchpad then one thing to note is that the emulation shares the same USB and disconnecting the USB cable will also disconnect emulation.

    The USB_handleVbusOffEvent() is called when a disconnected cable is detected and USB_handleVbusOnEvent() is called when a USB cable is connected. These functions can be found in the "USBCDCDEVICE.c" file. If you need to do something different than what is already being done to handle the disconnected cable event, you can modify this function.

    Hope this helps.

    Best,

    Ashish

  • Hi Ashish,

    Thanks for the input. As you requested i am attaching code snippet for the reference. 

    USB task will invoke the ADC task on reception of packet. ADC task will take the sample and generate event for the sending result back to PC application.

    So my code will have following routines...........

    I have declared the task, semaphore and events in main function as shown below,

    /* Create a Semaphore object to be use as a resource lock */
    sem = Semaphore_create(1, NULL, NULL);
    evt = Event_create(NULL, NULL);
    /* create a Semaphore Instance */
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;
    semParams.event = evt;
    semParams.eventId = Event_Id_01 + Event_Id_02+Event_Id_03;
    sem = Semaphore_create(0, &semParams, NULL);

    Task_Params_init(&taskParams);
    taskParams.priority = 3;
    tsk1 = Task_create (ADCTask, &taskParams, NULL);

    USBTask()

    {

    while (true)

    {

             /* Block while the device is NOT connected to the USB */

            USBCDCD_waitForConnect(BIOS_WAIT_FOREVER);

           if(bCDCDataReceived_event)// Some data is in the buffer; begin receiving a //command

            {

                    uint8_t readBytes = 0;

                    // Add bytes in USB buffer to theCommand

                    readBytes = USBCDCD_receiveData((uint8_t *)RxPacket, 31, BIOS_WAIT_FOREVER);

                    if ( readBytes > 0 && RxPacket[0] == START_DATA_HEADER && RxPacket[readBytes -2]== END_DATA_HEADER)

                    {

                         CommandByte = RxPacket[1];

                         //Decode_Recieved_Command();

                         //Event_post(evt, Event_Id_02);

                    }

                    bCDCDataReceived_event = FALSE;

    posted = Event_pend(evt,0, Event_Id_03,BIOS_WAIT_FOREVER);

    //wait for event 3 which is posted by ADC interrupt
    if (posted & Event_Id_03)
    {
    //some code......
    }
    tostring(&text[15],avg_ms);
    USBCDCD_sendData(text, sizeof(text), BIOS_WAIT_FOREVER);

                  }

          }

    }

     ADCTask()

    {

    for (;;)

    {

     

                         // read adc data untill buffer is full

                         // add event for the buffer full

                   /* wait for (Event_Id_01) */

     

                         // different event can be raised as per our test commands

                         // make use of the

    posted = Event_pend(evt,Event_Id_01 /*+ Event_Id_02*/, Event_Id_01,TIMEOUT);

     

                         if (posted == 0)

                         {

                         }

                          if (posted & Event_Id_02)

                         {

    ADC12_A_startConversion(ADC12_A_BASE, ADC12_A_MEMORY_4,ADC12_A_SINGLECHANNEL);

                               Task_sleep(1000);

                         }

                          if (posted & Event_Id_01)

                         {

                               // calculate the measured sample

                               //if required

                               ADC12_A_disable(ADC12_A_BASE);

    // set event flag and control moves to USB Task
    Event_post(evt, Event_Id_03);

                   }

                          Task_sleep(1000);

                  }

    }

    ADC interrupt routine will generate events 1,2

    1. On event 2 ADC is repeated to take the sample 

    2. On event 1 ADC stop the sampling after no. of samples set and ADC task will generate the Event 3 to transfer the control to USB task for the result transmit

    Now i have few challenges

    1. How to stop/block the ADC task and all the events after event 3 is used by USB task to send result  to PC application, so that on next  data reception (USB Task) event are started and ADC task is resumed?

    2. Better method to stop/block event,semaphore and task? 

    Nitesh

     

  • Hi Nitesh,

    Thanks for sharing the code snippet. There are a lot of commented out Event_pend() and Event_post() calls. Can you clarify which ones are actually used ?

    Based on what I have understood so far, I would recommend having two separate event objects for USB and ADC tasks and do something like this:

    USBTask()
    {
        // Wait for connection.
        while (1) {
            // Receive data
            // Post ADC event01 to unblock the ADC task
            // Pend on USB event01. Event posted when ADC task done
        }
    }
    ADCTask()
    {
        while (1) {
            // Pend on ADC event01. This should ensure the ADC task
               blocks after completing the ADC conversion and posting
               USB event
            // Start ADC conversion
            // Post USB event01
        }
    }

    I see you created a semaphore and set the event & eventId fields but I dont see where are you using the Semaphore ?

    Best,

    Ashish

  • hi Ashish,

    Thanks for the input, i have a question you mentioned Event01 for both, it suspect it should be event01 and event02 right?
    One more thing semaphore based events are required or i can have only events?
    I have one more requirement is - ADC task will be invoked by USB task, but USB task should not invoked by ADC since USB needs to be sending acknowledge to PC application on periodic basis, so that whenever data is ready it will transmit data or send some acknowledge till data is ready.

    Please guide me how to achieve the periodic task in TI RTOS

    -Nitesh
  • Hi Nitesh,

    Nitesh Padiyar52 said:
    hi Ashish,

    Thanks for the input, i have a question you mentioned Event01 for both, it suspect it should be event01 and event02 right?

    I was suggesting to create 2 separate event objects and use event01 of each object for signalling. Alternatively, you can skip events and just use a semaphore. ADC task can call Semaphore_pend() at the beginning of the while loop. USB task can post the semaphore to unblock the ADC task.

    Nitesh Padiyar52 said:


    I have one more requirement is - ADC task will be invoked by USB task, but USB task should not invoked by ADC since USB needs to be sending acknowledge to PC application on periodic basis, so that whenever data is ready it will transmit data or send some acknowledge till data is ready.

    Please guide me how to achieve the periodic task in TI RTOS

    If I understand your requirement correctly then you can maybe try the following:

     - Make the ADC task higher priority than USB task.
     - ADC task implements a while(1) loop whose first instruction is a pend on a semaphore.
     - USB task makes a blocking call to receive data and once the data is received, it posts the semaphore to unblock ADC task.
     - ADC task being higher priority will run to completion and block again when it attempts to pend on semaphore in the next iteration of while loop.
     - USB task will resume, send data back to USB, and then try to receive new data (and possibly block till data is received)

    Best,

    Ashish

  • Hi Ashish,

    Thanks for suggestion, you are understanding is correct. I will try this.

    Can you please answer to my other question "how to achieve the periodic task in TI RTOS"

    Thanks

    Nitesh

  • Hi Nitesh,

    Do you need the USB task to execute the loop periodically ? You can create a semaphore and a clock object with the desired period. The task can pend on the semaphore once its work is done and the registered clock function can post the semaphore and unblock the task every <period> micro secs.

    Best,
    Ashish
  • Ashish,

    Thanks for the suggestion, but i have few more tasks which needs periodic calling like NV Task and Diagnostic Task. So those task only i need periodic task.

    As you told my USB task needs to wait for time period and i will try as you suggested.

    Please can you share the example or let me know which example, uses the clock period based semaphore handling.

    One more problem i am faced yesterday, i tried changing the priority of USB task which is created using UI, it gives error. I changed the priority to 4 from 3, it gives error saying task priority should be below 4. Even task created using code also gives error. Then i found in script there is parameter

    Task.numPriorities = 4;  i changed this to Task.numPriorities = 10; and code got compiled successfully. Is this is correct way to do? Please clarify why it is set in code?

    Thanks

    Nitesh  

  • You can maybe go through Section 3.6.6 (Task Yielding for Time-Slice Scheduling) of the latest SYS/BIOS User Guide (SPRUEX3P). The example in this section mentions a 4th task of higher priority that executes periodically and is implemented using the scheme I suggested earlier.

    If you need multiple tasks to execute periodically and the period is the same, you could also leverage the Time-slice scheduling scheme mentioned in this example.

    Best,

    Ashish

  • Ashish,

    Need some i help in handling Task, see below about some description

    I have question on ADC multiple channel handling for TI RTOS based msp430 application.

    I have 3 ADC input from external(battery voltage, normal voltage input, one more voltage input) , i want to design such a way that i will keep monitoring these inputs on every second and blink the LED

    My design idea is to configure the ADC in 1st task and
    2nd task will read the ADC data from the channel and updates the value.
    And 3rd task will blink the LED.

    Please suggest any other way to handle this How i can achieve this,
    also let me know can ADC task read multiple ADC with single trigger.
    Please give some input, example to handle this.

    Thanks

    Nitesh
  • Hi Nitesh,

    This thread has already been closed. Can you create a new thread & post your question ? It will help us track your post.

    Thanks,
    Ashish