微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > 广播时 LED 闪亮频率 mode触发。

广播时 LED 闪亮频率 mode触发。

时间:10-02 整理:3721RD 点击:

我在sensorTag demo基础上开发的项目,给锂电充电和BLE广播 共用LED1 LED2,我发现在BLE设备启动后广播还没有联机时 LED1闪烁显示提示没连线,会不断的调用(void HalLedOnOff (uint8 leds, uint8 mode))函数,可是我发现mode 的触发切换(HAL_LED_MODE_TOGGLE  0x08)不在void HalLedUpdate (void)函数,也不在void HalLedBlink (uint8 leds, uint8 numBlinks, uint8 percent, uint16 period), 因为我在这个函数入口设置断点不会进去,请问mode(0 1) 切换在哪个函数里处理的? 谢谢,

我这个帖子发了好几天了,TI的还有回复我的疑问,我反复看了LED.c程序里面的每个子程序,

我又参考了keyfobdemo.c 的demo,该例子是按键S2启动广播后,函数static void peripheralStateNotificationCB( gaprole_States_t newState )的

 case GAPROLE_ADVERTISING:
      {
        // Visual feedback that we are advertising.
        HalLedSet( HAL_LED_1, HAL_LED_MODE_ON ); 调用LED1 开关模式设置,
      }
      break;

在按键S2广播后,LED1(红色)一直工作在闪亮状态(不断的调用函数void HalLedOnOff )

我在函数void HalLedUpdate (void)中采用了断点的方式也是没有看到void HalLedOnOff (uint8 leds, uint8 mode)中的mode转换的触发,

/* LED control structure */
typedef struct {
  uint8 mode;       /* Operation mode */
  uint8 left;       /* Blink cycles left */
  uint8 onPct;      /* On cycle percentage */
  uint16 time;      /* On/off cycle time (msec) */
  uint32 next;      /* Time for next change */
} HalLedControl_t;

因为我开发的案子要调用LED1 LED2的广播状态,还要兼容两个LED在给电池充电的充电状态充电时LED1常亮,充满后LED2常亮)移走充电线LED1,LED2 熄灭,请哪位大侠解决我的疑问,

1、建议如果是自己的板子,闪灯程序可以自己做,可以用事件触发的方式,用TI的底层驱动可能不太符合你的要求,当然如果不怕麻烦,也可以更必一下它底层的驱动

2、以下是我的led闪烁的事件

//=================================
// LED blink event
//=================================
if(events & KFD_ECIG_LED_FLASH_EVT)
{
if(led_blink_cnt <led_blink_set)
{
WLED_TRIG();
led_blink_cnt++;
led_blink_flag = TRUE;

osal_start_timerEx( keyfobapp_TaskID, KFD_ECIG_LED_FLASH_EVT, trig_time);
}
else
{
WLED_OFF();
led_blink_cnt = 0;
led_blink_flag = FALSE;
led_blink_set = LED_BLINK_OFF;
osal_stop_timerEx( keyfobapp_TaskID, KFD_ECIG_LED_FLASH_EVT );
osal_pwrmgr_device( PWRMGR_BATTERY );
}

return (events ^ KFD_ECIG_LED_FLASH_EVT);
}

3、希望可以帮到你,祝你早日解决问题,如果可以,也希望您能分享一下您解决问题的方法,谢谢!

mark ,非常感谢你的回复和帮助,我先看下你的程序,我的方案是在SensorTag的基础上修改的,我先搞清sensorTag的LED程序,直接修改我怕有冲突,我修改完成后测试没问题再告诉你我修改的方法。我可以肯定的确认广播时LED闪烁不是调用了函数HalLedBlink (leds, 1, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);好像只调用了函数HalLedSet(HAL_LED_1, HAL_LED_MODE_ON );//HAL_LED_MODE_ON );和void HalLedOnOff (uint8 leds, uint8 mode),mode的转换应该是在定时器处理函数里,我先参考你的程序,非常感谢你。

没仔细看你的问题

