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/CC2640: ICALL_ERRNO_INVALID_SERVICE: My GAP task terminates and I can't restart it

Part Number: CC2640

Tool/software: TI-RTOS

The compiler: TI v16.9.2.LTS

RTOS: 2_20_01_08

BLE stack: 2_02_01_18

Stack is configured to run as PERIPHERAL + OBSERVER

After running for an indeterminate amount of time, the application receives a GAPROLE_ERROR status change from my peripheral_observer profile.

In the debugger, the GAPROLE_ERROR is coming from the profile asking the GAP:

if (GAP_MakeDiscoverable(selfEntity, &params) != SUCCESS)

Basically, when GAP_MakeDiscoverable is called, the system tries to formulate an ICall call to the GAP service, but the service is terminated.

So:

1) How does RTOS tell you when something terminated so you can catch it?

2) Can I restart the GAP or should I just reboot the device?

3) As far as I can tell, I have plenty of overhead on all my task stacks and heaps and whatnot, no errors are visible in the RTOS viewer, no stack overruns etc.  All the memory alloc/dealloc looks to be balanced, whenever a device discovery event occurs I copy the information to a new message for my event loop.  I switch off advertising when I am doing device discovery.

Really unsure how to proceed here.

  • Hi,

    What do you mean by service is terminated? If you look at the API description in gap.h, it should return some error code:

    /**
    * @brief Setup or change advertising. Also starts advertising.
    *
    * @par Corresponding Events:
    * @ref GAP_MAKE_DISCOVERABLE_DONE_EVENT of type @ref gapMakeDiscoverableRspEvent_t
    *
    * @param taskID - task to receive event
    * @param pParams - advertising parameters
    *
    * @return @ref SUCCESS : advertising request sent to stack
    * @return @ref bleIncorrectMode : invalid profile role
    * @return @ref bleAlreadyInRequestedMode : already advertising
    * @return @ref bleNotReady : advertising data isn't set up yet
    */
    extern bStatus_t GAP_MakeDiscoverable( uint8 taskID, gapAdvertisingParams_t *pParams );

    Please let us know the return value of the function.

    Best wishes
  • Ah it's actually because I did a big piece of very stupid cut and paste coding.

    The example observer.c supplied with the BLE stack only checks to see if the return code is SUCCESS, it doesn't make any other distinctions, just pushes the observer role into GAPROLE_ERROR if it doesn't succeed.  This is obviously both stupid and wrong.

    Also wrong was the way I handled the error.  I will cater for all the return codes and try it again.

  • So more error checking later here is the situation. I am using a clock in my main application task to do a discovery every 30 seconds. The discovery is only supposed to last 3 seconds.

    However, there seems to be a situation where the discovery is still going the next time my clock fires.

    The bStatus_t result is "bleAlreadyInRequestedMode".

    I am guessing I do a call to cancel discovery mode at that point, but will that adequately fix the bluetooth stack if it's stuck in a funny state? It seems odd that it would be stuck waiting for a discovery to finish for 10X the period of time I asked it to do a discovery.