TI中文支持网
TI专业的中文技术问题咨询交流网站

cc2640r2f rsm外部中断不能唤醒

由TI 标准例程\simplelink_cc2640r2_sdk_2_20_00_49\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral修改而来。

删除了CC2640R2_LAUNCHXL,增加了CC2640R2DK_4XS,Display_DISABLE_ALL。按键驱动程序改为如下:

#define Board_BTN1 CC2640R2DK_4XS_KEY_UP
#define Board_BTN2 CC2640R2DK_4XS_KEY_DOWN

/*********************************************************************
* LOCAL FUNCTIONS
*/
static void Board_keyChangeHandler(UArg a0);
static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId);

/*******************************************************************************
* EXTERNAL VARIABLES
*/

/*********************************************************************
* LOCAL VARIABLES
*/

// Value of keys Pressed
static uint8_t keysPressed;

// Key debounce clock
static Clock_Struct keyChangeClock;

// Pointer to application callback
keysPressedCB_t appKeyChangeHandler = NULL;

// Memory for the GPIO module to construct a Hwi
Hwi_Struct callbackHwiKeys;

// PIN configuration structure to set all KEY pins as inputs with pullups enabled
PIN_Config keyPinsCfg[] =
{

Board_BTN1 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_BTN2 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,

PIN_TERMINATE
};

PIN_State keyPins;
PIN_Handle hKeyPins;

/*********************************************************************
* PUBLIC FUNCTIONS
*/
/*********************************************************************
* @fn Board_initKeys
*
* @brief Enable interrupts for keys on GPIOs.
*
* @param appKeyCB – application key pressed callback
*
* @return none
*/
void Board_initKeys(keysPressedCB_t appKeyCB)
{
// Initialize KEY pins. Enable int after callback registered
hKeyPins = PIN_open(&keyPins, keyPinsCfg);
PIN_registerIntCb(hKeyPins, Board_keyCallback);

PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN1 | PIN_IRQ_BOTHEDGES);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN2 | PIN_IRQ_BOTHEDGES);

#ifdef POWER_SAVING
//Enable wakeup

PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN1 | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN2 | PINCC26XX_WAKEUP_NEGEDGE);

#endif //POWER_SAVING

// Setup keycallback for keys
Util_constructClock(&keyChangeClock, Board_keyChangeHandler,
KEY_DEBOUNCE_TIMEOUT, 0, false, 0);

// Set the application callback
appKeyChangeHandler = appKeyCB;
}

/*********************************************************************
* @fn Board_keyCallback
*
* @brief Interrupt handler for Keys
*
* @param none
*
* @return none
*/
static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId)
{
keysPressed = 0;

if ( PIN_getInputValue(Board_BTN1) == 0 )
{
keysPressed |= KEY_UP;
}

if ( PIN_getInputValue(Board_BTN2) == 0 )
{
keysPressed |= KEY_DOWN;
}

Util_startClock(&keyChangeClock);
}

/*********************************************************************
* @fn Board_keyChangeHandler
*
* @brief Handler for key change
*
* @param UArg a0 – ignored
*
* @return none
*/
static void Board_keyChangeHandler(UArg a0)
{
if (appKeyChangeHandler != NULL)
{
// Notify the application
(*appKeyChangeHandler)(keysPressed);
}
}
/*********************************************************************
*********************************************************************/

应用层调用函数如下:

/*********************************************************************
* @fn SimpleBLEPeripheral_handleKeys
*
* @brief Handles all key events for this device.
*
* @param keys – bit field for key events. Valid entries:
* KEY_LEFT
* KEY_RIGHT
*
* @return none
*/
static void SimpleBLEPeripheral_handleKeys(uint8_t keys)
{
uint8_t initialAdvertEnable;
if (keys & KEY_UP)
{

if (PIN_getInputValue(Board_PIN_BUTTON0) == 0)
{
initialAdvertEnable = TRUE;
// Set the Peripheral GAPRole Parameters
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
&initialAdvertEnable);
}
}
else if (keys & KEY_DOWN)
{

if (PIN_getInputValue(Board_PIN_BUTTON1) == 0)
{

initialAdvertEnable = FALSE;
// Set the Peripheral GAPRole Parameters
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
&initialAdvertEnable);

}
}
}

问题如下;

刚烧录完这两个按键可以正常启动和关闭蓝牙。