sensorTag的闪烁好象是在进入低功耗状态时关闭的,如果不打开POWERSAVE(ING)宏定义,就不闪了

谢谢你的提示,我仔细看了POWERSAVE 以及void halSleep( uint32 osal_timeout )函数,每次周期都有一个睡眠时间sleepTimer,所以在一个流程经过POWERSAVE时,广播LED都有一个熄灭的时间段,才明白广播时闪烁的方式是因为POWER_SAVING,连机后LED是熄灭状态,如果是充电时我就要关闭POWER_SAVING,这样就达到我要求LED状态显示,谢谢你们的帮助。

谢谢你的提示,我看了POWER_SAVING的相关函数osal_pwrmgr_powerconserve(),void halSleep( uint32 osal_timeout ),原来LED闪烁是因为每次经过POWER_SAVING时就会睡眠一段时间,在睡眠时就会关掉LED,睡眠定时器到时唤醒后又点亮LED,这样我就知道了我在充电时就关闭POWER_SAVING。以达到LED在充电时要显示所需的充电状态。

我参考了协议栈SimpleBLEPeripheral和SimpleBLEPeripheralStack的例程,想添加自己的代码,在SimpleBLEPeripheral的simpleBLEPeripheral.c文件中的static void SimpleBLEPeripheral_init(void)函数中,添加以下代码,提示编译出错,无法生成.out文件。添加的代码如下:

static void SimpleBLEPeripheral_init(void)
{
  // ******************************************************************
  // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
  // ******************************************************************
  // Register the current thread as an ICall dispatcher application
  // so that the application can send and receive messages.
  ICall_registerApp(&selfEntity, &sem);

  // Hard code the BD Address till CC2650 board gets its own IEEE address
  //uint8 bdAddress[B_ADDR_LEN] = { 0xAD, 0xD0, 0x0A, 0xAD, 0xD0, 0x0A };
  //HCI_EXT_SetBDADDRCmd(bdAddress);

  // Set device's Sleep Clock Accuracy
  //HCI_EXT_SetSCACmd(40);

  // Create an RTOS queue for message from profile to be sent to app.
  appMsgQueue = Util_constructQueue(&appMsg);

  // Create one-shot clocks for internal periodic events.
  Util_constructClock(&periodicClock, SimpleBLEPeripheral_clockHandler,
                      SBP_PERIODIC_EVT_PERIOD, 0, false, SBP_PERIODIC_EVT);

#ifndef SENSORTAG_HW
  Board_openLCD();
#endif //SENSORTAG_HW
  
#if SENSORTAG_HW
  // Setup SPI bus for serial flash and Devpack interface
  bspSpiOpen();
#endif //SENSORTAG_HW
  
  // Setup the GAP
  GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL);

  // Setup the GAP Peripheral Role Profile
  {
    // For all hardware platforms, device starts advertising upon initialization
    uint8_t initialAdvertEnable = TRUE;

    // By setting this to zero, the device will go into the waiting state after
    // being discoverable for 30.72 second, and will not being advertising again
    // until the enabler is set back to TRUE
    uint16_t advertOffTime = 0;

    uint8_t enableUpdateRequest = DEFAULT_ENABLE_UPDATE_REQUEST;
    uint16_t desiredMinInterval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
    uint16_t desiredMaxInterval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
    uint16_t desiredSlaveLatency = DEFAULT_DESIRED_SLAVE_LATENCY;
    uint16_t desiredConnTimeout = DEFAULT_DESIRED_CONN_TIMEOUT;

    // Set the GAP Role Parameters
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
                         &initialAdvertEnable);
    GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t),
                         &advertOffTime);

    GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData),
                         scanRspData);
    GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);

    GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE, sizeof(uint8_t),
                         &enableUpdateRequest);
    GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t),
                         &desiredMinInterval);
    GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t),
                         &desiredMaxInterval);
    GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t),
                         &desiredSlaveLatency);
    GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t),
                         &desiredConnTimeout);
  }

  // Set the GAP Characteristics
  GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName);

  // Set advertising interval
  {
    uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL;

    GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, advInt);
    GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, advInt);
    GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, advInt);
    GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advInt);
  }

  // Setup the GAP Bond Manager
  {
    uint32_t passkey = 0; // passkey "000000"
    uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
    uint8_t mitm = TRUE;
    uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
    uint8_t bonding = TRUE;

    GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t),
                            &passkey);
    GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
    GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
    GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
    GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
  }

   // Initialize GATT attributes
  GGS_AddService(GATT_ALL_SERVICES);           // GAP
  GATTServApp_AddService(GATT_ALL_SERVICES);   // GATT attributes
  DevInfo_AddService();                        // Device Information Service

