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.

Task Switching and Memory sharing CC2650

Other Parts Discussed in Thread: CC2650

I am speaking in regards to cc2650 launchpad and TI-RTOS.I tried to combine aspects of heart rate and project zero in the same project. 

The project zero was being used to toggle LEDs through an android Application where it was also storing the log of the time and mobile number which toggled the led. 

I wanted to transmit this stored log, so i tried to combined the heart rate with my project zero. 

If I define 2 tasks in a same project, for example two separate functions for Project Zero and Heart Rate, can I share memory between the two functions? Right now I am defining all the functions in the same task.

If the memory sharing is not possible, is it possible to define two separate tasks for project zero and heart rate in the same project and use the task switch option, if any , to get the cc2650launchpad to transmit the datalog to the smartphone. Essentially, the heart rate task fxn will be used as a transmitter. Please let me know your views on this. Sorry to trouble you. 

I understand that my end application might require memory sharing between these two functions since task 1 will store the log and task 2 will transmit it . But I can't wrap my head around how to do it.

Please Help.

Regards,
Keyshav

  • Hi Keyshav,

    Here are your options:

    1. Share the memory with synchronization modules. Two functions can share memory but it is highly advisable that you protect this shared memory with some sort of locking mechanism (ex: task disable, binary semaphore, GateMutex, etc.).
    2. Use a mailbox to pass data from one function to the other.

    Also, I would probably try to separate the two functions in separate tasks to separate the two aspects that you are combining.

    What I would do for shared memory:

    1. Create two tasks (one for each aspect)
    2. Decide which locking mechanism to use (in this case, a binary semaphore will most likely be enough).
    3. In a separate file, add functions to store and retrieve the data. Also, create your synchronization module here.(if you use the semaphore, make sure to use a count of 1 for initial value)
    4. In your function to store the data: Before storing your data: you use Semaphore_pend. Once you, finish storing data, release the semaphore with Semaphore_post
    5. In your function to retrieve the data: Before retrieving data, use Semaphore_post, once your retrieved what you wanted, use Semaphore_post to release.

    What I would do for Mailbox:

    1. Create the two tasks
    2. In the "reading" tasks, create the mailbox. Also add a function so your other task can push data to the mailbox through the Mailbox_post function.
    3. Your reading tasks would contain something like this:
      while(1) {
         Mailbox_pend(.......);
         //Do your stuff here
      }
    4. You writing task, would contain something like this:
      while(1) {
         //Get you data here
         Mailbox_post(.......);
      }

    So it's up to you to decide what works best in your scenario. If you have very little data, I wouldn't use the mailbox because the overhead of each message will take up a lot of space. If you always send the same data, you can create a struct that will contain all your data which you give to the mailbox.


    Regards,

    Michel

  • Hi Keyshav,

    why do you want two task functions?
    You can use one to controll your leds and send data if you application connects to its services.
    It is all about connecting to the toogle led service and heartrate service. The service will go to its callback functions.
    The task function will be called if a message has ben triggered or a semaphore is called. The task will look for the corresponded event and do toogle led for example or send data.

    Look at this function "user_processApplicationMessage" description:

    /*
    * @brief Handle application messages
    *
    * These are messages not from the BLE stack, but from the
    * application itself.
    *
    * For example, in a Software Interrupt (Swi) it is not possible to
    * call any BLE APIs, so instead the Swi function must send a message
    * to the application Task for processing in Task context.
    *
    * @param pMsg Pointer to the message of type app_msg_t.
    *
    * @return None.
    */

    So as far as i understood you want to toogle led and then send message via heartrateservice. You can also use the led service to send data to your app using LED_Service_ReadAttrCB on your app side. On the cc2650 side you will have to set the call back function to send whatever you want to. Difference is that the heartrate service send a notification to the app and the app on the project zero can read and write to the led service.
    Notification are good but it can cause of data loss depending on size and speed. The app doesnt say "please send me that again" and the cc2650 will never know if the app gets it or not.
    The safer way is to the client your app, read and write from/to the service from the server. In this way you will always get/transmitt your data safer.

    Regards,

    Michael