按下复位键之后,两个按键就不能正常工作了。不能唤醒。

请问下这是怎么回事呢?谢谢!

Kevin Qiu1:

初始化中的程序改过吗,复位后debug看程序能到这里吗

user6328081:

回复 Kevin Qiu1:

没改过,初始化时是打开蓝牙,复位之后蓝牙也不能打开。

user6328081:

回复 user6328081:

/********************************************************************** @fnSimpleBLEPeripheral_init** @briefCalled during initialization and contains application*specific initialization (ie. hardware initialization/setup,*table initialization, power up notification, etc), and*profile initialization/setup.** @paramNone.** @returnNone.*/
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, &syncEvent);

#ifdef USE_RCOSCRCOSC_enableCalibration();
#endif // USE_RCOSC

#if defined( USE_FPGA )// configure RF Core SMI Data LinkIOCPortConfigureSet(IOID_12, IOC_PORT_RFC_GPO0, IOC_STD_OUTPUT);IOCPortConfigureSet(IOID_11, IOC_PORT_RFC_GPI0, IOC_STD_INPUT);
// configure RF Core SMI Command LinkIOCPortConfigureSet(IOID_10, IOC_IOCFG0_PORT_ID_RFC_SMI_CL_OUT, IOC_STD_OUTPUT);IOCPortConfigureSet(IOID_9, IOC_IOCFG0_PORT_ID_RFC_SMI_CL_IN, IOC_STD_INPUT);
// configure RF Core tracer IOIOCPortConfigureSet(IOID_8, IOC_PORT_RFC_TRC, IOC_STD_OUTPUT);
#else // !USE_FPGA#if defined( DEBUG_SW_TRACE )// configure RF Core tracer IOIOCPortConfigureSet(IOID_8, IOC_PORT_RFC_TRC, IOC_STD_OUTPUT | IOC_CURRENT_4MA | IOC_SLEW_ENABLE);#endif // DEBUG_SW_TRACE
#endif // USE_FPGA
// 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);
dispHandle = Display_open(SBP_DISPLAY_TYPE, NULL);
// Set GAP Parameters: After a connection was established, delay in seconds// before sending when GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE,…)// uses GAPROLE_LINK_PARAM_UPDATE_INITIATE_BOTH_PARAMS or// GAPROLE_LINK_PARAM_UPDATE_INITIATE_APP_PARAMS// For current defaults, this has no effect.GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL);
// Setup the Peripheral GAPRole Profile. For more information see the User's Guide:// software-dl.ti.com/…/gaprole.html{// Device starts advertising upon initialization of GAPuint8_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 re-enabled by the applicationuint16_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 Peripheral GAPRole ParametersGAPRole_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 Device Name characteristic in the GAP GATT Service// For more information, see the section in the User's Guide:// software-dl.ti.com/…/gaprole.htmlGGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName);
// Set GAP Parameters to set the advertising interval// For more information, see the GAP section of the User's Guide:// software-dl.ti.com/…/gatt.html{// Use the same interval for general and limited advertising.// Note that only general advertising will occur based on the above configurationuint16_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. For more information see the section in the// User's Guide:// software-dl.ti.com/…/gapbondmngr.html{// Hard code the passkey that will be used for pairing. The GAPBondMgr will// use this key instead of issuing a callback to the application. This only// works if both sides of the connection know to use this same key at// compile-time.uint32_t passkey = 0; // passkey "000000"// Don't send a pairing request after connecting; the peer device must// initiate pairinguint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;// Use authenticated pairing: require passcode.uint8_t mitm = TRUE;// This device only has display capabilities. Therefore, it will display the// passcode during pairing. However, since the default passcode is being// used, there is no need to display anything.uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;// Request bonding (storing long-term keys for re-encryption upon subsequent// connections without repairing)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 attributesGGS_AddService(GATT_ALL_SERVICES);// GAP GATT ServiceGATTServApp_AddService(GATT_ALL_SERVICES);// GATT ServiceDevInfo_AddService();// Device Information Service

#ifndef FEATURE_OAD_ONCHIPSimpleProfile_AddService(GATT_ALL_SERVICES); // Simple GATT Profile
#endif //!FEATURE_OAD_ONCHIP

#ifdef FEATURE_OADVOID OAD_addService();// OAD ProfileOAD_register((oadTargetCBs_t *)&simpleBLEPeripheral_oadCBs);hOadQ = Util_constructQueue(&oadQ);
#endif //FEATURE_OAD

