TI E2E 英文论坛海量技术问答的中文版全新上线,可点击相关论坛查看,或在站内搜索 “参考译文” 获取。

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.

CC2640R2L: 定时器异常

Part Number: CC2640R2L

我需要实现使用两个定时器进行广播切换的功能,在定时器A的事件触发时进行自定义广播包的切换,在定时器B事件触发时,进行标准广播包的切换,并循环持续30s,但是当第一个广播包切换后,定时出现异常,且其他的触发事件都出现了异常,例如串口,按键,都无法触发了,请问这是什么情况导致的。

我的代码如下:

#define SP_ADV_SOS_EVT_PERIOD                300
advInt = 160


Util_constructClock(&advsos, SimplePeripheral_clockHandler,
                      SP_ADV_SOS_EVT_PERIOD, 0, false, (UArg)&argadvsos);
                      
Util_constructClock(&advupade, SimplePeripheral_clockHandler,
                      advInt * 0.625, 0, false, (UArg)&argadvupade);


static void adv_init()
{
    //Method 1
    if (sos_state == 1)
        memcpy(updateAdvData, advertDataNew, sizeof(advertDataNew));
    else if(sos_state == 0)
        memcpy(updateAdvData, advertData, sizeof(advertData));

    bStatus_t status = FAILURE;

    status = GapAdv_prepareLoadByHandle(advHandleLegacy,GAP_ADV_FREE_OPTION_ADV_DATA);
    SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);

    // Load advertising data for set #1 that is statically allocated by the app
    status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_ADV,
                                 sizeof(updateAdvData), updateAdvData);
    SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);


    //Method 2
/*
        GapAdv_params_t advParamLegacy;

        advParamLegacy.eventProps = GAP_ADV_PROP_CONNECTABLE | GAP_ADV_PROP_SCANNABLE | GAP_ADV_PROP_LEGACY;
        advParamLegacy.primIntMin = advInt;
        advParamLegacy.primIntMax = advInt;
        advParamLegacy.primChanMap = GAP_ADV_CHAN_ALL;
        advParamLegacy.peerAddrType = PEER_ADDRTYPE_PUBLIC_OR_PUBLIC_ID;
        //memcpy(advParamLegacy.peerAddr, pPkt->devAddr, B_ADDR_LEN);
        advParamLegacy.filterPolicy = GAP_ADV_WL_POLICY_ANY_REQ;
        advParamLegacy.primPhy = GAP_ADV_PRIM_PHY_1_MBPS;
        advParamLegacy.secPhy  = GAP_ADV_SEC_PHY_1_MBPS;
        advParamLegacy.sid     = 0;

        // Create Advertisement set #1 and assign handle
        status = GapAdv_create(&SimplePeripheral_advCallback, &advParamLegacy,
                               &advHandleLegacy);
        SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);

        // Load advertising data for set #1 that is statically allocated by the app
        status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_ADV,
                                     sizeof(updateAdvData), updateAdvData);
        SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);

        // Load scan response data for set #1 that is statically allocated by the app
        status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_SCAN_RSP,
                                     sizeof(scanRspData), scanRspData);
        SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);

        // Set event mask for set #1
        status = GapAdv_setEventMask(advHandleLegacy,
                                     GAP_ADV_EVT_MASK_START_AFTER_ENABLE |
                                     GAP_ADV_EVT_MASK_END_AFTER_DISABLE |
                                     GAP_ADV_EVT_MASK_SET_TERMINATED);

    // Enable legacy advertising for set #1
    status = GapAdv_enable(advHandleLegacy, GAP_ADV_ENABLE_OPTIONS_USE_MAX, 0);

    SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
*/
}

static void SimplePeripheral_processAppMsg(spEvt_t *pMsg)
{
  bool dealloc = TRUE;

  switch (pMsg->event)
  {
    ...
    case SP_ADV_SOS_EVT:
        sos_start_handler();
        break;

    case SP_ADV_UPDATE_EVT:
        adv_start_handler();
        break;

    default:
      // Do nothing.
      break;
  }
}

static void sos_start_handler(void)
{
    flag_status.adv_clock_ticks++;
    Util_startClock(&advsos);
    if (flag_status.adv_clock_ticks == 50)
    {
        Uart0_Write("Stop\r\n", 6);
        flag_status.adv_clock_ticks = 0;
        GapAdv_disable(advHandleLegacy);
        sos_state = 0;
        adv_init();
        Util_stopClock(&advsos);
        Util_stopClock(&advupade);
    }
    else
    {
        Uart0_Write("sos\r\n", 5);
        sos_state = 1;
        adv_init();        
    }
}

static void adv_start_handler(void)
{
    Uart0_Write("adv\r\n", 5);
    Util_startClock(&advupade);
    sos_state = 0;
    adv_init();
}
  

如果我把代码中的adv_init()屏蔽以后,在定时器事件中添加串口log,发现定时器可以进行触发,其他事件也可以正常进行。

  • 您好,

    收到您的问题了,我们升级到英文论坛给工程师看下,有答复尽快给到您。

  • 您好,

    请问该问题有答复了么

  • 您好,

    我们认为不能多次“创建” advertisement set,我们建议只调用一次函数“GapAdv_create()”,并且只更新在User's Guide中提到的广播数据(advertising data)。

    您还需要考虑使用两个advertising sets的情况下,每个advertising sets将根据定时器来启用/禁用。

    希望能够帮助到您。

  • 谢谢您的解答,我使用 该方法更新数据是可以正常工作的:

    static void adv_update()
    {
        GapAdv_disable(advHandleLegacy);
        
        if (sos_state == 1)
            memcpy(updateAdvData, advertDataNew, sizeof(advertDataNew));
        else if(sos_state == 0)
            memcpy(updateAdvData, advertData, sizeof(advertData));
    
        GapAdv_prepareLoadByHandle(advHandleLegacy,GAP_ADV_FREE_OPTION_DONT_FREE);
        
        // Load advertising data for set #1 that is statically allocated by the app
        GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_ADV,
                                     ADV_UPDATA_LEN, updateAdvData);
    
        GapAdv_enable(advHandleLegacy, GAP_ADV_ENABLE_OPTIONS_USE_MAX, 0);
    
    }

  • 您好,

    很高兴您的问题又被解决。感谢您的支持。