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.

CC2650: simple_peripheral_cc2650lp: how to do simple inter-task communication

Part Number: CC2650


Hi,

I started with simple_peripheral on the CC2650LP, added a 6th characteristic which I'm able to write and read using nRF Connect.  Then I pulled in the PWM_LED example, and got the red LED flashing at 0.5s rate. (thanks to this forum!)  Now, I'm trying to use the 6th characteristic to write a global variable called ledEnable to enable/disable the LED flashing.  Here is the result of a text search for ledEnable:

I declared ledEnable as volatile in simple_gatt_profile.c and as extern volatile in main.c.  In the SimpleProfile_SetParameter function I assign the characteristic 6 value to led Enable and then I use ledEnable in SimpleProfile_GetParameter.  This works i.e. I can write a value to char 6 and read it back.  So I think this means that the value from BLE is being assigned to the ledEnable variable.  The problem is that the value is not available in my redLED task in main.c as a live variable.  

I was trying to avoid using interprocess communications to reduce latency, but I can't seem to make this simple approach work.

Any hints?

Thanks,

Jim

  • Jim,

    Interesting. Usually the code in main.c only runs at startup - the call to BIOS_start() at the end of main() starts the RTOS scheduler and the main task that runs continuously is SimpleBLEPeripheral_taskFxn() at the file <simple_perihperal.c> - I would put the LED code within the for(;;) inside this task.

    You can verify this by setting a breakpoint at line 184 of main.c and it will probably be hit just once during the code execution. 

    Of course this assumes that you defined ledEnable as global in <simple_gatt_profile.c>, right?

    Hope this helps,

    Rafael

  • Hi Rafael,

    In main.c I defined a task to call the redLED function every 500ms, before the call to BIOS_Start() so I think that is why it's running continuously even while the BLE stack is running.

    Here is the code that I used to set up the LED task:

      /* Construct LED Task thread */
      Task_Params_init(&ledTaskParams);
      ledTaskParams.stackSize = TASKSTACKSIZE;
      ledTaskParams.stack = &tsk0Stack;
      ledTaskParams.arg0 = 50000;  // task period = 0.5s
      Task_construct(&tsk0Struct, (Task_FuncPtr)redLED, &ledTaskParams, NULL);
    

    And here is the redLED task function (outside of the main() function, but located within the main.c file:

    /*
     *  ======== redLED ========
     *  Task periodically toggles the red LED as proof of life...
     */
    Void redLED(UArg arg0, UArg arg1)
    {
        PWM_Handle pwm1;
        PWM_Params params;
        uint16_t   pwmPeriod = 3000;      // Period and duty in microseconds
        uint16_t   ledState;
    
        PWM_Params_init(&params);
        params.dutyUnits = PWM_DUTY_US;
        params.dutyValue = 0;
        params.periodUnits = PWM_PERIOD_US;
        params.periodValue = pwmPeriod;
        pwm1 = PWM_open(Board_PWM0, &params);
    
        if (pwm1 == NULL) {
            System_abort("Board_PWM0 did not open");
        }
        PWM_start(pwm1);
        ledState = 0;
    
        /* Loop forever toggling the LED based on the value of beatEnable */
        while (1) {
            if (ledState == 0)
            {
                if (ledEnable == LED_ENABLED)
                    {
                    ledState = 1;
                    PWM_setDuty(pwm1,3000);
                    }
            }
            else
            {
                ledState = 0;
                PWM_setDuty(pwm1,0);
            }
    
    //        System_printf("in LED task\n");
    //        System_flush();
    
            Task_sleep((UInt) arg0);
        }
    }

    I was trying to use this to learn how to have separate tasks in TI-RTOS.  

    Yes, I declared ledEnable in the global variable area of simple_gatt_profile.c

    Thanks,

    Jim

  • Jim,

    When you run your code, can you spot your Task on the ROV task list?

    To open the ROV, go to menu Tools --> Runtime Object View and then select the option to connect to the running target and browse as shown below (the image will differ on your project)

    If the Task is not there or is continuously blocked, then it is not running. Also, check if a breakpoint inside the task is hit - that would be also another indicator.

    I will try to think about additional scenarios and report back.

    Hope this helps,

    Rafael

  • Hi Rafael,

    My redLED task is in main.c but is not part of the main function; I just initialized the task in main().  I can tell that this task is running since I can see the LED toggling at the execution frequency of the redLED task.  

    I will try though moving it and the interprocess communication varialbe into the simple_peripheral.c file and see if that works.

    I will keep you posted.

    Thanks,

    Jim

  • I was able to get this working by using the _Get function to read the value of the BLE characteristic.  I'm not sure why reading the variable directly didn't work, but I'm able to move ahead.