热度 2|
Binaries | 存放的是生成的elf文件 | |
Include | 包含头文件路径及头文件 | |
config | 工程配置及系统配置相关的文件 | |
App | 用户应用层相关源文件(这个是我后面建的,原DEMO中没有,原工程中main文件放在工程目录下的) | |
misc | 关于内在地址的一些配置,不需要改动 | |
sdk | adapters | 存放的是系统应用层的驱动接口源文件,包括电池,i2c,uart等 |
ble | BLE协议栈相关的源文件,一般情况下不需要修改 | |
ble_service | 存放的是蓝牙服务相关的源代码 | |
bsp_include | 存放的是底层相关的一些头文件 | |
config | 存放的是配置相关的头文件,一般情况下不需要修改 | |
cpm | 存放的是系统相关的一些应用文件,一般情况下不需要修改 | |
FreeRTOS | 存放的是FreeRTOS相关的一条源文件,一般情况下不需要修改 | |
Idscripts | 链接相关的一些文件,不需要修改 | |
memory | 关于外部FLASH相关的源文件,换外部FALSH时可能要修改,目前没仔细研究 | |
osal | 系统相关的源文件,一般情况下不需要修改 | |
peripherals | 芯片外设相关的驱动,在适当的时候调用或者配合系统调用 | |
startup | 关于芯片底层的一些配置文件,暂时不需要改动 |
static void myservice_init(ble_service_t *include_svc) { att_uuid_t uuid; /* * This service does absolutely nothing, it just checks that it's possible to use 128-bit * UUIDs for services, characteristics and descriptors. */ // 这些API在 ble_uuid.c中有调用 ble_uuid_from_string("91a7608d-4456-479d-b9b1-4706e8711cf8", &uuid); ble_gatts_add_service(&uuid, GATT_SERVICE_PRIMARY, ble_gatts_get_num_attr(1, 1, 1)); if (include_svc) { ble_gatts_add_include(include_svc->start_h, NULL); } ble_uuid_from_string("25047e64-657c-4856-afcf-e315048a965b", &uuid); ble_gatts_add_characteristic(&uuid, GATT_PROP_NONE, ATT_PERM_NONE, 1, 0, NULL, NULL); ble_uuid_from_string("6b09fe25-eed7-41fc-8da7-1ec89fab7ecb", &uuid); ble_gatts_add_descriptor(&uuid, ATT_PERM_NONE, 1, 0, NULL); ble_gatts_register_service(NULL, 0); } |
void ble_peripheral_task(void *params) { int8_t wdog_id; #if CFG_CTS ble_service_t *cts; cts_local_time_info_t cts_lti = { /* Example time zone, should be taken from permanent storage or RTC */ .dst = CTS_DST_DAYLIGHT_TIME, .time_zone = cts_get_time_zone(+3, 0), // UTC + 3 Athens }; #endif ble_service_t *svc; // in case services which do not use svc are all disabled, just surpress -Wunused-variable (void) svc; file:///C:\Users\XCU\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png /* register ble_peripheral task to be monitored by watchdog */ wdog_id = sys_watchdog_register(false); ble_peripheral_task_handle = OS_GET_CURRENT_TASK(); srand(time(NULL)); ble_peripheral_start(); ble_register_app(); ble_gap_device_name_set("Dialog Peripheral", ATT_PERM_READ); file:///C:\Users\XCU\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png #if CFG_DEBUG_SERVICE /* register debug service */ dbgs = dlgdebug_init(NULL); #endif /* CFG_DEBUG_SERVICE */ #if CFG_BAS #if CFG_BAS_MULTIPLE /* register BAS (1st instance) */ svc = bas_init(NULL, &bas_bat1); #if CFG_DEBUG_SERVICE dlgdebug_register_handler(dbgs, "bas", "set", dbg_bas_set, svc); #endif /* CFG_DEBUG_SERVICE */ bas_set_level(svc, 90, false); /* register BAS (2nd instance) */ svc = bas_init(NULL, &bas_bat2); bas_set_level(svc, 60, false); #else file:///C:\Users\XCU\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png /* register BAS */ svc = bas_init(NULL, NULL); #if CFG_DEBUG_SERVICE dlgdebug_register_handler(dbgs, "bas", "set", dbg_bas_set, svc); #endif /* CFG_DEBUG_SERVICE */ bas_set_level(svc, 90, false); #endif /* CFG_BAS_MULTIPLE */ #endif /* CFG_BAS */ #if CFG_CTS /* register CTS */ cts = cts_init(&cts_lti, &cts_callbacks); #if CFG_DEBUG_SERVICE dlgdebug_register_handler(dbgs, "cts", "adjust", dbg_cts_adjust, cts); #endif /* CFG_DEBUG_SERVICE */ #endif #if CFG_USER_SERVICE /* register custom service */ #if CFG_CTS myservice_init(cts); #else myservice_init(NULL); #endif #endif #if CFG_DIS /* Add DIS */ dis_init(NULL, &dis_info); #endif #if CFG_SCPS /* register ScPS */ scps_init(&scps_callbacks); #endif #if CFG_CTS /* create timer for CTS, this will be used to update current time every second */ cts_timer = OS_TIMER_CREATE("cts", portCONVERT_MS_2_TICKS(1000), OS_TIMER_SUCCESS, (void *) OS_GET_CURRENT_TASK(), cts_timer_cb); OS_ASSERT(cts_timer); OS_TIMER_START(cts_timer, OS_TIMER_FOREVER); #endif file:///C:\Users\XCU\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png ble_gap_adv_data_set(sizeof(adv_data), adv_data, 0, NULL); ble_gap_adv_start(GAP_CONN_MODE_UNDIRECTED); for (;;) { OS_BASE_TYPE ret; uint32_t notif; /* notify watchdog on each loop */ sys_watchdog_notify(wdog_id); /* suspend watchdog while blocking on OS_TASK_NOTIFY_WAIT() */ sys_watchdog_suspend(wdog_id); /* * Wait on any of the notification bits, then clear them all */ ret = OS_TASK_NOTIFY_WAIT(0, OS_TASK_NOTIFY_ALL_BITS, ¬if, OS_TASK_NOTIFY_FOREVER); /* Blocks forever waiting for task notification. The return value must be OS_OK */ OS_ASSERT(ret == OS_OK); /* resume watchdog */ sys_watchdog_notify_and_resume(wdog_id); /* notified from BLE manager, can get event */ if (notif & BLE_APP_NOTIFY_MASK) { file:///C:\Users\XCU\AppData\Local\Temp\msohtmlclip1\01\clip_image006.png ble_evt_hdr_t *hdr; hdr = ble_get_event(false); if (!hdr) { goto no_event; } if (ble_service_handle_event(hdr)) { goto handled; } switch (hdr->evt_code) { case BLE_EVT_GAP_CONNECTED: { handle_evt_gap_connected((ble_evt_gap_connected_t *) hdr); }break; case BLE_EVT_GAP_ADV_COMPLETED: { handle_evt_gap_adv_completed((ble_evt_gap_adv_completed_t *) hdr); }break; case BLE_EVT_GAP_DISCONNECTED: { handle_evt_gap_disconnected((ble_evt_gap_disconnected_t *) hdr); }break; case BLE_EVT_GAP_PAIR_REQ: { ble_evt_gap_pair_req_t *evt = (ble_evt_gap_pair_req_t *) hdr; ble_gap_pair_reply(evt->conn_idx, true, evt->bond); break; } default: { ble_handle_event_default(hdr); }break; } handled: OS_FREE(hdr); no_event: // notify again if there are more events to process in queue if (ble_has_event()) { OS_TASK_NOTIFY(OS_GET_CURRENT_TASK(), BLE_APP_NOTIFY_MASK, eSetBits); } } file:///C:\Users\XCU\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png#if CFG_CTS if (notif & CTS_SET_TIME_NOTIF) { cts_notify_time_all(cts, &cts_time); } #endif } } |