mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-23 13:18:59 +00:00
[style] format files by clang-format
This commit is contained in:
parent
47ce9f871c
commit
d427e7fdda
1131 changed files with 7338846 additions and 422042 deletions
|
@ -23,65 +23,66 @@ NOTES
|
|||
#include "ble_central_tp_client.h"
|
||||
#include "log.h"
|
||||
|
||||
static void ble_subscribe();
|
||||
static void ble_discover(u8_t type, u16_t start_handle);
|
||||
static void ble_tp_connected(struct bt_conn *conn, u8_t err);
|
||||
static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason);
|
||||
|
||||
struct bt_conn *ble_tp_conn;
|
||||
struct bt_gatt_exchange_params exchg_mtu;
|
||||
TaskHandle_t ble_write_data_task_h;
|
||||
static struct bt_conn *ble_tp_conn;
|
||||
static TaskHandle_t ble_write_data_task_h;
|
||||
|
||||
static struct bt_gatt_discover_params discover_params;
|
||||
static struct bt_gatt_subscribe_params subscribe_params;
|
||||
static struct tp_char_hdl char_hdl;
|
||||
struct k_sem write_data_poll_sem;
|
||||
|
||||
|
||||
int tx_mtu_size = 20;
|
||||
static struct k_sem write_data_poll_sem;
|
||||
|
||||
static u8_t created_write_data_task = 0;
|
||||
static u8_t isRegister = 0;
|
||||
|
||||
static struct bt_conn_cb ble_tp_conn_callbacks = {
|
||||
.connected = ble_tp_connected,
|
||||
.disconnected = ble_tp_disconnected,
|
||||
.connected = ble_tp_connected,
|
||||
.disconnected = ble_tp_disconnected,
|
||||
};
|
||||
|
||||
static void ble_subscribe();
|
||||
static void ble_discover(u8_t type);
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
notify_func(receive data from server)
|
||||
*/
|
||||
static u8_t notify_func(struct bt_conn *conn,
|
||||
struct bt_gatt_subscribe_params *params,
|
||||
const void *data, u16_t length)
|
||||
struct bt_gatt_subscribe_params *params,
|
||||
const void *data, u16_t length)
|
||||
{
|
||||
static u32_t time = 0;
|
||||
static int len = 0;
|
||||
BT_WARN("notify_func complete \r\n");
|
||||
BT_WARN("notify_func complete");
|
||||
|
||||
if (!params->value) {
|
||||
BT_WARN("Unsubscribed\r\n");
|
||||
params->value_handle = 0U;
|
||||
BT_WARN("Unsubscribed");
|
||||
params->value_handle = 0U;
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
|
||||
if(!time){
|
||||
|
||||
if (!time) {
|
||||
time = k_now_ms();
|
||||
}
|
||||
|
||||
len += length;
|
||||
if(k_now_ms()- time >= 1000){
|
||||
BT_WARN("data_len=[%d]\r\n",len);
|
||||
|
||||
if (k_now_ms() - time >= 1000) {
|
||||
BT_WARN("data_len=[%d]", len);
|
||||
time = k_now_ms();
|
||||
len = 0;
|
||||
}
|
||||
|
||||
BT_WARN("Notification: data length %u\r\n", length);
|
||||
if(length)
|
||||
{
|
||||
k_sem_give(&write_data_poll_sem);
|
||||
|
||||
BT_WARN("Notification: data length %u", length);
|
||||
if (length != 0) {
|
||||
BT_WARN("The first 10 recv data %s", bt_hex(data, 10));
|
||||
}
|
||||
|
||||
if (length) {
|
||||
k_sem_give(&write_data_poll_sem);
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -92,15 +93,16 @@ NAME
|
|||
static void ble_write_data_task(void *pvParameters)
|
||||
{
|
||||
int error;
|
||||
uint8_t buf[20] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
|
||||
while(1)
|
||||
{
|
||||
k_sem_take(&write_data_poll_sem, K_FOREVER);
|
||||
BT_WARN("ble_write_data\r\n");
|
||||
// Send data to server
|
||||
error = bt_gatt_write_without_response(ble_tp_conn,char_hdl.tp_wr_hdl,buf,20,0);
|
||||
BT_WARN("Write Complete (err %d)\r\n", error);
|
||||
}
|
||||
u8_t buf[20] = { 0x1 };
|
||||
|
||||
while (1) {
|
||||
k_sem_take(&write_data_poll_sem, K_FOREVER);
|
||||
BT_WARN("ble_write_data");
|
||||
// Send data to server
|
||||
error = bt_gatt_write_without_response(ble_tp_conn, char_hdl.tp_wr_hdl, buf, 20, 0);
|
||||
buf[0] = buf[0] + 1;
|
||||
BT_WARN("Write Complete (err %d)", error);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -110,7 +112,7 @@ NAME
|
|||
static void ble_subscribe()
|
||||
{
|
||||
if (!ble_tp_conn) {
|
||||
BT_WARN("Not connected\r\n");
|
||||
BT_WARN("Not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -120,23 +122,22 @@ static void ble_subscribe()
|
|||
subscribe_params.notify = notify_func;
|
||||
|
||||
int err = bt_gatt_subscribe(ble_tp_conn, &subscribe_params);
|
||||
|
||||
if (err) {
|
||||
BT_WARN("Subscribe failed (err %d)\r\n", err);
|
||||
BT_WARN("Subscribe failed (err %d)", err);
|
||||
} else {
|
||||
BT_WARN("Subscribed\r\n");
|
||||
BT_WARN("Subscribed");
|
||||
}
|
||||
|
||||
k_sem_init(&write_data_poll_sem, 0, 1);
|
||||
if(!created_write_data_task && (xTaskCreate(ble_write_data_task, (char*)"ble_write_data", 512, NULL, 15, &ble_write_data_task_h) == pdPASS))
|
||||
{
|
||||
|
||||
if (!created_write_data_task && (xTaskCreate(ble_write_data_task, (char *)"ble_write_data", 512, NULL, 15, &ble_write_data_task_h) == pdPASS)) {
|
||||
created_write_data_task = 1;
|
||||
BT_WARN("Create write data task success .\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
created_write_data_task = 0;
|
||||
BT_WARN("Create write data taskfail .\n");
|
||||
}
|
||||
|
||||
BT_WARN("Create write data task success");
|
||||
} else {
|
||||
created_write_data_task = 0;
|
||||
BT_WARN("Create write data taskfail");
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -147,63 +148,56 @@ static uint8_t ble_discover_func(struct bt_conn *conn, const struct bt_gatt_attr
|
|||
{
|
||||
struct bt_gatt_chrc *gatt_chrc;
|
||||
char str[37];
|
||||
BT_WARN( "ble_discover_func\r\n");
|
||||
|
||||
if (!attr) {
|
||||
BT_WARN( "Discover complete\r\n");
|
||||
if(params->type!= BT_GATT_DISCOVER_DESCRIPTOR)
|
||||
{
|
||||
ble_discover(BT_GATT_DISCOVER_DESCRIPTOR);
|
||||
BT_WARN("Discover complete");
|
||||
|
||||
if (params->type != BT_GATT_DISCOVER_DESCRIPTOR) {
|
||||
ble_discover(BT_GATT_DISCOVER_DESCRIPTOR, char_hdl.tp_notify_hdl);
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
(void)memset(params, 0, sizeof(*params));
|
||||
ble_subscribe();
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
if(params == NULL)
|
||||
{
|
||||
BT_WARN( "ble_discover_func_PARAMS\r\n");
|
||||
}
|
||||
|
||||
if (params == NULL) {
|
||||
BT_WARN("ble_discover_func_PARAMS");
|
||||
}
|
||||
|
||||
switch (params->type) {
|
||||
case BT_GATT_DISCOVER_PRIMARY:
|
||||
break;
|
||||
|
||||
|
||||
case BT_GATT_DISCOVER_SECONDARY:
|
||||
break;
|
||||
|
||||
|
||||
case BT_GATT_DISCOVER_CHARACTERISTIC:
|
||||
gatt_chrc = attr->user_data;
|
||||
bt_uuid_to_str(gatt_chrc->uuid, str, sizeof(str));
|
||||
if(!bt_uuid_cmp(gatt_chrc->uuid, BT_UUID_CHAR_BLE_TP_RD)) {
|
||||
char_hdl.tp_rd_hdl= gatt_chrc->value_handle;
|
||||
BT_WARN("TP SERVICE, char_hdl.tp_rd_hdl: %d\n", char_hdl.tp_rd_hdl);
|
||||
}
|
||||
else if(!bt_uuid_cmp(gatt_chrc->uuid, BT_UUID_CHAR_BLE_TP_WR)) {
|
||||
char_hdl.tp_wr_hdl= gatt_chrc->value_handle;
|
||||
BT_WARN("TP SERVICE, char_hdl..tp_wr_hdl: %d\n", char_hdl.tp_wr_hdl);
|
||||
}
|
||||
else if(!bt_uuid_cmp(gatt_chrc->uuid, BT_UUID_CHAR_BLE_TP_IND)) {
|
||||
char_hdl.tp_ind_hdl= gatt_chrc->value_handle;
|
||||
BT_WARN("TP SERVICE, char_hdl.tp_ind_hdl: %d\n", char_hdl.tp_ind_hdl);
|
||||
}
|
||||
else if(!bt_uuid_cmp(gatt_chrc->uuid, BT_UUID_CHAR_BLE_TP_NOT))
|
||||
{
|
||||
|
||||
if (!bt_uuid_cmp(gatt_chrc->uuid, BT_UUID_CHAR_BLE_TP_RD)) {
|
||||
char_hdl.tp_rd_hdl = gatt_chrc->value_handle;
|
||||
} else if (!bt_uuid_cmp(gatt_chrc->uuid, BT_UUID_CHAR_BLE_TP_WR)) {
|
||||
char_hdl.tp_wr_hdl = gatt_chrc->value_handle;
|
||||
} else if (!bt_uuid_cmp(gatt_chrc->uuid, BT_UUID_CHAR_BLE_TP_IND)) {
|
||||
char_hdl.tp_ind_hdl = gatt_chrc->value_handle;
|
||||
} else if (!bt_uuid_cmp(gatt_chrc->uuid, BT_UUID_CHAR_BLE_TP_NOT)) {
|
||||
char_hdl.tp_notify_hdl = gatt_chrc->value_handle;
|
||||
BT_WARN("TP SERVICE, char_hdl.tp_notify_hdl: %d\n", char_hdl.tp_notify_hdl);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case BT_GATT_DISCOVER_INCLUDE:
|
||||
break;
|
||||
|
||||
case BT_GATT_DISCOVER_DESCRIPTOR:
|
||||
if(!bt_uuid_cmp(attr->uuid,BT_UUID_GATT_CCC))
|
||||
{
|
||||
char_hdl.tp_ccc_hdl = attr->handle;
|
||||
BT_WARN("TP SERVICE, char_hdl.tp_ccc_hdl: %d\n", char_hdl.tp_ccc_hdl);
|
||||
|
||||
if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CCC)) {
|
||||
char_hdl.tp_ccc_hdl = attr->handle;
|
||||
(void)memset(params, 0, sizeof(*params));
|
||||
ble_subscribe();
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -215,7 +209,7 @@ static uint8_t ble_discover_func(struct bt_conn *conn, const struct bt_gatt_attr
|
|||
NAME
|
||||
ble_discover
|
||||
*/
|
||||
static void ble_discover(u8_t type)
|
||||
static void ble_discover(u8_t type, u16_t start_handle)
|
||||
{
|
||||
int err;
|
||||
|
||||
|
@ -224,37 +218,18 @@ static void ble_discover(u8_t type)
|
|||
}
|
||||
|
||||
discover_params.func = ble_discover_func;
|
||||
discover_params.start_handle = 0x0001;
|
||||
discover_params.start_handle = start_handle;
|
||||
discover_params.end_handle = 0xffff;
|
||||
discover_params.type = type;
|
||||
discover_params.uuid = NULL;
|
||||
|
||||
err = bt_gatt_discover(ble_tp_conn, &discover_params);
|
||||
|
||||
if (err) {
|
||||
BT_WARN("Discover failed (err %d)\r\n", err);
|
||||
BT_WARN("Discover failed (err %d)", err);
|
||||
} else {
|
||||
BT_WARN("Discover pending\r\n");
|
||||
BT_WARN("Discover pending");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
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\n", tx_mtu_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
BT_WARN("ble tp echange mtu size failure, err: %d\n", err);
|
||||
}
|
||||
ble_discover( BT_GATT_DISCOVER_CHARACTERISTIC);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -263,62 +238,52 @@ NAME
|
|||
*/
|
||||
static void ble_tp_connected(struct bt_conn *conn, u8_t err)
|
||||
{
|
||||
int tx_octets = 0x00fb;
|
||||
int tx_time = 0x0848;
|
||||
int ret = -1;
|
||||
int tx_octets = 0x00fb;
|
||||
int tx_time = 0x0848;
|
||||
int ret = -1;
|
||||
|
||||
if( err )
|
||||
if (err) {
|
||||
return;
|
||||
BT_WARN("%s\n",__func__);
|
||||
ble_tp_conn = conn;
|
||||
}
|
||||
|
||||
//set data length after connected.
|
||||
ret = bt_le_set_data_len(ble_tp_conn, tx_octets, tx_time);
|
||||
if(!ret)
|
||||
{
|
||||
BT_WARN("ble tp set data length success.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
BT_WARN("ble tp set data length failure, err: %d\n", ret);
|
||||
}
|
||||
BT_WARN("TP connected");
|
||||
ble_tp_conn = conn;
|
||||
|
||||
//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.\n");
|
||||
} else {
|
||||
BT_WARN("ble tp exchange mtu size failure, err: %d\n", ret);
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
//discover after connected.
|
||||
ble_discover(BT_GATT_DISCOVER_CHARACTERISTIC, 0x0001);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
ble_tp_disconnected
|
||||
*/
|
||||
static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason)
|
||||
{
|
||||
BT_WARN("%s\n",__func__);
|
||||
ble_tp_conn = NULL;
|
||||
if(created_write_data_task)
|
||||
{
|
||||
BT_WARN("Delete write data task .\n");
|
||||
vTaskDelete(ble_write_data_task_h);
|
||||
created_write_data_task = 0;
|
||||
}
|
||||
{
|
||||
ble_tp_conn = NULL;
|
||||
BT_WARN("TP Disconnected");
|
||||
if (created_write_data_task) {
|
||||
BT_WARN("Delete write data task");
|
||||
vTaskDelete(ble_write_data_task_h);
|
||||
created_write_data_task = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
ble_tp_init
|
||||
*/
|
||||
void ble_tp_init()
|
||||
{
|
||||
if( !isRegister )
|
||||
{
|
||||
if (!isRegister) {
|
||||
isRegister = 1;
|
||||
bt_conn_cb_register(&ble_tp_conn_callbacks);
|
||||
}
|
||||
|
|
|
@ -12,37 +12,34 @@ NOTES
|
|||
|
||||
#include "config.h"
|
||||
|
||||
struct tp_char_hdl
|
||||
{
|
||||
uint16_t tp_rd_hdl;
|
||||
uint16_t tp_wr_hdl;
|
||||
uint16_t tp_ind_hdl;
|
||||
uint16_t tp_notify_hdl;
|
||||
uint16_t tp_ccc_hdl;
|
||||
//struct hids_rpt_hdl rpt_hdl[7];
|
||||
}__packed;
|
||||
|
||||
struct tp_char_hdl {
|
||||
uint16_t tp_rd_hdl;
|
||||
uint16_t tp_wr_hdl;
|
||||
uint16_t tp_ind_hdl;
|
||||
uint16_t tp_notify_hdl;
|
||||
uint16_t tp_ccc_hdl;
|
||||
//struct hids_rpt_hdl rpt_hdl[7];
|
||||
} __packed;
|
||||
|
||||
//07af27a5-9c22-11ea-9afe-02fcdc4e7412
|
||||
#define BT_UUID_SVC_BLE_TP BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x07af27a5, 0x9c22, 0x11ea, 0x9afe, 0x02fcdc4e7412))
|
||||
#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))
|
||||
#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))
|
||||
#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))
|
||||
#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))
|
||||
#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)
|
||||
#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)
|
||||
#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)
|
||||
#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)
|
||||
#define BT_CHAR_BLE_TP_NOT_ATTR_VAL_INDEX (9)
|
||||
|
||||
void ble_tp_init();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
/**
|
||||
* @file main.c
|
||||
* @brief
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you 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 "hal_uart.h"
|
||||
#include <FreeRTOS.h>
|
||||
|
@ -29,30 +29,28 @@
|
|||
#include "ble_central_tp_client.h"
|
||||
#include "conn.h"
|
||||
#include "log.h"
|
||||
#include "ble_lib_api.h"
|
||||
#include "hci_driver.h"
|
||||
|
||||
#define NAME_LEN 30
|
||||
#define NAME_LEN 30
|
||||
|
||||
extern uint8_t _heap_start;
|
||||
extern uint8_t _heap_size; // @suppress("Type cannot be resolved")
|
||||
static HeapRegion_t xHeapRegions[] =
|
||||
{
|
||||
{ &_heap_start, (unsigned int) &_heap_size },
|
||||
{ NULL, 0 }, /* Terminates the array. */
|
||||
{ NULL, 0 } /* Terminates the array. */
|
||||
static HeapRegion_t xHeapRegions[] = {
|
||||
{ &_heap_start, (unsigned int)&_heap_size },
|
||||
{ NULL, 0 }, /* Terminates the array. */
|
||||
{ NULL, 0 } /* Terminates the array. */
|
||||
};
|
||||
|
||||
uint8_t sharedBuf[16];
|
||||
|
||||
extern void ble_controller_init(uint8_t task_priority);
|
||||
#if defined(BFLB_BLE)
|
||||
extern int hci_driver_init(void);
|
||||
#endif
|
||||
|
||||
void user_vAssertCalled(void) __attribute__ ((weak, alias ("vAssertCalled")));
|
||||
void user_vAssertCalled(void) __attribute__((weak, alias("vAssertCalled")));
|
||||
void vAssertCalled(void)
|
||||
{
|
||||
MSG("vAssertCalled\r\n");
|
||||
while( 1 );
|
||||
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
void vApplicationTickHook(void)
|
||||
|
@ -60,19 +58,24 @@ void vApplicationTickHook(void)
|
|||
//MSG("vApplicationTickHook\r\n");
|
||||
}
|
||||
|
||||
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName )
|
||||
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
|
||||
{
|
||||
MSG("vApplicationStackOverflowHook\r\n");
|
||||
if(pcTaskName){
|
||||
MSG("Stack name %s\r\n", pcTaskName);
|
||||
}
|
||||
while( 1 );
|
||||
|
||||
if (pcTaskName) {
|
||||
MSG("Stack name %s\r\n", pcTaskName);
|
||||
}
|
||||
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
void vApplicationMallocFailedHook(void)
|
||||
{
|
||||
MSG("vApplicationMallocFailedHook\r\n");
|
||||
while( 1 );
|
||||
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize)
|
||||
{
|
||||
|
@ -80,7 +83,7 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackTyp
|
|||
function then they must be declared static - otherwise they will be allocated on
|
||||
the stack and so not exists after this function exits. */
|
||||
static StaticTask_t xIdleTaskTCB;
|
||||
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
|
||||
static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];
|
||||
|
||||
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
|
||||
state will be stored. */
|
||||
|
@ -104,7 +107,7 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackT
|
|||
function then they must be declared static - otherwise they will be allocated on
|
||||
the stack and so not exists after this function exits. */
|
||||
static StaticTask_t xTimerTaskTCB;
|
||||
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
|
||||
static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];
|
||||
|
||||
/* Pass out a pointer to the StaticTask_t structure in which the Timer
|
||||
task's state will be stored. */
|
||||
|
@ -119,137 +122,137 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackT
|
|||
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
data_cb
|
||||
*/
|
||||
static bool data_cb(struct bt_data *data, void *user_data)
|
||||
{
|
||||
char *name = user_data;
|
||||
u8_t len;
|
||||
char *name = user_data;
|
||||
u8_t len;
|
||||
|
||||
switch (data->type) {
|
||||
case BT_DATA_NAME_SHORTENED:
|
||||
case BT_DATA_NAME_COMPLETE:
|
||||
len = (data->data_len > NAME_LEN - 1)?(NAME_LEN - 1):(data->data_len);
|
||||
memcpy(name, data->data, len);
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
switch (data->type) {
|
||||
case BT_DATA_NAME_SHORTENED:
|
||||
case BT_DATA_NAME_COMPLETE:
|
||||
len = (data->data_len > NAME_LEN - 1) ? (NAME_LEN - 1) : (data->data_len);
|
||||
memcpy(name, data->data, len);
|
||||
return false;
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
device_found
|
||||
*/
|
||||
|
||||
static void device_found(const bt_addr_le_t *addr, s8_t rssi, u8_t evtype,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
char le_addr[BT_ADDR_LE_STR_LEN];
|
||||
char name[30];
|
||||
int err;
|
||||
char *adv_name = "BL_TEST_01"; //This name must be the same as adv_name in ble_central
|
||||
|
||||
(void)memset(name, 0, sizeof(name));
|
||||
bt_data_parse(buf, data_cb, name);
|
||||
bt_addr_le_to_str(addr, le_addr, sizeof(le_addr));
|
||||
|
||||
BT_WARN("[DEVICE]: %s, AD evt type %u, RSSI %i %s \r\n",le_addr, evtype, rssi, name);
|
||||
if(strcmp(name,adv_name) == 0)
|
||||
{
|
||||
struct bt_conn *conn;
|
||||
struct bt_le_conn_param param = {
|
||||
.interval_min = BT_GAP_INIT_CONN_INT_MIN,\
|
||||
.interval_max = BT_GAP_INIT_CONN_INT_MAX,\
|
||||
.latency = 0,\
|
||||
.timeout = 400,\
|
||||
};
|
||||
err = bt_le_scan_stop();
|
||||
if (err) {
|
||||
BT_WARN("Stopping scanning failed (err %d)\r\n", err);
|
||||
} else {
|
||||
BT_WARN("Scan successfully stopped \r\n");
|
||||
}
|
||||
conn = bt_conn_create_le(addr, ¶m);
|
||||
if(!conn) {
|
||||
BT_WARN("Connection failed\r\n");
|
||||
}else{
|
||||
BT_WARN("Connection pending\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
ble_start_scan
|
||||
*/
|
||||
static void ble_start_scan(void)
|
||||
{
|
||||
int err;
|
||||
struct bt_le_scan_param scan_param = {
|
||||
.type = 0, \
|
||||
.filter_dup = 1,\
|
||||
.interval = BT_GAP_SCAN_FAST_INTERVAL, \
|
||||
.window = BT_GAP_SCAN_FAST_WINDOW, \
|
||||
};
|
||||
err = bt_le_scan_start(&scan_param, device_found);
|
||||
if(err){
|
||||
BT_WARN("Failed to start scan (err %d) \r\n", err);
|
||||
}else{
|
||||
BT_WARN("Start scan successfully \r\n");
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
device_found
|
||||
*/
|
||||
|
||||
static void device_found(const bt_addr_le_t *addr, s8_t rssi, u8_t evtype,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
char le_addr[BT_ADDR_LE_STR_LEN];
|
||||
char name[30];
|
||||
int err;
|
||||
char *adv_name = "BL_TEST_01"; //This name must be the same as adv_name in ble_central
|
||||
|
||||
(void)memset(name, 0, sizeof(name));
|
||||
bt_data_parse(buf, data_cb, name);
|
||||
bt_addr_le_to_str(addr, le_addr, sizeof(le_addr));
|
||||
|
||||
BT_WARN("[DEVICE]: %s, AD evt type %u, RSSI %i %s", le_addr, evtype, rssi, name);
|
||||
|
||||
if (strcmp(name, adv_name) == 0) {
|
||||
struct bt_conn *conn;
|
||||
struct bt_le_conn_param param = {
|
||||
.interval_min = BT_GAP_INIT_CONN_INT_MIN,
|
||||
.interval_max = BT_GAP_INIT_CONN_INT_MAX,
|
||||
.latency = 0,
|
||||
.timeout = 400,
|
||||
};
|
||||
err = bt_le_scan_stop();
|
||||
|
||||
if (err) {
|
||||
BT_WARN("Stopping scanning failed (err %d)", err);
|
||||
} else {
|
||||
BT_WARN("Scan successfully stopped");
|
||||
}
|
||||
|
||||
conn = bt_conn_create_le(addr, ¶m);
|
||||
|
||||
if (!conn) {
|
||||
BT_WARN("Connection failed");
|
||||
} else {
|
||||
BT_WARN("Connection pending");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
ble_start_scan
|
||||
*/
|
||||
static void ble_start_scan(void)
|
||||
{
|
||||
int err;
|
||||
struct bt_le_scan_param scan_param = {
|
||||
.type = 0,
|
||||
.filter_dup = 1,
|
||||
.interval = BT_GAP_SCAN_FAST_INTERVAL,
|
||||
.window = BT_GAP_SCAN_FAST_WINDOW,
|
||||
};
|
||||
err = bt_le_scan_start(&scan_param, device_found);
|
||||
|
||||
if (err) {
|
||||
BT_WARN("Failed to start scan (err %d)", err);
|
||||
} else {
|
||||
BT_WARN("Start scan successfully");
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
bt_enable_cb
|
||||
*/
|
||||
|
||||
static void bt_enable_cb(int err)
|
||||
{
|
||||
|
||||
ble_tp_init();
|
||||
ble_start_scan();
|
||||
|
||||
ble_tp_init();
|
||||
ble_start_scan();
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
ble_stack_start
|
||||
*/
|
||||
void ble_stack_start(void)
|
||||
{
|
||||
|
||||
GLB_Set_EM_Sel(GLB_EM_8KB);
|
||||
|
||||
// Initialize BLE controller
|
||||
|
||||
// Initialize BLE controller
|
||||
MSG("[OS] ble_controller_init...\r\n");
|
||||
ble_controller_init(configMAX_PRIORITIES - 1);
|
||||
|
||||
|
||||
// Initialize BLE Host stack
|
||||
MSG("[OS] hci_driver_init...\r\n");
|
||||
|
||||
|
||||
hci_driver_init();
|
||||
|
||||
|
||||
MSG("[OS] bt_enable...\r\n");
|
||||
bt_enable(bt_enable_cb);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
ble_init
|
||||
*/
|
||||
void ble_init(void)
|
||||
{
|
||||
extern void ble_stack_start(void);
|
||||
ble_stack_start();
|
||||
ble_stack_start();
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
ble_init_task
|
||||
*/
|
||||
static void ble_init_task(void *pvParameters)
|
||||
|
@ -262,18 +265,17 @@ int main(void)
|
|||
{
|
||||
static StackType_t ble_init_stack[1024];
|
||||
static StaticTask_t ble_init_task_h;
|
||||
|
||||
|
||||
bflb_platform_init(0);
|
||||
HBN_Set_XCLK_CLK_Sel(HBN_XCLK_CLK_XTAL);
|
||||
GLB_Set_MTimer_CLK(1, GLB_MTIMER_CLK_BCLK, 17);
|
||||
|
||||
HBN_Set_XCLK_CLK_Sel(HBN_XCLK_CLK_XTAL);
|
||||
|
||||
vPortDefineHeapRegions(xHeapRegions);
|
||||
|
||||
|
||||
MSG("[OS] ble init task...\r\n");
|
||||
xTaskCreateStatic(ble_init_task, (char*)"ble_init", sizeof(ble_init_stack)/4, NULL, 15, ble_init_stack, &ble_init_task_h);
|
||||
|
||||
vTaskStartScheduler();
|
||||
while(1)
|
||||
{
|
||||
xTaskCreateStatic(ble_init_task, (char *)"ble_init", sizeof(ble_init_stack) / 4, NULL, 15, ble_init_stack, &ble_init_task_h);
|
||||
|
||||
vTaskStartScheduler();
|
||||
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,21 +26,19 @@ NOTES
|
|||
static void ble_tp_connected(struct bt_conn *conn, u8_t err);
|
||||
static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason);
|
||||
|
||||
struct bt_conn *ble_tp_conn;
|
||||
struct bt_gatt_exchange_params exchg_mtu;
|
||||
TaskHandle_t ble_tp_task_h;
|
||||
static struct bt_conn *ble_tp_conn;
|
||||
static struct bt_gatt_exchange_params exchg_mtu;
|
||||
static TaskHandle_t ble_tp_task_h;
|
||||
|
||||
struct k_sem notify_poll_sem;
|
||||
static struct k_sem notify_poll_sem;
|
||||
|
||||
|
||||
int tx_mtu_size = 20;
|
||||
u8_t tp_start = 0;
|
||||
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,
|
||||
.connected = ble_tp_connected,
|
||||
.disconnected = ble_tp_disconnected,
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -48,87 +46,79 @@ 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)
|
||||
struct bt_gatt_exchange_params *params)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
if (!err) {
|
||||
tx_mtu_size = bt_gatt_get_mtu(ble_tp_conn);
|
||||
BT_WARN("ble tp echange mtu size success, mtu size: %d\n", tx_mtu_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
BT_WARN("ble tp echange mtu size failure, err: %d\n", err);
|
||||
}
|
||||
//ble_write_data();
|
||||
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_tp_connected
|
||||
*/
|
||||
static void ble_tp_connected(struct bt_conn *conn, u8_t err)
|
||||
{
|
||||
int tx_octets = 0x00fb;
|
||||
int tx_time = 0x0848;
|
||||
int ret = -1;
|
||||
int tx_octets = 0x00fb;
|
||||
int tx_time = 0x0848;
|
||||
int ret = -1;
|
||||
|
||||
if( err )
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
BT_WARN("%s\n",__func__);
|
||||
ble_tp_conn = conn;
|
||||
BT_WARN("Tp connected");
|
||||
ble_tp_conn = conn;
|
||||
|
||||
//set data length after connected.
|
||||
ret = bt_le_set_data_len(ble_tp_conn, tx_octets, tx_time);
|
||||
if(!ret)
|
||||
{
|
||||
BT_WARN("ble tp set data length success.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
BT_WARN("ble tp set data length failure, err: %d\n", ret);
|
||||
}
|
||||
//set data length after connected.
|
||||
ret = bt_le_set_data_len(ble_tp_conn, tx_octets, tx_time);
|
||||
|
||||
//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.\n");
|
||||
} else {
|
||||
BT_WARN("ble tp exchange mtu size failure, err: %d\n", ret);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
ble_tp_disconnected
|
||||
*/
|
||||
static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason)
|
||||
{
|
||||
BT_WARN("%s\n",__func__);
|
||||
if(created_tp_task){
|
||||
BT_WARN("Delete throughput tx task .\n");
|
||||
vTaskDelete(ble_tp_task_h);
|
||||
created_tp_task = 0;
|
||||
}
|
||||
{
|
||||
BT_WARN("Tp disconnected");
|
||||
|
||||
ble_tp_conn = NULL;
|
||||
if (created_tp_task) {
|
||||
BT_WARN("Delete throughput tx task");
|
||||
vTaskDelete(ble_tp_task_h);
|
||||
created_tp_task = 0;
|
||||
}
|
||||
|
||||
ble_tp_conn = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
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)
|
||||
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};
|
||||
char data[9] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
|
||||
|
||||
memcpy(buf, data, size);
|
||||
|
||||
|
@ -140,53 +130,51 @@ 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)
|
||||
const void *buf, u16_t len, u16_t offset, u8_t flags)
|
||||
{
|
||||
BT_WARN("recv data len=%d, offset=%d, flag=%d\r\n", len, offset, 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)
|
||||
{
|
||||
if (flags & BT_GATT_WRITE_FLAG_PREPARE) {
|
||||
//Don't use prepare write data, execute write will upload data again.
|
||||
BT_WARN("rcv prepare write request\n");
|
||||
BT_WARN("recv prepare write request");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(flags & BT_GATT_WRITE_FLAG_CMD)
|
||||
{
|
||||
if (flags & BT_GATT_WRITE_FLAG_CMD) {
|
||||
//Use write command data.
|
||||
BT_WARN("rcv write command\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
BT_WARN("recv write command");
|
||||
} else {
|
||||
//Use write request / execute write data.
|
||||
BT_WARN("rcv write request / exce write\n");
|
||||
BT_WARN("recv write request / exce write");
|
||||
}
|
||||
|
||||
k_sem_give(¬ify_poll_sem);
|
||||
return len;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
indicate_rsp /bl_tp_send_indicate
|
||||
*/
|
||||
*/
|
||||
|
||||
void indicate_rsp(struct bt_conn *conn, const struct bt_gatt_attr *attr, u8_t err)
|
||||
static void indicate_rsp(struct bt_conn *conn, const struct bt_gatt_attr *attr, u8_t err)
|
||||
{
|
||||
BT_WARN("%s, receive comfirmation, err:%d\n", __func__, 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)
|
||||
const void *data, u16_t len)
|
||||
{
|
||||
static struct bt_gatt_indicate_params ind_params;
|
||||
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;
|
||||
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);
|
||||
return bt_gatt_indicate(conn, &ind_params);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -196,11 +184,11 @@ NAME
|
|||
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};
|
||||
char data[9] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
|
||||
|
||||
if(value == BT_GATT_CCC_INDICATE) {
|
||||
if (value == BT_GATT_CCC_INDICATE) {
|
||||
err = bl_tp_send_indicate(ble_tp_conn, get_attr(BT_CHAR_BLE_TP_IND_ATTR_VAL_INDEX), data, 9);
|
||||
BT_WARN("ble tp send indatcate: %d\n", err);
|
||||
BT_WARN("ble tp send indatcate: %d", err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,114 +199,105 @@ NAME
|
|||
static void ble_tp_notify_task(void *pvParameters)
|
||||
{
|
||||
int err = -1;
|
||||
char data[244] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
|
||||
u8_t data[244] = { 0x01 };
|
||||
k_sem_give(¬ify_poll_sem);
|
||||
while(1)
|
||||
{
|
||||
k_sem_take(¬ify_poll_sem, K_FOREVER);
|
||||
|
||||
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));
|
||||
BT_WARN("ble tp send notify : %d\n", err);
|
||||
|
||||
data[0] = data[0] + 1;
|
||||
BT_WARN("ble tp send notify : %d", err);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
ble_tp_not_ccc_changed
|
||||
*/
|
||||
static void ble_tp_not_ccc_changed(const struct bt_gatt_attr *attr, u16_t value)
|
||||
*/
|
||||
static void ble_tp_notify_ccc_changed(const struct bt_gatt_attr *attr, u16_t value)
|
||||
{
|
||||
BT_WARN("ccc:value=[%d]\r\n",value);
|
||||
|
||||
if(value == BT_GATT_CCC_NOTIFY) {
|
||||
k_sem_init(¬ify_poll_sem, 0, 1);
|
||||
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 .\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
created_tp_task = 0;
|
||||
BT_WARN("Create throughput tx taskfail .\n");
|
||||
}
|
||||
BT_WARN("ccc:value=[%d]", value);
|
||||
|
||||
if (value == BT_GATT_CCC_NOTIFY) {
|
||||
k_sem_init(¬ify_poll_sem, 0, 1);
|
||||
|
||||
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 {
|
||||
|
||||
if(created_tp_task){
|
||||
BT_WARN("Delete throughput tx task .\n");
|
||||
vTaskDelete(ble_tp_task_h);
|
||||
created_tp_task = 0;
|
||||
}
|
||||
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
|
||||
* DEFINE : attrs
|
||||
*/
|
||||
static struct bt_gatt_attr attrs[]= {
|
||||
BT_GATT_PRIMARY_SERVICE(BT_UUID_SVC_BLE_TP),
|
||||
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_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_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_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_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_not_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
|
||||
NAME
|
||||
get_attr
|
||||
*/
|
||||
struct bt_gatt_attr *get_attr(u8_t index)
|
||||
{
|
||||
return &attrs[index];
|
||||
return &attrs[index];
|
||||
}
|
||||
|
||||
struct bt_gatt_service ble_tp_server = BT_GATT_SERVICE(attrs);
|
||||
|
||||
static struct bt_gatt_service ble_tp_server = BT_GATT_SERVICE(attrs);
|
||||
|
||||
/*************************************************************************
|
||||
NAME
|
||||
NAME
|
||||
ble_tp_init
|
||||
*/
|
||||
void ble_tp_init()
|
||||
{
|
||||
if( !isRegister )
|
||||
{
|
||||
if (!isRegister) {
|
||||
isRegister = 1;
|
||||
bt_conn_cb_register(&ble_tp_conn_callbacks);
|
||||
bt_gatt_service_register(&ble_tp_server);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -13,29 +13,26 @@ NOTES
|
|||
#include "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))
|
||||
#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))
|
||||
#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))
|
||||
#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))
|
||||
#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))
|
||||
#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)
|
||||
#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)
|
||||
#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)
|
||||
#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)
|
||||
#define BT_CHAR_BLE_TP_NOT_ATTR_VAL_INDEX (9)
|
||||
|
||||
void ble_tp_init();
|
||||
struct bt_gatt_attr *get_attr(u8_t index);
|
||||
void ble_write_data(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
/**
|
||||
* @file main.c
|
||||
* @brief
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you 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 "hal_uart.h"
|
||||
#include <FreeRTOS.h>
|
||||
|
@ -27,22 +27,25 @@
|
|||
#include "gap.h"
|
||||
#include "bl702_glb.h"
|
||||
#include "ble_peripheral_tp_server.h"
|
||||
#include "ble_lib_api.h"
|
||||
#include "hci_driver.h"
|
||||
|
||||
extern uint8_t _heap_start;
|
||||
extern uint8_t _heap_size; // @suppress("Type cannot be resolved")
|
||||
static HeapRegion_t xHeapRegions[] =
|
||||
{
|
||||
{ &_heap_start, (unsigned int) &_heap_size },
|
||||
{ NULL, 0 }, /* Terminates the array. */
|
||||
{ NULL, 0 } /* Terminates the array. */
|
||||
static HeapRegion_t xHeapRegions[] = {
|
||||
{ &_heap_start, (unsigned int)&_heap_size },
|
||||
{ NULL, 0 }, /* Terminates the array. */
|
||||
{ NULL, 0 } /* Terminates the array. */
|
||||
};
|
||||
|
||||
uint8_t sharedBuf[16];
|
||||
void user_vAssertCalled(void) __attribute__ ((weak, alias ("vAssertCalled")));
|
||||
void user_vAssertCalled(void) __attribute__((weak, alias("vAssertCalled")));
|
||||
void vAssertCalled(void)
|
||||
{
|
||||
MSG("vAssertCalled\r\n");
|
||||
while( 1 );
|
||||
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
void vApplicationTickHook(void)
|
||||
|
@ -50,19 +53,24 @@ void vApplicationTickHook(void)
|
|||
//MSG("vApplicationTickHook\r\n");
|
||||
}
|
||||
|
||||
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName )
|
||||
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
|
||||
{
|
||||
MSG("vApplicationStackOverflowHook\r\n");
|
||||
if(pcTaskName){
|
||||
MSG("Stack name %s\r\n", pcTaskName);
|
||||
}
|
||||
while( 1 );
|
||||
|
||||
if (pcTaskName) {
|
||||
MSG("Stack name %s\r\n", pcTaskName);
|
||||
}
|
||||
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
void vApplicationMallocFailedHook(void)
|
||||
{
|
||||
MSG("vApplicationMallocFailedHook\r\n");
|
||||
while( 1 );
|
||||
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize)
|
||||
{
|
||||
|
@ -70,7 +78,7 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackTyp
|
|||
function then they must be declared static - otherwise they will be allocated on
|
||||
the stack and so not exists after this function exits. */
|
||||
static StaticTask_t xIdleTaskTCB;
|
||||
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
|
||||
static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];
|
||||
|
||||
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
|
||||
state will be stored. */
|
||||
|
@ -94,7 +102,7 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackT
|
|||
function then they must be declared static - otherwise they will be allocated on
|
||||
the stack and so not exists after this function exits. */
|
||||
static StaticTask_t xTimerTaskTCB;
|
||||
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
|
||||
static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];
|
||||
|
||||
/* Pass out a pointer to the StaticTask_t structure in which the Timer
|
||||
task's state will be stored. */
|
||||
|
@ -110,28 +118,18 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackT
|
|||
}
|
||||
|
||||
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, \
|
||||
.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
|
||||
uint8_t data[1] = {(BT_LE_AD_LIMITED | BT_LE_AD_NO_BREDR)};
|
||||
uint8_t data_uuid[2] = {0x12, 0x18};//0x1812
|
||||
uint8_t data_appearance[2] = {0x80, 0x01};//0x0180
|
||||
uint8_t data_manu[4] = {0x71, 0x01, 0x04, 0x13};
|
||||
struct bt_data adv_data[] = {
|
||||
BT_DATA(BT_DATA_FLAGS, data, 1),
|
||||
BT_DATA(BT_DATA_UUID16_ALL, data_uuid, sizeof(data_uuid)),
|
||||
BT_DATA(BT_DATA_GAP_APPEARANCE, data_appearance, sizeof(data_appearance)),
|
||||
BT_DATA(BT_DATA_NAME_COMPLETE, adv_name, strlen(adv_name)),
|
||||
BT_DATA(BT_DATA_MANUFACTURER_DATA, data_manu, sizeof(data_manu))
|
||||
};
|
||||
|
||||
BT_DATA(BT_DATA_NAME_COMPLETE, adv_name, strlen(adv_name)),
|
||||
};
|
||||
|
||||
return bt_le_adv_start(&adv_param, adv_data, ARRAY_SIZE(adv_data), NULL, 0);
|
||||
}
|
||||
|
@ -141,30 +139,24 @@ void bt_enable_cb(int err)
|
|||
ble_tp_init();
|
||||
ble_start_adv();
|
||||
}
|
||||
extern void ble_controller_init(uint8_t task_priority);
|
||||
#if defined(BFLB_BLE)
|
||||
extern int hci_driver_init(void);
|
||||
#endif
|
||||
|
||||
void ble_stack_start(void)
|
||||
{
|
||||
|
||||
MSG("[OS] ble_controller_init...\r\n");
|
||||
GLB_Set_EM_Sel(GLB_EM_8KB);
|
||||
ble_controller_init(configMAX_PRIORITIES - 1);
|
||||
|
||||
|
||||
// Initialize BLE Host stack
|
||||
MSG("[OS] hci_driver_init...\r\n");
|
||||
hci_driver_init();
|
||||
|
||||
MSG("[OS] bt_enable...\r\n");
|
||||
|
||||
MSG("[OS] bt_enable...\r\n");
|
||||
bt_enable(bt_enable_cb);
|
||||
}
|
||||
|
||||
void ble_init(void)
|
||||
{
|
||||
extern void ble_stack_start(void);
|
||||
ble_stack_start();
|
||||
{
|
||||
ble_stack_start();
|
||||
}
|
||||
|
||||
static void ble_init_task(void *pvParameters)
|
||||
|
@ -173,23 +165,21 @@ static void ble_init_task(void *pvParameters)
|
|||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static StackType_t ble_init_stack[1024];
|
||||
static StaticTask_t ble_init_task_h;
|
||||
|
||||
|
||||
bflb_platform_init(0);
|
||||
HBN_Set_XCLK_CLK_Sel(HBN_XCLK_CLK_XTAL);
|
||||
GLB_Set_MTimer_CLK(1, GLB_MTIMER_CLK_BCLK, 17);
|
||||
HBN_Set_XCLK_CLK_Sel(HBN_XCLK_CLK_XTAL);
|
||||
|
||||
vPortDefineHeapRegions(xHeapRegions);
|
||||
|
||||
|
||||
MSG("[OS] ble_init_task.....\r\n");
|
||||
xTaskCreateStatic(ble_init_task, (char*)"ble_init", sizeof(ble_init_stack)/4, NULL, 15, ble_init_stack, &ble_init_task_h);
|
||||
|
||||
vTaskStartScheduler();
|
||||
while(1)
|
||||
{
|
||||
xTaskCreateStatic(ble_init_task, (char *)"ble_init", sizeof(ble_init_stack) / 4, NULL, 15, ble_init_stack, &ble_init_task_h);
|
||||
|
||||
vTaskStartScheduler();
|
||||
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue