CC2640R2F参考官方simple_peripheral_cc2640r2lp_app例程写了一段Peripheral向Central写变量的代码,采用WriteNoRsp方式,connection handle和character handle已事先正确获得,并且simple_peripheral_cc2640r2lp_stack部分已去掉了NO_GATT_CLIENT定义,WriteNoRsp返回SUCCESS,通过sniffer抓包也能够抓到Peripheral发送的写变量数据包。
现在遇到的问题是WriteNoRsp执行完之后,执行到Event_post这里程序就会崩溃,跳到ti_sysbios_family_arm_m3_Hwi_excHandler,如果不执行WrtieNoRsp就没有问题,查了很久都没有找到原因,希望各位高手能指点一二,非常感谢!
static gattMsg_t t_Message; static uint16 u16_ConnectionHandle; static uint16 u16_CharacterHandle; static ICall_SyncHandle t_ICallSyncHandle; static ICall_EntityID t_ICallEntityID; #define EVENT_WRITE (1 << 0) void ProcessTask(UArg a0, UArg a1) { uint32_t t_Events; ICall_registerApp(&t_ICallEntityID, &t_ICallSyncHandle); while (1) { t_Events = Event_pend(t_ICallSyncHandle, Event_Id_NONE, EVENT_WRITE, ICALL_TIMEOUT_FOREVER); //do something } } uint GATT_Write (const uint8 *u8p_Data, uint8 u8_Length) { attWriteReq_t *tp_WriteRequest; tp_WriteRequest = &t_Message.writeReq; tp_WriteRequest->pValue = (uint8 *)GATT_bm_alloc(u16_ConnectionHandle, ATT_WRITE_REQ, (uint16)u8_Length, NULL); if (tp_WriteRequest->pValue != NULL ) { tp_WriteRequest->len = u8_Length; tp_WriteRequest->sig = 0; tp_WriteRequest->cmd = 1; memcpy(tp_WriteRequest->pValue, u8p_Data, u8_Length); tp_WriteRequest->handle = u16_CharacterHandle; if (GATT_WriteNoRsp(u16_ConnectionHandle, tp_WriteRequest) != SUCCESS) { GATT_bm_free(&t_Message, ATT_WRITE_REQ); return FUNCTION_FAIL; } } Event_post(t_ICallSyncHandle, EVENT_WRITE); return FUNCTION_OK; }