From 28011a3993e6d2cb638e6e246bc89fbffc59a1b9 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Thu, 27 Oct 2022 08:02:45 +1100 Subject: [PATCH] Organising a bit --- source/Core/BSP/Pinecilv2/ble.c | 58 +-- source/Core/BSP/Pinecilv2/ble.h | 23 ++ .../Core/BSP/Pinecilv2/ble_characteristics.h | 33 ++ source/Core/BSP/Pinecilv2/ble_peripheral.c | 249 +++++++++++++ source/Core/BSP/Pinecilv2/ble_peripheral.h | 36 ++ .../BSP/Pinecilv2/ble_peripheral_tp_server.c | 352 ------------------ .../BSP/Pinecilv2/ble_peripheral_tp_server.h | 38 -- source/Core/BSP/Pinecilv2/postRTOS.cpp | 6 +- 8 files changed, 349 insertions(+), 446 deletions(-) create mode 100644 source/Core/BSP/Pinecilv2/ble.h create mode 100644 source/Core/BSP/Pinecilv2/ble_characteristics.h create mode 100644 source/Core/BSP/Pinecilv2/ble_peripheral.c create mode 100644 source/Core/BSP/Pinecilv2/ble_peripheral.h delete mode 100644 source/Core/BSP/Pinecilv2/ble_peripheral_tp_server.c delete mode 100644 source/Core/BSP/Pinecilv2/ble_peripheral_tp_server.h diff --git a/source/Core/BSP/Pinecilv2/ble.c b/source/Core/BSP/Pinecilv2/ble.c index 833a6692..b8b3f5c1 100644 --- a/source/Core/BSP/Pinecilv2/ble.c +++ b/source/Core/BSP/Pinecilv2/ble.c @@ -1,14 +1,3 @@ -/**************************************************************************** -FILE NAME - ble_peripheral_tp_server.c - -DESCRIPTION - test profile demo - -NOTES -*/ -/****************************************************************************/ - #include #include #include @@ -21,62 +10,27 @@ NOTES #include "gatt.h" #include "hci_core.h" #include "uuid.h" -#include "ble_peripheral_tp_server.h" +#include "ble_peripheral.h" #include "log.h" #include "bl702_glb.h" +#include "ble_characteristics.h" +#include "hal_clock.h" +#include "ble.h" -int ble_start_adv(void) -{ - struct bt_le_adv_param adv_param = { - //options:3, connectable undirected, adv one time - .options = 3, - .interval_min = BT_GAP_ADV_FAST_INT_MIN_3, - .interval_max = BT_GAP_ADV_FAST_INT_MAX_3, - }; - - char *adv_name = "BL_TEST_01"; // This name must be the same as adv_name in ble_central - struct bt_data adv_data[2] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL)), - BT_DATA(BT_DATA_NAME_COMPLETE, adv_name, strlen(adv_name)), - }; - - return bt_le_adv_start(&adv_param, adv_data, ARRAY_SIZE(adv_data), &adv_data[1], 1); -} - - -void bt_enable_cb(int err) -{ - MSG("[OS] bt_enable_cb...\r\n"); - MSG("[OS] ble_tp_init...\r\n"); - ble_tp_init(); - MSG("[OS] ble_tp_init...Done\r\n"); - - MSG("[OS] ble_start_adv...\r\n"); - ble_start_adv(); - MSG("[OS] ble_start_adv...Done\r\n"); -} - - - void ble_stack_start(void) { - MSG("[OS] ble_stack_start...\r\n"); + MSG("BLE Starting\n"); GLB_Set_EM_Sel(GLB_EM_8KB); - MSG("[OS] ble_controller_init...\r\n"); ble_controller_init(configMAX_PRIORITIES - 1); - MSG("[OS] ble_controller_init...Done\r\n"); // // Initialize BLE Host stack - MSG("[OS] hci_driver_init...\r\n"); hci_driver_init(); - MSG("[OS] hci_driver_init...Done\r\n"); - MSG("[OS] bt_enable...\r\n"); bt_enable(bt_enable_cb); - MSG("[OS] bt_enable...Done\r\n"); + MSG("BLE Starting...Done\n"); } diff --git a/source/Core/BSP/Pinecilv2/ble.h b/source/Core/BSP/Pinecilv2/ble.h new file mode 100644 index 00000000..8f5355bc --- /dev/null +++ b/source/Core/BSP/Pinecilv2/ble.h @@ -0,0 +1,23 @@ +#ifndef PINECILV2_BLE_H_ +#define PINECILV2_BLE_H_ + +/* + * BLE Interface for the Pinecil V2 + * + * Exposes: + * - Live Measurements + * - Device Settings Names + * - Device Settings Values + */ +#ifdef __cplusplus +extern "C" { +#endif + +// Spawns the BLE stack tasks and makes the device available to be connected to via BLE. +void ble_stack_start(void); + +#ifdef __cplusplus +}; +#endif + +#endif \ No newline at end of file diff --git a/source/Core/BSP/Pinecilv2/ble_characteristics.h b/source/Core/BSP/Pinecilv2/ble_characteristics.h new file mode 100644 index 00000000..63344680 --- /dev/null +++ b/source/Core/BSP/Pinecilv2/ble_characteristics.h @@ -0,0 +1,33 @@ +#ifndef BLE_CHARACTERISTICS_H_ +#define BLE_CHARACTERISTICS_H_ + +#include "ble_config.h" + +/* + + Pinecil exposes two main services; Status and settings + + Status: + - Current setpoint temperature + - Current live tip temperature + - Current DC Input + - Current Handle cold junction temperature + - Current power level (aka pwm level) + + Settings: + - One entry for every setting in the unit +*/ + +// d85efab4-168e-4a71-affd-33e27f9bc533 +#define BT_UUID_SVC_LIVE_DATA BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0xd85efab4, 0x168e, 0x4a71, 0xaffd, 0x33e27f9bc533)) +// f6d75f91-5a10-4eba-a233-47d3f26a907f +#define BT_UUID_SVC_SETTINGS_DATA BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0xf6d75f91, 0x5a10, 0x4eba, 0xa233, 0x47d3f26a907f)) + +#define BT_UUID_CHAR_BLE_LIVE_SETPOINT_TEMP BT_UUID_DECLARE_16(0x0001) +#define BT_UUID_CHAR_BLE_LIVE_LIVE_TEMP BT_UUID_DECLARE_16(0x0002) +#define BT_UUID_CHAR_BLE_LIVE_DC_INPUT BT_UUID_DECLARE_16(0x0003) +#define BT_UUID_CHAR_BLE_LIVE_HANDLE_TEMP BT_UUID_DECLARE_16(0x0004) +#define BT_UUID_CHAR_BLE_LIVE_POWER_LEVEL BT_UUID_DECLARE_16(0x0005) +#define BT_UUID_CHAR_BLE_LIVE_POWER_SRC BT_UUID_DECLARE_16(0x0006) + +#endif \ No newline at end of file diff --git a/source/Core/BSP/Pinecilv2/ble_peripheral.c b/source/Core/BSP/Pinecilv2/ble_peripheral.c new file mode 100644 index 00000000..35370d8a --- /dev/null +++ b/source/Core/BSP/Pinecilv2/ble_peripheral.c @@ -0,0 +1,249 @@ +/**************************************************************************** +FILE NAME + ble_peripheral_tp_server.c + +DESCRIPTION + test profile demo + +NOTES +*/ +/****************************************************************************/ + +#include +#include +#include +#include +#include +#include "ble_characteristics.h" +#include "bluetooth.h" +#include "conn.h" +#include "gatt.h" +#include "hci_core.h" +#include "uuid.h" +#include "ble_peripheral.h" +#include "log.h" +#include "hal_clock.h" + +bool pds_start; + +static void ble_device_connected(struct bt_conn *conn, u8_t err); +static void ble_device_disconnected(struct bt_conn *conn, u8_t reason); +static void ble_connection_param_changed(struct bt_conn *conn, u16_t interval, u16_t latency, u16_t timeout); + +static struct bt_conn *ble_tp_conn; +static struct bt_gatt_exchange_params exchg_mtu; +static TaskHandle_t ble_tp_task_h; +static int tx_mtu_size = 20; +static u8_t created_tp_task = 0; + +static struct bt_conn_cb ble_tp_conn_callbacks = { + .connected = ble_device_connected, + .disconnected = ble_device_disconnected, + .le_param_updated = ble_connection_param_changed, +}; + +/************************************************************************* +NAME + ble_tx_mtu_change_callback +*/ +static void ble_tx_mtu_change_callback(struct bt_conn *conn, u8_t err, + struct bt_gatt_exchange_params *params) +{ + if (!err) { + tx_mtu_size = bt_gatt_get_mtu(ble_tp_conn); + BT_WARN("ble tp echange mtu size success, mtu size: %d", tx_mtu_size); + } else { + BT_WARN("ble tp echange mtu size failure, err: %d", err); + } +} +/************************************************************************* +NAME + ble_device_connected +*/ +static void ble_device_connected(struct bt_conn *conn, u8_t err) +{ + int tx_octets = 0x00fb; + int tx_time = 0x0848; + int ret = -1; + + if (err) { + return; + } + + BT_INFO("BLE connected"); + ble_tp_conn = conn; + pds_start = false; + + //set data length after connected. + ret = bt_le_set_data_len(ble_tp_conn, tx_octets, tx_time); + + if (!ret) { + BT_INFO("ble tp set data length success"); + } else { + BT_WARN("ble tp set data length failure, err: %d", ret); + } + + //exchange mtu size after connected. + exchg_mtu.func = ble_tx_mtu_change_callback; + ret = bt_gatt_exchange_mtu(ble_tp_conn, &exchg_mtu); + + if (!ret) { + BT_INFO("ble tp exchange mtu size pending"); + } else { + BT_WARN("ble tp exchange mtu size failure, err: %d", ret); + } +} + +/************************************************************************* +NAME + ble_device_disconnected +*/ +static void ble_device_disconnected(struct bt_conn *conn, u8_t reason) +{ + BT_WARN("Tp disconnected"); + + if (created_tp_task) { + BT_WARN("Delete throughput tx task"); + vTaskDelete(ble_tp_task_h); + created_tp_task = 0; + } + + ble_tp_conn = NULL; + extern int ble_start_adv(void); + ble_start_adv(); + pds_start = true; +} + +/************************************************************************* +NAME + ble_connection_param_changed +*/ + +static void ble_connection_param_changed(struct bt_conn *conn, u16_t interval, + u16_t latency, u16_t timeout) +{ + BT_INFO("LE conn param updated: int 0x%04x lat %d to %d \r\n", interval, latency, timeout); +} + +/************************************************************************* +NAME + ble_tp_recv_rd +*/ +static int ble_tp_recv_rd(struct bt_conn *conn, const struct bt_gatt_attr *attr, + void *buf, u16_t len, u16_t offset) +{ + int size = 9; + char data[9] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; + + memcpy(buf, data, size); + + return size; +} + +/************************************************************************* +NAME + ble_tp_recv_wr(receive data from client) +*/ +static int ble_tp_recv_wr(struct bt_conn *conn, const struct bt_gatt_attr *attr, + const void *buf, u16_t len, u16_t offset, u8_t flags) +{ + BT_WARN("recv data len=%d, offset=%d, flag=%d", len, offset, flags); + BT_WARN("recv data:%s", bt_hex(buf, len)); + + if (flags & BT_GATT_WRITE_FLAG_PREPARE) { + //Don't use prepare write data, execute write will upload data again. + BT_WARN("recv prepare write request"); + return 0; + } + + if (flags & BT_GATT_WRITE_FLAG_CMD) { + //Use write command data. + BT_WARN("recv write command"); + } else { + //Use write request / execute write data. + BT_WARN("recv write request / exce write"); + } + + return len; +} + + +/************************************************************************* +NAME + ble_tp_ind_ccc_changed +*/ +static void ble_tp_ind_ccc_changed(const struct bt_gatt_attr *attr, u16_t value) +{ + int err = -1; + char data[9] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; + + if (value == BT_GATT_CCC_INDICATE) { + err = bl_tp_send_indicate(ble_tp_conn, get_attr(BT_CHAR_BLE_TP_IND_ATTR_VAL_INDEX), data, 9); + BT_WARN("ble tp send indicate: %d", err); + } +} + + +/************************************************************************* +* DEFINE : attrs +*/ +static struct bt_gatt_attr attrs[] = { + BT_GATT_PRIMARY_SERVICE(BT_UUID_SVC_LIVE_DATA), + + BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_LIVE_SETPOINT_TEMP, + BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, + ble_tp_recv_rd, + NULL, + NULL), + + + + +}; + +/************************************************************************* +NAME + get_attr +*/ +struct bt_gatt_attr *get_attr(u8_t index) +{ + return &attrs[index]; +} + +static struct bt_gatt_service ble_tp_server = BT_GATT_SERVICE(attrs); + + + +const char* DEVICE_BLE_NAME="Pinecil"; + +//Start advertising with expected default values +int ble_start_adv(void) +{ + MSG("BLE Starting advertising\n"); + struct bt_le_adv_param adv_param = { + //options:3, connectable undirected, adv one time + .options = 3, + .interval_min = BT_GAP_ADV_FAST_INT_MIN_3, + .interval_max = BT_GAP_ADV_FAST_INT_MAX_3, + }; + + struct bt_data adv_data[2] = { + BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL)), + BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_BLE_NAME, strlen(DEVICE_BLE_NAME)), + }; + + return bt_le_adv_start(&adv_param, adv_data, ARRAY_SIZE(adv_data), &adv_data[1], 1); +} + + + +// Callback that the ble stack will call once it has been kicked off running +// We use this to register the handlers (as we know its now ready for them) + start advertising to the world +void bt_enable_cb(int err) +{ + bt_conn_cb_register(&ble_tp_conn_callbacks); + bt_gatt_service_register(&ble_tp_server); + + ble_start_adv(); +} \ No newline at end of file diff --git a/source/Core/BSP/Pinecilv2/ble_peripheral.h b/source/Core/BSP/Pinecilv2/ble_peripheral.h new file mode 100644 index 00000000..5e0ce502 --- /dev/null +++ b/source/Core/BSP/Pinecilv2/ble_peripheral.h @@ -0,0 +1,36 @@ +/**************************************************************************** +FILE NAME + ble_peripheral_tp_server.h + +DESCRIPTION +NOTES +*/ +/****************************************************************************/ + +#ifndef _BLE_TP_SVC_H_ +#define _BLE_TP_SVC_H_ + +#include "ble_config.h" + + +//read value handle offset 2 +#define BT_CHAR_BLE_TP_RD_ATTR_VAL_INDEX (2) +//write value handle offset 4 +#define BT_CHAR_BLE_TP_WR_ATTR_VAL_INDEX (4) +//indicate value handle offset 6 +#define BT_CHAR_BLE_TP_IND_ATTR_VAL_INDEX (6) +//notity value handle offset 9 +#define BT_CHAR_BLE_TP_NOT_ATTR_VAL_INDEX (9) +#ifdef __cplusplus +extern "C" { +#endif + +void ble_tp_init(); +void bt_enable_cb(int err); +struct bt_gatt_attr *get_attr(u8_t index); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/source/Core/BSP/Pinecilv2/ble_peripheral_tp_server.c b/source/Core/BSP/Pinecilv2/ble_peripheral_tp_server.c deleted file mode 100644 index 4554fa2d..00000000 --- a/source/Core/BSP/Pinecilv2/ble_peripheral_tp_server.c +++ /dev/null @@ -1,352 +0,0 @@ -/**************************************************************************** -FILE NAME - ble_peripheral_tp_server.c - -DESCRIPTION - test profile demo - -NOTES -*/ -/****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "bluetooth.h" -#include "conn.h" -#include "gatt.h" -#include "hci_core.h" -#include "uuid.h" -#include "ble_peripheral_tp_server.h" -#include "log.h" -#include "hal_clock.h" - - bool pds_start; - -static void ble_tp_connected(struct bt_conn *conn, u8_t err); -static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason); -static void ble_param_updated(struct bt_conn *conn, u16_t interval, u16_t latency, u16_t timeout); - -static struct bt_conn *ble_tp_conn; -#if !defined(CONFIG_BT_OAD_SERVER) -static struct bt_gatt_exchange_params exchg_mtu; -#endif -static TaskHandle_t ble_tp_task_h; - -static struct k_sem notify_poll_sem; - -static int tx_mtu_size = 20; -static u8_t created_tp_task = 0; -static u8_t isRegister = 0; - -static struct bt_conn_cb ble_tp_conn_callbacks = { - .connected = ble_tp_connected, - .disconnected = ble_tp_disconnected, - .le_param_updated = ble_param_updated, -}; - -#if !defined(CONFIG_BT_OAD_SERVER) -/************************************************************************* -NAME - ble_tp_tx_mtu_size -*/ -static void ble_tp_tx_mtu_size(struct bt_conn *conn, u8_t err, - struct bt_gatt_exchange_params *params) -{ - if (!err) { - tx_mtu_size = bt_gatt_get_mtu(ble_tp_conn); - BT_WARN("ble tp echange mtu size success, mtu size: %d", tx_mtu_size); - } else { - BT_WARN("ble tp echange mtu size failure, err: %d", err); - } -} -#endif -/************************************************************************* -NAME - ble_tp_connected -*/ -static void ble_tp_connected(struct bt_conn *conn, u8_t err) -{ -#if !defined(CONFIG_BT_OAD_SERVER) - int tx_octets = 0x00fb; - int tx_time = 0x0848; - int ret = -1; -#endif - -#if XTAL_32K_TYPE == EXTERNAL_XTAL_32K - struct bt_le_conn_param param; -#endif - - if (err) { - return; - } - - BT_WARN("Tp connected"); - ble_tp_conn = conn; - pds_start = false; - -#if XTAL_32K_TYPE == EXTERNAL_XTAL_32K - param.interval_min = param.interval_max = 0x320; - param.latency = 0; - param.timeout = 0x05dc; - ret = bt_conn_le_param_update(ble_tp_conn, ¶m); - if (ret) { - BT_WARN("conn update failed (err %d)\r\n", ret); - } else { - BT_WARN("conn update initiated\r\n"); - } -#endif - -#if !defined(CONFIG_BT_OAD_SERVER) - //set data length after connected. - ret = bt_le_set_data_len(ble_tp_conn, tx_octets, tx_time); - - if (!ret) { - BT_WARN("ble tp set data length success"); - } else { - BT_WARN("ble tp set data length failure, err: %d", ret); - } - - //exchange mtu size after connected. - exchg_mtu.func = ble_tp_tx_mtu_size; - ret = bt_gatt_exchange_mtu(ble_tp_conn, &exchg_mtu); - - if (!ret) { - BT_WARN("ble tp exchange mtu size pending"); - } else { - BT_WARN("ble tp exchange mtu size failure, err: %d", ret); - } -#endif -} - -/************************************************************************* -NAME - ble_tp_disconnected -*/ -static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason) -{ - BT_WARN("Tp disconnected"); - - if (created_tp_task) { - BT_WARN("Delete throughput tx task"); - vTaskDelete(ble_tp_task_h); - created_tp_task = 0; - } - - ble_tp_conn = NULL; - extern int ble_start_adv(void); - ble_start_adv(); - pds_start = true; -} - -/************************************************************************* -NAME - ble_param_updated -*/ - -static void ble_param_updated(struct bt_conn *conn, u16_t interval, - u16_t latency, u16_t timeout) -{ - BT_WARN("LE conn param updated: int 0x%04x lat %d to %d \r\n", interval, latency, timeout); -#if XTAL_32K_TYPE == EXTERNAL_XTAL_32K - if (interval > 80) { - pds_start = true; - } else { - pds_start = false; - } -#endif -} - -/************************************************************************* -NAME - ble_tp_recv_rd -*/ -static int ble_tp_recv_rd(struct bt_conn *conn, const struct bt_gatt_attr *attr, - void *buf, u16_t len, u16_t offset) -{ - int size = 9; - char data[9] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; - - memcpy(buf, data, size); - - return size; -} - -/************************************************************************* -NAME - ble_tp_recv_wr(receive data from client) -*/ -static int ble_tp_recv_wr(struct bt_conn *conn, const struct bt_gatt_attr *attr, - const void *buf, u16_t len, u16_t offset, u8_t flags) -{ - BT_WARN("recv data len=%d, offset=%d, flag=%d", len, offset, flags); - BT_WARN("recv data:%s", bt_hex(buf, len)); - - if (flags & BT_GATT_WRITE_FLAG_PREPARE) { - //Don't use prepare write data, execute write will upload data again. - BT_WARN("recv prepare write request"); - return 0; - } - - if (flags & BT_GATT_WRITE_FLAG_CMD) { - //Use write command data. - BT_WARN("recv write command"); - } else { - //Use write request / execute write data. - BT_WARN("recv write request / exce write"); - } - - k_sem_give(¬ify_poll_sem); - return len; -} - -/************************************************************************* -NAME - indicate_rsp /bl_tp_send_indicate -*/ - -static void indicate_rsp(struct bt_conn *conn, const struct bt_gatt_attr *attr, u8_t err) -{ - BT_WARN("receive comfirmation, err:%d", err); -} - -static int bl_tp_send_indicate(struct bt_conn *conn, const struct bt_gatt_attr *attr, - const void *data, u16_t len) -{ - static struct bt_gatt_indicate_params ind_params; - - ind_params.attr = attr; - ind_params.data = data; - ind_params.len = len; - ind_params.func = indicate_rsp; - ind_params.uuid = NULL; - - return bt_gatt_indicate(conn, &ind_params); -} - -/************************************************************************* -NAME - ble_tp_ind_ccc_changed -*/ -static void ble_tp_ind_ccc_changed(const struct bt_gatt_attr *attr, u16_t value) -{ - int err = -1; - char data[9] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; - - if (value == BT_GATT_CCC_INDICATE) { - err = bl_tp_send_indicate(ble_tp_conn, get_attr(BT_CHAR_BLE_TP_IND_ATTR_VAL_INDEX), data, 9); - BT_WARN("ble tp send indatcate: %d", err); - } -} - -/************************************************************************* -NAME - ble_tp_notify(send data to client) -*/ -static void ble_tp_notify_task(void *pvParameters) -{ - int err = -1; - u8_t data[244] = { 0x01 }; - k_sem_give(¬ify_poll_sem); - - while (1) { - k_sem_take(¬ify_poll_sem, K_FOREVER); - //send data to client - err = bt_gatt_notify(ble_tp_conn, get_attr(BT_CHAR_BLE_TP_NOT_ATTR_VAL_INDEX), data, (tx_mtu_size - 3)); - data[0] = data[0] + 1; - BT_WARN("ble tp send notify : %d", err); - } -} - -/************************************************************************* -NAME - ble_tp_not_ccc_changed -*/ -static void ble_tp_notify_ccc_changed(const struct bt_gatt_attr *attr, u16_t value) -{ - BT_WARN("ccc:value=[%d]", value); - - if (value == BT_GATT_CCC_NOTIFY) { - if (xTaskCreate(ble_tp_notify_task, (char *)"bletp", 512, NULL, 15, &ble_tp_task_h) == pdPASS) { - created_tp_task = 1; - BT_WARN("Create throughput tx task success"); - } else { - created_tp_task = 0; - BT_WARN("Create throughput tx taskfail"); - } - } else { - if (created_tp_task) { - BT_WARN("Delete throughput tx task"); - vTaskDelete(ble_tp_task_h); - created_tp_task = 0; - } - } -} - -/************************************************************************* -* DEFINE : attrs -*/ -static struct bt_gatt_attr attrs[] = { - BT_GATT_PRIMARY_SERVICE(BT_UUID_SVC_BLE_TP), - - BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_TP_RD, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - ble_tp_recv_rd, - NULL, - NULL), - - BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_TP_WR, - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP, - BT_GATT_PERM_WRITE | BT_GATT_PERM_PREPARE_WRITE, - NULL, - ble_tp_recv_wr, - NULL), - - BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_TP_IND, - BT_GATT_CHRC_INDICATE, - 0, - NULL, - NULL, - NULL), - - BT_GATT_CCC(ble_tp_ind_ccc_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), - - BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_TP_NOT, - BT_GATT_CHRC_NOTIFY, - 0, - NULL, - NULL, - NULL), - - BT_GATT_CCC(ble_tp_notify_ccc_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE) - -}; - -/************************************************************************* -NAME - get_attr -*/ -struct bt_gatt_attr *get_attr(u8_t index) -{ - return &attrs[index]; -} - -static struct bt_gatt_service ble_tp_server = BT_GATT_SERVICE(attrs); - -/************************************************************************* -NAME - ble_tp_init -*/ -void ble_tp_init() -{ - if (!isRegister) { - isRegister = 1; - bt_conn_cb_register(&ble_tp_conn_callbacks); - bt_gatt_service_register(&ble_tp_server); - k_sem_init(¬ify_poll_sem, 0, 1); - } -} diff --git a/source/Core/BSP/Pinecilv2/ble_peripheral_tp_server.h b/source/Core/BSP/Pinecilv2/ble_peripheral_tp_server.h deleted file mode 100644 index 235039af..00000000 --- a/source/Core/BSP/Pinecilv2/ble_peripheral_tp_server.h +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -FILE NAME - ble_peripheral_tp_server.h - -DESCRIPTION -NOTES -*/ -/****************************************************************************/ - -#ifndef _BLE_TP_SVC_H_ -#define _BLE_TP_SVC_H_ - -#include "ble_config.h" - -//07af27a5-9c22-11ea-9afe-02fcdc4e7412 -#define BT_UUID_SVC_BLE_TP BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x07af27a5, 0x9c22, 0x11ea, 0x9afe, 0x02fcdc4e7412)) -//07af27a6-9c22-11ea-9afe-02fcdc4e7412 -#define BT_UUID_CHAR_BLE_TP_RD BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x07af27a6, 0x9c22, 0x11ea, 0x9afe, 0x02fcdc4e7412)) -//07af27a7-9c22-11ea-9afe-02fcdc4e7412 -#define BT_UUID_CHAR_BLE_TP_WR BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x07af27a7, 0x9c22, 0x11ea, 0x9afe, 0x02fcdc4e7412)) -//07af27a8-9c22-11ea-9afe-02fcdc4e7412 -#define BT_UUID_CHAR_BLE_TP_IND BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x07af27a8, 0x9c22, 0x11ea, 0x9afe, 0x02fcdc4e7412)) -//07af27a9-9c22-11ea-9afe-02fcdc4e7412 -#define BT_UUID_CHAR_BLE_TP_NOT BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x07af27a9, 0x9c22, 0x11ea, 0x9afe, 0x02fcdc4e7412)) - -//read value handle offset 2 -#define BT_CHAR_BLE_TP_RD_ATTR_VAL_INDEX (2) -//write value handle offset 4 -#define BT_CHAR_BLE_TP_WR_ATTR_VAL_INDEX (4) -//indicate value handle offset 6 -#define BT_CHAR_BLE_TP_IND_ATTR_VAL_INDEX (6) -//notity value handle offset 9 -#define BT_CHAR_BLE_TP_NOT_ATTR_VAL_INDEX (9) - -void ble_tp_init(); -struct bt_gatt_attr *get_attr(u8_t index); - -#endif diff --git a/source/Core/BSP/Pinecilv2/postRTOS.cpp b/source/Core/BSP/Pinecilv2/postRTOS.cpp index 44119950..dbd7a433 100644 --- a/source/Core/BSP/Pinecilv2/postRTOS.cpp +++ b/source/Core/BSP/Pinecilv2/postRTOS.cpp @@ -4,16 +4,14 @@ #include "QC3.h" #include "Settings.h" #include "Si7210.h" +#include "ble.h" #include "cmsis_os.h" #include "main.hpp" #include "power.hpp" #include "stdlib.h" #include "task.h" - bool hall_effect_present = false; -extern "C" { -void ble_stack_start(void); -}; + void postRToSInit() { // Any after RTos setup #ifdef HALL_SI7210