1
0
forked from me/IronOS
This commit is contained in:
Ben V. Brown
2022-10-21 23:10:54 +11:00
parent a6bb022997
commit 721c7d36f3
3 changed files with 0 additions and 442 deletions

View File

@@ -1,292 +0,0 @@
/****************************************************************************
FILE NAME
ble_tp_svc.c
DESCRIPTION
test profile demo
NOTES
*/
/****************************************************************************/
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <FreeRTOS.h>
#include <task.h>
#include "bluetooth.h"
#include "conn.h"
#include "gatt.h"
#include "hci_core.h"
#include "uuid.h"
#include "ble_tp_svc.h"
#include "log.h"
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;
int tx_mtu_size = 20;
u8_t tp_start = 0;
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,
};
/*************************************************************************
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);
}
}
/*************************************************************************
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;
if (err)
return;
printf("%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);
}
//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);
}
}
/*************************************************************************
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;
}
/*************************************************************************
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
*/
static int ble_tp_recv_wr(struct bt_conn *conn, const struct bt_gatt_attr *attr,
const void *buf, u16_t len, u16_t offset, u8_t flags)
{
BT_INFO("recv data len=%d, offset=%d, flag=%d\r\n", len, offset, flags);
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");
return 0;
}
if (flags & BT_GATT_WRITE_FLAG_CMD) {
//Use write command data.
BT_INFO("rcv write command\n");
} else {
//Use write request / execute write data.
BT_INFO("rcv write request / exce write\n");
}
return len;
}
/*************************************************************************
NAME
indicate_rsp /bl_tp_send_indicate
*/
void indicate_rsp(struct bt_conn *conn, const struct bt_gatt_attr *attr, u8_t err)
{
BT_WARN("receive confirm, err:%d\n", err);
}
static int bl_tp_send_indicate(struct bt_conn *conn, const struct bt_gatt_attr *attr,
const void *data, u16_t len)
{
//indicate paramete must be allocated statically
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\n", err);
}
}
/*************************************************************************
NAME
ble_tp_notify
*/
static void ble_tp_notify_task(void *pvParameters)
{
int err = -1;
char data[244] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
while (1) {
err = bt_gatt_notify(ble_tp_conn, get_attr(BT_CHAR_BLE_TP_NOT_ATTR_VAL_INDEX), data, (tx_mtu_size - 3));
BT_WARN("ble tp send notify : %d\n", err);
}
}
/*************************************************************************
NAME
ble_tp_not_ccc_changed
*/
static void ble_tp_not_ccc_changed(const struct bt_gatt_attr *attr, u16_t value)
{
BT_WARN("ccc:value=[%d]\r\n", value);
if (tp_start) {
if (value == BT_GATT_CCC_NOTIFY) {
if (xTaskCreate(ble_tp_notify_task, (char *)"bletp", 256, NULL, 15, &ble_tp_task_h) == pdPASS) {
created_tp_task = 1;
BT_WARN("Create throughput tx task success .\n");
} else {
created_tp_task = 0;
BT_WARN("Create throughput tx taskfail .\n");
}
} else {
if (created_tp_task) {
BT_WARN("Delete throughput tx task .\n");
vTaskDelete(ble_tp_task_h);
created_tp_task = 0;
}
}
} else if (tp_start == 0) {
if (created_tp_task) {
BT_WARN("Delete throughput tx task .\n");
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,
NULL,
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,
NULL,
NULL,
NULL,
NULL),
BT_GATT_CCC(ble_tp_not_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];
}
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);
}
}

View File

@@ -1,38 +0,0 @@
/****************************************************************************
FILE NAME
ble_tp_svc.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

View File

@@ -1,112 +0,0 @@
/*
* FreeRTOS Kernel V10.2.1
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#define configSUPPORT_STATIC_ALLOCATION 1
#define CLINT_CTRL_ADDR (0x02000000UL)
#define configCLINT_BASE_ADDRESS CLINT_CTRL_ADDR
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ (1000000UL)
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES (7)
#define configMINIMAL_STACK_SIZE ((unsigned short)512) /* Only needs to be this high as some demo tasks also use this constant. In production only the idle task would use this. */
#define configTOTAL_HEAP_SIZE ((size_t)48 * 1024)
#define configMAX_TASK_NAME_LEN (16)
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 2
#define configUSE_TICKLESS_IDLE 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES (2)
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1)
#define configTIMER_QUEUE_LENGTH 8
#define configTIMER_TASK_STACK_DEPTH (160)
/* Task priorities. Allow these to be overridden. */
#ifndef uartPRIMARY_PRIORITY
#define uartPRIMARY_PRIORITY (configMAX_PRIORITIES - 3)
#endif
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
void vAssertCalled(void);
#define configASSERT(x) \
if ((x) == 0) \
vAssertCalled()
#if (configUSE_TICKLESS_IDLE != 0)
void vApplicationSleep(uint32_t xExpectedIdleTime);
#define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) vApplicationSleep(xExpectedIdleTime)
#endif
#define portUSING_MPU_WRAPPERS 0
#endif /* FREERTOS_CONFIG_H */