]> granicus.if.org Git - esp-idf/commitdiff
Merge branch 'bugfix/xtal_freq_40' into 'master'
authorWu Jian Gang <wujiangang@espressif.com>
Thu, 24 Aug 2017 12:40:22 +0000 (20:40 +0800)
committerWu Jian Gang <wujiangang@espressif.com>
Thu, 24 Aug 2017 12:40:22 +0000 (20:40 +0800)
esp32: by default, set 40MHz crystal frequency

See merge request !1140

238 files changed:
.gitlab-ci.yml
components/bt/bluedroid/api/esp_bt_main.c
components/bt/bluedroid/bta/av/bta_av_aact.c
components/bt/bluedroid/bta/av/bta_av_act.c
components/bt/bluedroid/bta/av/bta_av_api.c
components/bt/bluedroid/bta/av/bta_av_cfg.c
components/bt/bluedroid/bta/av/bta_av_ci.c
components/bt/bluedroid/bta/av/bta_av_main.c
components/bt/bluedroid/bta/dm/bta_dm_act.c
components/bt/bluedroid/bta/dm/bta_dm_api.c
components/bt/bluedroid/bta/dm/bta_dm_ci.c
components/bt/bluedroid/bta/dm/bta_dm_int.h
components/bt/bluedroid/bta/dm/bta_dm_pm.c
components/bt/bluedroid/bta/gatt/bta_gattc_act.c
components/bt/bluedroid/bta/gatt/bta_gattc_api.c
components/bt/bluedroid/bta/gatt/bta_gattc_cache.c
components/bt/bluedroid/bta/gatt/bta_gattc_ci.c
components/bt/bluedroid/bta/gatt/bta_gattc_main.c
components/bt/bluedroid/bta/gatt/bta_gattc_utils.c
components/bt/bluedroid/bta/gatt/bta_gatts_act.c
components/bt/bluedroid/bta/gatt/bta_gatts_api.c
components/bt/bluedroid/bta/gatt/bta_gatts_main.c
components/bt/bluedroid/bta/gatt/bta_gatts_utils.c
components/bt/bluedroid/bta/hh/bta_hh_act.c
components/bt/bluedroid/bta/hh/bta_hh_api.c
components/bt/bluedroid/bta/hh/bta_hh_cfg.c
components/bt/bluedroid/bta/hh/bta_hh_le.c
components/bt/bluedroid/bta/hh/bta_hh_main.c
components/bt/bluedroid/bta/hh/bta_hh_utils.c
components/bt/bluedroid/bta/include/bta_av_co.h
components/bt/bluedroid/bta/include/bta_gattc_int.h
components/bt/bluedroid/bta/include/bta_gatts_int.h
components/bt/bluedroid/bta/include/bta_sys.h
components/bt/bluedroid/bta/include/utl.h
components/bt/bluedroid/bta/sdp/bta_sdp_act.c
components/bt/bluedroid/bta/sdp/bta_sdp_api.c
components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c
components/bt/bluedroid/bta/sdp/bta_sdp_int.h
components/bt/bluedroid/bta/sys/bta_sys_conn.c
components/bt/bluedroid/bta/sys/bta_sys_main.c
components/bt/bluedroid/bta/sys/utl.c
components/bt/bluedroid/btc/core/btc_config.c
components/bt/bluedroid/btc/core/btc_dm.c
components/bt/bluedroid/btc/core/btc_manage.c
components/bt/bluedroid/btc/core/btc_profile_queue.c
components/bt/bluedroid/btc/core/btc_sm.c
components/bt/bluedroid/btc/core/btc_task.c
components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c
components/bt/bluedroid/btc/profile/std/a2dp/bta_av_co.c
components/bt/bluedroid/btc/profile/std/a2dp/btc_avk.c
components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c
components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c
components/bt/bluedroid/btc/profile/std/dis/dis_profile.c
components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c
components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c
components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c
components/bt/bluedroid/btc/profile/std/include/btc_media.h
components/bt/bluedroid/btif/bta_dm_co.c
components/bt/bluedroid/btif/bta_gattc_co.c
components/bt/bluedroid/btif/bta_gatts_co.c
components/bt/bluedroid/gki/gki_buffer.c [deleted file]
components/bt/bluedroid/gki/gki_ulinux.c [deleted file]
components/bt/bluedroid/gki/include/gki.h [deleted file]
components/bt/bluedroid/gki/include/gki_common.h [deleted file]
components/bt/bluedroid/hci/buffer_allocator.c
components/bt/bluedroid/hci/hci_layer.c
components/bt/bluedroid/include/bt_defs.h
components/bt/bluedroid/include/bt_target.h
components/bt/bluedroid/include/bte.h
components/bt/bluedroid/include/gki_target.h [deleted file]
components/bt/bluedroid/main/bte_main.c
components/bt/bluedroid/osi/alarm.c
components/bt/bluedroid/osi/allocator.c
components/bt/bluedroid/osi/fixed_queue.c
components/bt/bluedroid/osi/future.c
components/bt/bluedroid/osi/include/alarm.h
components/bt/bluedroid/osi/include/allocator.h
components/bt/bluedroid/osi/include/fixed_queue.h
components/bt/bluedroid/osi/include/future.h
components/bt/bluedroid/osi/include/list.h
components/bt/bluedroid/osi/include/mutex.h [new file with mode: 0644]
components/bt/bluedroid/osi/include/osi.h
components/bt/bluedroid/osi/include/osi_arch.h [deleted file]
components/bt/bluedroid/osi/include/semaphore.h [moved from components/bt/bluedroid/gki/include/gki_int.h with 54% similarity]
components/bt/bluedroid/osi/list.c
components/bt/bluedroid/osi/mutex.c [new file with mode: 0644]
components/bt/bluedroid/osi/osi.c [new file with mode: 0644]
components/bt/bluedroid/osi/osi_arch.c [deleted file]
components/bt/bluedroid/osi/semaphore.c [new file with mode: 0644]
components/bt/bluedroid/stack/avct/avct_api.c
components/bt/bluedroid/stack/avct/avct_l2c.c
components/bt/bluedroid/stack/avct/avct_lcb.c
components/bt/bluedroid/stack/avct/avct_lcb_act.c
components/bt/bluedroid/stack/avct/include/avct_int.h
components/bt/bluedroid/stack/avdt/avdt_ad.c
components/bt/bluedroid/stack/avdt/avdt_api.c
components/bt/bluedroid/stack/avdt/avdt_ccb.c
components/bt/bluedroid/stack/avdt/avdt_ccb_act.c
components/bt/bluedroid/stack/avdt/avdt_l2c.c
components/bt/bluedroid/stack/avdt/avdt_msg.c
components/bt/bluedroid/stack/avdt/avdt_scb.c
components/bt/bluedroid/stack/avdt/avdt_scb_act.c
components/bt/bluedroid/stack/avdt/include/avdt_int.h
components/bt/bluedroid/stack/avrc/avrc_api.c
components/bt/bluedroid/stack/avrc/avrc_bld_ct.c
components/bt/bluedroid/stack/avrc/avrc_bld_tg.c
components/bt/bluedroid/stack/avrc/avrc_opt.c
components/bt/bluedroid/stack/avrc/avrc_pars_ct.c
components/bt/bluedroid/stack/avrc/avrc_pars_tg.c
components/bt/bluedroid/stack/avrc/avrc_sdp.c
components/bt/bluedroid/stack/avrc/avrc_utils.c
components/bt/bluedroid/stack/btm/btm_acl.c
components/bt/bluedroid/stack/btm/btm_ble.c
components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c
components/bt/bluedroid/stack/btm/btm_ble_batchscan.c
components/bt/bluedroid/stack/btm/btm_ble_bgconn.c
components/bt/bluedroid/stack/btm/btm_ble_gap.c
components/bt/bluedroid/stack/btm/btm_ble_multi_adv.c
components/bt/bluedroid/stack/btm/btm_ble_privacy.c
components/bt/bluedroid/stack/btm/btm_dev.c
components/bt/bluedroid/stack/btm/btm_devctl.c
components/bt/bluedroid/stack/btm/btm_inq.c
components/bt/bluedroid/stack/btm/btm_main.c
components/bt/bluedroid/stack/btm/btm_pm.c
components/bt/bluedroid/stack/btm/btm_sco.c
components/bt/bluedroid/stack/btm/btm_sec.c
components/bt/bluedroid/stack/btu/btu_hcif.c
components/bt/bluedroid/stack/btu/btu_init.c
components/bt/bluedroid/stack/btu/btu_task.c
components/bt/bluedroid/stack/gap/gap_ble.c
components/bt/bluedroid/stack/gap/gap_conn.c
components/bt/bluedroid/stack/gap/include/gap_int.h
components/bt/bluedroid/stack/gatt/att_protocol.c
components/bt/bluedroid/stack/gatt/gatt_api.c
components/bt/bluedroid/stack/gatt/gatt_auth.c
components/bt/bluedroid/stack/gatt/gatt_cl.c
components/bt/bluedroid/stack/gatt/gatt_db.c
components/bt/bluedroid/stack/gatt/gatt_main.c
components/bt/bluedroid/stack/gatt/gatt_sr.c
components/bt/bluedroid/stack/gatt/gatt_utils.c
components/bt/bluedroid/stack/gatt/include/gatt_int.h
components/bt/bluedroid/stack/hcic/hciblecmds.c
components/bt/bluedroid/stack/hcic/hcicmds.c
components/bt/bluedroid/stack/include/btm_ble_api.h
components/bt/bluedroid/stack/include/btm_ble_int.h
components/bt/bluedroid/stack/include/btm_int.h
components/bt/bluedroid/stack/include/btu.h
components/bt/bluedroid/stack/include/l2c_api.h
components/bt/bluedroid/stack/include/l2cdefs.h
components/bt/bluedroid/stack/include/port_ext.h
components/bt/bluedroid/stack/l2cap/include/l2c_int.h
components/bt/bluedroid/stack/l2cap/l2c_api.c
components/bt/bluedroid/stack/l2cap/l2c_csm.c
components/bt/bluedroid/stack/l2cap/l2c_fcr.c
components/bt/bluedroid/stack/l2cap/l2c_link.c
components/bt/bluedroid/stack/l2cap/l2c_main.c
components/bt/bluedroid/stack/l2cap/l2c_ucd.c
components/bt/bluedroid/stack/l2cap/l2c_utils.c
components/bt/bluedroid/stack/l2cap/l2cap_client.c
components/bt/bluedroid/stack/rfcomm/include/port_int.h
components/bt/bluedroid/stack/rfcomm/port_api.c
components/bt/bluedroid/stack/rfcomm/port_rfc.c
components/bt/bluedroid/stack/rfcomm/port_utils.c
components/bt/bluedroid/stack/rfcomm/rfc_l2cap_if.c
components/bt/bluedroid/stack/rfcomm/rfc_mx_fsm.c
components/bt/bluedroid/stack/rfcomm/rfc_port_fsm.c
components/bt/bluedroid/stack/rfcomm/rfc_port_if.c
components/bt/bluedroid/stack/rfcomm/rfc_ts_frames.c
components/bt/bluedroid/stack/rfcomm/rfc_utils.c
components/bt/bluedroid/stack/sdp/include/sdpint.h
components/bt/bluedroid/stack/sdp/sdp_api.c
components/bt/bluedroid/stack/sdp/sdp_db.c
components/bt/bluedroid/stack/sdp/sdp_discovery.c
components/bt/bluedroid/stack/sdp/sdp_main.c
components/bt/bluedroid/stack/sdp/sdp_server.c
components/bt/bluedroid/stack/sdp/sdp_utils.c
components/bt/bluedroid/stack/smp/smp_cmac.c
components/bt/bluedroid/stack/smp/smp_keys.c
components/bt/bluedroid/stack/smp/smp_l2c.c
components/bt/bluedroid/stack/smp/smp_utils.c
components/console/commands.c
components/driver/include/driver/spi_master.h
components/driver/include/driver/touch_pad.h
components/driver/rtc_module.c
components/driver/spi_master.c
components/esp32/Kconfig
components/esp32/component.mk
components/esp32/include/esp_wifi.h
components/esp32/ld/esp32.peripherals.ld
components/ethernet/Kconfig
components/idf_test/integration_test/TestEnvAll.yml
components/idf_test/unit_test/TestEnvAll.yml
components/libsodium/component.mk
components/libsodium/port/crypto_hash_sha256_mbedtls.c [new file with mode: 0644]
components/libsodium/port/crypto_hash_sha512_mbedtls.c [new file with mode: 0644]
components/libsodium/port/randombytes_default.h [moved from components/libsodium/private/randombytes_default.h with 100% similarity]
components/libsodium/port/randombytes_esp32.c [moved from components/libsodium/private/randombytes_esp32.c with 100% similarity]
components/libsodium/port_include/sodium.h [new file with mode: 0644]
components/libsodium/port_include/sodium/crypto_auth.h [new file with mode: 0644]
components/libsodium/port_include/sodium/crypto_auth_hmacsha256.h [new file with mode: 0644]
components/libsodium/port_include/sodium/crypto_auth_hmacsha512.h [new file with mode: 0644]
components/libsodium/port_include/sodium/crypto_auth_hmacsha512256.h [new file with mode: 0644]
components/libsodium/port_include/sodium/crypto_hash_sha256.h [new file with mode: 0644]
components/libsodium/port_include/sodium/crypto_hash_sha512.h [new file with mode: 0644]
components/libsodium/test/component.mk
components/libsodium/test/test_sodium.c
components/lwip/api/api_msg.c
components/mbedtls/port/include/mbedtls/config.h [new file with mode: 0644]
components/nghttp/nghttp2
components/nvs_flash/README.rst
components/nvs_flash/include/nvs.h
components/nvs_flash/include/nvs_flash.h
components/nvs_flash/src/nvs_api.cpp
components/nvs_flash/src/nvs_storage.hpp
components/nvs_flash/src/nvs_test_api.h
components/nvs_flash/test_nvs_host/test_nvs.cpp
components/sdmmc/test/test_sd.c
components/soc/esp32/include/soc/rtc_cntl_struct.h
components/soc/esp32/include/soc/rtc_io_struct.h
components/soc/esp32/include/soc/sens_struct.h [new file with mode: 0644]
docs/Doxyfile
docs/_static/esp-wrover-kit-v2-layout-back.png [new file with mode: 0644]
docs/_static/esp-wrover-kit-v2-layout-front.png [new file with mode: 0644]
docs/api-reference/peripherals/index.rst
docs/api-reference/peripherals/touch_pad.rst [new file with mode: 0644]
docs/get-started/get-started-wrover-kit-v2.rst [new file with mode: 0644]
docs/get-started/get-started-wrover-kit.rst
docs/hw-reference/modules-and-boards.rst
docs/requirements.txt
examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c
examples/peripherals/touch_pad_read/main/tp_read_main.c
examples/system/app_trace_to_host/Makefile [new file with mode: 0644]
examples/system/app_trace_to_host/README.md [new file with mode: 0644]
examples/system/app_trace_to_host/main/Kconfig.projbuild [new file with mode: 0644]
examples/system/app_trace_to_host/main/app_trace_to_host_test.c [new file with mode: 0644]
examples/system/app_trace_to_host/main/component.mk [new file with mode: 0644]
examples/system/app_trace_to_host/sdkconfig.defaults [new file with mode: 0644]
tools/unit-test-app/components/unity/unity_platform.c

index 465a8c7106397875ea8e02b840fdb2e6b3317a58..c4b0ee0c0d28c8f9c404c9a31bb5c607c60d7d7f 100644 (file)
@@ -525,6 +525,18 @@ UT_001_04:
     - ESP32_IDF
     - UT_T1_1
 
+UT_001_05:
+  <<: *unit_test_template
+  tags:
+    - ESP32_IDF
+    - UT_T1_SDMODE
+
+UT_001_06:
+  <<: *unit_test_template
+  tags:
+    - ESP32_IDF
+    - UT_T1_SPIMODE
+
 IT_001_01:
   <<: *test_template
   tags:
index a04f0db5ed6b78ba5dbea0609554fae6342fec26..1f1a42ac8c70595137655a3b0ede00438bf49fe6 100644 (file)
@@ -18,6 +18,7 @@
 #include "btc_main.h"
 #include "bt.h"
 #include "future.h"
+#include "allocator.h"
 
 static bool bd_already_enable = false;
 static bool bd_already_init = false;
index 91def0985bcd811fbb23f1e80b9d6ea8e585671a..c0f0b3398dcf6937a49580312d3b982537ddde63 100644 (file)
@@ -31,7 +31,7 @@
 #include "bt_trace.h"
 #include <string.h>
 
-// #include <cutils/properties.h>
+#include "allocator.h"
 
 #include "bta_av_int.h"
 #include "avdt_api.h"
@@ -387,7 +387,7 @@ static BOOLEAN bta_av_next_getcap(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 
             /* we got a stream; get its capabilities */
             if (p_scb->p_cap == NULL) {
-                p_scb->p_cap = (tAVDT_CFG *) GKI_getbuf(sizeof(tAVDT_CFG));
+                p_scb->p_cap = (tAVDT_CFG *) osi_malloc(sizeof(tAVDT_CFG));
             }
             if (p_scb->p_cap == NULL) {
                 i = p_scb->num_seps;
@@ -441,7 +441,7 @@ static void bta_av_proc_stream_evt(UINT8 handle, BD_ADDR bd_addr, UINT8 event, t
         }
     }
 
-    if (p_scb && (p_msg = (tBTA_AV_STR_MSG *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_STR_MSG) + sec_len))) != NULL) {
+    if (p_scb && (p_msg = (tBTA_AV_STR_MSG *) osi_malloc((UINT16) (sizeof(tBTA_AV_STR_MSG) + sec_len))) != NULL) {
 
         /* copy event data, bd addr, and handle to event message buffer */
         p_msg->hdr.offset = 0;
@@ -574,12 +574,12 @@ void bta_av_stream_data_cback(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, UI
         }
     }
     if (index == BTA_AV_NUM_STRS) { /* cannot find correct handler */
-        GKI_freebuf(p_pkt);
+        osi_free(p_pkt);
         return;
     }
     p_pkt->event = BTA_AV_MEDIA_DATA_EVT;
     p_scb->seps[p_scb->sep_idx].p_app_data_cback(BTA_AV_MEDIA_DATA_EVT, (tBTA_AV_MEDIA *)p_pkt);
-    GKI_freebuf(p_pkt);  /* a copy of packet had been delivered, we free this buffer */
+    osi_free(p_pkt);  /* a copy of packet had been delivered, we free this buffer */
 }
 
 /*******************************************************************************
@@ -694,7 +694,7 @@ static void bta_av_a2d_sdp_cback(BOOLEAN found, tA2D_Service *p_service)
     tBTA_AV_SDP_RES *p_msg;
     tBTA_AV_SCB     *p_scb;
 
-    if ((p_msg = (tBTA_AV_SDP_RES *) GKI_getbuf(sizeof(tBTA_AV_SDP_RES))) != NULL) {
+    if ((p_msg = (tBTA_AV_SDP_RES *) osi_malloc(sizeof(tBTA_AV_SDP_RES))) != NULL) {
         p_msg->hdr.event = (found) ? BTA_AV_SDP_DISC_OK_EVT : BTA_AV_SDP_DISC_FAIL_EVT;
 
         p_scb = bta_av_hndl_to_scb(bta_av_cb.handle);
@@ -957,7 +957,7 @@ void bta_av_do_disc_a2d (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 
     /* allocate discovery database */
     if (p_scb->p_disc_db == NULL) {
-        p_scb->p_disc_db = (tSDP_DISCOVERY_DB *) GKI_getbuf(BTA_AV_DISC_BUF_SIZE);
+        p_scb->p_disc_db = (tSDP_DISCOVERY_DB *) osi_malloc(BTA_AV_DISC_BUF_SIZE);
     }
 
     /* only one A2D find service is active at a time */
@@ -1985,7 +1985,7 @@ void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
         while (!list_is_empty(p_scb->a2d_list)) {
             p_buf = (BT_HDR *)list_front(p_scb->a2d_list);
             list_remove(p_scb->a2d_list, p_buf);
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
         }
 
         /* drop the audio buffers queued in L2CAP */
@@ -2048,7 +2048,7 @@ void bta_av_reconfig (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
     p_scb->num_recfg = 0;
     /* store the new configuration in control block */
     if (p_scb->p_cap == NULL) {
-        p_scb->p_cap = (tAVDT_CFG *) GKI_getbuf(sizeof(tAVDT_CFG));
+        p_scb->p_cap = (tAVDT_CFG *) osi_malloc(sizeof(tAVDT_CFG));
     }
     if ((p_cfg = p_scb->p_cap) == NULL) {
         /* report failure */
@@ -2180,7 +2180,7 @@ void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
                 } else {
                     /* too many buffers in a2d_list, drop it. */
                     bta_av_co_audio_drop(p_scb->hndl);
-                    GKI_freebuf(p_buf);
+                    osi_free(p_buf);
                 }
             }
         }
@@ -2909,7 +2909,7 @@ void bta_av_open_at_inc (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
         p_scb->coll_mask = 0;
         bta_av_set_scb_sst_init (p_scb);
 
-        if ((p_buf = (tBTA_AV_API_OPEN *) GKI_getbuf(sizeof(tBTA_AV_API_OPEN))) != NULL) {
+        if ((p_buf = (tBTA_AV_API_OPEN *) osi_malloc(sizeof(tBTA_AV_API_OPEN))) != NULL) {
             memcpy(p_buf, &(p_scb->open_api), sizeof(tBTA_AV_API_OPEN));
             bta_sys_sendmsg(p_buf);
         }
index e0c7c271dcbdb6992a2519ac1ec8bf7d1920b94f..89195015bd0cd5ea8c2f4a508eb7b87a3924b5f7 100644 (file)
@@ -32,7 +32,7 @@
 #include "avdt_api.h"
 #include "utl.h"
 #include "l2c_api.h"
-// #include "osi/include/list.h"
+#include "allocator.h"
 #include "list.h"
 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
 #include "bta_ar_api.h"
@@ -187,7 +187,7 @@ static void bta_av_avrc_sdp_cback(UINT16 status)
     BT_HDR *p_msg;
     UNUSED(status);
 
-    if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_msg->event = BTA_AV_SDP_AVRC_DISC_EVT;
         bta_sys_sendmsg(p_msg);
     }
@@ -223,7 +223,7 @@ static void bta_av_rc_ctrl_cback(UINT8 handle, UINT8 event, UINT16 result, BD_AD
     }
 
     if (msg_event) {
-        if ((p_msg = (tBTA_AV_RC_CONN_CHG *) GKI_getbuf(sizeof(tBTA_AV_RC_CONN_CHG))) != NULL) {
+        if ((p_msg = (tBTA_AV_RC_CONN_CHG *) osi_malloc(sizeof(tBTA_AV_RC_CONN_CHG))) != NULL) {
             p_msg->hdr.event = msg_event;
             p_msg->handle    = handle;
             if (peer_addr) {
@@ -261,7 +261,7 @@ static void bta_av_rc_msg_cback(UINT8 handle, UINT8 label, UINT8 opcode, tAVRC_M
 
     /* Create a copy of the message */
     tBTA_AV_RC_MSG *p_buf =
-        (tBTA_AV_RC_MSG *)GKI_getbuf((UINT16)(sizeof(tBTA_AV_RC_MSG) + data_len));
+        (tBTA_AV_RC_MSG *)osi_malloc((UINT16)(sizeof(tBTA_AV_RC_MSG) + data_len));
     if (p_buf != NULL) {
         p_buf->hdr.event = BTA_AV_AVRC_MSG_EVT;
         p_buf->handle = handle;
@@ -636,7 +636,7 @@ void bta_av_rc_meta_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
     }
 
     if (do_free) {
-        GKI_freebuf (p_data->api_meta_rsp.p_pkt);
+        osi_free (p_data->api_meta_rsp.p_pkt);
     }
 }
 
@@ -653,7 +653,7 @@ void bta_av_rc_free_rsp (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
 {
     UNUSED(p_cb);
 
-    GKI_freebuf (p_data->api_meta_rsp.p_pkt);
+    osi_free (p_data->api_meta_rsp.p_pkt);
 }
 
 /*******************************************************************************
@@ -1460,7 +1460,7 @@ static void bta_av_acp_sig_timer_cback (TIMER_LIST_ENT *p_tle)
                     p_scb->coll_mask &= ~BTA_AV_COLL_API_CALLED;
 
                     /* BTA_AV_API_OPEN_EVT */
-                    if ((p_buf = (tBTA_AV_API_OPEN *) GKI_getbuf(sizeof(tBTA_AV_API_OPEN))) != NULL) {
+                    if ((p_buf = (tBTA_AV_API_OPEN *) osi_malloc(sizeof(tBTA_AV_API_OPEN))) != NULL) {
                         memcpy(p_buf, &(p_scb->open_api), sizeof(tBTA_AV_API_OPEN));
                         bta_sys_sendmsg(p_buf);
                     }
@@ -1755,7 +1755,7 @@ void bta_av_rc_disc(UINT8 disc)
     if (p_addr) {
         /* allocate discovery database */
         if (p_cb->p_disc_db == NULL) {
-            p_cb->p_disc_db = (tSDP_DISCOVERY_DB *) GKI_getbuf(BTA_AV_DISC_BUF_SIZE);
+            p_cb->p_disc_db = (tSDP_DISCOVERY_DB *) osi_malloc(BTA_AV_DISC_BUF_SIZE);
         }
 
         if (p_cb->p_disc_db) {
@@ -1811,7 +1811,7 @@ void bta_av_dereg_comp(tBTA_AV_DATA *p_data)
                 while (!list_is_empty(p_scb->a2d_list)) {
                     p_buf = (BT_HDR *)list_front(p_scb->a2d_list);
                     list_remove(p_scb->a2d_list, p_buf);
-                    GKI_freebuf(p_buf);
+                    osi_free(p_buf);
                 }
             }
 
index 0da44643d79968004243b8b85eeefb62c7ffd58a..7ea9855d8a9a00d82d111f4d0d4e366cb1fbaa5f 100644 (file)
 #include "bt_target.h"
 #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE)
 
+#include "allocator.h"
 #include "bta_api.h"
 #include "bta_sys.h"
 #include "bta_av_api.h"
 #include "bta_av_int.h"
-#include "gki.h"
 #include <string.h>
 
 /*****************************************************************************
@@ -63,7 +63,7 @@ void BTA_AvEnable(tBTA_SEC sec_mask, tBTA_AV_FEAT features, tBTA_AV_CBACK *p_cba
     /* register with BTA system manager */
     bta_sys_register(BTA_ID_AV, &bta_av_reg);
 
-    if ((p_buf = (tBTA_AV_API_ENABLE *) GKI_getbuf(sizeof(tBTA_AV_API_ENABLE))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_ENABLE *) osi_malloc(sizeof(tBTA_AV_API_ENABLE))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_ENABLE_EVT;
         p_buf->p_cback  = p_cback;
         p_buf->features = features;
@@ -86,7 +86,7 @@ void BTA_AvDisable(void)
     BT_HDR  *p_buf;
 
     bta_sys_deregister(BTA_ID_AV);
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_AV_API_DISABLE_EVT;
         bta_sys_sendmsg(p_buf);
     }
@@ -110,7 +110,7 @@ void BTA_AvRegister(tBTA_AV_CHNL chnl, const char *p_service_name, UINT8 app_id,
     tBTA_AV_API_REG  *p_buf;
 
 
-    if ((p_buf = (tBTA_AV_API_REG *) GKI_getbuf(sizeof(tBTA_AV_API_REG))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_REG *) osi_malloc(sizeof(tBTA_AV_API_REG))) != NULL) {
         p_buf->hdr.layer_specific   = chnl;
         p_buf->hdr.event = BTA_AV_API_REGISTER_EVT;
         if (p_service_name) {
@@ -139,7 +139,7 @@ void BTA_AvDeregister(tBTA_AV_HNDL hndl)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->layer_specific   = hndl;
         p_buf->event = BTA_AV_API_DEREGISTER_EVT;
         bta_sys_sendmsg(p_buf);
@@ -162,7 +162,7 @@ void BTA_AvOpen(BD_ADDR bd_addr, tBTA_AV_HNDL handle, BOOLEAN use_rc, tBTA_SEC s
 {
     tBTA_AV_API_OPEN  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_OPEN *) GKI_getbuf(sizeof(tBTA_AV_API_OPEN))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_OPEN *) osi_malloc(sizeof(tBTA_AV_API_OPEN))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_OPEN_EVT;
         p_buf->hdr.layer_specific   = handle;
         bdcpy(p_buf->bd_addr, bd_addr);
@@ -187,7 +187,7 @@ void BTA_AvClose(tBTA_AV_HNDL handle)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_AV_API_CLOSE_EVT;
         p_buf->layer_specific   = handle;
         bta_sys_sendmsg(p_buf);
@@ -207,7 +207,7 @@ void BTA_AvDisconnect(BD_ADDR bd_addr)
 {
     tBTA_AV_API_DISCNT  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_DISCNT *) GKI_getbuf(sizeof(tBTA_AV_API_DISCNT))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_DISCNT *) osi_malloc(sizeof(tBTA_AV_API_DISCNT))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_DISCONNECT_EVT;
         bdcpy(p_buf->bd_addr, bd_addr);
         bta_sys_sendmsg(p_buf);
@@ -227,7 +227,7 @@ void BTA_AvStart(void)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_AV_API_START_EVT;
         bta_sys_sendmsg(p_buf);
     }
@@ -246,7 +246,7 @@ void BTA_AvEnable_Sink(int enable)
 {
 #if (BTA_AV_SINK_INCLUDED == TRUE)
     BT_HDR  *p_buf;
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_AV_API_SINK_ENABLE_EVT;
         p_buf->layer_specific = enable;
         bta_sys_sendmsg(p_buf);
@@ -271,7 +271,7 @@ void BTA_AvStop(BOOLEAN suspend)
 {
     tBTA_AV_API_STOP  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_STOP *) GKI_getbuf(sizeof(tBTA_AV_API_STOP))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_STOP *) osi_malloc(sizeof(tBTA_AV_API_STOP))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_STOP_EVT;
         p_buf->flush   = TRUE;
         p_buf->suspend = suspend;
@@ -297,7 +297,7 @@ void BTA_AvReconfig(tBTA_AV_HNDL hndl, BOOLEAN suspend, UINT8 sep_info_idx,
 {
     tBTA_AV_API_RCFG  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_RCFG *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_API_RCFG) + num_protect))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_RCFG *) osi_malloc((UINT16) (sizeof(tBTA_AV_API_RCFG) + num_protect))) != NULL) {
         p_buf->hdr.layer_specific   = hndl;
         p_buf->hdr.event    = BTA_AV_API_RECONFIG_EVT;
         p_buf->num_protect  = num_protect;
@@ -324,7 +324,7 @@ void BTA_AvProtectReq(tBTA_AV_HNDL hndl, UINT8 *p_data, UINT16 len)
 {
     tBTA_AV_API_PROTECT_REQ  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_PROTECT_REQ *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_API_PROTECT_REQ) + len))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_PROTECT_REQ *) osi_malloc((UINT16) (sizeof(tBTA_AV_API_PROTECT_REQ) + len))) != NULL) {
         p_buf->hdr.layer_specific   = hndl;
         p_buf->hdr.event = BTA_AV_API_PROTECT_REQ_EVT;
         p_buf->len       = len;
@@ -354,7 +354,7 @@ void BTA_AvProtectRsp(tBTA_AV_HNDL hndl, UINT8 error_code, UINT8 *p_data, UINT16
 {
     tBTA_AV_API_PROTECT_RSP  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_PROTECT_RSP *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_API_PROTECT_RSP) + len))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_PROTECT_RSP *) osi_malloc((UINT16) (sizeof(tBTA_AV_API_PROTECT_RSP) + len))) != NULL) {
         p_buf->hdr.layer_specific   = hndl;
         p_buf->hdr.event    = BTA_AV_API_PROTECT_RSP_EVT;
         p_buf->len          = len;
@@ -383,7 +383,7 @@ void BTA_AvRemoteCmd(UINT8 rc_handle, UINT8 label, tBTA_AV_RC rc_id, tBTA_AV_STA
 {
     tBTA_AV_API_REMOTE_CMD  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_REMOTE_CMD *) GKI_getbuf(sizeof(tBTA_AV_API_REMOTE_CMD))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_REMOTE_CMD *) osi_malloc(sizeof(tBTA_AV_API_REMOTE_CMD))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_REMOTE_CMD_EVT;
         p_buf->hdr.layer_specific   = rc_handle;
         p_buf->msg.op_id = rc_id;
@@ -410,7 +410,7 @@ void BTA_AvVendorCmd(UINT8 rc_handle, UINT8 label, tBTA_AV_CODE cmd_code, UINT8
 {
     tBTA_AV_API_VENDOR  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_VENDOR *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_API_VENDOR) + len))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_VENDOR *) osi_malloc((UINT16) (sizeof(tBTA_AV_API_VENDOR) + len))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_VENDOR_CMD_EVT;
         p_buf->hdr.layer_specific   = rc_handle;
         p_buf->msg.hdr.ctype = cmd_code;
@@ -445,7 +445,7 @@ void BTA_AvVendorRsp(UINT8 rc_handle, UINT8 label, tBTA_AV_CODE rsp_code, UINT8
 {
     tBTA_AV_API_VENDOR  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_VENDOR *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_API_VENDOR) + len))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_VENDOR *) osi_malloc((UINT16) (sizeof(tBTA_AV_API_VENDOR) + len))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_VENDOR_RSP_EVT;
         p_buf->hdr.layer_specific   = rc_handle;
         p_buf->msg.hdr.ctype = rsp_code;
@@ -482,7 +482,7 @@ void BTA_AvOpenRc(tBTA_AV_HNDL handle)
 {
     tBTA_AV_API_OPEN_RC  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_OPEN_RC *) GKI_getbuf(sizeof(tBTA_AV_API_OPEN_RC))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_OPEN_RC *) osi_malloc(sizeof(tBTA_AV_API_OPEN_RC))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_RC_OPEN_EVT;
         p_buf->hdr.layer_specific   = handle;
         bta_sys_sendmsg(p_buf);
@@ -502,7 +502,7 @@ void BTA_AvCloseRc(UINT8 rc_handle)
 {
     tBTA_AV_API_CLOSE_RC  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_CLOSE_RC *) GKI_getbuf(sizeof(tBTA_AV_API_CLOSE_RC))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_CLOSE_RC *) osi_malloc(sizeof(tBTA_AV_API_CLOSE_RC))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_RC_CLOSE_EVT;
         p_buf->hdr.layer_specific   = rc_handle;
         bta_sys_sendmsg(p_buf);
@@ -526,7 +526,7 @@ void BTA_AvMetaRsp(UINT8 rc_handle, UINT8 label, tBTA_AV_CODE rsp_code,
 {
     tBTA_AV_API_META_RSP  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_META_RSP *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_API_META_RSP)))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_META_RSP *) osi_malloc((UINT16) (sizeof(tBTA_AV_API_META_RSP)))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_META_RSP_EVT;
         p_buf->hdr.layer_specific   = rc_handle;
         p_buf->rsp_code = rsp_code;
@@ -536,7 +536,7 @@ void BTA_AvMetaRsp(UINT8 rc_handle, UINT8 label, tBTA_AV_CODE rsp_code,
 
         bta_sys_sendmsg(p_buf);
     } else if (p_pkt) {
-        GKI_freebuf(p_pkt);
+        osi_free(p_pkt);
     }
 }
 
@@ -558,7 +558,7 @@ void BTA_AvMetaCmd(UINT8 rc_handle, UINT8 label, tBTA_AV_CMD cmd_code, BT_HDR *p
 {
     tBTA_AV_API_META_RSP  *p_buf;
 
-    if ((p_buf = (tBTA_AV_API_META_RSP *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_API_META_RSP)))) != NULL) {
+    if ((p_buf = (tBTA_AV_API_META_RSP *) osi_malloc((UINT16) (sizeof(tBTA_AV_API_META_RSP)))) != NULL) {
         p_buf->hdr.event = BTA_AV_API_META_RSP_EVT;
         p_buf->hdr.layer_specific   = rc_handle;
         p_buf->p_pkt = p_pkt;
index d057eee29891b82aa06de90b6eb56f8250a964f5..5774be1d33ae7c2a51e5818c201142aed49341f2 100644 (file)
@@ -26,7 +26,6 @@
 #include <stddef.h>
 
 #include "bt_target.h"
-#include "gki.h"
 #include "bta_api.h"
 #include "bta_av_int.h"
 
index 11a47dc74dbf142b2b7e670466668e9f64a84d6b..8f1426e00c7d9d87c50baf78344bde9a02417298 100644 (file)
@@ -28,6 +28,7 @@
 #include "bta_sys.h"
 #include "bta_av_int.h"
 #include "bta_av_ci.h"
+#include "allocator.h"
 
 #include <string.h>
 
@@ -48,7 +49,7 @@ void bta_av_ci_src_data_ready(tBTA_AV_CHNL chnl)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->layer_specific   = chnl;
         p_buf->event = BTA_AV_CI_SRC_DATA_READY_EVT;
         bta_sys_sendmsg(p_buf);
@@ -73,7 +74,7 @@ void bta_av_ci_setconfig(tBTA_AV_HNDL hndl, UINT8 err_code, UINT8 category,
 {
     tBTA_AV_CI_SETCONFIG  *p_buf;
 
-    if ((p_buf = (tBTA_AV_CI_SETCONFIG *) GKI_getbuf(sizeof(tBTA_AV_CI_SETCONFIG))) != NULL) {
+    if ((p_buf = (tBTA_AV_CI_SETCONFIG *) osi_malloc(sizeof(tBTA_AV_CI_SETCONFIG))) != NULL) {
         p_buf->hdr.layer_specific   = hndl;
         p_buf->hdr.event = (err_code == AVDT_SUCCESS) ?
                            BTA_AV_CI_SETCONFIG_OK_EVT : BTA_AV_CI_SETCONFIG_FAIL_EVT;
index 1d844775c736d3b12a5ade2b9576a7d6b6ea1e8a..5d5f441a63917c000a39ec10c9e2bebbd5f5d39b 100644 (file)
@@ -26,8 +26,8 @@
 #include <string.h>
 
 #include "bt_target.h"
-// #include "osi/include/log.h"
 #include "bt_trace.h"
+#include "allocator.h"
 
 #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE)
 #include "bta_av_int.h"
@@ -224,7 +224,7 @@ static void bta_av_timer_cback(void *p_tle)
         }
     }
 
-    if (p_scb && (p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if (p_scb && (p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         /* send the event through the audio state machine.
          * only when the audio SM is open, the main SM opens the RC connection as INT */
         p_buf->event = p->event;
@@ -356,7 +356,7 @@ static tBTA_AV_SCB *bta_av_alloc_scb(tBTA_AV_CHNL chnl)
         for (xx = 0; xx < BTA_AV_NUM_STRS; xx++) {
             if (bta_av_cb.p_scb[xx] == NULL) {
                 /* found an empty spot */
-                p_ret = (tBTA_AV_SCB *)GKI_getbuf(sizeof(tBTA_AV_SCB));
+                p_ret = (tBTA_AV_SCB *)osi_malloc(sizeof(tBTA_AV_SCB));
                 if (p_ret) {
                     memset(p_ret, 0, sizeof(tBTA_AV_SCB));
                     p_ret->rc_handle = BTA_AV_RC_HANDLE_NONE;
@@ -389,7 +389,7 @@ UNUSED_ATTR static void bta_av_free_scb(tBTA_AV_SCB *p_scb)
     assert(p_scb != NULL);
 
     list_free(p_scb->a2d_list);
-    GKI_freebuf(p_scb);
+    osi_free(p_scb);
 }
 
 /*******************************************************************************
@@ -423,7 +423,7 @@ void bta_av_conn_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p
             //(AVDT_CONNECT_IND_EVT == event && AVDT_ACP == p_data->hdr.err_param))
 
             (AVDT_CONNECT_IND_EVT == event))&& */
-            (p_msg = (tBTA_AV_STR_MSG *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_STR_MSG)))) != NULL) {
+            (p_msg = (tBTA_AV_STR_MSG *) osi_malloc((UINT16) (sizeof(tBTA_AV_STR_MSG)))) != NULL) {
             p_msg->hdr.event = evt;
             p_msg->hdr.layer_specific = event;
             p_msg->hdr.offset = p_data->hdr.err_param;
@@ -891,7 +891,7 @@ static void bta_av_sys_rs_cback (tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 ap
         /* note that more than one SCB (a2dp & vdp) maybe waiting for this event */
         p_scb = bta_av_cb.p_scb[i];
         if (p_scb && (bdcmp (peer_addr, p_scb->peer_addr) == 0) &&
-                (p_buf = (tBTA_AV_ROLE_RES *) GKI_getbuf(sizeof(tBTA_AV_ROLE_RES))) != NULL) {
+                (p_buf = (tBTA_AV_ROLE_RES *) osi_malloc(sizeof(tBTA_AV_ROLE_RES))) != NULL) {
             APPL_TRACE_DEBUG("new_role:%d, hci_status:x%x hndl: x%x\n", id, app_id, p_scb->hndl);
             /*
             if ((id != BTM_ROLE_MASTER) && (app_id != HCI_SUCCESS))
@@ -1128,7 +1128,7 @@ void bta_av_dup_audio_buf(tBTA_AV_SCB *p_scb, BT_HDR *p_buf)
 {
     tBTA_AV_SCB *p_scbi;
     int     i;
-    UINT16  size, copy_size;
+    UINT16  copy_size;
     BT_HDR *p_new;
 
     if (!p_buf) {
@@ -1136,7 +1136,6 @@ void bta_av_dup_audio_buf(tBTA_AV_SCB *p_scb, BT_HDR *p_buf)
     }
 
     if (bta_av_cb.audio_open_cnt >= 2) {
-        size = GKI_get_buf_size(p_buf);
         copy_size = BT_HDR_SIZE + p_buf->len + p_buf->offset;
         /* more than one audio channel is connected */
         for (i = 0; i < BTA_AV_NUM_STRS; i++) {
@@ -1145,7 +1144,7 @@ void bta_av_dup_audio_buf(tBTA_AV_SCB *p_scb, BT_HDR *p_buf)
                     (bta_av_cb.conn_audio & BTA_AV_HNDL_TO_MSK(i)) && /* connected audio */
                     p_scbi && p_scbi->co_started ) { /* scb is used and started */
                 /* enqueue the data only when the stream is started */
-                p_new = (BT_HDR *)GKI_getbuf(size);
+                p_new = (BT_HDR *)osi_malloc(copy_size);
                 if (p_new) {
                     memcpy(p_new, p_buf, copy_size);
                     list_append(p_scbi->a2d_list, p_new);
@@ -1154,7 +1153,7 @@ void bta_av_dup_audio_buf(tBTA_AV_SCB *p_scb, BT_HDR *p_buf)
                         bta_av_co_audio_drop(p_scbi->hndl);
                         BT_HDR *p_buf = list_front(p_scbi->a2d_list);
                         list_remove(p_scbi->a2d_list, p_buf);
-                        GKI_freebuf(p_buf);
+                        osi_free(p_buf);
                     }
                 }
             }
index 49289a9ab47e629f84680a14ab5afa7039cf748d..1ca0b06fe57cec0b9ab0eb46f7ca39699b14824a 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "bt_target.h"
 #include "bt_types.h"
-#include "gki.h"
 #include "bta_sys.h"
 #include "bta_api.h"
 #include "bta_dm_int.h"
@@ -275,7 +274,7 @@ void bta_dm_enable(tBTA_DM_MSG *p_data)
     bta_dm_cb.is_bta_dm_active = TRUE;
 
     /* send a message to BTA SYS */
-    if ((sys_enable_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
+    if ((sys_enable_event = (tBTA_SYS_HW_MSG *) osi_malloc(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
         sys_enable_event->hdr.event = BTA_SYS_API_ENABLE_EVT;
         sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH;
 
@@ -1131,7 +1130,7 @@ void bta_dm_search_start (tBTA_DM_MSG *p_data)
 
     if ((bta_dm_search_cb.num_uuid = p_data->search.num_uuid) != 0 &&
             p_data->search.p_uuid != NULL) {
-        if ((bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)GKI_getbuf(len)) == NULL) {
+        if ((bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)osi_malloc(len)) == NULL) {
             APPL_TRACE_ERROR("%s no resources", __func__);
 
             result.status = BTA_FAILURE;
@@ -1172,7 +1171,7 @@ void bta_dm_search_cancel (tBTA_DM_MSG *p_data)
     if (BTM_IsInquiryActive()) {
         if (BTM_CancelInquiry() != BTM_CMD_STARTED) {
             bta_dm_search_cancel_notify(NULL);
-            p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG));
+            p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG));
             if (p_msg != NULL) {
                 p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
                 p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
@@ -1187,14 +1186,14 @@ void bta_dm_search_cancel (tBTA_DM_MSG *p_data)
     else if (!bta_dm_search_cb.name_discover_done) {
         BTM_CancelRemoteDeviceName();
 
-        if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+        if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
             p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
             p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
             bta_sys_sendmsg(p_msg);
         }
 
     } else {
-        if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+        if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
             p_msg->hdr.event = BTA_DM_INQUIRY_CMPL_EVT;
             p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
             bta_sys_sendmsg(p_msg);
@@ -1235,7 +1234,7 @@ void bta_dm_discover (tBTA_DM_MSG *p_data)
     utl_freebuf((void **)&bta_dm_search_cb.p_srvc_uuid);
     if ((bta_dm_search_cb.num_uuid = p_data->discover.num_uuid) != 0 &&
             p_data->discover.p_uuid != NULL) {
-        if ((bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)GKI_getbuf(len)) == NULL) {
+        if ((bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)osi_malloc(len)) == NULL) {
             p_data->discover.p_cback(BTA_DM_DISC_CMPL_EVT, NULL);
             return;
         }
@@ -1300,7 +1299,7 @@ static void bta_dm_di_disc_callback(UINT16 result)
 {
     tBTA_DM_MSG *p_msg;
 
-    if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+    if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
         p_msg->hdr.event            = BTA_DM_SEARCH_CMPL_EVT;
         p_msg->hdr.layer_specific   = BTA_DM_API_DI_DISCOVER_EVT;
         p_msg->hdr.offset           = result;
@@ -1359,7 +1358,7 @@ void bta_dm_di_disc (tBTA_DM_MSG *p_data)
     bdcpy(bta_dm_search_cb.peer_bdaddr, p_data->di_disc.bd_addr);
     bta_dm_di_cb.p_di_db = p_data->di_disc.p_sdp_db;
 
-    if ((bta_dm_search_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)GKI_getbuf(BTA_DM_SDP_DB_SIZE)) != NULL) {
+    if ((bta_dm_search_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(BTA_DM_SDP_DB_SIZE)) != NULL) {
         if ( SDP_DiDiscover(bta_dm_search_cb.peer_bdaddr, p_data->di_disc.p_sdp_db,
                             p_data->di_disc.len, bta_dm_di_disc_callback) == SDP_SUCCESS) {
             result = BTA_SUCCESS;
@@ -1369,7 +1368,7 @@ void bta_dm_di_disc (tBTA_DM_MSG *p_data)
     }
 
     if ( result == BTA_FAILURE &&
-            (p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+            (p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
         p_msg->hdr.event            = BTA_DM_SEARCH_CMPL_EVT;
         p_msg->hdr.layer_specific   = BTA_DM_API_DI_DISCOVER_EVT;
         p_data->hdr.offset          = result;
@@ -1451,7 +1450,7 @@ void bta_dm_inq_cmpl (tBTA_DM_MSG *p_data)
         /* no devices, search complete */
         bta_dm_search_cb.services = 0;
 
-        if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+        if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
             p_msg->hdr.event          = BTA_DM_SEARCH_CMPL_EVT;
             p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
             bta_sys_sendmsg(p_msg);
@@ -1622,7 +1621,7 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
 
         } while (bta_dm_search_cb.service_index <= BTA_MAX_SERVICE_ID);
 
-//        GKI_freebuf(bta_dm_search_cb.p_sdp_db);
+//        osi_free(bta_dm_search_cb.p_sdp_db);
 //        bta_dm_search_cb.p_sdp_db = NULL;
         APPL_TRACE_DEBUG("%s services_found = %04x", __FUNCTION__,
                          bta_dm_search_cb.services_found);
@@ -1654,7 +1653,7 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
             BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback);
 
 
-            if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+            if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
                 p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
                 p_msg->disc_result.result.disc_res.result = BTA_SUCCESS;
                 p_msg->disc_result.result.disc_res.p_raw_data = NULL;
@@ -1662,7 +1661,7 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
                 p_msg->disc_result.result.disc_res.num_uuids = num_uuids;
                 p_msg->disc_result.result.disc_res.p_uuid_list = NULL;
                 if (num_uuids > 0) {
-                    p_msg->disc_result.result.disc_res.p_uuid_list = (UINT8 *)GKI_getbuf(num_uuids * MAX_UUID_SIZE);
+                    p_msg->disc_result.result.disc_res.p_uuid_list = (UINT8 *)osi_malloc(num_uuids * MAX_UUID_SIZE);
                     if (p_msg->disc_result.result.disc_res.p_uuid_list) {
                         memcpy(p_msg->disc_result.result.disc_res.p_uuid_list, uuid_list,
                                num_uuids * MAX_UUID_SIZE);
@@ -1681,7 +1680,7 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
                         bta_dm_search_cb.p_sdp_db->raw_used,
                         bta_dm_search_cb.p_sdp_db->raw_data);
 
-                    p_msg->disc_result.result.disc_res.p_raw_data = GKI_getbuf(bta_dm_search_cb.p_sdp_db->raw_used);
+                    p_msg->disc_result.result.disc_res.p_raw_data = osi_malloc(bta_dm_search_cb.p_sdp_db->raw_used);
                     if ( NULL != p_msg->disc_result.result.disc_res.p_raw_data  ) {
                         memcpy(     p_msg->disc_result.result.disc_res.p_raw_data,
                                     bta_dm_search_cb.p_sdp_db->raw_data,
@@ -1691,7 +1690,7 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
                             bta_dm_search_cb.p_sdp_db->raw_used;
 
                     } else {
-                        APPL_TRACE_DEBUG("%s GKI Alloc failed to allocate %d bytes !!", __func__,
+                        APPL_TRACE_DEBUG("%s Alloc failed to allocate %d bytes !!", __func__,
                                          bta_dm_search_cb.p_sdp_db->raw_used);
                     }
 
@@ -1731,12 +1730,12 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
         }
 
         /* not able to connect go to next device */
-        GKI_freebuf(bta_dm_search_cb.p_sdp_db);
+        osi_free(bta_dm_search_cb.p_sdp_db);
         bta_dm_search_cb.p_sdp_db = NULL;
 
         BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback);
 
-        if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+        if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
             p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
             p_msg->disc_result.result.disc_res.result = BTA_FAILURE;
             p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found;
@@ -1798,7 +1797,7 @@ void bta_dm_disc_result (tBTA_DM_MSG *p_data)
 #endif
         bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT, &p_data->disc_result.result);
 
-    tBTA_DM_MSG *p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG));
+    tBTA_DM_MSG *p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG));
 
     /* send a message to change state */
     if (p_msg != NULL) {
@@ -1881,7 +1880,7 @@ void bta_dm_free_sdp_db (tBTA_DM_MSG *p_data)
 {
     UNUSED(p_data);
     if (bta_dm_search_cb.p_sdp_db) {
-        GKI_freebuf(bta_dm_search_cb.p_sdp_db);
+        osi_free(bta_dm_search_cb.p_sdp_db);
         bta_dm_search_cb.p_sdp_db = NULL;
     }
 }
@@ -1899,10 +1898,10 @@ void bta_dm_free_sdp_db (tBTA_DM_MSG *p_data)
 void bta_dm_queue_search (tBTA_DM_MSG *p_data)
 {
     if (bta_dm_search_cb.p_search_queue) {
-        GKI_freebuf(bta_dm_search_cb.p_search_queue);
+        osi_free(bta_dm_search_cb.p_search_queue);
     }
 
-    bta_dm_search_cb.p_search_queue = (tBTA_DM_MSG *)GKI_getbuf(sizeof(tBTA_DM_API_SEARCH));
+    bta_dm_search_cb.p_search_queue = (tBTA_DM_MSG *)osi_malloc(sizeof(tBTA_DM_API_SEARCH));
     memcpy(bta_dm_search_cb.p_search_queue, p_data, sizeof(tBTA_DM_API_SEARCH));
 
 }
@@ -1920,10 +1919,10 @@ void bta_dm_queue_search (tBTA_DM_MSG *p_data)
 void bta_dm_queue_disc (tBTA_DM_MSG *p_data)
 {
     if (bta_dm_search_cb.p_search_queue) {
-        GKI_freebuf(bta_dm_search_cb.p_search_queue);
+        osi_free(bta_dm_search_cb.p_search_queue);
     }
 
-    bta_dm_search_cb.p_search_queue = (tBTA_DM_MSG *)GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER));
+    bta_dm_search_cb.p_search_queue = (tBTA_DM_MSG *)osi_malloc(sizeof(tBTA_DM_API_DISCOVER));
     memcpy(bta_dm_search_cb.p_search_queue, p_data, sizeof(tBTA_DM_API_DISCOVER));
 }
 #endif  ///SDP_INCLUDED == TRUE
@@ -1941,7 +1940,7 @@ void bta_dm_search_clear_queue (tBTA_DM_MSG *p_data)
 {
     UNUSED(p_data);
     if (bta_dm_search_cb.p_search_queue) {
-        GKI_freebuf(bta_dm_search_cb.p_search_queue);
+        osi_free(bta_dm_search_cb.p_search_queue);
         bta_dm_search_cb.p_search_queue = NULL;
     }
 }
@@ -1980,7 +1979,7 @@ void bta_dm_search_cancel_transac_cmpl(tBTA_DM_MSG *p_data)
 {
     UNUSED(p_data);
     if (bta_dm_search_cb.p_sdp_db) {
-        GKI_freebuf(bta_dm_search_cb.p_sdp_db);
+        osi_free(bta_dm_search_cb.p_sdp_db);
         bta_dm_search_cb.p_sdp_db = NULL;
     }
 
@@ -2035,7 +2034,7 @@ static void bta_dm_find_services ( BD_ADDR bd_addr)
     while (bta_dm_search_cb.service_index < BTA_MAX_SERVICE_ID) {
         if ( bta_dm_search_cb.services_to_search
                 & (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index))) {
-            if ((bta_dm_search_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)GKI_getbuf(BTA_DM_SDP_DB_SIZE)) != NULL) {
+            if ((bta_dm_search_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(BTA_DM_SDP_DB_SIZE)) != NULL) {
                 APPL_TRACE_DEBUG("bta_dm_search_cb.services = %04x***********", bta_dm_search_cb.services);
                 /* try to search all services by search based on L2CAP UUID */
                 if (bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK ) {
@@ -2096,7 +2095,7 @@ static void bta_dm_find_services ( BD_ADDR bd_addr)
                 if (!SDP_ServiceSearchAttributeRequest (bd_addr, bta_dm_search_cb.p_sdp_db, &bta_dm_sdp_callback)) {
                     /* if discovery not successful with this device
                     proceed to next one */
-                    GKI_freebuf(bta_dm_search_cb.p_sdp_db);
+                    osi_free(bta_dm_search_cb.p_sdp_db);
                     bta_dm_search_cb.p_sdp_db = NULL;
                     bta_dm_search_cb.service_index = BTA_MAX_SERVICE_ID;
 
@@ -2119,7 +2118,7 @@ static void bta_dm_find_services ( BD_ADDR bd_addr)
 
     /* no more services to be discovered */
     if (bta_dm_search_cb.service_index >= BTA_MAX_SERVICE_ID) {
-        if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+        if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
             p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
             p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found;
             bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
@@ -2162,7 +2161,7 @@ static void bta_dm_discover_next_device(void)
         /* no devices, search complete */
         bta_dm_search_cb.services = 0;
 
-        if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+        if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
             p_msg->hdr.event          = BTA_DM_SEARCH_CMPL_EVT;
             p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
             bta_sys_sendmsg(p_msg);
@@ -2302,7 +2301,7 @@ static void bta_dm_discover_device(BD_ADDR remote_bd_addr)
     }
 
     /* name discovery and service discovery are done for this device */
-    if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+    if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
         p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
         /* initialize the data structure - includes p_raw_data and raw_data_size */
         memset(&(p_msg->disc_result.result), 0, sizeof(tBTA_DM_DISC_RES));
@@ -2333,7 +2332,7 @@ static void bta_dm_sdp_callback (UINT16 sdp_status)
 
     tBTA_DM_SDP_RESULT *p_msg;
 
-    if ((p_msg = (tBTA_DM_SDP_RESULT *) GKI_getbuf(sizeof(tBTA_DM_SDP_RESULT))) != NULL) {
+    if ((p_msg = (tBTA_DM_SDP_RESULT *) osi_malloc(sizeof(tBTA_DM_SDP_RESULT))) != NULL) {
         p_msg->hdr.event = BTA_DM_SDP_RESULT_EVT;
         p_msg->sdp_result = sdp_status;
         bta_sys_sendmsg(p_msg);
@@ -2411,7 +2410,7 @@ static void bta_dm_inq_cmpl_cb (void *p_result)
 
     if (bta_dm_search_cb.cancel_pending == FALSE) {
         APPL_TRACE_DEBUG("%s", __FUNCTION__);
-        p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG));
+        p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG));
         if (p_msg != NULL) {
             p_msg->inq_cmpl.hdr.event = BTA_DM_INQUIRY_CMPL_EVT;
             p_msg->inq_cmpl.num = ((tBTM_INQUIRY_CMPL *)p_result)->num_resp;
@@ -2421,7 +2420,7 @@ static void bta_dm_inq_cmpl_cb (void *p_result)
         bta_dm_search_cb.cancel_pending = FALSE;
         bta_dm_search_cancel_notify(NULL);
 
-        p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG));
+        p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG));
         if (p_msg != NULL) {
             p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
             p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
@@ -2508,7 +2507,7 @@ static void bta_dm_remname_cback (tBTM_REMOTE_DEV_NAME *p_remote_name)
     }
 #endif
 
-    if ((p_msg = (tBTA_DM_REM_NAME *) GKI_getbuf(sizeof(tBTA_DM_REM_NAME))) != NULL) {
+    if ((p_msg = (tBTA_DM_REM_NAME *) osi_malloc(sizeof(tBTA_DM_REM_NAME))) != NULL) {
         bdcpy (p_msg->result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
         BCM_STRNCPY_S((char *)p_msg->result.disc_res.bd_name, sizeof(BD_NAME), (char *)p_remote_name->remote_bd_name, (BD_NAME_LEN));
 
@@ -2960,7 +2959,7 @@ static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data)
 {
     tBTA_DM_ACL_CHANGE *p_msg;
 
-    if ((p_msg = (tBTA_DM_ACL_CHANGE *) GKI_getbuf(sizeof(tBTA_DM_ACL_CHANGE))) != NULL) {
+    if ((p_msg = (tBTA_DM_ACL_CHANGE *) osi_malloc(sizeof(tBTA_DM_ACL_CHANGE))) != NULL) {
         p_msg->event = p_data->event;
         p_msg->is_new = FALSE;
 
@@ -3297,7 +3296,7 @@ static void bta_dm_disable_conn_down_timer_cback (TIMER_LIST_ENT *p_tle)
     bta_sys_hw_register( BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback );
 
     /* send a message to BTA SYS */
-    if ((sys_enable_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
+    if ((sys_enable_event = (tBTA_SYS_HW_MSG *) osi_malloc(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
         sys_enable_event->hdr.event = BTA_SYS_API_DISABLE_EVT;
         sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH;
         bta_sys_sendmsg(sys_enable_event);
@@ -3624,7 +3623,7 @@ static void bta_dm_set_eir (char *local_name)
 #endif  // BTA_EIR_CANNED_UUID_LIST
 
     /* Allocate a buffer to hold HCI command */
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf(BTM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(BTM_CMD_BUF_SIZE)) == NULL) {
         APPL_TRACE_ERROR("bta_dm_set_eir couldn't allocate buffer");
         return;
     }
@@ -5440,7 +5439,7 @@ static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status)
         bta_dm_search_cb.uuid_to_search = 0;
 
         /* no more services to be discovered */
-        if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) {
+        if ((p_msg = (tBTA_DM_MSG *) osi_malloc(sizeof(tBTA_DM_MSG))) != NULL) {
             p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
             p_msg->disc_result.result.disc_res.result = (status == BTA_GATT_OK) ? BTA_SUCCESS : BTA_FAILURE;
             APPL_TRACE_DEBUG("%s service found: 0x%08x", __FUNCTION__,
@@ -5457,7 +5456,7 @@ static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status)
 
             p_msg->disc_result.result.disc_res.device_type |= BT_DEVICE_TYPE_BLE;
             if ( bta_dm_search_cb.ble_raw_used > 0 ) {
-                p_msg->disc_result.result.disc_res.p_raw_data = GKI_getbuf(bta_dm_search_cb.ble_raw_used);
+                p_msg->disc_result.result.disc_res.p_raw_data = osi_malloc(bta_dm_search_cb.ble_raw_used);
 
                 memcpy( p_msg->disc_result.result.disc_res.p_raw_data,
                         bta_dm_search_cb.p_ble_rawdata,
index fcb27004f0b39a02cc232ff05d4a9e0a5405dd8e..095fd55570d56cadd043bbb22a15dcecb1e30e91 100644 (file)
@@ -22,7 +22,6 @@
  *
  ******************************************************************************/
 
-#include "gki.h"
 #include "bta_sys.h"
 #include "bta_api.h"
 #include "bta_dm_int.h"
@@ -31,6 +30,7 @@
 #include "btm_int.h"
 #include <string.h>
 #include "utl.h"
+#include "allocator.h"
 
 /*****************************************************************************
 **  Constants
@@ -75,7 +75,7 @@ tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
     /* if UUID list is not provided as static data */
     bta_sys_eir_register(bta_dm_eir_update_uuid);
 
-    if ((p_msg = (tBTA_DM_API_ENABLE *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_ENABLE *) osi_malloc(sizeof(tBTA_DM_API_ENABLE))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
         p_msg->p_sec_cback = p_cback;
         bta_sys_sendmsg(p_msg);
@@ -100,7 +100,7 @@ tBTA_STATUS BTA_DisableBluetooth(void)
 
     BT_HDR    *p_msg;
 
-    if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_msg->event = BTA_DM_API_DISABLE_EVT;
         bta_sys_sendmsg(p_msg);
     } else {
@@ -126,7 +126,7 @@ tBTA_STATUS BTA_EnableTestMode(void)
 
     APPL_TRACE_API("BTA_EnableTestMode");
 
-    if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
         bta_sys_sendmsg(p_msg);
         return BTA_SUCCESS;
@@ -150,7 +150,7 @@ void BTA_DisableTestMode(void)
 
     APPL_TRACE_API("BTA_DisableTestMode");
 
-    if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
         bta_sys_sendmsg(p_msg);
     }
@@ -171,7 +171,7 @@ void BTA_DmSetDeviceName(char *p_name)
 
     tBTA_DM_API_SET_NAME    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_SET_NAME *) GKI_getbuf(sizeof(tBTA_DM_API_SET_NAME))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_SET_NAME *) osi_malloc(sizeof(tBTA_DM_API_SET_NAME))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
         /* truncate the name if needed */
         BCM_STRNCPY_S((char *)p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN - 1);
@@ -199,7 +199,7 @@ void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 p
 
     tBTA_DM_API_SET_VISIBILITY    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) GKI_getbuf(sizeof(tBTA_DM_API_SET_VISIBILITY))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) osi_malloc(sizeof(tBTA_DM_API_SET_VISIBILITY))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
         p_msg->disc_mode = disc_mode;
         p_msg->conn_mode = conn_mode;
@@ -230,7 +230,7 @@ void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEA
 
     tBTA_DM_API_SEARCH    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(sizeof(tBTA_DM_API_SEARCH))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_SEARCH *) osi_malloc(sizeof(tBTA_DM_API_SEARCH))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_SEARCH));
 
         p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
@@ -258,7 +258,7 @@ void BTA_DmSearchCancel(void)
 {
     BT_HDR    *p_msg;
 
-    if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
         bta_sys_sendmsg(p_msg);
     }
@@ -282,7 +282,7 @@ void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
 {
     tBTA_DM_API_DISCOVER    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_DISCOVER));
 
         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
@@ -310,7 +310,7 @@ void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
 {
     tBTA_DM_API_DISCOVER    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
         bdcpy(p_msg->bd_addr, bd_addr);
         p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
@@ -343,7 +343,7 @@ void BTA_DmBond(BD_ADDR bd_addr)
 {
     tBTA_DM_API_BOND    *p_msg;
 
-    p_msg = (tBTA_DM_API_BOND *) GKI_getbuf(sizeof(tBTA_DM_API_BOND));
+    p_msg = (tBTA_DM_API_BOND *) osi_malloc(sizeof(tBTA_DM_API_BOND));
     if (p_msg != NULL) {
         p_msg->hdr.event = BTA_DM_API_BOND_EVT;
         bdcpy(p_msg->bd_addr, bd_addr);
@@ -367,7 +367,7 @@ void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
 {
     tBTA_DM_API_BOND    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_BOND *) GKI_getbuf(sizeof(tBTA_DM_API_BOND))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BOND *) osi_malloc(sizeof(tBTA_DM_API_BOND))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BOND_EVT;
         bdcpy(p_msg->bd_addr, bd_addr);
         p_msg->transport = transport;
@@ -392,7 +392,7 @@ void BTA_DmBondCancel(BD_ADDR bd_addr)
 {
     tBTA_DM_API_BOND_CANCEL    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) GKI_getbuf(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
         bdcpy(p_msg->bd_addr, bd_addr);
         bta_sys_sendmsg(p_msg);
@@ -417,7 +417,7 @@ void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin
 {
     tBTA_DM_API_PIN_REPLY    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_PIN_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_PIN_REPLY *) osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
         bdcpy(p_msg->bd_addr, bd_addr);
         p_msg->accept = accept;
@@ -448,7 +448,7 @@ void BTA_DmLocalOob(void)
 {
     tBTA_DM_API_LOC_OOB    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_LOC_OOB *) GKI_getbuf(sizeof(tBTA_DM_API_LOC_OOB))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_LOC_OOB *) osi_malloc(sizeof(tBTA_DM_API_LOC_OOB))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
         bta_sys_sendmsg(p_msg);
     }
@@ -468,7 +468,7 @@ void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
 {
     tBTA_DM_API_CONFIRM    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_DM_API_CONFIRM))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_CONFIRM *) osi_malloc(sizeof(tBTA_DM_API_CONFIRM))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
         bdcpy(p_msg->bd_addr, bd_addr);
         p_msg->accept = accept;
@@ -494,7 +494,7 @@ void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
 
     tBTA_DM_API_ADD_DEVICE *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) {
         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE));
 
         p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
@@ -539,7 +539,7 @@ tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
 {
     tBTA_DM_API_REMOVE_DEVICE *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL) {
         memset (p_msg, 0, sizeof(tBTA_DM_API_REMOVE_DEVICE));
 
         p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
@@ -663,7 +663,7 @@ void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK *p_callback, void *p_param)
 {
     tBTA_DM_API_EXECUTE_CBACK *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) GKI_getbuf(sizeof(tBTA_DM_API_EXECUTE_CBACK))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) osi_malloc(sizeof(tBTA_DM_API_EXECUTE_CBACK))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
         p_msg->p_param = p_param;
         p_msg->p_exec_cback = p_callback;
@@ -693,7 +693,7 @@ void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_
 {
     tBTA_DM_API_ADD_BLEKEY *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) osi_malloc(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL) {
         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLEKEY));
 
         p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
@@ -725,7 +725,7 @@ void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TY
 {
     tBTA_DM_API_ADD_BLE_DEVICE *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL) {
         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
 
         p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
@@ -754,7 +754,7 @@ void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
 {
     tBTA_DM_API_PASSKEY_REPLY    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) osi_malloc(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_PASSKEY_REPLY));
 
         p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
@@ -781,7 +781,7 @@ void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
 *******************************************************************************/
 void BTA_DmBleConfirmReply(BD_ADDR bd_addr, BOOLEAN accept)
 {
-    tBTA_DM_API_CONFIRM *p_msg = (tBTA_DM_API_CONFIRM *)GKI_getbuf(sizeof(tBTA_DM_API_CONFIRM));
+    tBTA_DM_API_CONFIRM *p_msg = (tBTA_DM_API_CONFIRM *)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
     if (p_msg != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_CONFIRM));
         p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
@@ -807,7 +807,7 @@ void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
 {
     tBTA_DM_API_BLE_SEC_GRANT    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) osi_malloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SEC_GRANT));
 
         p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
@@ -847,7 +847,7 @@ void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
 #if BLE_INCLUDED == TRUE
     tBTA_DM_API_BLE_CONN_PARAMS    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
 
         p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
@@ -880,7 +880,7 @@ void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
 void BTA_DmSetBleConnScanParams(UINT32 scan_interval, UINT32 scan_window)
 {
     tBTA_DM_API_BLE_SCAN_PARAMS  *p_msg;
-    if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
         p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
         p_msg->scan_int         = scan_interval;
@@ -910,7 +910,7 @@ void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval,
 {
     tBTA_DM_API_BLE_SCAN_PARAMS *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
         p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
         p_msg->client_if = client_if;
@@ -945,7 +945,7 @@ void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval,
 {
     tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS));
         p_msg->hdr.event = BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT;
         p_msg->client_if = client_if;
@@ -982,7 +982,7 @@ void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
 
     APPL_TRACE_API ("BTA_DmSetBleAdvParam: %d, %d\n", adv_int_min, adv_int_max);
 
-    if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS)
+    if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS)
                  + sizeof(tBLE_BD_ADDR))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS) + sizeof(tBLE_BD_ADDR));
 
@@ -1012,7 +1012,7 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max,
     APPL_TRACE_API ("BTA_DmSetBleAdvParamsAll: %d, %d\n", adv_int_min, adv_int_max);
     APPL_TRACE_API ("adv_type = %d, addr_type_own = %d, chnl_map = %d, adv_fil_pol = %d\n",
                       adv_type, addr_type_own, chnl_map, adv_fil_pol);
-    if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)
+    if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)
                  + sizeof(tBLE_BD_ADDR))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL));
 
@@ -1063,7 +1063,7 @@ void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv
     tBTA_DM_API_SET_ADV_CONFIG  *p_msg;
 
     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
-                 GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
+                 osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT;
         p_msg->data_mask = data_mask;
         p_msg->p_adv_data_cback = p_adv_data_cback;
@@ -1092,7 +1092,7 @@ void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len,
     tBTA_DM_API_SET_ADV_CONFIG_RAW  *p_msg;
 
     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
-                 GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW))) != NULL) {
+                 osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT;
         p_msg->p_adv_data_cback = p_adv_data_cback;
         p_msg->p_raw_adv = p_raw_adv;
@@ -1119,7 +1119,7 @@ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *
     tBTA_DM_API_SET_ADV_CONFIG  *p_msg;
 
     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
-                 GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
+                 osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT;
         p_msg->data_mask = data_mask;
         p_msg->p_adv_data_cback = p_adv_data_cback;
@@ -1148,7 +1148,7 @@ void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len,
     tBTA_DM_API_SET_ADV_CONFIG_RAW  *p_msg;
 
     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
-                 GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW))) != NULL) {
+                 osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT;
         p_msg->p_adv_data_cback = p_scan_rsp_data_cback;
         p_msg->p_raw_adv = p_raw_scan_rsp;
@@ -1186,7 +1186,7 @@ extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,
     tBTA_DM_API_SET_STORAGE_CONFIG  *p_msg;
     bta_dm_cb.p_setup_cback = p_setup_cback;
     if ((p_msg = (tBTA_DM_API_SET_STORAGE_CONFIG *)
-                 GKI_getbuf(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG))) != NULL) {
+                 osi_malloc(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
         p_msg->p_setup_cback = bta_ble_scan_setup_cb;
         p_msg->p_thres_cback = p_thres_cback;
@@ -1223,7 +1223,7 @@ extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
 {
     tBTA_DM_API_ENABLE_SCAN  *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_ENABLE_SCAN *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE_SCAN))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_ENABLE_SCAN *) osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
         p_msg->scan_mode = scan_mode;
         p_msg->scan_int = scan_interval;
@@ -1251,7 +1251,7 @@ extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
     tBTA_DM_API_DISABLE_SCAN  *p_msg;
 
     if ((p_msg = (tBTA_DM_API_DISABLE_SCAN *)
-                 GKI_getbuf(sizeof(tBTA_DM_API_DISABLE_SCAN))) != NULL) {
+                 osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
         p_msg->ref_value = ref_value;
         bta_sys_sendmsg(p_msg);
@@ -1276,7 +1276,7 @@ extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
     tBTA_DM_API_READ_SCAN_REPORTS  *p_msg;
 
     if ((p_msg = (tBTA_DM_API_READ_SCAN_REPORTS *)
-                 GKI_getbuf(sizeof(tBTA_DM_API_READ_SCAN_REPORTS))) != NULL) {
+                 osi_malloc(sizeof(tBTA_DM_API_READ_SCAN_REPORTS))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
         p_msg->scan_type = scan_type;
         p_msg->ref_value = ref_value;
@@ -1302,7 +1302,7 @@ extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
     tBTA_DM_API_TRACK_ADVERTISER  *p_msg;
 
     if ((p_msg = (tBTA_DM_API_TRACK_ADVERTISER *)
-                 GKI_getbuf(sizeof(tBTA_DM_API_TRACK_ADVERTISER))) != NULL) {
+                 osi_malloc(sizeof(tBTA_DM_API_TRACK_ADVERTISER))) != NULL) {
         p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
         p_msg->p_track_adv_cback = p_track_adv_cback;
         p_msg->ref_value = ref_value;
@@ -1334,7 +1334,7 @@ extern void BTA_DmBleBroadcast (BOOLEAN start, tBTA_START_STOP_ADV_CMPL_CBACK *p
 
     APPL_TRACE_API("BTA_DmBleBroadcast: start = %d \n", start);
 
-    if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) osi_malloc(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
 
         p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
@@ -1367,7 +1367,7 @@ void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_
 #if BLE_INCLUDED == TRUE
     tBTA_DM_API_BLE_SET_BG_CONN_TYPE    *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) osi_malloc(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
 
         p_msg->hdr.event        = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
@@ -1398,7 +1398,7 @@ static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_s
                                 sizeof(tBT_UUID) * p_services->num_uuid) :
                   sizeof(tBTA_DM_API_DISCOVER);
 
-    if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(len)) != NULL) {
+    if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(len)) != NULL) {
         memset(p_msg, 0, len);
 
         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
@@ -1498,7 +1498,7 @@ void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, t
     UINT16  len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid) :
                   sizeof(tBTA_DM_API_SEARCH);
 
-    if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(len)) != NULL) {
+    if ((p_msg = (tBTA_DM_API_SEARCH *) osi_malloc(len)) != NULL) {
         memset(p_msg, 0, len);
 
         p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
@@ -1549,7 +1549,7 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
 #if BLE_INCLUDED == TRUE
     tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
 
-    p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
+    p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) osi_malloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
     if (p_msg != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
 
@@ -1581,7 +1581,7 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_
 #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
     tBTA_DM_API_LOCAL_PRIVACY *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_LOCAL_PRIVACY *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE_PRIVACY))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_LOCAL_PRIVACY *) osi_malloc(sizeof(tBTA_DM_API_ENABLE_PRIVACY))) != NULL) {
         memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_PRIVACY));
 
         p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
@@ -1619,7 +1619,7 @@ void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
 
     APPL_TRACE_API ("BTA_BleEnableAdvInstance");
 
-    if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_ENB *) GKI_getbuf(len)) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_ENB *) osi_malloc(len)) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB));
 
         p_msg->hdr.event     = BTA_DM_API_BLE_MULTI_ADV_ENB_EVT;
@@ -1654,7 +1654,7 @@ void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params)
     UINT16      len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM);
 
     APPL_TRACE_API ("BTA_BleUpdateAdvInstParam");
-    if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_PARAM *) GKI_getbuf(len)) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_PARAM *) osi_malloc(len)) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM));
         p_msg->hdr.event     = BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT;
         p_msg->inst_id        = inst_id;
@@ -1692,7 +1692,7 @@ void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp,
 
     APPL_TRACE_API ("BTA_BleCfgAdvInstData");
 
-    if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DATA *) GKI_getbuf(len)) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DATA *) osi_malloc(len)) != NULL) {
         memset(p_msg, 0, len);
         p_msg->hdr.event     = BTA_DM_API_BLE_MULTI_ADV_DATA_EVT;
         p_msg->inst_id      = inst_id;
@@ -1721,7 +1721,7 @@ void BTA_BleDisableAdvInstance (UINT8  inst_id)     //this function just used fo
 
     APPL_TRACE_API ("BTA_BleDisableAdvInstance: %d", inst_id);
     if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DISABLE *)
-                 GKI_getbuf(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE))) != NULL) {
+                 osi_malloc(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE));
         p_msg->hdr.event    = BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT;
         p_msg->inst_id      = inst_id;
@@ -1785,7 +1785,7 @@ void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
         }
     }
 
-    if ((p_msg = (tBTA_DM_API_CFG_FILTER_COND *) GKI_getbuf(len)) != NULL) {
+    if ((p_msg = (tBTA_DM_API_CFG_FILTER_COND *) osi_malloc(len)) != NULL) {
         memset (p_msg, 0, len);
 
         p_msg->hdr.event        = BTA_DM_API_CFG_FILTER_COND_EVT;
@@ -1881,7 +1881,7 @@ void BTA_DmBleScanFilterSetup(UINT8 action, tBTA_DM_BLE_PF_FILT_INDEX filt_index
 
     UINT16  len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) + sizeof(tBLE_BD_ADDR);
 
-    if ((p_msg = (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *) GKI_getbuf(len)) != NULL) {
+    if ((p_msg = (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *) osi_malloc(len)) != NULL) {
         memset (p_msg, 0, len);
 
         p_msg->hdr.event        = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
@@ -1928,7 +1928,7 @@ void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
 
     UINT16  len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
 
-    if ((p_msg = (tBTA_DM_API_ENERGY_INFO *) GKI_getbuf(len)) != NULL) {
+    if ((p_msg = (tBTA_DM_API_ENERGY_INFO *) osi_malloc(len)) != NULL) {
         memset (p_msg, 0, len);
         p_msg->hdr.event        = BTA_DM_API_BLE_ENERGY_INFO_EVT;
         p_msg->p_energy_info_cback = p_cmpl_cback;
@@ -1958,7 +1958,7 @@ void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cb
 
     UINT16  len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) + sizeof(tBLE_BD_ADDR);
 
-    if ((p_msg = (tBTA_DM_API_ENABLE_SCAN_FILTER *) GKI_getbuf(len)) != NULL) {
+    if ((p_msg = (tBTA_DM_API_ENABLE_SCAN_FILTER *) osi_malloc(len)) != NULL) {
         memset (p_msg, 0, len);
 
         p_msg->hdr.event        = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
@@ -1995,7 +1995,7 @@ void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max
 {
     tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) osi_malloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM))) != NULL) {
         memset (p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
 
         p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
@@ -2023,7 +2023,7 @@ void BTA_DmBleDisconnect(BD_ADDR bd_addr)
 {
     tBTA_DM_API_BLE_DISCONNECT *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_BLE_DISCONNECT *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_DISCONNECT))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_DISCONNECT *) osi_malloc(sizeof(tBTA_DM_API_BLE_DISCONNECT))) != NULL) {
         memset (p_msg, 0, sizeof(tBTA_DM_API_BLE_DISCONNECT));
 
         p_msg->hdr.event = BTA_DM_API_BLE_DISCONNECT_EVT;
@@ -2046,7 +2046,7 @@ void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_S
 {
     tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg;
 
-    if ((p_msg = (tBTA_DM_API_BLE_SET_DATA_LENGTH *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH)))
+    if ((p_msg = (tBTA_DM_API_BLE_SET_DATA_LENGTH *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH)))
             != NULL) {
         bdcpy(p_msg->remote_bda, remote_device);
         p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
@@ -2088,7 +2088,7 @@ void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCR
     tBTA_DM_API_SET_ENCRYPTION   *p_msg;
 
     APPL_TRACE_API("BTA_DmSetEncryption"); //todo
-    if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) osi_malloc(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_SET_ENCRYPTION));
 
         p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
@@ -2122,7 +2122,7 @@ void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transpor
 
     APPL_TRACE_API("BTA_DmCloseACL");
 
-    if ((p_msg = (tBTA_DM_API_REMOVE_ACL *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_ACL))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_REMOVE_ACL *) osi_malloc(sizeof(tBTA_DM_API_REMOVE_ACL))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_REMOVE_ACL));
 
         p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
@@ -2159,7 +2159,7 @@ extern void BTA_DmBleObserve(BOOLEAN start, UINT32 duration,
 
     APPL_TRACE_API("BTA_DmBleObserve:start = %d ", start);
 
-    if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
+    if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) osi_malloc(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
 
         p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
@@ -2195,7 +2195,7 @@ extern void BTA_DmBleStopAdvertising(void)
 
     APPL_TRACE_API("BTA_DmBleStopAdvertising\n");
 
-    if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         memset(p_msg, 0, sizeof(BT_HDR));
         p_msg->event = BTA_DM_API_BLE_STOP_ADV_EVT;
         bta_sys_sendmsg(p_msg);
@@ -2219,7 +2219,7 @@ extern void BTA_DmSetRandAddress(BD_ADDR rand_addr)
 {
     tBTA_DM_APT_SET_DEV_ADDR *p_msg;
     APPL_TRACE_API("set the random address ");
-    if ((p_msg = (tBTA_DM_APT_SET_DEV_ADDR *) GKI_getbuf(sizeof(tBTA_DM_APT_SET_DEV_ADDR))) != NULL) {
+    if ((p_msg = (tBTA_DM_APT_SET_DEV_ADDR *) osi_malloc(sizeof(tBTA_DM_APT_SET_DEV_ADDR))) != NULL) {
         memset(p_msg, 0, sizeof(tBTA_DM_APT_SET_DEV_ADDR));
         memcpy(p_msg->address, rand_addr, BD_ADDR_LEN);
         p_msg->hdr.event = BTA_DM_API_SET_RAND_ADDR_EVT;
index fb7d0e06d93c4ba280c7095b37d73df8b3150ec5..afceda0c28de3c1ce833fc170014ab32b5c07f35 100644 (file)
  *
  ******************************************************************************/
 
-#include "gki.h"
 #include "bta_sys.h"
 #include "bta_api.h"
 #include "bta_dm_int.h"
 #include <string.h>
 #include "bta_dm_ci.h"
+#include "allocator.h"
 
 
 #if (BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
@@ -48,7 +48,7 @@ void bta_dm_ci_io_req(BD_ADDR bd_addr, tBTA_IO_CAP io_cap, tBTA_OOB_DATA oob_dat
 {
     tBTA_DM_CI_IO_REQ    *p_msg;
 
-    if ((p_msg = (tBTA_DM_CI_IO_REQ *) GKI_getbuf(sizeof(tBTA_DM_CI_IO_REQ))) != NULL) {
+    if ((p_msg = (tBTA_DM_CI_IO_REQ *) osi_malloc(sizeof(tBTA_DM_CI_IO_REQ))) != NULL) {
         p_msg->hdr.event = BTA_DM_CI_IO_REQ_EVT;
         bdcpy(p_msg->bd_addr, bd_addr);
         p_msg->io_cap   = io_cap;
@@ -73,7 +73,7 @@ void bta_dm_ci_rmt_oob(BOOLEAN accept, BD_ADDR bd_addr, BT_OCTET16 c, BT_OCTET16
 {
     tBTA_DM_CI_RMT_OOB    *p_msg;
 
-    if ((p_msg = (tBTA_DM_CI_RMT_OOB *) GKI_getbuf(sizeof(tBTA_DM_CI_RMT_OOB))) != NULL) {
+    if ((p_msg = (tBTA_DM_CI_RMT_OOB *) osi_malloc(sizeof(tBTA_DM_CI_RMT_OOB))) != NULL) {
         p_msg->hdr.event = BTA_DM_CI_RMT_OOB_EVT;
         bdcpy(p_msg->bd_addr, bd_addr);
         p_msg->accept    = accept;
@@ -104,7 +104,7 @@ void bta_dm_sco_ci_data_ready(UINT16 event, UINT16 sco_handle)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = event;
         p_buf->layer_specific = sco_handle;
 
index e4bf0fadb03c740807eda37f35095813a81d2334..0980f1f8afaa5969e12aa8af12d63a9522151f0c 100644 (file)
@@ -679,7 +679,7 @@ typedef struct {
 
 /* union of all data types */
 typedef union {
-    /* GKI event buffer header */
+    /* event buffer header */
     BT_HDR              hdr;
     tBTA_DM_API_ENABLE  enable;
 
index 4434dcbda2cebfcc8f0546b433472ab9301d1673..7afec045a19356426166eddcf3242495030cccb6 100644 (file)
@@ -26,7 +26,6 @@
 // #include <assert.h>
 #include <string.h>
 
-#include "gki.h"
 #include "bta_sys.h"
 #include "bta_api.h"
 #include "bta_dm_int.h"
@@ -844,7 +843,7 @@ static void bta_dm_pm_btm_cback(BD_ADDR bd_addr, tBTM_PM_STATUS status, UINT16 v
 {
     tBTA_DM_PM_BTM_STATUS  *p_buf;
 
-    if ((p_buf = (tBTA_DM_PM_BTM_STATUS *) GKI_getbuf(sizeof(tBTA_DM_PM_BTM_STATUS))) != NULL) {
+    if ((p_buf = (tBTA_DM_PM_BTM_STATUS *) osi_malloc(sizeof(tBTA_DM_PM_BTM_STATUS))) != NULL) {
         p_buf->hdr.event = BTA_DM_PM_BTM_STATUS_EVT;
         p_buf->status = status;
         p_buf->value = value;
@@ -893,7 +892,7 @@ static void bta_dm_pm_timer_cback(void *p_tle)
         return;
     }
 
-    tBTA_DM_PM_TIMER *p_buf = (tBTA_DM_PM_TIMER *) GKI_getbuf(sizeof(tBTA_DM_PM_TIMER));
+    tBTA_DM_PM_TIMER *p_buf = (tBTA_DM_PM_TIMER *) osi_malloc(sizeof(tBTA_DM_PM_TIMER));
     if (p_buf != NULL) {
         p_buf->hdr.event = BTA_DM_PM_TIMER_EVT;
         p_buf->pm_request = bta_dm_cb.pm_timer[i].pm_action[j];
index 617aa02cdf277dbfaaa3d78ed6db4d55adbdd060..22f3d6b180cf3c54dbabe800fa7077c037fd0d8d 100644 (file)
 #include "bt_target.h"
 
 #include "utl.h"
-#include "gki.h"
 #include "bta_sys.h"
 
 #include "bta_gattc_int.h"
 #include "l2c_api.h"
 #include "l2c_int.h"
 #include "gatt_int.h"
+#include "allocator.h"
 
 #if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
 #include "bta_hh_int.h"
@@ -209,7 +209,7 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data)
                 /* BTA use the same client interface as BTE GATT statck */
                 cb_data.reg_oper.client_if = p_cb->cl_rcb[i].client_if;
 
-                if ((p_buf = (tBTA_GATTC_INT_START_IF *) GKI_getbuf(sizeof(tBTA_GATTC_INT_START_IF))) != NULL) {
+                if ((p_buf = (tBTA_GATTC_INT_START_IF *) osi_malloc(sizeof(tBTA_GATTC_INT_START_IF))) != NULL) {
                     p_buf->hdr.event    = BTA_GATTC_INT_START_IF_EVT;
                     p_buf->client_if    = p_cb->cl_rcb[i].client_if;
                     APPL_TRACE_DEBUG("GATTC getbuf sucess.\n");
@@ -1004,9 +1004,10 @@ void bta_gattc_disc_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
     if (p_clcb->status != GATT_SUCCESS) {
         /* clean up cache */
         if (p_clcb->p_srcb && p_clcb->p_srcb->p_srvc_cache) {
-            while (!GKI_queue_is_empty(&p_clcb->p_srcb->cache_buffer)) {
-                GKI_freebuf (GKI_dequeue (&p_clcb->p_srcb->cache_buffer));
+            while (!fixed_queue_is_empty(p_clcb->p_srcb->cache_buffer)) {
+                osi_free(fixed_queue_try_dequeue(p_clcb->p_srcb->cache_buffer));
             }
+            //fixed_queue_free(p_clcb->p_srcb->cache_buffer, NULL);
             p_clcb->p_srcb->p_srvc_cache = NULL;
         }
 
@@ -1756,7 +1757,7 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id,
     else if ((transport == BT_TRANSPORT_LE) && (connected == FALSE) && (p_conn != NULL)){
             p_conn->service_change_ccc_written = FALSE;
             if (p_conn->ccc_timer_used == TRUE){
-                GKI_freebuf((void *)p_conn->service_change_ccc_timer.param);
+                osi_free((void *)p_conn->service_change_ccc_timer.param);
                 bta_sys_stop_timer(&(p_conn->service_change_ccc_timer));
                 p_conn->ccc_timer_used = FALSE;
             }
@@ -1765,7 +1766,7 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id,
     bt_bdaddr_t bdaddr;
     bdcpy(bdaddr.address, bda);
 
-    if ((p_buf = (tBTA_GATTC_DATA *) GKI_getbuf(sizeof(tBTA_GATTC_DATA))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_DATA *) osi_malloc(sizeof(tBTA_GATTC_DATA))) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_GATTC_DATA));
 
         p_buf->int_conn.hdr.event            = connected ? BTA_GATTC_INT_CONN_EVT :
@@ -1810,9 +1811,7 @@ static void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda)
 
     APPL_TRACE_DEBUG("bta_gattc_enc_cmpl_cback: cif = %d", gattc_if);
 
-    if ((p_buf = (tBTA_GATTC_DATA *) GKI_getbuf(sizeof(tBTA_GATTC_DATA))) != NULL) {
-        memset(p_buf, 0, sizeof(tBTA_GATTC_DATA));
-
+    if ((p_buf = (tBTA_GATTC_DATA *) osi_calloc(sizeof(tBTA_GATTC_DATA))) != NULL) {
         p_buf->enc_cmpl.hdr.event            = BTA_GATTC_ENC_CMPL_EVT;
         p_buf->enc_cmpl.hdr.layer_specific   = p_clcb->bta_conn_id;
         p_buf->enc_cmpl.client_if            = gattc_if;
@@ -1856,10 +1855,10 @@ void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
         }
         /* in all other cases, mark it and delete the cache */
         if (p_srvc_cb->p_srvc_cache != NULL) {
-            while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer)) {
-                GKI_freebuf (GKI_dequeue (&p_srvc_cb->cache_buffer));
+            while (!fixed_queue_is_empty(p_clcb->p_srcb->cache_buffer)) {
+                osi_free(fixed_queue_try_dequeue(p_clcb->p_srcb->cache_buffer));
             }
-
+            //fixed_queue_free(p_clcb->p_srcb->cache_buffer, NULL);
             p_srvc_cb->p_srvc_cache = NULL;
         }
     }
@@ -2095,7 +2094,7 @@ static void bta_gattc_cmpl_sendmsg(UINT16 conn_id, tGATTC_OPTYPE op,
                                    tGATT_CL_COMPLETE *p_data)
 {
     const UINT16         len = sizeof(tBTA_GATTC_OP_CMPL) + sizeof(tGATT_CL_COMPLETE);
-    tBTA_GATTC_OP_CMPL  *p_buf = (tBTA_GATTC_OP_CMPL *) GKI_getbuf(len);
+    tBTA_GATTC_OP_CMPL  *p_buf = (tBTA_GATTC_OP_CMPL *) osi_malloc(len);
 
     if (p_buf != NULL) {
         memset(p_buf, 0, len);
@@ -2295,7 +2294,7 @@ void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
 void bta_gattc_start_service_change_ccc_timer(UINT16 conn_id, BD_ADDR bda,UINT32 timeout_ms,
                                               UINT8 timer_cnt, UINT8 last_status, TIMER_LIST_ENT *ccc_timer)
 {
-    tBTA_GATTC_WAIT_CCC_TIMER *p_timer_param = (tBTA_GATTC_WAIT_CCC_TIMER*) GKI_getbuf(sizeof(tBTA_GATTC_WAIT_CCC_TIMER));
+    tBTA_GATTC_WAIT_CCC_TIMER *p_timer_param = (tBTA_GATTC_WAIT_CCC_TIMER*) osi_malloc(sizeof(tBTA_GATTC_WAIT_CCC_TIMER));
     if (p_timer_param != NULL){
         p_timer_param->conn_id = conn_id;
         memcpy(p_timer_param->remote_bda, bda, sizeof(BD_ADDR));
@@ -2467,7 +2466,7 @@ static void bta_gattc_wait4_service_change_ccc_cback (TIMER_LIST_ENT *p_tle)
     tBTA_GATTC_CONN *p_conn = bta_gattc_conn_find(p_timer_param->remote_bda);
     if (p_conn == NULL){
         APPL_TRACE_ERROR("p_conn is NULL in %s\n", __func__);
-        GKI_freebuf(p_timer_param);
+        osi_free(p_timer_param);
         return;
     }
 
@@ -2498,7 +2497,7 @@ static void bta_gattc_wait4_service_change_ccc_cback (TIMER_LIST_ENT *p_tle)
         p_conn->service_change_ccc_written = TRUE;
     }
 
-    GKI_freebuf(p_timer_param);
+    osi_free(p_timer_param);
 }
 
 #endif
index 8d25f51da213869316c21937b022cccb0952231a..bca1c080d798aeda4315dcd3b73bd56d764110bf 100644 (file)
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "allocator.h"
 
 #if defined(GATTC_INCLUDED) && (GATTC_INCLUDED == TRUE)
 
 #include <string.h>
-#include "gki.h"
 #include "bta_sys.h"
 #include "bta_gatt_api.h"
 #include "bta_gattc_int.h"
@@ -61,7 +61,7 @@ void BTA_GATTC_Disable(void)
         APPL_TRACE_WARNING("GATTC Module not enabled/already disabled\n");
         return;
     }
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_GATTC_API_DISABLE_EVT;
         bta_sys_sendmsg(p_buf);
     }
@@ -90,7 +90,7 @@ void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb)
         bta_sys_register(BTA_ID_GATTC, &bta_gattc_reg);
     }
 
-    if ((p_buf = (tBTA_GATTC_API_REG *) GKI_getbuf(sizeof(tBTA_GATTC_API_REG))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_REG *) osi_malloc(sizeof(tBTA_GATTC_API_REG))) != NULL) {
         p_buf->hdr.event    = BTA_GATTC_API_REG_EVT;
         if (p_app_uuid != NULL) {
             memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID));
@@ -118,7 +118,7 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
 {
     tBTA_GATTC_API_DEREG  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_DEREG *) GKI_getbuf(sizeof(tBTA_GATTC_API_DEREG))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_DEREG *) osi_malloc(sizeof(tBTA_GATTC_API_DEREG))) != NULL) {
         p_buf->hdr.event = BTA_GATTC_API_DEREG_EVT;
         p_buf->client_if = client_if;
         bta_sys_sendmsg(p_buf);
@@ -146,7 +146,7 @@ void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
 {
     tBTA_GATTC_API_OPEN  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_OPEN *) GKI_getbuf(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
         p_buf->hdr.event = BTA_GATTC_API_OPEN_EVT;
 
         p_buf->client_if = client_if;
@@ -178,7 +178,7 @@ void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN i
 {
     tBTA_GATTC_API_CANCEL_OPEN  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_CANCEL_OPEN *) GKI_getbuf(sizeof(tBTA_GATTC_API_CANCEL_OPEN))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_CANCEL_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_CANCEL_OPEN))) != NULL) {
         p_buf->hdr.event = BTA_GATTC_API_CANCEL_OPEN_EVT;
 
         p_buf->client_if = client_if;
@@ -205,7 +205,7 @@ void BTA_GATTC_Close(UINT16 conn_id)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_GATTC_API_CLOSE_EVT;
 
         p_buf->layer_specific = conn_id;
@@ -232,7 +232,7 @@ void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu)
 {
     tBTA_GATTC_API_CFG_MTU  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_CFG_MTU *) GKI_getbuf(sizeof(tBTA_GATTC_API_CFG_MTU))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_CFG_MTU *) osi_malloc(sizeof(tBTA_GATTC_API_CFG_MTU))) != NULL) {
         p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT;
         p_buf->hdr.layer_specific = conn_id;
 
@@ -263,7 +263,7 @@ void BTA_GATTC_ServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid)
     tBTA_GATTC_API_SEARCH  *p_buf;
     UINT16  len = sizeof(tBTA_GATTC_API_SEARCH) + sizeof(tBT_UUID);
 
-    if ((p_buf = (tBTA_GATTC_API_SEARCH *) GKI_getbuf(len)) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_SEARCH *) osi_malloc(len)) != NULL) {
         memset(p_buf, 0, len);
 
         p_buf->hdr.event = BTA_GATTC_API_SEARCH_EVT;
@@ -553,7 +553,7 @@ void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
 {
     tBTA_GATTC_API_READ  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_READ *) GKI_getbuf(sizeof(tBTA_GATTC_API_READ))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_READ *) osi_malloc(sizeof(tBTA_GATTC_API_READ))) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_GATTC_API_READ));
 
         p_buf->hdr.event = BTA_GATTC_API_READ_EVT;
@@ -588,7 +588,7 @@ void BTA_GATTC_ReadCharDescr (UINT16 conn_id,
     tBTA_GATTC_API_READ  *p_buf;
     UINT16  len = (UINT16)(sizeof(tBTA_GATT_ID) + sizeof(tBTA_GATTC_API_READ));
 
-    if ((p_buf = (tBTA_GATTC_API_READ *) GKI_getbuf(len)) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_READ *) osi_malloc(len)) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_GATTC_API_READ));
 
         p_buf->hdr.event = BTA_GATTC_API_READ_EVT;
@@ -628,7 +628,7 @@ void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
                                p_read_multi->num_attr * sizeof(tBTA_GATTC_ATTR_ID));
     UINT8       i;
 
-    if ((p_buf = (tBTA_GATTC_API_READ_MULTI *) GKI_getbuf(len)) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_READ_MULTI *) osi_malloc(len)) != NULL) {
         memset(p_buf, 0, len);
 
         p_buf->hdr.event = BTA_GATTC_API_READ_MULTI_EVT;
@@ -674,7 +674,7 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
 {
     tBTA_GATTC_API_WRITE  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_GATTC_API_WRITE) + len);
 
         p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
@@ -723,7 +723,7 @@ void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
         len += p_data->len;
     }
 
-    if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf(len)) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc(len)) != NULL) {
         memset(p_buf, 0, len);
 
         p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
@@ -769,7 +769,7 @@ void BTA_GATTC_PrepareWrite  (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
 {
     tBTA_GATTC_API_WRITE  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_GATTC_API_WRITE) + len);
 
         p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
@@ -819,7 +819,7 @@ void BTA_GATTC_PrepareWriteCharDescr  (UINT16 conn_id, tBTA_GATTC_CHAR_DESCR_ID
         len += p_data->len;
     }
 
-    if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf(len)) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc(len)) != NULL) {
         memset(p_buf, 0, len);
 
         p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
@@ -861,7 +861,7 @@ void BTA_GATTC_ExecuteWrite  (UINT16 conn_id, BOOLEAN is_execute)
 {
     tBTA_GATTC_API_EXEC  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_EXEC *) GKI_getbuf((UINT16)sizeof(tBTA_GATTC_API_EXEC))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_EXEC *) osi_malloc((UINT16)sizeof(tBTA_GATTC_API_EXEC))) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_GATTC_API_EXEC));
 
         p_buf->hdr.event = BTA_GATTC_API_EXEC_EVT;
@@ -893,7 +893,7 @@ void BTA_GATTC_SendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id)
     APPL_TRACE_API("BTA_GATTC_SendIndConfirm conn_id=%d service uuid1=0x%x char uuid=0x%x",
                    conn_id, p_char_id->srvc_id.id.uuid.uu.uuid16, p_char_id->char_id.uuid.uu.uuid16);
 
-    if ((p_buf = (tBTA_GATTC_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_GATTC_API_CONFIRM))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_CONFIRM *) osi_malloc(sizeof(tBTA_GATTC_API_CONFIRM))) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_GATTC_API_CONFIRM));
 
         p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT;
@@ -1038,7 +1038,7 @@ void BTA_GATTC_Refresh(BD_ADDR remote_bda)
 {
     tBTA_GATTC_API_OPEN  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_OPEN *) GKI_getbuf(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
         p_buf->hdr.event = BTA_GATTC_API_REFRESH_EVT;
 
         memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
@@ -1068,7 +1068,7 @@ void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target
 {
     tBTA_GATTC_API_LISTEN  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_LISTEN *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
         p_buf->hdr.event = BTA_GATTC_API_LISTEN_EVT;
 
         p_buf->client_if = client_if;
@@ -1101,7 +1101,7 @@ void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start)
 {
     tBTA_GATTC_API_LISTEN  *p_buf;
 
-    if ((p_buf = (tBTA_GATTC_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
+    if ((p_buf = (tBTA_GATTC_API_LISTEN *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
         p_buf->hdr.event = BTA_GATTC_API_BROADCAST_EVT;
         p_buf->client_if = client_if;
         p_buf->start = start;
index b2d082da90f0a0600024d18d08fb277cfb6f322a..ff6207ab55e8752f741664bb909c84e5d6eb2ecd 100644 (file)
 
 #include <string.h>
 #include "utl.h"
-#include "gki.h"
 #include "bta_sys.h"
 #include "sdp_api.h"
 #include "sdpdefs.h"
 #include "bta_gattc_int.h"
 #include "btm_api.h"
 #include "btm_ble_api.h"
+#include "allocator.h"
 
 #define LOG_TAG "bt_bta_gattc"
 // #include "osi/include/log.h"
@@ -129,7 +129,7 @@ static void bta_gattc_display_explore_record(tBTA_GATTC_ATTR_REC *p_rec, UINT8 n
 **
 ** Function         bta_gattc_alloc_cache_buf
 **
-** Description      Allocate a GKI buffer for database cache.
+** Description      Allocate a buffer for database cache.
 **
 ** Returns          status
 **
@@ -138,17 +138,16 @@ BT_HDR *bta_gattc_alloc_cache_buf(tBTA_GATTC_SERV *p_srvc_cb)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf(GATT_DB_POOL_ID)) == NULL) {
-        APPL_TRACE_DEBUG("No resources: GKI buffer allocation failed.");
+    if ((p_buf = (BT_HDR *)osi_calloc(GATT_DB_BUF_SIZE)) == NULL) {
+        APPL_TRACE_DEBUG("No resources: buffer allocation failed.");
         utl_freebuf((void **)&p_srvc_cb->p_srvc_list);
         p_srvc_cb->free_byte = 0;
     } else {
-        memset(p_buf, 0, GKI_get_buf_size(p_buf));
         p_srvc_cb->p_free = (UINT8 *) p_buf;
-        p_srvc_cb->free_byte = GKI_get_buf_size(p_buf);
+        p_srvc_cb->free_byte = GATT_DB_BUF_SIZE;
 
         /* link into buffer queue */
-        GKI_enqueue(&p_srvc_cb->cache_buffer, p_buf);
+        fixed_queue_enqueue(p_srvc_cb->cache_buffer, p_buf);
     }
 #if BTA_GATT_DEBUG== TRUE
     APPL_TRACE_DEBUG("allocating new buffer: free byte = %d", p_srvc_cb->free_byte);
@@ -168,14 +167,14 @@ tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb)
 {
     tBTA_GATT_STATUS    status = BTA_GATT_OK;
 
-    while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer)) {
-        GKI_freebuf (GKI_dequeue (&p_srvc_cb->cache_buffer));
+    while (!fixed_queue_is_empty(p_srvc_cb->cache_buffer)) {
+        osi_free (fixed_queue_dequeue(p_srvc_cb->cache_buffer));
     }
 
     utl_freebuf((void **)&p_srvc_cb->p_srvc_list);
 
-    if ((p_srvc_cb->p_srvc_list = (tBTA_GATTC_ATTR_REC *)GKI_getbuf(BTA_GATTC_ATTR_LIST_SIZE)) == NULL) {
-        APPL_TRACE_DEBUG("No resources: GKI buffer allocation failed.");
+    if ((p_srvc_cb->p_srvc_list = (tBTA_GATTC_ATTR_REC *)osi_malloc(BTA_GATTC_ATTR_LIST_SIZE)) == NULL) {
+        APPL_TRACE_DEBUG("No resources: buffer allocation failed.");
         status = GATT_NO_RESOURCES;
     } else {
         p_srvc_cb->total_srvc = 0;
@@ -843,7 +842,7 @@ void bta_gattc_sdp_callback (UINT16 sdp_status)
         APPL_TRACE_ERROR("GATT service discovery is done on unknown connection");
     }
 
-    GKI_freebuf(bta_gattc_cb.p_sdp_db);
+    osi_free(bta_gattc_cb.p_sdp_db);
     bta_gattc_cb.p_sdp_db  = NULL;
     bta_gattc_cb.sdp_conn_id = 0;
 }
@@ -871,7 +870,7 @@ static tBTA_GATT_STATUS bta_gattc_sdp_service_disc(UINT16 conn_id, tBTA_GATTC_SE
     uuid.len = LEN_UUID_16;
     uuid.uu.uuid16 = UUID_PROTOCOL_ATT;
 
-    if ((bta_gattc_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)GKI_getbuf(BTA_GATT_SDP_DB_SIZE)) != NULL) {
+    if ((bta_gattc_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(BTA_GATT_SDP_DB_SIZE)) != NULL) {
         attr_list[0] = ATTR_ID_SERVICE_CLASS_ID_LIST;
         attr_list[1] = ATTR_ID_PROTOCOL_DESC_LIST;
 
@@ -880,7 +879,7 @@ static tBTA_GATT_STATUS bta_gattc_sdp_service_disc(UINT16 conn_id, tBTA_GATTC_SE
 
         if (!SDP_ServiceSearchAttributeRequest (p_server_cb->server_bda,
                                                 bta_gattc_cb.p_sdp_db, &bta_gattc_sdp_callback)) {
-            GKI_freebuf(bta_gattc_cb.p_sdp_db);
+            osi_free(bta_gattc_cb.p_sdp_db);
             bta_gattc_cb.p_sdp_db = NULL;
         } else {
             bta_gattc_cb.sdp_conn_id = conn_id;
@@ -1390,8 +1389,8 @@ void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srvc_cb, UINT16 num_attr,
     /* first attribute loading, initialize buffer */
     APPL_TRACE_ERROR("bta_gattc_rebuild_cache");
     if (attr_index == 0) {
-        while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer)) {
-            GKI_freebuf (GKI_dequeue (&p_srvc_cb->cache_buffer));
+        while (!fixed_queue_is_empty(p_srvc_cb->cache_buffer)) {
+            osi_free(fixed_queue_dequeue(p_srvc_cb->cache_buffer));
         }
 
         if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL) {
index 8c94a991c169dc6adb9263fe5f95a8fb76d48d40..19e7748fcef1cb5c054f6d1c80a9365a1ab12395 100644 (file)
@@ -31,8 +31,9 @@
 #include "bta_api.h"
 #include "bta_sys.h"
 #include "bta_gattc_ci.h"
-#include "gki.h"
 #include "utl.h"
+#include "allocator.h"
+
 
 /*******************************************************************************
 **
@@ -54,7 +55,7 @@ void bta_gattc_ci_cache_open(BD_ADDR server_bda, UINT16 evt, tBTA_GATT_STATUS st
     tBTA_GATTC_CI_EVT  *p_evt;
     UNUSED(server_bda);
 
-    if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL) {
+    if ((p_evt = (tBTA_GATTC_CI_EVT *) osi_malloc(sizeof(tBTA_GATTC_CI_EVT))) != NULL) {
         p_evt->hdr.event = evt;
         p_evt->hdr.layer_specific = conn_id;
 
@@ -86,7 +87,7 @@ void bta_gattc_ci_cache_load(BD_ADDR server_bda, UINT16 evt, UINT16 num_attr,
     tBTA_GATTC_CI_LOAD  *p_evt;
     UNUSED(server_bda);
 
-    if ((p_evt = (tBTA_GATTC_CI_LOAD *) GKI_getbuf(sizeof(tBTA_GATTC_CI_LOAD))) != NULL) {
+    if ((p_evt = (tBTA_GATTC_CI_LOAD *) osi_malloc(sizeof(tBTA_GATTC_CI_LOAD))) != NULL) {
         memset(p_evt, 0, sizeof(tBTA_GATTC_CI_LOAD));
 
         p_evt->hdr.event = evt;
@@ -125,7 +126,7 @@ void bta_gattc_ci_cache_save(BD_ADDR server_bda, UINT16 evt, tBTA_GATT_STATUS st
     tBTA_GATTC_CI_EVT  *p_evt;
     UNUSED(server_bda);
 
-    if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL) {
+    if ((p_evt = (tBTA_GATTC_CI_EVT *) osi_malloc(sizeof(tBTA_GATTC_CI_EVT))) != NULL) {
         p_evt->hdr.event = evt;
         p_evt->hdr.layer_specific = conn_id;
 
index 5045ff1475ec5db2656252891e68b758a085151b..995d74cfd7c090286eac8bb896decbef6cbd3480 100644 (file)
@@ -29,7 +29,6 @@
 #include <string.h>
 
 #include "bta_gattc_int.h"
-#include "gki.h"
 
 
 /*****************************************************************************
index 0a878e48b376cf892d4359eeae85292978b4b662..30a0b395ae71b6f79af9478074c126153bfe41a8 100644 (file)
 
 #include "bdaddr.h"
 // #include "btif/include/btif_util.h"
-#include "gki.h"
 #include "utl.h"
 #include "bta_sys.h"
 #include "bta_gattc_int.h"
 #include "l2c_api.h"
+#include "allocator.h"
 
 #define LOG_TAG "bt_bta_gattc"
 /*****************************************************************************
@@ -401,8 +401,11 @@ tBTA_GATTC_SERV *bta_gattc_srcb_alloc(BD_ADDR bda)
     }
 
     if (p_tcb != NULL) {
-        while (!GKI_queue_is_empty(&p_tcb->cache_buffer)) {
-            GKI_freebuf (GKI_dequeue (&p_tcb->cache_buffer));
+        if (p_tcb->cache_buffer) {
+            while (!fixed_queue_is_empty(p_tcb->cache_buffer)) {
+                osi_free(fixed_queue_dequeue(p_tcb->cache_buffer));
+            }
+            fixed_queue_free(p_tcb->cache_buffer, NULL);
         }
 
         utl_freebuf((void **)&p_tcb->p_srvc_list);
@@ -410,6 +413,8 @@ tBTA_GATTC_SERV *bta_gattc_srcb_alloc(BD_ADDR bda)
 
         p_tcb->in_use = TRUE;
         bdcpy(p_tcb->server_bda, bda);
+
+        p_tcb->cache_buffer = fixed_queue_new(SIZE_MAX); //by Snake
     }
     return p_tcb;
 }
index 414b1e5758f99aefc513fa4211b4070fa9163bad..c617fef829173ddcce338e3b76fc09f54ef70d74 100644 (file)
 #if defined(GATTS_INCLUDED) && (GATTS_INCLUDED == TRUE)
 
 #include "utl.h"
-#include "gki.h"
 #include "bta_sys.h"
 #include "bta_gatts_int.h"
 #include "bta_gatts_co.h"
 #include "btm_ble_api.h"
 #include <string.h>
+#include "allocator.h"
 
 static void bta_gatts_nv_save_cback(BOOLEAN is_saved, tGATTS_HNDL_RANGE *p_hndl_range);
 static BOOLEAN bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd, tGATTS_SRV_CHG_REQ *p_req,
@@ -213,7 +213,7 @@ void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
                 status = BTA_GATT_NO_RESOURCES;
             } else {
                 if ((p_buf =
-                            (tBTA_GATTS_INT_START_IF *) GKI_getbuf(sizeof(tBTA_GATTS_INT_START_IF))) != NULL) {
+                            (tBTA_GATTS_INT_START_IF *) osi_malloc(sizeof(tBTA_GATTS_INT_START_IF))) != NULL) {
                     p_buf->hdr.event    = BTA_GATTS_INT_START_IF_EVT;
                     p_buf->server_if    = p_cb->rcb[first_unuse].gatt_if;
 
@@ -432,7 +432,7 @@ void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
         cb_data.add_result.status = BTA_GATT_ERROR;
     }
     if((p_attr_val != NULL) && (p_attr_val->attr_val != NULL)){
-        GKI_freebuf(p_attr_val->attr_val);
+        osi_free(p_attr_val->attr_val);
     }
 
     if (p_rcb->p_cback) {
@@ -482,7 +482,7 @@ void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
         cb_data.add_result.status = BTA_GATT_ERROR;
     }
     if((p_attr_val != NULL) && (p_attr_val->attr_val != NULL)){
-        GKI_freebuf(p_attr_val->attr_val);
+        osi_free(p_attr_val->attr_val);
     }
 
     if (p_rcb->p_cback) {
@@ -516,7 +516,7 @@ void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
     cb_data.attr_val.status = gatts_status;
 
     if (p_msg->api_set_val.value  != NULL){
-        GKI_freebuf(p_msg->api_set_val.value);
+        osi_free(p_msg->api_set_val.value);
     }
 
     if (p_rcb->p_cback) {
index 1e7940a85b10600ffb38c66aeecb9cb2f99c5874..9228fa5fd5ded8ced6d736c48b9073ade281f0ba 100644 (file)
 #if defined(GATTS_INCLUDED) && (GATTS_INCLUDED == TRUE)
 
 #include <string.h>
-#include "gki.h"
 #include "bta_sys.h"
 #include "bta_gatt_api.h"
 #include "bta_gatts_int.h"
+#include "allocator.h"
 
 /*****************************************************************************
 **  Constants
@@ -61,7 +61,7 @@ void BTA_GATTS_Disable(void)
         return;
     }
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_GATTS_API_DISABLE_EVT;
         bta_sys_sendmsg(p_buf);
     }
@@ -91,7 +91,7 @@ void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback)
         bta_sys_register(BTA_ID_GATTS, &bta_gatts_reg);
     }
 
-    if ((p_buf = (tBTA_GATTS_API_REG *) GKI_getbuf(sizeof(tBTA_GATTS_API_REG))) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_REG *) osi_malloc(sizeof(tBTA_GATTS_API_REG))) != NULL) {
         p_buf->hdr.event    = BTA_GATTS_API_REG_EVT;
 
         if (p_app_uuid != NULL) {
@@ -121,7 +121,7 @@ void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if)
 {
     tBTA_GATTS_API_DEREG  *p_buf;
 
-    if ((p_buf = (tBTA_GATTS_API_DEREG *) GKI_getbuf(sizeof(tBTA_GATTS_API_DEREG))) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_DEREG *) osi_malloc(sizeof(tBTA_GATTS_API_DEREG))) != NULL) {
         p_buf->hdr.event    = BTA_GATTS_API_DEREG_EVT;
         p_buf->server_if    = server_if;
 
@@ -154,7 +154,7 @@ void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid,
 {
     tBTA_GATTS_API_CREATE_SRVC  *p_buf;
 
-    if ((p_buf = (tBTA_GATTS_API_CREATE_SRVC *) GKI_getbuf(sizeof(tBTA_GATTS_API_CREATE_SRVC))) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_CREATE_SRVC *) osi_malloc(sizeof(tBTA_GATTS_API_CREATE_SRVC))) != NULL) {
         p_buf->hdr.event = BTA_GATTS_API_CREATE_SRVC_EVT;
 
         p_buf->server_if = server_if;
@@ -187,7 +187,7 @@ void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id)
     tBTA_GATTS_API_ADD_INCL_SRVC  *p_buf;
 
     if ((p_buf =
-                (tBTA_GATTS_API_ADD_INCL_SRVC *) GKI_getbuf(sizeof(tBTA_GATTS_API_ADD_INCL_SRVC)))
+                (tBTA_GATTS_API_ADD_INCL_SRVC *) osi_malloc(sizeof(tBTA_GATTS_API_ADD_INCL_SRVC)))
             != NULL) {
         p_buf->hdr.event = BTA_GATTS_API_ADD_INCL_SRVC_EVT;
 
@@ -223,7 +223,7 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id,  tBT_UUID  *p_char_uuid,
     if(attr_val != NULL){
         len = attr_val->attr_len;
     }
-    if ((p_buf = (tBTA_GATTS_API_ADD_CHAR *) GKI_getbuf(sizeof(tBTA_GATTS_API_ADD_CHAR))) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_ADD_CHAR *) osi_malloc(sizeof(tBTA_GATTS_API_ADD_CHAR))) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_GATTS_API_ADD_CHAR));
 
         p_buf->hdr.event = BTA_GATTS_API_ADD_CHAR_EVT;
@@ -238,7 +238,7 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id,  tBT_UUID  *p_char_uuid,
             APPL_TRACE_DEBUG("!!!!!!!attr_val->attr_max_len = %x\n",attr_val->attr_max_len);
             p_buf->attr_val.attr_len = attr_val->attr_len;
             p_buf->attr_val.attr_max_len = attr_val->attr_max_len;
-            p_buf->attr_val.attr_val = (uint8_t *)GKI_getbuf(len);
+            p_buf->attr_val.attr_val = (uint8_t *)osi_malloc(len);
             if(p_buf->attr_val.attr_val != NULL){
                 memcpy(p_buf->attr_val.attr_val, attr_val->attr_val, attr_val->attr_len);
             }
@@ -276,7 +276,7 @@ void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
     tBTA_GATTS_API_ADD_DESCR  *p_buf;
     UINT16  value_len = 0;
 
-    if ((p_buf = (tBTA_GATTS_API_ADD_DESCR *) GKI_getbuf(sizeof(tBTA_GATTS_API_ADD_DESCR))) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_ADD_DESCR *) osi_malloc(sizeof(tBTA_GATTS_API_ADD_DESCR))) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_GATTS_API_ADD_DESCR));
 
         p_buf->hdr.event = BTA_GATTS_API_ADD_DESCR_EVT;
@@ -296,7 +296,7 @@ void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
             p_buf->attr_val.attr_max_len = attr_val->attr_max_len;
             value_len =  attr_val->attr_len;
             if (value_len != 0){
-                p_buf->attr_val.attr_val = (uint8_t*)GKI_getbuf(value_len);
+                p_buf->attr_val.attr_val = (uint8_t*)osi_malloc(value_len);
                 if(p_buf->attr_val.attr_val != NULL){
                     memcpy(p_buf->attr_val.attr_val, attr_val->attr_val, value_len);
                 }
@@ -329,7 +329,7 @@ void  BTA_GATTS_DeleteService(UINT16 service_id)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_GATTS_API_DEL_SRVC_EVT;
 
         p_buf->layer_specific = service_id;
@@ -356,7 +356,7 @@ void  BTA_GATTS_StartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transpor
 {
     tBTA_GATTS_API_START  *p_buf;
 
-    if ((p_buf = (tBTA_GATTS_API_START *) GKI_getbuf(sizeof(tBTA_GATTS_API_START))) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_START *) osi_malloc(sizeof(tBTA_GATTS_API_START))) != NULL) {
         p_buf->hdr.event = BTA_GATTS_API_START_SRVC_EVT;
 
         p_buf->hdr.layer_specific = service_id;
@@ -382,7 +382,7 @@ void BTA_GATTS_StopService(UINT16 service_id)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_GATTS_API_STOP_SRVC_EVT;
 
         p_buf->layer_specific = service_id;
@@ -413,7 +413,7 @@ void BTA_GATTS_HandleValueIndication (UINT16 conn_id, UINT16 attr_id, UINT16 dat
     tBTA_GATTS_API_INDICATION  *p_buf;
     UINT16  len = sizeof(tBTA_GATTS_API_INDICATION);
 
-    if ((p_buf = (tBTA_GATTS_API_INDICATION *) GKI_getbuf(len)) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_INDICATION *) osi_malloc(len)) != NULL) {
         memset(p_buf, 0, len);
 
         p_buf->hdr.event = BTA_GATTS_API_INDICATION_EVT;
@@ -451,7 +451,7 @@ void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id,
     tBTA_GATTS_API_RSP  *p_buf;
     UINT16  len = sizeof(tBTA_GATTS_API_RSP) + sizeof(tBTA_GATTS_RSP);
 
-    if ((p_buf = (tBTA_GATTS_API_RSP *) GKI_getbuf(len)) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_RSP *) osi_malloc(len)) != NULL) {
         memset(p_buf, 0, len);
 
         p_buf->hdr.event    = BTA_GATTS_API_RSP_EVT;
@@ -474,13 +474,13 @@ void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id,
 void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value)
 {
     tBTA_GATTS_API_SET_ATTR_VAL *p_buf;
-    if((p_buf = (tBTA_GATTS_API_SET_ATTR_VAL *)GKI_getbuf(
+    if((p_buf = (tBTA_GATTS_API_SET_ATTR_VAL *)osi_malloc(
                     sizeof(tBTA_GATTS_API_SET_ATTR_VAL))) != NULL){
         p_buf->hdr.event = BTA_GATTS_API_SET_ATTR_VAL_EVT;
         p_buf->hdr.layer_specific = attr_handle;
         p_buf->length = length;
         if(value != NULL){
-            if((p_buf->value = (UINT8 *)GKI_getbuf(length)) != NULL){
+            if((p_buf->value = (UINT8 *)osi_malloc(length)) != NULL){
                 memcpy(p_buf->value, value, length);
             }
         }
@@ -515,7 +515,7 @@ void BTA_GATTS_Open(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_dire
 {
     tBTA_GATTS_API_OPEN  *p_buf;
 
-    if ((p_buf = (tBTA_GATTS_API_OPEN *) GKI_getbuf(sizeof(tBTA_GATTS_API_OPEN))) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_OPEN *) osi_malloc(sizeof(tBTA_GATTS_API_OPEN))) != NULL) {
         p_buf->hdr.event = BTA_GATTS_API_OPEN_EVT;
         p_buf->server_if = server_if;
         p_buf->is_direct = is_direct;
@@ -546,7 +546,7 @@ void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN i
 {
     tBTA_GATTS_API_CANCEL_OPEN  *p_buf;
 
-    if ((p_buf = (tBTA_GATTS_API_CANCEL_OPEN *) GKI_getbuf(sizeof(tBTA_GATTS_API_CANCEL_OPEN))) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_CANCEL_OPEN *) osi_malloc(sizeof(tBTA_GATTS_API_CANCEL_OPEN))) != NULL) {
         p_buf->hdr.event = BTA_GATTS_API_CANCEL_OPEN_EVT;
         p_buf->server_if = server_if;
         p_buf->is_direct = is_direct;
@@ -571,7 +571,7 @@ void BTA_GATTS_Close(UINT16 conn_id)
 {
     BT_HDR  *p_buf;
 
-    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_GATTS_API_CLOSE_EVT;
         p_buf->layer_specific = conn_id;
         bta_sys_sendmsg(p_buf);
@@ -598,7 +598,7 @@ void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start, BD_ADDR_PTR target
 {
     tBTA_GATTS_API_LISTEN  *p_buf;
 
-    if ((p_buf = (tBTA_GATTS_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTS_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
+    if ((p_buf = (tBTA_GATTS_API_LISTEN *) osi_malloc((UINT16)(sizeof(tBTA_GATTS_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
         p_buf->hdr.event = BTA_GATTS_API_LISTEN_EVT;
 
         p_buf->server_if    = server_if;
index 1340b13995abc25344db5189cad09386b1d4281a..dc0cb425c09df46fa1873b90c0f2ce208da7e7c1 100644 (file)
@@ -29,7 +29,6 @@
 #include <string.h>
 
 #include "bta_gatts_int.h"
-#include "gki.h"
 
 /* type for service building action functions */
 typedef void (*tBTA_GATTS_SRVC_ACT)(tBTA_GATTS_SRVC_CB *p_rcb, tBTA_GATTS_DATA *p_data);
index 1904d7498505440aece1aacca52f6bec7e26d493..1862c72d340192cd09ed5fb50ee0ab35fe7e194d 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <string.h>
 #include "utl.h"
-#include "gki.h"
 #include "bta_sys.h"
 #include "bta_gatts_int.h"
 
index e874ed3109117476c1e2e84047bb3d7aa09fabc0..eb0cf7a2af0fe1dbcdbd06e44fead5310ea2968c 100644 (file)
@@ -356,7 +356,7 @@ void bta_hh_start_sdp(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
     }
     /* GetSDPRecord. at one time only one SDP precedure can be active */
     else if (!bta_hh_cb.p_disc_db) {
-        bta_hh_cb.p_disc_db = (tSDP_DISCOVERY_DB *) GKI_getbuf(p_bta_hh_cfg->sdp_db_size);
+        bta_hh_cb.p_disc_db = (tSDP_DISCOVERY_DB *) osi_malloc(p_bta_hh_cfg->sdp_db_size);
 
         if (bta_hh_cb.p_disc_db == NULL) {
             status = BTA_HH_ERR_NO_RES;
@@ -1156,7 +1156,7 @@ static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
     }
 
     if (sm_event != BTA_HH_INVALID_EVT &&
-            (p_buf = (tBTA_HH_CBACK_DATA *)GKI_getbuf(sizeof(tBTA_HH_CBACK_DATA) +
+            (p_buf = (tBTA_HH_CBACK_DATA *)osi_malloc(sizeof(tBTA_HH_CBACK_DATA) +
                      sizeof(BT_HDR))) != NULL) {
         p_buf->hdr.event  = sm_event;
         p_buf->hdr.layer_specific = (UINT16)dev_handle;
index efc00561c728a41856cda117cdbe96744280aeff..3887ed8d112eef46315f93a8fa9e4d1695c27baa 100644 (file)
@@ -68,7 +68,7 @@ void BTA_HhEnable(tBTA_SEC sec_mask, tBTA_HH_CBACK *p_cback)
     bta_sys_register(BTA_ID_HH, &bta_hh_reg);
 
     LOG_INFO("%s sec_mask:0x%x p_cback:%p", __func__, sec_mask, p_cback);
-    p_buf = (tBTA_HH_API_ENABLE *)GKI_getbuf((UINT16)sizeof(tBTA_HH_API_ENABLE));
+    p_buf = (tBTA_HH_API_ENABLE *)osi_malloc((UINT16)sizeof(tBTA_HH_API_ENABLE));
 
     if (p_buf != NULL) {
         memset(p_buf, 0, sizeof(tBTA_HH_API_ENABLE));
@@ -96,7 +96,7 @@ void BTA_HhDisable(void)
     BT_HDR  *p_buf;
 
     bta_sys_deregister(BTA_ID_HH);
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_HH_API_DISABLE_EVT;
         bta_sys_sendmsg(p_buf);
     }
@@ -115,7 +115,7 @@ void BTA_HhClose(UINT8 dev_handle)
 {
     BT_HDR    *p_buf;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf((UINT16)sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc((UINT16)sizeof(BT_HDR))) != NULL) {
         memset(p_buf, 0, sizeof(BT_HDR));
         p_buf->event            = BTA_HH_API_CLOSE_EVT;
         p_buf->layer_specific   = (UINT16) dev_handle;
@@ -138,7 +138,7 @@ void BTA_HhOpen(BD_ADDR dev_bda, tBTA_HH_PROTO_MODE mode, tBTA_SEC sec_mask)
 {
     tBTA_HH_API_CONN *p_buf;
 
-    p_buf = (tBTA_HH_API_CONN *)GKI_getbuf((UINT16)sizeof(tBTA_HH_API_CONN));
+    p_buf = (tBTA_HH_API_CONN *)osi_malloc((UINT16)sizeof(tBTA_HH_API_CONN));
 
     if (p_buf != NULL) {
         memset((void *)p_buf, 0, sizeof(tBTA_HH_API_CONN));
@@ -166,7 +166,7 @@ static void bta_hh_snd_write_dev(UINT8 dev_handle, UINT8 t_type, UINT8 param,
     tBTA_HH_CMD_DATA *p_buf;
     UINT16          len = (UINT16) (sizeof(tBTA_HH_CMD_DATA) );
 
-    if ((p_buf = (tBTA_HH_CMD_DATA *)GKI_getbuf(len)) != NULL) {
+    if ((p_buf = (tBTA_HH_CMD_DATA *)osi_malloc(len)) != NULL) {
         memset(p_buf, 0, sizeof(tBTA_HH_CMD_DATA));
 
         p_buf->hdr.event = BTA_HH_API_WRITE_DEV_EVT;
@@ -322,7 +322,7 @@ void BTA_HhGetDscpInfo(UINT8 dev_handle)
 {
     BT_HDR    *p_buf;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf((UINT16)sizeof(BT_HDR))) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc((UINT16)sizeof(BT_HDR))) != NULL) {
         memset(p_buf, 0, sizeof(BT_HDR));
         p_buf->event            = BTA_HH_API_GET_DSCP_EVT;
         p_buf->layer_specific   = (UINT16) dev_handle;
@@ -349,7 +349,7 @@ void BTA_HhAddDev(BD_ADDR bda, tBTA_HH_ATTR_MASK attr_mask, UINT8 sub_class,
     tBTA_HH_MAINT_DEV    *p_buf;
     UINT16  len = sizeof(tBTA_HH_MAINT_DEV) + dscp_info.descriptor.dl_len;
 
-    p_buf = (tBTA_HH_MAINT_DEV *)GKI_getbuf(len);
+    p_buf = (tBTA_HH_MAINT_DEV *)osi_malloc(len);
 
     if (p_buf != NULL) {
         memset(p_buf, 0, sizeof(tBTA_HH_MAINT_DEV));
@@ -389,7 +389,7 @@ void BTA_HhRemoveDev(UINT8 dev_handle )
 {
     tBTA_HH_MAINT_DEV    *p_buf;
 
-    p_buf = (tBTA_HH_MAINT_DEV *)GKI_getbuf((UINT16)sizeof(tBTA_HH_MAINT_DEV));
+    p_buf = (tBTA_HH_MAINT_DEV *)osi_malloc((UINT16)sizeof(tBTA_HH_MAINT_DEV));
 
     if (p_buf != NULL) {
         memset(p_buf, 0, sizeof(tBTA_HH_MAINT_DEV));
@@ -417,7 +417,7 @@ void BTA_HhUpdateLeScanParam(UINT8 dev_handle, UINT16 scan_int, UINT16 scan_win)
 {
     tBTA_HH_SCPP_UPDATE    *p_buf;
 
-    p_buf = (tBTA_HH_SCPP_UPDATE *)GKI_getbuf((UINT16)sizeof(tBTA_HH_SCPP_UPDATE));
+    p_buf = (tBTA_HH_SCPP_UPDATE *)osi_malloc((UINT16)sizeof(tBTA_HH_SCPP_UPDATE));
 
     if (p_buf != NULL) {
         memset(p_buf, 0, sizeof(tBTA_HH_SCPP_UPDATE));
index d80de5e8b9b6bb2fd0946411c2eac80c047e1212..9362a5d75fe9ff429282d6ee2df65dab009847b9 100644 (file)
@@ -34,7 +34,7 @@
 
 /* size of database for service discovery */
 #ifndef BTA_HH_DISC_BUF_SIZE
-#define BTA_HH_DISC_BUF_SIZE        GKI_MAX_BUF_SIZE
+#define BTA_HH_DISC_BUF_SIZE        BT_DEFAULT_BUFFER_SIZE
 #endif
 
 
@@ -61,4 +61,4 @@ const tBTA_HH_CFG bta_hh_cfg = {
 
 
 tBTA_HH_CFG *p_bta_hh_cfg = (tBTA_HH_CFG *) &bta_hh_cfg;
-#endif  ///defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE)
\ No newline at end of file
+#endif  ///defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE)
index b8d8a4e6edd52e0f74e65794cd22bef5e02c919f..163656fd2dd6ca3fe0af67e2cdb2b5d74f6d7b4d 100644 (file)
@@ -1425,7 +1425,7 @@ void bta_hh_le_close(tBTA_GATTC_CLOSE *p_data)
     UINT16  sm_event = BTA_HH_GATT_CLOSE_EVT;
 
     if (p_dev_cb != NULL &&
-            (p_buf = (tBTA_HH_LE_CLOSE *)GKI_getbuf(sizeof(tBTA_HH_LE_CLOSE))) != NULL) {
+            (p_buf = (tBTA_HH_LE_CLOSE *)osi_malloc(sizeof(tBTA_HH_LE_CLOSE))) != NULL) {
         p_buf->hdr.event            = sm_event;
         p_buf->hdr.layer_specific   = (UINT16)p_dev_cb->hid_handle;
         p_buf->conn_id              = p_data->conn_id;
@@ -1757,11 +1757,11 @@ void bta_hh_le_save_rpt_map(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_READ *p_data)
 
     /* save report descriptor */
     if (p_srvc->rpt_map != NULL) {
-        GKI_freebuf((void *)p_srvc->rpt_map);
+        osi_free((void *)p_srvc->rpt_map);
     }
 
     if (p_data->p_value->unformat.len > 0) {
-        p_srvc->rpt_map = (UINT8 *)GKI_getbuf(p_data->p_value->unformat.len);
+        p_srvc->rpt_map = (UINT8 *)osi_malloc(p_data->p_value->unformat.len);
     }
 
     if (p_srvc->rpt_map != NULL) {
@@ -1814,7 +1814,7 @@ void bta_hh_le_proc_get_rpt_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_READ *p_da
 
         if (p_rpt != NULL &&
                 p_data->p_value != NULL &&
-                (p_buf = (BT_HDR *)GKI_getbuf((UINT16)(sizeof(BT_HDR) + p_data->p_value->unformat.len + 1))) != NULL) {
+                (p_buf = (BT_HDR *)osi_malloc((UINT16)(sizeof(BT_HDR) + p_data->p_value->unformat.len + 1))) != NULL) {
             /* pack data send to app */
             hs_data.status  = BTA_HH_OK;
             p_buf->len = p_data->p_value->unformat.len + 1;
@@ -2252,7 +2252,7 @@ void bta_hh_le_input_rpt_notify(tBTA_GATTC_NOTIFY *p_data)
 
     /* need to append report ID to the head of data */
     if (p_rpt->rpt_id != 0) {
-        if ((p_buf = (UINT8 *)GKI_getbuf((UINT16)(p_data->len + 1))) == NULL) {
+        if ((p_buf = (UINT8 *)osi_malloc((UINT16)(p_data->len + 1))) == NULL) {
             APPL_TRACE_ERROR("No resources to send report data");
             return;
         }
@@ -2274,7 +2274,7 @@ void bta_hh_le_input_rpt_notify(tBTA_GATTC_NOTIFY *p_data)
                    app_id);
 
     if (p_buf != p_data->value) {
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
     }
 }
 
@@ -2436,7 +2436,7 @@ void bta_hh_le_write_rpt(tBTA_HH_DEV_CB *p_cb, UINT8 srvc_inst,
 
     if (p_rpt == NULL) {
         APPL_TRACE_ERROR("bta_hh_le_write_rpt: no matching report");
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
         return;
     }
 
index 7959b397755f9971b957ce79293d006540179c7a..aeee1061e01573bee445fec7bb59193ed849e7ce 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "bta_hh_api.h"
 #include "bta_hh_int.h"
-#include "gki.h"
 
 /*****************************************************************************
 ** Constants and types
@@ -308,7 +307,7 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA *p_data)
                 cback_event = (p_data->api_sndcmd.t_type - BTA_HH_FST_BTE_TRANS_EVT) +
                               BTA_HH_FST_TRANS_CB_EVT;
                 if (p_data->api_sndcmd.p_data != NULL) {
-                    GKI_freebuf(p_data->api_sndcmd.p_data);
+                    osi_free(p_data->api_sndcmd.p_data);
                 }
                 if (p_data->api_sndcmd.t_type == HID_TRANS_SET_PROTOCOL ||
                         p_data->api_sndcmd.t_type == HID_TRANS_SET_REPORT ||
@@ -341,7 +340,7 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA *p_data)
                 APPL_TRACE_ERROR("wrong device handle: [%d]", p_data->hdr.layer_specific);
                 /* Free the callback buffer now */
                 if (p_data != NULL && p_data->hid_cback.p_data != NULL) {
-                    GKI_freebuf(p_data->hid_cback.p_data);
+                    osi_free(p_data->hid_cback.p_data);
                     p_data->hid_cback.p_data = NULL;
                 }
                 break;
index d90f516e59c7b860aedb4d13e36c31fd82636c6a..16abfee73069e799cbd43608f46dea52b39449b1 100644 (file)
@@ -201,7 +201,7 @@ void bta_hh_add_device_to_list(tBTA_HH_DEV_CB *p_cb, UINT8 handle,
 
         if (p_dscp_info->dl_len &&
                 (p_cb->dscp_info.descriptor.dsc_list =
-                     (UINT8 *)GKI_getbuf(p_dscp_info->dl_len)) != NULL) {
+                     (UINT8 *)osi_malloc(p_dscp_info->dl_len)) != NULL) {
             p_cb->dscp_info.descriptor.dl_len = p_dscp_info->dl_len;
             memcpy(p_cb->dscp_info.descriptor.dsc_list, p_dscp_info->dsc_list,
                    p_dscp_info->dl_len);
index c2f94b63521bfaf2786120ee0f3ab38a7db8f5e7..3f7f989d6c98ae0e9d12f86b103b3e7f2eb4ebd5 100644 (file)
@@ -304,7 +304,7 @@ extern void bta_av_co_video_stop(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type);
 **                  the audio codec
 **
 ** Returns          NULL if data is not ready.
-**                  Otherwise, a GKI buffer (BT_HDR*) containing the audio data.
+**                  Otherwise, a buffer (BT_HDR*) containing the audio data.
 **
 *******************************************************************************/
 extern void *bta_av_co_audio_src_data_path(tBTA_AV_CODEC codec_type,
index 21cd4259453e980668f3b46241d06245bbeddc5c..3b71438e81f3d4b5b8dbcce7fdb4e3f6d784a5af 100644 (file)
@@ -29,7 +29,7 @@
 #include "bta_gatt_api.h"
 #include "bta_gattc_ci.h"
 #include "bta_gattc_co.h"
-#include "gki.h"
+#include "fixed_queue.h"
 
 /*****************************************************************************
 **  Constants and data types
@@ -302,7 +302,7 @@ typedef struct {
 
     tBTA_GATTC_CACHE    *p_srvc_cache;
     tBTA_GATTC_CACHE    *p_cur_srvc;
-    BUFFER_Q            cache_buffer;   /* buffer queue used for storing the cache data */
+    fixed_queue_t       *cache_buffer;   /* buffer queue used for storing the cache data */
     UINT8               *p_free;        /* starting point to next available byte */
     UINT16              free_byte;      /* number of available bytes in server cache buffer */
     UINT8               update_count;   /* indication received */
index 03920ddfd7ae8c0c81de40ba101c3796430bb0fe..211929f207586f40514e88aa9ecb4dddf123fe00 100644 (file)
@@ -29,7 +29,6 @@
 #include "bta_gatt_api.h"
 #include "gatt_api.h"
 
-#include "gki.h"
 
 /*****************************************************************************
 **  Constants and data types
index 808edbb4c5ed3161169cf2eed9060486bceb13a2..94ebd805086e30adf16323a51ec579e39d45b44a 100644 (file)
@@ -25,7 +25,7 @@
 #define BTA_SYS_H
 
 #include "bt_target.h"
-#include "gki.h"
+#include "bt_defs.h"
 
 /*****************************************************************************
 **  Constants and data types
index 39dbe297d9213fd3572f74d058a6c526e60897b1..eab971e7dc60f5a9683a13ab2689e9663e59d5df 100644 (file)
@@ -105,7 +105,7 @@ extern UINT8 utl_itoa(UINT16 i, char *p_s);
 **
 ** Function         utl_freebuf
 **
-** Description      This function calls GKI_freebuf to free the buffer passed
+** Description      This function calls osi_free to free the buffer passed
 **                  in, if buffer pointer is not NULL, and also initializes
 **                  buffer pointer to NULL.
 **
index 702a5cf4f391c100028b0ae150cc842a5974af75..21e3fd17354d30b82acb630969a3cf6a2897f809 100644 (file)
@@ -29,7 +29,6 @@
 #include "bt_target.h"
 #include "allocator.h"
 #include "bt_types.h"
-#include "gki.h"
 #include "utl.h"
 #include "bta_sys.h"
 #include "bta_api.h"
index cbbf0f47555e7a5686b56d28d6a2919a4d64545a..c49d38e8c0ef30e5fa7d63c9b7dc6d41d69e3cd6 100644 (file)
@@ -27,9 +27,8 @@
 #include "bta_sys.h"
 #include "bta_sdp_api.h"
 #include "bta_sdp_int.h"
-#include "gki.h"
 #include <string.h>
-// #include "port_api.h"
+#include "allocator.h"
 #include "sdp_api.h"
 
 #if defined(BTA_SDP_INCLUDED) && (BTA_SDP_INCLUDED == TRUE)
@@ -69,7 +68,7 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
         bta_sys_register(BTA_ID_SDP, &bta_sdp_reg);
 
         if (p_cback &&
-                (p_buf = (tBTA_SDP_API_ENABLE *) GKI_getbuf(sizeof(tBTA_SDP_API_ENABLE))) != NULL) {
+                (p_buf = (tBTA_SDP_API_ENABLE *) osi_malloc(sizeof(tBTA_SDP_API_ENABLE))) != NULL) {
             p_buf->hdr.event = BTA_SDP_API_ENABLE_EVT;
             p_buf->p_cback = p_cback;
             bta_sys_sendmsg(p_buf);
@@ -98,7 +97,7 @@ tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
     tBTA_SDP_API_SEARCH *p_msg;
 
     APPL_TRACE_API("%s\n", __FUNCTION__);
-    if ((p_msg = (tBTA_SDP_API_SEARCH *)GKI_getbuf(sizeof(tBTA_SDP_API_SEARCH))) != NULL) {
+    if ((p_msg = (tBTA_SDP_API_SEARCH *)osi_malloc(sizeof(tBTA_SDP_API_SEARCH))) != NULL) {
         p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
         bdcpy(p_msg->bd_addr, bd_addr);
         //p_msg->uuid = uuid;
@@ -128,7 +127,7 @@ tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void *user_data)
     tBTA_SDP_API_RECORD_USER *p_msg;
 
     APPL_TRACE_API("%s\n", __FUNCTION__);
-    if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
+    if ((p_msg = (tBTA_SDP_API_RECORD_USER *)osi_malloc(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
         p_msg->hdr.event = BTA_SDP_API_CREATE_RECORD_USER_EVT;
         p_msg->user_data = user_data;
         bta_sys_sendmsg(p_msg);
@@ -156,7 +155,7 @@ tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void *user_data)
     tBTA_SDP_API_RECORD_USER *p_msg;
 
     APPL_TRACE_API("%s\n", __FUNCTION__);
-    if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
+    if ((p_msg = (tBTA_SDP_API_RECORD_USER *)osi_malloc(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
         p_msg->hdr.event = BTA_SDP_API_REMOVE_RECORD_USER_EVT;
         p_msg->user_data = user_data;
         bta_sys_sendmsg(p_msg);
index bbdd8c78e9776d84f387ff7a9762f2c94348c425..c515c090c72fe69dac4e1ffa96011d283178eeae 100644 (file)
@@ -21,7 +21,6 @@
  ******************************************************************************/
 
 #include "bt_target.h"
-#include "gki.h"
 #include "bta_api.h"
 #include "bta_sdp_api.h"
 
index 4f9f7d2cb8fa9a921e03e715f214659ad6373c41..9dee3fc96317400a11295af5e2b0d6a3615f7ff3 100644 (file)
@@ -73,7 +73,7 @@ typedef struct {
 
 /* union of all data types */
 typedef union {
-    /* GKI event buffer header */
+    /* event buffer header */
     BT_HDR                                 hdr;
     tBTA_SDP_API_ENABLE                    enable;
     tBTA_SDP_API_SEARCH                    get_search;
index 6d671be9843d130c355987a0c98585610ecb80c3..55824e7a7a3555270f1a45b2a0eb679fc434c0ef 100644 (file)
@@ -26,7 +26,6 @@
 #include "bta_api.h"
 #include "bta_sys.h"
 #include "bta_sys_int.h"
-#include "gki.h"
 #include "utl.h"
 
 /*******************************************************************************
index b023ef463566ae0af930d02b46606fffb130ed74..48eec5f11293effc19d131d48ed73e8046dcbf58 100644 (file)
 #include "bta_sys_int.h"
 
 #include "fixed_queue.h"
-#include "gki.h"
 #include "hash_map.h"
 #include "osi.h"
 #include "hash_functions.h"
-// #include "osi/include/log.h"
-// #include "osi/include/thread.h"
 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
 #include "bta_ar_api.h"
 #endif
 #include "utl.h"
+#include "allocator.h"
+#include "mutex.h"
 
 
 /* system manager control block definition */
@@ -53,7 +52,7 @@ tBTA_SYS_CB bta_sys_cb;
 
 static hash_map_t *bta_alarm_hash_map;
 static const size_t BTA_ALARM_HASH_MAP_SIZE = 17;
-static pthread_mutex_t bta_alarm_lock;
+static osi_mutex_t bta_alarm_lock;
 // extern thread_t *bt_workqueue_thread;
 
 /* trace level */
@@ -168,7 +167,7 @@ void bta_sys_init(void)
 {
     memset(&bta_sys_cb, 0, sizeof(tBTA_SYS_CB));
 
-    pthread_mutex_init(&bta_alarm_lock, NULL);
+    osi_mutex_new(&bta_alarm_lock);
 
     bta_alarm_hash_map = hash_map_new(BTA_ALARM_HASH_MAP_SIZE,
                                       hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
@@ -190,7 +189,7 @@ void bta_sys_init(void)
 void bta_sys_free(void)
 {
     hash_map_free(bta_alarm_hash_map);
-    pthread_mutex_destroy(&bta_alarm_lock);
+    osi_mutex_free(&bta_alarm_lock);
 }
 
 /*******************************************************************************
@@ -259,14 +258,14 @@ void bta_sys_hw_btm_cback( tBTM_DEV_STATUS status )
     APPL_TRACE_DEBUG(" bta_sys_hw_btm_cback was called with parameter: %i" , status );
 
     /* send a message to BTA SYS */
-    if ((sys_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
+    if ((sys_event = (tBTA_SYS_HW_MSG *) osi_malloc(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
         if (status == BTM_DEV_STATUS_UP) {
             sys_event->hdr.event = BTA_SYS_EVT_STACK_ENABLED_EVT;
         } else if (status == BTM_DEV_STATUS_DOWN) {
             sys_event->hdr.event = BTA_SYS_ERROR_EVT;
         } else {
             /* BTM_DEV_STATUS_CMD_TOUT is ignored for now. */
-            GKI_freebuf (sys_event);
+            osi_free (sys_event);
             sys_event = NULL;
         }
 
@@ -334,7 +333,7 @@ void bta_sys_hw_api_enable( tBTA_SYS_HW_MSG *p_sys_hw_msg )
         bta_sys_cb.sys_hw_module_active |=  ((UINT32)1 << p_sys_hw_msg->hw_module );
 
         tBTA_SYS_HW_MSG *p_msg;
-        if ((p_msg = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
+        if ((p_msg = (tBTA_SYS_HW_MSG *) osi_malloc(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
             p_msg->hdr.event = BTA_SYS_EVT_ENABLED_EVT;
             p_msg->hw_module = p_sys_hw_msg->hw_module;
 
@@ -389,7 +388,7 @@ void bta_sys_hw_api_disable(tBTA_SYS_HW_MSG *p_sys_hw_msg)
         bta_sys_cb.state = BTA_SYS_HW_STOPPING;
 
         tBTA_SYS_HW_MSG *p_msg;
-        if ((p_msg = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
+        if ((p_msg = (tBTA_SYS_HW_MSG *) osi_malloc(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
             p_msg->hdr.event = BTA_SYS_EVT_DISABLED_EVT;
             p_msg->hw_module = p_sys_hw_msg->hw_module;
 
@@ -495,7 +494,7 @@ void bta_sys_event(BT_HDR *p_msg)
     }
 
     if (freebuf) {
-        GKI_freebuf(p_msg);
+        osi_free(p_msg);
     }
 
 }
@@ -553,7 +552,7 @@ BOOLEAN bta_sys_is_register(UINT8 id)
 **
 ** Function         bta_sys_sendmsg
 **
-** Description      Send a GKI message to BTA.  This function is designed to
+** Description      Send a message to BTA.  This function is designed to
 **                  optimize sending of messages to BTA.  It is called by BTA
 **                  API functions and call-in functions.
 **
@@ -568,7 +567,7 @@ void bta_sys_sendmsg(void *p_msg)
     // message queue. This causes |btu_bta_msg_queue| to get cleaned up before
     // it gets used here; hence we check for NULL before using it.
     if (btu_task_post(SIG_BTU_BTA_MSG, p_msg,  TASK_POST_BLOCKING) != TASK_POST_SUCCESS) {
-        GKI_freebuf(p_msg);
+        osi_free(p_msg);
     }
 }
 
@@ -595,11 +594,11 @@ void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms)
     assert(p_tle != NULL);
 
     // Get the alarm for this p_tle.
-    pthread_mutex_lock(&bta_alarm_lock);
+    osi_mutex_lock(&bta_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
     if (!hash_map_has_key(bta_alarm_hash_map, p_tle)) {
         hash_map_set(bta_alarm_hash_map, p_tle, osi_alarm_new("bta_sys", bta_alarm_cb, p_tle, 0));
     }
-    pthread_mutex_unlock(&bta_alarm_lock);
+    osi_mutex_unlock(&bta_alarm_lock);
 
     osi_alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_tle);
     if (alarm == NULL) {
@@ -624,10 +623,10 @@ bool hash_iter_ro_cb(hash_map_entry_t *hash_map_entry, void *context)
 UINT32 bta_sys_get_remaining_ticks(TIMER_LIST_ENT *p_target_tle)
 {
     period_ms_t remaining_ms = 0;
-    pthread_mutex_lock(&bta_alarm_lock);
+    osi_mutex_lock(&bta_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
     // Get the alarm for this p_tle
     hash_map_foreach(bta_alarm_hash_map, hash_iter_ro_cb, &remaining_ms);
-    pthread_mutex_unlock(&bta_alarm_lock);
+    osi_mutex_unlock(&bta_alarm_lock);
     return remaining_ms;
 }
 
index 6cc6728dfcb9dc8f9074e5ac1aae9d94d80a709a..d464086ad69c1a23601e37aabf8e9f0bccc8e1b3 100644 (file)
@@ -23,8 +23,8 @@
  ******************************************************************************/
 #include <stddef.h>
 #include "utl.h"
-#include "gki.h"
 #include "btm_api.h"
+#include "allocator.h"
 
 /*******************************************************************************
 **
@@ -143,7 +143,7 @@ UINT8 utl_itoa(UINT16 i, char *p_s)
 **
 ** Function         utl_freebuf
 **
-** Description      This function calls GKI_freebuf to free the buffer passed
+** Description      This function calls osi_free to free the buffer passed
 **                  in, if buffer pointer is not NULL, and also initializes
 **                  buffer pointer to NULL.
 **
@@ -154,7 +154,7 @@ UINT8 utl_itoa(UINT16 i, char *p_s)
 void utl_freebuf(void **p)
 {
     if (*p != NULL) {
-        GKI_freebuf(*p);
+        osi_free(*p);
         *p = NULL;
     }
 }
index dae7c571059f422ee2a13bf39d4412230cc1b322..94738806461ab0914d125022a14cc273ef5b2aab 100644 (file)
@@ -25,6 +25,7 @@
 #include "btc_util.h"
 #include "config.h"
 #include "osi.h"
+#include "mutex.h"
 
 #include "bt_types.h"
 
@@ -75,7 +76,7 @@ bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type)
     return TRUE;
 }
 
-static pthread_mutex_t lock;  // protects operations on |config|.
+static osi_mutex_t lock;  // protects operations on |config|.
 static config_t *config;
 
 bool btc_compare_address_key_value(const char *section, char *key_type, void *key_value, int key_length)
@@ -87,11 +88,11 @@ bool btc_compare_address_key_value(const char *section, char *key_type, void *ke
         return false;
     }
     btc_key_value_to_string((uint8_t *)key_value, value_str, key_length);
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     if ((status = config_has_key_in_section(config, key_type, value_str)) == true) {
         config_remove_section(config, section);
     }
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
     return status;
 }
 
@@ -114,7 +115,7 @@ static void btc_key_value_to_string(uint8_t *key_vaule, char *value_str, int key
 
 bool btc_config_init(void)
 {
-    pthread_mutex_init(&lock, NULL);
+    osi_mutex_new(&lock);
     config = config_new(CONFIG_FILE_PATH);
     if (!config) {
         LOG_WARN("%s unable to load config file; starting unconfigured.\n", __func__);
@@ -132,7 +133,7 @@ bool btc_config_init(void)
 
 error:;
     config_free(config);
-    pthread_mutex_destroy(&lock);
+    osi_mutex_free(&lock);
     config = NULL;
     LOG_ERROR("%s failed\n", __func__);
     return false;
@@ -149,7 +150,7 @@ bool btc_config_clean_up(void)
     btc_config_flush();
 
     config_free(config);
-    pthread_mutex_destroy(&lock);
+    osi_mutex_free(&lock);
     config = NULL;
     return true;
 }
@@ -159,9 +160,9 @@ bool btc_config_has_section(const char *section)
     assert(config != NULL);
     assert(section != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     bool ret = config_has_section(config, section);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     return ret;
 }
@@ -172,9 +173,9 @@ bool btc_config_exist(const char *section, const char *key)
     assert(section != NULL);
     assert(key != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     bool ret = config_has_key(config, section, key);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     return ret;
 }
@@ -186,12 +187,12 @@ bool btc_config_get_int(const char *section, const char *key, int *value)
     assert(key != NULL);
     assert(value != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     bool ret = config_has_key(config, section, key);
     if (ret) {
         *value = config_get_int(config, section, key, *value);
     }
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     return ret;
 }
@@ -202,9 +203,9 @@ bool btc_config_set_int(const char *section, const char *key, int value)
     assert(section != NULL);
     assert(key != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     config_set_int(config, section, key, value);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     return true;
 }
@@ -217,9 +218,9 @@ bool btc_config_get_str(const char *section, const char *key, char *value, int *
     assert(value != NULL);
     assert(size_bytes != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     const char *stored_value = config_get_string(config, section, key, NULL);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     if (!stored_value) {
         return false;
@@ -238,9 +239,9 @@ bool btc_config_set_str(const char *section, const char *key, const char *value)
     assert(key != NULL);
     assert(value != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     config_set_string(config, section, key, value, false);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     return true;
 }
@@ -253,9 +254,9 @@ bool btc_config_get_bin(const char *section, const char *key, uint8_t *value, si
     assert(value != NULL);
     assert(length != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     const char *value_str = config_get_string(config, section, key, NULL);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     if (!value_str) {
         return false;
@@ -286,9 +287,9 @@ size_t btc_config_get_bin_length(const char *section, const char *key)
     assert(section != NULL);
     assert(key != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     const char *value_str = config_get_string(config, section, key, NULL);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     if (!value_str) {
         return 0;
@@ -320,9 +321,9 @@ bool btc_config_set_bin(const char *section, const char *key, const uint8_t *val
         str[(i * 2) + 1] = lookup[value[i] & 0x0F];
     }
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     config_set_string(config, section, key, str, false);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     osi_free(str);
     return true;
@@ -360,9 +361,9 @@ bool btc_config_remove(const char *section, const char *key)
     assert(section != NULL);
     assert(key != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     bool ret = config_remove_key(config, section, key);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     return ret;
 }
@@ -372,9 +373,9 @@ bool btc_config_remove_section(const char *section)
     assert(config != NULL);
     assert(section != NULL);
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     bool ret = config_remove_section(config, section);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 
     return ret;
 }
@@ -393,7 +394,7 @@ void btc_config_save(void)
     size_t num_keys = 0;
     size_t total_candidates = 0;
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     for (const config_section_node_t *snode = config_section_begin(config); snode != config_section_end(config); snode = config_section_next(snode)) {
         const char *section = config_section_name(snode);
         if (!string_is_bdaddr(section)) {
@@ -421,15 +422,15 @@ void btc_config_save(void)
             config_remove_section(config, keys[--num_keys]);
         }
     config_save(config, CONFIG_FILE_PATH);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 }
 
 void btc_config_flush(void)
 {
     assert(config != NULL);
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     config_save(config, CONFIG_FILE_PATH);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
 }
 
 int btc_config_clear(void)
@@ -437,16 +438,16 @@ int btc_config_clear(void)
     assert(config != NULL);
 
 
-    pthread_mutex_lock(&lock);
+    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
     config_free(config);
 
     config = config_new_empty();
     if (config == NULL) {
-        pthread_mutex_unlock(&lock);
+        osi_mutex_unlock(&lock);
         return false;
     }
     int ret = config_save(config, CONFIG_FILE_PATH);
-    pthread_mutex_unlock(&lock);
+    osi_mutex_unlock(&lock);
     return ret;
 }
 
index 01f1a1e660f408349a474d6bf5155f0e767244f0..06d78a2b4838ccd4ed53930bcc832d64844e0a59 100644 (file)
@@ -26,6 +26,7 @@
 #include "btm_int.h"
 #include "bta_api.h"
 #include "bta_gatt_api.h"
+#include "allocator.h"
 
 
 /******************************************************************************
index 213c4939c1ebb2fc12ce2c47f3da1ec7afd4e525..32df4440bc58ed6b2cc39fa72947f4b4e5930bcb 100644 (file)
@@ -16,7 +16,6 @@
 #include "btc_task.h"
 #include "bt_trace.h"
 #include "thread.h"
-#include "gki.h"
 #include "esp_bt_defs.h"
 #include "esp_gatt_defs.h"
 
index 9d0c472dfb237267b225a7a42200af345edf8377..d72f822e701fe2085186d55483fdd2b1a48c01e2 100644 (file)
@@ -18,7 +18,6 @@
 #include "bt_trace.h"
 #include "bt_defs.h"
 #include "btc_profile_queue.h"
-#include "gki.h"
 #include "list.h"
 #include "allocator.h"
 
index 236b24fa2676dd77cb4bfec1b674d66c0e3be792..b3d87f8ee0f91dfe6264fe61921654dbf3be4bfd 100644 (file)
@@ -25,7 +25,6 @@
 #include "allocator.h"
 #include "btc_common.h"
 #include "btc_sm.h"
-#include "gki.h"
 
 #if BTC_SM_INCLUDED
 /*****************************************************************************
index 51b9ea247a3c54facdf6cbde8afd8ac2661898a0..534a0059ba587da011bd6ba1064eb3ec5051dc23 100644 (file)
@@ -17,8 +17,8 @@
 #include "btc_task.h"
 #include "bt_trace.h"
 #include "thread.h"
-#include "gki.h"
 #include "bt_defs.h"
+#include "allocator.h"
 #include "btc_main.h"
 #include "btc_dev.h"
 #include "btc_gatts.h"
@@ -88,7 +88,7 @@ static void btc_task(void *arg)
                 break;
             }
             if (msg.arg) {
-                GKI_freebuf(msg.arg);
+                osi_free(msg.arg);
             }
         }
     }
@@ -120,7 +120,7 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
 
     memcpy(&lmsg, msg, sizeof(btc_msg_t));
     if (arg) {
-        lmsg.arg = (void *)GKI_getbuf(arg_len);
+        lmsg.arg = (void *)osi_malloc(arg_len);
         if (lmsg.arg == NULL) {
             return BT_STATUS_NOMEM;
         }
index f2cd946b6853bbd2ad6c7c0b829d3f290a0418f5..14cad2ecfc519764d8bb585150b899bb1f360ee1 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "bt_target.h"
 #include "bt_trace.h"
+#include "allocator.h"
 #include "bt_types.h"
 #include "gatt_api.h"
 #include "bta_api.h"
@@ -144,7 +145,7 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
             tBTA_GATT_STATUS status = GATT_SUCCESS;
 
             if (blufi_env.prepare_buf == NULL) {
-                blufi_env.prepare_buf = GKI_getbuf(BLUFI_PREPAIR_BUF_MAX_SIZE);
+                blufi_env.prepare_buf = osi_malloc(BLUFI_PREPAIR_BUF_MAX_SIZE);
                 if (blufi_env.prepare_buf == NULL) {
                     LOG_ERROR("Blufi prep no mem\n");
                     status = GATT_NO_RESOURCES;
@@ -197,7 +198,7 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
         }
 
         if (blufi_env.prepare_buf) {
-            GKI_freebuf(blufi_env.prepare_buf);
+            osi_free(blufi_env.prepare_buf);
             blufi_env.prepare_buf = NULL;
         }
 
@@ -399,7 +400,7 @@ static void btc_blufi_recv_handler(uint8_t *data, int len)
     if (BLUFI_FC_IS_FRAG(hdr->fc)) {
         if (blufi_env.offset == 0) {
             blufi_env.total_len = hdr->data[0] | (((uint16_t) hdr->data[1]) << 8);
-            blufi_env.aggr_buf = GKI_getbuf(blufi_env.total_len);
+            blufi_env.aggr_buf = osi_malloc(blufi_env.total_len);
             if (blufi_env.aggr_buf == NULL) {
                 LOG_ERROR("%s no mem, len %d\n", __func__, blufi_env.total_len);
                 return;
@@ -413,7 +414,7 @@ static void btc_blufi_recv_handler(uint8_t *data, int len)
 
             btc_blufi_protocol_handler(hdr->type, blufi_env.aggr_buf, blufi_env.total_len);
             blufi_env.offset = 0;
-            GKI_freebuf(blufi_env.aggr_buf);
+            osi_free(blufi_env.aggr_buf);
             blufi_env.aggr_buf = NULL;
         } else {
             btc_blufi_protocol_handler(hdr->type, hdr->data, hdr->data_len);
@@ -430,7 +431,7 @@ void btc_blufi_send_encap(uint8_t type, uint8_t *data, int total_data_len)
 
     while (remain_len > 0) {
         if (remain_len > blufi_env.frag_size) {
-            hdr = GKI_getbuf(sizeof(struct blufi_hdr) + 2 + blufi_env.frag_size + 2);
+            hdr = osi_malloc(sizeof(struct blufi_hdr) + 2 + blufi_env.frag_size + 2);
             if (hdr == NULL) {
                 LOG_ERROR("%s no mem\n", __func__);
                 return;
@@ -442,7 +443,7 @@ void btc_blufi_send_encap(uint8_t type, uint8_t *data, int total_data_len)
             memcpy(hdr->data + 2, &data[total_data_len - remain_len], blufi_env.frag_size); //copy first, easy for check sum
             hdr->fc |= BLUFI_FC_FRAG;
         } else {
-            hdr = GKI_getbuf(sizeof(struct blufi_hdr) + remain_len + 2);
+            hdr = osi_malloc(sizeof(struct blufi_hdr) + remain_len + 2);
             if (hdr == NULL) {
                 LOG_ERROR("%s no mem\n", __func__);
                 return;
@@ -478,7 +479,7 @@ void btc_blufi_send_encap(uint8_t type, uint8_t *data, int total_data_len)
                     hdr->fc |= BLUFI_FC_ENC;
                 } else {
                     LOG_ERROR("%s encrypt error %d\n", __func__, ret);
-                    GKI_freebuf(hdr);
+                    osi_free(hdr);
                     return;
                 }
             }
@@ -495,7 +496,7 @@ void btc_blufi_send_encap(uint8_t type, uint8_t *data, int total_data_len)
                  hdr->data_len + sizeof(struct blufi_hdr) + 2 :
                  hdr->data_len + sizeof(struct blufi_hdr)));
 
-        GKI_freebuf(hdr);
+        osi_free(hdr);
         hdr =  NULL;
     }
 }
@@ -508,7 +509,7 @@ static void btc_blufi_wifi_conn_report(uint8_t opmode, uint8_t sta_conn_state, u
     uint8_t *p;
 
     data_len = info_len + 3;
-    p = data = GKI_getbuf(data_len);
+    p = data = osi_malloc(data_len);
     if (data == NULL) {
         return;
     }
@@ -570,7 +571,7 @@ static void btc_blufi_wifi_conn_report(uint8_t opmode, uint8_t sta_conn_state, u
     }
 
     btc_blufi_send_encap(type, data, data_len);
-    GKI_freebuf(data);
+    osi_free(data);
 }
 
 static void btc_blufi_send_ack(uint8_t seq)
@@ -591,70 +592,70 @@ void btc_blufi_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
 
     switch (msg->act) {
     case ESP_BLUFI_EVENT_RECV_STA_SSID:
-        dst->sta_ssid.ssid = GKI_getbuf(src->sta_ssid.ssid_len);
+        dst->sta_ssid.ssid = osi_malloc(src->sta_ssid.ssid_len);
         if (dst->sta_ssid.ssid == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
         memcpy(dst->sta_ssid.ssid, src->sta_ssid.ssid, src->sta_ssid.ssid_len);
         break;
     case ESP_BLUFI_EVENT_RECV_STA_PASSWD:
-        dst->sta_passwd.passwd = GKI_getbuf(src->sta_passwd.passwd_len);
+        dst->sta_passwd.passwd = osi_malloc(src->sta_passwd.passwd_len);
         if (dst->sta_passwd.passwd == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
         memcpy(dst->sta_passwd.passwd, src->sta_passwd.passwd, src->sta_passwd.passwd_len);
         break;
     case ESP_BLUFI_EVENT_RECV_SOFTAP_SSID:
-        dst->softap_ssid.ssid = GKI_getbuf(src->softap_ssid.ssid_len);
+        dst->softap_ssid.ssid = osi_malloc(src->softap_ssid.ssid_len);
         if (dst->softap_ssid.ssid == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
         memcpy(dst->softap_ssid.ssid, src->softap_ssid.ssid, src->softap_ssid.ssid_len);
         break;
     case ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD:
-        dst->softap_passwd.passwd = GKI_getbuf(src->softap_passwd.passwd_len);
+        dst->softap_passwd.passwd = osi_malloc(src->softap_passwd.passwd_len);
         if (dst->softap_passwd.passwd == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
         memcpy(dst->softap_passwd.passwd, src->softap_passwd.passwd, src->softap_passwd.passwd_len);
         break;
     case ESP_BLUFI_EVENT_RECV_USERNAME:
-        dst->username.name = GKI_getbuf(src->username.name_len);
+        dst->username.name = osi_malloc(src->username.name_len);
         if (dst->username.name == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
         memcpy(dst->username.name, src->username.name, src->username.name_len);
         break;
     case ESP_BLUFI_EVENT_RECV_CA_CERT:
-        dst->ca.cert = GKI_getbuf(src->ca.cert_len);
+        dst->ca.cert = osi_malloc(src->ca.cert_len);
         if (dst->ca.cert == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
         memcpy(dst->ca.cert, src->ca.cert, src->ca.cert_len);
         break;
     case ESP_BLUFI_EVENT_RECV_CLIENT_CERT:
-        dst->client_cert.cert = GKI_getbuf(src->client_cert.cert_len);
+        dst->client_cert.cert = osi_malloc(src->client_cert.cert_len);
         if (dst->client_cert.cert == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
         memcpy(dst->client_cert.cert, src->client_cert.cert, src->client_cert.cert_len);
         break;
     case ESP_BLUFI_EVENT_RECV_SERVER_CERT:
-        dst->server_cert.cert = GKI_getbuf(src->server_cert.cert_len);
+        dst->server_cert.cert = osi_malloc(src->server_cert.cert_len);
         if (dst->server_cert.cert == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
         memcpy(dst->server_cert.cert, src->server_cert.cert, src->server_cert.cert_len);
         break;
     case ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY:
-         dst->client_pkey.pkey = GKI_getbuf(src->client_pkey.pkey_len);
+         dst->client_pkey.pkey = osi_malloc(src->client_pkey.pkey_len);
         if (dst->client_pkey.pkey == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
         memcpy(dst->client_pkey.pkey, src->client_pkey.pkey, src->client_pkey.pkey_len);
         break;
     case ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY:
-         dst->server_pkey.pkey = GKI_getbuf(src->server_pkey.pkey_len);
+         dst->server_pkey.pkey = osi_malloc(src->server_pkey.pkey_len);
         if (dst->server_pkey.pkey == NULL) {
             LOG_ERROR("%s %d no mem\n", __func__, msg->act);
         }
@@ -671,34 +672,34 @@ void btc_blufi_cb_deep_free(btc_msg_t *msg)
 
     switch (msg->act) {
     case ESP_BLUFI_EVENT_RECV_STA_SSID:
-        GKI_freebuf(param->sta_ssid.ssid);
+        osi_free(param->sta_ssid.ssid);
         break;
     case ESP_BLUFI_EVENT_RECV_STA_PASSWD:
-        GKI_freebuf(param->sta_passwd.passwd);
+        osi_free(param->sta_passwd.passwd);
         break;
     case ESP_BLUFI_EVENT_RECV_SOFTAP_SSID:
-        GKI_freebuf(param->softap_ssid.ssid);
+        osi_free(param->softap_ssid.ssid);
         break;
     case ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD:
-        GKI_freebuf(param->softap_passwd.passwd);
+        osi_free(param->softap_passwd.passwd);
         break;
     case ESP_BLUFI_EVENT_RECV_USERNAME:
-        GKI_freebuf(param->username.name);
+        osi_free(param->username.name);
         break;
     case ESP_BLUFI_EVENT_RECV_CA_CERT:
-        GKI_freebuf(param->ca.cert);
+        osi_free(param->ca.cert);
         break;
     case ESP_BLUFI_EVENT_RECV_CLIENT_CERT:
-        GKI_freebuf(param->client_cert.cert);
+        osi_free(param->client_cert.cert);
         break;
     case ESP_BLUFI_EVENT_RECV_SERVER_CERT:
-        GKI_freebuf(param->server_cert.cert);
+        osi_free(param->server_cert.cert);
         break;
     case ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY:
-        GKI_freebuf(param->client_pkey.pkey);
+        osi_free(param->client_pkey.pkey);
         break;
     case ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY:
-        GKI_freebuf(param->server_pkey.pkey);
+        osi_free(param->server_pkey.pkey);
         break;
     default:
         break;
@@ -807,7 +808,7 @@ void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
             return;
         }
 
-        dst->wifi_conn_report.extra_info = GKI_getbuf(sizeof(esp_blufi_extra_info_t));
+        dst->wifi_conn_report.extra_info = osi_malloc(sizeof(esp_blufi_extra_info_t));
         if (dst->wifi_conn_report.extra_info == NULL) {
             return;
         }
@@ -818,7 +819,7 @@ void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
             dst->wifi_conn_report.extra_info_len += (6 + 2);
         }
         if (src_info->sta_ssid) {
-            dst->wifi_conn_report.extra_info->sta_ssid = GKI_getbuf(src_info->sta_ssid_len);
+            dst->wifi_conn_report.extra_info->sta_ssid = osi_malloc(src_info->sta_ssid_len);
             if (dst->wifi_conn_report.extra_info->sta_ssid) {
                 memcpy(dst->wifi_conn_report.extra_info->sta_ssid, src_info->sta_ssid, src_info->sta_ssid_len);
                 dst->wifi_conn_report.extra_info->sta_ssid_len = src_info->sta_ssid_len;
@@ -826,7 +827,7 @@ void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
             }
         }
         if (src_info->sta_passwd) {
-            dst->wifi_conn_report.extra_info->sta_passwd = GKI_getbuf(src_info->sta_passwd_len);
+            dst->wifi_conn_report.extra_info->sta_passwd = osi_malloc(src_info->sta_passwd_len);
             if (dst->wifi_conn_report.extra_info->sta_passwd) {
                 memcpy(dst->wifi_conn_report.extra_info->sta_passwd, src_info->sta_passwd, src_info->sta_passwd_len);
                 dst->wifi_conn_report.extra_info->sta_passwd_len = src_info->sta_passwd_len;
@@ -834,7 +835,7 @@ void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
             }
         }
         if (src_info->softap_ssid) {
-            dst->wifi_conn_report.extra_info->softap_ssid = GKI_getbuf(src_info->softap_ssid_len);
+            dst->wifi_conn_report.extra_info->softap_ssid = osi_malloc(src_info->softap_ssid_len);
             if (dst->wifi_conn_report.extra_info->softap_ssid) {
                 memcpy(dst->wifi_conn_report.extra_info->softap_ssid, src_info->softap_ssid, src_info->softap_ssid_len);
                 dst->wifi_conn_report.extra_info->softap_ssid_len = src_info->softap_ssid_len;
@@ -842,7 +843,7 @@ void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
             }
         }
         if (src_info->softap_passwd) {
-            dst->wifi_conn_report.extra_info->softap_passwd = GKI_getbuf(src_info->softap_passwd_len);
+            dst->wifi_conn_report.extra_info->softap_passwd = osi_malloc(src_info->softap_passwd_len);
             if (dst->wifi_conn_report.extra_info->softap_passwd) {
                 memcpy(dst->wifi_conn_report.extra_info->softap_passwd, src_info->softap_passwd, src_info->softap_passwd_len);
                 dst->wifi_conn_report.extra_info->softap_passwd_len = src_info->softap_passwd_len;
@@ -883,18 +884,18 @@ void btc_blufi_call_deep_free(btc_msg_t *msg)
             return;
         }
         if (info->sta_ssid) {
-            GKI_freebuf(info->sta_ssid);
+            osi_free(info->sta_ssid);
         }
         if (info->sta_passwd) {
-            GKI_freebuf(info->sta_passwd);
+            osi_free(info->sta_passwd);
         }
         if (info->softap_ssid) {
-            GKI_freebuf(info->softap_ssid);
+            osi_free(info->softap_ssid);
         }
         if (info->softap_passwd) {
-            GKI_freebuf(info->softap_passwd);
+            osi_free(info->softap_passwd);
         }
-        GKI_freebuf(info);
+        osi_free(info);
         break;
     }
     default:
index 4ee4ed3f12806216ee66cc00719930771215acc4..59c06d589d36baec08d35145099efb276682ca6a 100644 (file)
@@ -34,6 +34,7 @@
 #include "btc_media.h"
 #include "btc_av_co.h"
 #include "btc_util.h"
+#include "mutex.h"
 
 #if BTC_AV_INCLUDED
 
@@ -513,7 +514,7 @@ UINT8 bta_av_audio_sink_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
         APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig last SRC reached");
 
         /* Protect access to bta_av_co_cb.codec_cfg */
-        GKI_disable();
+        osi_mutex_global_lock();
 
         /* Find a src that matches the codec config */
         if (bta_av_co_audio_peer_src_supports_codec(p_peer, &index)) {
@@ -545,7 +546,7 @@ UINT8 bta_av_audio_sink_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
             }
         }
         /* Protect access to bta_av_co_cb.codec_cfg */
-        GKI_enable();
+        osi_mutex_global_unlock();
     }
     return result;
 }
@@ -634,7 +635,7 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
         APPL_TRACE_DEBUG("bta_av_co_audio_getconfig last sink reached");
 
         /* Protect access to bta_av_co_cb.codec_cfg */
-        GKI_disable();
+        osi_mutex_global_lock();
 
         /* Find a sink that matches the codec config */
         if (bta_av_co_audio_peer_supports_codec(p_peer, &index)) {
@@ -686,7 +687,7 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
             }
         }
         /* Protect access to bta_av_co_cb.codec_cfg */
-        GKI_enable();
+        osi_mutex_global_unlock();
     }
     return result;
 }
@@ -770,7 +771,7 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
         if (codec_cfg_supported) {
 
             /* Protect access to bta_av_co_cb.codec_cfg */
-            GKI_disable();
+            osi_mutex_global_lock();
 
             /* Check if the configuration matches the current codec config */
             switch (bta_av_co_cb.codec_cfg.id) {
@@ -804,7 +805,7 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
                 break;
             }
             /* Protect access to bta_av_co_cb.codec_cfg */
-            GKI_enable();
+            osi_mutex_global_unlock();
         } else {
             category = AVDT_ASC_CODEC;
             status = A2D_WRONG_CODEC;
@@ -947,7 +948,7 @@ extern void bta_av_co_audio_stop(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type)
  ** Description      This function is called to manage data transfer from
  **                  the audio codec to AVDTP.
  **
- ** Returns          Pointer to the GKI buffer to send, NULL if no buffer to send
+ ** Returns          Pointer to the buffer to send, NULL if no buffer to send
  **
  *******************************************************************************/
 void *bta_av_co_audio_src_data_path(tBTA_AV_CODEC codec_type, UINT32 *p_len,
@@ -1463,7 +1464,7 @@ BOOLEAN bta_av_co_audio_codec_supported(tBTC_STATUS *p_status)
  *******************************************************************************/
 void bta_av_co_audio_codec_reset(void)
 {
-    GKI_disable();
+    osi_mutex_global_lock();
     FUNC_TRACE();
 
     /* Reset the current configuration to SBC */
@@ -1473,7 +1474,7 @@ void bta_av_co_audio_codec_reset(void)
         APPL_TRACE_ERROR("bta_av_co_audio_codec_reset A2D_BldSbcInfo failed");
     }
 
-    GKI_enable();
+    osi_mutex_global_unlock();
 }
 
 /*******************************************************************************
@@ -1580,7 +1581,7 @@ BOOLEAN bta_av_co_audio_get_sbc_config(tA2D_SBC_CIE *p_sbc_config, UINT16 *p_min
     /* Minimum MTU is by default very large */
     *p_minmtu = 0xFFFF;
 
-    GKI_disable();
+    osi_mutex_global_lock();
     if (bta_av_co_cb.codec_cfg.id == BTC_AV_CODEC_SBC) {
         if (A2D_ParsSbcInfo(p_sbc_config, bta_av_co_cb.codec_cfg.info, FALSE) == A2D_SUCCESS) {
             for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++) {
@@ -1614,7 +1615,7 @@ BOOLEAN bta_av_co_audio_get_sbc_config(tA2D_SBC_CIE *p_sbc_config, UINT16 *p_min
         /* Not SBC, still return the default values */
         *p_sbc_config = btc_av_sbc_default_config;
     }
-    GKI_enable();
+    osi_mutex_global_unlock();
 
     return result;
 }
index 966f8d6ff3e821f7b6e701c1d98e04119533486a..b376e0bd1c64a6cbe0144850bf12945ce5a3555e 100644 (file)
@@ -34,7 +34,6 @@
 #include "bta_api.h"
 #include "btc_media.h"
 #include "bta_av_api.h"
-#include "gki.h"
 #include "btu.h"
 #include "bt_utils.h"
 #include "btc_common.h"
index 8610ef851f729392e0b36efe8fe2062656fde8e0..6444392a40dd65e04f1553438a2450364bfb8d43 100644 (file)
@@ -28,7 +28,6 @@
 #include <stdio.h>
 #include <stdint.h>
 #include "fixed_queue.h"
-#include "gki.h"
 #include "bta_api.h"
 #include "btu.h"
 #include "bta_sys.h"
@@ -52,6 +51,7 @@
 #include "allocator.h"
 #include "bt_utils.h"
 #include "esp_a2dp_api.h"
+#include "mutex.h"
 
 // #if (BTA_AV_SINK_INCLUDED == TRUE)
 #include "oi_codec_sbc.h"
@@ -124,7 +124,7 @@ typedef struct {
 } tBT_SBC_HDR;
 
 typedef struct {
-    BUFFER_Q RxSbcQ;
+    fixed_queue_t *RxSbcQ;
     void *av_sm_hdl;
     UINT8 peer_sep;
     UINT8 busy_level;
@@ -148,7 +148,7 @@ extern OI_STATUS OI_CODEC_SBC_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context
         OI_BOOL enhanced);
 // #endif
 
-static void btc_media_flush_q(BUFFER_Q *p_q);
+static void btc_media_flush_q(fixed_queue_t *p_q);
 static void btc_media_task_aa_rx_flush(void);
 static const char *dump_media_event(UINT16 event);
 static void btc_media_thread_handle_cmd(fixed_queue_t *queue);
@@ -379,7 +379,7 @@ void btc_a2dp_setup_codec(void)
 
     APPL_TRACE_EVENT("## A2DP SETUP CODEC ##\n");
 
-    GKI_disable();
+    osi_mutex_global_lock();
 
     /* for now hardcode 44.1 khz 16 bit stereo PCM format */
     media_feeding.cfg.pcm.sampling_freq = 44100;
@@ -389,7 +389,8 @@ void btc_a2dp_setup_codec(void)
 
     bta_av_co_audio_set_codec(&media_feeding, &status);
 
-    GKI_enable();
+
+    osi_mutex_global_unlock();
 }
 
 /*****************************************************************************
@@ -428,7 +429,7 @@ BOOLEAN btc_media_task_clear_track(void)
 {
     BT_HDR *p_buf;
 
-    if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR)))) {
+    if (NULL == (p_buf = osi_malloc(sizeof(BT_HDR)))) {
         return FALSE;
     }
 
@@ -457,7 +458,7 @@ void btc_reset_decoder(UINT8 *p_av)
                      p_av[4], p_av[5], p_av[6]);
 
     tBTC_MEDIA_SINK_CFG_UPDATE *p_buf;
-    if (NULL == (p_buf = GKI_getbuf(sizeof(tBTC_MEDIA_SINK_CFG_UPDATE)))) {
+    if (NULL == (p_buf = osi_malloc(sizeof(tBTC_MEDIA_SINK_CFG_UPDATE)))) {
         APPL_TRACE_ERROR("btc_reset_decoder No Buffer ");
         return;
     }
@@ -519,26 +520,24 @@ void btc_a2dp_set_rx_flush(BOOLEAN enable)
 
 static void btc_media_task_avk_data_ready(UNUSED_ATTR void *context)
 {
-    UINT8 count;
     tBT_SBC_HDR *p_msg;
 
-    count = btc_media_cb.RxSbcQ._count;
-    if (0 == count) {
+    if (fixed_queue_is_empty(btc_media_cb.RxSbcQ)) {
         APPL_TRACE_DEBUG("  QUE  EMPTY ");
     } else {
         if (btc_media_cb.rx_flush == TRUE) {
-            btc_media_flush_q(&(btc_media_cb.RxSbcQ));
+            btc_media_flush_q(btc_media_cb.RxSbcQ);
             return;
         }
 
-        while ((p_msg = (tBT_SBC_HDR *)GKI_getfirst(&(btc_media_cb.RxSbcQ))) != NULL ) {
+        while ((p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(btc_media_cb.RxSbcQ)) != NULL ) {
             btc_media_task_handle_inc_media(p_msg);
-            p_msg = GKI_dequeue(&(btc_media_cb.RxSbcQ));
+            p_msg = (tBT_SBC_HDR *)fixed_queue_try_dequeue(btc_media_cb.RxSbcQ);
             if ( p_msg == NULL ) {
                 APPL_TRACE_ERROR("Insufficient data in que ");
                 break;
             }
-            GKI_freebuf(p_msg);
+            osi_free(p_msg);
         }
         APPL_TRACE_DEBUG(" Process Frames - ");
     }
@@ -551,6 +550,8 @@ static void btc_media_thread_init(UNUSED_ATTR void *context)
     btc_media_cb.av_sm_hdl = btc_av_get_sm_handle();
     raise_priority_a2dp(TASK_HIGH_MEDIA);
     media_task_running = MEDIA_TASK_STATE_ON;
+
+    btc_media_cb.RxSbcQ = fixed_queue_new(SIZE_MAX);
 }
 
 static void btc_media_thread_cleanup(UNUSED_ATTR void *context)
@@ -561,6 +562,8 @@ static void btc_media_thread_cleanup(UNUSED_ATTR void *context)
     btc_media_cb.data_channel_open = FALSE;
     /* Clear media task flag */
     media_task_running = MEDIA_TASK_STATE_OFF;
+
+    fixed_queue_free(btc_media_cb.RxSbcQ, osi_free_func);
 }
 
 /*******************************************************************************
@@ -572,10 +575,10 @@ static void btc_media_thread_cleanup(UNUSED_ATTR void *context)
  ** Returns          void
  **
  *******************************************************************************/
-static void btc_media_flush_q(BUFFER_Q *p_q)
+static void btc_media_flush_q(fixed_queue_t *p_q)
 {
-    while (!GKI_queue_is_empty(p_q)) {
-        GKI_freebuf(GKI_dequeue(p_q));
+    while (! fixed_queue_is_empty(p_q)) {
+           osi_free(fixed_queue_try_dequeue(p_q));
     }
 }
 
@@ -600,7 +603,7 @@ static void btc_media_thread_handle_cmd(fixed_queue_t *queue)
         default:
             APPL_TRACE_ERROR("ERROR in %s unknown event %d\n", __func__, p_msg->event);
         }
-        GKI_freebuf(p_msg);
+        osi_free(p_msg);
         APPL_TRACE_VERBOSE("%s: %s DONE\n", __func__, dump_media_event(p_msg->event));
     }
 }
@@ -669,11 +672,11 @@ BOOLEAN btc_media_task_aa_rx_flush_req(void)
 {
     BT_HDR *p_buf;
 
-    if (GKI_queue_is_empty(&(btc_media_cb.RxSbcQ)) == TRUE) { /*  Que is already empty */
+    if (fixed_queue_is_empty(btc_media_cb.RxSbcQ) == TRUE) { /*  Que is already empty */
         return TRUE;
     }
 
-    if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR)))) {
+    if (NULL == (p_buf = osi_malloc(sizeof(BT_HDR)))) {
         return FALSE;
     }
 
@@ -695,10 +698,10 @@ BOOLEAN btc_media_task_aa_rx_flush_req(void)
  *******************************************************************************/
 static void btc_media_task_aa_rx_flush(void)
 {
-    /* Flush all enqueued GKI SBC  buffers (encoded) */
+    /* Flush all enqueued SBC  buffers (encoded) */
     APPL_TRACE_DEBUG("btc_media_task_aa_rx_flush");
 
-    btc_media_flush_q(&(btc_media_cb.RxSbcQ));
+    btc_media_flush_q(btc_media_cb.RxSbcQ);
 }
 
 int btc_a2dp_get_track_frequency(UINT8 frequency)
@@ -896,29 +899,29 @@ UINT8 btc_media_sink_enque_buf(BT_HDR *p_pkt)
     tBT_SBC_HDR *p_msg;
 
     if (btc_media_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/
-        return GKI_queue_length(&btc_media_cb.RxSbcQ);
+        return fixed_queue_length(btc_media_cb.RxSbcQ);
     }
 
-    if (GKI_queue_length(&btc_media_cb.RxSbcQ) >= MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ) {
+    if (fixed_queue_length(btc_media_cb.RxSbcQ) >= MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ) {
         APPL_TRACE_WARNING("Pkt dropped\n");
-        return GKI_queue_length(&btc_media_cb.RxSbcQ);
+        return fixed_queue_length(btc_media_cb.RxSbcQ);
     }
 
     APPL_TRACE_DEBUG("btc_media_sink_enque_buf + ");
 
     /* allocate and Queue this buffer */
-    if ((p_msg = (tBT_SBC_HDR *) GKI_getbuf(sizeof(tBT_SBC_HDR) +
+    if ((p_msg = (tBT_SBC_HDR *) osi_malloc(sizeof(tBT_SBC_HDR) +
                                             p_pkt->offset + p_pkt->len)) != NULL) {
         memcpy(p_msg, p_pkt, (sizeof(BT_HDR) + p_pkt->offset + p_pkt->len));
         p_msg->num_frames_to_be_processed = (*((UINT8 *)(p_msg + 1) + p_msg->offset)) & 0x0f;
         APPL_TRACE_VERBOSE("btc_media_sink_enque_buf %d + \n", p_msg->num_frames_to_be_processed);
-        GKI_enqueue(&(btc_media_cb.RxSbcQ), p_msg);
+        fixed_queue_enqueue(btc_media_cb.RxSbcQ, p_msg);
         btc_media_data_post();
     } else {
         /* let caller deal with a failed allocation */
         APPL_TRACE_WARNING("btc_media_sink_enque_buf No Buffer left - ");
     }
-    return GKI_queue_length(&btc_media_cb.RxSbcQ);
+    return fixed_queue_length(btc_media_cb.RxSbcQ);
 }
 
 /*******************************************************************************
index 083cb876bb78df66cd62ce2e93a5f7b440811b04..838183970b2cb81f13277c51554e839e085fd27c 100644 (file)
 #include "bta_api.h"
 #include "bta_av_api.h"
 #include "avrc_defs.h"
-#include "gki.h"
 #include "btc_common.h"
 #include "btc_util.h"
 #include "btc_av.h"
 #include "btc_avrc.h"
 #include "btc_manage.h"
 #include "esp_avrc_api.h"
+#include "mutex.h"
+
 #if BTC_AV_INCLUDED
 
 /*****************************************************************************
@@ -86,7 +87,7 @@ typedef struct {
 } rc_transaction_t;
 
 typedef struct {
-    pthread_mutex_t lbllock;
+    osi_mutex_t lbllock;
     rc_transaction_t transaction[MAX_TRANSACTIONS_PER_SESSION];
 } rc_device_t;
 
index 357db6eb764be9bebc81e20090b982275dae7b59..f880428353b4af8962683d30909b2214c5c24d7a 100644 (file)
@@ -266,13 +266,13 @@ tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR *p_info)
         while (dis_attr_bit && i < (DIS_MAX_CHAR_NUM - 1 )) {
             if (dis_attr_bit & (UINT16)(1 << i)) {
                 if (dis_cb.dis_value.data_string[i - 1] != NULL) {
-                    GKI_freebuf(dis_cb.dis_value.data_string[i - 1]);
+                    osi_free(dis_cb.dis_value.data_string[i - 1]);
                 }
                 /* coverity[OVERRUN-STATIC] False-positive : when i = 8, (1 << i) == DIS_ATTR_PNP_ID_BIT, and it will never come down here
                 CID 49902: Out-of-bounds read (OVERRUN_STATIC)
                 Overrunning static array "dis_cb.dis_value.data_string", with 7 elements, at position 7 with index variable "i".
                 */
-                if ((dis_cb.dis_value.data_string[i - 1] = (UINT8 *)GKI_getbuf((UINT16)(p_info->data_str.len + 1))) != NULL) {
+                if ((dis_cb.dis_value.data_string[i - 1] = (UINT8 *)osi_malloc((UINT16)(p_info->data_str.len + 1))) != NULL) {
 
                     memcpy(dis_cb.dis_value.data_string[i - 1], p_info->data_str.p_data, p_info->data_str.len);
                     dis_cb.dis_value.data_string[i - 1][p_info->data_str.len] = 0; /* make sure null terminate */
index a9a667f4edfa072d78f785b9e0aa38661a35bcf5..43ab55e659744d023a3929b2c6479d802471fc46 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <string.h>
 
+#include "allocator.h"
 #include "bt_types.h"
 #include "bt_defs.h"
 #include "bta_api.h"
@@ -42,7 +43,7 @@ static void btc_gap_adv_point_cleanup(void **buf)
     if (NULL == *buf) {
         return;
     }
-    GKI_freebuf(*buf);
+    osi_free(*buf);
     *buf = NULL;
 }
 
@@ -199,9 +200,9 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
     }
 
     if (p_adv_data->manufacturer_len > 0 && p_adv_data->p_manufacturer_data != NULL) {
-        bta_adv_data->p_manu = GKI_getbuf(sizeof(tBTA_BLE_MANU));
+        bta_adv_data->p_manu = osi_malloc(sizeof(tBTA_BLE_MANU));
         if (bta_adv_data->p_manu != NULL) {
-            bta_adv_data->p_manu->p_val = GKI_getbuf(p_adv_data->manufacturer_len);
+            bta_adv_data->p_manu->p_val = osi_malloc(p_adv_data->manufacturer_len);
             if (bta_adv_data->p_manu->p_val != NULL) {
                 mask |= BTM_BLE_AD_BIT_MANU;
                 bta_adv_data->p_manu->len = p_adv_data->manufacturer_len;
@@ -212,35 +213,35 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
 
     tBTA_BLE_PROP_ELEM *p_elem_service_data = NULL;
     if (p_adv_data->service_data_len > 0 && p_adv_data->p_service_data != NULL) {
-        p_elem_service_data = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM));
+        p_elem_service_data = osi_malloc(sizeof(tBTA_BLE_PROP_ELEM));
         if (p_elem_service_data != NULL) {
-            p_elem_service_data->p_val = GKI_getbuf(p_adv_data->service_data_len);
+            p_elem_service_data->p_val = osi_malloc(p_adv_data->service_data_len);
             if (p_elem_service_data->p_val != NULL) {
                 p_elem_service_data->adv_type = BTM_BLE_AD_TYPE_SERVICE_DATA;
                 p_elem_service_data->len = p_adv_data->service_data_len;
                 memcpy(p_elem_service_data->p_val, p_adv_data->p_service_data,
                        p_adv_data->service_data_len);
             } else {
-                GKI_freebuf(p_elem_service_data);
+                osi_free(p_elem_service_data);
                 p_elem_service_data = NULL;
             }
         }
     }
 
     if (NULL != p_elem_service_data) {
-        bta_adv_data->p_proprietary = GKI_getbuf(sizeof(tBTA_BLE_PROPRIETARY));
+        bta_adv_data->p_proprietary = osi_malloc(sizeof(tBTA_BLE_PROPRIETARY));
         if (NULL != bta_adv_data->p_proprietary) {
             tBTA_BLE_PROP_ELEM *p_elem = NULL;
             tBTA_BLE_PROPRIETARY *p_prop = bta_adv_data->p_proprietary;
             p_prop->num_elem = 0;
             mask |= BTM_BLE_AD_BIT_PROPRIETARY;
             p_prop->num_elem = 1;
-            p_prop->p_elem = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM) * p_prop->num_elem);
+            p_prop->p_elem = osi_malloc(sizeof(tBTA_BLE_PROP_ELEM) * p_prop->num_elem);
             p_elem = p_prop->p_elem;
             if (NULL != p_elem) {
                 memcpy(p_elem++, p_elem_service_data, sizeof(tBTA_BLE_PROP_ELEM));
             }
-            GKI_freebuf(p_elem_service_data);
+            osi_free(p_elem_service_data);
         }
     }
 
@@ -255,10 +256,10 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
             switch (bt_uuid.len) {
             case (LEN_UUID_16): {
                 if (NULL == bta_adv_data->p_services) {
-                    bta_adv_data->p_services = GKI_getbuf(sizeof(tBTA_BLE_SERVICE));
+                    bta_adv_data->p_services = osi_malloc(sizeof(tBTA_BLE_SERVICE));
                     bta_adv_data->p_services->list_cmpl = FALSE;
                     bta_adv_data->p_services->num_service = 0;
-                    bta_adv_data->p_services->p_uuid = GKI_getbuf(p_adv_data->service_uuid_len / LEN_UUID_128 * LEN_UUID_16);
+                    bta_adv_data->p_services->p_uuid = osi_malloc(p_adv_data->service_uuid_len / LEN_UUID_128 * LEN_UUID_16);
                     p_uuid_out16 = bta_adv_data->p_services->p_uuid;
                 }
 
@@ -274,11 +275,11 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
             case (LEN_UUID_32): {
                 if (NULL == bta_adv_data->p_service_32b) {
                     bta_adv_data->p_service_32b =
-                        GKI_getbuf(sizeof(tBTA_BLE_32SERVICE));
+                        osi_malloc(sizeof(tBTA_BLE_32SERVICE));
                     bta_adv_data->p_service_32b->list_cmpl = FALSE;
                     bta_adv_data->p_service_32b->num_service = 0;
                     bta_adv_data->p_service_32b->p_uuid =
-                        GKI_getbuf(p_adv_data->service_uuid_len / LEN_UUID_128 * LEN_UUID_32);
+                        osi_malloc(p_adv_data->service_uuid_len / LEN_UUID_128 * LEN_UUID_32);
                     p_uuid_out32 = bta_adv_data->p_service_32b->p_uuid;
                 }
 
@@ -295,7 +296,7 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
                 /* Currently, only one 128-bit UUID is supported */
                 if (NULL == bta_adv_data->p_services_128b) {
                     bta_adv_data->p_services_128b =
-                        GKI_getbuf(sizeof(tBTA_BLE_128SERVICE));
+                        osi_malloc(sizeof(tBTA_BLE_128SERVICE));
                     if (NULL != bta_adv_data->p_services_128b) {
                         LOG_ERROR("%s - In 128-UUID_data", __FUNCTION__);
                         mask |= BTM_BLE_AD_BIT_SERVICE_128;
@@ -757,16 +758,27 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
     param.set_rand_addr_cmpl.status = ESP_BT_STATUS_SUCCESS;
 
     if (rand_addr != NULL) {
-        if((rand_addr[BD_ADDR_LEN - 1] & BT_STATIC_RAND_ADDR_MASK)
-            == BT_STATIC_RAND_ADDR_MASK) {
+        /*
+        A static address is a 48-bit randomly generated address and shall meet the following requirements:
+        • The two most significant bits of the address shall be equal to 1
+        • All bits of the random part of the address shall not be equal to 1
+        • All bits of the random part of the address shall not be equal to 0
+        */
+        BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b;
+        memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR));
+        memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR));
+        invalid_rand_addr_b[BD_ADDR_LEN - 1] = invalid_rand_addr_b[BD_ADDR_LEN - 1] | BT_STATIC_RAND_ADDR_MASK;
+        if((rand_addr[BD_ADDR_LEN - 1] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK
+            && memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0
+            && memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0){
             BTA_DmSetRandAddress(rand_addr);
         } else {
             param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
-            LOG_ERROR("Invalid randrom address, the high bit should be 0x11xx");
+            LOG_ERROR("Invalid random address, the high bit should be 0b11, the random part shall not be to 1 or 0");
         }
     } else {
         param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
-        LOG_ERROR("Invalid randrom addressm, the address value is NULL");
+        LOG_ERROR("Invalid random addressm, the address value is NULL");
     }
 
     msg.sig = BTC_SIG_API_CB;
@@ -826,7 +838,7 @@ static void btc_ble_get_bond_device_list(void)
     esp_ble_bond_dev_t *bond_dev;
     btc_msg_t msg;
     int num_dev = btc_storage_get_num_ble_bond_devices();
-    bond_dev = GKI_getbuf(sizeof(esp_ble_bond_dev_t)*num_dev);
+    bond_dev = (esp_ble_bond_dev_t *)osi_malloc(sizeof(esp_ble_bond_dev_t)*num_dev);
 
     param.get_bond_dev_cmpl.status = btc_get_bonded_ble_devices_list(bond_dev);
     param.get_bond_dev_cmpl.dev_num = num_dev;
@@ -841,7 +853,7 @@ static void btc_ble_get_bond_device_list(void)
         LOG_ERROR("%s btc_transfer_context failed", __func__);
     }
     // release the buffer after used.
-    GKI_freebuf((void *)bond_dev);
+    osi_free(bond_dev);
 }
 #endif /* #if (SMP_INCLUDED) */
 
@@ -877,18 +889,18 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
         btc_ble_gap_args_t  *dst = (btc_ble_gap_args_t *) p_dest;
 
         if (src->cfg_adv_data.adv_data.p_manufacturer_data) {
-            dst->cfg_adv_data.adv_data.p_manufacturer_data = GKI_getbuf(src->cfg_adv_data.adv_data.manufacturer_len);
+            dst->cfg_adv_data.adv_data.p_manufacturer_data = osi_malloc(src->cfg_adv_data.adv_data.manufacturer_len);
             memcpy(dst->cfg_adv_data.adv_data.p_manufacturer_data, src->cfg_adv_data.adv_data.p_manufacturer_data,
                    src->cfg_adv_data.adv_data.manufacturer_len);
         }
 
         if (src->cfg_adv_data.adv_data.p_service_data) {
-            dst->cfg_adv_data.adv_data.p_service_data = GKI_getbuf(src->cfg_adv_data.adv_data.service_data_len);
+            dst->cfg_adv_data.adv_data.p_service_data = osi_malloc(src->cfg_adv_data.adv_data.service_data_len);
             memcpy(dst->cfg_adv_data.adv_data.p_service_data, src->cfg_adv_data.adv_data.p_service_data, src->cfg_adv_data.adv_data.service_data_len);
         }
 
         if (src->cfg_adv_data.adv_data.p_service_uuid) {
-            dst->cfg_adv_data.adv_data.p_service_uuid = GKI_getbuf(src->cfg_adv_data.adv_data.service_uuid_len);
+            dst->cfg_adv_data.adv_data.p_service_uuid = osi_malloc(src->cfg_adv_data.adv_data.service_uuid_len);
             memcpy(dst->cfg_adv_data.adv_data.p_service_uuid, src->cfg_adv_data.adv_data.p_service_uuid, src->cfg_adv_data.adv_data.service_uuid_len);
         }
         break;
@@ -898,7 +910,7 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
         btc_ble_gap_args_t *dst = (btc_ble_gap_args_t *) p_dest;
 
         if (src && src->cfg_adv_data_raw.raw_adv && src->cfg_adv_data_raw.raw_adv_len > 0) {
-            dst->cfg_adv_data_raw.raw_adv = GKI_getbuf(src->cfg_adv_data_raw.raw_adv_len);
+            dst->cfg_adv_data_raw.raw_adv = osi_malloc(src->cfg_adv_data_raw.raw_adv_len);
             if (dst->cfg_adv_data_raw.raw_adv) {
                 memcpy(dst->cfg_adv_data_raw.raw_adv, src->cfg_adv_data_raw.raw_adv, src->cfg_adv_data_raw.raw_adv_len);
             }
@@ -910,7 +922,7 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
         btc_ble_gap_args_t *dst = (btc_ble_gap_args_t *) p_dest;
 
         if (src && src->cfg_scan_rsp_data_raw.raw_scan_rsp && src->cfg_scan_rsp_data_raw.raw_scan_rsp_len > 0) {
-            dst->cfg_scan_rsp_data_raw.raw_scan_rsp = GKI_getbuf(src->cfg_scan_rsp_data_raw.raw_scan_rsp_len);
+            dst->cfg_scan_rsp_data_raw.raw_scan_rsp = osi_malloc(src->cfg_scan_rsp_data_raw.raw_scan_rsp_len);
             if (dst->cfg_scan_rsp_data_raw.raw_scan_rsp) {
                 memcpy(dst->cfg_scan_rsp_data_raw.raw_scan_rsp, src->cfg_scan_rsp_data_raw.raw_scan_rsp, src->cfg_scan_rsp_data_raw.raw_scan_rsp_len);
             }
@@ -923,7 +935,7 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
         uint8_t length = 0;
         if (src->set_security_param.value) {
             length = dst->set_security_param.len;
-            dst->set_security_param.value = GKI_getbuf(length);
+            dst->set_security_param.value = osi_malloc(length);
             if (dst->set_security_param.value != NULL) {
                 memcpy(dst->set_security_param.value, src->set_security_param.value, length);
             } else {
@@ -947,7 +959,7 @@ void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
         uint16_t length = 0;
         if (src->get_bond_dev_cmpl.bond_dev) {
             length = (src->get_bond_dev_cmpl.dev_num)*sizeof(esp_ble_bond_dev_t);
-            dst->get_bond_dev_cmpl.bond_dev = GKI_getbuf(length);
+            dst->get_bond_dev_cmpl.bond_dev = (esp_ble_bond_dev_t *)osi_malloc(length);
             if (dst->get_bond_dev_cmpl.bond_dev != NULL) {
                 memcpy(dst->get_bond_dev_cmpl.bond_dev, src->get_bond_dev_cmpl.bond_dev, length);
             } else {
@@ -969,29 +981,29 @@ void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
     case BTC_GAP_BLE_ACT_CFG_ADV_DATA: {
         esp_ble_adv_data_t *adv = &((btc_ble_gap_args_t *)msg->arg)->cfg_adv_data.adv_data;
         if (adv->p_service_data) {
-            GKI_freebuf(adv->p_service_data);
+            osi_free(adv->p_service_data);
         }
 
         if (adv->p_service_uuid) {
-            GKI_freebuf(adv->p_service_uuid);
+            osi_free(adv->p_service_uuid);
         }
 
         if (adv->p_manufacturer_data) {
-            GKI_freebuf(adv->p_manufacturer_data);
+            osi_free(adv->p_manufacturer_data);
         }
         break;
     }
     case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW: {
         uint8_t *raw_adv = ((btc_ble_gap_args_t *)msg->arg)->cfg_adv_data_raw.raw_adv;
         if (raw_adv) {
-            GKI_freebuf(raw_adv);
+            osi_free(raw_adv);
         }
         break;
     }
     case BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW: {
         uint8_t *raw_scan_rsp = ((btc_ble_gap_args_t *)msg->arg)->cfg_scan_rsp_data_raw.raw_scan_rsp;
         if (raw_scan_rsp) {
-            GKI_freebuf(raw_scan_rsp);
+            osi_free(raw_scan_rsp);
         }
         break;
     }
@@ -1008,7 +1020,7 @@ void btc_gap_ble_cb_deep_free(btc_msg_t *msg)
         case ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT: {
             esp_ble_bond_dev_t *bond_dev = ((esp_ble_gap_cb_param_t *)msg->arg)->get_bond_dev_cmpl.bond_dev;
             if (bond_dev) {
-                GKI_freebuf((void *)bond_dev);
+                osi_free(bond_dev);
             }
             break;
         }
index bc8f665a80828b1eaeb2bfaa89f2a4f29aff7fb6..62d6ed4e0bde1a90af7913e103f10cd949e93eb7 100644 (file)
@@ -20,6 +20,7 @@
 #include "btc_manage.h"
 #include "bta_gatt_api.h"
 #include "bt_trace.h"
+#include "allocator.h"
 #include "esp_gattc_api.h"
 
 #if (GATTC_INCLUDED == TRUE)
@@ -38,7 +39,7 @@ void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
 
     switch (msg->act) {
     case BTC_GATTC_ACT_WRITE_CHAR: {
-        dst->write_char.value = (uint8_t *)GKI_getbuf(src->write_char.value_len);
+        dst->write_char.value = (uint8_t *)osi_malloc(src->write_char.value_len);
         if (dst->write_char.value) {
             memcpy(dst->write_char.value, src->write_char.value, src->write_char.value_len);
         } else {
@@ -47,7 +48,7 @@ void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
         break;
     }
     case BTC_GATTC_ACT_WRITE_CHAR_DESCR: {
-        dst->write_descr.value = (uint8_t *)GKI_getbuf(src->write_descr.value_len);
+        dst->write_descr.value = (uint8_t *)osi_malloc(src->write_descr.value_len);
         if (dst->write_descr.value) {
             memcpy(dst->write_descr.value, src->write_descr.value, src->write_descr.value_len);
         } else {
@@ -56,7 +57,7 @@ void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
         break;
     }
     case BTC_GATTC_ACT_PREPARE_WRITE: {
-        dst->prep_write.value = (uint8_t *)GKI_getbuf(src->prep_write.value_len);
+        dst->prep_write.value = (uint8_t *)osi_malloc(src->prep_write.value_len);
         if (dst->prep_write.value) {
             memcpy(dst->prep_write.value, src->prep_write.value, src->prep_write.value_len);
         } else {
@@ -65,7 +66,7 @@ void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
         break;
     }
     case BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR: {
-        dst->prep_write_descr.value = (uint8_t *)GKI_getbuf(src->prep_write_descr.value_len);
+        dst->prep_write_descr.value = (uint8_t *)osi_malloc(src->prep_write_descr.value_len);
         if (dst->prep_write_descr.value) {
             memcpy(dst->prep_write_descr.value, src->prep_write_descr.value, src->prep_write_descr.value_len);
         } else {
@@ -86,25 +87,25 @@ void btc_gattc_arg_deep_free(btc_msg_t *msg)
     switch (msg->act) {
     case BTC_GATTC_ACT_WRITE_CHAR: {
         if (arg->write_char.value) {
-            GKI_freebuf(arg->write_char.value);
+            osi_free(arg->write_char.value);
         }
         break;
     }
     case BTC_GATTC_ACT_WRITE_CHAR_DESCR: {
         if (arg->write_descr.value) {
-            GKI_freebuf(arg->write_descr.value);
+            osi_free(arg->write_descr.value);
         }
         break;
     }
     case BTC_GATTC_ACT_PREPARE_WRITE: {
         if (arg->prep_write.value) {
-            GKI_freebuf(arg->prep_write.value);
+            osi_free(arg->prep_write.value);
         }
         break;
     }
     case BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR: {
         if (arg->prep_write_descr.value) {
-            GKI_freebuf(arg->prep_write_descr.value);
+            osi_free(arg->prep_write_descr.value);
         }
         break;
     }
@@ -757,4 +758,4 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
     btc_gattc_free_req_data(msg);
 }
 
-#endif  ///GATTC_INCLUDED == TRUE
\ No newline at end of file
+#endif  ///GATTC_INCLUDED == TRUE
index 35c6094bf7d0b0e5fbe776a724ed1c97b5d369d1..df2d742127caea9189a67dd2b5cbc4ce3ca230ca 100644 (file)
@@ -21,6 +21,7 @@
 #include "btc_gatts.h"
 #include "btc_gatt_util.h"
 #include "future.h"
+#include "allocator.h"
 #include "btc_main.h"
 #include "esp_gatts_api.h"
 
@@ -80,7 +81,7 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
 
     switch (msg->act) {
     case BTC_GATTS_ACT_SEND_INDICATE: {
-        dst->send_ind.value = (uint8_t *)GKI_getbuf(src->send_ind.value_len);
+        dst->send_ind.value = (uint8_t *)osi_malloc(src->send_ind.value_len);
         if (dst->send_ind.value) {
             memcpy(dst->send_ind.value, src->send_ind.value, src->send_ind.value_len);
         } else {
@@ -90,7 +91,7 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
     }
     case BTC_GATTS_ACT_SEND_RESPONSE: {
         if (src->send_rsp.rsp) {
-            dst->send_rsp.rsp = (esp_gatt_rsp_t *)GKI_getbuf(sizeof(esp_gatt_rsp_t));
+            dst->send_rsp.rsp = (esp_gatt_rsp_t *)osi_malloc(sizeof(esp_gatt_rsp_t));
             if (dst->send_rsp.rsp) {
                 memcpy(dst->send_rsp.rsp, src->send_rsp.rsp, sizeof(esp_gatt_rsp_t));
             } else {
@@ -102,7 +103,7 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
     }
     case BTC_GATTS_ACT_ADD_CHAR:{
         if (src->add_char.char_val.attr_value != NULL){
-            dst->add_char.char_val.attr_value = (uint8_t *)GKI_getbuf(src->add_char.char_val.attr_len);
+            dst->add_char.char_val.attr_value = (uint8_t *)osi_malloc(src->add_char.char_val.attr_len);
             if(dst->add_char.char_val.attr_value != NULL){
                 memcpy(dst->add_char.char_val.attr_value, src->add_char.char_val.attr_value, 
                         src->add_char.char_val.attr_len);
@@ -114,7 +115,7 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
     }
     case BTC_GATTS_ACT_ADD_CHAR_DESCR:{
         if(src->add_descr.descr_val.attr_value != NULL){
-            dst->add_descr.descr_val.attr_value = (uint8_t *)GKI_getbuf(src->add_descr.descr_val.attr_len);
+            dst->add_descr.descr_val.attr_value = (uint8_t *)osi_malloc(src->add_descr.descr_val.attr_len);
             if(dst->add_descr.descr_val.attr_value != NULL){
                 memcpy(dst->add_descr.descr_val.attr_value, src->add_descr.descr_val.attr_value,
                         src->add_descr.descr_val.attr_len);
@@ -127,7 +128,7 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
     case BTC_GATTS_ACT_CREATE_ATTR_TAB:{
         uint8_t num_attr = src->create_attr_tab.max_nb_attr;
         if(src->create_attr_tab.gatts_attr_db != NULL){
-            dst->create_attr_tab.gatts_attr_db = (esp_gatts_attr_db_t *)GKI_getbuf(sizeof(esp_gatts_attr_db_t)*num_attr);
+            dst->create_attr_tab.gatts_attr_db = (esp_gatts_attr_db_t *)osi_malloc(sizeof(esp_gatts_attr_db_t)*num_attr);
             if(dst->create_attr_tab.gatts_attr_db != NULL){
                 memcpy(dst->create_attr_tab.gatts_attr_db, src->create_attr_tab.gatts_attr_db,
                         sizeof(esp_gatts_attr_db_t)*num_attr);
@@ -140,7 +141,7 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
    case BTC_GATTS_ACT_SET_ATTR_VALUE:{
         uint16_t len = src->set_attr_val.length;
         if(src->set_attr_val.value){
-            dst->set_attr_val.value = (uint8_t *)GKI_getbuf(len);
+            dst->set_attr_val.value = (uint8_t *)osi_malloc(len);
             if(dst->set_attr_val.value != NULL){
                 memcpy(dst->set_attr_val.value, src->set_attr_val.value, len);
             }else{
@@ -163,37 +164,37 @@ void btc_gatts_arg_deep_free(btc_msg_t *msg)
     switch (msg->act) {
     case BTC_GATTS_ACT_SEND_INDICATE: {
         if (arg->send_ind.value) {
-            GKI_freebuf(arg->send_ind.value);
+            osi_free(arg->send_ind.value);
         }
         break;
     }
     case BTC_GATTS_ACT_SEND_RESPONSE: {
         if (arg->send_rsp.rsp) {
-            GKI_freebuf(arg->send_rsp.rsp);
+            osi_free(arg->send_rsp.rsp);
         }
         break;
     }
     case BTC_GATTS_ACT_ADD_CHAR:{
         if (arg->add_char.char_val.attr_value != NULL) {
-            GKI_freebuf(arg->add_char.char_val.attr_value);
+            osi_free(arg->add_char.char_val.attr_value);
         }
         break;
     }
     case BTC_GATTS_ACT_ADD_CHAR_DESCR:{
         if (arg->add_descr.descr_val.attr_value != NULL){
-            GKI_freebuf(arg->add_descr.descr_val.attr_value);
+            osi_free(arg->add_descr.descr_val.attr_value);
         }
         break;
     }
     case BTC_GATTS_ACT_CREATE_ATTR_TAB:{
         if (arg->create_attr_tab.gatts_attr_db != NULL){
-            GKI_freebuf(arg->create_attr_tab.gatts_attr_db);
+            osi_free(arg->create_attr_tab.gatts_attr_db);
         }
         break;
     }
     case BTC_GATTS_ACT_SET_ATTR_VALUE:{
         if (arg->set_attr_val.value != NULL){
-            GKI_freebuf(arg->set_attr_val.value);
+            osi_free(arg->set_attr_val.value);
         }
     }
         break;
@@ -501,7 +502,7 @@ static void btc_gatts_cb_param_copy_req(btc_msg_t *msg, void *p_dest, void *p_sr
     case BTA_GATTS_WRITE_EVT:
     case BTA_GATTS_EXEC_WRITE_EVT:
     case BTA_GATTS_MTU_EVT:
-        p_dest_data->req_data.p_data = GKI_getbuf(sizeof(tBTA_GATTS_REQ_DATA));
+        p_dest_data->req_data.p_data = osi_malloc(sizeof(tBTA_GATTS_REQ_DATA));
         if (p_dest_data->req_data.p_data != NULL) {
             memcpy(p_dest_data->req_data.p_data, p_src_data->req_data.p_data,
                    sizeof(tBTA_GATTS_REQ_DATA));
@@ -523,7 +524,7 @@ static void btc_gatts_cb_param_copy_free(btc_msg_t *msg, tBTA_GATTS *p_data)
     case BTA_GATTS_EXEC_WRITE_EVT:
     case BTA_GATTS_MTU_EVT:
         if (p_data && p_data->req_data.p_data) {
-            GKI_freebuf(p_data->req_data.p_data);
+            osi_free(p_data->req_data.p_data);
         }
         break;
     default:
@@ -906,4 +907,4 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
     btc_gatts_cb_param_copy_free(msg, p_data);
 }
 
-#endif  ///GATTS_INCLUDED
\ No newline at end of file
+#endif  ///GATTS_INCLUDED
index a25da98778ee3d1f0cf1c0ed780fc2f5fb52b652..66ad366fbfcbe62797fb68230da8844d165d6fda 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <stdbool.h>
 #include "bta_api.h"
-#include "gki.h"
 #include "btc_av_api.h"
 
 #if (BTA_AV_INCLUDED == TRUE)
@@ -174,9 +173,9 @@ extern BOOLEAN btc_media_task_aa_tx_flush_req(void);
  **
  ** Function         btc_media_aa_readbuf
  **
- ** Description      Read an audio GKI buffer from the BTC media TX queue
+ ** Description      Read an audio buffer from the BTC media TX queue
  **
- ** Returns          pointer on a GKI aa buffer ready to send
+ ** Returns          pointer on a aa buffer ready to send
  **
  *******************************************************************************/
 extern BT_HDR *btc_media_aa_readbuf(void);
@@ -198,7 +197,7 @@ UINT8 btc_media_sink_enque_buf(BT_HDR *p_buf);
  **
  ** Function         btc_media_aa_writebuf
  **
- ** Description      Enqueue a Advance Audio media GKI buffer to be processed by btc media task.
+ ** Description      Enqueue a Advance Audio media buffer to be processed by btc media task.
  **
  ** Returns          TRUE is success
  **
@@ -209,7 +208,7 @@ extern void btc_media_aa_writebuf(BT_HDR *pBuf, UINT32 timestamp, UINT16 seq_num
  **
  ** Function         btc_media_av_writebuf
  **
- ** Description      Enqueue a video media GKI buffer to be processed by btc media task.
+ ** Description      Enqueue a video media buffer to be processed by btc media task.
  **
  ** Returns          TRUE is success
  **
index af888b5b0ecfbf38c4a01a9dfed4a12e69b66e0e..bd40a044e61393e0798f8b3e95f88b3d632c18ab 100644 (file)
@@ -326,7 +326,7 @@ void bta_dm_sco_co_in_data(BT_HDR  *p_buf)
     if (btui_cfg.sco_use_mic) {
         btui_sco_codec_inqdata (p_buf);
     } else {
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
     }
 }
 
index 380b7932b7387d554bd7ade77deaf8f83dfb5316..b716766a7f41a44783ee48b146d169e24646dba1 100644 (file)
@@ -20,7 +20,6 @@
 #include <unistd.h>
 #endif /* BT_SUPPORT_NVM */
 
-#include "gki.h"
 #include "bta_gattc_co.h"
 #include "bta_gattc_ci.h"
 // #include "btif_util.h"
index 77b6c35b155d758eda5471818615a4e772ca718d..9469c15832d1b2f96811bad4de9fa894b152c3bc 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include "gki.h"
 #include "bta_gatts_co.h"
 // #include "btif_util.h"
 
diff --git a/components/bt/bluedroid/gki/gki_buffer.c b/components/bt/bluedroid/gki/gki_buffer.c
deleted file mode 100644 (file)
index 9ce9a12..0000000
+++ /dev/null
@@ -1,551 +0,0 @@
-/******************************************************************************
- *
- *  Copyright (C) 1999-2012 Broadcom Corporation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at:
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- ******************************************************************************/
-
-#include "bt_trace.h"
-#include "allocator.h"
-#include "gki_int.h"
-
-/*******************************************************************************
-**
-** Function         gki_init_free_queue
-**
-** Description      Internal function called at startup to initialize a free
-**                  queue. It is called once for each free queue.
-**
-** Returns          void
-**
-*******************************************************************************/
-static void gki_init_free_queue (UINT8 id, UINT16 size, UINT16 total, void *p_mem)
-{
-    UINT16           i;
-    UINT16           act_size;
-    BUFFER_HDR_T    *hdr;
-    BUFFER_HDR_T    *hdr1 = NULL;
-    UINT32          *magic;
-    INT32            tempsize = size;
-    tGKI_COM_CB     *p_cb = &gki_cb.com;
-
-    /* Ensure an even number of longwords */
-    tempsize = (INT32)ALIGN_POOL(size);
-    act_size = (UINT16)(tempsize + BUFFER_PADDING_SIZE);
-
-    /* Remember pool start and end addresses */
-    if (p_mem) {
-        p_cb->pool_start[id] = (UINT8 *)p_mem;
-        p_cb->pool_end[id]   = (UINT8 *)p_mem + (act_size * total);
-    }
-
-    p_cb->pool_size[id]  = act_size;
-
-    p_cb->freeq[id].size      = (UINT16) tempsize;
-    p_cb->freeq[id].total     = total;
-    p_cb->freeq[id].cur_cnt   = 0;
-    p_cb->freeq[id].max_cnt   = 0;
-
-    /* Initialize  index table */
-    if (p_mem) {
-        hdr = (BUFFER_HDR_T *)p_mem;
-        p_cb->freeq[id]._p_first = hdr;
-        for (i = 0; i < total; i++) {
-            hdr->q_id    = id;
-            hdr->status  = BUF_STATUS_FREE;
-            magic        = (UINT32 *)((UINT8 *)hdr + BUFFER_HDR_SIZE + tempsize);
-            *magic       = MAGIC_NO;
-            hdr1         = hdr;
-            hdr          = (BUFFER_HDR_T *)((UINT8 *)hdr + act_size);
-            hdr1->p_next = hdr;
-        }
-        hdr1->p_next = NULL;
-        p_cb->freeq[id]._p_last = hdr1;
-    }
-}
-
-void gki_buffer_cleanup(void)
-{
-    UINT8   i;
-    tGKI_COM_CB *p_cb = &gki_cb.com;
-
-    for (i = 0; i < GKI_NUM_FIXED_BUF_POOLS; i++) {
-        if ( 0 < p_cb->freeq[i].max_cnt ) {
-            osi_free(p_cb->pool_start[i]);
-
-            p_cb->freeq[i].cur_cnt   = 0;
-            p_cb->freeq[i].max_cnt   = 0;
-            p_cb->freeq[i]._p_first   = NULL;
-            p_cb->freeq[i]._p_last    = NULL;
-
-            p_cb->pool_start[i] = NULL;
-            p_cb->pool_end[i]   = NULL;
-            p_cb->pool_size[i]  = 0;
-        }
-    }
-}
-
-/*******************************************************************************
-**
-** Function         gki_buffer_init
-**
-** Description      Called once internally by GKI at startup to initialize all
-**                  buffers and free buffer pools.
-**
-** Returns          void
-**
-*******************************************************************************/
-void gki_buffer_init(void)
-{
-    static const struct {
-        uint16_t size;
-        uint16_t count;
-    } buffer_info[GKI_NUM_FIXED_BUF_POOLS] = {
-        { GKI_BUF0_SIZE, GKI_BUF0_MAX },
-        { GKI_BUF1_SIZE, GKI_BUF1_MAX },
-        { GKI_BUF2_SIZE, GKI_BUF2_MAX },
-        { GKI_BUF3_SIZE, GKI_BUF3_MAX },
-        { GKI_BUF4_SIZE, GKI_BUF4_MAX },
-        { GKI_BUF5_SIZE, GKI_BUF5_MAX },
-        { GKI_BUF6_SIZE, GKI_BUF6_MAX },
-        { GKI_BUF7_SIZE, GKI_BUF7_MAX },
-        { GKI_BUF8_SIZE, GKI_BUF8_MAX },
-        { GKI_BUF9_SIZE, GKI_BUF9_MAX },
-    };
-
-    tGKI_COM_CB *p_cb = &gki_cb.com;
-
-    for (int i = 0; i < GKI_NUM_TOTAL_BUF_POOLS; i++) {
-        p_cb->pool_start[i] = NULL;
-        p_cb->pool_end[i]   = NULL;
-        p_cb->pool_size[i]  = 0;
-
-        p_cb->freeq[i]._p_first = 0;
-        p_cb->freeq[i]._p_last  = 0;
-        p_cb->freeq[i].size    = 0;
-        p_cb->freeq[i].total   = 0;
-        p_cb->freeq[i].cur_cnt = 0;
-        p_cb->freeq[i].max_cnt = 0;
-    }
-
-    /* Use default from target.h */
-    p_cb->pool_access_mask = GKI_DEF_BUFPOOL_PERM_MASK;
-
-    for (int i = 0; i < GKI_NUM_FIXED_BUF_POOLS; ++i) {
-        gki_init_free_queue(i, buffer_info[i].size, buffer_info[i].count, NULL);
-    }
-}
-
-/*******************************************************************************
-**
-** Function         GKI_init_q
-**
-** Description      Called by an application to initialize a buffer queue.
-**
-** Returns          void
-**
-*******************************************************************************/
-void GKI_init_q (BUFFER_Q *p_q)
-{
-    p_q->_p_first = p_q->_p_last = NULL;
-    p_q->_count = 0;
-}
-
-/*******************************************************************************
-**
-** Function         GKI_getbuf_func
-**
-** Description      Called by an application to get a free buffer which
-**                  is of size greater or equal to the requested size.
-**
-**                  Note: This routine only takes buffers from public pools.
-**                        It will not use any buffers from pools
-**                        marked GKI_RESTRICTED_POOL.
-**
-** Parameters       size - (input) number of bytes needed.
-**
-** Returns          A pointer to the buffer, or NULL if none available
-**
-*******************************************************************************/
-void *GKI_getbuf_func(UINT16 size)
-{
-    BUFFER_HDR_T *header = osi_malloc(size + BUFFER_HDR_SIZE);
-    if (header != NULL) {
-        header->status  = BUF_STATUS_UNLINKED;
-        header->p_next  = NULL;
-        header->Type    = 0;
-        header->size = size;
-
-        return header + 1;
-    } else {
-        return NULL;
-    }
-}
-
-/*******************************************************************************
-**
-** Function         GKI_getpoolbuf_func
-**
-** Description      Called by an application to get a free buffer from
-**                  a specific buffer pool.
-**
-**                  Note: If there are no more buffers available from the pool,
-**                        the public buffers are searched for an available buffer.
-**
-** Parameters       pool_id - (input) pool ID to get a buffer out of.
-**
-** Returns          A pointer to the buffer, or NULL if none available
-**
-*******************************************************************************/
-void *GKI_getpoolbuf_func(UINT8 pool_id)
-{
-    return GKI_getbuf_func(gki_cb.com.pool_size[pool_id]);
-}
-
-/*******************************************************************************
-**
-** Function         GKI_freebuf
-**
-** Description      Called by an application to return a buffer to the free pool.
-**
-** Parameters       p_buf - (input) address of the beginning of a buffer.
-**
-** Returns          void
-**
-*******************************************************************************/
-void GKI_freebuf (void *p_buf)
-{
-    osi_free((BUFFER_HDR_T *)p_buf - 1);
-}
-
-/*******************************************************************************
-**
-** Function         GKI_get_buf_size
-**
-** Description      Called by an application to get the size of a buffer.
-**
-** Parameters       p_buf - (input) address of the beginning of a buffer.
-**
-** Returns          the size of the buffer
-**
-*******************************************************************************/
-UINT16 GKI_get_buf_size (void *p_buf)
-{
-    BUFFER_HDR_T *header = (BUFFER_HDR_T *)p_buf - 1;
-    return header->size;
-}
-
-/*******************************************************************************
-**
-** Function         GKI_enqueue
-**
-** Description      Enqueue a buffer at the tail of the queue
-**
-** Parameters:      p_q  -  (input) pointer to a queue.
-**                  p_buf - (input) address of the buffer to enqueue
-**
-** Returns          void
-**
-*******************************************************************************/
-void GKI_enqueue (BUFFER_Q *p_q, void *p_buf)
-{
-    BUFFER_HDR_T *p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
-    assert(p_hdr->status == BUF_STATUS_UNLINKED);
-
-    GKI_disable();
-
-    /* Since the queue is exposed (C vs C++), keep the pointers in exposed format */
-    if (p_q->_p_last) {
-        BUFFER_HDR_T *_p_last_hdr = (BUFFER_HDR_T *)((UINT8 *)p_q->_p_last - BUFFER_HDR_SIZE);
-        _p_last_hdr->p_next = p_hdr;
-    } else {
-        p_q->_p_first = p_buf;
-    }
-
-    p_q->_p_last = p_buf;
-    p_q->_count++;
-
-    p_hdr->p_next = NULL;
-    p_hdr->status = BUF_STATUS_QUEUED;
-
-    GKI_enable();
-}
-
-/*******************************************************************************
-**
-** Function         GKI_dequeue
-**
-** Description      Dequeues a buffer from the head of a queue
-**
-** Parameters:      p_q  - (input) pointer to a queue.
-**
-** Returns          NULL if queue is empty, else buffer
-**
-*******************************************************************************/
-void *GKI_dequeue (BUFFER_Q *p_q)
-{
-    BUFFER_HDR_T    *p_hdr;
-
-    GKI_disable();
-
-    if (!p_q || !p_q->_count) {
-        GKI_enable();
-        return (NULL);
-    }
-
-    p_hdr = (BUFFER_HDR_T *)((UINT8 *)p_q->_p_first - BUFFER_HDR_SIZE);
-
-    /* Keep buffers such that GKI header is invisible
-    */
-    if (p_hdr->p_next) {
-        p_q->_p_first = ((UINT8 *)p_hdr->p_next + BUFFER_HDR_SIZE);
-    } else {
-        p_q->_p_first = NULL;
-        p_q->_p_last  = NULL;
-    }
-
-    p_q->_count--;
-
-    p_hdr->p_next = NULL;
-    p_hdr->status = BUF_STATUS_UNLINKED;
-
-    GKI_enable();
-
-    return ((UINT8 *)p_hdr + BUFFER_HDR_SIZE);
-}
-
-/*******************************************************************************
-**
-** Function         GKI_remove_from_queue
-**
-** Description      Dequeue a buffer from the middle of the queue
-**
-** Parameters:      p_q  - (input) pointer to a queue.
-**                  p_buf - (input) address of the buffer to enqueue
-**
-** Returns          NULL if queue is empty, else buffer
-**
-*******************************************************************************/
-void *GKI_remove_from_queue (BUFFER_Q *p_q, void *p_buf)
-{
-    BUFFER_HDR_T    *p_prev;
-    BUFFER_HDR_T    *p_buf_hdr;
-
-    GKI_disable();
-
-    if (p_buf == p_q->_p_first) {
-        GKI_enable();
-        return (GKI_dequeue (p_q));
-    }
-
-    p_buf_hdr = (BUFFER_HDR_T *)((UINT8 *)p_buf - BUFFER_HDR_SIZE);
-    p_prev    = (BUFFER_HDR_T *)((UINT8 *)p_q->_p_first - BUFFER_HDR_SIZE);
-
-    for ( ; p_prev; p_prev = p_prev->p_next) {
-        /* If the previous points to this one, move the pointers around */
-        if (p_prev->p_next == p_buf_hdr) {
-            p_prev->p_next = p_buf_hdr->p_next;
-
-            /* If we are removing the last guy in the queue, update _p_last */
-            if (p_buf == p_q->_p_last) {
-                p_q->_p_last = p_prev + 1;
-            }
-
-            /* One less in the queue */
-            p_q->_count--;
-
-            /* The buffer is now unlinked */
-            p_buf_hdr->p_next = NULL;
-            p_buf_hdr->status = BUF_STATUS_UNLINKED;
-
-            GKI_enable();
-            return (p_buf);
-        }
-    }
-
-    GKI_enable();
-    return (NULL);
-}
-
-/*******************************************************************************
-**
-** Function         GKI_getfirst
-**
-** Description      Return a pointer to the first buffer in a queue
-**
-** Parameters:      p_q  - (input) pointer to a queue.
-**
-** Returns          NULL if queue is empty, else buffer address
-**
-*******************************************************************************/
-void *GKI_getfirst (BUFFER_Q *p_q)
-{
-    return (p_q->_p_first);
-}
-
-/*******************************************************************************
-**
-** Function         GKI_getlast
-**
-** Description      Return a pointer to the last buffer in a queue
-**
-** Parameters:      p_q  - (input) pointer to a queue.
-**
-** Returns          NULL if queue is empty, else buffer address
-**
-*******************************************************************************/
-void *GKI_getlast (BUFFER_Q *p_q)
-{
-    return (p_q->_p_last);
-}
-
-/*******************************************************************************
-**
-** Function         GKI_getnext
-**
-** Description      Return a pointer to the next buffer in a queue
-**
-** Parameters:      p_buf  - (input) pointer to the buffer to find the next one from.
-**
-** Returns          NULL if no more buffers in the queue, else next buffer address
-**
-*******************************************************************************/
-void *GKI_getnext (void *p_buf)
-{
-    BUFFER_HDR_T    *p_hdr;
-
-    p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
-
-    if (p_hdr->p_next) {
-        return ((UINT8 *)p_hdr->p_next + BUFFER_HDR_SIZE);
-    } else {
-        return (NULL);
-    }
-}
-
-/*******************************************************************************
-**
-** Function         GKI_queue_is_empty
-**
-** Description      Check the status of a queue.
-**
-** Parameters:      p_q  - (input) pointer to a queue.
-**
-** Returns          TRUE if queue is empty, else FALSE
-**
-*******************************************************************************/
-BOOLEAN GKI_queue_is_empty(BUFFER_Q *p_q)
-{
-    return ((BOOLEAN) (p_q->_count == 0));
-}
-
-UINT16 GKI_queue_length(BUFFER_Q *p_q)
-{
-    return p_q->_count;
-}
-
-/*******************************************************************************
-**
-** Function         GKI_poolcount
-**
-** Description      Called by an application to get the total number of buffers
-**                  in the specified buffer pool.
-**
-** Parameters       pool_id - (input) pool ID to get the free count of.
-**
-** Returns          the total number of buffers in the pool
-**
-*******************************************************************************/
-UINT16 GKI_poolcount (UINT8 pool_id)
-{
-    if (pool_id >= GKI_NUM_TOTAL_BUF_POOLS) {
-        return (0);
-    }
-
-    return (gki_cb.com.freeq[pool_id].total);
-}
-
-/*******************************************************************************
-**
-** Function         GKI_poolfreecount
-**
-** Description      Called by an application to get the number of free buffers
-**                  in the specified buffer pool.
-**
-** Parameters       pool_id - (input) pool ID to get the free count of.
-**
-** Returns          the number of free buffers in the pool
-**
-*******************************************************************************/
-UINT16 GKI_poolfreecount (UINT8 pool_id)
-{
-    FREE_QUEUE_T  *Q;
-
-    if (pool_id >= GKI_NUM_TOTAL_BUF_POOLS) {
-        return (0);
-    }
-
-    Q  = &gki_cb.com.freeq[pool_id];
-
-    return ((UINT16)(Q->total - Q->cur_cnt));
-}
-
-/*******************************************************************************
-**
-** Function         GKI_get_pool_bufsize
-**
-** Description      Called by an application to get the size of buffers in a pool
-**
-** Parameters       Pool ID.
-**
-** Returns          the size of buffers in the pool
-**
-*******************************************************************************/
-UINT16 GKI_get_pool_bufsize (UINT8 pool_id)
-{
-    if (pool_id < GKI_NUM_TOTAL_BUF_POOLS) {
-        return (gki_cb.com.freeq[pool_id].size);
-    }
-
-    return (0);
-}
-
-/*******************************************************************************
-**
-** Function         GKI_poolutilization
-**
-** Description      Called by an application to get the buffer utilization
-**                  in the specified buffer pool.
-**
-** Parameters       pool_id - (input) pool ID to get the free count of.
-**
-** Returns          % of buffers used from 0 to 100
-**
-*******************************************************************************/
-UINT16 GKI_poolutilization (UINT8 pool_id)
-{
-    FREE_QUEUE_T  *Q;
-
-    if (pool_id >= GKI_NUM_TOTAL_BUF_POOLS) {
-        return (100);
-    }
-
-    Q  = &gki_cb.com.freeq[pool_id];
-
-    if (Q->total == 0) {
-        return (100);
-    }
-
-    return ((Q->cur_cnt * 100) / Q->total);
-}
diff --git a/components/bt/bluedroid/gki/gki_ulinux.c b/components/bt/bluedroid/gki/gki_ulinux.c
deleted file mode 100644 (file)
index ed29f3b..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/******************************************************************************
- *
- *  Copyright (C) 2009-2012 Broadcom Corporation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at:
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- ******************************************************************************/
-#include <string.h>
-#include "bt_trace.h"
-#include "gki_int.h"
-#include "osi.h"
-#include "osi_arch.h"
-#include "alarm.h"
-#include "bt_defs.h"
-
-tGKI_CB gki_cb;
-
-int gki_init(void)
-{
-    memset(&gki_cb, 0, sizeof(gki_cb));
-
-    //pthread_mutexattr_t attr;
-    //pthread_mutexattr_init(&attr);
-    //pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
-    pthread_mutex_init(&gki_cb.lock, NULL);//&attr);
-
-    gki_buffer_init();
-    return 0;
-}
-
-void gki_clean_up(void)
-{
-    gki_buffer_cleanup();
-
-    pthread_mutex_destroy(&gki_cb.lock);
-}
-
-UINT32 GKI_get_os_tick_count(void)
-{
-    return osi_alarm_now();
-}
-
-// Sleep the calling thread unconditionally for |timeout_ms| milliseconds.
-void GKI_delay(UINT32 timeout_ms)
-{
-    osi_delay_ms(timeout_ms);
-    /*TODO:*/
-}
-
-void GKI_enable(void)
-{
-    pthread_mutex_unlock(&gki_cb.lock);
-}
-
-void GKI_disable(void)
-{
-    pthread_mutex_lock(&gki_cb.lock);
-}
diff --git a/components/bt/bluedroid/gki/include/gki.h b/components/bt/bluedroid/gki/include/gki.h
deleted file mode 100644 (file)
index 4e5f3c2..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/******************************************************************************
- *
- *  Copyright (C) 1999-2012 Broadcom Corporation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at:
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- ******************************************************************************/
-
-#ifndef _GKI_H_
-#define _GKI_H_
-
-#include "bt_target.h"
-#include "bt_types.h"
-#include "gki_common.h"
-#include "gki_int.h"
-#include "allocator.h"
-
-#define ALIGN_POOL(pl_size)  ( (((pl_size) + 3) / sizeof(UINT32)) * sizeof(UINT32))
-#define BUFFER_HDR_SIZE     (sizeof(BUFFER_HDR_T))                  /* Offset past header */
-#define BUFFER_PADDING_SIZE (sizeof(BUFFER_HDR_T) + sizeof(UINT32)) /* Header + Magic Number */
-#define MAGIC_NO            0xDDBADDBA
-
-#define BUF_STATUS_FREE     0
-#define BUF_STATUS_UNLINKED 1
-#define BUF_STATUS_QUEUED   2
-
-/* Timer list entry callback type
-*/
-typedef void (TIMER_CBACK)(void *p_tle);
-#ifndef TIMER_PARAM_TYPE
-#define TIMER_PARAM_TYPE    UINT32
-#endif
-/* Define a timer list entry
-*/
-typedef struct _tle {
-    struct _tle  *p_next;
-    struct _tle  *p_prev;
-    TIMER_CBACK  *p_cback;
-    INT32         ticks;
-    INT32         ticks_initial;
-    TIMER_PARAM_TYPE   param;
-    TIMER_PARAM_TYPE   data;
-    UINT16        event;
-    UINT8         in_use;
-} TIMER_LIST_ENT;
-
-/***********************************************************************
-** This queue is a general purpose buffer queue, for application use.
-*/
-typedef struct {
-    void    *_p_first;
-    void    *_p_last;
-    UINT16   _count;
-} BUFFER_Q;
-
-#define GKI_PUBLIC_POOL         0       /* General pool accessible to GKI_getbuf() */
-#define GKI_RESTRICTED_POOL     1       /* Inaccessible pool to GKI_getbuf() */
-
-/***********************************************************************
-** Function prototypes
-*/
-
-/* To get and release buffers, change owner and get size
-*/
-void   *GKI_getbuf_func(UINT16);
-void   *GKI_getpoolbuf_func(UINT8);
-void    GKI_freebuf(void *);
-UINT16  GKI_get_buf_size (void *);
-void   *GKI_getpoolbuf (UINT8);
-UINT16  GKI_poolcount (UINT8);
-UINT16  GKI_poolfreecount (UINT8);
-UINT16  GKI_poolutilization (UINT8);
-
-#ifdef CONFIG_BLUEDROID_MEM_DEBUG
-
-#define GKI_getbuf(_size)                                            \
-({                                                                  \
-    BUFFER_HDR_T *header = osi_malloc((_size) + BUFFER_HDR_SIZE);      \
-    header->status  = BUF_STATUS_UNLINKED;                          \
-    header->p_next  = NULL;                                         \
-    header->Type    = 0;                                            \
-    header->size = (_size);                                          \
-    (void *)(header + 1);                                                   \
-})
-
-#define GKI_getpoolbuf(_pool_id)                                     \
-({                                                                  \
-    (void *)GKI_getbuf(gki_cb.com.pool_size[(_pool_id)]);                    \
-})
-           
-#else
-#define GKI_getbuf          GKI_getbuf_func
-#define GKI_getpoolbuf      GKI_getpoolbuf_func
-
-#endif /* CONFIG_BLUEDROID_MEM_DEBUG */
-
-/* User buffer queue management
-*/
-void   *GKI_dequeue  (BUFFER_Q *);
-void    GKI_enqueue (BUFFER_Q *, void *);
-void   *GKI_getfirst (BUFFER_Q *);
-void   *GKI_getlast (BUFFER_Q *);
-void   *GKI_getnext (void *);
-void    GKI_init_q (BUFFER_Q *);
-UINT16  GKI_queue_length(BUFFER_Q *);
-BOOLEAN GKI_queue_is_empty(BUFFER_Q *);
-void   *GKI_remove_from_queue (BUFFER_Q *, void *);
-UINT16  GKI_get_pool_bufsize (UINT8);
-
-/* Timer management
-*/
-void    GKI_delay(UINT32);
-
-/* Disable Interrupts, Enable Interrupts
-*/
-void    GKI_enable(void);
-void    GKI_disable(void);
-
-/* os timer operation */
-UINT32 GKI_get_os_tick_count(void);
-
-#endif /*_GKI_H_*/
diff --git a/components/bt/bluedroid/gki/include/gki_common.h b/components/bt/bluedroid/gki/include/gki_common.h
deleted file mode 100644 (file)
index 838896e..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/******************************************************************************
- *
- *  Copyright (C) 1999-2012 Broadcom Corporation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at:
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- ******************************************************************************/
-
-#ifndef _GKI_COMMON_H_
-#define _GKI_COMMON_H_
-
-#include "gki.h"
-
-typedef struct _buffer_hdr {
-    struct _buffer_hdr *p_next;   /* next buffer in the queue */
-    UINT8   q_id;                 /* id of the queue */
-    UINT8   status;               /* FREE, UNLINKED or QUEUED */
-    UINT8   Type;
-    UINT16  size;
-} BUFFER_HDR_T;
-
-typedef struct _free_queue {
-    BUFFER_HDR_T *_p_first;      /* first buffer in the queue */
-    BUFFER_HDR_T *_p_last;       /* last buffer in the queue */
-    UINT16       size;             /* size of the buffers in the pool */
-    UINT16       total;            /* toatal number of buffers */
-    UINT16       cur_cnt;          /* number of  buffers currently allocated */
-    UINT16       max_cnt;          /* maximum number of buffers allocated at any time */
-} FREE_QUEUE_T;
-
-/* Put all GKI variables into one control block
-*/
-typedef struct {
-    /* Define the buffer pool management variables
-    */
-    FREE_QUEUE_T    freeq[GKI_NUM_TOTAL_BUF_POOLS];
-
-    UINT16   pool_buf_size[GKI_NUM_TOTAL_BUF_POOLS];
-
-    /* Define the buffer pool start addresses
-    */
-    UINT8   *pool_start[GKI_NUM_TOTAL_BUF_POOLS];   /* array of pointers to the start of each buffer pool */
-    UINT8   *pool_end[GKI_NUM_TOTAL_BUF_POOLS];     /* array of pointers to the end of each buffer pool */
-    UINT16   pool_size[GKI_NUM_TOTAL_BUF_POOLS];    /* actual size of the buffers in a pool */
-
-    /* Define the buffer pool access control variables */
-    UINT16      pool_access_mask;                   /* Bits are set if the corresponding buffer pool is a restricted pool */
-} tGKI_COM_CB;
-
-/* Internal GKI function prototypes
-*/
-void      gki_buffer_init(void);
-void      gki_buffer_cleanup(void);
-
-#endif /*_GKI_COMMON_H_*/
index 7cd51a9a016eedfb7c0d70dd8f8c53024f33287c..1a5fc69b7cd14bbd5ded86ad14ebd7781631ad6e 100644 (file)
  *
  ******************************************************************************/
 #include "buffer_allocator.h"
-#include "gki.h"
+#include "allocator.h"
 
-// TODO(zachoverflow): move the assertion into GKI_getbuf in the future
+// TODO(zachoverflow): move the assertion into osi_malloc in the future
 static void *buffer_alloc(size_t size)
 {
-    return GKI_getbuf((uint16_t)size);
+    return osi_malloc(size);
+}
+static void buffer_free(void *p)
+{
+    osi_free(p);
 }
-
 static const allocator_t interface = {
     buffer_alloc,
-    GKI_freebuf
+    buffer_free
 };
 
 const allocator_t *buffer_allocator_get_interface()
index aa93184e2b37e638e711b45a89e584f50c52bb06..5b5205dd9a5d0faab461005ccc04c998482f4972 100644 (file)
@@ -31,6 +31,7 @@
 #include "list.h"
 #include "alarm.h"
 #include "thread.h"
+#include "mutex.h"
 
 typedef struct {
     uint16_t opcode;
@@ -46,7 +47,7 @@ typedef struct {
     bool timer_is_set;
     osi_alarm_t *command_response_timer;
     list_t *commands_pending_response;
-    pthread_mutex_t commands_pending_response_lock;
+    osi_mutex_t commands_pending_response_lock;
 } command_waiting_response_t;
 
 typedef struct {
@@ -59,7 +60,7 @@ typedef struct {
     /*
       non_repeating_timer_t *command_response_timer;
       list_t *commands_pending_response;
-      pthread_mutex_t commands_pending_response_lock;
+      osi_mutex_t commands_pending_response_lock;
     */
 } hci_host_env_t;
 
@@ -183,7 +184,7 @@ static int hci_layer_init_env(void)
         LOG_ERROR("%s unable to create list for commands pending response.", __func__);
         return -1;
     }
-    pthread_mutex_init(&cmd_wait_q->commands_pending_response_lock, NULL);
+    osi_mutex_new(&cmd_wait_q->commands_pending_response_lock);
     cmd_wait_q->command_response_timer = osi_alarm_new("cmd_rsp_to", command_timed_out, cmd_wait_q, COMMAND_PENDING_TIMEOUT);
     if (!cmd_wait_q->command_response_timer) {
         LOG_ERROR("%s unable to create command response timer.", __func__);
@@ -206,7 +207,7 @@ static void hci_layer_deinit_env(void)
 
     cmd_wait_q = &hci_host_env.cmd_waiting_q;
     list_free(cmd_wait_q->commands_pending_response);
-    pthread_mutex_destroy(&cmd_wait_q->commands_pending_response_lock);
+    osi_mutex_free(&cmd_wait_q->commands_pending_response_lock);
     osi_alarm_free(cmd_wait_q->command_response_timer);
     cmd_wait_q->command_response_timer = NULL;
 }
@@ -321,9 +322,9 @@ static void event_command_ready(fixed_queue_t *queue)
     hci_host_env.command_credits--;
 
     // Move it to the list of commands awaiting response
-    pthread_mutex_lock(&cmd_wait_q->commands_pending_response_lock);
+    osi_mutex_lock(&cmd_wait_q->commands_pending_response_lock, OSI_MUTEX_MAX_TIMEOUT);
     list_append(cmd_wait_q->commands_pending_response, wait_entry);
-    pthread_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
+    osi_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
 
     // Send it off
     packet_fragmenter->fragment_and_dispatch(wait_entry->command);
@@ -387,10 +388,10 @@ static void restart_comamnd_waiting_response_timer(
         cmd_wait_q->timer_is_set = false;
     }
 
-    pthread_mutex_lock(&cmd_wait_q->commands_pending_response_lock);
+    osi_mutex_lock(&cmd_wait_q->commands_pending_response_lock, OSI_MUTEX_MAX_TIMEOUT);
     wait_entry = (list_is_empty(cmd_wait_q->commands_pending_response) ?
                   NULL : list_front(cmd_wait_q->commands_pending_response));
-    pthread_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
+    osi_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
 
     if (wait_entry == NULL) {
         return;
@@ -409,10 +410,10 @@ static void command_timed_out(void *context)
     command_waiting_response_t *cmd_wait_q = (command_waiting_response_t *)context;
     waiting_command_t *wait_entry;
 
-    pthread_mutex_lock(&cmd_wait_q->commands_pending_response_lock);
+    osi_mutex_lock(&cmd_wait_q->commands_pending_response_lock, OSI_MUTEX_MAX_TIMEOUT);
     wait_entry = (list_is_empty(cmd_wait_q->commands_pending_response) ?
                   NULL : list_front(cmd_wait_q->commands_pending_response));
-    pthread_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
+    osi_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
 
     if (wait_entry == NULL) {
         LOG_ERROR("%s with no commands pending response", __func__);
@@ -542,7 +543,7 @@ static serial_data_type_t event_to_data_type(uint16_t event)
 static waiting_command_t *get_waiting_command(command_opcode_t opcode)
 {
     command_waiting_response_t *cmd_wait_q = &hci_host_env.cmd_waiting_q;
-    pthread_mutex_lock(&cmd_wait_q->commands_pending_response_lock);
+    osi_mutex_lock(&cmd_wait_q->commands_pending_response_lock, OSI_MUTEX_MAX_TIMEOUT);
 
     for (const list_node_t *node = list_begin(cmd_wait_q->commands_pending_response);
             node != list_end(cmd_wait_q->commands_pending_response);
@@ -554,11 +555,11 @@ static waiting_command_t *get_waiting_command(command_opcode_t opcode)
 
         list_remove(cmd_wait_q->commands_pending_response, wait_entry);
 
-        pthread_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
+        osi_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
         return wait_entry;
     }
 
-    pthread_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
+    osi_mutex_unlock(&cmd_wait_q->commands_pending_response_lock);
     return NULL;
 }
 
index 5d0dd3d9c02d222f94abb2aa9b50d72975005523..bb0ca6de5a0a825a863441676d68530bd7dc8ddf 100644 (file)
@@ -22,8 +22,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include "bt_trace.h"
-
-#include "osi_arch.h"
+#include "bt_target.h"
 
 #define UNUSED(x)                   (void)(x)
 
 #endif
 /*Timer Related Defination*/
 
+//by Snake.T
+typedef void (TIMER_CBACK)(void *p_tle);
+typedef struct _tle {
+    struct _tle  *p_next;
+    struct _tle  *p_prev;
+    TIMER_CBACK  *p_cback;
+    INT32         ticks;
+    INT32         ticks_initial;
+    TIMER_PARAM_TYPE   param;
+    TIMER_PARAM_TYPE   data;
+    UINT16        event;
+    UINT8         in_use;
+} TIMER_LIST_ENT;
+
 #define alarm_timer_t               uint32_t
 #define alarm_timer_setfn(timer, cb, data)           \
 do {                                                 \
@@ -45,23 +58,6 @@ do {                                                 \
 #define alarm_timer_now()             (0)
 
 
-/*Thread and locker related defination*/
-#define RTOS_SUPPORT
-#ifdef RTOS_SUPPORT
-#define pthread_mutex_t               osi_mutex_t
-#define pthread_mutex_init(mutex, a)  osi_mutex_new(mutex)
-#define pthread_mutex_destroy(mutex)  osi_mutex_free(mutex)
-#define pthread_mutex_lock            osi_mutex_lock
-#define pthread_mutex_unlock          osi_mutex_unlock
-#else
-#define pthread_mutex_t               uint8_t
-#define pthread_mutex_init(x1, x2)
-#define pthread_mutex_destroy(mutex)
-#define pthread_mutex_lock(mutex)
-#define pthread_mutex_unlock(mutex)
-#endif
-
-
 /*Bluetooth Address*/
 typedef struct {
     uint8_t address[6];
index a426d69fe6e339fbebdd41328c29f3b54c3eb691..34b8c194e6b4f802691bc20db3a974a9301117a4 100644 (file)
@@ -37,8 +37,6 @@
 #include "sdkconfig.h"
 #include "bt_types.h"   /* This must be defined AFTER buildcfg.h */
 
-/* Include common GKI definitions used by this platform */
-#include "gki_target.h"
 #include "dyn_mem.h"    /* defines static and/or dynamic memory for components */
 
 #if CONFIG_CLASSIC_BT_ENABLED
 #define BTA_DISABLE_DELAY 200 /* in milliseconds */
 #endif
 
-// If the next wakeup time is less than this threshold, we should acquire
-// a wakelock instead of setting a wake alarm so we're not bouncing in
-// and out of suspend frequently.
-// in millisecond
-// TODO(zachoverflow): reinstate in alarm code
-#ifndef GKI_TIMER_INTERVAL_FOR_WAKELOCK
-#define GKI_TIMER_INTERVAL_FOR_WAKELOCK 3000
-#endif
-
 #ifndef BTA_SYS_TIMER_PERIOD
 #define BTA_SYS_TIMER_PERIOD  100
 #endif
 
 /******************************************************************************
 **
-** GKI Buffer Pools
+** Buffer Size
 **
 ******************************************************************************/
 
-/* Receives HCI events from the lower-layer. */
-#ifndef HCI_CMD_POOL_ID
-#define HCI_CMD_POOL_ID             GKI_POOL_ID_2
-#endif
-
-#ifndef HCI_CMD_POOL_BUF_SIZE
-#define HCI_CMD_POOL_BUF_SIZE       GKI_BUF2_SIZE
-#endif
-
-/* Receives ACL data packets from thelower-layer. */
-#ifndef HCI_ACL_POOL_ID
-#define HCI_ACL_POOL_ID             GKI_POOL_ID_3
+#ifndef BT_DEFAULT_BUFFER_SIZE
+#define BT_DEFAULT_BUFFER_SIZE          (4096 + 16)
 #endif
 
-/* Maximum number of buffers available for ACL receive data. */
-#ifndef HCI_ACL_BUF_MAX
-#define HCI_ACL_BUF_MAX             GKI_BUF3_MAX
+#ifndef BT_SMALL_BUFFER_SIZE
+#define BT_SMALL_BUFFER_SIZE            660
 #endif
 
-/* Receives SCO data packets from the lower-layer. */
-#ifndef HCI_SCO_POOL_ID
-#define HCI_SCO_POOL_ID             GKI_POOL_ID_6
+/* Receives HCI events from the lower-layer. */
+#ifndef HCI_CMD_BUF_SIZE
+#define HCI_CMD_BUF_SIZE                BT_SMALL_BUFFER_SIZE
 #endif
 
 /* Sends SDP data packets. */
-#ifndef SDP_POOL_ID
-#define SDP_POOL_ID                 3
+#ifndef SDP_DATA_BUF_SIZE
+#define SDP_DATA_BUF_SIZE               BT_DEFAULT_BUFFER_SIZE
 #endif
 
 /* Sends RFCOMM command packets. */
-#ifndef RFCOMM_CMD_POOL_ID
-#define RFCOMM_CMD_POOL_ID          GKI_POOL_ID_2
+#ifndef RFCOMM_CMD_BUF_SIZE
+#define RFCOMM_CMD_BUF_SIZE             BT_SMALL_BUFFER_SIZE
 #endif
 
 /* Sends RFCOMM data packets. */
-#ifndef RFCOMM_DATA_POOL_ID
-#define RFCOMM_DATA_POOL_ID         GKI_POOL_ID_3
+#ifndef RFCOMM_DATA_BUF_SIZE
+#define RFCOMM_DATA_BUF_SIZE            BT_DEFAULT_BUFFER_SIZE
 #endif
 
-#ifndef RFCOMM_DATA_POOL_BUF_SIZE
-#define RFCOMM_DATA_POOL_BUF_SIZE   GKI_BUF3_SIZE
+/* Sends L2CAP packets to the peer and HCI messages to the controller. */
+#ifndef L2CAP_CMD_BUF_SIZE
+#define L2CAP_CMD_BUF_SIZE              BT_SMALL_BUFFER_SIZE
 #endif
 
-/* Sends L2CAP packets to the peer and HCI messages to the controller. */
-#ifndef L2CAP_CMD_POOL_ID
-#define L2CAP_CMD_POOL_ID           GKI_POOL_ID_2
+#ifndef L2CAP_USER_TX_BUF_SIZE
+#define L2CAP_USER_TX_BUF_SIZE          BT_DEFAULT_BUFFER_SIZE
+#endif
+
+#ifndef L2CAP_USER_RX_BUF_SIZE
+#define L2CAP_USER_RX_BUF_SIZE          BT_DEFAULT_BUFFER_SIZE
 #endif
 
 /* Sends L2CAP segmented packets in ERTM mode */
-#ifndef L2CAP_FCR_TX_POOL_ID
-#define L2CAP_FCR_TX_POOL_ID        HCI_ACL_POOL_ID
+#ifndef L2CAP_FCR_TX_BUF_SIZE
+#define L2CAP_FCR_TX_BUF_SIZE           BT_DEFAULT_BUFFER_SIZE
 #endif
 
 /* Receives L2CAP segmented packets in ERTM mode */
-#ifndef L2CAP_FCR_RX_POOL_ID
-#define L2CAP_FCR_RX_POOL_ID        HCI_ACL_POOL_ID
+#ifndef L2CAP_FCR_RX_BUF_SIZE
+#define L2CAP_FCR_RX_BUF_SIZE           BT_DEFAULT_BUFFER_SIZE
+#endif
+
+#ifndef L2CAP_FCR_ERTM_BUF_SIZE
+#define L2CAP_FCR_ERTM_BUF_SIZE         (10240 + 24)
 #endif
 
 /* Number of ACL buffers to assign to LE
 #endif
 
 /* Used by BTM when it sends HCI commands to the controller. */
-#ifndef BTM_CMD_POOL_ID
-#define BTM_CMD_POOL_ID             GKI_POOL_ID_2
+#ifndef BTM_CMD_BUF_SIZE
+#define BTM_CMD_BUF_SIZE                BT_SMALL_BUFFER_SIZE
 #endif
 
-#ifndef OBX_LRG_DATA_POOL_SIZE
-#define OBX_LRG_DATA_POOL_SIZE      GKI_BUF4_SIZE
+#ifndef OBX_LRG_DATA_BUF_SIZE
+#define OBX_LRG_DATA_BUF_SIZE           (8080 + 26)
 #endif
 
-#ifndef OBX_LRG_DATA_POOL_ID
-#define OBX_LRG_DATA_POOL_ID        GKI_POOL_ID_4
-#endif
 /* Used to send data to L2CAP. */
-#ifndef GAP_DATA_POOL_ID
-#define GAP_DATA_POOL_ID            GKI_POOL_ID_3
-#endif
-
-#ifndef SPP_DB_SIZE
-#define SPP_DB_SIZE                 GKI_BUF3_SIZE
+#ifndef GAP_DATA_BUF_SIZE
+#define GAP_DATA_BUF_SIZE               BT_DEFAULT_BUFFER_SIZE
 #endif
 
 /* BNEP data and protocol messages. */
-#ifndef BNEP_POOL_ID
-#define BNEP_POOL_ID                GKI_POOL_ID_3
-#endif
-
-/* RPC pool for temporary trace message buffers. */
-#ifndef RPC_SCRATCH_POOL_ID
-#define RPC_SCRATCH_POOL_ID         GKI_POOL_ID_2
-#endif
-
-/* AVDTP pool for protocol messages */
-#ifndef AVDT_CMD_POOL_ID
-#define AVDT_CMD_POOL_ID            GKI_POOL_ID_2
-#endif
-
-/* AVDTP pool size for media packets in case of fragmentation */
-#ifndef AVDT_DATA_POOL_SIZE
-#define AVDT_DATA_POOL_SIZE         GKI_BUF3_SIZE
-#endif
-
-#ifndef PAN_POOL_ID
-#define PAN_POOL_ID                 GKI_POOL_ID_3
-/* Maximum amount of the shared buffer to allocate for PAN */
-#define PAN_POOL_MAX                (GKI_BUF3_MAX / 4)
+#ifndef BNEP_BUF_SIZE
+#define BNEP_BUF_SIZE                   BT_DEFAULT_BUFFER_SIZE
 #endif
 
-/* AVCTP pool for protocol messages */
-#ifndef AVCT_CMD_POOL_ID
-#define AVCT_CMD_POOL_ID            GKI_POOL_ID_1
+/* AVDTP buffer size for protocol messages */
+#ifndef AVDT_CMD_BUF_SIZE
+#define AVDT_CMD_BUF_SIZE               BT_SMALL_BUFFER_SIZE
 #endif
 
-/* AVRCP pool for protocol messages */
-#ifndef AVRC_CMD_POOL_ID
-#define AVRC_CMD_POOL_ID            GKI_POOL_ID_1
+/* AVDTP buffer size for media packets in case of fragmentation */
+#ifndef AVDT_DATA_BUF_SIZE
+#define AVDT_DATA_BUF_SIZE              BT_DEFAULT_BUFFER_SIZE
 #endif
 
-/* AVRCP pool size for protocol messages */
-#ifndef AVRC_CMD_POOL_SIZE
-#define AVRC_CMD_POOL_SIZE          GKI_BUF1_SIZE
+#ifndef PAN_BUF_SIZE
+#define PAN_BUF_SIZE                    BT_DEFAULT_BUFFER_SIZE
 #endif
 
-/* AVRCP Metadata pool for protocol messages */
-#ifndef AVRC_META_CMD_POOL_ID
-#define AVRC_META_CMD_POOL_ID       GKI_POOL_ID_2
+/* Maximum number of buffers to allocate for PAN */
+#ifndef PAN_BUF_MAX
+#define PAN_BUF_MAX                     100
 #endif
 
-/* AVRCP Metadata pool size for protocol messages */
-#ifndef AVRC_META_CMD_POOL_SIZE
-#define AVRC_META_CMD_POOL_SIZE     GKI_BUF2_SIZE
+/* AVCTP buffer size for protocol messages */
+#ifndef AVCT_CMD_BUF_SIZE
+#define AVCT_CMD_BUF_SIZE               288
 #endif
 
-
-/* AVRCP buffer size for browsing channel messages */
-#ifndef AVRC_BROWSE_POOL_SIZE
-#define AVRC_BROWSE_POOL_SIZE     GKI_MAX_BUF_SIZE
+/* AVRCP buffer size for protocol messages */
+#ifndef AVRC_CMD_BUF_SIZE
+#define AVRC_CMD_BUF_SIZE               288
 #endif
 
-#ifndef BTA_HL_LRG_DATA_POOL_ID
-#define BTA_HL_LRG_DATA_POOL_ID        GKI_POOL_ID_7
+/* AVRCP Metadata buffer size for protocol messages */
+#ifndef AVRC_META_CMD_BUF_SIZE
+#define AVRC_META_CMD_BUF_SIZE          BT_SMALL_BUFFER_SIZE
 #endif
 
-/* GATT Server Database pool ID */
-#ifndef GATT_DB_POOL_ID
-#define GATT_DB_POOL_ID                 GKI_POOL_ID_8
+#ifndef BTA_HL_LRG_DATA_BUF_SIZE
+#define BTA_HL_LRG_DATA_BUF_SIZE        (10240 + 24)
 #endif
 
-/* GATT Data sending buffer pool ID, use default ACL pool for fix channel data */
-#ifndef GATT_BUF_POOL_ID
-#define GATT_BUF_POOL_ID                HCI_ACL_POOL_ID
+/* GATT Server Database buffer size */
+#ifndef GATT_DB_BUF_SIZE
+#define GATT_DB_BUF_SIZE                128
 #endif
 
-/******************************************************************************
-**
-** Lower Layer Interface
-**
-******************************************************************************/
-
-/* Macro for allocating buffer for HCI commands */
-#ifndef HCI_GET_CMD_BUF
-#if (!defined(HCI_USE_VARIABLE_SIZE_CMD_BUF) || (HCI_USE_VARIABLE_SIZE_CMD_BUF == FALSE))
-/* Allocate fixed-size buffer from HCI_CMD_POOL (default case) */
-#define HCI_GET_CMD_BUF(paramlen)    ((BT_HDR *)GKI_getpoolbuf (HCI_CMD_POOL_ID))
-#else
-/* Allocate smallest possible buffer (for platforms with limited RAM) */
-#define HCI_GET_CMD_BUF(paramlen)    ((BT_HDR *)GKI_getbuf ((UINT16)(BT_HDR_SIZE + HCIC_PREAMBLE_SIZE + (paramlen))))
+/* GATT Data sending buffer size */
+#ifndef GATT_DATA_BUF_SIZE
+#define GATT_DATA_BUF_SIZE              BT_DEFAULT_BUFFER_SIZE
 #endif
-#endif  /* HCI_GET_CMD_BUF */
 
 /******************************************************************************
 **
 #define PORT_CREDIT_RX_LOW          8
 #endif
 
-/* if application like BTA, Java or script test engine is running on other than BTU thread, */
-/* PORT_SCHEDULE_LOCK shall be defined as GKI_sched_lock() or GKI_disable() */
-#ifndef PORT_SCHEDULE_LOCK
-#define PORT_SCHEDULE_LOCK          GKI_disable()
-#endif
-
-/* if application like BTA, Java or script test engine is running on other than BTU thread, */
-/* PORT_SCHEDULE_LOCK shall be defined as GKI_sched_unlock() or GKI_enable() */
-#ifndef PORT_SCHEDULE_UNLOCK
-#define PORT_SCHEDULE_UNLOCK        GKI_enable()
-#endif
-
 /******************************************************************************
 **
 ** OBEX
 **
 ******************************************************************************/
-#define OBX_14_INCLUDED             FALSE
 
-/* The maximum number of registered servers. */
-#ifndef OBX_NUM_SERVERS
-#define OBX_NUM_SERVERS             12
-#endif
-
-/* The maximum number of active clients. */
-#ifndef OBX_NUM_CLIENTS
-#define OBX_NUM_CLIENTS             8
-#endif
-
-/* This option is application when OBX_14_INCLUDED=TRUE
-   Pool ID where to reassemble the SDU.
-   This Pool will allow buffers to be used that are larger than
-   the L2CAP_MAX_MTU. */
-#ifndef OBX_USER_RX_POOL_ID
-#define OBX_USER_RX_POOL_ID     OBX_LRG_DATA_POOL_ID
+/*
+ * Buffer size to reassemble the SDU.
+ * It will allow buffers to be used that are larger than the L2CAP_MAX_MTU.
+ */
+#ifndef OBX_USER_RX_BUF_SIZE
+#define OBX_USER_RX_BUF_SIZE    OBX_LRG_DATA_BUF_SIZE
 #endif
 
-/* This option is application when OBX_14_INCLUDED=TRUE
  Pool ID where to hold the SDU.
-   This Pool will allow buffers to be used that are larger than
  the L2CAP_MAX_MTU. */
-#ifndef OBX_USER_TX_POOL_ID
-#define OBX_USER_TX_POOL_ID     OBX_LRG_DATA_POOL_ID
+/*
* Buffer size to hold the SDU.
+ * It will allow buffers to be used that are larger than the L2CAP_MAX_MTU.
+ */
+#ifndef OBX_USER_TX_BUF_SIZE
+#define OBX_USER_TX_BUF_SIZE    OBX_LRG_DATA_BUF_SIZE
 #endif
 
-/* This option is application when OBX_14_INCLUDED=TRUE
-GKI Buffer Pool ID used to hold MPS segments during SDU reassembly
-*/
-#ifndef OBX_FCR_RX_POOL_ID
-#define OBX_FCR_RX_POOL_ID      HCI_ACL_POOL_ID
+/* Buffer size used to hold MPS segments during SDU reassembly. */
+#ifndef OBX_FCR_RX_BUF_SIZE
+#define OBX_FCR_RX_BUF_SIZE     BT_DEFAULT_BUFFER_SIZE
 #endif
 
-/* This option is application when OBX_14_INCLUDED=TRUE
-GKI Buffer Pool ID used to hold MPS segments used in (re)transmissions.
-L2CAP_DEFAULT_ERM_POOL_ID is specified to use the HCI ACL data pool.
-Note:  This pool needs to have enough buffers to hold two times the window size negotiated
- in the L2CA_SetFCROptions (2 * tx_win_size)  to allow for retransmissions.
- The size of each buffer must be able to hold the maximum MPS segment size passed in
- L2CA_SetFCROptions plus BT_HDR (8) + HCI preamble (4) + L2CAP_MIN_OFFSET (11 - as of BT 2.1 + EDR Spec).
-*/
-#ifndef OBX_FCR_TX_POOL_ID
-#define OBX_FCR_TX_POOL_ID      HCI_ACL_POOL_ID
+/*
+ * Buffer size used to hold MPS segments used in (re)transmissions.
+ * The size of each buffer must be able to hold the maximum MPS segment size
+ * passed in L2CA_SetFCROptions plus BT_HDR (8) + HCI preamble (4) +
+ * L2CAP_MIN_OFFSET (11 - as of BT 2.1 + EDR Spec).
+ */
+#ifndef OBX_FCR_TX_BUF_SIZE
+#define OBX_FCR_TX_BUF_SIZE     BT_DEFAULT_BUFFER_SIZE
 #endif
 
 /* This option is application when OBX_14_INCLUDED=TRUE
@@ -1623,16 +1540,12 @@ Range: 2 octets
 **
 ******************************************************************************/
 
-#ifndef HID_DEV_SUBCLASS
-#define HID_DEV_SUBCLASS            COD_MINOR_POINTING
-#endif
-
-#ifndef HID_CONTROL_POOL_ID
-#define HID_CONTROL_POOL_ID             2
+#ifndef HID_CONTROL_BUF_SIZE
+#define HID_CONTROL_BUF_SIZE            BT_DEFAULT_BUFFER_SIZE
 #endif
 
-#ifndef HID_INTERRUPT_POOL_ID
-#define HID_INTERRUPT_POOL_ID           2
+#ifndef HID_INTERRUPT_BUF_SIZE
+#define HID_INTERRUPT_BUF_SIZE          BT_DEFAULT_BUFFER_SIZE
 #endif
 
 /*************************************************************************
@@ -1767,33 +1680,31 @@ Range: 2 octets
 #define MCA_NUM_MDLS    4
 #endif
 
-/* Pool ID where to reassemble the SDU. */
-#ifndef MCA_USER_RX_POOL_ID
-#define MCA_USER_RX_POOL_ID     HCI_ACL_POOL_ID
+/* Buffer size to reassemble the SDU. */
+#ifndef MCA_USER_RX_BUF_SIZE
+#define MCA_USER_RX_BUF_SIZE    BT_DEFAULT_BUFFER_SIZE
 #endif
 
-/* Pool ID where to hold the SDU. */
-#ifndef MCA_USER_TX_POOL_ID
-#define MCA_USER_TX_POOL_ID     HCI_ACL_POOL_ID
+/* Buffer size to hold the SDU. */
+#ifndef MCA_USER_TX_BUF_SIZE
+#define MCA_USER_TX_BUF_SIZE    BT_DEFAULT_BUFFER_SIZE
 #endif
 
 /*
-GKI Buffer Pool ID used to hold MPS segments during SDU reassembly
-*/
-#ifndef MCA_FCR_RX_POOL_ID
-#define MCA_FCR_RX_POOL_ID      HCI_ACL_POOL_ID
+ * Buffer size used to hold MPS segments during SDU reassembly
+ */
+#ifndef MCA_FCR_RX_BUF_SIZE
+#define MCA_FCR_RX_BUF_SIZE     BT_DEFAULT_BUFFER_SIZE
 #endif
 
 /*
-GKI Buffer Pool ID used to hold MPS segments used in (re)transmissions.
-L2CAP_DEFAULT_ERM_POOL_ID is specified to use the HCI ACL data pool.
-Note:  This pool needs to have enough buffers to hold two times the window size negotiated
- in the tL2CAP_FCR_OPTIONS (2 * tx_win_size)  to allow for retransmissions.
- The size of each buffer must be able to hold the maximum MPS segment size passed in
- tL2CAP_FCR_OPTIONS plus BT_HDR (8) + HCI preamble (4) + L2CAP_MIN_OFFSET (11 - as of BT 2.1 + EDR Spec).
-*/
-#ifndef MCA_FCR_TX_POOL_ID
-#define MCA_FCR_TX_POOL_ID      HCI_ACL_POOL_ID
+ * Default buffer size used to hold MPS segments used in (re)transmissions.
+ * The size of each buffer must be able to hold the maximum MPS segment size
+ * passed in tL2CAP_FCR_OPTIONS plus BT_HDR (8) + HCI preamble (4) +
+ * L2CAP_MIN_OFFSET (11 - as of BT 2.1 + EDR Spec).
+ */
+#ifndef MCA_FCR_TX_BUF_SIZE
+#define MCA_FCR_TX_BUF_SIZE     BT_DEFAULT_BUFFER_SIZE
 #endif
 
 /* MCAP control channel FCR Option:
index 6a3ffe8011dfb916d3bb8d53c128351d05d97129..171967cfc388dc9f0a364f85ccb3f724c80f35cb 100644 (file)
@@ -110,7 +110,6 @@ typedef struct tBAUD_REG_tag {
     UINT8 ExplicitBaudRate3;
 } tBAUD_REG;
 
-#include "gki.h"
 
 extern const tBAUD_REG baud_rate_regs[];
 
diff --git a/components/bt/bluedroid/include/gki_target.h b/components/bt/bluedroid/include/gki_target.h
deleted file mode 100644 (file)
index fc84451..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/******************************************************************************
- *
- *  Copyright (C) 1999-2012 Broadcom Corporation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at:
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- ******************************************************************************/
-
-#ifndef _GKI_TARGET_H_
-#define _GKI_TARGET_H_
-
-/******************************************************************************
-**
-** Buffer configuration
-**
-******************************************************************************/
-
-/* The size of the buffers in pool 0. */
-#ifndef GKI_BUF0_SIZE
-#define GKI_BUF0_SIZE               64
-#endif
-
-/* The number of buffers in buffer pool 0. */
-#ifndef GKI_BUF0_MAX
-#define GKI_BUF0_MAX                96
-#endif
-
-/* The ID of buffer pool 0. */
-#ifndef GKI_POOL_ID_0
-#define GKI_POOL_ID_0               0
-#endif
-
-/* The size of the buffers in pool 1. */
-#ifndef GKI_BUF1_SIZE
-#define GKI_BUF1_SIZE               288
-#endif
-
-/* The number of buffers in buffer pool 1. */
-#ifndef GKI_BUF1_MAX
-#define GKI_BUF1_MAX                52
-#endif
-
-/* The ID of buffer pool 1. */
-#ifndef GKI_POOL_ID_1
-#define GKI_POOL_ID_1               1
-#endif
-
-/* The size of the buffers in pool 2. */
-#ifndef GKI_BUF2_SIZE
-#define GKI_BUF2_SIZE               660
-#endif
-
-/* The number of buffers in buffer pool 2. */
-#ifndef GKI_BUF2_MAX
-#define GKI_BUF2_MAX                90
-#endif
-
-/* The ID of buffer pool 2. */
-#ifndef GKI_POOL_ID_2
-#define GKI_POOL_ID_2               2
-#endif
-
-/* The size of the buffers in pool 3. */
-#ifndef GKI_BUF3_SIZE
-#define GKI_BUF3_SIZE               (4096+16)
-#endif
-
-/* The number of buffers in buffer pool 3. */
-#ifndef GKI_BUF3_MAX
-#define GKI_BUF3_MAX                400
-#endif
-
-/* The ID of buffer pool 3. */
-#ifndef GKI_POOL_ID_3
-#define GKI_POOL_ID_3               3
-#endif
-
-/* The size of the largest PUBLIC fixed buffer in system. */
-#ifndef GKI_MAX_BUF_SIZE
-#define GKI_MAX_BUF_SIZE            GKI_BUF3_SIZE
-#endif
-
-/* The pool ID of the largest PUBLIC fixed buffer in system. */
-#ifndef GKI_MAX_BUF_SIZE_POOL_ID
-#define GKI_MAX_BUF_SIZE_POOL_ID    GKI_POOL_ID_3
-#endif
-
-/* Pool 4 is used for BluetoothSocket L2CAP connections */
-/* The size of the buffers in pool 4. */
-#ifndef GKI_BUF4_SIZE
-#define GKI_BUF4_SIZE               (8080+26)
-#endif
-
-/* The number of buffers in buffer pool 4. */
-#ifndef GKI_BUF4_MAX
-#define GKI_BUF4_MAX                (OBX_NUM_SERVERS + OBX_NUM_CLIENTS)
-#endif
-
-/* The ID of buffer pool 4. */
-#ifndef GKI_POOL_ID_4
-#define GKI_POOL_ID_4               4
-#endif
-
-/* The number of fixed GKI buffer pools.
-eL2CAP requires Pool ID 5
-If BTM_SCO_HCI_INCLUDED is FALSE, Pool ID 6 is unnecessary, otherwise set to 7
-If BTA_HL_INCLUDED is FALSE then Pool ID 7 is uncessary and set the following to 7, otherwise set to 8
-If BLE_INCLUDED is FALSE then Pool ID 8 is uncessary and set the following to 8, otherwise set to 9
-POOL_ID 9 is a public pool meant for large buffer needs such as SDP_DB
-*/
-#ifndef GKI_NUM_FIXED_BUF_POOLS
-#define GKI_NUM_FIXED_BUF_POOLS     10
-#endif
-
-/* The buffer pool usage mask. */
-#ifndef GKI_DEF_BUFPOOL_PERM_MASK
-/* Setting POOL_ID 9 as a public pool meant for large buffers such as SDP_DB */
-#define GKI_DEF_BUFPOOL_PERM_MASK   0xfdf0
-#endif
-
-/* The following is intended to be a reserved pool for L2CAP
-Flow control and retransmissions and intentionally kept out
-of order */
-
-/* The number of buffers in buffer pool 5. */
-#ifndef GKI_BUF5_MAX
-#define GKI_BUF5_MAX                64
-#endif
-
-/* The ID of buffer pool 5. */
-#ifndef GKI_POOL_ID_5
-#define GKI_POOL_ID_5               5
-#endif
-
-/* The size of the buffers in pool 5
-** Special pool used by L2CAP retransmissions only.  This size based on segment
-** that will fit into both DH5 and 2-DH3 packet types after accounting for GKI
-** header.  13 bytes of max headers allows us a 339 payload max. (in btui_app.txt)
-** Note: 748 used for insight scriptwrapper with CAT-2 scripts.
-*/
-#ifndef GKI_BUF5_SIZE
-#define GKI_BUF5_SIZE               748
-#endif
-
-/* The following is intended to be a reserved pool for SCO
-over HCI data and intentionally kept out of order */
-
-/* The ID of buffer pool 6. */
-#ifndef GKI_POOL_ID_6
-#define GKI_POOL_ID_6               6
-#endif
-
-/* The size of the buffers in pool 6,
-  BUF_SIZE = max SCO data 255 + sizeof(BT_HDR) = 8 + SCO packet header 3 + padding 2 = 268 */
-#ifndef GKI_BUF6_SIZE
-#define GKI_BUF6_SIZE               268
-#endif
-
-/* The number of buffers in buffer pool 6. */
-#ifndef GKI_BUF6_MAX
-#define GKI_BUF6_MAX                60
-#endif
-
-
-/* The following pool is a dedicated pool for HDP
-   If a shared pool is more desirable then
-   1. set BTA_HL_LRG_DATA_POOL_ID to the desired Gki Pool ID
-   2. make sure that the shared pool size is larger than 9472
-   3. adjust GKI_NUM_FIXED_BUF_POOLS accordingly since
-      POOL ID 7 is not needed
-*/
-
-/* The ID of buffer pool 7. */
-#ifndef GKI_POOL_ID_7
-#define GKI_POOL_ID_7               7
-#endif
-
-/* The size of the buffers in pool 7 */
-#ifndef GKI_BUF7_SIZE
-#define GKI_BUF7_SIZE               (10240 + 24)
-#endif
-
-/* The number of buffers in buffer pool 7. */
-#ifndef GKI_BUF7_MAX
-#define GKI_BUF7_MAX                2
-#endif
-
-/* The following pool is a dedicated pool for GATT
-   If a shared pool is more desirable then
-   1. set GATT_DB_POOL_ID to the desired Gki Pool ID
-   2. make sure that the shared pool size fit a common GATT database needs
-   3. adjust GKI_NUM_FIXED_BUF_POOLS accordingly since
-      POOL ID 8 is not needed
-*/
-
-/* The ID of buffer pool 8. */
-#ifndef GKI_POOL_ID_8
-#define GKI_POOL_ID_8               8
-#endif
-
-/* The size of the buffers in pool 8 */
-#ifndef GKI_BUF8_SIZE
-#define GKI_BUF8_SIZE               128
-#endif
-
-/* The number of buffers in buffer pool 8. */
-#ifndef GKI_BUF8_MAX
-#define GKI_BUF8_MAX                30
-#endif
-
-/* The following pool is  meant for large allocations such as SDP_DB */
-#ifndef GKI_POOL_ID_9
-#define GKI_POOL_ID_9              9
-#endif
-
-#ifndef GKI_BUF9_SIZE
-#define GKI_BUF9_SIZE            8192
-#endif
-
-#ifndef GKI_BUF9_MAX
-#define GKI_BUF9_MAX           5
-#endif
-
-/* The number of fixed and dynamic buffer pools */
-#ifndef GKI_NUM_TOTAL_BUF_POOLS
-#define GKI_NUM_TOTAL_BUF_POOLS     10
-#endif
-
-int gki_init(void);
-void gki_clean_up(void);
-
-//void LogMsg (UINT32 trace_set_mask, const char *fmt_str, ...);
-
-#endif /*_GKI_TARGET_H_*/
index 8e77072e9210072a8a23e623f0cdc7bf9cc4b973..32ae87d34773669997e344ca17381031aa906b77 100644 (file)
@@ -75,11 +75,6 @@ extern void osi_mem_dbg_init(void);
 ******************************************************************************/
 int bte_main_boot_entry(bluedroid_init_done_cb_t cb)
 {
-    if (gki_init()) {
-        LOG_ERROR("%s: Init GKI Module Failure.\n", __func__);
-        return -1;
-    }
-
     hci = hci_layer_get_interface();
     if (!hci) {
         LOG_ERROR("%s could not get hci layer interface.\n", __func__);
@@ -88,6 +83,8 @@ int bte_main_boot_entry(bluedroid_init_done_cb_t cb)
 
     bluedroid_init_done_cb = cb;
 
+    osi_init();
+
     //Enbale HCI
     bte_main_enable();
 
@@ -109,7 +106,8 @@ void bte_main_shutdown(void)
     BTA_VendorCleanup();
 #endif
     bte_main_disable();
-    gki_clean_up();
+
+    osi_deinit();
 }
 
 /******************************************************************************
@@ -244,6 +242,6 @@ void bte_main_hci_send (BT_HDR *p_msg, UINT16 event)
         hci->transmit_downward(event, p_msg);
     } else {
         //APPL_TRACE_ERROR("Invalid Controller ID. Discarding message.");
-        GKI_freebuf(p_msg);
+        osi_free(p_msg);
     }
 }
index 4ac903cc4e8d3d8390f73ee25a40655d97c7244e..98d2aefef9b57ec2b3733087e8b55e8474177561 100644 (file)
@@ -29,6 +29,8 @@
 #include "rom/ets_sys.h"
 #include "btc_task.h"
 #include "btc_alarm.h"
+#include "mutex.h"
+#include "time.h"
 
 #define RTC_TIMER_TICKS_TO_MS(ticks)            (((ticks/625)<<1) + (ticks-(ticks/625)*625)/312)
 
@@ -74,7 +76,7 @@ void osi_alarm_init(void)
 {
     assert(alarm_mutex != NULL);
     
-    osi_mutex_lock(&alarm_mutex);
+    osi_mutex_lock(&alarm_mutex, OSI_MUTEX_MAX_TIMEOUT);
     if (alarm_state != ALARM_STATE_IDLE) {
         LOG_WARN("%s, invalid state %d\n", __func__, alarm_state);
         goto end;
@@ -90,7 +92,7 @@ void osi_alarm_deinit(void)
 {
     assert(alarm_mutex != NULL);
     
-    osi_mutex_lock(&alarm_mutex);
+    osi_mutex_lock(&alarm_mutex, OSI_MUTEX_MAX_TIMEOUT);
     if (alarm_state != ALARM_STATE_OPEN) {
         LOG_WARN("%s, invalid state %d\n", __func__, alarm_state);
         goto end;
@@ -147,7 +149,7 @@ osi_alarm_t *osi_alarm_new(char *alarm_name, osi_alarm_callback_t callback, void
 
     struct alarm_t *timer_id = NULL;
     
-    osi_mutex_lock(&alarm_mutex);
+    osi_mutex_lock(&alarm_mutex, OSI_MUTEX_MAX_TIMEOUT);
     if (alarm_state != ALARM_STATE_OPEN) {
         LOG_ERROR("%s, invalid state %d\n", __func__, alarm_state);
         timer_id = NULL;
@@ -203,7 +205,7 @@ int osi_alarm_free(osi_alarm_t *alarm)
     assert(alarm_mutex != NULL);
     
     int ret = 0;
-    osi_mutex_lock(&alarm_mutex);
+    osi_mutex_lock(&alarm_mutex, OSI_MUTEX_MAX_TIMEOUT);
     if (alarm_state != ALARM_STATE_OPEN) {
         LOG_ERROR("%s, invalid state %d\n", __func__, alarm_state);
         ret = -3;
@@ -222,7 +224,7 @@ int osi_alarm_set(osi_alarm_t *alarm, period_ms_t timeout)
     assert(alarm_mutex != NULL);
     
     int ret = 0;
-    osi_mutex_lock(&alarm_mutex);
+    osi_mutex_lock(&alarm_mutex, OSI_MUTEX_MAX_TIMEOUT);
     if (alarm_state != ALARM_STATE_OPEN) {
         LOG_ERROR("%s, invalid state %d\n", __func__, alarm_state);
         ret = -3;
@@ -256,7 +258,7 @@ end:
 int osi_alarm_cancel(osi_alarm_t *alarm)
 {
     int ret = 0;
-    osi_mutex_lock(&alarm_mutex);
+    osi_mutex_lock(&alarm_mutex, OSI_MUTEX_MAX_TIMEOUT);
     if (alarm_state != ALARM_STATE_OPEN) {
         LOG_ERROR("%s, invalid state %d\n", __func__, alarm_state);
         ret = -3;
@@ -309,3 +311,14 @@ period_ms_t osi_alarm_time_diff(period_ms_t t1, period_ms_t t2)
     }
     return (period_ms_t)diff;
 }
+
+uint32_t osi_time_get_os_boottime_ms(void)
+{
+    return RTC_TIMER_TICKS_TO_MS((alarm_current_tick()));
+}
+
+void osi_delay_ms(uint32_t ms)
+{
+    vTaskDelay(ms / portTICK_PERIOD_MS);
+}
+
index be90dfc24b2aff1d03b1636a3ed01b90534af27a..b96c288413a8bc4989411d3c59506e5df76a0f88 100644 (file)
@@ -133,11 +133,11 @@ void *osi_malloc_func(size_t size)
 #ifdef CONFIG_BLUEDROID_MEM_DEBUG
     void *p;
 
-    p = calloc(1, size);
+    p = malloc(size);
     osi_mem_dbg_record(p, size, __func__, __LINE__);
     return p;
 #else
-    return calloc(1, size);
+    return malloc(size);
 #endif
 }
 
index 5f3f2a3df0ce498ac18c51971b1b4e017e7a4dcb..802354a21c3eb3e335f2f7ace3d155e63f7fc372 100644 (file)
 #include "fixed_queue.h"
 #include "list.h"
 #include "osi.h"
-#include "osi_arch.h"
 #include "bt_trace.h"
+#include "mutex.h"
+#include "semaphore.h"
 
 typedef struct fixed_queue_t {
 
     list_t *list;
     osi_sem_t enqueue_sem;
     osi_sem_t dequeue_sem;
-    pthread_mutex_t lock;
+    osi_mutex_t lock;
     size_t capacity;
 
     fixed_queue_cb dequeue_ready;
-    /*
-      reactor_object_t *dequeue_object;
-      fixed_queue_cb dequeue_ready;
-      void *dequeue_context;
-    */
 } fixed_queue_t;
 
-//static void internal_dequeue_ready(void *context);
 
 fixed_queue_t *fixed_queue_new(size_t capacity)
 {
@@ -49,7 +44,7 @@ fixed_queue_t *fixed_queue_new(size_t capacity)
         goto error;
     }
 
-    pthread_mutex_init(&ret->lock, NULL);
+    osi_mutex_new(&ret->lock);
     ret->capacity = capacity;
 
     ret->list = list_new(NULL);
@@ -78,36 +73,55 @@ error:;
 void fixed_queue_free(fixed_queue_t *queue, fixed_queue_free_cb free_cb)
 {
     const list_node_t *node;
-    if (!queue) {
-        return;
-    }
 
-//  fixed_queue_unregister_dequeue(queue);
+    if (queue == NULL) {
+           return;
+       }
+
+    fixed_queue_unregister_dequeue(queue);
 
-    if (free_cb)
+    if (free_cb) {
         for (node = list_begin(queue->list); node != list_end(queue->list); node = list_next(node)) {
             free_cb(list_node(node));
         }
+    }
 
     list_free(queue->list);
     osi_sem_free(&queue->enqueue_sem);
     osi_sem_free(&queue->dequeue_sem);
-    pthread_mutex_destroy(&queue->lock);
+    osi_mutex_free(&queue->lock);
     osi_free(queue);
 }
 
 bool fixed_queue_is_empty(fixed_queue_t *queue)
 {
     bool is_empty = false;
-    assert(queue != NULL);
 
-    pthread_mutex_lock(&queue->lock);
+    if (queue == NULL) {
+        return true;
+    }
+
+    osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
     is_empty = list_is_empty(queue->list);
-    pthread_mutex_unlock(&queue->lock);
+    osi_mutex_unlock(&queue->lock);
 
     return is_empty;
 }
 
+size_t fixed_queue_length(fixed_queue_t *queue)
+{
+    size_t length;
+
+    if (queue == NULL) {
+        return 0;
+    }
+
+    osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
+    length = list_length(queue->list);
+    osi_mutex_unlock(&queue->lock);
+
+    return length;
+}
 size_t fixed_queue_capacity(fixed_queue_t *queue)
 {
     assert(queue != NULL);
@@ -120,56 +134,138 @@ void fixed_queue_enqueue(fixed_queue_t *queue, void *data)
     assert(queue != NULL);
     assert(data != NULL);
 
-    osi_sem_wait(&queue->enqueue_sem, 0);
+    osi_sem_take(&queue->enqueue_sem, OSI_SEM_MAX_TIMEOUT);
 
-    pthread_mutex_lock(&queue->lock);
+    osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
 
     list_append(queue->list, data);
-    pthread_mutex_unlock(&queue->lock);
+    osi_mutex_unlock(&queue->lock);
 
-    osi_sem_signal(&queue->dequeue_sem);
+    osi_sem_give(&queue->dequeue_sem);
 }
 
 void *fixed_queue_dequeue(fixed_queue_t *queue)
 {
     void *ret = NULL;
+
     assert(queue != NULL);
 
-    osi_sem_wait(&queue->dequeue_sem, 0);
+    osi_sem_take(&queue->dequeue_sem, OSI_SEM_MAX_TIMEOUT);
 
-    pthread_mutex_lock(&queue->lock);
+    osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
     ret = list_front(queue->list);
     list_remove(queue->list, ret);
-    pthread_mutex_unlock(&queue->lock);
+    osi_mutex_unlock(&queue->lock);
 
-    osi_sem_signal(&queue->enqueue_sem);
+    osi_sem_give(&queue->enqueue_sem);
 
     return ret;
 }
 
-/*
-void *fixed_queue_try_dequeue(fixed_queue_t *queue) {
-  void *ret = NULL;
-  assert(queue != NULL);
+bool fixed_queue_try_enqueue(fixed_queue_t *queue, void *data)
+{
+    assert(queue != NULL);
+    assert(data != NULL);
 
-  if (!semaphore_try_wait(queue->dequeue_sem))
-    return NULL;
+    if (osi_sem_take(&queue->enqueue_sem, 0) != 0) {
+        return false;
+    }
+
+    osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
+
+    list_append(queue->list, data);
+    osi_mutex_unlock(&queue->lock);
+
+    osi_sem_give(&queue->dequeue_sem);
+
+    return true;
+}
+
+void *fixed_queue_try_dequeue(fixed_queue_t *queue)
+{
+    void *ret = NULL;
+
+    if (queue == NULL) {
+        return NULL;
+    }
+
+    if (osi_sem_take(queue->dequeue_sem, 0) != 0) {
+        return NULL;
+    }
+
+    osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
+    ret = list_front(queue->list);
+    list_remove(queue->list, ret);
+    osi_mutex_unlock(&queue->lock);
+
+    osi_sem_give(&queue->enqueue_sem);
 
-  pthread_mutex_lock(&queue->lock);
-  ret = list_front(queue->list);
-  list_remove(queue->list, ret);
-  pthread_mutex_unlock(&queue->lock);
+    return ret;
+}
+
+void *fixed_queue_try_peek_first(fixed_queue_t *queue)
+{
+    void *ret = NULL;
 
-  semaphore_post(queue->enqueue_sem);
+    if (queue == NULL) {
+        return NULL;
+    }
+
+    osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
+    ret = list_is_empty(queue->list) ? NULL : list_front(queue->list);
+    osi_mutex_unlock(&queue->lock);
 
-  return ret;
+    return ret;
 }
 
-int fixed_queue_get_dequeue_fd(const fixed_queue_t *queue) {
-  assert(queue != NULL);
-  return semaphore_get_fd(queue->dequeue_sem);
+void *fixed_queue_try_peek_last(fixed_queue_t *queue)
+{
+    void *ret = NULL;
+
+    if (queue == NULL) {
+        return NULL;
+    }
+
+    osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
+    ret = list_is_empty(queue->list) ? NULL : list_back(queue->list);
+    osi_mutex_unlock(&queue->lock);
+
+    return ret;
 }
-*/
+
+void *fixed_queue_try_remove_from_queue(fixed_queue_t *queue, void *data)
+{
+    bool removed = false;
+
+    if (queue == NULL) {
+        return NULL;
+    }
+
+    osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
+    if (list_contains(queue->list, data) &&
+            osi_sem_take(queue->dequeue_sem, 0) == 0) {
+        removed = list_remove(queue->list, data);
+        assert(removed);
+    }
+    osi_mutex_unlock(&queue->lock);
+
+    if (removed) {
+        osi_sem_give(queue->enqueue_sem);
+        return data;
+    }
+
+    return NULL;
+}
+
+list_t *fixed_queue_get_list(fixed_queue_t *queue)
+{
+    assert(queue != NULL);
+
+    // NOTE: This function is not thread safe, and there is no point for
+    // calling osi_mutex_lock() / osi_mutex_unlock()
+    return queue->list;
+}
+
 void fixed_queue_register_dequeue(fixed_queue_t *queue, fixed_queue_cb ready_cb)
 {
     assert(queue != NULL);
@@ -187,19 +283,10 @@ void fixed_queue_unregister_dequeue(fixed_queue_t *queue)
 
 void fixed_queue_process(fixed_queue_t *queue)
 {
-    if (queue == NULL) {
-        return;
-    }
+    assert(queue != NULL);
 
     if (queue->dequeue_ready) {
         queue->dequeue_ready(queue);
     }
 }
-/*
-static void internal_dequeue_ready(void *context) {
-  assert(context != NULL);
 
-  fixed_queue_t *queue = context;
-  queue->dequeue_ready(queue, queue->dequeue_context);
-}
-*/
index 1ee113db1e192405566cdd7bbdf331eb330fbfa8..415b44ebf15e272cd3f51e95086db00c7f617dec 100644 (file)
@@ -21,7 +21,6 @@
 #include "allocator.h"
 #include "future.h"
 #include "osi.h"
-#include "osi_arch.h"
 
 void future_free(future_t *future);
 
@@ -68,7 +67,7 @@ void future_ready(future_t *future, void *value)
 
     future->ready_can_be_called = false;
     future->result = value;
-    osi_sem_signal(&future->semaphore);
+    osi_sem_give(&future->semaphore);
 }
 
 void *future_await(future_t *future)
@@ -77,7 +76,7 @@ void *future_await(future_t *future)
 
     // If the future is immediate, it will not have a semaphore
     if (future->semaphore) {
-        osi_sem_wait(&future->semaphore, 0);
+        osi_sem_take(&future->semaphore, OSI_SEM_MAX_TIMEOUT);
     }
 
     void *result = future->result;
index 937874f219544b6fb2c37a080b23aed6dc7215ef..07efbc5ac1cc170e612f36ae8f35fe7a03daf8f1 100644 (file)
@@ -76,4 +76,6 @@ period_ms_t osi_alarm_get_remaining_ms(const osi_alarm_t *alarm);
 // t1 and t2 should be no greater than the time of MAX ticks
 period_ms_t osi_alarm_time_diff(period_ms_t t1, period_ms_t t2);
 
+uint32_t osi_time_get_os_boottime_ms(void);
+
 #endif /*_ALARM_H_*/
index 82ef5b0ea0be7cbb2ec3161b47915495002c8c6d..b217cef9a4166cef17a6b9470242de9a847a2b55 100644 (file)
@@ -20,7 +20,7 @@
 #define _ALLOCATOR_H_
 
 #include <stddef.h>
-//#include <stdlib.h>
+#include <stdlib.h>
 #include "sdkconfig.h"
 
 typedef void *(*alloc_fn)(size_t size);
@@ -52,7 +52,7 @@ void osi_mem_dbg_show(void);
 ({                                                      \
     void *p;                                            \
                                                         \
-    p = calloc(1, (size));                              \
+    p = malloc((size));                                 \
     osi_mem_dbg_record(p, size, __func__, __LINE__);    \
     (void *)p;                                          \
 })
@@ -67,14 +67,15 @@ void osi_mem_dbg_show(void);
 })
 
 #define osi_free(ptr)                                   \
-({                                                      \
-    osi_mem_dbg_clean(ptr, __func__, __LINE__);         \
-    free((ptr));                                        \
-})
+do {                                                    \
+    void *tmp_point = (void *)(ptr);                    \
+    osi_mem_dbg_clean(tmp_point, __func__, __LINE__);   \
+    free(tmp_point);                                    \
+} while (0)
 
 #else
 
-#define osi_malloc(size)                  calloc(1, (size))
+#define osi_malloc(size)                  malloc((size))
 #define osi_calloc(size)                  calloc(1, (size))
 #define osi_free(p)                       free((p))
 
index 9cbb846d5876e8a5344fa83d451562ad95a80064..becafea1988e3a22495ea42b04c4cfe1d206c883 100644 (file)
 #define _FIXED_QUEUE_H_
 
 #include <stdbool.h>
+#include "list.h"
 
 struct fixed_queue_t;
+
 typedef struct fixed_queue_t fixed_queue_t;
 //typedef struct reactor_t reactor_t;
 
@@ -38,10 +40,14 @@ fixed_queue_t *fixed_queue_new(size_t capacity);
 // blocked on it) results in undefined behaviour.
 void fixed_queue_free(fixed_queue_t *queue, fixed_queue_free_cb free_cb);
 
-// Returns a value indicating whether the given |queue| is empty. |queue| may
-// not be NULL.
+// Returns a value indicating whether the given |queue| is empty. If |queue|
+// is NULL, the return value is true.
 bool fixed_queue_is_empty(fixed_queue_t *queue);
 
+// Returns the length of the |queue|. If |queue| is NULL, the return value
+// is 0.
+size_t fixed_queue_length(fixed_queue_t *queue);
+
 // Returns the maximum number of elements this queue may hold. |queue| may
 // not be NULL.
 size_t fixed_queue_capacity(fixed_queue_t *queue);
@@ -66,12 +72,33 @@ bool fixed_queue_try_enqueue(fixed_queue_t *queue, void *data);
 // the caller. If the queue is empty, this function returns NULL immediately.
 // Otherwise, the next element in the queue is returned. |queue| may not be
 // NULL.
-//void *fixed_queue_try_dequeue(fixed_queue_t *queue);
+void *fixed_queue_try_dequeue(fixed_queue_t *queue);
 
 // Returns the first element from |queue|, if present, without dequeuing it.
-// This function will never block the caller. Returns NULL if there are no elements
-// in the queue. |queue| may not be NULL.
-//void *fixed_queue_try_peek(fixed_queue_t *queue);
+// This function will never block the caller. Returns NULL if there are no
+// elements in the queue or |queue| is NULL.
+void *fixed_queue_try_peek_first(fixed_queue_t *queue);
+
+// Returns the last element from |queue|, if present, without dequeuing it.
+// This function will never block the caller. Returns NULL if there are no
+// elements in the queue or |queue| is NULL.
+void *fixed_queue_try_peek_last(fixed_queue_t *queue);
+
+// Tries to remove a |data| element from the middle of the |queue|. This
+// function will never block the caller. If the queue is empty or NULL, this
+// function returns NULL immediately. |data| may not be NULL. If the |data|
+// element is found in the queue, a pointer to the removed data is returned,
+// otherwise NULL.
+void *fixed_queue_try_remove_from_queue(fixed_queue_t *queue, void *data);
+
+// Returns the iterateable list with all entries in the |queue|. This function
+// will never block the caller. |queue| may not be NULL.
+//
+// NOTE: The return result of this function is not thread safe: the list could
+// be modified by another thread, and the result would be unpredictable.
+// TODO: The usage of this function should be refactored, and the function
+// itself should be removed.
+list_t *fixed_queue_get_list(fixed_queue_t *queue);
 
 // This function returns a valid file descriptor. Callers may perform one
 // operation on the fd: select(2). If |select| indicates that the file
@@ -99,4 +126,6 @@ void fixed_queue_unregister_dequeue(fixed_queue_t *queue);
 
 void fixed_queue_process(fixed_queue_t *queue);
 
+list_t *fixed_queue_get_list(fixed_queue_t *queue);
+
 #endif
index a89640c27e7a0f6ce42b102b3f627605ec2803d6..f001f1f1337d36000fc7de5ca4047aaebac20d8f 100644 (file)
@@ -18,9 +18,8 @@
 
 #ifndef __FUTURE_H__
 #define __FUTURE_H__
-// #pragma once
 
-#include "osi_arch.h"
+#include "semaphore.h"
 
 struct future {
     bool ready_can_be_called;
index 770979672d12e66cfb17e5de6310e78f26d43865..c0abd106e555bdafa663d0c5a2103a9e09b82bbf 100644 (file)
@@ -10,7 +10,7 @@ struct list_t;
 typedef struct list_t list_t;
 
 typedef void (*list_free_cb)(void *data);
-typedef bool (*list_iter_cb)(void *data);
+typedef bool (*list_iter_cb)(void *data, void *context);
 
 // Returns a new, empty list. Returns NULL if not enough memory could be allocated
 // for the list structure. The returned list must be freed with |list_free|. The
@@ -22,7 +22,6 @@ list_t *list_new(list_free_cb callback);
 
 
 list_node_t *list_free_node(list_t *list, list_node_t *node);
-//list_node_t *list_free_node(list_t *list, list_node_t *node);
 // Frees the list. This function accepts NULL as an argument, in which case it
 // behaves like a no-op.
 void list_free(list_t *list);
@@ -44,7 +43,8 @@ void *list_front(const list_t *list);
 
 // Returns the last element in the list without removing it. |list| may not
 // be NULL or empty.
-//void *list_back(const list_t *list);
+void *list_back(const list_t *list);
+list_node_t *list_back_node(const list_t *list);
 
 // Inserts |data| after |prev_node| in |list|. |data|, |list|, and |prev_node|
 // may not be NULL. This function does not make a copy of |data| so the pointer
@@ -84,7 +84,7 @@ void list_clear(list_t *list);
 // list inside the callback. If an element is added before the node being visited,
 // there will be no callback for the newly-inserted node. Neither |list| nor
 // |callback| may be NULL.
-void list_foreach(const list_t *list, list_iter_cb callback);
+list_node_t *list_foreach(const list_t *list, list_iter_cb callback, void *context);
 
 // Returns an iterator to the first element in |list|. |list| may not be NULL.
 // The returned iterator is valid as long as it does not equal the value returned
diff --git a/components/bt/bluedroid/osi/include/mutex.h b/components/bt/bluedroid/osi/include/mutex.h
new file mode 100644 (file)
index 0000000..65180a7
--- /dev/null
@@ -0,0 +1,53 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 2015 Google, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#ifndef __MUTEX_H__
+#define __MUTEX_H__
+
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "freertos/queue.h"
+#include "freertos/semphr.h"
+
+
+#define OSI_MUTEX_MAX_TIMEOUT 0xffffffffUL
+
+#define osi_mutex_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
+#define osi_mutex_set_invalid( x ) ( ( *x ) = NULL )
+
+typedef xSemaphoreHandle osi_mutex_t;
+
+int osi_mutex_new(osi_mutex_t *mutex);
+
+int osi_mutex_lock(osi_mutex_t *mutex, uint32_t timeout);
+
+void osi_mutex_unlock(osi_mutex_t *mutex);
+
+void osi_mutex_free(osi_mutex_t *mutex);
+
+/* Just for a global mutex */
+int osi_mutex_global_init(void);
+
+void osi_mutex_global_deinit(void);
+
+void osi_mutex_global_lock(void);
+
+void osi_mutex_global_unlock(void);
+
+#endif /* __MUTEX_H__ */
+
index 3308255b2d05599867d04fd8823db401de62c72d..3bd217af3eb7cb5d2d5b28ff167460d737d290e8 100644 (file)
@@ -6,21 +6,11 @@
 #include <stdint.h>
 
 #define UNUSED_ATTR __attribute__((unused))
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define INVALID_FD (-1)
 
 #define CONCAT(a, b) a##b
+#define COMPILE_ASSERT(x)
 
-// Use during compile time to check conditional values
-// NOTE: The the failures will present as a generic error
-// "error: initialization makes pointer from integer without a cast"
-// but the file and line number will present the condition that
-// failed.
-#define DUMMY_COUNTER(c) CONCAT(__osi_dummy_, c)
-#define DUMMY_PTR DUMMY_COUNTER(__COUNTER__)
-
-#define COMPILE_ASSERT(x) char * DUMMY_PTR = !(x)
-
-typedef uint32_t timeout_t;
+int osi_init(void);
+void osi_deinit(void);
 
 #endif /*_OSI_H_*/
diff --git a/components/bt/bluedroid/osi/include/osi_arch.h b/components/bt/bluedroid/osi/include/osi_arch.h
deleted file mode 100644 (file)
index 491d482..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef __os_ARCH_H__
-#define __os_ARCH_H__
-
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
-#include "freertos/semphr.h"
-
-#define OSI_ARCH_TIMEOUT 0xffffffffUL
-
-typedef xSemaphoreHandle osi_sem_t;
-typedef xSemaphoreHandle osi_mutex_t;
-
-#define osi_mutex_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
-#define osi_mutex_set_invalid( x ) ( ( *x ) = NULL )
-#define osi_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
-#define osi_sem_set_invalid( x ) ( ( *x ) = NULL )
-
-int osi_mutex_new(osi_mutex_t *pxMutex);
-
-void osi_mutex_lock(osi_mutex_t *pxMutex);
-
-int osi_mutex_trylock(osi_mutex_t *pxMutex);
-
-void osi_mutex_unlock(osi_mutex_t *pxMutex);
-
-void osi_mutex_free(osi_mutex_t *pxMutex);
-
-int osi_sem_new(osi_sem_t *sem, uint32_t max_count, uint32_t init_count);
-
-void osi_sem_signal(osi_sem_t *sem);
-
-uint32_t osi_sem_wait(osi_sem_t *sem, uint32_t timeout);
-
-void osi_sem_free(osi_sem_t *sem);
-
-void osi_arch_init(void);
-
-uint32_t osi_now(void);
-
-void osi_delay_ms(uint32_t ms);
-
-
-#endif /* __os_ARCH_H__ */
-
similarity index 54%
rename from components/bt/bluedroid/gki/include/gki_int.h
rename to components/bt/bluedroid/osi/include/semaphore.h
index 3307066efbf6ad98bb37c4b20bc771348af9b028..621d5a2c1e9563b03866d303539881c48673c0c6 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright (C) 1999-2012 Broadcom Corporation
+ *  Copyright (C) 2015 Google, Inc.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *
  ******************************************************************************/
 
-#ifndef _GKI_INT_H_
-#define _GKI_INT_H_
+#ifndef __SEMAPHORE_H__
+#define __SEMAPHORE_H__
 
-//#include <pthread.h>
-#include "bt_defs.h"
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "freertos/queue.h"
+#include "freertos/semphr.h"
 
-#include "gki_common.h"
+#define OSI_SEM_MAX_TIMEOUT 0xffffffffUL
 
-typedef struct {
-    pthread_mutex_t lock;
-    tGKI_COM_CB com;
-} tGKI_CB;
+typedef xSemaphoreHandle osi_sem_t;
 
-extern tGKI_CB  gki_cb;
+#define osi_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
+#define osi_sem_set_invalid( x ) ( ( *x ) = NULL )
 
-#endif /*_GKI_INT_H_*/
+int osi_sem_new(osi_sem_t *sem, uint32_t max_count, uint32_t init_count);
+
+void osi_sem_free(osi_sem_t *sem);
+
+int osi_sem_take(osi_sem_t *sem, uint32_t timeout);
+
+void osi_sem_give(osi_sem_t *sem);
+
+
+#endif /* __SEMAPHORE_H__ */
index 7ffcb47d4eea7332715ddbb187c38507b28552d6..d93478274c6f55e52a1544a232bc6c277ece3606 100644 (file)
@@ -57,20 +57,18 @@ bool list_is_empty(const list_t *list)
     return (list->length == 0);
 }
 
-/*
-bool list_contains(const list_t *list, const void *data) {
-  const list_node_t *node;
+bool list_contains(const list_t *list, const void *data)
+{
   assert(list != NULL);
   assert(data != NULL);
 
-  for (node = list_begin(list); node != list_end(list); node = list_next(node)) {
+  for (const list_node_t *node = list_begin(list); node != list_end(list); node = list_next(node)) {
     if (list_node(node) == data)
       return true;
   }
 
   return false;
 }
-*/
 
 size_t list_length(const list_t *list)
 {
@@ -86,26 +84,28 @@ void *list_front(const list_t *list)
     return list->head->data;
 }
 
-/*
 void *list_back(const list_t *list) {
   assert(list != NULL);
   assert(!list_is_empty(list));
 
   return list->tail->data;
 }
-*/
 
-bool list_insert_after(list_t *list, list_node_t *prev_node, void *data)
-{
-    list_node_t *node;
-    assert(list != NULL);
-    assert(prev_node != NULL);
-    assert(data != NULL);
+list_node_t *list_back_node(const list_t *list) {
+  assert(list != NULL);
+  assert(!list_is_empty(list));
 
-    node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t));
-    if (!node) {
-        return false;
-    }
+  return list->tail;
+}
+
+bool list_insert_after(list_t *list, list_node_t *prev_node, void *data) {
+  assert(list != NULL);
+  assert(prev_node != NULL);
+  assert(data != NULL);
+
+  list_node_t *node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t));
+  if (!node)
+    return false;
 
     node->next = prev_node->next;
     node->data = data;
@@ -119,11 +119,10 @@ bool list_insert_after(list_t *list, list_node_t *prev_node, void *data)
 
 bool list_prepend(list_t *list, void *data)
 {
-    list_node_t *node;
     assert(list != NULL);
     assert(data != NULL);
 
-    node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t));
+  list_node_t *node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t));
     if (!node) {
         return false;
     }
@@ -139,11 +138,10 @@ bool list_prepend(list_t *list, void *data)
 
 bool list_append(list_t *list, void *data)
 {
-    list_node_t *node;
     assert(list != NULL);
     assert(data != NULL);
 
-    node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t));
+  list_node_t *node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t));
     if (!node) {
         return false;
     }
@@ -201,16 +199,18 @@ void list_clear(list_t *list)
     list->length = 0;
 }
 
-void list_foreach(const list_t *list, list_iter_cb callback)
+list_node_t *list_foreach(const list_t *list, list_iter_cb callback, void *context)
 {
-    assert(list != NULL);
-    assert(callback != NULL);
+  assert(list != NULL);
+  assert(callback != NULL);
 
-    for (list_node_t *node = list->head; node; ) {
-        list_node_t *next = node->next;
-        callback(node->data);
-        node = next;
-    }
+  for (list_node_t *node = list->head; node; ) {
+    list_node_t *next = node->next;
+    if (!callback(node->data, context))
+      return node;
+    node = next;
+  }
+  return NULL;
 }
 
 list_node_t *list_begin(const list_t *list)
diff --git a/components/bt/bluedroid/osi/mutex.c b/components/bt/bluedroid/osi/mutex.c
new file mode 100644 (file)
index 0000000..9b679f4
--- /dev/null
@@ -0,0 +1,99 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 2015 Google, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#include "mutex.h"
+
+
+/* static section */
+static osi_mutex_t gl_mutex; /* Recursive Type */
+
+
+/** Create a new mutex
+ * @param mutex pointer to the mutex to create
+ * @return a new mutex */
+int osi_mutex_new(osi_mutex_t *mutex)
+{
+    int xReturn = -1;
+
+    *mutex = xSemaphoreCreateMutex();
+
+    if (*mutex != NULL) {
+        xReturn = 0;
+    }
+
+    return xReturn;
+}
+
+/** Lock a mutex
+ * @param mutex the mutex to lock */
+int osi_mutex_lock(osi_mutex_t *mutex, uint32_t timeout)
+{
+    int ret = 0;
+
+    if (timeout == OSI_MUTEX_MAX_TIMEOUT) {
+        if (xSemaphoreTake(*mutex, portMAX_DELAY) != pdTRUE) {
+            ret = -1;
+        }
+    } else {
+        if (xSemaphoreTake(*mutex, timeout / portTICK_PERIOD_MS) != pdTRUE)  {
+            ret = -2;
+        }
+    }
+
+    return ret;
+}
+
+/** Unlock a mutex
+ * @param mutex the mutex to unlock */
+void osi_mutex_unlock(osi_mutex_t *mutex)
+{
+    xSemaphoreGive(*mutex);
+}
+
+/** Delete a semaphore
+ * @param mutex the mutex to delete */
+void osi_mutex_free(osi_mutex_t *mutex)
+{
+    vSemaphoreDelete(*mutex);
+    *mutex = NULL;
+}
+
+int osi_mutex_global_init(void)
+{
+    gl_mutex = xSemaphoreCreateRecursiveMutex();
+    if (gl_mutex == NULL) {
+        return -1;
+    }
+
+    return 0;
+}
+
+void osi_mutex_global_deinit(void)
+{
+    vSemaphoreDelete(gl_mutex);
+}
+
+void osi_mutex_global_lock(void)
+{
+    xSemaphoreTakeRecursive(gl_mutex, portMAX_DELAY);
+}
+
+void osi_mutex_global_unlock(void)
+{
+    xSemaphoreGiveRecursive(gl_mutex);
+}
diff --git a/components/bt/bluedroid/osi/osi.c b/components/bt/bluedroid/osi/osi.c
new file mode 100644 (file)
index 0000000..348ee0b
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+
+#include "osi.h"
+#include "mutex.h"
+
+int osi_init(void)
+{
+    int ret = 0;
+
+    if (osi_mutex_global_init() != 0) {
+        ret = -1;
+    }
+
+    return ret;
+}
+
+void osi_deinit(void)
+{
+    osi_mutex_global_deinit();
+}
diff --git a/components/bt/bluedroid/osi/osi_arch.c b/components/bt/bluedroid/osi/osi_arch.c
deleted file mode 100644 (file)
index d1d0185..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * This file is part of the bluedroid stack.
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- */
-
-#include "osi_arch.h"
-
-/** Create a new mutex
- * @param mutex pointer to the mutex to create
- * @return a new mutex */
-int
-osi_mutex_new(osi_mutex_t *pxMutex)
-{
-    int xReturn = -1;
-
-    *pxMutex = xSemaphoreCreateMutex();
-
-    if (*pxMutex != NULL) {
-        xReturn = 0;
-    }
-
-    //LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("osi_mutex_new: m=%p\n", *pxMutex));
-
-    return xReturn;
-}
-
-/** Lock a mutex
- * @param mutex the mutex to lock */
-void
-osi_mutex_lock(osi_mutex_t *pxMutex)
-{
-    while (xSemaphoreTake(*pxMutex, portMAX_DELAY) != pdPASS);
-}
-
-int
-osi_mutex_trylock(osi_mutex_t *pxMutex)
-{
-    if (xSemaphoreTake(*pxMutex, 0) == pdPASS) {
-        return 0;
-    } else {
-        return -1;
-    }
-}
-
-/** Unlock a mutex
- * @param mutex the mutex to unlock */
-void
-osi_mutex_unlock(osi_mutex_t *pxMutex)
-{
-    xSemaphoreGive(*pxMutex);
-}
-
-/** Delete a semaphore
- * @param mutex the mutex to delete */
-void
-osi_mutex_free(osi_mutex_t *pxMutex)
-{
-    //LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("osi_mutex_free: m=%p\n", *pxMutex));
-    vQueueDelete(*pxMutex);
-}
-
-/*-----------------------------------------------------------------------------------*/
-//  Creates and returns a new semaphore. The "init_count" argument specifies
-//  the initial state of the semaphore, "max_count" specifies the maximum value
-//  that can be reached.
-int
-osi_sem_new(osi_sem_t *sem, uint32_t max_count, uint32_t init_count)
-{
-    int xReturn = -1;
-    if (sem) {
-        *sem = xSemaphoreCreateCounting(max_count, init_count);
-        if ((*sem) != NULL) {
-            xReturn = 0;
-        }
-    }
-
-    return xReturn;
-}
-
-/*-----------------------------------------------------------------------------------*/
-// Signals a semaphore
-void
-osi_sem_signal(osi_sem_t *sem)
-{
-    xSemaphoreGive(*sem);
-}
-
-/*-----------------------------------------------------------------------------------*/
-/*
-  Blocks the thread while waiting for the semaphore to be
-  signaled. If the "timeout" argument is non-zero, the thread should
-  only be blocked for the specified time (measured in
-  milliseconds).
-
-  If the timeout argument is non-zero, the return value is the number of
-  milliseconds spent waiting for the semaphore to be signaled. If the
-  semaphore wasn't signaled within the specified time, the return value is
-  OSI_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore
-  (i.e., it was already signaled), the function may return zero.
-
-  Notice that lwIP implements a function with a similar name,
-  osi_sem_wait(), that uses the osi_arch_sem_wait() function.
-*/
-uint32_t
-osi_sem_wait(osi_sem_t *sem, uint32_t timeout)
-{
-    portTickType StartTime, EndTime, Elapsed;
-    unsigned long ulReturn;
-
-    StartTime = xTaskGetTickCount();
-
-    if (timeout != 0) {
-        if (xSemaphoreTake(*sem, timeout / portTICK_PERIOD_MS) == pdTRUE) {
-            EndTime = xTaskGetTickCount();
-            Elapsed = (EndTime - StartTime) * portTICK_PERIOD_MS;
-
-            if (Elapsed == 0) {
-                Elapsed = 1;
-            }
-
-            ulReturn = Elapsed;
-        } else {
-            ulReturn = OSI_ARCH_TIMEOUT;
-        }
-    } else { // must block without a timeout
-        while (xSemaphoreTake(*sem, portMAX_DELAY) != pdTRUE);
-
-        EndTime = xTaskGetTickCount();
-        Elapsed = (EndTime - StartTime) * portTICK_PERIOD_MS;
-
-        if (Elapsed == 0) {
-            Elapsed = 1;
-        }
-
-        ulReturn = Elapsed;
-    }
-
-    return ulReturn ; // return time blocked
-}
-
-/*-----------------------------------------------------------------------------------*/
-// Deallocates a semaphore
-void
-osi_sem_free(osi_sem_t *sem)
-{
-    vSemaphoreDelete(*sem);
-}
-
-/*-----------------------------------------------------------------------------------*/
-// Initialize osi arch
-void
-osi_arch_init(void)
-{
-}
-
-/*-----------------------------------------------------------------------------------*/
-uint32_t
-osi_now(void)
-{
-    return xTaskGetTickCount();
-}
-
-
-void osi_delay_ms(uint32_t ms)
-{
-    vTaskDelay(ms / portTICK_PERIOD_MS);
-}
-
-
diff --git a/components/bt/bluedroid/osi/semaphore.c b/components/bt/bluedroid/osi/semaphore.c
new file mode 100644 (file)
index 0000000..86493eb
--- /dev/null
@@ -0,0 +1,77 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 2015 Google, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+
+#include "semaphore.h"
+
+/*-----------------------------------------------------------------------------------*/
+//  Creates and returns a new semaphore. The "init_count" argument specifies
+//  the initial state of the semaphore, "max_count" specifies the maximum value
+//  that can be reached.
+int osi_sem_new(osi_sem_t *sem, uint32_t max_count, uint32_t init_count)
+{
+    int ret = -1;
+
+    if (sem) {
+        *sem = xSemaphoreCreateCounting(max_count, init_count);
+        if ((*sem) != NULL) {
+            ret = 0;
+        }
+    }
+
+    return ret;
+}
+
+/*-----------------------------------------------------------------------------------*/
+// Give a semaphore
+void osi_sem_give(osi_sem_t *sem)
+{
+    xSemaphoreGive(*sem);
+}
+
+/*
+  Blocks the thread while waiting for the semaphore to be
+  signaled. If the "timeout" argument is non-zero, the thread should
+  only be blocked for the specified time (measured in
+  milliseconds).
+
+*/
+int
+osi_sem_take(osi_sem_t *sem, uint32_t timeout)
+{
+    int ret = 0;
+
+    if (timeout ==  OSI_SEM_MAX_TIMEOUT) {
+        if (xSemaphoreTake(*sem, portMAX_DELAY) != pdTRUE) {
+            ret = -1;
+        }
+    } else {
+        if (xSemaphoreTake(*sem, timeout / portTICK_PERIOD_MS) != pdTRUE) {
+            ret = -2;
+        }
+    }
+
+    return ret;
+}
+
+// Deallocates a semaphore
+void osi_sem_free(osi_sem_t *sem)
+{
+    vSemaphoreDelete(*sem);
+    *sem = NULL;
+}
index 15ae41b6eeb68403549cddbb6863e260adf7a807..675ecaf83af9240859490087be7d2b2d9248eb1a 100644 (file)
 #include "bt_types.h"
 #include "bt_target.h"
 #include "bt_utils.h"
-#include "gki.h"
 #include "l2c_api.h"
 #include "l2cdefs.h"
 #include "btm_api.h"
 #include "avct_api.h"
 #include "avct_int.h"
+#include "allocator.h"
 
 #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE)
 
@@ -403,12 +403,12 @@ UINT16 AVCT_MsgReq(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR *p_msg)
     /* map handle to ccb */
     if ((p_ccb = avct_ccb_by_idx(handle)) == NULL) {
         result = AVCT_BAD_HANDLE;
-        GKI_freebuf(p_msg);
+        osi_free(p_msg);
     }
     /* verify channel is bound to link */
     else if (p_ccb->p_lcb == NULL) {
         result = AVCT_NOT_OPEN;
-        GKI_freebuf(p_msg);
+        osi_free(p_msg);
     }
 
     if (result == AVCT_SUCCESS) {
@@ -423,7 +423,7 @@ UINT16 AVCT_MsgReq(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR *p_msg)
             if (p_ccb->p_bcb == NULL && (p_ccb->allocated & AVCT_ALOC_BCB) == 0) {
                 /* BCB channel is not open and not allocated */
                 result = AVCT_BAD_HANDLE;
-                GKI_freebuf(p_msg);
+                osi_free(p_msg);
             } else {
                 p_ccb->p_bcb = avct_bcb_by_lcb(p_ccb->p_lcb);
                 avct_bcb_event(p_ccb->p_bcb, AVCT_LCB_UL_MSG_EVT, (tAVCT_LCB_EVT *) &ul_msg);
index 9de15da173497ec1590335e2b3b75ee555555b4a..a1656d7f5c48d13a10770397d899f5f90a3127a5 100644 (file)
@@ -30,6 +30,7 @@
 #include "avct_int.h"
 #include "l2c_api.h"
 #include "l2cdefs.h"
+#include "allocator.h"
 
 #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE)
 
@@ -398,7 +399,7 @@ void avct_l2c_data_ind_cback(UINT16 lcid, BT_HDR *p_buf)
         avct_lcb_event(p_lcb, AVCT_LCB_LL_MSG_EVT, (tAVCT_LCB_EVT *) &p_buf);
     } else { /* prevent buffer leak */
         AVCT_TRACE_WARNING("ERROR -> avct_l2c_data_ind_cback drop buffer");
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
     }
 }
 
index 008fa8ff565a97ecc8cb0e50543589bb86e03695..faf07b0a79502f5d52cfcb8d9c90444171ba6de4 100644 (file)
@@ -29,7 +29,7 @@
 #include "bt_utils.h"
 #include "avct_api.h"
 #include "avct_int.h"
-#include "gki.h"
+#include "allocator.h"
 
 #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE)
 
@@ -313,6 +313,7 @@ tAVCT_LCB *avct_lcb_alloc(BD_ADDR bd_addr)
             p_lcb->allocated = (UINT8)(i + 1);
             memcpy(p_lcb->peer_addr, bd_addr, BD_ADDR_LEN);
             AVCT_TRACE_DEBUG("avct_lcb_alloc %d", p_lcb->allocated);
+            p_lcb->tx_q = fixed_queue_new(SIZE_MAX);
             break;
         }
     }
@@ -337,33 +338,28 @@ tAVCT_LCB *avct_lcb_alloc(BD_ADDR bd_addr)
 *******************************************************************************/
 void avct_lcb_dealloc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 {
-    tAVCT_CCB   *p_ccb = &avct_cb.ccb[0];
-    BOOLEAN     found = FALSE;
-    int         i;
     UNUSED(p_data);
 
-    AVCT_TRACE_DEBUG("avct_lcb_dealloc %d", p_lcb->allocated);
+    AVCT_TRACE_DEBUG("%s allocated: %d", __func__, p_lcb->allocated);
 
-    for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) {
-        /* if ccb allocated and */
-        if (p_ccb->allocated) {
-            if (p_ccb->p_lcb == p_lcb) {
-                AVCT_TRACE_DEBUG("avct_lcb_dealloc used by ccb: %d", i);
-                found = TRUE;
-                break;
-            }
+    // Check if the LCB is still referenced
+
+    tAVCT_CCB *p_ccb = &avct_cb.ccb[0];
+    for (size_t i = 0; i < AVCT_NUM_CONN; i++, p_ccb++)
+    {
+        if (p_ccb->allocated && p_ccb->p_lcb == p_lcb)
+        {
+            AVCT_TRACE_DEBUG("%s LCB in use; lcb index: %d", __func__, i);
+            return;
         }
     }
 
-    if (!found) {
-        AVCT_TRACE_DEBUG("avct_lcb_dealloc now");
+    // If not, de-allocate now...
 
-        /* clear reassembled msg buffer if in use */
-        if (p_lcb->p_rx_msg != NULL) {
-            GKI_freebuf(p_lcb->p_rx_msg);
-        }
-        memset(p_lcb, 0, sizeof(tAVCT_LCB));
-    }
+    AVCT_TRACE_DEBUG("%s Freeing LCB", __func__);
+    osi_free(p_lcb->p_rx_msg);
+    fixed_queue_free(p_lcb->tx_q, NULL);
+    memset(p_lcb, 0, sizeof(tAVCT_LCB));
 }
 
 /*******************************************************************************
index 164e630991e5009adffd2e970ceb9e36a237221b..b61690616390e15a5b3125acba857419927b726d 100644 (file)
@@ -28,8 +28,8 @@
 #include "bt_utils.h"
 #include "avct_api.h"
 #include "avct_int.h"
-#include "gki.h"
 #include "btm_api.h"
+#include "allocator.h"
 
 #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE)
 
@@ -65,7 +65,7 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)
 
     /* quick sanity check on length */
     if (p_buf->len < avct_lcb_pkt_type_len[pkt_type]) {
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
         AVCT_TRACE_WARNING("Bad length during reassembly");
         p_ret = NULL;
     }
@@ -73,32 +73,32 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)
     else if (pkt_type == AVCT_PKT_TYPE_SINGLE) {
         /* if reassembly in progress drop message and process new single */
         if (p_lcb->p_rx_msg != NULL) {
-            GKI_freebuf(p_lcb->p_rx_msg);
-            p_lcb->p_rx_msg = NULL;
             AVCT_TRACE_WARNING("Got single during reassembly");
         }
+        osi_free(p_lcb->p_rx_msg);
+        p_lcb->p_rx_msg = NULL;
         p_ret = p_buf;
     }
     /* start packet */
     else if (pkt_type == AVCT_PKT_TYPE_START) {
         /* if reassembly in progress drop message and process new start */
         if (p_lcb->p_rx_msg != NULL) {
-            GKI_freebuf(p_lcb->p_rx_msg);
             AVCT_TRACE_WARNING("Got start during reassembly");
         }
+        osi_free(p_lcb->p_rx_msg);
         /* Allocate bigger buffer for reassembly. As lower layers are
          * not aware of possible packet size after reassembly they
          * would have allocated smaller buffer.
          */
-        p_lcb->p_rx_msg = (BT_HDR *)GKI_getbuf(GKI_MAX_BUF_SIZE);
+        p_lcb->p_rx_msg = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE);
         if (p_lcb->p_rx_msg == NULL) {
             AVCT_TRACE_ERROR ("Cannot alloc buffer for reassembly !!");
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
         } else {
             memcpy (p_lcb->p_rx_msg, p_buf,
                     sizeof(BT_HDR) + p_buf->offset + p_buf->len);
             /* Free original buffer */
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
 
             /* update p to point to new buffer */
             p = (UINT8 *)(p_lcb->p_rx_msg + 1) + p_lcb->p_rx_msg->offset;
@@ -118,12 +118,16 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)
     else {
         /* if no reassembly in progress drop message */
         if (p_lcb->p_rx_msg == NULL) {
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
             AVCT_TRACE_WARNING("Pkt type=%d out of order", pkt_type);
             p_ret = NULL;
         } else {
             /* get size of buffer holding assembled message */
-            buf_len = GKI_get_buf_size(p_lcb->p_rx_msg) - sizeof(BT_HDR);
+            /*
+             * NOTE: The buffer is allocated above at the beginning of the
+             * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE.
+             */
+            buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR);
 
             /* adjust offset and len of fragment for header byte */
             p_buf->offset += AVCT_HDR_LEN_CONT;
@@ -132,11 +136,11 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)
             /* verify length */
             if ((p_lcb->p_rx_msg->offset + p_buf->len) > buf_len) {
                 /* won't fit; free everything */
-                GKI_freebuf(p_lcb->p_rx_msg);
+                AVCT_TRACE_WARNING("%s: Fragmented message too big!", __func__);
+                osi_free(p_lcb->p_rx_msg);
                 p_lcb->p_rx_msg = NULL;
-                GKI_freebuf(p_buf);
+                osi_free(p_buf);
                 p_ret = NULL;
-                AVCT_TRACE_WARNING("Fragmented message to big!");
             } else {
                 /* copy contents of p_buf to p_rx_msg */
                 memcpy((UINT8 *)(p_lcb->p_rx_msg + 1) + p_lcb->p_rx_msg->offset,
@@ -152,7 +156,7 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)
                     p_lcb->p_rx_msg->len += p_buf->len;
                     p_ret = NULL;
                 }
-                GKI_freebuf(p_buf);
+                osi_free(p_buf);
             }
         }
     }
@@ -442,9 +446,13 @@ void avct_lcb_cong_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
     /* set event */
     event = (p_data->cong) ? AVCT_CONG_IND_EVT : AVCT_UNCONG_IND_EVT;
     p_lcb->cong = p_data->cong;
-    if (p_lcb->cong == FALSE && GKI_getfirst(&p_lcb->tx_q)) {
-        while ( !p_lcb->cong  && (p_buf = (BT_HDR *)GKI_dequeue(&p_lcb->tx_q)) != NULL) {
-            if (L2CA_DataWrite(p_lcb->ch_lcid, p_buf) == L2CAP_DW_CONGESTED) {
+    if (p_lcb->cong == FALSE && !fixed_queue_is_empty(p_lcb->tx_q))
+    {
+        while (!p_lcb->cong &&
+               (p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_lcb->tx_q)) != NULL)
+        {
+            if (L2CA_DataWrite(p_lcb->ch_lcid, p_buf) == L2CAP_DW_CONGESTED)
+            {
                 p_lcb->cong = TRUE;
             }
         }
@@ -474,7 +482,8 @@ void avct_lcb_discard_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 
     AVCT_TRACE_WARNING("Dropping msg");
 
-    GKI_freebuf(p_data->ul_msg.p_buf);
+    osi_free(p_data->ul_msg.p_buf);
+    p_data->ul_msg.p_buf = NULL;
 }
 
 /*******************************************************************************
@@ -492,7 +501,6 @@ void avct_lcb_send_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
     UINT16          curr_msg_len;
     UINT8           pkt_type;
     UINT8           hdr_len;
-    BT_HDR          *p_buf;
     UINT8           *p;
     UINT8           nosp = 0;       /* number of subsequent packets */
     UINT16          temp;
@@ -516,16 +524,18 @@ void avct_lcb_send_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 
     /* while we haven't sent all packets */
     while (curr_msg_len != 0) {
+        BT_HDR *p_buf;
+
         /* set header len */
         hdr_len = avct_lcb_pkt_type_len[pkt_type];
 
         /* if remaining msg must be fragmented */
         if (p_data->ul_msg.p_buf->len > (p_lcb->peer_mtu - hdr_len)) {
             /* get a new buffer for fragment we are sending */
-            if ((p_buf = (BT_HDR *) GKI_getbuf(buf_size)) == NULL) {
+            if ((p_buf = (BT_HDR *) osi_malloc(buf_size)) == NULL) {
                 /* whoops; free original msg buf and bail */
                 AVCT_TRACE_ERROR ("avct_lcb_send_msg cannot alloc buffer!!");
-                GKI_freebuf(p_data->ul_msg.p_buf);
+                osi_free(p_data->ul_msg.p_buf);
                 break;
             }
 
@@ -559,7 +569,7 @@ void avct_lcb_send_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
         }
 
         if (p_lcb->cong == TRUE) {
-            GKI_enqueue (&p_lcb->tx_q, p_buf);
+            fixed_queue_enqueue(p_lcb->tx_q, p_buf);
         }
 
         /* send message to L2CAP */
@@ -576,7 +586,8 @@ void avct_lcb_send_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
             pkt_type = AVCT_PKT_TYPE_END;
         }
     }
-    AVCT_TRACE_DEBUG ("avct_lcb_send_msg tx_q_count:%d", GKI_queue_length(&p_lcb->tx_q));
+    AVCT_TRACE_DEBUG ("avct_lcb_send_msg tx_q_count:%d",
+                      fixed_queue_length(p_lcb->tx_q));
     return;
 }
 
@@ -594,10 +605,11 @@ void avct_lcb_free_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 {
     UNUSED(p_lcb);
 
-    if (p_data) {
-        GKI_freebuf(p_data->p_buf);
-    }
-    return;
+    if (p_data == NULL)
+        return;
+
+    osi_free(p_data->p_buf);
+    p_data->p_buf = NULL;
 }
 
 /*******************************************************************************
@@ -637,7 +649,8 @@ void avct_lcb_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
     /* check for invalid cr_ipid */
     if (cr_ipid == AVCT_CR_IPID_INVALID) {
         AVCT_TRACE_WARNING("Invalid cr_ipid %d", cr_ipid);
-        GKI_freebuf(p_data->p_buf);
+        osi_free(p_data->p_buf);
+        p_data->p_buf = NULL;
         return;
     }
 
@@ -651,11 +664,12 @@ void avct_lcb_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
     } else {
         /* PID not found; drop message */
         AVCT_TRACE_WARNING("No ccb for PID=%x", pid);
-        GKI_freebuf(p_data->p_buf);
+        osi_free(p_data->p_buf);
+        p_data->p_buf = NULL;
 
         /* if command send reject */
         if (cr_ipid == AVCT_CMD) {
-            if ((p_buf = (BT_HDR *) GKI_getpoolbuf(AVCT_CMD_POOL_ID)) != NULL) {
+            if ((p_buf = (BT_HDR *) osi_malloc(AVCT_CMD_BUF_SIZE)) != NULL) {
                 p_buf->len = AVCT_HDR_LEN_SINGLE;
                 p_buf->offset = AVCT_MSG_OFFSET - AVCT_HDR_LEN_SINGLE;
                 p = (UINT8 *)(p_buf + 1) + p_buf->offset;
index c922fe1166331305d331cd0762b3bfea3c7cdd8b..f70f516c0df6ee47d5323a034baf1bf6d1903a14 100644 (file)
 #ifndef AVCT_INT_H
 #define AVCT_INT_H
 
-#include "gki.h"
 #include "avct_api.h"
 #include "avct_defs.h"
 #include "l2c_api.h"
+#include "fixed_queue.h"
 
 /*****************************************************************************
 ** constants
@@ -81,7 +81,7 @@ typedef struct {
     BT_HDR              *p_rx_msg;      /* Message being reassembled */
     UINT16              conflict_lcid;  /* L2CAP channel LCID */
     BD_ADDR             peer_addr;      /* BD address of peer */
-    BUFFER_Q            tx_q;           /* Transmit data buffer queue       */
+    fixed_queue_t       *tx_q;           /* Transmit data buffer queue       */
     BOOLEAN             cong;           /* TRUE, if congested */
 } tAVCT_LCB;
 
index 4b37bf3298f61b99946f47c792b9be3779505660..a4724120475f59d1e6d452efa45b376856f57223 100644 (file)
@@ -34,6 +34,7 @@
 #include "avdt_int.h"
 #include "l2c_api.h"
 #include "l2cdefs.h"
+#include "allocator.h"
 
 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
 /*******************************************************************************
@@ -449,7 +450,7 @@ void avdt_ad_tc_data_ind(tAVDT_TC_TBL *p_tbl, BT_HDR *p_buf)
         if (p_scb != NULL) {
             avdt_scb_event(p_scb, AVDT_SCB_TC_DATA_EVT, (tAVDT_SCB_EVT *) &p_buf);
         } else {
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
             AVDT_TRACE_ERROR(" avdt_ad_tc_data_ind buffer freed");
         }
     }
index 1fd534f6ed23abb05b0052f0e2cf48469a7e8145..d9147032e260e6f14e87b1c64a7c485317e37fa7 100644 (file)
@@ -32,6 +32,7 @@
 #include "l2c_api.h"
 #include "btm_api.h"
 #include "btu.h"
+#include "allocator.h"
 
 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
 
@@ -892,9 +893,6 @@ UINT16 AVDT_WriteReqOpt(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, UINT8 m_
         evt.apiwrite.time_stamp = time_stamp;
         evt.apiwrite.m_pt = m_pt;
         evt.apiwrite.opt = opt;
-#if AVDT_MULTIPLEXING == TRUE
-        GKI_init_q (&evt.apiwrite.frag_q);
-#endif
         avdt_scb_event(p_scb, AVDT_SCB_API_WRITE_REQ_EVT, &evt);
     }
 
@@ -1068,88 +1066,7 @@ UINT16 AVDT_GetSignalChannel(UINT8 handle, BD_ADDR bd_addr)
     return (lcid);
 }
 
-#if AVDT_MULTIPLEXING == TRUE
-/*******************************************************************************
-**
-** Function         AVDT_WriteDataReq
-**
-** Description      Send a media packet to the peer device.  The stream must
-**                  be started before this function is called.  Also, this
-**                  function can only be called if the stream is a SRC.
-**
-**                  When AVDTP has sent the media packet and is ready for the
-**                  next packet, an AVDT_WRITE_CFM_EVT is sent to the
-**                  application via the control callback.  The application must
-**                  wait for the AVDT_WRITE_CFM_EVT before it makes the next
-**                  call to AVDT_WriteDataReq().  If the applications calls
-**                  AVDT_WriteDataReq() before it receives the event the packet
-**                  will not be sent.  The application may make its first call
-**                  to AVDT_WriteDataReq() after it receives an
-**                  AVDT_START_CFM_EVT or AVDT_START_IND_EVT.
-**
-** Returns          AVDT_SUCCESS if successful, otherwise error.
-**
-*******************************************************************************/
-extern UINT16 AVDT_WriteDataReq(UINT8 handle, UINT8 *p_data, UINT32 data_len,
-                                UINT32 time_stamp, UINT8 m_pt, UINT8 marker)
-{
-
-    tAVDT_SCB       *p_scb;
-    tAVDT_SCB_EVT   evt;
-    UINT16          result = AVDT_SUCCESS;
-
-    do {
-        /* check length of media frame */
-        if (data_len > AVDT_MAX_MEDIA_SIZE) {
-            result = AVDT_BAD_PARAMS;
-            break;
-        }
-        /* map handle to scb */
-        if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
-            result = AVDT_BAD_HANDLE;
-            break;
-        }
-        AVDT_TRACE_WARNING("mux_tsid_media:%d\n", p_scb->curr_cfg.mux_tsid_media);
-
-        if (p_scb->p_pkt != NULL
-                || p_scb->p_ccb == NULL
-                || !GKI_queue_is_empty(&p_scb->frag_q)
-                || p_scb->frag_off != 0
-                || p_scb->curr_cfg.mux_tsid_media == 0) {
-            result = AVDT_ERR_BAD_STATE;
-            AVDT_TRACE_WARNING("p_scb->p_pkt=%p, p_scb->p_ccb=%p, IsQueueEmpty=%x, p_scb->frag_off=%x\n",
-                               p_scb->p_pkt, p_scb->p_ccb, GKI_queue_is_empty(&p_scb->frag_q), p_scb->frag_off);
-            break;
-        }
-        evt.apiwrite.p_buf = 0; /* it will indicate using of fragments queue frag_q */
-        /* create queue of media fragments */
-        GKI_init_q (&evt.apiwrite.frag_q);
-
-        /* compose fragments from media payload and put fragments into gueue */
-        avdt_scb_queue_frags(p_scb, &p_data, &data_len, &evt.apiwrite.frag_q);
 
-        if (GKI_queue_is_empty(&evt.apiwrite.frag_q)) {
-            AVDT_TRACE_WARNING("AVDT_WriteDataReq out of GKI buffers");
-            result = AVDT_ERR_RESOURCE;
-            break;
-        }
-        evt.apiwrite.data_len = data_len;
-        evt.apiwrite.p_data = p_data;
-
-        /* process the fragments queue */
-        evt.apiwrite.time_stamp = time_stamp;
-        evt.apiwrite.m_pt = m_pt | (marker << 7);
-        avdt_scb_event(p_scb, AVDT_SCB_API_WRITE_REQ_EVT, &evt);
-    } while (0);
-
-#if (BT_USE_TRACES == TRUE)
-    if (result != AVDT_SUCCESS) {
-        AVDT_TRACE_WARNING("*** AVDT_WriteDataReq failed result=%d\n", result);
-    }
-#endif
-    return result;
-}
-#endif
 
 #if AVDT_MULTIPLEXING == TRUE
 /*******************************************************************************
@@ -1228,7 +1145,7 @@ UINT16 AVDT_SendReport(UINT8 handle, AVDT_REPORT_TYPE type,
         /* build SR - assume fit in one packet */
         p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb);
         if ((p_tbl->state == AVDT_AD_ST_OPEN) &&
-                (p_pkt = (BT_HDR *)GKI_getbuf(p_tbl->peer_mtu)) != NULL) {
+                (p_pkt = (BT_HDR *)osi_malloc(p_tbl->peer_mtu)) != NULL) {
             p_pkt->offset = L2CAP_MIN_OFFSET;
             p = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
 #if AVDT_MULTIPLEXING == TRUE
index f9821a220b74f672b27bca3f7d7dcbfe6401d9e5..55cd1f9dc994994b1521ce7f5ff45aecfc144e09 100644 (file)
@@ -30,7 +30,6 @@
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
-#include "gki.h"
 #include "btu.h"
 
 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
@@ -377,8 +376,8 @@ tAVDT_CCB *avdt_ccb_alloc(BD_ADDR bd_addr)
         if (!p_ccb->allocated) {
             p_ccb->allocated = TRUE;
             memcpy(p_ccb->peer_addr, bd_addr, BD_ADDR_LEN);
-            GKI_init_q(&p_ccb->cmd_q);
-            GKI_init_q(&p_ccb->rsp_q);
+            p_ccb->cmd_q = fixed_queue_new(SIZE_MAX);
+            p_ccb->rsp_q = fixed_queue_new(SIZE_MAX);
             p_ccb->timer_entry.param = (UINT32) p_ccb;
             AVDT_TRACE_DEBUG("avdt_ccb_alloc %d\n", i);
             break;
@@ -409,6 +408,8 @@ void avdt_ccb_dealloc(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 
     AVDT_TRACE_DEBUG("avdt_ccb_dealloc %d\n", avdt_ccb_to_idx(p_ccb));
     btu_stop_timer(&p_ccb->timer_entry);
+    fixed_queue_free(p_ccb->cmd_q, NULL);
+    fixed_queue_free(p_ccb->rsp_q, NULL);
     memset(p_ccb, 0, sizeof(tAVDT_CCB));
 }
 
index 8c0e04229f7d95ed44df8ed9c998bb00d6934e5f..0314438d54d171dcf48e799f41ec864fdff2b1be 100644 (file)
@@ -30,9 +30,9 @@
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
-#include "gki.h"
 #include "btu.h"
 #include "btm_api.h"
+#include "allocator.h"
 
 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
 
@@ -57,19 +57,19 @@ static void avdt_ccb_clear_ccb(tAVDT_CCB *p_ccb)
 
     /* free message being fragmented */
     if (p_ccb->p_curr_msg != NULL) {
-        GKI_freebuf(p_ccb->p_curr_msg);
+        osi_free(p_ccb->p_curr_msg);
         p_ccb->p_curr_msg = NULL;
     }
 
     /* free message being reassembled */
     if (p_ccb->p_rx_msg != NULL) {
-        GKI_freebuf(p_ccb->p_rx_msg);
+        osi_free(p_ccb->p_rx_msg);
         p_ccb->p_rx_msg = NULL;
     }
 
     /* clear out response queue */
-    while ((p_buf = (BT_HDR *) GKI_dequeue(&p_ccb->rsp_q)) != NULL) {
-        GKI_freebuf(p_buf);
+    while ((p_buf = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) {
+        osi_free(p_buf);
     }
 }
 
@@ -659,7 +659,7 @@ void avdt_ccb_clear_cmds(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
         avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT *) &err_code);
 
         /* set up next message */
-        p_ccb->p_curr_cmd = (BT_HDR *) GKI_dequeue(&p_ccb->cmd_q);
+        p_ccb->p_curr_cmd = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->cmd_q);
 
     } while (p_ccb->p_curr_cmd != NULL);
 
@@ -708,7 +708,7 @@ void avdt_ccb_cmd_fail(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
             }
         }
 
-        GKI_freebuf(p_ccb->p_curr_cmd);
+        osi_free(p_ccb->p_curr_cmd);
         p_ccb->p_curr_cmd = NULL;
     }
 }
@@ -729,7 +729,7 @@ void avdt_ccb_free_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
     UNUSED(p_data);
 
     if (p_ccb->p_curr_cmd != NULL) {
-        GKI_freebuf(p_ccb->p_curr_cmd);
+        osi_free(p_ccb->p_curr_cmd);
         p_ccb->p_curr_cmd = NULL;
     }
 }
@@ -780,7 +780,7 @@ void avdt_ccb_ret_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
         /* if command pending and we're not congested and not sending a fragment */
         if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && (p_ccb->p_curr_cmd != NULL)) {
             /* make copy of message in p_curr_cmd and send it */
-            if ((p_msg = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID)) != NULL) {
+            if ((p_msg = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) != NULL) {
                 memcpy(p_msg, p_ccb->p_curr_cmd,
                        (sizeof(BT_HDR) + p_ccb->p_curr_cmd->offset + p_ccb->p_curr_cmd->len));
                 avdt_msg_send(p_ccb, p_msg);
@@ -812,9 +812,9 @@ void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
     ** not congested, not sending fragment, not waiting for response
     */
     if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && (p_ccb->p_curr_cmd == NULL)) {
-        if ((p_msg = (BT_HDR *) GKI_dequeue(&p_ccb->cmd_q)) != NULL) {
+        if ((p_msg = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->cmd_q)) != NULL) {
             /* make a copy of buffer in p_curr_cmd */
-            if ((p_ccb->p_curr_cmd = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID)) != NULL) {
+            if ((p_ccb->p_curr_cmd = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) != NULL) {
                 memcpy(p_ccb->p_curr_cmd, p_msg, (sizeof(BT_HDR) + p_msg->offset + p_msg->len));
 
                 avdt_msg_send(p_ccb, p_msg);
@@ -845,8 +845,8 @@ void avdt_ccb_snd_msg(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
             avdt_msg_send(p_ccb, NULL);
         }
         /* do we have responses to send?  send them */
-        else if (!GKI_queue_is_empty(&p_ccb->rsp_q)) {
-            while ((p_msg = (BT_HDR *) GKI_dequeue(&p_ccb->rsp_q)) != NULL) {
+        else if (!fixed_queue_is_empty(p_ccb->rsp_q)) {
+            while ((p_msg = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) {
                 if (avdt_msg_send(p_ccb, p_msg) == TRUE) {
                     /* break out if congested */
                     break;
index ef4609098bedeca63dc0af67440d07d31d80319d..b99e831595ac90411fec48cdcca28cb3d1ef9375 100644 (file)
@@ -33,6 +33,7 @@
 #include "l2cdefs.h"
 #include "btm_api.h"
 #include "btm_int.h"
+#include "allocator.h"
 
 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
 
@@ -486,7 +487,7 @@ void avdt_l2c_data_ind_cback(UINT16 lcid, BT_HDR *p_buf)
     if ((p_tbl = avdt_ad_tc_tbl_by_lcid(lcid)) != NULL) {
         avdt_ad_tc_data_ind(p_tbl, p_buf);
     } else { /* prevent buffer leak */
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
     }
 }
 
index 557f942637f9ea2fc945371f134b44668fb6b0b7..43245b87b3953b83cfc9cb13d547c2d86400534e 100644 (file)
@@ -33,8 +33,8 @@
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
-#include "gki.h"
 #include "btu.h"
+#include "allocator.h"
 
 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
 /*****************************************************************************
@@ -1177,7 +1177,7 @@ BOOLEAN avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg)
                    (p_tbl->peer_mtu - 1) + 2;
 
             /* get a new buffer for fragment we are sending */
-            if ((p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID)) == NULL) {
+            if ((p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) == NULL) {
                 /* do we even want to try and recover from this? could do so
                 by setting retransmission timer */
                 return TRUE;
@@ -1196,7 +1196,7 @@ BOOLEAN avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg)
             hdr_len = AVDT_LEN_TYPE_CONT;
 
             /* get a new buffer for fragment we are sending */
-            if ((p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID)) == NULL) {
+            if ((p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) == NULL) {
                 /* do we even want to try and recover from this? could do so
                 by setting retransmission timer */
                 return TRUE;
@@ -1287,7 +1287,7 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
 
     /* quick sanity check on length */
     if (p_buf->len < avdt_msg_pkt_type_len[pkt_type]) {
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
         AVDT_TRACE_WARNING("Bad length during reassembly");
         p_ret = NULL;
     }
@@ -1295,7 +1295,7 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
     else if (pkt_type == AVDT_PKT_TYPE_SINGLE) {
         /* if reassembly in progress drop message and process new single */
         if (p_ccb->p_rx_msg != NULL) {
-            GKI_freebuf(p_ccb->p_rx_msg);
+            osi_free(p_ccb->p_rx_msg);
             p_ccb->p_rx_msg = NULL;
             AVDT_TRACE_WARNING("Got single during reassembly");
         }
@@ -1305,10 +1305,24 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
     else if (pkt_type == AVDT_PKT_TYPE_START) {
         /* if reassembly in progress drop message and process new single */
         if (p_ccb->p_rx_msg != NULL) {
-            GKI_freebuf(p_ccb->p_rx_msg);
+                   osi_free(p_ccb->p_rx_msg);
+                   p_ccb->p_rx_msg = NULL;
             AVDT_TRACE_WARNING("Got start during reassembly");
         }
-        p_ccb->p_rx_msg = p_buf;
+        /*
+         * Allocate bigger buffer for reassembly. As lower layers are
+         * not aware of possible packet size after reassembly, they
+         * would have allocated smaller buffer.
+         */
+        p_ccb->p_rx_msg = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE);
+        memcpy(p_ccb->p_rx_msg, p_buf,
+               sizeof(BT_HDR) + p_buf->offset + p_buf->len);
+
+        /* Free original buffer */
+        osi_free(p_buf);
+
+        /* update p to point to new buffer */
+        p = (UINT8 *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset;
 
         /* copy first header byte over nosp */
         *(p + 1) = *p;
@@ -1325,12 +1339,12 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
     else {
         /* if no reassembly in progress drop message */
         if (p_ccb->p_rx_msg == NULL) {
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
             AVDT_TRACE_WARNING("Pkt type=%d out of order\n", pkt_type);
             p_ret = NULL;
         } else {
             /* get size of buffer holding assembled message */
-            buf_len = GKI_get_buf_size(p_ccb->p_rx_msg) - sizeof(BT_HDR);
+            buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR);
 
             /* adjust offset and len of fragment for header byte */
             p_buf->offset += AVDT_LEN_TYPE_CONT;
@@ -1339,9 +1353,10 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
             /* verify length */
             if ((p_ccb->p_rx_msg->offset + p_buf->len) > buf_len) {
                 /* won't fit; free everything */
-                GKI_freebuf(p_ccb->p_rx_msg);
+                AVDT_TRACE_WARNING("%s: Fragmented message too big!", __func__);
+                osi_free(p_ccb->p_rx_msg);
                 p_ccb->p_rx_msg = NULL;
-                GKI_freebuf(p_buf);
+                osi_free(p_buf);
                 p_ret = NULL;
             } else {
                 /* copy contents of p_buf to p_rx_msg */
@@ -1358,7 +1373,7 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
                     p_ccb->p_rx_msg->len += p_buf->len;
                     p_ret = NULL;
                 }
-                GKI_freebuf(p_buf);
+                osi_free(p_buf);
             }
         }
     }
@@ -1387,7 +1402,7 @@ void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, UINT8 sig_id, tAVDT_MSG *p
     UINT8       *p_start;
 
     /* get a buffer */
-    p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID);
+    p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE);
     if (p_buf == NULL) {
         AVDT_TRACE_ERROR("avdt_msg_send_cmd out of buffer!!");
         return;
@@ -1425,7 +1440,7 @@ void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, UINT8 sig_id, tAVDT_MSG *p
     p_ccb->label = (p_ccb->label + 1) % 16;
 
     /* queue message and trigger ccb to send it */
-    GKI_enqueue(&p_ccb->cmd_q, p_buf);
+    fixed_queue_enqueue(p_ccb->cmd_q, p_buf);
     avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
 }
 
@@ -1452,7 +1467,7 @@ void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
     UINT8       *p_start;
 
     /* get a buffer */
-    p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID);
+    p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE);
     if (p_buf == NULL) {
         return;
     }
@@ -1472,7 +1487,7 @@ void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
     AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_RSP, p_params->hdr.label);
 
     /* queue message and trigger ccb to send it */
-    GKI_enqueue(&p_ccb->rsp_q, p_buf);
+    fixed_queue_enqueue(p_ccb->rsp_q, p_buf);
     avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
 }
 
@@ -1499,7 +1514,7 @@ void avdt_msg_send_rej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
     UINT8       *p_start;
 
     /* get a buffer */
-    p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID);
+    p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE);
     if (p_buf == NULL) {
         return;
     }
@@ -1532,7 +1547,7 @@ void avdt_msg_send_rej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
     AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_REJ, p_params->hdr.label);
 
     /* queue message and trigger ccb to send it */
-    GKI_enqueue(&p_ccb->rsp_q, p_buf);
+    fixed_queue_enqueue(p_ccb->rsp_q, p_buf);
     avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
 }
 
@@ -1558,7 +1573,7 @@ void avdt_msg_send_grej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
     UINT8       *p_start;
 
     /* get a buffer */
-    p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID);
+    p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE);
     if (p_buf == NULL) {
         return;
     }
@@ -1576,7 +1591,7 @@ void avdt_msg_send_grej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
     AVDT_TRACE_DEBUG("avdt_msg_send_grej");
 
     /* queue message and trigger ccb to send it */
-    GKI_enqueue(&p_ccb->rsp_q, p_buf);
+    fixed_queue_enqueue(p_ccb->rsp_q, p_buf);
     avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
 }
 
@@ -1756,7 +1771,7 @@ void avdt_msg_ind(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
     }
 
     /* free message buffer */
-    GKI_freebuf(p_buf);
+    osi_free(p_buf);
 
     /* if its a rsp or rej, send event to ccb to free associated
     ** cmd msg buffer and handle cmd queue
index 7f4dc7229ce77a87d4ce0205c34b144be6d6c40d..bbad585281c7185871cd76b66eed56add85fb3d2 100644 (file)
@@ -30,8 +30,9 @@
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
-#include "gki.h"
 #include "btu.h"
+#include "allocator.h"
+#include "fixed_queue.h"
 
 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
 
@@ -602,7 +603,7 @@ tAVDT_SCB *avdt_scb_alloc(tAVDT_CS *p_cs)
             memcpy(&p_scb->cs, p_cs, sizeof(tAVDT_CS));
 #if AVDT_MULTIPLEXING == TRUE
             /* initialize fragments gueue */
-            GKI_init_q(&p_scb->frag_q);
+            p_scb->frag_q = fixed_queue_new(SIZE_MAX);
 
             if (p_cs->cfg.psc_mask & AVDT_PSC_MUX) {
                 p_scb->cs.cfg.mux_tcid_media = avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb);
@@ -640,9 +641,6 @@ tAVDT_SCB *avdt_scb_alloc(tAVDT_CS *p_cs)
 *******************************************************************************/
 void avdt_scb_dealloc(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
-#if AVDT_MULTIPLEXING == TRUE
-    void *p_buf;
-#endif
     UNUSED(p_data);
 
     AVDT_TRACE_DEBUG("avdt_scb_dealloc hdl=%d\n", avdt_scb_to_hdl(p_scb));
@@ -650,9 +648,7 @@ void avdt_scb_dealloc(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 
 #if AVDT_MULTIPLEXING == TRUE
     /* free fragments we're holding, if any; it shouldn't happen */
-    while ((p_buf = GKI_dequeue (&p_scb->frag_q)) != NULL) {
-        GKI_freebuf(p_buf);
-    }
+    fixed_queue_free(p_scb->frag_q, osi_free_func);
 #endif
 
     memset(p_scb, 0, sizeof(tAVDT_SCB));
index d645f32d1490648f358ccf7c668ffb1a386ed275..d7699c2e61d6d41e89b4609191504bf8d19cb15b 100644 (file)
@@ -30,8 +30,8 @@
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
-#include "gki.h"
 #include "btu.h"
+#include "allocator.h"
 
 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
 
@@ -286,7 +286,8 @@ void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
     /* do sanity check */
     if ((offset > p_data->p_pkt->len) || ((pad_len + offset) > p_data->p_pkt->len)) {
         AVDT_TRACE_WARNING("Got bad media packet");
-        GKI_freebuf(p_data->p_pkt);
+        osi_free(p_data->p_pkt);
+        p_data->p_pkt = NULL;
     }
     /* adjust offset and length and send it up */
     else {
@@ -310,7 +311,8 @@ void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
                                            p_scb->media_buf_len, time_stamp, seq, m_pt, marker);
             }
 #endif
-            GKI_freebuf(p_data->p_pkt);
+            osi_free(p_data->p_pkt);
+            p_data->p_pkt = NULL;
         }
     }
 }
@@ -599,7 +601,8 @@ void avdt_scb_hdl_pkt_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
     if (p < p_end) {
         AVDT_TRACE_WARNING("*** Got bad media packet");
     }
-    GKI_freebuf(p_data->p_pkt);
+    osi_free(p_data->p_pkt);
+    p_data->p_pkt = NULL;
 }
 #endif
 
@@ -628,7 +631,8 @@ void avdt_scb_hdl_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
         if (p_data->p_pkt->layer_specific == AVDT_CHAN_REPORT) {
             p = (UINT8 *)(p_data->p_pkt + 1) + p_data->p_pkt->offset;
             avdt_scb_hdl_report(p_scb, p, p_data->p_pkt->len);
-            GKI_freebuf(p_data->p_pkt);
+        osi_free(p_data->p_pkt);
+        p_data->p_pkt = NULL;
         } else
 #endif
             avdt_scb_hdl_pkt_no_frag(p_scb, p_data);
@@ -648,8 +652,9 @@ void avdt_scb_drop_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
     UNUSED(p_scb);
 
-    GKI_freebuf(p_data->p_pkt);
-    AVDT_TRACE_ERROR(" avdt_scb_drop_pkt Dropped incoming media packet");
+    AVDT_TRACE_ERROR("%s dropped incoming media packet", __func__);
+    osi_free(p_data->p_pkt);
+    p_data->p_pkt = NULL;
 }
 
 /*******************************************************************************
@@ -969,7 +974,7 @@ void avdt_scb_hdl_tc_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 
     /* free pkt we're holding, if any */
     if (p_scb->p_pkt != NULL) {
-        GKI_freebuf(p_scb->p_pkt);
+        osi_free(p_scb->p_pkt);
         p_scb->p_pkt = NULL;
     }
 
@@ -1171,7 +1176,8 @@ void avdt_scb_hdl_write_req_no_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 
     /* free packet we're holding, if any; to be replaced with new */
     if (p_scb->p_pkt != NULL) {
-        GKI_freebuf(p_scb->p_pkt);
+        osi_free(p_scb->p_pkt);
+        p_scb->p_pkt = NULL;
 
         /* this shouldn't be happening */
         AVDT_TRACE_WARNING("Dropped media packet; congested");
@@ -1213,16 +1219,15 @@ void avdt_scb_hdl_write_req_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
     UINT8   *p;
     UINT32  ssrc;
-    BT_HDR  *p_frag;
 
     /* free fragments we're holding, if any; it shouldn't happen */
-    if (!GKI_queue_is_empty(&p_scb->frag_q)) {
-        while ((p_frag = (BT_HDR *)GKI_dequeue (&p_scb->frag_q)) != NULL) {
-            GKI_freebuf(p_frag);
-        }
-
+    if (!fixed_queue_is_empty(p_scb->frag_q))
+    {
         /* this shouldn't be happening */
         AVDT_TRACE_WARNING("*** Dropped media packet; congested");
+        BT_HDR *p_frag;
+        while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL)
+             osi_free(p_frag);
     }
 
     /* build a media fragments */
@@ -1231,42 +1236,54 @@ void avdt_scb_hdl_write_req_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 
     ssrc = avdt_scb_gen_ssrc(p_scb);
 
-    /* get first packet */
-    p_frag = (BT_HDR *)GKI_getfirst (&p_data->apiwrite.frag_q);
-    /* posit on Adaptation Layer header */
-    p_frag->len += AVDT_AL_HDR_SIZE + AVDT_MEDIA_HDR_SIZE;
-    p_frag->offset -= AVDT_AL_HDR_SIZE + AVDT_MEDIA_HDR_SIZE;
-    p = (UINT8 *)(p_frag + 1) + p_frag->offset;
-
-    /* Adaptation Layer header */
-    /* TSID, no-fragment bit and coding of length(in 2 length octets following) */
-    *p++ = (p_scb->curr_cfg.mux_tsid_media << 3) | AVDT_ALH_LCODE_16BIT;
-
-    /* length of all remaining transport packet */
-    UINT16_TO_BE_STREAM(p, p_frag->layer_specific + AVDT_MEDIA_HDR_SIZE );
-    /* media header */
-    UINT8_TO_BE_STREAM(p, AVDT_MEDIA_OCTET1);
-    UINT8_TO_BE_STREAM(p, p_data->apiwrite.m_pt);
-    UINT16_TO_BE_STREAM(p, p_scb->media_seq);
-    UINT32_TO_BE_STREAM(p, p_data->apiwrite.time_stamp);
-    UINT32_TO_BE_STREAM(p, ssrc);
-    p_scb->media_seq++;
-
-    while ((p_frag = (BT_HDR *)GKI_getnext (p_frag)) != NULL) {
-        /* posit on Adaptation Layer header */
-        p_frag->len += AVDT_AL_HDR_SIZE;
-        p_frag->offset -= AVDT_AL_HDR_SIZE;
-        p = (UINT8 *)(p_frag + 1) + p_frag->offset;
-        /* Adaptation Layer header */
-        /* TSID, fragment bit and coding of length(in 2 length octets following) */
-        *p++ = (p_scb->curr_cfg.mux_tsid_media << 3) | (AVDT_ALH_FRAG_MASK | AVDT_ALH_LCODE_16BIT);
-
-        /* length of all remaining transport packet */
-        UINT16_TO_BE_STREAM(p, p_frag->layer_specific );
-    }
+    if (! fixed_queue_is_empty(p_scb->frag_q)) {
+        list_t *list = fixed_queue_get_list(p_scb->frag_q);
+        const list_node_t *node = list_begin(list);
+        if (node != list_end(list)) {
+            BT_HDR *p_frag = (BT_HDR *)list_node(node);
+            node = list_next(node);
+
+            /* get first packet */
+            /* posit on Adaptation Layer header */
+            p_frag->len += AVDT_AL_HDR_SIZE + AVDT_MEDIA_HDR_SIZE;
+            p_frag->offset -= AVDT_AL_HDR_SIZE + AVDT_MEDIA_HDR_SIZE;
+            p = (UINT8 *)(p_frag + 1) + p_frag->offset;
 
-    /* store it */
-    p_scb->frag_q = p_data->apiwrite.frag_q;
+            /* Adaptation Layer header */
+            /* TSID, no-fragment bit and coding of length (in 2 length octets
+             * following)
+             */
+            *p++ = (p_scb->curr_cfg.mux_tsid_media<<3) | AVDT_ALH_LCODE_16BIT;
+
+            /* length of all remaining transport packet */
+            UINT16_TO_BE_STREAM(p, p_frag->layer_specific + AVDT_MEDIA_HDR_SIZE );
+            /* media header */
+            UINT8_TO_BE_STREAM(p, AVDT_MEDIA_OCTET1);
+            UINT8_TO_BE_STREAM(p, p_data->apiwrite.m_pt);
+            UINT16_TO_BE_STREAM(p, p_scb->media_seq);
+            UINT32_TO_BE_STREAM(p, p_data->apiwrite.time_stamp);
+            UINT32_TO_BE_STREAM(p, ssrc);
+            p_scb->media_seq++;
+        }
+
+        for ( ; node != list_end(list); node = list_next(node)) {
+            BT_HDR *p_frag = (BT_HDR *)list_node(node);
+
+            /* posit on Adaptation Layer header */
+            p_frag->len += AVDT_AL_HDR_SIZE;
+            p_frag->offset -= AVDT_AL_HDR_SIZE;
+            p = (UINT8 *)(p_frag + 1) + p_frag->offset;
+            /* Adaptation Layer header */
+            /* TSID, fragment bit and coding of length (in 2 length octets
+             * following)
+             */
+            *p++ = (p_scb->curr_cfg.mux_tsid_media << 3) |
+                (AVDT_ALH_FRAG_MASK | AVDT_ALH_LCODE_16BIT);
+
+            /* length of all remaining transport packet */
+            UINT16_TO_BE_STREAM(p, p_frag->layer_specific);
+        }
+    }
 }
 #endif
 
@@ -1284,7 +1301,7 @@ void avdt_scb_hdl_write_req_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 void avdt_scb_hdl_write_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
 #if AVDT_MULTIPLEXING == TRUE
-    if (GKI_queue_is_empty(&p_data->apiwrite.frag_q))
+    if (fixed_queue_is_empty(p_scb->frag_q))
 #endif
         avdt_scb_hdl_write_req_no_frag(p_scb, p_data);
 #if AVDT_MULTIPLEXING == TRUE
@@ -1367,28 +1384,21 @@ void avdt_scb_snd_close_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 void avdt_scb_snd_stream_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
 #if AVDT_MULTIPLEXING == TRUE
-    BT_HDR          *p_frag;
+    AVDT_TRACE_WARNING("%s c:%d, off:%d", __func__,
+        fixed_queue_length(p_scb->frag_q), p_scb->frag_off);
 
-    AVDT_TRACE_WARNING("avdt_scb_snd_stream_close c:%d, off:%d\n",
-                       GKI_queue_length(&p_scb->frag_q), p_scb->frag_off);
     /* clean fragments queue */
-    while ((p_frag = (BT_HDR *)GKI_dequeue (&p_scb->frag_q)) != NULL) {
-        GKI_freebuf(p_frag);
+    BT_HDR *p_frag;
+    while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) {
+        osi_free(p_frag);
     }
     p_scb->frag_off = 0;
 #endif
     if (p_scb->p_pkt) {
-        GKI_freebuf(p_scb->p_pkt);
+        osi_free(p_scb->p_pkt);
         p_scb->p_pkt = NULL;
     }
 
-#if 0
-    if (p_scb->cong) {
-        p_scb->cong = FALSE;
-    }
-
-    /* p_scb->curr_cfg.mux_tsid_media == 0 */
-#endif
     avdt_scb_snd_close_req(p_scb, p_data);
 }
 
@@ -1792,9 +1802,6 @@ void avdt_scb_set_remove(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 void avdt_scb_free_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
     tAVDT_CTRL      avdt_ctrl;
-#if AVDT_MULTIPLEXING == TRUE
-    BT_HDR          *p_frag;
-#endif
 
     /* set error code and parameter */
     avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE;
@@ -1802,14 +1809,16 @@ void avdt_scb_free_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 
     /* p_buf can be NULL in case using of fragments queue frag_q */
     if (p_data->apiwrite.p_buf) {
-        GKI_freebuf(p_data->apiwrite.p_buf);
+        osi_free(p_data->apiwrite.p_buf);
+        p_data->apiwrite.p_buf = NULL;
     }
 
 #if AVDT_MULTIPLEXING == TRUE
     /* clean fragments queue */
-    while ((p_frag = (BT_HDR *)GKI_dequeue (&p_data->apiwrite.frag_q)) != NULL) {
-        GKI_freebuf(p_frag);
-    }
+    BT_HDR          *p_frag;
+    while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) {
+         osi_free(p_frag);
+       }
 #endif
 
     AVDT_TRACE_WARNING("Dropped media packet");
@@ -1834,9 +1843,6 @@ void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
     tAVDT_CCB       *p_ccb;
     UINT8           tcid;
     UINT16          lcid;
-#if AVDT_MULTIPLEXING == TRUE
-    BT_HDR          *p_frag;
-#endif
     UNUSED(p_data);
 
     /* set error code and parameter */
@@ -1852,7 +1858,7 @@ void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
     }
 
     if (p_scb->p_pkt != NULL) {
-        GKI_freebuf(p_scb->p_pkt);
+        osi_free(p_scb->p_pkt);
         p_scb->p_pkt = NULL;
 
         AVDT_TRACE_DEBUG("Dropped stored media packet");
@@ -1862,13 +1868,13 @@ void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
                                   &avdt_ctrl);
     }
 #if AVDT_MULTIPLEXING == TRUE
-    else if (!GKI_queue_is_empty (&p_scb->frag_q)) {
+    else if (!fixed_queue_is_empty(p_scb->frag_q)) {
         AVDT_TRACE_DEBUG("Dropped fragments queue");
         /* clean fragments queue */
-        while ((p_frag = (BT_HDR *)GKI_dequeue (&p_scb->frag_q)) != NULL) {
-            GKI_freebuf(p_frag);
-        }
-
+        BT_HDR *p_frag;
+        while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) {
+             osi_free(p_frag);
+               }
         p_scb->frag_off = 0;
 
         /* we need to call callback to keep data flow going */
@@ -1919,7 +1925,7 @@ void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
                              L2CA_FlushChannel(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_scb->p_ccb)][avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb)].lcid),
                              L2CAP_FLUSH_CHANS_GET);
 #endif
-            while ((p_pkt = (BT_HDR *)GKI_dequeue (&p_scb->frag_q)) != NULL) {
+            while ((p_pkt = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) {
                 sent = TRUE;
                 AVDT_TRACE_DEBUG("Send fragment len=%d\n", p_pkt->len);
                 /* fragments queue contains fragment to send */
@@ -1933,10 +1939,10 @@ void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
             AVDT_TRACE_DEBUG("res=%d left=%d\n", res, p_scb->frag_off);
 
             if (p_scb->frag_off) {
-                if (AVDT_AD_SUCCESS == res || GKI_queue_is_empty (&p_scb->frag_q)) {
+                if (AVDT_AD_SUCCESS == res || fixed_queue_is_empty(p_scb->frag_q)) {
                     /* all buffers were sent to L2CAP, compose more to queue */
-                    avdt_scb_queue_frags(p_scb, &p_scb->p_next_frag, &p_scb->frag_off, &p_scb->frag_q);
-                    if (!GKI_queue_is_empty (&p_scb->frag_q)) {
+                    avdt_scb_queue_frags(p_scb, &p_scb->p_next_frag, &p_scb->frag_off, p_scb->frag_q);
+                    if (!fixed_queue_is_empty(p_scb->frag_q)) {
                         data.llcong = p_scb->cong;
                         avdt_scb_event(p_scb, AVDT_SCB_TC_CONG_EVT, &data);
                     }
@@ -1944,7 +1950,7 @@ void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
             }
 
             /* Send event AVDT_WRITE_CFM_EVT if it was last fragment */
-            else if (sent && GKI_queue_is_empty (&p_scb->frag_q)) {
+            else if (sent && fixed_queue_is_empty(p_scb->frag_q)) {
                 (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, AVDT_WRITE_CFM_EVT, &avdt_ctrl);
             }
         }
@@ -2003,7 +2009,7 @@ void avdt_scb_clr_vars(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 ** Returns          Nothing.
 **
 *******************************************************************************/
-void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data, UINT32 *p_data_len, BUFFER_Q *pq)
+void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data, UINT32 *p_data_len, fixed_queue_t *pq)
 {
     UINT16  lcid;
     UINT16  num_frag;
@@ -2043,15 +2049,15 @@ void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data, UINT32 *p_data_len,
     AVDT_TRACE_DEBUG("peer_mtu: %d, buf_size: %d num_frag=%d\n",
                      p_tbl->peer_mtu, buf_size, num_frag);
 
-    if (buf_size > AVDT_DATA_POOL_SIZE) {
-        buf_size = AVDT_DATA_POOL_SIZE;
+    if (buf_size > AVDT_DATA_BUF_SIZE) {
+        buf_size = AVDT_DATA_BUF_SIZE;
     }
 
     mtu_used = buf_size - BT_HDR_SIZE;
 
     while (*p_data_len && num_frag) {
         /* allocate buffer for fragment */
-        if (NULL == (p_frag = (BT_HDR *)GKI_getbuf(buf_size))) {
+        if (NULL == (p_frag = (BT_HDR *)osi_malloc(buf_size))) {
             AVDT_TRACE_WARNING("avdt_scb_queue_frags len=%d(out of GKI buffers)\n", *p_data_len);
             break;
         }
@@ -2082,7 +2088,7 @@ void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data, UINT32 *p_data_len,
             UINT16_TO_BE_STREAM(p, p_frag->layer_specific );
         }
         /* put fragment into gueue */
-        GKI_enqueue(pq, p_frag);
+        fixed_queue_enqueue(p_scb->frag_q, p_frag);
         num_frag--;
     }
 }
index 5050f0668f31401a1f02991b1d8dac04e285c81a..6555152ac09b9778d314b52e4ccd9f35d330e380 100644 (file)
 #ifndef AVDT_INT_H
 #define AVDT_INT_H
 
-#include "gki.h"
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_defs.h"
 #include "l2c_api.h"
 #include "btm_api.h"
+#include "fixed_queue.h"
 
 #if (AVRC_INCLUDED == TRUE)
 
@@ -425,8 +425,8 @@ typedef union {
 typedef struct {
     BD_ADDR             peer_addr;      /* BD address of peer */
     TIMER_LIST_ENT      timer_entry;    /* CCB timer list entry */
-    BUFFER_Q            cmd_q;          /* Queue for outgoing command messages */
-    BUFFER_Q            rsp_q;          /* Queue for outgoing response and reject messages */
+    fixed_queue_t       *cmd_q;          /* Queue for outgoing command messages */
+    fixed_queue_t       *rsp_q;          /* Queue for outgoing response and reject messages */
     tAVDT_CTRL_CBACK    *proc_cback;    /* Procedure callback function */
     tAVDT_CTRL_CBACK    *p_conn_cback;  /* Connection/disconnection callback function */
     void                *p_proc_data;   /* Pointer to data storage for procedure */
@@ -453,7 +453,7 @@ typedef struct {
     BT_HDR      *p_buf;
     UINT32      time_stamp;
 #if AVDT_MULTIPLEXING == TRUE
-    BUFFER_Q    frag_q;          /* Queue for outgoing media fragments. p_buf should be 0 */
+    fixed_queue_t    *frag_q;          /* Queue for outgoing media fragments. p_buf should be 0 */
     UINT8       *p_data;
     UINT32      data_len;
 #endif
@@ -500,7 +500,7 @@ typedef struct {
     BOOLEAN         cong;           /* Whether media transport channel is congested */
     UINT8           close_code;     /* Error code received in close response */
 #if AVDT_MULTIPLEXING == TRUE
-    BUFFER_Q        frag_q;         /* Queue for outgoing media fragments */
+    fixed_queue_t        *frag_q;         /* Queue for outgoing media fragments */
     UINT32          frag_off;       /* length of already received media fragments */
     UINT32          frag_org_len;   /* original length before fragmentation of receiving media packet */
     UINT8           *p_next_frag;   /* next fragment to send */
@@ -673,7 +673,7 @@ extern void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
 extern void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
 extern void avdt_scb_tc_timer(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
 extern void avdt_scb_clr_vars(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
-extern void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data, UINT32 *p_data_len, BUFFER_Q *pq);
+extern void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data, UINT32 *p_data_len, fixed_queue_t *pq);
 
 /* msg function declarations */
 extern BOOLEAN avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg);
index d619c693886b5b69c84e1491cce26a5d372ab52c..d9d614a0e26125cd72a821b6c79e0f387e6e2218 100644 (file)
@@ -25,9 +25,9 @@
 #include "bt_trace.h"
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "avrc_api.h"
 #include "avrc_int.h"
+#include "allocator.h"
 
 #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
 
@@ -120,7 +120,7 @@ static BT_HDR *avrc_copy_packet(BT_HDR *p_pkt, int rsp_pkt_len)
     const int offset = MAX(AVCT_MSG_OFFSET, p_pkt->offset);
     const int pkt_len = MAX(rsp_pkt_len, p_pkt->len);
     BT_HDR *p_pkt_copy =
-        (BT_HDR *)GKI_getbuf((UINT16)(BT_HDR_SIZE + offset + pkt_len));
+        (BT_HDR *)osi_malloc((UINT16)(BT_HDR_SIZE + offset + pkt_len));
 
     /* Copy the packet header, set the new offset, and copy the payload */
     if (p_pkt_copy != NULL) {
@@ -200,7 +200,7 @@ static void avrc_send_continue_frag(UINT8 handle, UINT8 label)
     if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) {
         int offset_len = MAX(AVCT_MSG_OFFSET, p_pkt->offset);
         p_pkt_old = p_fcb->p_fmsg;
-        p_pkt = (BT_HDR *)GKI_getbuf((UINT16)(AVRC_PACKET_LEN + offset_len + BT_HDR_SIZE));
+        p_pkt = (BT_HDR *)osi_malloc((UINT16)(AVRC_PACKET_LEN + offset_len + BT_HDR_SIZE));
         if (p_pkt) {
             p_pkt->len          = AVRC_MAX_CTRL_DATA_LEN;
             p_pkt->offset       = AVCT_MSG_OFFSET;
@@ -319,9 +319,9 @@ static BT_HDR *avrc_proc_vendor_command(UINT8 handle, UINT8 label,
 
         if (abort_frag) {
             if (p_fcb->p_fmsg) {
-                GKI_freebuf(p_fcb->p_fmsg);
+                osi_free(p_fcb->p_fmsg);
+                p_fcb->p_fmsg = NULL;
             }
-            p_fcb->p_fmsg = NULL;
             p_fcb->frag_enabled = FALSE;
         }
     }
@@ -362,7 +362,6 @@ static UINT8 avrc_proc_far_msg(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR **pp_
     BOOLEAN     req_continue = FALSE;
     BT_HDR      *p_pkt_new = NULL;
     UINT8       pkt_type;
-    UINT16      buf_len;
     tAVRC_RASM_CB   *p_rcb;
     tAVRC_NEXT_CMD   avrc_cmd;
 
@@ -380,7 +379,7 @@ static UINT8 avrc_proc_far_msg(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR **pp_
             /* previous fragments need to be dropped, when received another new message */
             p_rcb->rasm_offset = 0;
             if (p_rcb->p_rmsg) {
-                GKI_freebuf(p_rcb->p_rmsg);
+                osi_free(p_rcb->p_rmsg);
                 p_rcb->p_rmsg = NULL;
             }
         }
@@ -390,7 +389,7 @@ static UINT8 avrc_proc_far_msg(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR **pp_
             if (pkt_type == AVRC_PKT_START) {
                 /* Allocate buffer for re-assembly */
                 p_rcb->rasm_pdu = *p_data;
-                if ((p_rcb->p_rmsg = (BT_HDR *)GKI_getbuf(GKI_MAX_BUF_SIZE)) != NULL) {
+                if ((p_rcb->p_rmsg = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE)) != NULL) {
                     /* Copy START packet to buffer for re-assembling fragments*/
                     memcpy(p_rcb->p_rmsg, p_pkt, sizeof(BT_HDR));   /* Copy bt hdr */
 
@@ -402,7 +401,7 @@ static UINT8 avrc_proc_far_msg(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR **pp_
                     p_rcb->p_rmsg->offset = p_rcb->rasm_offset = 0;
 
                     /* Free original START packet, replace with pointer to reassembly buffer  */
-                    GKI_freebuf(p_pkt);
+                    osi_free(p_pkt);
                     *pp_pkt = p_rcb->p_rmsg;
                 } else {
                     /* Unable to allocate buffer for fragmented avrc message. Reuse START
@@ -422,11 +421,15 @@ static UINT8 avrc_proc_far_msg(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR **pp_
                 AVRC_TRACE_DEBUG ("Received a CONTINUE/END without no corresponding START \
                                    (or previous fragmented response was dropped)");
                 drop_code = 5;
-                GKI_freebuf(p_pkt);
+                osi_free(p_pkt);
                 *pp_pkt = NULL;
             } else {
                 /* get size of buffer holding assembled message */
-                buf_len = GKI_get_buf_size (p_rcb->p_rmsg) - sizeof(BT_HDR);
+                /*
+                 * NOTE: The buffer is allocated above at the beginning of the
+                 * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE.
+                 */
+                UINT16 buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR);
                 /* adjust offset and len of fragment for header byte */
                 p_pkt->offset += (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE);
                 p_pkt->len -= (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE);
@@ -463,7 +466,7 @@ static UINT8 avrc_proc_far_msg(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR **pp_
                     p_pkt_new = NULL;
                     req_continue = TRUE;
                 }
-                GKI_freebuf(p_pkt);
+                osi_free(p_pkt);
                 *pp_pkt = p_pkt_new;
             }
         }
@@ -528,14 +531,14 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr,
 #if (BT_USE_TRACES == TRUE)
         p_drop_msg = "dropped - too long AV/C cmd frame size";
 #endif
-        GKI_freebuf(p_pkt);
+        osi_free(p_pkt);
         return;
     }
 
     if (cr == AVCT_REJ) {
         /* The peer thinks that this PID is no longer open - remove this handle */
         /*  */
-        GKI_freebuf(p_pkt);
+        osi_free(p_pkt);
         AVCT_RemoveConn(handle);
         return;
     }
@@ -751,7 +754,7 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr,
 
 
     if (do_free) {
-        GKI_freebuf(p_pkt);
+        osi_free(p_pkt);
     }
 }
 
@@ -780,9 +783,9 @@ static BT_HDR   *avrc_pass_msg(tAVRC_MSG_PASS *p_msg)
     UINT8   *p_data;
 
     assert(p_msg != NULL);
-    assert(AVRC_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN + p_msg->pass_len));
+    assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN+p_msg->pass_len));
 
-    if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) {
+    if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL) {
         p_cmd->offset   = AVCT_MSG_OFFSET;
         p_cmd->layer_specific   = AVCT_DATA_CTRL;
         p_data          = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
@@ -974,7 +977,7 @@ UINT16 AVRC_MsgReq (UINT8 handle, UINT8 label, UINT8 ctype, BT_HDR *p_pkt)
     }
 
     if (p_fcb->p_fmsg) {
-        GKI_freebuf(p_fcb->p_fmsg);
+        osi_free(p_fcb->p_fmsg);
         p_fcb->p_fmsg = NULL;
     }
 
@@ -983,7 +986,7 @@ UINT16 AVRC_MsgReq (UINT8 handle, UINT8 label, UINT8 ctype, BT_HDR *p_pkt)
     if ((cr == AVCT_RSP) && (chk_frag == TRUE)) {
         if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) {
             int offset_len = MAX(AVCT_MSG_OFFSET, p_pkt->offset);
-            p_pkt_new = (BT_HDR *)GKI_getbuf((UINT16)(AVRC_PACKET_LEN + offset_len
+            p_pkt_new = (BT_HDR *)osi_malloc((UINT16)(AVRC_PACKET_LEN + offset_len
                                              + BT_HDR_SIZE));
             if (p_pkt_new && (p_start != NULL)) {
                 p_fcb->frag_enabled = TRUE;
@@ -1012,7 +1015,7 @@ UINT16 AVRC_MsgReq (UINT8 handle, UINT8 label, UINT8 ctype, BT_HDR *p_pkt)
                                   p_pkt->len, len, p_fcb->p_fmsg->len );
             } else {
                 AVRC_TRACE_ERROR ("AVRC_MsgReq no buffers for fragmentation" );
-                GKI_freebuf(p_pkt);
+                osi_free(p_pkt);
                 return AVRC_NO_RESOURCES;
             }
         }
index 692a3ee52a2bef150d5a69979df7e534f159f43e..41ca87bf857ed57e3de6a20eb8f293f715df37c8 100644 (file)
  ******************************************************************************/
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "avrc_api.h"
 #include "avrc_defs.h"
 #include "avrc_int.h"
+#include "allocator.h"
 
 #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
 
@@ -128,14 +128,12 @@ static tAVRC_STS avrc_bld_vol_change_notfn(BT_HDR *p_pkt)
 *******************************************************************************/
 static BT_HDR *avrc_bld_init_cmd_buffer(tAVRC_COMMAND *p_cmd)
 {
-    UINT16 offset = 0, chnl = AVCT_DATA_CTRL, len = AVRC_META_CMD_POOL_SIZE;
-    BT_HDR *p_pkt = NULL;
-    UINT8  opcode;
-
-    opcode = avrc_opcode_from_pdu(p_cmd->pdu);
+    UINT8  opcode = avrc_opcode_from_pdu(p_cmd->pdu);
     AVRC_TRACE_API("avrc_bld_init_cmd_buffer: pdu=%x, opcode=%x", p_cmd->pdu, opcode);
 
-    switch (opcode) {
+    UINT16 offset = 0;
+    switch (opcode)
+    {
     case AVRC_OP_PASS_THRU:
         offset  = AVRC_MSG_PASS_THRU_OFFSET;
         break;
@@ -146,11 +144,11 @@ static BT_HDR *avrc_bld_init_cmd_buffer(tAVRC_COMMAND *p_cmd)
     }
 
     /* allocate and initialize the buffer */
-    p_pkt = (BT_HDR *)GKI_getbuf(len);
+    BT_HDR *p_pkt = (BT_HDR *)osi_malloc(AVRC_META_CMD_BUF_SIZE);
     if (p_pkt) {
         UINT8 *p_data, *p_start;
 
-        p_pkt->layer_specific = chnl;
+    p_pkt->layer_specific = AVCT_DATA_CTRL;
         p_pkt->event    = opcode;
         p_pkt->offset   = offset;
         p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
@@ -236,7 +234,7 @@ tAVRC_STS AVRC_BldCommand( tAVRC_COMMAND *p_cmd, BT_HDR **pp_pkt)
     }
 
     if (alloc && (status != AVRC_STS_NO_ERROR) ) {
-        GKI_freebuf(p_pkt);
+        osi_free(p_pkt);
         *pp_pkt = NULL;
     }
     AVRC_TRACE_API("AVRC_BldCommand: returning %d", status);
index 0ff8692d911019b7cb205eac27a079b4c2b63933..19ac85c58485a7f7dacc9d4d2e26bea7fcd067d2 100644 (file)
  ******************************************************************************/
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "avrc_api.h"
 #include "avrc_defs.h"
 #include "avrc_int.h"
 #include "bt_utils.h"
+#include "allocator.h"
 
 #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
 
@@ -288,7 +288,12 @@ static tAVRC_STS avrc_bld_app_setting_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rs
     /* get the existing length, if any, and also the num attributes */
     p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
     p_data = p_len = p_start + 2; /* pdu + rsvd */
-    len_left = GKI_get_buf_size(p_pkt) - BT_HDR_SIZE - p_pkt->offset - p_pkt->len;
+
+    /*
+     * NOTE: The buffer is allocated within avrc_bld_init_rsp_buffer(), and is
+     * always of size BT_DEFAULT_BUFFER_SIZE.
+     */
+    len_left = BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE - p_pkt->offset - p_pkt->len;
 
     BE_STREAM_TO_UINT16(len, p_data);
     p_count = p_data;
@@ -686,8 +691,8 @@ static tAVRC_STS avrc_bld_rejected_rsp( tAVRC_RSP *p_rsp, BT_HDR *p_pkt )
 *******************************************************************************/
 static BT_HDR *avrc_bld_init_rsp_buffer(tAVRC_RESPONSE *p_rsp)
 {
-    UINT16 offset = AVRC_MSG_PASS_THRU_OFFSET, chnl = AVCT_DATA_CTRL, len = AVRC_META_CMD_POOL_SIZE;
-    BT_HDR *p_pkt = NULL;
+    UINT16 offset = AVRC_MSG_PASS_THRU_OFFSET;
+    UINT16 chnl = AVCT_DATA_CTRL;
     UINT8  opcode = avrc_opcode_from_pdu(p_rsp->pdu);
 
     AVRC_TRACE_API("avrc_bld_init_rsp_buffer: pdu=%x, opcode=%x/%x", p_rsp->pdu, opcode,
@@ -705,14 +710,11 @@ static BT_HDR *avrc_bld_init_rsp_buffer(tAVRC_RESPONSE *p_rsp)
 
     case AVRC_OP_VENDOR:
         offset  = AVRC_MSG_VENDOR_OFFSET;
-        if (p_rsp->pdu == AVRC_PDU_GET_ELEMENT_ATTR) {
-            len     = AVRC_BROWSE_POOL_SIZE;
-        }
         break;
     }
 
     /* allocate and initialize the buffer */
-    p_pkt = (BT_HDR *)GKI_getbuf(len);
+    BT_HDR *p_pkt = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE);
     if (p_pkt) {
         UINT8 *p_data, *p_start;
 
@@ -846,7 +848,7 @@ tAVRC_STS AVRC_BldResponse( UINT8 handle, tAVRC_RESPONSE *p_rsp, BT_HDR **pp_pkt
     }
 
     if (alloc && (status != AVRC_STS_NO_ERROR) ) {
-        GKI_freebuf(p_pkt);
+        osi_free(p_pkt);
         *pp_pkt = NULL;
     }
     AVRC_TRACE_API("AVRC_BldResponse: returning %d", status);
index 0c231c0b73652ea6d1416cc8134e1019ae541b88..7caaf375fd68c58d7a4a2f0cb22c9f7cb10467e2 100644 (file)
@@ -24,9 +24,9 @@
 // #include <assert.h>
 #include "bt_target.h"
 #include <string.h>
-#include "gki.h"
 #include "avrc_api.h"
 #include "avrc_int.h"
+#include "allocator.h"
 
 #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
 
@@ -54,11 +54,11 @@ static BT_HDR   *avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg)
     assert(p_msg != NULL);
 
 #if AVRC_METADATA_INCLUDED == TRUE
-    assert(AVRC_META_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
-    if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_META_CMD_POOL_ID)) != NULL)
+    assert(AVRC_META_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
+    if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_META_CMD_BUF_SIZE)) != NULL)
 #else
-    assert(AVRC_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
-    if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL)
+    assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
+    if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL)
 #endif
     {
         p_cmd->offset   = AVCT_MSG_OFFSET;
@@ -102,7 +102,7 @@ UINT16 AVRC_UnitCmd(UINT8 handle, UINT8 label)
     BT_HDR  *p_cmd;
     UINT8   *p_data;
 
-    if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) {
+    if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL) {
         p_cmd->offset   = AVCT_MSG_OFFSET;
         p_data          = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
         *p_data++       = AVRC_CMD_STATUS;
@@ -146,7 +146,7 @@ UINT16 AVRC_SubCmd(UINT8 handle, UINT8 label, UINT8 page)
     BT_HDR  *p_cmd;
     UINT8   *p_data;
 
-    if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) {
+    if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL) {
         p_cmd->offset   = AVCT_MSG_OFFSET;
         p_data          = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
         *p_data++       = AVRC_CMD_STATUS;
index d65935de76a27bc44989d84b03d9445b3a03a60c..02b1eac8842af5709471b3e55aad499de5f254b6 100644 (file)
@@ -17,7 +17,6 @@
  ******************************************************************************/
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "avrc_api.h"
 #include "avrc_defs.h"
 #include "avrc_int.h"
index feecad64465c67e88b4fd8dfaffc53d42aca71b0..5d5d79737f1eb937facdb6230f3234b2ec51cd72 100644 (file)
@@ -17,7 +17,6 @@
  ******************************************************************************/
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "avrc_api.h"
 #include "avrc_defs.h"
 #include "avrc_int.h"
index 4acc8181b6f18055ec57a329e9d973afc595735a..4904c533d9edebbc693a488949fbb5ae7c4219ee 100644 (file)
@@ -23,7 +23,6 @@
  ******************************************************************************/
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "avrc_api.h"
 #include "avrc_int.h"
 
index 316edae87c37233409276a3c4b382184b82b0209..821f07c19b28b3f8ca3ea08172eda5f0c0f4e35a 100644 (file)
@@ -17,7 +17,6 @@
  ******************************************************************************/
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "avrc_api.h"
 #include "avrc_int.h"
 
index 239d6d6507bdf0b87e78db02e31dfe6fdfe7f46b..2603a9a8d117c855cef90b59c28dcb8aeefe896e 100644 (file)
@@ -39,7 +39,6 @@
 #include "bt_types.h"
 #include "bt_target.h"
 #include "controller.h"
-#include "gki.h"
 #include "hcimsgs.h"
 #include "btu.h"
 #include "btm_api.h"
@@ -2325,7 +2324,7 @@ void btm_acl_resubmit_page (void)
     BD_ADDR bda;
     BTM_TRACE_DEBUG ("btm_acl_resubmit_page\n");
     /* If there were other page request schedule can start the next one */
-    if ((p_buf = (BT_HDR *)GKI_dequeue (&btm_cb.page_queue)) != NULL) {
+    if ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) {
         /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr
          * for both create_conn and rmt_name */
         pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3;
@@ -2356,8 +2355,8 @@ void  btm_acl_reset_paging (void)
     BT_HDR *p;
     BTM_TRACE_DEBUG ("btm_acl_reset_paging\n");
     /* If we sent reset we are definitely not paging any more */
-    while ((p = (BT_HDR *)GKI_dequeue(&btm_cb.page_queue)) != NULL) {
-        GKI_freebuf (p);
+    while ((p = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) {
+        osi_free (p);
     }
 
     btm_cb.paging = FALSE;
@@ -2380,7 +2379,7 @@ void  btm_acl_paging (BT_HDR *p, BD_ADDR bda)
                      (bda[0] << 16) + (bda[1] << 8) + bda[2], (bda[3] << 16) + (bda[4] << 8) + bda[5]);
     if (btm_cb.discing) {
         btm_cb.paging = TRUE;
-        GKI_enqueue (&btm_cb.page_queue, p);
+        fixed_queue_enqueue(btm_cb.page_queue, p);
     } else {
         if (!BTM_ACL_IS_CONNECTED (bda)) {
             BTM_TRACE_DEBUG ("connecting_bda: %06x%06x\n",
@@ -2390,7 +2389,7 @@ void  btm_acl_paging (BT_HDR *p, BD_ADDR bda)
                              btm_cb.connecting_bda[5]);
             if (btm_cb.paging &&
                     memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) {
-                GKI_enqueue (&btm_cb.page_queue, p);
+                fixed_queue_enqueue(btm_cb.page_queue, p);
             } else {
                 p_dev_rec = btm_find_or_alloc_dev (bda);
                 memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr,   BD_ADDR_LEN);
index 8c90b9c3333e8a3b67f83378a2b71b77e59fab11..81f2d50fed5580a76c532c8fdada0e4e7ab6e450 100644 (file)
@@ -1951,7 +1951,7 @@ BOOLEAN BTM_BleDataSignature (BD_ADDR bd_addr, UINT8 *p_text, UINT16 len,
     } else {
         UINT8 *p_mac = (UINT8 *)signature;
         UINT8 *p_buf, *pp;
-        if ((p_buf = (UINT8 *)GKI_getbuf((UINT16)(len + 4))) != NULL) {
+        if ((p_buf = (UINT8 *)osi_malloc((UINT16)(len + 4))) != NULL) {
             BTM_TRACE_DEBUG("%s-Start to generate Local CSRK", __func__);
             pp = p_buf;
             /* prepare plain text */
@@ -1973,7 +1973,7 @@ BOOLEAN BTM_BleDataSignature (BD_ADDR bd_addr, UINT8 *p_text, UINT16 len,
                             *p_mac, *(p_mac + 1), *(p_mac + 2), *(p_mac + 3));
             BTM_TRACE_DEBUG("p_mac[4] = 0x%02x p_mac[5] = 0x%02x p_mac[6] = 0x%02x p_mac[7] = 0x%02x",
                             *(p_mac + 4), *(p_mac + 5), *(p_mac + 6), *(p_mac + 7));
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
         }
     }
     return ret;
index 78b4a8ed2c1879cea714051b42f1ed5f948085fa..3453b15dcef286ff567c2ae0858f930293b9c6c2 100644 (file)
@@ -26,7 +26,7 @@
 #include "hcimsgs.h"
 #include "btu.h"
 #include "btm_int.h"
-//#include "bt_utils.h"
+#include "allocator.h"
 #include "hcidefs.h"
 #include "btm_ble_api.h"
 #include "controller.h"
@@ -1248,7 +1248,7 @@ void btm_ble_adv_filter_init(void)
 
     if (cmn_ble_vsc_cb.max_filter > 0) {
         btm_ble_adv_filt_cb.p_addr_filter_count =
-            (tBTM_BLE_PF_COUNT *) GKI_getbuf( sizeof(tBTM_BLE_PF_COUNT) * cmn_ble_vsc_cb.max_filter);
+            (tBTM_BLE_PF_COUNT *) osi_malloc( sizeof(tBTM_BLE_PF_COUNT) * cmn_ble_vsc_cb.max_filter);
     }
 }
 
@@ -1266,7 +1266,8 @@ void btm_ble_adv_filter_init(void)
 void btm_ble_adv_filter_cleanup(void)
 {
     if (btm_ble_adv_filt_cb.p_addr_filter_count) {
-        GKI_freebuf (btm_ble_adv_filt_cb.p_addr_filter_count);
+        osi_free(btm_ble_adv_filt_cb.p_addr_filter_count);
+        btm_ble_adv_filt_cb.p_addr_filter_count = NULL;
     }
 }
 
index d64373664e1af2bd7ea9e97dfb427dd7960bd952..a758510504f3da597c12184470df01db1784052c 100644 (file)
@@ -96,13 +96,13 @@ void btm_ble_batchscan_filter_track_adv_vse_cback(UINT8 len, UINT8 *p)
 
                 STREAM_TO_UINT8(adv_data.adv_pkt_len, p);
                 if (adv_data.adv_pkt_len > 0) {
-                    adv_data.p_adv_pkt_data = GKI_getbuf(adv_data.adv_pkt_len);
+                    adv_data.p_adv_pkt_data = osi_malloc(adv_data.adv_pkt_len);
                     memcpy(adv_data.p_adv_pkt_data, p, adv_data.adv_pkt_len);
                 }
 
                 STREAM_TO_UINT8(adv_data.scan_rsp_len, p);
                 if (adv_data.scan_rsp_len > 0) {
-                    adv_data.p_scan_rsp_data = GKI_getbuf(adv_data.scan_rsp_len);
+                    adv_data.p_scan_rsp_data = osi_malloc(adv_data.scan_rsp_len);
                     memcpy(adv_data.p_scan_rsp_data, p, adv_data.scan_rsp_len);
                 }
             }
@@ -205,15 +205,15 @@ void btm_ble_batchscan_enq_rep_data(UINT8 report_format, UINT8 num_records, UINT
         len = ble_batchscan_cb.main_rep_q.data_len[index];
         p_orig_data = ble_batchscan_cb.main_rep_q.p_data[index];
         if (NULL != p_orig_data) {
-            p_app_data = GKI_getbuf(len + data_len);
+            p_app_data = osi_malloc(len + data_len);
             memcpy(p_app_data, p_orig_data, len);
             memcpy(p_app_data + len, p_data, data_len);
-            GKI_freebuf(p_orig_data);
+            osi_free(p_orig_data);
             ble_batchscan_cb.main_rep_q.p_data[index] = p_app_data;
             ble_batchscan_cb.main_rep_q.num_records[index] += num_records;
             ble_batchscan_cb.main_rep_q.data_len[index] += data_len;
         } else {
-            p_app_data = GKI_getbuf(data_len);
+            p_app_data = osi_malloc(data_len);
             memcpy(p_app_data, p_data, data_len);
             ble_batchscan_cb.main_rep_q.p_data[index] = p_app_data;
             ble_batchscan_cb.main_rep_q.num_records[index] = num_records;
@@ -918,9 +918,9 @@ void btm_ble_batchscan_cleanup(void)
 
     for (index = 0; index < BTM_BLE_BATCH_REP_MAIN_Q_SIZE; index++) {
         if (NULL != ble_batchscan_cb.main_rep_q.p_data[index]) {
-            GKI_freebuf(ble_batchscan_cb.main_rep_q.p_data[index]);
+            osi_free(ble_batchscan_cb.main_rep_q.p_data[index]);
+            ble_batchscan_cb.main_rep_q.p_data[index] = NULL;
         }
-        ble_batchscan_cb.main_rep_q.p_data[index] = NULL;
     }
 
     memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB));
index e846ef5b9221443cc2c1ef2f510343e868dffa7e..faf5713eff7d64c1a62b8e0d8b75e3e31275a96d 100644 (file)
@@ -64,7 +64,7 @@ static void background_connections_lazy_init()
 {
     if (!background_connections) {
         background_connections = hash_map_new(background_connection_buckets,
-                                              hash_function_bdaddr, NULL, allocator_calloc.free, bdaddr_equality_fn);
+                                      hash_function_bdaddr, NULL, osi_free_func, bdaddr_equality_fn);
         assert(background_connections);
     }
 }
@@ -672,11 +672,11 @@ void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st)
 *******************************************************************************/
 void btm_ble_enqueue_direct_conn_req(void *p_param)
 {
-    tBTM_BLE_CONN_REQ   *p = (tBTM_BLE_CONN_REQ *)GKI_getbuf(sizeof(tBTM_BLE_CONN_REQ));
+    tBTM_BLE_CONN_REQ   *p = (tBTM_BLE_CONN_REQ *)osi_malloc(sizeof(tBTM_BLE_CONN_REQ));
 
     p->p_param = p_param;
 
-    GKI_enqueue (&btm_cb.ble_ctr_cb.conn_pending_q, p);
+    fixed_queue_enqueue(btm_cb.ble_ctr_cb.conn_pending_q, p);
 }
 /*******************************************************************************
 **
@@ -692,12 +692,11 @@ BOOLEAN btm_send_pending_direct_conn(void)
     tBTM_BLE_CONN_REQ *p_req;
     BOOLEAN     rt = FALSE;
 
-    if (!GKI_queue_is_empty(&btm_cb.ble_ctr_cb.conn_pending_q)) {
-        p_req = (tBTM_BLE_CONN_REQ *)GKI_dequeue (&btm_cb.ble_ctr_cb.conn_pending_q);
-
+    p_req = (tBTM_BLE_CONN_REQ*)fixed_queue_try_dequeue(btm_cb.ble_ctr_cb.conn_pending_q);
+    if (p_req != NULL) {
         rt = l2cble_init_direct_conn((tL2C_LCB *)(p_req->p_param));
 
-        GKI_freebuf((void *)p_req);
+        osi_free((void *)p_req);
     }
 
     return rt;
index 1029977cb29413a092aca2f0c9b8a07f719d220b..4edd1a5f0f641f9d2e01c2269b44b4de5701b715 100644 (file)
@@ -663,6 +663,10 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK
     if (!privacy_mode) { /* if privacy disabled, always use public address */
         p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_PUBLIC;
         p_cb->privacy_mode = BTM_PRIVACY_NONE;
+        if (random_cb && random_cb->set_local_privacy_cback){
+            (*random_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_SUCCESS);
+            random_cb->set_local_privacy_cback = NULL;
+        }
     } else { /* privacy is turned on*/
         /* always set host random address, used when privacy 1.1 or priavcy 1.2 is disabled */
         p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM;
@@ -3502,6 +3506,8 @@ void btm_ble_init (void)
     btm_cb.cmn_ble_vsc_cb.values_read = FALSE;
     p_cb->cur_states       = 0;
 
+    p_cb->conn_pending_q = fixed_queue_new(SIZE_MAX);
+
     p_cb->inq_var.adv_mode = BTM_BLE_ADV_DISABLE;
     p_cb->inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE;
     p_cb->inq_var.adv_chnl_map = BTM_BLE_DEFAULT_ADV_CHNL_MAP;
@@ -3520,6 +3526,24 @@ void btm_ble_init (void)
 #endif
 }
 
+/*******************************************************************************
+**
+** Function         btm_ble_free
+**
+** Description      free the control block variable values.
+**
+** Returns          void
+**
+*******************************************************************************/
+void btm_ble_free (void)
+{
+    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
+
+    BTM_TRACE_DEBUG("%s", __func__);
+
+    fixed_queue_free(p_cb->conn_pending_q, osi_free_func);
+}
+
 /*******************************************************************************
 **
 ** Function         btm_ble_topology_check
index cb273ef9d4ccab4fedeb9e4807f29feb9fac0356..4d9e7841eedc902f2ffc6adf297c68576cc2514f 100644 (file)
@@ -771,17 +771,17 @@ void btm_ble_multi_adv_init()
     btm_multi_adv_idx_q.rear = -1;
 
     if (btm_cb.cmn_ble_vsc_cb.adv_inst_max > 0) {
-        btm_multi_adv_cb.p_adv_inst = GKI_getbuf( sizeof(tBTM_BLE_MULTI_ADV_INST) *
+        btm_multi_adv_cb.p_adv_inst = osi_malloc( sizeof(tBTM_BLE_MULTI_ADV_INST) *
                                       (btm_cb.cmn_ble_vsc_cb.adv_inst_max));
         memset(btm_multi_adv_cb.p_adv_inst, 0, sizeof(tBTM_BLE_MULTI_ADV_INST) *
                (btm_cb.cmn_ble_vsc_cb.adv_inst_max));
 
-        btm_multi_adv_cb.op_q.p_sub_code = GKI_getbuf( sizeof(UINT8) *
+        btm_multi_adv_cb.op_q.p_sub_code = osi_malloc( sizeof(UINT8) *
                                            (btm_cb.cmn_ble_vsc_cb.adv_inst_max));
         memset(btm_multi_adv_cb.op_q.p_sub_code, 0,
                sizeof(UINT8) * (btm_cb.cmn_ble_vsc_cb.adv_inst_max));
 
-        btm_multi_adv_cb.op_q.p_inst_id = GKI_getbuf( sizeof(UINT8) *
+        btm_multi_adv_cb.op_q.p_inst_id = osi_malloc( sizeof(UINT8) *
                                           (btm_cb.cmn_ble_vsc_cb.adv_inst_max));
         memset(btm_multi_adv_cb.op_q.p_inst_id, 0,
                sizeof(UINT8) * (btm_cb.cmn_ble_vsc_cb.adv_inst_max));
@@ -809,15 +809,18 @@ void btm_ble_multi_adv_init()
 void btm_ble_multi_adv_cleanup(void)
 {
     if (btm_multi_adv_cb.p_adv_inst) {
-        GKI_freebuf(btm_multi_adv_cb.p_adv_inst);
+        osi_free(btm_multi_adv_cb.p_adv_inst);
+        btm_multi_adv_cb.p_adv_inst = NULL;
     }
 
     if (btm_multi_adv_cb.op_q.p_sub_code) {
-        GKI_freebuf(btm_multi_adv_cb.op_q.p_sub_code);
+        osi_free(btm_multi_adv_cb.op_q.p_sub_code);
+        btm_multi_adv_cb.op_q.p_sub_code = NULL;
     }
 
     if (btm_multi_adv_cb.op_q.p_inst_id) {
-        GKI_freebuf(btm_multi_adv_cb.op_q.p_inst_id);
+        osi_free(btm_multi_adv_cb.op_q.p_inst_id);
+        btm_multi_adv_cb.op_q.p_inst_id = NULL;
     }
 
 }
index 59aa49fbab426adc9f0a8c4b0427382c9879605d..a159855370c8d45120b06df5306080e721c16e92 100644 (file)
@@ -948,12 +948,12 @@ void btm_ble_resolving_list_init(UINT8 max_irk_list_sz)
                            (max_irk_list_sz / 8 + 1) : (max_irk_list_sz / 8);
 
     if (max_irk_list_sz > 0) {
-        p_q->resolve_q_random_pseudo = (BD_ADDR *)GKI_getbuf(sizeof(BD_ADDR) * max_irk_list_sz);
-        p_q->resolve_q_action = (UINT8 *)GKI_getbuf(max_irk_list_sz);
+        p_q->resolve_q_random_pseudo = (BD_ADDR *)osi_malloc(sizeof(BD_ADDR) * max_irk_list_sz);
+        p_q->resolve_q_action = (UINT8 *)osi_malloc(max_irk_list_sz);
 
         /* RPA offloading feature */
         if (btm_cb.ble_ctr_cb.irk_list_mask == NULL) {
-            btm_cb.ble_ctr_cb.irk_list_mask = (UINT8 *)GKI_getbuf(irk_mask_size);
+            btm_cb.ble_ctr_cb.irk_list_mask = (UINT8 *)osi_malloc(irk_mask_size);
         }
 
         BTM_TRACE_DEBUG ("%s max_irk_list_sz = %d", __func__, max_irk_list_sz);
@@ -980,18 +980,20 @@ void btm_ble_resolving_list_cleanup(void)
     tBTM_BLE_RESOLVE_Q *p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q;
 
     if (p_q->resolve_q_random_pseudo) {
-        GKI_freebuf(p_q->resolve_q_random_pseudo);
+        osi_free(p_q->resolve_q_random_pseudo);
+        p_q->resolve_q_random_pseudo = NULL;
     }
 
     if (p_q->resolve_q_action) {
-        GKI_freebuf(p_q->resolve_q_action);
+        osi_free(p_q->resolve_q_action);
+        p_q->resolve_q_action = NULL;
     }
 
     controller_get_interface()->set_ble_resolving_list_max_size(0);
     if (btm_cb.ble_ctr_cb.irk_list_mask) {
-        GKI_freebuf(btm_cb.ble_ctr_cb.irk_list_mask);
+        osi_free(btm_cb.ble_ctr_cb.irk_list_mask);
+        btm_cb.ble_ctr_cb.irk_list_mask = NULL;
     }
 
-    btm_cb.ble_ctr_cb.irk_list_mask = NULL;
 }
 #endif
index b86f861a47f1576a586b21fca2f373d8b620568b..2985b46ff94f0768cffd173ea2f0cf3a7d73452e 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "bt_types.h"
 #include "controller.h"
-#include "gki.h"
 #include "hcimsgs.h"
 #include "btu.h"
 #include "btm_api.h"
index 45cc82cddbf48aafe71f5b9537b51b3ba87cf1fe..00d580b3e80f0091b838b6c538627f2a72a3396c 100644 (file)
@@ -655,7 +655,7 @@ tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len,
                      opcode, param_len);
 
     /* Allocate a buffer to hold HCI command plus the callback function */
-    if ((p_buf = GKI_getbuf((UINT16)(sizeof(BT_HDR) + sizeof (tBTM_CMPL_CB *) +
+    if ((p_buf = osi_malloc((UINT16)(sizeof(BT_HDR) + sizeof (tBTM_CMPL_CB *) +
                                      param_len + HCIC_PREAMBLE_SIZE))) != NULL) {
         /* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */
         btsnd_hcic_vendor_spec_cmd (p_buf, opcode, param_len, p_param_buf, (void *)p_cb);
index ff0fcc5b04afa2324e6807f76f13f8855a10d01b..d9baa4b81c5490a2827cf0afd38d4f066c2e6198 100644 (file)
@@ -29,9 +29,9 @@
 #include <stdio.h>
 #include <stddef.h>
 
+#include "alarm.h"
 #include "bt_types.h"
 #include "controller.h"
-#include "gki.h"
 #include "hcimsgs.h"
 #include "btu.h"
 #include "btm_api.h"
@@ -1461,7 +1461,7 @@ static void btm_clr_inq_result_flt (void)
     tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
 
     if (p_inq->p_bd_db) {
-        GKI_freebuf(p_inq->p_bd_db);
+        osi_free(p_inq->p_bd_db);
         p_inq->p_bd_db = NULL;
     }
     p_inq->num_bd_entries = 0;
@@ -1784,9 +1784,8 @@ static void btm_initiate_inquiry (tBTM_INQUIRY_VAR_ST *p_inq)
         btm_clr_inq_result_flt();
 
         /* Allocate memory to hold bd_addrs responding */
-        if ((p_inq->p_bd_db = (tINQ_BDADDR *)GKI_getbuf(GKI_MAX_BUF_SIZE)) != NULL) {
-            p_inq->max_bd_entries = (UINT16)(GKI_MAX_BUF_SIZE / sizeof(tINQ_BDADDR));
-            memset(p_inq->p_bd_db, 0, GKI_MAX_BUF_SIZE);
+        if ((p_inq->p_bd_db = (tINQ_BDADDR *)osi_calloc(BT_DEFAULT_BUFFER_SIZE)) != NULL) {
+            p_inq->max_bd_entries = (UINT16)(BT_DEFAULT_BUFFER_SIZE / sizeof(tINQ_BDADDR));
             /*            BTM_TRACE_DEBUG("btm_initiate_inquiry: memory allocated for %d bdaddrs",
                                           p_inq->max_bd_entries); */
         }
@@ -1949,7 +1948,7 @@ void btm_process_inq_results (UINT8 *p, UINT8 inq_res_mode)
             p_cur->dev_class[2]       = dc[2];
             p_cur->clock_offset       = clock_offset  | BTM_CLOCK_OFFSET_VALID;
 
-            p_i->time_of_resp = GKI_get_os_tick_count();
+            p_i->time_of_resp = osi_time_get_os_boottime_ms();
 
             if (p_i->inq_count != p_inq->inq_counter) {
                 p_inq->inq_cmpl_info.num_resp++;    /* A new response was found */
@@ -2031,7 +2030,7 @@ void btm_sort_inq_result(void)
     num_resp = (btm_cb.btm_inq_vars.inq_cmpl_info.num_resp < BTM_INQ_DB_SIZE) ?
                btm_cb.btm_inq_vars.inq_cmpl_info.num_resp : BTM_INQ_DB_SIZE;
 
-    if ((p_tmp = (tINQ_DB_ENT *)GKI_getbuf(sizeof(tINQ_DB_ENT))) != NULL) {
+    if ((p_tmp = (tINQ_DB_ENT *)osi_malloc(sizeof(tINQ_DB_ENT))) != NULL) {
         size = sizeof(tINQ_DB_ENT);
         for (xx = 0; xx < num_resp - 1; xx++, p_ent++) {
             for (yy = xx + 1, p_next = p_ent + 1; yy < num_resp; yy++, p_next++) {
@@ -2043,7 +2042,7 @@ void btm_sort_inq_result(void)
             }
         }
 
-        GKI_freebuf(p_tmp);
+        osi_free(p_tmp);
     }
 }
 
@@ -2412,7 +2411,7 @@ tBTM_STATUS BTM_WriteEIR( BT_HDR *p_buff )
         btsnd_hcic_write_ext_inquiry_response (p_buff, BTM_EIR_DEFAULT_FEC_REQUIRED);
         return BTM_SUCCESS;
     } else {
-        GKI_freebuf(p_buff);
+        osi_free(p_buff);
         return BTM_MODE_UNSUPPORTED;
     }
 }
index f067dded66062c9f52ebaec12d841701786fa123..a2ee6ca3d64bdefaf9635bd2973750335544c196 100644 (file)
@@ -27,6 +27,7 @@
 #include "bt_target.h"
 #include <string.h>
 #include "btm_int.h"
+#include "allocator.h"
 
 /* Global BTM control block structure
 */
@@ -51,6 +52,9 @@ void btm_init (void)
     /* All fields are cleared; nonzero fields are reinitialized in appropriate function */
     memset(&btm_cb, 0, sizeof(tBTM_CB));
 
+    btm_cb.page_queue = fixed_queue_new(SIZE_MAX);
+    btm_cb.sec_pending_q = fixed_queue_new(SIZE_MAX);
+
 #if defined(BTM_INITIAL_TRACE_LEVEL)
     btm_cb.trace_level = BTM_INITIAL_TRACE_LEVEL;
 #else
@@ -70,3 +74,17 @@ void btm_init (void)
 }
 
 
+/*******************************************************************************
+**
+** Function         btm_free
+**
+** Description      This function is called at btu core free the fixed queue
+**
+** Returns          void
+**
+*******************************************************************************/
+void btm_free(void)
+{
+    fixed_queue_free(btm_cb.page_queue, osi_free_func);
+    fixed_queue_free(btm_cb.sec_pending_q, osi_free_func);
+}
index a0aaa06102f660e16c8d2805e1059df1a7c417dc..56157fcd833b9ecc486022a53a4f5a0aa2ccb29c 100644 (file)
@@ -36,7 +36,6 @@
 #include <stddef.h>
 
 #include "bt_types.h"
-#include "gki.h"
 #include "hcimsgs.h"
 #include "btu.h"
 #include "btm_api.h"
@@ -916,7 +915,7 @@ BOOLEAN btm_pm_device_in_scan_state(void)
     /* Scan state-paging, inquiry, and trying to connect */
 
     /* Check for paging */
-    if (btm_cb.is_paging || GKI_queue_length(&btm_cb.page_queue) > 0 ||
+    if (btm_cb.is_paging || (!fixed_queue_is_empty(btm_cb.page_queue)) ||
             BTM_BL_PAGING_STARTED == btm_cb.busy_level) {
         BTM_TRACE_DEBUG("btm_pm_device_in_scan_state- paging");
         return TRUE;
index 076bb655dfab55a298f45d30a4f6be893226f3e7..04a510f78714b17c089f07ebb1e5c92a6de5d8b1 100644 (file)
@@ -26,7 +26,6 @@
 #include <string.h>
 #include "bt_types.h"
 #include "bt_target.h"
-#include "gki.h"
 #include "bt_types.h"
 #include "hcimsgs.h"
 #include "btu.h"
@@ -86,10 +85,8 @@ void btm_sco_flush_sco_data(UINT16 sco_inx)
 
     if (sco_inx < BTM_MAX_SCO_LINKS) {
         p = &btm_cb.sco_cb.sco_db[sco_inx];
-        while (p->xmit_data_q.p_first) {
-            if ((p_buf = (BT_HDR *)GKI_dequeue (&p->xmit_data_q)) != NULL) {
-                GKI_freebuf (p_buf);
-            }
+        while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p->xmit_data_q)) != NULL) {
+            osi_free(p_buf);
         }
     }
 #else
@@ -222,20 +219,19 @@ static void btm_esco_conn_rsp (UINT16 sco_inx, UINT8 hci_status, BD_ADDR bda,
 *******************************************************************************/
 void btm_sco_check_send_pkts (UINT16 sco_inx)
 {
-    BT_HDR  *p_buf;
     tSCO_CB  *p_cb = &btm_cb.sco_cb;
     tSCO_CONN   *p_ccb = &p_cb->sco_db[sco_inx];
 
     /* If there is data to send, send it now */
-    while (p_ccb->xmit_data_q.p_first != NULL) {
-        p_buf = NULL;
-
+    BT_HDR  *p_buf;
+    while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_data_q)) != NULL)
+    {
 #if BTM_SCO_HCI_DEBUG
-        BTM_TRACE_DEBUG ("btm: [%d] buf in xmit_data_q", p_ccb->xmit_data_q.count );
+        BTM_TRACE_DEBUG("btm: [%d] buf in xmit_data_q",
+                        fixed_queue_length(p_ccb->xmit_data_q) + 1);
 #endif
-        p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->xmit_data_q);
 
-        HCI_SCO_DATA_TO_LOWER (p_buf);
+        HCI_SCO_DATA_TO_LOWER(p_buf);
     }
 }
 #endif /* BTM_SCO_HCI_INCLUDED == TRUE */
@@ -269,15 +265,15 @@ void  btm_route_sco_data(BT_HDR *p_msg)
         if (!btm_cb.sco_cb.p_data_cb )
             /* if no data callback registered,  just free the buffer  */
         {
-            GKI_freebuf (p_msg);
+            osi_free (p_msg);
         } else {
             (*btm_cb.sco_cb.p_data_cb)(sco_inx, p_msg, (tBTM_SCO_DATA_FLAG) pkt_status);
         }
     } else { /* no mapping handle SCO connection is active, free the buffer */
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
     }
 #else
-    GKI_freebuf(p_msg);
+    osi_free(p_msg);
 #endif
 }
 
@@ -314,7 +310,7 @@ tBTM_STATUS BTM_WriteScoData (UINT16 sco_inx, BT_HDR *p_buf)
         /* Ensure we have enough space in the buffer for the SCO and HCI headers */
         if (p_buf->offset < HCI_SCO_PREAMBLE_SIZE) {
             BTM_TRACE_ERROR ("BTM SCO - cannot send buffer, offset: %d", p_buf->offset);
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
             status = BTM_ILLEGAL_VALUE;
         } else { /* write HCI header */
             /* Step back 3 bytes to add the headers */
@@ -333,12 +329,12 @@ tBTM_STATUS BTM_WriteScoData (UINT16 sco_inx, BT_HDR *p_buf)
             UINT8_TO_STREAM (p, (UINT8)p_buf->len);
             p_buf->len += HCI_SCO_PREAMBLE_SIZE;
 
-            GKI_enqueue (&p_ccb->xmit_data_q, p_buf);
+            fixed_queue_enqueue(p_ccb->xmit_data_q, p_buf);
 
             btm_sco_check_send_pkts (sco_inx);
         }
     } else {
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
 
         BTM_TRACE_WARNING ("BTM_WriteScoData, invalid sco index: %d at state [%d]",
                            sco_inx, btm_cb.sco_cb.sco_db[sco_inx].state);
index f5716ba82e5da244e38f6e9b442c9685a3886588..bf4a28319ae917f4004cf9bd7e176899028da4f2 100644 (file)
@@ -33,8 +33,8 @@
 #include "btu.h"
 #include "btm_int.h"
 #include "l2c_int.h"
-//#include "bt_utils.h"
-//#include "osi/include/log.h"
+#include "fixed_queue.h"
+#include "alarm.h"
 
 #if (BT_USE_TRACES == TRUE && BT_TRACE_VERBOSE == FALSE)
 /* needed for sprintf() */
@@ -2759,7 +2759,7 @@ void btm_create_conn_cancel_complete (UINT8 *p)
 void btm_sec_check_pending_reqs (void)
 {
     tBTM_SEC_QUEUE_ENTRY    *p_e;
-    BUFFER_Q                bq;
+    fixed_queue_t *bq;
 
     if (btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) {
         /* First, resubmit L2CAP requests */
@@ -2773,9 +2773,9 @@ void btm_sec_check_pending_reqs (void)
         /* Now, re-submit anything in the mux queue */
         bq = btm_cb.sec_pending_q;
 
-        GKI_init_q (&btm_cb.sec_pending_q);
+        btm_cb.sec_pending_q = fixed_queue_new(SIZE_MAX);
 
-        while ((p_e = (tBTM_SEC_QUEUE_ENTRY *)GKI_dequeue (&bq)) != NULL) {
+        while ((p_e = (tBTM_SEC_QUEUE_ENTRY *)fixed_queue_try_dequeue(bq)) != NULL) {
             /* Check that the ACL is still up before starting security procedures */
             if (btm_bda_to_acl(p_e->bd_addr, p_e->transport) != NULL) {
                 if (p_e->psm != 0) {
@@ -2792,7 +2792,7 @@ void btm_sec_check_pending_reqs (void)
                 }
             }
 
-            GKI_freebuf (p_e);
+            osi_free (p_e);
         }
     }
 }
@@ -3787,11 +3787,13 @@ static void btm_sec_auth_collision (UINT16 handle)
     tBTM_SEC_DEV_REC *p_dev_rec;
 
     if (!btm_cb.collision_start_time) {
-        btm_cb.collision_start_time = GKI_get_os_tick_count();
+        btm_cb.collision_start_time = osi_time_get_os_boottime_ms();
     }
 
-    if ((GKI_get_os_tick_count() - btm_cb.collision_start_time) < btm_cb.max_collision_delay) {
-        if (handle == BTM_SEC_INVALID_HANDLE) {
+    if ((osi_time_get_os_boottime_ms() - btm_cb.collision_start_time) < btm_cb.max_collision_delay)
+    {
+        if (handle == BTM_SEC_INVALID_HANDLE)
+        {
             if ((p_dev_rec = btm_sec_find_dev_by_sec_state (BTM_SEC_STATE_AUTHENTICATING)) == NULL) {
                 p_dev_rec = btm_sec_find_dev_by_sec_state (BTM_SEC_STATE_ENCRYPTING);
             }
@@ -5759,7 +5761,7 @@ static BOOLEAN btm_sec_queue_mx_request (BD_ADDR bd_addr,  UINT16 psm,  BOOLEAN
         UINT32 mx_proto_id, UINT32 mx_chan_id,
         tBTM_SEC_CALLBACK *p_callback, void *p_ref_data)
 {
-    tBTM_SEC_QUEUE_ENTRY *p_e = (tBTM_SEC_QUEUE_ENTRY *)GKI_getbuf (sizeof(tBTM_SEC_QUEUE_ENTRY));
+    tBTM_SEC_QUEUE_ENTRY *p_e = (tBTM_SEC_QUEUE_ENTRY *)osi_malloc (sizeof(tBTM_SEC_QUEUE_ENTRY));
 
     if (p_e) {
         p_e->psm            = psm;
@@ -5775,7 +5777,7 @@ static BOOLEAN btm_sec_queue_mx_request (BD_ADDR bd_addr,  UINT16 psm,  BOOLEAN
         BTM_TRACE_EVENT ("%s() PSM: 0x%04x  Is_Orig: %u  mx_proto_id: %u  mx_chan_id: %u\n",
                          __func__, psm, is_orig, mx_proto_id, mx_chan_id);
 
-        GKI_enqueue (&btm_cb.sec_pending_q, p_e);
+    fixed_queue_enqueue(btm_cb.sec_pending_q, p_e);
 
         return (TRUE);
     }
@@ -5860,7 +5862,7 @@ static BOOLEAN btm_sec_queue_encrypt_request (BD_ADDR bd_addr, tBT_TRANSPORT tra
         tBTM_SEC_CALLBACK *p_callback, void *p_ref_data)
 {
     tBTM_SEC_QUEUE_ENTRY  *p_e;
-    p_e = (tBTM_SEC_QUEUE_ENTRY *)GKI_getbuf(sizeof(tBTM_SEC_QUEUE_ENTRY) + 1);
+    p_e = (tBTM_SEC_QUEUE_ENTRY *)osi_malloc(sizeof(tBTM_SEC_QUEUE_ENTRY) + 1);
 
     if (p_e) {
         p_e->psm  = 0;  /* if PSM 0, encryption request */
@@ -5869,7 +5871,7 @@ static BOOLEAN btm_sec_queue_encrypt_request (BD_ADDR bd_addr, tBT_TRANSPORT tra
         *(UINT8 *)p_e->p_ref_data = *(UINT8 *)(p_ref_data);
         p_e->transport  = transport;
         memcpy(p_e->bd_addr, bd_addr, BD_ADDR_LEN);
-        GKI_enqueue(&btm_cb.sec_pending_q, p_e);
+        fixed_queue_enqueue(btm_cb.sec_pending_q, p_e);
         return TRUE;
     }
 
@@ -5950,16 +5952,18 @@ static BOOLEAN btm_sec_is_serv_level0(UINT16 psm)
 static void btm_sec_check_pending_enc_req (tBTM_SEC_DEV_REC  *p_dev_rec, tBT_TRANSPORT transport,
         UINT8 encr_enable)
 {
-    tBTM_SEC_QUEUE_ENTRY    *p_e;
-    BUFFER_Q                *bq = &btm_cb.sec_pending_q;
-    UINT8                   res = encr_enable ? BTM_SUCCESS : BTM_ERR_PROCESSING;
+    if (fixed_queue_is_empty(btm_cb.sec_pending_q))
+        return;
 
-    p_e = (tBTM_SEC_QUEUE_ENTRY *)GKI_getfirst(bq);
+    UINT8 res = encr_enable ? BTM_SUCCESS : BTM_ERR_PROCESSING;
+    list_t *list = fixed_queue_get_list(btm_cb.sec_pending_q);
+    for (const list_node_t *node = list_begin(list); node != list_end(list); ) {
+        tBTM_SEC_QUEUE_ENTRY *p_e = (tBTM_SEC_QUEUE_ENTRY *)list_node(node);
+        node = list_next(node);
 
-    while (p_e != NULL) {
         if (memcmp(p_e->bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0 && p_e->psm == 0
 #if BLE_INCLUDED == TRUE
-                && p_e->transport == transport
+            && p_e->transport == transport
 #endif
            ) {
 #if BLE_INCLUDED == TRUE
@@ -5970,14 +5974,16 @@ static void btm_sec_check_pending_enc_req (tBTM_SEC_DEV_REC  *p_dev_rec, tBT_TRA
 #if BLE_INCLUDED == TRUE
                     || (sec_act == BTM_BLE_SEC_ENCRYPT || sec_act == BTM_BLE_SEC_ENCRYPT_NO_MITM)
                     || (sec_act == BTM_BLE_SEC_ENCRYPT_MITM && p_dev_rec->sec_flags
-                        & BTM_SEC_LE_AUTHENTICATED)
+                    & BTM_SEC_LE_AUTHENTICATED)
 #endif
                ) {
-                (*p_e->p_callback) (p_dev_rec->bd_addr, transport, p_e->p_ref_data, res);
-                GKI_remove_from_queue(bq, (void *)p_e);
+                if (p_e->p_callback) {
+                    (*p_e->p_callback) (p_dev_rec->bd_addr, transport, p_e->p_ref_data, res);
+                }
+                               
+                               fixed_queue_try_remove_from_queue(btm_cb.sec_pending_q, (void *)p_e);
             }
         }
-        p_e = (tBTM_SEC_QUEUE_ENTRY *) GKI_getnext ((void *)p_e);
     }
 }
 #endif  ///SMP_INCLUDED == TRUE
index f3a6dd5c8ebe75ba75f8f35845de431a07fb7ed2..02e682333121eafb13a90cbf7ac6e682482040b7 100644 (file)
@@ -30,7 +30,6 @@
 //#include <stdlib.h>
 #include <string.h>
 
-#include "gki.h"
 #include "bt_types.h"
 #include "hcimsgs.h"
 #include "btu.h"
@@ -991,7 +990,7 @@ static void btu_hcif_command_complete_evt_on_task(BT_HDR *event)
         hack->response->len - 5, // 3 for the command complete headers, 2 for the event headers
         hack->context);
 
-    GKI_freebuf(hack->response);
+    osi_free(hack->response);
     osi_free(event);
 }
 
@@ -1190,7 +1189,7 @@ static void btu_hcif_command_status_evt_on_task(BT_HDR *event)
         stream,
         hack->context);
 
-    GKI_freebuf(hack->command);
+    osi_free(hack->command);
     osi_free(event);
 }
 
index 5ebb6edfc22d341f5689713dc88eeaff2dbb7d02..9776139ec4dd966c1a20f681f01643c8fb4f11ef 100644 (file)
@@ -25,6 +25,7 @@
 #include "hash_map.h"
 #include "hash_functions.h"
 #include "thread.h"
+#include "mutex.h"
 
 #include "l2c_int.h"
 #include "dyn_mem.h"
 #endif
 
 hash_map_t *btu_general_alarm_hash_map;
-pthread_mutex_t btu_general_alarm_lock;
+osi_mutex_t btu_general_alarm_lock;
 static const size_t BTU_GENERAL_ALARM_HASH_MAP_SIZE = 34;
 
 hash_map_t *btu_oneshot_alarm_hash_map;
-pthread_mutex_t btu_oneshot_alarm_lock;
+osi_mutex_t btu_oneshot_alarm_lock;
 static const size_t BTU_ONESHOT_ALARM_HASH_MAP_SIZE = 34;
 
 hash_map_t *btu_l2cap_alarm_hash_map;
-pthread_mutex_t btu_l2cap_alarm_lock;
+osi_mutex_t btu_l2cap_alarm_lock;
 static const size_t BTU_L2CAP_ALARM_HASH_MAP_SIZE = 34;
 
 //thread_t *bt_workqueue_thread;
@@ -121,7 +122,9 @@ void btu_free_core(void)
 #if (defined(GATTS_INCLUDED) && GATTS_INCLUDED == true)
     gatt_free();
 #endif
+    btm_ble_free();
 #endif
+    btm_free();
 }
 
 /*****************************************************************************
@@ -147,7 +150,7 @@ void BTU_StartUp(void)
         goto error_exit;
     }
 
-    pthread_mutex_init(&btu_general_alarm_lock, NULL);
+    osi_mutex_new(&btu_general_alarm_lock);
 
     btu_oneshot_alarm_hash_map = hash_map_new(BTU_ONESHOT_ALARM_HASH_MAP_SIZE,
                                  hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
@@ -155,7 +158,7 @@ void BTU_StartUp(void)
         goto error_exit;
     }
 
-    pthread_mutex_init(&btu_oneshot_alarm_lock, NULL);
+    osi_mutex_new(&btu_oneshot_alarm_lock);
 
     btu_l2cap_alarm_hash_map = hash_map_new(BTU_L2CAP_ALARM_HASH_MAP_SIZE,
                                             hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
@@ -163,7 +166,7 @@ void BTU_StartUp(void)
         goto error_exit;
     }
 
-    pthread_mutex_init(&btu_l2cap_alarm_lock, NULL);
+    osi_mutex_new(&btu_l2cap_alarm_lock);
 
     xBtuQueue = xQueueCreate(BTU_QUEUE_NUM, sizeof(BtTaskEvt_t));
     xTaskCreatePinnedToCore(btu_task_thread_handler, BTU_TASK_NAME, BTU_TASK_STACK_SIZE, NULL, BTU_TASK_PRIO, &xBtuTaskHandle, 0);
@@ -182,13 +185,13 @@ void BTU_ShutDown(void)
     btu_task_shut_down();
 
     hash_map_free(btu_general_alarm_hash_map);
-    pthread_mutex_destroy(&btu_general_alarm_lock);
+    osi_mutex_free(&btu_general_alarm_lock);
 
     hash_map_free(btu_oneshot_alarm_hash_map);
-    pthread_mutex_destroy(&btu_oneshot_alarm_lock);
+    osi_mutex_free(&btu_oneshot_alarm_lock);
 
     hash_map_free(btu_l2cap_alarm_hash_map);
-    pthread_mutex_destroy(&btu_l2cap_alarm_lock);
+    osi_mutex_free(&btu_l2cap_alarm_lock);
 
     vTaskDelete(xBtuTaskHandle);
     vQueueDelete(xBtuQueue);
index 0f0b3ec9bd36445c8afd2805b7a5d392da9fd002..a8b2703f4fa13c67f27c0a27a8088e218fd66054 100644 (file)
 #include "bt_trace.h"
 #include "bt_types.h"
 #include "allocator.h"
+#include "mutex.h"
 #include "btm_api.h"
 #include "btm_int.h"
 #include "btu.h"
-#include "gki.h"
 #include "hash_map.h"
 #include "hcimsgs.h"
 #include "l2c_int.h"
@@ -94,15 +94,15 @@ tBTU_CB  btu_cb;
 #endif
 
 extern hash_map_t *btu_general_alarm_hash_map;
-extern pthread_mutex_t btu_general_alarm_lock;
+extern osi_mutex_t btu_general_alarm_lock;
 
 // Oneshot timer queue.
 extern hash_map_t *btu_oneshot_alarm_hash_map;
-extern pthread_mutex_t btu_oneshot_alarm_lock;
+extern osi_mutex_t btu_oneshot_alarm_lock;
 
 // l2cap timer queue.
 extern hash_map_t *btu_l2cap_alarm_hash_map;
-extern pthread_mutex_t btu_l2cap_alarm_lock;
+extern osi_mutex_t btu_l2cap_alarm_lock;
 
 extern xTaskHandle  xBtuTaskHandle;
 extern xQueueHandle xBtuQueue;
@@ -147,7 +147,7 @@ static void btu_hci_msg_process(BT_HDR *p_msg)
 
     case BT_EVT_TO_BTU_HCI_EVT:
         btu_hcif_process_event ((UINT8)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
-        GKI_freebuf(p_msg);
+        osi_free(p_msg);
 
 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
         /* If host receives events which it doesn't response to, */
@@ -179,7 +179,7 @@ static void btu_hci_msg_process(BT_HDR *p_msg)
         }
 
         if (handled == FALSE) {
-            GKI_freebuf (p_msg);
+            osi_free (p_msg);
         }
 
         break;
@@ -195,10 +195,10 @@ static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle)
         (*p_tle->p_cback)(p_tle);
     } else if (p_tle->event) {
         BT_HDR *p_msg;
-        if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
+        if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
             p_msg->event = p_tle->event;
             p_msg->layer_specific = 0;
-            //GKI_freebuf(p_msg);
+            //osi_free(p_msg);
             bta_sys_sendmsg(p_msg);
         }
     }
@@ -448,12 +448,12 @@ void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec)
     assert(p_tle != NULL);
 
     // Get the alarm for the timer list entry.
-    pthread_mutex_lock(&btu_general_alarm_lock);
+    osi_mutex_lock(&btu_general_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
     if (!hash_map_has_key(btu_general_alarm_hash_map, p_tle)) {
         alarm = osi_alarm_new("btu_gen", btu_general_alarm_cb, (void *)p_tle, 0);
         hash_map_set(btu_general_alarm_hash_map, p_tle, alarm);
     }
-    pthread_mutex_unlock(&btu_general_alarm_lock);
+    osi_mutex_unlock(&btu_general_alarm_lock);
 
     alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
     if (alarm == NULL) {
@@ -537,12 +537,12 @@ void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ti
     assert(p_tle != NULL);
 
     // Get the alarm for the timer list entry.
-    pthread_mutex_lock(&btu_l2cap_alarm_lock);
+    osi_mutex_lock(&btu_l2cap_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
     if (!hash_map_has_key(btu_l2cap_alarm_hash_map, p_tle)) {
         alarm = osi_alarm_new("btu_l2cap", btu_l2cap_alarm_cb, (void *)p_tle, 0);
         hash_map_set(btu_l2cap_alarm_hash_map, p_tle, (void *)alarm);
     }
-    pthread_mutex_unlock(&btu_l2cap_alarm_lock);
+    osi_mutex_unlock(&btu_l2cap_alarm_lock);
 
     alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
     if (alarm == NULL) {
@@ -606,12 +606,12 @@ void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_
     assert(p_tle != NULL);
 
     // Get the alarm for the timer list entry.
-    pthread_mutex_lock(&btu_oneshot_alarm_lock);
+    osi_mutex_lock(&btu_oneshot_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
     if (!hash_map_has_key(btu_oneshot_alarm_hash_map, p_tle)) {
         alarm = osi_alarm_new("btu_oneshot", btu_oneshot_alarm_cb, (void *)p_tle, 0);
         hash_map_set(btu_oneshot_alarm_hash_map, p_tle, alarm);
     }
-    pthread_mutex_unlock(&btu_oneshot_alarm_lock);
+    osi_mutex_unlock(&btu_oneshot_alarm_lock);
 
     alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
     if (alarm == NULL) {
index b81bae4c49ba2775af86e6e1706c41c0571f8459..58012633a6d1e60fcc24d155777b45bdfff43953 100644 (file)
@@ -20,6 +20,7 @@
 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE)
 
 #include "bt_defs.h"
+#include "allocator.h"
 #include <string.h>
 #include "gap_int.h"
 #include "gap_api.h"
@@ -144,13 +145,13 @@ void gap_ble_dealloc_clcb(tGAP_CLCB *p_clcb)
 {
     tGAP_BLE_REQ    *p_q;
 
-    while ((p_q = (tGAP_BLE_REQ *)GKI_dequeue(&p_clcb->pending_req_q)) != NULL) {
+    while ((p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q)) != NULL) {
         /* send callback to all pending requests if being removed*/
         if (p_q->p_cback != NULL) {
             (*p_q->p_cback)(FALSE, p_clcb->bda, 0, NULL);
         }
 
-        GKI_freebuf (p_q);
+        osi_free (p_q);
     }
 
     memset(p_clcb, 0, sizeof(tGAP_CLCB));
@@ -167,12 +168,12 @@ void gap_ble_dealloc_clcb(tGAP_CLCB *p_clcb)
 *******************************************************************************/
 BOOLEAN gap_ble_enqueue_request (tGAP_CLCB *p_clcb, UINT16 uuid, tGAP_BLE_CMPL_CBACK *p_cback)
 {
-    tGAP_BLE_REQ  *p_q = (tGAP_BLE_REQ *)GKI_getbuf(sizeof(tGAP_BLE_REQ));
+    tGAP_BLE_REQ  *p_q = (tGAP_BLE_REQ *)osi_malloc(sizeof(tGAP_BLE_REQ));
 
     if (p_q != NULL) {
         p_q->p_cback = p_cback;
         p_q->uuid = uuid;
-        GKI_enqueue(&p_clcb->pending_req_q, p_q);
+        fixed_queue_enqueue(p_clcb->pending_req_q, p_q);
         return TRUE;
     }
 
@@ -189,12 +190,12 @@ BOOLEAN gap_ble_enqueue_request (tGAP_CLCB *p_clcb, UINT16 uuid, tGAP_BLE_CMPL_C
 *******************************************************************************/
 BOOLEAN gap_ble_dequeue_request (tGAP_CLCB *p_clcb, UINT16 *p_uuid, tGAP_BLE_CMPL_CBACK **p_cback)
 {
-    tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)GKI_dequeue(&p_clcb->pending_req_q);;
+    tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q);;
 
     if (p_q != NULL) {
         *p_cback    = p_q->p_cback;
         *p_uuid     = p_q->uuid;
-        GKI_freebuf((void *)p_q);
+        osi_free((void *)p_q);
         return TRUE;
     }
 
index 882e0b2d57f1de6f9e39209d5b05f838eb369f87..eb5b20cef023dad61c93df11ceebc83a0150cb33 100644 (file)
@@ -24,6 +24,9 @@
 #include "l2cdefs.h"
 #include "l2c_int.h"
 #include <string.h>
+#include "mutex.h"
+#include "allocator.h"
+
 #if GAP_CONN_INCLUDED == TRUE
 #include "btm_int.h"
 
@@ -199,10 +202,10 @@ UINT16 GAP_ConnOpen (char *p_serv_name, UINT8 service_id, BOOLEAN is_server,
     if ( p_ccb->cfg.fcr_present ) {
         if (ertm_info == NULL) {
             p_ccb->ertm_info.preferred_mode = p_ccb->cfg.fcr.mode;
-            p_ccb->ertm_info.user_rx_pool_id = GAP_DATA_POOL_ID;
-            p_ccb->ertm_info.user_tx_pool_id = GAP_DATA_POOL_ID;
-            p_ccb->ertm_info.fcr_rx_pool_id = L2CAP_DEFAULT_ERM_POOL_ID;
-            p_ccb->ertm_info.fcr_tx_pool_id = L2CAP_DEFAULT_ERM_POOL_ID;
+            p_ccb->ertm_info.user_rx_buf_size = GAP_DATA_BUF_SIZE;
+            p_ccb->ertm_info.user_tx_buf_size = GAP_DATA_BUF_SIZE;
+            p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE;
+            p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE;
         } else {
             p_ccb->ertm_info = *ertm_info;
         }
@@ -296,7 +299,6 @@ UINT16 GAP_ConnClose (UINT16 gap_handle)
 UINT16 GAP_ConnReadData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT16 *p_len)
 {
     tGAP_CCB    *p_ccb = gap_find_ccb_by_handle (gap_handle);
-    BT_HDR     *p_buf;
     UINT16      copy_len;
 
     if (!p_ccb) {
@@ -305,15 +307,19 @@ UINT16 GAP_ConnReadData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT1
 
     *p_len = 0;
 
-    p_buf = (BT_HDR *)GKI_getfirst (&p_ccb->rx_queue);
-    if (!p_buf) {
+    if (fixed_queue_is_empty(p_ccb->rx_queue)) {
         return (GAP_NO_DATA_AVAIL);
-    }
+       }
 
-    GKI_disable();
+    osi_mutex_global_lock();
+
+    while (max_len) {
+        BT_HDR *p_buf = fixed_queue_try_peek_first(p_ccb->rx_queue);
+        if (p_buf == NULL) {
+            break;
+               }
 
-    while (max_len && p_buf) {
-        copy_len = (p_buf->len > max_len) ? max_len : p_buf->len;
+        copy_len = (p_buf->len > max_len)?max_len:p_buf->len;
         max_len -= copy_len;
         *p_len  += copy_len;
         if (p_data) {
@@ -325,17 +331,13 @@ UINT16 GAP_ConnReadData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT1
             p_buf->offset += copy_len;
             p_buf->len    -= copy_len;
             break;
-        } else {
-            if (max_len) {
-                p_buf = (BT_HDR *)GKI_getnext (p_buf);
-            }
-            GKI_freebuf (GKI_dequeue (&p_ccb->rx_queue));
         }
+        osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue));
     }
 
     p_ccb->rx_queue_size -= *p_len;
 
-    GKI_enable();
+    osi_mutex_global_unlock();
 
     GAP_TRACE_EVENT ("GAP_ConnReadData - rx_queue_size left=%d, *p_len=%d",
                      p_ccb->rx_queue_size, *p_len);
@@ -402,7 +404,7 @@ UINT16 GAP_ConnBTRead (UINT16 gap_handle, BT_HDR **pp_buf)
         return (GAP_ERR_BAD_HANDLE);
     }
 
-    p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->rx_queue);
+    p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->rx_queue);
 
     if (p_buf) {
         *pp_buf = p_buf;
@@ -435,21 +437,21 @@ UINT16 GAP_ConnBTWrite (UINT16 gap_handle, BT_HDR *p_buf)
     tGAP_CCB    *p_ccb = gap_find_ccb_by_handle (gap_handle);
 
     if (!p_ccb) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (GAP_ERR_BAD_HANDLE);
     }
 
     if (p_ccb->con_state != GAP_CCB_STATE_CONNECTED) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (GAP_ERR_BAD_STATE);
     }
 
     if (p_buf->offset < L2CAP_MIN_OFFSET) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (GAP_ERR_BUF_OFFSET);
     }
 
-    GKI_enqueue (&p_ccb->tx_queue, p_buf);
+    fixed_queue_enqueue(p_ccb->tx_queue, p_buf);
 
     if (p_ccb->is_congested) {
         return (BT_PASS);
@@ -459,7 +461,7 @@ UINT16 GAP_ConnBTWrite (UINT16 gap_handle, BT_HDR *p_buf)
 #if (GAP_CONN_POST_EVT_INCLUDED == TRUE)
     gap_send_event (gap_handle);
 #else
-    while ((p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->tx_queue)) != NULL) {
+    while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) {
         UINT8 status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf);
 
         if (status == L2CAP_DW_CONGESTED) {
@@ -509,11 +511,11 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT
 
     while (max_len) {
         if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) {
-            if ((p_buf = (BT_HDR *)GKI_getpoolbuf (p_ccb->ertm_info.user_tx_pool_id)) == NULL) {
+            if ((p_buf = (BT_HDR *)osi_malloc(L2CAP_FCR_ERTM_BUF_SIZE)) == NULL) {
                 return (GAP_ERR_CONGESTED);
             }
         } else {
-            if ((p_buf = (BT_HDR *)GKI_getpoolbuf (GAP_DATA_POOL_ID)) == NULL) {
+            if ((p_buf = (BT_HDR *)osi_malloc(GAP_DATA_BUF_SIZE)) == NULL) {
                 return (GAP_ERR_CONGESTED);
             }
         }
@@ -530,7 +532,7 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT
 
         GAP_TRACE_EVENT ("GAP_WriteData %d bytes", p_buf->len);
 
-        GKI_enqueue (&p_ccb->tx_queue, p_buf);
+        fixed_queue_enqueue(p_ccb->tx_queue, p_buf);
     }
 
     if (p_ccb->is_congested) {
@@ -541,7 +543,8 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT
 #if (GAP_CONN_POST_EVT_INCLUDED == TRUE)
     gap_send_event (gap_handle);
 #else
-    while ((p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->tx_queue)) != NULL) {
+    while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL)
+    {
         UINT8 status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf);
 
         if (status == L2CAP_DW_CONGESTED) {
@@ -555,7 +558,6 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT
     return (BT_PASS);
 }
 
-
 /*******************************************************************************
 **
 ** Function         GAP_ConnReconfig
@@ -874,7 +876,7 @@ static void gap_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
     /* Remember the remote MTU size */
 
     if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) {
-        local_mtu_size = GKI_get_pool_bufsize (p_ccb->ertm_info.user_tx_pool_id)
+        local_mtu_size = p_ccb->ertm_info.user_tx_buf_size
                          - sizeof(BT_HDR) - L2CAP_MIN_OFFSET;
     } else {
         local_mtu_size = L2CAP_MTU_SIZE;
@@ -982,12 +984,12 @@ static void gap_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg)
 
     /* Find CCB based on CID */
     if ((p_ccb = gap_find_ccb_by_cid (l2cap_cid)) == NULL) {
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
         return;
     }
 
     if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) {
-        GKI_enqueue (&p_ccb->rx_queue, p_msg);
+        fixed_queue_enqueue(p_ccb->rx_queue, p_msg);
 
         p_ccb->rx_queue_size += p_msg->len;
         /*
@@ -997,7 +999,7 @@ static void gap_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg)
 
         p_ccb->p_callback (p_ccb->gap_handle, GAP_EVT_CONN_DATA_AVAIL);
     } else {
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
     }
 }
 
@@ -1031,7 +1033,7 @@ static void gap_congestion_ind (UINT16 lcid, BOOLEAN is_congested)
     p_ccb->p_callback (p_ccb->gap_handle, event);
 
     if (!is_congested) {
-        while ((p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->tx_queue)) != NULL) {
+        while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) {
             status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf);
 
             if (status == L2CAP_DW_CONGESTED) {
@@ -1118,6 +1120,8 @@ static tGAP_CCB *gap_allocate_ccb (void)
     for (xx = 0, p_ccb = gap_cb.conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; xx++, p_ccb++) {
         if (p_ccb->con_state == GAP_CCB_STATE_IDLE) {
             memset (p_ccb, 0, sizeof (tGAP_CCB));
+            p_ccb->tx_queue = fixed_queue_new(SIZE_MAX);
+            p_ccb->rx_queue = fixed_queue_new(SIZE_MAX);
 
             p_ccb->gap_handle   = xx;
             p_ccb->rem_mtu_size = L2CAP_MTU_SIZE;
@@ -1149,13 +1153,17 @@ static void gap_release_ccb (tGAP_CCB *p_ccb)
     /* Drop any buffers we may be holding */
     p_ccb->rx_queue_size = 0;
 
-    while (p_ccb->rx_queue._p_first) {
-        GKI_freebuf (GKI_dequeue (&p_ccb->rx_queue));
-    }
+    while (!fixed_queue_is_empty(p_ccb->rx_queue)) {
+        osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue));
+       }
+    fixed_queue_free(p_ccb->rx_queue, NULL);
+    p_ccb->rx_queue = NULL;
 
-    while (p_ccb->tx_queue._p_first) {
-        GKI_freebuf (GKI_dequeue (&p_ccb->tx_queue));
-    }
+    while (!fixed_queue_is_empty(p_ccb->tx_queue)) {
+        osi_free(fixed_queue_try_dequeue(p_ccb->tx_queue));
+       }
+    fixed_queue_free(p_ccb->tx_queue, NULL);
+    p_ccb->tx_queue = NULL;
 
     p_ccb->con_state = GAP_CCB_STATE_IDLE;
 
@@ -1187,7 +1195,7 @@ void gap_send_event (UINT16 gap_handle)
 {
     BT_HDR  *p_msg;
 
-    if ((p_msg = (BT_HDR *)GKI_getbuf(BT_HDR_SIZE)) != NULL) {
+    if ((p_msg = (BT_HDR *)osi_malloc(BT_HDR_SIZE)) != NULL) {
         p_msg->event  = BT_EVT_TO_GAP_MSG;
         p_msg->len    = 0;
         p_msg->offset = 0;
@@ -1199,46 +1207,5 @@ void gap_send_event (UINT16 gap_handle)
     }
 }
 
-/*******************************************************************************
-**
-** Function     gap_proc_btu_event
-**
-** Description  Event handler for BT_EVT_TO_GAP_MSG event from BTU task
-**
-** Returns      None
-**
-*******************************************************************************/
-void gap_proc_btu_event(BT_HDR *p_msg)
-{
-    tGAP_CCB   *p_ccb = gap_find_ccb_by_handle (p_msg->layer_specific);
-    UINT8       status;
-    BT_HDR     *p_buf;
-
-    if (!p_ccb) {
-        return;
-    }
-
-    if (p_ccb->con_state != GAP_CCB_STATE_CONNECTED) {
-        return;
-    }
-
-    if (p_ccb->is_congested) {
-        return;
-    }
-
-    /* Send the buffer through L2CAP */
-
-    while ((p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->tx_queue)) != NULL) {
-        status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf);
-
-        if (status == L2CAP_DW_CONGESTED) {
-            p_ccb->is_congested = TRUE;
-            break;
-        } else if (status != L2CAP_DW_SUCCESS) {
-            break;
-        }
-    }
-
-}
 #endif /* (GAP_CONN_POST_EVT_INCLUDED == TRUE) */
 #endif  /* GAP_CONN_INCLUDED */
index f05b0ce292a239e534103a005d3a3c75eb6150f0..e9317a04b4b9b43c13c1e01437ff3d288d3be0e1 100644 (file)
@@ -21,8 +21,8 @@
 #define GAP_INT_H
 
 #include "bt_target.h"
+#include "fixed_queue.h"
 #include "gap_api.h"
-#include "gki.h"
 #include "gatt_api.h"
 #define GAP_MAX_BLOCKS 2        /* Concurrent GAP commands pending at a time*/
 /* Define the Generic Access Profile control structure */
@@ -71,8 +71,8 @@ typedef struct {
     UINT16            rem_mtu_size;
 
     BOOLEAN           is_congested;
-    BUFFER_Q          tx_queue;             /* Queue of buffers waiting to be sent  */
-    BUFFER_Q          rx_queue;             /* Queue of buffers waiting to be read  */
+    fixed_queue_t     *tx_queue;             /* Queue of buffers waiting to be sent  */
+    fixed_queue_t     *rx_queue;             /* Queue of buffers waiting to be read  */
 
     UINT32            rx_queue_size;        /* Total data count in rx_queue         */
 
@@ -119,7 +119,7 @@ typedef struct {
     UINT16                  cl_op_uuid;
     BOOLEAN                 in_use;
     BOOLEAN                 connected;
-    BUFFER_Q                pending_req_q;
+    fixed_queue_t           *pending_req_q;
 
 } tGAP_CLCB;
 
index 28e4a255165ce215b41674b813f4f99a36b9380f..efc853a746fca160bf596aba55a830bfaa92dd3a 100644 (file)
@@ -23,6 +23,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "allocator.h"
 
 #if BLE_INCLUDED == TRUE
 
@@ -48,7 +49,7 @@ BT_HDR *attp_build_mtu_cmd(UINT8 op_code, UINT16 rx_mtu)
     BT_HDR      *p_buf = NULL;
     UINT8       *p;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + GATT_HDR_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + GATT_HDR_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, op_code);
@@ -73,7 +74,7 @@ BT_HDR *attp_build_exec_write_cmd (UINT8 op_code, UINT8 flag)
     BT_HDR      *p_buf = NULL;
     UINT8       *p;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf(GATT_BUF_POOL_ID)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(GATT_DATA_BUF_SIZE)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         p_buf->offset = L2CAP_MIN_OFFSET;
@@ -106,7 +107,7 @@ BT_HDR *attp_build_err_cmd(UINT8 cmd_code, UINT16 err_handle, UINT8 reason)
     BT_HDR      *p_buf = NULL;
     UINT8       *p;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + 5)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + 5)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, GATT_RSP_ERROR);
@@ -134,7 +135,7 @@ BT_HDR *attp_build_browse_cmd(UINT8 op_code, UINT16 s_hdl, UINT16 e_hdl, tBT_UUI
     BT_HDR      *p_buf = NULL;
     UINT8       *p;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + 8 + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + 8 + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
         /* Describe the built message location and size */
         p_buf->offset = L2CAP_MIN_OFFSET;
@@ -163,7 +164,7 @@ BT_HDR *attp_build_read_by_type_value_cmd (UINT16 payload_size, tGATT_FIND_TYPE_
     UINT8       *p;
     UINT16      len = p_value_type->value_len;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf((UINT16)(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET))) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc((UINT16)(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET))) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         p_buf->offset = L2CAP_MIN_OFFSET;
@@ -199,7 +200,7 @@ BT_HDR *attp_build_read_multi_cmd(UINT16 payload_size, UINT16 num_handle, UINT16
     BT_HDR      *p_buf = NULL;
     UINT8       *p, i = 0;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf((UINT16)(sizeof(BT_HDR) + num_handle * 2 + 1 + L2CAP_MIN_OFFSET))) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc((UINT16)(sizeof(BT_HDR) + num_handle * 2 + 1 + L2CAP_MIN_OFFSET))) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         p_buf->offset = L2CAP_MIN_OFFSET;
@@ -229,7 +230,7 @@ BT_HDR *attp_build_handle_cmd(UINT8 op_code, UINT16 handle, UINT16 offset)
     BT_HDR      *p_buf = NULL;
     UINT8       *p;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + 5 + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + 5 + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         p_buf->offset = L2CAP_MIN_OFFSET;
@@ -263,7 +264,7 @@ BT_HDR *attp_build_opcode_cmd(UINT8 op_code)
     BT_HDR      *p_buf = NULL;
     UINT8       *p;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + 1 + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + 1 + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
         p_buf->offset = L2CAP_MIN_OFFSET;
 
@@ -288,7 +289,7 @@ BT_HDR *attp_build_value_cmd (UINT16 payload_size, UINT8 op_code, UINT16 handle,
     BT_HDR      *p_buf = NULL;
     UINT8       *p, *pp, pair_len, *p_pair_len;
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf((UINT16)(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET))) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc((UINT16)(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET))) != NULL) {
         p = pp = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, op_code);
index ea39008cbb706bf0187d62879e7e0eed68f8f549..f8fffc2e62c26b88861be35a3550e741e9432b55 100644 (file)
@@ -26,8 +26,7 @@
 
 #if defined(BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)
 
-#include "gki.h"
-//#include <stdio.h>
+#include "allocator.h"
 #include <string.h>
 #include "gatt_api.h"
 #include "gatt_int.h"
@@ -235,7 +234,7 @@ UINT16 GATTS_CreateService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid,
         }
 
         if (p_buf) {
-            GKI_freebuf (GKI_remove_from_queue (&gatt_cb.pending_new_srv_start_q, p_buf));
+            osi_free(fixed_queue_try_remove_from_queue(gatt_cb.pending_new_srv_start_q, p_buf));
         }
         return (0);
     }
@@ -397,7 +396,7 @@ BOOLEAN GATTS_DeleteService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid, UINT16 svc_
                                          &p_list->asgn_range.svc_uuid,
                                          p_list->asgn_range.svc_inst)) != NULL) {
         GATT_TRACE_DEBUG ("Delete a new service changed item - the service has not yet started");
-        GKI_freebuf (GKI_remove_from_queue (&gatt_cb.pending_new_srv_start_q, p_buf));
+        osi_free(fixed_queue_try_remove_from_queue(gatt_cb.pending_new_srv_start_q, p_buf));
     } else {
         gatt_proc_srv_chg();
     }
@@ -512,7 +511,7 @@ tGATT_STATUS GATTS_StartService (tGATT_IF gatt_if, UINT16 service_handle,
         gatt_proc_srv_chg();
         /* remove the new service element after the srv changed processing is completed*/
 
-        GKI_freebuf (GKI_remove_from_queue (&gatt_cb.pending_new_srv_start_q, p_buf));
+        osi_free(fixed_queue_try_remove_from_queue(gatt_cb.pending_new_srv_start_q, p_buf));
     }
     return GATT_SUCCESS;
 }
@@ -943,7 +942,7 @@ tGATT_STATUS GATTC_Read (UINT16 conn_id, tGATT_READ_TYPE type, tGATT_READ_PARAM
         case GATT_READ_MULTIPLE:
             p_clcb->s_handle = 0;
             /* copy multiple handles in CB */
-            p_read_multi = (tGATT_READ_MULTI *)GKI_getbuf(sizeof(tGATT_READ_MULTI));
+            p_read_multi = (tGATT_READ_MULTI *)osi_malloc(sizeof(tGATT_READ_MULTI));
             p_clcb->p_attr_buf = (UINT8 *)p_read_multi;
             memcpy (p_read_multi, &p_read->read_multiple, sizeof(tGATT_READ_MULTI));
         case GATT_READ_BY_HANDLE:
@@ -1010,7 +1009,7 @@ tGATT_STATUS GATTC_Write (UINT16 conn_id, tGATT_WRITE_TYPE type, tGATT_VALUE *p_
         p_clcb->op_subtype = type;
         p_clcb->auth_req = p_write->auth_req;
 
-        if (( p_clcb->p_attr_buf = (UINT8 *)GKI_getbuf((UINT16)sizeof(tGATT_VALUE))) != NULL) {
+        if (( p_clcb->p_attr_buf = (UINT8 *)osi_malloc((UINT16)sizeof(tGATT_VALUE))) != NULL) {
             memcpy(p_clcb->p_attr_buf, (void *)p_write, sizeof(tGATT_VALUE));
 
             p =  (tGATT_VALUE *)p_clcb->p_attr_buf;
index 138fb062f1e677ccaf91367e84ee2c12008f7c0c..cee16dd7f9d5d84a618f852866dd94c04fe8853b 100644 (file)
  *
  ******************************************************************************/
 #include "bt_target.h"
-//#include "bt_utils.h"
+#include "allocator.h"
 
 #if BLE_INCLUDED == TRUE
 #include <string.h>
-#include "gki.h"
 
 #include "gatt_int.h"
 #include "gatt_api.h"
@@ -53,7 +52,7 @@ static BOOLEAN gatt_sign_data (tGATT_CLCB *p_clcb)
     /* do not need to mark channel securoty activity for data signing */
     gatt_set_sec_act(p_clcb->p_tcb, GATT_SEC_OK);
 
-    p_data = (UINT8 *)GKI_getbuf((UINT16)(p_attr->len + 3)); /* 3 = 2 byte handle + opcode */
+    p_data = (UINT8 *)osi_malloc((UINT16)(p_attr->len + 3)); /* 3 = 2 byte handle + opcode */
 
     if (p_data != NULL) {
         p = p_data;
@@ -80,7 +79,7 @@ static BOOLEAN gatt_sign_data (tGATT_CLCB *p_clcb)
             gatt_end_operation(p_clcb, GATT_INTERNAL_ERROR, NULL);
         }
 
-        GKI_freebuf(p_data);
+        osi_free(p_data);
     }
 
     return status;
@@ -141,7 +140,8 @@ void gatt_verify_signature(tGATT_TCB *p_tcb, BT_HDR *p_buf)
 *******************************************************************************/
 void gatt_sec_check_complete(BOOLEAN sec_check_ok, tGATT_CLCB   *p_clcb, UINT8 sec_act)
 {
-    if (p_clcb && p_clcb->p_tcb && GKI_queue_is_empty(&p_clcb->p_tcb->pending_enc_clcb)) {
+    if (p_clcb && p_clcb->p_tcb &&
+        fixed_queue_is_empty(p_clcb->p_tcb->pending_enc_clcb)) {
         gatt_set_sec_act(p_clcb->p_tcb, GATT_SEC_NONE);
     }
 #if (GATTC_INCLUDED == TRUE)
@@ -168,8 +168,6 @@ void gatt_enc_cmpl_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_d
     tGATT_TCB   *p_tcb;
     UINT8       sec_flag;
     BOOLEAN     status = FALSE;
-    tGATT_PENDING_ENC_CLCB  *p_buf;
-    UINT16       count;
     UNUSED(p_ref_data);
 
     GATT_TRACE_DEBUG("gatt_enc_cmpl_cback");
@@ -177,8 +175,9 @@ void gatt_enc_cmpl_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_d
         if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) {
             return;
         }
-
-        if ((p_buf = (tGATT_PENDING_ENC_CLCB *)GKI_dequeue (&p_tcb->pending_enc_clcb)) != NULL) {
+        tGATT_PENDING_ENC_CLCB *p_buf =
+            (tGATT_PENDING_ENC_CLCB *)fixed_queue_try_dequeue(p_tcb->pending_enc_clcb);
+        if (p_buf != NULL) {
             if (result == BTM_SUCCESS) {
                 if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENCRYPT_MITM ) {
                     BTM_GetSecurityFlagsByTransport(bd_addr, &sec_flag, transport);
@@ -191,13 +190,14 @@ void gatt_enc_cmpl_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_d
                 }
             }
             gatt_sec_check_complete(status , p_buf->p_clcb, p_tcb->sec_act);
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
             /* start all other pending operation in queue */
-            count = GKI_queue_length(&p_tcb->pending_enc_clcb);
-            for (; count > 0; count --) {
-                if ((p_buf = (tGATT_PENDING_ENC_CLCB *)GKI_dequeue (&p_tcb->pending_enc_clcb)) != NULL) {
+            for (size_t count = fixed_queue_length(p_tcb->pending_enc_clcb);
+                 count > 0; count--) {
+                p_buf = (tGATT_PENDING_ENC_CLCB *)fixed_queue_try_dequeue(p_tcb->pending_enc_clcb);
+                if (p_buf != NULL) {
                     gatt_security_check_start(p_buf->p_clcb);
-                    GKI_freebuf(p_buf);
+                    osi_free(p_buf);
                 } else {
                     break;
                 }
@@ -223,8 +223,6 @@ void gatt_enc_cmpl_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_d
 void gatt_notify_enc_cmpl(BD_ADDR bd_addr)
 {
     tGATT_TCB   *p_tcb;
-    tGATT_PENDING_ENC_CLCB  *p_buf;
-    UINT16       count;
     UINT8        i = 0;
 
     if ((p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE)) != NULL) {
@@ -237,12 +235,13 @@ void gatt_notify_enc_cmpl(BD_ADDR bd_addr)
         if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) {
             gatt_set_sec_act(p_tcb, GATT_SEC_NONE);
 
-            count = GKI_queue_length(&p_tcb->pending_enc_clcb);
-
-            for (; count > 0; count --) {
-                if ((p_buf = (tGATT_PENDING_ENC_CLCB *)GKI_dequeue (&p_tcb->pending_enc_clcb)) != NULL) {
+            size_t count = fixed_queue_length(p_tcb->pending_enc_clcb);
+            for (; count > 0; count--) {
+                tGATT_PENDING_ENC_CLCB *p_buf =
+                    (tGATT_PENDING_ENC_CLCB *)fixed_queue_try_dequeue(p_tcb->pending_enc_clcb);
+                if (p_buf != NULL) {
                     gatt_security_check_start(p_buf->p_clcb);
-                    GKI_freebuf(p_buf);
+                    osi_free(p_buf);
                 } else {
                     break;
                 }
index cefa32f852bc73acbf59b01509d3bb7feea0f12f..f561c3545eec15b3eb4e6a1a309f0134a94c8e44 100644 (file)
@@ -27,8 +27,7 @@
 #if BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE
 
 #include <string.h>
-//#include "bt_utils.h"
-#include "gki.h"
+#include "allocator.h"
 #include "gatt_int.h"
 #include "l2c_int.h"
 
@@ -812,7 +811,7 @@ void gatt_process_read_by_type_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8
             if ( p_clcb->counter == (p_clcb->p_tcb->payload_size - 4)) {
                 p_clcb->op_subtype = GATT_READ_BY_HANDLE;
                 if (!p_clcb->p_attr_buf) {
-                    p_clcb->p_attr_buf = (UINT8 *)GKI_getbuf(GATT_MAX_ATTR_LEN);
+                    p_clcb->p_attr_buf = (UINT8 *)osi_malloc(GATT_MAX_ATTR_LEN);
                 }
                 if (p_clcb->p_attr_buf && p_clcb->counter <= GATT_MAX_ATTR_LEN) {
                     memcpy(p_clcb->p_attr_buf, p, p_clcb->counter);
@@ -899,7 +898,7 @@ void gatt_process_read_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb,  UINT8 op_code,
 
             /* allocate GKI buffer holding up long attribute value  */
             if (!p_clcb->p_attr_buf) {
-                p_clcb->p_attr_buf = (UINT8 *)GKI_getbuf(GATT_MAX_ATTR_LEN);
+                p_clcb->p_attr_buf = (UINT8 *)osi_malloc(GATT_MAX_ATTR_LEN);
             }
 
             /* copy attrobute value into cb buffer  */
index 26cb5845b43567389c23d820809bc9ae402b8583..8518ea827a51fed21bf0d06a3564c3447545ef81 100644 (file)
@@ -27,7 +27,7 @@
 #if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE
 
 #include "bt_trace.h"
-//#include "bt_utils.h"
+#include "allocator.h"
 
 //#include <stdio.h>
 #include <string.h>
@@ -63,7 +63,9 @@ static BOOLEAN gatts_add_char_desc_value_check (tGATT_ATTR_VAL *attr_val, tGATTS
 BOOLEAN gatts_init_service_db (tGATT_SVC_DB *p_db, tBT_UUID *p_service,  BOOLEAN is_pri,
                                UINT16 s_hdl, UINT16 num_handle)
 {
-    GKI_init_q(&p_db->svc_buffer);
+    if (p_db->svc_buffer == NULL) { //in case already alloc
+        p_db->svc_buffer = fixed_queue_new(SIZE_MAX);
+    }
 
     if (!allocate_svc_db_buf(p_db)) {
         GATT_TRACE_ERROR("gatts_init_service_db failed, no resources\n");
@@ -509,7 +511,7 @@ UINT16 gatts_add_characteristic (tGATT_SVC_DB *p_db, tGATT_PERM perm,
             GATT_TRACE_DEBUG("attribute handle = %x\n", p_char_val->handle);
             p_char_val->p_value->attr_val.attr_len = attr_val->attr_len;
             p_char_val->p_value->attr_val.attr_max_len = attr_val->attr_max_len;
-            p_char_val->p_value->attr_val.attr_val = GKI_getbuf(attr_val->attr_max_len);
+            p_char_val->p_value->attr_val.attr_val = osi_malloc(attr_val->attr_max_len);
             if (p_char_val->p_value->attr_val.attr_val == NULL) {
                deallocate_attr_in_db(p_db, p_char_decl);
                deallocate_attr_in_db(p_db, p_char_val);
@@ -633,7 +635,7 @@ UINT16 gatts_add_char_descr (tGATT_SVC_DB *p_db, tGATT_PERM perm,
             p_char_dscptr->p_value->attr_val.attr_len = attr_val->attr_len;
             p_char_dscptr->p_value->attr_val.attr_max_len  = attr_val->attr_max_len;
             if (attr_val->attr_max_len != 0) {
-                p_char_dscptr->p_value->attr_val.attr_val = GKI_getbuf(attr_val->attr_max_len);
+                p_char_dscptr->p_value->attr_val.attr_val = osi_malloc(attr_val->attr_max_len);
                 if (p_char_dscptr->p_value->attr_val.attr_val == NULL) {
                     deallocate_attr_in_db(p_db, p_char_dscptr);
                     GATT_TRACE_WARNING("Warning in %s, line=%d, insufficient resource to allocate for descriptor value\n", __func__, __LINE__);
@@ -1335,16 +1337,15 @@ static BOOLEAN allocate_svc_db_buf(tGATT_SVC_DB *p_db)
 
     GATT_TRACE_DEBUG("allocate_svc_db_buf allocating extra buffer");
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf(GATT_DB_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_calloc(GATT_DB_BUF_SIZE)) == NULL) {
         GATT_TRACE_ERROR("allocate_svc_db_buf failed, no resources");
         return FALSE;
     }
 
-    memset(p_buf, 0, GKI_get_buf_size(p_buf));
     p_db->p_free_mem    = (UINT8 *) p_buf;
-    p_db->mem_free      = GKI_get_buf_size(p_buf);
+    p_db->mem_free = GATT_DB_BUF_SIZE;
 
-    GKI_enqueue(&p_db->svc_buffer, p_buf);
+    fixed_queue_enqueue(p_db->svc_buffer, p_buf);
 
     return TRUE;
 
index 7331d10c68023f4fd877a2c591d8daef90a3ad8a..bb226ba52d813d0f6af50f2e53a5320625d25e82 100644 (file)
 
 #if BLE_INCLUDED == TRUE
 
-#include "gki.h"
 #include "gatt_int.h"
 #include "l2c_api.h"
 #include "btm_int.h"
 #include "btm_ble_int.h"
-//#include "bt_utils.h"
+#include "allocator.h"
 
 /* Configuration flags. */
 #define GATT_L2C_CFG_IND_DONE   (1<<0)
@@ -105,9 +104,9 @@ void gatt_init (void)
     gatt_cb.trace_level = BT_TRACE_LEVEL_NONE;    /* No traces */
 #endif
     gatt_cb.def_mtu_size = GATT_DEF_BLE_MTU_SIZE;
-    GKI_init_q (&gatt_cb.sign_op_queue);
-    GKI_init_q (&gatt_cb.srv_chg_clt_q);
-    GKI_init_q (&gatt_cb.pending_new_srv_start_q);
+    gatt_cb.sign_op_queue = fixed_queue_new(SIZE_MAX);
+    gatt_cb.srv_chg_clt_q = fixed_queue_new(SIZE_MAX);
+    gatt_cb.pending_new_srv_start_q = fixed_queue_new(SIZE_MAX);
     /* First, register fixed L2CAP channel for ATT over BLE */
     fixed_reg.fixed_chnl_opts.mode         = L2CAP_FCR_BASIC_MODE;
     fixed_reg.fixed_chnl_opts.max_transmit = 0xFF;
@@ -155,6 +154,25 @@ void gatt_free(void)
 {
     int i;
     GATT_TRACE_DEBUG("gatt_free()");
+    fixed_queue_free(gatt_cb.sign_op_queue, NULL);
+    gatt_cb.sign_op_queue = NULL;
+    fixed_queue_free(gatt_cb.srv_chg_clt_q, NULL);
+    gatt_cb.srv_chg_clt_q = NULL;
+    fixed_queue_free(gatt_cb.pending_new_srv_start_q, NULL);
+    gatt_cb.pending_new_srv_start_q = NULL;
+
+    for (i = 0; i < GATT_MAX_PHY_CHANNEL; i++)
+    {
+        fixed_queue_free(gatt_cb.tcb[i].pending_enc_clcb, NULL);
+        gatt_cb.tcb[i].pending_enc_clcb = NULL;
+
+        fixed_queue_free(gatt_cb.tcb[i].pending_ind_q, NULL);
+        gatt_cb.tcb[i].pending_ind_q = NULL;
+
+        fixed_queue_free(gatt_cb.tcb[i].sr_cmd.multi_rsp_q, NULL);
+        gatt_cb.tcb[i].sr_cmd.multi_rsp_q = NULL;
+    }
+
     for (i = 0; i < GATT_MAX_SR_PROFILES; i++) {
         gatt_free_hdl_buffer(&gatt_cb.hdl_list[i]);
     }
@@ -351,6 +369,8 @@ BOOLEAN gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, tBT_TRANSPORT trans
         if ((p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, transport)) != NULL) {
             if (!gatt_connect(bd_addr,  p_tcb, transport)) {
                 GATT_TRACE_ERROR("gatt_connect failed");
+                fixed_queue_free(p_tcb->pending_enc_clcb, NULL);
+                fixed_queue_free(p_tcb->pending_ind_q, NULL);
                 memset(p_tcb, 0, sizeof(tGATT_TCB));
             } else {
                 ret = TRUE;
@@ -521,7 +541,7 @@ static void gatt_le_data_ind (UINT16 chan, BD_ADDR bd_addr, BT_HDR *p_buf)
             gatt_get_ch_state(p_tcb) >= GATT_CH_OPEN) {
         gatt_data_process(p_tcb, p_buf);
     } else {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
 
         if (p_tcb != NULL) {
             GATT_TRACE_WARNING ("ATT - Ignored L2CAP data while in state: %d\n",
@@ -824,7 +844,7 @@ static void gatt_l2cif_data_ind_cback(UINT16 lcid, BT_HDR *p_buf)
         /* process the data */
         gatt_data_process(p_tcb, p_buf);
     } else { /* prevent buffer leak */
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
     }
 
 }
@@ -947,7 +967,7 @@ void gatt_data_process (tGATT_TCB *p_tcb, BT_HDR *p_buf)
         GATT_TRACE_ERROR ("invalid data length, ignore\n");
     }
 
-    GKI_freebuf (p_buf);
+    osi_free (p_buf);
 }
 
 /*******************************************************************************
index 3d8259840f9d05c35f246d2814b095f7335518f8..cf6055e8c153d68630144c7adb3f4a5911500899 100644 (file)
@@ -23,7 +23,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
-//#include "bt_utils.h"
+#include "allocator.h"
 
 #if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE
 #include <string.h>
@@ -56,7 +56,7 @@ tGATT_STATUS gatt_send_packet (tGATT_TCB *p_tcb, UINT8 *p_data, UINT16 len)
     }
 
     buf_len = (UINT16)(sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET);
-    if ((p_msg = (BT_HDR *)GKI_getbuf(buf_len)) == NULL) {
+    if ((p_msg = (BT_HDR *)osi_malloc(buf_len)) == NULL) {
         return GATT_NO_RESOURCES;
     }
 
@@ -134,12 +134,17 @@ void gatt_dequeue_sr_cmd (tGATT_TCB *p_tcb)
     if (p_tcb->sr_cmd.p_rsp_msg) {
         GATT_TRACE_ERROR("%s free msg %p", __func__, p_tcb->sr_cmd.p_rsp_msg);
 
-        GKI_freebuf (p_tcb->sr_cmd.p_rsp_msg);
+        osi_free(p_tcb->sr_cmd.p_rsp_msg);
+        p_tcb->sr_cmd.p_rsp_msg = NULL;
     }
 
-    while (GKI_getfirst(&p_tcb->sr_cmd.multi_rsp_q)) {
-        GKI_freebuf (GKI_dequeue (&p_tcb->sr_cmd.multi_rsp_q));
+    if (p_tcb->sr_cmd.multi_rsp_q) {
+        while (!fixed_queue_is_empty(p_tcb->sr_cmd.multi_rsp_q)) {
+            osi_free(fixed_queue_try_dequeue(p_tcb->sr_cmd.multi_rsp_q));
+        }
+        fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, NULL);
     }
+
     memset( &p_tcb->sr_cmd, 0, sizeof(tGATT_SR_CMD));
 }
 
@@ -155,36 +160,39 @@ void gatt_dequeue_sr_cmd (tGATT_TCB *p_tcb)
 static BOOLEAN process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status,
                                        tGATTS_RSP *p_msg, UINT16 mtu)
 {
-    tGATTS_RSP       *p_rsp = NULL;
     UINT16          ii, total_len, len;
-    BT_HDR          *p_buf = (BT_HDR *)GKI_getbuf((UINT16)sizeof(tGATTS_RSP));
     UINT8           *p;
     BOOLEAN         is_overflow = FALSE;
 
     GATT_TRACE_DEBUG ("process_read_multi_rsp status=%d mtu=%d", status, mtu);
 
+       if (p_cmd->multi_rsp_q == NULL) {
+        p_cmd->multi_rsp_q = fixed_queue_new(SIZE_MAX);
+       }
+
+    /* Enqueue the response */
+    BT_HDR  *p_buf = (BT_HDR *)osi_malloc(sizeof(tGATTS_RSP));
     if (p_buf == NULL) {
         p_cmd->status = GATT_INSUF_RESOURCE;
         return FALSE;
     }
-
-    /* Enqueue the response */
     memcpy((void *)p_buf, (const void *)p_msg, sizeof(tGATTS_RSP));
-    GKI_enqueue (&p_cmd->multi_rsp_q, p_buf);
+
+    fixed_queue_enqueue(p_cmd->multi_rsp_q, p_buf);
 
     p_cmd->status = status;
     if (status == GATT_SUCCESS) {
         GATT_TRACE_DEBUG ("Multi read count=%d num_hdls=%d",
-                          GKI_queue_length(&p_cmd->multi_rsp_q), p_cmd->multi_req.num_handles);
+                         fixed_queue_length(p_cmd->multi_rsp_q),
+                         p_cmd->multi_req.num_handles);
         /* Wait till we get all the responses */
-        if (GKI_queue_length(&p_cmd->multi_rsp_q) == p_cmd->multi_req.num_handles) {
+        if (fixed_queue_length(p_cmd->multi_rsp_q) == p_cmd->multi_req.num_handles) {
             len = sizeof(BT_HDR) + L2CAP_MIN_OFFSET + mtu;
-            if ((p_buf = (BT_HDR *)GKI_getbuf(len)) == NULL) {
+            if ((p_buf = (BT_HDR *)osi_calloc(len)) == NULL) {
                 p_cmd->status = GATT_INSUF_RESOURCE;
                 return (TRUE);
             }
 
-            memset(p_buf, 0, len);
             p_buf->offset = L2CAP_MIN_OFFSET;
             p = (UINT8 *)(p_buf + 1) + p_buf->offset;
 
@@ -193,11 +201,22 @@ static BOOLEAN process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status,
             p_buf->len = 1;
 
             /* Now walk through the buffers puting the data into the response in order */
+            list_t *list = NULL;
+            const list_node_t *node = NULL;
+            if (! fixed_queue_is_empty(p_cmd->multi_rsp_q)) {
+                list = fixed_queue_get_list(p_cmd->multi_rsp_q);
+                       }
             for (ii = 0; ii < p_cmd->multi_req.num_handles; ii++) {
-                if (ii == 0) {
-                    p_rsp = (tGATTS_RSP *)GKI_getfirst (&p_cmd->multi_rsp_q);
-                } else {
-                    p_rsp = (tGATTS_RSP *)GKI_getnext (p_rsp);
+                tGATTS_RSP *p_rsp = NULL;
+                if (list != NULL) {
+                    if (ii == 0) {
+                        node = list_begin(list);
+                    } else {
+                        node = list_next(node);
+                                       }
+                    if (node != list_end(list)) {
+                        p_rsp = (tGATTS_RSP *)list_node(node);
+                                       }
                 }
 
                 if (p_rsp != NULL) {
@@ -240,10 +259,10 @@ static BOOLEAN process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status,
             if (p_buf->len == 0) {
                 GATT_TRACE_ERROR("process_read_multi_rsp - nothing found!!");
                 p_cmd->status = GATT_NOT_FOUND;
-                GKI_freebuf (p_buf);
-                GATT_TRACE_DEBUG(" GKI_freebuf (p_buf)");
+                osi_free (p_buf);
+                GATT_TRACE_DEBUG(" osi_free (p_buf)");
             } else if (p_cmd->p_rsp_msg != NULL) {
-                GKI_freebuf (p_buf);
+                osi_free (p_buf);
             } else {
                 p_cmd->p_rsp_msg = p_buf;
             }
@@ -363,8 +382,7 @@ void gatt_process_exec_write_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, U
     flag &= GATT_PREP_WRITE_EXEC;
 
     prepare_record = &(p_tcb->prepare_write_record);
-    queue_num = prepare_record->queue._count;
-    
+    queue_num = fixed_queue_length(prepare_record->queue);
 
     //if received prepare_write packets include stack_rsp and app_rsp, 
     //stack respond to execute_write only when stack_rsp handle has invalid_offset
@@ -398,15 +416,17 @@ void gatt_process_exec_write_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, U
     }
 
     //dequeue prepare write data
-    while(GKI_getfirst(&(prepare_record->queue))) {
-        queue_data = GKI_dequeue(&(prepare_record->queue));
+    while(fixed_queue_try_peek_first(prepare_record->queue)) {
+        queue_data = fixed_queue_dequeue(prepare_record->queue);
         if (is_prepare_write_valid){
             if((queue_data->p_attr->p_value != NULL) && (queue_data->p_attr->p_value->attr_val.attr_val != NULL)){
                 memcpy(queue_data->p_attr->p_value->attr_val.attr_val+queue_data->offset, queue_data->value, queue_data->len);
             }
         }
-        GKI_freebuf(queue_data);
-    } 
+        osi_free(queue_data);
+    }
+    fixed_queue_free(prepare_record->queue, NULL);
+    prepare_record->queue = NULL;
 
     /* according to ble spec, even if there is no prep write queued, 
      * need to respond execute_write_response
@@ -510,7 +530,7 @@ void gatt_process_read_multi_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, U
             gatt_sr_reset_cback_cnt(p_tcb); /* read multiple use multi_rsp_q's count*/
 
             for (ll = 0; ll < p_tcb->sr_cmd.multi_req.num_handles; ll ++) {
-                if ((p_msg = (tGATTS_RSP *)GKI_getbuf(sizeof(tGATTS_RSP))) != NULL) {
+                if ((p_msg = (tGATTS_RSP *)osi_malloc(sizeof(tGATTS_RSP))) != NULL) {
                     memset(p_msg, 0, sizeof(tGATTS_RSP))
                     ;
                     handle = p_tcb->sr_cmd.multi_req.handles[ll];
@@ -533,7 +553,7 @@ void gatt_process_read_multi_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, U
                         gatt_sr_process_app_rsp(p_tcb, gatt_cb.sr_reg[i_rcb].gatt_if , trans_id, op_code, GATT_SUCCESS, p_msg);
                     }
                     /* either not using or done using the buffer, release it now */
-                    GKI_freebuf(p_msg);
+                    osi_free(p_msg);
                 } else {
                     err = GATT_NO_RESOURCES;
                     gatt_dequeue_sr_cmd(p_tcb);
@@ -795,11 +815,10 @@ void gatts_process_primary_service_req(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 l
             }
 
             if (reason == GATT_SUCCESS) {
-                if ((p_msg =  (BT_HDR *)GKI_getbuf(msg_len)) == NULL) {
+                if ((p_msg =  (BT_HDR *)osi_calloc(msg_len)) == NULL) {
                     GATT_TRACE_ERROR("gatts_process_primary_service_req failed. no resources.");
                     reason = GATT_NO_RESOURCES;
                 } else {
-                    memset(p_msg, 0, msg_len);
                     reason = gatt_build_primary_service_rsp (p_msg, p_tcb, op_code, s_hdl, e_hdl, p_data, value);
                 }
             }
@@ -817,7 +836,7 @@ void gatts_process_primary_service_req(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 l
 
     if (reason != GATT_SUCCESS) {
         if (p_msg) {
-            GKI_freebuf(p_msg);
+            osi_free(p_msg);
         }
         gatt_send_error_rsp (p_tcb, reason, op_code, s_hdl, FALSE);
     } else {
@@ -850,12 +869,11 @@ static void gatts_process_find_info(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len,
     if (reason == GATT_SUCCESS) {
         buf_len = (UINT16)(sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET);
 
-        if ((p_msg =  (BT_HDR *)GKI_getbuf(buf_len)) == NULL) {
+        if ((p_msg =  (BT_HDR *)osi_calloc(buf_len)) == NULL) {
             reason = GATT_NO_RESOURCES;
         } else {
             reason = GATT_NOT_FOUND;
 
-            memset(p_msg, 0, buf_len);
             p = (UINT8 *)(p_msg + 1) + L2CAP_MIN_OFFSET;
             *p ++ = op_code + 1;
             p_msg->len = 2;
@@ -886,7 +904,7 @@ static void gatts_process_find_info(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len,
 
     if (reason != GATT_SUCCESS) {
         if (p_msg) {
-            GKI_freebuf(p_msg);
+            osi_free(p_msg);
         }
         gatt_send_error_rsp (p_tcb, reason, op_code, s_hdl, FALSE);
     } else {
@@ -993,12 +1011,11 @@ void gatts_process_read_by_type_req(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len,
 #endif
 
     if (reason == GATT_SUCCESS) {
-        if ((p_msg =  (BT_HDR *)GKI_getbuf(msg_len)) == NULL) {
+        if ((p_msg =  (BT_HDR *)osi_calloc(msg_len)) == NULL) {
             GATT_TRACE_ERROR("gatts_process_find_info failed. no resources.\n");
 
             reason = GATT_NO_RESOURCES;
         } else {
-            memset(p_msg, 0, msg_len);
             p = (UINT8 *)(p_msg + 1) + L2CAP_MIN_OFFSET;
 
             *p ++ = op_code + 1;
@@ -1053,7 +1070,7 @@ void gatts_process_read_by_type_req(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len,
     }
     if (reason != GATT_SUCCESS && reason != GATT_STACK_RSP) {
         if (p_msg) {
-            GKI_freebuf(p_msg);
+            osi_free(p_msg);
         }
 
         /* in theroy BUSY is not possible(should already been checked), protected check */
@@ -1254,7 +1271,7 @@ void gatt_attr_process_prepare_write (tGATT_TCB *p_tcb, UINT8 i_rcb, UINT16 hand
     }
 
     if (is_need_queue_data){
-        queue_data = (tGATT_PREPARE_WRITE_QUEUE_DATA *)GKI_getbuf(len + sizeof(tGATT_PREPARE_WRITE_QUEUE_DATA));
+        queue_data = (tGATT_PREPARE_WRITE_QUEUE_DATA *)osi_malloc(len + sizeof(tGATT_PREPARE_WRITE_QUEUE_DATA));
         if (queue_data == NULL){
             status = GATT_PREPARE_Q_FULL;
         } else {
@@ -1263,7 +1280,10 @@ void gatt_attr_process_prepare_write (tGATT_TCB *p_tcb, UINT8 i_rcb, UINT16 hand
             queue_data->handle = handle;
             queue_data->offset = offset;
             memcpy(queue_data->value, p, len);
-            GKI_enqueue(&(prepare_record->queue), queue_data);
+            if (prepare_record->queue == NULL) {
+                prepare_record->queue = fixed_queue_new(SIZE_MAX);
+            }
+            fixed_queue_enqueue(prepare_record->queue, queue_data);
         }
     }
     
@@ -1327,7 +1347,7 @@ static void gatts_process_read_req(tGATT_TCB *p_tcb, tGATT_SR_REG *p_rcb, UINT8
     UINT16       offset = 0, value_len = 0;
 
     UNUSED (len);
-    if ((p_msg =  (BT_HDR *)GKI_getbuf(buf_len)) == NULL) {
+    if ((p_msg =  (BT_HDR *)osi_calloc(buf_len)) == NULL) {
         GATT_TRACE_ERROR("gatts_process_find_info failed. no resources.\n");
 
         reason = GATT_NO_RESOURCES;
@@ -1336,7 +1356,6 @@ static void gatts_process_read_req(tGATT_TCB *p_tcb, tGATT_SR_REG *p_rcb, UINT8
             STREAM_TO_UINT16(offset, p_data);
         }
 
-        memset(p_msg, 0, buf_len);
         p = (UINT8 *)(p_msg + 1) + L2CAP_MIN_OFFSET;
         *p ++ = op_code + 1;
         p_msg->len = 1;
@@ -1365,7 +1384,7 @@ static void gatts_process_read_req(tGATT_TCB *p_tcb, tGATT_SR_REG *p_rcb, UINT8
 
     if (reason != GATT_SUCCESS && reason != GATT_PENDING && reason != GATT_STACK_RSP) {
         if (p_msg) {
-            GKI_freebuf(p_msg);
+            osi_free(p_msg);
         }
 
         /* in theroy BUSY is not possible(should already been checked), protected check */
@@ -1378,7 +1397,7 @@ static void gatts_process_read_req(tGATT_TCB *p_tcb, tGATT_SR_REG *p_rcb, UINT8
         gatt_dequeue_sr_cmd(p_tcb);
     } else {
         if (p_msg) {
-            GKI_freebuf(p_msg);
+            osi_free(p_msg);
         }
     }
 
@@ -1500,7 +1519,7 @@ static void gatts_proc_srv_chg_ind_ack(tGATT_TCB *p_tcb )
 static void gatts_chk_pending_ind(tGATT_TCB *p_tcb )
 {
 #if (GATTS_INCLUDED == TRUE)
-    tGATT_VALUE *p_buf = (tGATT_VALUE *)GKI_getfirst(&p_tcb->pending_ind_q);
+    tGATT_VALUE *p_buf = (tGATT_VALUE *)fixed_queue_try_peek_first(p_tcb->pending_ind_q);
     GATT_TRACE_DEBUG("gatts_chk_pending_ind");
 
     if (p_buf ) {
@@ -1508,7 +1527,8 @@ static void gatts_chk_pending_ind(tGATT_TCB *p_tcb )
                                      p_buf->handle,
                                      p_buf->len,
                                      p_buf->value);
-        GKI_freebuf(GKI_remove_from_queue (&p_tcb->pending_ind_q, p_buf));
+        osi_free(fixed_queue_try_remove_from_queue(p_tcb->pending_ind_q,
+                                                      p_buf));
     }
 #endif  ///GATTS_INCLUDED == TRUE
 }
index ac51e19662478b3d2926359cb25d54456be40aac..30b618001b214c66411b0964d234e6fe2fceb246 100644 (file)
  *
  ******************************************************************************/
 #include "bt_target.h"
-//#include "bt_utils.h"
+#include "allocator.h"
 
 #if BLE_INCLUDED == TRUE
 #include <string.h>
 #include <stdio.h>
-#include "gki.h"
 
 #include "l2cdefs.h"
 #include "gatt_int.h"
@@ -92,10 +91,16 @@ static const UINT8  base_uuid[LEN_UUID_128] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x0
 void gatt_free_pending_ind(tGATT_TCB *p_tcb)
 {
     GATT_TRACE_DEBUG("gatt_free_pending_ind");
-    /* release all queued indications */
-    while (!GKI_queue_is_empty(&p_tcb->pending_ind_q)) {
-        GKI_freebuf (GKI_dequeue (&p_tcb->pending_ind_q));
+    if (p_tcb->pending_ind_q == NULL) {
+        return;
     }
+       
+    /* release all queued indications */
+    while (!fixed_queue_is_empty(p_tcb->pending_ind_q)) {
+        osi_free(fixed_queue_try_dequeue(p_tcb->pending_ind_q));
+       }
+    fixed_queue_free(p_tcb->pending_ind_q, NULL);
+    p_tcb->pending_ind_q = NULL;
 }
 
 /*******************************************************************************
@@ -110,10 +115,16 @@ void gatt_free_pending_ind(tGATT_TCB *p_tcb)
 void gatt_free_pending_enc_queue(tGATT_TCB *p_tcb)
 {
     GATT_TRACE_DEBUG("gatt_free_pending_enc_queue");
+    if (p_tcb->pending_enc_clcb == NULL) {
+        return;
+    }
+       
     /* release all queued indications */
-    while (!GKI_queue_is_empty(&p_tcb->pending_enc_clcb)) {
-        GKI_freebuf (GKI_dequeue (&p_tcb->pending_enc_clcb));
+    while (!fixed_queue_is_empty(p_tcb->pending_enc_clcb)) {
+        osi_free(fixed_queue_try_dequeue(p_tcb->pending_enc_clcb));
     }
+       fixed_queue_free(p_tcb->pending_enc_clcb, NULL);
+    p_tcb->pending_enc_clcb = NULL;
 }
 
 /*******************************************************************************
@@ -128,10 +139,16 @@ void gatt_free_pending_enc_queue(tGATT_TCB *p_tcb)
 void gatt_free_pending_prepare_write_queue(tGATT_TCB *p_tcb)
 {
     GATT_TRACE_DEBUG("gatt_free_pending_prepare_write_queue");
-    /* release all queued prepare write packets */
-    while (!GKI_queue_is_empty(&(p_tcb->prepare_write_record.queue))) {
-        GKI_freebuf (GKI_dequeue (&(p_tcb->prepare_write_record.queue)));
+
+    if (p_tcb->prepare_write_record.queue) {
+        /* release all queued prepare write packets */
+        while (!fixed_queue_is_empty(p_tcb->prepare_write_record.queue)) {
+            osi_free(fixed_queue_dequeue(p_tcb->prepare_write_record.queue));
+        }
+        fixed_queue_free(p_tcb->prepare_write_record.queue, NULL);
+        p_tcb->prepare_write_record.queue = NULL;
     }
+
     p_tcb->prepare_write_record.total_num = 0;
     p_tcb->prepare_write_record.error_code_app = GATT_SUCCESS;
 }
@@ -157,7 +174,8 @@ void gatt_delete_dev_from_srv_chg_clt_list(BD_ADDR bd_addr)
             memcpy(req.srv_chg.bda, bd_addr, BD_ADDR_LEN);
             (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_REMOVE_CLIENT, &req, NULL);
         }
-        GKI_freebuf (GKI_remove_from_queue (&gatt_cb.srv_chg_clt_q, p_buf));
+        osi_free(fixed_queue_try_remove_from_queue(gatt_cb.srv_chg_clt_q,
+                                                      p_buf));
     }
 
 }
@@ -173,21 +191,27 @@ void gatt_delete_dev_from_srv_chg_clt_list(BD_ADDR bd_addr)
 *******************************************************************************/
 void gatt_set_srv_chg(void)
 {
-    tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)GKI_getfirst(&gatt_cb.srv_chg_clt_q);
-    tGATTS_SRV_CHG_REQ req;
-
     GATT_TRACE_DEBUG ("gatt_set_srv_chg");
-    while (p_buf) {
+
+    if (fixed_queue_is_empty(gatt_cb.srv_chg_clt_q)) {
+        return;
+       }
+
+    list_t *list = fixed_queue_get_list(gatt_cb.srv_chg_clt_q);
+    for (const list_node_t *node = list_begin(list); node != list_end(list);
+         node = list_next(node)) {
         GATT_TRACE_DEBUG ("found a srv_chg clt");
+
+        tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)list_node(node);
         if (!p_buf->srv_changed) {
-            GATT_TRACE_DEBUG ("set srv_changed to TRUE");
+            GATT_TRACE_DEBUG("set srv_changed to TRUE");
             p_buf->srv_changed = TRUE;
+            tGATTS_SRV_CHG_REQ req;
             memcpy(&req.srv_chg, p_buf, sizeof(tGATTS_SRV_CHG));
             if (gatt_cb.cb_info.p_srv_chg_callback) {
-                (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_UPDATE_CLIENT, &req, NULL);
-            }
+                (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_UPDATE_CLIENT,&req, NULL);
+                       }
         }
-        p_buf = (tGATTS_SRV_CHG *)GKI_getnext(p_buf);
     }
 }
 
@@ -202,18 +226,23 @@ void gatt_set_srv_chg(void)
 *******************************************************************************/
 tGATTS_PENDING_NEW_SRV_START *gatt_sr_is_new_srv_chg(tBT_UUID *p_app_uuid128, tBT_UUID *p_svc_uuid, UINT16 svc_inst)
 {
-    tGATTS_HNDL_RANGE *p;
-    tGATTS_PENDING_NEW_SRV_START *p_buf = (tGATTS_PENDING_NEW_SRV_START *)GKI_getfirst(&gatt_cb.pending_new_srv_start_q);
+    tGATTS_PENDING_NEW_SRV_START *p_buf = NULL;
 
-    while (p_buf != NULL) {
-        p = p_buf->p_new_srv_start;
-        if (  gatt_uuid_compare (*p_app_uuid128, p->app_uuid128)
-                &&  gatt_uuid_compare (*p_svc_uuid, p->svc_uuid)
-                &&  (svc_inst == p->svc_inst) ) {
-            GATT_TRACE_DEBUG ("gatt_sr_is_new_srv_chg: Yes");
+    if (fixed_queue_is_empty(gatt_cb.pending_new_srv_start_q)) {
+        return NULL;
+       }
+
+    list_t *list = fixed_queue_get_list(gatt_cb.pending_new_srv_start_q);
+    for (const list_node_t *node = list_begin(list); node != list_end(list);
+         node = list_next(node)) {
+        p_buf = (tGATTS_PENDING_NEW_SRV_START *)list_node(node);
+        tGATTS_HNDL_RANGE *p = p_buf->p_new_srv_start;
+        if (gatt_uuid_compare(*p_app_uuid128, p->app_uuid128)
+            && gatt_uuid_compare (*p_svc_uuid, p->svc_uuid)
+            && (svc_inst == p->svc_inst)) {
+            GATT_TRACE_DEBUG("gatt_sr_is_new_srv_chg: Yes");
             break;
         }
-        p_buf = (tGATTS_PENDING_NEW_SRV_START *)GKI_getnext(p_buf);
     }
 
     return p_buf;
@@ -233,10 +262,10 @@ tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB  *p_tcb, tGATT_VALUE *p_ind)
 {
     tGATT_VALUE   *p_buf;
     GATT_TRACE_DEBUG ("gatt_add_pending_ind");
-    if ((p_buf = (tGATT_VALUE *)GKI_getbuf((UINT16)sizeof(tGATT_VALUE))) != NULL) {
+    if ((p_buf = (tGATT_VALUE *)osi_malloc((UINT16)sizeof(tGATT_VALUE))) != NULL) {
         GATT_TRACE_DEBUG ("enqueue a pending indication");
         memcpy(p_buf, p_ind, sizeof(tGATT_VALUE));
-        GKI_enqueue (&p_tcb->pending_ind_q, p_buf);
+    fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf);
     }
     return p_buf;
 }
@@ -256,10 +285,10 @@ tGATTS_PENDING_NEW_SRV_START *gatt_add_pending_new_srv_start(tGATTS_HNDL_RANGE *
     tGATTS_PENDING_NEW_SRV_START   *p_buf;
 
     GATT_TRACE_DEBUG ("gatt_add_pending_new_srv_start");
-    if ((p_buf = (tGATTS_PENDING_NEW_SRV_START *)GKI_getbuf((UINT16)sizeof(tGATTS_PENDING_NEW_SRV_START))) != NULL) {
+    if ((p_buf = (tGATTS_PENDING_NEW_SRV_START *)osi_malloc((UINT16)sizeof(tGATTS_PENDING_NEW_SRV_START))) != NULL) {
         GATT_TRACE_DEBUG ("enqueue a new pending new srv start");
         p_buf->p_new_srv_start = p_new_srv_start;
-        GKI_enqueue (&gatt_cb.pending_new_srv_start_q, p_buf);
+    fixed_queue_enqueue(gatt_cb.pending_new_srv_start_q, p_buf);
     }
     return p_buf;
 }
@@ -278,10 +307,10 @@ tGATTS_SRV_CHG *gatt_add_srv_chg_clt(tGATTS_SRV_CHG *p_srv_chg)
 {
     tGATTS_SRV_CHG *p_buf;
     GATT_TRACE_DEBUG ("gatt_add_srv_chg_clt");
-    if ((p_buf = (tGATTS_SRV_CHG *)GKI_getbuf((UINT16)sizeof(tGATTS_SRV_CHG))) != NULL) {
+    if ((p_buf = (tGATTS_SRV_CHG *)osi_malloc((UINT16)sizeof(tGATTS_SRV_CHG))) != NULL) {
         GATT_TRACE_DEBUG ("enqueue a srv chg client");
         memcpy(p_buf, p_srv_chg, sizeof(tGATTS_SRV_CHG));
-        GKI_enqueue (&gatt_cb.srv_chg_clt_q, p_buf);
+    fixed_queue_enqueue(gatt_cb.srv_chg_clt_q, p_buf);
     }
 
     return p_buf;
@@ -308,6 +337,7 @@ tGATT_HDL_LIST_ELEM *gatt_alloc_hdl_buffer(void)
         if (!p_cb->hdl_list[i].in_use) {
             memset(p_elem, 0, sizeof(tGATT_HDL_LIST_ELEM));
             p_elem->in_use = TRUE;
+            p_elem->svc_db.svc_buffer = fixed_queue_new(SIZE_MAX);
             return p_elem;
         }
     }
@@ -418,7 +448,7 @@ void gatt_free_attr_value_buffer(tGATT_HDL_LIST_ELEM *p)
             if (p_attr->mask & GATT_ATTR_VALUE_ALLOCATED){
                 p_value = p_attr->p_value;
                 if ((p_value != NULL) && (p_value->attr_val.attr_val != NULL)){
-                    GKI_freebuf(p_value->attr_val.attr_val);
+                    osi_free(p_value->attr_val.attr_val);
                 }
             }
             p_attr = p_attr->p_next;
@@ -438,9 +468,10 @@ void gatt_free_hdl_buffer(tGATT_HDL_LIST_ELEM *p)
 {
 
     if (p) {
-        while (!GKI_queue_is_empty(&p->svc_db.svc_buffer)) {
-            GKI_freebuf (GKI_dequeue (&p->svc_db.svc_buffer));
-        }
+        while (!fixed_queue_is_empty(p->svc_db.svc_buffer)) {
+            osi_free(fixed_queue_try_dequeue(p->svc_db.svc_buffer));
+               }
+        fixed_queue_free(p->svc_db.svc_buffer, NULL);
         memset(p, 0, sizeof(tGATT_HDL_LIST_ELEM));
     }
 }
@@ -463,9 +494,11 @@ void gatt_free_srvc_db_buffer_app_id(tBT_UUID *p_app_id)
     for (i = 0; i < GATT_MAX_SR_PROFILES; i ++, p_elem ++) {
         if (memcmp(p_app_id, &p_elem->asgn_range.app_uuid128, sizeof(tBT_UUID)) == 0) {
             gatt_free_attr_value_buffer(p_elem);
-            while (!GKI_queue_is_empty(&p_elem->svc_db.svc_buffer)) {
-                GKI_freebuf (GKI_dequeue (&p_elem->svc_db.svc_buffer));
-            }
+            while (!fixed_queue_is_empty(p_elem->svc_db.svc_buffer)) {
+                osi_free(fixed_queue_try_dequeue(p_elem->svc_db.svc_buffer));
+                       }
+            fixed_queue_free(p_elem->svc_db.svc_buffer, NULL);
+            p_elem->svc_db.svc_buffer = NULL;
 
             p_elem->svc_db.mem_free = 0;
             p_elem->svc_db.p_attr_list = p_elem->svc_db.p_free_mem = NULL;
@@ -779,20 +812,24 @@ BOOLEAN gatt_find_the_connected_bda(UINT8 start_idx, BD_ADDR bda, UINT8 *p_found
 *******************************************************************************/
 BOOLEAN gatt_is_srv_chg_ind_pending (tGATT_TCB *p_tcb)
 {
-    tGATT_VALUE *p_buf = (tGATT_VALUE *)GKI_getfirst(&p_tcb->pending_ind_q);
     BOOLEAN srv_chg_ind_pending = FALSE;
 
-    GATT_TRACE_DEBUG("gatt_is_srv_chg_ind_pending is_queue_empty=%d", GKI_queue_is_empty(&p_tcb->pending_ind_q) );
+    GATT_TRACE_DEBUG("gatt_is_srv_chg_ind_pending is_queue_empty=%d",
+                     fixed_queue_is_empty(p_tcb->pending_ind_q));
 
     if (p_tcb->indicate_handle == gatt_cb.handle_of_h_r) {
         srv_chg_ind_pending = TRUE;
-    } else {
-        while (p_buf) {
-            if (p_buf->handle == gatt_cb.handle_of_h_r) {
+    } else if (! fixed_queue_is_empty(p_tcb->pending_ind_q)) {
+        list_t *list = fixed_queue_get_list(p_tcb->pending_ind_q);
+        for (const list_node_t *node = list_begin(list);
+             node != list_end(list);
+             node = list_next(node)) {
+            tGATT_VALUE *p_buf = (tGATT_VALUE *)list_node(node);
+            if (p_buf->handle == gatt_cb.handle_of_h_r)
+            {
                 srv_chg_ind_pending = TRUE;
                 break;
             }
-            p_buf = (tGATT_VALUE *)GKI_getnext(p_buf);
         }
     }
 
@@ -812,17 +849,23 @@ BOOLEAN gatt_is_srv_chg_ind_pending (tGATT_TCB *p_tcb)
 *******************************************************************************/
 tGATTS_SRV_CHG *gatt_is_bda_in_the_srv_chg_clt_list (BD_ADDR bda)
 {
-    tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)GKI_getfirst(&gatt_cb.srv_chg_clt_q);
+    tGATTS_SRV_CHG *p_buf = NULL;
 
     GATT_TRACE_DEBUG("gatt_is_bda_in_the_srv_chg_clt_list :%02x-%02x-%02x-%02x-%02x-%02x",
                      bda[0],  bda[1], bda[2],  bda[3], bda[4],  bda[5]);
 
-    while (p_buf != NULL) {
+    if (fixed_queue_is_empty(gatt_cb.srv_chg_clt_q)) {
+        return NULL;
+       }
+
+    list_t *list = fixed_queue_get_list(gatt_cb.srv_chg_clt_q);
+    for (const list_node_t *node = list_begin(list); node != list_end(list);
+         node = list_next(node)) {
+        tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)list_node(node);
         if (!memcmp( bda, p_buf->bda, BD_ADDR_LEN)) {
             GATT_TRACE_DEBUG("bda is in the srv chg clt list");
             break;
         }
-        p_buf = (tGATTS_SRV_CHG *)GKI_getnext(p_buf);
     }
 
     return p_buf;
@@ -964,8 +1007,8 @@ tGATT_TCB *gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, tBT_TRANSPORT transport)
 
         if (allocated) {
             memset(p_tcb, 0, sizeof(tGATT_TCB));
-            GKI_init_q (&p_tcb->pending_enc_clcb);
-            GKI_init_q (&p_tcb->pending_ind_q);
+            p_tcb->pending_enc_clcb = fixed_queue_new(SIZE_MAX);
+            p_tcb->pending_ind_q = fixed_queue_new(SIZE_MAX);
             p_tcb->in_use = TRUE;
             p_tcb->tcb_idx = i;
             p_tcb->transport = transport;
@@ -1357,7 +1400,7 @@ UINT8 gatt_sr_alloc_rcb(tGATT_HDL_LIST_ELEM *p_list )
             p_sreg->e_hdl               = p_list->asgn_range.e_handle;
             p_sreg->p_db                = &p_list->svc_db;
 
-            GATT_TRACE_DEBUG ("total GKI buffer in db [%d]", GKI_queue_length(&p_sreg->p_db->svc_buffer));
+            GATT_TRACE_DEBUG ("total buffer in db [%d]", fixed_queue_length(p_sreg->p_db->svc_buffer));
             break;
         }
     }
@@ -2112,7 +2155,7 @@ void gatt_end_operation(tGATT_CLCB *p_clcb, tGATT_STATUS status, void *p_data)
     }
 
     if (p_clcb->p_attr_buf) {
-        GKI_freebuf(p_clcb->p_attr_buf);
+        osi_free(p_clcb->p_attr_buf);
     }
 
     operation =  p_clcb->operation;
@@ -2173,6 +2216,8 @@ void gatt_cleanup_upon_disc(BD_ADDR bda, UINT16 reason, tBT_TRANSPORT transport)
         gatt_free_pending_ind(p_tcb);
         gatt_free_pending_enc_queue(p_tcb);
         gatt_free_pending_prepare_write_queue(p_tcb);
+        fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, osi_free_func);
+        p_tcb->sr_cmd.multi_rsp_q = NULL;
 
         for (i = 0; i < GATT_MAX_APPS; i ++) {
             p_reg = &gatt_cb.cl_rcb[i];
@@ -2650,10 +2695,10 @@ tGATT_PENDING_ENC_CLCB *gatt_add_pending_enc_channel_clcb(tGATT_TCB *p_tcb, tGAT
     tGATT_PENDING_ENC_CLCB   *p_buf;
 
     GATT_TRACE_DEBUG ("gatt_add_pending_new_srv_start");
-    if ((p_buf = (tGATT_PENDING_ENC_CLCB *)GKI_getbuf((UINT16)sizeof(tGATT_PENDING_ENC_CLCB))) != NULL) {
+    if ((p_buf = (tGATT_PENDING_ENC_CLCB *)osi_malloc((UINT16)sizeof(tGATT_PENDING_ENC_CLCB))) != NULL) {
         GATT_TRACE_DEBUG ("enqueue a new pending encryption channel clcb");
         p_buf->p_clcb = p_clcb;
-        GKI_enqueue (&p_tcb->pending_enc_clcb, p_buf);
+    fixed_queue_enqueue(p_tcb->pending_enc_clcb, p_buf);
     }
     return p_buf;
 }
index b538ed8b5c49696900cc101a1a9b70ac7408d0f2..eee0d2858b01033915a889af5ed17d2df2ce8270 100644 (file)
 #define  GATT_INT_H
 
 #include "bt_target.h"
-
-
 #include "bt_trace.h"
 #include "gatt_api.h"
 #include "btm_ble_api.h"
 #include "btu.h"
+#include "fixed_queue.h"
 
 #include <string.h>
 
@@ -222,7 +221,7 @@ typedef struct {
 typedef struct {
     void            *p_attr_list;       /* pointer to the first attribute, either tGATT_ATTR16 or tGATT_ATTR128 */
     UINT8           *p_free_mem;        /* Pointer to free memory       */
-    BUFFER_Q        svc_buffer;         /* buffer queue used for service database */
+    fixed_queue_t   *svc_buffer;         /* buffer queue used for service database */
     UINT32          mem_free;           /* Memory still available       */
     UINT16          end_handle;         /* Last handle number           */
     UINT16          next_handle;        /* Next usable handle value     */
@@ -285,7 +284,7 @@ typedef struct {
     BT_HDR          *p_rsp_msg;
     UINT32           trans_id;
     tGATT_READ_MULTI multi_req;
-    BUFFER_Q         multi_rsp_q;
+    fixed_queue_t    *multi_rsp_q;
     UINT16           handle;
     UINT8            op_code;
     UINT8            status;
@@ -357,7 +356,7 @@ typedef struct{
 typedef struct{
     //only store prepare write packets which need
     //to be responded by stack (not by application)
-    BUFFER_Q queue;
+    fixed_queue_t *queue;
 
     //store the total number of prepare write packets
     //including that should be responded by stack or by application
@@ -369,7 +368,7 @@ typedef struct{
 }tGATT_PREPARE_WRITE_RECORD;
 
 typedef struct {
-    BUFFER_Q        pending_enc_clcb;   /* pending encryption channel q */
+    fixed_queue_t    *pending_enc_clcb;   /* pending encryption channel q */
     tGATT_SEC_ACTION sec_act;
     BD_ADDR         peer_bda;
     tBT_TRANSPORT   transport;
@@ -389,7 +388,7 @@ typedef struct {
     tGATT_SR_CMD    sr_cmd;
 #endif  ///GATTS_INCLUDED == TRUE
     UINT16          indicate_handle;
-    BUFFER_Q        pending_ind_q;
+    fixed_queue_t   *pending_ind_q;
 
     TIMER_LIST_ENT  conf_timer_ent;     /* peer confirm to indication timer */
 
@@ -498,7 +497,7 @@ typedef struct {
 
 typedef struct {
     tGATT_TCB           tcb[GATT_MAX_PHY_CHANNEL];
-    BUFFER_Q            sign_op_queue;
+    fixed_queue_t       *sign_op_queue;
 
     tGATT_SR_REG        sr_reg[GATT_MAX_SR_PROFILES];
     UINT16              next_handle;    /* next available handle */
@@ -510,8 +509,8 @@ typedef struct {
     tGATT_SRV_LIST_INFO srv_list_info;
     tGATT_SRV_LIST_ELEM srv_list[GATT_MAX_SR_PROFILES];
 #endif  ///GATTS_INCLUDED == TRUE
-    BUFFER_Q            srv_chg_clt_q;   /* service change clients queue */
-    BUFFER_Q            pending_new_srv_start_q; /* pending new service start queue */
+    fixed_queue_t       *srv_chg_clt_q;   /* service change clients queue */
+    fixed_queue_t       *pending_new_srv_start_q; /* pending new service start queue */
     tGATT_REG           cl_rcb[GATT_MAX_APPS];
     tGATT_CLCB          clcb[GATT_CL_MAX_LCB];  /* connection link control block*/
     tGATT_SCCB          sccb[GATT_MAX_SCCB];    /* sign complete callback function GATT_MAX_SCCB <= GATT_CL_MAX_LCB */
index 2c970f9b43edaf8ad25f110ca484bedde6579e38..6cb692a7d09576fae91dcf9a8b291fd627bdbeee 100644 (file)
@@ -24,7 +24,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
-#include "gki.h"
+#include "allocator.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
 #include "hcidefs.h"
@@ -33,6 +33,8 @@
 #include <stddef.h>
 #include <string.h>
 
+#define HCI_GET_CMD_BUF(paramlen)       ((BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE))
+
 #if (defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)
 
 BOOLEAN btsnd_hcic_ble_set_local_used_feat (UINT8 feat_set[8])
index 3a88561922fab94073174eddf54de041818ffb05..1f0aa7235ae3b6b49892ffc1f306b2a0eceaa204 100644 (file)
@@ -24,8 +24,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
-//#include "btcore/include/counter.h"
-#include "gki.h"
+#include "allocator.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
 #include "hcidefs.h"
@@ -36,6 +35,8 @@
 
 #include "btm_int.h"    /* Included for UIPC_* macro definitions */
 
+#define HCI_GET_CMD_BUF(paramlen)       ((BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE))
+
 BOOLEAN btsnd_hcic_inquiry(const LAP inq_lap, UINT8 duration, UINT8 response_cnt)
 {
     BT_HDR *p;
@@ -1853,7 +1854,7 @@ BOOLEAN btsnd_hcic_write_pagescan_type (UINT8 type)
 }
 
 /* Must have room to store BT_HDR + max VSC length + callback pointer */
-#if (HCI_CMD_POOL_BUF_SIZE < 268)
+#if (HCI_CMD_BUF_SIZE < 268)
 #error "HCI_CMD_POOL_BUF_SIZE must be larger than 268"
 #endif
 
index dda03d1810a52476a306da733e6fa81b05bbc7e0..d7f069286746bf240de1194cc43fe6d02724b175 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "bt_defs.h"
 #include "btm_api.h"
-#include "gki.h"
 #include "bt_common_types.h"
 
 #define CHANNEL_MAP_LEN    5
index 60684bdb32b45eb6e724dea3e77d2f07dbdb4c78..a73a42e76d79b6858fee61e59aaf177eb0ad4176 100644 (file)
@@ -27,7 +27,7 @@
 #define BTM_BLE_INT_H
 
 #include "bt_target.h"
-#include "gki.h"
+#include "fixed_queue.h"
 #include "hcidefs.h"
 #include "btm_ble_api.h"
 #include "btm_int.h"
@@ -316,7 +316,7 @@ typedef struct {
     UINT8 white_list_avail_size;
     tBTM_BLE_WL_STATE wl_state;
 
-    BUFFER_Q conn_pending_q;
+    fixed_queue_t *conn_pending_q;
     tBTM_BLE_CONN_ST conn_state;
 
     /* random address management control block */
@@ -363,6 +363,7 @@ BOOLEAN btm_ble_send_extended_scan_params(UINT8 scan_type, UINT32 scan_int,
         UINT8 scan_filter_policy);
 void btm_ble_stop_inquiry(void);
 void btm_ble_init (void);
+void btm_ble_free (void);
 void btm_ble_connected (UINT8 *bda, UINT16 handle, UINT8 enc_mode, UINT8 role, tBLE_ADDR_TYPE addr_type, BOOLEAN addr_matched);
 void btm_ble_read_remote_features_complete(UINT8 *p);
 void btm_ble_write_adv_enable_complete(UINT8 *p);
index 4d263d572919b39be444c7bf10c385dcd6428363..2e017463b41593325ff556a60af113e4ad543248 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "bt_defs.h"
 #include "bt_target.h"
-#include "gki.h"
 #include "hcidefs.h"
 
 #include "rfcdefs.h"
@@ -367,7 +366,7 @@ typedef struct {
 typedef struct {
     tBTM_ESCO_INFO   esco;              /* Current settings             */
 #if BTM_SCO_HCI_INCLUDED == TRUE
-    BUFFER_Q         xmit_data_q;       /* SCO data transmitting queue  */
+    fixed_queue_t   *xmit_data_q;       /* SCO data transmitting queue  */
 #endif
     tBTM_SCO_CB     *p_conn_cb;         /* Callback for when connected  */
     tBTM_SCO_CB     *p_disc_cb;         /* Callback for when disconnect */
@@ -865,10 +864,10 @@ typedef struct {
     UINT8                   busy_level; /* the current busy level */
     BOOLEAN                 is_paging;  /* TRUE, if paging is in progess */
     BOOLEAN                 is_inquiry; /* TRUE, if inquiry is in progess */
-    BUFFER_Q                page_queue;
+    fixed_queue_t           *page_queue;
     BOOLEAN                 paging;
     BOOLEAN                 discing;
-    BUFFER_Q                sec_pending_q;  /* pending sequrity requests in tBTM_SEC_QUEUE_ENTRY format */
+    fixed_queue_t           *sec_pending_q;  /* pending sequrity requests in tBTM_SEC_QUEUE_ENTRY format */
 #if  (!defined(BT_TRACE_VERBOSE) || (BT_TRACE_VERBOSE == FALSE))
     char state_temp_buffer[BTM_STATE_BUFFER_SIZE];
 #endif
@@ -892,6 +891,7 @@ extern tBTM_CB *btm_cb_ptr;
 ********************************************
 */
 void         btm_init (void);
+void         btm_free (void);
 
 /* Internal functions provided by btm_inq.c
 *******************************************
index b2d723646af20b3a8df0b26f978fa6a239212edd..cc960c5916570f502300d5708e7419fa16d96b39 100644 (file)
@@ -28,7 +28,7 @@
 #define BTU_H
 
 #include "bt_target.h"
-#include "gki.h"
+#include "bt_defs.h"
 
 // HACK(zachoverflow): temporary dark magic
 #define BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK 0x1700 // didn't look used in bt_types...here goes nothing
index f2a4d7c4c1a800f845fbd499920a4aca7837eb62..e6e7e44f0e42799eaa36b6d1d002ee69d0c6ba29 100644 (file)
@@ -306,10 +306,10 @@ typedef struct {
 typedef struct {
     UINT8       preferred_mode;
     UINT8       allowed_modes;
-    UINT8       user_rx_pool_id;
-    UINT8       user_tx_pool_id;
-    UINT8       fcr_rx_pool_id;
-    UINT8       fcr_tx_pool_id;
+    UINT16      user_rx_buf_size;
+    UINT16      user_tx_buf_size;
+    UINT16      fcr_rx_buf_size;
+    UINT16      fcr_tx_buf_size;
 
 } tL2CAP_ERTM_INFO;
 
index e31ee24b154d73eba8de6c691133c65e014b71f4..db5013a135ce01e0297883c6cad91561d3caafe8 100644 (file)
 #define L2CAP_BLE_EXTFEA_MASK 0
 #endif
 
-/* Define a value that tells L2CAP to use the default HCI ACL buffer pool */
-#define L2CAP_DEFAULT_ERM_POOL_ID       0xFF
+/* Define a value that tells L2CAP to use the default HCI ACL buffer size */
+#define L2CAP_INVALID_ERM_BUF_SIZE      0
+
 /* Define a value that tells L2CAP to use the default MPS */
 #define L2CAP_DEFAULT_ERM_MPS           0x0000
 
 /* To optimize this, it must be a multiplum of the L2CAP PDU length AND match the 3DH5 air
  * including the l2cap headers in each packet - to match the latter - the -5 is added
  */
-#define L2CAP_MAX_SDU_LENGTH     (GKI_BUF4_SIZE - (L2CAP_MIN_OFFSET + L2CAP_MAX_HEADER_FCS) -5)
+#define L2CAP_MAX_SDU_LENGTH     (8080 + 26 - (L2CAP_MIN_OFFSET + 6))
+#define L2CAP_MAX_BUF_SIZE       (10240 + 24)
 
 /* Part of L2CAP_MIN_OFFSET that is not part of L2CAP
 */
index e25b6d94fd283445cd2dfb2ad953ba4e12d11f7b..40cdbfce70d8c24a4c5079a7521f81c7b8213e3a 100644 (file)
@@ -25,7 +25,6 @@
 #ifndef PORTEXT_H
 #define PORTEXT_H
 
-#include "gki.h"
 
 /* Port emulation entity Entry Points */
 extern void rfcomm_process_timeout (TIMER_LIST_ENT  *p_tle);
index b88659172dc73dff4bb1bcb714ac83de2dc792c7..4199a9252a2e6f70528a2ba8e88d4e95c795be38 100644 (file)
 #include <stdbool.h>
 
 #include "btm_api.h"
-#include "gki.h"
 #include "l2c_api.h"
 #include "l2cdefs.h"
 #include "list.h"
+#include "fixed_queue.h"
 
 #define L2CAP_MIN_MTU   48      /* Minimum acceptable MTU is 48 bytes */
 
@@ -176,9 +176,9 @@ typedef struct {
 
     UINT16      rx_sdu_len;                 /* Length of the SDU being received         */
     BT_HDR      *p_rx_sdu;                  /* Buffer holding the SDU being received    */
-    BUFFER_Q    waiting_for_ack_q;          /* Buffers sent and waiting for peer to ack */
-    BUFFER_Q    srej_rcv_hold_q;            /* Buffers rcvd but held pending SREJ rsp   */
-    BUFFER_Q    retrans_q;                  /* Buffers being retransmitted              */
+    fixed_queue_t    *waiting_for_ack_q;          /* Buffers sent and waiting for peer to ack */
+    fixed_queue_t    *srej_rcv_hold_q;            /* Buffers rcvd but held pending SREJ rsp   */
+    fixed_queue_t    *retrans_q;                  /* Buffers being retransmitted              */
 
     TIMER_LIST_ENT ack_timer;               /* Timer delaying RR                        */
     TIMER_LIST_ENT mon_retrans_timer;       /* Timer Monitor or Retransmission          */
@@ -241,6 +241,9 @@ typedef struct {
 } tL2C_RCB;
 
 
+#ifndef L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA
+#define L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA 100
+#endif
 /* Define a channel control block (CCB). There may be many channel control blocks
 ** between the same two Bluetooth devices (i.e. on the same link).
 ** Each CCB has unique local and remote CIDs. All channel control blocks on
@@ -279,7 +282,7 @@ typedef struct t_l2c_ccb {
     tL2CAP_CH_CFG_BITS  peer_cfg_bits;          /* Store what peer wants to configure */
     tL2CAP_CFG_INFO     peer_cfg;               /* Peer's saved configuration options */
 
-    BUFFER_Q            xmit_hold_q;            /* Transmit data hold queue         */
+    fixed_queue_t       *xmit_hold_q;            /* Transmit data hold queue         */
     BOOLEAN             cong_sent;              /* Set when congested status sent   */
     UINT16              buff_quota;             /* Buffer quota before sending congestion   */
 
@@ -379,8 +382,8 @@ typedef struct t_l2c_linkcb {
     UINT8               peer_chnl_mask[L2CAP_FIXED_CHNL_ARRAY_SIZE];
 #if (L2CAP_UCD_INCLUDED == TRUE)
     UINT16              ucd_mtu;                    /* peer MTU on UCD */
-    BUFFER_Q            ucd_out_sec_pending_q;      /* Security pending outgoing UCD packet  */
-    BUFFER_Q            ucd_in_sec_pending_q;       /* Security pending incoming UCD packet  */
+    fixed_queue_t       *ucd_out_sec_pending_q;      /* Security pending outgoing UCD packet  */
+    fixed_queue_t       *ucd_in_sec_pending_q;       /* Security pending incoming UCD packet  */
 #endif
 
     BT_HDR              *p_hcit_rcv_acl;            /* Current HCIT ACL buf being rcvd  */
@@ -706,7 +709,7 @@ extern void     l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf);
 extern void     l2c_fcr_proc_tout (tL2C_CCB *p_ccb);
 extern void     l2c_fcr_proc_ack_tout (tL2C_CCB *p_ccb);
 extern void     l2c_fcr_send_S_frame (tL2C_CCB *p_ccb, UINT16 function_code, UINT16 pf_bit);
-extern BT_HDR   *l2c_fcr_clone_buf (BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes, UINT8 pool);
+extern BT_HDR   *l2c_fcr_clone_buf (BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes);
 extern BOOLEAN  l2c_fcr_is_flow_controlled (tL2C_CCB *p_ccb);
 extern BT_HDR   *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length);
 extern void     l2c_fcr_start_timer (tL2C_CCB *p_ccb);
index 3b3f18701c7bc7cef37fc4acd446c425286485a1..78c927fcdf7552b293d36c33a30af68d9e227b77 100644 (file)
@@ -28,7 +28,6 @@
 #include <string.h>
 #include <stdio.h>
 #include "bt_trace.h"
-#include "gki.h"
 #include "bt_types.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
@@ -271,26 +270,24 @@ UINT16 L2CA_ErtmConnectReq (UINT16 psm, BD_ADDR p_bd_addr, tL2CAP_ERTM_INFO *p_e
         p_ccb->ertm_info  = *p_ertm_info;
 
         /* Replace default indicators with the actual default pool */
-        if (p_ccb->ertm_info.fcr_rx_pool_id == L2CAP_DEFAULT_ERM_POOL_ID) {
-            p_ccb->ertm_info.fcr_rx_pool_id = L2CAP_FCR_RX_POOL_ID;
-        }
+        if (p_ccb->ertm_info.fcr_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE)
+            p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE;
 
-        if (p_ccb->ertm_info.fcr_tx_pool_id == L2CAP_DEFAULT_ERM_POOL_ID) {
-            p_ccb->ertm_info.fcr_tx_pool_id = L2CAP_FCR_TX_POOL_ID;
-        }
+        if (p_ccb->ertm_info.fcr_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE)
+            p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE;
 
-        if (p_ccb->ertm_info.user_rx_pool_id == L2CAP_DEFAULT_ERM_POOL_ID) {
-            p_ccb->ertm_info.user_rx_pool_id = HCI_ACL_POOL_ID;
-        }
+        if (p_ccb->ertm_info.user_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE)
+            p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE;
 
-        if (p_ccb->ertm_info.user_tx_pool_id == L2CAP_DEFAULT_ERM_POOL_ID) {
-            p_ccb->ertm_info.user_tx_pool_id = HCI_ACL_POOL_ID;
-        }
+        if (p_ccb->ertm_info.user_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE)
+            p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE;
 
-        p_ccb->max_rx_mtu = GKI_get_pool_bufsize (p_ertm_info->user_rx_pool_id) -
-                            (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN);
+        p_ccb->max_rx_mtu = p_ertm_info->user_rx_buf_size -
+            (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN);
     }
 
+
+
     /* If link is up, start the L2CAP connection */
     if (p_lcb->link_state == LST_CONNECTED) {
         l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_REQ, NULL);
@@ -419,23 +416,20 @@ BOOLEAN L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, UINT16 re
         p_ccb->ertm_info  = *p_ertm_info;
 
         /* Replace default indicators with the actual default pool */
-        if (p_ccb->ertm_info.fcr_rx_pool_id == L2CAP_DEFAULT_ERM_POOL_ID) {
-            p_ccb->ertm_info.fcr_rx_pool_id = L2CAP_FCR_RX_POOL_ID;
-        }
+        if (p_ccb->ertm_info.fcr_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE)
+            p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE;
 
-        if (p_ccb->ertm_info.fcr_tx_pool_id == L2CAP_DEFAULT_ERM_POOL_ID) {
-            p_ccb->ertm_info.fcr_tx_pool_id = L2CAP_FCR_TX_POOL_ID;
-        }
+        if (p_ccb->ertm_info.fcr_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE)
+            p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE;
 
-        if (p_ccb->ertm_info.user_rx_pool_id == L2CAP_DEFAULT_ERM_POOL_ID) {
-            p_ccb->ertm_info.user_rx_pool_id = HCI_ACL_POOL_ID;
-        }
+        if (p_ccb->ertm_info.user_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE)
+            p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE;
 
-        if (p_ccb->ertm_info.user_tx_pool_id == L2CAP_DEFAULT_ERM_POOL_ID) {
-            p_ccb->ertm_info.user_tx_pool_id = HCI_ACL_POOL_ID;
-        }
+        if (p_ccb->ertm_info.user_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE)
+            p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE;
 
-        p_ccb->max_rx_mtu = GKI_get_pool_bufsize (p_ertm_info->user_rx_pool_id) - (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN);
+        p_ccb->max_rx_mtu = p_ertm_info->user_rx_buf_size -
+            (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN);
     }
 
     if (result == L2CAP_CONN_OK) {
@@ -1467,14 +1461,14 @@ UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf)
     if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL)
             ||  (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == NULL) ) {
         L2CAP_TRACE_ERROR ("L2CA_SendFixedChnlData()  Invalid CID: 0x%04x", fixed_cid);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (L2CAP_DW_FAILED);
     }
 
     // Fail if BT is not yet up
     if (!BTM_IsDeviceUp()) {
         L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData(0x%04x) - BTU not ready", fixed_cid);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (L2CAP_DW_FAILED);
     }
 
@@ -1483,7 +1477,7 @@ UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf)
             /* if link is disconnecting, also report data sending failure */
             p_lcb->link_state == LST_DISCONNECTING) {
         L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData(0x%04x) - no LCB", fixed_cid);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (L2CAP_DW_FAILED);
     }
 
@@ -1499,7 +1493,7 @@ UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf)
 
     if ((peer_channel_mask & (1 << fixed_cid)) == 0) {
         L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData() - peer does not support fixed chnl: 0x%04x", fixed_cid);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (L2CAP_DW_FAILED);
     }
 
@@ -1509,7 +1503,7 @@ UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf)
     if (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]) {
         if (!l2cu_initialize_fixed_ccb (p_lcb, fixed_cid, &l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) {
             L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData() - no CCB for chnl: 0x%4x", fixed_cid);
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
             return (L2CAP_DW_FAILED);
         }
     }
@@ -1518,9 +1512,9 @@ UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf)
     if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent) {
         L2CAP_TRACE_ERROR ("L2CAP - CID: 0x%04x cannot send, already congested \
             xmit_hold_q.count: %u buff_quota: %u", fixed_cid,
-                           GKI_queue_length(&p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->xmit_hold_q),
-                           p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->buff_quota);
-        GKI_freebuf (p_buf);
+            fixed_queue_length(p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->xmit_hold_q),
+            p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->buff_quota);
+        osi_free(p_buf);
         return (L2CAP_DW_FAILED);
     }
 
@@ -1848,7 +1842,9 @@ UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush)
 
     if (num_to_flush != L2CAP_FLUSH_CHANS_GET) {
         L2CAP_TRACE_API ("L2CA_FlushChannel (FLUSH)  CID: 0x%04x  NumToFlush: %d  QC: %u  pFirst: %p",
-                         lcid, num_to_flush, GKI_queue_length(&p_ccb->xmit_hold_q), GKI_getfirst(&p_ccb->xmit_hold_q));
+                         lcid, num_to_flush,
+                         fixed_queue_length(p_ccb->xmit_hold_q),
+                         fixed_queue_try_peek_first(p_ccb->xmit_hold_q));
     } else {
         L2CAP_TRACE_API ("L2CA_FlushChannel (QUERY)  CID: 0x%04x", lcid);
     }
@@ -1881,16 +1877,16 @@ UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush)
                 num_flushed1++;
 
                 list_remove(p_lcb->link_xmit_data_q, p_buf);
-                GKI_freebuf(p_buf);
+                osi_free(p_buf);
             }
         }
     }
 
     /* If needed, flush buffers in the CCB xmit hold queue */
-    while ( (num_to_flush != 0) && (!GKI_queue_is_empty(&p_ccb->xmit_hold_q))) {
-        BT_HDR *p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->xmit_hold_q);
+    while ( (num_to_flush != 0) && (!fixed_queue_is_empty(p_ccb->xmit_hold_q))) {
+        BT_HDR *p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q);
         if (p_buf) {
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
         }
         num_to_flush--;
         num_flushed2++;
@@ -1913,7 +1909,7 @@ UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush)
     }
 
     /* Add in the number in the CCB xmit queue */
-    num_left += GKI_queue_length(&p_ccb->xmit_hold_q);
+    num_left += fixed_queue_length(p_ccb->xmit_hold_q);
 
     /* Return the local number of buffers left for the CID */
     L2CAP_TRACE_DEBUG ("L2CA_FlushChannel()  flushed: %u + %u,  num_left: %u", num_flushed1, num_flushed2, num_left);
index 1bcee70195e01a55b35fac7c27b57cfa2ff66f67..0c6b3a53e3b598f18292c7396e84b94c67be8143 100644 (file)
@@ -27,7 +27,6 @@
 #include <stdio.h>
 
 #include "bt_target.h"
-#include "gki.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
 #include "l2cdefs.h"
@@ -35,6 +34,8 @@
 #include "btm_int.h"
 #include "btu.h"
 #include "hcimsgs.h"
+#include "allocator.h"
+
 #if (CLASSIC_BT_INCLUDED == TRUE)
 /********************************************************************************/
 /*              L O C A L    F U N C T I O N     P R O T O T Y P E S            */
@@ -260,7 +261,7 @@ static void l2c_csm_closed (tL2C_CCB *p_ccb, UINT16 event, void *p_data)
 
     case L2CEVT_L2CAP_DATA:                         /* Peer data packet rcvd    */
     case L2CEVT_L2CA_DATA_WRITE:                    /* Upper layer data to send */
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         break;
 
     case L2CEVT_L2CA_DISCONNECT_REQ:                 /* Upper wants to disconnect */
@@ -345,7 +346,7 @@ static void l2c_csm_orig_w4_sec_comp (tL2C_CCB *p_ccb, UINT16 event, void *p_dat
 
     case L2CEVT_L2CA_DATA_WRITE:                    /* Upper layer data to send */
     case L2CEVT_L2CAP_DATA:                         /* Peer data packet rcvd    */
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         break;
 
     case L2CEVT_L2CA_DISCONNECT_REQ:                 /* Upper wants to disconnect */
@@ -432,7 +433,7 @@ static void l2c_csm_term_w4_sec_comp (tL2C_CCB *p_ccb, UINT16 event, void *p_dat
 
     case L2CEVT_L2CA_DATA_WRITE:                    /* Upper layer data to send */
     case L2CEVT_L2CAP_DATA:                         /* Peer data packet rcvd    */
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         break;
 
     case L2CEVT_L2CA_DISCONNECT_REQ:                 /* Upper wants to disconnect */
@@ -544,7 +545,7 @@ static void l2c_csm_w4_l2cap_connect_rsp (tL2C_CCB *p_ccb, UINT16 event, void *p
 
     case L2CEVT_L2CA_DATA_WRITE:                    /* Upper layer data to send */
     case L2CEVT_L2CAP_DATA:                         /* Peer data packet rcvd    */
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         break;
 
     case L2CEVT_L2CAP_INFO_RSP:
@@ -621,7 +622,7 @@ static void l2c_csm_w4_l2ca_connect_rsp (tL2C_CCB *p_ccb, UINT16 event, void *p_
 
     case L2CEVT_L2CA_DATA_WRITE:                    /* Upper layer data to send */
     case L2CEVT_L2CAP_DATA:                         /* Peer data packet rcvd    */
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         break;
 
     case L2CEVT_L2CA_DISCONNECT_REQ:                 /* Upper wants to disconnect */
@@ -731,10 +732,10 @@ static void l2c_csm_config (tL2C_CCB *p_ccb, UINT16 event, void *p_data)
                 }
 
 #if (L2CAP_ERTM_STATS == TRUE)
-                p_ccb->fcrb.connect_tick_count = GKI_get_os_tick_count();
+                p_ccb->fcrb.connect_tick_count = osi_time_get_os_boottime_ms();
 #endif
                 /* See if we can forward anything on the hold queue */
-                if (!GKI_queue_is_empty(&p_ccb->xmit_hold_q)) {
+                if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
                     l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL);
                 }
             }
@@ -809,11 +810,12 @@ static void l2c_csm_config (tL2C_CCB *p_ccb, UINT16 event, void *p_data)
         }
 
 #if (L2CAP_ERTM_STATS == TRUE)
-        p_ccb->fcrb.connect_tick_count = GKI_get_os_tick_count();
+        p_ccb->fcrb.connect_tick_count = osi_time_get_os_boottime_ms();
 #endif
 
         /* See if we can forward anything on the hold queue */
-        if ( (p_ccb->chnl_state == CST_OPEN) && (!GKI_queue_is_empty(&p_ccb->xmit_hold_q))) {
+        if ( (p_ccb->chnl_state == CST_OPEN) &&
+             (!fixed_queue_is_empty(p_ccb->xmit_hold_q))) {
             l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL);
         }
         break;
@@ -839,7 +841,7 @@ static void l2c_csm_config (tL2C_CCB *p_ccb, UINT16 event, void *p_data)
                     (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb)
                     (p_ccb->local_cid, p_ccb->p_lcb->remote_bd_addr, (BT_HDR *)p_data);
                 else {
-                    GKI_freebuf (p_data);
+                    osi_free (p_data);
                 }
                 break;
             }
@@ -852,7 +854,7 @@ static void l2c_csm_config (tL2C_CCB *p_ccb, UINT16 event, void *p_data)
         if (p_ccb->config_done & OB_CFG_DONE) {
             l2c_enqueue_peer_data (p_ccb, (BT_HDR *)p_data);
         } else {
-            GKI_freebuf (p_data);
+            osi_free (p_data);
         }
         break;
 
@@ -1062,7 +1064,7 @@ static void l2c_csm_w4_l2cap_disconnect_rsp (tL2C_CCB *p_ccb, UINT16 event, void
 
     case L2CEVT_L2CAP_DATA:                         /* Peer data packet rcvd    */
     case L2CEVT_L2CA_DATA_WRITE:                    /* Upper layer data to send */
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         break;
     }
 }
@@ -1111,7 +1113,7 @@ static void l2c_csm_w4_l2ca_disconnect_rsp (tL2C_CCB *p_ccb, UINT16 event, void
 
     case L2CEVT_L2CAP_DATA:                         /* Peer data packet rcvd    */
     case L2CEVT_L2CA_DATA_WRITE:                    /* Upper layer data to send */
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         break;
     }
 }
@@ -1241,7 +1243,7 @@ void l2c_enqueue_peer_data (tL2C_CCB *p_ccb, BT_HDR *p_buf)
         UINT16_TO_STREAM (p, p_ccb->remote_cid);
     }
 
-    GKI_enqueue (&p_ccb->xmit_hold_q, p_buf);
+    fixed_queue_enqueue(p_ccb->xmit_hold_q, p_buf);
 
     l2cu_check_channel_congestion (p_ccb);
 
index c31e4b7f339e768a98dc5ea11ab49b5bb371bf8e..640e4908ccb8232328fd0173d578b7e8b73e4a70 100644 (file)
@@ -28,7 +28,6 @@
 #include <string.h>
 #include "bt_trace.h"
 #include "bt_types.h"
-#include "gki.h"
 #include "hcimsgs.h"
 #include "l2c_api.h"
 #include "l2c_int.h"
@@ -36,6 +35,7 @@
 #include "btm_api.h"
 #include "btm_int.h"
 #include "btu.h"
+#include "allocator.h"
 
 #if (CLASSIC_BT_INCLUDED == TRUE)
 
@@ -218,28 +218,27 @@ void l2c_fcr_cleanup (tL2C_CCB *p_ccb)
     l2c_fcr_stop_timer (p_ccb);
 
     if (p_fcrb->p_rx_sdu) {
-        GKI_freebuf (p_fcrb->p_rx_sdu);
+        osi_free(p_fcrb->p_rx_sdu);
+        p_fcrb->p_rx_sdu = NULL;
     }
 
-    while (!GKI_queue_is_empty(&p_fcrb->waiting_for_ack_q)) {
-        GKI_freebuf (GKI_dequeue (&p_fcrb->waiting_for_ack_q));
-    }
 
-    while (!GKI_queue_is_empty(&p_fcrb->srej_rcv_hold_q)) {
-        GKI_freebuf (GKI_dequeue (&p_fcrb->srej_rcv_hold_q));
-    }
+    fixed_queue_free(p_fcrb->waiting_for_ack_q, osi_free_func);
+    p_fcrb->waiting_for_ack_q = NULL;
 
-    while (!GKI_queue_is_empty(&p_fcrb->retrans_q)) {
-        GKI_freebuf (GKI_dequeue (&p_fcrb->retrans_q));
-    }
+    fixed_queue_free(p_fcrb->srej_rcv_hold_q, osi_free_func);
+    p_fcrb->srej_rcv_hold_q = NULL;
 
+    fixed_queue_free(p_fcrb->retrans_q, osi_free_func);
+    p_fcrb->retrans_q = NULL;
+       
     btu_stop_quick_timer (&p_fcrb->ack_timer);
     btu_stop_quick_timer (&p_ccb->fcrb.mon_retrans_timer);
 
 #if (L2CAP_ERTM_STATS == TRUE)
     if ( (p_ccb->local_cid >= L2CAP_BASE_APPL_CID) && (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) ) {
-        UINT32  dur = GKI_get_os_tick_count() - p_ccb->fcrb.connect_tick_count;
-        char    *p_str = (char *)GKI_getbuf(120);
+        UINT32  dur = osi_time_get_os_boottime_ms() - p_ccb->fcrb.connect_tick_count;
+        char    *p_str = (char *)osi_malloc(120);
         UINT16  i;
         UINT32  throughput_avg, ack_delay_avg, ack_q_count_avg;
 
@@ -298,7 +297,7 @@ void l2c_fcr_cleanup (tL2C_CCB *p_ccb)
                      "throughput_avg: %8u (kbytes/sec), ack_delay_avg: %8u ms, ack_q_count_avg: %8u",
                      throughput_avg, ack_delay_avg, ack_q_count_avg );
 
-            GKI_freebuf(p_str);
+            osi_free(p_str);
         }
 
         BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC,
@@ -319,40 +318,28 @@ void l2c_fcr_cleanup (tL2C_CCB *p_ccb)
 ** Returns          pointer to new buffer
 **
 *******************************************************************************/
-BT_HDR *l2c_fcr_clone_buf (BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes, UINT8 pool)
+BT_HDR *l2c_fcr_clone_buf (BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes)
 {
     assert(p_buf != NULL);
-    BT_HDR *p_buf2;
-
-    /* If using the common pool, should be at least 10% free. */
-    if ( (pool == HCI_ACL_POOL_ID) && (GKI_poolutilization (pool) > 90) ) {
-        L2CAP_TRACE_ERROR ("L2CAP - failed to clone buffer on HCI_ACL_POOL_ID Utilization: %u", GKI_poolutilization(pool));
-        return (NULL);
-    }
-
-    if ((p_buf2 = (BT_HDR *)GKI_getpoolbuf(pool)) != NULL) {
-        UINT16    pool_buf_size = GKI_get_pool_bufsize (pool);
-
-        /* Make sure buffer fits into buffer pool */
-        if ((no_of_bytes + sizeof(BT_HDR) + new_offset) > pool_buf_size) {
-            L2CAP_TRACE_ERROR("##### l2c_fcr_clone_buf (NumBytes %d) -> Exceeds poolsize %d [bytes %d + BT_HDR %d + offset %d]",
-                              (no_of_bytes + sizeof(BT_HDR) + new_offset),
-                              pool_buf_size, no_of_bytes, sizeof(BT_HDR),
-                              new_offset);
-
-            GKI_freebuf(p_buf2);
-            return (NULL);
-        }
-
-        p_buf2->offset = new_offset;
-        p_buf2->len    = no_of_bytes;
+    /*
+     * NOTE: We allocate extra L2CAP_FCS_LEN octets, in case we need to put
+     * the FCS (Frame Check Sequence) at the end of the buffer.
+     */
+    uint16_t buf_size = no_of_bytes + sizeof(BT_HDR) + new_offset + L2CAP_FCS_LEN;
+#if (L2CAP_ERTM_STATS == TRUE)
+    /*
+     * NOTE: If L2CAP_ERTM_STATS is enabled, we need 4 extra octets at the
+     * end for a timestamp at the end of an I-frame.
+     */
+    buf_size += sizeof(uint32_t);
+#endif
+    BT_HDR *p_buf2 = (BT_HDR *)osi_malloc(buf_size);
 
-        memcpy (((UINT8 *)(p_buf2 + 1)) + p_buf2->offset,
-                ((UINT8 *)(p_buf + 1))  + p_buf->offset,
-                no_of_bytes);
-    } else {
-        L2CAP_TRACE_ERROR ("L2CAP - failed to clone buffer, Pool: %u  Count: %u", pool,  GKI_poolfreecount(pool));
-    }
+    p_buf2->offset = new_offset;
+    p_buf2->len = no_of_bytes;
+    memcpy(((UINT8 *)(p_buf2 + 1)) + p_buf2->offset,
+           ((UINT8 *)(p_buf + 1))  + p_buf->offset,
+           no_of_bytes);
 
     return (p_buf2);
 }
@@ -372,9 +359,9 @@ BOOLEAN l2c_fcr_is_flow_controlled (tL2C_CCB *p_ccb)
     if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) {
         /* Check if remote side flowed us off or the transmit window is full */
         if ( (p_ccb->fcrb.remote_busy == TRUE)
-                ||  (GKI_queue_length(&p_ccb->fcrb.waiting_for_ack_q) >= p_ccb->peer_cfg.fcr.tx_win_sz) ) {
+         ||  (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q) >= p_ccb->peer_cfg.fcr.tx_win_sz) ) {
 #if (L2CAP_ERTM_STATS == TRUE)
-            if (!GKI_queue_is_empty(&p_ccb->xmit_hold_q)) {
+            if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
                 p_ccb->fcrb.xmit_window_closed++;
 
                 if ((p_ccb->p_lcb->sent_not_acked < 2) && (l2cb.controller_xmit_window > 0)) {
@@ -523,7 +510,7 @@ void l2c_fcr_send_S_frame (tL2C_CCB *p_ccb, UINT16 function_code, UINT16 pf_bit)
     ctrl_word |= (p_ccb->fcrb.next_seq_expected << L2CAP_FCR_REQ_SEQ_BITS_SHIFT);
     ctrl_word |= pf_bit;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (L2CAP_CMD_POOL_ID)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(L2CAP_CMD_BUF_SIZE)) != NULL) {
         p_buf->offset = HCI_DATA_PREAMBLE_SIZE;
         p_buf->len    = L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD;
 
@@ -610,7 +597,7 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
 
     if (p_buf->len < min_pdu_len) {
         L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x  Len too short: %u", p_ccb->local_cid, p_buf->len);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -652,8 +639,11 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
     }
 
     L2CAP_TRACE_EVENT ("      eRTM Rx Nxt_tx_seq %u, Lst_rx_ack %u, Nxt_seq_exp %u, Lst_ack_snt %u, wt_q.cnt %u, tries %u",
-                       p_ccb->fcrb.next_tx_seq, p_ccb->fcrb.last_rx_ack, p_ccb->fcrb.next_seq_expected,
-                       p_ccb->fcrb.last_ack_sent, GKI_queue_length(&p_ccb->fcrb.waiting_for_ack_q), p_ccb->fcrb.num_tries);
+                       p_ccb->fcrb.next_tx_seq, p_ccb->fcrb.last_rx_ack,
+                       p_ccb->fcrb.next_seq_expected,
+                       p_ccb->fcrb.last_ack_sent,
+                       fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q),
+                       p_ccb->fcrb.num_tries);
 
 #endif /* BT_TRACE_VERBOSE */
 
@@ -667,7 +657,7 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
 
         if (l2c_fcr_rx_get_fcs(p_buf) != fcs) {
             L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x  BAD FCS", p_ccb->local_cid);
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
             return;
         }
     }
@@ -699,7 +689,7 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
                 /* then it speeds up recovery significantly if we poll him back soon after his poll. */
                 btu_start_quick_timer (&p_ccb->fcrb.mon_retrans_timer, BTU_TTYPE_L2CAP_CHNL, QUICK_TIMER_TICKS_PER_SEC);
             }
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
             return;
         }
 
@@ -710,7 +700,7 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
             ctrl_word &= ~L2CAP_FCR_P_BIT;
         }
 
-        if (GKI_queue_is_empty(&p_ccb->fcrb.waiting_for_ack_q)) {
+        if (fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) {
             p_ccb->fcrb.num_tries = 0;
         }
 
@@ -722,7 +712,7 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
 
     /* Process receive sequence number */
     if (!process_reqseq (p_ccb, ctrl_word)) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -739,12 +729,12 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
     }
 
     /* If we have some buffers held while doing SREJ, and SREJ has cleared, process them now */
-    if ( (!p_ccb->fcrb.local_busy) && (!p_ccb->fcrb.srej_sent) && (!GKI_queue_is_empty(&p_ccb->fcrb.srej_rcv_hold_q))) {
-        BUFFER_Q temp_q = p_ccb->fcrb.srej_rcv_hold_q;
-
-        GKI_init_q (&p_ccb->fcrb.srej_rcv_hold_q);
+    if ( (!p_ccb->fcrb.local_busy) && (!p_ccb->fcrb.srej_sent) &&
+         (!fixed_queue_is_empty(p_ccb->fcrb.srej_rcv_hold_q))) {
+        fixed_queue_t *temp_q = p_ccb->fcrb.srej_rcv_hold_q;
+        p_ccb->fcrb.srej_rcv_hold_q = fixed_queue_new(SIZE_MAX);
 
-        while ((p_buf = (BT_HDR *)GKI_dequeue (&temp_q)) != NULL) {
+        while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(temp_q)) != NULL) {
             if (p_ccb->in_use && (p_ccb->chnl_state == CST_OPEN)) {
                 /* Get the control word */
                 p = ((UINT8 *)(p_buf + 1)) + p_buf->offset - L2CAP_FCR_OVERHEAD;
@@ -758,7 +748,7 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
                 /* Process the SREJ held I-frame, but do not send an RR for each individual frame */
                 process_i_frame (p_ccb, p_buf, ctrl_word, TRUE);
             } else {
-                GKI_freebuf (p_buf);
+                osi_free (p_buf);
             }
 
             /* If more frames were lost during SREJ, send a REJ */
@@ -769,6 +759,7 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
                 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_REJ, 0);
             }
         }
+        fixed_queue_free(temp_q, NULL);
 
         /* Now, if needed, send one RR for the whole held queue */
         if ( (!p_ccb->fcrb.local_busy) && (!p_ccb->fcrb.rej_sent) && (!p_ccb->fcrb.srej_sent)
@@ -782,7 +773,8 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
     }
 
     /* If a window has opened, check if we can send any more packets */
-    if ( (!GKI_queue_is_empty(&p_ccb->fcrb.retrans_q) || !GKI_queue_is_empty(&p_ccb->xmit_hold_q))
+    if ( (!fixed_queue_is_empty(p_ccb->fcrb.retrans_q) ||
+          !fixed_queue_is_empty(p_ccb->xmit_hold_q))
             && (p_ccb->fcrb.wait_ack == FALSE)
             && (l2c_fcr_is_flow_controlled (p_ccb) == FALSE) ) {
         l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL);
@@ -802,8 +794,10 @@ void l2c_fcr_proc_tout (tL2C_CCB *p_ccb)
 {
     assert(p_ccb != NULL);
     L2CAP_TRACE_DEBUG ("l2c_fcr_proc_tout:  CID: 0x%04x  num_tries: %u (max: %u)  wait_ack: %u  ack_q_count: %u",
-                       p_ccb->local_cid, p_ccb->fcrb.num_tries, p_ccb->peer_cfg.fcr.max_transmit,
-                       p_ccb->fcrb.wait_ack, GKI_queue_length(&p_ccb->fcrb.waiting_for_ack_q));
+                       p_ccb->local_cid, p_ccb->fcrb.num_tries,
+                       p_ccb->peer_cfg.fcr.max_transmit,
+                       p_ccb->fcrb.wait_ack,
+                       fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q));
 
 #if (L2CAP_ERTM_STATS == TRUE)
     p_ccb->fcrb.retrans_touts++;
@@ -874,9 +868,9 @@ static BOOLEAN process_reqseq (tL2C_CCB *p_ccb, UINT16 ctrl_word)
             &&  ((ctrl_word & L2CAP_FCR_SUP_BITS) == (L2CAP_FCR_SUP_SREJ << L2CAP_FCR_SUP_SHIFT))
             &&  ((ctrl_word & L2CAP_FCR_P_BIT) == 0) ) {
         /* If anything still waiting for ack, restart the timer if it was stopped */
-        if (!GKI_queue_is_empty(&p_fcrb->waiting_for_ack_q)) {
-            l2c_fcr_start_timer (p_ccb);
-        }
+        if (!fixed_queue_is_empty(p_fcrb->waiting_for_ack_q)) {
+            l2c_fcr_start_timer(p_ccb);
+               }
 
         return (TRUE);
     }
@@ -887,10 +881,11 @@ static BOOLEAN process_reqseq (tL2C_CCB *p_ccb, UINT16 ctrl_word)
     num_bufs_acked = (req_seq - p_fcrb->last_rx_ack) & L2CAP_FCR_SEQ_MODULO;
 
     /* Verify the request sequence is in range before proceeding */
-    if (num_bufs_acked > GKI_queue_length(&p_fcrb->waiting_for_ack_q)) {
+    if (num_bufs_acked > fixed_queue_length(p_fcrb->waiting_for_ack_q)) {
         /* The channel is closed if ReqSeq is not in range */
         L2CAP_TRACE_WARNING ("L2CAP eRTM Frame BAD Req_Seq - ctrl_word: 0x%04x  req_seq 0x%02x  last_rx_ack: 0x%02x  QCount: %u",
-                             ctrl_word, req_seq, p_fcrb->last_rx_ack, GKI_queue_length(&p_fcrb->waiting_for_ack_q));
+                             ctrl_word, req_seq, p_fcrb->last_rx_ack,
+                             fixed_queue_length(p_fcrb->waiting_for_ack_q));
 
         l2cu_disconnect_chnl (p_ccb);
         return (FALSE);
@@ -908,13 +903,13 @@ static BOOLEAN process_reqseq (tL2C_CCB *p_ccb, UINT16 ctrl_word)
 #endif
 
         for (xx = 0; xx < num_bufs_acked; xx++) {
-            ls = ((BT_HDR *)(GKI_getfirst(&p_fcrb->waiting_for_ack_q)))->layer_specific & L2CAP_FCR_SAR_BITS;
+            BT_HDR *p_tmp = (BT_HDR *)fixed_queue_try_dequeue(p_fcrb->waiting_for_ack_q);
+            ls = p_tmp->layer_specific & L2CAP_FCR_SAR_BITS;
 
             if ( (ls == L2CAP_FCR_UNSEG_SDU) || (ls == L2CAP_FCR_END_SDU) ) {
                 full_sdus_xmitted++;
             }
-
-            GKI_freebuf (GKI_dequeue (&p_fcrb->waiting_for_ack_q));
+            osi_free(p_tmp);
         }
 
         /* If we are still in a wait_ack state, do not mess with the timer */
@@ -925,7 +920,8 @@ static BOOLEAN process_reqseq (tL2C_CCB *p_ccb, UINT16 ctrl_word)
         /* Check if we need to call the "packet_sent" callback */
         if ( (p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_TxComplete_Cb) && (full_sdus_xmitted) ) {
             /* Special case for eRTM, if all packets sent, send 0xFFFF */
-            if (GKI_queue_is_empty(&p_fcrb->waiting_for_ack_q) && (GKI_queue_is_empty(&p_ccb->xmit_hold_q))) {
+            if (fixed_queue_is_empty(p_fcrb->waiting_for_ack_q) &&
+                fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
                 full_sdus_xmitted = 0xFFFF;
             }
 
@@ -934,7 +930,7 @@ static BOOLEAN process_reqseq (tL2C_CCB *p_ccb, UINT16 ctrl_word)
     }
 
     /* If anything still waiting for ack, restart the timer if it was stopped */
-    if (!GKI_queue_is_empty(&p_fcrb->waiting_for_ack_q)) {
+    if (!fixed_queue_is_empty(p_fcrb->waiting_for_ack_q)) {
         l2c_fcr_start_timer (p_ccb);
     }
 
@@ -1019,7 +1015,7 @@ static void process_s_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word)
         L2CAP_TRACE_DEBUG ("process_s_frame hit_max_retries");
     }
 
-    GKI_freebuf (p_buf);
+    osi_free (p_buf);
 }
 
 
@@ -1043,7 +1039,7 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, B
     /* If we were doing checkpoint recovery, first retransmit all unacked I-frames */
     if (ctrl_word & L2CAP_FCR_F_BIT) {
         if (!retransmit_i_frames (p_ccb, L2C_FCR_RETX_ALL_PKTS)) {
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
             return;
         }
     }
@@ -1060,17 +1056,7 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, B
     if ( (tx_seq != p_fcrb->next_seq_expected) && (p_fcrb->local_busy) ) {
         L2CAP_TRACE_WARNING ("Dropping bad I-Frame since we flowed off, tx_seq:%u", tx_seq);
         l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0);
-        GKI_freebuf(p_buf);
-        return;
-    }
-
-    /* If there are no free buffers in the user Rx queue, drop the  */
-    /* received buffer now before we update any sequence numbers    */
-    if (GKI_poolfreecount (p_ccb->ertm_info.user_rx_pool_id) == 0) {
-        L2CAP_TRACE_WARNING ("L2CAP CID: 0x%04x  Dropping I-Frame seq: %u  User RX Pool: %u  (Size: %u)  has no free buffers!!",
-                             p_ccb->local_cid, tx_seq, p_ccb->ertm_info.user_rx_pool_id,
-                             GKI_poolcount (p_ccb->ertm_info.user_rx_pool_id));
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
         return;
     }
 
@@ -1082,28 +1068,29 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, B
         if (num_lost >= p_ccb->our_cfg.fcr.tx_win_sz) {
             /* Duplicate - simply drop it */
             L2CAP_TRACE_WARNING ("process_i_frame() Dropping Duplicate Frame tx_seq:%u  ExpectedTxSeq %u", tx_seq, p_fcrb->next_seq_expected);
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
         } else {
             L2CAP_TRACE_WARNING ("process_i_frame() CID: 0x%04x  Lost: %u  tx_seq:%u  ExpTxSeq %u  Rej: %u  SRej: %u",
                                  p_ccb->local_cid, num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent, p_fcrb->srej_sent);
 
             if (p_fcrb->srej_sent) {
                 /* If SREJ sent, save the frame for later processing as long as it is in sequence */
-                next_srej = (((BT_HDR *)GKI_getlast(&p_fcrb->srej_rcv_hold_q))->layer_specific + 1) & L2CAP_FCR_SEQ_MODULO;
+                next_srej = (((BT_HDR *)fixed_queue_try_peek_last(p_fcrb->srej_rcv_hold_q))->layer_specific + 1) & L2CAP_FCR_SEQ_MODULO;
 
-                if ( (tx_seq == next_srej) && (GKI_queue_length(&p_fcrb->srej_rcv_hold_q) < p_ccb->our_cfg.fcr.tx_win_sz) ) {
+                if ( (tx_seq == next_srej) && (fixed_queue_length(p_fcrb->srej_rcv_hold_q) < p_ccb->our_cfg.fcr.tx_win_sz) ) {
                     /* If user gave us a pool for held rx buffers, use that */
-                    if (p_ccb->ertm_info.fcr_rx_pool_id != HCI_ACL_POOL_ID) {
+                    /* TODO: Could that happen? Get rid of this code. */
+                    if (p_ccb->ertm_info.fcr_rx_buf_size != L2CAP_FCR_RX_BUF_SIZE) {
                         BT_HDR *p_buf2;
 
                         /* Adjust offset and len so that control word is copied */
                         p_buf->offset -= L2CAP_FCR_OVERHEAD;
                         p_buf->len    += L2CAP_FCR_OVERHEAD;
 
-                        p_buf2 = l2c_fcr_clone_buf (p_buf, p_buf->offset, p_buf->len, p_ccb->ertm_info.fcr_rx_pool_id);
+                        p_buf2 = l2c_fcr_clone_buf (p_buf, p_buf->offset, p_buf->len);
 
                         if (p_buf2) {
-                            GKI_freebuf (p_buf);
+                            osi_free (p_buf);
                             p_buf = p_buf2;
                         }
                         p_buf->offset += L2CAP_FCR_OVERHEAD;
@@ -1113,36 +1100,36 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, B
                                        num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent);
 
                     p_buf->layer_specific = tx_seq;
-                    GKI_enqueue (&p_fcrb->srej_rcv_hold_q, p_buf);
+                    fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf);
                 } else {
                     L2CAP_TRACE_WARNING ("process_i_frame() CID: 0x%04x  frame dropped in Srej Sent next_srej:%u  hold_q.count:%u  win_sz:%u",
-                                         p_ccb->local_cid, next_srej, GKI_queue_length(&p_fcrb->srej_rcv_hold_q), p_ccb->our_cfg.fcr.tx_win_sz);
+                                         p_ccb->local_cid, next_srej, fixed_queue_length(p_fcrb->srej_rcv_hold_q), p_ccb->our_cfg.fcr.tx_win_sz);
 
                     p_fcrb->rej_after_srej = TRUE;
-                    GKI_freebuf (p_buf);
+                    osi_free (p_buf);
                 }
             } else if (p_fcrb->rej_sent) {
                 L2CAP_TRACE_WARNING ("process_i_frame() CID: 0x%04x  Lost: %u  tx_seq:%u  ExpTxSeq %u  Rej: 1  SRej: %u",
                                      p_ccb->local_cid, num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->srej_sent);
 
                 /* If REJ sent, just drop the frame */
-                GKI_freebuf (p_buf);
+                osi_free (p_buf);
             } else {
                 L2CAP_TRACE_DEBUG ("process_i_frame() CID: 0x%04x  tx_seq:%u  ExpTxSeq %u  Rej: %u",
                                    p_ccb->local_cid, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent);
 
                 /* If only one lost, we will send SREJ, otherwise we will send REJ */
                 if (num_lost > 1) {
-                    GKI_freebuf (p_buf);
+                    osi_free (p_buf);
                     p_fcrb->rej_sent = TRUE;
                     l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_REJ, 0);
                 } else {
-                    if (!GKI_queue_is_empty(&p_fcrb->srej_rcv_hold_q)) {
+                    if (!fixed_queue_is_empty(p_fcrb->srej_rcv_hold_q)) {
                         L2CAP_TRACE_ERROR ("process_i_frame() CID: 0x%04x  sending SREJ tx_seq:%d hold_q.count:%u",
-                                           p_ccb->local_cid, tx_seq, GKI_queue_length(&p_fcrb->srej_rcv_hold_q));
+                                             p_ccb->local_cid, tx_seq, fixed_queue_length(p_fcrb->srej_rcv_hold_q));
                     }
                     p_buf->layer_specific = tx_seq;
-                    GKI_enqueue (&p_fcrb->srej_rcv_hold_q, p_buf);
+                    fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf);
                     p_fcrb->srej_sent = TRUE;
                     l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_SREJ, 0);
                 }
@@ -1182,8 +1169,9 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, B
                 btu_start_quick_timer (&p_ccb->fcrb.ack_timer, BTU_TTYPE_L2CAP_FCR_ACK,
                                        (L2CAP_FCR_ACK_TOUT * QUICK_TIMER_TICKS_PER_SEC) / 1000);
             }
-        } else if ( ((GKI_queue_is_empty(&p_ccb->xmit_hold_q)) || (l2c_fcr_is_flow_controlled (p_ccb)))
-                    &&  (GKI_queue_is_empty(&p_ccb->fcrb.srej_rcv_hold_q))) {
+        } else if ((fixed_queue_is_empty(p_ccb->xmit_hold_q) ||
+                  l2c_fcr_is_flow_controlled(p_ccb))
+                 && fixed_queue_is_empty(p_ccb->fcrb.srej_rcv_hold_q)) {
             if (p_fcrb->local_busy) {
                 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0);
             } else {
@@ -1223,7 +1211,7 @@ static void process_stream_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf)
 
         if (l2c_fcr_rx_get_fcs(p_buf) != fcs) {
             L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x  BAD FCS", p_ccb->local_cid);
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
             return;
         }
     }
@@ -1239,7 +1227,7 @@ static void process_stream_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf)
     /* Make sure it is an I-frame */
     if (ctrl_word & L2CAP_FCR_S_FRAME_BIT) {
         L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x  BAD S-frame in streaming mode  ctrl_word: 0x%04x", p_ccb->local_cid, ctrl_word);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -1262,7 +1250,7 @@ static void process_stream_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf)
 
         /* Lost one or more packets, so flush the SAR queue */
         if (p_ccb->fcrb.p_rx_sdu != NULL) {
-            GKI_freebuf (p_ccb->fcrb.p_rx_sdu);
+            osi_free(p_ccb->fcrb.p_rx_sdu);
             p_ccb->fcrb.p_rx_sdu = NULL;
         }
     }
@@ -1272,7 +1260,7 @@ static void process_stream_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf)
     if (!do_sar_reassembly (p_ccb, p_buf, ctrl_word)) {
         /* Some sort of SAR error, so flush the SAR queue */
         if (p_ccb->fcrb.p_rx_sdu != NULL) {
-            GKI_freebuf (p_ccb->fcrb.p_rx_sdu);
+            osi_free(p_ccb->fcrb.p_rx_sdu);
             p_ccb->fcrb.p_rx_sdu = NULL;
         }
     }
@@ -1331,8 +1319,8 @@ static BOOLEAN do_sar_reassembly (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_wo
             if (p_fcrb->rx_sdu_len > p_ccb->max_rx_mtu) {
                 L2CAP_TRACE_WARNING ("SAR - SDU len: %u  larger than MTU: %u", p_fcrb->rx_sdu_len, p_fcrb->rx_sdu_len);
                 packet_ok = FALSE;
-            } else if ((p_fcrb->p_rx_sdu = (BT_HDR *)GKI_getpoolbuf (p_ccb->ertm_info.user_rx_pool_id)) == NULL) {
-                L2CAP_TRACE_ERROR ("SAR - no buffer for SDU start user_rx_pool_id:%d", p_ccb->ertm_info.user_rx_pool_id);
+            } else if ((p_fcrb->p_rx_sdu = (BT_HDR *)osi_malloc(L2CAP_MAX_BUF_SIZE)) == NULL) {
+                L2CAP_TRACE_ERROR ("SAR - no buffer for SDU start user_rx_buf_size:%d", p_ccb->ertm_info.user_rx_buf_size);
                 packet_ok = FALSE;
             } else {
                 p_fcrb->p_rx_sdu->offset = 4; /* this is the minimal offset required by OBX to process incoming packets */
@@ -1354,7 +1342,7 @@ static BOOLEAN do_sar_reassembly (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_wo
 
                 p_fcrb->p_rx_sdu->len += p_buf->len;
 
-                GKI_freebuf (p_buf);
+                osi_free (p_buf);
                 p_buf = NULL;
 
                 if (sar_type == L2CAP_FCR_END_SDU) {
@@ -1366,7 +1354,7 @@ static BOOLEAN do_sar_reassembly (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_wo
     }
 
     if (packet_ok == FALSE) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
     } else if (p_buf != NULL) {
 #if (L2CAP_NUM_FIXED_CHNLS > 0)
         if (p_ccb->local_cid < L2CAP_BASE_APPL_CID &&
@@ -1396,43 +1384,54 @@ static BOOLEAN retransmit_i_frames (tL2C_CCB *p_ccb, UINT8 tx_seq)
 {
     assert(p_ccb != NULL);
 
-    BT_HDR      *p_buf, *p_buf2;
+    BT_HDR      *p_buf = NULL;
     UINT8       *p;
     UINT8       buf_seq;
     UINT16      ctrl_word;
 
-    if ( (GKI_getfirst(&p_ccb->fcrb.waiting_for_ack_q))
+    if ( (!fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q))
             &&  (p_ccb->peer_cfg.fcr.max_transmit != 0)
             &&  (p_ccb->fcrb.num_tries >= p_ccb->peer_cfg.fcr.max_transmit) ) {
         L2CAP_TRACE_EVENT ("Max Tries Exceeded:  (last_acq: %d  CID: 0x%04x  num_tries: %u (max: %u) ack_q_count: %u",
                            p_ccb->fcrb.last_rx_ack, p_ccb->local_cid, p_ccb->fcrb.num_tries, p_ccb->peer_cfg.fcr.max_transmit,
-                           GKI_queue_length(&p_ccb->fcrb.waiting_for_ack_q));
+                fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q));
 
         l2cu_disconnect_chnl (p_ccb);
         return (FALSE);
     }
 
     /* tx_seq indicates whether to retransmit a specific sequence or all (if == L2C_FCR_RETX_ALL_PKTS) */
+    list_t *list_ack = NULL;
+    const list_node_t *node_ack = NULL;
+    if (! fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) {
+        list_ack = fixed_queue_get_list(p_ccb->fcrb.waiting_for_ack_q);
+        node_ack = list_begin(list_ack);
+    }
     if (tx_seq != L2C_FCR_RETX_ALL_PKTS) {
         /* If sending only one, the sequence number tells us which one. Look for it.
         */
-        for (p_buf = (BT_HDR *)GKI_getfirst(&p_ccb->fcrb.waiting_for_ack_q); p_buf; p_buf = (BT_HDR *)GKI_getnext (p_buf)) {
-            /* Get the old control word */
-            p = ((UINT8 *) (p_buf + 1)) + p_buf->offset + L2CAP_PKT_OVERHEAD;
+        if (list_ack != NULL) {
+            for ( ; node_ack != list_end(list_ack); node_ack = list_next(node_ack)) {
+                p_buf = (BT_HDR *)list_node(node_ack);
+                /* Get the old control word */
+                p = ((UINT8 *) (p_buf+1)) + p_buf->offset + L2CAP_PKT_OVERHEAD;
 
-            STREAM_TO_UINT16 (ctrl_word, p);
+                STREAM_TO_UINT16 (ctrl_word, p);
 
-            buf_seq = (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT;
+                buf_seq = (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT;
 
-            L2CAP_TRACE_DEBUG ("retransmit_i_frames()   cur seq: %u  looking for: %u", buf_seq, tx_seq);
+                L2CAP_TRACE_DEBUG ("retransmit_i_frames()   cur seq: %u  looking for: %u", buf_seq, tx_seq);
 
-            if (tx_seq == buf_seq) {
-                break;
+                if (tx_seq == buf_seq) {
+                    break;
+                               }
             }
         }
 
         if (!p_buf) {
-            L2CAP_TRACE_ERROR ("retransmit_i_frames() UNKNOWN seq: %u  q_count: %u", tx_seq, GKI_queue_length(&p_ccb->fcrb.waiting_for_ack_q));
+            L2CAP_TRACE_ERROR ("retransmit_i_frames() UNKNOWN seq: %u  q_count: %u",
+                               tx_seq,
+                               fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q));
             return (TRUE);
         }
     } else {
@@ -1446,37 +1445,44 @@ static BOOLEAN retransmit_i_frames (tL2C_CCB *p_ccb, UINT8 tx_seq)
             /* Do not flush other CIDs or partial segments */
             if ((p_buf->layer_specific == 0) && (p_buf->event == p_ccb->local_cid)) {
                 list_remove(p_ccb->p_lcb->link_xmit_data_q, p_buf);
-                GKI_freebuf(p_buf);
+                osi_free(p_buf);
             }
         }
 
         /* Also flush our retransmission queue */
-        while (!GKI_queue_is_empty(&p_ccb->fcrb.retrans_q)) {
-            GKI_freebuf (GKI_dequeue (&p_ccb->fcrb.retrans_q));
-        }
+        while (!fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) {
+            osi_free(fixed_queue_try_dequeue(p_ccb->fcrb.retrans_q));
+               }
 
-        p_buf = (BT_HDR *)GKI_getfirst(&p_ccb->fcrb.waiting_for_ack_q);
+        if (list_ack != NULL) {
+            node_ack = list_begin(list_ack);
+               }
     }
 
-    while (p_buf != NULL) {
-        p_buf2 = l2c_fcr_clone_buf (p_buf, p_buf->offset, p_buf->len, p_ccb->ertm_info.fcr_tx_pool_id);
+    if (list_ack != NULL) {
+        while (node_ack != list_end(list_ack))
+        {
+            p_buf = (BT_HDR *)list_node(node_ack);
+            node_ack = list_next(node_ack);
 
-        if (p_buf2) {
-            p_buf2->layer_specific = p_buf->layer_specific;
+            BT_HDR *p_buf2 = l2c_fcr_clone_buf(p_buf, p_buf->offset, p_buf->len);
+            if (p_buf2)
+            {
+                p_buf2->layer_specific = p_buf->layer_specific;
 
-            GKI_enqueue (&p_ccb->fcrb.retrans_q, p_buf2);
-        }
+                fixed_queue_enqueue(p_ccb->fcrb.retrans_q, p_buf2);
+            }
 
-        if ( (tx_seq != L2C_FCR_RETX_ALL_PKTS) || (p_buf2 == NULL) ) {
-            break;
-        } else {
-            p_buf = (BT_HDR *)GKI_getnext (p_buf);
+            if ( (tx_seq != L2C_FCR_RETX_ALL_PKTS) || (p_buf2 == NULL) ) {
+                break;
+                       }
         }
     }
 
     l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL);
 
-    if (GKI_queue_length(&p_ccb->fcrb.waiting_for_ack_q)) {
+    if (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q))
+    {
         p_ccb->fcrb.num_tries++;
         l2c_fcr_start_timer (p_ccb);
     }
@@ -1508,9 +1514,8 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length
 
     /* If there is anything in the retransmit queue, that goes first
     */
-    if (GKI_getfirst(&p_ccb->fcrb.retrans_q)) {
-        p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->fcrb.retrans_q);
-
+    p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->fcrb.retrans_q);
+    if (p_buf != NULL) {
         /* Update Rx Seq and FCS if we acked some packets while this one was queued */
         prepare_I_frame (p_ccb, p_buf, TRUE);
 
@@ -1531,7 +1536,7 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length
         max_pdu = max_packet_length - L2CAP_MAX_HEADER_FCS;
     }
 
-    p_buf = (BT_HDR *)GKI_getfirst(&p_ccb->xmit_hold_q);
+    p_buf = (BT_HDR *)fixed_queue_try_peek_first(p_ccb->xmit_hold_q);
 
     /* If there is more data than the MPS, it requires segmentation */
     if (p_buf->len > max_pdu) {
@@ -1545,7 +1550,7 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length
 
         /* Get a new buffer and copy the data that can be sent in a PDU */
         p_xmit = l2c_fcr_clone_buf (p_buf, L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET,
-                                    max_pdu, p_ccb->ertm_info.fcr_tx_pool_id);
+                                    max_pdu);
 
         if (p_xmit != NULL) {
             p_buf->event  = p_ccb->local_cid;
@@ -1557,11 +1562,11 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length
             /* copy PBF setting */
             p_xmit->layer_specific = p_buf->layer_specific;
         } else { /* Should never happen if the application has configured buffers correctly */
-            L2CAP_TRACE_ERROR ("L2CAP - cannot get buffer, for segmentation, pool: %u", p_ccb->ertm_info.fcr_tx_pool_id);
+            L2CAP_TRACE_ERROR ("L2CAP - cannot get buffer for segmentation, max_pdu: %u", max_pdu);
             return (NULL);
         }
     } else { /* Use the original buffer if no segmentation, or the last segment */
-        p_xmit = (BT_HDR *)GKI_dequeue (&p_ccb->xmit_hold_q);
+        p_xmit = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q);
 
         if (p_xmit->event != 0) {
             last_seg = TRUE;
@@ -1610,11 +1615,11 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length
     prepare_I_frame (p_ccb, p_xmit, FALSE);
 
     if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) {
-        BT_HDR *p_wack = l2c_fcr_clone_buf (p_xmit, HCI_DATA_PREAMBLE_SIZE, p_xmit->len, p_ccb->ertm_info.fcr_tx_pool_id);
+        BT_HDR *p_wack = l2c_fcr_clone_buf (p_xmit, HCI_DATA_PREAMBLE_SIZE, p_xmit->len);
 
         if (!p_wack) {
-            L2CAP_TRACE_ERROR ("L2CAP - no buffer for xmit cloning, CID: 0x%04x  Pool: %u  Count: %u",
-                               p_ccb->local_cid, p_ccb->ertm_info.fcr_tx_pool_id,  GKI_poolfreecount(p_ccb->ertm_info.fcr_tx_pool_id));
+            L2CAP_TRACE_ERROR("L2CAP - no buffer for xmit cloning, CID: 0x%04x  Length: %u",
+                              p_ccb->local_cid, p_xmit->len);
 
             /* We will not save the FCS in case we reconfigure and change options */
             if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) {
@@ -1622,13 +1627,13 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length
             }
 
             /* Pretend we sent it and it got lost */
-            GKI_enqueue (&p_ccb->fcrb.waiting_for_ack_q, p_xmit);
+            fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_xmit);
             return (NULL);
         } else {
 #if (L2CAP_ERTM_STATS == TRUE)
             /* set timestamp at the end of tx I-frame to get acking delay */
             p = ((UINT8 *) (p_wack + 1)) + p_wack->offset + p_wack->len;
-            UINT32_TO_STREAM (p, GKI_get_os_tick_count());
+            UINT32_TO_STREAM (p, osi_time_get_os_boottime_ms());
 #endif
             /* We will not save the FCS in case we reconfigure and change options */
             if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) {
@@ -1636,7 +1641,7 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length
             }
 
             p_wack->layer_specific = p_xmit->layer_specific;
-            GKI_enqueue (&p_ccb->fcrb.waiting_for_ack_q, p_wack);
+            fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_wack);
         }
 
 #if (L2CAP_ERTM_STATS == TRUE)
@@ -2047,7 +2052,7 @@ UINT8 l2c_fcr_process_peer_cfg_req(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg)
                 }
             }
 
-            max_retrans_size = GKI_get_pool_bufsize (p_ccb->ertm_info.fcr_tx_pool_id) - sizeof(BT_HDR)
+            max_retrans_size = p_ccb->ertm_info.fcr_tx_buf_size - sizeof(BT_HDR)
                                - L2CAP_MIN_OFFSET - L2CAP_SDU_LEN_OFFSET - L2CAP_FCS_LEN;
 
             /* Ensure the MPS is not bigger than the MTU */
@@ -2113,42 +2118,48 @@ static void l2c_fcr_collect_ack_delay (tL2C_CCB *p_ccb, UINT8 num_bufs_acked)
     index = p_ccb->fcrb.ack_delay_avg_index;
 
     /* update sum, max and min of waiting for ack queue size */
-    p_ccb->fcrb.ack_q_count_avg[index] += p_ccb->fcrb.waiting_for_ack_q.count;
+    p_ccb->fcrb.ack_q_count_avg[index] +=
+        fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q);
 
-    if ( p_ccb->fcrb.waiting_for_ack_q.count > p_ccb->fcrb.ack_q_count_max[index] ) {
-        p_ccb->fcrb.ack_q_count_max[index] = p_ccb->fcrb.waiting_for_ack_q.count;
-    }
+    if (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q) > p_ccb->fcrb.ack_q_count_max[index]) {
+        p_ccb->fcrb.ack_q_count_max[index] = fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q);
+       }
 
-    if ( p_ccb->fcrb.waiting_for_ack_q.count < p_ccb->fcrb.ack_q_count_min[index] ) {
-        p_ccb->fcrb.ack_q_count_min[index] = p_ccb->fcrb.waiting_for_ack_q.count;
-    }
+    if (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q) < p_ccb->fcrb.ack_q_count_min[index]) {
+        p_ccb->fcrb.ack_q_count_min[index] = fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q);
+       }
 
     /* update sum, max and min of round trip delay of acking */
-    p_buf = (BT_HDR *)(p_ccb->fcrb.waiting_for_ack_q.p_first);
-    for (xx = 0; (xx < num_bufs_acked) && (p_buf); xx++) {
-        /* adding up length of acked I-frames to get throughput */
-        p_ccb->fcrb.throughput[index] += p_buf->len - 8;
-
-        if ( xx == num_bufs_acked - 1 ) {
-            /* get timestamp from tx I-frame that receiver is acking */
-            p = ((UINT8 *) (p_buf + 1)) + p_buf->offset + p_buf->len;
-            if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) {
-                p += L2CAP_FCS_LEN;
-            }
+    list_t *list = NULL;
+    if (! fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q))
+        list = fixed_queue_get_list(p_ccb->fcrb.waiting_for_ack_q);
+    if (list != NULL) {
+        for (const list_node_t *node = list_begin(list), xx = 0;
+             (node != list_end(list)) && (xx < num_bufs_acked);
+             node = list_next(node), xx++) {
+            p_buf = list_node(node);
+            /* adding up length of acked I-frames to get throughput */
+            p_ccb->fcrb.throughput[index] += p_buf->len - 8;
+
+            if ( xx == num_bufs_acked - 1 ) {
+                /* get timestamp from tx I-frame that receiver is acking */
+                p = ((UINT8 *) (p_buf+1)) + p_buf->offset + p_buf->len;
+                if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) {
+                    p += L2CAP_FCS_LEN;
+                }
 
-            STREAM_TO_UINT32 (timestamp, p);
-            delay = GKI_get_os_tick_count() - timestamp;
+                STREAM_TO_UINT32(timestamp, p);
+                delay = osi_time_get_os_boottime_ms() - timestamp;
 
-            p_ccb->fcrb.ack_delay_avg[index] += delay;
-            if ( delay > p_ccb->fcrb.ack_delay_max[index] ) {
-                p_ccb->fcrb.ack_delay_max[index] = delay;
-            }
-            if ( delay < p_ccb->fcrb.ack_delay_min[index] ) {
-                p_ccb->fcrb.ack_delay_min[index] = delay;
-            }
+                p_ccb->fcrb.ack_delay_avg[index] += delay;
+                if ( delay > p_ccb->fcrb.ack_delay_max[index] ) {
+                    p_ccb->fcrb.ack_delay_max[index] = delay;
+                }
+                if ( delay < p_ccb->fcrb.ack_delay_min[index] ) {
+                    p_ccb->fcrb.ack_delay_min[index] = delay;
+                }
+                       }
         }
-
-        p_buf = GKI_getnext(p_buf);
     }
 
     p_ccb->fcrb.ack_delay_avg_count++;
@@ -2161,7 +2172,7 @@ static void l2c_fcr_collect_ack_delay (tL2C_CCB *p_ccb, UINT8 num_bufs_acked)
         p_ccb->fcrb.ack_delay_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES;
 
         /* calculate throughput */
-        timestamp = GKI_get_os_tick_count();
+        timestamp = osi_time_get_os_boottime_ms();
         if (timestamp - p_ccb->fcrb.throughput_start > 0 ) {
             p_ccb->fcrb.throughput[index] /= (timestamp - p_ccb->fcrb.throughput_start);
         }
@@ -2191,4 +2202,4 @@ static void l2c_fcr_collect_ack_delay (tL2C_CCB *p_ccb, UINT8 num_bufs_acked)
     }
 }
 #endif
-#endif ///CLASSIC_BT_INCLUDED == TRUE
\ No newline at end of file
+#endif ///CLASSIC_BT_INCLUDED == TRUE
index 72dc20774022e4203803343292804667e048de0a..e7dd2e7759c5c1fd21907fe2fdd93e2f3912e344 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "controller.h"
 //#include "btcore/include/counter.h"
-#include "gki.h"
 #include "bt_types.h"
 //#include "bt_utils.h"
 #include "hcimsgs.h"
@@ -421,7 +420,7 @@ BOOLEAN l2c_link_hci_disc_comp (UINT16 handle, UINT8 reason)
                 while (!list_is_empty(p_lcb->link_xmit_data_q)) {
                     p_buf = list_front(p_lcb->link_xmit_data_q);
                     list_remove(p_lcb->link_xmit_data_q, p_buf);
-                    GKI_freebuf(p_buf);
+                    osi_free(p_buf);
                 }
             } else
 #endif
@@ -795,90 +794,26 @@ void l2c_link_adjust_allocation (void)
 *******************************************************************************/
 void l2c_link_adjust_chnl_allocation (void)
 {
-    tL2C_CCB    *p_ccb;
     UINT8       xx;
 
-    UINT16      weighted_chnls[GKI_NUM_TOTAL_BUF_POOLS];
-    UINT16      quota_per_weighted_chnls[GKI_NUM_TOTAL_BUF_POOLS];
-    UINT16      reserved_buff[GKI_NUM_TOTAL_BUF_POOLS];
 
     L2CAP_TRACE_DEBUG ("l2c_link_adjust_chnl_allocation");
 
-    /* initialize variables */
-    for (xx = 0; xx < GKI_NUM_TOTAL_BUF_POOLS; xx++ ) {
-        weighted_chnls[xx] = 0;
-        reserved_buff[xx] = 0;
-    }
-
-    /* add up all of tx and rx data rate requirement */
-    /* channel required higher data rate will get more buffer quota */
-    for (xx = 0; xx < MAX_L2CAP_CHANNELS; xx++) {
-        p_ccb = l2cb.ccb_pool + xx;
-
-        if (!p_ccb->in_use) {
-            continue;
-        }
-
-        if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) {
-            weighted_chnls[p_ccb->ertm_info.user_tx_pool_id] += p_ccb->tx_data_rate;
-            weighted_chnls[p_ccb->ertm_info.user_rx_pool_id] += p_ccb->rx_data_rate;
-
-            if (p_ccb->ertm_info.fcr_tx_pool_id == HCI_ACL_POOL_ID) {
-                /* reserve buffers only for wait_for_ack_q to maximize throughput */
-                /* retrans_q will work based on buffer status */
-                reserved_buff[HCI_ACL_POOL_ID] += p_ccb->peer_cfg.fcr.tx_win_sz;
-            }
-
-            if (p_ccb->ertm_info.fcr_rx_pool_id == HCI_ACL_POOL_ID) {
-                /* reserve buffers for srej_rcv_hold_q */
-                reserved_buff[HCI_ACL_POOL_ID] += p_ccb->peer_cfg.fcr.tx_win_sz;
-            }
-        } else {
-            /* low data rate is 1, medium is 2, high is 3 and no traffic is 0 */
-            weighted_chnls[HCI_ACL_POOL_ID] += p_ccb->tx_data_rate + p_ccb->rx_data_rate;
-        }
-    }
-
-
-    /* get unit quota per pool */
-    for (xx = 0; xx < GKI_NUM_TOTAL_BUF_POOLS; xx++ ) {
-        if ( weighted_chnls[xx] > 0 ) {
-            if (GKI_poolcount(xx) > reserved_buff[xx]) {
-                quota_per_weighted_chnls[xx] = ((GKI_poolcount(xx) - reserved_buff[xx]) / weighted_chnls[xx]) + 1;
-            } else {
-                quota_per_weighted_chnls[xx] = 1;
-            }
-
-            L2CAP_TRACE_DEBUG ("POOL ID:%d, GKI_poolcount = %d, reserved_buff = %d, weighted_chnls = %d, quota_per_weighted_chnls = %d",
-                               xx, GKI_poolcount(xx), reserved_buff[xx], weighted_chnls[xx], quota_per_weighted_chnls[xx] );
-        } else {
-            quota_per_weighted_chnls[xx] = 0;
-        }
-    }
-
-
     /* assign buffer quota to each channel based on its data rate requirement */
-    for (xx = 0; xx < MAX_L2CAP_CHANNELS; xx++) {
-        p_ccb = l2cb.ccb_pool + xx;
+    for (xx = 0; xx < MAX_L2CAP_CHANNELS; xx++)
+    {
+        tL2C_CCB *p_ccb = l2cb.ccb_pool + xx;
 
         if (!p_ccb->in_use) {
             continue;
-        }
-
-        if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) {
-            p_ccb->buff_quota = quota_per_weighted_chnls[p_ccb->ertm_info.user_tx_pool_id] * p_ccb->tx_data_rate;
+               }
 
-            L2CAP_TRACE_EVENT ("CID:0x%04x FCR Mode:%u UserTxPool:%u Priority:%u TxDataRate:%u Quota:%u",
-                               p_ccb->local_cid, p_ccb->peer_cfg.fcr.mode, p_ccb->ertm_info.user_tx_pool_id,
-                               p_ccb->ccb_priority, p_ccb->tx_data_rate, p_ccb->buff_quota);
-
-        } else {
-            p_ccb->buff_quota = quota_per_weighted_chnls[HCI_ACL_POOL_ID] * p_ccb->tx_data_rate;
-
-            L2CAP_TRACE_EVENT ("CID:0x%04x Priority:%u TxDataRate:%u Quota:%u",
-                               p_ccb->local_cid,
-                               p_ccb->ccb_priority, p_ccb->tx_data_rate, p_ccb->buff_quota);
-        }
+        tL2CAP_CHNL_DATA_RATE data_rate = p_ccb->tx_data_rate + p_ccb->rx_data_rate;
+        p_ccb->buff_quota = L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA * data_rate;
+        L2CAP_TRACE_EVENT("CID:0x%04x FCR Mode:%u Priority:%u TxDataRate:%u RxDataRate:%u Quota:%u",
+                          p_ccb->local_cid, p_ccb->peer_cfg.fcr.mode,
+                          p_ccb->ccb_priority, p_ccb->tx_data_rate,
+                          p_ccb->rx_data_rate, p_ccb->buff_quota);
 
         /* quota may be change so check congestion */
         l2cu_check_channel_congestion (p_ccb);
@@ -1005,7 +940,7 @@ BOOLEAN l2c_link_check_power_mode (tL2C_LCB *p_lcb)
      */
     if (list_is_empty(p_lcb->link_xmit_data_q)) {
         for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) {
-            if (!GKI_queue_is_empty(&p_ccb->xmit_hold_q)) {
+            if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
                 need_to_active = TRUE;
                 break;
             }
@@ -1488,7 +1423,7 @@ void l2c_link_segments_xmitted (BT_HDR *p_msg)
     /* Find the LCB based on the handle */
     if ((p_lcb = l2cu_find_lcb_by_handle (handle)) == NULL) {
         L2CAP_TRACE_WARNING ("L2CAP - rcvd segment complete, unknown handle: %d\n", handle);
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
         return;
     }
 
@@ -1501,6 +1436,6 @@ void l2c_link_segments_xmitted (BT_HDR *p_msg)
 
         l2c_link_check_send_pkts (p_lcb, NULL, NULL);
     } else {
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
     }
 }
index 3ed8a0d002bdcb854adb0db72afa151806dd0927..d995d7376bc14d77ec97b8b52317ec395d13ea08 100644 (file)
@@ -31,7 +31,6 @@
 #include "bt_target.h"
 #include "btm_int.h"
 #include "btu.h"
-#include "gki.h"
 #include "hcimsgs.h"
 #include "l2c_api.h"
 #include "l2c_int.h"
@@ -67,7 +66,7 @@ void l2c_bcst_msg( BT_HDR *p_buf, UINT16 psm )
     /* Ensure we have enough space in the buffer for the L2CAP and HCI headers */
     if (p_buf->offset < L2CAP_BCST_MIN_OFFSET) {
         L2CAP_TRACE_ERROR ("L2CAP - cannot send buffer, offset: %d", p_buf->offset);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -162,12 +161,12 @@ void l2c_rcv_acl_data (BT_HDR *p_msg)
                                    " opcode:%d cur count:%d", handle, p_msg->layer_specific, rcv_cid,
                                    cmd_code, list_length(l2cb.rcv_pending_q));
             }
-            GKI_freebuf (p_msg);
+            osi_free (p_msg);
             return;
         }
     } else {
         L2CAP_TRACE_WARNING ("L2CAP - expected pkt start or complete, got: %d", pkt_type);
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
         return;
     }
 
@@ -192,7 +191,7 @@ void l2c_rcv_acl_data (BT_HDR *p_msg)
     if (rcv_cid >= L2CAP_BASE_APPL_CID) {
         if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, rcv_cid)) == NULL) {
             L2CAP_TRACE_WARNING ("L2CAP - unknown CID: 0x%04x", rcv_cid);
-            GKI_freebuf (p_msg);
+            osi_free (p_msg);
             return;
         }
     }
@@ -202,7 +201,7 @@ void l2c_rcv_acl_data (BT_HDR *p_msg)
         p_msg->offset += L2CAP_PKT_OVERHEAD;
     } else {
         L2CAP_TRACE_WARNING ("L2CAP - got incorrect hci header" );
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
         return;
     }
 
@@ -210,7 +209,7 @@ void l2c_rcv_acl_data (BT_HDR *p_msg)
         L2CAP_TRACE_WARNING ("L2CAP - bad length in pkt. Exp: %d  Act: %d",
                              l2cap_len, p_msg->len);
 
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
         return;
     }
 
@@ -221,7 +220,7 @@ void l2c_rcv_acl_data (BT_HDR *p_msg)
 #if (CLASSIC_BT_INCLUDED == TRUE)
         process_l2cap_cmd (p_lcb, p, l2cap_len);
 #endif  ///CLASSIC_BT_INCLUDED == TRUE
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
     } else if (rcv_cid == L2CAP_CONNECTIONLESS_CID) {
         //counter_add("l2cap.ch2.rx.bytes", l2cap_len);
         //counter_add("l2cap.ch2.rx.pkts", 1);
@@ -235,14 +234,14 @@ void l2c_rcv_acl_data (BT_HDR *p_msg)
             /* nothing to do */
         } else
 #endif
-            GKI_freebuf (p_msg);
+            osi_free (p_msg);
     }
 #if (BLE_INCLUDED == TRUE)
     else if (rcv_cid == L2CAP_BLE_SIGNALLING_CID) {
         //counter_add("l2cap.ble.rx.bytes", l2cap_len);
         //counter_add("l2cap.ble.rx.pkts", 1);
         l2cble_process_sig_cmd (p_lcb, p, l2cap_len);
-        GKI_freebuf (p_msg);
+        osi_free (p_msg);
     }
 #endif
 #if (L2CAP_NUM_FIXED_CHNLS > 0)
@@ -265,7 +264,7 @@ void l2c_rcv_acl_data (BT_HDR *p_msg)
                 (*l2cb.fixed_reg[rcv_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb)
                 (rcv_cid, p_lcb->remote_bd_addr, p_msg);
         } else {
-            GKI_freebuf (p_msg);
+            osi_free (p_msg);
         }
     }
 #endif
@@ -274,7 +273,7 @@ void l2c_rcv_acl_data (BT_HDR *p_msg)
         //counter_add("l2cap.dyn.rx.bytes", l2cap_len);
         //counter_add("l2cap.dyn.rx.pkts", 1);
         if (p_ccb == NULL) {
-            GKI_freebuf (p_msg);
+            osi_free (p_msg);
         } else {
             /* Basic mode packets go straight to the state machine */
             if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) {
@@ -288,7 +287,7 @@ void l2c_rcv_acl_data (BT_HDR *p_msg)
                     l2c_fcr_proc_pdu (p_ccb, p_msg);
 #endif  ///CLASSIC_BT_INCLUDED == TRUE
                 } else {
-                    GKI_freebuf (p_msg);
+                    osi_free (p_msg);
                 }
             }
         }
@@ -859,6 +858,7 @@ void l2c_init (void)
 void l2c_free(void)
 {
     list_free(l2cb.rcv_pending_q);
+    l2cb.rcv_pending_q = NULL;
 }
 
 /*******************************************************************************
@@ -921,7 +921,7 @@ UINT8 l2c_data_write (UINT16 cid, BT_HDR *p_data, UINT16 flags)
     /* Find the channel control block. We don't know the link it is on. */
     if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
         L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_DataWrite, CID: %d", cid);
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         return (L2CAP_DW_FAILED);
     }
 
@@ -929,7 +929,7 @@ UINT8 l2c_data_write (UINT16 cid, BT_HDR *p_data, UINT16 flags)
                   bigger than mtu size of peer is a violation of protocol */
     if (p_data->len > p_ccb->peer_cfg.mtu) {
         L2CAP_TRACE_WARNING ("L2CAP - CID: 0x%04x  cannot send message bigger than peer's mtu size", cid);
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         return (L2CAP_DW_FAILED);
     }
 #endif
@@ -940,9 +940,11 @@ UINT8 l2c_data_write (UINT16 cid, BT_HDR *p_data, UINT16 flags)
     /* If already congested, do not accept any more packets */
     if (p_ccb->cong_sent) {
         L2CAP_TRACE_ERROR ("L2CAP - CID: 0x%04x cannot send, already congested  xmit_hold_q.count: %u  buff_quota: %u",
-                           p_ccb->local_cid, GKI_queue_length(&p_ccb->xmit_hold_q), p_ccb->buff_quota);
+                           p_ccb->local_cid,
+                           fixed_queue_length(p_ccb->xmit_hold_q),
+                           p_ccb->buff_quota);
 
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         return (L2CAP_DW_FAILED);
     }
 
index 9340ed24f61502eda2b8ff4798bd5c5087060c29..a3c92e47ead3e4a20311f1d58f12a9e9e7380569 100644 (file)
@@ -26,7 +26,6 @@
 #include <string.h>
 //#include <stdio.h>
 
-#include "gki.h"
 #include "bt_types.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
@@ -99,7 +98,7 @@ static void l2c_ucd_data_ind_cback (BD_ADDR rem_bda, BT_HDR *p_buf)
 
     if ((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) {
         L2CAP_TRACE_ERROR ("L2CAP - no RCB for l2c_ucd_data_ind_cback, PSM: 0x%04x", psm);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
     } else {
         p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb(rem_bda, p_buf);
     }
@@ -381,7 +380,7 @@ UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 fla
     if (((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL)
             || ( p_rcb->ucd.state == L2C_UCD_STATE_UNUSED )) {
         L2CAP_TRACE_WARNING ("L2CAP - no RCB for L2CA_UcdDataWrite, PSM: 0x%04x", psm);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (L2CAP_DW_FAILED);
     }
 
@@ -390,14 +389,14 @@ UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 fla
     if (((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL)
             || ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL)) {
         if ( l2c_ucd_connect (rem_bda) == FALSE ) {
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
             return (L2CAP_DW_FAILED);
         }
 
         /* If we still don't have lcb and ccb after connect attempt, then can't proceed */
         if (((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL)
                 || ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL)) {
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
             return (L2CAP_DW_FAILED);
         }
     }
@@ -412,7 +411,7 @@ UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 fla
     /* UCD MTU check */
     if ((p_lcb->ucd_mtu) && (p_buf->len > p_lcb->ucd_mtu)) {
         L2CAP_TRACE_WARNING ("L2CAP - Handle: 0x%04x  UCD bigger than peer's UCD mtu size cannot be sent", p_lcb->handle);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (L2CAP_DW_FAILED);
     }
 
@@ -420,10 +419,11 @@ UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 fla
     if (p_ccb->cong_sent) {
         L2CAP_TRACE_ERROR ("L2CAP - Handle: 0x%04x UCD cannot be sent, already congested count: %u  buff_quota: %u",
                            p_lcb->handle,
-                           (p_ccb->xmit_hold_q.count + p_lcb->ucd_out_sec_pending_q.count),
+                           (fixed_queue_length(p_ccb->xmit_hold_q) +
+                            fixed_queue_length(p_lcb->ucd_out_sec_pending_q)),
                            p_ccb->buff_quota);
 
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (L2CAP_DW_FAILED);
     }
 
@@ -596,12 +596,16 @@ void l2c_ucd_delete_sec_pending_q(tL2C_LCB  *p_lcb)
 {
     /* clean up any security pending UCD */
     while (p_lcb->ucd_out_sec_pending_q.p_first) {
-        GKI_freebuf (GKI_dequeue (&p_lcb->ucd_out_sec_pending_q));
-    }
-
-    while (p_lcb->ucd_in_sec_pending_q.p_first) {
-        GKI_freebuf (GKI_dequeue (&p_lcb->ucd_in_sec_pending_q));
-    }
+        osi_free(fixed_queue_try_dequeue(p_lcb->ucd_out_sec_pending_q));
+       }
+    fixed_queue_free(p_lcb->ucd_out_sec_pending_q, NULL);
+    p_lcb->ucd_out_sec_pending_q = NULL;
+
+    while (! fixed_queue_is_empty(p_lcb->ucd_in_sec_pending_q)) {
+        osi_free(fixed_queue_try_dequeue(p_lcb->ucd_in_sec_pending_q));
+       }
+    fixed_queue_free(p_lcb->ucd_in_sec_pending_q);
+    p_lcb->ucd_in_sec_pending_q = NULL;
 }
 
 /*******************************************************************************
@@ -679,7 +683,7 @@ BOOLEAN l2c_ucd_check_pending_info_req(tL2C_CCB  *p_ccb)
 *******************************************************************************/
 void l2c_ucd_enqueue_pending_out_sec_q(tL2C_CCB  *p_ccb, void *p_data)
 {
-    GKI_enqueue (&p_ccb->p_lcb->ucd_out_sec_pending_q, p_data);
+    fixed_queue_enqueue(p_ccb->p_lcb->ucd_out_sec_pending_q, p_data);
     l2cu_check_channel_congestion (p_ccb);
 }
 
@@ -694,13 +698,12 @@ void l2c_ucd_enqueue_pending_out_sec_q(tL2C_CCB  *p_ccb, void *p_data)
 *******************************************************************************/
 BOOLEAN l2c_ucd_check_pending_out_sec_q(tL2C_CCB  *p_ccb)
 {
-    UINT8 *p;
-    UINT16 psm;
-    BT_HDR *p_buf;
+    BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_peek_first(p_ccb->p_lcb->ucd_out_sec_pending_q);
+
+    if (p_buf != NULL) {
+        UINT16 psm;
+        UINT8 *p = (UINT8 *)(p_buf + 1) + p_buf->offset;
 
-    if ( p_ccb->p_lcb->ucd_out_sec_pending_q.count ) {
-        p_buf = (BT_HDR *)(p_ccb->p_lcb->ucd_out_sec_pending_q.p_first);
-        p = (UINT8 *)(p_buf + 1) + p_buf->offset;
         STREAM_TO_UINT16(psm, p)
 
         p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP;
@@ -724,11 +727,9 @@ BOOLEAN l2c_ucd_check_pending_out_sec_q(tL2C_CCB  *p_ccb)
 *******************************************************************************/
 void l2c_ucd_send_pending_out_sec_q(tL2C_CCB  *p_ccb)
 {
-    BT_HDR *p_buf;
-
-    if ( p_ccb->p_lcb->ucd_out_sec_pending_q.count ) {
-        p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->p_lcb->ucd_out_sec_pending_q);
+    BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q);
 
+    if (p_buf != NULL) {
         l2c_enqueue_peer_data (p_ccb, (BT_HDR *)p_buf);
         l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL);
     }
@@ -746,14 +747,12 @@ void l2c_ucd_send_pending_out_sec_q(tL2C_CCB  *p_ccb)
 *******************************************************************************/
 void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB  *p_ccb)
 {
-    BT_HDR *p_buf;
-
-    p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->p_lcb->ucd_out_sec_pending_q);
+    BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q);
 
     /* we may need to report to application */
 
     if (p_buf) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
     }
 }
 
@@ -768,13 +767,11 @@ void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB  *p_ccb)
 *******************************************************************************/
 BOOLEAN l2c_ucd_check_pending_in_sec_q(tL2C_CCB  *p_ccb)
 {
-    UINT8 *p;
-    UINT16 psm;
-    BT_HDR *p_buf;
+    BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q);
 
-    if ( p_ccb->p_lcb->ucd_in_sec_pending_q.count ) {
-        p_buf = (BT_HDR *)(p_ccb->p_lcb->ucd_in_sec_pending_q.p_first);
-        p = (UINT8 *)(p_buf + 1) + p_buf->offset;
+    if (p_buf != NULL) {
+        UINT16 psm;
+        UINT8 *p = (UINT8 *)(p_buf + 1) + p_buf->offset;
         STREAM_TO_UINT16(psm, p)
 
         p_ccb->chnl_state = CST_TERM_W4_SEC_COMP;
@@ -798,11 +795,9 @@ BOOLEAN l2c_ucd_check_pending_in_sec_q(tL2C_CCB  *p_ccb)
 *******************************************************************************/
 void l2c_ucd_send_pending_in_sec_q(tL2C_CCB  *p_ccb)
 {
-    BT_HDR *p_buf;
-
-    if ( p_ccb->p_lcb->ucd_in_sec_pending_q.count ) {
-        p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->p_lcb->ucd_in_sec_pending_q);
+    BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q)
 
+    if (p_buf != NULL) {
         p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb(p_ccb->p_lcb->remote_bd_addr, (BT_HDR *)p_buf);
     }
 }
@@ -819,12 +814,10 @@ void l2c_ucd_send_pending_in_sec_q(tL2C_CCB  *p_ccb)
 *******************************************************************************/
 void l2c_ucd_discard_pending_in_sec_q(tL2C_CCB  *p_ccb)
 {
-    BT_HDR *p_buf;
-
-    p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->p_lcb->ucd_in_sec_pending_q);
+    BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q);
 
     if (p_buf) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
     }
 }
 
@@ -849,7 +842,7 @@ BOOLEAN l2c_ucd_check_rx_pkts(tL2C_LCB  *p_lcb, BT_HDR *p_msg)
             /* Allocate a channel control block */
             if ((p_ccb = l2cu_allocate_ccb (p_lcb, 0)) == NULL) {
                 L2CAP_TRACE_WARNING ("L2CAP - no CCB for UCD reception");
-                GKI_freebuf (p_msg);
+                osi_free (p_msg);
                 return TRUE;
             } else {
                 /* Set CID for the connection */
@@ -905,7 +898,7 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data)
             break;
 
         case L2CEVT_L2CAP_DATA:         /* Peer data packet rcvd    */
-            GKI_enqueue (&p_ccb->p_lcb->ucd_in_sec_pending_q, p_data);
+            fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data);
             break;
 
         case L2CEVT_L2CA_DATA_WRITE:    /* Upper layer data to send */
@@ -941,7 +934,8 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data)
             p_ccb->chnl_state = CST_OPEN;
             l2c_ucd_send_pending_out_sec_q(p_ccb);
 
-            if ( p_ccb->p_lcb->ucd_out_sec_pending_q.count ) {
+            if (! fixed_queue_is_empty(p_ccb->p_lcb->ucd_out_sec_pending_q))
+            {
                 /* start a timer to send next UCD packet in OPEN state */
                 /* it will prevent stack overflow */
                 btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, 0);
@@ -964,7 +958,7 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data)
             break;
 
         case L2CEVT_L2CAP_DATA:         /* Peer data packet rcvd    */
-            GKI_enqueue (&p_ccb->p_lcb->ucd_in_sec_pending_q, p_data);
+            fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data);
             break;
 
         case L2CEVT_L2CAP_INFO_RSP:
@@ -985,7 +979,7 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data)
             p_ccb->chnl_state = CST_OPEN;
             l2c_ucd_send_pending_in_sec_q (p_ccb);
 
-            if ( p_ccb->p_lcb->ucd_in_sec_pending_q.count ) {
+            if (! fixed_queue_is_empty(p_ccb->p_lcb->ucd_in_sec_pending_q)) {
                 /* start a timer to check next UCD packet in OPEN state */
                 /* it will prevent stack overflow */
                 btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, 0);
@@ -1012,7 +1006,7 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data)
             break;
 
         case L2CEVT_L2CAP_DATA:             /* Peer data packet rcvd    */
-            GKI_enqueue (&p_ccb->p_lcb->ucd_in_sec_pending_q, p_data);
+            fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data);
             break;
 
         case L2CEVT_SEC_RE_SEND_CMD:        /* BTM has enough info to proceed */
@@ -1039,7 +1033,7 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data)
             /* stop idle timer of UCD */
             btu_stop_timer (&p_ccb->timer_entry);
 
-            GKI_enqueue (&p_ccb->p_lcb->ucd_in_sec_pending_q, p_data);
+            fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data);
             l2c_ucd_check_pending_in_sec_q (p_ccb);
             break;
 
index f0f96dbedca9f44961d1c19b169d0b0960a28cc5..b6514b23b5c0a85f3f21dcb6b2dbdd0c8251604f 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-//#include <stdio.h>
 
+#include "allocator.h"
 #include "controller.h"
-#include "gki.h"
 #include "bt_types.h"
 #include "hcimsgs.h"
 #include "l2cdefs.h"
@@ -133,7 +132,7 @@ void l2cu_release_lcb (tL2C_LCB *p_lcb)
 
     /* Release any unfinished L2CAP packet on this link */
     if (p_lcb->p_hcit_rcv_acl) {
-        GKI_freebuf(p_lcb->p_hcit_rcv_acl);
+        osi_free(p_lcb->p_hcit_rcv_acl);
         p_lcb->p_hcit_rcv_acl = NULL;
     }
 
@@ -191,7 +190,7 @@ void l2cu_release_lcb (tL2C_LCB *p_lcb)
         while (!list_is_empty(p_lcb->link_xmit_data_q)) {
             BT_HDR *p_buf = list_front(p_lcb->link_xmit_data_q);
             list_remove(p_lcb->link_xmit_data_q, p_buf);
-            GKI_freebuf(p_buf);
+            osi_free(p_buf);
         }
         list_free(p_lcb->link_xmit_data_q);
         p_lcb->link_xmit_data_q = NULL;
@@ -321,7 +320,7 @@ BOOLEAN l2c_is_cmd_rejected (UINT8 cmd_code, UINT8 id, tL2C_LCB *p_lcb)
 *******************************************************************************/
 BT_HDR *l2cu_build_header (tL2C_LCB *p_lcb, UINT16 len, UINT8 cmd, UINT8 id)
 {
-    BT_HDR  *p_buf = (BT_HDR *)GKI_getpoolbuf (L2CAP_CMD_POOL_ID);
+    BT_HDR  *p_buf = (BT_HDR *)osi_malloc(L2CAP_CMD_BUF_SIZE);
     UINT8   *p;
 
     if (!p_buf) {
@@ -770,7 +769,7 @@ void l2cu_send_peer_config_rej (tL2C_CCB *p_ccb, UINT8 *p_data, UINT16 data_len,
         return;
     }
 
-    p_buf = (BT_HDR *)GKI_getbuf (len + rej_len);
+    p_buf = (BT_HDR *)osi_malloc (len + rej_len);
 
     if (!p_buf) {
         L2CAP_TRACE_ERROR ("L2CAP - no buffer for cfg_rej");
@@ -895,8 +894,7 @@ void l2cu_send_peer_disc_req (tL2C_CCB *p_ccb)
        layer checks that all buffers are sent before disconnecting.
     */
     if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) {
-        while (GKI_getfirst(&p_ccb->xmit_hold_q)) {
-            p_buf2 = (BT_HDR *)GKI_dequeue (&p_ccb->xmit_hold_q);
+        while ((p_buf2 = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q)) != NULL) {
             l2cu_set_acl_hci_header (p_buf2, p_ccb);
             l2c_link_check_send_pkts (p_ccb->p_lcb, p_ccb, p_buf2);
         }
@@ -1002,17 +1000,12 @@ void l2cu_send_peer_echo_rsp (tL2C_LCB *p_lcb, UINT8 id, UINT8 *p_data, UINT16 d
     } else {
         p_lcb->cur_echo_id = id;
     }
-    /* Don't respond if we more than 10% of our buffers are used */
-    if (GKI_poolutilization (L2CAP_CMD_POOL_ID) > 10) {
-        L2CAP_TRACE_WARNING ("L2CAP gki pool used up to more than 10%%, ignore echo response");
-        return;
-    }
 
     uint16_t acl_data_size = controller_get_interface()->get_acl_data_size_classic();
     uint16_t acl_packet_size = controller_get_interface()->get_acl_packet_size_classic();
     /* Don't return data if it does not fit in ACL and L2CAP MTU */
-    maxlen = (GKI_get_pool_bufsize(L2CAP_CMD_POOL_ID) > acl_packet_size) ?
-             acl_data_size : (UINT16)GKI_get_pool_bufsize(L2CAP_CMD_POOL_ID);
+    maxlen = (L2CAP_CMD_BUF_SIZE > acl_packet_size) ?
+               acl_data_size : (UINT16)L2CAP_CMD_BUF_SIZE;
     maxlen -= (UINT16)(BT_HDR_SIZE + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD +
                        L2CAP_CMD_OVERHEAD + L2CAP_ECHO_RSP_LEN);
 
@@ -1490,14 +1483,17 @@ tL2C_CCB *l2cu_allocate_ccb (tL2C_LCB *p_lcb, UINT16 cid)
 #endif  ///CLASSIC_BT_INCLUDED == TRUE
     p_ccb->ertm_info.preferred_mode  = L2CAP_FCR_BASIC_MODE;        /* Default mode for channel is basic mode */
     p_ccb->ertm_info.allowed_modes   = L2CAP_FCR_CHAN_OPT_BASIC;    /* Default mode for channel is basic mode */
-    p_ccb->ertm_info.fcr_rx_pool_id  = L2CAP_FCR_RX_POOL_ID;
-    p_ccb->ertm_info.fcr_tx_pool_id  = L2CAP_FCR_TX_POOL_ID;
-    p_ccb->ertm_info.user_rx_pool_id = HCI_ACL_POOL_ID;
-    p_ccb->ertm_info.user_tx_pool_id = HCI_ACL_POOL_ID;
+    p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE;
+    p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE;
+    p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE;
+    p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE;
     p_ccb->max_rx_mtu                = L2CAP_MTU_SIZE;
-    p_ccb->tx_mps                    = GKI_get_pool_bufsize(HCI_ACL_POOL_ID) - 32;
+    p_ccb->tx_mps                    = L2CAP_FCR_TX_BUF_SIZE - 32;
 
-    GKI_init_q (&p_ccb->xmit_hold_q);
+    p_ccb->xmit_hold_q  = fixed_queue_new(SIZE_MAX);
+    p_ccb->fcrb.srej_rcv_hold_q = fixed_queue_new(SIZE_MAX);
+    p_ccb->fcrb.retrans_q = fixed_queue_new(SIZE_MAX);
+    p_ccb->fcrb.waiting_for_ack_q = fixed_queue_new(SIZE_MAX);
 
     p_ccb->cong_sent    = FALSE;
     p_ccb->buff_quota   = 2;                /* This gets set after config */
@@ -1618,9 +1614,10 @@ void l2cu_release_ccb (tL2C_CCB *p_ccb)
     /* Stop the timer */
     btu_stop_timer (&p_ccb->timer_entry);
 
-    while (!GKI_queue_is_empty(&p_ccb->xmit_hold_q)) {
-        GKI_freebuf (GKI_dequeue (&p_ccb->xmit_hold_q));
-    }
+
+    fixed_queue_free(p_ccb->xmit_hold_q, osi_free_func);
+    p_ccb->xmit_hold_q = NULL;
+
 #if (CLASSIC_BT_INCLUDED == TRUE)
     l2c_fcr_cleanup (p_ccb);
 #endif  ///CLASSIC_BT_INCLUDED == TRUE
@@ -2553,8 +2550,6 @@ BOOLEAN l2cu_initialize_fixed_ccb (tL2C_LCB *p_lcb, UINT16 fixed_cid, tL2CAP_FCR
     p_ccb->local_cid  = fixed_cid;
     p_ccb->remote_cid = fixed_cid;
 
-    GKI_init_q (&p_ccb->xmit_hold_q);
-
     p_ccb->is_flushable = FALSE;
 
     p_ccb->timer_entry.param  = (TIMER_PARAM_TYPE)p_ccb;
@@ -2564,10 +2559,10 @@ BOOLEAN l2cu_initialize_fixed_ccb (tL2C_LCB *p_lcb, UINT16 fixed_cid, tL2CAP_FCR
         /* Set the FCR parameters. For now, we will use default pools */
         p_ccb->our_cfg.fcr = p_ccb->peer_cfg.fcr = *p_fcr;
 
-        p_ccb->ertm_info.fcr_rx_pool_id  = HCI_ACL_POOL_ID;
-        p_ccb->ertm_info.fcr_tx_pool_id  = HCI_ACL_POOL_ID;
-        p_ccb->ertm_info.user_rx_pool_id = HCI_ACL_POOL_ID;
-        p_ccb->ertm_info.user_tx_pool_id = HCI_ACL_POOL_ID;
+        p_ccb->ertm_info.fcr_rx_buf_size  = L2CAP_FCR_RX_BUF_SIZE;
+        p_ccb->ertm_info.fcr_tx_buf_size  = L2CAP_FCR_TX_BUF_SIZE;
+        p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE;
+        p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE;
 
         p_ccb->fcrb.max_held_acks = p_fcr->tx_win_sz / 3;
     }
@@ -2969,7 +2964,8 @@ static tL2C_CCB *l2cu_get_next_channel_in_rr(tL2C_LCB *p_lcb)
             }
 
             L2CAP_TRACE_DEBUG("RR scan pri=%d, lcid=0x%04x, q_cout=%d",
-                              p_ccb->ccb_priority, p_ccb->local_cid, GKI_queue_length(&p_ccb->xmit_hold_q));
+                              p_ccb->ccb_priority, p_ccb->local_cid,
+                              fixed_queue_length(p_ccb->xmit_hold_q));
 
             /* store the next serving channel */
             /* this channel is the last channel of its priority group */
@@ -2992,15 +2988,12 @@ static tL2C_CCB *l2cu_get_next_channel_in_rr(tL2C_LCB *p_lcb)
                     continue;
                 }
 
-                if ( GKI_queue_is_empty(&p_ccb->fcrb.retrans_q)) {
-                    if ( GKI_queue_is_empty(&p_ccb->xmit_hold_q)) {
+                if (fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) {
+                    if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
                         continue;
                     }
 
-                    /* If using the common pool, should be at least 10% free. */
-                    if ( (p_ccb->ertm_info.fcr_tx_pool_id == HCI_ACL_POOL_ID) && (GKI_poolutilization (HCI_ACL_POOL_ID) > 90) ) {
-                        continue;
-                    }
+
 #if (CLASSIC_BT_INCLUDED == TRUE)
                     /* If in eRTM mode, check for window closure */
                     if ( (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && (l2c_fcr_is_flow_controlled (p_ccb)) ) {
@@ -3009,7 +3002,7 @@ static tL2C_CCB *l2cu_get_next_channel_in_rr(tL2C_LCB *p_lcb)
 #endif  ///CLASSIC_BT_INCLUDED == TRUE
                 }
             } else {
-                if (GKI_queue_is_empty(&p_ccb->xmit_hold_q)) {
+                if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
                     continue;
                 }
             }
@@ -3067,16 +3060,11 @@ static tL2C_CCB *l2cu_get_next_channel(tL2C_LCB *p_lcb)
             continue;
         }
 
-        if (p_ccb->fcrb.retrans_q.count != 0) {
+        if (!fixed_queue_is_empty(p_ccb->fcrb.retrans_q))
             return p_ccb;
         }
 
-        if (p_ccb->xmit_hold_q.count == 0) {
-            continue;
-        }
-
-        /* If using the common pool, should be at least 10% free. */
-        if ( (p_ccb->ertm_info.fcr_tx_pool_id == HCI_ACL_POOL_ID) && (GKI_poolutilization (HCI_ACL_POOL_ID) > 90) ) {
+        if (fixed_queue_is_empty(p_ccb->xmit_hold_q))
             continue;
         }
 
@@ -3127,13 +3115,9 @@ BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb)
             }
 
             /* No more checks needed if sending from the reatransmit queue */
-            if (GKI_queue_is_empty(&p_ccb->fcrb.retrans_q)) {
-                if (GKI_queue_is_empty(&p_ccb->xmit_hold_q)) {
-                    continue;
-                }
-
-                /* If using the common pool, should be at least 10% free. */
-                if ( (p_ccb->ertm_info.fcr_tx_pool_id == HCI_ACL_POOL_ID) && (GKI_poolutilization (HCI_ACL_POOL_ID) > 90) ) {
+            if (fixed_queue_is_empty(p_ccb->fcrb.retrans_q))
+            {
+                if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
                     continue;
                 }
                 /* If in eRTM mode, check for window closure */
@@ -3151,8 +3135,8 @@ BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb)
 #endif  ///CLASSIC_BT_INCLUDED == TRUE
 
         } else {
-            if (!GKI_queue_is_empty(&p_ccb->xmit_hold_q)) {
-                p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->xmit_hold_q);
+            if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
+                p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q);
                 if (NULL == p_buf) {
                     L2CAP_TRACE_ERROR("l2cu_get_buffer_to_send: No data to be sent");
                     return (NULL);
@@ -3189,7 +3173,7 @@ BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb)
         }
 
     } else {
-        p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->xmit_hold_q);
+        p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q);
         if (NULL == p_buf) {
             L2CAP_TRACE_ERROR("l2cu_get_buffer_to_send() #2: No data to be sent");
             return (NULL);
@@ -3274,11 +3258,11 @@ void l2cu_set_acl_hci_header (BT_HDR *p_buf, tL2C_CCB *p_ccb)
 *******************************************************************************/
 void l2cu_check_channel_congestion (tL2C_CCB *p_ccb)
 {
-    UINT16 q_count = GKI_queue_length(&p_ccb->xmit_hold_q);
+    size_t q_count = fixed_queue_length(p_ccb->xmit_hold_q);
 
 #if (L2CAP_UCD_INCLUDED == TRUE)
     if ( p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID ) {
-        q_count += p_ccb->p_lcb->ucd_out_sec_pending_q.count;
+        q_count += fixed_queue_length(p_ccb->p_lcb->ucd_out_sec_pending_q);
     }
 #endif
     /* If the CCB queue limit is subject to a quota, check for congestion */
@@ -3302,8 +3286,9 @@ void l2cu_check_channel_congestion (tL2C_CCB *p_ccb)
                 else if ( p_ccb->p_rcb && p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID ) {
                     if ( p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb ) {
                         L2CAP_TRACE_DEBUG ("L2CAP - Calling UCD CongestionStatus_Cb (FALSE), SecPendingQ:%u,XmitQ:%u,Quota:%u",
-                                           p_ccb->p_lcb->ucd_out_sec_pending_q.count,
-                                           p_ccb->xmit_hold_q.count, p_ccb->buff_quota);
+                                           fixed_queue_length(p_ccb->p_lcb->ucd_out_sec_pending_q),
+                                           fixed_queue_length(p_ccb->xmit_hold_q),
+                                           p_ccb->buff_quota);
                         p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb( p_ccb->p_lcb->remote_bd_addr, FALSE );
                     }
                 }
@@ -3336,8 +3321,9 @@ void l2cu_check_channel_congestion (tL2C_CCB *p_ccb)
                 else if ( p_ccb->p_rcb && p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID ) {
                     if ( p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb ) {
                         L2CAP_TRACE_DEBUG ("L2CAP - Calling UCD CongestionStatus_Cb (TRUE), SecPendingQ:%u,XmitQ:%u,Quota:%u",
-                                           p_ccb->p_lcb->ucd_out_sec_pending_q.count,
-                                           p_ccb->xmit_hold_q.count, p_ccb->buff_quota);
+                                          fixed_queue_length(p_ccb->p_lcb->ucd_out_sec_pending_q),
+                                          fixed_queue_length(p_ccb->xmit_hold_q),
+                                          p_ccb->buff_quota);
                         p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb( p_ccb->p_lcb->remote_bd_addr, TRUE );
                     }
                 }
index 64a729d190fe35d51a7d1dd49e982e7bcd673857..d8bf8c39439e3f386a176794df0558a834d8e25f 100644 (file)
@@ -20,7 +20,6 @@
 #include "bt_trace.h"
 #include "bt_defs.h"
 #include "bdaddr.h"
-#include "gki.h"
 #include "allocator.h"
 #include "buffer.h"
 #include "list.h"
@@ -170,7 +169,7 @@ void l2cap_client_disconnect(l2cap_client_t *client)
     client->is_congested = false;
 
     for (const list_node_t *node = list_begin(client->outbound_fragments); node != list_end(client->outbound_fragments); node = list_next(node)) {
-        GKI_freebuf(list_node(node));
+        osi_free(list_node(node));
     }
 
     list_clear(client->outbound_fragments);
@@ -375,7 +374,7 @@ static void read_ready_cb(uint16_t local_channel_id, BT_HDR *packet)
     // TODO(sharvil): eliminate copy from BT_HDR.
     buffer_t *buffer = buffer_new(packet->len);
     memcpy(buffer_ptr(buffer), packet->data + packet->offset, packet->len);
-    GKI_freebuf(packet);
+    osi_free(packet);
 
     client->callbacks.read_ready(client, buffer, client->context);
     buffer_free(buffer);
@@ -394,7 +393,7 @@ static void fragment_packet(l2cap_client_t *client, buffer_t *packet)
     assert(packet != NULL);
 
     // TODO(sharvil): eliminate copy into BT_HDR.
-    BT_HDR *bt_packet = GKI_getbuf(buffer_length(packet) + L2CAP_MIN_OFFSET);
+    BT_HDR *bt_packet = osi_malloc(buffer_length(packet) + L2CAP_MIN_OFFSET);
     bt_packet->offset = L2CAP_MIN_OFFSET;
     bt_packet->len = buffer_length(packet);
     memcpy(bt_packet->data + bt_packet->offset, buffer_ptr(packet), buffer_length(packet));
@@ -404,12 +403,12 @@ static void fragment_packet(l2cap_client_t *client, buffer_t *packet)
             if (bt_packet->len > 0) {
                 list_append(client->outbound_fragments, bt_packet);
             } else {
-                GKI_freebuf(bt_packet);
+                osi_free(bt_packet);
             }
             break;
         }
 
-        BT_HDR *fragment = GKI_getbuf(client->remote_mtu + L2CAP_MIN_OFFSET);
+        BT_HDR *fragment = osi_malloc(client->remote_mtu + L2CAP_MIN_OFFSET);
         fragment->offset = L2CAP_MIN_OFFSET;
         fragment->len = client->remote_mtu;
         memcpy(fragment->data + fragment->offset, bt_packet->data + bt_packet->offset, client->remote_mtu);
index fb72d5038a2802e44896abf0fc644ed799ba68cf..aa6d48e7fcd8ae868684331bcf5c27d541f1c520 100644 (file)
@@ -26,7 +26,6 @@
 #define PORT_INT_H
 
 #include "bt_target.h"
-#include "gki.h"
 #include "rfcdefs.h"
 #include "port_api.h"
 
@@ -52,7 +51,7 @@
 ** Define Port Data Transfere control block
 */
 typedef struct {
-    BUFFER_Q queue;         /* Queue of buffers waiting to be sent */
+    fixed_queue_t *queue;         /* Queue of buffers waiting to be sent */
     BOOLEAN  peer_fc;       /* TRUE if flow control is set based on peer's request */
     BOOLEAN  user_fc;       /* TRUE if flow control is set based on user's request  */
     UINT32   queue_size;    /* Number of data bytes in the queue */
@@ -88,7 +87,7 @@ typedef struct {
 */
 typedef struct {
     TIMER_LIST_ENT tle;       /* Timer list entry */
-    BUFFER_Q  cmd_q;          /* Queue for command messages on this mux */
+    fixed_queue_t  *cmd_q;          /* Queue for command messages on this mux */
     UINT8     port_inx[RFCOMM_MAX_DLCI + 1];  /* Array for quick access to  */
     /* tPORT based on dlci        */
     BD_ADDR   bd_addr;        /* BD ADDR of the peer if initiator */
index 753fc34256ce53af8c682370676d62a6cdaf1c7a..30eeaff4ebf9b0551d4bc7ada6c1e40c8593c691 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "rfcdefs.h"
 #include "port_api.h"
 #include "port_int.h"
@@ -1091,17 +1090,17 @@ int PORT_Purge (UINT16 handle, UINT8 purge_flags)
     }
 
     if (purge_flags & PORT_PURGE_RXCLEAR) {
-        PORT_SCHEDULE_LOCK;  /* to prevent missing credit */
+        osi_mutex_global_lock();  /* to prevent missing credit */
 
-        count = GKI_queue_length(&p_port->rx.queue);
+        count = fixed_queue_length(p_port->rx.queue);
 
-        while ((p_buf = (BT_HDR *)GKI_dequeue (&p_port->rx.queue)) != NULL) {
-            GKI_freebuf (p_buf);
+        while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL) {
+            osi_free (p_buf);
         }
 
         p_port->rx.queue_size = 0;
 
-        PORT_SCHEDULE_UNLOCK;
+        osi_mutex_global_unlock();
 
         /* If we flowed controlled peer based on rx_queue size enable data again */
         if (count) {
@@ -1110,15 +1109,15 @@ int PORT_Purge (UINT16 handle, UINT8 purge_flags)
     }
 
     if (purge_flags & PORT_PURGE_TXCLEAR) {
-        PORT_SCHEDULE_LOCK;  /* to prevent tx.queue_size from being negative */
+        osi_mutex_global_lock();  /* to prevent tx.queue_size from being negative */
 
-        while ((p_buf = (BT_HDR *)GKI_dequeue (&p_port->tx.queue)) != NULL) {
-            GKI_freebuf (p_buf);
+        while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) {
+            osi_free (p_buf);
         }
 
         p_port->tx.queue_size = 0;
 
-        PORT_SCHEDULE_UNLOCK;
+        osi_mutex_global_unlock();
 
         events = PORT_EV_TXEMPTY;
 
@@ -1174,14 +1173,19 @@ int PORT_ReadData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len)
         return (PORT_LINE_ERR);
     }
 
-    p_buf = (BT_HDR *)GKI_getfirst (&p_port->rx.queue);
+    if (fixed_queue_is_empty(p_port->rx.queue))
     if (!p_buf) {
         return (PORT_SUCCESS);
     }
 
     count = 0;
 
-    while (max_len && p_buf) {
+    while (max_len)
+    {
+        p_buf = (BT_HDR *)fixed_queue_try_peek_first(p_port->rx.queue);
+        if (p_buf == NULL)
+            break;
+
         if (p_buf->len > max_len) {
             memcpy (p_data, (UINT8 *)(p_buf + 1) + p_buf->offset, max_len);
             p_buf->offset += max_len;
@@ -1189,11 +1193,11 @@ int PORT_ReadData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len)
 
             *p_len += max_len;
 
-            PORT_SCHEDULE_LOCK;
+            osi_mutex_global_lock();
 
             p_port->rx.queue_size -= max_len;
 
-            PORT_SCHEDULE_UNLOCK;
+            osi_mutex_global_unlock();
 
             break;
         } else {
@@ -1202,18 +1206,17 @@ int PORT_ReadData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len)
             *p_len  += p_buf->len;
             max_len -= p_buf->len;
 
-            PORT_SCHEDULE_LOCK;
+            osi_mutex_global_lock();
 
             p_port->rx.queue_size -= p_buf->len;
 
             if (max_len) {
                 p_data  += p_buf->len;
-                p_buf = (BT_HDR *)GKI_getnext (p_buf);
             }
 
-            GKI_freebuf (GKI_dequeue (&p_port->rx.queue));
+            osi_free(fixed_queue_try_dequeue(p_port->rx.queue));
 
-            PORT_SCHEDULE_UNLOCK;
+            osi_mutex_global_unlock();
 
             count++;
         }
@@ -1265,19 +1268,19 @@ int PORT_Read (UINT16 handle, BT_HDR **pp_buf)
         return (PORT_LINE_ERR);
     }
 
-    PORT_SCHEDULE_LOCK;
+    osi_mutex_global_lock();
 
-    p_buf = (BT_HDR *)GKI_dequeue (&p_port->rx.queue);
+    p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue);
     if (p_buf) {
         p_port->rx.queue_size -= p_buf->len;
 
-        PORT_SCHEDULE_UNLOCK;
+        osi_mutex_global_unlock();
 
         /* If rfcomm suspended traffic from the peer based on the rx_queue_size */
         /* check if it can be resumed now */
         port_flow_control_peer (p_port, TRUE, 1);
     } else {
-        PORT_SCHEDULE_UNLOCK;
+        osi_mutex_global_unlock();
     }
 
     *pp_buf = p_buf;
@@ -1300,7 +1303,7 @@ static int port_write (tPORT *p_port, BT_HDR *p_buf)
 {
     /* We should not allow to write data in to server port when connection is not opened */
     if (p_port->is_server && (p_port->rfc.state != RFC_STATE_OPENED)) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (PORT_CLOSED);
     }
 
@@ -1314,11 +1317,11 @@ static int port_write (tPORT *p_port, BT_HDR *p_buf)
             || ((p_port->port_ctrl & (PORT_CTRL_REQ_SENT | PORT_CTRL_IND_RECEIVED)) !=
                 (PORT_CTRL_REQ_SENT | PORT_CTRL_IND_RECEIVED))) {
         if ((p_port->tx.queue_size  > PORT_TX_CRITICAL_WM)
-                || (GKI_queue_length(&p_port->tx.queue) > PORT_TX_BUF_CRITICAL_WM)) {
+         || (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_CRITICAL_WM))
             RFCOMM_TRACE_WARNING ("PORT_Write: Queue size: %d",
                                   p_port->tx.queue_size);
 
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
 
             if ((p_port->p_callback != NULL) && (p_port->ev_mask & PORT_EV_ERR)) {
                 p_port->p_callback (PORT_EV_ERR, p_port->inx);
@@ -1333,7 +1336,7 @@ static int port_write (tPORT *p_port, BT_HDR *p_buf)
                             p_port->rfc.state,
                             p_port->port_ctrl);
 
-        GKI_enqueue (&p_port->tx.queue, p_buf);
+        fixed_queue_enqueue(p_port->tx.queue, p_buf);
         p_port->tx.queue_size += p_buf->len;
 
         return (PORT_CMD_PENDING);
@@ -1366,21 +1369,21 @@ int PORT_Write (UINT16 handle, BT_HDR *p_buf)
 
     /* Check if handle is valid to avoid crashing */
     if ((handle == 0) || (handle > MAX_RFC_PORTS)) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (PORT_BAD_HANDLE);
     }
 
     p_port = &rfc_cb.port.port[handle - 1];
 
     if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (PORT_NOT_OPENED);
     }
 
     if (p_port->line_status) {
         RFCOMM_TRACE_WARNING ("PORT_Write: Data dropped line_status:0x%x",
                               p_port->line_status);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return (PORT_LINE_ERR);
     }
 
@@ -1456,14 +1459,14 @@ int PORT_WriteDataCO (UINT16 handle, int *p_len)
         return PORT_SUCCESS;
     }
     /* Length for each buffer is the smaller of GKI buffer, peer MTU, or max_len */
-    length = RFCOMM_DATA_POOL_BUF_SIZE -
+    length = RFCOMM_DATA_BUF_SIZE -
              (UINT16)(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + RFCOMM_DATA_OVERHEAD);
 
     /* If there are buffers scheduled for transmission check if requested */
     /* data fits into the end of the queue */
-    PORT_SCHEDULE_LOCK;
+    osi_mutex_global_lock();
 
-    if (((p_buf = (BT_HDR *)GKI_getlast(&p_port->tx.queue)) != NULL)
+    if (((p_buf = (BT_HDR *)fixed_queue_try_peek_last(p_port->tx.queue)) != NULL)
             && (((int)p_buf->len + available) <= (int)p_port->peer_mtu)
             && (((int)p_buf->len + available) <= (int)length)) {
         //if(recv(fd, (UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len, available, 0) != available)
@@ -1472,7 +1475,7 @@ int PORT_WriteDataCO (UINT16 handle, int *p_len)
 
         {
             RFCOMM_TRACE_ERROR("p_data_co_callback DATA_CO_CALLBACK_TYPE_OUTGOING failed, available:%d", available);
-            PORT_SCHEDULE_UNLOCK;
+            osi_mutex_global_unlock();
             return (PORT_UNKNOWN_ERROR);
         }
         //memcpy ((UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, max_len);
@@ -1481,12 +1484,12 @@ int PORT_WriteDataCO (UINT16 handle, int *p_len)
         *p_len = available;
         p_buf->len += (UINT16)available;
 
-        PORT_SCHEDULE_UNLOCK;
+        osi_mutex_global_unlock();
 
         return (PORT_SUCCESS);
     }
 
-    PORT_SCHEDULE_UNLOCK;
+    osi_mutex_global_unlock();
 
     //int max_read = length < p_port->peer_mtu ? length : p_port->peer_mtu;
 
@@ -1495,16 +1498,16 @@ int PORT_WriteDataCO (UINT16 handle, int *p_len)
     while (available) {
         /* if we're over buffer high water mark, we're done */
         if ((p_port->tx.queue_size  > PORT_TX_HIGH_WM)
-                || (GKI_queue_length(&p_port->tx.queue) > PORT_TX_BUF_HIGH_WM)) {
+         || (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM)) {
             port_flow_control_user(p_port);
             event |= PORT_EV_FC;
             RFCOMM_TRACE_EVENT ("tx queue is full,tx.queue_size:%d,tx.queue.count:%d,available:%d",
-                                p_port->tx.queue_size, GKI_queue_length(&p_port->tx.queue), available);
+                    p_port->tx.queue_size, fixed_queue_length(p_port->tx.queue), available);
             break;
         }
 
         /* continue with rfcomm data write */
-        p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_DATA_POOL_ID);
+        p_buf = (BT_HDR *)osi_malloc(RFCOMM_DATA_BUF_SIZE);
         if (!p_buf) {
             break;
         }
@@ -1612,9 +1615,9 @@ int PORT_WriteData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len)
 
     /* If there are buffers scheduled for transmission check if requested */
     /* data fits into the end of the queue */
-    PORT_SCHEDULE_LOCK;
+    osi_mutex_global_lock();
 
-    if (((p_buf = (BT_HDR *)GKI_getlast(&p_port->tx.queue)) != NULL)
+    if (((p_buf = (BT_HDR *)fixed_queue_try_peek_last(p_port->tx.queue)) != NULL) {
             && ((p_buf->len + max_len) <= p_port->peer_mtu)
             && ((p_buf->len + max_len) <= length)) {
         memcpy ((UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, max_len);
@@ -1623,22 +1626,22 @@ int PORT_WriteData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len)
         *p_len = max_len;
         p_buf->len += max_len;
 
-        PORT_SCHEDULE_UNLOCK;
+        osi_mutex_global_unlock();
 
         return (PORT_SUCCESS);
     }
 
-    PORT_SCHEDULE_UNLOCK;
+    osi_mutex_global_unlock();
 
     while (max_len) {
         /* if we're over buffer high water mark, we're done */
         if ((p_port->tx.queue_size  > PORT_TX_HIGH_WM)
-                || (GKI_queue_length(&p_port->tx.queue) > PORT_TX_BUF_HIGH_WM)) {
+         || (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM)) {
             break;
         }
 
         /* continue with rfcomm data write */
-        p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_DATA_POOL_ID);
+        p_buf = (BT_HDR *)osi_malloc(RFCOMM_DATA_BUF_SIZE);
         if (!p_buf) {
             break;
         }
@@ -1724,7 +1727,7 @@ int PORT_Test (UINT16 handle, UINT8 *p_data, UINT16 len)
         return (PORT_UNKNOWN_ERROR);
     }
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) != NULL) {
 
         p_buf->offset  = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2;
         p_buf->len = len;
index 009cc6363de7815197c4b612438648bb1304f780..e3076f7121c3cf735bf310e1c3ff3fdbbb7c7df5 100644 (file)
@@ -25,7 +25,6 @@
 #include <string.h>
 
 #include "bt_target.h"
-#include "gki.h"
 #include "rfcdefs.h"
 #include "port_api.h"
 #include "btm_int.h"
@@ -817,7 +816,7 @@ void PORT_DataInd (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf)
     RFCOMM_TRACE_EVENT("PORT_DataInd with data length %d, p_mcb:%p,p_port:%p,dlci:%d",
                        p_buf->len, p_mcb, p_port, dlci);
     if (!p_port) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
     /* If client registered callout callback with flow control we can just deliver receive data */
@@ -829,7 +828,7 @@ void PORT_DataInd (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf)
         } else {
             port_flow_control_peer(p_port, FALSE, 0);
         }
-        //GKI_freebuf (p_buf);
+        //osi_free (p_buf);
         return;
     } else {
         RFCOMM_TRACE_ERROR("PORT_DataInd, p_port:%p, p_data_co_callback is null", p_port);
@@ -840,15 +839,15 @@ void PORT_DataInd (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf)
         port_flow_control_peer(p_port, TRUE, 1);
 
         p_port->p_data_callback (p_port->inx, (UINT8 *)(p_buf + 1) + p_buf->offset, p_buf->len);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
     /* Check if rx queue exceeds the limit */
     if ((p_port->rx.queue_size + p_buf->len > PORT_RX_CRITICAL_WM)
-            || (GKI_queue_length(&p_port->rx.queue) + 1 > p_port->rx_buf_critical)) {
+     || (fixed_queue_length(p_port->rx.queue) + 1 > p_port->rx_buf_critical)) {
         RFCOMM_TRACE_EVENT ("PORT_DataInd. Buffer over run. Dropping the buffer");
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
 
         RFCOMM_LineStatusReq (p_mcb, dlci, LINE_STATUS_OVERRUN);
         return;
@@ -866,12 +865,12 @@ void PORT_DataInd (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf)
         }
     }
 
-    PORT_SCHEDULE_LOCK;
+    osi_mutex_global_lock();
 
-    GKI_enqueue (&p_port->rx.queue, p_buf);
+    fixed_queue_enqueue(p_port->rx.queue, p_buf);
     p_port->rx.queue_size += p_buf->len;
 
-    PORT_SCHEDULE_UNLOCK;
+    osi_mutex_global_unlock();
 
     /* perform flow control procedures if necessary */
     port_flow_control_peer(p_port, FALSE, 0);
@@ -973,12 +972,12 @@ UINT32 port_rfc_send_tx_data (tPORT *p_port)
         /* while the rfcomm peer is not flow controlling us, and peer is ready */
         while (!p_port->tx.peer_fc && p_port->rfc.p_mcb && p_port->rfc.p_mcb->peer_ready) {
             /* get data from tx queue and send it */
-            PORT_SCHEDULE_LOCK;
+            osi_mutex_global_lock();
 
-            if ((p_buf = (BT_HDR *)GKI_dequeue (&p_port->tx.queue)) != NULL) {
+            if ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) {
                 p_port->tx.queue_size -= p_buf->len;
 
-                PORT_SCHEDULE_UNLOCK;
+                osi_mutex_global_unlock();
 
                 RFCOMM_TRACE_DEBUG ("Sending RFCOMM_DataReq tx.queue_size=%d", p_port->tx.queue_size);
 
@@ -993,7 +992,7 @@ UINT32 port_rfc_send_tx_data (tPORT *p_port)
             }
             /* queue is empty-- all data sent */
             else {
-                PORT_SCHEDULE_UNLOCK;
+                osi_mutex_global_unlock();
 
                 events |= PORT_EV_TXEMPTY;
                 break;
index 5b2e79178f166062a4955390340df9d61220fc74..92485075be79759c25d90c3456257d2f05c00b0e 100644 (file)
@@ -24,7 +24,6 @@
 #include <string.h>
 
 #include "bt_target.h"
-#include "gki.h"
 #include "rfcdefs.h"
 #include "port_api.h"
 #include "port_int.h"
@@ -125,6 +124,9 @@ void port_set_defaults (tPORT *p_port)
     memset (&p_port->peer_ctrl, 0, sizeof (p_port->peer_ctrl));
     memset (&p_port->rx, 0, sizeof (p_port->rx));
     memset (&p_port->tx, 0, sizeof (p_port->tx));
+
+    p_port->tx.queue = fixed_queue_new(SIZE_MAX);
+    p_port->rx.queue = fixed_queue_new(SIZE_MAX);
 }
 
 /*******************************************************************************
@@ -203,21 +205,21 @@ void port_release_port (tPORT *p_port)
     tPORT_CALLBACK *p_port_cb;
     tPORT_STATE user_port_pars;
 
-    PORT_SCHEDULE_LOCK;
+    osi_mutex_global_lock();
     RFCOMM_TRACE_DEBUG("port_release_port, p_port:%p", p_port);
-    while ((p_buf = (BT_HDR *)GKI_dequeue (&p_port->rx.queue)) != NULL) {
-        GKI_freebuf (p_buf);
+    while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL) {
+        osi_free (p_buf);
     }
 
     p_port->rx.queue_size = 0;
 
-    while ((p_buf = (BT_HDR *)GKI_dequeue (&p_port->tx.queue)) != NULL) {
-        GKI_freebuf (p_buf);
+    while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) {
+        osi_free (p_buf);
     }
 
     p_port->tx.queue_size = 0;
 
-    PORT_SCHEDULE_UNLOCK;
+    osi_mutex_global_unlock();
 
     p_port->state = PORT_STATE_CLOSED;
 
@@ -230,6 +232,11 @@ void port_release_port (tPORT *p_port)
             rfc_check_mcb_active (p_port->rfc.p_mcb);
         }
         rfc_port_timer_stop (p_port);
+        fixed_queue_free(p_port->tx.queue, NULL);
+        p_port->tx.queue = NULL;
+        fixed_queue_free(p_port->rx.queue, NULL);
+        p_port->rx.queue = NULL;
+               
         RFCOMM_TRACE_DEBUG ("port_release_port:p_port->keep_port_handle:%d", p_port->keep_port_handle);
         if ( p_port->keep_port_handle ) {
             RFCOMM_TRACE_DEBUG ("port_release_port:Initialize handle:%d", p_port->inx);
@@ -402,7 +409,7 @@ UINT32 port_flow_control_user (tPORT *p_port)
                  || !p_port->rfc.p_mcb
                  || !p_port->rfc.p_mcb->peer_ready
                  || (p_port->tx.queue_size > PORT_TX_HIGH_WM)
-                 || (GKI_queue_length(&p_port->tx.queue) > PORT_TX_BUF_HIGH_WM);
+                 || (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM);
 
     if (p_port->tx.user_fc == fc) {
         return (0);
@@ -514,7 +521,7 @@ void port_flow_control_peer(tPORT *p_port, BOOLEAN enable, UINT16 count)
                 p_port->rx.peer_fc = TRUE;
             }
             /* if queue count reached credit rx max, set peer fc */
-            else if (GKI_queue_length(&p_port->rx.queue) >= p_port->credit_rx_max) {
+            else if (fixed_queue_length(p_port->rx.queue) >= p_port->credit_rx_max) {
                 p_port->rx.peer_fc = TRUE;
             }
         }
@@ -527,7 +534,7 @@ void port_flow_control_peer(tPORT *p_port, BOOLEAN enable, UINT16 count)
             /* check if it can be resumed now */
             if (p_port->rx.peer_fc
                     && (p_port->rx.queue_size < PORT_RX_LOW_WM)
-                    && (GKI_queue_length(&p_port->rx.queue) < PORT_RX_BUF_LOW_WM)) {
+                    && (fixed_queue_length(p_port->rx.queue) < PORT_RX_BUF_LOW_WM)) {
                 p_port->rx.peer_fc = FALSE;
 
                 /* If user did not force flow control allow traffic now */
@@ -546,7 +553,7 @@ void port_flow_control_peer(tPORT *p_port, BOOLEAN enable, UINT16 count)
             /* Check the size of the rx queue.  If it exceeds certain */
             /* level and flow control has not been sent to the peer do it now */
             else if ( ((p_port->rx.queue_size > PORT_RX_HIGH_WM)
-                       || (GKI_queue_length(&p_port->rx.queue) > PORT_RX_BUF_HIGH_WM))
+                      || (fixed_queue_length(p_port->rx.queue) > PORT_RX_BUF_HIGH_WM))
                       && !p_port->rx.peer_fc) {
                 RFCOMM_TRACE_EVENT ("PORT_DataInd Data reached HW. Sending FC set.");
 
index b050532d014fb1593da696c6082eb399eac866e8..1458166ed351fe844d50da6b5ab93a039024b8f6 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <stddef.h>
 #include "bt_target.h"
-#include "gki.h"
 
 #include "rfcdefs.h"
 #include "port_api.h"
@@ -103,7 +102,7 @@ void RFCOMM_ConnectInd (BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id)
             RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectInd start timer for collision, initiator's LCID(0x%x), acceptor's LCID(0x%x)",
                                 p_mcb->lcid, p_mcb->pending_lcid);
 
-            rfc_timer_start(p_mcb, (UINT16)(GKI_get_os_tick_count() % 10 + 2));
+            rfc_timer_start(p_mcb, (UINT16)(osi_time_get_os_boottime_ms() % 10 + 2));
             return;
         } else {
             /* we cannot accept connection request from peer at this state */
@@ -292,7 +291,7 @@ void RFCOMM_BufDataInd (UINT16 lcid, BT_HDR *p_buf)
 
     if (!p_mcb) {
         RFCOMM_TRACE_WARNING ("RFCOMM_BufDataInd LCID:0x%x", lcid);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -300,7 +299,7 @@ void RFCOMM_BufDataInd (UINT16 lcid, BT_HDR *p_buf)
 
     /* If the frame did not pass validation just ignore it */
     if (event == RFC_EVENT_BAD_FRAME) {
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -313,7 +312,7 @@ void RFCOMM_BufDataInd (UINT16 lcid, BT_HDR *p_buf)
 
         /* Other multiplexer events go to state machine */
         rfc_mx_sm_execute (p_mcb, event, NULL);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -326,13 +325,13 @@ void RFCOMM_BufDataInd (UINT16 lcid, BT_HDR *p_buf)
                     || (!p_mcb->is_initiator &&  rfc_cb.rfc.rx_frame.cr)) {
                 rfc_send_dm (p_mcb, rfc_cb.rfc.rx_frame.dlci, rfc_cb.rfc.rx_frame.pf);
             }
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
             return;
         }
 
         if ((p_port = port_find_dlci_port (rfc_cb.rfc.rx_frame.dlci)) == NULL) {
             rfc_send_dm (p_mcb, rfc_cb.rfc.rx_frame.dlci, TRUE);
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
             return;
         }
         p_mcb->port_inx[rfc_cb.rfc.rx_frame.dlci] = p_port->inx;
@@ -343,7 +342,7 @@ void RFCOMM_BufDataInd (UINT16 lcid, BT_HDR *p_buf)
         if (p_buf->len > 0) {
             rfc_port_sm_execute (p_port, event, p_buf);
         } else {
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
         }
 
         if (rfc_cb.rfc.rx_frame.credit != 0) {
@@ -353,7 +352,7 @@ void RFCOMM_BufDataInd (UINT16 lcid, BT_HDR *p_buf)
         return;
     }
     rfc_port_sm_execute (p_port, event,  NULL);
-    GKI_freebuf (p_buf);
+    osi_free (p_buf);
 }
 
 /*******************************************************************************
index 70411e9846cb600dff1dadfce238722f9f862035..f7a063d8008113ec8812cde0440d414a0689a51c 100644 (file)
@@ -23,7 +23,6 @@
  *
  ******************************************************************************/
 #include <string.h>
-#include "gki.h"
 #include "bt_types.h"
 #include "rfcdefs.h"
 #include "l2cdefs.h"
@@ -485,8 +484,8 @@ void rfc_mx_sm_state_disc_wait_ua (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
             rfc_save_lcid_mcb (p_mcb, p_mcb->lcid);
 
             /* clean up before reuse it */
-            while ((p_buf = (BT_HDR *)GKI_dequeue(&p_mcb->cmd_q)) != NULL) {
-                GKI_freebuf(p_buf);
+            while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_mcb->cmd_q)) != NULL) {
+                osi_free(p_buf);
             }
 
             rfc_timer_start (p_mcb, RFC_MCB_INIT_INACT_TIMER);
@@ -507,7 +506,7 @@ void rfc_mx_sm_state_disc_wait_ua (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
         return;
 
     case RFC_EVENT_UIH:
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         rfc_send_dm (p_mcb, RFCOMM_MX_DLCI, FALSE);
         return;
 
index da1e81e806110c1845660c62ec6b81ce1bbf08fc..710c893a15b99401adf788edcba79906493b030f 100644 (file)
@@ -24,7 +24,6 @@
  ******************************************************************************/
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "rfcdefs.h"
 #include "btm_api.h"
 #include "btm_int.h"
@@ -121,7 +120,7 @@ void rfc_port_sm_state_closed (tPORT *p_port, UINT16 event, void *p_data)
         return;
 
     case RFC_EVENT_DATA:
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         break;
 
     case RFC_EVENT_SABME:
@@ -143,7 +142,7 @@ void rfc_port_sm_state_closed (tPORT *p_port, UINT16 event, void *p_data)
         return;
 
     case RFC_EVENT_UIH:
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, FALSE);
         return;
 
@@ -191,7 +190,7 @@ void rfc_port_sm_sabme_wait_ua (tPORT *p_port, UINT16 event, void *p_data)
         return;
 
     case RFC_EVENT_DATA:
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         break;
 
     case RFC_EVENT_UA:
@@ -218,7 +217,7 @@ void rfc_port_sm_sabme_wait_ua (tPORT *p_port, UINT16 event, void *p_data)
         return;
 
     case RFC_EVENT_UIH:
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         return;
 
     case RFC_EVENT_TIMEOUT:
@@ -271,7 +270,7 @@ void rfc_port_sm_term_wait_sec_check (tPORT *p_port, UINT16 event, void *p_data)
 
     case RFC_EVENT_DATA:
         RFCOMM_TRACE_ERROR ("Port error state Term Wait Sec event Data");
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         return;
 
     case RFC_EVENT_SABME:
@@ -287,7 +286,7 @@ void rfc_port_sm_term_wait_sec_check (tPORT *p_port, UINT16 event, void *p_data)
         return;
 
     case RFC_EVENT_UIH:
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         return;
 
     case RFC_EVENT_ESTABLISH_RSP:
@@ -343,11 +342,11 @@ void rfc_port_sm_orig_wait_sec_check (tPORT *p_port, UINT16 event, void *p_data)
 
     case RFC_EVENT_DATA:
         RFCOMM_TRACE_ERROR ("Port error state Orig Wait Sec event Data");
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         return;
 
     case RFC_EVENT_UIH:
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         return;
     }
     RFCOMM_TRACE_WARNING ("Port state orig_wait_sec_check Event ignored %d", event);
@@ -414,7 +413,7 @@ void rfc_port_sm_opened (tPORT *p_port, UINT16 event, void *p_data)
     case RFC_EVENT_DISC:
         p_port->rfc.state = RFC_STATE_CLOSED;
         rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci);
-        if (!GKI_queue_is_empty(&p_port->rx.queue)) {
+        if (! fixed_queue_is_empty(p_port->rx.queue)) {
             /* give a chance to upper stack to close port properly */
             RFCOMM_TRACE_DEBUG("port queue is not empty");
             rfc_port_timer_start (p_port, RFC_DISC_TIMEOUT);
@@ -459,7 +458,7 @@ void rfc_port_sm_disc_wait_ua (tPORT *p_port, UINT16 event, void *p_data)
         return;
 
     case RFC_EVENT_DATA:
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         return;
 
     case RFC_EVENT_UA:
@@ -479,7 +478,7 @@ void rfc_port_sm_disc_wait_ua (tPORT *p_port, UINT16 event, void *p_data)
         return;
 
     case RFC_EVENT_UIH:
-        GKI_freebuf (p_data);
+        osi_free (p_data);
         rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, FALSE);
         return;
 
@@ -784,7 +783,7 @@ void rfc_process_test_rsp (tRFC_MCB *p_mcb, BT_HDR *p_buf)
 {
     UNUSED(p_mcb);
 
-    GKI_freebuf (p_buf);
+    osi_free (p_buf);
 }
 
 
index 845b77940c4809131f6ff84229ec6a0be827696e..c09d263402724086176753a58cfcf6840050a925 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <string.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "rfcdefs.h"
 #include "port_api.h"
 #include "l2c_api.h"
index 617e2f4bf0c7e39bbcd97c0b4808d926efab61fb..ac29ccec63ad6f762a74f3181645e05877c3a303 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <stddef.h>
 #include "bt_target.h"
-#include "gki.h"
 #include "rfcdefs.h"
 #include "port_api.h"
 #include "l2c_api.h"
@@ -44,7 +43,7 @@ void rfc_send_sabme (tRFC_MCB *p_mcb, UINT8 dlci)
     UINT8   *p_data;
     UINT8   cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -77,7 +76,7 @@ void rfc_send_ua (tRFC_MCB *p_mcb, UINT8 dlci)
     UINT8   *p_data;
     UINT8   cr = RFCOMM_CR(p_mcb->is_initiator, FALSE);
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -110,7 +109,7 @@ void rfc_send_dm (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN pf)
     UINT8   *p_data;
     UINT8   cr = RFCOMM_CR(p_mcb->is_initiator, FALSE);
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -143,7 +142,7 @@ void rfc_send_disc (tRFC_MCB *p_mcb, UINT8 dlci)
     UINT8   *p_data;
     UINT8   cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -234,7 +233,7 @@ void rfc_send_pn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT16 mtu, U
     BT_HDR   *p_buf;
     UINT8    *p_data;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -281,7 +280,7 @@ void rfc_send_fcon (tRFC_MCB *p_mcb, BOOLEAN is_command)
     BT_HDR  *p_buf;
     UINT8   *p_data;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -310,7 +309,7 @@ void rfc_send_fcoff (tRFC_MCB *p_mcb, BOOLEAN is_command)
     BT_HDR  *p_buf;
     UINT8   *p_data;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -346,7 +345,7 @@ void rfc_send_msc (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command,
     signals        = p_pars->modem_signal;
     break_duration = p_pars->break_signal;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -394,7 +393,7 @@ void rfc_send_rls (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT8 status
     BT_HDR  *p_buf;
     UINT8   *p_data;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -426,7 +425,7 @@ void rfc_send_nsc (tRFC_MCB *p_mcb)
     BT_HDR  *p_buf;
     UINT8   *p_data;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -460,7 +459,7 @@ void rfc_send_rpn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command,
     BT_HDR   *p_buf;
     UINT8    *p_data;
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -548,7 +547,7 @@ void rfc_send_credit(tRFC_MCB *p_mcb, UINT8 dlci, UINT8 credit)
     UINT8    *p_data;
     UINT8    cr = RFCOMM_CR(p_mcb->is_initiator, TRUE);
 
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE)) == NULL) {
         return;
     }
 
@@ -701,7 +700,7 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
 
     if (!p_rx_frame->ea || !length) {
         RFCOMM_TRACE_ERROR ("Illegal MX Frame ea:%d len:%d", p_rx_frame->ea, length);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -721,7 +720,7 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
 
     if (mx_len != length) {
         RFCOMM_TRACE_ERROR ("Bad MX frame");
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -749,7 +748,7 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
             break;
         }
 
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
 
         rfc_process_pn (p_mcb, is_command, p_rx_frame);
         return;
@@ -777,7 +776,7 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
             break;
         }
 
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
 
         rfc_process_fcon (p_mcb, is_command);
         return;
@@ -787,7 +786,7 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
             break;
         }
 
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
 
         rfc_process_fcoff (p_mcb, is_command);
         return;
@@ -813,7 +812,7 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
             p_rx_frame->u.msc.break_present  = FALSE;
             p_rx_frame->u.msc.break_duration = 0;
         }
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
 
         rfc_process_msc (p_mcb, is_command, p_rx_frame);
         return;
@@ -827,7 +826,7 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
         p_rx_frame->u.nsc.cr   = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR;
         p_rx_frame->u.nsc.type = *p_data++ >> RFCOMM_SHIFT_DLCI;
 
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
 
         rfc_process_nsc (p_mcb, p_rx_frame);
         return;
@@ -861,7 +860,7 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
             p_rx_frame->u.rpn.xoff_char   = *p_data++;
             p_rx_frame->u.rpn.param_mask  = (*p_data + (*(p_data + 1) << 8)) & RFCOMM_RPN_PM_MASK;
         }
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
 
         rfc_process_rpn (p_mcb, is_command, p_rx_frame->u.rpn.is_request, p_rx_frame);
         return;
@@ -883,13 +882,13 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
             break;
         }
 
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
 
         rfc_process_rls (p_mcb, is_command, p_rx_frame);
         return;
     }
 
-    GKI_freebuf (p_buf);
+    osi_free (p_buf);
 
     if (is_command) {
         rfc_send_nsc (p_mcb);
index 42183021fd327d664d32dfd2612d6b21520f7fe3..dc55f8028fe6ee12785112482a59857b3a5bdc2a 100644 (file)
@@ -23,7 +23,6 @@
  *****************************************************************************/
 
 #include "bt_target.h"
-#include "gki.h"
 
 #include "btm_api.h"
 #include "btm_int.h"
@@ -165,12 +164,13 @@ tRFC_MCB *rfc_alloc_multiplexer_channel (BD_ADDR bd_addr, BOOLEAN is_initiator)
         p_mcb = &rfc_cb.port.rfc_mcb[j];
         if (rfc_cb.port.rfc_mcb[j].state == RFC_MX_STATE_IDLE) {
             /* New multiplexer control block */
+            fixed_queue_free(p_mcb->cmd_q, NULL);
             memset (p_mcb, 0, sizeof (tRFC_MCB));
             memcpy (p_mcb->bd_addr, bd_addr, BD_ADDR_LEN);
             RFCOMM_TRACE_DEBUG("rfc_alloc_multiplexer_channel:is_initiator:%d, create new p_mcb:%p, index:%d",
                                is_initiator, &rfc_cb.port.rfc_mcb[j], j);
 
-            GKI_init_q(&p_mcb->cmd_q);
+            p_mcb->cmd_q = fixed_queue_new(SIZE_MAX);
 
             p_mcb->is_initiator = is_initiator;
 
@@ -194,13 +194,11 @@ tRFC_MCB *rfc_alloc_multiplexer_channel (BD_ADDR bd_addr, BOOLEAN is_initiator)
 *******************************************************************************/
 void rfc_release_multiplexer_channel (tRFC_MCB *p_mcb)
 {
-    void    *p_buf;
 
     rfc_timer_stop (p_mcb);
 
-    while ((p_buf = GKI_dequeue(&p_mcb->cmd_q)) != NULL) {
-        GKI_freebuf(p_buf);
-    }
+
+    fixed_queue_free(p_mcb->cmd_q, osi_free);
 
     memset (p_mcb, 0, sizeof (tRFC_MCB));
     p_mcb->state = RFC_MX_STATE_IDLE;
@@ -457,12 +455,17 @@ void rfc_check_send_cmd(tRFC_MCB *p_mcb, BT_HDR *p_buf)
 
     /* if passed a buffer queue it */
     if (p_buf != NULL) {
-        GKI_enqueue(&p_mcb->cmd_q, p_buf);
+        if (p_mcb->cmd_q == NULL) {
+            RFCOMM_TRACE_ERROR("%s: empty queue: p_mcb = %p p_mcb->lcid = %u cached p_mcb = %p",
+                               __func__, p_mcb, p_mcb->lcid,
+                               rfc_find_lcid_mcb(p_mcb->lcid));
+        }
+        fixed_queue_enqueue(p_mcb->cmd_q, p_buf);
     }
 
     /* handle queue if L2CAP not congested */
     while (p_mcb->l2cap_congested == FALSE) {
-        if ((p = (BT_HDR *) GKI_dequeue(&p_mcb->cmd_q)) == NULL) {
+        if ((p = (BT_HDR *)fixed_queue_try_dequeue(p_mcb->cmd_q)) == NULL) {
             break;
         }
 
index 3e89606f0e0407828d6659961b4b14c5fcb56ee3..9e721d9f9d82af08b6d15ed055078d11145622da 100644 (file)
@@ -26,6 +26,7 @@
 #define  SDP_INT_H
 
 #include "bt_target.h"
+#include "bt_defs.h"
 #include "sdp_api.h"
 #include "l2c_api.h"
 
index bc793c22be824e36d922dc2d77fe0d93e94c2888..91b989eebd68aa8d8fc143d0c2e2176018106f45 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "bt_target.h"
 //#include "bt_utils.h"
-#include "gki.h"
 #include "l2cdefs.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
index 978c859739a1afa33fab83f8b73ef6a1fea9ff24..4ecfab1481eb75b1e68fe76acc04daea2edb9809 100644 (file)
@@ -27,8 +27,8 @@
 #include <stdio.h>
 
 #include "bt_target.h"
+#include "allocator.h"
 
-#include "gki.h"
 
 #include "l2cdefs.h"
 #include "hcidefs.h"
@@ -511,7 +511,7 @@ BOOLEAN SDP_AddSequence (UINT32 handle,  UINT16 attr_id, UINT16 num_elem,
     UINT8           *p_head;
     BOOLEAN         result;
 
-    if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
+    if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
         SDP_TRACE_ERROR("SDP_AddSequence cannot get a buffer!\n");
         return (FALSE);
     }
@@ -550,7 +550,7 @@ BOOLEAN SDP_AddSequence (UINT32 handle,  UINT16 attr_id, UINT16 num_elem,
             if (p_head == p_buff) {
                 /* the first element exceed the max length */
                 SDP_TRACE_ERROR ("SDP_AddSequence - too long(attribute is not added)!!\n");
-                GKI_freebuf(p_buff);
+                osi_free(p_buff);
                 return FALSE;
             } else {
                 SDP_TRACE_ERROR ("SDP_AddSequence - too long, add %d elements of %d\n", xx, num_elem);
@@ -559,7 +559,7 @@ BOOLEAN SDP_AddSequence (UINT32 handle,  UINT16 attr_id, UINT16 num_elem,
         }
     }
     result = SDP_AddAttribute (handle, attr_id, DATA_ELE_SEQ_DESC_TYPE, (UINT32) (p - p_buff), p_buff);
-    GKI_freebuf(p_buff);
+    osi_free(p_buff);
     return result;
 #else   /* SDP_SERVER_ENABLED == FALSE */
     return (FALSE);
@@ -589,7 +589,7 @@ BOOLEAN SDP_AddUuidSequence (UINT32 handle,  UINT16 attr_id, UINT16 num_uuids,
     INT32           max_len = SDP_MAX_ATTR_LEN - 3;
     BOOLEAN         result;
 
-    if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
+    if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
         SDP_TRACE_ERROR("SDP_AddUuidSequence cannot get a buffer!\n");
         return (FALSE);
     }
@@ -607,7 +607,7 @@ BOOLEAN SDP_AddUuidSequence (UINT32 handle,  UINT16 attr_id, UINT16 num_uuids,
     }
 
     result = SDP_AddAttribute (handle, attr_id, DATA_ELE_SEQ_DESC_TYPE, (UINT32) (p - p_buff), p_buff);
-    GKI_freebuf(p_buff);
+    osi_free(p_buff);
     return result;
 #else   /* SDP_SERVER_ENABLED == FALSE */
     return (FALSE);
@@ -634,14 +634,14 @@ BOOLEAN SDP_AddProtocolList (UINT32 handle, UINT16 num_elem,
     int             offset;
     BOOLEAN         result;
 
-    if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
+    if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
         SDP_TRACE_ERROR("SDP_AddProtocolList cannot get a buffer!\n");
         return (FALSE);
     }
 
     offset = sdp_compose_proto_list(p_buff, num_elem, p_elem_list);
     result = SDP_AddAttribute (handle, ATTR_ID_PROTOCOL_DESC_LIST, DATA_ELE_SEQ_DESC_TYPE, (UINT32) offset, p_buff);
-    GKI_freebuf(p_buff);
+    osi_free(p_buff);
     return result;
 #else   /* SDP_SERVER_ENABLED == FALSE */
     return (FALSE);
@@ -672,7 +672,7 @@ BOOLEAN SDP_AddAdditionProtoLists (UINT32 handle, UINT16 num_elem,
     int             offset;
     BOOLEAN         result;
 
-    if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
+    if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
         SDP_TRACE_ERROR("SDP_AddAdditionProtoLists cannot get a buffer!\n");
         return (FALSE);
     }
@@ -691,7 +691,7 @@ BOOLEAN SDP_AddAdditionProtoLists (UINT32 handle, UINT16 num_elem,
     }
     result = SDP_AddAttribute (handle, ATTR_ID_ADDITION_PROTO_DESC_LISTS, DATA_ELE_SEQ_DESC_TYPE,
                                (UINT32) (p - p_buff), p_buff);
-    GKI_freebuf(p_buff);
+    osi_free(p_buff);
     return result;
 
 #else   /* SDP_SERVER_ENABLED == FALSE */
@@ -719,7 +719,7 @@ BOOLEAN SDP_AddProfileDescriptorList (UINT32 handle, UINT16 profile_uuid,
     UINT8           *p;
     BOOLEAN        result;
 
-    if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL) {
+    if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL) {
         SDP_TRACE_ERROR("SDP_AddProfileDescriptorList cannot get a buffer!\n");
         return (FALSE);
     }
@@ -738,7 +738,7 @@ BOOLEAN SDP_AddProfileDescriptorList (UINT32 handle, UINT16 profile_uuid,
     *(p_buff + 1) = (UINT8) (p - (p_buff + 2));
 
     result = SDP_AddAttribute (handle, ATTR_ID_BT_PROFILE_DESC_LIST, DATA_ELE_SEQ_DESC_TYPE, (UINT32) (p - p_buff), p_buff);
-    GKI_freebuf(p_buff);
+    osi_free(p_buff);
     return result;
 
 #else   /* SDP_SERVER_ENABLED == FALSE */
@@ -767,7 +767,7 @@ BOOLEAN SDP_AddLanguageBaseAttrIDList (UINT32 handle, UINT16 lang,
     UINT8           *p;
     BOOLEAN         result;
 
-    if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL) {
+    if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL) {
         SDP_TRACE_ERROR("SDP_AddLanguageBaseAttrIDList cannot get a buffer!\n");
         return (FALSE);
     }
@@ -786,7 +786,7 @@ BOOLEAN SDP_AddLanguageBaseAttrIDList (UINT32 handle, UINT16 lang,
 
     result = SDP_AddAttribute (handle, ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST, DATA_ELE_SEQ_DESC_TYPE,
                                (UINT32) (p - p_buff), p_buff);
-    GKI_freebuf(p_buff);
+    osi_free(p_buff);
     return result;
 #else   /* SDP_SERVER_ENABLED == FALSE */
     return (FALSE);
@@ -815,7 +815,7 @@ BOOLEAN SDP_AddServiceClassIdList (UINT32 handle, UINT16 num_services,
     UINT8           *p;
     BOOLEAN         result;
 
-    if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
+    if ((p_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL) {
         SDP_TRACE_ERROR("SDP_AddServiceClassIdList cannot get a buffer!\n");
         return (FALSE);
     }
@@ -828,7 +828,7 @@ BOOLEAN SDP_AddServiceClassIdList (UINT32 handle, UINT16 num_services,
 
     result = SDP_AddAttribute (handle, ATTR_ID_SERVICE_CLASS_ID_LIST, DATA_ELE_SEQ_DESC_TYPE,
                                (UINT32) (p - p_buff), p_buff);
-    GKI_freebuf(p_buff);
+    osi_free(p_buff);
     return result;
 #else   /* SDP_SERVER_ENABLED == FALSE */
     return (FALSE);
@@ -967,4 +967,4 @@ INT32 SDP_ReadRecord(UINT32 handle, UINT8 *p_data, INT32 *p_data_len)
 }
 #endif
 
-#endif  ///SDP_INCLUDED == TRUE
\ No newline at end of file
+#endif  ///SDP_INCLUDED == TRUE
index dcbd357e419b218ff727d92a60ca9aa0159a5eb6..059ad6364a5cd10360286f7e3982936c90cfce1a 100644 (file)
@@ -27,7 +27,7 @@
 #include <stdio.h>
 
 #include "bt_target.h"
-#include "gki.h"
+#include "allocator.h"
 #include "l2cdefs.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
@@ -117,7 +117,7 @@ static void sdp_snd_service_search_req(tCONN_CB *p_ccb, UINT8 cont_len, UINT8 *p
     UINT16          param_len;
 
     /* Get a buffer to send the packet to L2CAP */
-    if ((p_cmd = (BT_HDR *) GKI_getpoolbuf (SDP_POOL_ID)) == NULL) {
+    if ((p_cmd = (BT_HDR *) osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
         sdp_disconnect (p_ccb, SDP_NO_RESOURCES);
         return;
     }
@@ -412,7 +412,7 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
                           p_ccb->list_len, list_byte_count);
 #endif
         if (p_ccb->rsp_list == NULL) {
-            p_ccb->rsp_list = (UINT8 *)GKI_getbuf (SDP_MAX_LIST_BYTE_COUNT);
+            p_ccb->rsp_list = (UINT8 *)osi_malloc (SDP_MAX_LIST_BYTE_COUNT);
             if (p_ccb->rsp_list == NULL) {
                 SDP_TRACE_ERROR ("SDP - no gki buf to save rsp\n");
                 sdp_disconnect (p_ccb, SDP_NO_RESOURCES);
@@ -453,7 +453,7 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
 
     /* Now, ask for the next handle. Re-use the buffer we just got. */
     if (p_ccb->cur_handle < p_ccb->num_handles) {
-        BT_HDR  *p_msg = (BT_HDR *) GKI_getpoolbuf (SDP_POOL_ID);
+        BT_HDR  *p_msg = (BT_HDR *) osi_malloc(SDP_DATA_BUF_SIZE);
         UINT8   *p;
 
         if (!p_msg) {
@@ -558,7 +558,7 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
                           p_ccb->list_len, lists_byte_count);
 #endif
         if (p_ccb->rsp_list == NULL) {
-            p_ccb->rsp_list = (UINT8 *)GKI_getbuf (SDP_MAX_LIST_BYTE_COUNT);
+            p_ccb->rsp_list = (UINT8 *)osi_malloc (SDP_MAX_LIST_BYTE_COUNT);
             if (p_ccb->rsp_list == NULL) {
                 SDP_TRACE_ERROR ("SDP - no gki buf to save rsp\n");
                 sdp_disconnect (p_ccb, SDP_NO_RESOURCES);
@@ -589,7 +589,7 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
 #endif
     /* If continuation request (or first time request) */
     if ((cont_request_needed) || (!p_reply)) {
-        BT_HDR  *p_msg = (BT_HDR *) GKI_getpoolbuf (SDP_POOL_ID);
+        BT_HDR  *p_msg = (BT_HDR *) osi_malloc(SDP_DATA_BUF_SIZE);
         UINT8   *p;
 
         if (!p_msg) {
index 0b7e9aa40320a79e70bf606221f67d05e854bef1..114eb8b2ef4a7ad7d5816cfaa182e06ef809ef77 100644 (file)
@@ -27,8 +27,7 @@
 //#include <stdio.h>
 
 #include "bt_target.h"
-//#include "bt_utils.h"
-#include "gki.h"
+#include "allocator.h"
 #include "l2cdefs.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
@@ -501,7 +500,7 @@ static void sdp_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg)
         SDP_TRACE_WARNING ("SDP - Rcvd L2CAP data, unknown CID: 0x%x\n", l2cap_cid);
     }
 
-    GKI_freebuf (p_msg);
+    osi_free (p_msg);
 }
 
 
index 02a33793d64bfb375a0ec86daaa8799d94589d66..b88134a74d58f773a5545e20a7d4becfc0be89b4 100644 (file)
@@ -27,9 +27,8 @@
 #include <string.h>
 //#include <stdio.h>
 
-#include "gki.h"
 #include "bt_types.h"
-//#include "bt_utils.h"
+#include "allocator.h"
 #include "btu.h"
 #include "bt_defs.h"
 #include "l2cdefs.h"
@@ -247,7 +246,7 @@ static void process_service_search (tCONN_CB *p_ccb, UINT16 trans_num,
     }
 
     /* Get a buffer to use to build the response */
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
         SDP_TRACE_ERROR ("SDP - no buf for search rsp\n");
         return;
     }
@@ -355,10 +354,10 @@ static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
     if (*p_req) {
         /* Free and reallocate buffer */
         if (p_ccb->rsp_list) {
-            GKI_freebuf(p_ccb->rsp_list);
+            osi_free(p_ccb->rsp_list);
         }
 
-        p_ccb->rsp_list = (UINT8 *)GKI_getbuf(max_list_len);
+        p_ccb->rsp_list = (UINT8 *)osi_malloc(max_list_len);
         if (p_ccb->rsp_list == NULL) {
             SDP_TRACE_ERROR("%s No scratch buf for attr rsp\n", __func__);
             return;
@@ -385,18 +384,14 @@ static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
         p_rsp = &p_ccb->rsp_list[0];
         attr_seq.attr_entry[p_ccb->cont_info.next_attr_index].start = p_ccb->cont_info.next_attr_start_id;
     } else {
-        /* Get a scratch buffer to store response */
-        if (!p_ccb->rsp_list || (GKI_get_buf_size(p_ccb->rsp_list) < max_list_len)) {
-            /* Free and reallocate if the earlier allocated buffer is small */
-            if (p_ccb->rsp_list) {
-                GKI_freebuf (p_ccb->rsp_list);
-            }
+           if (p_ccb->rsp_list) {
+            osi_free (p_ccb->rsp_list);
+        }
 
-            p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
-            if (p_ccb->rsp_list == NULL) {
-                SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
-                return;
-            }
+        p_ccb->rsp_list = (UINT8 *)osi_malloc (max_list_len);
+        if (p_ccb->rsp_list == NULL) {
+            SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
+            return;
         }
 
         p_ccb->cont_offset = 0;
@@ -490,7 +485,7 @@ static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
     }
 
     /* Get a buffer to use to build the response */
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
         SDP_TRACE_ERROR ("SDP - no buf for search rsp\n");
         return;
     }
@@ -594,10 +589,10 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
     if (*p_req) {
         /* Free and reallocate buffer */
         if (p_ccb->rsp_list) {
-            GKI_freebuf (p_ccb->rsp_list);
+            osi_free (p_ccb->rsp_list);
         }
 
-        p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
+        p_ccb->rsp_list = (UINT8 *)osi_malloc (max_list_len);
         if (p_ccb->rsp_list == NULL) {
             SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
             return;
@@ -625,17 +620,15 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
         attr_seq.attr_entry[p_ccb->cont_info.next_attr_index].start = p_ccb->cont_info.next_attr_start_id;
     } else {
         /* Get a scratch buffer to store response */
-        if (!p_ccb->rsp_list || (GKI_get_buf_size(p_ccb->rsp_list) < max_list_len)) {
-            /* Free and reallocate if the earlier allocated buffer is small */
-            if (p_ccb->rsp_list) {
-                GKI_freebuf (p_ccb->rsp_list);
-            }
+        /* Free and reallocate if the earlier allocated buffer is small */
+        if (p_ccb->rsp_list) {
+            osi_free (p_ccb->rsp_list);
+        }
 
-            p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
-            if (p_ccb->rsp_list == NULL) {
-                SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
-                return;
-            }
+        p_ccb->rsp_list = (UINT8 *)osi_malloc (max_list_len);
+        if (p_ccb->rsp_list == NULL) {
+            SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
+            return;
         }
 
         p_ccb->cont_offset = 0;
@@ -796,7 +789,7 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
     }
 
     /* Get a buffer to use to build the response */
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
         SDP_TRACE_ERROR ("SDP - no buf for search rsp\n");
         return;
     }
index 2a93fe56793251ee971d44bce8f32d079d0f5801..223c27400336a64f559ffa81f1c06dd0f29527bb 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-//#include <netinet/in.h>
-//#include <stdio.h>
+
+#include "allocator.h"
 
 #include "bt_defs.h"
 
-#include "gki.h"
 #include "bt_types.h"
 
 #include "l2cdefs.h"
@@ -157,7 +156,7 @@ void sdpu_release_ccb (tCONN_CB *p_ccb)
     if (p_ccb->rsp_list) {
         SDP_TRACE_DEBUG("releasing SDP rsp_list\n");
 
-        GKI_freebuf(p_ccb->rsp_list);
+        osi_free(p_ccb->rsp_list);
         p_ccb->rsp_list = NULL;
     }
 }
@@ -312,7 +311,7 @@ void sdpu_build_n_send_error (tCONN_CB *p_ccb, UINT16 trans_num, UINT16 error_co
                        error_code, p_ccb->connection_id);
 
     /* Get a buffer to use to build and send the packet to L2CAP */
-    if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
         SDP_TRACE_ERROR ("SDP - no buf for err msg\n");
         return;
     }
@@ -981,7 +980,7 @@ UINT8 *sdpu_build_partial_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr, UI
     size_t  len_to_copy;
     UINT16  attr_len;
 
-    if ((p_attr_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN )) == NULL) {
+    if ((p_attr_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN )) == NULL) {
         SDP_TRACE_ERROR("sdpu_build_partial_attrib_entry cannot get a buffer!\n");
         return NULL;
     }
@@ -997,7 +996,7 @@ UINT8 *sdpu_build_partial_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr, UI
     p_out = &p_out[len_to_copy];
     *offset += len_to_copy;
 
-    GKI_freebuf(p_attr_buff);
+    osi_free(p_attr_buff);
     return p_out;
 }
 
@@ -1024,4 +1023,4 @@ void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8 *p_uuid128)
     memcpy(p_uuid128 + 2, &uuid16_bo, sizeof(uint16_t));
 }
 
-#endif  ///SDP_INCLUDED == TRUE
\ No newline at end of file
+#endif  ///SDP_INCLUDED == TRUE
index 46f6ab73ea2b0b91318ce67ed490dc402cc0ac9f..0eedb9a98b8e3eb42a4a742ad99c772eb14e1bab 100644 (file)
@@ -23,6 +23,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "allocator.h"
 
 #if SMP_INCLUDED == TRUE
 //    #include <stdio.h>
@@ -115,7 +116,7 @@ static void leftshift_onebit(UINT8 *input, UINT8 *output)
 static void cmac_aes_cleanup(void)
 {
     if (cmac_cb.text != NULL) {
-        GKI_freebuf(cmac_cb.text);
+        osi_free(cmac_cb.text);
     }
     memset(&cmac_cb, 0, sizeof(tCMAC_CB));
 }
@@ -292,7 +293,7 @@ BOOLEAN aes_cipher_msg_auth_code(BT_OCTET16 key, UINT8 *input, UINT16 length,
 
     SMP_TRACE_WARNING("AES128_CMAC started, allocate buffer size = %d", len);
     /* allocate a memory space of multiple of 16 bytes to hold text  */
-    if ((cmac_cb.text = (UINT8 *)GKI_getbuf(len)) != NULL) {
+    if ((cmac_cb.text = (UINT8 *)osi_malloc(len)) != NULL) {
         cmac_cb.round = n;
 
         memset(cmac_cb.text, 0, len);
index 28e4499fd58c07eda0e94093177b7ffcd6728083..cc1a25f80f4b56996a43b9ffa10762de09e49d4b 100644 (file)
@@ -146,7 +146,7 @@ BOOLEAN smp_encrypt_data (UINT8 *key, UINT8 key_len,
         return FALSE;
     }
 
-    if ((p_start = (UINT8 *)GKI_getbuf((SMP_ENCRYT_DATA_SIZE * 4))) == NULL) {
+    if ((p_start = (UINT8 *)osi_malloc((SMP_ENCRYT_DATA_SIZE * 4))) == NULL) {
         SMP_TRACE_ERROR ("%s failed unable to allocate buffer\n", __func__);
         return FALSE;
     }
@@ -181,7 +181,7 @@ BOOLEAN smp_encrypt_data (UINT8 *key, UINT8 key_len,
     p_out->status = HCI_SUCCESS;
     p_out->opcode =  HCI_BLE_ENCRYPT;
 
-    GKI_freebuf(p_start);
+    osi_free(p_start);
 
     return TRUE;
 }
index 452b84edcd839e2ed3b979706bba976ae591b0d3..d7b7a68815b9214a6c9831b77d1ea8d94421005f 100644 (file)
@@ -23,6 +23,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "allocator.h"
 
 #if SMP_INCLUDED == TRUE
 
@@ -151,7 +152,7 @@ static void smp_data_received(UINT16 channel, BD_ADDR bd_addr, BT_HDR *p_buf)
     /* sanity check */
     if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) {
         SMP_TRACE_WARNING( "Ignore received command with RESERVED code 0x%02x\n", cmd);
-        GKI_freebuf (p_buf);
+        osi_free (p_buf);
         return;
     }
 
@@ -162,7 +163,7 @@ static void smp_data_received(UINT16 channel, BD_ADDR bd_addr, BT_HDR *p_buf)
             p_cb->role = L2CA_GetBleConnRole(bd_addr);
             memcpy(&p_cb->pairing_bda[0], bd_addr, BD_ADDR_LEN);
         } else if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN)) {
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
             smp_reject_unexpected_pairing_command(bd_addr);
             return;
         }
@@ -190,7 +191,7 @@ static void smp_data_received(UINT16 channel, BD_ADDR bd_addr, BT_HDR *p_buf)
         smp_sm_event(p_cb, cmd, p);
     }
 
-    GKI_freebuf (p_buf);
+    osi_free (p_buf);
 }
 
 /*******************************************************************************
@@ -292,7 +293,7 @@ static void smp_br_data_received(UINT16 channel, BD_ADDR bd_addr, BT_HDR *p_buf)
     /* sanity check */
     if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) {
         SMP_TRACE_WARNING( "Ignore received command with RESERVED code 0x%02x", cmd);
-        GKI_freebuf(p_buf);
+        osi_free(p_buf);
         return;
     }
 
@@ -303,7 +304,7 @@ static void smp_br_data_received(UINT16 channel, BD_ADDR bd_addr, BT_HDR *p_buf)
             p_cb->smp_over_br = TRUE;
             memcpy(&p_cb->pairing_bda[0], bd_addr, BD_ADDR_LEN);
         } else if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN)) {
-            GKI_freebuf (p_buf);
+            osi_free (p_buf);
             smp_reject_unexpected_pairing_command(bd_addr);
             return;
         }
@@ -320,7 +321,7 @@ static void smp_br_data_received(UINT16 channel, BD_ADDR bd_addr, BT_HDR *p_buf)
         smp_br_state_machine_event(p_cb, cmd, p);
     }
 
-    GKI_freebuf (p_buf);
+    osi_free (p_buf);
 }
 #endif  /* CLASSIC_BT_INCLUDED == TRUE */
 
index 0e49bb68de2337bf0c1f70ec9d4ab90efdfe7e08..05cabc92a9fc09006ca57572abcb93d934ca43df 100644 (file)
@@ -412,7 +412,7 @@ BT_HDR *smp_build_pairing_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     UINT8       *p;
 
     SMP_TRACE_EVENT("smp_build_pairing_cmd");
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_PAIRING_REQ_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_PAIRING_REQ_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, cmd_code);
@@ -445,7 +445,7 @@ static BT_HDR *smp_build_confirm_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(cmd_code);
 
     SMP_TRACE_EVENT("smp_build_confirm_cmd\n");
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_CONFIRM_CMD_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_CONFIRM_CMD_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, SMP_OPCODE_CONFIRM);
@@ -471,7 +471,7 @@ static BT_HDR *smp_build_rand_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(cmd_code);
 
     SMP_TRACE_EVENT("%s\n", __func__);
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_RAND_CMD_SIZE + L2CAP_MIN_OFFSET))
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_RAND_CMD_SIZE + L2CAP_MIN_OFFSET))
             != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
@@ -498,7 +498,7 @@ static BT_HDR *smp_build_encrypt_info_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(cmd_code);
 
     SMP_TRACE_EVENT("smp_build_encrypt_info_cmd\n");
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_ENC_INFO_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_ENC_INFO_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, SMP_OPCODE_ENCRYPT_INFO);
@@ -526,7 +526,7 @@ static BT_HDR *smp_build_master_id_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
 
     SMP_TRACE_EVENT("%s\n", __func__);
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_MASTER_ID_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_MASTER_ID_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, SMP_OPCODE_MASTER_ID);
@@ -556,7 +556,7 @@ static BT_HDR *smp_build_identity_info_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(p_cb);
 
     SMP_TRACE_EVENT("smp_build_identity_info_cmd\n");
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_ID_INFO_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_ID_INFO_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         BTM_GetDeviceIDRoot(irk);
@@ -586,7 +586,7 @@ static BT_HDR *smp_build_id_addr_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(cmd_code);
     UNUSED(p_cb);
     SMP_TRACE_EVENT("smp_build_id_addr_cmd\n");
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_ID_ADDR_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_ID_ADDR_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, SMP_OPCODE_ID_ADDR);
@@ -614,7 +614,7 @@ static BT_HDR *smp_build_signing_info_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(cmd_code);
 
     SMP_TRACE_EVENT("smp_build_signing_info_cmd\n");
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_SIGN_INFO_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_SIGN_INFO_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, SMP_OPCODE_SIGN_INFO);
@@ -641,7 +641,7 @@ static BT_HDR *smp_build_pairing_fail(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(cmd_code);
 
     SMP_TRACE_EVENT("%s\n", __func__);
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_PAIR_FAIL_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_PAIR_FAIL_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, SMP_OPCODE_PAIRING_FAILED);
@@ -668,7 +668,7 @@ static BT_HDR *smp_build_security_request(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(cmd_code);
 
     SMP_TRACE_EVENT("%s\n", __func__);
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + 2 + L2CAP_MIN_OFFSET)) != NULL) {
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + 2 + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
         UINT8_TO_STREAM (p, SMP_OPCODE_SEC_REQ);
@@ -704,7 +704,7 @@ static BT_HDR *smp_build_pair_public_key_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     memcpy(p_publ_key, p_cb->loc_publ_key.x, BT_OCTET32_LEN);
     memcpy(p_publ_key + BT_OCTET32_LEN, p_cb->loc_publ_key.y, BT_OCTET32_LEN);
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) +
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) +
                                       SMP_PAIR_PUBL_KEY_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
@@ -732,7 +732,7 @@ static BT_HDR *smp_build_pairing_commitment_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(cmd_code);
 
     SMP_TRACE_EVENT("%s\n", __func__);
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_PAIR_COMMITM_SIZE + L2CAP_MIN_OFFSET))
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + SMP_PAIR_COMMITM_SIZE + L2CAP_MIN_OFFSET))
             != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
@@ -760,7 +760,7 @@ static BT_HDR *smp_build_pair_dhkey_check_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
     UNUSED(cmd_code);
 
     SMP_TRACE_EVENT("%s\n", __FUNCTION__);
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) +
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) +
                                       SMP_PAIR_DHKEY_CHECK_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
@@ -788,7 +788,7 @@ static BT_HDR *smp_build_pairing_keypress_notification_cmd(UINT8 cmd_code, tSMP_
     UNUSED(cmd_code);
 
     SMP_TRACE_EVENT("%s\n", __FUNCTION__);
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR)\
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR)\
                                       + SMP_PAIR_KEYPR_NOTIF_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
@@ -1163,7 +1163,7 @@ void smp_reject_unexpected_pairing_command(BD_ADDR bd_addr)
 
     SMP_TRACE_DEBUG ("%s\n", __FUNCTION__);
 
-    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + \
+    if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + \
                                       SMP_PAIR_FAIL_SIZE + L2CAP_MIN_OFFSET)) != NULL) {
         p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
 
index a451584d569b61b06f4e816837b3a5e1d808bfbf..dfcbf450c1a44a1773137596d4075271b4368f32 100644 (file)
@@ -105,11 +105,13 @@ esp_err_t esp_console_cmd_register(const esp_console_cmd_t *cmd)
         asprintf(&item->hint, " %s", cmd->hint);
     } else if (cmd->argtable) {
         /* Generate hint based on cmd->argtable */
-        char* buf;
-        size_t buf_size;
+        char* buf = NULL;
+        size_t buf_size = 0;
         FILE* f = open_memstream(&buf, &buf_size);
-        arg_print_syntax(f, cmd->argtable, NULL);
-        fclose(f);
+        if (f != NULL) {
+            arg_print_syntax(f, cmd->argtable, NULL);
+            fclose(f);
+        }
         item->hint = buf;
     }
     item->argtable = cmd->argtable;
index 04f4c069944d26f6987a4dd0be8cab55b8acb167..099f3b7573cd6cb6254647294e7a0a16d254f346 100644 (file)
@@ -86,7 +86,7 @@ struct spi_transaction_t {
         void *rx_buffer;            ///< Pointer to receive buffer, or NULL for no MISO phase. Written by 4 bytes-unit if DMA is used.
         uint8_t rx_data[4];         ///< If SPI_USE_RXDATA is set, data is received directly to this variable
     };
-};
+} ;        //the rx data should start from a 32-bit aligned address to get around dma issue.
 
 
 typedef struct spi_device_t* spi_device_handle_t;  ///< Handle for a device on a SPI bus
index e880ff611f2ae4412f8cab3ec3d9f9dd0540882a..548edbcf524a68ec7811d18ab7e5c711b9109ef1 100644 (file)
@@ -20,150 +20,476 @@ extern "C" {
 #include "esp_intr.h"
 #include "esp_err.h"
 #include "esp_intr_alloc.h"
-#define TOUCH_PAD_SLEEP_CYCLE_CONFIG   (0x1000)//The Time is 150Khz,the Max value is 0xffff
-#define TOUCH_PAD_MEASURE_CYCLE_CONFIG (0xffff)//The Time is 8Mhz,the Max value is 0xffff
+
 typedef enum {
     TOUCH_PAD_NUM0 = 0, /*!< Touch pad channel 0 is GPIO4 */
-    TOUCH_PAD_NUM1,    /*!< Touch pad channel 0 is GPIO0 */
-    TOUCH_PAD_NUM2,    /*!< Touch pad channel 0 is GPIO2 */
-    TOUCH_PAD_NUM3,    /*!< Touch pad channel 0 is GPIO15 */
-    TOUCH_PAD_NUM4,    /*!< Touch pad channel 0 is GPIO13 */
-    TOUCH_PAD_NUM5,    /*!< Touch pad channel 0 is GPIO12 */
-    TOUCH_PAD_NUM6,    /*!< Touch pad channel 0 is GPIO14 */
-    TOUCH_PAD_NUM7,    /*!< Touch pad channel 0 is GPIO27*/
-    TOUCH_PAD_NUM8,    /*!< Touch pad channel 0 is GPIO33*/
-    TOUCH_PAD_NUM9,    /*!< Touch pad channel 0 is GPIO32*/
+    TOUCH_PAD_NUM1,     /*!< Touch pad channel 1 is GPIO0 */
+    TOUCH_PAD_NUM2,     /*!< Touch pad channel 2 is GPIO2 */
+    TOUCH_PAD_NUM3,     /*!< Touch pad channel 3 is GPIO15*/
+    TOUCH_PAD_NUM4,     /*!< Touch pad channel 4 is GPIO13*/
+    TOUCH_PAD_NUM5,     /*!< Touch pad channel 5 is GPIO12*/
+    TOUCH_PAD_NUM6,     /*!< Touch pad channel 6 is GPIO14*/
+    TOUCH_PAD_NUM7,     /*!< Touch pad channel 7 is GPIO27*/
+    TOUCH_PAD_NUM8,     /*!< Touch pad channel 8 is GPIO32*/
+    TOUCH_PAD_NUM9,     /*!< Touch pad channel 9 is GPIO33*/
     TOUCH_PAD_MAX,
 } touch_pad_t;
 
+typedef enum {
+    TOUCH_HVOLT_KEEP = -1, /*!<Touch sensor high reference voltage, no change  */
+    TOUCH_HVOLT_2V4 = 0,   /*!<Touch sensor high reference voltage, 2.4V  */
+    TOUCH_HVOLT_2V5,       /*!<Touch sensor high reference voltage, 2.5V  */
+    TOUCH_HVOLT_2V6,       /*!<Touch sensor high reference voltage, 2.6V  */
+    TOUCH_HVOLT_2V7,       /*!<Touch sensor high reference voltage, 2.7V  */
+    TOUCH_HVOLT_MAX,
+} touch_high_volt_t;
+
+typedef enum {
+    TOUCH_LVOLT_KEEP = -1, /*!<Touch sensor low reference voltage, no change  */
+    TOUCH_LVOLT_0V5 = 0,   /*!<Touch sensor low reference voltage, 0.5V  */
+    TOUCH_LVOLT_0V6,       /*!<Touch sensor low reference voltage, 0.6V  */
+    TOUCH_LVOLT_0V7,       /*!<Touch sensor low reference voltage, 0.7V  */
+    TOUCH_LVOLT_0V8,       /*!<Touch sensor low reference voltage, 0.8V  */
+    TOUCH_LVOLT_MAX,
+} touch_low_volt_t;
+
+typedef enum {
+    TOUCH_HVOLT_ATTEN_KEEP = -1,  /*!<Touch sensor high reference voltage attenuation, no change  */
+    TOUCH_HVOLT_ATTEN_1V5 = 0,    /*!<Touch sensor high reference voltage attenuation, 1.5V attenuation  */
+    TOUCH_HVOLT_ATTEN_1V,         /*!<Touch sensor high reference voltage attenuation, 1.0V attenuation  */
+    TOUCH_HVOLT_ATTEN_0V5,        /*!<Touch sensor high reference voltage attenuation, 0.5V attenuation  */
+    TOUCH_HVOLT_ATTEN_0V,         /*!<Touch sensor high reference voltage attenuation,   0V attenuation  */
+    TOUCH_HVOLT_ATTEN_MAX,
+} touch_volt_atten_t;
+
+typedef enum {
+    TOUCH_PAD_SLOPE_0 = 0,       /*!<Touch sensor charge / discharge speed, always zero  */
+    TOUCH_PAD_SLOPE_1 = 1,       /*!<Touch sensor charge / discharge speed, slowest  */
+    TOUCH_PAD_SLOPE_2 = 2,       /*!<Touch sensor charge / discharge speed */
+    TOUCH_PAD_SLOPE_3 = 3,       /*!<Touch sensor charge / discharge speed  */
+    TOUCH_PAD_SLOPE_4 = 4,       /*!<Touch sensor charge / discharge speed  */
+    TOUCH_PAD_SLOPE_5 = 5,       /*!<Touch sensor charge / discharge speed  */
+    TOUCH_PAD_SLOPE_6 = 6,       /*!<Touch sensor charge / discharge speed  */
+    TOUCH_PAD_SLOPE_7 = 7,       /*!<Touch sensor charge / discharge speed, fast  */
+    TOUCH_PAD_SLOPE_MAX,
+} touch_cnt_slope_t;
+
+typedef enum {
+    TOUCH_TRIGGER_BELOW = 0,   /*!<Touch interrupt will happen if counter value is less than threshold.*/
+    TOUCH_TRIGGER_ABOVE = 1,   /*!<Touch interrupt will happen if counter value is larger than threshold.*/
+    TOUCH_TRIGGER_MAX,
+} touch_trigger_mode_t;
+
+typedef enum {
+    TOUCH_TRIGGER_SOURCE_BOTH = 0,  /*!< wakeup interrupt is generated if both SET1 and SET2 are "touched"*/
+    TOUCH_TRIGGER_SOURCE_SET1 = 1,  /*!< wakeup interrupt is generated if SET1 is "touched"*/
+    TOUCH_TRIGGER_SOURCE_MAX,
+} touch_trigger_src_t;
+
+typedef enum {
+    TOUCH_PAD_TIE_OPT_LOW = 0,    /*!<Initial level of charging voltage, low level */
+    TOUCH_PAD_TIE_OPT_HIGH = 1,   /*!<Initial level of charging voltage, high level */
+    TOUCH_PAD_TIE_OPT_MAX,
+} touch_tie_opt_t;
+
+typedef enum {
+    TOUCH_FSM_MODE_TIMER = 0,   /*!<To start touch FSM by timer */
+    TOUCH_FSM_MODE_SW,          /*!<To start touch FSM by software trigger */
+    TOUCH_FSM_MODE_MAX,
+} touch_fsm_mode_t;
+
+
 typedef intr_handle_t touch_isr_handle_t;
 
+#define TOUCH_PAD_SLEEP_CYCLE_DEFAULT   (0x1000)  /*!<The timer frequency is RTC_SLOW_CLK( can be 150k or 32k depending on the options), max value is 0xffff */
+#define TOUCH_PAD_MEASURE_CYCLE_DEFAULT (0xffff)  /*!<The time frequency is 8Mhz, the max value is 0xffff */
+#define TOUCH_FSM_MODE_DEFAULT          (TOUCH_FSM_MODE_TIMER)
+#define TOUCH_TRIGGER_MODE_DEFAULT      (TOUCH_TRIGGER_BELOW)
+#define TOUCH_TRIGGER_SOURCE_DEFAULT    (TOUCH_TRIGGER_SOURCE_SET1)
+#define TOUCH_PAD_BIT_MASK_MAX          (0x3ff)
+
 /**
- * @brief       Initialize touch module.
- *
- *This function int touch pad module ,enable touch module
- *
+ * @brief Initialize touch module.
  * @return
  *     - ESP_OK Success
  *     - ESP_FAIL Touch pad init error
- *
  */
 esp_err_t touch_pad_init();
 
 /**
- * @brief Uninstall TouchPad driver.
- *
+ * @brief Un-install touch pad driver.
  * @return
  *     - ESP_OK   Success
- *     - ESP_FAIL Touch pad deinit error
+ *     - ESP_FAIL Touch pad driver not initialized
  */
 esp_err_t touch_pad_deinit();
 
 /**
- * @brief       Configure touch pad interrupt threshold.
- *
- *
- * @param[in]  touch_num  : config touch num
- *
- * @param[in]  threshold : interrupt threshold  ,When the touch_pad_register less than threshold,
- *                         will trigger the touch interrupt.User can use touch_pad_read function
- *                         to determine the threshold.
- *
+ * @brief Configure touch pad interrupt threshold.
+ * @param touch_num touch pad index
+ * @param threshold interrupt threshold,
  * @return    - ESP_OK Success
- *            - ESP_ERR_INVALID_ARG Touch pad error
- *            - ESP_FAIL Touch pad not initialized
- *
+ *            - ESP_ERR_INVALID_ARG if argument wrong
+ *            - ESP_FAIL if touch pad not initialized
  */
 esp_err_t touch_pad_config(touch_pad_t touch_num, uint16_t threshold);
 
 /**
- * @brief       get touch pad touch_pad_register counter.
- *
- *User can use this function to determine the the interrupt threshold .When you do not touch  the
- *pad ,read the touch_pad_read number(NumNotTouch) by the touch_pad_register.When you touch the pad ,read the touch_pad_register
- *number(NumTouch) by the touch_pad_read.Normal NumNotTouch>NumTouch,so you can select a interrupt threshold.
+ * @brief get touch sensor counter value.
+ *  Each touch sensor has a counter to count the number of charge/discharge cycles.
+ *  When the pad is not 'touched', we can get a number of the counter.
+ *  When the pad is 'touched', the value in counter will get smaller because of the larger equivalent capacitance.
+ *  User can use this function to determine the interrupt trigger threshold.
  *
- * @param[in]  touch_num    : touch num
- * @param[out]  touch_value : touch output value
- *
- *  @return   - ESP_OK Success
+ * @param touch_num touch pad index
+ * @param touch_value pointer to accept touch sensor value
+ * @return   - ESP_OK Success
  *            - ESP_ERR_INVALID_ARG Touch pad error
  *            - ESP_FAIL Touch pad not initialized
- *
  */
 esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t * touch_value);
 
 /**
- * @brief   register TouchPad interrupt handler, the handler is an ISR.
- *          The handler will be attached to the same CPU core that this function is running on.
- *
- * @param  fn  Interrupt handler function.
- * @param  arg  Parameter for handler function
- * @param  intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred)
- *            ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
- * @param  handle Pointer to return handle. If non-NULL, a handle for the interrupt will
- *            be returned here.
+ * @brief get filtered touch sensor counter value by IIR filter.
+ * @note touch_pad_filter_start has to be called before calling touch_pad_read_filtered.
+ *       This function can be called from ISR
  *
+ * @param touch_num touch pad index
+ * @param touch_value pointer to accept touch sensor value
+ * @return   - ESP_OK Success
+ *            - ESP_ERR_INVALID_ARG Touch pad error
+ *            - ESP_FAIL Touch pad not initialized
+ */
+esp_err_t touch_pad_read_filtered(touch_pad_t touch_num, uint16_t *touch_value);
+
+/**
+ * @brief   Register touch-pad ISR,
+ * @note Deprecated function, users should replace this with touch_pad_isr_register,
+ *       because RTC modules share a same interrupt index.
+ * @param fn  Pointer to ISR handler
+ * @param arg  Parameter for ISR
+ * @param unused Reserved, not used
+ * @param handle_unused Reserved, not used
+ * @return
+ *     - ESP_OK Success ;
+ *     - ESP_ERR_INVALID_ARG GPIO error
+ */
+esp_err_t touch_pad_isr_handler_register(void(*fn)(void *), void *arg, int unused, intr_handle_t *handle_unused) __attribute__ ((deprecated));
+
+/**
+ * @brief   Register touch-pad ISR.
+ *          The handler will be attached to the same CPU core that this function is running on.
+ * @param fn  Pointer to ISR handler
+ * @param arg  Parameter for ISR
  * @return
  *     - ESP_OK Success ;
  *     - ESP_ERR_INVALID_ARG GPIO error
  */
-esp_err_t touch_pad_isr_handler_register(void(*fn)(void *), void *arg, int intr_alloc_flags, touch_isr_handle_t *handle);
-
-
-/**
- * ***************        ATTENTION       ********************/
-/**
- *@attention
- *Touch button is through the body's capacitive characteristics, 
- *there is a charge discharge circuit inside the. When the hands touch, 
- *the charge and discharge time will be slow.
- *Because of the different hardware, each pad needs to be calibrated at the factory.
- *We use touch_pad_read to determine factory parameters.
- */
-/**
- *----------EXAMPLE TO CONFIGURE GPIO AS OUTPUT ------------ *
- * @code{c}
- *  touch_pad_init();                            
- *  void taskA(void* arg)
- *  {
- *      for(;;){
- *          vtaskDelay(20/portTICK_PERIOD_MS);
- *          ets_printf("touch pad value %u\n",touch_pad_read(0));//Take the touched status and untouched status value
- *      } 
- *  }
- * @endcode
- **/
-/**
- *----------EXAMPLE TO SET ISR HANDLER ----------------------
- * @code{c}
- *   touch_pad_isr_handler_register(rtc_intr,NULL, 0, NULL)    //hook the isr handler for TouchPad interrupt
- * @endcode
- */
-/**
- *----------EXAMPLE TO USE TOUCH_PAD------------ *
- * @code{c}
- *   touch_pad_init();//only init one time
- *   touch_pad_config(0,300);//set the intr threshold,use touch_pad_read to determine this threshold 
- *   touch_pad_isr_handler_register(rtc_intr,NULL, 0, NULL)
- *   #include "esp_attr.h"
- *   void rtc_intr(void * arg)
- *   {
- *       uint32_t pad_intr = READ_PERI_REG(SARADC_SAR_TOUCH_CTRL2_REG) & 0x3ff;
- *       uint8_t i = 0;
- *       uint32_t rtc_intr = READ_PERI_REG(RTC_CNTL_INT_ST_REG);
- *       WRITE_PERI_REG(RTC_CNTL_INT_CLR_REG, rtc_intr);
- *       SET_PERI_REG_MASK(SARADC_SAR_TOUCH_CTRL2_REG, SARADC_TOUCH_MEAS_EN_CLR);
- *       if (rtc_intr & RTC_CNTL_TOUCH_INT_ST) {
- *           for (i = 0; i < TOUCH_PAD_MAX; ++i) {
- *               if ((pad_intr >> i) & 0x01) {
- *                   ets_printf("touch pad intr %u\n",i);
- *               }
- *           }
- *       }
- *  }
- * @endcode
- **/
+esp_err_t touch_pad_isr_register(intr_handler_t fn, void* arg);
+
+/**
+ * @brief Deregister the handler previously registered using touch_pad_isr_handler_register
+ * @param fn  handler function to call (as passed to touch_pad_isr_handler_register)
+ * @param arg  argument of the handler (as passed to touch_pad_isr_handler_register)
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_STATE if a handler matching both fn and
+ *        arg isn't registered
+ */
+esp_err_t touch_pad_isr_deregister(void(*fn)(void *), void *arg);
+
+/**
+ * @brief Set touch sensor measurement and sleep time
+ * @param sleep_cycle  The touch sensor will sleep after each measurement.
+ *                     sleep_cycle decide the interval between each measurement.
+ *                     t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
+ *                     The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
+ * @param meas_cycle The duration of the touch sensor measurement.
+ *                   t_meas = meas_cycle / 8M, the maximum measure time is 0xffff / 8M = 8.19 ms
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_cycle);
+
+/**
+ * @brief Get touch sensor measurement and sleep time
+ * @param sleep_cycle  Pointer to accept sleep cycle number
+ * @param meas_cycle Pointer to accept measurement cycle count.
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_cycle);
+
+/**
+ * @brief Set touch sensor reference voltage, if the voltage gap between high and low reference voltage get less,
+ *        the charging and discharging time would be faster, accordingly, the counter value would be larger.
+ *        In the case of detecting very slight change of capacitance, we can narrow down the gap so as to increase
+ *        the sensitivity. On the other hand, narrow voltage gap would also introduce more noise, but we can use a
+ *        software filter to pre-process the counter value.
+ * @param refh the value of DREFH
+ * @param refl the value of DREFL
+ * @param atten the attenuation on DREFH
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_set_voltage(touch_high_volt_t refh, touch_low_volt_t refl, touch_volt_atten_t atten);
+
+/**
+ * @brief Get touch sensor reference voltage,
+ * @param refh pointer to accept DREFH value
+ * @param refl pointer to accept DREFL value
+ * @param atten pointer to accept the attenuation on DREFH
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_get_voltage(touch_high_volt_t *refh, touch_low_volt_t *refl, touch_volt_atten_t *atten);
+
+/**
+ * @brief Set touch sensor charge/discharge speed for each pad.
+ *        If the slope is 0, the counter would always be zero.
+ *        If the slope is 1, the charging and discharging would be slow, accordingly, the counter value would be small.
+ *        If the slope is set 7, which is the maximum value, the charging and discharging would be fast, accordingly, the
+ *        counter value would be larger.
+ * @param touch_num touch pad index
+ * @param slope touch pad charge/discharge speed
+ * @param opt the initial voltage
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_set_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t slope, touch_tie_opt_t opt);
+
+/**
+ * @brief Get touch sensor charge/discharge speed for each pad
+ * @param touch_num touch pad index
+ * @param slope pointer to accept touch pad charge/discharge slope
+ * @param opt pointer to accept the initial voltage
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_get_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t *slope, touch_tie_opt_t *opt);
+
+/**
+ * @brief Initialize touch pad GPIO
+ * @param touch_num touch pad index
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_io_init(touch_pad_t touch_num);
+
+/**
+ * @brief Set touch sensor FSM mode, the test action can be triggered by the timer,
+ *        as well as by the software.
+ * @param mode FSM mode
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_set_fsm_mode(touch_fsm_mode_t mode);
+
+/**
+ * @brief Get touch sensor FSM mode
+ * @param mode pointer to accept FSM mode
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_get_fsm_mode(touch_fsm_mode_t *mode);
+
+/**
+ * @brief Trigger a touch sensor measurement, only support in SW mode of FSM
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_sw_start();
+
+/**
+ * @brief Set touch sensor interrupt threshold
+ * @param touch_num touch pad index
+ * @param threshold threshold of touchpad count, refer to touch_pad_set_trigger_mode to see how to set trigger mode.
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint16_t threshold);
+
+/**
+ * @brief Get touch sensor interrupt threshold
+ * @param touch_num touch pad index
+ * @param threshold pointer to accept threshold
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint16_t *threshold);
+
+/**
+ * @brief Set touch sensor interrupt trigger mode.
+ *        Interrupt can be triggered either when counter result is less than
+ *        threshold or when counter result is more than threshold.
+ * @param mode touch sensor interrupt trigger mode
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_set_trigger_mode(touch_trigger_mode_t mode);
+
+/**
+ * @brief Get touch sensor interrupt trigger mode
+ * @param mode pointer to accept touch sensor interrupt trigger mode
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_get_trigger_mode(touch_trigger_mode_t *mode);
+
+/**
+ * @brief Set touch sensor interrupt trigger source. There are two sets of touch signals.
+ *        Set1 and set2 can be mapped to several touch signals. Either set will be triggered
+ *        if at least one of its touch signal is 'touched'. The interrupt can be configured to be generated
+ *        if set1 is triggered, or only if both sets are triggered.
+ * @param src touch sensor interrupt trigger source
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_set_trigger_source(touch_trigger_src_t src);
+
+/**
+ * @brief Get touch sensor interrupt trigger source
+ * @param src pointer to accept touch sensor interrupt trigger source
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_get_trigger_source(touch_trigger_src_t *src);
+
+/**
+ * @brief Set touch sensor group mask.
+ *        Touch pad module has two sets of signals, 'Touched' signal is triggered only if
+ *        at least one of touch pad in this group is "touched".
+ *        This function will set the register bits according to the given bitmask.
+ * @param set1_mask bitmask of touch sensor signal group1, it's a 10-bit value
+ * @param set2_mask bitmask of touch sensor signal group2, it's a 10-bit value
+ * @param en_mask bitmask of touch sensor work enable, it's a 10-bit value
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_set_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask);
+
+/**
+ * @brief Get touch sensor group mask.
+ * @param set1_mask pointer to accept bitmask of touch sensor signal group1, it's a 10-bit value
+ * @param set2_mask pointer to accept bitmask of touch sensor signal group2, it's a 10-bit value
+ * @param en_mask pointer to accept bitmask of touch sensor work enable, it's a 10-bit value
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_get_group_mask(uint16_t *set1_mask, uint16_t *set2_mask, uint16_t *en_mask);
+
+/**
+ * @brief Clear touch sensor group mask.
+ *        Touch pad module has two sets of signals, Interrupt is triggered only if
+ *        at least one of touch pad in this group is "touched".
+ *        This function will clear the register bits according to the given bitmask.
+ * @param set1_mask bitmask touch sensor signal group1, it's a 10-bit value
+ * @param set2_mask bitmask touch sensor signal group2, it's a 10-bit value
+ * @param en_mask bitmask of touch sensor work enable, it's a 10-bit value
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_INVALID_ARG if argument is wrong
+ */
+esp_err_t touch_pad_clear_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask);
+
+/**
+ * @brief To clear the touch status register, usually use this function in touch ISR to clear status.
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_clear_status();
+
+/**
+ * @brief Get the touch sensor status, usually used in ISR to decide which pads are 'touched'.
+ * @return
+ *      - touch status
+ */
+uint32_t touch_pad_get_status();
+
+/**
+ * @brief To enable touch pad interrupt
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_intr_enable();
+
+/**
+ * @brief To disable touch pad interrupt
+ * @return
+ *      - ESP_OK on success
+ */
+esp_err_t touch_pad_intr_disable();
+
+/**
+ * @brief set touch pad filter calibration period, in ms.
+ *        Need to call touch_pad_filter_start before all touch filter APIs
+ * @param new_period_ms filter period, in ms
+ * @return
+ *      - ESP_OK Success
+ *      - ESP_ERR_INVALID_STATE driver state error
+ *      - ESP_ERR_INVALID_ARG parameter error
+ */
+esp_err_t touch_pad_set_filter_period(uint32_t new_period_ms);
+
+/**
+ * @brief get touch pad filter calibration period, in ms
+ *        Need to call touch_pad_filter_start before all touch filter APIs
+ * @param p_period_ms pointer to accept period
+ * @return
+ *      - ESP_OK Success
+ *      - ESP_ERR_INVALID_STATE driver state error
+ *      - ESP_ERR_INVALID_ARG parameter error
+ */
+esp_err_t touch_pad_get_filter_period(uint32_t* p_period_ms);
+
+/**
+ * @brief start touch pad filter function
+ *      This API will start a filter to process the noise in order to prevent false triggering
+ *      when detecting slight change of capacitance.
+ *      Need to call touch_pad_filter_start before all touch filter APIs
+ *
+ *      If filter is not initialized, this API will initialize the filter with given period.
+ *      If filter is already initialized, this API will update the filter period.
+ * @note This filter uses FreeRTOS timer, which is dipatched from a task with
+ *       priority 1 by default on CPU 0. So if some application task with higher priority
+ *       takes a lot of CPU0 time, then the quality of data obtained from this filter will be affected.
+ *       You can adjust FreeRTOS timer task priority in menuconfig.
+ * @param filter_period_ms filter calibration period, in ms
+ * @return
+ *      - ESP_OK Success
+ *      - ESP_ERR_INVALID_ARG parameter error
+ *      - ESP_ERR_NO_MEM No memory for driver
+ *      - ESP_ERR_INVALID_STATE driver state error
+ */
+esp_err_t touch_pad_filter_start(uint32_t filter_period_ms);
+
+/**
+ * @brief stop touch pad filter function
+ *        Need to call touch_pad_filter_start before all touch filter APIs
+ * @return
+ *      - ESP_OK Success
+ *      - ESP_ERR_INVALID_STATE driver state error
+ */
+esp_err_t touch_pad_filter_stop();
+
+/**
+ * @brief delete touch pad filter driver and release the memory
+ *        Need to call touch_pad_filter_start before all touch filter APIs
+ * @return
+ *      - ESP_OK Success
+ *      - ESP_ERR_INVALID_STATE driver state error
+ */
+esp_err_t touch_pad_filter_delete();
 
 #ifdef __cplusplus
 }
index 39e5de72dd0d005d6bd99f18421097ece427e1bb..eb89da60cb0bff0add85d2d893679ed4a08b2580 100644 (file)
 #include "rom/ets_sys.h"
 #include "esp_log.h"
 #include "soc/rtc_io_reg.h"
+#include "soc/rtc_io_struct.h"
 #include "soc/sens_reg.h"
+#include "soc/sens_struct.h"
 #include "soc/rtc_cntl_reg.h"
+#include "soc/rtc_cntl_struct.h"
 #include "rtc_io.h"
 #include "touch_pad.h"
 #include "adc.h"
@@ -24,6 +27,7 @@
 #include "freertos/FreeRTOS.h"
 #include "freertos/xtensa_api.h"
 #include "freertos/semphr.h"
+#include "freertos/timers.h"
 #include "esp_intr_alloc.h"
 #include "sys/lock.h"
 #include "driver/rtc_cntl.h"
@@ -43,6 +47,11 @@ static const char *RTC_MODULE_TAG = "RTC_MODULE";
     return (ret_val);                                                              \
 }
 
+#define RTC_RES_CHECK(res, ret_val) if ( (a) != ESP_OK) {                           \
+        ESP_LOGE(RTC_MODULE_TAG,"%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__); \
+        return (ret_val);                                                              \
+}
+
 #define ADC1_CHECK_FUNCTION_RET(fun_ret) if(fun_ret!=ESP_OK){\
     ESP_LOGE(RTC_MODULE_TAG,"%s:%d\n",__FUNCTION__,__LINE__);\
     return ESP_FAIL;\
@@ -51,7 +60,17 @@ static const char *RTC_MODULE_TAG = "RTC_MODULE";
 #define DAC_ERR_STR_CHANNEL_ERROR   "DAC channel error"
 
 portMUX_TYPE rtc_spinlock = portMUX_INITIALIZER_UNLOCKED;
-static xSemaphoreHandle rtc_touch_sem = NULL;
+static SemaphoreHandle_t rtc_touch_mux = NULL;
+
+
+typedef struct {
+    TimerHandle_t timer;
+    uint32_t filtered_val[TOUCH_PAD_MAX];
+    uint32_t filter_period;
+    uint32_t period;
+    bool enable;
+} touch_pad_filter_t;
+static touch_pad_filter_t *s_touch_pad_filter = NULL;
 
 //Reg,Mux,Fun,IE,Up,Down,Rtc_number
 const rtc_gpio_desc_t rtc_gpio_desc[GPIO_PIN_COUNT] = {
@@ -337,10 +356,21 @@ void rtc_gpio_force_hold_dis_all()
 /*---------------------------------------------------------------
                     Touch Pad
 ---------------------------------------------------------------*/
-esp_err_t touch_pad_isr_handler_register(void(*fn)(void *), void *arg, int intr_alloc_flags, touch_isr_handle_t *handle)
+esp_err_t touch_pad_isr_handler_register(void (*fn)(void *), void *arg, int no_use, intr_handle_t *handle_no_use)
 {
     RTC_MODULE_CHECK(fn, "Touch_Pad ISR null", ESP_ERR_INVALID_ARG);
-    return esp_intr_alloc(ETS_RTC_CORE_INTR_SOURCE, intr_alloc_flags, fn, arg, handle);
+    return rtc_isr_register(fn, arg, RTC_CNTL_TOUCH_INT_ST_M);
+}
+
+esp_err_t touch_pad_isr_register(intr_handler_t fn, void* arg)
+{
+    RTC_MODULE_CHECK(fn, "Touch_Pad ISR null", ESP_ERR_INVALID_ARG);
+    return rtc_isr_register(fn, arg, RTC_CNTL_TOUCH_INT_ST_M);
+}
+
+esp_err_t touch_pad_isr_deregister(intr_handler_t fn, void *arg)
+{
+    return rtc_isr_deregister(fn, arg);
 }
 
 static esp_err_t touch_pad_get_io_num(touch_pad_t touch_num, gpio_num_t *gpio_num)
@@ -371,129 +401,346 @@ static esp_err_t touch_pad_get_io_num(touch_pad_t touch_num, gpio_num_t *gpio_nu
         *gpio_num = 27;
         break;
     case TOUCH_PAD_NUM8:
-        *gpio_num = 33;
+        *gpio_num = 32;
         break;
     case TOUCH_PAD_NUM9:
-        *gpio_num = 32;
+        *gpio_num = 33;
         break;
     default:
         return ESP_ERR_INVALID_ARG;
     }
-
     return ESP_OK;
 }
 
-static esp_err_t touch_pad_init_config(uint16_t sleep_cycle, uint16_t sample_cycle_num)
+#define TOUCH_PAD_FILTER_FACTOR_DEFAULT   (16)
+#define TOUCH_PAD_SHIFT_DEFAULT           (4)
+static uint32_t _touch_filter_iir(uint32_t in_now, uint32_t out_last, uint32_t k)
+{
+    if (k == 0) {
+        return in_now;
+    } else {
+        uint32_t out_now = (in_now + (k - 1) * out_last) / k;
+        return out_now;
+    }
+}
+
+static void touch_pad_filter_cb(void *arg)
+{
+    if (s_touch_pad_filter == NULL) {
+        return;
+    }
+    uint16_t val;
+    for (int i = 0; i < TOUCH_PAD_MAX; i++) {
+        touch_pad_read(i, &val);
+        s_touch_pad_filter->filtered_val[i] = s_touch_pad_filter->filtered_val[i] == 0 ? (val << TOUCH_PAD_SHIFT_DEFAULT) : s_touch_pad_filter->filtered_val[i];
+        s_touch_pad_filter->filtered_val[i] = _touch_filter_iir((val << TOUCH_PAD_SHIFT_DEFAULT),
+                s_touch_pad_filter->filtered_val[i], TOUCH_PAD_FILTER_FACTOR_DEFAULT);
+    }
+}
+
+esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_cycle)
 {
-    xSemaphoreTake(rtc_touch_sem, portMAX_DELAY);
+    xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
     portENTER_CRITICAL(&rtc_spinlock);
-    SET_PERI_REG_BITS(RTC_IO_TOUCH_CFG_REG, RTC_IO_TOUCH_XPD_BIAS, 1, RTC_IO_TOUCH_XPD_BIAS_S);
-    SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN_CLR);
-    //clear touch enable
-    WRITE_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG, 0x0);
-    //enable Rtc Touch pad Timer
-    SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_TOUCH_SLP_TIMER_EN);
-    //config pad module sleep time and sample num
-    //Touch pad SleepCycle Time = 150Khz
-    SET_PERI_REG_BITS(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_SLEEP_CYCLES, sleep_cycle, SENS_TOUCH_SLEEP_CYCLES_S);//150kHZ
-    //Touch Pad Measure Time= 8Mhz
-    SET_PERI_REG_BITS(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_MEAS_DELAY, sample_cycle_num, SENS_TOUCH_MEAS_DELAY_S); //8Mhz
+    //touch sensor sleep cycle Time = sleep_cycle / RTC_SLOW_CLK( can be 150k or 32k depending on the options)
+    SENS.sar_touch_ctrl2.touch_sleep_cycles = sleep_cycle;
+    //touch sensor measure time= meas_cycle / 8Mhz
+    SENS.sar_touch_ctrl1.touch_meas_delay = meas_cycle;
     portEXIT_CRITICAL(&rtc_spinlock);
-    xSemaphoreGive(rtc_touch_sem);
+    xSemaphoreGive(rtc_touch_mux);
     return ESP_OK;
 }
 
-esp_err_t touch_pad_init()
+esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_cycle)
 {
-    if(rtc_touch_sem == NULL) {
-        rtc_touch_sem = xSemaphoreCreateMutex();
+    portENTER_CRITICAL(&rtc_spinlock);
+    if (sleep_cycle) {
+        *sleep_cycle = SENS.sar_touch_ctrl2.touch_sleep_cycles;
     }
-    if(rtc_touch_sem == NULL) {
-        return ESP_FAIL;
+    if (meas_cycle) {
+        *meas_cycle = SENS.sar_touch_ctrl1.touch_meas_delay;
     }
-    return touch_pad_init_config(TOUCH_PAD_SLEEP_CYCLE_CONFIG, TOUCH_PAD_MEASURE_CYCLE_CONFIG);
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
 }
 
-esp_err_t touch_pad_deinit()
+esp_err_t touch_pad_set_voltage(touch_high_volt_t refh, touch_low_volt_t refl, touch_volt_atten_t atten)
 {
+    RTC_MODULE_CHECK(((refh < TOUCH_HVOLT_MAX) && (refh >= (int )TOUCH_HVOLT_KEEP)), "touch refh error",
+            ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK(((refl < TOUCH_LVOLT_MAX) && (refh >= (int )TOUCH_LVOLT_KEEP)), "touch refl error",
+            ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK(((atten < TOUCH_HVOLT_ATTEN_MAX) && (refh >= (int )TOUCH_HVOLT_ATTEN_KEEP)), "touch atten error",
+            ESP_ERR_INVALID_ARG);
 
-    if(rtc_touch_sem == NULL) {
-        return ESP_FAIL;
+    portENTER_CRITICAL(&rtc_spinlock);
+    if (refh > TOUCH_HVOLT_KEEP) {
+        RTCIO.touch_cfg.drefh = refh;
+    }
+    if (refl > TOUCH_LVOLT_KEEP) {
+        RTCIO.touch_cfg.drefl = refl;
     }
-    vSemaphoreDelete(rtc_touch_sem);
-    rtc_touch_sem=NULL;
+    if (atten > TOUCH_HVOLT_ATTEN_KEEP) {
+        RTCIO.touch_cfg.drange = atten;
+    }
+    portEXIT_CRITICAL(&rtc_spinlock);
     return ESP_OK;
 }
 
-static void touch_pad_counter_init(touch_pad_t touch_num)
+esp_err_t touch_pad_get_voltage(touch_high_volt_t *refh, touch_low_volt_t *refl, touch_volt_atten_t *atten)
 {
     portENTER_CRITICAL(&rtc_spinlock);
-    //Enable Tie,Init Level(Counter)
-    SET_PERI_REG_MASK(RTC_IO_TOUCH_PAD0_REG + touch_num * 4, RTC_IO_TOUCH_PAD0_TIE_OPT_M);
-    //Touch Set Slop(Counter)
-    SET_PERI_REG_BITS(RTC_IO_TOUCH_PAD0_REG + touch_num * 4, RTC_IO_TOUCH_PAD0_DAC_V, 7, RTC_IO_TOUCH_PAD0_DAC_S);
-    //Enable Touch Pad IO
-    SET_PERI_REG_MASK(RTC_IO_TOUCH_PAD0_REG + touch_num * 4, RTC_IO_TOUCH_PAD0_START_M);
+    if (refh) {
+        *refh = RTCIO.touch_cfg.drefh;
+    }
+    if (refl) {
+        *refl = RTCIO.touch_cfg.drefl;
+    }
+    if (atten) {
+        *atten = RTCIO.touch_cfg.drange;
+    }
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_set_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t slope, touch_tie_opt_t opt)
+{
+    RTC_MODULE_CHECK((slope < TOUCH_PAD_SLOPE_MAX), "touch slope error", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK((opt < TOUCH_PAD_TIE_OPT_MAX), "touch opt error", ESP_ERR_INVALID_ARG);
+    portENTER_CRITICAL(&rtc_spinlock);
+    //set tie opt value, high or low level seem no difference for counter
+    RTCIO.touch_pad[touch_num].tie_opt = opt;
+    //touch sensor set slope for charging and discharging.
+    RTCIO.touch_pad[touch_num].dac = slope;
     portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
 }
 
-static void touch_pad_power_on(touch_pad_t touch_num)
+esp_err_t touch_pad_get_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t *slope, touch_tie_opt_t *opt)
 {
+    RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG);
     portENTER_CRITICAL(&rtc_spinlock);
-    //Enable Touch Pad Power on
-    SET_PERI_REG_MASK(RTC_IO_TOUCH_PAD0_REG + touch_num * 4, RTC_IO_TOUCH_PAD0_XPD_M);
+    if (slope) {
+        *slope = RTCIO.touch_pad[touch_num].dac;
+    }
+    if (opt) {
+        *opt = RTCIO.touch_pad[touch_num].tie_opt;
+    }
     portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
 }
 
-static void toch_pad_io_init(touch_pad_t touch_num)
+esp_err_t touch_pad_io_init(touch_pad_t touch_num)
 {
+    RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG);
     gpio_num_t gpio_num = GPIO_NUM_0;
     touch_pad_get_io_num(touch_num, &gpio_num);
     rtc_gpio_init(gpio_num);
     rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED);
     rtc_gpio_pulldown_dis(gpio_num);
     rtc_gpio_pullup_dis(gpio_num);
+    return ESP_OK;
 }
 
-static esp_err_t touch_start(touch_pad_t touch_num)
+esp_err_t touch_pad_set_fsm_mode(touch_fsm_mode_t mode)
+{
+    RTC_MODULE_CHECK((mode < TOUCH_FSM_MODE_MAX), "touch fsm mode error", ESP_ERR_INVALID_ARG);
+    portENTER_CRITICAL(&rtc_spinlock);
+    SENS.sar_touch_ctrl2.touch_start_en = 0;
+    SENS.sar_touch_ctrl2.touch_start_force = mode;
+    RTCCNTL.state0.touch_slp_timer_en = (mode == TOUCH_FSM_MODE_TIMER ? 1 : 0);
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_get_fsm_mode(touch_fsm_mode_t *mode)
+{
+    if (mode) {
+        *mode = SENS.sar_touch_ctrl2.touch_start_force;
+    }
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_sw_start()
+{
+    portENTER_CRITICAL(&rtc_spinlock);
+    SENS.sar_touch_ctrl2.touch_start_en = 0;
+    SENS.sar_touch_ctrl2.touch_start_en = 1;
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint16_t threshold)
+{
+    RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG);
+    portENTER_CRITICAL(&rtc_spinlock);
+    if (touch_num & 0x1) {
+        SENS.touch_thresh[touch_num / 2].l_thresh = threshold;
+    } else {
+        SENS.touch_thresh[touch_num / 2].h_thresh = threshold;
+
+    }
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint16_t *threshold)
+{
+    RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG);
+    if (threshold) {
+        *threshold = (touch_num & 0x1 )? \
+                SENS.touch_thresh[touch_num / 2].l_thresh : \
+                SENS.touch_thresh[touch_num / 2].h_thresh;
+    }
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_set_trigger_mode(touch_trigger_mode_t mode)
+{
+    RTC_MODULE_CHECK((mode < TOUCH_TRIGGER_MAX), "touch trigger mode error", ESP_ERR_INVALID_ARG);
+    portENTER_CRITICAL(&rtc_spinlock);
+    SENS.sar_touch_ctrl1.touch_out_sel = mode;
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_get_trigger_mode(touch_trigger_mode_t *mode)
+{
+    if (mode) {
+        *mode = SENS.sar_touch_ctrl1.touch_out_sel;
+    }
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_set_trigger_source(touch_trigger_src_t src)
+{
+    RTC_MODULE_CHECK((src < TOUCH_TRIGGER_SOURCE_MAX), "touch trigger source error", ESP_ERR_INVALID_ARG);
+    portENTER_CRITICAL(&rtc_spinlock);
+    SENS.sar_touch_ctrl1.touch_out_1en = src;
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_get_trigger_source(touch_trigger_src_t *src)
+{
+    if (src) {
+        *src = SENS.sar_touch_ctrl1.touch_out_1en;
+    }
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_set_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask)
+{
+    RTC_MODULE_CHECK((set1_mask <= TOUCH_PAD_BIT_MASK_MAX), "touch set1 bitmask error", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK((set2_mask <= TOUCH_PAD_BIT_MASK_MAX), "touch set2 bitmask error", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK((en_mask <= TOUCH_PAD_BIT_MASK_MAX), "touch work_en bitmask error", ESP_ERR_INVALID_ARG);
+
+    portENTER_CRITICAL(&rtc_spinlock);
+    SENS.sar_touch_enable.touch_pad_outen1 |= set1_mask;
+    SENS.sar_touch_enable.touch_pad_outen2 |= set2_mask;
+    SENS.sar_touch_enable.touch_pad_worken |= en_mask;
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_get_group_mask(uint16_t *set1_mask, uint16_t *set2_mask, uint16_t *en_mask)
+{
+    portENTER_CRITICAL(&rtc_spinlock);
+    if (set1_mask) {
+        *set1_mask = SENS.sar_touch_enable.touch_pad_outen1;
+    }
+    if (set2_mask) {
+        *set2_mask = SENS.sar_touch_enable.touch_pad_outen2;
+    }
+    if (en_mask) {
+        *en_mask = SENS.sar_touch_enable.touch_pad_worken;
+    }
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_clear_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask)
+{
+    RTC_MODULE_CHECK((set1_mask <= TOUCH_PAD_BIT_MASK_MAX), "touch set1 bitmask error", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK((set2_mask <= TOUCH_PAD_BIT_MASK_MAX), "touch set2 bitmask error", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK((en_mask <= TOUCH_PAD_BIT_MASK_MAX), "touch work_en bitmask error", ESP_ERR_INVALID_ARG);
+
+    portENTER_CRITICAL(&rtc_spinlock);
+    SENS.sar_touch_enable.touch_pad_outen1 &= (~set1_mask);
+    SENS.sar_touch_enable.touch_pad_outen2 &= (~set2_mask);
+    SENS.sar_touch_enable.touch_pad_worken &= (~en_mask);
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
+
+uint32_t IRAM_ATTR touch_pad_get_status()
+{
+    return SENS.sar_touch_ctrl2.touch_meas_en;
+}
+
+esp_err_t IRAM_ATTR touch_pad_clear_status()
 {
-    RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG);
     portENTER_CRITICAL(&rtc_spinlock);
+    SENS.sar_touch_ctrl2.touch_meas_en_clr = 1;
+    portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
 
-    //Enable Digital rtc control :work mode and out mode
-    SET_PERI_REG_MASK(SENS_SAR_TOUCH_ENABLE_REG, (1 << (touch_num + SENS_TOUCH_PAD_WORKEN_S)) | \
-                      (1 << (touch_num + SENS_TOUCH_PAD_OUTEN2_S)) | \
-                      (1 << (touch_num + SENS_TOUCH_PAD_OUTEN1_S)));
+esp_err_t touch_pad_intr_enable()
+{
+    portENTER_CRITICAL(&rtc_spinlock);
+    RTCCNTL.int_ena.rtc_touch = 1;
     portEXIT_CRITICAL(&rtc_spinlock);
+    return ESP_OK;
+}
 
+esp_err_t touch_pad_intr_disable()
+{
+    portENTER_CRITICAL(&rtc_spinlock);
+    RTCCNTL.int_ena.rtc_touch = 0;
+    portEXIT_CRITICAL(&rtc_spinlock);
     return ESP_OK;
 }
 
 esp_err_t touch_pad_config(touch_pad_t touch_num, uint16_t threshold)
 {
-    RTC_MODULE_CHECK(rtc_touch_sem != NULL, "Touch pad not initialized", ESP_FAIL);
+    RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL);
     RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG);
-    xSemaphoreTake(rtc_touch_sem, portMAX_DELAY);
-    portENTER_CRITICAL(&rtc_spinlock);
-    //clear touch force ,select the Touch mode is Timer
-    CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_EN_M);
-    CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_FORCE_M);
-    //set threshold
-    uint8_t shift;
-    shift = (touch_num & 1) ? SENS_TOUCH_OUT_TH1_S : SENS_TOUCH_OUT_TH0_S;
-    SET_PERI_REG_BITS((SENS_SAR_TOUCH_THRES1_REG + (touch_num / 2) * 4), SENS_TOUCH_OUT_TH0, threshold, shift);
-    //When touch value < threshold ,the Intr will give
-    CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_OUT_SEL);
-    //Intr will give ,when SET0 < threshold
-    SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_OUT_1EN);
-    //Enable Rtc Touch Module Intr,the Interrupt need Rtc out  Enable
-    SET_PERI_REG_MASK(RTC_CNTL_INT_ENA_REG, RTC_CNTL_TOUCH_INT_ENA);
-    portEXIT_CRITICAL(&rtc_spinlock);
-    xSemaphoreGive(rtc_touch_sem);
-    touch_pad_power_on(touch_num);
-    toch_pad_io_init(touch_num);
-    touch_pad_counter_init(touch_num);
-    touch_start(touch_num);
+    touch_pad_set_thresh(touch_num, threshold);
+    touch_pad_io_init(touch_num);
+    touch_pad_set_cnt_mode(touch_num, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_HIGH);
+    touch_pad_set_group_mask((1 << touch_num), (1 << touch_num), (1 << touch_num));
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_init()
+{
+    if (rtc_touch_mux == NULL) {
+        rtc_touch_mux = xSemaphoreCreateMutex();
+    }
+    if (rtc_touch_mux == NULL) {
+        return ESP_FAIL;
+    }
+    touch_pad_intr_disable();
+    touch_pad_set_fsm_mode(TOUCH_FSM_MODE_DEFAULT);
+    touch_pad_set_trigger_mode(TOUCH_TRIGGER_MODE_DEFAULT);
+    touch_pad_set_trigger_source(TOUCH_TRIGGER_SOURCE_DEFAULT);
+    touch_pad_clear_status();
+    touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_deinit()
+{
+    if (rtc_touch_mux == NULL) {
+        return ESP_FAIL;
+    }
+    touch_pad_filter_delete();
+    touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW);
+    touch_pad_clear_status();
+    touch_pad_intr_disable();
+    vSemaphoreDelete(rtc_touch_mux);
+    rtc_touch_mux = NULL;
     return ESP_OK;
 }
 
@@ -501,33 +748,125 @@ esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value)
 {
     RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG);
     RTC_MODULE_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG);
-    RTC_MODULE_CHECK(rtc_touch_sem != NULL, "Touch pad not initialized", ESP_FAIL);
-    xSemaphoreTake(rtc_touch_sem, portMAX_DELAY);
-    uint32_t v0 = READ_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG);
-    portENTER_CRITICAL(&rtc_spinlock);
-    SET_PERI_REG_MASK(SENS_SAR_TOUCH_ENABLE_REG, (1 << (touch_num)));
-    //Disable Intr
-    CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_ENABLE_REG, (1 << (touch_num + SENS_TOUCH_PAD_OUTEN2_S)) | \
-                        ((1 << (touch_num + SENS_TOUCH_PAD_OUTEN1_S))));
-    toch_pad_io_init(touch_num);
-    touch_pad_counter_init(touch_num);
-    touch_pad_power_on(touch_num);
-    //force oneTime test start
-    SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_EN_M);
-    SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_FORCE_M);
-    SET_PERI_REG_BITS(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_XPD_WAIT, 10, SENS_TOUCH_XPD_WAIT_S);
-    portEXIT_CRITICAL(&rtc_spinlock);
-    while (GET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_DONE) == 0) {};
-    uint8_t shift = (touch_num & 1) ? SENS_TOUCH_MEAS_OUT1_S : SENS_TOUCH_MEAS_OUT0_S;
-    *touch_value = READ_PERI_REG(SENS_SAR_TOUCH_OUT1_REG + (touch_num / 2) * 4) >> shift;
-    WRITE_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG, v0);
-    //force oneTime test end
-    //clear touch force ,select the Touch mode is Timer
-    portENTER_CRITICAL(&rtc_spinlock);
-    CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_EN_M);
-    CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_FORCE_M);
-    portEXIT_CRITICAL(&rtc_spinlock);
-    xSemaphoreGive(rtc_touch_sem);
+    RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL);
+    xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
+    while (SENS.sar_touch_ctrl2.touch_meas_done == 0) {};
+    *touch_value = (touch_num & 0x1) ? \
+                        SENS.touch_meas[touch_num / 2].l_val: \
+                        SENS.touch_meas[touch_num / 2].h_val;
+    xSemaphoreGive(rtc_touch_mux);
+    return ESP_OK;
+}
+
+IRAM_ATTR esp_err_t touch_pad_read_filtered(touch_pad_t touch_num, uint16_t *touch_value)
+{
+    RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL);
+    RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE);
+
+    *touch_value = (s_touch_pad_filter->filtered_val[touch_num] >> TOUCH_PAD_SHIFT_DEFAULT);
+    return ESP_OK;
+}
+
+esp_err_t touch_pad_set_filter_period(uint32_t new_period_ms)
+{
+    RTC_MODULE_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE);
+    RTC_MODULE_CHECK(new_period_ms > 0, "Touch pad filter period error", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE);
+
+    esp_err_t ret = ESP_OK;
+    xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
+    if (s_touch_pad_filter != NULL) {
+        xTimerChangePeriod(s_touch_pad_filter->timer, new_period_ms / portTICK_PERIOD_MS, portMAX_DELAY);
+        s_touch_pad_filter->period = new_period_ms;
+    } else {
+        ESP_LOGE(RTC_MODULE_TAG, "Touch pad filter deleted");
+        ret = ESP_ERR_INVALID_STATE;
+    }
+    xSemaphoreGive(rtc_touch_mux);
+    return ret;
+}
+
+esp_err_t touch_pad_get_filter_period(uint32_t* p_period_ms)
+{
+    RTC_MODULE_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE);
+    RTC_MODULE_CHECK(p_period_ms != NULL, "Touch pad period pointer error", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE);
+
+    esp_err_t ret = ESP_OK;
+    xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
+    if (s_touch_pad_filter != NULL) {
+        *p_period_ms = s_touch_pad_filter->period;
+    } else {
+        ESP_LOGE(RTC_MODULE_TAG, "Touch pad filter deleted");
+        ret = ESP_ERR_INVALID_STATE;
+    }
+    xSemaphoreGive(rtc_touch_mux);
+    return ret;
+}
+
+esp_err_t touch_pad_filter_start(uint32_t filter_period_ms)
+{
+    RTC_MODULE_CHECK(filter_period_ms >= portTICK_PERIOD_MS, "Touch pad filter period error", ESP_ERR_INVALID_ARG);
+    RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE);
+
+    esp_err_t ret = ESP_OK;
+    xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
+    if (s_touch_pad_filter == NULL) {
+        s_touch_pad_filter = (touch_pad_filter_t *) calloc(1, sizeof(touch_pad_filter_t));
+        if (s_touch_pad_filter == NULL) {
+            ret = ESP_ERR_NO_MEM;
+        }
+    }
+    if (s_touch_pad_filter->timer == NULL) {
+        s_touch_pad_filter->timer = xTimerCreate("filter_tmr", filter_period_ms / portTICK_PERIOD_MS, pdTRUE,
+        NULL, touch_pad_filter_cb);
+        if (s_touch_pad_filter->timer == NULL) {
+            ret = ESP_ERR_NO_MEM;
+        }
+        xTimerStart(s_touch_pad_filter->timer, portMAX_DELAY);
+        s_touch_pad_filter->enable = true;
+    } else {
+        xTimerChangePeriod(s_touch_pad_filter->timer, filter_period_ms / portTICK_PERIOD_MS, portMAX_DELAY);
+        s_touch_pad_filter->period = filter_period_ms;
+        xTimerStart(s_touch_pad_filter->timer, portMAX_DELAY);
+    }
+    xSemaphoreGive(rtc_touch_mux);
+    return ret;
+}
+
+esp_err_t touch_pad_filter_stop()
+{
+    RTC_MODULE_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE);
+
+    esp_err_t ret = ESP_OK;
+    xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
+    if (s_touch_pad_filter != NULL) {
+        xTimerStop(s_touch_pad_filter->timer, portMAX_DELAY);
+        s_touch_pad_filter->enable = false;
+    } else {
+        ESP_LOGE(RTC_MODULE_TAG, "Touch pad filter deleted");
+        ret = ESP_ERR_INVALID_STATE;
+    }
+    xSemaphoreGive(rtc_touch_mux);
+    return ret;
+}
+
+esp_err_t touch_pad_filter_delete()
+{
+    RTC_MODULE_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE);
+    xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
+    if (s_touch_pad_filter != NULL) {
+        if (s_touch_pad_filter->timer != NULL) {
+            xTimerStop(s_touch_pad_filter->timer, portMAX_DELAY);
+            xTimerDelete(s_touch_pad_filter->timer, portMAX_DELAY);
+            s_touch_pad_filter->timer = NULL;
+        }
+        free(s_touch_pad_filter);
+        s_touch_pad_filter = NULL;
+    }
+    xSemaphoreGive(rtc_touch_mux);
     return ESP_OK;
 }
 
@@ -578,7 +917,6 @@ static esp_err_t adc1_pad_init(adc1_channel_t channel)
     ADC1_CHECK_FUNCTION_RET(rtc_gpio_output_disable(gpio_num));
     ADC1_CHECK_FUNCTION_RET(rtc_gpio_input_disable(gpio_num));
     ADC1_CHECK_FUNCTION_RET(gpio_set_pull_mode(gpio_num, GPIO_FLOATING));
-
     return ESP_OK;
 }
 
index e6175ebae9579d8418720b2111eaf3ab9c336264..0e42be78f7d6af69c1871009557c11a8f45a81b1 100644 (file)
@@ -603,7 +603,7 @@ esp_err_t spi_device_queue_trans(spi_device_handle_t handle, spi_transaction_t *
         //if not use RXDATA neither rx_buffer, buffer_to_rcv assigned to NULL
         trans_buf.buffer_to_rcv = trans_desc->rx_buffer;
     }
-    if ( trans_buf.buffer_to_rcv && handle->host->dma_chan && !esp_ptr_dma_capable( trans_buf.buffer_to_rcv )) {
+    if ( trans_buf.buffer_to_rcv && handle->host->dma_chan && (!esp_ptr_dma_capable( trans_buf.buffer_to_rcv ) || ((int)trans_buf.buffer_to_rcv%4!=0)) ) {
         //if rxbuf in the desc not DMA-capable, malloc a new one
         trans_buf.buffer_to_rcv = heap_caps_malloc((trans_desc->rxlength+7)/8, MALLOC_CAP_DMA);
         if ( trans_buf.buffer_to_rcv==NULL ) return ESP_ERR_NO_MEM;
index 75bf7da6376c67a7ced51bcdb93c8ff884beaa67..ca3a65939434b49f1e434ccff0d90ccde6c94c86 100644 (file)
@@ -722,7 +722,9 @@ config ESP32_WIFI_NVS_ENABLED
     help
         Select this option to enable WiFi NVS flash
 
-menu PHY
+endmenu
+
+menu Phy
        
 config ESP32_PHY_CALIBRATION_AND_DATA_STORAGE
     bool "Do phy calibration and store calibration data in NVS"
@@ -763,4 +765,3 @@ config ESP32_PHY_MAX_TX_POWER
        default ESP32_PHY_MAX_WIFI_TX_POWER
 
 endmenu
-endmenu
\ No newline at end of file
index 32876da0eeacaacced3dd4bb097f7b08cf5b13a6..bb58ad88f46b2533b5e7e687c50cb442aa5bd6d7 100644 (file)
@@ -2,10 +2,6 @@
 # Component Makefile
 #
 
-#ifdef IS_BOOTLOADER_BUILD
-CFLAGS += -DBOOTLOADER_BUILD
-#endif
-
 COMPONENT_SRCDIRS := . hwcrypto
 ifndef CONFIG_NO_BLOBS
 LIBS := core rtc net80211 pp wpa smartconfig coexist wps wpa2 phy
index 58b1146e1d503dfe70a0abc20881f4ff422b5a3a..7bfa96379ee0efe60774b5e35272df8f72c9a797 100755 (executable)
@@ -145,6 +145,14 @@ extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs;
 
 #define WIFI_INIT_CONFIG_MAGIC    0x1F2F3F4F
 
+#ifdef CONFIG_ESP32_WIFI_AMPDU_ENABLED
+#define WIFI_DEFAULT_TX_BA_WIN CONFIG_ESP32_WIFI_TX_BA_WIN
+#define WIFI_DEFAULT_RX_BA_WIN CONFIG_ESP32_WIFI_RX_BA_WIN
+#else
+#define WIFI_DEFAULT_TX_BA_WIN 0 /* unused if ampdu_enable == false */
+#define WIFI_DEFAULT_RX_BA_WIN 0
+#endif
+
 #define WIFI_INIT_CONFIG_DEFAULT() { \
     .event_handler = &esp_event_send, \
     .wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
@@ -156,8 +164,8 @@ extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs;
     .ampdu_enable = WIFI_AMPDU_ENABLED,\
     .nvs_enable = WIFI_NVS_ENABLED,\
     .nano_enable = WIFI_NANO_FORMAT_ENABLED,\
-    .tx_ba_win = CONFIG_ESP32_WIFI_TX_BA_WIN,\
-    .rx_ba_win = CONFIG_ESP32_WIFI_RX_BA_WIN,\
+    .tx_ba_win = WIFI_DEFAULT_TX_BA_WIN,\
+    .rx_ba_win = WIFI_DEFAULT_RX_BA_WIN,\
     .magic = WIFI_INIT_CONFIG_MAGIC\
 };
 
index 79becfc928e652b80e5106bcd2f6fc6ac1b399fe..2ff635f20fb2d16b6025ff0bfbded5e538e8c409 100644 (file)
@@ -3,6 +3,9 @@ PROVIDE ( SPI1 = 0x3ff42000 );
 PROVIDE ( SPI0 = 0x3ff43000 );
 PROVIDE ( GPIO = 0x3ff44000 );
 PROVIDE ( SIGMADELTA = 0x3ff44f00 );
+PROVIDE ( RTCCNTL = 0x3ff48000 );
+PROVIDE ( RTCIO = 0x3ff48400 );
+PROVIDE ( SENS = 0x3ff48800 );
 PROVIDE ( UHCI1 = 0x3ff4C000 );
 PROVIDE ( I2S0 = 0x3ff4F000 );
 PROVIDE ( UART1 = 0x3ff50000 );
index c213a3fc1bbdffb37f60d09eb6d6b0360128ee6d..11d6d84b2a70a944904659bae70d28d55e49b87f 100644 (file)
@@ -1,4 +1,4 @@
-menu ETHERNET
+menu Ethernet
 
 config DMA_RX_BUF_NUM
     int "Number of DMA RX buffers"
@@ -42,4 +42,4 @@ config EMAC_TASK_PRIORITY
     help
         Ethernet MAC task priority.
 
-endmenu
\ No newline at end of file
+endmenu
index 33026a7d4cf860bef01007e8e2c5eae9645ced4f..6926a2dcdd03ebeda8afde39bdaff74de991ed6a 100644 (file)
@@ -272,6 +272,10 @@ test environment:
     通过 TTLcable 连到PC', test script: EnvBase}
 - {PC OS: '', Special: N, Target Count: 1.0, script path: EnvBase.py, tag: UT_T1_1,
   test environment detail: Environment for running ESP32 unit tests, test script: EnvBase}
+- {PC OS: '', Special: N, Target Count: 1.0, script path: EnvBase.py, tag: UT_T1_SDMODE,
+  test environment detail: Environment for running sd card sd mode unit tests, test script: EnvBase}
+- {PC OS: '', Special: N, Target Count: 1.0, script path: EnvBase.py, tag: UT_T1_SPIMODE,
+  test environment detail: Environment for running sd card spi mode unit tests, test script: EnvBase}
 - {PC OS: linux, Special: Y, Target Count: 1.0, script path: EnvBase.py, tag: WebServer_T1_1,
   test environment detail: 'Web Server target connect with PC by UART.
 
index b8a2a497c6505a39a5852e95d0850498e52a80ce..a6054cf512b59d3ac4bdbe5da315e18dc1ee4edd 100644 (file)
@@ -272,6 +272,10 @@ test environment:
     通过 TTLcable 连到PC', test script: EnvBase}
 - {PC OS: '', Special: N, Target Count: 1.0, script path: EnvBase.py, tag: UT_T1_1,
   test environment detail: Environment for running ESP32 unit tests, test script: EnvBase}
+- {PC OS: '', Special: N, Target Count: 1.0, script path: EnvBase.py, tag: UT_T1_SDMODE,
+  test environment detail: Environment for running sd card sd mode unit tests, test script: EnvBase}
+- {PC OS: '', Special: N, Target Count: 1.0, script path: EnvBase.py, tag: UT_T1_SPIMODE,
+  test environment detail: Environment for running sd card spi mode unit tests, test script: EnvBase}
 - {PC OS: linux, Special: Y, Target Count: 1.0, script path: EnvBase.py, tag: WebServer_T1_1,
   test environment detail: 'Web Server target connect with PC by UART.
 
index d28a07e452a8f130cd61b9840edc94ea14c6f293..482fc8e55a86babf4759268aa89a7742b7b32ef5 100644 (file)
@@ -3,7 +3,7 @@ COMPONENT_SUBMODULES += libsodium
 # Common root directory for all source directories
 LSRC := libsodium/src/libsodium
 
-COMPONENT_SRCDIRS := private
+COMPONENT_SRCDIRS := port
 
 # Derived from libsodium/src/libsodium/Makefile.am
 # (ignoring the !MINIMAL set)
@@ -26,9 +26,7 @@ COMPONENT_SRCDIRS += \
        $(LSRC)/crypto_generichash/blake2b/ref \
        $(LSRC)/crypto_hash \
        $(LSRC)/crypto_hash/sha256 \
-       $(LSRC)/crypto_hash/sha256/cp \
        $(LSRC)/crypto_hash/sha512 \
-       $(LSRC)/crypto_hash/sha512/cp \
        $(LSRC)/crypto_kdf/blake2b \
        $(LSRC)/crypto_kdf \
        $(LSRC)/crypto_kx \
@@ -68,8 +66,9 @@ $(LSRC)/crypto_pwhash/argon2/argon2-core.o: CFLAGS += -Wno-type-limits
 $(LSRC)/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.o: CFLAGS += -Wno-type-limits
 $(LSRC)/sodium/utils.o: CFLAGS += -Wno-unused-variable
 
-COMPONENT_ADD_INCLUDEDIRS := $(LSRC)/include port_include
-COMPONENT_PRIV_INCLUDEDIRS := $(LSRC)/include/sodium port_include/sodium private
+COMPONENT_ADD_INCLUDEDIRS := port_include $(LSRC)/include
+# (port_include repeated here as these include directories come before COMPONENT_ADD_INCLUDEDIRS)
+COMPONENT_PRIV_INCLUDEDIRS := port_include port_include/sodium $(LSRC)/include/sodium port
 
 # Not using autoconf, but this needs to be set
 CFLAGS += -DCONFIGURED
diff --git a/components/libsodium/port/crypto_hash_sha256_mbedtls.c b/components/libsodium/port/crypto_hash_sha256_mbedtls.c
new file mode 100644 (file)
index 0000000..dbb8aba
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "crypto_hash_sha256.h"
+
+int
+crypto_hash_sha256_init(crypto_hash_sha256_state *state)
+{
+    mbedtls_sha256_init(state);
+    return 0;
+}
+
+int
+crypto_hash_sha256_update(crypto_hash_sha256_state *state,
+                          const unsigned char *in, unsigned long long inlen)
+{
+    mbedtls_sha256_update(state, in, inlen);
+    return 0;
+}
+
+int
+crypto_hash_sha256_final(crypto_hash_sha256_state *state, unsigned char *out)
+{
+    mbedtls_sha256_finish(state, out);
+    return 0;
+}
+
+int
+crypto_hash_sha256(unsigned char *out, const unsigned char *in,
+                   unsigned long long inlen)
+{
+    mbedtls_sha256(in, inlen, out, 0);
+    return 0;
+}
diff --git a/components/libsodium/port/crypto_hash_sha512_mbedtls.c b/components/libsodium/port/crypto_hash_sha512_mbedtls.c
new file mode 100644 (file)
index 0000000..22761f3
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "crypto_hash_sha512.h"
+
+int
+crypto_hash_sha512_init(crypto_hash_sha512_state *state)
+{
+    mbedtls_sha512_init(state);
+    return 0;
+}
+
+int
+crypto_hash_sha512_update(crypto_hash_sha512_state *state,
+                          const unsigned char *in, unsigned long long inlen)
+{
+    mbedtls_sha512_update(state, in, inlen);
+    return 0;
+}
+
+int
+crypto_hash_sha512_final(crypto_hash_sha512_state *state, unsigned char *out)
+{
+    mbedtls_sha512_finish(state, out);
+    return 0;
+}
+
+int
+crypto_hash_sha512(unsigned char *out, const unsigned char *in,
+                   unsigned long long inlen)
+{
+    mbedtls_sha512(in, inlen, out, 0);
+    return 0;
+}
diff --git a/components/libsodium/port_include/sodium.h b/components/libsodium/port_include/sodium.h
new file mode 100644 (file)
index 0000000..05ad613
--- /dev/null
@@ -0,0 +1,6 @@
+/* Shim needed to make sure the mbedTLS-specific
+   sha256 & 512 headers are included */
+#pragma once
+#include "sodium/crypto_hash_sha512.h"
+#include "sodium/crypto_hash_sha256.h"
+#include_next "sodium.h"
diff --git a/components/libsodium/port_include/sodium/crypto_auth.h b/components/libsodium/port_include/sodium/crypto_auth.h
new file mode 100644 (file)
index 0000000..d877199
--- /dev/null
@@ -0,0 +1,6 @@
+/* Shim needed to make sure the mbedTLS-specific
+   sha256 & sha512 headers are included */
+#pragma once
+#include "crypto_hash_sha512.h"
+#include "crypto_hash_sha256.h"
+#include_next "sodium/crypto_auth.h"
diff --git a/components/libsodium/port_include/sodium/crypto_auth_hmacsha256.h b/components/libsodium/port_include/sodium/crypto_auth_hmacsha256.h
new file mode 100644 (file)
index 0000000..1a80a26
--- /dev/null
@@ -0,0 +1,6 @@
+/* Shim needed to make sure the mbedTLS-specific
+   sha256 header is included */
+#pragma once
+#include "crypto_hash_sha256.h"
+#include_next "sodium/crypto_auth_hmacsha256.h"
+
diff --git a/components/libsodium/port_include/sodium/crypto_auth_hmacsha512.h b/components/libsodium/port_include/sodium/crypto_auth_hmacsha512.h
new file mode 100644 (file)
index 0000000..d296d61
--- /dev/null
@@ -0,0 +1,5 @@
+/* Shim needed to make sure the mbedTLS-specific
+   sha512 header is included */
+#pragma once
+#include "crypto_hash_sha512.h"
+#include_next "sodium/crypto_auth_hmacsha512.h"
diff --git a/components/libsodium/port_include/sodium/crypto_auth_hmacsha512256.h b/components/libsodium/port_include/sodium/crypto_auth_hmacsha512256.h
new file mode 100644 (file)
index 0000000..af50b23
--- /dev/null
@@ -0,0 +1,6 @@
+/* Shim needed to make sure the mbedTLS-specific
+   sha256 & sha512 headers are included */
+#pragma once
+#include "crypto_hash_sha512.h"
+#include "crypto_hash_sha256.h"
+#include_next "sodium/crypto_auth_hmacsha512256.h"
diff --git a/components/libsodium/port_include/sodium/crypto_hash_sha256.h b/components/libsodium/port_include/sodium/crypto_hash_sha256.h
new file mode 100644 (file)
index 0000000..c66a97a
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#ifndef crypto_hash_sha256_H
+#define crypto_hash_sha256_H
+
+/* This is a wrapper for libsodium sha256 that calls back to
+   the mbedTLS implementation (to reduce code size, improve
+   performance, provide hardware acceleration option).
+*/
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <mbedtls/sha256.h>
+
+#include "sodium/export.h"
+
+#ifdef __cplusplus
+# ifdef __GNUC__
+#  pragma GCC diagnostic ignored "-Wlong-long"
+# endif
+extern "C" {
+#endif
+
+typedef mbedtls_sha256_context crypto_hash_sha256_state;
+
+SODIUM_EXPORT
+size_t crypto_hash_sha256_statebytes(void);
+
+#define crypto_hash_sha256_BYTES 32U
+SODIUM_EXPORT
+size_t crypto_hash_sha256_bytes(void);
+
+SODIUM_EXPORT
+int crypto_hash_sha256(unsigned char *out, const unsigned char *in,
+                       unsigned long long inlen);
+
+SODIUM_EXPORT
+int crypto_hash_sha256_init(crypto_hash_sha256_state *state);
+
+SODIUM_EXPORT
+int crypto_hash_sha256_update(crypto_hash_sha256_state *state,
+                              const unsigned char *in,
+                              unsigned long long inlen);
+
+SODIUM_EXPORT
+int crypto_hash_sha256_final(crypto_hash_sha256_state *state,
+                             unsigned char *out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/components/libsodium/port_include/sodium/crypto_hash_sha512.h b/components/libsodium/port_include/sodium/crypto_hash_sha512.h
new file mode 100644 (file)
index 0000000..f173eeb
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#ifndef crypto_hash_sha512_H
+#define crypto_hash_sha512_H
+
+/* This is a wrapper for libsodium sha512 that calls back to
+   the mbedTLS implementation (to reduce code size, improve
+   performance, provide hardware acceleration option).
+*/
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <mbedtls/sha512.h>
+
+#include "sodium/export.h"
+
+#ifdef __cplusplus
+# ifdef __GNUC__
+#  pragma GCC diagnostic ignored "-Wlong-long"
+# endif
+extern "C" {
+#endif
+
+typedef mbedtls_sha512_context crypto_hash_sha512_state;
+
+SODIUM_EXPORT
+size_t crypto_hash_sha512_statebytes(void);
+
+#define crypto_hash_sha512_BYTES 64U
+SODIUM_EXPORT
+size_t crypto_hash_sha512_bytes(void);
+
+SODIUM_EXPORT
+int crypto_hash_sha512(unsigned char *out, const unsigned char *in,
+                       unsigned long long inlen);
+
+SODIUM_EXPORT
+int crypto_hash_sha512_init(crypto_hash_sha512_state *state);
+
+SODIUM_EXPORT
+int crypto_hash_sha512_update(crypto_hash_sha512_state *state,
+                              const unsigned char *in,
+                              unsigned long long inlen);
+
+SODIUM_EXPORT
+int crypto_hash_sha512_final(crypto_hash_sha512_state *state,
+                             unsigned char *out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index ec8a3e932ac75a2e58d88e1bf75f816295582372..6e7c3bc7a94086e099f4c1fde709ac58847ba89d 100644 (file)
@@ -32,7 +32,7 @@ ote:
 COMPONENT_OBJS += $(LS_TESTDIR)/$(1).o
 endef
 
-TEST_CASES := chacha20 aead_chacha20poly1305 box box2 ed25519_convert sign
+TEST_CASES := chacha20 aead_chacha20poly1305 box box2 ed25519_convert sign hash
 
 $(foreach case,$(TEST_CASES),$(eval $(call sodium_testcase,$(case))))
 
index 097d61990bad9cc84c8ed1dfb23afe94362f1a95..9c9cd33dc3b8b33273ac0f801a4d5ad5fe0b54ef 100644 (file)
@@ -51,4 +51,12 @@ TEST_CASE("sign tests", "[libsodium]")
     TEST_ASSERT_EQUAL(0, sign_xmain() );
 }
 
+extern int hash_xmain();
+
+TEST_CASE("hash tests", "[libsodium]")
+{
+    printf("Running hash\n");
+    TEST_ASSERT_EQUAL(0, hash_xmain() );
+}
+
 
index b49d26041d6f524415e896f61cf475cf76323ad5..bfb07b876ace16acde8a8f51109bf6f73f57b9e1 100755 (executable)
@@ -1026,9 +1026,12 @@ lwip_netconn_do_delconn(void *m)
   } else
 #endif /* LWIP_NETCONN_FULLDUPLEX */
   {
-    LWIP_ASSERT("blocking connect in progress",
-      (state != NETCONN_CONNECT) || IN_NONBLOCKING_CONNECT(msg->conn));
-    msg->err = ERR_OK;
+    if (!(state != NETCONN_CONNECT || IN_NONBLOCKING_CONNECT(msg->conn))) {
+      msg->err = ERR_INPROGRESS;
+      NETCONN_SET_SAFE_ERR(msg->conn, ERR_INPROGRESS);
+      LWIP_DEBUGF(API_MSG_DEBUG, ("netconn error:ERR_INPROGRESS\n"));
+      return;
+    }
     /* Drain and delete mboxes */
     netconn_drain(msg->conn);
 
diff --git a/components/mbedtls/port/include/mbedtls/config.h b/components/mbedtls/port/include/mbedtls/config.h
new file mode 100644 (file)
index 0000000..cf3d904
--- /dev/null
@@ -0,0 +1,9 @@
+/* This shim header is added so that any application code
+   which includes "mbedtls/config.h" directly gets the correct
+   config. */
+#pragma once
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include_next "mbedtls/config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
index 2f146e4d4cfe895d65599b87df7d847435f0e1b4..3bcc416e13cc790e2fb45fcfe9111d38609c5032 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 2f146e4d4cfe895d65599b87df7d847435f0e1b4
+Subproject commit 3bcc416e13cc790e2fb45fcfe9111d38609c5032
index 7691cfd3ada8c6776cb6287ea5062e2071a3513b..f04ac592cea1dac52c1c7462114e351f2af4ba18 100644 (file)
@@ -9,7 +9,7 @@ Non-volatile storage (NVS) library is designed to store key-value pairs in flash
 Underlying storage
 ^^^^^^^^^^^^^^^^^^
 
-Currently NVS uses a portion of main flash memory through ``spi_flash_{read|write|erase}`` APIs. The library uses the first partition with ``data`` type and ``nvs`` subtype.
+Currently NVS uses a portion of main flash memory through ``spi_flash_{read|write|erase}`` APIs. The library uses the all the partitions with ``data`` type and ``nvs`` subtype. The application can choose to use the partition with label ``nvs`` through ``nvs_open`` API or any of the other partition by specifying its name through ``nvs_open_from_part`` API.
 
 Future versions of this library may add other storage backends to keep data in another flash chip (SPI or I2C), RTC, FRAM, etc.
 
@@ -41,7 +41,8 @@ Data type check is also performed when reading a value. An error is returned if
 Namespaces
 ^^^^^^^^^^
 
-To mitigate potential conflicts in key names between different components, NVS assigns each key-value pair to one of namespaces. Namespace names follow the same rules as key names, i.e. 15 character maximum length. Namespace name is specified in the ``nvs_open`` call. This call returns an opaque handle, which is used in subsequent calls to ``nvs_read_*``, ``nvs_write_*``, and ``nvs_commit`` functions. This way, handle is associated with a namespace, and key names will not collide with same names in other namespaces.
+To mitigate potential conflicts in key names between different components, NVS assigns each key-value pair to one of namespaces. Namespace names follow the same rules as key names, i.e. 15 character maximum length. Namespace name is specified in the ``nvs_open`` or ``nvs_open_from_part`` call. This call returns an opaque handle, which is used in subsequent calls to ``nvs_read_*``, ``nvs_write_*``, and ``nvs_commit`` functions. This way, handle is associated with a namespace, and key names will not collide with same names in other namespaces.
+Please note that the namespaces with same name in different NVS partitions are considered as separate namespaces.
 
 Security, tampering, and robustness
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
index 5b469f764a7a1ea4b3977a1ca6e54ddae7ddea70..dfdd18c92c889586f2e56fb586ab56e568faa151 100644 (file)
@@ -43,7 +43,9 @@ typedef uint32_t nvs_handle;
 #define ESP_ERR_NVS_INVALID_LENGTH      (ESP_ERR_NVS_BASE + 0x0c)  /*!< String or blob length is not sufficient to store data */
 #define ESP_ERR_NVS_NO_FREE_PAGES       (ESP_ERR_NVS_BASE + 0x0d)  /*!< NVS partition doesn't contain any empty pages. This may happen if NVS partition was truncated. Erase the whole partition and call nvs_flash_init again. */
 #define ESP_ERR_NVS_VALUE_TOO_LONG      (ESP_ERR_NVS_BASE + 0x0e)  /*!< String or blob length is longer than supported by the implementation */
+#define ESP_ERR_NVS_PART_NOT_FOUND      (ESP_ERR_NVS_BASE + 0x0f)  /*!< Partition with specified name is not found in the partition table */
 
+#define NVS_DEFAULT_PART_NAME           "nvs"   /*!< Default partition name of the NVS partition in the partition table */
 /**
  * @brief Mode of opening the non-volatile storage
  *
@@ -54,15 +56,45 @@ typedef enum {
 } nvs_open_mode;
 
 /**
- * @brief      Open non-volatile storage with a given namespace
+ * @brief      Open non-volatile storage with a given namespace from the default NVS partition
  *
  * Multiple internal ESP-IDF and third party application modules can store
  * their key-value pairs in the NVS module. In order to reduce possible
  * conflicts on key names, each module can use its own namespace.
+ * The default NVS partition is the one that is labelled "nvs" in the partition
+ * table.
  *
  * @param[in]  name        Namespace name. Maximal length is determined by the
  *                         underlying implementation, but is guaranteed to be
  *                         at least 15 characters. Shouldn't be empty.
+ * @param[in]  open_mode   NVS_READWRITE or NVS_READONLY. If NVS_READONLY, will
+ *                         open a handle for reading only. All write requests will
+ *                        be rejected for this handle.
+ * @param[out] out_handle  If successful (return code is zero), handle will be
+ *                         returned in this argument.
+ *
+ * @return
+ *             - ESP_OK if storage handle was opened successfully
+ *             - ESP_ERR_NVS_NOT_INITIALIZED if the storage driver is not initialized
+ *             - ESP_ERR_NVS_PART_NOT_FOUND if the partition with label "nvs" is not found
+ *             - ESP_ERR_NVS_NOT_FOUND id namespace doesn't exist yet and
+ *               mode is NVS_READONLY
+ *             - ESP_ERR_NVS_INVALID_NAME if namespace name doesn't satisfy constraints
+ *             - other error codes from the underlying storage driver
+ */
+esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_handle);
+
+/**
+ * @brief      Open non-volatile storage with a given namespace from specified partition
+ *
+ * The behaviour is same as nvs_open() API. However this API can operate on a specified NVS
+ * partition instead of default NVS partition. Note that the specified partition must be registered
+ * with NVS using nvs_flash_init_partition() API.
+ *
+ * @param[in]  part_name   Label (name) of the partition of interest for object read/write/erase
+ * @param[in]  name        Namespace name. Maximal length is determined by the
+ *                         underlying implementation, but is guaranteed to be
+ *                         at least 15 characters. Shouldn't be empty.
  * @param[in]  open_mode   NVS_READWRITE or NVS_READONLY. If NVS_READONLY, will 
  *                         open a handle for reading only. All write requests will 
  *                        be rejected for this handle.
@@ -72,12 +104,13 @@ typedef enum {
  * @return
  *             - ESP_OK if storage handle was opened successfully
  *             - ESP_ERR_NVS_NOT_INITIALIZED if the storage driver is not initialized
+ *             - ESP_ERR_NVS_PART_NOT_FOUND if the partition with specified name is not found
  *             - ESP_ERR_NVS_NOT_FOUND id namespace doesn't exist yet and
  *               mode is NVS_READONLY
  *             - ESP_ERR_NVS_INVALID_NAME if namespace name doesn't satisfy constraints
  *             - other error codes from the underlying storage driver
  */
-esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_handle);
+esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_open_mode open_mode, nvs_handle *out_handle);
 
 /**@{*/
 /**
index 9220f0d3ff5d39a4f0f0afc8e60e416d1fddc693..c9e4a72d742498a591eff8f73012a554d85643c1 100644 (file)
@@ -21,28 +21,61 @@ extern "C" {
 #include "nvs.h"
 
 /**
- * @brief Initialize NVS flash storage with layout given in the partition table.
+ * @brief Initialize the default NVS partition.
+ *
+ * This API initialises the default NVS partition. The default NVS partition
+ * is the one that is labelled "nvs" in the partition table.
  *
  * @return
  *      - ESP_OK if storage was successfully initialized.
  *      - ESP_ERR_NVS_NO_FREE_PAGES if the NVS storage contains no empty pages
  *        (which may happen if NVS partition was truncated)
+ *      - ESP_ERR_NOT_FOUND if no partition with label "nvs" is found in the partition table
  *      - one of the error codes from the underlying flash storage driver
  */
 esp_err_t nvs_flash_init(void);
 
+/**
+ * @brief Initialize NVS flash storage for the specified partition.
+ *
+ * @param[in]  partition_name    Name (label) of the partition. Note that internally a reference to
+ *                               passed value is kept and it should be accessible for future operations
+ *
+ * @return
+ *      - ESP_OK if storage was successfully initialized.
+ *      - ESP_ERR_NVS_NO_FREE_PAGES if the NVS storage contains no empty pages
+ *        (which may happen if NVS partition was truncated)
+ *      - ESP_ERR_NOT_FOUND if specified partition is not found in the partition table
+ *      - one of the error codes from the underlying flash storage driver
+ */
+esp_err_t nvs_flash_init_partition(const char *partition_name);
 
 /**
- * @brief Erase NVS partition
+ * @brief Erase the default NVS partition
  *
- * This function erases all contents of NVS partition
+ * This function erases all contents of the default NVS partition (one with label "nvs")
  *
  * @return
  *      - ESP_OK on success
- *      - ESP_ERR_NOT_FOUND if there is no NVS partition in the partition table
+ *      - ESP_ERR_NOT_FOUND if there is no NVS partition labeled "nvs" in the
+ *        partition table
  */
 esp_err_t nvs_flash_erase(void);
 
+/**
+ * @brief Erase specified NVS partition
+ *
+ * This function erases all contents of specified NVS partition
+ *
+ * @param[in]  part_name    Name (label) of the partition to be erased
+ *
+ * @return
+ *      - ESP_OK on success
+ *      - ESP_ERR_NOT_FOUND if there is no NVS partition with the specified name
+ *        in the partition table
+ */
+esp_err_t nvs_flash_erase_partition(const char *part_name);
+
 #ifdef __cplusplus
 }
 #endif
index 300ea289421fd242111c6b8836b993237855c69c..57759ecd83798fda1280f998e70c9076cdad0408 100644 (file)
@@ -11,6 +11,7 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
+#include <vector>
 #include "nvs.hpp"
 #include "nvs_flash.h"
 #include "nvs_storage.hpp"
@@ -30,19 +31,22 @@ static const char* TAG = "nvs";
 
 class HandleEntry : public intrusive_list_node<HandleEntry>
 {
+    static uint32_t s_nvs_next_handle;
 public:
     HandleEntry() {}
 
-    HandleEntry(nvs_handle handle, bool readOnly, uint8_t nsIndex) :
-        mHandle(handle),
+    HandleEntry(bool readOnly, uint8_t nsIndex, nvs::Storage* StoragePtr) :
+        mHandle(++s_nvs_next_handle),  // Begin the handle value with 1
         mReadOnly(readOnly),
-        mNsIndex(nsIndex)
+        mNsIndex(nsIndex),
+        mStoragePtr(StoragePtr)
     {
     }
 
     nvs_handle mHandle;
     uint8_t mReadOnly;
     uint8_t mNsIndex;
+    nvs::Storage* mStoragePtr;
 };
 
 #ifdef ESP_PLATFORM
@@ -53,50 +57,91 @@ using namespace std;
 using namespace nvs;
 
 static intrusive_list<HandleEntry> s_nvs_handles;
-static uint32_t s_nvs_next_handle = 1;
-static nvs::Storage s_nvs_storage;
+uint32_t HandleEntry::s_nvs_next_handle;
+static intrusive_list<nvs::Storage> s_nvs_storage_list;
 
-extern "C" void nvs_dump()
+static nvs::Storage* lookup_storage_from_name(const char *name)
+{
+    auto it = find_if(begin(s_nvs_storage_list), end(s_nvs_storage_list), [=](Storage& e) -> bool {
+        return (strcmp(e.getPartName(), name) == 0);
+    });
+
+    if (it == end(s_nvs_storage_list)) {
+        return NULL;
+    }
+    return it;
+}
+
+extern "C" void nvs_dump(const char *partName)
 {
     Lock lock;
-    s_nvs_storage.debugDump();
+    nvs::Storage* pStorage;
+
+    pStorage = lookup_storage_from_name(partName);
+    if (pStorage == NULL) {
+        return;
+    }
+
+    pStorage->debugDump();
+    return;
 }
 
-extern "C" esp_err_t nvs_flash_init_custom(uint32_t baseSector, uint32_t sectorCount)
+extern "C" esp_err_t nvs_flash_init_custom(const char *partName, uint32_t baseSector, uint32_t sectorCount)
 {
-    ESP_LOGD(TAG, "nvs_flash_init_custom start=%d count=%d", baseSector, sectorCount);
-    s_nvs_handles.clear();
-    return s_nvs_storage.init(baseSector, sectorCount);
+    ESP_LOGD(TAG, "nvs_flash_init_custom partition=%s start=%d count=%d", partName, baseSector, sectorCount);
+    nvs::Storage* mStorage;
+
+    mStorage = lookup_storage_from_name(partName);
+    if (mStorage == NULL) {
+        mStorage = new nvs::Storage((const char *)partName);
+        s_nvs_storage_list.push_back(mStorage);
+    }
+
+    return mStorage->init(baseSector, sectorCount);
 }
 
 #ifdef ESP_PLATFORM
-extern "C" esp_err_t nvs_flash_init(void)
+extern "C" esp_err_t nvs_flash_init_partition(const char *part_name)
 {
     Lock::init();
     Lock lock;
-    if (s_nvs_storage.isValid()) {
+    nvs::Storage* mStorage;
+
+    mStorage = lookup_storage_from_name(NVS_DEFAULT_PART_NAME);
+    if (mStorage) {
         return ESP_OK;
     }
+
     const esp_partition_t* partition = esp_partition_find_first(
-            ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);
+            ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, part_name);
     if (partition == NULL) {
         return ESP_ERR_NOT_FOUND;
     }
 
-    return nvs_flash_init_custom(partition->address / SPI_FLASH_SEC_SIZE,
+    return nvs_flash_init_custom(part_name, partition->address / SPI_FLASH_SEC_SIZE,
             partition->size / SPI_FLASH_SEC_SIZE);
 }
 
-extern "C" esp_err_t nvs_flash_erase()
+extern "C" esp_err_t nvs_flash_init(void)
+{
+    return nvs_flash_init_partition(NVS_DEFAULT_PART_NAME);
+}
+
+extern "C" esp_err_t nvs_flash_erase_partition(const char *part_name)
 {
     const esp_partition_t* partition = esp_partition_find_first(
-            ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);
+            ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, part_name);
     if (partition == NULL) {
         return ESP_ERR_NOT_FOUND;
     }
 
     return esp_partition_erase_range(partition, 0, partition->size);
 }
+
+extern "C" esp_err_t nvs_flash_erase()
+{
+    return nvs_flash_erase_partition(NVS_DEFAULT_PART_NAME);
+}
 #endif
 
 static esp_err_t nvs_find_ns_handle(nvs_handle handle, HandleEntry& entry)
@@ -111,24 +156,40 @@ static esp_err_t nvs_find_ns_handle(nvs_handle handle, HandleEntry& entry)
     return ESP_OK;
 }
 
-extern "C" esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_handle)
+extern "C" esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_open_mode open_mode, nvs_handle *out_handle)
 {
     Lock lock;
     ESP_LOGD(TAG, "%s %s %d", __func__, name, open_mode);
     uint8_t nsIndex;
-    esp_err_t err = s_nvs_storage.createOrOpenNamespace(name, open_mode == NVS_READWRITE, nsIndex);
+    nvs::Storage* sHandle;
+
+    sHandle = lookup_storage_from_name(part_name);
+    if (sHandle == NULL) {
+        return ESP_ERR_NVS_PART_NOT_FOUND;
+    }
+
+    esp_err_t err = sHandle->createOrOpenNamespace(name, open_mode == NVS_READWRITE, nsIndex);
     if (err != ESP_OK) {
         return err;
     }
 
-    uint32_t handle = s_nvs_next_handle;
-    ++s_nvs_next_handle;
-    *out_handle = handle;
+    HandleEntry *handle_entry = new HandleEntry(open_mode==NVS_READONLY, nsIndex, sHandle);
+    s_nvs_handles.push_back(handle_entry);
+
+    *out_handle = handle_entry->mHandle;
 
-    s_nvs_handles.push_back(new HandleEntry(handle, open_mode==NVS_READONLY, nsIndex));
     return ESP_OK;
 }
 
+extern "C" esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_handle)
+{
+    if (s_nvs_storage_list.size() == 0) {
+        return ESP_ERR_NVS_NOT_INITIALIZED;
+    }
+
+    return nvs_open_from_partition(NVS_DEFAULT_PART_NAME, name, open_mode, out_handle);
+}
+
 extern "C" void nvs_close(nvs_handle handle)
 {
     Lock lock;
@@ -155,7 +216,7 @@ extern "C" esp_err_t nvs_erase_key(nvs_handle handle, const char* key)
     if (entry.mReadOnly) {
         return ESP_ERR_NVS_READ_ONLY;
     }
-    return s_nvs_storage.eraseItem(entry.mNsIndex, key);
+    return entry.mStoragePtr->eraseItem(entry.mNsIndex, key);
 }
 
 extern "C" esp_err_t nvs_erase_all(nvs_handle handle)
@@ -170,7 +231,7 @@ extern "C" esp_err_t nvs_erase_all(nvs_handle handle)
     if (entry.mReadOnly) {
         return ESP_ERR_NVS_READ_ONLY;
     }
-    return s_nvs_storage.eraseNamespace(entry.mNsIndex);
+    return entry.mStoragePtr->eraseNamespace(entry.mNsIndex);
 }
 
 template<typename T>
@@ -186,7 +247,7 @@ static esp_err_t nvs_set(nvs_handle handle, const char* key, T value)
     if (entry.mReadOnly) {
         return ESP_ERR_NVS_READ_ONLY;
     }
-    return s_nvs_storage.writeItem(entry.mNsIndex, key, value);
+    return entry.mStoragePtr->writeItem(entry.mNsIndex, key, value);
 }
 
 extern "C" esp_err_t nvs_set_i8  (nvs_handle handle, const char* key, int8_t value)
@@ -246,7 +307,7 @@ extern "C" esp_err_t nvs_set_str(nvs_handle handle, const char* key, const char*
     if (err != ESP_OK) {
         return err;
     }
-    return s_nvs_storage.writeItem(entry.mNsIndex, nvs::ItemType::SZ, key, value, strlen(value) + 1);
+    return entry.mStoragePtr->writeItem(entry.mNsIndex, nvs::ItemType::SZ, key, value, strlen(value) + 1);
 }
 
 extern "C" esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, size_t length)
@@ -258,7 +319,7 @@ extern "C" esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void
     if (err != ESP_OK) {
         return err;
     }
-    return s_nvs_storage.writeItem(entry.mNsIndex, nvs::ItemType::BLOB, key, value, length);
+    return entry.mStoragePtr->writeItem(entry.mNsIndex, nvs::ItemType::BLOB, key, value, length);
 }
 
 
@@ -272,7 +333,7 @@ static esp_err_t nvs_get(nvs_handle handle, const char* key, T* out_value)
     if (err != ESP_OK) {
         return err;
     }
-    return s_nvs_storage.readItem(entry.mNsIndex, key, *out_value);
+    return entry.mStoragePtr->readItem(entry.mNsIndex, key, *out_value);
 }
 
 extern "C" esp_err_t nvs_get_i8  (nvs_handle handle, const char* key, int8_t* out_value)
@@ -326,7 +387,7 @@ static esp_err_t nvs_get_str_or_blob(nvs_handle handle, nvs::ItemType type, cons
     }
 
     size_t dataSize;
-    err = s_nvs_storage.getItemDataSize(entry.mNsIndex, type, key, dataSize);
+    err = entry.mStoragePtr->getItemDataSize(entry.mNsIndex, type, key, dataSize);
     if (err != ESP_OK) {
         return err;
     }
@@ -341,7 +402,7 @@ static esp_err_t nvs_get_str_or_blob(nvs_handle handle, nvs::ItemType type, cons
         return ESP_ERR_NVS_INVALID_LENGTH;
     }
 
-    return s_nvs_storage.readItem(entry.mNsIndex, type, key, out_value, dataSize);
+    return entry.mStoragePtr->readItem(entry.mNsIndex, type, key, out_value, dataSize);
 }
 
 extern "C" esp_err_t nvs_get_str(nvs_handle handle, const char* key, char* out_value, size_t* length)
index ecf2651ae5ffecc22e095316831c843c15876cfb..3c0e0c85a5beca8a1d232b945a1ef00eb0644fd7 100644 (file)
@@ -27,7 +27,7 @@
 namespace nvs
 {
 
-class Storage
+class Storage : public intrusive_list_node<Storage>
 {
     enum class StorageState : uint32_t {
         INVALID,
@@ -45,6 +45,8 @@ class Storage
 public:
     ~Storage();
 
+    Storage(const char *pName = NVS_DEFAULT_PART_NAME) : mPartitionName(pName) { };
+
     esp_err_t init(uint32_t baseSector, uint32_t sectorCount);
 
     bool isValid() const;
@@ -78,6 +80,11 @@ public:
     
     esp_err_t eraseNamespace(uint8_t nsIndex);
 
+    const char *getPartName() const
+    {
+        return mPartitionName;
+    }
+
     void debugDump();
     
     void debugCheck();
@@ -95,6 +102,7 @@ protected:
     esp_err_t findItem(uint8_t nsIndex, ItemType datatype, const char* key, Page* &page, Item& item);
 
 protected:
+    const char *mPartitionName;
     size_t mPageCount;
     PageManager mPageManager;
     TNamespaces mNamespaces;
index 97940092d53048b96c3b4117b093060149af8ca3..3cf3e7fa1897bfa308c86113c3ed016d34e611cd 100644 (file)
@@ -25,12 +25,13 @@ extern "C" {
  *
  * @note  This API is intended to be used in unit tests.
  * 
+ * @param partName Partition name of the NVS partition as per partition table
  * @param baseSector Flash sector (units of 4096 bytes) offset to start NVS
  * @param sectorCount Length (in flash sectors) of NVS region. 
                                          NVS partition must be at least 3 sectors long.
  * @return ESP_OK if flash was successfully initialized
  */
-esp_err_t nvs_flash_init_custom(uint32_t baseSector, uint32_t sectorCount);
+esp_err_t nvs_flash_init_custom(const char *partName, uint32_t baseSector, uint32_t sectorCount);
 
 
 /**
@@ -38,8 +39,10 @@ esp_err_t nvs_flash_init_custom(uint32_t baseSector, uint32_t sectorCount);
  *
  * This function may be used for debugging purposes to inspect the state
  * of NVS pages. For each page, list of entries is also dumped.
+ *
+ * @param partName Partition name of the NVS partition as per partition table
  */
-void nvs_dump(void);
+void nvs_dump(const char *partName);
 
 
 #ifdef __cplusplus
index 22d4c3b70bc52b00cb0eef553837606fa2e83472..c549eace2c2371188600124af0e18d43d1885834 100644 (file)
@@ -494,7 +494,7 @@ TEST_CASE("nvs api tests", "[nvs]")
     for (uint16_t i = NVS_FLASH_SECTOR; i <NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN; ++i) {
         spi_flash_erase_sector(i);
     }
-    TEST_ESP_OK(nvs_flash_init_custom(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
+    TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
 
     TEST_ESP_ERR(nvs_open("namespace1", NVS_READONLY, &handle_1), ESP_ERR_NVS_NOT_FOUND);
 
@@ -535,7 +535,6 @@ TEST_CASE("nvs api tests", "[nvs]")
     CHECK(0 == strcmp(buf, str));
 }
 
-
 TEST_CASE("wifi test", "[nvs]")
 {
     SpiFlashEmulator emu(10);
@@ -545,7 +544,7 @@ TEST_CASE("wifi test", "[nvs]")
     const uint32_t NVS_FLASH_SECTOR = 5;
     const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
     emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
-    TEST_ESP_OK(nvs_flash_init_custom(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
+    TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
     
     nvs_handle misc_handle;
     TEST_ESP_OK(nvs_open("nvs.net80211", NVS_READWRITE, &misc_handle));
@@ -687,7 +686,7 @@ TEST_CASE("can init storage from flash with random contents", "[nvs]")
     const uint32_t NVS_FLASH_SECTOR = 5;
     const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
     emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
-    TEST_ESP_OK(nvs_flash_init_custom(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
+    TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
     
     TEST_ESP_OK(nvs_open("nvs.net80211", NVS_READWRITE, &handle));
     
@@ -708,7 +707,7 @@ TEST_CASE("nvs api tests, starting with random data in flash", "[nvs][.][long]")
         const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
         emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
         
-        TEST_ESP_OK(nvs_flash_init_custom(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
+        TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
         
         nvs_handle handle_1;
         TEST_ESP_ERR(nvs_open("namespace1", NVS_READONLY, &handle_1), ESP_ERR_NVS_NOT_FOUND);
@@ -745,7 +744,7 @@ TEST_CASE("nvs api tests, starting with random data in flash", "[nvs][.][long]")
     }
 }
 
-extern "C" void nvs_dump();
+extern "C" void nvs_dump(const char *partName);
 
 class RandomTest {
     
@@ -944,7 +943,7 @@ TEST_CASE("monkey test", "[nvs][monkey]")
     const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
     emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
     
-    TEST_ESP_OK(nvs_flash_init_custom(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
+    TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
     
     nvs_handle handle;
     TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle));
@@ -990,7 +989,7 @@ TEST_CASE("test recovery from sudden poweroff", "[.][long][nvs][recovery][monkey
         nvs_handle handle;
         size_t count = iter_count;
 
-        if (nvs_flash_init_custom(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK) {
+        if (nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK) {
             if (nvs_open("namespace1", NVS_READWRITE, &handle) == ESP_OK) {
                 if(test.doRandomThings(handle, gen, count) != ESP_ERR_FLASH_OP_FAIL) {
                     nvs_close(handle);
@@ -1000,11 +999,11 @@ TEST_CASE("test recovery from sudden poweroff", "[.][long][nvs][recovery][monkey
             }
         }
         
-        TEST_ESP_OK(nvs_flash_init_custom(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
+        TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
         TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle));
         auto res = test.doRandomThings(handle, gen, count);
         if (res != ESP_OK) {
-            nvs_dump();
+            nvs_dump(NVS_DEFAULT_PART_NAME);
             CHECK(0);
         }
         nvs_close(handle);
@@ -1018,7 +1017,7 @@ TEST_CASE("test for memory leaks in open/set", "[leaks]")
     const uint32_t NVS_FLASH_SECTOR = 6;
     const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
     emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
-    TEST_ESP_OK(nvs_flash_init_custom(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
+    TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
     
     for (int i = 0; i < 100000; ++i) {
         nvs_handle light_handle = 0;
@@ -1135,7 +1134,7 @@ TEST_CASE("crc error in variable length item is handled", "[nvs]")
 TEST_CASE("read/write failure (TW8406)", "[nvs]")
 {
     SpiFlashEmulator emu(3);
-    nvs_flash_init_custom(0, 3);
+    nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3);
     for (int attempts = 0; attempts < 3; ++attempts) {
         int i = 0;
         nvs_handle light_handle = 0;
@@ -1169,7 +1168,7 @@ TEST_CASE("nvs_flash_init checks for an empty page", "[nvs]")
     const size_t blob_size = Page::BLOB_MAX_SIZE;
     uint8_t blob[blob_size] = {0};
     SpiFlashEmulator emu(5);
-    TEST_ESP_OK( nvs_flash_init_custom(0, 5) );
+    TEST_ESP_OK( nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 5) );
     nvs_handle handle;
     TEST_ESP_OK( nvs_open("test", NVS_READWRITE, &handle) );
     // Fill first page
@@ -1185,7 +1184,24 @@ TEST_CASE("nvs_flash_init checks for an empty page", "[nvs]")
     nvs_close(handle);
     // first two pages are now full, third one is writable, last two are empty
     // init should fail
-    TEST_ESP_ERR( nvs_flash_init_custom(0, 3), ESP_ERR_NVS_NO_FREE_PAGES );
+    TEST_ESP_ERR( nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3), ESP_ERR_NVS_NO_FREE_PAGES );
+}
+
+TEST_CASE("multiple partitions access check", "[nvs]")
+{
+    SpiFlashEmulator emu(10);
+    TEST_ESP_OK( nvs_flash_init_custom("nvs1", 0, 5) );
+    TEST_ESP_OK( nvs_flash_init_custom("nvs2", 5, 5) );
+    nvs_handle handle1, handle2;
+    TEST_ESP_OK( nvs_open_from_partition("nvs1", "test", NVS_READWRITE, &handle1) );
+    TEST_ESP_OK( nvs_open_from_partition("nvs2", "test", NVS_READWRITE, &handle2) );
+    TEST_ESP_OK( nvs_set_i32(handle1, "foo", 0xdeadbeef));
+    TEST_ESP_OK( nvs_set_i32(handle2, "foo", 0xcafebabe));
+    int32_t v1, v2;
+    TEST_ESP_OK( nvs_get_i32(handle1, "foo", &v1));
+    TEST_ESP_OK( nvs_get_i32(handle2, "foo", &v2));
+    CHECK(v1 == 0xdeadbeef);
+    CHECK(v2 == 0xcafebabe);
 }
 
 TEST_CASE("dump all performance data", "[nvs]")
index 5602bd608449d045e3ddbcb65eb8be8baab2fdde..b431752955c86b6d5b10fa16e4c27e101b997a57 100644 (file)
@@ -36,7 +36,7 @@ TEST_CASE("MMC_RSP_BITS", "[sd]")
     TEST_ASSERT_EQUAL_HEX32(0x11,  MMC_RSP_BITS(data, 59, 5));
 }
 
-TEST_CASE("can probe SD", "[sd][ignore]")
+TEST_CASE("can probe SD", "[sd][test_env=UT_T1_SDMODE]")
 {
     sdmmc_host_t config = SDMMC_HOST_DEFAULT();
     sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
@@ -50,7 +50,8 @@ TEST_CASE("can probe SD", "[sd][ignore]")
     free(card);
 }
 
-TEST_CASE("can probe SD (using SPI)", "[sdspi][ignore]")
+
+TEST_CASE("can probe SD(using SPI)", "[sdspi][test_env=UT_T1_SPIMODE]")
 {
     sdmmc_host_t config = SDSPI_HOST_DEFAULT();
     sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
@@ -145,7 +146,7 @@ static void read_write_test(sdmmc_card_t* card)
     do_single_write_read_test(card, card->csd.capacity/2, 128, 1);
 }
 
-TEST_CASE("can write and read back blocks", "[sd][ignore]")
+TEST_CASE("can write and read back blocks", "[sd][test_env=UT_T1_SDMODE]")
 {
     sdmmc_host_t config = SDMMC_HOST_DEFAULT();
     config.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
@@ -160,7 +161,7 @@ TEST_CASE("can write and read back blocks", "[sd][ignore]")
     TEST_ESP_OK(sdmmc_host_deinit());
 }
 
-TEST_CASE("can write and read back blocks (using SPI)", "[sdspi][ignore]")
+TEST_CASE("can write and read back blocks(using SPI)", "[sdspi][test_env=UT_T1_SPIMODE]")
 {
     sdmmc_host_t config = SDSPI_HOST_DEFAULT();
     config.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
@@ -175,11 +176,12 @@ TEST_CASE("can write and read back blocks (using SPI)", "[sdspi][ignore]")
     TEST_ESP_OK(sdspi_host_deinit());
 }
 
-TEST_CASE("reads and writes with an unaligned buffer", "[sd][ignore]")
+TEST_CASE("reads and writes with an unaligned buffer", "[sd][test_env=UT_T1_SDMODE]")
 {
     sdmmc_host_t config = SDMMC_HOST_DEFAULT();
-    TEST_ESP_OK(sdmmc_host_init());
     sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
+    TEST_ESP_OK(sdmmc_host_init());
+
     TEST_ESP_OK(sdmmc_host_init_slot(SDMMC_HOST_SLOT_1, &slot_config));
     sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
     TEST_ASSERT_NOT_NULL(card);
index acb12432b01b533a99ea0073f222cb0adb5455f6..c2a7f63c43202006fcda941123598e2f26c16ffa 100644 (file)
@@ -550,4 +550,5 @@ typedef volatile struct {
         uint32_t val;
     } date;
 } rtc_cntl_dev_t;
+extern rtc_cntl_dev_t RTCCNTL;
 #endif  /* _SOC_RTC_CNTL_STRUCT_H_ */
index da27078c8e09673a41957e97c028532adf7041a6..f9964e376ead90a71ce42f2fc2449d46551f3e62 100644 (file)
@@ -277,4 +277,5 @@ typedef volatile struct {
         uint32_t val;
     } date;
 } rtc_io_dev_t;
+extern rtc_io_dev_t RTCIO;
 #endif  /* _SOC_RTC_IO_STRUCT_H_ */
diff --git a/components/soc/esp32/include/soc/sens_struct.h b/components/soc/esp32/include/soc/sens_struct.h
new file mode 100644 (file)
index 0000000..b0fce38
--- /dev/null
@@ -0,0 +1,316 @@
+// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#ifndef _SOC_SENS_STRUCT_H_
+#define _SOC_SENS_STRUCT_H_
+typedef volatile struct {
+    union {
+        struct {
+            uint32_t sar1_clk_div:      8;
+            uint32_t sar1_sample_cycle: 8;
+            uint32_t sar1_sample_bit:   2;
+            uint32_t sar1_clk_gated:    1;
+            uint32_t sar1_sample_num:   8;
+            uint32_t sar1_dig_force:    1;
+            uint32_t sar1_data_inv:     1;
+            uint32_t reserved29:        3;
+        };
+        uint32_t val;
+    } sar_read_ctrl;
+    uint32_t sar_read_status1;                            /**/
+    union {
+        struct {
+            uint32_t sar_amp_wait1:16;
+            uint32_t sar_amp_wait2:16;
+        };
+        uint32_t val;
+    } sar_meas_wait1;
+    union {
+        struct {
+            uint32_t sar_amp_wait3: 16;
+            uint32_t force_xpd_amp:  2;
+            uint32_t force_xpd_sar:  2;
+            uint32_t sar2_rstb_wait: 8;
+            uint32_t reserved28:     4;
+        };
+        uint32_t val;
+    } sar_meas_wait2;
+    union {
+        struct {
+            uint32_t xpd_sar_amp_fsm:       4;
+            uint32_t amp_rst_fb_fsm:        4;
+            uint32_t amp_short_ref_fsm:     4;
+            uint32_t amp_short_ref_gnd_fsm: 4;
+            uint32_t xpd_sar_fsm:           4;
+            uint32_t sar_rstb_fsm:          4;
+            uint32_t sar2_xpd_wait:         8;
+        };
+        uint32_t val;
+    } sar_meas_ctrl;
+    uint32_t sar_read_status2;                            /**/
+    uint32_t ulp_cp_sleep_cyc0;                          /**/
+    uint32_t ulp_cp_sleep_cyc1;                          /**/
+    uint32_t ulp_cp_sleep_cyc2;                          /**/
+    uint32_t ulp_cp_sleep_cyc3;                          /**/
+    uint32_t ulp_cp_sleep_cyc4;                          /**/
+    union {
+        struct {
+            uint32_t sar1_bit_width:         2;
+            uint32_t sar2_bit_width:         2;
+            uint32_t sar2_en_test:           1;
+            uint32_t sar2_pwdet_cct:         3;
+            uint32_t ulp_cp_force_start_top: 1;
+            uint32_t ulp_cp_start_top:       1;
+            uint32_t sarclk_en:              1;
+            uint32_t pc_init:               11;
+            uint32_t sar2_stop:              1;
+            uint32_t sar1_stop:              1;
+            uint32_t sar2_pwdet_en:          1;
+            uint32_t reserved25:             7;
+        };
+        uint32_t val;
+    } sar_start_force;
+    union {
+        struct {
+            uint32_t mem_wr_addr_init:    11;
+            uint32_t mem_wr_addr_size:    11;
+            uint32_t rtc_mem_wr_offst_clr: 1;
+            uint32_t reserved23:           9;
+        };
+        uint32_t val;
+    } sar_mem_wr_ctrl;
+    uint32_t sar_atten1;                                  /**/
+    uint32_t sar_atten2;                                  /**/
+    union {
+        struct {
+            uint32_t i2c_slave_addr1:   11;
+            uint32_t i2c_slave_addr0:   11;
+            uint32_t meas_status:        8;
+            uint32_t reserved30:         2;
+        };
+        uint32_t val;
+    } sar_slave_addr1;
+    union {
+        struct {
+            uint32_t i2c_slave_addr3:11;
+            uint32_t i2c_slave_addr2:11;
+            uint32_t reserved22:     10;
+        };
+        uint32_t val;
+    } sar_slave_addr2;
+    union {
+        struct {
+            uint32_t i2c_slave_addr5:11;
+            uint32_t i2c_slave_addr4:11;
+            uint32_t tsens_out:       8;
+            uint32_t tsens_rdy_out:   1;
+            uint32_t reserved31:      1;
+        };
+        uint32_t val;
+    } sar_slave_addr3;
+    union {
+        struct {
+            uint32_t i2c_slave_addr7:11;
+            uint32_t i2c_slave_addr6:11;
+            uint32_t i2c_rdata:       8;
+            uint32_t i2c_done:        1;
+            uint32_t reserved31:      1;
+        };
+        uint32_t val;
+    } sar_slave_addr4;
+    union {
+        struct {
+            uint32_t tsens_xpd_wait:      12;
+            uint32_t tsens_xpd_force:      1;
+            uint32_t tsens_clk_inv:        1;
+            uint32_t tsens_clk_gated:      1;
+            uint32_t tsens_in_inv:         1;
+            uint32_t tsens_clk_div:        8;
+            uint32_t tsens_power_up:       1;
+            uint32_t tsens_power_up_force: 1;
+            uint32_t tsens_dump_out:       1;
+            uint32_t reserved27:           5;
+        };
+        uint32_t val;
+    } sar_tctrl;
+    union {
+        struct {
+            uint32_t sar_i2c_ctrl:       28;
+            uint32_t sar_i2c_start:       1;
+            uint32_t sar_i2c_start_force: 1;
+            uint32_t reserved30:          2;
+        };
+        uint32_t val;
+    } sar_i2c_ctrl;
+    union {
+        struct {
+            uint32_t meas1_data_sar:   16;
+            uint32_t meas1_done_sar:    1;
+            uint32_t meas1_start_sar:   1;
+            uint32_t meas1_start_force: 1;
+            uint32_t sar1_en_pad:      12;
+            uint32_t sar1_en_pad_force: 1;
+        };
+        uint32_t val;
+    } sar_meas_start1;
+    union {
+        struct {
+            uint32_t touch_meas_delay:16;
+            uint32_t touch_xpd_wait:   8;
+            uint32_t touch_out_sel:    1;
+            uint32_t touch_out_1en:    1;
+            uint32_t xpd_hall_force:   1;
+            uint32_t hall_phase_force: 1;
+            uint32_t reserved28:       4;
+        };
+        uint32_t val;
+    } sar_touch_ctrl1;
+    union {
+        struct {
+            uint32_t l_thresh: 16;
+            uint32_t h_thresh: 16;
+        };
+        uint32_t val;
+    } touch_thresh[5];
+    union {
+        struct {
+            uint32_t l_val: 16;
+            uint32_t h_val: 16;
+        };
+        uint32_t val;
+    } touch_meas[5];
+    union {
+        struct {
+            uint32_t touch_meas_en:     10;
+            uint32_t touch_meas_done:    1;
+            uint32_t touch_start_fsm_en: 1;
+            uint32_t touch_start_en:     1;
+            uint32_t touch_start_force:  1;
+            uint32_t touch_sleep_cycles:16;
+            uint32_t touch_meas_en_clr:  1;
+            uint32_t reserved31:         1;
+        };
+        uint32_t val;
+    } sar_touch_ctrl2;
+    uint32_t reserved_88;
+    union {
+        struct {
+            uint32_t touch_pad_worken:10;
+            uint32_t touch_pad_outen2:10;
+            uint32_t touch_pad_outen1:10;
+            uint32_t reserved30:       2;
+        };
+        uint32_t val;
+    } sar_touch_enable;
+    union {
+        struct {
+            uint32_t sar2_clk_div:      8;
+            uint32_t sar2_sample_cycle: 8;
+            uint32_t sar2_sample_bit:   2;
+            uint32_t sar2_clk_gated:    1;
+            uint32_t sar2_sample_num:   8;
+            uint32_t sar2_pwdet_force:  1;
+            uint32_t sar2_dig_force:    1;
+            uint32_t sar2_data_inv:     1;
+            uint32_t reserved30:        2;
+        };
+        uint32_t val;
+    } sar_read_ctrl2;
+    union {
+        struct {
+            uint32_t meas2_data_sar:   16;
+            uint32_t meas2_done_sar:    1;
+            uint32_t meas2_start_sar:   1;
+            uint32_t meas2_start_force: 1;
+            uint32_t sar2_en_pad:      12;
+            uint32_t sar2_en_pad_force: 1;
+        };
+        uint32_t val;
+    } sar_meas_start2;
+    union {
+        struct {
+            uint32_t sw_fstep:          16;
+            uint32_t sw_tone_en:         1;
+            uint32_t debug_bit_sel:      5;
+            uint32_t dac_dig_force:      1;
+            uint32_t dac_clk_force_low:  1;
+            uint32_t dac_clk_force_high: 1;
+            uint32_t dac_clk_inv:        1;
+            uint32_t reserved26:         6;
+        };
+        uint32_t val;
+    } sar_dac_ctrl1;
+    union {
+        struct {
+            uint32_t dac_dc1:    8;
+            uint32_t dac_dc2:    8;
+            uint32_t dac_scale1: 2;
+            uint32_t dac_scale2: 2;
+            uint32_t dac_inv1:   2;
+            uint32_t dac_inv2:   2;
+            uint32_t dac_cw_en1: 1;
+            uint32_t dac_cw_en2: 1;
+            uint32_t reserved26: 6;
+        };
+        uint32_t val;
+    } sar_dac_ctrl2;
+    union {
+        struct {
+            uint32_t sar1_dac_xpd_fsm:           4;
+            uint32_t sar1_dac_xpd_fsm_idle:      1;
+            uint32_t xpd_sar_amp_fsm_idle:       1;
+            uint32_t amp_rst_fb_fsm_idle:        1;
+            uint32_t amp_short_ref_fsm_idle:     1;
+            uint32_t amp_short_ref_gnd_fsm_idle: 1;
+            uint32_t xpd_sar_fsm_idle:           1;
+            uint32_t sar_rstb_fsm_idle:          1;
+            uint32_t sar2_rstb_force:            2;
+            uint32_t amp_rst_fb_force:           2;
+            uint32_t amp_short_ref_force:        2;
+            uint32_t amp_short_ref_gnd_force:    2;
+            uint32_t reserved19:                13;
+        };
+        uint32_t val;
+    } sar_meas_ctrl2;
+    uint32_t reserved_a4;
+    uint32_t reserved_a8;
+    uint32_t reserved_ac;
+    uint32_t reserved_b0;
+    uint32_t reserved_b4;
+    uint32_t reserved_b8;
+    uint32_t reserved_bc;
+    uint32_t reserved_c0;
+    uint32_t reserved_c4;
+    uint32_t reserved_c8;
+    uint32_t reserved_cc;
+    uint32_t reserved_d0;
+    uint32_t reserved_d4;
+    uint32_t reserved_d8;
+    uint32_t reserved_dc;
+    uint32_t reserved_e0;
+    uint32_t reserved_e4;
+    uint32_t reserved_e8;
+    uint32_t reserved_ec;
+    uint32_t reserved_f0;
+    uint32_t reserved_f4;
+    uint32_t sar_nouse;                                   /**/
+    union {
+        struct {
+            uint32_t sar_date:  28;
+            uint32_t reserved28: 4;
+        };
+        uint32_t val;
+    } sardate;
+} sens_dev_t;
+extern sens_dev_t SENS;
+#endif  /* _SOC_SENS_STRUCT_H_ */
index 1873be46d3d5606815d399395ee127037e47f6ed..c8e2364c482da9f945d8365704aef1bc7991772b 100644 (file)
@@ -72,6 +72,7 @@ INPUT = \
     ../components/driver/include/driver/spi_master.h \
     ../components/driver/include/driver/spi_slave.h \
     ../components/driver/include/driver/timer.h \
+    ../components/driver/include/driver/touch_pad.h \
     ../components/driver/include/driver/uart.h \
     ##
     ## Protocols - API Reference
diff --git a/docs/_static/esp-wrover-kit-v2-layout-back.png b/docs/_static/esp-wrover-kit-v2-layout-back.png
new file mode 100644 (file)
index 0000000..84dab7a
Binary files /dev/null and b/docs/_static/esp-wrover-kit-v2-layout-back.png differ
diff --git a/docs/_static/esp-wrover-kit-v2-layout-front.png b/docs/_static/esp-wrover-kit-v2-layout-front.png
new file mode 100644 (file)
index 0000000..d7806ad
Binary files /dev/null and b/docs/_static/esp-wrover-kit-v2-layout-front.png differ
index 491d98033f3caa97a6e5d083e99d825dcad8c455..51a46febd439d126fd81f666199c136879bffa1b 100644 (file)
@@ -18,6 +18,7 @@ Peripherals API
    SPI Master <spi_master>
    SPI Slave <spi_slave>
    Timer <timer>
+   Touch pad <touch_pad>
    UART <uart>
 
 Example code for this API section is provided in :example:`peripherals` directory of ESP-IDF examples.
diff --git a/docs/api-reference/peripherals/touch_pad.rst b/docs/api-reference/peripherals/touch_pad.rst
new file mode 100644 (file)
index 0000000..274d694
--- /dev/null
@@ -0,0 +1,23 @@
+Touch sensor
+===========
+
+Overview
+--------
+
+A touch-sensor system is built on a substrate which carries electrodes and relevant connections under a protective flat surface. 
+When a user touches the surface, the capacitance variation is triggered and a binary signal is generated to indicate whether the touch is valid.
+
+ESP32 can provide up to 10 capacitive touch pads / GPIOs. The sensing pads can be arranged in different combinations, 
+so that a larger area or more points can be detected. The touch pad sensing process is under the control of a hardware-implemented finite-state machine (FSM) which is initiated by software or a dedicated hardware timer.
+
+Application Example
+-------------------
+
+Touch sensor read example: :example:`peripherals/touch_pad_read`.
+Touch sensor interrupt example: :example:`peripherals/touch_pad_interrupt`.
+
+API Reference
+-------------
+
+.. include:: /_build/inc/touch_pad.inc
+
diff --git a/docs/get-started/get-started-wrover-kit-v2.rst b/docs/get-started/get-started-wrover-kit-v2.rst
new file mode 100644 (file)
index 0000000..144b71e
--- /dev/null
@@ -0,0 +1,192 @@
+ESP-WROVER-KIT V2 Getting Started Guide
+=======================================
+
+This user guide shows how to get started with ESP-WROVER-KIT V2 development board including description of its functionality and configuration options. You can find out what version you have in section :doc:`../hw-reference/modules-and-boards`.
+
+If you like to start using this board right now, go directly to section :ref:`esp-wrover-kit-v2-start-development`.
+
+
+What You Need
+-------------
+
+* 1 × ESP-WROVER-KIT V2 board
+* 1 x Micro USB 2.0 Cable, Type A to Micro B
+* 1 × PC loaded with Windows, Linux or Mac OS
+
+
+Overview
+^^^^^^^^
+
+The ESP-WROVER-KIT is a development board produced by `Espressif <http://espressif.com>`_ built around ESP32. This board is compatible with ESP32 modules, including the ESP-WROOM-32 and ESP32-WROVER. The ESP-WROVER-KIT features support for an LCD and MicroSD card. The I/O pins have been broken out from the ESP32 module for easy extension. The board carries an advanced multi-protocol USB bridge (the FTDI FT2232HL), enabling developers to use JTAG directly to debug the ESP32 through the USB interface. The development board makes secondary development easy and cost-effective.
+
+.. note::
+
+    ESP-WROVER-KIT V2 integrates the ESP-WROOM-32 module by default.
+
+
+Functionality Overview
+^^^^^^^^^^^^^^^^^^^^^^
+
+Block diagram below presents main components of ESP-WROVER-KIT and interconnections between components.
+
+.. figure:: ../_static/esp32-wrover-kit-block-diagram.png
+    :align: center
+    :alt: ESP-WROVER-KIT block diagram
+    :figclass: align-center
+
+    ESP-WROVER-KIT block diagram
+
+
+Functional Description
+^^^^^^^^^^^^^^^^^^^^^^
+
+The following list and figures below describe key components, interfaces and controls of ESP-WROVER-KIT board.
+
+32.768 kHz
+    An external precision 32.768 kHz crystal oscillator provides the chip with a clock of low-power consumption during the Deep-sleep mode.
+ESP32 Module
+    ESP-WROVER-KIT is compatible with both ESP-WROOM-32 and ESP32-WROVER. The ESP32-WROVER module features all the functions of ESP-WROOM-32 and integrates an external 32-MBit PSRAM for flexible extended storage and data processing capabilities.
+
+    .. note::
+
+        GPIO16 and GPIO17 are used as the CS and clock signal for PSRAM. To ensure reliable performance, the two GPIOs are not broken out.
+
+CTS/RTS
+    Serial port flow control signals: the pins are not connected to the circuitry by default. To enable them, respective pins of JP14 must be shorted with jumpers.
+UART
+    Serial port: the serial TX/RX signals on FT2232HL and ESP32 are broken out to the two sides of JP11. By default, the two signals are connected with jumpers. To use the ESP32 module serial interface only, the jumpers may be removed and the module can be connected to another external serial device.
+SPI
+    SPI interface: the SPI interface connects to an external flash (PSRAM). To interface another SPI device, an extra CS signal is needed. If an ESP32-WROVER is being used, please note that the electrical level on the flash and SRAM is 1.8V.
+JTAG
+    JTAG interface: the JTAG signals on FT2232HL and ESP32 are broken out to the two sides of JP8. By default, the two signals are disconnected. To enable JTAG, shorting jumpers are required on the signals.
+FT2232
+    FT2232 chip is a multi-protocol USB-to-serial bridge. The FT2232 chip features USB-to-UART and USB-to-JTAG functionalities. Users can control and program the FT2232 chip through the USB interface to establish communication with ESP32.
+
+    The embedded FT2232 chip is one of the distinguishing features of the ESP-WROVER-KIT. It enhances users’ convenience in terms of application development and debugging. In addition, uses do not need to buy a JTAG debugger separately, which reduces the development cost, see `ESP-WROVER-KIT V2 schematic`_.
+EN
+    Reset button: pressing this button resets the system.
+Boot
+    Download button: holding down the **Boot** button and pressing the **EN** button initiates the firmware download mode. Then user can download firmware through the serial port.
+USB
+    USB interface. It functions as the power supply for the board and the communication interface between PC and ESP32 module.
+Power Select
+    Power supply selection interface: the ESP-WROVER-KIT can be powered through the USB interface or the 5V Input interface. The user can select the power supply with a jumper. More details can be found in section :ref:`esp-wrover-kit-v2-setup-options`, jumper header JP7.
+Power Key
+    Power on/off button: toggling to the right powers the board on; toggling to the left powers the board off.
+5V Input
+    The 5V power supply interface is used as a backup power supply in case of full-load operation.
+LDO
+    NCP1117(1A). 5V-to-3.3V LDO. (There is an alternative pin-compatible LDO — LM317DCY, with an output current of up to 1.5A). NCP1117 can provide a maximum current of 1A. The LDO solutions are available with both fixed output voltage and variable output voltage. For details please refer to `ESP-WROVER-KIT V2 schematic`_.
+Camera
+    Camera interface: a standard OV7670 camera module is supported.
+RGB
+    Red, green and blue (RGB) light emitting diodes (LEDs), which may be controlled by pulse width modulation (PWM).
+I/O
+    All the pins on the ESP32 module are led out to the pin headers on the ESPWROVER-KIT. Users can program ESP32 to enable multiple functions such as PWM, ADC, DAC, I2C, I2S, SPI, etc.
+
+Micro SD Card
+    Micro SD card slot for data storage: when ESP32 enters the download mode, GPIO2 cannot be held high. However, a pull-up resistor is required on GPIO2 to enable the Micro SD Card. By default, GPIO2 and the pull-up resistor R153 are disconnected. To enable the SD Card, use jumpers on JP1 as shown in section :ref:`esp-wrover-kit-v2-setup-options`.
+LCD
+    ESP-WROVER-KIT supports mounting and interfacing a 3.2” SPI (standard 4-wire Serial Peripheral Interface) LCD, as shown on figure :ref:`esp-wrover-kit-v2-board-back`.
+
+.. figure:: ../_static/esp-wrover-kit-v2-layout-front.png
+    :align: center
+    :alt: ESP-WROVER-KIT board layout - front
+    :figclass: align-center
+
+    ESP-WROVER-KIT board layout - front
+
+.. _esp-wrover-kit-v2-board-back:
+
+.. figure:: ../_static/esp-wrover-kit-v2-layout-back.png
+    :align: center
+    :alt: ESP-WROVER-KIT board layout - back
+    :figclass: align-center
+
+    ESP-WROVER-KIT board layout - back
+
+
+.. _esp-wrover-kit-v2-setup-options:
+
+Setup Options
+^^^^^^^^^^^^^
+
+There are five jumper headers available to set up the board functionality. Typical options to select from are listed in table below.
+
++--------+----------------------+-------------------------------------------------+
+| Header | Jumper Setting       | Description of Functionality                    |
++--------+----------------------+-------------------------------------------------+
+|  JP1   | |jp1-sd_io2|         | Enable pull up for the Micro SD Card            |
++--------+----------------------+-------------------------------------------------+
+|  JP1   | |jp1-both|           | Assert GPIO2 low during each download           |
+|        |                      | (by jumping it to GPIO0)                        |
++--------+----------------------+-------------------------------------------------+
+|  JP7   | |jp7-ext_5v|         | Power ESP-WROVER-KIT board from an external     |
+|        |                      | power supply                                    |
++--------+----------------------+-------------------------------------------------+
+|  JP7   | |jp7-usb_5v|         | Power ESP-WROVER-KIT board from an USB port     |
++--------+----------------------+-------------------------------------------------+
+|  JP8   | |jp8|                | Enable JTAG functionality                       |
++--------+----------------------+-------------------------------------------------+
+|  JP11  | |jp11-rx-tx|         | Enable UART communication                       |
++--------+----------------------+-------------------------------------------------+
+|  JP14  | |jp14|               | Enable RTS/CTS flow control for serial          |
+|        |                      | communication                                   |
++--------+----------------------+-------------------------------------------------+
+
+
+.. _esp-wrover-kit-v2-start-development:
+
+Start Application Development
+-----------------------------
+
+Before powering up the ESP-WROVER-KIT, please make sure that the board has been received in good condition with no obvious signs of damage.
+
+
+Initial Setup
+^^^^^^^^^^^^^
+
+Select the source of power supply for the board by setting jumper JP7. The options are either USB port or an external power supply. For this application selection of USB port is sufficient. Enable UART communication by installing jumpers on JP11. Both selections are shown in table below.
+
++----------------------+----------------------+
+| Power up             | Enable UART          |
+| from USB port        | communication        |
++----------------------+----------------------+
+| |jp7-usb_5v|         | |jp11-rx-tx|         |
++----------------------+----------------------+
+
+Do not install any other jumpers.
+
+
+Now to Development
+^^^^^^^^^^^^^^^^^^
+
+To start development of applications for ESP32-DevKitC, proceed to section :doc:`index`, that will walk you through the following steps:
+
+* :ref:`get-started-setup-toochain` in your PC to develop applications for ESP32 in C language
+* :ref:`get-started-connect` the module to the PC and verify if it is accessible
+* :ref:`get-started-build-flash` an example application to the ESP32
+* :ref:`get-started-build-monitor` instantly what the application is doing
+
+
+Related Documents
+-----------------
+
+* `ESP-WROVER-KIT V2 schematic`_ (PDF)
+* `ESP32 Datasheet <http://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf>`_ (PDF)
+* `ESP-WROOM-32 Datasheet <http://www.espressif.com/sites/default/files/documentation/esp_wroom_32_datasheet_en.pdf>`_ (PDF)
+* `ESP32-WROVER Datasheet <http://espressif.com/sites/default/files/documentation/esp32-wrover_datasheet_en.pdf>`_ (PDF)
+* :doc:`../api-guides/jtag-debugging/index`
+* :doc:`../hw-reference/modules-and-boards`
+
+
+
+.. |jp1-sd_io2| image:: ../_static/wrover-jp1-sd_io2.png
+.. |jp1-both| image:: ../_static/wrover-jp1-both.png
+.. |jp7-ext_5v| image:: ../_static/wrover-jp7-ext_5v.png
+.. |jp7-usb_5v| image:: ../_static/wrover-jp7-usb_5v.png
+.. |jp8| image:: ../_static/wrover-jp8.png
+.. |jp11-rx-tx| image:: ../_static/wrover-jp11-tx-rx.png
+.. |jp14| image:: ../_static/wrover-jp14.png
+
+.. _ESP-WROVER-KIT V2 schematic: http://dl.espressif.com/dl/schematics/ESP-WROVER-KIT_SCH-2.pdf
index c3422350aa932708389e0f7e0e7f27feda4d5a86..37d6464323dcc0a1818552255edb8ba44f0a216f 100644 (file)
@@ -1,23 +1,19 @@
-ESP-WROVER-KIT Getting Started Guide\r
-====================================\r
+ESP-WROVER-KIT V3 Getting Started Guide\r
+=======================================\r
 \r
-This user guide shows how to get started with ESP-WROVER-KIT development board.\r
+This user guide shows how to get started with ESP-WROVER-KIT V3 development board including description of its functionality and configuration options. You can find out what version you have in section :doc:`../hw-reference/modules-and-boards`.\r
+\r
+If you like to start using this board right now, go directly to section :ref:`esp-wrover-kit-start-development`.\r
 \r
 \r
 What You Need\r
 -------------\r
 \r
-* 1 × ESP-WROVER-KIT board\r
-* 1 × USB A / micro USB B cable \r
+* 1 × ESP-WROVER-KIT V3 board\r
+* 1 x Micro USB 2.0 Cable, Type A to Micro B\r
 * 1 × PC loaded with Windows, Linux or Mac OS\r
 \r
 \r
-The Board\r
----------\r
-\r
-This section describes functionality of ESP-WROVER-KIT board and configuration options. If you like to start using it now, go directly to section :ref:`esp-wrover-start-development`\r
-\r
-\r
 Overview\r
 ^^^^^^^^\r
 \r
@@ -25,7 +21,7 @@ The ESP-WROVER-KIT is a development board produced by `Espressif <http://espress
 \r
 .. note::\r
 \r
-    ESP-WROVER-KIT integrates the ESP-WROOM-32 module, while ESP-WROVER-KIT-RVB integrates the ESP32-WROVER. Both ESP-WROVER-KIT and ESP-WROVER-KIT-RVB have the same baseboard. The only difference is the module\r
+    ESP-WROVER-KIT V3 integrates the ESP32-WROVER module by default\r
 \r
 \r
 Functionality Overview\r
@@ -58,15 +54,11 @@ ESP32 Module
         GPIO16 and GPIO17 are used as the CS and clock signal for PSRAM. To ensure reliable performance, the two GPIOs are not broken out.\r
 \r
 FT2232\r
-    FT2232 chip is a multi-protocol USB-to-serial bridge. Users can control and program the FT2232 chip through the USB interface to establish communication with ESP32. The FT2232 chip also features USB-to-JTAG interface. \r
-\r
-    USB-to-JTAG is available on channel A of FT2232, USB-to-serial on channel B.\r
-\r
-    The embedded FT2232 chip is one of the distinguishing features of the ESPWROVER-KIT. It enhances users’ convenience in terms of application development and debugging. In addition, uses do not need to buy a JTAG debugger separately, which reduces the development cost. The schematics is provided in section :ref:`wrover-kit-related-documents`.\r
+    The FT2232 chip is a multi-protocol USB-to-serial bridge. Users can control and program the FT2232 chip through the USB interface to establish communication with ESP32. The FT2232 chip also features USB-to-JTAG interface. USB-to-JTAG is available on channel A of FT2232, USB-to-serial on channel B. The embedded FT2232 chip is one of the distinguishing features of the ESPWROVER-KIT. It enhances users’ convenience in terms of application development and debugging. In addition, users do not need to buy a JTAG debugger separately, which reduces the development cost, see `ESP-WROVER-KIT V3 schematic`_.\r
 UART\r
     Serial port: the serial TX/RX signals on FT2232HL and ESP32 are broken out to the two sides of JP11. By default, the two signals are connected with jumpers. To use the ESP32 module serial interface only, the jumpers may be removed and the module can be connected to another external serial device.\r
 SPI\r
-    SPI interface: the SPI interface connects to an external flash (PSRAM). To interface another SPI device, an extra CS signal is needed. If an ESP32-WROVER is being used, please note that the electrical level on the flash and SRAM is 1.8V.\r
+    SPI interface: the SPI interface connects to an external flash (PSRAM). To interface another SPI device, an extra CS signal is needed. The electrical level on the flash of this module is 1.8V. If an ESP-WROOM-32 is being used, please note that the electrical level on the flash of this module is 3.3V.\r
 CTS/RTS\r
     Serial port flow control signals: the pins are not connected to the circuitry by default. To enable them, respective pins of JP14 must be shorted with jumpers.\r
 JTAG\r
@@ -78,24 +70,23 @@ Boot
 USB\r
     USB interface. It functions as the power supply for the board and the communication interface between PC and ESP32 module.\r
 Power Select\r
-    Power supply selection interface: the ESP-WROVER-KIT can be powered through the USB interface or the 5V Input interface. The user can select the power supply with a jumper. More details can be found in section :ref:`esp-wrover-setup-options`, jumper header JP7.\r
+    Power supply selection interface: the ESP-WROVER-KIT can be powered through the USB interface or the 5V Input interface. The user can select the power supply with a jumper. More details can be found in section :ref:`esp-wrover-kit-setup-options`, jumper header JP7.\r
 Power Key\r
     Power on/off button: toggling to the right powers the board on; toggling to the left powers the board off.\r
 5V Input\r
     The 5V power supply interface is used as a backup power supply in case of full-load operation.\r
 LDO\r
-    NCP1117(1A). 5V-to-3.3V LDO. (There is an alternative pin-compatible LDO — LM317DCY, with an output current of up to 1.5A). NCP1117 can provide a maximum current of 1A. The LDO solutions are available with both fixed output voltage and variable output voltage. For details please refer to `ESP-WROVER-KIT schematic`_.\r
+    NCP1117(1A). 5V-to-3.3V LDO. (There is an alternative pin-compatible LDO — LM317DCY, with an output current of up to 1.5A). NCP1117 can provide a maximum current of 1A. The LDO solutions are available with both fixed output voltage and variable output voltage. For details please refer to `ESP-WROVER-KIT V3 schematic`_.\r
 Camera\r
     Camera interface: a standard OV7670 camera module is supported.\r
 RGB\r
     Red, green and blue (RGB) light emitting diodes (LEDs), which may be controlled by pulse width modulation (PWM).\r
 I/O\r
     All the pins on the ESP32 module are led out to the pin headers on the ESPWROVER-KIT. Users can program ESP32 to enable multiple functions such as PWM, ADC, DAC, I2C, I2S, SPI, etc.\r
-\r
 Micro SD Card\r
-    Micro SD card slot for data storage: when ESP32 enters the download mode, GPIO2 cannot be held high. However, a pull-up resistor is required on GPIO2 to enable the Micro SD Card. By default, GPIO2 and the pull-up resistor R153 are disconnected. To enable the SD Card, use jumpers on JP1 as shown in section :ref:`esp-wrover-setup-options`.\r
+    Micro SD card slot for data storage.\r
 LCD\r
-    ESP-WROVER-KIT supports mounting and interfacing a 3.2” SPI (standard 4-wire Serial Peripheral Interface) LCD, as shown on figure :ref:`esp-wrover-board-back`.\r
+    ESP-WROVER-KIT supports mounting and interfacing a 3.2” SPI (standard 4-wire Serial Peripheral Interface) LCD, as shown on figure :ref:`esp-wrover-kit-board-back`.\r
 \r
 .. figure:: ../_static/esp32-wrover-kit-layout-front.jpg\r
     :align: center\r
@@ -104,7 +95,7 @@ LCD
 \r
     ESP-WROVER-KIT board layout - front\r
 \r
-.. _esp-wrover-board-back:\r
+.. _esp-wrover-kit-board-back:\r
 \r
 .. figure:: ../_static/esp32-wrover-kit-layout-back.jpg\r
     :align: center\r
@@ -114,40 +105,188 @@ LCD
     ESP-WROVER-KIT board layout - back\r
 \r
 \r
-.. _esp-wrover-setup-options:\r
+.. _esp-wrover-kit-setup-options:\r
 \r
 Setup Options\r
 ^^^^^^^^^^^^^\r
 \r
 There are five jumper headers available to set up the board functionality. Typical options to select from are listed in table below.\r
 \r
-+--------+----------------------+-----------------------------------------------------------+\r
-| Header | Jumper Setting       | Description of Functionality                              |\r
-+--------+----------------------+-----------------------------------------------------------+\r
-|  JP1   | |jp1-both|           | Assert GPIO2 low during each download                     |\r
-|        |                      | (by jumping it to GPIO0)                                  |\r
-+--------+----------------------+-----------------------------------------------------------+\r
-|  JP1   | |jp1-sd_io2|         | Enable pull up for the Micro SD Card,                     |\r
-|        |                      | ESP-WROVER-KIT V2 only                                    |\r
-|        |                      |                                                           |\r
-|        |                      | **Note:**                                                 |\r
-|        |                      | No jumpers are needed for SD card function on the V3      |\r
-+--------+----------------------+-----------------------------------------------------------+\r
-|  JP7   | |jp7-ext_5v|         | Power ESP-WROVER-KIT board from an external               |\r
-|        |                      | power supply                                              |\r
-+--------+----------------------+-----------------------------------------------------------+\r
-|  JP7   | |jp7-usb_5v|         | Power ESP-WROVER-KIT board from an USB port               |\r
-+--------+----------------------+-----------------------------------------------------------+\r
-|  JP8   | |jp8|                | Enable JTAG functionality                                 |\r
-+--------+----------------------+-----------------------------------------------------------+\r
-|  JP11  | |jp11-rx-tx|         | Enable UART communication                                 |\r
-+--------+----------------------+-----------------------------------------------------------+\r
-|  JP14  | |jp14|               | Enable RTS/CTS flow control for serial                    |\r
-|        |                      | communication                                             |\r
-+--------+----------------------+-----------------------------------------------------------+\r
-\r
-\r
-.. _esp-wrover-start-development:\r
++--------+------------------+--------------------------------------------------+\r
+| Header | Jumper Setting   | Description of Functionality                     |\r
++--------+------------------+--------------------------------------------------+\r
+|  JP7   | |jp7-ext_5v|     | Power ESP-WROVER-KIT board from an external      |\r
+|        |                  | power supply                                     |\r
++--------+------------------+--------------------------------------------------+\r
+|  JP7   | |jp7-usb_5v|     | Power ESP-WROVER-KIT board from an USB port      |\r
++--------+------------------+--------------------------------------------------+\r
+|  JP8   | |jp8|            | Enable JTAG functionality                        |\r
++--------+------------------+--------------------------------------------------+\r
+|  JP11  | |jp11-rx-tx|     | Enable UART communication                        |\r
++--------+------------------+--------------------------------------------------+\r
+|  JP14  | |jp14|           | Enable RTS/CTS flow control for serial           |\r
+|        |                  | communication                                    |\r
++--------+------------------+--------------------------------------------------+\r
+\r
+\r
+Allocation of ESP32 Pins\r
+^^^^^^^^^^^^^^^^^^^^^^^^\r
+\r
+Several pins / terminals of ESP32 module are allocated to the on board hardware. Some of them, like GPIO0 or GPIO2, have multiple functions. If certain hardware is not installed, e.g. nothing is plugged in to the Camera / JP4 header, then selected GPIOs may be used for other purposes.\r
+\r
+\r
+32.768 kHz Oscillator\r
+"""""""""""""""""""""\r
+\r
++---+---------------+\r
+|   | ESP32 Pin     |\r
++===+===============+\r
+| 1 | GPIO32        |\r
++---+---------------+\r
+| 2 | GPIO33        |\r
++---+---------------+\r
+\r
+.. note::\r
+\r
+    As GPIO32 and GPIO33 are connected to the oscillator, to maintain signal integrity, they are not connected to JP1 I/O expansion connector. This allocation may be changed from oscillator to JP1 by desoldering 0R resistors from positions R11 / R23 and installing them in positions R12 / R24.\r
+\r
+\r
+SPI Flash / JP13\r
+""""""""""""""""\r
+\r
++---+---------------+\r
+|   | ESP32 Pin     |\r
++===+===============+\r
+| 1 | CLK / GPIO6   |\r
++---+---------------+\r
+| 2 | SD0 / GPIO7   |\r
++---+---------------+\r
+| 3 | SD1 / GPIO8   |\r
++---+---------------+\r
+| 4 | SD2 / GPIO9   |\r
++---+---------------+\r
+| 5 | SD3 / GPIO10  |\r
++---+---------------+\r
+| 6 | CMD / GPIO11  |\r
++---+---------------+\r
+\r
+\r
+JTAG / JP8\r
+""""""""""\r
+\r
++---+---------------+----------------+\r
+|   | ESP32 Pin     | JTAG Signal    |\r
++===+===============+================+\r
+| 1 | CHIP_PU       | TRST_N         |\r
++---+---------------+----------------+\r
+| 2 | MTDO / GPIO15 | TDO            |\r
++---+---------------+----------------+\r
+| 3 | MTDI / GPIO12 | TDI            |\r
++---+---------------+----------------+\r
+| 4 | MTCK / GPIO13 | TCK            |\r
++---+---------------+----------------+\r
+| 5 | MTMS / GPIO14 | TMS            |\r
++---+---------------+----------------+\r
+\r
+\r
+Camera / JP4\r
+""""""""""""\r
+\r
++----+--------------+----------------------+\r
+|    | ESP32 Pin    | Camera Signal        |\r
++====+==============+======================+\r
+|  1 | GPIO27       | SCCB Clock           |\r
++----+--------------+----------------------+\r
+|  2 | GPIO26       | SCCB Data            |\r
++----+--------------+----------------------+\r
+|  3 | GPIO21       | System Clock         |\r
++----+--------------+----------------------+\r
+|  4 | GPIO25       | Vertical Sync        |\r
++----+--------------+----------------------+\r
+|  5 | GPIO23       | Horizontal Reference |\r
++----+--------------+----------------------+\r
+|  6 | GPIO22       | Pixel Clock          |\r
++----+--------------+----------------------+\r
+|  7 | GPIO4        | Pixel Data Bit 0     |\r
++----+--------------+----------------------+\r
+|  8 | GPIO5        | Pixel Data Bit 1     |\r
++----+--------------+----------------------+\r
+|  9 | GPIO18       | Pixel Data Bit 2     |\r
++----+--------------+----------------------+\r
+| 10 | GPIO19       | Pixel Data Bit 3     |\r
++----+--------------+----------------------+\r
+| 11 | GPIO36       | Pixel Data Bit 4     |\r
++----+--------------+----------------------+\r
+| 11 | GPIO39       | Pixel Data Bit 5     |\r
++----+--------------+----------------------+\r
+| 11 | GPIO34       | Pixel Data Bit 6     |\r
++----+--------------+----------------------+\r
+| 11 | GPIO35       | Pixel Data Bit 7     |\r
++----+--------------+----------------------+\r
+| 11 | GPIO2        | Camera Reset         |\r
++----+--------------+----------------------+\r
+\r
+\r
+RGB LED\r
+"""""""\r
+\r
++---+---------------+----------------+\r
+|   | ESP32 Pin     | RGB LED        |\r
++===+===============+================+\r
+| 1 | GPIO0         | Red            |\r
++---+---------------+----------------+\r
+| 2 | GPIO2         | Blue           |\r
++---+---------------+----------------+\r
+| 3 | GPIO4         | Green          |\r
++---+---------------+----------------+\r
+\r
+\r
+MicroSD Card / J4\r
+"""""""""""""""""\r
+\r
++---+---------------+----------------+\r
+|   | ESP32 Pin     | MicroSD Signal |\r
++===+===============+================+\r
+| 1 | MTDI / GPIO12 | DATA2          |\r
++---+---------------+----------------+\r
+| 2 | MTCK / GPIO13 | CD / DATA3     |\r
++---+---------------+----------------+\r
+| 3 | MTDO / GPIO15 | CMD            |\r
++---+---------------+----------------+\r
+| 4 | MTMS / GPIO14 | CLK            |\r
++---+---------------+----------------+\r
+| 5 | GPIO2         | DATA0          |\r
++---+---------------+----------------+\r
+| 6 | GPIO4         | DATA1          |\r
++---+---------------+----------------+\r
+| 7 | GPIO21        | CD             |\r
++---+---------------+----------------+\r
+\r
+\r
+\r
+LCD / U5\r
+""""""""\r
+\r
++---+---------------+----------------+\r
+|   | ESP32 Pin     | LCD Signal     |\r
++===+===============+================+\r
+| 1 | GPIO18        | RESET          |\r
++---+---------------+----------------+\r
+| 2 | GPIO19        | SCL            |\r
++---+---------------+----------------+\r
+| 3 | GPIO21        | D/C            |\r
++---+---------------+----------------+\r
+| 4 | GPIO22        | CS             |\r
++---+---------------+----------------+\r
+| 5 | GPIO23        | SDA            |\r
++---+---------------+----------------+\r
+| 6 | GPIO25        | SDO            |\r
++---+---------------+----------------+\r
+| 7 | GPIO5         | Backlight      |\r
++---+---------------+----------------+\r
+\r
+\r
+.. _esp-wrover-kit-start-development:\r
 \r
 Start Application Development\r
 -----------------------------\r
@@ -181,16 +320,15 @@ To start development of applications for ESP-WROVER-KIT, proceed to section :doc
 * :ref:`get-started-build-monitor` instantly what the application is doing\r
 \r
 \r
-.. _wrover-kit-related-documents:\r
-\r
 Related Documents\r
 -----------------\r
 \r
-* `ESP-WROVER-KIT schematic`_ (PDF)\r
+* `ESP-WROVER-KIT V3 schematic`_ (PDF)\r
 * `ESP32 Datasheet <http://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf>`_ (PDF)\r
+* `ESP32-WROVER Datasheet <http://espressif.com/sites/default/files/documentation/esp32-wrover_datasheet_en.pdf>`_ (PDF)\r
 * `ESP-WROOM-32 Datasheet <http://espressif.com/sites/default/files/documentation/esp-wroom-32_datasheet_en.pdf>`_ (PDF)\r
 * :doc:`../api-guides/jtag-debugging/index`\r
-\r
+* :doc:`../hw-reference/modules-and-boards`\r
 \r
 \r
 .. |jp1-sd_io2| image:: ../_static/wrover-jp1-sd_io2.png\r
@@ -201,4 +339,4 @@ Related Documents
 .. |jp11-rx-tx| image:: ../_static/wrover-jp11-tx-rx.png\r
 .. |jp14| image:: ../_static/wrover-jp14.png\r
 \r
-.. _ESP-WROVER-KIT schematic: http://dl.espressif.com/dl/schematics/ESP-WROVER-KIT_SCH-3.pdf\r
+.. _ESP-WROVER-KIT V3 schematic: http://dl.espressif.com/dl/schematics/ESP-WROVER-KIT_SCH-3.pdf\r
index 33631269f4c8c384daa236e57029ea41e6fb2c92..fc1dfd540155e69691f92e65a992aa874e486b00 100644 (file)
@@ -1,3 +1,5 @@
+.. _esp-modules-and-boards:
+
 ESP32 Modules and Boards
 ========================
 
@@ -6,30 +8,56 @@ Espressif designed and manufactured several development modules and boards to he
 For details please refer to documentation below, provided together with description of particular boards.
 
 
+.. _esp-modules-and-boards-esp-wroom-32:
+
 ESP-WROOM-32
 ------------
 
 The smallest module intended for installation in final products. Can be also used for evaluation after adding extra components like programming interface, boot strapping resistors and break out headers.
 
-.. image:: http://dl.espressif.com/dl/schematics/pictures/esp-wroom-32.jpg
+.. figure:: http://dl.espressif.com/dl/schematics/pictures/esp-wroom-32.jpg
     :align: center
-    :width: 40%
     :alt: ESP-WROOM-32 module (front and back)
+    :width: 40%
+
+    ESP-WROOM-32 module (front and back)
 
 * `Schematic <http://dl.espressif.com/dl/schematics/ESP-WROOM-32-v3.2_sch.pdf>`__ (PDF)
 * `Datasheet <http://espressif.com/sites/default/files/documentation/esp-wroom-32_datasheet_en.pdf>`__ (PDF)
 * `ESP32 Module Reference Design <https://espressif.com/sites/default/files/documentation/esp32_module_reference_design.zip>`_ (ZIP) containing OrCAD schematic, PCB layout, gerbers and BOM
 
+
+.. _esp-modules-and-boards-esp32-wrover:
+
+ESP32-WROVER
+------------
+
+A step upgrade of ESP-WROOM-32 described above with an additional 4 MB SPI PSRAM (Pseudo static RAM). Module is provided in two versions: 'ESP32-WROVER' with PCB antenna (shown below) and 'ESP32-WROVER-I' with an IPEX antenna.
+
+.. figure:: http://dl.espressif.com/dl/schematics/pictures/esp32-wrover.jpg
+    :align: center
+    :alt: ESP32-WROVER module (front and back)
+    :width: 40%
+
+    ESP32-WROVER module (front and back)
+
+* `Datasheet <http://espressif.com/sites/default/files/documentation/esp32-wrover_datasheet_en.pdf>`__ (PDF)
+* `ESP-PSRAM32 Datasheet <http://espressif.com/sites/default/files/documentation/esp-psram32_datasheet_en.pdf>`__ (PDF)
+
+
+.. _esp-modules-and-boards-esp32-devkitc:
    
 ESP32 Core Board V2 / ESP32 DevKitC
 -----------------------------------
 
-Small and convenient development board with break out pin headers and minimum additional components. Includes USB to serial programming interface, that also provides power supply for the board. Has press buttons to reset the board and put it in upload mode. 
+Small and convenient development board with ESP-WROOM-32 module installed, break out pin headers and minimum additional components. Includes USB to serial programming interface, that also provides power supply for the board. Has press buttons to reset the board and put it in upload mode. 
 
-.. image:: http://dl.espressif.com/dl/schematics/pictures/esp32-core-board-v2.jpg
+.. figure:: http://dl.espressif.com/dl/schematics/pictures/esp32-core-board-v2.jpg
     :align: center
-    :width: 50%
     :alt: ESP32 Core Board V2 / ESP32 DevKitC board
+    :width: 50%
+
+    ESP32 Core Board V2 / ESP32 DevKitC board
 
 * `Schematic <http://dl.espressif.com/dl/schematics/ESP32-Core-Board-V2_sch.pdf>`__ (PDF)
 * `ESP32 Development Board Reference Design <https://espressif.com/sites/default/files/documentation/esp32_development_board_reference_design.zip>`_ (ZIP) containing OrCAD schematic, PCB layout, gerbers and BOM
@@ -37,64 +65,95 @@ Small and convenient development board with break out pin headers and minimum ad
 * `CP210x USB to UART Bridge VCP Drivers <http://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers>`_
 
 
+.. _esp-modules-and-boards-esp32-demo-board-v2:
+
 ESP32 Demo Board V2
 -------------------
 
 One of first feature rich evaluation boards that contains several pin headers, dip switches, USB to serial programming interface, reset and boot mode press buttons, power switch, 10 touch pads and separate header to connect LCD screen.
 
-.. image:: http://dl.espressif.com/dl/schematics/pictures/esp32-demo-board-v2.jpg
+.. figure:: http://dl.espressif.com/dl/schematics/pictures/esp32-demo-board-v2.jpg
     :align: center
-    :alt: ESP32 Demo Board V2 board
+    :alt: ESP32 Demo Board V2
+
+    ESP32 Demo Board V2
 
 * `Schematic <http://dl.espressif.com/dl/schematics/ESP32-Demo-Board-V2_sch.pdf>`__ (PDF)
 * `FTDI Virtual COM Port Drivers`_
 
 
-ESP32 WROVER KIT V1 / ESP32 DevKitJ V1
---------------------------------------
+.. _esp-modules-and-boards-esp-wrover-kit:
+
+ESP-WROVER-KIT
+--------------
+
+This section describes several revisions of ESP-WROVER-KIT development board.
+
+All versions of ESP-WROVER-KIT are ready to accommodate an :ref:`esp-modules-and-boards-esp-wroom-32` or :ref:`esp-modules-and-boards-esp32-wrover` module.
 
-Development board that has dual port USB to serial converter for programming and JTAG interface for debugging. Power supply is provided by USB interface or from standard 5 mm power supply jack. Power supply selection is done with a jumper and may be put on/off with a separate switch. Has SD card slot, 3.2” SPI LCD screen and dedicated header to connect a camera. Provides RGB diode for diagnostics. Also, includes 32.768 kHz XTAL for internal RTC to operate it in low power modes.
+ESP-WROVER-KIT has dual port USB to serial converter for programming and JTAG interface for debugging. Power supply is provided by USB interface or from standard 5 mm power supply jack. Power supply selection is done with a jumper and may be put on/off with a separate switch. The board has MicroSD card slot, 3.2” SPI LCD screen and dedicated header to connect a camera. It provides RGB diode for diagnostics. Includes 32.768 kHz XTAL for internal RTC to operate it in low power modes.
 
-.. image:: http://dl.espressif.com/dl/schematics/pictures/esp32-devkitj-v1.jpg
+
+.. _esp-modules-and-boards-esp-wrover-kit-v1:
+
+ESP-WROVER-KIT V1 / ESP32 DevKitJ V1
+""""""""""""""""""""""""""""""""""""
+
+First version of ESP-WROVER-KIT. Shipped with ESP-WROOM-32 on board.
+
+.. figure:: http://dl.espressif.com/dl/schematics/pictures/esp32-devkitj-v1.jpg
     :align: center
+    :alt: ESP-WROVER-KIT V1 / ESP32 DevKitJ V1 board
     :width: 90%
-    :alt: ESP32 WROVER KIT V1 / ESP32 DevKitJ V1 board
+
+    ESP-WROVER-KIT V1 / ESP32 DevKitJ V1 board
+
+The board has red soldermask.
 
 * `Schematic <http://dl.espressif.com/dl/schematics/ESP32-DevKitJ-v1_sch.pdf>`__ (PDF)
 * :doc:`../api-guides/jtag-debugging/index`
 * `FTDI Virtual COM Port Drivers`_
 
 
-ESP32 WROVER KIT V2
--------------------
+.. _esp-modules-and-boards-esp-wrover-kit-v2:
+
+ESP-WROVER-KIT V2
+"""""""""""""""""
 
-This is updated version of ESP32 DevKitJ V1 described above with design improvements identified when DevKitJ was in use.
+This is updated version of ESP32 DevKitJ V1 described above with design improvements identified when DevKitJ was in use, e.g. improved support for SD card. By default board has ESP-WROOM-32 module installed.
 
-.. image:: http://dl.espressif.com/dl/schematics/pictures/esp-wrover-kit-v2.jpg
+.. figure:: http://dl.espressif.com/dl/schematics/pictures/esp-wrover-kit-v2.jpg
    :align: center
+   :alt: ESP-WROVER-KIT V2 board
    :width: 90%
-   :alt: ESP32 WROVER KIT V2 board
+
+   ESP-WROVER-KIT V2 board
 
 Comparing to previous version, this board has a shiny black finish and a male camera header.
 
 * `Schematic V2 <http://dl.espressif.com/dl/schematics/ESP-WROVER-KIT_SCH-2.pdf>`__ (PDF)
+
+.. * :doc:`../get-started/get-started-wrover-kit-v2`
+
 * :doc:`../api-guides/jtag-debugging/index`
 * `FTDI Virtual COM Port Drivers`_
 
 
-ESP32 WROVER KIT V3
--------------------
+.. _esp-modules-and-boards-esp-wrover-kit-v3:
 
-This revision of ESP32 WROVER KIT introduced several changes to conditioning and interlocking of signals to the bootstrapping pins. A zero Ohm resistor (R166) has been addedd between WROVER/WROOM module and VDD33 net, which can be desoldered or replaced with a shunt resistor for current measurement. This should facilitate power consumption analysis in varius operation modes of ESP32. Refer to schematic - the changes are enclosed in green border. 
+ESP-WROVER-KIT V3
+"""""""""""""""""
 
-.. image:: http://dl.espressif.com/dl/schematics/pictures/esp-wrover-kit-v3.jpg
+The first release of ESP-WROVER-KIT shipped with ESP32-WROVER module installed by default. This release also introduced several design changes to conditioning and interlocking of signals to the bootstrapping pins. Also, a zero Ohm resistor (R166) has been added between WROVER/WROOM module and VDD33 net, which can be desoldered, or replaced with a shunt resistor, for current measurement. This is intended to facilitate power consumption analysis in various operation modes of ESP32. Refer to schematic - the changes are enclosed in green border. 
+
+.. figure:: http://dl.espressif.com/dl/schematics/pictures/esp-wrover-kit-v3.jpg
    :align: center
+   :alt: ESP-WROVER-KIT V3 board
    :width: 90%
-   :alt: ESP32 WROVER KIT V3 board
 
-The camera header has been changed from male back to female. The board soldermask is matte black.
+   ESP-WROVER-KIT V3 board
 
-All versions of ESP32 WROVER KIT are ready to accommodate an ESP-WROOM-32 or ESP32-WROVER module. On picture above ESP32-WROVER is installed.
+The camera header has been changed from male back to female. The board soldermask is matte black. The board on picture above has ESP32-WROVER is installed.
 
 * `Schematic V3 <http://dl.espressif.com/dl/schematics/ESP-WROVER-KIT_SCH-3.pdf>`__ (PDF)
 * :doc:`../get-started/get-started-wrover-kit`
@@ -103,4 +162,3 @@ All versions of ESP32 WROVER KIT are ready to accommodate an ESP-WROOM-32 or ESP
 
 
 .. _FTDI Virtual COM Port Drivers: http://www.ftdichip.com/Drivers/D2XX.htm
-
index 73429ba7cd61d645d2f63732e67b97555f3dac2b..3c54fef29b97914c97d7b2143a51da487b966a03 100644 (file)
@@ -1,6 +1,6 @@
 # This is a list of python packages used to generate documentation. This file is used with pip:
 # pip install -r requirements.txt
 #
-sphinx==1.5.6
+sphinx==1.6.3
 sphinx-rtd-theme
-breathe==4.6.0
+breathe==4.7.1
index 490d8683eca733e4b0b80168f7feaf48c27b8ab0..a1c58762a7488371a91e0ee66081181782bf23e4 100644 (file)
 #include "soc/sens_reg.h"
 
 static const char* TAG = "Touch pad";
+#define TOUCH_THRESH_NO_USE   (0)
+#define TOUCH_THRESH_PERCENT  (99)
 
 static bool s_pad_activated[TOUCH_PAD_MAX];
+static uint32_t s_pad_init_val[TOUCH_PAD_MAX];
 
 
 /*
   Read values sensed at all available touch pads.
-  Use half of read value as the threshold
+  Use 2 / 3 of read value as the threshold
   to trigger interrupt when the pad is touched.
   Note: this routine demonstrates a simple way
   to configure activation threshold for the touch pads.
@@ -32,9 +35,17 @@ static bool s_pad_activated[TOUCH_PAD_MAX];
 static void tp_example_set_thresholds(void)
 {
     uint16_t touch_value;
-    for (int i=0; i<TOUCH_PAD_MAX; i++) {
-        ESP_ERROR_CHECK(touch_pad_read(i, &touch_value));
-        ESP_ERROR_CHECK(touch_pad_config(i, touch_value/2));
+    //delay some time in order to make the filter work and get a initial value
+    vTaskDelay(500/portTICK_PERIOD_MS);
+
+    for (int i = 0; i<TOUCH_PAD_MAX; i++) {
+        //read filtered value
+        touch_pad_read_filtered(i, &touch_value);
+        s_pad_init_val[i] = touch_value;
+        ESP_LOGI(TAG, "test init touch val: %d\n", touch_value);
+        //set interrupt threshold.
+        ESP_ERROR_CHECK(touch_pad_set_thresh(i, touch_value * 2 / 3));
+
     }
 }
 
@@ -43,29 +54,69 @@ static void tp_example_set_thresholds(void)
   by reading a table updated by rtc_intr()
   If so, then print it out on a serial monitor.
   Clear related entry in the table afterwards
+
+  In interrupt mode, the table is updated in touch ISR.
+
+  In filter mode, we will compare the current filtered value with the initial one.
+  If the current filtered value is less than 99% of the initial value, we can
+  regard it as a 'touched' event.
+  When calling touch_pad_init, a timer will be started to run the filter.
+  This mode is designed for the situation that the pad is covered
+  by a 2-or-3-mm-thick medium, usually glass or plastic.
+  The difference caused by a 'touch' action could be very small, but we can still use
+  filter mode to detect a 'touch' event.
  */
 static void tp_example_read_task(void *pvParameter)
 {
     static int show_message;
+    int change_mode = 0;
+    int filter_mode = 0;
     while (1) {
-        for (int i=0; i<TOUCH_PAD_MAX; i++) {
-            if (s_pad_activated[i] == true) {
-                ESP_LOGI(TAG, "T%d activated!", i);
-                // Wait a while for the pad being released
-                vTaskDelay(200 / portTICK_PERIOD_MS);
-                // Clear information on pad activation
-                s_pad_activated[i] = false;
-                // Reset the counter triggering a message
-                // that application is running
-                show_message = 1;
+        if (filter_mode == 0) {
+            //interrupt mode, enable touch interrupt
+            touch_pad_intr_enable();
+            for (int i = 0; i < TOUCH_PAD_MAX; i++) {
+                if (s_pad_activated[i] == true) {
+                    ESP_LOGI(TAG, "T%d activated!", i);
+                    // Wait a while for the pad being released
+                    vTaskDelay(200 / portTICK_PERIOD_MS);
+                    // Clear information on pad activation
+                    s_pad_activated[i] = false;
+                    // Reset the counter triggering a message
+                    // that application is running
+                    show_message = 1;
+                }
+            }
+        } else {
+            //filter mode, disable touch interrupt
+            touch_pad_intr_disable();
+            for (int i = 0; i < TOUCH_PAD_MAX; i++) {
+                uint16_t value = 0;
+                touch_pad_read_filtered(i, &value);
+                if (value < s_pad_init_val[i] * TOUCH_THRESH_PERCENT / 100) {
+                    ESP_LOGI(TAG, "T%d activated!", i);
+                    ESP_LOGI(TAG, "value: %d; init val: %d\n", value, s_pad_init_val[i]);
+                    vTaskDelay(200 / portTICK_PERIOD_MS);
+                    // Reset the counter to stop changing mode.
+                    change_mode = 1;
+                    show_message = 1;
+                }
             }
         }
+
+        vTaskDelay(10 / portTICK_PERIOD_MS);
+
         // If no pad is touched, every couple of seconds, show a message
         // that application is running
         if (show_message++ % 500 == 0) {
             ESP_LOGI(TAG, "Waiting for any pad being touched...");
         }
-        vTaskDelay(10 / portTICK_PERIOD_MS);
+        // Change mode if no pad is touched for a long time.
+        // We can compare the two different mode.
+        if (change_mode++ % 2000 == 0) {
+            filter_mode = !filter_mode;
+            ESP_LOGI(TAG, "Change mode...%s\n", filter_mode == 0? "interrupt mode": "filter mode");
+        }
     }
 }
 
@@ -75,29 +126,51 @@ static void tp_example_read_task(void *pvParameter)
  */
 static void tp_example_rtc_intr(void * arg)
 {
-    uint32_t pad_intr = READ_PERI_REG(SENS_SAR_TOUCH_CTRL2_REG) & 0x3ff;
-    uint32_t rtc_intr = READ_PERI_REG(RTC_CNTL_INT_ST_REG);
+    uint32_t pad_intr = touch_pad_get_status();
     //clear interrupt
-    WRITE_PERI_REG(RTC_CNTL_INT_CLR_REG, rtc_intr);
-    SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN_CLR);
-
-    if (rtc_intr & RTC_CNTL_TOUCH_INT_ST) {
-        for (int i = 0; i < TOUCH_PAD_MAX; i++) {
-            if ((pad_intr >> i) & 0x01) {
-                s_pad_activated[i] = true;
-            }
+    touch_pad_clear_status();
+    for (int i = 0; i < TOUCH_PAD_MAX; i++) {
+        if ((pad_intr >> i) & 0x01) {
+            s_pad_activated[i] = true;
         }
     }
 }
 
+/*
+ * Before reading touch pad, we need to initialize the RTC IO.
+ */
+static void tp_example_touch_pad_init()
+{
+    for (int i = 0;i< TOUCH_PAD_MAX;i++) {
+        //init RTC IO and mode for touch pad.
+        touch_pad_config(i, TOUCH_THRESH_NO_USE);
+    }
+}
 
 void app_main()
 {
-    // Initialize touch pad peripheral
+    // Initialize touch pad peripheral, it will start a timer to run a filter
     ESP_LOGI(TAG, "Initializing touch pad");
     touch_pad_init();
+
+    // Initialize and start a software filter to detect slight change of capacitance.
+    touch_pad_filter_start(10);
+    // Set measuring time and sleep time
+    // In this case, measurement will sustain 0xffff / 8Mhz = 8.19ms
+    // Meanwhile, sleep time between two measurement will be 0x1000 / 150Khz = 27.3 ms
+    touch_pad_set_meas_time(0x1000, 0xffff);
+
+    //set reference voltage for charging/discharging
+    // In this case, the high reference valtage will be 2.4V - 1.5V = 0.9V
+    // The low reference voltage will be 0.8V, so that the procedure of charging
+    // and discharging would be very fast.
+    touch_pad_set_voltage(TOUCH_HVOLT_2V4, TOUCH_LVOLT_0V8, TOUCH_HVOLT_ATTEN_1V5);
+    // Init touch pad IO
+    tp_example_touch_pad_init();
+    // Set thresh hold
     tp_example_set_thresholds();
-    touch_pad_isr_handler_register(tp_example_rtc_intr, NULL, 0, NULL);
+    // Register touch interrupt ISR
+    touch_pad_isr_register(tp_example_rtc_intr, NULL);
 
     // Start a task to show what pads have been touched
     xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL);
index da7baa6baf74f8dc46207a57c10f17e189b52741..def1dacf075519ceb87a82a63d6af0cdf11945db 100644 (file)
@@ -9,24 +9,78 @@
 #include <stdio.h>\r
 #include "freertos/FreeRTOS.h"\r
 #include "freertos/task.h"\r
-\r
 #include "driver/touch_pad.h"\r
 \r
-\r
+#define TOUCH_TEST_LOOP_NUM   (10)\r
+#define TOUCH_PAD_NO_CHANGE   (-1)\r
+#define TOUCH_THRESH_NO_USE   (0)\r
 /*\r
   Read values sensed at all available touch pads.\r
 Print out values in a loop on a serial monitor.\r
+ Print out values in a loop on a serial monitor.\r
  */\r
 static void tp_example_read_task(void *pvParameter)\r
 {\r
     while (1) {\r
         uint16_t touch_value;\r
-        for (int i=0; i<TOUCH_PAD_MAX; i++) {\r
-            ESP_ERROR_CHECK(touch_pad_read(i, &touch_value));\r
-            printf("T%d:%4d ", i, touch_value);\r
+        //set reference voltage for charging/discharging\r
+        // In this case, the high reference valtage will be 2.7V - 0V = 2.7V\r
+        // The low reference voltage will be 0.5\r
+        // So the charing/discharging time would be longer, so the counter value would be smaller.\r
+        touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V);\r
+\r
+        vTaskDelay(100 / portTICK_PERIOD_MS);\r
+        printf("Case[1], set default measure time\n");\r
+        for (int j = 0; j < TOUCH_TEST_LOOP_NUM; j++) {\r
+            for (int i = 0; i < TOUCH_PAD_MAX; i++) {\r
+                ESP_ERROR_CHECK(touch_pad_read(i, &touch_value));\r
+                printf("T%d:%5d ", i, touch_value);\r
+            }\r
+            printf("\n");\r
+            vTaskDelay(500 / portTICK_PERIOD_MS);\r
+        }\r
+\r
+        printf("Case[2], set max measure time\n");\r
+        //set reference voltage for charging/discharging\r
+        // In this case, the high reference valtage will be 2.4V - 1.5V = 0.9V\r
+        // The low reference voltage will be 0.8\r
+        // So the charing/discharging time would be shorter, so the counter value would be larger.\r
+        touch_pad_set_voltage(TOUCH_HVOLT_2V4, TOUCH_LVOLT_0V8, TOUCH_HVOLT_ATTEN_1V5);\r
+        vTaskDelay(100 / portTICK_PERIOD_MS);\r
+        for (int j = 0; j < TOUCH_TEST_LOOP_NUM; j++) {\r
+            for (int i = 0; i < TOUCH_PAD_MAX; i++) {\r
+                ESP_ERROR_CHECK(touch_pad_read(i, &touch_value));\r
+                printf("T%d:%5d ", i, touch_value);\r
+            }\r
+            printf("\n");\r
+            vTaskDelay(500 / portTICK_PERIOD_MS);\r
         }\r
-        printf("\n");\r
-        vTaskDelay(500 / portTICK_PERIOD_MS);\r
+\r
+\r
+        touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V);\r
+        vTaskDelay(100/portTICK_PERIOD_MS);\r
+\r
+        printf("Case[3], set differen slope for each channel\n");\r
+        for (int i = 0;i<TOUCH_PAD_MAX;i++) {\r
+            touch_pad_set_cnt_mode(i, (i % TOUCH_PAD_SLOPE_7) + 1, TOUCH_PAD_TIE_OPT_HIGH);\r
+        }\r
+        for (int j = 0; j < TOUCH_TEST_LOOP_NUM; j++) {\r
+            for (int i = 0; i < TOUCH_PAD_MAX; i++) {\r
+                ESP_ERROR_CHECK(touch_pad_read(i, &touch_value));\r
+                printf("T%d:%5d ", i, touch_value);\r
+            }\r
+            printf("\n");\r
+            vTaskDelay(500 / portTICK_PERIOD_MS);\r
+        }\r
+        for (int i = 0;i<TOUCH_PAD_MAX;i++) {\r
+            touch_pad_set_cnt_mode(i, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_HIGH);\r
+        }\r
+    }\r
+}\r
+\r
+static void tp_example_touch_pad_init()\r
+{\r
+    for (int i = 0;i< TOUCH_PAD_MAX;i++) {\r
+        touch_pad_config(i, TOUCH_THRESH_NO_USE);\r
     }\r
 }\r
 \r
@@ -34,6 +88,7 @@ void app_main()
 {\r
     // Initialize touch pad peripheral\r
     touch_pad_init();\r
+    tp_example_touch_pad_init();\r
 \r
     // Start task to read values sensed by pads\r
     xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL);\r
diff --git a/examples/system/app_trace_to_host/Makefile b/examples/system/app_trace_to_host/Makefile
new file mode 100644 (file)
index 0000000..e0f7180
--- /dev/null
@@ -0,0 +1,9 @@
+#
+# This is a project Makefile. It is assumed the directory this Makefile resides in is a
+# project subdirectory.
+#
+
+PROJECT_NAME := app_trace_to_host_test
+
+include $(IDF_PATH)/make/project.mk
+
diff --git a/examples/system/app_trace_to_host/README.md b/examples/system/app_trace_to_host/README.md
new file mode 100644 (file)
index 0000000..b15466d
--- /dev/null
@@ -0,0 +1,177 @@
+# Example: Application Level Tracing - Logging to Host (app_trace_to_host)
+
+This test code shows how to perform high speed logging by redirecting the log messages to a host instead of UART.
+
+For description of [logging to a host](http://esp-idf.readthedocs.io/en/latest/api-guides/app_trace.html#logging-to-host) please refer to **ESP32 Programming Guide**, section **Application Level Tracing library**. The following example provides practical implementation of this functionality.
+
+
+## Use Case
+
+Debugging of time critical functions may not work as desired if log messages are sent though the UART port. Printing out the logs may considerably slow down tested function to the point where it will not operate as expected.
+
+Let's consider a case we are testing implementation of [zero level crossing](https://en.wikipedia.org/wiki/Zero_crossing) detection for a 50 Hz signal with ESP32's ADC. 
+
+We will start by checking if we can read ADC, what is the signal level and how many samples can be collected over 20 ms period by using a code snippet below:
+
+```
+int sampling_period = 20;
+int i = 0;
+uint32_t sampling_start =  esp_log_timestamp();  //this clock counts miliseconds
+do {
+    ESP_LOGI(TAG, "Sample:%d, Value:%d", ++i, adc1_get_voltage(ADC1_TEST_CHANNEL));
+} while (esp_log_timestamp() - sampling_start < sampling_period);
+```
+
+Above code is sampling ADC in a loop continuously for 20 ms of time to collect one full period of 50 Hz signal (use 17 ms for 60 Hz signal), and printing out results. If you run this code, result will be likely as below:
+
+```
+I (4309) example: Sample:1, Value:2224
+I (4309) example: Sample:2, Value:840
+I (4309) example: Sample:3, Value:3503
+I (4319) example: Sample:4, Value:27
+I (4319) example: Sample:5, Value:4095
+```
+
+As you see we were able to collect only five samples. This seems rather not adequate for zero crossing detection. 
+
+We can remove `ESP_LOGI()` line and sample much faster, but then will not be able to see the values. To see the values we would need to save them in the memory and print out later.
+
+Instead of saving samples to memory, a simple and compelling solution to this issue is sending logs to a host over a JTAG interface. This works much faster than with the UART. To do so, we need to redirect log messages to JTAG by calling the following function before `ESP_LOGx` line:
+
+```
+esp_log_set_vprintf(esp_apptrace_vprintf);
+```
+
+Once time critical messages are sent out, we can redirect `ESP_LOGx` back back to the UART by adding extra two lines of code. 
+
+```
+esp_log_set_vprintf(vprintf);
+esp_apptrace_flush(ESP_APPTRACE_DEST_TRAX, 100000);
+```
+
+Note command `esp_apptrace_flush()` used to empty buffer with pending messages to the host.
+
+If checking the log received by the host, we will see over 400 samples collected!
+
+```
+...
+I (59379) example: Sample:424, Value:298
+I (59379) example: Sample:425, Value:345
+I (59379) example: Sample:426, Value:386
+I (59379) example: Sample:427, Value:432
+I (61409) example: Sample:1, Value:2653
+```
+
+
+## Example in Action
+
+Check the full example code [app_trace_to_host](main/app_trace_to_host_test.c) that combines both tests above and runs them in a loop showing instantly the number of samples collected:
+
+```
+I (4289) example: Sampling ADC and sending data to the host...
+I (4309) example: Collected 427 samples in 20 ms.
+
+I (4309) example: Sampling ADC and sending data to the UART...
+I (4309) example: Sample:1, Value:2224
+I (4309) example: Sample:2, Value:840
+I (4309) example: Sample:3, Value:3503
+I (4319) example: Sample:4, Value:27
+I (4319) example: Sample:5, Value:4095
+I (4329) example: Collected 5 samples in 20 ms.
+```
+
+
+## Do it Yourself
+
+To run the example and retrieve the log from the host, do the following:
+
+1.  Connect JTAG interface to ESP32 board, power up both JTAG and ESP32. For details how to setup JTAG interface see [JTAG Debugging](http://esp-idf.readthedocs.io/en/latest/api-guides/jtag-debugging/index.html). 
+
+2.  [Run OpenOCD](http://esp-idf.readthedocs.io/en/latest/api-guides/jtag-debugging/index.html#run-openocd). If you are using the [binary distribution of OpenOCD](http://esp-idf.readthedocs.io/en/latest/api-guides/jtag-debugging/index.html#jtag-debugging-setup-openocd) and one of versions of [ESP-WROVER-KIT](http://esp-idf.readthedocs.io/en/latest/hw-reference/modules-and-boards.html#esp32-wrover-kit-v1-esp32-devkitj-v1), respective command line will look as follows:
+
+    ```
+    cd ~/esp/openocd-esp32
+    bin/openocd -s share/openocd/scripts -f interface/ftdi/esp32_devkitj_v1.cfg -f board/esp-wroom-32.cfg
+    ```
+
+3.  Compile and load the example. Note to enable application tracing in menuconfig by going to `Component config > Application Level Tracing` and selecting `(X) Trace memory` 
+
+4.  Connect 50 Hz sinusoidal signal to ADC1_CHANNEL_6 / GPIO34. The signal range should be from 0V to max 3.1V. Optionally bridge GPIO34 with DAC_CHANNEL_1 / GPIO25, that generates 130 Hz signal within 0V..3.1V. To get 50 Hz, you need to set non standard divider of RTC 8 MHz clock to lower the minimum CW (Cosine Waveform) generator's frequency. You can do it in menuconfig by going to `Component config > Example configuration > Set custom RTC 8 MHz clock divider to lower CW frequency`.
+
+5.  Open a separate terminal window and run telnet by entering:
+
+    ```
+    telnet localhost 4444
+    ``` 
+
+6.  In telnet execute the following command:
+
+    ```
+    esp32 apptrace start file://adc0.log file://adc1.log 0 9000 5 0 0
+    ```
+
+    This command should collect 9000 bytes of log data and save them to `adc0.log` file in `~/esp/openocd-esp32` folder. The `adc1.log` file will be empty / is not used.
+
+7.  Decode and print out retrieved log file by executing:
+
+    ```
+    $IDF_PATH/tools/esp_app_trace/logtrace_proc.py ~/esp/openocd-esp32/adc0.log ~/esp/app_trace_to_host/build/app_trace_to_host_test.elf
+    ```
+
+    This should provide a similar output:
+
+    ```
+    Parse trace file '/user-home/esp/openocd-esp32/adc0.log'...
+    Unprocessed 7 bytes of log record args!
+    Parsing completed.
+    ====================================================================
+    I (59369) example: Sample:1, Value:3717
+    I (59369) example: Sample:2, Value:3647
+    I (59369) example: Sample:3, Value:3575
+    I (59369) example: Sample:4, Value:3491
+    ...
+
+    I (59379) example: Sample:398, Value:78
+    I (59379) example: Sample:399, Value:58
+    I (59379) example: Sample:400, Value:22
+    I (59379) example: Sample:401, Value:14
+    I (59379) example: Sample:402, Value:0
+    I (59379) example: Sample:403, Value:0
+    I (59379) example: Sample:404, Value:0
+    I (59379) example: Sample:405, Value:0
+    I (59379) example: Sample:406, Value:0
+    I (59379) example: Sample:407, Value:0
+    I (59379) example: Sample:408, Value:0
+    I (59379) example: Sample:409, Value:0
+    I (59379) example: Sample:410, Value:0
+    I (59379) example: Sample:411, Value:0
+    I (59379) example: Sample:412, Value:0
+    I (59379) example: Sample:413, Value:0
+    I (59379) example: Sample:414, Value:16
+    I (59379) example: Sample:415, Value:32
+    I (59379) example: Sample:416, Value:40
+    I (59379) example: Sample:417, Value:74
+    I (59379) example: Sample:418, Value:89
+    I (59379) example: Sample:419, Value:113
+    I (59379) example: Sample:420, Value:160
+    I (59379) example: Sample:421, Value:192
+    I (59379) example: Sample:422, Value:221
+    I (59379) example: Sample:423, Value:256
+    I (59379) example: Sample:424, Value:298
+    I (59379) example: Sample:425, Value:345
+    I (59379) example: Sample:426, Value:386
+    I (59379) example: Sample:427, Value:432
+    I (61409) example: Sample:1, Value:2653
+
+    ====================================================================
+
+    Log records count: 428
+    ```
+
+This is the log we have been looking for, complete with timestamps as if printed to UART, but almost two orders of magnitude faster.
+
+
+## Conclusion
+
+With this example code we have demonstrated powerful functionality of logging to host with JTAG interface. With standard UART communication speed setting of 115200 BPS, printing out a single line of a log message takes about 4 ms. This is also the maximum period we can sequentially execute other tasks in between. By providing the same logging over JTAG, we were able improve performance of this process over 80 times.
+
diff --git a/examples/system/app_trace_to_host/main/Kconfig.projbuild b/examples/system/app_trace_to_host/main/Kconfig.projbuild
new file mode 100644 (file)
index 0000000..777a3ec
--- /dev/null
@@ -0,0 +1,20 @@
+menu "Example Configuration"
+
+config CUSTOM_RTC_CLK_8M_DIV
+   bool "Set custom RTC 8 MHz clock divider to lower CW frequency (CHECK HELP FIRST)"
+   default "n"
+   help
+       Set custom / non standard divider for RTC 8 MHz clock.
+       This is to lower minimum frequency of cosine waveform generator (CW)
+       in order to provide sinusoidal signal at about 50 or 60 Hz.
+       
+       WARNINIG: setting non standard divider for the RTC 8 MHz clock
+       will affect functionality of RTC peripherals other than CW.
+
+       This includes ADC sampling, and will in general make
+       all RTC register access slower. 
+
+       DO NOT use this option / change default RTC 8 MHz clock divider
+       in your applications, if you are not sure what you are doing.
+
+endmenu
diff --git a/examples/system/app_trace_to_host/main/app_trace_to_host_test.c b/examples/system/app_trace_to_host/main/app_trace_to_host_test.c
new file mode 100644 (file)
index 0000000..d0b8df8
--- /dev/null
@@ -0,0 +1,140 @@
+/* Application Trace to Host Example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "freertos/queue.h"
+
+#include "driver/gpio.h"
+#include "driver/adc.h"
+#include "esp_log.h"
+#include "esp_app_trace.h"
+
+#include "soc/rtc_io_reg.h"
+#include "soc/rtc_cntl_reg.h"
+#include "soc/sens_reg.h"
+#include "soc/rtc.h"
+
+#include "driver/dac.h"
+
+
+#define ADC1_TEST_CHANNEL (ADC1_CHANNEL_6)
+#define TEST_SAMPLING_PERIOD 20
+
+/*
+ * When setting custom divider of RTC 8 MHz clock in menuconfig,
+ * use the following values to set the CW frequency:
+ * ~ 50 Hz (entered below)
+ *     RTC_CLK_8M_DIV 7
+ *     CW_FREQUENCY_STEP 3
+ * ~ 60 Hz
+ *     RTC_CLK_8M_DIV 1
+ *     CW_FREQUENCY_STEP 1
+ */
+#ifdef CONFIG_CUSTOM_RTC_CLK_8M_DIV
+#define RTC_CLK_8M_DIV 7
+#define CW_FREQUENCY_STEP 3
+#else
+#define CW_FREQUENCY_STEP 1
+#endif
+
+static const char *TAG = "example";
+
+
+/*
+ * Enable cosine waveform generator (CW)
+ * on channel 1 / GPIO25 to provide sinusoidal signal
+ * It can be used instead of a live signal for testing
+ * of speed of logging to the host
+ * sequentially with data retrieval from ADC
+ */
+void enable_cosine_generator(void)
+{
+    // Enable tone generator common to both DAC channels 1 and 2
+    SET_PERI_REG_MASK(SENS_SAR_DAC_CTRL1_REG, SENS_SW_TONE_EN);
+    // Enable / connect tone tone generator on / to channel 1
+    SET_PERI_REG_MASK(SENS_SAR_DAC_CTRL2_REG, SENS_DAC_CW_EN1_M);
+    // Invert MSB, otherwise part of the waveform will be inverted
+    SET_PERI_REG_BITS(SENS_SAR_DAC_CTRL2_REG, SENS_DAC_INV1, 2, SENS_DAC_INV1_S);
+    // Set the frequency of waveform on CW output
+#ifdef CONFIG_CUSTOM_RTC_CLK_8M_DIV
+    REG_SET_FIELD(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_CK8M_DIV_SEL, RTC_CLK_8M_DIV);
+    ESP_LOGI(TAG, "Custom divider of RTC 8 MHz clock has been set.");
+#endif
+    SET_PERI_REG_BITS(SENS_SAR_DAC_CTRL1_REG, SENS_SW_FSTEP, CW_FREQUENCY_STEP, SENS_SW_FSTEP_S);
+
+    dac_output_enable(DAC_CHANNEL_1);
+}
+
+
+/*
+ * Sample data an ADC1 channel 6 / GPIO34
+ * over specific 'sampling_period' in milliseconds.
+ * Print out sampling result using standard ESP_LOGI() function.
+ * Return the number of samples collected.
+ */
+int adc1_sample_and_show(int sampling_period)
+{
+    int i = 0;
+    uint32_t sampling_start =  esp_log_timestamp();
+    do {
+        ESP_LOGI(TAG, "Sample:%d, Value:%d", ++i, adc1_get_voltage(ADC1_TEST_CHANNEL));
+    } while (esp_log_timestamp() - sampling_start < sampling_period);
+    return i;
+}
+
+
+/*
+ * Main program loop that is sampling data on ADC
+ * and logging results with application tracing to the host
+ * as well as for comparison printing out sampling result to UART
+ */
+void test_task(void *arg)
+{
+    ESP_LOGI(TAG, "Enabling ADC1 on channel 6 / GPIO34.");
+    adc1_config_width(ADC_WIDTH_12Bit);
+    adc1_config_channel_atten(ADC1_TEST_CHANNEL, ADC_ATTEN_11db);
+
+    ESP_LOGI(TAG, "Enabling CW generator on DAC channel 1 / GPIO25.");
+    enable_cosine_generator();
+
+    while (1) {
+
+        /*
+         * Test of Logging with the Application Trace
+         */
+        ESP_LOGI(TAG, "Sampling ADC and sending data to the host...");
+        // Route LOGx() to the host
+        esp_log_set_vprintf(esp_apptrace_vprintf);
+        int samples_collected = adc1_sample_and_show(TEST_SAMPLING_PERIOD);
+        // Route LOGx() back to UART
+        esp_log_set_vprintf(vprintf);
+        // Flush collected data to the host
+        esp_apptrace_flush(ESP_APPTRACE_DEST_TRAX, 100000);
+        ESP_LOGI(TAG, "Collected %d samples in %d ms.\n", samples_collected, TEST_SAMPLING_PERIOD);
+
+        /*
+         * Test of Logging to UART
+         */
+        ESP_LOGI(TAG, "Sampling ADC and sending data to the UART...");
+        samples_collected = adc1_sample_and_show(TEST_SAMPLING_PERIOD);
+        ESP_LOGI(TAG, "Collected %d samples in %d ms.\n", samples_collected, TEST_SAMPLING_PERIOD);
+
+        vTaskDelay(2000 / portTICK_PERIOD_MS);
+    }
+}
+
+
+void app_main()
+{
+    xTaskCreate(test_task, "test_task", 1024 * 3, NULL, 10, NULL);
+}
diff --git a/examples/system/app_trace_to_host/main/component.mk b/examples/system/app_trace_to_host/main/component.mk
new file mode 100644 (file)
index 0000000..44bd2b5
--- /dev/null
@@ -0,0 +1,3 @@
+#
+# Main Makefile. This is basically the same as a component makefile.
+#
diff --git a/examples/system/app_trace_to_host/sdkconfig.defaults b/examples/system/app_trace_to_host/sdkconfig.defaults
new file mode 100644 (file)
index 0000000..e20d2b7
--- /dev/null
@@ -0,0 +1,5 @@
+# Enable application tracing by default
+CONFIG_ESP32_APPTRACE_DEST_TRAX=y
+CONFIG_ESP32_APPTRACE_ENABLE=y
+# Disable WiFi stack by default
+CONFIG_WIFI_ENABLED=n
\ No newline at end of file
index 03d79d26bc99cc8786467e3dad5731264d84b494..9ee114fc67a11809fe06c19238516f37288220fb 100644 (file)
@@ -107,7 +107,7 @@ static void unity_run_single_test_by_name(const char* filter)
     tmp[strlen(filter) - 2] = 0;
     for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
     {
-        if (strstr(test->name, tmp) != NULL)
+        if (strcmp(test->name, tmp) == 0)
         {
             unity_run_single_test(test);
         }