diff --git a/Makefile b/Makefile index 6dd2598a..d81dd87b 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ SUPPORT_ROMAPI?=y SUPPORT_HALAPI?=y SUPPORT_USB_HS?=n SUPPORT_HW_SEC_ENG_DISABLE?=n -SUPPORT_BLECONTROLLER_LIB?= +SUPPORT_BLECONTROLLER_LIB?=std #cmake definition config cmake_definition+= -DCHIP=$(CHIP) diff --git a/components/ble/bl702_rf/lib/libbl702_rf.a b/components/ble/bl702_rf/lib/libbl702_rf.a index eb99532e..dc37ffcd 100644 Binary files a/components/ble/bl702_rf/lib/libbl702_rf.a and b/components/ble/bl702_rf/lib/libbl702_rf.a differ diff --git a/components/ble/ble_stack/bl_hci_wrapper/bl_hci_wrapper.c b/components/ble/ble_stack/bl_hci_wrapper/bl_hci_wrapper.c index 238b9b20..dd90fba1 100644 --- a/components/ble/ble_stack/bl_hci_wrapper/bl_hci_wrapper.c +++ b/components/ble/ble_stack/bl_hci_wrapper/bl_hci_wrapper.c @@ -15,7 +15,7 @@ #include "hci_host.h" #include "bl_hci_wrapper.h" #include "hci_driver.h" -#include "../common/include/errno.h" +#include "errno.h" #include "byteorder.h" #include "hci_onchip.h" @@ -187,12 +187,14 @@ void bl_packet_to_host(uint8_t pkt_type, uint16_t src_id, uint8_t *param, uint8_ memcpy(buf_data, param, param_len); break; } +#if defined(CONFIG_BT_CONN) case BT_HCI_ACL_DATA: { prio = false; bt_buf_set_type(buf, BT_BUF_ACL_IN); tlt_len = bt_onchiphci_hanlde_rx_acl(param, buf_data); break; } +#endif default: { net_buf_unref(buf); return; @@ -217,14 +219,18 @@ void bl_trigger_queued_msg() unsigned int lock = irq_lock(); if (k_queue_is_empty(&msg_queue)) { + irq_unlock(lock); break; } - if (bt_buf_get_rx_avail_cnt() <= CONFIG_BT_RX_BUF_RSV_COUNT) + if (bt_buf_get_rx_avail_cnt() <= CONFIG_BT_RX_BUF_RSV_COUNT) { + irq_unlock(lock); break; + } buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT); if (!buf) { + irq_unlock(lock); break; } @@ -253,7 +259,9 @@ static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, ui buf = bt_buf_get_cmd_complete(K_FOREVER); bl_packet_to_host(pkt_type, src_id, param, param_len, buf); return; - } else if (pkt_type == BT_HCI_LE_EVT && param[0] == BT_HCI_EVT_LE_ADVERTISING_REPORT) { + } +#if defined(CONFIG_BT_OBSERVER) || defined(CONFIG_BT_CENTRAL) || defined(CONFIG_BT_ALLROLES) + else if (pkt_type == BT_HCI_LE_EVT && param[0] == BT_HCI_EVT_LE_ADVERTISING_REPORT) { if (bt_buf_get_rx_avail_cnt() <= CONFIG_BT_RX_BUF_RSV_COUNT) { BT_INFO("Discard adv report."); #if defined(BFLB_BLE_NOTIFY_ADV_DISCARDED) @@ -265,7 +273,9 @@ static void bl_onchiphci_rx_packet_handler(uint8_t pkt_type, uint16_t src_id, ui if (buf) bl_packet_to_host(pkt_type, src_id, param, param_len, buf); return; - } else { + } +#endif /*(CONFIG_BT_OBSERVER || CONFIG_BT_CENTRAL || CONFIG_BT_ALLROLES)*/ + else { if (pkt_type != BT_HCI_ACL_DATA) { /* Using the reserved buf (CONFIG_BT_RX_BUF_RSV_COUNT) firstly. */ buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT); diff --git a/components/ble/ble_stack/cli_cmds/ble_cli_cmds.c b/components/ble/ble_stack/cli_cmds/ble_cli_cmds.c index de73e85b..4821a711 100644 --- a/components/ble/ble_stack/cli_cmds/ble_cli_cmds.c +++ b/components/ble/ble_stack/cli_cmds/ble_cli_cmds.c @@ -28,9 +28,12 @@ bool ble_inited = false; struct bt_conn *default_conn = NULL; #endif +uint8_t non_disc = BT_LE_AD_NO_BREDR; +uint8_t gen_disc = BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL; +uint8_t lim_disc = BT_LE_AD_NO_BREDR | BT_LE_AD_LIMITED; struct bt_data ad_discov[2] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL)), - BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, 13), + BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL), + BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME), }; #if defined(CONFIG_BLE_MULTI_ADV) static int ble_adv_id; @@ -41,6 +44,7 @@ static int ble_adv_id; static void blecli_init(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); #if defined(BL702) static void blecli_set_2M_phy(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); +static void blecli_set_coded_phy(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); static void blecli_set_default_phy(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); #endif static void blecli_get_device_name(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); @@ -68,6 +72,7 @@ static void blecli_connect(char *pcWriteBuffer, int xWriteBufferLen, int argc, c static void blecli_disconnect(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); static void blecli_select_conn(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); static void blecli_conn_update(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); +static void blecli_read_rssi(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); static void blecli_unpair(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); #endif #if defined(CONFIG_BT_SMP) @@ -100,141 +105,142 @@ static void blecli_hog_srv_notify(char *pcWriteBuffer, int xWriteBufferLen, int #endif const struct cli_command btStackCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = { -#if 0 +#if 1 /*1.The cmd string to type, 2.Cmd description, 3.The function to run, 4.Number of parameters*/ - {"ble_init", "\r\nble_init:[Initialize]\r\n Parameter[Null]\r\n", blecli_init}, - - {"ble_get_device_name", "\r\nble_get_device_name:[Read local device name]\r\n Parameter[Null]\r\n", blecli_get_device_name}, - - {"ble_set_device_name", "\r\nble_set_device_name:\r\n\[Lenth of name]\r\n\[name]\r\n", blecli_set_device_name}, + { "ble_init", "ble Initialize\r\nParameter [Null]\r\n", blecli_init }, + { "ble_get_device_name", "ble get device name\r\nParameter [Null]\r\n", blecli_get_device_name }, + { "ble_set_device_name", "ble set device name\r\nParameter [Lenth of name] [name]\r\n", blecli_set_device_name }, #if defined(CONFIG_BLE_TP_SERVER) - - {"ble_tp_start", "\r\nble_tp_start:\r\n\ - [TP test,1:enable, 0:disable]\r\n", blecli_tp_start}, + { "ble_tp_start", "throughput start\r\nParameter [TP test,1:enable, 0:disable]\r\n", blecli_tp_start }, +#endif +#if defined(BL702) +#if defined(CONFIG_BT_CONN) + { "ble_set_default_phy", "ble set default phy\r\nParameter [defualt phys]\r\n", blecli_set_default_phy }, + { "ble_set_2M_Phy", "ble set 2M Phy\r\nParameter [defualt phys]\r\n", blecli_set_2M_phy }, + { "ble_set_coded_phy", "ble set coded phy\r\nParameter [all phys] [coded option]\r\n", blecli_set_coded_phy }, +#endif #endif - #if defined(CONFIG_BT_OBSERVER) - {"ble_start_scan", "\r\nble_start_scan:\r\n\ - [Scan type, 0:passive scan, 1:active scan]\r\n\ - [Duplicate filtering, 0:Disable duplicate filtering, 1:Enable duplicate filtering]\r\n\ - [Scan interval, 0x0004-4000,e.g.0080]\r\n\ - [Scan window, 0x0004-4000,e.g.0050]\r\n", blecli_start_scan}, - - {"ble_stop_scan", "\r\nble_stop_scan:[Stop scan]\r\nParameter[Null]\r\n", blecli_stop_scan}, +#if defined(BL702) || defined(BL602) + { "ble_scan_filter_size", "ble scan filter sizer\nParameter [filter table size]\r\n", blecli_scan_filter_size }, +#endif +#endif +#if defined(BFLB_DISABLE_BT) + { "ble_disable", "ble disable\r\nParameter [Null]\r\n", blecli_disable }, +#endif +#if defined(CONFIG_BT_OBSERVER) + { "ble_start_scan", " ble start scan\r\n\ + Parameter [Scan type, 0:passive scan, 1:active scan]\r\n\ + [filtering, 0:Disable duplicate, 1:Enable duplicate]\r\n\ + [Scan interval, 0x0004-4000,e.g.0080]\r\n\ + [Scan window, 0x0004-4000,e.g.0050]\r\n", + blecli_start_scan }, + { "ble_stop_scan", "ble stop scan\r\nParameter [Null]\r\n", blecli_stop_scan }, #endif - #if defined(CONFIG_BT_PERIPHERAL) - {"ble_start_adv", "\r\nble_start_adv:\r\n\ - [Adv type,0:adv_ind,1:adv_scan_ind,2:adv_nonconn_ind]\r\n\ + { "ble_set_adv_channel", "ble set adv channel\r\nParameter [adv channel]\r\n", blecli_set_adv_channel }, + { "ble_start_adv", "ble start adv\r\n\ + Parameter [Adv type, 0:adv_ind, 1:adv_scan_ind, 2:adv_nonconn_ind]\r\n\ [Mode, 0:discov, 1:non-discov]\r\n\ [Adv Interval Min,0x0020-4000,e.g.0030]\r\n\ - [Adv Interval Max,0x0020-4000,e.g.0060]\r\n", blecli_start_advertise}, - - {"ble_stop_adv", "\r\nble_stop_adv:[Stop advertising]\r\nParameter[Null]\r\n", blecli_stop_advertise}, - - {"ble_read_local_address", "\r\nble_read_local_address:[Read local address]\r\n", blecli_read_local_address}, + [Adv Interval Max,0x0020-4000,e.g.0060]\r\n", + blecli_start_advertise }, + { "ble_stop_adv", "ble stop adv\r\nParameter [Null]\r\n", blecli_stop_advertise }, +#if defined(CONFIG_BLE_MULTI_ADV) + { "ble_start_multi_adv", "ble start multi adv\r\nParameter [Null]\r\n", blecli_start_multi_advertise }, + { "ble_stop_multi_adv", "ble stop multi adv\r\nParameter [instant id]\r\n", blecli_stop_multi_advertise }, +#endif + { "ble_read_local_address", "ble read local address\r\nParameter [Null]\r\n", blecli_read_local_address }, #endif - #if defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_CENTRAL) - {"ble_connect", "\r\nble_connect:[Connect remote device]\r\n\ - [Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\ - [Address value, e.g.112233AABBCC]\r\n", blecli_connect}, -#endif //CONFIG_BT_CENTRAL - - {"ble_disconnect", "\r\nble_disconnect:[Disconnect remote device]\r\n\ - [Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\ - [Address value,e.g.112233AABBCC]\r\n", blecli_disconnect}, - - {"ble_select_conn", "\r\nble_select_conn:[Select a specific connection]\r\n\ - [Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\ - [Address value, e.g.112233AABBCC]\r\n", blecli_select_conn}, - - {"ble_unpair", "\r\nble_unpair:[Unpair connection]\r\n\ - [Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\ - [Address value, all 0: unpair all connection, otherwise:unpair specific connection]\r\n", blecli_unpair}, - - {"ble_conn_update", "\r\nble_conn_update:\r\n\ - [Conn Interval Min,0x0006-0C80,e.g.0030]\r\n\ + { "ble_connect", "ble Connect remote device\r\n\ + Parameter [Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\ + [Address value, e.g.112233AABBCC]\r\n", + blecli_connect }, +#endif + { "ble_disconnect", "Disconnect remote device\r\n\ + Parameter [Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\ + [Address value,e.g.112233AABBCC]\r\n", + blecli_disconnect }, + { "ble_select_conn", "Select a specific connection\r\n\ + Parameter [Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\ + [Address value, e.g.112233AABBCC]\r\n", + blecli_select_conn }, + { "ble_unpair", "bleUnpair connection]\r\n\ + Parameter [Address type, 0:ADDR_PUBLIC, 1:ADDR_RAND, 2:ADDR_RPA_OR_PUBLIC, 3:ADDR_RPA_OR_RAND]\r\n\ + [Address value, all 0: unpair all connection, otherwise:unpair specific connection]\r\n", + blecli_unpair }, + { "ble_conn_update", "ble conn update\r\n\ + Parameter [Conn Interval Min,0x0006-0C80,e.g.0030]\r\n\ [Conn Interval Max,0x0006-0C80,e.g.0030]\r\n\ [Conn Latency,0x0000-01f3,e.g.0004]\r\n\ - [Supervision Timeout,0x000A-0C80,e.g.0010]\r\n", blecli_conn_update}, -#endif //CONFIG_BT_CONN - + [Supervision Timeout,0x000A-0C80,e.g.0010]\r\n", + blecli_conn_update }, + { "ble_read_rssi", "ble read rssi\r\nParameter [Null]\r\n", blecli_read_rssi }, #if defined(CONFIG_BT_SMP) - {"ble_security", "\r\nble_security:[Start security]\r\n\ - [Security level, Default value 4, 2:BT_SECURITY_MEDIUM, 3:BT_SECURITY_HIGH, 4:BT_SECURITY_FIPS]\r\n", blecli_security}, - - {"ble_auth", "\r\nble_auth:[Register auth callback]\r\n", blecli_auth}, - - {"ble_auth_cancel", "\r\nble_auth_cancel:[Register auth callback]\r\n", blecli_auth_cancel}, - - {"ble_auth_passkey_confirm", "\r\nble_auth_passkey_confirm:[Confirm passkey]\r\n", blecli_auth_passkey_confirm}, - - {"ble_auth_pairing_confirm", "\r\nble_auth_pairing_confirm:[Confirm pairing in secure connection]\r\n", blecli_auth_pairing_confirm}, - - {"ble_auth_passkey", "\r\nble_auth_passkey:[Input passkey]\r\n[Passkey, 00000000-000F423F]", blecli_auth_passkey}, - -#endif //CONFIG_BT_SMP - + { "ble_security", "Start security\r\n\ + Parameter [Security level, Default value 4, 2:BT_SECURITY_MEDIUM, 3:BT_SECURITY_HIGH, 4:BT_SECURITY_FIPS]\r\n", + blecli_security }, + { "ble_auth", "Register auth callback\r\nParameter [Null]\r\n", blecli_auth }, + { "ble_auth_cancel", "Cancel register auth callback\r\nParameter [Null]]\r\n", blecli_auth_cancel }, + { "ble_auth_passkey_confirm", "Confirm passkey]\r\nParameter [Null]]\r\n", blecli_auth_passkey_confirm }, + { "ble_auth_pairing_confirm", "Confirm pairing in secure connection\r\nParameter [Null]\r\n", blecli_auth_pairing_confirm }, + { "ble_auth_passkey", "Input passkey\r\nParameter [Passkey, 00000000-000F423F]\r\n", blecli_auth_passkey }, +#endif #if defined(CONFIG_BT_GATT_CLIENT) - {"ble_exchange_mtu", "\r\nble_exchange_mtu:[Exchange mtu]\r\n Parameter[Null]\r\n", blecli_exchange_mtu}, - - {"ble_discover", "\r\nble_discover:[Gatt discovery]\r\n\ - [Discovery type, 0:Primary, 1:Secondary, 2:Include, 3:Characteristic, 4:Descriptor]\r\n\ + { "ble_exchange_mtu", "Exchange mtu\r\nParameter [Null]\r\n", blecli_exchange_mtu }, + { "ble_discover", "Gatt discovery\r\n\ + Parameter [Discovery type, 0:Primary, 1:Secondary, 2:Include, 3:Characteristic, 4:Descriptor]\r\n\ [Uuid value, 2 Octets, e.g.1800]\r\n\ [Start handle, 2 Octets, e.g.0001]\r\n\ - [End handle, 2 Octets, e.g.ffff]\r\n", blecli_discover}, - - {"ble_read", "\r\nble_read:[Gatt Read]\r\n\ - [Attribute handle, 2 Octets]\r\n\ - [Value offset, 2 Octets]\r\n", blecli_read}, - - {"ble_write", "\r\nble_write:[Gatt write]\r\n\ - [Attribute handle, 2 Octets]\r\n\ + [End handle, 2 Octets, e.g.ffff]\r\n", + blecli_discover }, + { "ble_read", "Gatt Read\r\n\ + Parameter [Attribute handle, 2 Octets]\r\n\ + [Value offset, 2 Octets]\r\n", + blecli_read }, + { "ble_write", "Gatt write\r\n\ + Parameter [Attribute handle, 2 Octets]\r\n\ [Value offset, 2 Octets]\r\n\ [Value length, 2 Octets]\r\n\ - [Value data]\r\n", blecli_write}, - - {"ble_write_without_rsp", "\r\nble_write_without_rsp:[Gatt write without response]\r\n\ - [Sign, 0: No need signed, 1:Signed write cmd if no smp]\r\n\ + [Value data]\r\n", + blecli_write }, + { "ble_write_without_rsp", "Gatt write without response\r\n\ + Parameter [Sign, 0: No need signed, 1:Signed write cmd if no smp]\r\n\ [Attribute handle, 2 Octets]\r\n\ [Value length, 2 Octets]\r\n\ - [Value data]\r\n", blecli_write_without_rsp}, - - {"ble_subscribe", "\r\nble_subscribe:[Gatt subscribe]\r\n\ - [CCC handle, 2 Octets]\r\n\ + [Value data]\r\n", + blecli_write_without_rsp }, + { "ble_subscribe", "Gatt subscribe\r\n\ + Parameter [CCC handle, 2 Octets]\r\n\ [Value handle, 2 Octets]\r\n\ - [Value, 1:notify, 2:indicate]\r\n", blecli_subscribe}, - - {"ble_unsubscribe", "\r\nble_unsubscribe:[Gatt unsubscribe]\r\n Parameter[Null]\r\n", blecli_unsubscribe}, -#endif /*CONFIG_BT_GATT_CLIENT*/ - - {"ble_set_data_len", - "\r\nble_set_data_len:[LE Set Data Length]\r\n\ - [tx octets, 2 octets]\r\n\ - [tx time, 2 octets]\r\n", - blecli_set_data_len}, - - {"ble_conn_info", "\r\nble_conn_info:[LE get all connection devices info]\r\n", blecli_get_all_conn_info}, + [Value, 1:notify, 2:indicate]\r\n", + blecli_subscribe }, + { "ble_unsubscribe", "Gatt unsubscribe\r\nParameter [Null]\r\n", blecli_unsubscribe }, +#endif + { "ble_set_data_len", "LE Set Data Length\r\n\ + Parameter [tx octets, 2 octets] [tx time, 2 octets]\r\n", + blecli_set_data_len }, + { "ble_conn_info", "LE get all connection devices info\r\nParameter [Null]\r\n", blecli_get_all_conn_info }, +#endif //CONFIG_BT_CONN #if defined(CONFIG_SET_TX_PWR) - {"ble_set_tx_pwr", - "\r\nble_set_tx_pwr:[Set tx power mode]\r\n\ - [mode, 1 octet, value:5,6,7]\r\n", - blecli_set_tx_pwr}, + { "ble_set_tx_pwr", "Set tx power mode\r\nParameter [mode, 1 octet, value:5,6,7]\r\n", blecli_set_tx_pwr }, +#endif +#if defined(CONFIG_HOGP_SERVER) + { "ble_hog_srv_notify", "HOG srv notify\r\nParameter [hid usage] [press]\r\n", blecli_hog_srv_notify }, #endif #else { "ble_init", "", blecli_init }, - #if defined(CONFIG_BLE_TP_SERVER) { "ble_tp_start", "", blecli_tp_start }, #endif - #if defined(BL702) { "ble_set_2M_Phy", "", blecli_set_2M_phy }, + { "ble_set_coded_phy", "", blecli_set_coded_phy }, { "ble_set_default_phy", "", blecli_set_default_phy }, #endif #if defined(BFLB_DISABLE_BT) @@ -247,7 +253,7 @@ const struct cli_command btStackCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = { { "ble_stop_scan", "", blecli_stop_scan }, #if defined(BL702) || defined(BL602) { "ble_scan_filter_size", "", blecli_scan_filter_size }, -#endif /* BL702 || BL602*/ +#endif #endif #if defined(CONFIG_BT_PERIPHERAL) { "ble_set_adv_channel", "", blecli_set_adv_channel }, @@ -262,12 +268,13 @@ const struct cli_command btStackCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = { #if defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_CENTRAL) { "ble_connect", "", blecli_connect }, -#endif //CONFIG_BT_CENTRAL +#endif { "ble_disconnect", "", blecli_disconnect }, { "ble_select_conn", "", blecli_select_conn }, { "ble_unpair", "", blecli_unpair }, { "ble_conn_update", "", blecli_conn_update }, -#endif //CONFIG_BT_CONN + { "ble_read_rssi", "", blecli_read_rssi }, +#endif #if defined(CONFIG_BT_SMP) { "ble_security", "", blecli_security }, { "ble_auth", "", blecli_auth }, @@ -275,7 +282,7 @@ const struct cli_command btStackCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = { { "ble_auth_passkey_confirm", "", blecli_auth_passkey_confirm }, { "ble_auth_pairing_confirm", "", blecli_auth_pairing_confirm }, { "ble_auth_passkey", "", blecli_auth_passkey }, -#endif //CONFIG_BT_SMP +#endif #if defined(CONFIG_BT_GATT_CLIENT) { "ble_exchange_mtu", "", blecli_exchange_mtu }, { "ble_discover", "", blecli_discover }, @@ -284,7 +291,7 @@ const struct cli_command btStackCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = { { "ble_write_without_rsp", "", blecli_write_without_rsp }, { "ble_subscribe", "", blecli_subscribe }, { "ble_unsubscribe", "", blecli_unsubscribe }, -#endif /*CONFIG_BT_GATT_CLIENT*/ +#endif { "ble_set_data_len", "", blecli_set_data_len }, { "ble_conn_info", "", blecli_get_all_conn_info }, #if defined(CONFIG_SET_TX_PWR) @@ -299,6 +306,10 @@ const struct cli_command btStackCmdSet[] STATIC_CLI_CMD_ATTRIBUTE = { #if defined(CONFIG_BT_CONN) static void connected(struct bt_conn *conn, u8_t err) { + if (err || conn->type != BT_CONN_TYPE_LE) { + return; + } + char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); @@ -333,6 +344,10 @@ static void connected(struct bt_conn *conn, u8_t err) static void disconnected(struct bt_conn *conn, u8_t reason) { + if (conn->type != BT_CONN_TYPE_LE) { + return; + } + char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); @@ -349,6 +364,10 @@ static void disconnected(struct bt_conn *conn, u8_t reason) #endif if (default_conn == conn) { +#if defined(CONFIG_BT_CENTRAL) + if (conn->role == BT_HCI_ROLE_MASTER) + bt_conn_unref(conn); +#endif default_conn = NULL; } } @@ -356,28 +375,41 @@ static void disconnected(struct bt_conn *conn, u8_t reason) static void le_param_updated(struct bt_conn *conn, u16_t interval, u16_t latency, u16_t timeout) { - vOutputString("LE conn param updated: int 0x%04x lat %d to %d \r\n", interval, latency, timeout); + if (conn == default_conn) { + vOutputString("LE conn param updated: int 0x%04x lat %d to %d \r\n", interval, latency, timeout); + } +} + +static void le_phy_updated(struct bt_conn *conn, u8_t tx_phy, u8_t rx_phy) +{ + if (conn == default_conn) { + vOutputString("LE phy updated: rx_phy %d, rx_phy %d\r\n", tx_phy, rx_phy); + } } #if defined(CONFIG_BT_SMP) static void identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, const bt_addr_le_t *identity) { - char addr_identity[BT_ADDR_LE_STR_LEN]; - char addr_rpa[BT_ADDR_LE_STR_LEN]; + if (conn == default_conn) { + char addr_identity[BT_ADDR_LE_STR_LEN]; + char addr_rpa[BT_ADDR_LE_STR_LEN]; - bt_addr_le_to_str(identity, addr_identity, sizeof(addr_identity)); - bt_addr_le_to_str(rpa, addr_rpa, sizeof(addr_rpa)); + bt_addr_le_to_str(identity, addr_identity, sizeof(addr_identity)); + bt_addr_le_to_str(rpa, addr_rpa, sizeof(addr_rpa)); - vOutputString("Identity resolved %s -> %s \r\n", addr_rpa, addr_identity); + vOutputString("Identity resolved %s -> %s \r\n", addr_rpa, addr_identity); + } } static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) { - char addr[BT_ADDR_LE_STR_LEN]; + if (conn == default_conn) { + char addr[BT_ADDR_LE_STR_LEN]; - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - vOutputString("Security changed: %s level %u \r\n", addr, level); + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + vOutputString("Security changed: %s level %u \r\n", addr, level); + } } #endif @@ -385,6 +417,7 @@ static struct bt_conn_cb conn_callbacks = { .connected = connected, .disconnected = disconnected, .le_param_updated = le_param_updated, + .le_phy_updated = le_phy_updated, #if defined(CONFIG_BT_SMP) .identity_resolved = identity_resolved, .security_changed = security_changed, @@ -406,48 +439,74 @@ static void blecli_init(char *pcWriteBuffer, int xWriteBufferLen, int argc, char ble_inited = true; vOutputString("Init successfully \r\n"); } + #if defined(BL702) +#if defined(CONFIG_BT_CONN) static void blecli_set_2M_phy(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { + int err = 0; + if (!default_conn) { vOutputString("Not connected \r\n"); return; } - if (!hci_le_set_phy(default_conn)) { - vOutputString("Set ble 2M Phy successfully \r\n"); + err = hci_le_set_phy(default_conn, 0U, BT_HCI_LE_PHY_PREFER_2M, + BT_HCI_LE_PHY_PREFER_2M, + BT_HCI_LE_PHY_CODED_ANY); + if (!err) { + vOutputString("Set ble 2M Phy pending \r\n"); } else { vOutputString("Failed to set ble 2M Phy\r\n"); } } -static void blecli_set_default_phy(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) +static void blecli_set_coded_phy(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { - u8_t phy = 0; - u8_t default_phy = 0; + int err = 0; + uint8_t all_phys = 0; + uint8_t opts; + uint8_t coded_opts = BT_HCI_LE_PHY_CODED_ANY; if (!default_conn) { vOutputString("Not connected \r\n"); return; } - get_uint8_from_string(&argv[1], &phy); - if (phy == 0) { - default_phy = BT_HCI_LE_PHY_PREFER_1M; - } else if (phy == 1) { - default_phy = BT_HCI_LE_PHY_PREFER_2M; - } else if (phy == 2) { - default_phy = BT_HCI_LE_PHY_PREFER_CODED; - } else { - vOutputString("Invaild parameter\r\n"); + get_uint8_from_string(&argv[1], &all_phys); + + get_uint8_from_string(&argv[2], &opts); + if (opts == 2) { + coded_opts = BT_HCI_LE_PHY_CODED_S2; + } + if (opts == 8) { + coded_opts = BT_HCI_LE_PHY_CODED_S8; } - if (!hci_le_set_default_phy(default_conn, default_phy)) { - vOutputString("Set ble default(2M) Phy successfully \r\n"); + err = hci_le_set_phy(default_conn, all_phys, BT_HCI_LE_PHY_PREFER_CODED, + BT_HCI_LE_PHY_PREFER_CODED, + coded_opts); + if (!err) { + vOutputString("Set ble coded Phy pending \r\n"); } else { - vOutputString("Failed to set ble default(2M) Phy\r\n"); + vOutputString("Failed to set ble coded Phy\r\n"); + } +} + +static void blecli_set_default_phy(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) +{ + u8_t default_phy = 0; + + get_uint8_from_string(&argv[1], &default_phy); + + if (!hci_le_set_default_phy(default_phy)) { + vOutputString("Set ble default Phy successfully \r\n"); + } else { + vOutputString("Failed to set ble default Phy\r\n"); } } #endif +#endif + static void blecli_get_device_name(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { const char *device_name = bt_get_name(); @@ -649,35 +708,24 @@ static void blecli_start_advertise(char *pcWriteBuffer, int xWriteBufferLen, int return; } - /*Get mode, 0:General discoverable, 1:non discoverable, 2:limit discoverable*/ + /*Get mode, 0:General discoverable, 1:limit discoverable, 2:non discoverable*/ get_uint8_from_string(&argv[2], &mode); vOutputString("mode 0x%x\r\n", mode); - if (mode == 0 || mode == 1 || mode == 2) { - if (mode == 0) { - struct bt_data gen_disc_data = (struct bt_data)BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL)); - ad_discov[0] = gen_disc_data; - } else if (mode == 1) { - struct bt_data non_disc_data = (struct bt_data)BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR); - ad_discov[0] = non_disc_data; - } else if (mode == 2) { - struct bt_data limt_disc_data = (struct bt_data)BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_LIMITED)); - ad_discov[0] = limt_disc_data; - } else { - vOutputString("Invalied AD Mode 0x%x\r\n", mode); - } - - const char *name = bt_get_name(); - struct bt_data data = (struct bt_data)BT_DATA(BT_DATA_NAME_COMPLETE, name, strlen(name)); - ad_discov[1] = data; - - ad = ad_discov; - ad_len = ARRAY_SIZE(ad_discov); + if (mode == 0) { + ad_discov[0].data = &gen_disc; + } else if (mode == 1) { + ad_discov[0].data = &lim_disc; + } else if (mode == 2) { + ad_discov[0].data = &non_disc; } else { - vOutputString("Arg2 is invalid\r\n"); + vOutputString("Invalied AD Mode 0x%x\r\n", mode); return; } + ad = ad_discov; + ad_len = ARRAY_SIZE(ad_discov); + if (argc == 5) { get_uint16_from_string(&argv[3], ¶m.interval_min); get_uint16_from_string(&argv[4], ¶m.interval_max); @@ -730,6 +778,8 @@ static void blecli_stop_advertise(char *pcWriteBuffer, int xWriteBufferLen, int } #if defined(CONFIG_BLE_MULTI_ADV) +struct bt_data data_1 = (struct bt_data)BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, "multi_adv_connect_01"); +struct bt_data data_2 = (struct bt_data)BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, "multi_adv_nonconn_02"); static void blecli_start_multi_advertise(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { struct bt_le_adv_param param_1, param_2; @@ -743,11 +793,7 @@ static void blecli_start_multi_advertise(char *pcWriteBuffer, int xWriteBufferLe param_1.interval_max = 0x00A0; param_1.options = BT_LE_ADV_OPT_CONNECTABLE; - const char *name_1 = "multi_adv_connect_0x0001"; - struct bt_data flag_1 = (struct bt_data)BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL)); - struct bt_data data_1 = (struct bt_data)BT_DATA(BT_DATA_NAME_COMPLETE, name_1, strlen(name_1)); - ad_discov[0] = flag_1; - ad_discov[0] = data_1; + ad_discov[1] = data_1; ad_1 = ad_discov; ad_len_1 = ARRAY_SIZE(ad_discov); @@ -763,11 +809,7 @@ static void blecli_start_multi_advertise(char *pcWriteBuffer, int xWriteBufferLe param_2.interval_max = 0x0140; param_2.options = 0; - const char *name_2 = "multi_adv_nonconn_0x0002"; - struct bt_data flag_2 = (struct bt_data)BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL)); - struct bt_data data_2 = (struct bt_data)BT_DATA(BT_DATA_NAME_COMPLETE, name_2, strlen(name_2)); - ad_discov[0] = flag_2; - ad_discov[0] = data_2; + ad_discov[1] = data_2; ad_2 = ad_discov; ad_len_2 = ARRAY_SIZE(ad_discov); @@ -959,6 +1001,25 @@ static void blecli_conn_update(char *pcWriteBuffer, int xWriteBufferLen, int arg vOutputString("conn update initiated\r\n"); } } + +static void blecli_read_rssi(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) +{ + int8_t rssi; + int err; + + if (!default_conn) { + vOutputString("not connect\r\n"); + return; + } + + err = bt_le_read_rssi(default_conn->handle, &rssi); + if (err) { + vOutputString("read rssi failed (err %d)\r\n", err); + } else { + vOutputString("read rssi %d\r\n", rssi); + } +} + #endif //#if defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_SMP) @@ -1132,6 +1193,7 @@ static void blecli_auth_passkey(char *pcWriteBuffer, int xWriteBufferLen, int ar #endif //#if defined(CONFIG_BT_SMP) +#if defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_GATT_CLIENT) static void exchange_func(struct bt_conn *conn, u8_t err, struct bt_gatt_exchange_params *params) @@ -1450,6 +1512,7 @@ static u8_t notify_func(struct bt_conn *conn, #if defined(CONFIG_BLE_TP_TEST) static u32_t time = 0; static int len = 0; + static int8_t rssi; #endif if (!params->value) { @@ -1464,7 +1527,8 @@ static u8_t notify_func(struct bt_conn *conn, } len += length; if (k_now_ms() - time >= 1000) { - vOutputString("data_len=[%d]\r\n", len); + bt_le_read_rssi(default_conn->handle, &rssi); + vOutputString("data rate = [%d byte], rssi = [%d dbm]\r\n", len, rssi); time = k_now_ms(); len = 0; } @@ -1566,6 +1630,7 @@ static void blecli_get_all_conn_info(char *pcWriteBuffer, int xWriteBufferLen, i vOutputString("[%d]: address %s\r\n", i, le_addr); } } +#endif /* CONFIG_BT_CONN*/ #if defined(CONFIG_SET_TX_PWR) static void blecli_set_tx_pwr(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) diff --git a/components/ble/ble_stack/cli_cmds/bredr_cli_cmds.c b/components/ble/ble_stack/cli_cmds/bredr_cli_cmds.c index c473641f..bd321c44 100644 --- a/components/ble/ble_stack/cli_cmds/bredr_cli_cmds.c +++ b/components/ble/ble_stack/cli_cmds/bredr_cli_cmds.c @@ -9,14 +9,21 @@ #include #include #include +#include #include +#include #include +#if CONFIG_BT_A2DP +#include +#endif +#if CONFIG_BT_AVRCP +#include +#endif #include "cli.h" #if PCM_PRINTF #include "oi_codec_sbc.h" -#include "a2dp.h" #endif static void bredr_connected(struct bt_conn *conn, u8_t err); @@ -31,6 +38,26 @@ static struct bt_conn_cb conn_callbacks = { .disconnected = bredr_disconnected, }; +#if CONFIG_BT_A2DP +static void a2dp_chain(struct bt_conn *conn, uint8_t state); +static void a2dp_stream(uint8_t state); + +static struct a2dp_callback a2dp_callbacks = { + .chain = a2dp_chain, + .stream = a2dp_stream, +}; +#endif + +#if CONFIG_BT_AVRCP +static void avrcp_chain(struct bt_conn *conn, uint8_t state); +static void avrcp_absvol(uint8_t vol); + +static struct a2dp_callback avrcp_callbacks = { + .chain = avrcp_chain, + .stream = avrcp_absvol, +}; +#endif + #if PCM_PRINTF static void pcm(char *p_write_buffer, int write_buffer_len, int argc, char **argv); #endif @@ -38,6 +65,20 @@ static void bredr_init(char *pcWriteBuffer, int xWriteBufferLen, int argc, char static void bredr_write_eir(char *p_write_buffer, int write_buffer_len, int argc, char **argv); static void bredr_discoverable(char *p_write_buffer, int write_buffer_len, int argc, char **argv); static void bredr_connectable(char *p_write_buffer, int write_buffer_len, int argc, char **argv); +static void bredr_connect(char *p_write_buffer, int write_buffer_len, int argc, char **argv); +static void bredr_disconnect(char *p_write_buffer, int write_buffer_len, int argc, char **argv); +static void bredr_remote_name(char *p_write_buffer, int write_buffer_len, int argc, char **argv); + +#if CONFIG_BT_A2DP +static void a2dp_connect(char *p_write_buffer, int write_buffer_len, int argc, char **argv); +#endif + +#if CONFIG_BT_AVRCP +static void avrcp_connect(char *p_write_buffer, int write_buffer_len, int argc, char **argv); +static void avrcp_pth_key(char *p_write_buffer, int write_buffer_len, int argc, char **argv); +static void avrcp_pth_key_act(char *p_write_buffer, int write_buffer_len, int argc, char **argv); +static void avrcp_change_vol(char *p_write_buffer, int write_buffer_len, int argc, char **argv); +#endif const struct cli_command bredr_cmd_set[] STATIC_CLI_CMD_ATTRIBUTE = { #if PCM_PRINTF @@ -47,6 +88,20 @@ const struct cli_command bredr_cmd_set[] STATIC_CLI_CMD_ATTRIBUTE = { { "bredr_eir", "", bredr_write_eir }, { "bredr_connectable", "", bredr_connectable }, { "bredr_discoverable", "", bredr_discoverable }, + { "bredr_connect", "", bredr_connect }, + { "bredr_disconnect", "", bredr_disconnect }, + { "bredr_remote_name", "", bredr_remote_name }, + +#if CONFIG_BT_A2DP + { "a2dp_connect", "", a2dp_connect }, +#endif + +#if CONFIG_BT_AVRCP + { "avrcp_connect", "", avrcp_connect }, + { "avrcp_pth_key", "", avrcp_pth_key }, + { "avrcp_pth_key_act", "", avrcp_pth_key_act }, + { "avrcp_change_vol", "", avrcp_change_vol }, +#endif }; @@ -87,6 +142,12 @@ static void bredr_init(char *pcWriteBuffer, int xWriteBufferLen, int argc, char default_conn = NULL; bt_conn_cb_register(&conn_callbacks); +#if CONFIG_BT_A2DP + a2dp_cb_register(&a2dp_callbacks); +#endif +#if CONFIG_BT_AVRCP + avrcp_cb_register(&avrcp_callbacks); +#endif init = true; printf("bredr init successfully\n"); @@ -94,6 +155,10 @@ static void bredr_init(char *pcWriteBuffer, int xWriteBufferLen, int argc, char static void bredr_connected(struct bt_conn *conn, u8_t err) { + if (err || conn->type != BT_CONN_TYPE_BR) { + return; + } + char addr[BT_ADDR_STR_LEN]; bt_conn_get_info(conn, &conn_info); @@ -109,10 +174,16 @@ static void bredr_connected(struct bt_conn *conn, u8_t err) if (!default_conn) { default_conn = conn; } + + bt_br_set_connectable(false); } static void bredr_disconnected(struct bt_conn *conn, u8_t reason) { + if (conn->type != BT_CONN_TYPE_BR) { + return; + } + char addr[BT_ADDR_STR_LEN]; bt_conn_get_info(conn, &conn_info); @@ -128,7 +199,7 @@ static void bredr_disconnected(struct bt_conn *conn, u8_t reason) static void bredr_write_eir(char *p_write_buffer, int write_buffer_len, int argc, char **argv) { int err; - char *name = "Bouffalolab-bl606p-classic-bt"; + char *name = "Bouffalolab-classic-bluetooth"; uint8_t rec = 1; uint8_t data[32] = { 0 }; @@ -205,6 +276,222 @@ static void bredr_connectable(char *p_write_buffer, int write_buffer_len, int ar } } +static void bredr_connect(char *p_write_buffer, int write_buffer_len, int argc, char **argv) +{ + struct bt_conn *conn; + u8_t addr_val[6]; + bt_addr_t peer_addr; + struct bt_br_conn_param param; + char addr_str[18]; + + get_bytearray_from_string(&argv[1], addr_val, 6); + reverse_bytearray(addr_val, peer_addr.val, 6); + + bt_addr_to_str(&peer_addr, addr_str, sizeof(addr_str)); + printf("%s, create bredr connection with : %s \n", __func__, addr_str); + + param.allow_role_switch = true; + + conn = bt_conn_create_br(&peer_addr, ¶m); + if (conn) { + printf("Connect bredr ACL success.\n"); + } else { + printf("Connect bredr ACL fail.\n"); + } +} + +static void bredr_disconnect(char *p_write_buffer, int write_buffer_len, int argc, char **argv) +{ + if (!default_conn) { + printf("Not connected.\n"); + return; + } + + int err = bt_conn_disconnect(default_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + if (err) { + printf("Disconnection failed.\n"); + } else { + printf("Disconnect successfully.\n"); + } +} + +void remote_name(const char *name) +{ + if (name) { + printf("%s, remote name len: %d, : %s\n", __func__, strlen(name), name); + } else { + printf("%s, remote name request fail\n", __func__); + } +} + +static void bredr_remote_name(char *p_write_buffer, int write_buffer_len, int argc, char **argv) +{ + struct bt_conn *conn; + u8_t addr_val[6]; + bt_addr_t peer_addr; + char addr_str[18]; + + get_bytearray_from_string(&argv[1], addr_val, 6); + reverse_bytearray(addr_val, peer_addr.val, 6); + + bt_addr_to_str(&peer_addr, addr_str, sizeof(addr_str)); + printf("%s, create bredr connection with : %s \n", __func__, addr_str); + + int err = remote_name_req(&peer_addr, remote_name); + if (!err) { + printf("remote name request pending.\n"); + } else { + printf("remote name request fail.\n"); + } +} + +#if CONFIG_BT_A2DP +static void a2dp_chain(struct bt_conn *conn, uint8_t state) +{ + printf("%s, conn: %p \n", __func__, conn); + + if (state == BT_A2DP_CHAIN_CONNECTED) { + printf("a2dp connected. \n"); + } else if (state == BT_A2DP_CHAIN_DISCONNECTED) { + printf("a2dp disconnected. \n"); + } +} + +static void a2dp_stream(uint8_t state) +{ + printf("%s, state: %d \n", __func__, state); + + if (state == BT_A2DP_STREAM_START) { + printf("a2dp play. \n"); + } else if (state == BT_A2DP_STREAM_SUSPEND) { + printf("a2dp stop. \n"); + } +} + +static void a2dp_connect(char *p_write_buffer, int write_buffer_len, int argc, char **argv) +{ + int err; + + if (!default_conn) { + printf("Not connected.\n"); + return; + } + + err = bt_a2dp_connect(default_conn); + if (err) { + printf("a2dp connect failed, err: %d\n", err); + } else { + printf("a2dp connect successfully.\n"); + } +} +#endif + +#if CONFIG_BT_AVRCP +static void avrcp_chain(struct bt_conn *conn, uint8_t state) +{ + printf("%s, conn: %p \n", __func__, conn); + + if (state == BT_AVRCP_CHAIN_CONNECTED) { + printf("avrcp connected. \n"); + } else if (state == BT_AVRCP_CHAIN_DISCONNECTED) { + printf("avrcp disconnected. \n"); + } +} + +static void avrcp_absvol(uint8_t vol) +{ + printf("%s, vol: %d \n", __func__, vol); +} + +static void avrcp_connect(char *p_write_buffer, int write_buffer_len, int argc, char **argv) +{ + int err; + + if (!default_conn) { + printf("Not connected.\n"); + return; + } + + err = bt_avrcp_connect(default_conn); + if (err) { + printf("avrcp connect failed, err: %d\n", err); + } else { + printf("avrcp connect successfully.\n"); + } +} + +static void avrcp_pth_key(char *p_write_buffer, int write_buffer_len, int argc, char **argv) +{ + int err; + uint8_t key; + + if (!default_conn) { + printf("Not connected.\n"); + return; + } + + get_uint8_from_string(&argv[1], &key); + + err = avrcp_pasthr_cmd(NULL, PASTHR_STATE_PRESSED, key); + if (err) { + printf("avrcp key pressed failed, err: %d\n", err); + } else { + printf("avrcp key pressed successfully.\n"); + } + + err = avrcp_pasthr_cmd(NULL, PASTHR_STATE_RELEASED, key); + if (err) { + printf("avrcp key released failed, err: %d\n", err); + } else { + printf("avrcp key play released successfully.\n"); + } +} + +static void avrcp_pth_key_act(char *p_write_buffer, int write_buffer_len, int argc, char **argv) +{ + int err; + uint8_t key; + uint8_t action; + + if (!default_conn) { + printf("Not connected.\n"); + return; + } + + get_uint8_from_string(&argv[1], &key); + get_uint8_from_string(&argv[2], &action); + + if (action != PASTHR_STATE_PRESSED && action != PASTHR_STATE_RELEASED) { + printf("invalid key action.\n"); + return; + } + + err = avrcp_pasthr_cmd(NULL, action, key); + if (err) { + printf("avrcp key action failed, err: %d\n", err); + } else { + printf("avrcp %s key %d successfully.\n", action ? "released" : "pressed", key); + } +} + +static void avrcp_change_vol(char *p_write_buffer, int write_buffer_len, int argc, char **argv) +{ + int err; + uint8_t vol; + if (!default_conn) { + printf("Not connected.\n"); + return; + } + + get_uint8_from_string(&argv[1], &vol); + err = avrcp_change_volume(vol); + if (err) { + printf("avrcp change volume fail\n"); + } +} + +#endif + int bredr_cli_register(void) { // static command(s) do NOT need to call aos_cli_register_command(s) to register. diff --git a/components/ble/ble_stack/common/buf.c b/components/ble/ble_stack/common/buf.c index 44bdbda0..4778435a 100644 --- a/components/ble/ble_stack/common/buf.c +++ b/components/ble/ble_stack/common/buf.c @@ -28,6 +28,10 @@ #include "bl_hci_wrapper.h" #endif +#if (BFLB_STATIC_ALLOC_MEM) +#include "l2cap.h" +#endif + #if defined(CONFIG_NET_BUF_LOG) #define NET_BUF_DBG(fmt, ...) LOG_DBG("(%p) " fmt, k_current_get(), \ ##__VA_ARGS__) @@ -59,21 +63,41 @@ #if defined(BFLB_DYNAMIC_ALLOC_MEM) extern struct net_buf_pool hci_cmd_pool; extern struct net_buf_pool hci_rx_pool; +#if (BFLB_STATIC_ALLOC_MEM) +__attribute__((section(".tcm_data"))) u8_t hci_cmd_data_pool[CONFIG_BT_HCI_CMD_COUNT * BT_BUF_RX_SIZE]; +__attribute__((section(".tcm_data"))) u8_t hci_rx_data_pool[CONFIG_BT_RX_BUF_COUNT * BT_BUF_RX_SIZE]; +#endif #if defined(CONFIG_BT_CONN) extern struct net_buf_pool acl_tx_pool; extern struct net_buf_pool num_complete_pool; +#if (BFLB_STATIC_ALLOC_MEM) +__attribute__((section(".tcm_data"))) u8_t acl_tx_data_pool[CONFIG_BT_L2CAP_TX_BUF_COUNT * BT_L2CAP_BUF_SIZE(CONFIG_BT_L2CAP_TX_MTU)]; +__attribute__((section(".tcm_data"))) u8_t num_complete_data_pool[1 * BT_BUF_RX_SIZE]; +#endif #if CONFIG_BT_ATT_PREPARE_COUNT > 0 extern struct net_buf_pool prep_pool; +#if (BFLB_STATIC_ALLOC_MEM) +__attribute__((section(".tcm_data"))) u8_t prep_data_pool[CONFIG_BT_ATT_PREPARE_COUNT * BT_ATT_MTU]; +#endif #endif #if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) extern struct net_buf_pool acl_in_pool; +#if (BFLB_STATIC_ALLOC_MEM) +__attribute__((section(".tcm_data"))) u8_t acl_in_data_pool[CONFIG_BT_ACL_RX_COUNT * ACL_IN_SIZE]; +#endif #endif #if CONFIG_BT_ATT_PREPARE_COUNT > 0 extern struct net_buf_pool frag_pool; +#if (BFLB_STATIC_ALLOC_MEM) +__attribute__((section(".tcm_data"))) u8_t frag_data_pool[CONFIG_BT_L2CAP_TX_FRAG_COUNT * FRAG_SIZE]; +#endif #endif #endif //CONFIG_BT_CONN #if defined(CONFIG_BT_DISCARDABLE_BUF_COUNT) extern struct net_buf_pool discardable_pool; +#if (BFLB_STATIC_ALLOC_MEM) +__attribute__((section(".tcm_data"))) u8_t discardable_data_pool[CONFIG_BT_DISCARDABLE_BUF_COUNT * BT_BUF_RX_SIZE]; +#endif #endif #ifdef CONFIG_BT_MESH extern struct net_buf_pool adv_buf_pool; @@ -138,17 +162,62 @@ extern struct net_buf_pool _net_buf_pool_list[]; #endif //BFLB_DYNAMIC_ALLOC_MEM #if defined(BFLB_DYNAMIC_ALLOC_MEM) +#if (BFLB_STATIC_ALLOC_MEM) +void net_buf_init(u8_t buf_type, struct net_buf_pool *buf_pool, u16_t buf_count, size_t data_size, destroy_cb_t destroy) +#else void net_buf_init(struct net_buf_pool *buf_pool, u16_t buf_count, size_t data_size, destroy_cb_t destroy) +#endif { struct net_buf_pool_fixed *buf_fixed; - buf_pool->alloc = (struct net_buf_data_alloc *)k_malloc(sizeof(void *)); - buf_pool->alloc->alloc_data = (struct net_buf_pool_fixed *)k_malloc(sizeof(void *)); + buf_pool->alloc = (struct net_buf_data_alloc *)k_malloc(sizeof(struct net_buf_data_alloc)); + buf_pool->alloc->alloc_data = (struct net_buf_pool_fixed *)k_malloc(sizeof(struct net_buf_pool_fixed)); buf_fixed = (struct net_buf_pool_fixed *)buf_pool->alloc->alloc_data; buf_pool->alloc->cb = &net_buf_fixed_cb; buf_fixed->data_size = data_size; +#if (BFLB_STATIC_ALLOC_MEM) + switch (buf_type) { + case HCI_CMD: + buf_fixed->data_pool = hci_cmd_data_pool; + break; + case HCI_RX: + buf_fixed->data_pool = hci_rx_data_pool; + break; +#if defined(CONFIG_BT_CONN) + case ACL_TX: + buf_fixed->data_pool = acl_tx_data_pool; + break; + case NUM_COMPLETE: + buf_fixed->data_pool = num_complete_data_pool; + break; +#if CONFIG_BT_ATT_PREPARE_COUNT > 0 + case PREP: + buf_fixed->data_pool = prep_data_pool; + break; +#endif +#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) + case ACL_IN: + buf_fixed->data_pool = acl_in_data_pool; + break; +#endif +#if CONFIG_BT_L2CAP_TX_FRAG_COUNT > 0 + case FRAG: + buf_fixed->data_pool = frag_data_pool; + break; +#endif +#endif +#if defined(CONFIG_BT_DISCARDABLE_BUF_COUNT) + case DISCARDABLE: + buf_fixed->data_pool = discardable_data_pool; + break; +#endif + default: + break; + } +#else buf_fixed->data_pool = (u8_t *)k_malloc(buf_count * data_size); +#endif buf_pool->__bufs = (struct net_buf *)k_malloc(buf_count * sizeof(struct net_buf)); buf_pool->buf_count = buf_count; buf_pool->uninit_count = buf_count; @@ -166,7 +235,9 @@ void net_buf_deinit(struct net_buf_pool *buf_pool) bt_delete_queue((struct k_fifo *)(&(buf_pool->free))); struct net_buf_pool_fixed *buf_fixed = (struct net_buf_pool_fixed *)buf_pool->alloc->alloc_data; +#if !(BFLB_STATIC_ALLOC_MEM) k_free(buf_fixed->data_pool); +#endif k_free(buf_pool->__bufs); k_free(buf_pool->alloc->alloc_data); k_free(buf_pool->alloc); @@ -387,6 +458,12 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size, NET_BUF_DBG("%s():%d: pool %p size %zu timeout %d", func, line, pool, size, timeout); +#if (BFLB_BT_CO_THREAD) + extern struct k_thread co_thread_data; + if (k_is_current_thread(&co_thread_data)) + timeout = K_NO_WAIT; +#endif + /* We need to lock interrupts temporarily to prevent race conditions * when accessing pool->uninit_count. */ diff --git a/components/ble/ble_stack/common/include/net/buf.h b/components/ble/ble_stack/common/include/net/buf.h index b89d8232..a50c5e37 100644 --- a/components/ble/ble_stack/common/include/net/buf.h +++ b/components/ble/ble_stack/common/include/net/buf.h @@ -66,6 +66,19 @@ extern "C" { .__buf = net_buf_data_##_name, \ } +#if (BFLB_STATIC_ALLOC_MEM) +enum { + HCI_CMD = 0, + HCI_RX, + NUM_COMPLETE, + ACL_IN, + DISCARDABLE, + ACL_TX, + FRAG, + PREP, + +}; +#endif /** @brief Simple network buffer representation. * * This is a simpler variant of the net_buf object (in fact net_buf uses @@ -827,7 +840,11 @@ extern const struct net_buf_data_cb net_buf_var_cb; #endif #if defined(BFLB_DYNAMIC_ALLOC_MEM) +#if (BFLB_STATIC_ALLOC_MEM) +void net_buf_init(u8_t buf_type, struct net_buf_pool *buf_pool, u16_t buf_count, size_t data_size, destroy_cb_t destroy); +#else void net_buf_init(struct net_buf_pool *buf_pool, u16_t buf_count, size_t data_size, destroy_cb_t destroy); +#endif void net_buf_deinit(struct net_buf_pool *buf_pool); #endif /** diff --git a/components/ble/ble_stack/common/include/zephyr/types.h b/components/ble/ble_stack/common/include/zephyr/types.h index 3b07e3b1..ac12b55b 100644 --- a/components/ble/ble_stack/common/include/zephyr/types.h +++ b/components/ble/ble_stack/common/include/zephyr/types.h @@ -15,12 +15,12 @@ extern "C" { typedef signed char s8_t; typedef signed short s16_t; -typedef signed int s32_t; +typedef int32_t s32_t; typedef signed long long s64_t; typedef unsigned char u8_t; typedef unsigned short u16_t; -typedef unsigned int u32_t; +typedef uint32_t u32_t; typedef unsigned long long u64_t; #ifdef __cplusplus diff --git a/components/ble/ble_stack/common/log.c b/components/ble/ble_stack/common/log.c index 3a579079..b4c23dff 100644 --- a/components/ble/ble_stack/common/log.c +++ b/components/ble/ble_stack/common/log.c @@ -23,7 +23,7 @@ const char *bt_hex_real(const void *buf, size_t len) { static const char hex[] = "0123456789abcdef"; #if defined(CONFIG_BT_DEBUG_MONITOR) - static char str[255]; + static char str[512]; #else static char str[128]; #endif diff --git a/components/ble/ble_stack/common/log.h b/components/ble/ble_stack/common/log.h index 1c426de1..3191ccce 100644 --- a/components/ble/ble_stack/common/log.h +++ b/components/ble/ble_stack/common/log.h @@ -43,11 +43,15 @@ extern "C" { #if defined(BFLB_BLE) #if defined(BL_MCU_SDK) -#define BT_DBG(fmt, ...) //bflb_platform_printf(fmt", %s\r\n", ##__VA_ARGS__, __func__) -#define BT_ERR(fmt, ...) bflb_platform_printf(fmt ", %s\r\n", ##__VA_ARGS__, __func__) +#define BT_DBG(fmt, ...) //bflb_platform_printf(fmt", %s\r\n", ##__VA_ARGS__, __func__) +#define BT_ERR(fmt, ...) bflb_platform_printf(fmt ", %s\r\n", ##__VA_ARGS__, __func__) +#define BT_WARN(fmt, ...) bflb_platform_printf(fmt ", %s\r\n", ##__VA_ARGS__, __func__) +#define BT_INFO(fmt, ...) //bflb_platform_printf(fmt", %s\r\n", ##__VA_ARGS__, __func__) #else -#define BT_DBG(fmt, ...) //printf(fmt", %s\r\n", ##__VA_ARGS__, __func__) -#define BT_ERR(fmt, ...) printf(fmt ", %s\r\n", ##__VA_ARGS__, __func__) +#define BT_DBG(fmt, ...) //printf(fmt", %s\r\n", ##__VA_ARGS__, __func__) +#define BT_ERR(fmt, ...) printf(fmt ", %s\r\n", ##__VA_ARGS__, __func__) +#define BT_WARN(fmt, ...) printf(fmt ", %s\r\n", ##__VA_ARGS__, __func__) +#define BT_INFO(fmt, ...) //printf(fmt", %s\r\n", ##__VA_ARGS__, __func__) #endif #if defined(CONFIG_BT_STACK_PTS) || defined(CONFIG_BT_MESH_PTS) @@ -56,14 +60,6 @@ extern "C" { #else #define BT_PTS(fmt, ...) printf(fmt "\r\n", ##__VA_ARGS__) #endif - -#endif -#if defined(BL_MCU_SDK) -#define BT_WARN(fmt, ...) bflb_platform_printf(fmt ", %s\r\n", ##__VA_ARGS__, __func__) -#define BT_INFO(fmt, ...) //bflb_platform_printf(fmt", %s\r\n", ##__VA_ARGS__, __func__) -#else -#define BT_WARN(fmt, ...) printf(fmt ", %s\r\n", ##__VA_ARGS__, __func__) -#define BT_INFO(fmt, ...) //printf(fmt", %s\r\n", ##__VA_ARGS__, __func__) #endif #else /*BFLB_BLE*/ diff --git a/components/ble/ble_stack/common/poll.c b/components/ble/ble_stack/common/poll.c index b97a4f79..0c7fc9b5 100644 --- a/components/ble/ble_stack/common/poll.c +++ b/components/ble/ble_stack/common/poll.c @@ -154,14 +154,25 @@ static inline void set_event_ready(struct k_poll_event *event, u32_t state) event->state |= state; } +#if (BFLB_BT_CO_THREAD) +static bool polling_events(struct k_poll_event *events, int num_events, int total_evt_array_cnt, + s32_t timeout, int *last_registered) +#else static bool polling_events(struct k_poll_event *events, int num_events, s32_t timeout, int *last_registered) +#endif { int rc; bool polling = true; unsigned int key; +#if (BFLB_BT_CO_THREAD) + for (int ii = 0; ii < total_evt_array_cnt; ii++) { + if (ii >= num_events && ii != total_evt_array_cnt - 1) + continue; +#else for (int ii = 0; ii < num_events; ii++) { +#endif u32_t state; key = irq_lock(); if (is_condition_met(&events[ii], &state)) { @@ -180,7 +191,11 @@ static bool polling_events(struct k_poll_event *events, int num_events, return polling; } +#if (BFLB_BT_CO_THREAD) +int k_poll(struct k_poll_event *events, int num_events, int total_evt_array_cnt, s32_t timeout, u8_t *to_process) +#else int k_poll(struct k_poll_event *events, int num_events, s32_t timeout) +#endif { __ASSERT(events, "NULL events\n"); __ASSERT(num_events > 0, "zero events\n"); @@ -190,16 +205,32 @@ int k_poll(struct k_poll_event *events, int num_events, s32_t timeout) bool polling = true; /* find events whose condition is already fulfilled */ +#if (BFLB_BT_CO_THREAD) + polling = polling_events(events, num_events, total_evt_array_cnt, timeout, &last_registered); +#else polling = polling_events(events, num_events, timeout, &last_registered); +#endif if (polling == false) { goto exit; } +#if (BFLB_BT_CO_THREAD) + if (timeout != K_NO_WAIT) +#endif + { + k_sem_take(&g_poll_sem, timeout); + last_registered = -1; +#if (BFLB_BT_CO_THREAD) + polling = polling_events(events, num_events, total_evt_array_cnt, timeout, &last_registered); +#else + polling_events(events, num_events, timeout, &last_registered); +#endif + } - k_sem_take(&g_poll_sem, timeout); - - last_registered = -1; - polling_events(events, num_events, timeout, &last_registered); +#if (BFLB_BT_CO_THREAD) + if (to_process) + *to_process = polling ? 0 : 1; +#endif exit: key = irq_lock(); clear_event_registrations(events, last_registered, key); diff --git a/components/ble/ble_stack/common/work_q.c b/components/ble/ble_stack/common/work_q.c index f8f72ad6..afd74de7 100644 --- a/components/ble/ble_stack/common/work_q.c +++ b/components/ble/ble_stack/common/work_q.c @@ -26,10 +26,25 @@ static void k_work_submit_to_queue(struct k_work_q *work_q, { if (!atomic_test_and_set_bit(work->flags, K_WORK_STATE_PENDING)) { k_fifo_put(&work_q->fifo, work); +#if (BFLB_BT_CO_THREAD) + extern struct k_sem g_poll_sem; + k_sem_give(&g_poll_sem); +#endif } } #if defined(BFLB_BLE) +#if (BFLB_BT_CO_THREAD) +void handle_work_queue(void) +{ + struct k_work *work; + work = k_fifo_get(&g_work_queue_main.fifo, K_NO_WAIT); + + if (atomic_test_and_clear_bit(work->flags, K_WORK_STATE_PENDING)) { + work->handler(work); + } +} +#else static void work_queue_main(void *p1) { struct k_work *work; @@ -53,6 +68,7 @@ int k_work_q_start(void) CONFIG_BT_WORK_QUEUE_STACK_SIZE, work_queue_main, CONFIG_BT_WORK_QUEUE_PRIO); } +#endif int k_work_init(struct k_work *work, k_work_handler_t handler) { diff --git a/components/ble/ble_stack/hci_onchip/hci_driver.c b/components/ble/ble_stack/hci_onchip/hci_driver.c index a0c33488..dcebd777 100644 --- a/components/ble/ble_stack/hci_onchip/hci_driver.c +++ b/components/ble/ble_stack/hci_onchip/hci_driver.c @@ -51,11 +51,6 @@ static K_SEM_DEFINE(sem_prio_recv, 0, BT_UINT_MAX); #endif K_FIFO_DEFINE(recv_fifo); -#if (BFLB_BLE_CO_THREAD) -extern struct k_sem g_poll_sem; -static int recv_fifo_count = 0; -#endif - #if !defined(BFLB_BLE) struct k_thread prio_recv_thread_data; static BT_STACK_NOINIT(prio_recv_thread_stack, @@ -291,37 +286,6 @@ static inline struct net_buf *process_hbuf(struct radio_pdu_node_rx *n) #endif #if defined(BFLB_BLE) -#if (BFLB_BLE_CO_THREAD) -void co_rx_thread() -{ - struct net_buf *buf = NULL; - buf = net_buf_get(&recv_fifo, K_NO_WAIT); - if (buf) { - BT_DBG("Calling bt_recv(%p)", buf); - bt_recv(buf); - } -} - -void co_tx_rx_thread(void *p1) -{ - UNUSED(p1); - BT_DBG("using %s\n", __func__); - while (1) { - if (k_sem_count_get(&g_poll_sem) > 0) { - co_tx_thread(); - } - - if (recv_fifo_count > 0) { - recv_fifo_count--; - co_rx_thread(); - } - - k_sleep(portTICK_PERIOD_MS); - k_yield(); - } -} - -#else static void recv_thread(void *p1) { UNUSED(p1); @@ -399,7 +363,6 @@ static void recv_thread(void *p1) } } #endif -#endif #if !defined(BFLB_BLE) static int cmd_handle(struct net_buf *buf) @@ -498,15 +461,11 @@ static int hci_driver_open(void) hci_init(NULL); #endif #endif +#if (!BFLB_BT_CO_THREAD) k_fifo_init(&recv_fifo, 20); - +#endif #if defined(BFLB_BLE) -#if (BFLB_BLE_CO_THREAD) - k_thread_create(&recv_thread_data, "co_tx_rx_thread", - CONFIG_BT_RX_STACK_SIZE, - co_tx_rx_thread, - K_PRIO_COOP(CONFIG_BT_RX_PRIO)); -#else +#if (!BFLB_BT_CO_THREAD) k_thread_create(&recv_thread_data, "recv_thread", CONFIG_BT_RX_STACK_SIZE /*K_THREAD_STACK_SIZEOF(recv_thread_stack)*/, recv_thread, @@ -527,8 +486,9 @@ static int hci_driver_open(void) void hci_driver_enque_recvq(struct net_buf *buf) { net_buf_put(&recv_fifo, buf); -#if (BFLB_BLE_CO_THREAD) - recv_fifo_count++; +#if (BFLB_BT_CO_THREAD) + extern struct k_sem g_poll_sem; + k_sem_give(&g_poll_sem); #endif } diff --git a/components/ble/ble_stack/host/att.c b/components/ble/ble_stack/host/att.c index d792f0b6..8fa18d49 100644 --- a/components/ble/ble_stack/host/att.c +++ b/components/ble/ble_stack/host/att.c @@ -392,7 +392,9 @@ static u8_t att_handle_rsp(struct bt_att *att, void *pdu, u16_t len, u8_t err) func = att->req->func; att->req->func = NULL; - func(att->chan.chan.conn, err, pdu, len, att->req); + if (func) { + func(att->chan.chan.conn, err, pdu, len, att->req); + } /* Don't destroy if callback had reused the request */ if (!att->req->func) { @@ -2265,7 +2267,14 @@ static void bt_att_encrypt_change(struct bt_l2cap_chan *chan, return; } +#if (BFLB_BT_CO_THREAD) + if (k_sem_take(&att->tx_sem, K_NO_WAIT) < 0) { + k_fifo_put(&att->tx_queue, att->req->buf); + return; + } +#else k_sem_take(&att->tx_sem, K_FOREVER); +#endif if (!att_is_connected(att)) { BT_WARN("Disconnected"); k_sem_give(&att->tx_sem); @@ -2342,8 +2351,12 @@ void bt_att_init(void) #if CONFIG_BT_ATT_PREPARE_COUNT > 0 #if defined(BFLB_DYNAMIC_ALLOC_MEM) +#if (BFLB_STATIC_ALLOC_MEM) + net_buf_init(PREP, &prep_pool, CONFIG_BT_ATT_PREPARE_COUNT, BT_ATT_MTU, NULL); +#else net_buf_init(&prep_pool, CONFIG_BT_ATT_PREPARE_COUNT, BT_ATT_MTU, NULL); #endif +#endif #endif bt_gatt_init(); diff --git a/components/ble/ble_stack/host/conn.c b/components/ble/ble_stack/host/conn.c index 86b90b3e..c55cb1f1 100644 --- a/components/ble/ble_stack/host/conn.c +++ b/components/ble/ble_stack/host/conn.c @@ -160,12 +160,12 @@ static void notify_connected(struct bt_conn *conn) } } - if (!conn->err) { + if (conn->type == BT_CONN_TYPE_LE && !conn->err) { bt_gatt_connected(conn); } } -static void notify_disconnected(struct bt_conn *conn) +void notify_disconnected(struct bt_conn *conn) { struct bt_conn_cb *cb; @@ -211,6 +211,17 @@ void notify_le_param_updated(struct bt_conn *conn) } } +void notify_le_phy_updated(struct bt_conn *conn, u8_t tx_phy, u8_t rx_phy) +{ + struct bt_conn_cb *cb; + + for (cb = callback_list; cb; cb = cb->_next) { + if (cb->le_phy_updated) { + cb->le_phy_updated(conn, tx_phy, rx_phy); + } + } +} + bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) { struct bt_conn_cb *cb; @@ -336,7 +347,9 @@ static void conn_update_timeout(struct k_work *work) if (conn->state == BT_CONN_DISCONNECTED) { bt_l2cap_disconnected(conn); +#if !defined(BFLB_BLE) notify_disconnected(conn); +#endif /* Release the reference we took for the very first * state transition. @@ -548,6 +561,7 @@ struct bt_conn *bt_conn_create_br(const bt_addr_t *peer, bt_conn_set_state(conn, BT_CONN_CONNECT); conn->role = BT_CONN_ROLE_MASTER; + bt_conn_unref(conn); return conn; } @@ -1371,10 +1385,21 @@ int bt_conn_send_cb(struct bt_conn *conn, struct net_buf *buf, tx_data(buf)->tx = NULL; } +#if (BFLB_BT_CO_THREAD) + if (k_is_current_thread(bt_get_co_thread())) + bt_conn_process_tx(conn, buf); + else + net_buf_put(&conn->tx_queue, buf); +#if defined(BFLB_BLE) + k_sem_give(&g_poll_sem); +#endif +#else //BFLB_BT_CO_THREAD + net_buf_put(&conn->tx_queue, buf); #if defined(BFLB_BLE) k_sem_give(&g_poll_sem); #endif +#endif //BFLB_BT_CO_THREAD return 0; } @@ -1600,7 +1625,11 @@ int bt_conn_prepare_events(struct k_poll_event events[]) return ev_count; } +#if (BFLB_BT_CO_THREAD) +void bt_conn_process_tx(struct bt_conn *conn, struct net_buf *tx_buf) +#else void bt_conn_process_tx(struct bt_conn *conn) +#endif { struct net_buf *buf; @@ -1612,9 +1641,15 @@ void bt_conn_process_tx(struct bt_conn *conn) conn_cleanup(conn); return; } - +#if (BFLB_BT_CO_THREAD) + if (tx_buf) + buf = tx_buf; + else + buf = net_buf_get(&conn->tx_queue, K_NO_WAIT); +#else /* Get next ACL packet for connection */ buf = net_buf_get(&conn->tx_queue, K_NO_WAIT); +#endif BT_ASSERT(buf); if (!send_buf(conn, buf)) { net_buf_unref(buf); @@ -2646,10 +2681,18 @@ int bt_conn_init(void) #if defined(BFLB_BLE) #if defined(BFLB_DYNAMIC_ALLOC_MEM) +#if (BFLB_STATIC_ALLOC_MEM) + net_buf_init(ACL_TX, &acl_tx_pool, CONFIG_BT_L2CAP_TX_BUF_COUNT, BT_L2CAP_BUF_SIZE(CONFIG_BT_L2CAP_TX_MTU), NULL); +#else net_buf_init(&acl_tx_pool, CONFIG_BT_L2CAP_TX_BUF_COUNT, BT_L2CAP_BUF_SIZE(CONFIG_BT_L2CAP_TX_MTU), NULL); +#endif #if CONFIG_BT_L2CAP_TX_FRAG_COUNT > 0 +#if (BFLB_STATIC_ALLOC_MEM) + net_buf_init(FRAG, &frag_pool, CONFIG_BT_L2CAP_TX_FRAG_COUNT, FRAG_SIZE, NULL); +#else net_buf_init(&frag_pool, CONFIG_BT_L2CAP_TX_FRAG_COUNT, FRAG_SIZE, NULL); #endif +#endif #else //BFLB_DYNAMIC_ALLOC_MEM struct net_buf_pool num_complete_pool; struct net_buf_pool acl_tx_pool; diff --git a/components/ble/ble_stack/host/conn_internal.h b/components/ble/ble_stack/host/conn_internal.h index 9fbaa0d6..2ba9a9c8 100644 --- a/components/ble/ble_stack/host/conn_internal.h +++ b/components/ble/ble_stack/host/conn_internal.h @@ -264,6 +264,8 @@ void notify_remote_info(struct bt_conn *conn); void notify_le_param_updated(struct bt_conn *conn); +void notify_le_phy_updated(struct bt_conn *conn, u8_t tx_phy, u8_t rx_phy); + bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param); #if defined(CONFIG_BT_SMP) @@ -327,7 +329,12 @@ struct k_sem *bt_conn_get_pkts(struct bt_conn *conn); /* k_poll related helpers for the TX thread */ int bt_conn_prepare_events(struct k_poll_event events[]); + +#if (BFLB_BT_CO_THREAD) +void bt_conn_process_tx(struct bt_conn *conn, struct net_buf *tx_buf); +#else void bt_conn_process_tx(struct bt_conn *conn); +#endif #if defined(BFLB_BLE) /** @brief Get connection handle for a connection. diff --git a/components/ble/ble_stack/host/gatt.c b/components/ble/ble_stack/host/gatt.c index a9c4d916..d9e58419 100644 --- a/components/ble/ble_stack/host/gatt.c +++ b/components/ble/ble_stack/host/gatt.c @@ -72,6 +72,13 @@ struct ccc_store { #if defined(CONFIG_BT_GATT_CLIENT) static sys_slist_t subscriptions; +#if defined(BFLB_BLE_NOTIFY_ALL) +bt_notification_all_cb_t gatt_notify_all_cb; +#endif +#if defined(BFLB_BLE_DISCOVER_ONGOING) +uint8_t discover_ongoing = BT_GATT_ITER_STOP; +extern int bt_gatt_discover_continue(struct bt_conn *conn, struct bt_gatt_discover_params *params); +#endif #endif /* CONFIG_BT_GATT_CLIENT */ static const u16_t gap_appearance = CONFIG_BT_DEVICE_APPEARANCE; @@ -942,11 +949,9 @@ int service_change_test(struct bt_gatt_indicate_params *params, const struct bt_ params->data = &sc_range[0]; params->len = sizeof(sc_range); - if (bt_gatt_indicate(con, params)) { - /* No connections to indicate */ - return; - } + return bt_gatt_indicate(con, params); } + #endif #if defined(CONFIG_BT_SETTINGS_CCC_STORE_ON_WRITE) @@ -2314,13 +2319,23 @@ bool bt_gatt_is_subscribed(struct bt_conn *conn, } #if defined(CONFIG_BT_GATT_CLIENT) +#if defined(BFLB_BLE_NOTIFY_ALL) +void bt_gatt_register_notification_callback(bt_notification_all_cb_t cb) +{ + gatt_notify_all_cb = cb; +} +#endif void bt_gatt_notification(struct bt_conn *conn, u16_t handle, const void *data, u16_t length) { struct bt_gatt_subscribe_params *params, *tmp; BT_DBG("handle 0x%04x length %u", handle, length); - +#if defined(BFLB_BLE_NOTIFY_ALL) + if (gatt_notify_all_cb) { + gatt_notify_all_cb(conn, handle, data, length); + } +#endif SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&subscriptions, params, tmp, node) { if (bt_conn_addr_le_cmp(conn, ¶ms->_peer) || @@ -2473,12 +2488,19 @@ static void gatt_discover_next(struct bt_conn *conn, u16_t last_handle, discover: /* Discover next range */ +#if defined(BFLB_BLE_DISCOVER_ONGOING) + if (!bt_gatt_discover_continue(conn, params)) { +#else if (!bt_gatt_discover(conn, params)) { +#endif return; } done: params->func(conn, NULL, params); +#if defined(BFLB_BLE_DISCOVER_ONGOING) + discover_ongoing = BT_GATT_ITER_STOP; +#endif } static void gatt_find_type_rsp(struct bt_conn *conn, u8_t err, @@ -2521,6 +2543,9 @@ static void gatt_find_type_rsp(struct bt_conn *conn, u8_t err, attr.user_data = &value; if (params->func(conn, &attr, params) == BT_GATT_ITER_STOP) { +#if defined(BFLB_BLE_DISCOVER_ONGOING) + discover_ongoing = BT_GATT_ITER_STOP; +#endif return; } } @@ -2535,6 +2560,9 @@ static void gatt_find_type_rsp(struct bt_conn *conn, u8_t err, return; done: params->func(conn, NULL, params); +#if defined(BFLB_BLE_DISCOVER_ONGOING) + discover_ongoing = BT_GATT_ITER_STOP; +#endif } static int gatt_find_type(struct bt_conn *conn, @@ -2846,6 +2874,9 @@ static void gatt_read_type_rsp(struct bt_conn *conn, u8_t err, if (err) { params->func(conn, NULL, params); +#if defined(BFLB_BLE_DISCOVER_ONGOING) + discover_ongoing = BT_GATT_ITER_STOP; +#endif return; } @@ -2856,6 +2887,9 @@ static void gatt_read_type_rsp(struct bt_conn *conn, u8_t err, } if (!handle) { +#if defined(BFLB_BLE_DISCOVER_ONGOING) + discover_ongoing = BT_GATT_ITER_STOP; +#endif return; } @@ -2982,11 +3016,17 @@ static void gatt_read_group_rsp(struct bt_conn *conn, u8_t err, if (err) { params->func(conn, NULL, params); +#if defined(BFLB_BLE_DISCOVER_ONGOING) + discover_ongoing = BT_GATT_ITER_STOP; +#endif return; } handle = parse_service(conn, pdu, params, length); if (!handle) { +#if defined(BFLB_BLE_DISCOVER_ONGOING) + discover_ongoing = BT_GATT_ITER_STOP; +#endif return; } @@ -3121,6 +3161,9 @@ static void gatt_find_info_rsp(struct bt_conn *conn, u8_t err, attr->handle = handle; if (params->func(conn, attr, params) == BT_GATT_ITER_STOP) { +#if defined(BFLB_BLE_DISCOVER_ONGOING) + discover_ongoing = BT_GATT_ITER_STOP; +#endif return; } } @@ -3131,6 +3174,9 @@ static void gatt_find_info_rsp(struct bt_conn *conn, u8_t err, done: params->func(conn, NULL, params); +#if defined(BFLB_BLE_DISCOVER_ONGOING) + discover_ongoing = BT_GATT_ITER_STOP; +#endif } static int gatt_find_info(struct bt_conn *conn, @@ -3168,6 +3214,18 @@ int bt_gatt_discover(struct bt_conn *conn, return -ENOTCONN; } +#if defined(BFLB_BLE_DISCOVER_ONGOING) + if (discover_ongoing != BT_GATT_ITER_STOP) { + return -EINPROGRESS; + } + discover_ongoing = BT_GATT_ITER_CONTINUE; + + return bt_gatt_discover_continue(conn, params); +} +int bt_gatt_discover_continue(struct bt_conn *conn, + struct bt_gatt_discover_params *params) +{ +#endif switch (params->type) { case BT_GATT_DISCOVER_PRIMARY: case BT_GATT_DISCOVER_SECONDARY: @@ -4690,3 +4748,23 @@ SETTINGS_STATIC_HANDLER_DEFINE(bt_hash, "bt/hash", NULL, db_hash_set, db_hash_commit, NULL); #endif /*CONFIG_BT_GATT_CACHING */ #endif /* CONFIG_BT_SETTINGS */ + +#if defined(CONFIG_BT_GATT_DYNAMIC_DB) +uint16_t bt_gatt_get_last_handle(void) +{ + struct bt_gatt_service *last; + u16_t handle, last_handle; + + if (sys_slist_is_empty(&db)) { + handle = last_static_handle; + last_handle = handle; + goto last; + } + + last = SYS_SLIST_PEEK_TAIL_CONTAINER(&db, last, node); + handle = last->attrs[last->attr_count - 1].handle; + last_handle = handle; +last: + return last_handle; +} +#endif diff --git a/components/ble/ble_stack/host/hci_core.c b/components/ble/ble_stack/host/hci_core.c index f6bbf28a..05e4a667 100644 --- a/components/ble/ble_stack/host/hci_core.c +++ b/components/ble/ble_stack/host/hci_core.c @@ -45,12 +45,15 @@ #include "settings.h" #if defined(BFLB_BLE) #include "bl_hci_wrapper.h" +#include "ble_lib_api.h" #if defined(BL602) #include "bl602_hbn.h" #elif defined(BL702) #include "bl702_hbn.h" -#elif defined(BL606p) +#elif defined(BL606P) || defined(BL616) #include "bl606p_hbn.h" +#elif defined(BL808) //no bl808_hbn.h currently, comment it out temporarily +#include "bl808_hbn.h" #endif #include "work_q.h" #endif @@ -64,12 +67,18 @@ #define HCI_CMD_TIMEOUT K_SECONDS(10) +extern struct k_fifo recv_fifo; +extern struct k_work_q g_work_queue_main; /* Stacks for the threads */ #if !defined(CONFIG_BT_RECV_IS_RX_THREAD) static struct k_thread rx_thread_data; static K_THREAD_STACK_DEFINE(rx_thread_stack, CONFIG_BT_RX_STACK_SIZE); #endif -#if (!BFLB_BLE_CO_THREAD) +#if (BFLB_BT_CO_THREAD) +struct k_thread co_thread_data; +static void process_events(struct k_poll_event *ev, int count, int total_evt_array_cnt); +static void send_cmd(struct net_buf *tx_buf); +#else static struct k_thread tx_thread_data; #endif #if !defined(BFLB_BLE) @@ -139,6 +148,24 @@ volatile u8_t event_flag = 0; struct blhast_cb *host_assist_cb; #endif +#if (BFLB_BT_CO_THREAD) +#if defined(CONFIG_BT_CONN) +/* command FIFO + conn_change signal +tx queue + rxqueue + workQueue + MAX_CONN */ +#define EV_COUNT (4 + CONFIG_BT_MAX_CONN) +#else +/* command FIFO */ +#define EV_COUNT 2 +#endif +#else +#if defined(CONFIG_BT_CONN) +/* command FIFO + conn_change signal + MAX_CONN */ +#define EV_COUNT (2 + CONFIG_BT_MAX_CONN) +#else +/* command FIFO */ +#define EV_COUNT 1 +#endif +#endif //BFLB_BT_CO_THREAD + struct cmd_state_set { atomic_t *target; int bit; @@ -166,7 +193,9 @@ struct cmd_data { /** The state to update when command completes with success. */ struct cmd_state_set *state; - +#if (BFLB_BT_CO_THREAD) + uint8_t sync_state; +#endif /** Used by bt_hci_cmd_send_sync. */ struct k_sem *sync; }; @@ -186,7 +215,7 @@ struct acl_data { extern struct k_sem g_poll_sem; #endif -static struct cmd_data cmd_data[CONFIG_BT_HCI_CMD_COUNT]; +__attribute__((section(".tcm_data"))) static struct cmd_data cmd_data[CONFIG_BT_HCI_CMD_COUNT]; #define cmd(buf) (&cmd_data[net_buf_id(buf)]) #define acl(buf) ((struct acl_data *)net_buf_user_data(buf)) @@ -225,7 +254,9 @@ struct net_buf_pool discardable_pool; #endif #endif /*!defined(BFLB_DYNAMIC_ALLOC_MEM)*/ +#if defined CONFIG_BT_HFP extern bool hfp_codec_msbc; +#endif struct event_handler { u8_t event; @@ -394,6 +425,57 @@ int bt_hci_cmd_send(u16_t opcode, struct net_buf *buf) return 0; } +#if (BFLB_BT_CO_THREAD) +struct k_thread *bt_get_co_thread(void) +{ + return &co_thread_data; +} + +static void bt_hci_sync_check(struct net_buf *buf) +{ + static struct k_poll_event events[EV_COUNT] = { + [0] = K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, + K_POLL_MODE_NOTIFY_ONLY, + &g_work_queue_main.fifo, + BT_EVENT_WORK_QUEUE), + [1] = K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, + K_POLL_MODE_NOTIFY_ONLY, + &bt_dev.cmd_tx_queue, + BT_EVENT_CMD_TX), + [EV_COUNT - 1] = K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, + K_POLL_MODE_NOTIFY_ONLY, + &recv_fifo, + BT_EVENT_RX_QUEUE), + }; + + uint32_t time_start = k_uptime_get_32(); + send_cmd(buf); + + while (1) { + int ev_count, err; + u8_t to_process = 0; + + events[0].state = K_POLL_STATE_NOT_READY; + events[1].state = K_POLL_STATE_NOT_READY; + events[EV_COUNT - 1].state = K_POLL_STATE_NOT_READY; + ev_count = 2; + + if (IS_ENABLED(CONFIG_BT_CONN)) { + ev_count += bt_conn_prepare_events(&events[2]); + } + err = k_poll(events, ev_count, EV_COUNT, K_NO_WAIT, &to_process); + BT_ASSERT(err == 0); + if (to_process) + process_events(events, ev_count, EV_COUNT); + + if ((cmd(buf)->sync_state == BT_CMD_SYNC_TX_DONE) || + (k_uptime_get_32() - time_start) >= HCI_CMD_TIMEOUT) { + break; + } + } +} +#endif + #if defined(BFLB_HOST_ASSISTANT) extern void blhast_bt_reset(void); uint16_t hci_cmd_to_cnt = 0; @@ -403,6 +485,9 @@ int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf, { struct k_sem sync_sem; int err; +#if (BFLB_BT_CO_THREAD) + bool is_bt_co_thread = k_is_current_thread(&co_thread_data); +#endif if (!buf) { buf = bt_hci_cmd_create(opcode, 0); @@ -413,8 +498,19 @@ int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf, BT_DBG("buf %p opcode 0x%04x len %u", buf, opcode, buf->len); +#if (BFLB_BT_CO_THREAD) + if (is_bt_co_thread) { + cmd(buf)->sync_state = BT_CMD_SYNC_TX; + cmd(buf)->sync = NULL; + } else { + k_sem_init(&sync_sem, 0, 1); + cmd(buf)->sync = &sync_sem; + cmd(buf)->sync_state = BT_CMD_SYNC_NONE; + } +#else k_sem_init(&sync_sem, 0, 1); cmd(buf)->sync = &sync_sem; +#endif #if defined(BFLB_BLE) /*Assign a initial value to status in order to check if hci cmd timeout*/ @@ -424,6 +520,21 @@ int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf, /* Make sure the buffer stays around until the command completes */ net_buf_ref(buf); +#if (BFLB_BT_CO_THREAD) + if (is_bt_co_thread) + bt_hci_sync_check(buf); + else { + net_buf_put(&bt_dev.cmd_tx_queue, buf); +#if defined(BFLB_BLE) + k_sem_give(&g_poll_sem); +#endif + err = k_sem_take(&sync_sem, HCI_CMD_TIMEOUT); +#ifdef BFLB_BLE_PATCH_FREE_ALLOCATED_BUFFER_IN_OS + k_sem_delete(&sync_sem); +#endif + __ASSERT(err == 0, "k_sem_take failed with err %d", err); + } +#else net_buf_put(&bt_dev.cmd_tx_queue, buf); #if defined(BFLB_BLE) k_sem_give(&g_poll_sem); @@ -433,6 +544,7 @@ int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf, k_sem_delete(&sync_sem); #endif __ASSERT(err == 0, "k_sem_take failed with err %d", err); +#endif //#if (BFLB_BT_CO_THREAD) BT_DBG("opcode 0x%04x status 0x%02x", opcode, cmd(buf)->status); @@ -679,6 +791,10 @@ static int le_set_non_resolv_private_addr(u8_t id) bt_addr_t nrpa; int err; + if (atomic_test_bit(bt_dev.flags, BT_DEV_SETTED_NON_RESOLV_ADDR)) { + return 0; + } + err = bt_rand(nrpa.val, sizeof(nrpa.val)); if (err) { return err; @@ -689,6 +805,20 @@ static int le_set_non_resolv_private_addr(u8_t id) return set_random_address(&nrpa); } +int le_set_non_resolv_private_addr_ext(u8_t id, bt_addr_t *addr) +{ + bt_addr_t *nrpa = addr; + int err; + + err = bt_rand(nrpa->val, sizeof(nrpa->val)); + if (err) { + return err; + } + + nrpa->val[5] &= 0x3f; + atomic_clear_bit(bt_dev.flags, BT_DEV_RPA_VALID); + return set_random_address(nrpa); +} #endif #else @@ -1105,6 +1235,9 @@ static void hci_disconn_complete(struct net_buf *buf) } #endif bt_conn_unref(conn); +#if defined(CONFIG_BT_BREDR) + notify_disconnected(conn); +#endif return; } @@ -1125,6 +1258,10 @@ static void hci_disconn_complete(struct net_buf *buf) hci_release_conn_related_cmd(); #endif +#if defined(BFLB_BLE) + notify_disconnected(conn); +#endif + #if defined(CONFIG_BLE_RECONNECT_TEST) if (conn->role == BT_CONN_ROLE_MASTER) { struct bt_le_conn_param param = { @@ -1135,9 +1272,9 @@ static void hci_disconn_complete(struct net_buf *buf) }; if (bt_conn_create_le(&conn->le.dst, ¶m)) { - printf("Reconnecting. \n"); + BT_DBG("Reconnecting. \n"); } else { - printf("Reconnect fail. \n"); + BT_DBG("Reconnect fail. \n"); } } #endif @@ -1228,7 +1365,8 @@ int bt_le_set_data_len(struct bt_conn *conn, u16_t tx_octets, u16_t tx_time) return bt_hci_cmd_send(BT_HCI_OP_LE_SET_DATA_LEN, buf); } -int hci_le_set_phy(struct bt_conn *conn) +int hci_le_set_phy(struct bt_conn *conn, uint8_t all_phys, + uint8_t pref_tx_phy, uint8_t pref_rx_phy, uint8_t phy_opts) { struct bt_hci_cp_le_set_phy *cp; struct net_buf *buf; @@ -1240,16 +1378,15 @@ int hci_le_set_phy(struct bt_conn *conn) cp = net_buf_add(buf, sizeof(*cp)); cp->handle = sys_cpu_to_le16(conn->handle); - cp->all_phys = 0U; - cp->tx_phys = BT_HCI_LE_PHY_PREFER_2M; - cp->rx_phys = BT_HCI_LE_PHY_PREFER_2M; - cp->phy_opts = BT_HCI_LE_PHY_CODED_ANY; - bt_hci_cmd_send(BT_HCI_OP_LE_SET_PHY, buf); + cp->all_phys = all_phys; + cp->tx_phys = pref_tx_phy; + cp->rx_phys = pref_rx_phy; + cp->phy_opts = phy_opts; - return 0; + return bt_hci_cmd_send(BT_HCI_OP_LE_SET_PHY, buf); } -int hci_le_set_default_phy(struct bt_conn *conn, u8_t default_phy) +int hci_le_set_default_phy(u8_t default_phy) { struct bt_hci_cp_le_set_default_phy *cp; struct net_buf *buf; @@ -1543,7 +1680,9 @@ static void enh_conn_complete(struct bt_hci_evt_le_enh_conn_complete *evt) if (IS_ENABLED(CONFIG_BT_AUTO_PHY_UPDATE) && BT_FEAT_LE_PHY_2M(bt_dev.le.features)) { - err = hci_le_set_phy(conn); + err = hci_le_set_phy(conn, 0U, BT_HCI_LE_PHY_PREFER_2M, + BT_HCI_LE_PHY_PREFER_2M, + BT_HCI_LE_PHY_CODED_ANY); if (!err) { atomic_set_bit(conn->flags, BT_CONN_AUTO_PHY_UPDATE); goto done; @@ -1636,7 +1775,9 @@ static void le_remote_feat_complete(struct net_buf *buf) BT_FEAT_LE_PHY_2M(conn->le.features)) { int err; - err = hci_le_set_phy(conn); + err = hci_le_set_phy(conn, 0U, BT_HCI_LE_PHY_PREFER_2M, + BT_HCI_LE_PHY_PREFER_2M, + BT_HCI_LE_PHY_CODED_ANY); if (!err) { atomic_set_bit(conn->flags, BT_CONN_AUTO_PHY_UPDATE); goto done; @@ -1706,6 +1847,8 @@ static void le_phy_update_complete(struct net_buf *buf) BT_DBG("PHY updated: status: 0x%02x, tx: %u, rx: %u", evt->status, evt->tx_phy, evt->rx_phy); + notify_le_phy_updated(conn, evt->tx_phy, evt->rx_phy); + if (!IS_ENABLED(CONFIG_BT_AUTO_PHY_UPDATE) || !atomic_test_and_clear_bit(conn->flags, BT_CONN_AUTO_PHY_UPDATE)) { goto done; @@ -2088,18 +2231,17 @@ static int accept_sco_conn(const bt_addr_t *bdaddr, struct bt_conn *sco_conn) cp->tx_bandwidth = 0x00001f40; cp->rx_bandwidth = 0x00001f40; + cp->max_latency = 0x0007; + cp->retrans_effort = 0x01; + cp->content_format = BT_VOICE_CVSD_16BIT; +#if defined CONFIG_BT_HFP if (!hfp_codec_msbc) { - cp->max_latency = 0x0007; - cp->retrans_effort = 0x01; - cp->content_format = BT_VOICE_CVSD_16BIT; - BT_DBG("eSCO air coding CVSD!"); - } else { cp->max_latency = 0x000d; cp->retrans_effort = 0x02; cp->content_format = BT_VOICE_MSBC_16BIT; BT_DBG("eSCO air coding mSBC!"); } - +#endif err = bt_hci_cmd_send_sync(BT_HCI_OP_ACCEPT_SYNC_CONN_REQ, buf, NULL); if (err) { return err; @@ -2700,6 +2842,24 @@ static int request_name(const bt_addr_t *addr, u8_t pscan, u16_t offset) return bt_hci_cmd_send_sync(BT_HCI_OP_REMOTE_NAME_REQUEST, buf, NULL); } +bredr_name_callback name_callback = NULL; +int remote_name_req(const bt_addr_t *addr, bredr_name_callback cb) +{ + u8_t pscan = 0x01; + u16_t clock_offset = 0x00; + + name_callback = cb; + + return request_name(addr, pscan, clock_offset); +} + +void remote_name_complete(u8_t *name) +{ + if (name_callback) { + name_callback((const char *)name); + } +} + #define EIR_SHORT_NAME 0x08 #define EIR_COMPLETE_NAME 0x09 @@ -2912,6 +3072,11 @@ static void remote_name_request_complete(struct net_buf *buf) int eir_len = 240; u8_t *eir; int i; + BT_DBG("remote name:%s", evt->name); + + if (evt->name) { + remote_name_complete(evt->name); + } result = get_result_slot(&evt->bdaddr, 0xff); if (!result) { @@ -3693,11 +3858,21 @@ static void hci_cmd_done(u16_t opcode, u8_t status, struct net_buf *buf) atomic_set_bit_to(update->target, update->bit, update->val); } +#if (BFLB_BT_CO_THREAD) /* If the command was synchronous wake up bt_hci_cmd_send_sync() */ + if (cmd(buf)->sync || cmd(buf)->sync_state) { + cmd(buf)->status = status; + if (cmd(buf)->sync_state) + cmd(buf)->sync_state = BT_CMD_SYNC_TX_DONE; + else + k_sem_give(cmd(buf)->sync); + } +#else if (cmd(buf)->sync) { cmd(buf)->status = status; k_sem_give(cmd(buf)->sync); } +#endif //BFLB_BT_CO_THREAD } static void hci_cmd_complete(struct net_buf *buf) @@ -4207,14 +4382,26 @@ static void hci_event(struct net_buf *buf) net_buf_unref(buf); } +#if (BFLB_BT_CO_THREAD) +static void send_cmd(struct net_buf *tx_buf) +#else static void send_cmd(void) +#endif { struct net_buf *buf; int err; +#if (BFLB_BT_CO_THREAD) + if (tx_buf) { + buf = tx_buf; + } else { + buf = net_buf_get(&bt_dev.cmd_tx_queue, K_NO_WAIT); + } +#else /* Get next command */ BT_DBG("calling net_buf_get"); buf = net_buf_get(&bt_dev.cmd_tx_queue, K_NO_WAIT); +#endif BT_ASSERT(buf); /* Wait until ncmd > 0 */ @@ -4244,27 +4431,64 @@ static void send_cmd(void) } } +#if (BFLB_BT_CO_THREAD) +static void handle_rx_queue(void) +{ + struct net_buf *buf = NULL; + buf = net_buf_get(&recv_fifo, K_NO_WAIT); + if (buf) { + BT_DBG("Calling bt_recv(%p)", buf); + bt_recv(buf); + } +} +#endif + +#if (BFLB_BT_CO_THREAD) +static void process_events(struct k_poll_event *ev, int count, int total_evt_array_cnt) +#else static void process_events(struct k_poll_event *ev, int count) +#endif { BT_DBG("count %d", count); - +#if (BFLB_BT_CO_THREAD) + for (int ii = 0; ii < total_evt_array_cnt; ev++, ii++) { + if (ii >= count && ii != total_evt_array_cnt - 1) + continue; +#else for (; count; ev++, count--) { +#endif BT_DBG("ev->state %u", ev->state); - switch (ev->state) { case K_POLL_STATE_SIGNALED: break; case K_POLL_STATE_FIFO_DATA_AVAILABLE: if (ev->tag == BT_EVENT_CMD_TX) { +#if (BFLB_BT_CO_THREAD) + send_cmd(NULL); +#else send_cmd(); - } else if (IS_ENABLED(CONFIG_BT_CONN)) { +#endif + } +#if (BFLB_BT_CO_THREAD) + else if (ev->tag == BT_EVENT_RX_QUEUE) { + handle_rx_queue(); + } else if (ev->tag == BT_EVENT_WORK_QUEUE) { + extern void handle_work_queue(void); + handle_work_queue(); + } +#endif + else if (IS_ENABLED(CONFIG_BT_CONN)) { struct bt_conn *conn; if (ev->tag == BT_EVENT_CONN_TX_QUEUE) { conn = CONTAINER_OF(ev->fifo, struct bt_conn, tx_queue); +#if (BFLB_BT_CO_THREAD) + bt_conn_process_tx(conn, NULL); +#else bt_conn_process_tx(conn); +#endif } } break; @@ -4277,40 +4501,56 @@ static void process_events(struct k_poll_event *ev, int count) } } -#if defined(CONFIG_BT_CONN) -/* command FIFO + conn_change signal + MAX_CONN */ -#define EV_COUNT (2 + CONFIG_BT_MAX_CONN) -#else -/* command FIFO */ -#define EV_COUNT 1 -#endif - -#if defined(BFLB_BLE) -#if (BFLB_BLE_CO_THREAD) -void co_tx_thread() +#if (BFLB_BT_CO_THREAD) +static void bt_co_thread(void *p1, void *p2, void *p3) { static struct k_poll_event events[EV_COUNT] = { - K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, - K_POLL_MODE_NOTIFY_ONLY, - &bt_dev.cmd_tx_queue, - BT_EVENT_CMD_TX), + + [0] = K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, + K_POLL_MODE_NOTIFY_ONLY, + &g_work_queue_main.fifo, + BT_EVENT_WORK_QUEUE), + [1] = K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, + K_POLL_MODE_NOTIFY_ONLY, + &bt_dev.cmd_tx_queue, + BT_EVENT_CMD_TX), + [EV_COUNT - 1] = K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, + K_POLL_MODE_NOTIFY_ONLY, + &recv_fifo, + BT_EVENT_RX_QUEUE), }; - if (k_sem_count_get(&g_poll_sem) > 0) { + BT_DBG("Started"); + + while (1) { int ev_count, err; + events[0].state = K_POLL_STATE_NOT_READY; - ev_count = 1; + events[1].state = K_POLL_STATE_NOT_READY; + events[EV_COUNT - 1].state = K_POLL_STATE_NOT_READY; + ev_count = 2; if (IS_ENABLED(CONFIG_BT_CONN)) { - ev_count += bt_conn_prepare_events(&events[1]); + ev_count += bt_conn_prepare_events(&events[2]); } - err = k_poll(events, ev_count, K_NO_WAIT); - process_events(events, ev_count); + BT_DBG("Calling k_poll with %d events", ev_count); + + err = k_poll(events, ev_count, EV_COUNT, K_FOREVER, NULL); + + BT_ASSERT(err == 0); + + process_events(events, ev_count, EV_COUNT); + + /* Make sure we don't hog the CPU if there's all the time + * some ready events. + */ + k_yield(); } } -#endif +#else +#if defined(BFLB_BLE) static void hci_tx_thread(void *p1) #else static void hci_tx_thread(void *p1, void *p2, void *p3) @@ -4348,6 +4588,7 @@ static void hci_tx_thread(void *p1, void *p2, void *p3) k_yield(); } } +#endif //BFLB_BT_CO_THREAD static void read_local_ver_complete(struct net_buf *buf) { @@ -4862,6 +5103,10 @@ static int br_init(void) { struct net_buf *buf; struct bt_hci_cp_write_ssp_mode *ssp_cp; + struct bt_hci_cp_write_class_of_device *cod_cp; + struct bt_hci_cp_write_inquiry_scan_activity *inq_scan_act_cp; + struct bt_hci_cp_write_inquiry_scan_type *inq_scan_cp; + struct bt_hci_cp_write_page_scan_type *page_scan_cp; struct bt_hci_cp_write_inquiry_mode *inq_cp; struct bt_hci_write_local_name *name_cp; int err; @@ -4899,6 +5144,60 @@ static int br_init(void) return err; } + /* Write Class of Device */ + buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_CLASS_OF_DEVICE, sizeof(*cod_cp)); + if (!buf) { + return -ENOBUFS; + } + + cod_cp = net_buf_add(buf, sizeof(*cod_cp)); + u8_t cd[3] = { 0x14, 0x04, 0x24 }; + memcpy(cod_cp->cod, cd, 3); + err = bt_hci_cmd_send_sync(BT_HCI_OP_WRITE_CLASS_OF_DEVICE, buf, NULL); + if (err) { + return err; + } + + /* Write Inquiry Scan Activity */ + buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_INQUIRY_SCAN_ACTIVITY, sizeof(*inq_scan_act_cp)); + if (!buf) { + return -ENOBUFS; + } + + inq_scan_act_cp = net_buf_add(buf, sizeof(*inq_scan_act_cp)); + inq_scan_act_cp->interval = 0x0400; + inq_scan_act_cp->window = 0x0012; + err = bt_hci_cmd_send_sync(BT_HCI_OP_WRITE_INQUIRY_SCAN_ACTIVITY, buf, NULL); + if (err) { + return err; + } + + /* Write Inquiry Scan type with Interlaced */ + buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_INQUIRY_SCAN_TYPE, sizeof(*inq_scan_cp)); + if (!buf) { + return -ENOBUFS; + } + + inq_scan_cp = net_buf_add(buf, sizeof(*inq_scan_cp)); + inq_scan_cp->type = 0x01; + err = bt_hci_cmd_send_sync(BT_HCI_OP_WRITE_INQUIRY_SCAN_TYPE, buf, NULL); + if (err) { + return err; + } + + /* Write Page Scan type with Interlaced */ + buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_PAGE_SCAN_TYPE, sizeof(*page_scan_cp)); + if (!buf) { + return -ENOBUFS; + } + + page_scan_cp = net_buf_add(buf, sizeof(*page_scan_cp)); + page_scan_cp->type = 0x01; + err = bt_hci_cmd_send_sync(BT_HCI_OP_WRITE_PAGE_SCAN_TYPE, buf, NULL); + if (err) { + return err; + } + /* Enable Inquiry results with RSSI or extended Inquiry */ buf = bt_hci_cmd_create(BT_HCI_OP_WRITE_INQUIRY_MODE, sizeof(*inq_cp)); if (!buf) { @@ -5573,21 +5872,42 @@ int bt_enable(bt_ready_cb_t cb) #if defined(BFLB_BLE) #if defined(BFLB_DYNAMIC_ALLOC_MEM) +#if (BFLB_STATIC_ALLOC_MEM) + net_buf_init(HCI_CMD, &hci_cmd_pool, CONFIG_BT_HCI_CMD_COUNT, CMD_BUF_SIZE, NULL); + net_buf_init(HCI_RX, &hci_rx_pool, CONFIG_BT_RX_BUF_COUNT, BT_BUF_RX_SIZE, NULL); +#else net_buf_init(&hci_cmd_pool, CONFIG_BT_HCI_CMD_COUNT, CMD_BUF_SIZE, NULL); net_buf_init(&hci_rx_pool, CONFIG_BT_RX_BUF_COUNT, BT_BUF_RX_SIZE, NULL); +#endif #if defined(CONFIG_BT_CONN) +#if (BFLB_STATIC_ALLOC_MEM) + net_buf_init(NUM_COMPLETE, &num_complete_pool, 1, BT_BUF_RX_SIZE, NULL); +#else net_buf_init(&num_complete_pool, 1, BT_BUF_RX_SIZE, NULL); +#endif #if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) +#if (BFLB_STATIC_ALLOC_MEM) + net_buf_init(ACL_IN, &acl_in_pool, CONFIG_BT_ACL_RX_COUNT, ACL_IN_SIZE, report_completed_packet); +#else net_buf_init(&acl_in_pool, CONFIG_BT_ACL_RX_COUNT, ACL_IN_SIZE, report_completed_packet); +#endif #endif //CONFIG_BT_HCI_ACL_FLOW_CONTROL #endif //CONFIG_BT_CONN #if defined(CONFIG_BT_DISCARDABLE_BUF_COUNT) +#if (BFLB_STATIC_ALLOC_MEM) + net_buf_init(DISCARDABLE, &discardable_pool, CONFIG_BT_DISCARDABLE_BUF_COUNT, BT_BUF_RX_SIZE, NULL); +#else net_buf_init(&discardable_pool, CONFIG_BT_DISCARDABLE_BUF_COUNT, BT_BUF_RX_SIZE, NULL); #endif +#endif #endif k_work_init(&bt_dev.init, init_work); +#if (BFLB_BT_CO_THREAD) + k_fifo_init(&g_work_queue_main.fifo, 20); +#else k_work_q_start(); +#endif #if !defined(CONFIG_BT_WAIT_NOP) k_sem_init(&bt_dev.ncmd_sem, 1, 1); #else @@ -5599,6 +5919,10 @@ int bt_enable(bt_ready_cb_t cb) #endif k_sem_init(&g_poll_sem, 0, 1); +#if (BFLB_BT_CO_THREAD) + //need to initialize recv_fifo before create bt_co_thread + k_fifo_init(&recv_fifo, 20); +#endif #endif #if defined(BFLB_BLE_PATCH_SETTINGS_LOAD) @@ -5625,7 +5949,12 @@ int bt_enable(bt_ready_cb_t cb) /* TX thread */ #if defined(BFLB_BLE) -#if (!BFLB_BLE_CO_THREAD) +#if (BFLB_BT_CO_THREAD) + k_thread_create(&co_thread_data, "bt_co_thread", + CONFIG_BT_CO_STACK_SIZE, + bt_co_thread, + CONFIG_BT_CO_TASK_PRIO); +#else k_thread_create(&tx_thread_data, "hci_tx_thread", CONFIG_BT_HCI_TX_STACK_SIZE, hci_tx_thread, @@ -5696,9 +6025,7 @@ bool le_check_valid_scan(void) #if defined(BFLB_DISABLE_BT) extern struct k_thread recv_thread_data; extern struct k_thread work_q_thread; -extern struct k_fifo recv_fifo; extern struct k_fifo free_tx; -extern struct k_work_q g_work_queue_main; #if defined(CONFIG_BT_SMP) extern struct k_sem sc_local_pkey_ready; #endif @@ -5721,38 +6048,37 @@ extern struct net_buf_pool prep_pool; #if defined(CONFIG_BT_BREDR) extern struct net_buf_pool br_sig_pool; extern struct net_buf_pool sdp_pool; +#if defined CONFIG_BT_HFP extern struct net_buf_pool hf_pool; extern struct net_buf_pool dummy_pool; #endif #endif +#endif int bt_disable_action(void) { #if defined(CONFIG_BT_PRIVACY) k_delayed_work_del_timer(&bt_dev.rpa_update); #endif - +#if defined(CONFIG_BT_CONN) bt_gatt_deinit(); - - //delete task - k_thread_delete(&tx_thread_data); - k_thread_delete(&recv_thread_data); - k_thread_delete(&work_q_thread); - +#endif //delete queue, not delete hci_cmd_pool.free/hci_rx_pool.free/acl_tx_pool.free which store released buffers. bt_delete_queue(&recv_fifo); bt_delete_queue(&g_work_queue_main.fifo); bt_delete_queue(&bt_dev.cmd_tx_queue); - +#if defined(CONFIG_BT_CONN) k_queue_free((struct k_queue *)&free_tx); - +#endif //delete sem k_sem_delete(&bt_dev.ncmd_sem); k_sem_delete(&g_poll_sem); #if defined(CONFIG_BT_SMP) k_sem_delete(&sc_local_pkey_ready); #endif +#if defined(CONFIG_BT_CONN) k_sem_delete(&bt_dev.le.pkts); +#endif atomic_clear_bit(bt_dev.flags, BT_DEV_ENABLE); @@ -5774,9 +6100,11 @@ int bt_disable_action(void) #if defined(CONFIG_BT_BREDR) net_buf_deinit(&br_sig_pool); net_buf_deinit(&sdp_pool); +#if defined CONFIG_BT_HFP net_buf_deinit(&hf_pool); net_buf_deinit(&dummy_pool); #endif +#endif #endif //defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_DISCARDABLE_BUF_COUNT) net_buf_deinit(&discardable_pool); @@ -5785,15 +6113,26 @@ int bt_disable_action(void) bl_onchiphci_interface_deinit(); - extern void ble_controller_deinit(void); + //delete task ble_controller_deinit(); +#if (BFLB_BT_CO_THREAD) + k_thread_delete(&co_thread_data); +#else + k_thread_delete(&tx_thread_data); + k_thread_delete(&work_q_thread); + k_thread_delete(&recv_thread_data); +#endif return 0; } int bt_disable(void) { - if (le_check_valid_conn() || atomic_test_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN) || atomic_test_bit(bt_dev.flags, BT_DEV_ADVERTISING)) { + if ( +#if defined(CONFIG_BT_CONN) + le_check_valid_conn() || +#endif + atomic_test_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN) || atomic_test_bit(bt_dev.flags, BT_DEV_ADVERTISING)) { return -1; } else return bt_disable_action(); @@ -6357,10 +6696,10 @@ int bt_le_adv_start_internal(const struct bt_le_adv_param *param, if (param->options & BT_LE_ADV_OPT_CONNECTABLE) { if (IS_ENABLED(CONFIG_BT_PRIVACY) && !(param->options & BT_LE_ADV_OPT_USE_IDENTITY)) { -#if defined(CONFIG_BT_STACK_PTS) - if (param->addr_type == BT_ADDR_TYPE_RPA) +#if defined(CONFIG_BT_STACK_PTS) || defined(CONFIG_AUTO_PTS) + if (param->addr_type == BT_ADDR_LE_RANDOM_ID) err = le_set_private_addr(param->id); - else if (param->addr_type == BT_ADDR_TYPE_NON_RPA) + else if (param->addr_type == BT_ADDR_LE_RANDOM) err = le_set_non_resolv_private_addr(param->id); #else err = le_set_private_addr(param->id); @@ -6370,13 +6709,8 @@ int bt_le_adv_start_internal(const struct bt_le_adv_param *param, } if (BT_FEAT_LE_PRIVACY(bt_dev.le.features)) { -#if defined(CONFIG_BT_STACK_PTS) - if (param->addr_type == BT_ADDR_LE_PUBLIC) - set_param.own_addr_type = BT_ADDR_LE_PUBLIC; - if (param->addr_type == BT_ADDR_TYPE_RPA) - set_param.own_addr_type = BT_HCI_OWN_ADDR_RPA_OR_RANDOM; - else if (param->addr_type == BT_ADDR_TYPE_NON_RPA) - set_param.own_addr_type = BT_ADDR_LE_RANDOM; +#if defined(CONFIG_BT_STACK_PTS) || defined(CONFIG_AUTO_PTS) + set_param.own_addr_type = param->addr_type; #else set_param.own_addr_type = BT_HCI_OWN_ADDR_RPA_OR_RANDOM; @@ -6432,25 +6766,24 @@ int bt_le_adv_start_internal(const struct bt_le_adv_param *param, set_param.own_addr_type = id_addr->type; } else { #if defined(BFLB_BLE) && !defined(CONFIG_BT_MESH) -#if defined(CONFIG_BT_STACK_PTS) - if (param->addr_type == BT_ADDR_TYPE_RPA) +#if defined(CONFIG_BT_STACK_PTS) || defined(CONFIG_AUTO_PTS) + if (param->addr_type == BT_ADDR_LE_RANDOM_ID) err = le_set_private_addr(param->id); - else if (param->addr_type == BT_ADDR_TYPE_NON_RPA) + else if (param->addr_type == BT_ADDR_LE_RANDOM) err = le_set_non_resolv_private_addr(param->id); #else //#if !defined(CONFIG_BT_ADV_WITH_PUBLIC_ADDR) //err = le_set_private_addr(param->id); //#endif #endif //CONFIG_BT_STACK_PTS -#if defined(CONFIG_BT_STACK_PTS) - if (param->addr_type == BT_ADDR_LE_PUBLIC) - set_param.own_addr_type = BT_ADDR_LE_PUBLIC; - else +#if defined(CONFIG_BT_STACK_PTS) || defined(CONFIG_AUTO_PTS) + set_param.own_addr_type = param->addr_type; +#else + //set_param.own_addr_type = BT_ADDR_LE_RANDOM; + //#if defined(CONFIG_BT_ADV_WITH_PUBLIC_ADDR) + set_param.own_addr_type = BT_ADDR_LE_PUBLIC; +//#endif #endif - //set_param.own_addr_type = BT_ADDR_LE_RANDOM; - //#if defined(CONFIG_BT_ADV_WITH_PUBLIC_ADDR) - set_param.own_addr_type = BT_ADDR_LE_PUBLIC; - //#endif #endif } diff --git a/components/ble/ble_stack/host/hci_core.h b/components/ble/ble_stack/host/hci_core.h index 488e5311..2411fc60 100644 --- a/components/ble/ble_stack/host/hci_core.h +++ b/components/ble/ble_stack/host/hci_core.h @@ -20,10 +20,22 @@ #define BT_VOICE_CVSD_16BIT 0x0060 #define BT_VOICE_MSBC_16BIT 0x0063 +#if (BFLB_BT_CO_THREAD) +enum { + BT_CMD_SYNC_NONE = 0, + BT_CMD_SYNC_TX = 1, + BT_CMD_SYNC_TX_DONE = 2 +}; +#endif + /* k_poll event tags */ enum { BT_EVENT_CMD_TX, BT_EVENT_CONN_TX_QUEUE, +#if (BFLB_BT_CO_THREAD) + BT_EVENT_RX_QUEUE, + BT_EVENT_WORK_QUEUE, +#endif }; /* bt_dev flags: the flags defined here represent BT controller state */ @@ -60,6 +72,10 @@ enum { BT_DEV_ADV_ADDRESS_IS_PUBLIC, #endif +#if defined(CONFIG_AUTO_PTS) + BT_DEV_SETTED_NON_RESOLV_ADDR, //The non-reslovable address have been set. +#endif + #if defined(BFLB_HOST_ASSISTANT) BT_DEV_ASSIST_RUN, #endif @@ -262,8 +278,9 @@ int set_adv_channel_map(u8_t channel); int bt_get_local_public_address(bt_addr_le_t *adv_addr); int bt_get_local_ramdon_address(bt_addr_le_t *adv_addr); int bt_le_set_data_len(struct bt_conn *conn, u16_t tx_octets, u16_t tx_time); -int hci_le_set_phy(struct bt_conn *conn); -int hci_le_set_default_phy(struct bt_conn *conn, u8_t default_phy); +int hci_le_set_phy(struct bt_conn *conn, uint8_t all_phys, + uint8_t pref_tx_phy, uint8_t pref_rx_phy, uint8_t phy_opts); +int hci_le_set_default_phy(u8_t default_phy); #if defined(CONFIG_SET_TX_PWR) int bt_set_tx_pwr(int8_t power); @@ -282,4 +299,7 @@ void bt_hci_reset_complete(struct net_buf *buf); void bt_register_host_assist_cb(struct blhast_cb *cb); #endif +typedef void (*bredr_name_callback)(const char *name); +int remote_name_req(const bt_addr_t *addr, bredr_name_callback cb); + #endif diff --git a/components/ble/ble_stack/host/l2cap_br.c b/components/ble/ble_stack/host/l2cap_br.c index a282debc..c8fb201d 100644 --- a/components/ble/ble_stack/host/l2cap_br.c +++ b/components/ble/ble_stack/host/l2cap_br.c @@ -30,6 +30,8 @@ #include "a2dp_internal.h" #include "rfcomm_internal.h" #include "hfp_hf.h" +#include "avctp.h" +#include "avrcp.h" #define BR_CHAN(_ch) CONTAINER_OF(_ch, struct bt_l2cap_br_chan, chan) #define BR_CHAN_RTX(_w) CONTAINER_OF(_w, struct bt_l2cap_br_chan, chan.rtx_work) @@ -74,6 +76,7 @@ enum { }; static sys_slist_t br_servers; +static uint8_t ident; /* Pool for outgoing BR/EDR signaling packets, min MTU is 48 */ #if !defined(BFLB_DYNAMIC_ALLOC_MEM) @@ -215,8 +218,6 @@ static bool l2cap_br_chan_add(struct bt_conn *conn, struct bt_l2cap_chan *chan, static uint8_t l2cap_br_get_ident(void) { - static uint8_t ident; - ident++; /* handle integer overflow (0 is not valid) */ if (!ident) { @@ -478,6 +479,8 @@ void bt_l2cap_br_connected(struct bt_conn *conn) connect_fixed_channel(ch); + /* reset l2cap signaling channel identifier */ + ident = 0; sig_ch = CONTAINER_OF(ch, struct bt_l2cap_br, chan); l2cap_br_get_info(sig_ch, BT_L2CAP_INFO_FEAT_MASK); } @@ -1556,19 +1559,18 @@ void bt_l2cap_br_init(void) bt_sdp_init(); - if (IS_ENABLED(CONFIG_BT_RFCOMM)) { - bt_rfcomm_init(); - } - if (IS_ENABLED(CONFIG_BT_HFP)) { + bt_rfcomm_init(); bt_hfp_hf_init(); } - if (IS_ENABLED(CONFIG_BT_AVDTP)) { - bt_avdtp_init(); - } - if (IS_ENABLED(CONFIG_BT_A2DP)) { + bt_avdtp_init(); bt_a2dp_init(); } + + if (IS_ENABLED(CONFIG_BT_AVRCP)) { + bt_avctp_init(); + bt_avrcp_init(); + } } diff --git a/components/ble/ble_stack/host/monitor.c b/components/ble/ble_stack/host/monitor.c index af4ee9c2..de5191a0 100644 --- a/components/ble/ble_stack/host/monitor.c +++ b/components/ble/ble_stack/host/monitor.c @@ -17,8 +17,9 @@ void bt_monitor_send(uint16_t opcode, const void *data, size_t len) { const uint8_t *buf = data; - + unsigned int key = irq_lock(); BT_WARN("[Hci]:pkt_type:[0x%x],pkt_data:[%s]\r\n", opcode, bt_hex(buf, len)); + irq_unlock(key); } void bt_monitor_new_index(uint8_t type, uint8_t bus, bt_addr_t *addr, diff --git a/components/ble/ble_stack/host/multi_adv.c b/components/ble/ble_stack/host/multi_adv.c index 4a141878..b933470a 100644 --- a/components/ble/ble_stack/host/multi_adv.c +++ b/components/ble/ble_stack/host/multi_adv.c @@ -11,6 +11,7 @@ #include "multi_adv.h" #include "work_q.h" +#include "log.h" static struct multi_adv_instant g_multi_adv_list[MAX_MULTI_ADV_INSTANT]; static struct multi_adv_scheduler g_multi_adv_scheduler; @@ -310,7 +311,7 @@ void multi_adv_schedule_timeslot(struct multi_adv_scheduler *adv_scheduler) } } - // BT_DBG("multi_adv_schedule_timeslot, num = %d, match = %d", inst_num, match); + BT_DBG("multi_adv_schedule_timeslot, num = %d, match = %d", inst_num, match); if (match) { int offset_per_instant, diff; offset_per_instant = TIME_PRIOD_MS / match; @@ -416,7 +417,7 @@ void multi_adv_new_schedule(void) } if (high_duty_instant) { - //BT_WARN("High Duty Cycle Instants, id = %d, interval = %d\n", adv_instant->instant_id, adv_instant->param.interval_min); + BT_WARN("High Duty Cycle Instants, id = %d, interval = %d\n", adv_instant->instant_id, adv_instant->param.interval_min); multi_adv_start_adv_instant(adv_instant); return; } @@ -449,7 +450,7 @@ void multi_adv_new_schedule(void) adv_instant->instant_interval = inst_interval[i]; adv_instant->instant_offset = inst_offset[i]; - //BT_WARN("adv_instant id = %d, interval = %d, offset = %d\n", adv_instant->instant_id, adv_instant->instant_interval, adv_instant->instant_offset); + BT_WARN("adv_instant id = %d, interval = %d, offset = %d\n", adv_instant->instant_id, adv_instant->instant_interval, adv_instant->instant_offset); } multi_adv_schedule_start(); @@ -493,7 +494,7 @@ int bt_le_multi_adv_stop(int instant_id) if (multi_adv_find_instant_by_id(instant_id) == 0) return -1; - //BT_WARN("%s id[%d]\n", __func__, instant_id); + BT_WARN("%s id[%d]\n", __func__, instant_id); multi_adv_delete_instant_by_id(instant_id); multi_adv_new_schedule(); diff --git a/components/ble/ble_stack/host/settings.c b/components/ble/ble_stack/host/settings.c index 1eaffca7..6d39e757 100644 --- a/components/ble/ble_stack/host/settings.c +++ b/components/ble/ble_stack/host/settings.c @@ -253,61 +253,30 @@ int bt_check_if_ef_ready() int bt_settings_set_bin(const char *key, const uint8_t *value, size_t length) { - const char *lookup = "0123456789abcdef"; - char *str_value; int err; err = bt_check_if_ef_ready(); if (err) return err; - str_value = pvPortMalloc(length * 2 + 1); - - BT_ASSERT(str_value != NULL); - - for (size_t i = 0; i < length; i++) { - str_value[(i * 2) + 0] = lookup[(value[i] >> 4) & 0x0F]; - str_value[(i * 2) + 1] = lookup[value[i] & 0x0F]; - } - str_value[length * 2] = '\0'; - - err = ef_set_env(key, (const char *)str_value); - - vPortFree(str_value); + err = ef_set_env_blob(key, value, length); return err; } int bt_settings_get_bin(const char *key, u8_t *value, size_t exp_len, size_t *real_len) { - char *str_value; - size_t str_value_len; - char rand[3]; int err; + size_t rlen; err = bt_check_if_ef_ready(); if (err) return err; - str_value = ef_get_env(key); - if (str_value == NULL) { - return -1; - } - - str_value_len = strlen(str_value); - - if ((str_value_len % 2) != 0 || (exp_len > 0 && str_value_len > exp_len * 2)) { - return -1; - } + rlen = ef_get_env_blob(key, value, exp_len, NULL); if (real_len) - *real_len = str_value_len / 2; - - for (size_t i = 0; i < str_value_len / 2; i++) { - strncpy(rand, str_value + 2 * i, 2); - rand[2] = '\0'; - value[i] = strtol(rand, NULL, 16); - } + *real_len = rlen; return 0; } @@ -344,10 +313,7 @@ void bt_settings_save_id(void) #if defined(CONFIG_BT_SETTINGS) void bt_settings_save_name(void) { - if (bt_check_if_ef_ready()) - return; - - ef_set_env(NV_LOCAL_NAME, bt_dev.name); + bt_settings_set_bin(NV_LOCAL_NAME, (u8_t *)bt_dev.name, strlen(bt_dev.name) + 1); } void bt_local_info_load(void) @@ -355,13 +321,7 @@ void bt_local_info_load(void) if (bt_check_if_ef_ready()) return; #if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC) - char *dev_name; - uint8_t len; - dev_name = ef_get_env(NV_LOCAL_NAME); - if (dev_name != NULL) { - len = ((strlen(dev_name) + 1) < CONFIG_BT_DEVICE_NAME_MAX) ? (strlen(dev_name) + 1) : CONFIG_BT_DEVICE_NAME_MAX; - memcpy(bt_dev.name, dev_name, len); - } + bt_settings_get_bin(NV_LOCAL_NAME, (u8_t *)bt_dev.name, CONFIG_BT_DEVICE_NAME_MAX, NULL); #endif bt_settings_get_bin(NV_LOCAL_ID_ADDR, (u8_t *)&bt_dev.id_addr[0], sizeof(bt_addr_le_t) * CONFIG_BT_ID_MAX, NULL); #if defined(CONFIG_BT_PRIVACY) diff --git a/components/ble/ble_stack/host/smp.c b/components/ble/ble_stack/host/smp.c index 06c16bc5..f2358edb 100644 --- a/components/ble/ble_stack/host/smp.c +++ b/components/ble/ble_stack/host/smp.c @@ -258,8 +258,10 @@ struct bt_smp_br { static struct bt_smp_br bt_smp_br_pool[CONFIG_BT_MAX_CONN]; #endif /* CONFIG_BT_BREDR */ -#if defined(CONFIG_BT_STACK_PTS) +#if defined(CONFIG_BT_STACK_PTS) || defined(CONFIG_AUTO_PTS) static bool mitm = IS_ENABLED(CONFIG_BT_SMP_ENFORCE_MITM); +#endif +#if defined(CONFIG_BT_STACK_PTS) static int smp_test_flag = 0; #endif @@ -2660,12 +2662,14 @@ void bt_set_bondable(bool enable) bondable = enable; } -#if defined(CONFIG_BT_STACK_PTS) +#if defined(CONFIG_BT_STACK_PTS) || defined(CONFIG_AUTO_PTS) void bt_set_mitm(bool enable) { mitm = enable; } +#endif +#if defined(CONFIG_BT_STACK_PTS) void bt_set_smpflag(smp_test_id id) { atomic_set_bit(&smp_test_flag, id); @@ -2708,7 +2712,7 @@ static u8_t get_auth(struct bt_conn *conn, u8_t auth) auth &= BT_SMP_AUTH_MASK; } -#if defined(CONFIG_BT_STACK_PTS) +#if defined(CONFIG_BT_STACK_PTS) || defined(CONFIG_AUTO_PTS) if ((get_io_capa() == BT_SMP_IO_NO_INPUT_OUTPUT) || (!mitm && (conn->required_sec_level < BT_SECURITY_L3))) { diff --git a/components/ble/ble_stack/include/bluetooth/addr.h b/components/ble/ble_stack/include/bluetooth/addr.h index 768f3189..016181f6 100644 --- a/components/ble/ble_stack/include/bluetooth/addr.h +++ b/components/ble/ble_stack/include/bluetooth/addr.h @@ -21,12 +21,6 @@ extern "C" { #define BT_ADDR_LE_PUBLIC_ID 0x02 #define BT_ADDR_LE_RANDOM_ID 0x03 -#if defined(CONFIG_BT_STACK_PTS) -//for app layer to deliver the address type:non rpa ,rpa -#define BT_ADDR_TYPE_NON_RPA 0x01 -#define BT_ADDR_TYPE_RPA 0x02 -#endif - /** Bluetooth Device Address */ typedef struct { u8_t val[6]; diff --git a/components/ble/ble_stack/include/bluetooth/bluetooth.h b/components/ble/ble_stack/include/bluetooth/bluetooth.h index ec0a5d52..826d4ec5 100644 --- a/components/ble/ble_stack/include/bluetooth/bluetooth.h +++ b/components/ble/ble_stack/include/bluetooth/bluetooth.h @@ -315,7 +315,7 @@ struct bt_le_adv_param { /** Maximum Advertising Interval (N * 0.625) */ u16_t interval_max; -#if defined(CONFIG_BT_STACK_PTS) +#if defined(CONFIG_BT_STACK_PTS) || defined(CONFIG_AUTO_PTS) u8_t addr_type; #endif }; diff --git a/components/ble/ble_stack/include/bluetooth/conn.h b/components/ble/ble_stack/include/bluetooth/conn.h index 98ba3c8c..66376abc 100644 --- a/components/ble/ble_stack/include/bluetooth/conn.h +++ b/components/ble/ble_stack/include/bluetooth/conn.h @@ -106,6 +106,7 @@ struct bt_conn *bt_conn_lookup_addr_le(u8_t id, const bt_addr_le_t *peer); #if defined(BFLB_BLE) bool le_check_valid_conn(void); +void notify_disconnected(struct bt_conn *conn); #if defined(BFLB_HOST_ASSISTANT) void bt_notify_disconnected(void); #endif @@ -490,6 +491,17 @@ struct bt_conn_cb { */ void (*le_param_updated)(struct bt_conn *conn, u16_t interval, u16_t latency, u16_t timeout); + + /** @brief The PHY of the connection has changed. + * + * This callback notifies the application that the PHY of the + * connection has changed. + * + * @param conn Connection object. + * @param tx_phy Transmit phy. + * @param rx_phy Receive phy. + */ + void (*le_phy_updated)(struct bt_conn *conn, u8_t tx_phy, u8_t rx_phy); #if defined(CONFIG_BT_SMP) /** @brief Remote Identity Address has been resolved. * diff --git a/components/ble/ble_stack/include/bluetooth/gatt.h b/components/ble/ble_stack/include/bluetooth/gatt.h index 709e8bc2..20b9391c 100644 --- a/components/ble/ble_stack/include/bluetooth/gatt.h +++ b/components/ble/ble_stack/include/bluetooth/gatt.h @@ -529,6 +529,13 @@ ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset); +#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \ + { \ + .uuid = _uuid, \ + .value_handle = _handle, \ + .properties = _props, \ + } + /** @def BT_GATT_CHARACTERISTIC * @brief Characteristic and Value Declaration Macro. * @@ -545,10 +552,8 @@ ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn, #define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _value) \ BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \ bt_gatt_attr_read_chrc, NULL, \ - (&(struct bt_gatt_chrc){ \ - .uuid = _uuid, \ - .value_handle = 0U, \ - .properties = _props, \ + ((struct bt_gatt_chrc[]){ \ + BT_GATT_CHRC_INIT(_uuid, 0U, _props), \ })), \ BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _value) @@ -784,10 +789,11 @@ ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn, #define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _value) \ { \ .uuid = _uuid, \ - .perm = _perm, \ .read = _read, \ .write = _write, \ .user_data = _value, \ + .handle = 0, \ + .perm = _perm, \ } /** @brief Notification complete result callback. @@ -1370,7 +1376,12 @@ void bt_gatt_cancel(struct bt_conn *conn, void *params); typedef void (*bt_gatt_mtu_changed_cb_t)(struct bt_conn *conn, int mtu); void bt_gatt_register_mtu_callback(bt_gatt_mtu_changed_cb_t cb); #endif - +#if defined(CONFIG_BT_GATT_CLIENT) +#if defined(BFLB_BLE_NOTIFY_ALL) +typedef void (*bt_notification_all_cb_t)(struct bt_conn *conn, u16_t handle, const void *data, u16_t length); +void bt_gatt_register_notification_callback(bt_notification_all_cb_t cb); +#endif +#endif #if defined(BFLB_BLE) /** @brief load gatt ccc from flash * diff --git a/components/ble/ble_stack/include/bluetooth/hci_host.h b/components/ble/ble_stack/include/bluetooth/hci_host.h index 5d79f000..b1c514b9 100644 --- a/components/ble/ble_stack/include/bluetooth/hci_host.h +++ b/components/ble/ble_stack/include/bluetooth/hci_host.h @@ -476,6 +476,17 @@ struct bt_hci_write_local_name { #define BT_BREDR_SCAN_INQUIRY 0x01 #define BT_BREDR_SCAN_PAGE 0x02 +#define BT_HCI_OP_WRITE_INQUIRY_SCAN_ACTIVITY BT_OP(BT_OGF_BASEBAND, 0x001e) +struct bt_hci_cp_write_inquiry_scan_activity { + u16_t interval; + u16_t window; +} __packed; + +#define BT_HCI_OP_WRITE_CLASS_OF_DEVICE BT_OP(BT_OGF_BASEBAND, 0x0024) +struct bt_hci_cp_write_class_of_device { + u8_t cod[3]; +} __packed; + #define BT_TX_POWER_LEVEL_CURRENT 0x00 #define BT_TX_POWER_LEVEL_MAX 0x01 #define BT_HCI_OP_READ_TX_POWER_LEVEL BT_OP(BT_OGF_BASEBAND, 0x002d) @@ -516,11 +527,21 @@ struct bt_hci_cp_host_num_completed_packets { struct bt_hci_handle_count h[0]; } __packed; +#define BT_HCI_OP_WRITE_INQUIRY_SCAN_TYPE BT_OP(BT_OGF_BASEBAND, 0x0043) +struct bt_hci_cp_write_inquiry_scan_type { + u8_t type; +} __packed; + #define BT_HCI_OP_WRITE_INQUIRY_MODE BT_OP(BT_OGF_BASEBAND, 0x0045) struct bt_hci_cp_write_inquiry_mode { u8_t mode; } __packed; +#define BT_HCI_OP_WRITE_PAGE_SCAN_TYPE BT_OP(BT_OGF_BASEBAND, 0x0047) +struct bt_hci_cp_write_page_scan_type { + u8_t type; +} __packed; + #define BT_HCI_OP_WRITE_EXT_INQUIRY_RESP BT_OP(BT_OGF_BASEBAND, 0x0052) struct bt_hci_cp_write_ext_inquiry_resp { u8_t rec; @@ -2617,6 +2638,10 @@ typedef bool bt_hci_vnd_evt_cb_t(struct net_buf_simple *buf); */ int bt_hci_register_vnd_evt_cb(bt_hci_vnd_evt_cb_t cb); +#if (BFLB_BT_CO_THREAD) +struct k_thread *bt_get_co_thread(void); +#endif + #ifdef __cplusplus } #endif diff --git a/components/ble/ble_stack/include/bluetooth/l2cap.h b/components/ble/ble_stack/include/bluetooth/l2cap.h index 8b83dac0..12db69e7 100644 --- a/components/ble/ble_stack/include/bluetooth/l2cap.h +++ b/components/ble/ble_stack/include/bluetooth/l2cap.h @@ -17,7 +17,6 @@ * @{ */ -#include #include <../bluetooth/buf.h> #include #include diff --git a/components/ble/ble_stack/include/bluetooth/uuid.h b/components/ble/ble_stack/include/bluetooth/uuid.h index dcfbc92e..8483b16e 100644 --- a/components/ble/ble_stack/include/bluetooth/uuid.h +++ b/components/ble/ble_stack/include/bluetooth/uuid.h @@ -69,11 +69,11 @@ struct bt_uuid_128 { } #define BT_UUID_DECLARE_16(value) \ - ((struct bt_uuid *)(&(struct bt_uuid_16)BT_UUID_INIT_16(value))) + ((struct bt_uuid *)((struct bt_uuid_16[]){ BT_UUID_INIT_16(value) })) #define BT_UUID_DECLARE_32(value) \ - ((struct bt_uuid *)(&(struct bt_uuid_32)BT_UUID_INIT_32(value))) + ((struct bt_uuid *)((struct bt_uuid_32[]){ BT_UUID_INIT_32(value) })) #define BT_UUID_DECLARE_128(value...) \ - ((struct bt_uuid *)(&(struct bt_uuid_128)BT_UUID_INIT_128(value))) + ((struct bt_uuid *)((struct bt_uuid_128[]){ BT_UUID_INIT_128(value) })) #define BT_UUID_16(__u) CONTAINER_OF(__u, struct bt_uuid_16, uuid) #define BT_UUID_32(__u) CONTAINER_OF(__u, struct bt_uuid_32, uuid) diff --git a/components/ble/ble_stack/include/drivers/bluetooth/hci_driver.h b/components/ble/ble_stack/include/drivers/bluetooth/hci_driver.h index 2cb23d06..3bc5d40b 100644 --- a/components/ble/ble_stack/include/drivers/bluetooth/hci_driver.h +++ b/components/ble/ble_stack/include/drivers/bluetooth/hci_driver.h @@ -194,10 +194,6 @@ void hci_driver_enque_recvq(struct net_buf *buf); int hci_driver_init(void); -#if (BFLB_BLE_CO_THREAD) -void co_tx_thread(); -#endif - #endif //#if (BFLB_BLE) #ifdef __cplusplus diff --git a/components/ble/ble_stack/port/bl_port.c b/components/ble/ble_stack/port/bl_port.c index ccc1568d..65046780 100644 --- a/components/ble/ble_stack/port/bl_port.c +++ b/components/ble/ble_stack/port/bl_port.c @@ -29,7 +29,6 @@ extern int bl_rand(); int ble_rand() { #if defined(CONFIG_HW_SEC_ENG_DISABLE) - extern long random(void); return random(); #else return bl_rand(); @@ -59,7 +58,7 @@ int bl_rand() void k_queue_init(struct k_queue *queue, int size) { //int size = 20; - uint8_t blk_size = sizeof(void *) + 1; + uint8_t blk_size = sizeof(void *); queue->hdl = xQueueCreate(size, blk_size); BT_ASSERT(queue->hdl != NULL); @@ -249,18 +248,27 @@ int k_thread_create(struct k_thread *new_thread, const char *name, return new_thread->task ? 0 : -1; } -void k_thread_delete(struct k_thread *new_thread) +void k_thread_delete(struct k_thread *thread) { - if (NULL == new_thread || 0 == new_thread->task) { + if (NULL == thread || 0 == thread->task) { BT_ERR("task is NULL\n"); return; } - vTaskDelete((void *)(new_thread->task)); - new_thread->task = 0; + vTaskDelete((void *)(thread->task)); + thread->task = 0; return; } +bool k_is_current_thread(struct k_thread *thread) +{ + eTaskState thread_state = eTaskGetState((void *)(thread->task)); + if (thread_state == eRunning) + return true; + else + return false; +} + int k_yield(void) { taskYIELD(); @@ -367,7 +375,7 @@ long long k_now_ms(void) void k_get_random_byte_array(uint8_t *buf, size_t len) { - // bl_rand() return a word, but *buf may not be word-aligned + // ble_rand() return a word, but *buf may not be word-aligned for (int i = 0; i < len; i++) { *(buf + i) = (uint8_t)(ble_rand() & 0xFF); } @@ -375,10 +383,18 @@ void k_get_random_byte_array(uint8_t *buf, size_t len) void *k_malloc(size_t size) { +#if defined(CFG_USE_PSRAM) + return pvPortMallocPsram(size); +#else return pvPortMalloc(size); +#endif /* CFG_USE_PSRAM */ } void k_free(void *buf) { +#if defined(CFG_USE_PSRAM) + return vPortFreePsram(buf); +#else return vPortFree(buf); +#endif } diff --git a/components/ble/ble_stack/port/include/bl_port.h b/components/ble/ble_stack/port/include/bl_port.h index 7e55feeb..5cbcc628 100644 --- a/components/ble/ble_stack/port/include/bl_port.h +++ b/components/ble/ble_stack/port/include/bl_port.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "types.h" #include "bl_port.h" @@ -242,6 +243,8 @@ int k_thread_create(struct k_thread *new_thread, const char *name, void k_thread_delete(struct k_thread *new_thread); +bool k_is_current_thread(struct k_thread *thread); + /** * @brief Yield the current thread. */ diff --git a/components/ble/ble_stack/port/include/config.h b/components/ble/ble_stack/port/include/config.h index 073c9401..6d3bfb7b 100644 --- a/components/ble/ble_stack/port/include/config.h +++ b/components/ble/ble_stack/port/include/config.h @@ -52,13 +52,31 @@ #define CONFIG_BT_HCI_RX_STACK_SIZE 512 #endif +/** + * BL_BLE_CO_THREAD: combine tx rx thread + */ +#define BFLB_BT_CO_THREAD 1 + +#if (BFLB_BT_CO_THREAD) +#define CONFIG_BT_CO_TASK_PRIO (configMAX_PRIORITIES - 3) +#if defined(CONFIG_BT_MESH) +#define CONFIG_BT_CO_STACK_SIZE 3072 //2048//1536//1024 +#else +#define CONFIG_BT_CO_STACK_SIZE 2048 //2048//1536//1024 +#endif +#endif + #ifndef CONFIG_BT_RX_STACK_SIZE #if defined(CONFIG_BT_MESH) #define CONFIG_BT_RX_STACK_SIZE 3072 //2048//1536//1024 #else +#if !defined(CONFIG_BT_CONN) +#define CONFIG_BT_RX_STACK_SIZE 1024 +#else #define CONFIG_BT_RX_STACK_SIZE 2048 //1536//1024 #endif #endif +#endif #ifndef CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE #define CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE 156 @@ -74,8 +92,12 @@ */ #ifndef CONFIG_BT_HCI_TX_STACK_SIZE +#if !defined(CONFIG_BT_CONN) +#define CONFIG_BT_HCI_TX_STACK_SIZE 1024 +#else #define CONFIG_BT_HCI_TX_STACK_SIZE 1536 //1024//200 #endif +#endif /** * CONFIG_BT_HCI_TX_PRIO: tx thread priority @@ -88,13 +110,6 @@ #define CONFIG_BT_CTLR_RX_PRIO (configMAX_PRIORITIES - 4) #endif -/** - * BL_BLE_CO_THREAD: combine tx rx thread - */ -#ifndef BFLB_BLE_CO_THREAD -#define BFLB_BLE_CO_THREAD 0 -#endif - /** * CONFIG_BT_HCI_CMD_COUNT: hci cmd buffer count,range 2 to 64 */ @@ -288,9 +303,13 @@ * range 1 to 65535,seconds */ #ifndef CONFIG_BT_RPA_TIMEOUT +#if defined(CONFIG_AUTO_PTS) +#define CONFIG_BT_RPA_TIMEOUT 60 +#else #define CONFIG_BT_RPA_TIMEOUT 900 #endif #endif +#endif /** * CONFIG_BT_GATT_DYNAMIC_DB:enables GATT services to be added dynamically to database @@ -352,7 +371,7 @@ #elif defined(BL702) #define CONFIG_BT_DEVICE_NAME "BL702-BLE-DEV" #else -#define CONFIG_BT_DEVICE_NAME "BL606P-BTBLE" +#define CONFIG_BT_DEVICE_NAME "BTBLE-DEV" #endif #endif #endif @@ -381,9 +400,13 @@ #ifndef CONFIG_BT_MESH #define CONFIG_BT_WORK_QUEUE_STACK_SIZE 1536 //1280//512 #else +#if !defined(CONFIG_BT_CONN) +#define CONFIG_BT_WORK_QUEUE_STACK_SIZE 1024 +#else #define CONFIG_BT_WORK_QUEUE_STACK_SIZE 2048 #endif /* CONFIG_BT_MESH */ #endif +#endif /** * CONFIG_BT_WORK_QUEUE_PRIO:Work queue priority. @@ -540,6 +563,10 @@ #define CONFIG_BT_PERIPHERAL_PREF_TIMEOUT 400 #endif +#ifndef CONFIG_BT_PHY_UPDATE +#define CONFIG_BT_PHY_UPDATE 1 +#endif + #if defined(CONFIG_BT_BREDR) #define CONFIG_BT_PAGE_TIMEOUT 0x2000 //5.12s #define CONFIG_BT_L2CAP_RX_MTU 672 @@ -566,7 +593,15 @@ #define BFLB_DISABLE_BT #define BFLB_FIXED_IRK 0 #define BFLB_DYNAMIC_ALLOC_MEM +#if defined(CFG_BLE_PDS) && defined(BL702) && defined(BFLB_BLE) && defined(BFLB_DYNAMIC_ALLOC_MEM) +#define BFLB_STATIC_ALLOC_MEM 1 +#else +#define BFLB_STATIC_ALLOC_MEM 0 +#endif +#define CONFIG_BT_SCAN_WITH_IDENTITY 1 + #if defined(CONFIG_AUTO_PTS) +#define CONFIG_BT_L2CAP_DYNAMIC_CHANNEL #define CONFIG_BT_DEVICE_NAME_GATT_WRITABLE 1 #define CONFIG_BT_GATT_SERVICE_CHANGED 1 #define CONFIG_BT_GATT_CACHING 1 @@ -587,9 +622,11 @@ happens, which cause memory leak issue.*/ /*To avoid duplicated pubkey callback.*/ #define BFLB_BLE_PATCH_AVOID_DUPLI_PUBKEY_CB /*The flag @conn_ref is not clean up after disconnect*/ -#define BFLB_BLE_PATCH_CLEAN_UP_CONNECT_REF +//#define BFLB_BLE_PATCH_CLEAN_UP_CONNECT_REF +#if !defined(CONFIG_AUTO_PTS) /*To avoid sevice changed indication sent at the very beginning, without any new service added.*/ #define BFLB_BLE_PATCH_SET_SCRANGE_CHAGD_ONLY_IN_CONNECTED_STATE +#endif #ifdef CONFIG_BT_SETTINGS /*Semaphore is used during flash operation. Make sure that freertos has already run up when it intends to write information to flash.*/ @@ -607,10 +644,14 @@ BT_SMP_DIST_ENC_KEY bit is not cleared while remote ENC_KEY is received.*/ #define BFLB_BLE_PATCH_CLEAR_REMOTE_KEY_BIT #if defined(CONFIG_BT_CENTRAL) || defined(CONFIG_BT_OBSERVER) +#if defined(BL602) || defined(BL702) #define BFLB_BLE_NOTIFY_ADV_DISCARDED #endif -#if defined(__cplusplus) -} +#endif + +#if defined(CONFIG_BT_CENTRAL) +#define BFLB_BLE_NOTIFY_ALL +#define BFLB_BLE_DISCOVER_ONGOING #endif #endif /* BLE_CONFIG_H */ diff --git a/components/ble/ble_stack/port/include/zephyr.h b/components/ble/ble_stack/port/include/zephyr.h index ca2d0dd3..2b064112 100644 --- a/components/ble/ble_stack/port/include/zephyr.h +++ b/components/ble/ble_stack/port/include/zephyr.h @@ -128,7 +128,11 @@ struct k_poll_signal { } extern int k_poll_signal_raise(struct k_poll_signal *signal, int result); +#if (BFLB_BT_CO_THREAD) +extern int k_poll(struct k_poll_event *events, int num_events, int total_evt_array_cnt, s32_t timeout, u8_t *to_process); +#else extern int k_poll(struct k_poll_event *events, int num_events, s32_t timeout); +#endif extern void k_poll_event_init(struct k_poll_event *event, u32_t type, int mode, void *obj); /* public - polling modes */ diff --git a/components/ble/ble_stack/sbc/enc/sbc_encoder.c b/components/ble/ble_stack/sbc/enc/sbc_encoder.c index bcfdfa45..0fb9a5e8 100644 --- a/components/ble/ble_stack/sbc/enc/sbc_encoder.c +++ b/components/ble/ble_stack/sbc/enc/sbc_encoder.c @@ -24,6 +24,7 @@ #include #include +#include "log.h" #include "sbc_encoder.h" #include "sbc_enc_func_declare.h" diff --git a/components/ble/ble_stack/services/ble_tp_svc.c b/components/ble/ble_stack/services/ble_tp_svc.c index 4f27a55b..a067a4e4 100644 --- a/components/ble/ble_stack/services/ble_tp_svc.c +++ b/components/ble/ble_stack/services/ble_tp_svc.c @@ -18,12 +18,15 @@ NOTES #include "bluetooth.h" #include "conn.h" +#include "conn_internal.h" #include "gatt.h" #include "hci_core.h" #include "uuid.h" #include "ble_tp_svc.h" #include "log.h" +#define TP_PRIO configMAX_PRIORITIES - 5 + static void ble_tp_connected(struct bt_conn *conn, u8_t err); static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason); @@ -50,9 +53,9 @@ static void ble_tp_tx_mtu_size(struct bt_conn *conn, u8_t err, { if (!err) { tx_mtu_size = bt_gatt_get_mtu(ble_tp_conn); - BT_WARN("ble tp echange mtu size success, mtu size: %d\n", tx_mtu_size); + BT_WARN("ble tp echange mtu size success, mtu size: %d", tx_mtu_size); } else { - BT_WARN("ble tp echange mtu size failure, err: %d\n", err); + BT_WARN("ble tp echange mtu size failure, err: %d", err); } } @@ -62,20 +65,21 @@ NAME */ static void ble_tp_connected(struct bt_conn *conn, u8_t err) { + if (err || conn->type != BT_CONN_TYPE_LE) { + return; + } + int tx_octets = 0x00fb; int tx_time = 0x0848; int ret = -1; - if (err) - return; - - printf("%s\n", __func__); + BT_INFO("%s", __func__); ble_tp_conn = conn; //set data length after connected. ret = bt_le_set_data_len(ble_tp_conn, tx_octets, tx_time); if (!ret) { - BT_WARN("ble tp set data length success.\n"); + BT_WARN("ble tp set data length success."); } else { BT_WARN("ble tp set data length failure, err: %d\n", ret); } @@ -84,9 +88,9 @@ static void ble_tp_connected(struct bt_conn *conn, u8_t err) exchg_mtu.func = ble_tp_tx_mtu_size; ret = bt_gatt_exchange_mtu(ble_tp_conn, &exchg_mtu); if (!ret) { - BT_WARN("ble tp exchange mtu size pending.\n"); + BT_WARN("ble tp exchange mtu size pending."); } else { - BT_WARN("ble tp exchange mtu size failure, err: %d\n", ret); + BT_WARN("ble tp exchange mtu size failure, err: %d", ret); } } @@ -96,7 +100,11 @@ NAME */ static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason) { - BT_WARN("%s\n", __func__); + if (conn->type != BT_CONN_TYPE_LE) { + return; + } + + BT_INFO("%s", __func__); ble_tp_conn = NULL; } @@ -123,20 +131,20 @@ NAME static int ble_tp_recv_wr(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, u16_t len, u16_t offset, u8_t flags) { - BT_INFO("recv data len=%d, offset=%d, flag=%d\r\n", len, offset, flags); + BT_INFO("recv data len=%d, offset=%d, flag=%d", len, offset, flags); if (flags & BT_GATT_WRITE_FLAG_PREPARE) { //Don't use prepare write data, execute write will upload data again. - BT_WARN("rcv prepare write request\n"); + BT_INFO("rcv prepare write request"); return 0; } if (flags & BT_GATT_WRITE_FLAG_CMD) { //Use write command data. - BT_INFO("rcv write command\n"); + BT_INFO("rcv write command"); } else { //Use write request / execute write data. - BT_INFO("rcv write request / exce write\n"); + BT_INFO("rcv write request / exce write"); } return len; @@ -148,7 +156,7 @@ NAME */ void indicate_rsp(struct bt_conn *conn, const struct bt_gatt_attr *attr, u8_t err) { - BT_WARN("receive confirm, err:%d\n", err); + BT_INFO("receive confirm, err:%d", err); } static int bl_tp_send_indicate(struct bt_conn *conn, const struct bt_gatt_attr *attr, @@ -176,7 +184,7 @@ static void ble_tp_ind_ccc_changed(const struct bt_gatt_attr *attr, u16_t value) if (value == BT_GATT_CCC_INDICATE) { err = bl_tp_send_indicate(ble_tp_conn, get_attr(BT_CHAR_BLE_TP_IND_ATTR_VAL_INDEX), data, 9); - BT_WARN("ble tp send indatcate: %d\n", err); + BT_INFO("ble tp send indatcate: %d", err); } } @@ -191,7 +199,7 @@ static void ble_tp_notify_task(void *pvParameters) while (1) { err = bt_gatt_notify(ble_tp_conn, get_attr(BT_CHAR_BLE_TP_NOT_ATTR_VAL_INDEX), data, (tx_mtu_size - 3)); - BT_WARN("ble tp send notify : %d\n", err); + BT_INFO("ble tp send notify : %d", err); } } @@ -201,27 +209,27 @@ NAME */ static void ble_tp_not_ccc_changed(const struct bt_gatt_attr *attr, u16_t value) { - BT_WARN("ccc:value=[%d]\r\n", value); + BT_INFO("ccc:value=[%d]", value); if (tp_start) { if (value == BT_GATT_CCC_NOTIFY) { - if (xTaskCreate(ble_tp_notify_task, (char *)"bletp", 256, NULL, 15, &ble_tp_task_h) == pdPASS) { + if (xTaskCreate(ble_tp_notify_task, (char *)"bletp", 256, NULL, TP_PRIO, &ble_tp_task_h) == pdPASS) { created_tp_task = 1; - BT_WARN("Create throughput tx task success .\n"); + BT_WARN("Create throughput tx task success."); } else { created_tp_task = 0; - BT_WARN("Create throughput tx taskfail .\n"); + BT_WARN("Create throughput tx task fail."); } } else { if (created_tp_task) { - BT_WARN("Delete throughput tx task .\n"); + BT_WARN("Delete throughput tx task."); vTaskDelete(ble_tp_task_h); created_tp_task = 0; } } - } else if (tp_start == 0) { + } else { if (created_tp_task) { - BT_WARN("Delete throughput tx task .\n"); + BT_WARN("Delete throughput tx task."); vTaskDelete(ble_tp_task_h); created_tp_task = 0; } diff --git a/components/ble/ble_stack/services/oad/oad_main.c b/components/ble/ble_stack/services/oad/oad_main.c index d324eddb..3758b4ee 100644 --- a/components/ble/ble_stack/services/oad/oad_main.c +++ b/components/ble/ble_stack/services/oad/oad_main.c @@ -179,7 +179,7 @@ void ota_finish(struct k_work *work) #endif #if defined(CONFIG_BL_MCU_SDK) - GLB_SW_System_Reset(); + GLB_SW_POR_Reset(); #else hal_reboot(); #endif diff --git a/components/ble/blecontroller/ble_inc/ble_lib_api.h b/components/ble/blecontroller/ble_inc/ble_lib_api.h index 948d34eb..638e20c3 100644 --- a/components/ble/blecontroller/ble_inc/ble_lib_api.h +++ b/components/ble/blecontroller/ble_inc/ble_lib_api.h @@ -6,6 +6,9 @@ void ble_controller_init(uint8_t task_priority); void ble_controller_deinit(void); +#if !defined(CFG_FREERTOS) && !defined(CFG_AOS) +void blecontroller_main(void); +#endif #if defined(CFG_BT_RESET) void ble_controller_reset(void); #endif @@ -74,6 +77,7 @@ int le_rx_test_cmd_handler(uint16_t src_id, void *param, bool from_hci); int le_tx_test_cmd_handler(uint16_t src_id, void *param, bool from_hci); int le_test_end_cmd_handler(bool from_hci); uint8_t le_get_direct_test_type(void); +void le_test_mode_custom_aa(uint32_t access_code); #if defined(CONFIG_BLE_MFG_HCI_CMD) int reset_cmd_handler(void); diff --git a/components/ble/blecontroller/lib/libblecontroller.a b/components/ble/blecontroller/lib/libblecontroller.a deleted file mode 100644 index 3864f499..00000000 Binary files a/components/ble/blecontroller/lib/libblecontroller.a and /dev/null differ diff --git a/components/ble/blecontroller/lib/libblecontroller_702_m0s1.a b/components/ble/blecontroller/lib/libblecontroller_702_m0s1.a index 8e6d38a4..7b9fdff9 100644 Binary files a/components/ble/blecontroller/lib/libblecontroller_702_m0s1.a and b/components/ble/blecontroller/lib/libblecontroller_702_m0s1.a differ diff --git a/components/ble/blecontroller/lib/libblecontroller_702_m0s1p.a b/components/ble/blecontroller/lib/libblecontroller_702_m0s1p.a index 785fd49c..0237e0df 100644 Binary files a/components/ble/blecontroller/lib/libblecontroller_702_m0s1p.a and b/components/ble/blecontroller/lib/libblecontroller_702_m0s1p.a differ diff --git a/components/ble/blecontroller/lib/libblecontroller_702_m0s1s.a b/components/ble/blecontroller/lib/libblecontroller_702_m0s1s.a index 8127fefd..bfdd966f 100644 Binary files a/components/ble/blecontroller/lib/libblecontroller_702_m0s1s.a and b/components/ble/blecontroller/lib/libblecontroller_702_m0s1s.a differ diff --git a/components/ble/blecontroller/lib/libblecontroller_702_std.a b/components/ble/blecontroller/lib/libblecontroller_702_std.a index 7faebca0..3902fdcb 100644 Binary files a/components/ble/blecontroller/lib/libblecontroller_702_std.a and b/components/ble/blecontroller/lib/libblecontroller_702_std.a differ diff --git a/examples/ble/bl_irq.c b/examples/ble/bl_irq.c new file mode 100644 index 00000000..6834a2b0 --- /dev/null +++ b/examples/ble/bl_irq.c @@ -0,0 +1,46 @@ +#include "bl_irq.h" + + +extern pFunc __Interrupt_Handlers[IRQn_LAST]; + + +void bl_irq_enable(unsigned int source) +{ + *(volatile uint8_t*)(CLIC_HART0_ADDR + CLIC_INTIE + source) = 1; +} + +void bl_irq_disable(unsigned int source) +{ + *(volatile uint8_t*)(CLIC_HART0_ADDR + CLIC_INTIE + source) = 0; +} + +void bl_irq_pending_set(unsigned int source) +{ + *(volatile uint8_t*)(CLIC_HART0_ADDR + CLIC_INTIP + source) = 1; +} + +void bl_irq_pending_clear(unsigned int source) +{ + *(volatile uint8_t*)(CLIC_HART0_ADDR + CLIC_INTIP + source) = 0; +} + +void bl_irq_register(int irqnum, void *handler) +{ + if(irqnum + @@ -503,200 +504,6 @@ Board: bl70x_iot 100:8;100:8;100:8;100:8; - - - - - no - 0x23000000 - 0x100000 - - - no - 0x22014000 - 0x4000 - - - no - 0x42018000 - 0x8000 - - - no - - - - - no - - - - - - - yes - 0x42020000 - 0xc000 - yes - - - no - - - yes - - - no - - - yes - - - no - - - yes - - - no - - - yes - - - rv32imafc - yes - little - no - no - no - no - - - $(ProjectName) - Executable - no - yes - no - yes - no - yes - - - - no - - - - no - - - - no - $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" - - - - ARCH_RISCV;BFLB_USE_HAL_DRIVER;CFG_FREERTOS;BL702;CFG_BLE_ENABLE;BFLB_BLE;CFG_BLE;CFG_SLEEP;OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER;BL_MCU_SDK;CFG_CON=2;CFG_BLE_TX_BUFF_DATA=2;CONFIG_BT_ALLROLES;CONFIG_BT_CENTRAL;CONFIG_BT_OBSERVER;CONFIG_BT_PERIPHERAL;CONFIG_BT_BROADCASTER;CONFIG_BT_L2CAP_DYNAMIC_CHANNEL;CONFIG_BT_GATT_CLIENT;CONFIG_BT_CONN;CONFIG_BT_GATT_DIS_PNP;CONFIG_BT_GATT_DIS_SERIAL_NUMBER;CONFIG_BT_GATT_DIS_FW_REV;CONFIG_BT_GATT_DIS_HW_REV;CONFIG_BT_GATT_DIS_SW_REV;CONFIG_BT_ECC;CONFIG_BT_GATT_DYNAMIC_DB;CONFIG_BT_GATT_SERVICE_CHANGED;CONFIG_BT_KEYS_OVERWRITE_OLDEST;CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING;CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS;CONFIG_BT_BONDABLE;CONFIG_BT_HCI_VS_EVT_USER;CONFIG_BT_ASSERT;CONFIG_BT_SMP;CONFIG_BT_SIGNING;CONFIG_BT_SETTINGS_CCC_LAZY_LOADING;CONFIG_BT_SETTINGS_USE_PRINTK;CFG_BLE_STACK_DBG_PRINT;bl706_iot;MBEDTLS_CONFIG_FILE=\"mbedtls_bflb_config.h\" - - Optimize more (-O2) - Default (-g) - $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/include;$(ProjectPath)../../../../components/freertos/portable/gcc/risc-v/bl702;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/ble/ble_stack/bl_hci_wrapper;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../components/mbedtls/library;$(ProjectPath)../../../../components/mbedtls/include/psa;$(ProjectPath)../../../../components/mbedtls/include;$(ProjectPath)../../../../components/mbedtls/bflb_port/inc; - -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -Wignored-qualifiers -Wunused -Wundef -msmall-data-limit=4 -std=c99 - no - no - no - no - no - no - yes - no - yes - no - no - - - portasmHANDLE_INTERRUPT=FreeRTOS_Interrupt_Handler; - - $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/include;$(ProjectPath)../../../../components/freertos/portable/gcc/risc-v/bl702;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/ble/ble_stack/bl_hci_wrapper;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc - - gdwarf2 - - - yes - yes - $(ProjectPath)/../../bl702_flash_ble.ld - blecontroller;bl702_rf;c; - $(ProjectPath)../../../../components/ble/bl702_rf/lib;$(ProjectPath)../../../../components/ble/blecontroller/lib; - --specs=nano.specs - no - - - - yes - OpenOCD - yes - main - - $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init - yes - Hard Reset - 23000000 - no - - no - $(ProjectPath)/$(ProjectName).cdkcore - - localhost - 1025 - 0 - 2000 - 10 - 50 - yes - no - no - Normal - Hard Reset - 21000000 - Bare Metal - yes - yes - - Local - -arch riscv - - - - - yes - no - no - - - openocd-hifive - no - 4444 - no - 6666 - -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg - 5000 - - - - - Erase Sectors - bl70x_flasher.elf - yes - yes - no - Hard Reset - - no - $(ProjectPath)/../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe - --chipname=bl702 --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" - - @@ -820,7 +627,7 @@ Board: bl70x_iot yes yes $(ProjectPath)/../../bl702_flash_ble.ld - blecontroller;bl702_rf;c; + blecontroller_702_std;bl702_rf;c; $(ProjectPath)../../../../components/ble/bl702_rf/lib;$(ProjectPath)../../../../components/ble/blecontroller/lib; --specs=nano.specs no @@ -891,5 +698,199 @@ Board: bl70x_iot --chipname=bl702 --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + + no + 0x23000000 + 0x100000 + + + no + 0x22014000 + 0x4000 + + + no + 0x42018000 + 0x8000 + + + no + + + + + no + + + + + + + yes + 0x42020000 + 0xc000 + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + rv32imafc + yes + little + no + no + no + no + + + $(ProjectName) + Executable + no + yes + no + yes + no + yes + + + + no + + + + no + + + + no + $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + ARCH_RISCV;BFLB_USE_HAL_DRIVER;CFG_FREERTOS;BL702;CFG_BLE_ENABLE;BFLB_BLE;CFG_BLE;CFG_SLEEP;OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER;BL_MCU_SDK;CFG_CON=2;CFG_BLE_TX_BUFF_DATA=2;CONFIG_BT_ALLROLES;CONFIG_BT_CENTRAL;CONFIG_BT_OBSERVER;CONFIG_BT_PERIPHERAL;CONFIG_BT_BROADCASTER;CONFIG_BT_L2CAP_DYNAMIC_CHANNEL;CONFIG_BT_GATT_CLIENT;CONFIG_BT_CONN;CONFIG_BT_GATT_DIS_PNP;CONFIG_BT_GATT_DIS_SERIAL_NUMBER;CONFIG_BT_GATT_DIS_FW_REV;CONFIG_BT_GATT_DIS_HW_REV;CONFIG_BT_GATT_DIS_SW_REV;CONFIG_BT_ECC;CONFIG_BT_GATT_DYNAMIC_DB;CONFIG_BT_GATT_SERVICE_CHANGED;CONFIG_BT_KEYS_OVERWRITE_OLDEST;CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING;CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS;CONFIG_BT_BONDABLE;CONFIG_BT_HCI_VS_EVT_USER;CONFIG_BT_ASSERT;CONFIG_BT_SMP;CONFIG_BT_SIGNING;CONFIG_BT_SETTINGS_CCC_LAZY_LOADING;CONFIG_BT_SETTINGS_USE_PRINTK;CFG_BLE_STACK_DBG_PRINT;bl706_iot;MBEDTLS_CONFIG_FILE=\"mbedtls_bflb_config.h\" + + Optimize more (-O2) + Default (-g) + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/include;$(ProjectPath)../../../../components/freertos/portable/gcc/risc-v/bl702;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/ble/ble_stack/bl_hci_wrapper;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../components/mbedtls/library;$(ProjectPath)../../../../components/mbedtls/include/psa;$(ProjectPath)../../../../components/mbedtls/include;$(ProjectPath)../../../../components/mbedtls/bflb_port/inc; + -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -Wignored-qualifiers -Wunused -Wundef -msmall-data-limit=4 -std=c99 + no + no + no + no + no + no + yes + no + yes + no + no + + + portasmHANDLE_INTERRUPT=FreeRTOS_Interrupt_Handler; + + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/include;$(ProjectPath)../../../../components/freertos/portable/gcc/risc-v/bl702;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/ble/ble_stack/bl_hci_wrapper;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc + + gdwarf2 + + + yes + yes + $(ProjectPath)/../../bl702_flash_ble.ld + blecontroller_702_std;bl702_rf;c; + $(ProjectPath)../../../../components/ble/bl702_rf/lib;$(ProjectPath)../../../../components/ble/blecontroller/lib; + --specs=nano.specs + no + + + + yes + OpenOCD + yes + main + + $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init + yes + Hard Reset + 23000000 + no + + no + $(ProjectPath)/$(ProjectName).cdkcore + + localhost + 1025 + 0 + 2000 + 10 + 50 + yes + no + no + Normal + Hard Reset + 21000000 + Bare Metal + yes + yes + + Local + -arch riscv + + + + + yes + no + no + + + openocd-hifive + no + 4444 + no + 6666 + -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg + 5000 + + + + + Erase Sectors + bl70x_flasher.elf + yes + yes + no + Hard Reset + + no + $(ProjectPath)/../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe + --chipname=bl702 --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + diff --git a/examples/ble/ble_central/readme.md b/examples/ble/ble_central/readme.md index 2bf75df7..29385ddc 100644 --- a/examples/ble/ble_central/readme.md +++ b/examples/ble/ble_central/readme.md @@ -1,3 +1,5 @@ +请使用 10.2 版本以上 T-head 工具链编译该 demo + ```bash $ make APP=ble_central BOARD=bl706_iot SUPPORT_FLOAT=y diff --git a/examples/ble/ble_pds/CMakeLists.txt b/examples/ble/ble_pds/CMakeLists.txt index 76065381..3112c5ad 100644 --- a/examples/ble/ble_pds/CMakeLists.txt +++ b/examples/ble/ble_pds/CMakeLists.txt @@ -1,5 +1,7 @@ set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common) -set(TARGET_REQUIRED_SRCS ${CMAKE_CURRENT_LIST_DIR}/ble_peripheral_tp_server.c) +set(TARGET_REQUIRED_SRCS + ${CMAKE_CURRENT_LIST_DIR}/ble_peripheral_tp_server.c + ${CMAKE_CURRENT_LIST_DIR}/../bl_irq.c) set(TARGET_REQUIRED_LIBS freertos ble mbedtls) set(mains main.c) set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/examples/ble/bl702_flash_ble_pds.ld) diff --git a/examples/ble/ble_pds/readme.md b/examples/ble/ble_pds/readme.md new file mode 100644 index 00000000..fad104ac --- /dev/null +++ b/examples/ble/ble_pds/readme.md @@ -0,0 +1,7 @@ +请使用 10.2 版本以上 T-head 工具链编译该 demo + +```bash + +$ make APP=ble_pds BOARD=bl706_iot SUPPORT_FLOAT=y + +``` \ No newline at end of file diff --git a/examples/ble/ble_peripheral/CMakeLists.txt b/examples/ble/ble_peripheral/CMakeLists.txt index dfb68bba..412f4885 100644 --- a/examples/ble/ble_peripheral/CMakeLists.txt +++ b/examples/ble/ble_peripheral/CMakeLists.txt @@ -1,5 +1,7 @@ set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common) -set(TARGET_REQUIRED_SRCS ${CMAKE_CURRENT_LIST_DIR}/ble_peripheral_tp_server.c) +set(TARGET_REQUIRED_SRCS + ${CMAKE_CURRENT_LIST_DIR}/ble_peripheral_tp_server.c + ${CMAKE_CURRENT_LIST_DIR}/../bl_irq.c) set(TARGET_REQUIRED_LIBS freertos ble mbedtls) set(mains main.c) set(LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/../bl702_flash_ble.ld) diff --git a/examples/ble/ble_peripheral/cdk/ble_peripheral.cdkproj b/examples/ble/ble_peripheral/cdk/ble_peripheral.cdkproj index 15979cfd..2e497428 100644 --- a/examples/ble/ble_peripheral/cdk/ble_peripheral.cdkproj +++ b/examples/ble/ble_peripheral/cdk/ble_peripheral.cdkproj @@ -12,6 +12,7 @@ Board: bl70x_iot + @@ -503,200 +504,6 @@ Board: bl70x_iot 100:8;100:8;100:8;100:8; - - - - - no - 0x23000000 - 0x100000 - - - no - 0x22014000 - 0x4000 - - - no - 0x42018000 - 0x8000 - - - no - - - - - no - - - - - - - yes - 0x42020000 - 0xc000 - yes - - - no - - - yes - - - no - - - yes - - - no - - - yes - - - no - - - yes - - - rv32imafc - yes - little - no - no - no - no - - - $(ProjectName) - Executable - no - yes - no - yes - no - yes - - - - no - - - - no - - - - no - $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" - - - - ARCH_RISCV;BFLB_USE_HAL_DRIVER;CFG_FREERTOS;BL702;CFG_BLE_ENABLE;BFLB_BLE;CFG_BLE;CFG_SLEEP;OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER;BL_MCU_SDK;CFG_CON=2;CFG_BLE_TX_BUFF_DATA=2;CONFIG_BT_ALLROLES;CONFIG_BT_CENTRAL;CONFIG_BT_OBSERVER;CONFIG_BT_PERIPHERAL;CONFIG_BT_BROADCASTER;CONFIG_BT_L2CAP_DYNAMIC_CHANNEL;CONFIG_BT_GATT_CLIENT;CONFIG_BT_CONN;CONFIG_BT_GATT_DIS_PNP;CONFIG_BT_GATT_DIS_SERIAL_NUMBER;CONFIG_BT_GATT_DIS_FW_REV;CONFIG_BT_GATT_DIS_HW_REV;CONFIG_BT_GATT_DIS_SW_REV;CONFIG_BT_ECC;CONFIG_BT_GATT_DYNAMIC_DB;CONFIG_BT_GATT_SERVICE_CHANGED;CONFIG_BT_KEYS_OVERWRITE_OLDEST;CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING;CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS;CONFIG_BT_BONDABLE;CONFIG_BT_HCI_VS_EVT_USER;CONFIG_BT_ASSERT;CONFIG_BT_SMP;CONFIG_BT_SIGNING;CONFIG_BT_SETTINGS_CCC_LAZY_LOADING;CONFIG_BT_SETTINGS_USE_PRINTK;CFG_BLE_STACK_DBG_PRINT;bl706_iot;MBEDTLS_CONFIG_FILE=\"mbedtls_bflb_config.h\" - - Optimize more (-O2) - Default (-g) - $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/include;$(ProjectPath)../../../../components/freertos/portable/gcc/risc-v/bl702;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/ble/ble_stack/bl_hci_wrapper;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../components/mbedtls/library;$(ProjectPath)../../../../components/mbedtls/include/psa;$(ProjectPath)../../../../components/mbedtls/include;$(ProjectPath)../../../../components/mbedtls/bflb_port/inc - -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -Wignored-qualifiers -Wunused -Wundef -msmall-data-limit=4 -std=c99 - no - no - no - no - no - no - yes - no - yes - no - no - - - portasmHANDLE_INTERRUPT=FreeRTOS_Interrupt_Handler; - - $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/include;$(ProjectPath)../../../../components/freertos/portable/gcc/risc-v/bl702;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/ble/ble_stack/bl_hci_wrapper;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc - - gdwarf2 - - - yes - yes - $(ProjectPath)/../../bl702_flash_ble.ld - blecontroller;bl702_rf;c; - $(ProjectPath)../../../../components/ble/bl702_rf/lib;$(ProjectPath)../../../../components/ble/blecontroller/lib; - --specs=nano.specs - no - - - - yes - ICE - yes - main - - $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init - yes - Hard Reset - 23000000 - no - - no - $(ProjectPath)/$(ProjectName).cdkcore - - localhost - 1025 - 0 - 2000 - 10 - 50 - yes - no - no - Normal - Hard Reset - 21000000 - Bare Metal - yes - yes - - Local - -arch riscv - - - - - yes - no - no - - - openocd-hifive - no - 4444 - no - 6666 - -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg - 5000 - - - - - Erase Sectors - bl70x_flasher.elf - yes - yes - no - Hard Reset - - no - $(ProjectPath)/../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe - --chipname=bl702 --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" - - @@ -820,7 +627,7 @@ Board: bl70x_iot yes yes $(ProjectPath)/../../bl702_flash_ble.ld - blecontroller;bl702_rf;c; + blecontroller_702_std;bl702_rf;c; $(ProjectPath)../../../../components/ble/bl702_rf/lib;$(ProjectPath)../../../../components/ble/blecontroller/lib; --specs=nano.specs no @@ -891,5 +698,199 @@ Board: bl70x_iot --chipname=bl702 --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + + no + 0x23000000 + 0x100000 + + + no + 0x22014000 + 0x4000 + + + no + 0x42018000 + 0x8000 + + + no + + + + + no + + + + + + + yes + 0x42020000 + 0xc000 + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + rv32imafc + yes + little + no + no + no + no + + + $(ProjectName) + Executable + no + yes + no + yes + no + yes + + + + no + + + + no + + + + no + $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + ARCH_RISCV;BFLB_USE_HAL_DRIVER;CFG_FREERTOS;BL702;CFG_BLE_ENABLE;BFLB_BLE;CFG_BLE;CFG_SLEEP;OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER;BL_MCU_SDK;CFG_CON=2;CFG_BLE_TX_BUFF_DATA=2;CONFIG_BT_ALLROLES;CONFIG_BT_CENTRAL;CONFIG_BT_OBSERVER;CONFIG_BT_PERIPHERAL;CONFIG_BT_BROADCASTER;CONFIG_BT_L2CAP_DYNAMIC_CHANNEL;CONFIG_BT_GATT_CLIENT;CONFIG_BT_CONN;CONFIG_BT_GATT_DIS_PNP;CONFIG_BT_GATT_DIS_SERIAL_NUMBER;CONFIG_BT_GATT_DIS_FW_REV;CONFIG_BT_GATT_DIS_HW_REV;CONFIG_BT_GATT_DIS_SW_REV;CONFIG_BT_ECC;CONFIG_BT_GATT_DYNAMIC_DB;CONFIG_BT_GATT_SERVICE_CHANGED;CONFIG_BT_KEYS_OVERWRITE_OLDEST;CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING;CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS;CONFIG_BT_BONDABLE;CONFIG_BT_HCI_VS_EVT_USER;CONFIG_BT_ASSERT;CONFIG_BT_SMP;CONFIG_BT_SIGNING;CONFIG_BT_SETTINGS_CCC_LAZY_LOADING;CONFIG_BT_SETTINGS_USE_PRINTK;CFG_BLE_STACK_DBG_PRINT;bl706_iot;MBEDTLS_CONFIG_FILE=\"mbedtls_bflb_config.h\" + + Optimize more (-O2) + Default (-g) + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/include;$(ProjectPath)../../../../components/freertos/portable/gcc/risc-v/bl702;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/ble/ble_stack/bl_hci_wrapper;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../components/mbedtls/library;$(ProjectPath)../../../../components/mbedtls/include/psa;$(ProjectPath)../../../../components/mbedtls/include;$(ProjectPath)../../../../components/mbedtls/bflb_port/inc + -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -Wignored-qualifiers -Wunused -Wundef -msmall-data-limit=4 -std=c99 + no + no + no + no + no + no + yes + no + yes + no + no + + + portasmHANDLE_INTERRUPT=FreeRTOS_Interrupt_Handler; + + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/include;$(ProjectPath)../../../../components/freertos/portable/gcc/risc-v/bl702;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/ble/ble_stack/bl_hci_wrapper;$(ProjectPath)../../../../components/ble/ble_stack/cli_cmds;$(ProjectPath)../../../../components/ble/ble_stack/common;$(ProjectPath)../../../../components/ble/ble_stack/common/include;$(ProjectPath)../../../../components/ble/ble_stack/common/include/misc;$(ProjectPath)../../../../components/ble/ble_stack/common/include/toolchain;$(ProjectPath)../../../../components/ble/ble_stack/common/include/zephyr;$(ProjectPath)../../../../components/ble/ble_stack/common/tinycrypt/include/tinycrypt;$(ProjectPath)../../../../components/ble/ble_stack/port/include;$(ProjectPath)../../../../components/ble/ble_stack/hci_onchip;$(ProjectPath)../../../../components/ble/ble_stack/host;$(ProjectPath)../../../../components/ble/ble_stack/include/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/include/drivers/bluetooth;$(ProjectPath)../../../../components/ble/ble_stack/services;$(ProjectPath)../../../../components/ble/blecontroller/ble_inc;$(ProjectPath)../../../../components/ble/ble_stack/services/oad;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl702;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc + + gdwarf2 + + + yes + yes + $(ProjectPath)/../../bl702_flash_ble.ld + blecontroller_702_std;bl702_rf;c; + $(ProjectPath)../../../../components/ble/bl702_rf/lib;$(ProjectPath)../../../../components/ble/blecontroller/lib; + --specs=nano.specs + no + + + + yes + ICE + yes + main + + $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init + yes + Hard Reset + 23000000 + no + + no + $(ProjectPath)/$(ProjectName).cdkcore + + localhost + 1025 + 0 + 2000 + 10 + 50 + yes + no + no + Normal + Hard Reset + 21000000 + Bare Metal + yes + yes + + Local + -arch riscv + + + + + yes + no + no + + + openocd-hifive + no + 4444 + no + 6666 + -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg + 5000 + + + + + Erase Sectors + bl70x_flasher.elf + yes + yes + no + Hard Reset + + no + $(ProjectPath)/../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe + --chipname=bl702 --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + diff --git a/examples/ble/ble_peripheral/main.c b/examples/ble/ble_peripheral/main.c index d78b96b7..30ed9ce3 100644 --- a/examples/ble/ble_peripheral/main.c +++ b/examples/ble/ble_peripheral/main.c @@ -128,18 +128,18 @@ int ble_start_adv(void) { struct bt_le_adv_param adv_param = { //options:3, connectable undirected, adv one time - .options = 3, + .options = (BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_ONE_TIME), .interval_min = BT_GAP_ADV_FAST_INT_MIN_3, .interval_max = BT_GAP_ADV_FAST_INT_MAX_3, }; - char *adv_name = "BL_TEST_01"; // This name must be the same as adv_name in ble_central - struct bt_data adv_data[2] = { + //char *adv_name = "BL_TEST_01"; // This name must be the same as adv_name in ble_central + struct bt_data adv_data[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL)), - BT_DATA(BT_DATA_NAME_COMPLETE, adv_name, strlen(adv_name)), + //BT_DATA(BT_DATA_NAME_COMPLETE, adv_name, strlen(adv_name)), }; - return bt_le_adv_start(&adv_param, adv_data, ARRAY_SIZE(adv_data), &adv_data[1], 1); + return bt_le_adv_start(&adv_param, adv_data, ARRAY_SIZE(adv_data), NULL, 0); } #if defined(CONFIG_BT_OAD_SERVER) diff --git a/examples/ble/ble_peripheral/readme.md b/examples/ble/ble_peripheral/readme.md index de896b7c..6bd86379 100644 --- a/examples/ble/ble_peripheral/readme.md +++ b/examples/ble/ble_peripheral/readme.md @@ -1,3 +1,5 @@ +请使用 10.2 版本以上 T-head 工具链编译该 demo + ```bash $ make APP=ble_peripheral BOARD=bl706_iot SUPPORT_FLOAT=y