#ifdef IMAGE_INVALIDATEReset_addService();
#endif //IMAGE_INVALIDATE

#ifndef FEATURE_OAD_ONCHIP// Setup the SimpleProfile Characteristic Values// For more information, see the sections in the User's Guide:// software-dl.ti.com/…/gatt.html// software-dl.ti.com/…/gatt.html{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 SimpleGATTprofileSimpleProfile_RegisterAppCBs(&SimpleBLEPeripheral_simpleProfileCBs);
#endif //!FEATURE_OAD_ONCHIP
// Start Bond Manager and register callbackVOID GAPBondMgr_Register(&simpleBLEPeripheral_BondMgrCBs);
// Register with GAP for HCI/Host messages. This is needed to receive HCI// events. For more information, see the section in the User's Guide:// software-dl.ti.com/…/hci.htmlGAP_RegisterForMsgs(selfEntity);
// Register for GATT local events and ATT Responses pending for transmissionGATT_RegisterForMsgs(selfEntity);
// Set default values for Data Length Extension// This should be included only if Extended Data Length Feature is enabled// in build_config.opt in stack project.{//Set initial values to maximum, RX is set to max. by default(251 octets, 2120us)#define APP_SUGGESTED_PDU_SIZE 251 //default is 27 octets(TX)#define APP_SUGGESTED_TX_TIME 2120 //default is 328us(TX)
// This API is documented in hci.h// See BLE5-Stack User's Guide for information on using this command:// software-dl.ti.com/…/data-length-extensions.html// HCI_LE_WriteSuggestedDefaultDataLenCmd(APP_SUGGESTED_PDU_SIZE, APP_SUGGESTED_TX_TIME);}

#if defined (BLE_V42_FEATURES) && (BLE_V42_FEATURES & PRIVACY_1_2_CFG)// Initialize GATT ClientGATT_InitClient();
// This line masks the Resolvable Private Address Only (RPAO) Characteristic// in the GAP GATT Server from being detected by remote devices. This value// cannot be toggled without power cycling but should remain consistent across// power-cycles. Removing this command when Privacy is used will cause this// device to be treated in Network Privacy Mode by bonded devices – this means// that after disconnecting they will not respond to this device's PDUs which// contain its Identity Address.// Devices wanting to use Network Privacy Mode with other BT5 devices, this// line should be commented out.GGS_SetParamValue(GGS_DISABLE_RPAO_CHARACTERISTIC);
#endif // BLE_V42_FEATURES & PRIVACY_1_2_CFG

#if !defined(Display_DISABLE_ALL)// Set the title of the main menu#if defined FEATURE_OAD#if defined (HAL_IMAGE_A)TBM_SET_TITLE(&sbpMenuMain, "BLE Peripheral A");#elseTBM_SET_TITLE(&sbpMenuMain, "BLE Peripheral B");#endif // HAL_IMAGE_A#elseTBM_SET_TITLE(&sbpMenuMain, "BLE Peripheral");#endif // FEATURE_OAD
// Initialize Two-Button Menu moduletbm_setItemStatus(&sbpMenuMain, TBM_ITEM_NONE, TBM_ITEM_ALL);tbm_initTwoBtnMenu(dispHandle, &sbpMenuMain, 3, NULL);
// Init key debouncer

#endif// !Display_DISABLE_ALLBoard_initKeys(SimpleBLEPeripheral_keyChangeHandler);
#if !defined (USE_LL_CONN_PARAM_UPDATE)// Get the currently set local supported LE features// The will result in a HCI_LE_READ_LOCAL_SUPPORTED_FEATURES event that// will get received in the main task processing loop. At this point,// feature bits can be set / cleared and the features can be updated.HCI_LE_ReadLocalSupportedFeaturesCmd();
#endif // !defined (USE_LL_CONN_PARAM_UPDATE)
// Start the GAPRoleVOID GAPRole_StartDevice(&SimpleBLEPeripheral_gapRoleCBs);

}

Kevin Qiu1:

回复 user6328081:

复位后程序应该从头执行,不会搜不到广播,复位后单步运行看可以执行到哪一步

赞(0)
未经允许不得转载:TI中文支持网 » cc2640r2f rsm外部中断不能唤醒
分享到: 更多 (0)