#ifndef FEATURE_OAD
  SimpleProfile_AddService(GATT_ALL_SERVICES); // Simple GATT Profile
#endif //!FEATURE_OAD

#ifdef FEATURE_OAD
  VOID OAD_addService();                 // OAD Profile
  OAD_register((oadTargetCBs_t *)&simpleBLEPeripheral_oadCBs);
  hOadQ = Util_constructQueue(&oadQ);
#endif

#ifdef IMAGE_INVALIDATE
  Reset_addService();
#endif //IMAGE_INVALIDATE
  
  
#ifndef FEATURE_OAD
  // Setup the SimpleProfile Characteristic Values
  {
    uint8_t charValue1 = 1;
    uint8_t charValue2 = 2;
    uint8_t charValue3 = 3;
    uint8_t charValue4 = 4;
    uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = { 1, 2, 3, 4, 5 };

    SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, sizeof(uint8_t),
                               &charValue1);
    SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2, sizeof(uint8_t),
                               &charValue2);
    SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR3, sizeof(uint8_t),
                               &charValue3);
    SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(uint8_t),
                               &charValue4);
    SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN,
                               charValue5);
  }

  // Register callback with SimpleGATTprofile
  SimpleProfile_RegisterAppCBs(&SimpleBLEPeripheral_simpleProfileCBs);
#endif //!FEATURE_OAD

  // Start the Device
  VOID GAPRole_StartDevice(&SimpleBLEPeripheral_gapRoleCBs);

  // Start Bond Manager
  VOID GAPBondMgr_Register(&simpleBLEPeripheral_BondMgrCBs);

  //TODO HalLedSet(HAL_LED_1, HAL_LED_MODE_FLASH);

  // Register with GAP for HCI/Host messages
  GAP_RegisterForMsgs(selfEntity);
  
  // Register for GATT local events and ATT Responses pending for transmission
  GATT_RegisterForMsgs(selfEntity);
  
#if defined FEATURE_OAD
#if defined (HAL_IMAGE_A)
  LCD_WRITE_STRING("BLE Peripheral A", LCD_PAGE0);
#else
  LCD_WRITE_STRING("BLE Peripheral B", LCD_PAGE0);
#endif // HAL_IMAGE_A
#else
  LCD_WRITE_STRING("BLE Peripheral", LCD_PAGE0);
#endif // FEATURE_OAD
}

添加的代码如上述红色部分,hal_led.h头文件已包含,而且HAL_LED=TRUE已定义。如下图:

出现的错误信息如下:

<Linking>

 undefined first referenced
  symbol       in file     
 --------- ----------------
 HalLedSet <whole-program>

error #10234-D: unresolved symbols remain
error #10010: errors encountered during linking; "SimpleBLEPeripheral.out" not built

>> Compilation failure
gmake: *** [SimpleBLEPeripheral.out] Error 1
gmake: Target `all' not remade because of errors.

我查看了HalLedSet()函数的原型,发现在hal_led.h头文件中,有如下定义

extern uint8 HalLedSet( uint8 led, uint8 mode );

这是一个外部函数声明,并没有发现函数体,请问在调用时是否需要重写这个函数,该如何重写?出现这个错误的原因是不是HalLedSet的问题,希望高手帮忙,小弟不胜感激。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top