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.

CC2340R5: CC2340 App_startTimer bug

Part Number: CC2340R5


The CC2340 uses fmnap's project to create a timer with App_startTimer, and when I look at this interface code, the handle is generated by a random number. When I create 2 timers, there is a possibility that the randomly generated handles are the same, which will result in an error!

SDK:fmnap_7_20_00_01_eng

  • Hi,

    Thank you for reaching out.

    This is a good catch, and you are definitely right. Even if the probably of conflicting handles is limited to 1/256 when having two timers, this should be fixed.

    The fix I suggest is to check whether the handle is already used (and select another one if it already being used):

        // generate a random handle
        do
        {
            handle = rand();
            if(App_getTimerFromList(handle) != NULL)
            {
                handle = APP_TIMER_INVALID_HANDLE;
            }
        }
        while (handle == APP_TIMER_INVALID_HANDLE);

    Appreciate your inputs,

    Best regards,

  • Okay, thank you
    Each call to App_startTimer will create a new timer. I noticed that most parts of the project do not have code to delete the timer before creating a new one. For instance, if FMNAP_startUTDetection is called repeatedly, two timers will be operating simultaneously.
    Can Util_constructClock be used to replace App_startTimer, as I've found that App_startTimer consumes an extra 50 bytes of memory?
  • isMaintained:7392
    isMaintained:7080
    isMaintained2:7080
    isMaintained2:6968
    Clock_Struct:96