BLE streaming of sensor data working

This commit is contained in:
ggw
2026-04-30 18:14:35 -05:00
parent b6e40323e3
commit 42f91eb075
107 changed files with 39837 additions and 35 deletions
@@ -0,0 +1,88 @@
/**
******************************************************************************
* @file ble.h
* @author MCD Application Team
* @brief BLE interface
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __BLE_H
#define __BLE_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "ble_conf.h"
#include "ble_dbg_conf.h"
/**< core */
#include "core/ble_core.h"
#include "core/ble_bufsize.h"
#include "core/ble_defs.h"
#include "core/auto/ble_vs_codes.h"
#include "core/ble_legacy.h"
#include "core/ble_std.h"
/**< blesvc */
#include "svc/Inc/bas.h"
#include "svc/Inc/bls.h"
#include "svc/Inc/crs_stm.h"
#include "svc/Inc/dis.h"
#include "svc/Inc/eds_stm.h"
#include "svc/Inc/hids.h"
#include "svc/Inc/hrs.h"
#include "svc/Inc/hts.h"
#include "svc/Inc/ias.h"
#include "svc/Inc/lls.h"
#include "svc/Inc/tps.h"
#include "svc/Inc/motenv_stm.h"
#include "svc/Inc/p2p_stm.h"
#include "svc/Inc/zdd_stm.h"
#include "svc/Inc/otas_stm.h"
#include "svc/Inc/mesh.h"
#include "svc/Inc/template_stm.h"
#include "svc/Inc/svc_ctl.h"
#include "svc/Inc/uuid.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* -------------------------------- *
* [retrieved from ble_legacy file]
* Macro to get RSSI from advertising report #0.
* "p" must be a pointer to the event parameters buffer
* -------------------------------- */
#define HCI_LE_ADVERTISING_REPORT_RSSI_0(p) \
(*(int8_t*)((&((hci_le_advertising_report_event_rp0*)(p))-> \
Advertising_Report[0].Length_Data) + 1 + \
((hci_le_advertising_report_event_rp0*)(p))-> \
Advertising_Report[0].Length_Data))
/* Exported functions ------------------------------------------------------- */
#ifdef __cplusplus
}
#endif
#endif /*__BLE_H */
@@ -0,0 +1,117 @@
/**
******************************************************************************
* @file ble_common.h
* @author MCD Application Team
* @brief Common file to BLE Middleware
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __BLE_COMMON_H
#define __BLE_COMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "ble_conf.h"
#include "ble_dbg_conf.h"
/* Event types copied from MW Legacy file*/
#include "tl.h"
/* -------------------------------- *
* Basic definitions *
* -------------------------------- */
#undef NULL
#define NULL 0
#undef FALSE
#define FALSE 0
#undef TRUE
#define TRUE (!0)
/* -------------------------------- *
* Macro delimiters *
* -------------------------------- */
#define M_BEGIN do {
#define M_END } while(0)
/* -------------------------------- *
* Some useful macro definitions *
* -------------------------------- */
#ifndef MAX
#define MAX( a, b ) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN( a, b ) (((a) < (b)) ? (a) : (b))
#endif
#define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END
#define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END
#define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END
#define MODSUB( a, b, m ) MODADD( a, (m)-(b), m )
#ifdef WIN32
#define ALIGN(n)
#else
#define ALIGN(n) __attribute__((aligned(n)))
#endif
#define PAUSE( t ) M_BEGIN \
volatile int _i; \
for ( _i = t; _i > 0; _i -- ); \
M_END
#define DIVF( x, y ) ((x)/(y))
#define DIVC( x, y ) (((x)+(y)-1)/(y))
#define DIVR( x, y ) (((x)+((y)/2))/(y))
#define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1)
#define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1)
#define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END
/* -------------------------------- *
* Compiler *
* -------------------------------- */
#define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__)))
#ifdef __cplusplus
}
#endif
#endif /*__BLE_COMMON_H */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,120 @@
/*****************************************************************************
* @file ble_gen_aci.c
* @brief STM32WB BLE API (gen_aci)
* Auto-generated file: do not edit!
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#include "auto/ble_gen_aci.h"
tBleStatus aci_reset( uint8_t Mode,
uint32_t Options )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_reset_cp0 *cp0 = (aci_reset_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Mode = Mode;
index_input += 1;
cp0->Options = Options;
index_input += 4;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x300;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_get_information( uint32_t* Version,
uint32_t* Options,
uint32_t* Debug_Info )
{
struct hci_request rq;
aci_get_information_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x301;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
Osal_MemCpy( (void*)Version, (const void*)resp.Version, 8 );
*Options = resp.Options;
Osal_MemCpy( (void*)Debug_Info, (const void*)resp.Debug_Info, 12 );
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_write_config_data( uint8_t Offset,
uint8_t Length,
const uint8_t* Value )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_write_config_data_cp0 *cp0 = (aci_write_config_data_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Offset = Offset;
index_input += 1;
cp0->Length = Length;
index_input += 1;
Osal_MemCpy( (void*)&cp0->Value, (const void*)Value, Length );
index_input += Length;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x302;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_read_config_data( uint8_t Offset,
uint8_t* Data_Length,
uint8_t* Data )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_read_config_data_cp0 *cp0 = (aci_read_config_data_cp0*)(cmd_buffer);
aci_read_config_data_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
int index_input = 0;
cp0->Offset = Offset;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x303;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
*Data_Length = resp.Data_Length;
Osal_MemCpy( (void*)Data, (const void*)resp.Data, *Data_Length);
return BLE_STATUS_SUCCESS;
}
@@ -0,0 +1,142 @@
/*****************************************************************************
* @file ble_gen_aci.h
* @brief STM32WB BLE API (GEN_ACI)
* Auto-generated file: do not edit!
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_GEN_ACI_H__
#define BLE_GEN_ACI_H__
#include "auto/ble_types.h"
/**
* @brief ACI_RESET
* This command resets the BLE stack (Host and LE Controller).
*
* @param Mode ACI reset mode.
* Values:
* - 0x00: Reset without BLE stack options change
* - 0x01: Reset with BLE stack option changes
* @param Options New BLE stack options to set at ACI reset (a bit set to 1
* means that the corresponding optional feature is activated).
* Flags:
* - 0x00000001: LL only mode
* - 0x00000002: No service change description
* - 0x00000004: Device Name is read-only
* - 0x00000008: Support of Extended Advertising
* - 0x00000010: Support of Channel Selection Algorithm #2
* - 0x00000020: Reduced GATT database in NVM
* - 0x00000040: Support of GATT caching
* - 0x00000080: Support of LE Power Class 1 (flag not available in RCP
* mode)
* - 0x00000100: Appearance is writable
* - 0x00000200: Support of Enhanced ATT
* @return Value indicating success or error code.
*/
tBleStatus aci_reset( uint8_t Mode,
uint32_t Options );
/**
* @brief ACI_GET_INFORMATION
* This command reads the local ACI information.
*
* @param[out] Version BLE stack version.
* @param[out] Options Current BLE stack options (a bit set to 1 means that the
* corresponding optional feature is activated).
* Flags:
* - 0x00000001: LL only mode
* - 0x00000002: No service change description
* - 0x00000004: Device Name is read-only
* - 0x00000008: Support of Extended Advertising
* - 0x00000010: Support of Channel Selection Algorithm #2
* - 0x00000020: Reduced GATT database in NVM
* - 0x00000040: Support of GATT caching
* - 0x00000080: Support of LE Power Class 1 (flag not available in RCP
* mode)
* - 0x00000100: Appearance is writable
* - 0x00000200: Support of Enhanced ATT
* @param[out] Debug_Info BLE stack debug information.
* @return Value indicating success or error code.
*/
tBleStatus aci_get_information( uint32_t* Version,
uint32_t* Options,
uint32_t* Debug_Info );
/**
* @brief ACI_WRITE_CONFIG_DATA
* This command writes a value to a configure data structure. It is useful to
* setup directly some parameters for the BLE stack.
* Refer to Annex for details on the different parameters that can be
* configured.
*
* @param Offset Offset of the element in the configuration data structure
* which has to be written.
* Values:
* - 0x00: CONFIG_DATA_PUBLIC_ADDRESS_OFFSET;
* Bluetooth public address; 6 bytes
* - 0x08: CONFIG_DATA_ER_OFFSET;
* Encryption root key; 16 bytes
* - 0x18: CONFIG_DATA_IR_OFFSET;
* Identity root key; 16 bytes
* - 0x2E: CONFIG_DATA_RANDOM_ADDRESS_OFFSET;
* Static Random Address; 6 bytes
* - 0x34: CONFIG_DATA_GAP_ADD_REC_NBR_OFFSET;
* GAP service additional record number; 1 byte
* - 0x35: CONFIG_DATA_SC_KEY_TYPE_OFFSET;
* Secure Connections key type; 1 byte
* - 0xB0: CONFIG_DATA_SMP_MODE_OFFSET;
* SMP mode; 1 byte
* - 0xC0: CONFIG_DATA_LL_SCAN_CHAN_MAP_OFFSET;
* LL scan channel map; 1 byte
* - 0xC1: CONFIG_DATA_LL_BG_SCAN_MODE_OFFSET;
* LL background scan mode; 1 byte
* - 0xC3: CONFIG_DATA_LL_RPA_MODE_OFFSET;
* LL RPA mode; 1 byte
* - 0xD1: CONFIG_DATA_LL_MAX_DATA_EXT_OFFSET [only for full stack];
* LL maximum data length extension; 8 bytes
* @param Length Length of data to be written
* @param Value Data to be written
* @return Value indicating success or error code.
*/
tBleStatus aci_write_config_data( uint8_t Offset,
uint8_t Length,
const uint8_t* Value );
/**
* @brief ACI_READ_CONFIG_DATA
* This command requests the value in the configure data structure. The number
* of read bytes changes for different Offset.
*
* @param Offset Offset of the element in the configuration data structure
* which has to be read.
* Values:
* - 0x00: CONFIG_DATA_PUBLIC_ADDRESS_OFFSET;
* Bluetooth public address; 6 bytes
* - 0x08: CONFIG_DATA_ER_OFFSET;
* Encryption root key used to derive LTK (legacy) and CSRK; 16 bytes
* - 0x18: CONFIG_DATA_IR_OFFSET
* Identity root key used to derive DHK (legacy) and IRK; 16 bytes
* - 0x2E: CONFIG_DATA_RANDOM_ADDRESS_OFFSET;
* Static Random Address; 6 bytes
* @param[out] Data_Length Length of Data in octets
* @param[out] Data Data field associated with Offset parameter
* @return Value indicating success or error code.
*/
tBleStatus aci_read_config_data( uint8_t Offset,
uint8_t* Data_Length,
uint8_t* Data );
#endif /* BLE_GEN_ACI_H__ */
@@ -0,0 +1,418 @@
/*****************************************************************************
* @file ble_hal_aci.c
* @brief STM32WB BLE API (hal_aci)
* Auto-generated file: do not edit!
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#include "auto/ble_hal_aci.h"
tBleStatus aci_hal_write_config_data( uint8_t Offset,
uint8_t Length,
const uint8_t* Value )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_write_config_data_cp0 *cp0 = (aci_hal_write_config_data_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Offset = Offset;
index_input += 1;
cp0->Length = Length;
index_input += 1;
Osal_MemCpy( (void*)&cp0->Value, (const void*)Value, Length );
index_input += Length;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x00c;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_hal_read_config_data( uint8_t Offset,
uint8_t* Data_Length,
uint8_t* Data )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_read_config_data_cp0 *cp0 = (aci_hal_read_config_data_cp0*)(cmd_buffer);
aci_hal_read_config_data_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
int index_input = 0;
cp0->Offset = Offset;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x00d;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
*Data_Length = resp.Data_Length;
Osal_MemCpy( (void*)Data, (const void*)resp.Data, *Data_Length);
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_hal_set_tx_power_level( uint8_t En_High_Power,
uint8_t PA_Level )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_set_tx_power_level_cp0 *cp0 = (aci_hal_set_tx_power_level_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->En_High_Power = En_High_Power;
index_input += 1;
cp0->PA_Level = PA_Level;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x00f;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_hal_le_tx_test_packet_number( uint32_t* Number_Of_Packets )
{
struct hci_request rq;
aci_hal_le_tx_test_packet_number_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x014;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
*Number_Of_Packets = resp.Number_Of_Packets;
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_hal_tone_start( uint8_t RF_Channel,
uint8_t Freq_offset )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_tone_start_cp0 *cp0 = (aci_hal_tone_start_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->RF_Channel = RF_Channel;
index_input += 1;
cp0->Freq_offset = Freq_offset;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x015;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_hal_tone_stop( void )
{
struct hci_request rq;
tBleStatus status = 0;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x016;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_hal_get_link_status( uint8_t* Link_Status,
uint16_t* Link_Connection_Handle )
{
struct hci_request rq;
aci_hal_get_link_status_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x017;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
Osal_MemCpy( (void*)Link_Status, (const void*)resp.Link_Status, 8 );
Osal_MemCpy( (void*)Link_Connection_Handle, (const void*)resp.Link_Connection_Handle, 16 );
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_hal_set_radio_activity_mask( uint16_t Radio_Activity_Mask )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_set_radio_activity_mask_cp0 *cp0 = (aci_hal_set_radio_activity_mask_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Radio_Activity_Mask = Radio_Activity_Mask;
index_input += 2;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x018;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_hal_get_anchor_period( uint32_t* Anchor_Period,
uint32_t* Max_Free_Slot )
{
struct hci_request rq;
aci_hal_get_anchor_period_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x019;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
*Anchor_Period = resp.Anchor_Period;
*Max_Free_Slot = resp.Max_Free_Slot;
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_hal_set_event_mask( uint32_t Event_Mask )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_set_event_mask_cp0 *cp0 = (aci_hal_set_event_mask_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Event_Mask = Event_Mask;
index_input += 4;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x01a;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_hal_set_peripheral_latency( uint8_t Enable )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_set_peripheral_latency_cp0 *cp0 = (aci_hal_set_peripheral_latency_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Enable = Enable;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x020;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_hal_read_rssi( uint8_t* RSSI )
{
struct hci_request rq;
aci_hal_read_rssi_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x022;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
*RSSI = resp.RSSI;
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_hal_ead_encrypt_decrypt( uint8_t Mode,
const uint8_t* Key,
const uint8_t* IV,
uint16_t In_Data_Length,
const uint8_t* In_Data,
uint16_t* Out_Data_Length,
uint8_t* Out_Data )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_ead_encrypt_decrypt_cp0 *cp0 = (aci_hal_ead_encrypt_decrypt_cp0*)(cmd_buffer);
aci_hal_ead_encrypt_decrypt_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
int index_input = 0;
cp0->Mode = Mode;
index_input += 1;
Osal_MemCpy( (void*)&cp0->Key, (const void*)Key, 16 );
index_input += 16;
Osal_MemCpy( (void*)&cp0->IV, (const void*)IV, 8 );
index_input += 8;
cp0->In_Data_Length = In_Data_Length;
index_input += 2;
Osal_MemCpy( (void*)&cp0->In_Data, (const void*)In_Data, In_Data_Length );
index_input += In_Data_Length;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x02f;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
*Out_Data_Length = resp.Out_Data_Length;
Osal_MemCpy( (void*)Out_Data, (const void*)resp.Out_Data, *Out_Data_Length);
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_hal_read_radio_reg( uint8_t Register_Address,
uint8_t* reg_val )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_read_radio_reg_cp0 *cp0 = (aci_hal_read_radio_reg_cp0*)(cmd_buffer);
aci_hal_read_radio_reg_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
int index_input = 0;
cp0->Register_Address = Register_Address;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x030;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
*reg_val = resp.reg_val;
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_hal_write_radio_reg( uint8_t Register_Address,
uint8_t Register_Value )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_write_radio_reg_cp0 *cp0 = (aci_hal_write_radio_reg_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Register_Address = Register_Address;
index_input += 1;
cp0->Register_Value = Register_Value;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x031;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_hal_read_raw_rssi( uint8_t* Value )
{
struct hci_request rq;
aci_hal_read_raw_rssi_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x032;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
Osal_MemCpy( (void*)Value, (const void*)resp.Value, 3 );
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_hal_rx_start( uint8_t RF_Channel )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_hal_rx_start_cp0 *cp0 = (aci_hal_rx_start_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->RF_Channel = RF_Channel;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x033;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_hal_rx_stop( void )
{
struct hci_request rq;
tBleStatus status = 0;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x034;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
@@ -0,0 +1,361 @@
/*****************************************************************************
* @file ble_hal_aci.h
* @brief STM32WB BLE API (HAL_ACI)
* Auto-generated file: do not edit!
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_HAL_ACI_H__
#define BLE_HAL_ACI_H__
#include "auto/ble_types.h"
/**
* @brief ACI_HAL_WRITE_CONFIG_DATA
* This command writes a value to a configure data structure. It is useful to
* setup directly some parameters for the BLE stack.
* Refer to Annex for details on the different parameters that can be
* configured.
* Note: this command is an alias of ACI_WRITE_CONFIG_DATA.
*
* @param Offset Offset of the element in the configuration data structure
* which has to be written.
* Values:
* - 0x00: CONFIG_DATA_PUBLIC_ADDRESS_OFFSET;
* Bluetooth public address; 6 bytes
* - 0x08: CONFIG_DATA_ER_OFFSET;
* Encryption root key; 16 bytes
* - 0x18: CONFIG_DATA_IR_OFFSET;
* Identity root key; 16 bytes
* - 0x2E: CONFIG_DATA_RANDOM_ADDRESS_OFFSET;
* Static Random Address; 6 bytes
* - 0x34: CONFIG_DATA_GAP_ADD_REC_NBR_OFFSET;
* GAP service additional record number; 1 byte
* - 0x35: CONFIG_DATA_SC_KEY_TYPE_OFFSET;
* Secure Connections key type; 1 byte
* - 0xB0: CONFIG_DATA_SMP_MODE_OFFSET;
* SMP mode; 1 byte
* - 0xC0: CONFIG_DATA_LL_SCAN_CHAN_MAP_OFFSET;
* LL scan channel map; 1 byte
* - 0xC1: CONFIG_DATA_LL_BG_SCAN_MODE_OFFSET;
* LL background scan mode; 1 byte
* - 0xC3: CONFIG_DATA_LL_RPA_MODE_OFFSET;
* LL RPA mode; 1 byte
* - 0xD1: CONFIG_DATA_LL_MAX_DATA_EXT_OFFSET [only for full stack];
* LL maximum data length extension; 8 bytes
* @param Length Length of data to be written
* @param Value Data to be written
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_write_config_data( uint8_t Offset,
uint8_t Length,
const uint8_t* Value );
/**
* @brief ACI_HAL_READ_CONFIG_DATA
* This command requests the value in the configure data structure. The number
* of read bytes changes for different Offset.
* Note: this command is an alias of ACI_READ_CONFIG_DATA.
*
* @param Offset Offset of the element in the configuration data structure
* which has to be read.
* Values:
* - 0x00: CONFIG_DATA_PUBLIC_ADDRESS_OFFSET;
* Bluetooth public address; 6 bytes
* - 0x08: CONFIG_DATA_ER_OFFSET;
* Encryption root key used to derive LTK (legacy) and CSRK; 16 bytes
* - 0x18: CONFIG_DATA_IR_OFFSET
* Identity root key used to derive DHK (legacy) and IRK; 16 bytes
* - 0x2E: CONFIG_DATA_RANDOM_ADDRESS_OFFSET;
* Static Random Address; 6 bytes
* @param[out] Data_Length Length of Data in octets
* @param[out] Data Data field associated with Offset parameter
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_read_config_data( uint8_t Offset,
uint8_t* Data_Length,
uint8_t* Data );
/**
* @brief ACI_HAL_SET_TX_POWER_LEVEL
* This command sets the TX power level of the device. By controlling the PA
* level, that determines the output power level (dBm) at the IC pin.
* When the system starts up or reboots, the default TX power level is used,
* which is the maximum value. Once this command is given, the output power
* changes instantly, regardless if there is BLE communication going on or not.
* For example, for debugging purpose, the device can be set to advertise all
* the time. By using this command, one can then observe the evolution of the
* TX signal strength.
* The system keeps the last received TX power level from the command, i.e. the
* 2nd command overwrites the previous TX power level. The new TX power level
* remains until another ACI_HAL_SET_TX_POWER_LEVEL command, or the system
* reboots. However, note that the advertising extensions commands allow, per
* advertising set, to override the value of TX power determined by
* ACI_HAL_SET_TX_POWER_LEVEL command (e.g. see ACI_GAP_ADV_SET_CONFIGURATION).
* Refer to Annex for the dBm corresponding values of PA_Level parameter.
*
* @param En_High_Power Enable High Power mode - Deprecated and ignored
* Values:
* - 0x00: Standard Power
* - 0x01: High Power
* @param PA_Level Power amplifier output level.
* Values:
* - 0x00 ... 0x23
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_set_tx_power_level( uint8_t En_High_Power,
uint8_t PA_Level );
/**
* @brief ACI_HAL_LE_TX_TEST_PACKET_NUMBER
* This command returns the number of packets sent in Direct Test Mode.
* When the Direct TX test is started, a 16-bit counter is used to count how
* many packets have been transmitted.
* This command can be used to check how many packets have been sent during the
* Direct TX test.
* The counter starts from 0 and counts upwards. The counter can wrap and start
* from 0 again. The counter is not cleared until the next Direct TX test
* starts.
*
* @param[out] Number_Of_Packets Number of packets sent during the last Direct
* TX test.
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_le_tx_test_packet_number( uint32_t* Number_Of_Packets );
/**
* @brief ACI_HAL_TONE_START
* This command starts a carrier frequency, i.e. a tone, on a specific channel.
* The frequency sine wave at the specific channel may be used for debugging
* purpose only. The channel ID is a parameter from 0x00 to 0x27 for the 40 BLE
* channels, e.g. 0x00 for 2.402 GHz, 0x01 for 2.404 GHz etc.
* This command should not be used when normal BLE activities are ongoing.
* The tone should be stopped by ACI_HAL_TONE_STOP command.
*
* @param RF_Channel BLE Channel ID, from 0x00 to 0x27 meaning (2.402 +
* 0.002*0xXX) GHz
* Device will continuously emit 0s, that means that the tone will be at
* the channel center frequency minus the maximum frequency deviation
* (250 kHz).
* Values:
* - 0x00 ... 0x27
* @param Freq_offset Frequency Offset for tone channel
* Values:
* - 0x00 ... 0xFF
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_tone_start( uint8_t RF_Channel,
uint8_t Freq_offset );
/**
* @brief ACI_HAL_TONE_STOP
* This command is used to stop the previously started ACI_HAL_TONE_START
* command.
*
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_tone_stop( void );
/**
* @brief ACI_HAL_GET_LINK_STATUS
* This command returns the status of the 8 BLE links managed by the device.
*
* @param[out] Link_Status Array of link status (8 links). Each link status is
* 1 byte.
* Values:
* - 0x00: Idle
* - 0x01: Advertising
* - 0x02: Connected in Peripheral role
* - 0x03: Scanning
* - 0x04: Reserved
* - 0x05: Connected in Central role
* - 0x06: TX test mode
* - 0x07: RX test mode
* - 0x81: Advertising with Additional Beacon
* @param[out] Link_Connection_Handle Array of connection handles (2 bytes) for
* 8 links. Valid only if the link status is "connected" (0x02 or 0x05)
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_get_link_status( uint8_t* Link_Status,
uint16_t* Link_Connection_Handle );
/**
* @brief ACI_HAL_SET_RADIO_ACTIVITY_MASK
* This command set the bitmask associated to
* ACI_HAL_END_OF_RADIO_ACTIVITY_EVENT.
* Only the radio activities enabled in the mask will be reported to
* application by ACI_HAL_END_OF_RADIO_ACTIVITY_EVENT
*
* @param Radio_Activity_Mask Bitmask of radio events
* Flags:
* - 0x0001: Idle
* - 0x0002: Advertising
* - 0x0004: Peripheral connection
* - 0x0008: Scanning
* - 0x0020: Central connection
* - 0x0040: TX test mode
* - 0x0080: RX test mode
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_set_radio_activity_mask( uint16_t Radio_Activity_Mask );
/**
* @brief ACI_HAL_GET_ANCHOR_PERIOD
* This command returns information about the Anchor Period to help application
* in selecting slot timings when operating in multi-link scenarios.
*
* @param[out] Anchor_Period Current anchor period.
* T = N * 0.625 ms.
* @param[out] Max_Free_Slot Maximum available time that can be allocated for a
* new slot.
* T = N * 0.625 ms.
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_get_anchor_period( uint32_t* Anchor_Period,
uint32_t* Max_Free_Slot );
/**
* @brief ACI_HAL_SET_EVENT_MASK
* This command is used to enable/disable the generation of HAL events. If the
* bit in the Event_Mask is set to a one, then the event associated with that
* bit will be enabled.
*
* @param Event_Mask ACI HAL event mask. Default: 0x00000000.
* Flags:
* - 0x00000000: No events specified (Default)
* - 0x00000001: ACI_HAL_SCAN_REQ_REPORT_EVENT
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_set_event_mask( uint32_t Event_Mask );
/**
* @brief ACI_HAL_SET_PERIPHERAL_LATENCY
* This command is used to disable/enable the Peripheral latency feature during
* a connection. Note that, by default, the Peripheral latency is enabled at
* connection time.
*
* @param Enable Enable/disable Peripheral latency.
* Values:
* - 0x00: Peripheral latency is disabled
* - 0x01: Peripheral latency is enabled
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_set_peripheral_latency( uint8_t Enable );
/**
* @brief ACI_HAL_READ_RSSI
* This command returns the value of the RSSI.
*
* @param[out] RSSI RSSI (signed integer).
* Units: dBm.
* Values:
* - 127: RSSI not available
* - -127 ... 20
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_read_rssi( uint8_t* RSSI );
/**
* @brief ACI_HAL_EAD_ENCRYPT_DECRYPT
* This command encrypts or decrypts data following the Encrypted Advertising
* Data scheme.
* When encryption mode is selected, In_Data shall only contain the Payload
* field to encrypt. The command adds the Randomizer and MIC fields in the
* result. The result data length (Out_Data_Length) is equal to the input
* length plus 9.
* When decryption mode is selected, In_Data shall contain the full Encrypted
* Data (Randomizer + Payload + MIC). The result data length (Out_Data_Length)
* is equal to the input length minus 9.
* If the decryption fails, the returned status is BLE_STATUS_FAILED, otherwise
* it is BLE_STATUS_SUCCESS.
* Note: the In_Data_Length value must not exceed (BLE_CMD_MAX_PARAM_LEN - 27)
* i.e. 228 for BLE_CMD_MAX_PARAM_LEN default value.
*
* @param Mode EAD operation mode: encryption or decryption.
* Values:
* - 0x00: Encryption
* - 0x01: Decryption
* @param Key Session key used for EAD operation (in Little Endian format).
* @param IV Initialization vector used for EAD operation (in Little Endian
* format).
* @param In_Data_Length Length of input data
* @param In_Data Input data
* @param[out] Out_Data_Length Length of result data
* @param[out] Out_Data Result data
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_ead_encrypt_decrypt( uint8_t Mode,
const uint8_t* Key,
const uint8_t* IV,
uint16_t In_Data_Length,
const uint8_t* In_Data,
uint16_t* Out_Data_Length,
uint8_t* Out_Data );
/**
* @brief ACI_HAL_READ_RADIO_REG
* This command Reads Register value from the RF module.
*
* @param Register_Address Address of the register to be read
* @param[out] reg_val Register value
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_read_radio_reg( uint8_t Register_Address,
uint8_t* reg_val );
/**
* @brief ACI_HAL_WRITE_RADIO_REG
* This command writes Register value to the RF module.
*
* @param Register_Address Address of the register to be written
* @param Register_Value Value to be written
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_write_radio_reg( uint8_t Register_Address,
uint8_t Register_Value );
/**
* @brief ACI_HAL_READ_RAW_RSSI
* This command returns the raw value of the RSSI.
*
* @param[out] Value RAW RSSI value
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_read_raw_rssi( uint8_t* Value );
/**
* @brief ACI_HAL_RX_START
* This command does set up the RF to listen to a specific RF channel.
*
* @param RF_Channel BLE Channel ID, from 0x00 to 0x27 meaning (2.402 +
* 0.002*0xXX) GHz
* Device will continuously emit 0s, that means that the tone will be at
* the channel center frequency minus the maximum frequency deviation
* (250 kHz).
* Values:
* - 0x00 ... 0x27
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_rx_start( uint8_t RF_Channel );
/**
* @brief ACI_HAL_RX_STOP
* This command stops a previous ACI_HAL_RX_START command.
*
* @return Value indicating success or error code.
*/
tBleStatus aci_hal_rx_stop( void );
#endif /* BLE_HAL_ACI_H__ */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,306 @@
/*****************************************************************************
* @file ble_l2cap_aci.c
* @brief STM32WB BLE API (l2cap_aci)
* Auto-generated file: do not edit!
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#include "auto/ble_l2cap_aci.h"
tBleStatus aci_l2cap_connection_parameter_update_req( uint16_t Connection_Handle,
uint16_t Conn_Interval_Min,
uint16_t Conn_Interval_Max,
uint16_t Latency,
uint16_t Timeout_Multiplier )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_l2cap_connection_parameter_update_req_cp0 *cp0 = (aci_l2cap_connection_parameter_update_req_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Connection_Handle = Connection_Handle;
index_input += 2;
cp0->Conn_Interval_Min = Conn_Interval_Min;
index_input += 2;
cp0->Conn_Interval_Max = Conn_Interval_Max;
index_input += 2;
cp0->Latency = Latency;
index_input += 2;
cp0->Timeout_Multiplier = Timeout_Multiplier;
index_input += 2;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x181;
rq.event = 0x0F;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_l2cap_connection_parameter_update_resp( uint16_t Connection_Handle,
uint16_t Conn_Interval_Min,
uint16_t Conn_Interval_Max,
uint16_t Latency,
uint16_t Timeout_Multiplier,
uint16_t Minimum_CE_Length,
uint16_t Maximum_CE_Length,
uint8_t Identifier,
uint8_t Accept )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_l2cap_connection_parameter_update_resp_cp0 *cp0 = (aci_l2cap_connection_parameter_update_resp_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Connection_Handle = Connection_Handle;
index_input += 2;
cp0->Conn_Interval_Min = Conn_Interval_Min;
index_input += 2;
cp0->Conn_Interval_Max = Conn_Interval_Max;
index_input += 2;
cp0->Latency = Latency;
index_input += 2;
cp0->Timeout_Multiplier = Timeout_Multiplier;
index_input += 2;
cp0->Minimum_CE_Length = Minimum_CE_Length;
index_input += 2;
cp0->Maximum_CE_Length = Maximum_CE_Length;
index_input += 2;
cp0->Identifier = Identifier;
index_input += 1;
cp0->Accept = Accept;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x182;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_l2cap_coc_connect( uint16_t Connection_Handle,
uint16_t SPSM,
uint16_t MTU,
uint16_t MPS,
uint16_t Initial_Credits,
uint8_t Channel_Number )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_l2cap_coc_connect_cp0 *cp0 = (aci_l2cap_coc_connect_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Connection_Handle = Connection_Handle;
index_input += 2;
cp0->SPSM = SPSM;
index_input += 2;
cp0->MTU = MTU;
index_input += 2;
cp0->MPS = MPS;
index_input += 2;
cp0->Initial_Credits = Initial_Credits;
index_input += 2;
cp0->Channel_Number = Channel_Number;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x188;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_l2cap_coc_connect_confirm( uint16_t Connection_Handle,
uint16_t MTU,
uint16_t MPS,
uint16_t Initial_Credits,
uint16_t Result,
uint8_t Max_Channel_Number,
uint8_t* Channel_Number,
uint8_t* Channel_Index_List )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_l2cap_coc_connect_confirm_cp0 *cp0 = (aci_l2cap_coc_connect_confirm_cp0*)(cmd_buffer);
aci_l2cap_coc_connect_confirm_rp0 resp;
Osal_MemSet( &resp, 0, sizeof(resp) );
int index_input = 0;
cp0->Connection_Handle = Connection_Handle;
index_input += 2;
cp0->MTU = MTU;
index_input += 2;
cp0->MPS = MPS;
index_input += 2;
cp0->Initial_Credits = Initial_Credits;
index_input += 2;
cp0->Result = Result;
index_input += 2;
cp0->Max_Channel_Number = Max_Channel_Number;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x189;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &resp;
rq.rlen = sizeof(resp);
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
if ( resp.Status )
return resp.Status;
*Channel_Number = resp.Channel_Number;
Osal_MemCpy( (void*)Channel_Index_List, (const void*)resp.Channel_Index_List, *Channel_Number);
return BLE_STATUS_SUCCESS;
}
tBleStatus aci_l2cap_coc_reconf( uint16_t Connection_Handle,
uint16_t MTU,
uint16_t MPS,
uint8_t Channel_Number,
const uint8_t* Channel_Index_List )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_l2cap_coc_reconf_cp0 *cp0 = (aci_l2cap_coc_reconf_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Connection_Handle = Connection_Handle;
index_input += 2;
cp0->MTU = MTU;
index_input += 2;
cp0->MPS = MPS;
index_input += 2;
cp0->Channel_Number = Channel_Number;
index_input += 1;
Osal_MemCpy( (void*)&cp0->Channel_Index_List, (const void*)Channel_Index_List, Channel_Number );
index_input += Channel_Number;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x18a;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_l2cap_coc_reconf_confirm( uint16_t Connection_Handle,
uint16_t Result )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_l2cap_coc_reconf_confirm_cp0 *cp0 = (aci_l2cap_coc_reconf_confirm_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Connection_Handle = Connection_Handle;
index_input += 2;
cp0->Result = Result;
index_input += 2;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x18b;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_l2cap_coc_disconnect( uint8_t Channel_Index )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_l2cap_coc_disconnect_cp0 *cp0 = (aci_l2cap_coc_disconnect_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Channel_Index = Channel_Index;
index_input += 1;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x18c;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_l2cap_coc_flow_control( uint8_t Channel_Index,
uint16_t Credits )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_l2cap_coc_flow_control_cp0 *cp0 = (aci_l2cap_coc_flow_control_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Channel_Index = Channel_Index;
index_input += 1;
cp0->Credits = Credits;
index_input += 2;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x18d;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_l2cap_coc_tx_data( uint8_t Channel_Index,
uint16_t Length,
const uint8_t* Data )
{
struct hci_request rq;
uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN];
aci_l2cap_coc_tx_data_cp0 *cp0 = (aci_l2cap_coc_tx_data_cp0*)(cmd_buffer);
tBleStatus status = 0;
int index_input = 0;
cp0->Channel_Index = Channel_Index;
index_input += 1;
cp0->Length = Length;
index_input += 2;
Osal_MemCpy( (void*)&cp0->Data, (const void*)Data, Length );
index_input += Length;
Osal_MemSet( &rq, 0, sizeof(rq) );
rq.ogf = 0x3f;
rq.ocf = 0x18e;
rq.cparam = cmd_buffer;
rq.clen = index_input;
rq.rparam = &status;
rq.rlen = 1;
if ( hci_send_req(&rq, FALSE) < 0 )
return BLE_STATUS_TIMEOUT;
return status;
}
@@ -0,0 +1,304 @@
/*****************************************************************************
* @file ble_l2cap_aci.h
* @brief STM32WB BLE API (L2CAP_ACI)
* Auto-generated file: do not edit!
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_L2CAP_ACI_H__
#define BLE_L2CAP_ACI_H__
#include "auto/ble_types.h"
/**
* @brief ACI_L2CAP_CONNECTION_PARAMETER_UPDATE_REQ
* Sends an L2CAP connection parameter update request from the Peripheral to
* the Central.
* An ACI_L2CAP_CONNECTION_UPDATE_RESP_EVENT event is raised when the Central
* responds to the request (accepts or rejects).
*
* @param Connection_Handle Connection handle for which the command applies.
* Values:
* - 0x0000 ... 0x0EFF
* @param Conn_Interval_Min Minimum value for the connection event interval.
* Time = N * 1.25 ms.
* Values:
* - 0x0006 (7.50 ms) ... 0x0C80 (4000.00 ms)
* @param Conn_Interval_Max Maximum value for the connection event interval.
* Time = N * 1.25 ms.
* Values:
* - 0x0006 (7.50 ms) ... 0x0C80 (4000.00 ms)
* @param Latency Maximum Peripheral latency for the connection in number of
* connection events.
* Values:
* - 0x0000 ... 0x01F3
* @param Timeout_Multiplier Defines connection timeout parameter in the
* following manner: Timeout Multiplier * 10ms.
* @return Value indicating success or error code.
*/
tBleStatus aci_l2cap_connection_parameter_update_req( uint16_t Connection_Handle,
uint16_t Conn_Interval_Min,
uint16_t Conn_Interval_Max,
uint16_t Latency,
uint16_t Timeout_Multiplier );
/**
* @brief ACI_L2CAP_CONNECTION_PARAMETER_UPDATE_RESP
* Accepts or rejects a connection update. This command should be sent in
* response to an ACI_L2CAP_CONNECTION_UPDATE_REQ_EVENT event from the
* controller. The accept parameter has to be set if the connection parameters
* given in the event are acceptable.
*
* @param Connection_Handle Connection handle for which the command applies.
* Values:
* - 0x0000 ... 0x0EFF
* @param Conn_Interval_Min Minimum value for the connection event interval.
* Time = N * 1.25 ms.
* Values:
* - 0x0006 (7.50 ms) ... 0x0C80 (4000.00 ms)
* @param Conn_Interval_Max Maximum value for the connection event interval.
* Time = N * 1.25 ms.
* Values:
* - 0x0006 (7.50 ms) ... 0x0C80 (4000.00 ms)
* @param Latency Maximum Peripheral latency for the connection in number of
* connection events.
* Values:
* - 0x0000 ... 0x01F3
* @param Timeout_Multiplier Defines connection timeout parameter in the
* following manner: Timeout Multiplier * 10ms.
* @param Minimum_CE_Length Information parameter about the minimum length of
* connection needed for this LE connection.
* Time = N * 0.625 ms.
* Values:
* - 0x0000 (0.000 ms) ... 0xFFFF (40959.375 ms)
* @param Maximum_CE_Length Information parameter about the maximum length of
* connection needed for this LE connection.
* Time = N * 0.625 ms.
* Values:
* - 0x0000 (0.000 ms) ... 0xFFFF (40959.375 ms)
* @param Identifier Received identifier.
* @param Accept Specify if connection update parameters are acceptable or not.
* Values:
* - 0x00: Reject
* - 0x01: Accept
* @return Value indicating success or error code.
*/
tBleStatus aci_l2cap_connection_parameter_update_resp( uint16_t Connection_Handle,
uint16_t Conn_Interval_Min,
uint16_t Conn_Interval_Max,
uint16_t Latency,
uint16_t Timeout_Multiplier,
uint16_t Minimum_CE_Length,
uint16_t Maximum_CE_Length,
uint8_t Identifier,
uint8_t Accept );
/**
* @brief ACI_L2CAP_COC_CONNECT
* This command sends a Credit Based Connection Request packet on the specified
* connection. See Core Specification [Vol 3, Part A].
*
* @param Connection_Handle Connection handle for which the command applies.
* Values:
* - 0x0000 ... 0x0EFF
* @param SPSM Simplified Protocol/Service Multiplexer.
* Values:
* - 0x0001 ... 0x00FF
* @param MTU Maximum Transmission Unit.
* Values:
* - 23 ... 65535
* - 64 ... 246: for Enhanced ATT
* @param MPS Maximum payload size (in octets).
* Values:
* - 23 ... 248
* - 64 ... 248: for Enhanced ATT
* @param Initial_Credits Number of K-frames that can be received on the
* created channel(s) by the L2CAP layer entity sending this packet.
* Values:
* - 0 ... 65535
* @param Channel_Number Number of channels to be created. If this parameter is
* set to 0, it requests the creation of one LE credit based connection-
* oriented channel. Otherwise, it requests the creation of one or more
* enhanced credit based connection-oriented channels.
* Values:
* - 0 ... 5
* @return Value indicating success or error code.
*/
tBleStatus aci_l2cap_coc_connect( uint16_t Connection_Handle,
uint16_t SPSM,
uint16_t MTU,
uint16_t MPS,
uint16_t Initial_Credits,
uint8_t Channel_Number );
/**
* @brief ACI_L2CAP_COC_CONNECT_CONFIRM
* This command sends a Credit Based Connection Response packet. It must be
* used upon receipt of a connection request through an
* ACI_L2CAP_COC_CONNECT_EVENT event.
* By setting the Result parameter to 0x0000, the application can accept all
* connections or only some. In this case, the number of accepted connections
* depends on the Max_Channel_Number parameter. Note that if some connections
* are refused, the Result parameter is automatically modified by the BLE
* stack.
* By setting the Result parameter to a non-zero value, the application can
* refuse all connections. The Result value shall then be one of the
* "Connection refused" or "All connections refused" values.
* See Core Specification [Vol 3, Part A].
*
* @param Connection_Handle Connection handle for which the command applies.
* Values:
* - 0x0000 ... 0x0EFF
* @param MTU Maximum Transmission Unit.
* Values:
* - 23 ... 65535
* - 64 ... 246: for Enhanced ATT
* @param MPS Maximum payload size (in octets).
* Values:
* - 23 ... 248
* - 64 ... 248: for Enhanced ATT
* @param Initial_Credits Number of K-frames that can be received on the
* created channel(s) by the L2CAP layer entity sending this packet.
* Values:
* - 0 ... 65535
* @param Result Indicates the outcome of the request. See Core Specification
* [Vol 3, Part A, Table 4.16] for LE credit based connection-oriented
* channels, or [Vol 3, Part A, Table 4.17] for enhanced credit based
* connection-oriented channels.
* Values:
* - 0x0000 ... 0x000F
* @param Max_Channel_Number Indicates the maximum number of channels that can
* be created.
* Values:
* - 0x01 ... 0x05
* @param[out] Channel_Number Number of created channels. It is the length of
* Channel_Index_List.
* Values:
* - 0 ... 5
* @param[out] Channel_Index_List List of channel indexes for which the
* primitive applies.
* @return Value indicating success or error code.
*/
tBleStatus aci_l2cap_coc_connect_confirm( uint16_t Connection_Handle,
uint16_t MTU,
uint16_t MPS,
uint16_t Initial_Credits,
uint16_t Result,
uint8_t Max_Channel_Number,
uint8_t* Channel_Number,
uint8_t* Channel_Index_List );
/**
* @brief ACI_L2CAP_COC_RECONF
* This command sends a Credit Based Reconfigure Request packet on the
* specified connection. See Core Specification [Vol 3, Part A].
*
* @param Connection_Handle Connection handle for which the command applies.
* Values:
* - 0x0000 ... 0x0EFF
* @param MTU Maximum Transmission Unit.
* Values:
* - 23 ... 65535
* - 64 ... 246: for Enhanced ATT
* @param MPS Maximum payload size (in octets).
* Values:
* - 23 ... 248
* - 64 ... 248: for Enhanced ATT
* @param Channel_Number Number of created channels. It is the length of
* Channel_Index_List.
* Values:
* - 1 ... 5
* @param Channel_Index_List List of channel indexes for which the primitive
* applies.
* @return Value indicating success or error code.
*/
tBleStatus aci_l2cap_coc_reconf( uint16_t Connection_Handle,
uint16_t MTU,
uint16_t MPS,
uint8_t Channel_Number,
const uint8_t* Channel_Index_List );
/**
* @brief ACI_L2CAP_COC_RECONF_CONFIRM
* This command sends a Credit Based Reconfigure Response packet. It must be
* used upon receipt of a Credit Based Reconfigure Request through an
* ACI_L2CAP_COC_RECONF_EVENT event. A Result value of 0x0000 indicates success
* while a non-zero value indicates the request is refused.
* See Core Specification [Vol 3, Part A].
*
* @param Connection_Handle Connection handle for which the command applies.
* Values:
* - 0x0000 ... 0x0EFF
* @param Result Indicates the outcome of the request. See Core Specification
* [Vol 3, Part A, Table 4.18].
* Values:
* - 0x0000 ... 0x0004
* @return Value indicating success or error code.
*/
tBleStatus aci_l2cap_coc_reconf_confirm( uint16_t Connection_Handle,
uint16_t Result );
/**
* @brief ACI_L2CAP_COC_DISCONNECT
* This command sends a Disconnection Request signaling packet on the specified
* connection-oriented channel. See Core Specification [Vol 3, Part A].
* The ACI_L2CAP_COC_DISCONNECT_EVENT event is received when the disconnection
* of the channel is effective.
*
* @param Channel_Index Index of the connection-oriented channel for which the
* primitive applies.
* @return Value indicating success or error code.
*/
tBleStatus aci_l2cap_coc_disconnect( uint8_t Channel_Index );
/**
* @brief ACI_L2CAP_COC_FLOW_CONTROL
* This command sends a Flow Control Credit signaling packet on the specified
* connection-oriented channel. See Core Specification [Vol 3, Part A].
*
* @param Channel_Index Index of the connection-oriented channel for which the
* primitive applies.
* @param Credits Number of credits the receiving device can increment,
* corresponding to the number of K-frames that can be sent to the peer
* device sending the Flow Control Credit packet.
* Values:
* - 1 ... 65535
* @return Value indicating success or error code.
*/
tBleStatus aci_l2cap_coc_flow_control( uint8_t Channel_Index,
uint16_t Credits );
/**
* @brief ACI_L2CAP_COC_TX_DATA
* This command sends a K-frame packet on the specified connection-oriented
* channel. See Core Specification [Vol 3, Part A].
* Note: for the first K-frame of the SDU, the Information data shall contain
* the L2CAP SDU Length coded on two octets followed by the K-frame information
* payload. For the next K-frames of the SDU, the Information data shall only
* contain the K-frame information payload.
* The Length value must not exceed (BLE_CMD_MAX_PARAM_LEN - 3) i.e. 252 for
* BLE_CMD_MAX_PARAM_LEN default value.
*
* @param Channel_Index Index of the connection-oriented channel for which the
* primitive applies.
* @param Length Length of Data (in octets)
* @param Data Information data
* @return Value indicating success or error code.
*/
tBleStatus aci_l2cap_coc_tx_data( uint8_t Channel_Index,
uint16_t Length,
const uint8_t* Data );
#endif /* BLE_L2CAP_ACI_H__ */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,200 @@
/*****************************************************************************
* @file ble_vs_codes.h
* @brief STM32WB BLE API (vendor specific event codes)
* Auto-generated file: do not edit!
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_VS_CODES_H__
#define BLE_VS_CODES_H__
/* Vendor specific codes of ACI General events
*/
/* ACI_WARNING_EVENT code */
#define ACI_WARNING_VSEVT_CODE 0x0006U
/* Vendor specific codes of ACI GAP events
*/
/* ACI_GAP_LIMITED_DISCOVERABLE_EVENT code */
#define ACI_GAP_LIMITED_DISCOVERABLE_VSEVT_CODE 0x0400U
/* ACI_GAP_PAIRING_COMPLETE_EVENT code */
#define ACI_GAP_PAIRING_COMPLETE_VSEVT_CODE 0x0401U
/* ACI_GAP_PASS_KEY_REQ_EVENT code */
#define ACI_GAP_PASS_KEY_REQ_VSEVT_CODE 0x0402U
/* ACI_GAP_AUTHORIZATION_REQ_EVENT code */
#define ACI_GAP_AUTHORIZATION_REQ_VSEVT_CODE 0x0403U
/* ACI_GAP_BOND_LOST_EVENT code */
#define ACI_GAP_BOND_LOST_VSEVT_CODE 0x0405U
/* ACI_GAP_PROC_COMPLETE_EVENT code */
#define ACI_GAP_PROC_COMPLETE_VSEVT_CODE 0x0407U
/* ACI_GAP_ADDR_NOT_RESOLVED_EVENT code */
#define ACI_GAP_ADDR_NOT_RESOLVED_VSEVT_CODE 0x0408U
/* ACI_GAP_NUMERIC_COMPARISON_VALUE_EVENT code */
#define ACI_GAP_NUMERIC_COMPARISON_VALUE_VSEVT_CODE 0x0409U
/* ACI_GAP_KEYPRESS_NOTIFICATION_EVENT code */
#define ACI_GAP_KEYPRESS_NOTIFICATION_VSEVT_CODE 0x040AU
/* ACI_GAP_PAIRING_REQUEST_EVENT code */
#define ACI_GAP_PAIRING_REQUEST_VSEVT_CODE 0x040BU
/* Vendor specific codes of ACI GATT/ATT events
*/
/* ACI_GATT_ATTRIBUTE_MODIFIED_EVENT code */
#define ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE 0x0C01U
/* ACI_GATT_PROC_TIMEOUT_EVENT code */
#define ACI_GATT_PROC_TIMEOUT_VSEVT_CODE 0x0C02U
/* ACI_ATT_EXCHANGE_MTU_RESP_EVENT code */
#define ACI_ATT_EXCHANGE_MTU_RESP_VSEVT_CODE 0x0C03U
/* ACI_ATT_FIND_INFO_RESP_EVENT code */
#define ACI_ATT_FIND_INFO_RESP_VSEVT_CODE 0x0C04U
/* ACI_ATT_FIND_BY_TYPE_VALUE_RESP_EVENT code */
#define ACI_ATT_FIND_BY_TYPE_VALUE_RESP_VSEVT_CODE 0x0C05U
/* ACI_ATT_READ_BY_TYPE_RESP_EVENT code */
#define ACI_ATT_READ_BY_TYPE_RESP_VSEVT_CODE 0x0C06U
/* ACI_ATT_READ_RESP_EVENT code */
#define ACI_ATT_READ_RESP_VSEVT_CODE 0x0C07U
/* ACI_ATT_READ_BLOB_RESP_EVENT code */
#define ACI_ATT_READ_BLOB_RESP_VSEVT_CODE 0x0C08U
/* ACI_ATT_READ_MULTIPLE_RESP_EVENT code */
#define ACI_ATT_READ_MULTIPLE_RESP_VSEVT_CODE 0x0C09U
/* ACI_ATT_READ_BY_GROUP_TYPE_RESP_EVENT code */
#define ACI_ATT_READ_BY_GROUP_TYPE_RESP_VSEVT_CODE 0x0C0AU
/* ACI_ATT_PREPARE_WRITE_RESP_EVENT code */
#define ACI_ATT_PREPARE_WRITE_RESP_VSEVT_CODE 0x0C0CU
/* ACI_ATT_EXEC_WRITE_RESP_EVENT code */
#define ACI_ATT_EXEC_WRITE_RESP_VSEVT_CODE 0x0C0DU
/* ACI_GATT_INDICATION_EVENT code */
#define ACI_GATT_INDICATION_VSEVT_CODE 0x0C0EU
/* ACI_GATT_NOTIFICATION_EVENT code */
#define ACI_GATT_NOTIFICATION_VSEVT_CODE 0x0C0FU
/* ACI_GATT_PROC_COMPLETE_EVENT code */
#define ACI_GATT_PROC_COMPLETE_VSEVT_CODE 0x0C10U
/* ACI_GATT_ERROR_RESP_EVENT code */
#define ACI_GATT_ERROR_RESP_VSEVT_CODE 0x0C11U
/* ACI_GATT_DISC_READ_CHAR_BY_UUID_RESP_EVENT code */
#define ACI_GATT_DISC_READ_CHAR_BY_UUID_RESP_VSEVT_CODE 0x0C12U
/* ACI_GATT_WRITE_PERMIT_REQ_EVENT code */
#define ACI_GATT_WRITE_PERMIT_REQ_VSEVT_CODE 0x0C13U
/* ACI_GATT_READ_PERMIT_REQ_EVENT code */
#define ACI_GATT_READ_PERMIT_REQ_VSEVT_CODE 0x0C14U
/* ACI_GATT_READ_MULTI_PERMIT_REQ_EVENT code */
#define ACI_GATT_READ_MULTI_PERMIT_REQ_VSEVT_CODE 0x0C15U
/* ACI_GATT_TX_POOL_AVAILABLE_EVENT code */
#define ACI_GATT_TX_POOL_AVAILABLE_VSEVT_CODE 0x0C16U
/* ACI_GATT_SERVER_CONFIRMATION_EVENT code */
#define ACI_GATT_SERVER_CONFIRMATION_VSEVT_CODE 0x0C17U
/* ACI_GATT_PREPARE_WRITE_PERMIT_REQ_EVENT code */
#define ACI_GATT_PREPARE_WRITE_PERMIT_REQ_VSEVT_CODE 0x0C18U
/* ACI_GATT_EATT_BEARER_EVENT code */
#define ACI_GATT_EATT_BEARER_VSEVT_CODE 0x0C19U
/* ACI_GATT_MULT_NOTIFICATION_EVENT code */
#define ACI_GATT_MULT_NOTIFICATION_VSEVT_CODE 0x0C1AU
/* ACI_GATT_NOTIFICATION_COMPLETE_EVENT code */
#define ACI_GATT_NOTIFICATION_COMPLETE_VSEVT_CODE 0x0C1BU
/* ACI_GATT_READ_EXT_EVENT code */
#define ACI_GATT_READ_EXT_VSEVT_CODE 0x0C1DU
/* ACI_GATT_INDICATION_EXT_EVENT code */
#define ACI_GATT_INDICATION_EXT_VSEVT_CODE 0x0C1EU
/* ACI_GATT_NOTIFICATION_EXT_EVENT code */
#define ACI_GATT_NOTIFICATION_EXT_VSEVT_CODE 0x0C1FU
/* Vendor specific codes of ACI L2CAP events
*/
/* ACI_L2CAP_CONNECTION_UPDATE_RESP_EVENT code */
#define ACI_L2CAP_CONNECTION_UPDATE_RESP_VSEVT_CODE 0x0800U
/* ACI_L2CAP_PROC_TIMEOUT_EVENT code */
#define ACI_L2CAP_PROC_TIMEOUT_VSEVT_CODE 0x0801U
/* ACI_L2CAP_CONNECTION_UPDATE_REQ_EVENT code */
#define ACI_L2CAP_CONNECTION_UPDATE_REQ_VSEVT_CODE 0x0802U
/* ACI_L2CAP_COMMAND_REJECT_EVENT code */
#define ACI_L2CAP_COMMAND_REJECT_VSEVT_CODE 0x080AU
/* ACI_L2CAP_COC_CONNECT_EVENT code */
#define ACI_L2CAP_COC_CONNECT_VSEVT_CODE 0x0810U
/* ACI_L2CAP_COC_CONNECT_CONFIRM_EVENT code */
#define ACI_L2CAP_COC_CONNECT_CONFIRM_VSEVT_CODE 0x0811U
/* ACI_L2CAP_COC_RECONF_EVENT code */
#define ACI_L2CAP_COC_RECONF_VSEVT_CODE 0x0812U
/* ACI_L2CAP_COC_RECONF_CONFIRM_EVENT code */
#define ACI_L2CAP_COC_RECONF_CONFIRM_VSEVT_CODE 0x0813U
/* ACI_L2CAP_COC_DISCONNECT_EVENT code */
#define ACI_L2CAP_COC_DISCONNECT_VSEVT_CODE 0x0814U
/* ACI_L2CAP_COC_FLOW_CONTROL_EVENT code */
#define ACI_L2CAP_COC_FLOW_CONTROL_VSEVT_CODE 0x0815U
/* ACI_L2CAP_COC_RX_DATA_EVENT code */
#define ACI_L2CAP_COC_RX_DATA_VSEVT_CODE 0x0816U
/* ACI_L2CAP_COC_TX_POOL_AVAILABLE_EVENT code */
#define ACI_L2CAP_COC_TX_POOL_AVAILABLE_VSEVT_CODE 0x0817U
/* Vendor specific codes of ACI HAL events
*/
/* ACI_HAL_END_OF_RADIO_ACTIVITY_EVENT code */
#define ACI_HAL_END_OF_RADIO_ACTIVITY_VSEVT_CODE 0x1804U
/* ACI_HAL_SCAN_REQ_REPORT_EVENT code */
#define ACI_HAL_SCAN_REQ_REPORT_VSEVT_CODE 0x1805U
#endif /* BLE_VS_CODES_H__ */
@@ -0,0 +1,182 @@
/*****************************************************************************
* @file ble_bufsize.h
*
* @brief Definition of BLE stack buffers size
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_BUFSIZE_H__
#define BLE_BUFSIZE_H__
/*
* BLE_DEFAULT_ATT_MTU: minimum MTU value that GATT must support.
*/
#define BLE_DEFAULT_ATT_MTU 23
/*
* BLE_DEFAULT_MAX_ATT_SIZE: maximum attribute size.
*/
#define BLE_DEFAULT_MAX_ATT_SIZE 512
/*
* BLE_PREP_WRITE_X_ATT: compute how many Prepare Write Request are needed to
* write a characteristic with size 'max_att' when the used ATT_MTU value is
* equal to BLE_DEFAULT_ATT_MTU (23).
*/
#define BLE_PREP_WRITE_X_ATT(max_att) \
(DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2)
/*
* BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size.
*/
#define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \
BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE)
/*
* BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose
* an ATT packet with ATT_MTU=mtu.
*/
#define BLE_MEM_BLOCK_SIZE 32
#if (SLAVE_ONLY != 0) || (BASIC_FEATURES != 0)
#define BLE_MEM_BLOCK_X_PTX(n_link) 0
#else
#define BLE_MEM_BLOCK_X_PTX(n_link) (n_link)
#endif
#define BLE_MEM_BLOCK_X_TX(mtu) \
(DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1)
#define BLE_MEM_BLOCK_X_RX(mtu, n_link) \
((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1)
#define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \
(BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_PTX(n_link) + \
BLE_MEM_BLOCK_X_RX(mtu, n_link))
/*
* BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for
* secure connections
*/
#define BLE_MBLOCKS_SECURE_CONNECTIONS 4
/*
* BLE_MBLOCKS_CALC: minimum number of buffers needed by the stack.
* This is the minimum racomanded value and depends on:
* - pw: size of Prepare Write List
* - mtu: ATT_MTU size
* - n_link: maximum number of simultaneous connections
*/
#define BLE_MBLOCKS_CALC(pw, mtu, n_link) \
((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \
BLE_MBLOCKS_SECURE_CONNECTIONS))
/*
* BLE_FIXED_BUFFER_SIZE_BYTES:
* A part of the RAM, is dynamically allocated by initializing all the pointers
* defined in a global context variable "mem_alloc_ctx_p".
* This initialization is made in the Dynamic_allocator functions, which
* assign a portion of RAM given by the external application to the above
* mentioned "global pointers".
*
* The size of this Dynamic RAM is made of 2 main components:
* - a part that is parameters-dependent (num of links, GATT buffers, ...),
* and which value is made explicit by the following macro;
* - a part, that may be considered "fixed", i.e. independent from the above
* mentioned parameters.
*/
#if (BEACON_ONLY != 0)
#define BLE_FIXED_BUFFER_SIZE_BYTES 4200 /* Beacon only */
#elif (LL_ONLY_BASIC != 0)
#define BLE_FIXED_BUFFER_SIZE_BYTES 5960 /* LL only Basic*/
#elif (LL_ONLY != 0)
#define BLE_FIXED_BUFFER_SIZE_BYTES 6288 /* LL only Full */
#elif (SLAVE_ONLY != 0)
#define BLE_FIXED_BUFFER_SIZE_BYTES 6408 /* Peripheral only */
#elif (BASIC_FEATURES != 0)
#define BLE_FIXED_BUFFER_SIZE_BYTES 6928 /* Basic Features */
#else
#define BLE_FIXED_BUFFER_SIZE_BYTES 7212 /* Full stack */
#endif
/*
* BLE_PER_LINK_SIZE_BYTES: additional memory size used per link
*/
#if (BEACON_ONLY != 0)
#define BLE_PER_LINK_SIZE_BYTES 76 /* Beacon only */
#elif (LL_ONLY_BASIC != 0)
#define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Basic */
#elif (LL_ONLY != 0)
#define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Full */
#elif (SLAVE_ONLY != 0)
#define BLE_PER_LINK_SIZE_BYTES 392 /* Peripheral only */
#elif (BASIC_FEATURES != 0)
#define BLE_PER_LINK_SIZE_BYTES 420 /* Basic Features */
#else
#define BLE_PER_LINK_SIZE_BYTES 432 /* Full stack */
#endif
/*
* BLE_TOTAL_BUFFER_SIZE: this macro returns the amount of memory, in bytes,
* needed for the storage of data structures (except GATT database elements)
* whose size depends on the number of supported connections.
*
* @param n_link: Maximum number of simultaneous connections that the device
* will support. Valid values are from 1 to 8.
*
* @param mblocks_count: Number of memory blocks allocated for packets.
*/
#define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \
(16 + BLE_FIXED_BUFFER_SIZE_BYTES + \
(BLE_PER_LINK_SIZE_BYTES * (n_link)) + \
((BLE_MEM_BLOCK_SIZE + 8) * (mblocks_count)))
/*
* BLE_EXT_ADV_BUFFER_SIZE
* additional memory size used for Extended advertising;
* It has to be added to BLE_TOTAL_BUFFER_SIZE() if the Extended advertising
* feature is used.
*
* @param set_nbr: Maximum number of advertising sets.
* Valid values are from 1 to 8.
*
* @param data_len: Maximum size of advertising data.
* Valid values are from 31 to 1650.
*/
#define BLE_EXT_ADV_BUFFER_SIZE(set_nbr, data_len) \
(2512 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr)))
/*
* BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory,
* in bytes, needed for the storage of GATT database elements.
*
* @param num_gatt_attributes: Maximum number of Attributes (i.e. the number
* of characteristic + the number of characteristic values + the number of
* descriptors, excluding the services) that can be stored in the GATT
* database. Note that certain characteristics and relative descriptors are
* added automatically during device initialization so this parameters should
* be 9 plus the number of user Attributes
*
* @param num_gatt_services: Maximum number of Services that can be stored in
* the GATT database. Note that the GAP and GATT services are automatically
* added so this parameter should be 2 plus the number of user services
*
* @param att_value_array_size: Size of the storage area for Attribute values.
*/
#define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \
(((((att_value_array_size) - 1) | 3) + 1) + \
(40 * (num_gatt_attributes)) + (48 * (num_gatt_services)))
#endif /* BLE_BUFSIZE_H__ */
@@ -0,0 +1,43 @@
/*****************************************************************************
* @file ble_core.h
*
* @brief This file contains the definitions for BLE stack
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_CORE_H__
#define BLE_CORE_H__
/* BLE standard definitions */
#include "ble_std.h"
/* BLE stack API definitions */
#include "ble_defs.h"
#include "auto/ble_vs_codes.h"
#include "auto/ble_gen_aci.h"
#include "auto/ble_gap_aci.h"
#include "auto/ble_gatt_aci.h"
#include "auto/ble_l2cap_aci.h"
#include "auto/ble_hal_aci.h"
#include "auto/ble_hci_le.h"
#include "auto/ble_events.h"
/* BLE stack buffer size definitions */
#include "ble_bufsize.h"
/* BLE stack legacy definitions */
#include "ble_legacy.h"
#endif /* BLE_CORE_H__ */
@@ -0,0 +1,510 @@
/*****************************************************************************
* @file ble_defs.h
*
* @brief This file contains definitions used for BLE Stack interface.
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_DEFS_H__
#define BLE_DEFS_H__
/* ------------------------------------------------------------------------- */
/* Status codes */
/* Returned when the command has completed with success
*/
#define BLE_STATUS_SUCCESS 0x00U
/* The remote device in in the Blacklist and the pairing operation it requested
* cannot be performed.
*/
#define BLE_STATUS_DEV_IN_BLACKLIST 0x59U
/* CSRK not found during validation of an incoming signed packet
*/
#define BLE_STATUS_CSRK_NOT_FOUND 0x5AU
/* IRK not found (Currently not used)
*/
#define BLE_STATUS_IRK_NOT_FOUND 0x5BU
/* A search for a specific remote device was unsuccessful because no entry
* exists either into NVM Database or in volatile database.
*/
#define BLE_STATUS_DEV_NOT_FOUND 0x5CU
/* The remote device is not bonded, and no operations related to bonded devices
* may be performed (e.g. writing Gatt Client data).
*/
#define BLE_STATUS_DEV_NOT_BONDED 0x5EU
/* The attribute handle is invalid.
*/
#define BLE_STATUS_INVALID_HANDLE 0x60U
/* There aren't sufficient Attributes handles available for allocation during
* creation of Services, Characteristics or Descriptors.
*/
#define BLE_STATUS_OUT_OF_HANDLE 0x61U
/* The requested GATT operation is not allowed in this context/status or using
* the provided parameters.
* This is a specific GATT error, different from generic Not Allowed error,
* because it refers to specific GATT specifications/rules.
*/
#define BLE_STATUS_INVALID_OPERATION 0x62U
/* The requested operation failed for a temporary lack of resources
* (e.g. packet pool or timers), but it may be retried later when resources may
* become available (packets or timers may have been released by other
* consumers).
*/
#define BLE_STATUS_INSUFFICIENT_RESOURCES 0x64U
/* Notification/Indication can't be sent to the requested remote device because
* it doesn't satisfy the needed security permission.
*/
#define BLE_STATUS_SEC_PERMISSION_ERROR 0x65U
/* The address of the device could not be resolved using the IRK stored\n
*/
#define BLE_STATUS_ADDRESS_NOT_RESOLVED 0x70U
/* Returned when no valid slots are available
* (e.g. when there are no available state machines).
*/
#define BLE_STATUS_NO_VALID_SLOT 0x82U
/* The only slot available is not long enough to satisfy scan window request.
*/
#define BLE_STATUS_SCAN_WINDOW_SHORT 0x83U
/* Returned when the maximum requested interval to be allocated is shorter
* then the current anchor period and there is no submultiple for the
* current anchor period that is between the minimum and the maximum requested
* intervals.
*/
#define BLE_STATUS_NEW_INTERVAL_FAILED 0x84U
/* Returned when the maximum requested interval to be allocated is greater
* than the current anchor period and there is no multiple of the anchor
* period that is between the minimum and the maximum requested intervals.
*/
#define BLE_STATUS_INTERVAL_TOO_LARGE 0x85U
/* Returned when the current anchor period or a new one can be found that
* is compatible to the interval range requested by the new slot but the
* maximum available length that can be allocated is less than the minimum
* requested slot length.
*/
#define BLE_STATUS_LENGTH_FAILED 0x86U
/* The Host failed while performing the requested operation.
*/
#define BLE_STATUS_FAILED 0x91U
/* Invalid parameters in Host commands
*/
#define BLE_STATUS_INVALID_PARAMS 0x92U
/* The Host is already processing another request received in advance.
*/
#define BLE_STATUS_BUSY 0x93U
/* The operation requested cannot be completed immediately by the Host
* (usually because of lack of resources).
* The operation is generally put on hold by the caller and it's usually
* retried on later time.
*/
#define BLE_STATUS_PENDING 0x95U
/* The requested operation violates the logic of the called layer/function or
* the format of the data to be processed during the operation.
*/
#define BLE_STATUS_ERROR 0x97U
/* The requested operation failed because of lack of memory.
* Out of memory shall be returned for situations where memory will never
* become available again (e.g. ATT database)
*/
#define BLE_STATUS_OUT_OF_MEMORY 0x98U
/* Returned when a timeout occurs at BLE application interface
*/
#define BLE_STATUS_TIMEOUT 0xFFU
/* ------------------------------------------------------------------------- */
/* BLE stack options (Options)
* (ACI_RESET)
*/
#define BLE_OPTIONS_LL_ONLY 0x00000001UL
#define BLE_OPTIONS_NO_SVC_CHANGE_DESC 0x00000002UL
#define BLE_OPTIONS_DEV_NAME_READ_ONLY 0x00000004UL
#define BLE_OPTIONS_EXTENDED_ADV 0x00000008UL
#define BLE_OPTIONS_CS_ALGO_2 0x00000010UL
#define BLE_OPTIONS_REDUCED_DB_IN_NVM 0x00000020UL
#define BLE_OPTIONS_GATT_CACHING 0x00000040UL
#define BLE_OPTIONS_POWER_CLASS_1 0x00000080UL
#define BLE_OPTIONS_APPEARANCE_WRITABLE 0x00000100UL
#define BLE_OPTIONS_ENHANCED_ATT 0x00000200UL
/* ------------------------------------------------------------------------- */
/* Characteristic value lengths
*/
#define DEVICE_NAME_CHARACTERISTIC_LEN 8
#define APPEARANCE_CHARACTERISTIC_LEN 2
#define PERIPHERAL_PRIVACY_CHARACTERISTIC_LEN 1
#define RECONNECTION_ADDR_CHARACTERISTIC_LEN 6
#define PERIPHERAL_PREF_CONN_PARAMS_CHARACTERISTIC_LEN 8
/* Adv. lengths
*/
#define MAX_ADV_DATA_LEN 31
#define BD_ADDR_SIZE 6
/* Privacy flag values
*/
#define PRIVACY_DISABLED 0x00
#define PRIVACY_ENABLED 0x02
/* Intervals in terms of 625 micro sec
*/
#define DIR_CONN_ADV_INT_MIN 0x190U /* 250 ms */
#define DIR_CONN_ADV_INT_MAX 0x320U /* 500 ms */
#define UNDIR_CONN_ADV_INT_MIN 0x800U /* 1.28 s */
#define UNDIR_CONN_ADV_INT_MAX 0x1000U /* 2.56 s */
#define LIM_DISC_ADV_INT_MIN 0x190U /* 250 ms */
#define LIM_DISC_ADV_INT_MAX 0x320U /* 500 ms */
#define GEN_DISC_ADV_INT_MIN 0x800U /* 1.28 s */
#define GEN_DISC_ADV_INT_MAX 0x1000U /* 2.56 s */
/* GAP Roles
*/
#define GAP_PERIPHERAL_ROLE 0x01U
#define GAP_BROADCASTER_ROLE 0x02U
#define GAP_CENTRAL_ROLE 0x04U
#define GAP_OBSERVER_ROLE 0x08U
/* GAP procedure codes
* Procedure codes for ACI_GAP_PROC_COMPLETE_EVENT event
* and ACI_GAP_TERMINATE_GAP_PROC command.
*/
#define GAP_LIMITED_DISCOVERY_PROC 0x01U
#define GAP_GENERAL_DISCOVERY_PROC 0x02U
#define GAP_PERIODIC_ADVERTISING_CONNECTION_PROC 0x04U
#define GAP_AUTO_CONNECTION_ESTABLISHMENT_PROC 0x08U
#define GAP_GENERAL_CONNECTION_ESTABLISHMENT_PROC 0x10U
#define GAP_SELECTIVE_CONNECTION_ESTABLISHMENT_PROC 0x20U
#define GAP_DIRECT_CONNECTION_ESTABLISHMENT_PROC 0x40U
#define GAP_OBSERVATION_PROC 0x80U
/* GAP Address Type
*/
#define GAP_PUBLIC_ADDR 0x00U
#define GAP_STATIC_RANDOM_ADDR 0x01U
#define GAP_RESOLVABLE_PRIVATE_ADDR 0x02U
#define GAP_NON_RESOLVABLE_PRIVATE_ADDR 0x03U
/* Bitmap definitions for Mode of ACI_GAP_ADD_DEVICES_TO_LIST
*/
#define GAP_ADD_DEV_MODE_RESOLVING_LIST_ONLY 0x00U
#define GAP_ADD_DEV_MODE_CLEAR 0x01U
#define GAP_ADD_DEV_MODE_FILTER_ACC_LIST_ONLY 0x02U
#define GAP_ADD_DEV_MODE_BOTH_LISTS 0x04U
/* ------------------------------------------------------------------------- */
/* IO capabilities
* (ACI_GAP_SET_IO_CAPABILITY)
*/
#define IO_CAP_DISPLAY_ONLY 0x00U
#define IO_CAP_DISPLAY_YES_NO 0x01U
#define IO_CAP_KEYBOARD_ONLY 0x02U
#define IO_CAP_NO_INPUT_NO_OUTPUT 0x03U
#define IO_CAP_KEYBOARD_DISPLAY 0x04U
/* Bonding mode
* (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
*/
#define NO_BONDING 0x00U
#define BONDING 0x01U
/* MITM protection
* (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
*/
#define MITM_PROTECTION_NOT_REQUIRED 0x00U
#define MITM_PROTECTION_REQUIRED_AS_MANDATORY 0x01U
#define MITM_PROTECTION_REQUIRED_AS_OPTIONAL 0x02U
/* LE Secure Connections support
* (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
*/
#define SC_PAIRING_UNSUPPORTED 0x00U
#define SC_PAIRING_OPTIONAL 0x01U
#define SC_PAIRING_ONLY 0x02U
/* Keypress notification support
* (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
*/
#define KEYPRESS_NOT_SUPPORTED 0x00U
#define KEYPRESS_SUPPORTED 0x01U
/* Use fixed pin
* (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
*/
#define USE_FIXED_PIN_FOR_PAIRING_ALLOWED 0x00U
#define USE_FIXED_PIN_FOR_PAIRING_FORBIDDEN 0x01U
/* Authorization requirements
* (ACI_GAP_SET_AUTHORIZATION_REQUIREMENT)
*/
#define AUTHORIZATION_NOT_REQUIRED 0x00U
#define AUTHORIZATION_REQUIRED 0x01U
/* Connection authorization response
* (ACI_GAP_AUTHORIZATION_RESP)
*/
#define CONNECTION_AUTHORIZED 0x01U
#define CONNECTION_REJECTED 0x02U
/* SMP pairing status
* (ACI_GAP_PAIRING_COMPLETE_EVENT)
*/
#define SMP_PAIRING_STATUS_SUCCESS 0x00U
#define SMP_PAIRING_STATUS_SMP_TIMEOUT 0x01U
#define SMP_PAIRING_STATUS_PAIRING_FAILED 0x02U
#define SMP_PAIRING_STATUS_ENCRYPT_FAILED 0x03U
/* SMP pairing failed reason code
* (ACI_GAP_PAIRING_COMPLETE_EVENT)
*/
#define REASON_PASSKEY_ENTRY_FAILED 0x01U
#define REASON_OOB_NOT_AVAILABLE 0x02U
#define REASON_AUTHENTICATION_REQ 0x03U
#define REASON_CONFIRM_VALUE_FAILED 0x04U
#define REASON_PAIRING_NOT_SUPPORTED 0x05U
#define REASON_ENCRYPTION_KEY_SIZE 0x06U
#define REASON_COMMAND_NOT_SUPPORTED 0x07U
#define REASON_UNSPECIFIED_REASON 0x08U
#define REASON_REPEATED_ATTEMPTS 0x09U
#define REASON_INVALID_PARAMETERS 0x0AU
#define REASON_DHKEY_CHECK_FAILED 0x0BU
#define REASON_NUM_COMPARISON_FAILED 0x0CU
#define REASON_KEY_REJECTED 0x0FU
#define REASON_BUSY 0x10U
/* Passkey input type detected
* (ACI_GAP_PASSKEY_INPUT)
*/
#define PASSKEY_ENTRY_STARTED 0x00U
#define PASSKEY_DIGIT_ENTERED 0x01U
#define PASSKEY_DIGIT_ERASED 0x02U
#define PASSKEY_CLEARED 0x03U
#define PASSKEY_ENTRY_COMPLETED 0x04U
/* Numeric Comparison Confirm Value
* (ACI_GAP_NUMERIC_COMPARISON_VALUE_CONFIRM_YESNO)
*/
#define NUMERIC_COMPARISON_CONFIRM_NO 0x00U
#define NUMERIC_COMPARISON_CONFIRM_YES 0x01U
/* OOB Device Type
* (ACI_GAP_SET_OOB_DATA)
*/
#define OOB_DEVICE_TYPE_LOCAL 0x00U
#define OOB_DEVICE_TYPE_REMOTE 0x01U
/* OOB Data Type
* (ACI_GAP_GET_OOB_DATA, ACI_GAP_SET_OOB_DATA)
*/
#define OOB_DATA_TYPE_LP_TK 0x00U
#define OOB_DATA_TYPE_SC_RANDOM 0x01U
#define OOB_DATA_TYPE_SC_CONFIRM 0x02U
/* ------------------------------------------------------------------------- */
/* Access permissions for an attribute
*/
#define ATTR_NO_ACCESS 0x00U
#define ATTR_ACCESS_READ_ONLY 0x01U
#define ATTR_ACCESS_WRITE_REQ_ONLY 0x02U
#define ATTR_ACCESS_READ_WRITE 0x03U
#define ATTR_ACCESS_WRITE_WITHOUT_RESPONSE 0x04U
#define ATTR_ACCESS_SIGNED_WRITE_ALLOWED 0x08U
#define ATTR_ACCESS_WRITE_ANY 0x0EU
#define ATTR_ACCESS_ANY 0x0FU
/* Characteristic properties
*/
#define CHAR_PROP_NONE 0x00U
#define CHAR_PROP_BROADCAST 0x01U
#define CHAR_PROP_READ 0x02U
#define CHAR_PROP_WRITE_WITHOUT_RESP 0x04U
#define CHAR_PROP_WRITE 0x08U
#define CHAR_PROP_NOTIFY 0x10u
#define CHAR_PROP_INDICATE 0x20U
#define CHAR_PROP_SIGNED_WRITE 0x40U
#define CHAR_PROP_EXT 0x80U
/* Security permissions for an attribute
*/
#define ATTR_PERMISSION_NONE 0x00U /* No security. */
#define ATTR_PERMISSION_AUTHEN_READ 0x01U /* Need authentication to read */
#define ATTR_PERMISSION_AUTHOR_READ 0x02U /* Need authorization to read */
#define ATTR_PERMISSION_ENCRY_READ 0x04U /* Need encryption to read */
#define ATTR_PERMISSION_AUTHEN_WRITE 0x08U /* Need authentication to write */
#define ATTR_PERMISSION_AUTHOR_WRITE 0x10U /* Need authorization to write */
#define ATTR_PERMISSION_ENCRY_WRITE 0x20U /* Need encryption to write */
#define ATTR_PERMISSION_SC_READ 0x40U /* Need SC to read */
#define ATTR_PERMISSION_SC_WRITE 0x80U /* Need SC tto write */
/* Type of UUID (16 bit or 128 bit)
*/
#define UUID_TYPE_16 0x01U
#define UUID_TYPE_128 0x02U
/* Type of service (primary or secondary)
*/
#define PRIMARY_SERVICE 0x01U
#define SECONDARY_SERVICE 0x02U
/* Gatt Event Mask
* Type of event generated by GATT server
* See aci_gatt_add_char.
*/
#define GATT_DONT_NOTIFY_EVENTS 0x00U
#define GATT_NOTIFY_ATTRIBUTE_WRITE 0x01U
#define GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP 0x02U
#define GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP 0x04U
#define GATT_NOTIFY_NOTIFICATION_COMPLETION 0x08U
/* Type of characteristic length (see ACI_GATT_ADD_CHAR)
*/
#define CHAR_VALUE_LEN_CONSTANT 0x00
#define CHAR_VALUE_LEN_VARIABLE 0x01
/* Encryption key size
*/
#define MIN_ENCRY_KEY_SIZE 7
#define MAX_ENCRY_KEY_SIZE 16
/* Format
*/
#define FORMAT_UINT8 0x04U
#define FORMAT_UINT16 0x06U
#define FORMAT_SINT16 0x0EU
#define FORMAT_SINT24 0x0FU
/* Unit
*/
#define UNIT_UNITLESS 0x2700
#define UNIT_TEMP_CELSIUS 0x272F
#define UNIT_PRESSURE_BAR 0x2780
/* Update_Type definitions for ACI_GATT_UPDATE_CHAR_VALUE_EXT
*/
#define GATT_CHAR_UPDATE_LOCAL_ONLY 0x00U
#define GATT_CHAR_UPDATE_SEND_NOTIFICATION 0x01U
#define GATT_CHAR_UPDATE_SEND_INDICATION 0x02U
/* ------------------------------------------------------------------------- */
/* Advertising Type
*/
#define ADV_IND 0
#define ADV_DIRECT_IND 1
#define ADV_SCAN_IND 2
#define ADV_NONCONN_IND 3
#define ADV_DIRECT_IND_LDC 4
#define SCAN_RSP 4
/* Advertising channels
*/
#define ADV_CH_37 0x01
#define ADV_CH_38 0x02
#define ADV_CH_39 0x04
/* ------------------------------------------------------------------------- */
/* Definitions for Radio_Activity_Mask
* (ACI_HAL_SET_RADIO_ACTIVITY_MASK)
*/
#define RADIO_ACT_MASK_IDLE 0x0001U
#define RADIO_ACT_MASK_ADVERTISING 0x0002U
#define RADIO_ACT_MASK_PERIPH_CONNECT 0x0004U
#define RADIO_ACT_MASK_SCANNING 0x0008U
#define RADIO_ACT_MASK_CENTR_CONNECT 0x0020U
#define RADIO_ACT_MASK_TX_TEST 0x0040U
#define RADIO_ACT_MASK_RX_TEST 0x0080U
#define RADIO_ACT_MASK_PERIOD_ADVERTISING 0x0200U
#define RADIO_ACT_MASK_PERIOD_SYNC 0x0400U
#define RADIO_ACT_MASK_ISO_BROADCAST 0x0800U
#define RADIO_ACT_MASK_ISO_SYNC 0x1000U
#define RADIO_ACT_MASK_ISO_PERIPH_CONNECT 0x2000U
#define RADIO_ACT_MASK_ISO_CENTR_CONNECT 0x4000U
/* ------------------------------------------------------------------------- */
/* Definitions for Warning_Type
* (ACI_WARNING_EVENT)
*/
#define WARNING_L2CAP_RECOMBINATION_FAILURE 0x01U
#define WARNING_GATT_UNEXPECTED_PEER_MESSAGE 0x02U
#define WARNING_NVM_ALMOST_FULL 0x03U
#define WARNING_COC_RX_DATA_LENGTH_TOO_LARGE 0x04U
#define WARNING_COC_ALREADY_ASSIGNED_DCID 0x05U
#define WARNING_SMP_UNEXPECTED_LTK_REQUEST 0x06U
#define WARNING_GATT_BEARER_NOT_ALLOCATED 0x07U
/* ------------------------------------------------------------------------- */
/* Offset for configuration values (see ACI_HAL_WRITE_CONFIG_DATA)
*/
#define CONFIG_DATA_PUBLIC_ADDRESS_OFFSET 0x00U
#define CONFIG_DATA_ER_OFFSET 0x08U
#define CONFIG_DATA_IR_OFFSET 0x18U
#define CONFIG_DATA_RANDOM_ADDRESS_OFFSET 0x2EU
#define CONFIG_DATA_GAP_ADD_REC_NBR_OFFSET 0x34U
#define CONFIG_DATA_SC_KEY_TYPE_OFFSET 0x35U
#define CONFIG_DATA_SMP_MODE_OFFSET 0xB0U
#define CONFIG_DATA_LL_SCAN_CHAN_MAP_OFFSET 0xC0U
#define CONFIG_DATA_LL_BG_SCAN_MODE_OFFSET 0xC1U
#define CONFIG_DATA_LL_RSSI_GOLDEN_RANGE_OFFSET 0xC2U
#define CONFIG_DATA_LL_RPA_MODE_OFFSET 0xC3U
#define CONFIG_DATA_LL_RX_ACL_CTRL_OFFSET 0xC4U
#define CONFIG_DATA_LL_MAX_DATA_EXT_OFFSET 0xD1U
/* Length for configuration values (see ACI_HAL_WRITE_CONFIG_DATA)
*/
#define CONFIG_DATA_PUBLIC_ADDRESS_LEN 6
#define CONFIG_DATA_ER_LEN 16
#define CONFIG_DATA_IR_LEN 16
#define CONFIG_DATA_RANDOM_ADDRESS_LEN 6
#define CONFIG_DATA_GAP_ADD_REC_NBR_LEN 1
#define CONFIG_DATA_SC_KEY_TYPE_LEN 1
#define CONFIG_DATA_SMP_MODE_LEN 1
#define CONFIG_DATA_LL_SCAN_CHAN_MAP_LEN 1
#define CONFIG_DATA_LL_BG_SCAN_MODE_LEN 1
#define CONFIG_DATA_LL_RSSI_GOLDEN_RANGE_LEN 2
#define CONFIG_DATA_LL_RPA_MODE_LEN 1
#define CONFIG_DATA_LL_RX_ACL_CTRL_LEN 2
#define CONFIG_DATA_LL_MAX_DATA_EXT_LEN 8
/* ------------------------------------------------------------------------- */
#endif /* BLE_DEFS_H__ */
@@ -0,0 +1,363 @@
/*****************************************************************************
* @file ble_legacy.h
*
* @brief This file contains legacy definitions used for BLE.
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_LEGACY_H__
#define BLE_LEGACY_H__
/* Various obsolete definitions
*/
#define PERIPHERAL_PRIVACY_FLAG_UUID 0x2A02U
#define RECONNECTION_ADDR_UUID 0x2A03U
#define OOB_AUTH_DATA_ABSENT 0x00U
#define OOB_AUTH_DATA_PRESENT 0x01U
#define BLE_STATUS_SEC_DB_FULL 0x5DU
#define BLE_STATUS_INSUFFICIENT_ENC_KEYSIZE 0x5FU
#define BLE_STATUS_CHARAC_ALREADY_EXISTS 0x63U
#define GAP_NAME_DISCOVERY_PROC 0x04U
#define MITM_PROTECTION_REQUIRED 0x01U
#define HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE 0xFFU
/* Deprecated names for ACI/HCI commands and events
*/
#define hci_le_read_local_supported_features \
hci_le_read_local_supported_features_page_0
#define hci_le_read_remote_features \
hci_le_read_remote_features_page_0
#define aci_gap_configure_whitelist \
aci_gap_configure_filter_accept_list
#define aci_gap_slave_security_req \
aci_gap_peripheral_security_req
#define aci_hal_set_slave_latency \
aci_hal_set_peripheral_latency
#define aci_gap_slave_security_initiated_event \
aci_gap_peripheral_security_initiated_event
typedef __PACKED_STRUCT
{
/**
* Identity address type
* Values:
* - 0x00: Public Identity Address
* - 0x01: Random (static) Identity Address
*/
uint8_t Peer_Identity_Address_Type;
/**
* Public or Random (static) Identity Address of the peer device
*/
uint8_t Peer_Identity_Address[6];
} Identity_Entry_t;
#define Whitelist_Entry_t \
Peer_Entry_t
#define Whitelist_Identity_Entry_t \
Identity_Entry_t
#define HCI_LE_READ_REMOTE_FEATURES_COMPLETE_SUBEVT_CODE \
HCI_LE_READ_REMOTE_FEATURES_PAGE_0_COMPLETE_SUBEVT_CODE
#define hci_le_read_remote_features_complete_event_rp0 \
hci_le_read_remote_features_page_0_complete_event_rp0
#define ACI_GAP_SLAVE_SECURITY_INITIATED_VSEVT_CODE \
ACI_GAP_PERIPHERAL_SECURITY_INITIATED_VSEVT_CODE
#define ACI_HAL_FW_ERROR_VSEVT_CODE \
ACI_WARNING_VSEVT_CODE
#define ACI_HAL_WARNING_VSEVT_CODE \
ACI_WARNING_VSEVT_CODE
typedef __PACKED_STRUCT
{
uint8_t FW_Error_Type;
uint8_t Data_Length;
uint8_t Data[(BLE_EVT_MAX_PARAM_LEN - 2) - 2];
} aci_hal_fw_error_event_rp0;
#define aci_hal_warning_event_rp0 \
aci_warning_event_rp0
#define aci_hal_warning_event \
aci_warning_event
/* Other deprecated names
*/
#define HCI_ADV_FILTER_WHITELIST_SCAN \
HCI_ADV_FILTER_ACC_LIST_USED_FOR_SCAN
#define HCI_ADV_FILTER_WHITELIST_CONNECT \
HCI_ADV_FILTER_ACC_LIST_USED_FOR_CONNECT
#define HCI_ADV_FILTER_WHITELIST_SCAN_CONNECT \
HCI_ADV_FILTER_ACC_LIST_USED_FOR_ALL
#define NO_WHITE_LIST_USE \
HCI_ADV_FILTER_NO
#define WHITE_LIST_FOR_ONLY_SCAN \
HCI_ADV_FILTER_ACC_LIST_USED_FOR_SCAN
#define WHITE_LIST_FOR_ONLY_CONN \
HCI_ADV_FILTER_ACC_LIST_USED_FOR_CONNECT
#define WHITE_LIST_FOR_ALL \
HCI_ADV_FILTER_ACC_LIST_USED_FOR_ALL
#define HCI_SCAN_FILTER_WHITELIST \
HCI_SCAN_FILTER_ACC_LIST_USED
#define HCI_SCAN_FILTER_NO_EVEN_RPA \
HCI_SCAN_FILTER_NO_EXT
#define HCI_SCAN_FILTER_WHITELIST_BUT_RPA \
HCI_SCAN_FILTER_ACC_LIST_USED_EXT
#define HCI_INIT_FILTER_WHITELIST \
HCI_INIT_FILTER_ACC_LIST_USED
#define AD_TYPE_SLAVE_CONN_INTERVAL \
AD_TYPE_PERIPHERAL_CONN_INTERVAL
#define OOB_NOT_AVAILABLE REASON_OOB_NOT_AVAILABLE
#define AUTH_REQ_CANNOT_BE_MET REASON_AUTHENTICATION_REQ
#define CONFIRM_VALUE_FAILED REASON_CONFIRM_VALUE_FAILED
#define PAIRING_NOT_SUPPORTED REASON_PAIRING_NOT_SUPPORTED
#define INSUFF_ENCRYPTION_KEY_SIZE REASON_ENCRYPTION_KEY_SIZE
#define CMD_NOT_SUPPORTED REASON_COMMAND_NOT_SUPPORTED
#define UNSPECIFIED_REASON REASON_UNSPECIFIED_REASON
#define VERY_EARLY_NEXT_ATTEMPT REASON_REPEATED_ATTEMPTS
#define SM_INVALID_PARAMS REASON_INVALID_PARAMETERS
#define SMP_SC_DHKEY_CHECK_FAILED REASON_DHKEY_CHECK_FAILED
#define SMP_SC_NUMCOMPARISON_FAILED REASON_NUM_COMPARISON_FAILED
#define CONFIG_DATA_PUBADDR_OFFSET CONFIG_DATA_PUBLIC_ADDRESS_OFFSET
#define CONFIG_DATA_PUBADDR_LEN CONFIG_DATA_PUBLIC_ADDRESS_LEN
#define FW_L2CAP_RECOMBINATION_ERROR 0x01U
#define FW_GATT_UNEXPECTED_PEER_MESSAGE 0x02U
#define FW_NVM_LEVEL_WARNING 0x03U
#define FW_COC_RX_DATA_LENGTH_TOO_LARGE 0x04U
#define FW_ECOC_CONN_RSP_ALREADY_ASSIGNED_DCID 0x05U
/* Deprecated commands
*/
#define aci_gatt_read_long_char_desc\
aci_gatt_read_long_char_value
#define aci_gatt_read_char_desc \
aci_gatt_read_char_value
#define aci_gatt_write_long_char_desc \
aci_gatt_write_long_char_value
#define aci_gatt_write_char_desc \
aci_gatt_write_char_value
#define aci_gatt_write_resp \
aci_gatt_permit_write
/**
* @brief ACI_GAP_RESOLVE_PRIVATE_ADDR
* This command tries to resolve the address provided with the IRKs present in
* its database. If the address is resolved successfully with any one of the
* IRKs present in the database, it returns success and also the corresponding
* public/static random address stored with the IRK in the database.
*
* @param Address Address to be resolved
* @param[out] Actual_Address The public or static random address of the peer
* device, distributed during pairing phase.
* @return Value indicating success or error code.
*/
__STATIC_INLINE
tBleStatus aci_gap_resolve_private_addr( const uint8_t* Address,
uint8_t* Actual_Address )
{
uint8_t type;
return aci_gap_check_bonded_device( 1, Address, &type, Actual_Address );
}
/**
* @brief ACI_GAP_IS_DEVICE_BONDED
* The command finds whether the device, whose address is specified in the
* command, is present in the bonding table. If the device is found, the
* command returns "Success".
* Note: the specified address can be a RPA. In this case, even if privacy is
* not enabled, this address is resolved to check the presence of the peer
* device in the bonding table.
*
* @param Peer_Address_Type The address type of the peer device.
* Values:
* - 0x00: Public Device Address
* - 0x01: Random Device Address
* @param Peer_Address Public Device Address or Random Device Address of the
* peer device
* @return Value indicating success or error code.
*/
__STATIC_INLINE
tBleStatus aci_gap_is_device_bonded( uint8_t Peer_Address_Type,
const uint8_t* Peer_Address )
{
uint8_t type, address[6];
return aci_gap_check_bonded_device( Peer_Address_Type, Peer_Address,
&type, address );
}
/**
* @brief ACI_GAP_ADD_DEVICES_TO_RESOLVING_LIST
* This command is used to add devices to the list of address translations
* used to resolve Resolvable Private Addresses in the Controller.
*
* @param Num_of_Resolving_list_Entries Number of devices that have to be added
* to the list.
* @param Identity_Entry See @ref Identity_Entry_t
* @param Clear_Resolving_List Clear the resolving list
* Values:
* - 0x00: Do not clear
* - 0x01: Clear before adding
* @return Value indicating success or error code.
*/
__STATIC_INLINE
tBleStatus aci_gap_add_devices_to_resolving_list( uint8_t Num_of_Resolving_list_Entries,
const Identity_Entry_t* Identity_Entry,
uint8_t Clear_Resolving_List )
{
return aci_gap_add_devices_to_list( Num_of_Resolving_list_Entries,
(const List_Entry_t*)Identity_Entry,
Clear_Resolving_List );
}
/**
* @brief ACI_HAL_GET_FW_BUILD_NUMBER
* This command returns the build number associated with the firmware version
* currently running
*
* @param[out] Build_Number Build number of the firmware.
* @return Value indicating success or error code.
*/
__STATIC_INLINE
tBleStatus aci_hal_get_fw_build_number( uint16_t* Build_Number )
{
uint32_t version[2], options[1], debug_info[3];
tBleStatus status = aci_get_information( version, options, debug_info );
*Build_Number = (uint16_t)(version[1] >> 16);
return status;
}
/**
* @brief ACI_HAL_GET_PM_DEBUG_INFO
* This command is used to retrieve TX, RX and total buffer count allocated for
* ACL packets.
*
* @param[out] Allocated_For_TX MBlocks allocated for TXing
* @param[out] Allocated_For_RX MBlocks allocated for RXing
* @param[out] Allocated_MBlocks Overall allocated MBlocks
* @return Value indicating success or error code.
*/
__STATIC_INLINE
tBleStatus aci_hal_get_pm_debug_info( uint8_t* Allocated_For_TX,
uint8_t* Allocated_For_RX,
uint8_t* Allocated_MBlocks )
{
uint32_t version[2], options[1], debug_info[3];
tBleStatus status = aci_get_information( version, options, debug_info );
*Allocated_For_TX = ((uint8_t)(((uint16_t*)debug_info)[2]) +
(uint8_t)(((uint16_t*)debug_info)[3]));
*Allocated_For_RX = (uint8_t)(((uint16_t*)debug_info)[1]);
*Allocated_MBlocks = (*Allocated_For_TX) + (*Allocated_For_RX);
return status;
}
/**
* @brief ACI_HAL_STACK_RESET
* This command is equivalent to HCI_RESET but ensures the sleep mode is
* entered immediately after its completion.
*
* @return Value indicating success or error code.
*/
__STATIC_INLINE
tBleStatus aci_hal_stack_reset( void )
{
return aci_reset( 0, 0 );
}
/**
* @brief ACI_GATT_ALLOW_READ
* Allow the GATT server to send a response to a read request from a client.
* The application has to send this command when it receives the
* ACI_GATT_READ_PERMIT_REQ_EVENT or ACI_GATT_READ_MULTI_PERMIT_REQ_EVENT. This
* command indicates to the stack that the response can be sent to the client.
* So if the application wishes to update any of the attributes before they are
* read by the client, it must update the characteristic values using the
* ACI_GATT_UPDATE_CHAR_VALUE and then give this command. The application
* should perform the required operations within 30 seconds. Otherwise the GATT
* procedure will be timeout.
*
* @param Connection_Handle Specifies the ATT bearer for which the command
* applies.
* Values:
* - 0x0000 ... 0x0EFF: Unenhanced ATT bearer (the parameter is the
* connection handle)
* - 0xEA00 ... 0xEA3F: Enhanced ATT bearer (the LSB-byte of the
* parameter is the connection-oriented channel index)
* @return Value indicating success or error code.
*/
__STATIC_INLINE
tBleStatus aci_gatt_allow_read( uint16_t Connection_Handle )
{
return aci_gatt_permit_read( Connection_Handle, 0, 0, 0 );
}
/**
* @brief ACI_GATT_DENY_READ
* This command is used to deny the GATT server to send a response to a read
* request from a client.
* The application may send this command when it receives the
* ACI_GATT_READ_PERMIT_REQ_EVENT or ACI_GATT_READ_MULTI_PERMIT_REQ_EVENT.
* This command indicates to the stack that the client is not allowed to read
* the requested characteristic due to e.g. application restrictions.
* The Error code shall be either 0x08 (Insufficient Authorization) or a value
* in the range 0x80-0x9F (Application Error).
* The application should issue the ACI_GATT_DENY_READ or ACI_GATT_ALLOW_READ
* command within 30 seconds from the reception of the
* ACI_GATT_READ_PERMIT_REQ_EVENT or ACI_GATT_READ_MULTI_PERMIT_REQ_EVENT
* events; otherwise the GATT procedure issues a timeout.
*
* @param Connection_Handle Specifies the ATT bearer for which the command
* applies.
* Values:
* - 0x0000 ... 0x0EFF: Unenhanced ATT bearer (the parameter is the
* connection handle)
* - 0xEA00 ... 0xEA3F: Enhanced ATT bearer (the LSB-byte of the
* parameter is the connection-oriented channel index)
* @param Error_Code Error code for the command
* Values:
* - 0x08: Insufficient Authorization
* - 0x80 ... 0x9F: Application Error
* @return Value indicating success or error code.
*/
__STATIC_INLINE
tBleStatus aci_gatt_deny_read( uint16_t Connection_Handle,
uint8_t Error_Code )
{
return aci_gatt_permit_read( Connection_Handle, 1, Error_Code, 0 );
}
#endif /* BLE_LEGACY_H__ */
@@ -0,0 +1,387 @@
/******************************************************************************
* @file ble_std.h
*
* @brief BLE standard definitions
******************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_STD_H__
#define BLE_STD_H__
/* HCI packet type */
#define HCI_COMMAND_PKT_TYPE 0x01U
#define HCI_ACLDATA_PKT_TYPE 0x02U
#define HCI_EVENT_PKT_TYPE 0x04U
#define HCI_ISODATA_PKT_TYPE 0x05U
/* HCI packet header size */
#define HCI_COMMAND_HDR_SIZE 4
#define HCI_ACLDATA_HDR_SIZE 5
#define HCI_EVENT_HDR_SIZE 3
#define HCI_ISODATA_HDR_SIZE 5
/* HCI parameters length */
#define HCI_COMMAND_MAX_PARAM_LEN 255
#define HCI_ACLDATA_MAX_DATA_LEN 251 /* LE_ACL_Data_Packet_Length */
#define HCI_EVENT_MAX_PARAM_LEN 255
#define HCI_ISODATA_MAX_DATA_LEN 300 /* ISO_Data_Packet_Length */
/* HCI packet maximum size */
#define HCI_COMMAND_PKT_MAX_SIZE \
(HCI_COMMAND_HDR_SIZE + HCI_COMMAND_MAX_PARAM_LEN)
#define HCI_ACLDATA_PKT_MAX_SIZE \
(HCI_ACLDATA_HDR_SIZE + HCI_ACLDATA_MAX_DATA_LEN)
#define HCI_EVENT_PKT_MAX_SIZE \
(HCI_EVENT_HDR_SIZE + HCI_EVENT_MAX_PARAM_LEN)
#define HCI_ISODATA_PKT_MAX_SIZE \
(HCI_ISODATA_HDR_SIZE + HCI_ISODATA_MAX_DATA_LEN)
/* HCI event code */
#define HCI_DISCONNECTION_COMPLETE_EVT_CODE 0x05U
#define HCI_ENCRYPTION_CHANGE_EVT_CODE 0x08U
#define HCI_READ_REMOTE_VERSION_INFORMATION_COMPLETE_EVT_CODE 0x0CU
#define HCI_COMMAND_COMPLETE_EVT_CODE 0x0EU
#define HCI_COMMAND_STATUS_EVT_CODE 0x0FU
#define HCI_HARDWARE_ERROR_EVT_CODE 0x10U
#define HCI_NUMBER_OF_COMPLETED_PACKETS_EVT_CODE 0x13U
#define HCI_DATA_BUFFER_OVERFLOW_EVT_CODE 0x1AU
#define HCI_ENCRYPTION_KEY_REFRESH_COMPLETE_EVT_CODE 0x30U
#define HCI_LE_META_EVT_CODE 0x3EU
#define HCI_AUTHENTICATED_PAYLOAD_TIMEOUT_EXPIRED_EVT_CODE 0x57U
#define HCI_VENDOR_SPECIFIC_EVT_CODE 0xFFU
/* HCI LE subevent code */
#define HCI_LE_CONNECTION_COMPLETE_SUBEVT_CODE 0x01U
#define HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE 0x02U
#define HCI_LE_CONNECTION_UPDATE_COMPLETE_SUBEVT_CODE 0x03U
#define HCI_LE_READ_REMOTE_FEATURES_PAGE_0_COMPLETE_SUBEVT_CODE 0x04U
#define HCI_LE_LONG_TERM_KEY_REQUEST_SUBEVT_CODE 0x05U
#define HCI_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_SUBEVT_CODE 0x06U
#define HCI_LE_DATA_LENGTH_CHANGE_SUBEVT_CODE 0x07U
#define HCI_LE_READ_LOCAL_P256_PUBLIC_KEY_COMPLETE_SUBEVT_CODE 0x08U
#define HCI_LE_GENERATE_DHKEY_COMPLETE_SUBEVT_CODE 0x09U
#define HCI_LE_ENHANCED_CONNECTION_COMPLETE_SUBEVT_CODE 0x0AU
#define HCI_LE_DIRECTED_ADVERTISING_REPORT_SUBEVT_CODE 0x0BU
#define HCI_LE_PHY_UPDATE_COMPLETE_SUBEVT_CODE 0x0CU
#define HCI_LE_EXTENDED_ADVERTISING_REPORT_SUBEVT_CODE 0x0DU
#define HCI_LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_SUBEVT_CODE 0x0EU
#define HCI_LE_PERIODIC_ADVERTISING_REPORT_SUBEVT_CODE 0x0FU
#define HCI_LE_PERIODIC_ADVERTISING_SYNC_LOST_SUBEVT_CODE 0x10U
#define HCI_LE_SCAN_TIMEOUT_SUBEVT_CODE 0x11U
#define HCI_LE_ADVERTISING_SET_TERMINATED_SUBEVT_CODE 0x12U
#define HCI_LE_SCAN_REQUEST_RECEIVED_SUBEVT_CODE 0x13U
#define HCI_LE_CHANNEL_SELECTION_ALGORITHM_SUBEVT_CODE 0x14U
#define HCI_LE_CONNECTIONLESS_IQ_REPORT_SUBEVT_CODE 0x15U
#define HCI_LE_CONNECTION_IQ_REPORT_SUBEVT_CODE 0x16U
#define HCI_LE_CTE_REQUEST_FAILED_SUBEVT_CODE 0x17U
#define HCI_LE_PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED_SUBEVT_CODE 0x18U
#define HCI_LE_CIS_ESTABLISHED_SUBEVT_CODE 0x19U
#define HCI_LE_CIS_REQUEST_SUBEVT_CODE 0x1AU
#define HCI_LE_CREATE_BIG_COMPLETE_SUBEVT_CODE 0x1BU
#define HCI_LE_TERMINATE_BIG_COMPLETE_SUBEVT_CODE 0x1CU
#define HCI_LE_BIG_SYNC_ESTABLISHED_SUBEVT_CODE 0x1DU
#define HCI_LE_BIG_SYNC_LOST_SUBEVT_CODE 0x1EU
#define HCI_LE_REQUEST_PEER_SCA_COMPLETE_SUBEVT_CODE 0x1FU
#define HCI_LE_PATH_LOSS_THRESHOLD_SUBEVT_CODE 0x20U
#define HCI_LE_TRANSMIT_POWER_REPORTING_SUBEVT_CODE 0x21U
#define HCI_LE_BIGINFO_ADVERTISING_REPORT_SUBEVT_CODE 0x22U
#define HCI_LE_SUBRATE_CHANGE_SUBEVT_CODE 0x23U
#define HCI_LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_V2_SUBEVT_CODE 0x24U
#define HCI_LE_PERIODIC_ADVERTISING_REPORT_V2_SUBEVT_CODE 0x25U
#define HCI_LE_PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED_V2_SUBEVT_CODE 0x26U
#define HCI_LE_PERIODIC_ADVERTISING_SUBEVENT_DATA_REQUEST_SUBEVT_CODE 0x27U
#define HCI_LE_PERIODIC_ADVERTISING_RESPONSE_REPORT_SUBEVT_CODE 0x28U
#define HCI_LE_ENHANCED_CONNECTION_COMPLETE_V2_SUBEVT_CODE 0x29U
#define HCI_LE_CIS_ESTABLISHED_V2_SUBEVT_CODE 0x2AU
#define HCI_LE_READ_ALL_REMOTE_FEATURES_COMPLETE_SUBEVT_CODE 0x2BU
#define HCI_LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES_COMPLETE_SUBEVT_CODE 0x2CU
#define HCI_LE_CS_READ_REMOTE_FAE_TABLE_COMPLETE_SUBEVT_CODE 0x2DU
#define HCI_LE_CS_SECURITY_ENABLE_COMPLETE_SUBEVT_CODE 0x2EU
#define HCI_LE_CS_CONFIG_COMPLETE_SUBEVT_CODE 0x2FU
#define HCI_LE_CS_PROCEDURE_ENABLE_COMPLETE_SUBEVT_CODE 0x30U
#define HCI_LE_CS_SUBEVENT_RESULT_SUBEVT_CODE 0x31U
#define HCI_LE_CS_SUBEVENT_RESULT_CONTINUE_SUBEVT_CODE 0x32U
#define HCI_LE_CS_TEST_END_COMPLETE_SUBEVT_CODE 0x33U
#define HCI_LE_MONITORED_ADVERTISERS_REPORT_SUBEVT_CODE 0x34U
#define HCI_LE_FRAME_SPACE_UPDATE_COMPLETE_SUBEVT_CODE 0x35U
/* HCI error code */
#define HCI_SUCCESS_ERR_CODE 0x00U
#define HCI_UNKNOWN_HCI_COMMAND_ERR_CODE 0x01U
#define HCI_UNKNOWN_CONNECTION_IDENTIFIER_ERR_CODE 0x02U
#define HCI_HARDWARE_FAILURE_ERR_CODE 0x03U
#define HCI_AUTHENTICATION_FAILURE_ERR_CODE 0x05U
#define HCI_PIN_OR_KEY_MISSING_ERR_CODE 0x06U
#define HCI_MEMORY_CAPACITY_EXCEEDED_ERR_CODE 0x07U
#define HCI_CONNECTION_TIMEOUT_ERR_CODE 0x08U
#define HCI_CONNECTION_LIMIT_EXCEEDED_ERR_CODE 0x09U
#define HCI_CONNECTION_ALREADY_EXISTS_ERR_CODE 0x0BU
#define HCI_COMMAND_DISALLOWED_ERR_CODE 0x0CU
#define HCI_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE_ERR_CODE 0x11U
#define HCI_INVALID_HCI_COMMAND_PARAMETERS_ERR_CODE 0x12U
#define HCI_REMOTE_USER_TERMINATED_CONNECTION_ERR_CODE 0x13U
#define HCI_REMOTE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES_ERR_CODE 0x14U
#define HCI_REMOTE_TERMINATED_CONNECTION_DUE_TO_POWER_OFF_ERR_CODE 0x15U
#define HCI_CONNECTION_TERMINATED_BY_LOCAL_HOST_ERR_CODE 0x16U
#define HCI_UNSUPPORTED_REMOTE_FEATURE_ERR_CODE 0x1AU
#define HCI_INVALID_LL_PARAMETERS_ERR_CODE 0x1EU
#define HCI_UNSPECIFIED_ERROR_ERR_CODE 0x1FU
#define HCI_UNSUPPORTED_LL_PARAMETER_VALUE_ERR_CODE 0x20U
#define HCI_LL_RESPONSE_TIMEOUT_ERR_CODE 0x22U
#define HCI_LL_PROCEDURE_COLLISION_ERR_CODE 0x23U
#define HCI_LMP_PDU_NOT_ALLOWED_ERR_CODE 0x24U
#define HCI_INSTANT_PASSED_ERR_CODE 0x28U
#define HCI_DIFFERENT_TRANSACTION_COLLISION_ERR_CODE 0x2AU
#define HCI_PARAMETER_OUT_OF_MANDATORY_RANGE_ERR_CODE 0x30U
#define HCI_HOST_BUSY_PAIRING_ERR_CODE 0x38U
#define HCI_CONTROLLER_BUSY_ERR_CODE 0x3AU
#define HCI_UNACCEPTABLE_CONNECTION_PARAMETERS_ERR_CODE 0x3BU
#define HCI_ADVERTISING_TIMEOUT_ERR_CODE 0x3CU
#define HCI_CONNECTION_TERMINATED_DUE_TO_MIC_FAILURE_ERR_CODE 0x3DU
#define HCI_CONNECTION_FAILED_TO_BE_ESTABLISHED_ERR_CODE 0x3EU
#define HCI_UNKNOWN_ADVERTISING_IDENTIFIER_ERR_CODE 0x42U
#define HCI_ADVERTISING_LIMIT_REACHED_ERR_CODE 0x43U
#define HCI_PACKET_TOO_LONG_ERR_CODE 0x45U
/* HCI_LE_Set_Advertising_Parameters: Advertising_Type */
#define HCI_ADV_TYPE_ADV_IND 0x00U
#define HCI_ADV_TYPE_ADV_DIRECT_IND_HDC 0x01U
#define HCI_ADV_TYPE_ADV_SCAN_IND 0x02U
#define HCI_ADV_TYPE_ADV_NONCONN_IND 0x03U
#define HCI_ADV_TYPE_ADV_DIRECT_IND_LDC 0x04U
/* HCI_LE_Set_Advertising_Parameters: Advertising_Filter_Policy */
#define HCI_ADV_FILTER_NO 0x00U
#define HCI_ADV_FILTER_ACC_LIST_USED_FOR_SCAN 0x01U
#define HCI_ADV_FILTER_ACC_LIST_USED_FOR_CONNECT 0x02U
#define HCI_ADV_FILTER_ACC_LIST_USED_FOR_ALL 0x03U
/* HCI_LE_Set_[Advertising/Scan]_Parameters: Own_Address_Type */
#define HCI_OWN_ADDR_TYPE_PUBLIC 0x00U
#define HCI_OWN_ADDR_TYPE_RANDOM 0x01U
#define HCI_OWN_ADDR_TYPE_RP_OR_PUBLIC 0x02U
#define HCI_OWN_ADDR_TYPE_RP_OR_RANDOM 0x03U
/* HCI_LE_Set_Scan_Parameters: LE_Scan_Type */
#define HCI_SCAN_TYPE_PASSIVE 0x00U
#define HCI_SCAN_TYPE_ACTIVE 0x01U
/* HCI_LE_Set_Scan_Parameters: Scanning_Filter_Policy */
#define HCI_SCAN_FILTER_NO 0x00U
#define HCI_SCAN_FILTER_ACC_LIST_USED 0x01U
#define HCI_SCAN_FILTER_NO_EXT 0x02U
#define HCI_SCAN_FILTER_ACC_LIST_USED_EXT 0x03U
/* HCI_LE_Create_Connection: Initiator_Filter_Policy */
#define HCI_INIT_FILTER_NO 0x00U
#define HCI_INIT_FILTER_ACC_LIST_USED 0x01U
/* HCI_LE_Read_PHY: TX_PHY */
#define HCI_TX_PHY_LE_1M 0x01U
#define HCI_TX_PHY_LE_2M 0x02U
#define HCI_TX_PHY_LE_CODED 0x03U
/* HCI_LE_Read_PHY: RX_PHY */
#define HCI_RX_PHY_LE_1M 0x01U
#define HCI_RX_PHY_LE_2M 0x02U
#define HCI_RX_PHY_LE_CODED 0x03U
/* HCI_LE_Set_PHY: ALL_PHYS */
#define HCI_ALL_PHYS_TX_NO_PREF 0x01U
#define HCI_ALL_PHYS_RX_NO_PREF 0x02U
/* HCI_LE_Set_PHY: TX_PHYS */
#define HCI_TX_PHYS_LE_1M_PREF 0x01U
#define HCI_TX_PHYS_LE_2M_PREF 0x02U
#define HCI_TX_PHYS_LE_CODED_PREF 0x04U
/* HCI_LE_Set_PHY: RX_PHYS */
#define HCI_RX_PHYS_LE_1M_PREF 0x01U
#define HCI_RX_PHYS_LE_2M_PREF 0x02U
#define HCI_RX_PHYS_LE_CODED_PREF 0x04U
/* HCI_LE_Set_Extended_Advertising_Parameters: Advertising_Event_Properties */
#define HCI_ADV_EVENT_PROP_CONNECTABLE 0x0001U
#define HCI_ADV_EVENT_PROP_SCANNABLE 0x0002U
#define HCI_ADV_EVENT_PROP_DIRECTED 0x0004U
#define HCI_ADV_EVENT_PROP_HDC_DIRECTED 0x0008U
#define HCI_ADV_EVENT_PROP_LEGACY 0x0010U
#define HCI_ADV_EVENT_PROP_ANONYMOUS 0x0020U
#define HCI_ADV_EVENT_PROP_TXPOWER_INC 0x0040U
/* HCI_LE_Set_Extended_Advertising_Parameters: Primary_Advertising_PHY */
#define HCI_PRIMARY_ADV_PHY_LE_1M 0x01U
#define HCI_PRIMARY_ADV_PHY_LE_CODED 0x03U
/* HCI_LE_Set_Extended_Advertising_Data: Operation */
#define HCI_SET_ADV_DATA_OPERATION_INTERMEDIATE 0x00U
#define HCI_SET_ADV_DATA_OPERATION_FIRST 0x01U
#define HCI_SET_ADV_DATA_OPERATION_LAST 0x02U
#define HCI_SET_ADV_DATA_OPERATION_COMPLETE 0x03U
#define HCI_SET_ADV_DATA_OPERATION_UNCHANGED 0x04U
/* HCI_LE_Advertising_Report: Event_Type */
#define HCI_ADV_EVT_TYPE_ADV_IND 0x00U
#define HCI_ADV_EVT_TYPE_ADV_DIRECT_IND 0x01U
#define HCI_ADV_EVT_TYPE_ADV_SCAN_IND 0x02U
#define HCI_ADV_EVT_TYPE_ADV_NONCONN_IND 0x03U
#define HCI_ADV_EVT_TYPE_SCAN_RSP 0x04U
/* HCI_LE_Set_Extended_Scan_Parameters: Scanning_PHYs */
#define HCI_SCANNING_PHYS_LE_1M 0x01U
#define HCI_SCANNING_PHYS_LE_CODED 0x04U
/* HCI_LE_Extended_Create_Connection: Initiating_PHYs */
#define HCI_INIT_PHYS_SCAN_CONN_LE_1M 0x01U
#define HCI_INIT_PHYS_CONN_LE_2M 0x02U
#define HCI_INIT_PHYS_SCAN_CONN_LE_CODED 0x04U
/* HCI_LE_Receiver_Test/HCI_LE_Transmitter_Test [v2]: PHY */
#define HCI_TEST_PHY_LE_1M 0x01U
#define HCI_TEST_PHY_LE_2M 0x02U
/* HCI_LE_Connection_Complete/HCI_LE_Enhanced_Connection_Complete: Role */
#define HCI_ROLE_CENTRAL 0x00U
#define HCI_ROLE_PERIPHERAL 0x01U
/* HCI_LE_Set_Privacy_Mode: Privacy_Mode */
#define HCI_PRIV_MODE_NETWORK 0x00U
#define HCI_PRIV_MODE_DEVICE 0x01U
/* Bluetooth Core Specification versions
*/
#define BLE_CORE_5_2 11
#define BLE_CORE_5_3 12
#define BLE_CORE_5_4 13
#define BLE_CORE_6_0 14
#define BLE_CORE_6_1 15
/* AD types for advertising data and scan response data
*/
#define AD_TYPE_FLAGS 0x01U
#define AD_TYPE_16_BIT_SERV_UUID 0x02U
#define AD_TYPE_16_BIT_SERV_UUID_CMPLT_LIST 0x03U
#define AD_TYPE_32_BIT_SERV_UUID 0x04U
#define AD_TYPE_32_BIT_SERV_UUID_CMPLT_LIST 0x05U
#define AD_TYPE_128_BIT_SERV_UUID 0x06U
#define AD_TYPE_128_BIT_SERV_UUID_CMPLT_LIST 0x07U
#define AD_TYPE_SHORTENED_LOCAL_NAME 0x08U
#define AD_TYPE_COMPLETE_LOCAL_NAME 0x09U
#define AD_TYPE_TX_POWER_LEVEL 0x0AU
#define AD_TYPE_CLASS_OF_DEVICE 0x0DU
#define AD_TYPE_SEC_MGR_TK_VALUE 0x10U
#define AD_TYPE_SEC_MGR_OOB_FLAGS 0x11U
#define AD_TYPE_PERIPHERAL_CONN_INTERVAL 0x12U
#define AD_TYPE_SERV_SOLICIT_16_BIT_UUID_LIST 0x14U
#define AD_TYPE_SERV_SOLICIT_128_BIT_UUID_LIST 0x15U
#define AD_TYPE_SERVICE_DATA 0x16U
#define AD_TYPE_APPEARANCE 0x19U
#define AD_TYPE_ADVERTISING_INTERVAL 0x1AU
#define AD_TYPE_LE_ROLE 0x1CU
#define AD_TYPE_SERV_SOLICIT_32_BIT_UUID_LIST 0x1FU
#define AD_TYPE_URI 0x24U
#define AD_TYPE_MANUFACTURER_SPECIFIC_DATA 0xFFU
/* Flag bits for Flags AD Type
*/
#define FLAG_BIT_LE_LIMITED_DISCOVERABLE_MODE 0x01U
#define FLAG_BIT_LE_GENERAL_DISCOVERABLE_MODE 0x02U
#define FLAG_BIT_BR_EDR_NOT_SUPPORTED 0x04U
#define FLAG_BIT_LE_BR_EDR_CONTROLLER 0x08U
#define FLAG_BIT_LE_BR_EDR_HOST 0x10U
/* Appearance values
*/
#define GAP_APPEARANCE_UNKNOWN 0x0000
#define GAP_APPEARANCE_GENERIC_PHONE 0x0040
#define GAP_APPEARANCE_GENERIC_COMPUTER 0x0080
#define GAP_APPEARANCE_GENERIC_WATCH 0x00C0
#define GAP_APPEARANCE_WATCH_SPORT_WATCH 0x00C1
#define GAP_APPEARANCE_GENERIC_CLOCK 0x0100
#define GAP_APPEARANCE_GENERIC_DISPLAY 0x0140
#define GAP_APPEARANCE_GENERIC_REMOTE_CONTROL 0x0180
#define GAP_APPEARANCE_GENERIC_EYE_GLASSES 0x01C0
#define GAP_APPEARANCE_GENERIC_TAG 0x0200
#define GAP_APPEARANCE_GENERIC_KEYRING 0x0240
#define GAP_APPEARANCE_GENERIC_MEDIA_PLAYER 0x0280
#define GAP_APPEARANCE_GENERIC_BARCODE_SCANNER 0x02C0
#define GAP_APPEARANCE_GENERIC_THERMOMETER 0x0300
#define GAP_APPEARANCE_THERMOMETER_EAR 0x0301
#define GAP_APPEARANCE_GENERIC_HEART_RATE_SENSOR 0x0340
#define GAP_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT 0x0341
#define GAP_APPEARANCE_GENERIC_BLOOD_PRESSURE 0x0380
#define GAP_APPEARANCE_BLOOD_PRESSURE_ARM 0x0381
#define GAP_APPEARANCE_BLOOD_PRESSURE_WRIST 0x0382
#define GAP_APPEARANCE_HUMAN_INTERFACE_DEVICE 0x03C0
#define GAP_APPEARANCE_KEYBOARD 0x03C1
#define GAP_APPEARANCE_MOUSE 0x03C2
#define GAP_APPEARANCE_JOYSTICK 0x03C3
#define GAP_APPEARANCE_GAMEPAD 0x03C4
#define GAP_APPEARANCE_DIGITIZER_TABLET 0x03C5
#define GAP_APPEARANCE_CARD_READER 0x03C6
#define GAP_APPEARANCE_DIGITAL_PEN 0x03C7
#define GAP_APPEARANCE_BARCODE_SCANNER 0x03C8
#define GAP_APPEARANCE_GENERIC_GLUCOSE_METER 0x0400
#define GAP_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR 0x0440
#define GAP_APPEARANCE_RUNNING_WALKING_IN_SHOE 0x0441
#define GAP_APPEARANCE_RUNNING_WALKING_ON_SHOE 0x0442
#define GAP_APPEARANCE_RUNNING_WALKING_ON_HIP 0x0443
#define GAP_APPEARANCE_GENERIC_CYCLING 0x0480
#define GAP_APPEARANCE_CYCLING_CYCLING_COMPUTER 0x0481
#define GAP_APPEARANCE_CYCLING_SPEED_SENSOR 0x0482
#define GAP_APPEARANCE_CYCLING_CADENCE_SENSOR 0x0483
#define GAP_APPEARANCE_CYCLING_POWER_SENSOR 0x0484
#define GAP_APPEARANCE_CYCLING_SPEED_AND_CADENCE_SENSOR 0x0485
#define GAP_APPEARANCE_GENERIC_PULSE_OXYMETER 0x0C40
#define GAP_APPEARANCE_FINGERTIP 0x0C41
#define GAP_APPEARANCE_WRIST_WORN 0x0C42
#define GAP_APPEARANCE_GENERIC_WEIGHT_SCALE 0x0C80
#define GAP_APPEARANCE_GENERIC_OUTDOOR_SPORT_ACTIVITY 0x1440
#define GAP_APPEARANCE_LOCATION_DISPLAY_DEVICE 0x1441
#define GAP_APPEARANCE_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE 0x1442
#define GAP_APPEARANCE_LOCATION_POD 0x1443
#define GAP_APPEARANCE_LOCATION_AND_NAVIGATION_POD 0x1444
#define GAP_APPEARANCE_GENERIC_ENVIRONMENTAL_SENSOR 0x1640
/* GATT UUIDs
*/
#define GATT_SERVICE_UUID 0x1801U
#define PRIMARY_SERVICE_UUID 0x2800U
#define SECONDARY_SERVICE_UUID 0x2801U
#define INCLUDE_SERVICE_UUID 0x2802U
#define CHARACTERISTIC_UUID 0x2803U
#define CHAR_EXTENDED_PROP_DESC_UUID 0x2900U
#define CHAR_USER_DESC_UUID 0x2901U
#define CHAR_CLIENT_CONFIG_DESC_UUID 0x2902U
#define CHAR_SERVER_CONFIG_DESC_UUID 0x2903U
#define CHAR_FORMAT_DESC_UUID 0x2904U
#define CHAR_AGGR_FMT_DESC_UUID 0x2905U
#define SERVICE_CHANGED_UUID 0x2A05U
#define CLIENT_SUPPORTED_FEATURES_UUID 0X2B29U
#define DATABASE_HASH_UUID 0X2B2AU
#define SERVER_SUPPORTED_FEATURES_UUID 0X2B3AU
/* GAP UUIDs
*/
#define GAP_SERVICE_UUID 0x1800U
#define DEVICE_NAME_UUID 0x2A00U
#define APPEARANCE_UUID 0x2A01U
#define PERIPHERAL_PREFERRED_CONN_PARAMS_UUID 0x2A04U
#define CENTRAL_ADDRESS_RESOLUTION_UUID 0x2AA6U
#define RESOLVABLE_PRIVATE_ADDRESS_ONLY_UUID 0x2AC9U
#define ENCRYPTED_DATA_KEY_MATERIAL_UUID 0x2B88U
#define LE_GATT_SECURITY_LEVELS_UUID 0x2BF5U
#endif /* BLE_STD_H__ */
@@ -0,0 +1,129 @@
/*****************************************************************************
* @file ble_const.h
*
* @brief This file contains the definitions which are compiler dependent.
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef BLE_CONST_H__
#define BLE_CONST_H__
#include <stdint.h>
#include <string.h>
#include "ble_std.h"
#include "ble_defs.h"
#include "osal.h"
#include "compiler.h"
/* Default BLE variant */
#ifndef BASIC_FEATURES
#define BASIC_FEATURES 0
#endif
#ifndef SLAVE_ONLY
#define SLAVE_ONLY 0
#endif
#ifndef LL_ONLY
#define LL_ONLY 0
#endif
#ifndef LL_ONLY_BASIC
#define LL_ONLY_BASIC 0
#endif
#ifndef BEACON_ONLY
#define BEACON_ONLY 0
#endif
/* Definition to determine BLE Host stack presence */
#define BLE_HOST_PRESENT (!(LL_ONLY || LL_ONLY_BASIC || BEACON_ONLY))
/* Size of command/events buffers:
*
* To change the size of commands and events parameters used in the
* auto-generated files, you need to update 2 defines:
*
* - BLE_CMD_MAX_PARAM_LEN
* - BLE_EVT_MAX_PARAM_LEN
*
* These 2 defines are set below with default values and can be changed.
*
* To compute the value to support a characteristic of 512 bytes for a specific
* command or an event, you need to look in "ble_types.h".
*
* Here are 2 examples, one with a command and one with an event:
*
* - aci_gatt_update_char_value_ext_cp0
* ----------------------------------
*
* we have in the structure:
*
* uint8_t Value[(BLE_CMD_MAX_PARAM_LEN- 12)/sizeof(uint8_t)];
*
* so to support a 512 byte value, we need to have
*
* BLE_CMD_MAX_PARAM_LEN at least equal to: 512 + 12 = 524
*
* - aci_gatt_read_handle_value_rp0
* ------------------------------
*
* we have in the structure:
*
* uint8_t Value[((BLE_EVT_MAX_PARAM_LEN - 3) - 5)/sizeof(uint8_t)];
*
* so to support a 512 byte value, we need to have
*
* BLE_EVT_MAX_PARAM_LEN at least equal to: 512 + 3 + 5 = 520
*
* If you need several events or commands with 512-size values, you need to
* take the maximum values for BLE_EVT_MAX_PARAM_LEN and BLE_CMD_MAX_PARAM_LEN.
*
*/
/* Maximum parameter size of BLE commands.
* Change this value if needed. */
#define BLE_CMD_MAX_PARAM_LEN HCI_COMMAND_MAX_PARAM_LEN
/* Maximum parameter size of BLE responses/events.
* Change this value if needed. */
#define BLE_EVT_MAX_PARAM_LEN HCI_EVENT_MAX_PARAM_LEN
/* Callback function to send command and receive response */
struct hci_request
{
uint16_t ogf;
uint16_t ocf;
int event;
void* cparam;
int clen;
void* rparam;
int rlen;
};
extern int hci_send_req( struct hci_request* req, uint8_t async );
#ifndef FALSE
#define FALSE 0
#endif
#ifndef MIN
#define MIN( a, b ) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX( a, b ) (((a) > (b)) ? (a) : (b))
#endif
#endif /* BLE_CONST_H__ */
@@ -0,0 +1,160 @@
/*****************************************************************************
* @file compiler.h
*
* @brief This file contains the definitions which are compiler dependent.
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef COMPILER_H__
#define COMPILER_H__
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT PACKED(struct)
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION PACKED(union)
#endif
/**
* @brief This is the section dedicated to IAR toolchain
*/
#if defined(__ICCARM__) || defined(__IAR_SYSTEMS_ASM__)
#ifndef __WEAK
#define __WEAK __weak
#endif
#define QUOTE_(a) #a
/**
* @brief PACKED
* Use the PACKED macro for variables that needs to be packed.
* Usage: PACKED(struct) myStruct_s
* PACKED(union) myStruct_s
*/
#define PACKED(decl) __packed decl
/**
* @brief SECTION
* Use the SECTION macro to assign data or code in a specific section.
* Usage: SECTION(".my_section")
*/
#define SECTION(name) _Pragma(QUOTE_(location=name))
/**
* @brief ALIGN_DEF
* Use the ALIGN_DEF macro to specify the alignment of a variable.
* Usage: ALIGN_DEF(4)
*/
#define ALIGN_DEF(v) _Pragma(QUOTE_(data_alignment=v))
/**
* @brief NO_INIT
* Use the NO_INIT macro to declare a not initialized variable.
* Usage: NO_INIT(int my_no_init_var)
* Usage: NO_INIT(uint16_t my_no_init_array[10])
*/
#define NO_INIT(var) __no_init var
/**
* @brief This is the section dedicated to GNU toolchain
*/
#else
#ifdef __GNUC__
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
/**
* @brief PACKED
* Use the PACKED macro for variables that needs to be packed.
* Usage: PACKED(struct) myStruct_s
* PACKED(union) myStruct_s
*/
#define PACKED(decl) decl __attribute__((packed))
/**
* @brief SECTION
* Use the SECTION macro to assign data or code in a specific section.
* Usage: SECTION(".my_section")
*/
#define SECTION(name) __attribute__((section(name)))
/**
* @brief ALIGN_DEF
* Use the ALIGN_DEF macro to specify the alignment of a variable.
* Usage: ALIGN_DEF(4)
*/
#define ALIGN_DEF(N) __attribute__((aligned(N)))
/**
* @brief NO_INIT
* Use the NO_INIT macro to declare a not initialized variable.
* Usage: NO_INIT(int my_no_init_var)
* Usage: NO_INIT(uint16_t my_no_init_array[10])
*/
#define NO_INIT(var) var __attribute__((section(".noinit")))
/**
* @brief This is the section dedicated to Keil toolchain
*/
#else
#ifdef __CC_ARM
#ifndef __WEAK
#define __WEAK __weak
#endif
/**
* @brief PACKED
* Use the PACKED macro for variables that needs to be packed.
* Usage: PACKED(struct) myStruct_s
* PACKED(union) myStruct_s
*/
#define PACKED(decl) decl __attribute__((packed))
/**
* @brief SECTION
* Use the SECTION macro to assign data or code in a specific section.
* Usage: SECTION(".my_section")
*/
#define SECTION(name) __attribute__((section(name)))
/**
* @brief ALIGN_DEF
* Use the ALIGN_DEF macro to specify the alignment of a variable.
* Usage: ALIGN_DEF(4)
*/
#define ALIGN_DEF(N) __attribute__((aligned(N)))
/**
* @brief NO_INIT
* Use the NO_INIT macro to declare a not initialized variable.
* Usage: NO_INIT(int my_no_init_var)
* Usage: NO_INIT(uint16_t my_no_init_array[10])
*/
#define NO_INIT(var) var __attribute__((section("NoInit")))
#else
#error Neither ICCARM, CC ARM nor GNUC C detected. Define your macros.
#endif
#endif
#endif
#endif /* COMPILER_H__ */
@@ -0,0 +1,50 @@
/*****************************************************************************
* @file osal.c
*
* @brief Implements the interface defined in "osal.h" needed by the stack.
* Actually, only memset, memcpy and memcmp wrappers are implemented.
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#include <string.h>
#include "osal.h"
/**
* Osal_MemCpy
*
*/
void* Osal_MemCpy( void *dest, const void *src, unsigned int size )
{
return memcpy( dest, src, size );
}
/**
* Osal_MemSet
*
*/
void* Osal_MemSet( void *ptr, int value, unsigned int size )
{
return memset( ptr, value, size );
}
/**
* Osal_MemCmp
*
*/
int Osal_MemCmp( const void *s1, const void *s2, unsigned int size )
{
return memcmp( s1, s2, size );
}
@@ -0,0 +1,65 @@
/*****************************************************************************
* @file osal.h
*
* @brief This header file defines the OS abstraction layer used by
* the BLE stack. OSAL defines the set of functions which needs to be
* ported to target operating system and target platform.
* Actually, only memset, memcpy and memcmp wrappers are defined.
*****************************************************************************
* @attention
*
* Copyright (c) 2018-2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*****************************************************************************
*/
#ifndef OSAL_H__
#define OSAL_H__
/**
* This function copies size number of bytes from a
* memory location pointed by src to a destination
* memory location pointed by dest
*
* @param[in] dest Destination address
* @param[in] src Source address
* @param[in] size size in the bytes
*
* @return Address of the destination
*/
extern void* Osal_MemCpy( void *dest, const void *src, unsigned int size );
/**
* This function sets first number of bytes, specified
* by size, to the destination memory pointed by ptr
* to the specified value
*
* @param[in] ptr Destination address
* @param[in] value Value to be set
* @param[in] size Size in the bytes
*
* @return Address of the destination
*/
extern void* Osal_MemSet( void *ptr, int value, unsigned int size );
/**
* This function compares n bytes of two regions of memory
*
* @param[in] s1 First buffer to compare.
* @param[in] s2 Second buffer to compare.
* @param[in] size Number of bytes to compare.
*
* @return 0 if the two buffers are equal, 1 otherwise
*/
extern int Osal_MemCmp( const void *s1, const void *s2, unsigned int size );
#endif /* OSAL_H__ */
@@ -0,0 +1,62 @@
/**
******************************************************************************
* @file bas.h
* @author MCD Application Team
* @brief Header for bas.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __BAS_H
#define __BAS_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
BAS_LEVEL_NOT_ENABLED_EVT,
BAS_LEVEL_NOT_DISABLED_EVT,
BAS_LEVEL_READ_EVT
} BAS_Opcode_Notification_evt_t;
typedef struct
{
BAS_Opcode_Notification_evt_t BAS_Evt_Opcode;
uint8_t ServiceInstance;
}BAS_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
#define BAS_LEVEL_NOTIFICATION_OPTION 1
/* Exported functions ------------------------------------------------------- */
void BAS_Init(void);
void BAS_Update_Char(uint16_t UUID, uint8_t service_instance, uint8_t *pPayload);
void BAS_Notification(BAS_Notification_evt_t * pNotification);
#ifdef __cplusplus
}
#endif
#endif /*__BAS_H */
@@ -0,0 +1,102 @@
/**
******************************************************************************
* @file bls.h
* @author MCD Application Team
* @brief Header for bls.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __BLS_H
#define __BLS_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
NO_FLAG = 0,
VALUE_UNIT_KILO_PASCAL = (1<<0), /*0 -> Blood pressure systolic, diastolic & Mean values in units of mmHg - if 1 -> in units of kPa*/
TIME_STAMP_PRESENT = (1<<1),
PULSE_RATE_PRESENT = (1<<2),
USER_ID_PRESENT = (1<<3),
MEASUREMENT_STATUS_PRESENT = (1<<4)
} BLS_Measurement_Flags_t;
typedef enum
{
BLS_MEASUREMENT_IND_ENABLED_EVT,
BLS_MEASUREMENT_IND_DISABLED_EVT,
#if (BLE_CFG_BLS_INTERMEDIATE_CUFF_PRESSURE != 0)
BLS_INTERMEDIATE_CUFF_PRESSURE_NOTIF_ENABLED_EVT,
BLS_INTERMEDIATE_CUFF_PRESSURE_NOTIF_DISABLED_EVT,
#endif
} BLS_App_Opcode_Notification_evt_t;
typedef struct
{
BLS_App_Opcode_Notification_evt_t BLS_Evt_Opcode;
}BLS_App_Notification_evt_t;
typedef struct
{
uint16_t Year;
uint8_t Month;
uint8_t Day;
uint8_t Hours;
uint8_t Minutes;
uint8_t Seconds;
}BLS_TimeStamp_t;
typedef struct
{
uint16_t MeasurementValue_Systolic;
uint16_t MeasurementValue_Diastolic;
uint16_t MeasurementValue_Mean;
#if (BLE_CFG_BLS_TIME_STAMP_FLAG != 0)
BLS_TimeStamp_t TimeStamp;
#endif
#if (BLE_CFG_BLS_PULSE_RATE_FLAG != 0)
uint16_t PulseRate;
#endif
#if (BLE_CFG_BLS_USER_ID_FLAG != 0)
uint8_t UserID;
#endif
#if (BLE_CFG_BLS_MEASUREMENT_STATUS_FLAG != 0)
uint16_t MeasurementStatus;
#endif
uint8_t Flags;
}BLS_Value_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void BLS_Init(void);
void BLS_Update_Char(uint16_t UUID, uint8_t *pPayload);
void BLS_App_Notification(BLS_App_Notification_evt_t * pNotification);
#ifdef __cplusplus
}
#endif
#endif /*__BLS_H */
@@ -0,0 +1,72 @@
/**
******************************************************************************
* @file crs_stm.h
* @author MCD Application Team
* @brief Header for crs_stm.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32XX_CRS_H
#define __STM32XX_CRS_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
CRS_NOTIFY_ENABLED_EVT,
CRS_NOTIFY_DISABLED_EVT,
CRS_READ_EVT,
CRS_WRITE_EVT,
} CRS_Opcode_evt_t;
typedef struct
{
uint8_t * pPayload;
uint8_t Length;
}CRS_Data_t;
typedef struct
{
CRS_Opcode_evt_t CRS_Evt_Opcode;
CRS_Data_t DataTransfered;
uint16_t ConnectionHandle;
uint8_t ServiceInstance;
}CRS_STM_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
#define CRS_MAX_DATA_LEN (BLE_DEFAULT_ATT_MTU - 3) /**< Maximum length of data (in bytes) that can be transmitted to the peer. */
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void CRS_STM_Init(void);
void CRS_STM_Notification(CRS_STM_Notification_evt_t *p_Notification);
tBleStatus CRS_STM_Update_Char(uint16_t UUID, uint8_t *p_Payload);
#ifdef __cplusplus
}
#endif
#endif /*__STM32XX_CRS_H */
@@ -0,0 +1,52 @@
/**
******************************************************************************
* @file dis.h
* @author MCD Application Team
* @brief Header for dis.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DIS_H
#define __DIS_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef struct
{
uint8_t *pPayload;
uint8_t Length;
}DIS_Data_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void DIS_Init(void);
tBleStatus DIS_UpdateChar(uint16_t uuid, DIS_Data_t *p_data);
#ifdef __cplusplus
}
#endif
#endif /*__DIS_H */
@@ -0,0 +1,79 @@
/**
******************************************************************************
* @file eds_stm.h
* @author MCD Application Team
* @brief Header for stm32xx_enddevicemanagement.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __EDS_STM_H
#define __EDS_STM_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
EDS_STM_NOTIFY_DISABLED_EVT,
EDS_STM_NOTIFY_ENABLED_EVT,
} EDS_STM_Opcode_evt_t;
typedef struct
{
uint8_t Device1_Status;
uint8_t Device2_Status;
uint8_t Device3_Status;
uint8_t Device4_Status;
uint8_t Device5_Status;
uint8_t Device6_Status;
}EDS_STM_Status_t;
typedef struct
{
uint8_t * pPayload;
uint8_t Length;
}EDS_STM_Data_t;
typedef struct
{
EDS_STM_Opcode_evt_t EDS_Evt_Opcode;
EDS_STM_Data_t DataTransfered;
uint16_t ConnectionHandle;
}EDS_STM_App_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void EDS_STM_Init( void );
void EDS_STM_App_Notification(EDS_STM_App_Notification_evt_t * pNotification);
tBleStatus EDS_STM_Update_Char(uint16_t UUID, uint8_t *pPayload);
#ifdef __cplusplus
}
#endif
#endif /*__EDS_STM_H */
@@ -0,0 +1,79 @@
/**
******************************************************************************
* @file hids.h
* @author MCD Application Team
* @brief Header for hids.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HIDS_H
#define __HIDS_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
HIDS_REPORT_NOTIFICATION_ENABLED,
HIDS_REPORT_NOTIFICATION_DISABLED,
HIDS_KEYB_INPUT_NOTIFY_ENABLED,
HIDS_KEYB_INPUT_NOTIFY_DISABLED,
HIDS_MOUSE_INPUT_NOTIFY_ENABLED,
HIDS_MOUSE_INPUT_NOTIFY_DISABLED,
HIDS_OUTPUT_REPORT,
HIDS_KEYBOARD_INPUT_REPORT,
HIDS_KEYBOARD_OUTPUT_REPORT,
HIDS_MOUSE_INPUT_REPORT,
HIDS_CONN_HANDLE_EVT,
HIDS_DISCON_HANDLE_EVT
} HIDS_Opcode_Notification_evt_t;
typedef struct
{
HIDS_Opcode_Notification_evt_t HIDS_Evt_Opcode;
uint8_t Instance;
uint8_t Index;
uint8_t ReportLength;
uint8_t *pReport;
} HIDS_App_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void HIDS_Init(void);
tBleStatus HIDS_Update_Char(uint16_t UUID,
uint8_t service_instance,
uint8_t Report_Index,
uint8_t report_size,
uint8_t *pPayload);
void HIDS_Notification(HIDS_App_Notification_evt_t *pNotification);
#ifdef __cplusplus
}
#endif
#endif /*__HIDS_H */
@@ -0,0 +1,99 @@
/**
******************************************************************************
* @file hrs.h
* @author MCD Application Team
* @brief Header for stm32xx_heartrate.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HRS_H
#define __HRS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
HRS_HRM_VALUE_FORMAT_UINT16 = 1,
HRS_HRM_SENSOR_CONTACTS_PRESENT = 2,
HRS_HRM_SENSOR_CONTACTS_SUPPORTED = 4,
HRS_HRM_ENERGY_EXPENDED_PRESENT = 8,
HRS_HRM_RR_INTERVAL_PRESENT = 0x10
} HRS_HrmFlags_t;
typedef enum
{
HRS_BODY_SENSOR_LOCATION_OTHER = 0,
HRS_BODY_SENSOR_LOCATION_CHEST = 1,
HRS_BODY_SENSOR_LOCATION_WRIST = 2,
HRS_BODY_SENSOR_LOCATION_FINGER = 3,
HRS_BODY_SENSOR_LOCATION_HAND = 4,
HRS_BODY_SENSOR_LOCATION_EAR_LOBE = 5,
HRS_BODY_SENSOR_LOCATION_FOOT = 6
} HRS_BodySensorLocation_t;
typedef enum
{
HRS_RESET_ENERGY_EXPENDED_EVT,
HRS_NOTIFICATION_ENABLED,
HRS_NOTIFICATION_DISABLED,
HRS_STM_BOOT_REQUEST_EVT,
} HRS_NotCode_t;
typedef struct
{
uint8_t * pPayload;
uint8_t Length;
}HRS_Data_t;
typedef struct
{
HRS_NotCode_t HRS_Evt_Opcode;
HRS_Data_t DataTransfered;
uint16_t ConnectionHandle;
uint8_t ServiceInstance;
}HRS_App_Notification_evt_t;
typedef struct{
uint16_t MeasurementValue;
#if (BLE_CFG_HRS_ENERGY_EXPENDED_INFO_FLAG == 1)
uint16_t EnergyExpended;
#endif
#if (BLE_CFG_HRS_ENERGY_RR_INTERVAL_FLAG != 0)
uint16_t aRRIntervalValues[BLE_CFG_HRS_ENERGY_RR_INTERVAL_FLAG + BLE_CFG_HRS_ENERGY_EXPENDED_INFO_FLAG];
uint8_t NbreOfValidRRIntervalValues;
#endif
uint8_t Flags;
}HRS_MeasVal_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void HRS_Init(void);
tBleStatus HRS_UpdateChar(uint16_t uuid, uint8_t *p_payload);
void HRS_Notification(HRS_App_Notification_evt_t *pNotification);
#ifdef __cplusplus
}
#endif
#endif /*__HRS_H */
@@ -0,0 +1,113 @@
/**
******************************************************************************
* @file hts.h
* @author MCD Application Team
* @brief Header for shst.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HTS_H
#define __HTS_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
NO_FLAGS = 0,
VALUE_UNIT_FAHRENHEIT = (1<<0),
SENSOR_TIME_STAMP_PRESENT = (1<<1),
SENSOR_TEMPERATURE_TYPE_PRESENT = (1<<2),
} HTS_TM_Flags_t;
typedef enum
{
TT_Armpit = 1,
TT_Body = 2,
TT_Ear = 3,
TT_Finger = 4,
TT_Gastro_intestinal_Tract = 5,
TT_Mouth = 6,
TT_Rectum = 7,
TT_Toe = 8,
TT_Tympanum = 9
} HTS_Temperature_Type_t;
typedef enum
{
HTS_MEASUREMENT_INTERVAL_RECEIVED_EVT,
HTS_MEASUREMENT_IND_ENABLED_EVT,
HTS_MEASUREMENT_IND_DISABLED_EVT,
HTS_MEASUREMENT_INTERVAL_IND_ENABLED_EVT,
HTS_MEASUREMENT_INTERVAL_IND_DISABLED_EVT,
HTS_INTERMEDIATE_TEMPERATURE_NOT_ENABLED_EVT,
HTS_INTERMEDIATE_TEMPERATURE_NOT_DISABLED_EVT,
} HTS_App_Opcode_Notification_evt_t;
typedef struct
{
HTS_App_Opcode_Notification_evt_t HTS_Evt_Opcode;
#if (BLE_CFG_HTS_MEASUREMENT_INTERVAL != 0)
uint16_t RangeInterval;
#endif
}HTS_App_Notification_evt_t;
#if (BLE_CFG_HTS_TIME_STAMP_FLAG != 0)
typedef struct
{
uint16_t Year;
uint8_t Month;
uint8_t Day;
uint8_t Hours;
uint8_t Minutes;
uint8_t Seconds;
}HTS_TimeStamp_t;
#endif
typedef struct
{
uint32_t MeasurementValue;
#if (BLE_CFG_HTS_TIME_STAMP_FLAG != 0)
HTS_TimeStamp_t TimeStamp;
#endif
#if (BLE_CFG_HTS_TEMPERATURE_TYPE_VALUE_STATIC == 0)
HTS_Temperature_Type_t TemperatureType;
#endif
uint8_t Flags;
}HTS_TemperatureValue_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void HTS_Init(void);
tBleStatus HTS_Update_Char(uint16_t UUID,
uint8_t *pPayload);
void HTS_App_Notification(HTS_App_Notification_evt_t * pNotification);
#ifdef __cplusplus
}
#endif
#endif /*__HTS_H */
@@ -0,0 +1,62 @@
/**
******************************************************************************
* @file ias.h
* @author MCD Application Team
* @brief Header for ias.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __IAS_H
#define __IAS_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
IAS_NO_ALERT_EVT,
IAS_MID_ALERT_EVT,
IAS_HIGH_ALERT_EVT
} IAS_App_Opcode_Notification_evt_t;
typedef struct
{
IAS_App_Opcode_Notification_evt_t IAS_Evt_Opcode;
}IAS_App_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void IAS_Init(void);
tBleStatus IAS_Update_Char(uint16_t UUID, uint8_t *pPayload);
void IAS_App_Notification(IAS_App_Notification_evt_t *pNotification);
#ifdef __cplusplus
}
#endif
#endif /*__IAS_H */
@@ -0,0 +1,63 @@
/**
******************************************************************************
* @file lls.h
* @author MCD Application Team
* @brief Header for lls.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LLS_H
#define __LLS_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
LLS_NO_ALERT_EVT,
LLS_MID_ALERT_EVT,
LLS_HIGH_ALERT_EVT,
LLS_DISCONNECT_EVT,
LLS_CONNECT_EVT
} LLS_App_Opcode_Notification_evt_t;
typedef struct
{
LLS_App_Opcode_Notification_evt_t LLS_Evt_Opcode;
}LLS_App_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void LLS_Init(void);
tBleStatus LLS_Update_Char(uint16_t UUID, uint8_t *pPayload);
void LLS_App_Notification(LLS_App_Notification_evt_t *pNotification);
#ifdef __cplusplus
}
#endif
#endif /*__LLS_H */
@@ -0,0 +1,43 @@
/**
******************************************************************************
* @file mesh.h
* @author MCD Application Team
* @brief Header for mesh.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MESH_H
#define __MESH_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void MESH_Init(void);
#ifdef __cplusplus
}
#endif
#endif /*__MESH_H */
@@ -0,0 +1,177 @@
/**
******************************************************************************
* @file motenv_stm.h
* @author SRA/AST
* @brief Header for motenv_stm.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MOTENV_STM_H
#define MOTENV_STM_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/**
* @brief MOTENV Event Opcode definition
*/
typedef enum
{
/* HW Service Chars related events */
HW_MOTION_NOTIFY_ENABLED_EVT,
HW_MOTION_NOTIFY_DISABLED_EVT,
HW_ENV_NOTIFY_ENABLED_EVT,
HW_ENV_NOTIFY_DISABLED_EVT,
HW_ENV_READ_EVT,
HW_ACC_EVENT_NOTIFY_ENABLED_EVT,
HW_ACC_EVENT_NOTIFY_DISABLED_EVT,
HW_ACC_EVENT_READ_EVT,
HW_TOF_NOTIFY_ENABLED_EVT,
HW_TOF_NOTIFY_DISABLED_EVT,
HW_TOF_WRITE_EVT,
/* SW Service Chars related events */
SW_MOTIONFX_NOTIFY_ENABLED_EVT,
SW_MOTIONFX_NOTIFY_DISABLED_EVT,
SW_ECOMPASS_NOTIFY_ENABLED_EVT,
SW_ECOMPASS_NOTIFY_DISABLED_EVT,
SW_ACTIVITY_REC_NOTIFY_ENABLED_EVT,
SW_ACTIVITY_REC_NOTIFY_DISABLED_EVT,
SW_ACTIVITY_REC_READ_EVT,
SW_CARRY_POSITION_NOTIFY_ENABLED_EVT,
SW_CARRY_POSITION_NOTIFY_DISABLED_EVT,
SW_CARRY_POSITION_READ_EVT,
SW_GESTURE_REC_NOTIFY_ENABLED_EVT,
SW_GESTURE_REC_NOTIFY_DISABLED_EVT,
SW_GESTURE_REC_READ_EVT,
SW_PEDOMETER_NOTIFY_ENABLED_EVT,
SW_PEDOMETER_NOTIFY_DISABLED_EVT,
SW_PEDOMETER_READ_EVT,
SW_INTENSITY_DET_NOTIFY_ENABLED_EVT,
SW_INTENSITY_DET_NOTIFY_DISABLED_EVT,
MOTENV_STM_BOOT_REQUEST_EVT,
/* Config Service Chars related events */
CONFIG_NOTIFY_ENABLED_EVT,
CONFIG_NOTIFY_DISABLED_EVT,
CONFIG_WRITE_EVT,
/* Console Service Chars related events */
CONSOLE_TERM_NOTIFY_ENABLED_EVT,
CONSOLE_TERM_NOTIFY_DISABLED_EVT,
CONSOLE_STDERR_NOTIFY_ENABLED_EVT,
CONSOLE_STDERR_NOTIFY_DISABLED_EVT,
CONSOLE_TERM_READ_EVT,
CONSOLE_STDERR_READ_EVT
} MOTENV_STM_Opcode_evt_t;
/**
* @brief MOTENV Event data structure definition
*/
typedef struct
{
uint8_t *pPayload;
uint8_t Length;
} MOTENV_STM_Data_t;
/**
* @brief MOTENV Notification structure definition
*/
typedef struct
{
MOTENV_STM_Opcode_evt_t Motenv_Evt_Opcode;
MOTENV_STM_Data_t DataTransfered;
uint16_t ConnectionHandle;
uint8_t ServiceInstance;
} MOTENV_STM_App_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
/* Exported Variables ------------------------------------------------------- */
extern uint8_t ToF_BoardPresent;
/* Exported macros -----------------------------------------------------------*/
/**
* @brief Motion (Acc-Gyro-Magneto) Char shortened UUID
*/
#define MOTION_CHAR_UUID (0xE000)
/**
* @brief Environmental (Temp-Humidity-Pressure) Char shortened UUID
*/
#define ENV_CHAR_UUID (0x1D00)
/**
* @brief ToF Char shortened UUID
*/
#define TOF_CHAR_UUID (0x0000)
/**
* @brief Acceleration event Char shortened UUID
*/
#define ACC_EVENT_CHAR_UUID (0x0004)
/**
* @brief Sensor Fusion Char shortened UUID
*/
#define MOTION_FX_CHAR_UUID (0x0100)
/**
* @brief E-Compass event Char shortened UUID
*/
#define ECOMPASS_CHAR_UUID (0x0040)
/**
* @brief Activity Recognition Char event Char shortened UUID
*/
#define ACTIVITY_REC_CHAR_UUID (0x0010)
/**
* @brief Carry Position event Char shortened UUID
*/
#define CARRY_POSITION_CHAR_UUID (0x0008)
/**
* @brief Gesture Recognition event Char shortened UUID
*/
#define GESTURE_REC_CHAR_UUID (0x0200)
/**
* @brief Pedometer Char shortened UUID
*/
#define PEDOMETER_CHAR_UUID (0x0001)
/**
* @brief Intensity Detection Char shortened UUID
*/
#define INTENSITY_DET_CHAR_UUID (0x0020)
/**
* @brief Config Char shortened UUID
*/
#define CONFIG_CHAR_UUID (0x0002)
/**
* @brief Console Terminal Char shortened UUID
*/
#define CONSOLE_TERM_CHAR_UUID (0x010E)
/**
* @brief Cosnole Stderr Char shortened UUID
*/
#define CONSOLE_STDERR_CHAR_UUID (0x020E)
/* Exported functions ------------------------------------------------------- */
void MOTENV_STM_Init(void);
void MOTENV_STM_App_Notification(MOTENV_STM_App_Notification_evt_t *pNotification);
tBleStatus MOTENV_STM_App_Update_Char(uint16_t UUID, uint8_t payloadLen, uint8_t *pPayload);
#ifdef __cplusplus
}
#endif
#endif /* MOTENV_STM_H */
@@ -0,0 +1,108 @@
/**
******************************************************************************
* @file otas_stm.h
* @author MCD Application Team
* @brief Interface to OTA BLE service
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __OTAS_STM_H
#define __OTAS_STM_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32_wpan_common.h"
/* Exported defines -----------------------------------------------------------*/
#define OTAS_STM_RAW_DATA_SIZE (248)
/* Exported types ------------------------------------------------------------*/
typedef enum
{
OTAS_STM_BASE_ADDR_ID,
OTAS_STM_RAW_DATA_ID,
OTAS_STM_CONF_ID,
OTAS_STM_CONF_EVENT_ID,
} OTAS_STM_ChardId_t;
typedef enum
{
OTAS_STM_STOP_ALL_UPLOAD = 0x00,
OTAS_STM_WIRELESS_FW_UPLOAD = 0x01,
OTAS_STM_APPLICATION_UPLOAD = 0x02,
OTAS_STM_UPLOAD_FINISHED = 0x07,
OTAS_STM_CANCEL_UPLOAD = 0x08,
} OTAS_STM_Command_t;
typedef enum
{
OTAS_STM_REBOOT_CONFIRMED = 0x01,
} OTAS_STM_Indication_Msg_t;
typedef struct{
uint8_t *pPayload;
OTAS_STM_ChardId_t ChardId;
uint8_t ValueLength;
} OTA_STM_Notification_t;
typedef PACKED_STRUCT{
OTAS_STM_Command_t Command; /**< [0:7] */
uint8_t Base_Addr[3]; /**< [8:31] */
} OTA_STM_Base_Addr_Event_Format_t;
typedef PACKED_STRUCT{
uint8_t Raw_Data[OTAS_STM_RAW_DATA_SIZE];
} OTA_STM_Raw_Data_Event_Format_t;
typedef PACKED_STRUCT{
aci_gatt_server_confirmation_event_rp0 Conf_Event;
} OTA_STM_Conf_Event_Format_t;
typedef PACKED_STRUCT{
OTAS_STM_Indication_Msg_t Conf_Msg;
} OTA_STM_Conf_Char_Format_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void OTAS_STM_Notification( OTA_STM_Notification_t *p_notification );
/**
* @brief Service initialization
* @param None
* @retval None
*/
void OTAS_STM_Init(void);
/**
* @brief Characteristic update
* @param ChardId: Id of the characteristic to be written
* @param p_payload: The new value to be written
* @retval Command status
*/
tBleStatus OTAS_STM_UpdateChar(OTAS_STM_ChardId_t ChardId, uint8_t *p_payload);
#ifdef __cplusplus
}
#endif
#endif /*__OTAS_STM_H */
@@ -0,0 +1,73 @@
/**
******************************************************************************
* @file p2p_stm.h
* @author MCD Application Team
* @brief Header for p2p_stm.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __P2PS_STM_H
#define __P2PS_STM_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
P2PS_STM__NOTIFY_ENABLED_EVT,
P2PS_STM_NOTIFY_DISABLED_EVT,
P2PS_STM_READ_EVT,
P2PS_STM_WRITE_EVT,
P2PS_STM_BOOT_REQUEST_EVT,
} P2PS_STM_Opcode_evt_t;
typedef struct
{
uint8_t * pPayload;
uint8_t Length;
}P2PS_STM_Data_t;
typedef struct
{
P2PS_STM_Opcode_evt_t P2P_Evt_Opcode;
P2PS_STM_Data_t DataTransfered;
uint16_t ConnectionHandle;
uint8_t ServiceInstance;
}P2PS_STM_App_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void P2PS_STM_Init( void );
void P2PS_STM_App_Notification(P2PS_STM_App_Notification_evt_t *pNotification);
tBleStatus P2PS_STM_App_Update_Char(uint16_t UUID, uint8_t *pPayload);
#ifdef __cplusplus
}
#endif
#endif /*__P2PS_STM_H */
@@ -0,0 +1,171 @@
/**
******************************************************************************
* @file svc_ctl.h
* @author MCD Application Team
* @brief Header for ble_controller.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/**
* The BLE Controller supports the application to handle services and clients.
* It provides an API to initialize the BLE core Device and a handler mechanism to rout the GATT/GAP events to the
* application. When the ble_controller is used (recommended), the application shall register a callback for each
* Service and each Client implemented. This is already done with the Services and Clients provided in that delivery.
* + A GATT event is relevant to only one Service and/or one Client. When a GATT event is received, it is notified to
* the registered handlers to the BLE controller. When no registered handler acknowledges positively the GATT event,
* it is reported to the application.
* + A GAP event is not relevant to either a Service or a Client. It is sent to the application
* + In case the application does not want to take benefit from the ble_controller, it could bypass it. In that case,
* the application shall:
* - call SVCCTL_Init() to initialize the BLE core device (or implement on its own what is inside that function
* - implement TLHCI_UserEvtRx() which is the notification from the HCI layer to report all events (GATT/GAP).
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SVCCTL_H
#define __SVCCTL_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
SVCCTL_EvtNotAck,
SVCCTL_EvtAckFlowEnable,
SVCCTL_EvtAckFlowDisable,
} SVCCTL_EvtAckStatus_t;
typedef enum
{
SVCCTL_UserEvtFlowDisable,
SVCCTL_UserEvtFlowEnable,
} SVCCTL_UserEvtFlowStatus_t;
typedef SVCCTL_EvtAckStatus_t (*SVC_CTL_p_EvtHandler_t)(void *p_evt);
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/**
* @brief It initializes the BLE core Driver and sends some commands to initialize the BLE core device
* It shall be called before any BLE operation
*
* @param None
* @retval None
*/
void SVCCTL_Init( void );
/**
* @brief This API registers a handler to be called when a GATT user event is received from the BLE core device. When
* a Service is created, it shall register a callback to be notified when a GATT event is received from the
* BLE core device. When a GATT event is received, it shall be checked in the handler if the GATT events belongs
* to the Service or not. The handler shall return the correct status depending on the result. As soon as one
* Service handler registered acknowledges positively the GATT event, the ble_controller stops calling the
* registered Service handlers.
* This handler is called in the TL_BLE_HCI_UserEvtProc() context
*
* @param pfBLE_SVC_Service_Event_Handler: This is the Service handler that the ble_controller calls to report a GATT
* event received. If the GATT event belongs to that Service, the callback shall return positively with
* SVCCTL_EvtAckFlowEnable.
* @retval None
*/
void SVCCTL_RegisterSvcHandler( SVC_CTL_p_EvtHandler_t pfBLE_SVC_Service_Event_Handler );
/**
* @brief This API registers a handler to be called when a GATT user event is received from the BLE core device. When
* a Client is created, it shall register a callback to be notified when a GATT event is received from the
* BLE core device. When a GATT event is received, it shall be checked in the handler if the GATT events belongs
* to the Client or not. The handler shall return the correct status depending on the result. As soon as one
* Client handler registered acknowledges positively the GATT event, the ble_controller stops calling the
* registered Client handlers.
* This handler is called in the TL_BLE_HCI_UserEvtProc() context
*
* @param pfBLE_SVC_Client_Event_Handler: This is the Client handler that the ble_controller calls to report a GATT
* event received. If the GATT event belongs to that Client, the callback shall return positively with
* SVCCTL_EvtAckFlowEnable.
* @retval None
*/
void SVCCTL_RegisterCltHandler( SVC_CTL_p_EvtHandler_t pfBLE_SVC_Client_Event_Handler );
/**
* @brief This API is used to resume the User Event Flow that has been stopped in return of SVCCTL_UserEvtRx()
*
* @param None
* @retval None
*/
void SVCCTL_ResumeUserEventFlow( void );
/**
* @brief This callback is triggered when either
* + a GAP event is received from the BLE core device.
* + a GATT event that has not been positively acknowledged by the registered handler is received from the
* BLE core device.
* The event is returned in a HCI packet. The full HCI packet is stored in a single buffer and is available when
* this callback is triggered. However, an ACI event may be longer than a HCI packet and could be fragmented over
* several HCI packets. The HCI layer only handles HCI packets so when an ACI packet is split over several HCI
* packets, this callback is triggered for each HCI fragment. It is the responsibility of the application to
* reassemble the ACI event.
* This callback is triggered in the TL_BLE_HCI_UserEvtProc() context
*
* @param pckt: The user event received from the BLE core device
* @retval None
*/
SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt );
/**
* @brief
*
*
* @param pckt: The user event received from the BLE core device
* @retval SVCCTL_UserEvtFlowStatus_t: SVCCTL_UserEvtFlowEnable when the packet has been processed
* SVCCTL_UserEvtFlowDisable otherwise (the packet is kept in the queue)
*/
SVCCTL_UserEvtFlowStatus_t SVCCTL_UserEvtRx( void *pckt );
/**
* @brief This API may be used by the application when the Service Controller is used to add a custom service
*
*
* @param None
* @retval None
*/
void SVCCTL_InitCustomSvc( void );
/**
* @brief This API may be overloaded by the application to select a limited list of ble services to initialize.
* It is called by SVCCTL_Init()
* By default, SVCCTL_SvcInit() is implemented to initialize all BLE services which are included in the
* application at build time
* If it is required to initialize only limited part of the BLE service available in the application,
* this API may be used to call the initialization API of the subset of needed services at run time.
*
* @param None
* @retval None
*/
void SVCCTL_SvcInit( void );
#ifdef __cplusplus
}
#endif
#endif /*__SVCCTL_H */
@@ -0,0 +1,73 @@
/**
******************************************************************************
* @file template_stm.h
* @author MCD Application Team
* @brief Header for template_stm.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TEMPLATE_STM_H
#define __TEMPLATE_STM_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
TEMPLATE_STM_NOTIFY_ENABLED_EVT,
TEMPLATE_STM_NOTIFY_DISABLED_EVT,
TEMPLATE_STM_READ_EVT,
TEMPLATE_STM_WRITE_EVT,
TEMPLATE_STM_BOOT_REQUEST_EVT,
} TEMPLATE_STM_Opcode_evt_t;
typedef struct
{
uint8_t * pPayload;
uint8_t Length;
}TEMPLATE_STM_Data_t;
typedef struct
{
TEMPLATE_STM_Opcode_evt_t Template_Evt_Opcode;
TEMPLATE_STM_Data_t DataTransfered;
uint16_t ConnectionHandle;
uint8_t ServiceInstance;
}TEMPLATE_STM_App_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void TEMPLATE_STM_Init( void );
void TEMPLATE_STM_App_Notification(TEMPLATE_STM_App_Notification_evt_t *pNotification);
tBleStatus TEMPLATE_STM_App_Update_Char(uint16_t UUID, uint8_t *pPayload);
#ifdef __cplusplus
}
#endif
#endif /*__TEMPLATE_STM_H */
@@ -0,0 +1,46 @@
/**
******************************************************************************
* @file tps.h
* @author MCD Application Team
* @brief Header for tps.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TPS_H
#define __TPS_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void TPS_Init(void);
tBleStatus TPS_Update_Char(uint16_t UUID, uint8_t *pPayload);
#ifdef __cplusplus
}
#endif
#endif /*__TPS_H */
@@ -0,0 +1,328 @@
/**
******************************************************************************
* @file uuid.h.h
* @author MCD Application Team
* @brief Header containing the UUIDs of all the services and caharcteristics
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifndef _UUID_H_
#define _UUID_H_
/* Descriptor UUIDs */
#define CHAR_EXTENDED_PROPERTIES_DESCRIPTOR_UUID (0x2900)
#define CHAR_USER_DESCRIPTION_DESCRIPTOR_UUID (0x2901)
#define CLIENT_CHAR_CONFIG_DESCRIPTOR_UUID (0x2902)
#define SERVER_CHAR_CONFIG_DESCRIPTOR_UUID (0x2903)
#define CHAR_PRESENTATION_FORMAT_DESCRIPTOR_UUID (0x2904)
#define CHAR_AGGREGATE_FORMAT_DESCRIPTOR_UUID (0x2905)
#define VALID_RANGE_DESCRIPTOR_UUID (0x2906)
#define EXTERNAL_REPORT_REFERENCE_DESCRIPTOR_UUID (0x2907)
#define REPORT_REFERENCE_DESCRIPTOR_UUID (0x2908)
#define NUMBER_OF_DIGITALS_DESCRIPTOR_UUID (0x2909)
#define VALUE_TRIGGER_SETTING_DESCRIPTOR_UUID (0x290A)
#define ES_CONFIGURATION_DESCRIPTOR_UUID (0x290B)
#define ES_MEASUREMENT_DESCRIPTOR_UUID (0x290C)
#define ES_TRIGGER_SETTING_DESCRIPTOR_UUID (0x290D)
#define TIME_TRIGGER_SETTING_DESCRIPTOR_UUID (0x290E)
/* UUIDs of Generic Attribute service */
#define GENERIC_ATTRIBUTE_SERVICE_UUID (0x1801)
#define SERVICE_CHANGED_CHARACTERISTIC_UUID (0x2A05)
/* UUIDs of immediate alert service */
#define IMMEDIATE_ALERT_SERVICE_UUID (0x1802)
#define ALERT_LEVEL_CHARACTERISTIC_UUID (0x2A06)
/* UUIDs for Link Loss service */
#define LINK_LOSS_SERVICE_UUID (0x1803)
#define LINK_LOSS_ALERT_LEVEL_CHARACTERISTIC_UUID (0x2A06)
/* UUIDs for TX Power service */
#define TX_POWER_SERVICE_UUID (0x1804)
#define TX_POWER_LEVEL_CHARACTERISTIC_UUID (0x2A07)
/* UUIDs for Time service */
#define CURRENT_TIME_SERVICE_UUID (0x1805)
#define CURRENT_TIME_CHAR_UUID (0x2A2B)
#define LOCAL_TIME_INFORMATION_CHAR_UUID (0x2A0F)
#define REFERENCE_TIME_INFORMATION_CHAR_UUID (0x2A14)
/* UUIDs for Reference Time Update service */
#define REFERENCE_UPDATE_TIME_SERVICE_UUID (0x1806)
#define TIME_UPDATE_CONTROL_POINT_CHAR_UUID (0x2A16)
#define TIME_UPDATE_STATE_CHAR_UUID (0x2A17)
/* UUIDs for Next DST Change service */
#define NEXT_DST_CHANGE_SERVICE_UUID (0x1807)
#define TIME_WITH_DST_CHAR_UUID (0x2A11)
/* UUIDs for glucose profile */
#define GLUCOSE_SERVICE_UUID (0x1808)
#define GLUCOSE_MEASUREMENT_CHAR_UUID (0x2A18)
#define GLUCOSE_MEASUREMENT_CONTEXT_CHAR_UUID (0x2A34)
#define GLUCOSE_FEATURE_CHAR_UUID (0x2A51)
/* Record Access Control Point (RACP) */
#define GLUCOSE_RACP_CHAR_UUID (0x2A52)
/* UUIDs for health thermometer profile */
#define HEALTH_THERMOMETER_SERVICE_UUID (0x1809)
#define TEMPERATURE_MEASUREMENT_CHAR_UUID (0x2A1C)
#define TEMPERATURE_TYPE_CHAR_UUID (0x2A1D)
#define INTERMEDIATE_TEMPERATURE_CHAR_UUID (0x2A1E)
#define MEASUREMENT_INTERVAL_CHAR_UUID (0x2A21)
/* UUIDs for Device Information Service */
#define DEVICE_INFORMATION_SERVICE_UUID (0x180A)
#define SYSTEM_ID_UUID (0x2A23)
#define MODEL_NUMBER_UUID (0x2A24)
#define SERIAL_NUMBER_UUID (0x2A25)
#define FIRMWARE_REVISION_UUID (0x2A26)
#define HARDWARE_REVISION_UUID (0x2A27)
#define SOFTWARE_REVISION_UUID (0x2A28)
#define MANUFACTURER_NAME_UUID (0x2A29)
#define IEEE_CERTIFICATION_UUID (0x2A2A)
#define PNP_ID_UUID (0x2A50)
/* UUIDs for Heart Rate Service */
#define HEART_RATE_SERVICE_UUID (0x180D)
#define CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID (0x2902)
#define HEART_RATE_MEASURMENT_UUID (0x2A37)
#define SENSOR_LOCATION_UUID (0x2A38)
#define CONTROL_POINT_UUID (0x2A39)
/* UUIDs for Phone Alert status profile */
#define PHONE_ALERT_SERVICE_UUID (0x180E)
#define PHONE_ALERT_STATUS_CHARAC_UUID (0x2A3F)
#define RINGER_CNTRL_POINT_CHARAC_UUID (0x2A40)
#define RINGER_SETTING_CHARAC_UUID (0x2A41)
/* UUIDs for battery service */
#define BATTERY_SERVICE_UUID (0x180F)
#define BATTERY_LEVEL_CHAR_UUID (0x2A19)
/* UUIDs for Blood Pressure profile */
#define BLOOD_PRESSURE_SERVICE_UUID (0x1810)
#define BLOOD_PRESSURE_MEASUREMENT_CHAR_UUID (0x2A35)
#define INTERMEDIATE_CUFF_PRESSURE_CHAR_UUID (0x2A36)
#define BLOOD_PRESSURE_FEATURE_CHAR_UUID (0x2A49)
/* UUIDs for alert notification profile */
#define ALERT_NOTIFICATION_SERVICE_UUID (0x1811)
#define SUPPORTED_NEW_ALERT_CATEGORY_CHAR_UUID (0x2A47)
#define NEW_ALERT_CHAR_UUID (0x2A46)
#define SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR_UUID (0x2A48)
#define UNREAD_ALERT_STATUS_CHAR_UUID (0x2A45)
#define ALERT_NOTIFICATION_CONTROL_POINT_CHAR_UUID (0x2A44)
/* UUIDs for human interface device */
#define HUMAN_INTERFACE_DEVICE_SERVICE_UUID (0x1812)
#define PROTOCOL_MODE_CHAR_UUID (0x2A4E)
#define REPORT_CHAR_UUID (0x2A4D)
#define REPORT_MAP_CHAR_UUID (0x2A4B)
#define BOOT_KEYBOARD_INPUT_REPORT_CHAR_UUID (0x2A22)
#define BOOT_KEYBOARD_OUTPUT_REPORT_CHAR_UUID (0x2A32)
#define BOOT_MOUSE_INPUT_REPORT_CHAR_UUID (0x2A33)
#define HID_INFORMATION_CHAR_UUID (0x2A4A)
#define HID_CONTROL_POINT_CHAR_UUID (0x2A4C)
/* UUIDs for scan parameter service */
#define SCAN_PARAMETER_SERVICE_UUID (0x1813)
#define SCAN_INTERVAL_WINDOW_CHAR_UUID (0x2A4F)
#define SCAN_REFRESH_CHAR_UUID (0x2A31)
/* UUIDs for running speed and cadence service */
#define RUNNING_SPEED_CADENCE_SERVICE_UUID (0x1814)
#define RUNNING_SPEED_CADENCE_MEASUREMENT_CHAR_UUID (0x2A53)
#define RUNNING_SPEED_CADENCE_FEATURE_CHAR_UUID (0x2A54)
/* UUIDs for automation IO service */
#define AUTOMATION_IO_SERVICE_UUID (0x1815)
#define AUTOMATION_IO_DIGITAL_CHAR_UUID (0x2A56)
#define AUTOMATION_IO_ANALOG_CHAR_UUID (0x2A58)
#define AUTOMATION_IO_AGGREGATE_CHAR_UUID (0x2A5A)
/* UUIDs for cycling speed and cadence service */
#define CYCLING_SPEED_CADENCE_SERVICE_UUID (0x1816)
#define CYCLING_SPEED_CADENCE_MEASUREMENT_CHAR_UUID (0x2A5B)
#define CYCLING_SPEED_CADENCE_FEATURE_CHAR_UUID (0x2A5C)
/* UUIDs for cycling power service */
#define CYCLING_POWER_SERVICE_UUID (0x1818)
#define CYCLING_POWER_MEASUREMENT_CHAR_UUID (0x2A63)
#define CYCLING_POWER_FEATURE_CHAR_UUID (0x2A65)
#define CYCLING_POWER_SENSOR_LOCATION_CHAR_UUID (0x2A5D)
/* UUIDs for location and navigation device */
#define LOCATION_NAVIGATION_SERVICE_UUID (0x1819)
#define LN_FEATURE_UUID (0x2A6A)
#define LOCATION_SPEED_UUID (0x2A67)
#define POSITION_QUALITY_UUID (0x2A69)
#define LN_CONTROL_POINT_UUID (0x2A6B)
#define NAVIGATION_UUID (0x2A68)
/* UUIDs for environmental sensing profile */
#define ENVIRONMENTAL_SENSING_SERVICE_UUID (0x181A)
#define DESCRIPTOR_VALUE_CHANGED_UUID (0x2A7D)
#define APPARENT_WIND_DIRECTION_UUID (0x2A73)
#define APPARENT_WIND_SPEED_UUID (0x2A72)
#define DEW_POINT_UUID (0x2A7B)
#define ELEVATION_UUID (0x2A6C)
#define GUST_FACTOR_UUID (0x2A74)
#define HEAT_INDEX_UUID (0x2A7A)
#define HUMIDITY_UUID (0x2A6F)
#define IRRADIANCE_UUID (0x2A77)
#define POLLEN_CONCENTRATION_UUID (0x2A75)
#define RAINFALL_UUID (0x2A78)
#define PRESSURE_UUID (0x2A6D)
#define TEMPERATURE_UUID (0x2A6E)
#define TRUE_WIND_DIRECTION_UUID (0x2A71)
#define TRUE_WIND_SPEED_UUID (0x2A70)
#define UV_INDEX_UUID (0x2A76)
#define WIND_CHILL_UUID (0x2A79)
#define BAROMETRIC_PRESSURE_TREND_UUID (0x2AA3)
#define MAGNETIC_DECLINATION_UUID (0x2A2C)
#define MAGNETIC_FLUX_DENSITY_2D_UUID (0x2AA0)
#define MAGNETIC_FLUX_DENSITY_3D_UUID (0x2AA1)
/* UUIDs for body composition service */
#define BODY_COMPOSITION_SERVICE_UUID (0x181B)
#define BODY_COMPOSITION_MEASUREMENT_CHAR_UUID (0x2A9C)
#define BODY_COMPOSITION_FEATURE_CHARAC (0x2A9B)
/* UUIDs for user data service */
#define USER_DATA_SERVICE_UUID (0x181C)
#define AERO_HR_LOWER_LIMIT_CHAR_UUID (0x2A7E)
#define AEROBIC_THRESHOLD_CHAR_UUID (0x2A7F)
#define AGE_CHAR_UUID (0x2A80)
#define ANAERO_HR_LOWER_LIMIT_CHAR_UUID (0x2A81)
#define ANAERO_HR_UPPER_LIMIT_CHAR_UUID (0x2A82)
#define ANAEROBIC_THRESHOLD_CHAR_UUID (0x2A83)
#define AERO_HR_UPPER_LIMIT_CHAR_UUID (0x2A84)
#define BIRTH_DATE_CHAR_UUID (0x2A85)
#define DATE_THRESHOLD_ASSESSMENT_CHAR_UUID (0x2A86)
#define EMAIL_ADDRESS_CHAR_UUID (0x2A87)
#define FAT_BURN_HR_LOWER_LIMIT_CHAR_UUID (0x2A88)
#define FAT_BURN_HR_UPPER_LIMIT_CHAR_UUID (0x2A89)
#define FIRST_NAME_CHAR_UUID (0x2A8A)
#define FIVE_ZONE_HR_LIMIT_CHAR_UUID (0x2A8B)
#define GENDER_CHAR_UUID (0x2A8C)
#define HEART_RATE_MAX_CHAR_UUID (0x2A8D)
#define HEIGHT_CHAR_UUID (0x2A8E)
#define HIP_CIRC_CHAR_UUID (0x2A8F)
#define LAST_NAME_CHAR_UUID (0x2A90)
#define MAX_RECO_HEART_RATE_CHAR_UUID (0x2A91)
#define RESTING_HEART_RATE_CHAR_UUID (0x2A92)
#define SPORT_TYPE_CHAR_UUID (0x2A93)
#define THREE_ZONE_HR_LIMIT_CHAR_UUID (0x2A94)
#define TWO_ZONE_HR_LIMIT_CHAR_UUID (0x2A95)
#define VO2_MAX_CHAR_UUID (0x2A96)
#define WAIST_CIRC_CHAR_UUID (0x2A97)
#define WEIGHT_CHAR_UUID (0x2A98)
#define DATABASE_CHANGE_INCREMENT_CHAR_UUID (0x2A99)
#define USER_INDEX_CHAR_UUID (0x2A9A)
#define USER_CONTROL_POINT_CHAR_UUID (0x2A9F)
#define LANGUAGE_CHAR_UUID (0x2AA2)
/* UUIDs for weight scale profile */
#define WEIGHT_SCALE_SERVICE_UUID (0x181D)
#define WEIGHT_SCALE_MEASUREMENT_CHAR_UUID (0x2A9D)
#define WEIGHT_SCALE_FEATURE_CHAR_UUID (0x2A9E)
/* UUIDs for weight scale profile */
#define BOND_MANAGEMENT_SERVICE_UUID (0x181E)
#define BM_CONTROL_POINT_CHAR_UUID (0x2AA4)
#define BM_FEATURE_CHAR_UUID (0x2AA5)
/* UUIDs for Internet Support Service */
#define INTERNET_SUPPORT_SERVICE_UUID (0x1820)
/* UUIDs for Indoor Positioning Service */
#define INDOOR_POSITIONING_SERVICE_UUID (0x1821)
#define IP_CONFIGURATION_CHAR_UUID (0x2AAD)
#define IP_LATITUDE_CHAR_UUID (0x2AAE)
#define IP_LONGITUDE_CHAR_UUID (0x2AAF)
/* UUIDs for HTTP proxy Service */
#define HTTP_PROXY_SERVICE_UUID (0x1823)
#define HTTP_URI_CHAR_UUID (0x2AB6)
#define HTTP_HEADERS_CHAR_UUID (0x2AB7)
#define HTTP_STATUS_CODE_CHAR_UUID (0x2AB8)
#define HTTP_ENTITY_BODY_CHAR_UUID (0x2AB9)
#define HTTP_CONTROL_POINT_CHAR_UUID (0x2ABA)
#define HTTP_SECURITY_CHAR_UUID (0x2ABB)
/* UUIDs for Object Transfer Service */
#define OBJECT_TRANSFER_SERVICE_UUID (0x1825)
#define OTS_FEATURE_CHAR_UUID (0x2ABD)
#define OBJECT_NAME_CHAR_UUID (0x2ABE)
#define OBJECT_TYPE_CHAR_UUID (0x2ABF)
#define OBJECT_SIZE_CHAR_UUID (0x2AC0)
#define OBJECT_PROPERTIES_CHAR_UUID (0x2AC4)
#define OBJECT_ACTION_CONTROL_POINT_CHAR_UUID (0x2AC5)
#define OBJECT_LIST_CONTROL_POINT_CHAR_UUID (0x2AC6)
/* UUIDs for Zigbee Direct Service */
#define ZIGBEE_DIRECT_COMM_SERVICE_UUID (0xFFF7)
/* Custom Services*/
/* UUIDs for data transfer service */
#define DT_SERVICE_UUID (0xFE80)
#define DT_TX_CHAR_UUID (0xFE81)
#define DT_RX_CHAR_UUID (0xFE82)
#define DT_THROUGHPUT_CHAR_UUID (0xFE83)
/* UUIDs for custom battery service */
#define CUSTOM_BATTERY_SERVICE_UUID (0xF2F0)
#define CUSTOM_BATTERY_LEVEL_CHAR_UUID (0xF2F1)
/* Custom Services*/
/* UUIDs for data transfer service */
#define LED_BUTTON_SERVICE_UUID (0x1A30)
#define LED_CHAR_UUID (0x2B50)
#define BUTTON_CHAR_UUID (0x2B51)
/*UUIDs for End Device Management Service*/
#define END_DEVICE_MGT_SERVICE_UUID (0x1A40)
#define END_DEVICE_STATUS_CHAR_UUID (0x2B60)
#define P2P_SERVICE_UUID (0xFE40)
#define P2P_WRITE_CHAR_UUID (0xFE41)
#define P2P_NOTIFY_CHAR_UUID (0xFE42)
#define HOME_SERVICE_UUID (0xFE90)
#define HOME_WRITE_CHAR_UUID (0xFE91)
#define HOME_NOTIFY_CHAR_UUID (0xFE92)
#define CAM_SERVICE_UUID (0xFEA0)
#define CAM_WRITE_CHAR_UUID (0xFEA1)
#define CAM_NOTIFY_CHAR_UUID (0xFEA2)
/* UUIDs for Cable Replacement Service */
#define CRS_SERVICE_UUID (0xFE60)
#define CRS_TX_CHAR_UUID (0xFE61)
#define CRS_RX_CHAR_UUID (0xFE62)
/* UUIDs for Apple Notification Center Service */
#define ANCS_SERVICE_UUID (0xF431)
#define ANCS_NOTIFICATION_SOURCE_CHAR_UUID (0x120D)
#define ANCS_CONTROL_POINT_CHAR_UUID (0xD8F3)
#define ANCS_DATA_SOURCE_CHAR_UUID (0xC6E9)
/* UUIDs for Apple Media Service start from iOS 8*/
#define AMS_SERVICE_UUID (0x502B)
#define AMS_REMOTE_COMMAND_CHAR_UUID (0x81D8)
#define AMS_ENTITY_UPDATE_CHAR_UUID (0xABCE)
#define AMS_ENTITY_ATTRIBUTE_CHAR_UUID (0xF38C)
#endif /* _UUID_H_ */
@@ -0,0 +1,100 @@
/**
******************************************************************************
* @file zdd_stm.h
* @author MCD Application Team
* @brief Header for zdd_stm.c module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ZDD_STM_H
#define __ZDD_STM_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
/* ZDD P2P Events */
ZDD_P2P_STM__NOTIFY_ENABLED_EVT,
ZDD_P2P_STM_NOTIFY_DISABLED_EVT,
ZDD_P2P_STM_READ_EVT,
ZDD_P2P_STM_WRITE_EVT,
ZDD_P2P_STM_BOOT_REQUEST_EVT,
/* ZDD Security Events */
ZDD_SEC_P_256_INDICATE_ENABLED_EVT,
ZDD_SEC_P_256_INDICATE_DISABLED_EVT,
ZDD_SEC_P_256_WRITE_EVT,
ZDD_SEC_CURVE25519_INDICATE_ENABLED_EVT,
ZDD_SEC_CURVE25519_INDICATE_DISABLED_EVT,
ZDD_SEC_CURVE25519_WRITE_EVT,
/* ZDD Commissioning Events */
ZDD_COMM_FORM_NWK_WRITE_EVT,
ZDD_COMM_JOIN_NWK_WRITE_EVT,
ZDD_COMM_PERMIT_JOIN_WRITE_EVT,
ZDD_COMM_LEAVE_NWK_WRITE_EVT,
ZDD_COMM_STATUS_NOTIFY_ENABLED_EVT,
ZDD_COMM_STATUS_NOTIFY_DISABLED_EVT,
ZDD_COMM_STATUS_READ_EVT,
/* ZDD Tunnelling Events */
ZDD_TUNN_ZDTS_NPDU_INDICATE_ENABLED_EVT,
ZDD_TUNN_ZDTS_NPDU_INDICATE_DISABLED_EVT,
ZDD_TUNN_ZDTS_NPDU_WRITE_EVT
} ZDD_STM_Opcode_evt_t;
typedef struct
{
uint8_t * pPayload;
uint8_t Length;
}ZDD_STM_Data_t;
typedef struct
{
ZDD_STM_Opcode_evt_t ZDD_Evt_Opcode;
ZDD_STM_Data_t DataTransfered;
uint16_t ConnectionHandle;
uint8_t ServiceInstance;
}ZDD_STM_App_Notification_evt_t;
/* Exported constants --------------------------------------------------------*/
#define ZDD_P2P_NOTIFY_CHAR_UUID P2P_NOTIFY_CHAR_UUID /* Temp */
#define ZDD_SEC_P_256_CHAR_UUID (0xAF42) /* P-256 */
#define ZDD_SEC_CURVE25519_CHAR_UUID (0xAF43) /* Curve25519 */
#define ZDD_COMM_STATUS_CHAR_UUID (0x377D) /* Commissioning Status */
#define ZDD_TUNN_ZDTS_NPDU_CHAR_UUID (0x78FD) /* ZDTS-NPDU */
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void ZDD_STM_Init( void );
void ZDD_STM_App_Notification(ZDD_STM_App_Notification_evt_t *pNotification);
tBleStatus ZDD_STM_App_Update_Char(uint16_t UUID, uint8_t payloadLen, uint8_t *pPayload);
#ifdef __cplusplus
}
#endif
#endif /*__ZDD_STM_H */
@@ -0,0 +1,54 @@
/**
******************************************************************************
* @file common_blesvc.h
* @author MCD Application Team
* @brief Header for ble modules
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __COMMON_BLESVC_H
#define __COMMON_BLESVC_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "ble_common.h"
#include "ble.h"
#include "dbg_trace.h"
/* Exported types ------------------------------------------------------------*/
typedef enum
{
COMSVC_Notification = ( 1 << 0 ),
COMSVC_Indication = ( 1 << 1 ),
} COMSVC_ClientCharConfMask_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif /*__COMMON_BLESVC_H */
@@ -0,0 +1,330 @@
/**
******************************************************************************
* @file svc_ctl.c
* @author MCD Application Team
* @brief BLE Controller
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "common_blesvc.h"
#include "cmsis_compiler.h"
/* Private typedef -----------------------------------------------------------*/
typedef struct
{
#if (BLE_CFG_SVC_MAX_NBR_CB > 0)
SVC_CTL_p_EvtHandler_t SVCCTL__SvcHandlerTab[BLE_CFG_SVC_MAX_NBR_CB];
#endif
uint8_t NbreOfRegisteredHandler;
} SVCCTL_EvtHandler_t;
typedef struct
{
#if (BLE_CFG_CLT_MAX_NBR_CB > 0)
SVC_CTL_p_EvtHandler_t SVCCTL_CltHandlerTable[BLE_CFG_CLT_MAX_NBR_CB];
#endif
uint8_t NbreOfRegisteredHandler;
} SVCCTL_CltHandler_t;
/* Private defines -----------------------------------------------------------*/
#define SVCCTL_EGID_EVT_MASK 0xFF00
#define SVCCTL_GATT_EVT_TYPE 0x0C00
#define SVCCTL_GAP_DEVICE_NAME_LENGTH 7
/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/**
* START of Section BLE_DRIVER_CONTEXT
*/
PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") SVCCTL_EvtHandler_t SVCCTL_EvtHandler;
PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") SVCCTL_CltHandler_t SVCCTL_CltHandler;
/**
* END of Section BLE_DRIVER_CONTEXT
*/
/* Private functions ----------------------------------------------------------*/
/* Weak functions ----------------------------------------------------------*/
void BVOPUS_STM_Init(void);
__WEAK void BAS_Init( void )
{
return;
}
__WEAK void BLS_Init( void )
{
return;
}
__WEAK void CRS_STM_Init( void )
{
return;
}
__WEAK void DIS_Init( void )
{
return;
}
__WEAK void EDS_STM_Init( void )
{
return;
}
__WEAK void HIDS_Init( void )
{
return;
}
__WEAK void HRS_Init( void )
{
return;
}
__WEAK void HTS_Init( void )
{
return;
}
__WEAK void IAS_Init( void )
{
return;
}
__WEAK void LLS_Init( void )
{
return;
}
__WEAK void TPS_Init( void )
{
return;
}
__WEAK void MOTENV_STM_Init( void )
{
return;
}
__WEAK void P2PS_STM_Init( void )
{
return;
}
__WEAK void ZDD_STM_Init( void )
{
return;
}
__WEAK void OTAS_STM_Init( void )
{
return;
}
__WEAK void MESH_Init( void )
{
return;
}
__WEAK void BVOPUS_STM_Init( void )
{
return;
}
__WEAK void SVCCTL_InitCustomSvc( void )
{
return;
}
/* Functions Definition ------------------------------------------------------*/
void SVCCTL_Init( void )
{
/**
* Initialize the number of registered Handler
*/
SVCCTL_EvtHandler.NbreOfRegisteredHandler = 0;
SVCCTL_CltHandler.NbreOfRegisteredHandler = 0;
/**
* Add and Initialize requested services
*/
SVCCTL_SvcInit();
return;
}
__WEAK void SVCCTL_SvcInit(void)
{
BAS_Init();
BLS_Init();
CRS_STM_Init();
DIS_Init();
EDS_STM_Init();
HIDS_Init();
HRS_Init();
HTS_Init();
IAS_Init();
LLS_Init();
TPS_Init();
MOTENV_STM_Init();
P2PS_STM_Init();
ZDD_STM_Init();
OTAS_STM_Init();
BVOPUS_STM_Init();
MESH_Init();
SVCCTL_InitCustomSvc();
return;
}
/**
* @brief BLE Controller initialization
* @param None
* @retval None
*/
void SVCCTL_RegisterSvcHandler( SVC_CTL_p_EvtHandler_t pfBLE_SVC_Service_Event_Handler )
{
#if (BLE_CFG_SVC_MAX_NBR_CB > 0)
SVCCTL_EvtHandler.SVCCTL__SvcHandlerTab[SVCCTL_EvtHandler.NbreOfRegisteredHandler] = pfBLE_SVC_Service_Event_Handler;
SVCCTL_EvtHandler.NbreOfRegisteredHandler++;
#else
(void)(pfBLE_SVC_Service_Event_Handler);
#endif
return;
}
/**
* @brief BLE Controller initialization
* @param None
* @retval None
*/
void SVCCTL_RegisterCltHandler( SVC_CTL_p_EvtHandler_t pfBLE_SVC_Client_Event_Handler )
{
#if (BLE_CFG_CLT_MAX_NBR_CB > 0)
SVCCTL_CltHandler.SVCCTL_CltHandlerTable[SVCCTL_CltHandler.NbreOfRegisteredHandler] = pfBLE_SVC_Client_Event_Handler;
SVCCTL_CltHandler.NbreOfRegisteredHandler++;
#else
(void)(pfBLE_SVC_Client_Event_Handler);
#endif
return;
}
__WEAK SVCCTL_UserEvtFlowStatus_t SVCCTL_UserEvtRx( void *pckt )
{
hci_event_pckt *event_pckt;
evt_blecore_aci *blecore_evt;
SVCCTL_EvtAckStatus_t event_notification_status;
SVCCTL_UserEvtFlowStatus_t return_status;
uint8_t index;
event_pckt = (hci_event_pckt*) ((hci_uart_pckt *) pckt)->data;
event_notification_status = SVCCTL_EvtNotAck;
switch (event_pckt->evt)
{
case HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE:
{
blecore_evt = (evt_blecore_aci*) event_pckt->data;
switch ((blecore_evt->ecode) & SVCCTL_EGID_EVT_MASK)
{
case SVCCTL_GATT_EVT_TYPE:
#if (BLE_CFG_SVC_MAX_NBR_CB > 0)
/* For Service event handler */
for (index = 0; index < SVCCTL_EvtHandler.NbreOfRegisteredHandler; index++)
{
event_notification_status = SVCCTL_EvtHandler.SVCCTL__SvcHandlerTab[index](pckt);
/**
* When a GATT event has been acknowledged by a Service, there is no need to call the other registered handlers
* a GATT event is relevant for only one Service
*/
if (event_notification_status != SVCCTL_EvtNotAck)
{
/**
* The event has been managed. The Event processing should be stopped
*/
break;
}
}
#endif
#if (BLE_CFG_CLT_MAX_NBR_CB > 0)
/* For Client event handler */
event_notification_status = SVCCTL_EvtNotAck;
for(index = 0; index <SVCCTL_CltHandler.NbreOfRegisteredHandler; index++)
{
event_notification_status = SVCCTL_CltHandler.SVCCTL_CltHandlerTable[index](pckt);
/**
* When a GATT event has been acknowledged by a Client, there is no need to call the other registered handlers
* a GATT event is relevant for only one Client
*/
if (event_notification_status != SVCCTL_EvtNotAck)
{
/**
* The event has been managed. The Event processing should be stopped
*/
break;
}
}
#endif
break;
default:
break;
}
}
break; /* HCI_HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE_SPECIFIC */
default:
break;
}
/**
* When no registered handlers (either Service or Client) has acknowledged the GATT event, it is reported to the application
* a GAP event is always reported to the application.
*/
switch (event_notification_status)
{
case SVCCTL_EvtNotAck:
/**
* The event has NOT been managed.
* It shall be passed to the application for processing
*/
return_status = SVCCTL_App_Notification(pckt);
break;
case SVCCTL_EvtAckFlowEnable:
return_status = SVCCTL_UserEvtFlowEnable;
break;
case SVCCTL_EvtAckFlowDisable:
return_status = SVCCTL_UserEvtFlowDisable;
break;
default:
return_status = SVCCTL_UserEvtFlowEnable;
break;
}
return (return_status);
}
@@ -0,0 +1,105 @@
/**
******************************************************************************
* @file hw.h
* @author MCD Application Team
* @brief Hardware
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HW_H
#define __HW_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/******************************************************************************
* HW IPCC
******************************************************************************/
void HW_IPCC_Enable( void );
void HW_IPCC_Init( void );
void HW_IPCC_Rx_Handler( void );
void HW_IPCC_Tx_Handler( void );
void HW_IPCC_BLE_Init( void );
void HW_IPCC_BLE_SendCmd( void );
void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) );
void HW_IPCC_BLE_RxEvtNot( void );
void HW_IPCC_BLE_SendAclData( void );
void HW_IPCC_BLE_AclDataAckNot( void );
void HW_IPCC_SYS_Init( void );
void HW_IPCC_SYS_SendCmd( void );
void HW_IPCC_SYS_CmdEvtNot( void );
void HW_IPCC_SYS_EvtNot( void );
void HW_IPCC_THREAD_Init( void );
void HW_IPCC_OT_SendCmd( void );
void HW_IPCC_CLI_SendCmd( void );
void HW_IPCC_THREAD_SendAck( void );
void HW_IPCC_OT_CmdEvtNot( void );
void HW_IPCC_CLI_CmdEvtNot( void );
void HW_IPCC_THREAD_EvtNot( void );
void HW_IPCC_THREAD_CliSendAck( void );
void HW_IPCC_THREAD_CliEvtNot( void );
void HW_IPCC_LLDTESTS_Init( void );
void HW_IPCC_LLDTESTS_SendCliCmd( void );
void HW_IPCC_LLDTESTS_ReceiveCliRsp( void );
void HW_IPCC_LLDTESTS_SendCliRspAck( void );
void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void );
void HW_IPCC_LLDTESTS_SendM0CmdAck( void );
void HW_IPCC_BLE_LLD_Init( void );
void HW_IPCC_BLE_LLD_SendCliCmd( void );
void HW_IPCC_BLE_LLD_ReceiveCliRsp( void );
void HW_IPCC_BLE_LLD_SendCliRspAck( void );
void HW_IPCC_BLE_LLD_ReceiveM0Cmd( void );
void HW_IPCC_BLE_LLD_SendM0CmdAck( void );
void HW_IPCC_BLE_LLD_SendCmd( void );
void HW_IPCC_BLE_LLD_ReceiveRsp( void );
void HW_IPCC_BLE_LLD_SendRspAck( void );
void HW_IPCC_TRACES_Init( void );
void HW_IPCC_TRACES_EvtNot( void );
void HW_IPCC_MAC_802_15_4_Init( void );
void HW_IPCC_MAC_802_15_4_SendCmd( void );
void HW_IPCC_MAC_802_15_4_SendAck( void );
void HW_IPCC_MAC_802_15_4_CmdEvtNot( void );
void HW_IPCC_MAC_802_15_4_EvtNot( void );
void HW_IPCC_ZIGBEE_Init( void );
void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */
void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */
void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */
void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */
void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */
void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */
#ifdef __cplusplus
}
#endif
#endif /*__HW_H */
@@ -0,0 +1,780 @@
/**
******************************************************************************
* @file shci.c
* @author MCD Application Team
* @brief HCI command for the system channel
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32_wpan_common.h"
#include "shci_tl.h"
#include "shci.h"
#include "stm32wbxx.h"
/* Private typedef -----------------------------------------------------------*/
/* Private defines -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Global variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Local Functions Definition ------------------------------------------------------*/
/* Public Functions Definition ------------------------------------------------------*/
/**
* C2 COMMAND
* These commands are sent to the CPU2
*/
uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code )
{
/**
* Buffer is large enough to hold command complete with payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE + 1];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_FUS_GET_STATE,
0,
0,
p_rsp );
if(p_error_code != 0)
{
*p_error_code = (SHCI_FUS_GetState_ErrorCode_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1]);
}
return (((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_add )
{
/**
* TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 8 bytes of command parameters
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
uint32_t *p_cmd;
uint8_t cmd_length;
p_cmd = (uint32_t*)local_buffer;
cmd_length = 0;
if(fw_src_add != 0)
{
*p_cmd = fw_src_add;
cmd_length += 4;
}
if(fw_dest_add != 0)
{
*(p_cmd+1) = fw_dest_add;
cmd_length += 4;
}
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_FUS_FW_UPGRADE,
cmd_length,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_FUS_FW_DELETE,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_FwPurge( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_FUS_FW_PURGE,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY,
sizeof( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t ),
(uint8_t*)pParam,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index )
{
/**
* Buffer is large enough to hold command complete with payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE + 1];
TL_EvtPacket_t * p_rsp;
uint8_t local_payload_len;
if(pParam->KeyType == KEYTYPE_ENCRYPTED)
{
/**
* When the key is encrypted, the 12 bytes IV Key is included in the payload as well
* The IV key is always 12 bytes
*/
local_payload_len = pParam->KeySize + 2 + 12;
}
else
{
local_payload_len = pParam->KeySize + 2;
}
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_FUS_STORE_USR_KEY,
local_payload_len ,
(uint8_t*)pParam,
p_rsp );
*p_key_index = (((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1]);
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = key_index;
shci_send( SHCI_OPCODE_C2_FUS_LOAD_USR_KEY,
1,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_FUS_START_WS,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = key_index;
shci_send( SHCI_OPCODE_C2_FUS_LOCK_USR_KEY,
1,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = key_index;
shci_send( SHCI_OPCODE_C2_FUS_UNLOAD_USR_KEY,
1,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_FUS_ACTIVATE_ANTIROLLBACK,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_BLE_INIT,
sizeof( SHCI_C2_Ble_Init_Cmd_Param_t ),
(uint8_t*)&pCmdPacket->Param,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_THREAD_INIT,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_LLD_TESTS_INIT,
param_size,
p_param,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_BLE_LLD_INIT,
param_size,
p_param,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_DEBUG_INIT,
sizeof( SHCI_C2_DEBUG_init_Cmd_Param_t ),
(uint8_t*)&pCmdPacket->Param,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activity )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = erase_activity;
shci_send( SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY,
1,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mode )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = Mode;
shci_send( SHCI_OPCODE_C2_CONCURRENT_SET_MODE,
1,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t *pParam )
{
/**
* Buffer is large enough to hold command complete with payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE+4];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME,
0,
0,
p_rsp );
memcpy((void*)&(pParam->relative_time), (void*)&((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1], sizeof(pParam->relative_time));
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = Ip;
shci_send( SHCI_OPCODE_C2_FLASH_STORE_DATA,
1,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = Ip;
shci_send( SHCI_OPCODE_C2_FLASH_ERASE_DATA,
1,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn)
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = Ip;
local_buffer[1] = FlagRadioLowPowerOn;
shci_send( SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER,
2,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_Reinit( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_REINIT,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status)
{
/**
* TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 8 bytes of command parameters
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_port = gpio_port;
((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_pin_number = gpio_pin_number;
((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_polarity = gpio_polarity;
((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_status = gpio_status;
shci_send( SHCI_OPCODE_C2_EXTPA_CONFIG,
8,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source)
{
/**
* TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 1 byte of command parameter
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = (uint8_t)Source;
shci_send( SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL,
1,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket)
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_CONFIG,
sizeof(SHCI_C2_CONFIG_Cmd_Param_t),
(uint8_t*)pCmdPacket,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
shci_send( SHCI_OPCODE_C2_802_15_4_DEINIT,
0,
0,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
SHCI_CmdStatus_t SHCI_C2_SetSystemClock( SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t clockSel )
{
/**
* Buffer is large enough to hold command complete without payload
*/
uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE];
TL_EvtPacket_t * p_rsp;
p_rsp = (TL_EvtPacket_t *)local_buffer;
local_buffer[0] = (uint8_t)clockSel;
shci_send( SHCI_OPCODE_C2_SET_SYSTEM_CLOCK,
1,
local_buffer,
p_rsp );
return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]);
}
/**
* Local System COMMAND
* These commands are NOT sent to the CPU2
*/
SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo )
{
uint32_t ipccdba = 0;
MB_RefTable_t * p_RefTable = NULL;
uint32_t wireless_firmware_version = 0;
uint32_t wireless_firmware_memorySize = 0;
uint32_t wireless_firmware_infoStack = 0;
MB_FUS_DeviceInfoTable_t * p_fus_device_info_table = NULL;
uint32_t fus_version = 0;
uint32_t fus_memorySize = 0;
ipccdba = READ_BIT( FLASH->IPCCBR, FLASH_IPCCBR_IPCCDBA );
/**
* The Device Info Table mapping depends on which firmware is running on CPU2.
* If the FUS is running on CPU2, FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD shall be written in the table.
* Otherwise, it means the Wireless Firmware is running on the CPU2
*/
p_fus_device_info_table = (MB_FUS_DeviceInfoTable_t*)(*(uint32_t*)((ipccdba<<2) + SRAM2A_BASE));
if(p_fus_device_info_table->DeviceInfoTableState == FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD)
{
/* The FUS is running on CPU2 */
/**
* Retrieve the WirelessFwInfoTable
* This table is stored in RAM at startup during the TL (transport layer) initialization
*/
wireless_firmware_version = p_fus_device_info_table->WirelessStackVersion;
wireless_firmware_memorySize = p_fus_device_info_table->WirelessStackMemorySize;
wireless_firmware_infoStack = p_fus_device_info_table->WirelessFirmwareBleInfo;
/**
* Retrieve the FusInfoTable
* This table is stored in RAM at startup during the TL (transport layer) initialization
*/
fus_version = p_fus_device_info_table->FusVersion;
fus_memorySize = p_fus_device_info_table->FusMemorySize;
}
else
{
/* The Wireless Firmware is running on CPU2 */
p_RefTable = (MB_RefTable_t*)((ipccdba<<2) + SRAM2A_BASE);
/**
* Retrieve the WirelessFwInfoTable
* This table is stored in RAM at startup during the TL (transport layer) initialization
*/
wireless_firmware_version = p_RefTable->p_device_info_table->WirelessFwInfoTable.Version;
wireless_firmware_memorySize = p_RefTable->p_device_info_table->WirelessFwInfoTable.MemorySize;
wireless_firmware_infoStack = p_RefTable->p_device_info_table->WirelessFwInfoTable.InfoStack;
/**
* Retrieve the FusInfoTable
* This table is stored in RAM at startup during the TL (transport layer) initialization
*/
fus_version = p_RefTable->p_device_info_table->FusInfoTable.Version;
fus_memorySize = p_RefTable->p_device_info_table->FusInfoTable.MemorySize;
}
/**
* Retrieve the WirelessFwInfoTable
* This table is stored in RAM at startup during the TL (transport layer) initialization
*/
pWirelessInfo->VersionMajor = ((wireless_firmware_version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET);
pWirelessInfo->VersionMinor = ((wireless_firmware_version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET);
pWirelessInfo->VersionSub = ((wireless_firmware_version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET);
pWirelessInfo->VersionBranch = ((wireless_firmware_version & INFO_VERSION_BRANCH_MASK) >> INFO_VERSION_BRANCH_OFFSET);
pWirelessInfo->VersionReleaseType = ((wireless_firmware_version & INFO_VERSION_TYPE_MASK) >> INFO_VERSION_TYPE_OFFSET);
pWirelessInfo->MemorySizeSram2B = ((wireless_firmware_memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET);
pWirelessInfo->MemorySizeSram2A = ((wireless_firmware_memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET);
pWirelessInfo->MemorySizeSram1 = ((wireless_firmware_memorySize & INFO_SIZE_SRAM1_MASK) >> INFO_SIZE_SRAM1_OFFSET);
pWirelessInfo->MemorySizeFlash = ((wireless_firmware_memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET);
pWirelessInfo->StackType = ((wireless_firmware_infoStack & INFO_STACK_TYPE_MASK) >> INFO_STACK_TYPE_OFFSET);
/**
* Retrieve the FusInfoTable
* This table is stored in RAM at startup during the TL (transport layer) initialization
*/
pWirelessInfo->FusVersionMajor = ((fus_version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET);
pWirelessInfo->FusVersionMinor = ((fus_version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET);
pWirelessInfo->FusVersionSub = ((fus_version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET);
pWirelessInfo->FusMemorySizeSram2B = ((fus_memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET);
pWirelessInfo->FusMemorySizeSram2A = ((fus_memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET);
pWirelessInfo->FusMemorySizeFlash = ((fus_memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET);
return (SHCI_Success);
}
@@ -0,0 +1,308 @@
/**
******************************************************************************
* @file hci_tl.c
* @author MCD Application Team
* @brief Function for managing HCI interface.
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "ble_common.h"
#include "ble_const.h"
#include "stm_list.h"
#include "tl.h"
#include "hci_tl.h"
/* Private typedef -----------------------------------------------------------*/
typedef enum
{
HCI_TL_CMD_RESP_RELEASE,
HCI_TL_CMD_RESP_WAIT,
} HCI_TL_CmdRespStatus_t;
/* Private defines -----------------------------------------------------------*/
/**
* The default HCI layer timeout is set to 33s
*/
#define HCI_TL_DEFAULT_TIMEOUT (33000)
/* Private macros ------------------------------------------------------------*/
/* Public variables ---------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/**
* START of Section BLE_DRIVER_CONTEXT
*/
PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") static volatile uint8_t hci_timer_id;
PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") static tListNode HciAsynchEventQueue;
PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") static TL_CmdPacket_t *pCmdBuffer;
PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") HCI_TL_UserEventFlowStatus_t UserEventFlow;
/**
* END of Section BLE_DRIVER_CONTEXT
*/
static tHciContext hciContext;
static tListNode HciCmdEventQueue;
static void (* StatusNotCallBackFunction) (HCI_TL_CmdStatus_t status);
static volatile HCI_TL_CmdRespStatus_t CmdRspStatusFlag;
/* Private function prototypes -----------------------------------------------*/
static void NotifyCmdStatus(HCI_TL_CmdStatus_t hcicmdstatus);
static void SendCmd(uint16_t opcode, uint8_t plen, void *param);
static void TlEvtReceived(TL_EvtPacket_t *hcievt);
static void TlInit( TL_CmdPacket_t * p_cmdbuffer );
/* Interface ------- ---------------------------------------------------------*/
void hci_init(void(* UserEvtRx)(void* pData), void* pConf)
{
StatusNotCallBackFunction = ((HCI_TL_HciInitConf_t *)pConf)->StatusNotCallBack;
hciContext.UserEvtRx = UserEvtRx;
hci_register_io_bus (&hciContext.io);
TlInit((TL_CmdPacket_t *)(((HCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer));
return;
}
void hci_user_evt_proc(void)
{
TL_EvtPacket_t *phcievtbuffer;
tHCI_UserEvtRxParam UserEvtRxParam;
/**
* Up to release version v1.2.0, a while loop was implemented to read out events from the queue as long as
* it is not empty. However, in a bare metal implementation, this leads to calling in a "blocking" mode
* hci_user_evt_proc() as long as events are received without giving the opportunity to run other tasks
* in the background.
* From now, the events are reported one by one. When it is checked there is still an event pending in the queue,
* a request to the user is made to call again hci_user_evt_proc().
* This gives the opportunity to the application to run other background tasks between each event.
*/
/**
* It is more secure to use LST_remove_head()/LST_insert_head() compare to LST_get_next_node()/LST_remove_node()
* in case the user overwrite the header where the next/prev pointers are located
*/
if((LST_is_empty(&HciAsynchEventQueue) == FALSE) && (UserEventFlow != HCI_TL_UserEventFlow_Disable))
{
LST_remove_head ( &HciAsynchEventQueue, (tListNode **)&phcievtbuffer );
if (hciContext.UserEvtRx != NULL)
{
UserEvtRxParam.pckt = phcievtbuffer;
UserEvtRxParam.status = HCI_TL_UserEventFlow_Enable;
hciContext.UserEvtRx((void *)&UserEvtRxParam);
UserEventFlow = UserEvtRxParam.status;
}
else
{
UserEventFlow = HCI_TL_UserEventFlow_Enable;
}
if(UserEventFlow != HCI_TL_UserEventFlow_Disable)
{
TL_MM_EvtDone( phcievtbuffer );
}
else
{
/**
* put back the event in the queue
*/
LST_insert_head ( &HciAsynchEventQueue, (tListNode *)phcievtbuffer );
}
}
if((LST_is_empty(&HciAsynchEventQueue) == FALSE) && (UserEventFlow != HCI_TL_UserEventFlow_Disable))
{
hci_notify_asynch_evt((void*) &HciAsynchEventQueue);
}
return;
}
void hci_resume_flow( void )
{
UserEventFlow = HCI_TL_UserEventFlow_Enable;
/**
* It is better to go through the background process as it is not sure from which context this API may
* be called
*/
hci_notify_asynch_evt((void*) &HciAsynchEventQueue);
return;
}
int hci_send_req(struct hci_request *p_cmd, uint8_t async)
{
(void)(async);
uint16_t opcode;
TL_CcEvt_t *pcommand_complete_event;
TL_CsEvt_t *pcommand_status_event;
TL_EvtPacket_t *pevtpacket;
uint8_t hci_cmd_complete_return_parameters_length;
HCI_TL_CmdStatus_t local_cmd_status;
NotifyCmdStatus(HCI_TL_CmdBusy);
local_cmd_status = HCI_TL_CmdBusy;
opcode = ((p_cmd->ocf) & 0x03ff) | ((p_cmd->ogf) << 10);
CmdRspStatusFlag = HCI_TL_CMD_RESP_WAIT;
SendCmd(opcode, p_cmd->clen, p_cmd->cparam);
while(local_cmd_status == HCI_TL_CmdBusy)
{
hci_cmd_resp_wait(HCI_TL_DEFAULT_TIMEOUT);
/**
* Process Cmd Event
*/
while(LST_is_empty(&HciCmdEventQueue) == FALSE)
{
LST_remove_head (&HciCmdEventQueue, (tListNode **)&pevtpacket);
if(pevtpacket->evtserial.evt.evtcode == TL_BLEEVT_CS_OPCODE)
{
pcommand_status_event = (TL_CsEvt_t*)pevtpacket->evtserial.evt.payload;
if(pcommand_status_event->cmdcode == opcode)
{
*(uint8_t *)(p_cmd->rparam) = pcommand_status_event->status;
}
if(pcommand_status_event->numcmd != 0)
{
local_cmd_status = HCI_TL_CmdAvailable;
}
}
else
{
pcommand_complete_event = (TL_CcEvt_t*)pevtpacket->evtserial.evt.payload;
if(pcommand_complete_event->cmdcode == opcode)
{
hci_cmd_complete_return_parameters_length = pevtpacket->evtserial.evt.plen - TL_EVT_HDR_SIZE;
p_cmd->rlen = MIN(hci_cmd_complete_return_parameters_length, p_cmd->rlen);
memcpy(p_cmd->rparam, pcommand_complete_event->payload, p_cmd->rlen);
}
if(pcommand_complete_event->numcmd != 0)
{
local_cmd_status = HCI_TL_CmdAvailable;
}
}
}
}
NotifyCmdStatus(HCI_TL_CmdAvailable);
return 0;
}
/* Private functions ---------------------------------------------------------*/
static void TlInit( TL_CmdPacket_t * p_cmdbuffer )
{
TL_BLE_InitConf_t Conf;
/**
* Always initialize the command event queue
*/
LST_init_head (&HciCmdEventQueue);
pCmdBuffer = p_cmdbuffer;
LST_init_head (&HciAsynchEventQueue);
UserEventFlow = HCI_TL_UserEventFlow_Enable;
/* Initialize low level driver */
if (hciContext.io.Init)
{
Conf.p_cmdbuffer = (uint8_t *)p_cmdbuffer;
Conf.IoBusEvtCallBack = TlEvtReceived;
hciContext.io.Init(&Conf);
}
return;
}
static void SendCmd(uint16_t opcode, uint8_t plen, void *param)
{
pCmdBuffer->cmdserial.cmd.cmdcode = opcode;
pCmdBuffer->cmdserial.cmd.plen = plen;
memcpy( pCmdBuffer->cmdserial.cmd.payload, param, plen );
hciContext.io.Send(0,0);
return;
}
static void NotifyCmdStatus(HCI_TL_CmdStatus_t hcicmdstatus)
{
if(hcicmdstatus == HCI_TL_CmdBusy)
{
if(StatusNotCallBackFunction != 0)
{
StatusNotCallBackFunction(HCI_TL_CmdBusy);
}
}
else
{
if(StatusNotCallBackFunction != 0)
{
StatusNotCallBackFunction(HCI_TL_CmdAvailable);
}
}
return;
}
static void TlEvtReceived(TL_EvtPacket_t *hcievt)
{
if ( ((hcievt->evtserial.evt.evtcode) == TL_BLEEVT_CS_OPCODE) || ((hcievt->evtserial.evt.evtcode) == TL_BLEEVT_CC_OPCODE ) )
{
LST_insert_tail(&HciCmdEventQueue, (tListNode *)hcievt);
hci_cmd_resp_release(0); /**< Notify the application a full Cmd Event has been received */
}
else
{
LST_insert_tail(&HciAsynchEventQueue, (tListNode *)hcievt);
hci_notify_asynch_evt((void*) &HciAsynchEventQueue); /**< Notify the application a full HCI event has been received */
}
return;
}
/* Weak implementation ----------------------------------------------------------------*/
__WEAK void hci_cmd_resp_wait(uint32_t timeout)
{
(void)timeout;
while(CmdRspStatusFlag != HCI_TL_CMD_RESP_RELEASE);
return;
}
__WEAK void hci_cmd_resp_release(uint32_t flag)
{
(void)flag;
CmdRspStatusFlag = HCI_TL_CMD_RESP_RELEASE;
return;
}
@@ -0,0 +1,196 @@
/**
******************************************************************************
* @file hci_tl.h
* @author MCD Application Team
* @brief Constants and functions for HCI layer. See Bluetooth Core
* v 4.0, Vol. 2, Part E.
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifndef __HCI_TL_H_
#define __HCI_TL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32_wpan_common.h"
#include "tl.h"
/* Exported defines -----------------------------------------------------------*/
typedef enum
{
HCI_TL_UserEventFlow_Disable,
HCI_TL_UserEventFlow_Enable,
} HCI_TL_UserEventFlowStatus_t;
typedef enum
{
HCI_TL_CmdBusy,
HCI_TL_CmdAvailable
} HCI_TL_CmdStatus_t;
/**
* @brief Structure used to manage the BUS IO operations.
* All the structure fields will point to functions defined at user level.
* @{
*/
typedef struct
{
int32_t (* Init) (void* pConf); /**< Pointer to HCI TL function for the IO Bus initialization */
int32_t (* DeInit) (void); /**< Pointer to HCI TL function for the IO Bus de-initialization */
int32_t (* Reset) (void); /**< Pointer to HCI TL function for the IO Bus reset */
int32_t (* Receive) (uint8_t*, uint16_t); /**< Pointer to HCI TL function for the IO Bus data reception */
int32_t (* Send) (uint8_t*, uint16_t); /**< Pointer to HCI TL function for the IO Bus data transmission */
int32_t (* DataAck) (uint8_t*, uint16_t* len); /**< Pointer to HCI TL function for the IO Bus data ack reception */
int32_t (* GetTick) (void); /**< Pointer to BSP function for getting the HAL time base timestamp */
} tHciIO;
/**
* @}
*/
/**
* @brief Contain the HCI context
* @{
*/
typedef struct
{
tHciIO io; /**< Manage the BUS IO operations */
void (* UserEvtRx) (void * pData); /**< ACI events callback function pointer */
} tHciContext;
typedef struct
{
HCI_TL_UserEventFlowStatus_t status;
TL_EvtPacket_t *pckt;
} tHCI_UserEvtRxParam;
typedef struct
{
uint8_t *p_cmdbuffer;
void (* StatusNotCallBack) (HCI_TL_CmdStatus_t status);
} HCI_TL_HciInitConf_t;
/**
* @brief Register IO bus services.
* @param fops The HCI IO structure managing the IO BUS
* @retval None
*/
void hci_register_io_bus(tHciIO* fops);
/**
* @brief This callback is called from either
* - IPCC RX interrupt context
* - hci_user_evt_proc() context.
* - hci_resume_flow() context
* It requests hci_user_evt_proc() to be executed.
*
* @param pdata Packet or event pointer
* @retval None
*/
void hci_notify_asynch_evt(void* pdata);
/**
* @brief This function resume the User Event Flow which has been stopped on return
* from UserEvtRx() when the User Event has not been processed.
*
* @param None
* @retval None
*/
void hci_resume_flow(void);
/**
* @brief This function is called when an ACI/HCI command is sent to the CPU2 and the response is waited.
* It is called from the same context the HCI command has been sent.
* It shall not return until the command response notified by hci_cmd_resp_release() is received.
* A weak implementation is available in hci_tl.c based on polling mechanism
* The user may re-implement this function in the application to improve performance :
* - It may use UTIL_SEQ_WaitEvt() API when using the Sequencer
* - It may use a semaphore when using cmsis_os interface
*
* @param timeout: Waiting timeout
* @retval None
*/
void hci_cmd_resp_wait(uint32_t timeout);
/**
* @brief This function is called when an ACI/HCI command response is received from the CPU2.
* A weak implementation is available in hci_tl.c based on polling mechanism
* The user may re-implement this function in the application to improve performance :
* - It may use UTIL_SEQ_SetEvt() API when using the Sequencer
* - It may use a semaphore when using cmsis_os interface
*
* @param flag: Release flag
* @retval None
*/
void hci_cmd_resp_release(uint32_t flag);
/**
* END OF SECTION - FUNCTIONS TO BE IMPLEMENTED BY THE APPLICATION
*********************************************************************************************************************
*/
/**
*********************************************************************************************************************
* START OF SECTION - PROCESS TO BE CALLED BY THE SCHEDULER
*/
/**
* @brief This process shall be called by the scheduler each time it is requested with hci_notify_asynch_evt()
* This process may send an ACI/HCI command when the svc_ctl.c module is used
*
* @param None
* @retval None
*/
void hci_user_evt_proc(void);
/**
* END OF SECTION - PROCESS TO BE CALLED BY THE SCHEDULER
*********************************************************************************************************************
*/
/**
*********************************************************************************************************************
* START OF SECTION - INTERFACES USED BY THE BLE DRIVER
*/
/**
* @brief Initialize the Host Controller Interface.
* This function must be called before any data can be received
* from BLE controller.
*
* @param pData: ACI events callback function pointer
* This callback is triggered when an user event is received from
* the BLE core device.
* @param pConf: Configuration structure pointer
* @retval None
*/
void hci_init(void(* UserEvtRx)(void* pData), void* pConf);
/**
* END OF SECTION - INTERFACES USED BY THE BLE DRIVER
*********************************************************************************************************************
*/
#ifdef __cplusplus
}
#endif
#endif /* __TL_BLE_HCI_H_ */
@@ -0,0 +1,30 @@
/**
******************************************************************************
* @file hci_tl_if.c
* @author MCD Application Team
* @brief Transport layer interface to BLE
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include "hci_tl.h"
#include "tl.h"
void hci_register_io_bus(tHciIO* fops)
{
/* Register IO bus services */
fops->Init = TL_BLE_Init;
fops->Send = TL_BLE_SendCmd;
return;
}
@@ -0,0 +1,280 @@
/**
******************************************************************************
* @file mbox_def.h
* @author MCD Application Team
* @brief Mailbox definition
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MBOX_H
#define __MBOX_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32_wpan_common.h"
/**
* This file shall be identical between the CPU1 and the CPU2
*/
/**
*********************************************************************************
* TABLES
*********************************************************************************
*/
/**
* Version
* [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version
* [4:7] = branch - 0: Mass Market - x: ...
* [8:15] = Subversion
* [16:23] = Version minor
* [24:31] = Version major
*
* Memory Size
* [0:7] = Flash ( Number of 4k sector)
* [8:15] = Reserved ( Shall be set to 0 - may be used as flash extension )
* [16:23] = SRAM2b ( Number of 1k sector)
* [24:31] = SRAM2a ( Number of 1k sector)
*/
typedef PACKED_STRUCT
{
uint32_t Version;
} MB_SafeBootInfoTable_t;
typedef PACKED_STRUCT
{
uint32_t Version;
uint32_t MemorySize;
uint32_t FusInfo;
} MB_FusInfoTable_t;
typedef PACKED_STRUCT
{
uint32_t Version;
uint32_t MemorySize;
uint32_t InfoStack;
uint32_t Reserved;
} MB_WirelessFwInfoTable_t;
typedef struct
{
MB_SafeBootInfoTable_t SafeBootInfoTable;
MB_FusInfoTable_t FusInfoTable;
MB_WirelessFwInfoTable_t WirelessFwInfoTable;
} MB_DeviceInfoTable_t;
typedef struct
{
uint8_t *pcmd_buffer;
uint8_t *pcs_buffer;
uint8_t *pevt_queue;
uint8_t *phci_acl_data_buffer;
} MB_BleTable_t;
typedef struct
{
uint8_t *notack_buffer;
uint8_t *clicmdrsp_buffer;
uint8_t *otcmdrsp_buffer;
uint8_t *clinot_buffer;
} MB_ThreadTable_t;
typedef struct
{
uint8_t *clicmdrsp_buffer;
uint8_t *m0cmd_buffer;
} MB_LldTestsTable_t;
typedef struct
{
uint8_t *cmdrsp_buffer;
uint8_t *m0cmd_buffer;
} MB_BleLldTable_t;
typedef struct
{
uint8_t *notifM0toM4_buffer;
uint8_t *appliCmdM4toM0_buffer;
uint8_t *requestM0toM4_buffer;
} MB_ZigbeeTable_t;
/**
* msg
* [0:7] = cmd/evt
* [8:31] = Reserved
*/
typedef struct
{
uint8_t *pcmd_buffer;
uint8_t *sys_queue;
} MB_SysTable_t;
typedef struct
{
uint8_t *spare_ble_buffer;
uint8_t *spare_sys_buffer;
uint8_t *blepool;
uint32_t blepoolsize;
uint8_t *pevt_free_buffer_queue;
uint8_t *traces_evt_pool;
uint32_t tracespoolsize;
} MB_MemManagerTable_t;
typedef struct
{
uint8_t *traces_queue;
} MB_TracesTable_t;
typedef struct
{
uint8_t *p_cmdrsp_buffer;
uint8_t *p_notack_buffer;
uint8_t *evt_queue;
} MB_Mac_802_15_4_t;
typedef struct
{
MB_DeviceInfoTable_t *p_device_info_table;
MB_BleTable_t *p_ble_table;
MB_ThreadTable_t *p_thread_table;
MB_SysTable_t *p_sys_table;
MB_MemManagerTable_t *p_mem_manager_table;
MB_TracesTable_t *p_traces_table;
MB_Mac_802_15_4_t *p_mac_802_15_4_table;
MB_ZigbeeTable_t *p_zigbee_table;
MB_LldTestsTable_t *p_lld_tests_table;
MB_BleLldTable_t *p_ble_lld_table;
} MB_RefTable_t;
/**
* This table shall be used only in the case the CPU2 runs the FUS.
* It is used by the command SHCI_GetWirelessFwInfo()
*/
typedef struct
{
uint32_t DeviceInfoTableState;
uint8_t Reserved1;
uint8_t LastFusActiveState;
uint8_t LastWirelessStackState;
uint8_t CurrentWirelessStackType;
uint32_t SafeBootVersion;
uint32_t FusVersion;
uint32_t FusMemorySize;
uint32_t WirelessStackVersion;
uint32_t WirelessStackMemorySize;
uint32_t WirelessFirmwareBleInfo;
uint32_t WirelessFirmwareThreadInfo;
uint32_t Reserved2;
uint64_t UID64;
uint16_t DeviceId;
} MB_FUS_DeviceInfoTable_t ;
#ifdef __cplusplus
}
#endif
/**
*********************************************************************************
* IPCC CHANNELS
*********************************************************************************
*/
/* CPU1 CPU2
* | (SYSTEM) |
* |----HW_IPCC_SYSTEM_CMD_RSP_CHANNEL-------------->|
* | |
* |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------|
* | |
* | (ZIGBEE) |
* |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>|
* | |
* |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->|
* | |
* |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------|
* | |
* |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------|
* | |
* | (THREAD) |
* |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->|
* | |
* |----HW_IPCC_THREAD_CLI_CMD_CHANNEL-------------->|
* | |
* |<---HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL------|
* | |
* |<---HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL--|
* | |
* | (BLE) |
* |----HW_IPCC_BLE_CMD_CHANNEL--------------------->|
* | |
* |----HW_IPCC_HCI_ACL_DATA_CHANNEL---------------->|
* | |
* |<---HW_IPCC_BLE_EVENT_CHANNEL--------------------|
* | |
* | (BLE LLD) |
* |----HW_IPCC_BLE_LLD_CMD_CHANNEL----------------->|
* | |
* |<---HW_IPCC_BLE_LLD_RSP_CHANNEL------------------|
* | |
* |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------|
* | |
* | (MAC) |
* |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->|
* | |
* |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL|
* | |
* | (BUFFER) |
* |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>|
* | |
* | (TRACE) |
* |<----HW_IPCC_TRACES_CHANNEL----------------------|
* | |
*
*
*
*/
/** CPU1 */
#define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1
#define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2
#define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3
#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3
#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3
#define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4
#define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5
#define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5
#define HW_IPCC_BLE_LLD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5
#define HW_IPCC_BLE_LLD_CMD_CHANNEL LL_IPCC_CHANNEL_5
#define HW_IPCC_HCI_ACL_DATA_CHANNEL LL_IPCC_CHANNEL_6
/** CPU2 */
#define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1
#define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2
#define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3
#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3
#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3
#define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3
#define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3
#define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4
#define HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_5
#define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5
#define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5
#define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5
#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5
#endif /*__MBOX_H */
@@ -0,0 +1,254 @@
/**
******************************************************************************
* @file shci.c
* @author MCD Application Team
* @brief System HCI command implementation
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32_wpan_common.h"
#include "stm_list.h"
#include "shci_tl.h"
/* Private typedef -----------------------------------------------------------*/
typedef enum
{
SHCI_TL_CMD_RESP_RELEASE,
SHCI_TL_CMD_RESP_WAIT,
} SHCI_TL_CmdRespStatus_t;
/* Private defines -----------------------------------------------------------*/
/**
* The default System HCI layer timeout is set to 33s
*/
#define SHCI_TL_DEFAULT_TIMEOUT (33000)
/* Private macros ------------------------------------------------------------*/
/* Public variables ---------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/**
* START of Section SYSTEM_DRIVER_CONTEXT
*/
PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static tListNode SHciAsynchEventQueue;
PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static volatile SHCI_TL_CmdStatus_t SHCICmdStatus;
PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static TL_CmdPacket_t *pCmdBuffer;
PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") SHCI_TL_UserEventFlowStatus_t SHCI_TL_UserEventFlow;
/**
* END of Section SYSTEM_DRIVER_CONTEXT
*/
static tSHciContext shciContext;
static void (* StatusNotCallBackFunction) (SHCI_TL_CmdStatus_t status);
static volatile SHCI_TL_CmdRespStatus_t CmdRspStatusFlag;
/* Private function prototypes -----------------------------------------------*/
static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus);
static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt);
static void TlUserEvtReceived(TL_EvtPacket_t *shcievt);
static void TlInit( TL_CmdPacket_t * p_cmdbuffer );
/* Interface ------- ---------------------------------------------------------*/
void shci_init(void(* UserEvtRx)(void* pData), void* pConf)
{
StatusNotCallBackFunction = ((SHCI_TL_HciInitConf_t *)pConf)->StatusNotCallBack;
shciContext.UserEvtRx = UserEvtRx;
shci_register_io_bus (&shciContext.io);
TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer));
return;
}
void shci_user_evt_proc(void)
{
TL_EvtPacket_t *phcievtbuffer;
tSHCI_UserEvtRxParam UserEvtRxParam;
/**
* Up to release version v1.2.0, a while loop was implemented to read out events from the queue as long as
* it is not empty. However, in a bare metal implementation, this leads to calling in a "blocking" mode
* shci_user_evt_proc() as long as events are received without giving the opportunity to run other tasks
* in the background.
* From now, the events are reported one by one. When it is checked there is still an event pending in the queue,
* a request to the user is made to call again shci_user_evt_proc().
* This gives the opportunity to the application to run other background tasks between each event.
*/
/**
* It is more secure to use LST_remove_head()/LST_insert_head() compare to LST_get_next_node()/LST_remove_node()
* in case the user overwrite the header where the next/prev pointers are located
*/
if((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable))
{
LST_remove_head ( &SHciAsynchEventQueue, (tListNode **)&phcievtbuffer );
if (shciContext.UserEvtRx != NULL)
{
UserEvtRxParam.pckt = phcievtbuffer;
UserEvtRxParam.status = SHCI_TL_UserEventFlow_Enable;
shciContext.UserEvtRx((void *)&UserEvtRxParam);
SHCI_TL_UserEventFlow = UserEvtRxParam.status;
}
else
{
SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable;
}
if(SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)
{
TL_MM_EvtDone( phcievtbuffer );
}
else
{
/**
* put back the event in the queue
*/
LST_insert_head ( &SHciAsynchEventQueue, (tListNode *)phcievtbuffer );
}
}
if((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable))
{
shci_notify_asynch_evt((void*) &SHciAsynchEventQueue);
}
return;
}
void shci_resume_flow( void )
{
SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable;
/**
* It is better to go through the background process as it is not sure from which context this API may
* be called
*/
shci_notify_asynch_evt((void*) &SHciAsynchEventQueue);
return;
}
void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp )
{
Cmd_SetStatus(SHCI_TL_CmdBusy);
pCmdBuffer->cmdserial.cmd.cmdcode = cmd_code;
pCmdBuffer->cmdserial.cmd.plen = len_cmd_payload;
memcpy(pCmdBuffer->cmdserial.cmd.payload, p_cmd_payload, len_cmd_payload );
CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT;
shciContext.io.Send(0,0);
shci_cmd_resp_wait(SHCI_TL_DEFAULT_TIMEOUT);
/**
* The command complete of a system command does not have the header
* It starts immediately with the evtserial field
*/
memcpy( &(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t*)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE );
Cmd_SetStatus(SHCI_TL_CmdAvailable);
return;
}
/* Private functions ---------------------------------------------------------*/
static void TlInit( TL_CmdPacket_t * p_cmdbuffer )
{
TL_SYS_InitConf_t Conf;
pCmdBuffer = p_cmdbuffer;
LST_init_head (&SHciAsynchEventQueue);
Cmd_SetStatus(SHCI_TL_CmdAvailable);
SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable;
/* Initialize low level driver */
if (shciContext.io.Init)
{
Conf.p_cmdbuffer = (uint8_t *)p_cmdbuffer;
Conf.IoBusCallBackCmdEvt = TlCmdEvtReceived;
Conf.IoBusCallBackUserEvt = TlUserEvtReceived;
shciContext.io.Init(&Conf);
}
return;
}
static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus)
{
if(shcicmdstatus == SHCI_TL_CmdBusy)
{
if(StatusNotCallBackFunction != 0)
{
StatusNotCallBackFunction( SHCI_TL_CmdBusy );
}
SHCICmdStatus = SHCI_TL_CmdBusy;
}
else
{
SHCICmdStatus = SHCI_TL_CmdAvailable;
if(StatusNotCallBackFunction != 0)
{
StatusNotCallBackFunction( SHCI_TL_CmdAvailable );
}
}
return;
}
static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt)
{
(void)(shcievt);
shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */
return;
}
static void TlUserEvtReceived(TL_EvtPacket_t *shcievt)
{
LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt);
shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */
return;
}
/* Weak implementation ----------------------------------------------------------------*/
__WEAK void shci_cmd_resp_wait(uint32_t timeout)
{
(void)timeout;
while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE);
return;
}
__WEAK void shci_cmd_resp_release(uint32_t flag)
{
(void)flag;
CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE;
return;
}
@@ -0,0 +1,173 @@
/**
******************************************************************************
* @file shci_tl.h
* @author MCD Application Team
* @brief System HCI command header for the system channel
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifndef __SHCI_TL_H_
#define __SHCI_TL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "tl.h"
/* Exported defines -----------------------------------------------------------*/
typedef enum
{
SHCI_TL_UserEventFlow_Disable,
SHCI_TL_UserEventFlow_Enable,
} SHCI_TL_UserEventFlowStatus_t;
typedef enum
{
SHCI_TL_CmdBusy,
SHCI_TL_CmdAvailable
} SHCI_TL_CmdStatus_t;
/**
* @brief Structure used to manage the BUS IO operations.
* All the structure fields will point to functions defined at user level.
* @{
*/
typedef struct
{
int32_t (* Init) (void* pConf); /**< Pointer to SHCI TL function for the IO Bus initialization */
int32_t (* DeInit) (void); /**< Pointer to SHCI TL function for the IO Bus de-initialization */
int32_t (* Reset) (void); /**< Pointer to SHCI TL function for the IO Bus reset */
int32_t (* Receive) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data reception */
int32_t (* Send) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data transmission */
int32_t (* DataAck) (uint8_t*, uint16_t* len); /**< Pointer to SHCI TL function for the IO Bus data ack reception */
int32_t (* GetTick) (void); /**< Pointer to BSP function for getting the HAL time base timestamp */
} tSHciIO;
/**
* @}
*/
/**
* @brief Contain the SHCI context
* @{
*/
typedef struct
{
tSHciIO io; /**< Manage the BUS IO operations */
void (* UserEvtRx) (void * pData); /**< User System events callback function pointer */
} tSHciContext;
typedef struct
{
SHCI_TL_UserEventFlowStatus_t status;
TL_EvtPacket_t *pckt;
} tSHCI_UserEvtRxParam;
typedef struct
{
uint8_t *p_cmdbuffer;
void (* StatusNotCallBack) (SHCI_TL_CmdStatus_t status);
} SHCI_TL_HciInitConf_t;
/**
* shci_send
* @brief Send an System HCI Command
*
* @param : cmd_code = Opcode of the command
* @param : len_cmd_payload = Length of the command payload
* @param : p_cmd_payload = Address of the command payload
* @param : p_rsp_status = Address of the full buffer holding the command complete event
* @retval : None
*/
void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp_status );
/**
* @brief Register IO bus services.
* @param fops The SHCI IO structure managing the IO BUS
* @retval None
*/
void shci_register_io_bus(tSHciIO* fops);
/**
* @brief Interrupt service routine that must be called when the system channel
* reports a packet has been received
*
* @param pdata Packet or event pointer
* @retval None
*/
void shci_notify_asynch_evt(void* pdata);
/**
* @brief This function resume the User Event Flow which has been stopped on return
* from UserEvtRx() when the User Event has not been processed.
*
* @param None
* @retval None
*/
void shci_resume_flow(void);
/**
* @brief This function is called when an System HCI Command is sent to the CPU2 and the response is waited.
* It is called from the same context the System HCI command has been sent.
* It shall not return until the command response notified by shci_cmd_resp_release() is received.
* A weak implementation is available in shci_tl.c based on polling mechanism
* The user may re-implement this function in the application to improve performance :
* - It may use UTIL_SEQ_WaitEvt() API when using the Sequencer
* - It may use a semaphore when using cmsis_os interface
*
* @param timeout: Waiting timeout
* @retval None
*/
void shci_cmd_resp_wait(uint32_t timeout);
/**
* @brief This function is called when an System HCI command is received from the CPU2.
* A weak implementation is available in shci_tl.c based on polling mechanism
* The user may re-implement this function in the application to improve performance :
* - It may use UTIL_SEQ_SetEvt() API when using the Sequencer
* - It may use a semaphore when using cmsis_os interface
*
*
* @param flag: Release flag
* @retval None
*/
void shci_cmd_resp_release(uint32_t flag);
/**
* @brief This process shall be called each time the shci_notify_asynch_evt notification is received
*
* @param None
* @retval None
*/
void shci_user_evt_proc(void);
/**
* @brief Initialize the System Host Controller Interface.
* This function must be called before any communication on the System Channel
*
* @param UserEvtRx: System events callback function pointer
* This callback is triggered when an user event is received on
* the System Channel from CPU2.
* @param pConf: Configuration structure pointer
* @retval None
*/
void shci_init(void(* UserEvtRx)(void* pData), void* pConf);
#ifdef __cplusplus
}
#endif
#endif /* __SHCI_TL_H_ */
@@ -0,0 +1,30 @@
/**
******************************************************************************
* @file shci_tl_if.c
* @author MCD Application Team
* @brief Transport layer interface to the system channel
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include "shci_tl.h"
#include "tl.h"
void shci_register_io_bus(tSHciIO* fops)
{
/* Register IO bus services */
fops->Init = TL_SYS_Init;
fops->Send = TL_SYS_SendCmd;
return;
}
@@ -0,0 +1,372 @@
/**
******************************************************************************
* @file tl.h
* @author MCD Application Team
* @brief Header for tl module
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TL_H
#define __TL_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32_wpan_common.h"
/* Exported defines -----------------------------------------------------------*/
#define TL_BLECMD_PKT_TYPE ( 0x01 )
#define TL_ACL_DATA_PKT_TYPE ( 0x02 )
#define TL_BLEEVT_PKT_TYPE ( 0x04 )
#define TL_OTCMD_PKT_TYPE ( 0x08 )
#define TL_OTRSP_PKT_TYPE ( 0x09 )
#define TL_CLICMD_PKT_TYPE ( 0x0A )
#define TL_OTNOT_PKT_TYPE ( 0x0C )
#define TL_OTACK_PKT_TYPE ( 0x0D )
#define TL_CLINOT_PKT_TYPE ( 0x0E )
#define TL_CLIACK_PKT_TYPE ( 0x0F )
#define TL_SYSCMD_PKT_TYPE ( 0x10 )
#define TL_SYSRSP_PKT_TYPE ( 0x11 )
#define TL_SYSEVT_PKT_TYPE ( 0x12 )
#define TL_CLIRESP_PKT_TYPE ( 0x15 )
#define TL_M0CMD_PKT_TYPE ( 0x16 )
#define TL_LOCCMD_PKT_TYPE ( 0x20 )
#define TL_LOCRSP_PKT_TYPE ( 0x21 )
#define TL_TRACES_APP_PKT_TYPE ( 0x40 )
#define TL_TRACES_WL_PKT_TYPE ( 0x41 )
#define TL_CMD_HDR_SIZE (4)
#define TL_EVT_HDR_SIZE (3)
#define TL_EVT_CS_PAYLOAD_SIZE (4)
#define TL_BLEEVT_CC_OPCODE (0x0E)
#define TL_BLEEVT_CS_OPCODE (0x0F)
#define TL_BLEEVT_VS_OPCODE (0xFF)
#define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t))
#define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE)
/* Exported types ------------------------------------------------------------*/
/**< Packet header */
typedef PACKED_STRUCT
{
uint32_t *next;
uint32_t *prev;
} TL_PacketHeader_t;
/*******************************************************************************
* Event type
*/
/**
* This the payload of TL_Evt_t for a command status event
*/
typedef PACKED_STRUCT
{
uint8_t status;
uint8_t numcmd;
uint16_t cmdcode;
} TL_CsEvt_t;
/**
* This the payload of TL_Evt_t for a command complete event, only used a pointer
*/
typedef PACKED_STRUCT
{
uint8_t numcmd;
uint16_t cmdcode;
uint8_t payload[2];
} TL_CcEvt_t;
/**
* This the payload of TL_Evt_t for an asynchronous event, only used a pointer
*/
typedef PACKED_STRUCT
{
uint16_t subevtcode;
uint8_t payload[2];
} TL_AsynchEvt_t;
/**
* This the payload of TL_Evt_t, only used a pointer
*/
typedef PACKED_STRUCT
{
uint8_t evtcode;
uint8_t plen;
uint8_t payload[2];
} TL_Evt_t;
typedef PACKED_STRUCT
{
uint8_t type;
TL_Evt_t evt;
} TL_EvtSerial_t;
/**
* This format shall be used for all events (asynchronous and command response) reported
* by the CPU2 except for the command response of a system command where the header is not there
* and the format to be used shall be TL_EvtSerial_t.
* Note: Be careful that the asynchronous events reported by the CPU2 on the system channel do
* include the header and shall use TL_EvtPacket_t format. Only the command response format on the
* system channel is different.
*/
typedef PACKED_STRUCT
{
TL_PacketHeader_t header;
TL_EvtSerial_t evtserial;
} TL_EvtPacket_t;
/*****************************************************************************************
* Command type
*/
typedef PACKED_STRUCT
{
uint16_t cmdcode;
uint8_t plen;
uint8_t payload[255];
} TL_Cmd_t;
typedef PACKED_STRUCT
{
uint8_t type;
TL_Cmd_t cmd;
} TL_CmdSerial_t;
typedef PACKED_STRUCT
{
TL_PacketHeader_t header;
TL_CmdSerial_t cmdserial;
} TL_CmdPacket_t;
/*****************************************************************************************
* HCI ACL DATA type
*/
typedef PACKED_STRUCT
{
uint8_t type;
uint16_t handle;
uint16_t length;
uint8_t acl_data[1];
} TL_AclDataSerial_t;
typedef PACKED_STRUCT
{
TL_PacketHeader_t header;
TL_AclDataSerial_t AclDataSerial;
} TL_AclDataPacket_t;
typedef struct
{
uint8_t *p_BleSpareEvtBuffer;
uint8_t *p_SystemSpareEvtBuffer;
uint8_t *p_AsynchEvtPool;
uint32_t AsynchEvtPoolSize;
uint8_t *p_TracesEvtPool;
uint32_t TracesEvtPoolSize;
} TL_MM_Config_t;
typedef struct
{
uint8_t *p_ThreadOtCmdRspBuffer;
uint8_t *p_ThreadCliRspBuffer;
uint8_t *p_ThreadNotAckBuffer;
uint8_t *p_ThreadCliNotBuffer;
} TL_TH_Config_t;
typedef struct
{
uint8_t *p_LldTestsCliCmdRspBuffer;
uint8_t *p_LldTestsM0CmdBuffer;
} TL_LLD_tests_Config_t;
typedef struct
{
uint8_t *p_BleLldCmdRspBuffer;
uint8_t *p_BleLldM0CmdBuffer;
} TL_BLE_LLD_Config_t;
typedef struct
{
uint8_t *p_Mac_802_15_4_CmdRspBuffer;
uint8_t *p_Mac_802_15_4_NotAckBuffer;
} TL_MAC_802_15_4_Config_t;
typedef struct
{
uint8_t *p_ZigbeeOtCmdRspBuffer;
uint8_t *p_ZigbeeNotAckBuffer;
uint8_t *p_ZigbeeNotifRequestBuffer;
} TL_ZIGBEE_Config_t;
/**
* @brief Contain the BLE HCI Init Configuration
* @{
*/
typedef struct
{
void (* IoBusEvtCallBack) ( TL_EvtPacket_t *phcievt );
void (* IoBusAclDataTxAck) ( void );
uint8_t *p_cmdbuffer;
uint8_t *p_AclDataBuffer;
} TL_BLE_InitConf_t;
/**
* @brief Contain the SYSTEM HCI Init Configuration
* @{
*/
typedef struct
{
void (* IoBusCallBackCmdEvt) (TL_EvtPacket_t *phcievt);
void (* IoBusCallBackUserEvt) (TL_EvtPacket_t *phcievt);
uint8_t *p_cmdbuffer;
} TL_SYS_InitConf_t;
/*****************************************************************************************
* Event type copied from ble_legacy.h
*/
typedef PACKED_STRUCT
{
uint8_t type;
uint8_t data[1];
} hci_uart_pckt;
typedef PACKED_STRUCT
{
uint8_t evt;
uint8_t plen;
uint8_t data[1];
} hci_event_pckt;
typedef PACKED_STRUCT
{
uint8_t subevent;
uint8_t data[1];
} evt_le_meta_event;
/**
* Vendor specific event for BLE core.
*/
typedef PACKED_STRUCT
{
uint16_t ecode; /**< One of the BLE core event codes. */
uint8_t data[1];
} evt_blecore_aci;
/* Bluetooth 48 bit address (in little-endian order).
*/
typedef uint8_t tBDAddr[6];
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/******************************************************************************
* GENERAL
******************************************************************************/
void TL_Enable( void );
void TL_Init( void );
/******************************************************************************
* BLE
******************************************************************************/
int32_t TL_BLE_Init( void* pConf );
int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size );
int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size );
/******************************************************************************
* SYSTEM
******************************************************************************/
int32_t TL_SYS_Init( void* pConf );
int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size );
/******************************************************************************
* THREAD
******************************************************************************/
void TL_THREAD_Init( TL_TH_Config_t *p_Config );
void TL_OT_SendCmd( void );
void TL_CLI_SendCmd( void );
void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer );
void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer );
void TL_THREAD_SendAck ( void );
void TL_THREAD_CliSendAck ( void );
void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer );
/******************************************************************************
* LLD TESTS
******************************************************************************/
void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config );
void TL_LLDTESTS_SendCliCmd( void );
void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer );
void TL_LLDTESTS_SendCliRspAck( void );
void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer );
void TL_LLDTESTS_SendM0CmdAck( void );
/******************************************************************************
* BLE LLD
******************************************************************************/
void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config );
void TL_BLE_LLD_SendCliCmd( void );
void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer );
void TL_BLE_LLD_SendCliRspAck( void );
void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer );
void TL_BLE_LLD_SendM0CmdAck( void );
void TL_BLE_LLD_SendCmd( void );
void TL_BLE_LLD_ReceiveRsp( TL_CmdPacket_t * Notbuffer );
void TL_BLE_LLD_SendRspAck( void );
/******************************************************************************
* MEMORY MANAGER
******************************************************************************/
void TL_MM_Init( TL_MM_Config_t *p_Config );
void TL_MM_EvtDone( TL_EvtPacket_t * hcievt );
/******************************************************************************
* TRACES
******************************************************************************/
void TL_TRACES_Init( void );
void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt );
/******************************************************************************
* MAC 802.15.4
******************************************************************************/
void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config );
void TL_MAC_802_15_4_SendCmd( void );
void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer );
void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer );
void TL_MAC_802_15_4_SendAck ( void );
/******************************************************************************
* ZIGBEE
******************************************************************************/
void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config );
void TL_ZIGBEE_SendM4RequestToM0( void );
void TL_ZIGBEE_SendM4AckToM0Notify ( void );
void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer );
void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer );
void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer );
void TL_ZIGBEE_SendM4AckToM0Request(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*__TL_H */
@@ -0,0 +1,877 @@
/**
******************************************************************************
* @file tl_mbox.c
* @author MCD Application Team
* @brief Transport layer for the mailbox interface
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32_wpan_common.h"
#include "hw.h"
#include "stm_list.h"
#include "tl.h"
#include "mbox_def.h"
#include "tl_dbg_conf.h"
/* Private typedef -----------------------------------------------------------*/
typedef enum
{
TL_MB_MM_RELEASE_BUFFER,
TL_MB_BLE_CMD,
TL_MB_BLE_CMD_RSP,
TL_MB_ACL_DATA,
TL_MB_ACL_DATA_RSP,
TL_MB_BLE_ASYNCH_EVT,
TL_MB_SYS_CMD,
TL_MB_SYS_CMD_RSP,
TL_MB_SYS_ASYNCH_EVT,
} TL_MB_PacketType_t;
/* Private defines -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/**< reference table */
PLACE_IN_SECTION("MAPPING_TABLE") static volatile MB_RefTable_t TL_RefTable;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_DeviceInfoTable_t TL_DeviceInfoTable;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleTable_t TL_BleTable;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ThreadTable_t TL_ThreadTable;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldTestsTable_t TL_LldTestsTable;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table;
/**< tables */
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue;
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)];
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue;
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue;
static tListNode LocalFreeBufQueue;
static void (* BLE_IoBusEvtCallBackFunction) (TL_EvtPacket_t *phcievt);
static void (* BLE_IoBusAclDataTxAck) ( void );
static void (* SYS_CMD_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt);
static void (* SYS_EVT_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt);
/* Global variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static void SendFreeBuf( void );
static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer);
/* Public Functions Definition ------------------------------------------------------*/
/******************************************************************************
* GENERAL - refer to AN5289 for functions description.
******************************************************************************/
void TL_Enable( void )
{
HW_IPCC_Enable();
return;
}
void TL_Init( void )
{
TL_RefTable.p_device_info_table = &TL_DeviceInfoTable;
TL_RefTable.p_ble_table = &TL_BleTable;
TL_RefTable.p_thread_table = &TL_ThreadTable;
TL_RefTable.p_lld_tests_table = &TL_LldTestsTable;
TL_RefTable.p_ble_lld_table = &TL_BleLldTable;
TL_RefTable.p_sys_table = &TL_SysTable;
TL_RefTable.p_mem_manager_table = &TL_MemManagerTable;
TL_RefTable.p_traces_table = &TL_TracesTable;
TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table;
TL_RefTable.p_zigbee_table = &TL_Zigbee_Table;
HW_IPCC_Init();
return;
}
/******************************************************************************
* BLE
******************************************************************************/
int32_t TL_BLE_Init( void* pConf )
{
MB_BleTable_t * p_bletable;
TL_BLE_InitConf_t *pInitHciConf = (TL_BLE_InitConf_t *) pConf;
LST_init_head (&EvtQueue);
p_bletable = TL_RefTable.p_ble_table;
p_bletable->pcmd_buffer = pInitHciConf->p_cmdbuffer;
p_bletable->phci_acl_data_buffer = pInitHciConf->p_AclDataBuffer;
p_bletable->pcs_buffer = (uint8_t*)CsBuffer;
p_bletable->pevt_queue = (uint8_t*)&EvtQueue;
HW_IPCC_BLE_Init();
BLE_IoBusEvtCallBackFunction = pInitHciConf->IoBusEvtCallBack;
BLE_IoBusAclDataTxAck = pInitHciConf->IoBusAclDataTxAck;
return 0;
}
int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size )
{
(void)(buffer);
(void)(size);
((TL_CmdPacket_t*)(TL_RefTable.p_ble_table->pcmd_buffer))->cmdserial.type = TL_BLECMD_PKT_TYPE;
OutputDbgTrace(TL_MB_BLE_CMD, TL_RefTable.p_ble_table->pcmd_buffer);
HW_IPCC_BLE_SendCmd();
return 0;
}
void HW_IPCC_BLE_RxEvtNot(void)
{
TL_EvtPacket_t *phcievt;
while(LST_is_empty(&EvtQueue) == FALSE)
{
LST_remove_head (&EvtQueue, (tListNode **)&phcievt);
if ( ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CS_OPCODE) || ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CC_OPCODE ) )
{
OutputDbgTrace(TL_MB_BLE_CMD_RSP, (uint8_t*)phcievt);
}
else
{
OutputDbgTrace(TL_MB_BLE_ASYNCH_EVT, (uint8_t*)phcievt);
}
BLE_IoBusEvtCallBackFunction(phcievt);
}
return;
}
int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size )
{
(void)(buffer);
(void)(size);
((TL_AclDataPacket_t *)(TL_RefTable.p_ble_table->phci_acl_data_buffer))->AclDataSerial.type = TL_ACL_DATA_PKT_TYPE;
OutputDbgTrace(TL_MB_ACL_DATA, TL_RefTable.p_ble_table->phci_acl_data_buffer);
HW_IPCC_BLE_SendAclData();
return 0;
}
void HW_IPCC_BLE_AclDataAckNot(void)
{
OutputDbgTrace(TL_MB_ACL_DATA_RSP, (uint8_t*)NULL);
BLE_IoBusAclDataTxAck( );
return;
}
/******************************************************************************
* SYSTEM
******************************************************************************/
int32_t TL_SYS_Init( void* pConf )
{
MB_SysTable_t * p_systable;
TL_SYS_InitConf_t *pInitHciConf = (TL_SYS_InitConf_t *) pConf;
LST_init_head (&SystemEvtQueue);
p_systable = TL_RefTable.p_sys_table;
p_systable->pcmd_buffer = pInitHciConf->p_cmdbuffer;
p_systable->sys_queue = (uint8_t*)&SystemEvtQueue;
HW_IPCC_SYS_Init();
SYS_CMD_IoBusCallBackFunction = pInitHciConf->IoBusCallBackCmdEvt;
SYS_EVT_IoBusCallBackFunction = pInitHciConf->IoBusCallBackUserEvt;
return 0;
}
int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size )
{
(void)(buffer);
(void)(size);
((TL_CmdPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer))->cmdserial.type = TL_SYSCMD_PKT_TYPE;
OutputDbgTrace(TL_MB_SYS_CMD, TL_RefTable.p_sys_table->pcmd_buffer);
HW_IPCC_SYS_SendCmd();
return 0;
}
void HW_IPCC_SYS_CmdEvtNot(void)
{
OutputDbgTrace(TL_MB_SYS_CMD_RSP, (uint8_t*)(TL_RefTable.p_sys_table->pcmd_buffer) );
SYS_CMD_IoBusCallBackFunction( (TL_EvtPacket_t*)(TL_RefTable.p_sys_table->pcmd_buffer) );
return;
}
void HW_IPCC_SYS_EvtNot( void )
{
TL_EvtPacket_t *p_evt;
while(LST_is_empty(&SystemEvtQueue) == FALSE)
{
LST_remove_head (&SystemEvtQueue, (tListNode **)&p_evt);
OutputDbgTrace(TL_MB_SYS_ASYNCH_EVT, (uint8_t*)p_evt );
SYS_EVT_IoBusCallBackFunction( p_evt );
}
return;
}
/******************************************************************************
* THREAD
******************************************************************************/
#ifdef THREAD_WB
void TL_THREAD_Init( TL_TH_Config_t *p_Config )
{
MB_ThreadTable_t * p_thread_table;
p_thread_table = TL_RefTable.p_thread_table;
p_thread_table->clicmdrsp_buffer = p_Config->p_ThreadCliRspBuffer;
p_thread_table->otcmdrsp_buffer = p_Config->p_ThreadOtCmdRspBuffer;
p_thread_table->notack_buffer = p_Config->p_ThreadNotAckBuffer;
p_thread_table->clinot_buffer = p_Config->p_ThreadCliNotBuffer;
HW_IPCC_THREAD_Init();
return;
}
void TL_OT_SendCmd( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->otcmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE;
HW_IPCC_OT_SendCmd();
return;
}
void TL_CLI_SendCmd( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE;
HW_IPCC_CLI_SendCmd();
return;
}
void TL_THREAD_SendAck ( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
HW_IPCC_THREAD_SendAck();
return;
}
void TL_THREAD_CliSendAck ( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
HW_IPCC_THREAD_CliSendAck();
return;
}
void HW_IPCC_OT_CmdEvtNot(void)
{
TL_OT_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->otcmdrsp_buffer) );
return;
}
void HW_IPCC_THREAD_EvtNot( void )
{
TL_THREAD_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->notack_buffer) );
return;
}
void HW_IPCC_THREAD_CliEvtNot( void )
{
TL_THREAD_CliNotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->clinot_buffer) );
return;
}
__WEAK void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){};
__WEAK void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer ){};
__WEAK void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer ){};
#endif /* THREAD_WB */
/******************************************************************************
* LLD TESTS
******************************************************************************/
#ifdef LLD_TESTS_WB
void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config )
{
MB_LldTestsTable_t * p_lld_tests_table;
p_lld_tests_table = TL_RefTable.p_lld_tests_table;
p_lld_tests_table->clicmdrsp_buffer = p_Config->p_LldTestsCliCmdRspBuffer;
p_lld_tests_table->m0cmd_buffer = p_Config->p_LldTestsM0CmdBuffer;
HW_IPCC_LLDTESTS_Init();
return;
}
void TL_LLDTESTS_SendCliCmd( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE;
HW_IPCC_LLDTESTS_SendCliCmd();
return;
}
void HW_IPCC_LLDTESTS_ReceiveCliRsp( void )
{
TL_LLDTESTS_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer) );
return;
}
void TL_LLDTESTS_SendCliRspAck( void )
{
HW_IPCC_LLDTESTS_SendCliRspAck();
return;
}
void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void )
{
TL_LLDTESTS_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->m0cmd_buffer) );
return;
}
void TL_LLDTESTS_SendM0CmdAck( void )
{
HW_IPCC_LLDTESTS_SendM0CmdAck();
return;
}
__WEAK void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){};
__WEAK void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){};
#endif /* LLD_TESTS_WB */
/******************************************************************************
* BLE LLD
******************************************************************************/
#ifdef BLE_LLD_WB
void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config )
{
MB_BleLldTable_t * p_ble_lld_table;
p_ble_lld_table = TL_RefTable.p_ble_lld_table;
p_ble_lld_table->cmdrsp_buffer = p_Config->p_BleLldCmdRspBuffer;
p_ble_lld_table->m0cmd_buffer = p_Config->p_BleLldM0CmdBuffer;
HW_IPCC_BLE_LLD_Init();
return;
}
void TL_BLE_LLD_SendCliCmd( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE;
HW_IPCC_BLE_LLD_SendCliCmd();
return;
}
void HW_IPCC_BLE_LLD_ReceiveCliRsp( void )
{
TL_BLE_LLD_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) );
return;
}
void TL_BLE_LLD_SendCliRspAck( void )
{
HW_IPCC_BLE_LLD_SendCliRspAck();
return;
}
void HW_IPCC_BLE_LLD_ReceiveM0Cmd( void )
{
TL_BLE_LLD_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->m0cmd_buffer) );
return;
}
void TL_BLE_LLD_SendM0CmdAck( void )
{
HW_IPCC_BLE_LLD_SendM0CmdAck();
return;
}
__WEAK void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){};
__WEAK void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){};
/* Transparent Mode */
void TL_BLE_LLD_SendCmd( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE;
HW_IPCC_BLE_LLD_SendCmd();
return;
}
void HW_IPCC_BLE_LLD_ReceiveRsp( void )
{
TL_BLE_LLD_ReceiveRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) );
return;
}
void TL_BLE_LLD_SendRspAck( void )
{
HW_IPCC_BLE_LLD_SendRspAck();
return;
}
#endif /* BLE_LLD_WB */
#ifdef MAC_802_15_4_WB
/******************************************************************************
* MAC 802.15.4
******************************************************************************/
void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config )
{
MB_Mac_802_15_4_t * p_mac_802_15_4_table;
p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table;
p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer;
p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer;
HW_IPCC_MAC_802_15_4_Init();
return;
}
void TL_MAC_802_15_4_SendCmd( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE;
HW_IPCC_MAC_802_15_4_SendCmd();
return;
}
void TL_MAC_802_15_4_SendAck ( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
HW_IPCC_MAC_802_15_4_SendAck();
return;
}
void HW_IPCC_MAC_802_15_4_CmdEvtNot(void)
{
TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) );
return;
}
void HW_IPCC_MAC_802_15_4_EvtNot( void )
{
TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) );
return;
}
__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){};
__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){};
#endif
#ifdef ZIGBEE_WB
/******************************************************************************
* ZIGBEE
******************************************************************************/
void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config )
{
MB_ZigbeeTable_t * p_zigbee_table;
p_zigbee_table = TL_RefTable.p_zigbee_table;
p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer;
p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer;
p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer;
HW_IPCC_ZIGBEE_Init();
return;
}
/* Zigbee M4 to M0 Request */
void TL_ZIGBEE_SendM4RequestToM0( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE;
HW_IPCC_ZIGBEE_SendM4RequestToM0();
return;
}
/* Used to receive an ACK from the M0 */
void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void)
{
TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) );
return;
}
/* Zigbee notification from M0 to M4 */
void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void )
{
TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) );
return;
}
/* Send an ACK to the M0 for a Notification */
void TL_ZIGBEE_SendM4AckToM0Notify ( void )
{
((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
HW_IPCC_ZIGBEE_SendM4AckToM0Notify();
return;
}
/* Zigbee M0 to M4 Request */
void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void )
{
TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) );
return;
}
/* Send an ACK to the M0 for a Request */
void TL_ZIGBEE_SendM4AckToM0Request(void)
{
((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE;
HW_IPCC_ZIGBEE_SendM4AckToM0Request();
return;
}
__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){};
__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){};
#endif
/******************************************************************************
* MEMORY MANAGER
******************************************************************************/
void TL_MM_Init( TL_MM_Config_t *p_Config )
{
static MB_MemManagerTable_t * p_mem_manager_table;
LST_init_head (&FreeBufQueue);
LST_init_head (&LocalFreeBufQueue);
p_mem_manager_table = TL_RefTable.p_mem_manager_table;
p_mem_manager_table->blepool = p_Config->p_AsynchEvtPool;
p_mem_manager_table->blepoolsize = p_Config->AsynchEvtPoolSize;
p_mem_manager_table->pevt_free_buffer_queue = (uint8_t*)&FreeBufQueue;
p_mem_manager_table->spare_ble_buffer = p_Config->p_BleSpareEvtBuffer;
p_mem_manager_table->spare_sys_buffer = p_Config->p_SystemSpareEvtBuffer;
p_mem_manager_table->traces_evt_pool = p_Config->p_TracesEvtPool;
p_mem_manager_table->tracespoolsize = p_Config->TracesEvtPoolSize;
return;
}
void TL_MM_EvtDone(TL_EvtPacket_t * phcievt)
{
LST_insert_tail(&LocalFreeBufQueue, (tListNode *)phcievt);
OutputDbgTrace(TL_MB_MM_RELEASE_BUFFER, (uint8_t*)phcievt);
HW_IPCC_MM_SendFreeBuf( SendFreeBuf );
return;
}
static void SendFreeBuf( void )
{
tListNode *p_node;
while ( FALSE == LST_is_empty (&LocalFreeBufQueue) )
{
LST_remove_head( &LocalFreeBufQueue, (tListNode **)&p_node );
LST_insert_tail( (tListNode*)(TL_RefTable.p_mem_manager_table->pevt_free_buffer_queue), p_node );
}
return;
}
/******************************************************************************
* TRACES
******************************************************************************/
void TL_TRACES_Init( void )
{
LST_init_head (&TracesEvtQueue);
TL_RefTable.p_traces_table->traces_queue = (uint8_t*)&TracesEvtQueue;
HW_IPCC_TRACES_Init();
return;
}
void HW_IPCC_TRACES_EvtNot(void)
{
TL_EvtPacket_t *phcievt;
while(LST_is_empty(&TracesEvtQueue) == FALSE)
{
LST_remove_head (&TracesEvtQueue, (tListNode **)&phcievt);
TL_TRACES_EvtReceived( phcievt );
}
return;
}
__WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt )
{
(void)(hcievt);
}
/******************************************************************************
* DEBUG INFORMATION
******************************************************************************/
static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer)
{
TL_EvtPacket_t *p_evt_packet;
TL_CmdPacket_t *p_cmd_packet;
TL_AclDataPacket_t *p_acldata_packet;
TL_EvtSerial_t *p_cmd_rsp_packet;
switch(packet_type)
{
case TL_MB_MM_RELEASE_BUFFER:
p_evt_packet = (TL_EvtPacket_t*)buffer;
switch(p_evt_packet->evtserial.evt.evtcode)
{
case TL_BLEEVT_CS_OPCODE:
TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode);
TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet);
break;
case TL_BLEEVT_CC_OPCODE:
TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode);
TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet);
break;
case TL_BLEEVT_VS_OPCODE:
TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode);
TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet);
break;
default:
TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet);
break;
}
TL_MM_DBG_MSG("\r\n");
break;
case TL_MB_BLE_CMD:
p_cmd_packet = (TL_CmdPacket_t*)buffer;
TL_HCI_CMD_DBG_MSG("ble cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode);
if(p_cmd_packet->cmdserial.cmd.plen != 0)
{
TL_HCI_CMD_DBG_MSG(" payload:");
TL_HCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, "");
}
TL_HCI_CMD_DBG_MSG("\r\n");
TL_HCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE);
break;
case TL_MB_ACL_DATA:
(void)p_acldata_packet;
p_acldata_packet = (TL_AclDataPacket_t*)buffer;
TL_HCI_CMD_DBG_MSG("acl_data: 0x%02X", p_acldata_packet->AclDataSerial.type);
TL_HCI_CMD_DBG_MSG("acl_data: 0x%04X", p_acldata_packet->AclDataSerial.handle);
TL_HCI_CMD_DBG_MSG("acl_data: 0x%04X", p_acldata_packet->AclDataSerial.length);
/*if(p_acldata_packet->AclDataSerial.length != 0)
{
TL_HCI_CMD_DBG_MSG(" payload:");
TL_HCI_CMD_DBG_BUF(p_acldata_packet->AclDataSerial.acl_data, p_acldata_packet->AclDataSerial.length, "");
}*/
TL_HCI_CMD_DBG_MSG("\r\n");
/*TL_HCI_CMD_DBG_RAW(&p_acldata_packet->AclDataSerial, p_acldata_packet->AclDataSerial.length+TL_CMD_HDR_SIZE);*/
break;
case TL_MB_ACL_DATA_RSP:
TL_HCI_CMD_DBG_MSG(" ACL Data Tx Ack received");
TL_HCI_CMD_DBG_MSG("\r\n");
break;
case TL_MB_BLE_CMD_RSP:
p_evt_packet = (TL_EvtPacket_t*)buffer;
switch(p_evt_packet->evtserial.evt.evtcode)
{
case TL_BLEEVT_CS_OPCODE:
TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode);
TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd);
TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->status);
break;
case TL_BLEEVT_CC_OPCODE:
TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode);
TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd);
TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]);
if((p_evt_packet->evtserial.evt.plen-4) != 0)
{
TL_HCI_CMD_DBG_MSG(" payload:");
TL_HCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, "");
}
break;
default:
TL_HCI_CMD_DBG_MSG("unknown ble rsp received: %02X", p_evt_packet->evtserial.evt.evtcode);
break;
}
TL_HCI_CMD_DBG_MSG("\r\n");
TL_HCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE);
break;
case TL_MB_BLE_ASYNCH_EVT:
p_evt_packet = (TL_EvtPacket_t*)buffer;
if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE)
{
TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
if((p_evt_packet->evtserial.evt.plen) != 0)
{
TL_HCI_EVT_DBG_MSG(" payload:");
TL_HCI_EVT_DBG_BUF(p_evt_packet->evtserial.evt.payload, p_evt_packet->evtserial.evt.plen, "");
}
}
else
{
TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
TL_HCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode);
if((p_evt_packet->evtserial.evt.plen-2) != 0)
{
TL_HCI_EVT_DBG_MSG(" payload:");
TL_HCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, "");
}
}
TL_HCI_EVT_DBG_MSG("\r\n");
TL_HCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE);
break;
case TL_MB_SYS_CMD:
p_cmd_packet = (TL_CmdPacket_t*)buffer;
TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode);
if(p_cmd_packet->cmdserial.cmd.plen != 0)
{
TL_SHCI_CMD_DBG_MSG(" payload:");
TL_SHCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, "");
}
TL_SHCI_CMD_DBG_MSG("\r\n");
TL_SHCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE);
break;
case TL_MB_SYS_CMD_RSP:
p_cmd_rsp_packet = (TL_EvtSerial_t*)buffer;
switch(p_cmd_rsp_packet->evt.evtcode)
{
case TL_BLEEVT_CC_OPCODE:
TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_cmd_rsp_packet->evt.evtcode);
TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->cmdcode);
TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->payload[0]);
if((p_cmd_rsp_packet->evt.plen-4) != 0)
{
TL_SHCI_CMD_DBG_MSG(" payload:");
TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->payload[1], p_cmd_rsp_packet->evt.plen-4, "");
}
break;
default:
TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_cmd_rsp_packet->evt.evtcode);
break;
}
TL_SHCI_CMD_DBG_MSG("\r\n");
TL_SHCI_CMD_DBG_RAW(&p_cmd_rsp_packet->evt, p_cmd_rsp_packet->evt.plen+TL_EVT_HDR_SIZE);
break;
case TL_MB_SYS_ASYNCH_EVT:
p_evt_packet = (TL_EvtPacket_t*)buffer;
if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE)
{
TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", p_evt_packet->evtserial.evt.evtcode);
}
else
{
TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode);
TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode);
if((p_evt_packet->evtserial.evt.plen-2) != 0)
{
TL_SHCI_EVT_DBG_MSG(" payload:");
TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, "");
}
}
TL_SHCI_EVT_DBG_MSG("\r\n");
TL_SHCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE);
break;
default:
break;
}
return;
}
@@ -0,0 +1,171 @@
/**
******************************************************************************
* @file stm32_wpan_common.h
* @author MCD Application Team
* @brief Common file to utilities
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32_WPAN_COMMON_H
#define __STM32_WPAN_COMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined ( __CC_ARM )||defined (__ARMCC_VERSION)
#define __ASM __asm /*!< asm keyword for ARM Compiler */
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
#define __STATIC_INLINE static __inline
#elif defined ( __ICCARM__ )
#define __ASM __asm /*!< asm keyword for IAR Compiler */
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
#define __STATIC_INLINE static inline
#elif defined ( __GNUC__ )
#define __ASM __asm /*!< asm keyword for GNU Compiler */
#define __INLINE inline /*!< inline keyword for GNU Compiler */
#define __STATIC_INLINE static inline
#endif
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "cmsis_compiler.h"
/* -------------------------------- *
* Basic definitions *
* -------------------------------- */
#undef NULL
#define NULL 0U
#undef FALSE
#define FALSE 0U
#undef TRUE
#define TRUE (!0U)
/* -------------------------------- *
* Critical Section definition *
* -------------------------------- */
#undef BACKUP_PRIMASK
#define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK()
#undef DISABLE_IRQ
#define DISABLE_IRQ() __disable_irq()
#undef RESTORE_PRIMASK
#define RESTORE_PRIMASK() __set_PRIMASK(primask_bit)
/* -------------------------------- *
* Macro delimiters *
* -------------------------------- */
#undef M_BEGIN
#define M_BEGIN do {
#undef M_END
#define M_END } while(0)
/* -------------------------------- *
* Some useful macro definitions *
* -------------------------------- */
#undef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#undef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#undef MODINC
#define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END
#undef MODDEC
#define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END
#undef MODADD
#define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END
#undef MODSUB
#define MODSUB( a, b, m ) MODADD( a, (m)-(b), m )
#undef ALIGN
#ifdef WIN32
#define ALIGN(n)
#else
#define ALIGN(n) __attribute__((aligned(n)))
#endif
#undef PAUSE
#define PAUSE( t ) M_BEGIN \
volatile int _i; \
for ( _i = t; _i > 0; _i -- ); \
M_END
#undef DIVF
#define DIVF( x, y ) ((x)/(y))
#undef DIVC
#define DIVC( x, y ) (((x)+(y)-1)/(y))
#undef DIVR
#define DIVR( x, y ) (((x)+((y)/2))/(y))
#undef SHRR
#define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1)
#undef BITN
#define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1)
#undef BITNSET
#define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END
/* -------------------------------- *
* Section attribute *
* -------------------------------- */
#undef PLACE_IN_SECTION
#define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__)))
/* ----------------------------------- *
* Packed usage (compiler dependent) *
* ----------------------------------- */
#undef PACKED__
#undef PACKED_STRUCT
#if defined ( __CC_ARM )
#if defined ( __GNUC__ )
/* GNU extension */
#define PACKED__ __attribute__((packed))
#define PACKED_STRUCT struct PACKED__
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U)
#define PACKED__ __attribute__((packed))
#define PACKED_STRUCT struct PACKED__
#else
#define PACKED__(TYPE) __packed TYPE
#define PACKED_STRUCT PACKED__(struct)
#endif
#elif defined ( __GNUC__ )
#define PACKED__ __attribute__((packed))
#define PACKED_STRUCT struct PACKED__
#elif defined (__ICCARM__)
#define PACKED_STRUCT __packed struct
#else
#define PACKED_STRUCT __packed struct
#endif
#ifdef __cplusplus
}
#endif
#endif /*__STM32_WPAN_COMMON_H */
@@ -0,0 +1,360 @@
/**
******************************************************************************
* @file dbg_trace.c
* @author MCD Application Team
* @brief This file contains the Interface with BLE Drivers functions.
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "utilities_common.h"
#include "stm_queue.h"
#include "dbg_trace.h"
/* Definition of the function */
#if !defined(__GNUC__) /* SW4STM32 */
size_t __write(int handle, const unsigned char * buf, size_t bufSize);
#endif
/** @addtogroup TRACE
* @{
*/
/** @defgroup TRACE_LOG
* @brief TRACE Logging functions
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/** @defgroup TRACE Log private typedef
* @{
*/
/**
* @}
*/
/* Private defines -----------------------------------------------------------*/
/** @defgroup TRACE Log private defines
* @{
*/
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/** @defgroup TRACE Log private macros
* @{
*/
/**
* @}
*/
/* Private variables ---------------------------------------------------------*/
/** @defgroup TRACE Log private variables
* @{
*/
#if (( CFG_DEBUG_TRACE_FULL != 0 ) || ( CFG_DEBUG_TRACE_LIGHT != 0 ))
#if (DBG_TRACE_USE_CIRCULAR_QUEUE != 0)
static queue_t MsgDbgTraceQueue;
static uint8_t MsgDbgTraceQueueBuff[DBG_TRACE_MSG_QUEUE_SIZE];
#endif
__IO ITStatus DbgTracePeripheralReady = SET;
#endif
/**
* @}
*/
/* Global variables ----------------------------------------------------------*/
/** @defgroup TRACE Log Global variable
* @{
*/
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/** @defgroup TRACE Log private function prototypes
* @{
*/
#if (( CFG_DEBUG_TRACE_FULL != 0 ) || ( CFG_DEBUG_TRACE_LIGHT != 0 ))
static void DbgTrace_TxCpltCallback(void);
#endif
/**
* @}
*/
/* Private Functions Definition ------------------------------------------------------*/
/** @defgroup TRACE Log Private function
* @{
*/
/* Functions Definition ------------------------------------------------------*/
/** @defgroup TRACE Log APIs
* @{
*/
/**
* @brief DbgTraceGetFileName: Return filename string extracted from full path information
* @param *fullPath Fullpath string (path + filename)
* @retval char* Pointer on filename string
*/
const char *DbgTraceGetFileName(const char *fullpath)
{
const char *ret = fullpath;
if (strrchr(fullpath, '\\') != NULL)
{
ret = strrchr(fullpath, '\\') + 1;
}
else if (strrchr(fullpath, '/') != NULL)
{
ret = strrchr(fullpath, '/') + 1;
}
return ret;
}
/**
* @brief DbgTraceBuffer: Output buffer content information to output Stream
* @param *pBuffer Pointer on buffer to be output
* @param u32Length buffer Size
* @paramt strFormat string as expected by "printf" function. Used to desrcibe buffer content information.
* @param ... Parameters to be "formatted" in strFormat string (if any)
* @retval None
*/
void DbgTraceBuffer(const void *pBuffer, uint32_t u32Length, const char *strFormat, ...)
{
va_list vaArgs;
uint32_t u32Index;
va_start(vaArgs, strFormat);
vprintf(strFormat, vaArgs);
va_end(vaArgs);
for (u32Index = 0; u32Index < u32Length; u32Index ++)
{
printf(" %02X", ((const uint8_t *) pBuffer)[u32Index]);
}
}
#if (( CFG_DEBUG_TRACE_FULL != 0 ) || ( CFG_DEBUG_TRACE_LIGHT != 0 ))
/**
* @brief DBG_TRACE USART Tx Transfer completed callback
* @param UartHandle: UART handle.
* @note Indicate the end of the transmission of a DBG_TRACE trace buffer to DBG_TRACE USART. If queue
* contains new trace data to transmit, start a new transmission.
* @retval None
*/
static void DbgTrace_TxCpltCallback(void)
{
#if (DBG_TRACE_USE_CIRCULAR_QUEUE != 0)
uint8_t* buf;
uint16_t bufSize;
BACKUP_PRIMASK();
DISABLE_IRQ(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
/* Remove element just sent to UART */
CircularQueue_Remove(&MsgDbgTraceQueue,&bufSize);
/* Sense if new data to be sent */
buf=CircularQueue_Sense(&MsgDbgTraceQueue,&bufSize);
if ( buf != NULL)
{
RESTORE_PRIMASK();
DbgOutputTraces((uint8_t*)buf, bufSize, DbgTrace_TxCpltCallback);
}
else
{
DbgTracePeripheralReady = SET;
RESTORE_PRIMASK();
}
#else
BACKUP_PRIMASK();
DISABLE_IRQ(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
DbgTracePeripheralReady = SET;
RESTORE_PRIMASK();
#endif
}
#endif
void DbgTraceInit( void )
{
#if (( CFG_DEBUG_TRACE_FULL != 0 ) || ( CFG_DEBUG_TRACE_LIGHT != 0 ))
DbgOutputInit();
#if (DBG_TRACE_USE_CIRCULAR_QUEUE != 0)
CircularQueue_Init(&MsgDbgTraceQueue, MsgDbgTraceQueueBuff, DBG_TRACE_MSG_QUEUE_SIZE, 0, CIRCULAR_QUEUE_SPLIT_IF_WRAPPING_FLAG);
#endif
#endif
return;
}
#if (( CFG_DEBUG_TRACE_FULL != 0 ) || ( CFG_DEBUG_TRACE_LIGHT != 0 ))
#if defined(__GNUC__) /* SW4STM32 (GCC) */
/**
* @brief _write: override the __write standard lib function to redirect printf to USART.
* @param handle output handle (STDIO, STDERR...)
* @param buf buffer to write
* @param bufsize buffer size
* @param ...: arguments to be formatted in format string
* @retval none
*/
size_t _write(int handle, const unsigned char * buf, size_t bufSize)
{
return ( DbgTraceWrite(handle, buf, bufSize) );
}
#else
/**
* @brief __write: override the _write standard lib function to redirect printf to USART.
* @param handle output handle (STDIO, STDERR...)
* @param buf buffer to write
* @param bufsize buffer size
* @param ...: arguments to be formatted in format string
* @retval none
*/
size_t __write(int handle, const unsigned char * buf, size_t bufSize)
{
return ( DbgTraceWrite(handle, buf, bufSize) );
}
#endif /* #if defined(__GNUC__) */
/**
* @brief Override the standard lib function to redirect printf to USART.
* @param handle output handle (STDIO, STDERR...)
* @param buf buffer to write
* @param bufsize buffer size
* @retval Number of elements written
*/
size_t DbgTraceWrite(int handle, const unsigned char * buf, size_t bufSize)
{
size_t chars_written = 0;
uint8_t* buffer;
BACKUP_PRIMASK();
/* Ignore flushes */
if ( handle == -1 )
{
chars_written = ( size_t ) 0;
}
/* Only allow stdout/stderr output */
else if ( ( handle != 1 ) && ( handle != 2 ) )
{
chars_written = ( size_t ) - 1;
}
/* Parameters OK, call the low-level character output routine */
else if (bufSize != 0)
{
chars_written = bufSize;
/* If queue emepty and TX free, send directly */
/* CS Start */
#if (DBG_TRACE_USE_CIRCULAR_QUEUE != 0)
DISABLE_IRQ(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
buffer=CircularQueue_Add(&MsgDbgTraceQueue,(uint8_t*)buf, bufSize,1);
if (buffer && DbgTracePeripheralReady)
{
DbgTracePeripheralReady = RESET;
RESTORE_PRIMASK();
DbgOutputTraces((uint8_t*)buffer, bufSize, DbgTrace_TxCpltCallback);
}
else
{
RESTORE_PRIMASK();
}
#else
DISABLE_IRQ(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
DbgTracePeripheralReady = RESET;
RESTORE_PRIMASK();
DbgOutputTraces((uint8_t*)buf, bufSize, DbgTrace_TxCpltCallback);
while (!DbgTracePeripheralReady);
#endif
/* CS END */
}
return ( chars_written );
}
#if defined ( __CC_ARM ) || defined (__ARMCC_VERSION) /* Keil */
/**
Called from assert() and prints a message on stderr and calls abort().
\param[in] expr assert expression that was not TRUE
\param[in] file source file of the assertion
\param[in] line source line of the assertion
*/
__attribute__((weak,noreturn))
void __aeabi_assert (const char *expr, const char *file, int line) {
char str[12], *p;
fputs("*** assertion failed: ", stderr);
fputs(expr, stderr);
fputs(", file ", stderr);
fputs(file, stderr);
fputs(", line ", stderr);
p = str + sizeof(str);
*--p = '\0';
*--p = '\n';
while (line > 0) {
*--p = '0' + (line % 10);
line /= 10;
}
fputs(p, stderr);
abort();
}
/* For KEIL re-implement our own version of fputc */
int fputc(int ch, FILE *f)
{
/* temp char avoids endianness issue */
char tempch = ch;
/* Write one character to Debug Circular Queue */
DbgTraceWrite(1U, (const unsigned char *) &tempch, 1);
return ch;
}
#endif /* #if defined ( __CC_ARM ) */
#endif /* #if (( CFG_DEBUG_TRACE_FULL != 0 ) || ( CFG_DEBUG_TRACE_LIGHT != 0 )) */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,103 @@
/**
******************************************************************************
* @file dbg_trace.h
* @author MCD Application Team
* @brief Header for dbg_trace.c
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DBG_TRACE_H
#define __DBG_TRACE_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Exported types ------------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
#if ( ( CFG_DEBUG_TRACE_FULL != 0 ) || ( CFG_DEBUG_TRACE_LIGHT != 0 ) )
#define PRINT_LOG_BUFF_DBG(...) DbgTraceBuffer(__VA_ARGS__)
#if ( CFG_DEBUG_TRACE_FULL != 0 )
#define PRINT_MESG_DBG(...) do{printf("\r\n [%s][%s][%d] ", DbgTraceGetFileName(__FILE__),__FUNCTION__,__LINE__);printf(__VA_ARGS__);}while(0);
#else
#define PRINT_MESG_DBG printf
#endif
#else
#define PRINT_LOG_BUFF_DBG(...)
#define PRINT_MESG_DBG(...)
#endif
#define PRINT_NO_MESG(...)
/* Exported functions ------------------------------------------------------- */
/**
* @brief Request the user to initialize the peripheral to output traces
*
* @param None
* @retval None
*/
extern void DbgOutputInit( void );
/**
* @brief Request the user to sent the traces on the output peripheral
*
* @param p_data: Address of the buffer to be sent
* @param size: Size of the data to be sent
* @param cb: Function to be called when the data has been sent
* @retval None
*/
extern void DbgOutputTraces( uint8_t *p_data, uint16_t size, void (*cb)(void) );
/**
* @brief DbgTraceInit Initialize Logging feature.
*
* @param: None
* @retval: None
*/
void DbgTraceInit( void );
/**********************************************************************************************************************/
/** This function outputs into the log the buffer (in hex) and the provided format string and arguments.
***********************************************************************************************************************
*
* @param pBuffer Buffer to be output into the logs.
* @param u32Length Length of the buffer, in bytes.
* @param strFormat The format string in printf() style.
* @param ... Arguments of the format string.
*
**********************************************************************************************************************/
void DbgTraceBuffer( const void *pBuffer , uint32_t u32Length , const char *strFormat , ... );
const char *DbgTraceGetFileName( const char *fullpath );
/**
* @brief Override the standard lib function to redirect printf to USART.
* @param handle output handle (STDIO, STDERR...)
* @param buf buffer to write
* @param bufsize buffer size
* @retval Number of elements written
*/
size_t DbgTraceWrite(int handle, const unsigned char * buf, size_t bufSize);
#ifdef __cplusplus
}
#endif
#endif /*__DBG_TRACE_H */
@@ -0,0 +1,52 @@
/**
******************************************************************************
* @file otp.c
* @author MCD Application Team
* @brief OTP manager
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "utilities_common.h"
#include "otp.h"
/* Private typedef -----------------------------------------------------------*/
/* Private defines -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Global variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Functions Definition ------------------------------------------------------*/
uint8_t * OTP_Read( uint8_t id )
{
uint8_t *p_id;
p_id = (uint8_t*)(CFG_OTP_END_ADRESS - 7) ;
while( ((*( p_id + 7 )) != id) && ( p_id != (uint8_t*)CFG_OTP_BASE_ADDRESS) )
{
p_id -= 8 ;
}
if((*( p_id + 7 )) != id)
{
p_id = 0 ;
}
return p_id ;
}
@@ -0,0 +1,65 @@
/**
******************************************************************************
* @file otp.h
* @author MCD Application Team
* @brief OTP manager interface
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __OTP_H
#define __OTP_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "utilities_common.h"
/* Exported types ------------------------------------------------------------*/
typedef PACKED_STRUCT
{
uint8_t bd_address[6];
uint8_t hse_tuning;
uint8_t id;
} OTP_ID0_t;
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/**
* @brief This API return the address (64 bits aligned) of the ID parameter in the OTP
* It returns the first ID declaration found from the higher address down to the base address
* The user shall fill the OTP from the base address to the top of the OTP so that the more recent
* declaration is returned by the API
* The OTP manager handles only 64bits parameter
* | Id | Parameter |
* | 8bits | 58bits |
* | MSB | LSB |
*
* @param id: ID of the parameter to read from OTP
* @retval Address of the ID in the OTP - returns 0 when no ID found
*/
uint8_t * OTP_Read( uint8_t id );
#ifdef __cplusplus
}
#endif
#endif /*__OTP_H */
@@ -0,0 +1,207 @@
/**
******************************************************************************
* @file stm_list.c
* @author MCD Application Team
* @brief TCircular Linked List Implementation.
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/******************************************************************************
* Include Files
******************************************************************************/
#include "utilities_common.h"
#include "stm_list.h"
/******************************************************************************
* Function Definitions
******************************************************************************/
void LST_init_head (tListNode * listHead)
{
listHead->next = listHead;
listHead->prev = listHead;
}
uint8_t LST_is_empty (tListNode * listHead)
{
uint32_t primask_bit;
uint8_t return_value;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
if(listHead->next == listHead)
{
return_value = TRUE;
}
else
{
return_value = FALSE;
}
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
return return_value;
}
void LST_insert_head (tListNode * listHead, tListNode * node)
{
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
node->next = listHead->next;
node->prev = listHead;
listHead->next = node;
(node->next)->prev = node;
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
}
void LST_insert_tail (tListNode * listHead, tListNode * node)
{
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
node->next = listHead;
node->prev = listHead->prev;
listHead->prev = node;
(node->prev)->next = node;
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
}
void LST_remove_node (tListNode * node)
{
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
(node->prev)->next = node->next;
(node->next)->prev = node->prev;
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
}
void LST_remove_head (tListNode * listHead, tListNode ** node )
{
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
*node = listHead->next;
LST_remove_node (listHead->next);
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
}
void LST_remove_tail (tListNode * listHead, tListNode ** node )
{
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
*node = listHead->prev;
LST_remove_node (listHead->prev);
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
}
void LST_insert_node_after (tListNode * node, tListNode * ref_node)
{
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
node->next = ref_node->next;
node->prev = ref_node;
ref_node->next = node;
(node->next)->prev = node;
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
}
void LST_insert_node_before (tListNode * node, tListNode * ref_node)
{
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
node->next = ref_node;
node->prev = ref_node->prev;
ref_node->prev = node;
(node->prev)->next = node;
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
}
int LST_get_size (tListNode * listHead)
{
int size = 0;
tListNode * temp;
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
temp = listHead->next;
while (temp != listHead)
{
size++;
temp = temp->next;
}
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
return (size);
}
void LST_get_next_node (tListNode * ref_node, tListNode ** node)
{
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
*node = ref_node->next;
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
}
void LST_get_prev_node (tListNode * ref_node, tListNode ** node)
{
uint32_t primask_bit;
primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
__disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
*node = ref_node->prev;
__set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
}
@@ -0,0 +1,63 @@
/**
******************************************************************************
* @file stm_list.h
* @author MCD Application Team
* @brief Header file for linked list library.
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifndef _STM_LIST_H_
#define _STM_LIST_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32_wpan_common.h"
typedef PACKED_STRUCT _tListNode {
struct _tListNode * next;
struct _tListNode * prev;
} tListNode;
void LST_init_head (tListNode * listHead);
uint8_t LST_is_empty (tListNode * listHead);
void LST_insert_head (tListNode * listHead, tListNode * node);
void LST_insert_tail (tListNode * listHead, tListNode * node);
void LST_remove_node (tListNode * node);
void LST_remove_head (tListNode * listHead, tListNode ** node );
void LST_remove_tail (tListNode * listHead, tListNode ** node );
void LST_insert_node_after (tListNode * node, tListNode * ref_node);
void LST_insert_node_before (tListNode * node, tListNode * ref_node);
int LST_get_size (tListNode * listHead);
void LST_get_next_node (tListNode * ref_node, tListNode ** node);
void LST_get_prev_node (tListNode * ref_node, tListNode ** node);
#ifdef __cplusplus
}
#endif
#endif /* _STM_LIST_H_ */
@@ -0,0 +1,383 @@
/**
******************************************************************************
* @file stm_queue.c
* @author MCD Application Team
* @brief Queue management
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "utilities_common.h"
#include "stm_queue.h"
/* Private define ------------------------------------------------------------*/
/* Private typedef -------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
#define MOD(X,Y) (((X) >= (Y)) ? ((X)-(Y)) : (X))
/* Private variables ---------------------------------------------------------*/
/* Global variables ----------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Public functions ----------------------------------------------------------*/
/**
* @brief Initilaiilze queue structure .
* @note This function is used to initialize the global queue structure.
* @param q: pointer on queue structure to be initialised
* @param queueBuffer: pointer on Queue Buffer
* @param queueSize: Size of Queue Buffer
* @param elementSize: Size of an element in the queue. if =0, the queue will manage variable sizze elements
* @retval always 0
*/
int CircularQueue_Init(queue_t *q, uint8_t* queueBuffer, uint32_t queueSize, uint16_t elementSize, uint8_t optionFlags)
{
q->qBuff = queueBuffer;
q->first = 0;
q->last = 0; /* queueSize-1; */
q->byteCount = 0;
q->elementCount = 0;
q->queueMaxSize = queueSize;
q->elementSize = elementSize;
q->optionFlags = optionFlags;
if ((optionFlags & CIRCULAR_QUEUE_SPLIT_IF_WRAPPING_FLAG) && q-> elementSize)
{
/* can not deal with splitting at the end of buffer with fixed size element */
return -1;
}
return 0;
}
/**
* @brief Add element to the queue .
* @note This function is used to add one or more element(s) to the Circular Queue .
* @param q: pointer on queue structure to be handled
* @param X; pointer on element(s) to be added
* @param elementSize: Size of element to be added to the queue. Only used if the queue manage variable size elements
* @param nbElements: number of elements in the in buffer pointed by x
* @retval pointer on last element just added to the queue, NULL if the element to be added do not fit in the queue (too big)
*/
uint8_t* CircularQueue_Add(queue_t *q, uint8_t* x, uint16_t elementSize, uint32_t nbElements)
{
uint8_t* ptr = NULL; /* fct return ptr to the element freshly added, if no room fct return NULL */
uint16_t curElementSize = 0; /* the size of the element currently stored at q->last position */
uint8_t elemSizeStorageRoom = 0 ; /* Indicate the header (which contain only size) of element in case of varaibale size element (q->elementsize == 0) */
uint32_t curBuffPosition; /* the current position in the queue buffer */
uint32_t i; /* loop counter */
uint32_t NbBytesToCopy = 0, NbCopiedBytes = 0 ; /* Indicators for copying bytes in queue */
uint32_t eob_free_size; /* Eof End of Quque Buffer Free Size */
uint8_t wrap_will_occur = 0; /* indicate if a wrap around will occurs */
uint8_t wrapped_element_eob_size; /* In case of Wrap around, indicate size of parta of element that fit at thened of the queuue buffer */
uint16_t overhead = 0; /* In case of CIRCULAR_QUEUE_SPLIT_IF_WRAPPING_FLAG or CIRCULAR_QUEUE_NO_WRAP_FLAG options,
indcate the size overhead that will be generated by adding the element with wrap management (split or no wrap ) */
elemSizeStorageRoom = (q->elementSize == 0) ? 2 : 0;
/* retrieve the size of last element sored: the value stored at the beginning of the queue element if element size is variable otherwise take it from fixed element Size member */
if (q->byteCount)
{
curElementSize = (q->elementSize == 0) ? q->qBuff[q->last] + ((q->qBuff[MOD((q->last+1), q->queueMaxSize)])<<8) + 2 : q->elementSize;
}
/* if queue element have fixed size , reset the elementSize arg with fixed element size value */
if (q->elementSize > 0)
{
elementSize = q->elementSize;
}
eob_free_size = (q->last >= q->first) ? q->queueMaxSize - (q->last + curElementSize) : 0;
/* check how many bytes of wrapped element (if anay) are at end of buffer */
wrapped_element_eob_size = (((elementSize + elemSizeStorageRoom )*nbElements) < eob_free_size) ? 0 : (eob_free_size % (elementSize + elemSizeStorageRoom));
wrap_will_occur = wrapped_element_eob_size > elemSizeStorageRoom;
overhead = (wrap_will_occur && (q->optionFlags & CIRCULAR_QUEUE_NO_WRAP_FLAG)) ? wrapped_element_eob_size : overhead;
overhead = (wrap_will_occur && (q->optionFlags & CIRCULAR_QUEUE_SPLIT_IF_WRAPPING_FLAG)) ? elemSizeStorageRoom : overhead;
/* Store now the elements if ennough room for all elements */
if (elementSize && ((q->byteCount + ((elementSize + elemSizeStorageRoom )*nbElements) + overhead) <= q->queueMaxSize))
{
/* loop to add all elements */
for (i=0; i < nbElements; i++)
{
q->last = MOD ((q->last + curElementSize),q->queueMaxSize);
curBuffPosition = q->last;
/* store the element */
/* store first the element size if element size is variable */
if (q->elementSize == 0)
{
q->qBuff[curBuffPosition++]= elementSize & 0xFF;
curBuffPosition = MOD(curBuffPosition, q->queueMaxSize);
q->qBuff[curBuffPosition++]= (elementSize & 0xFF00) >> 8 ;
curBuffPosition = MOD(curBuffPosition, q->queueMaxSize);
q->byteCount += 2;
}
/* Identify number of bytes of copy takeing account possible wrap, in this case NbBytesToCopy will contains size that fit at end of the queue buffer */
NbBytesToCopy = MIN((q->queueMaxSize-curBuffPosition),elementSize);
/* check if no wrap (NbBytesToCopy == elementSize) or if Wrap and no spsicf option;
In this case part of data will copied at the end of the buffer and the rest a the beginning */
if ((NbBytesToCopy == elementSize) || ((NbBytesToCopy < elementSize) && (q->optionFlags == CIRCULAR_QUEUE_NO_FLAG)))
{
/* Copy First part (or emtire buffer ) from current position up to the end of the buffer queue (or before if enough room) */
memcpy(&q->qBuff[curBuffPosition],&x[i*elementSize],NbBytesToCopy);
/* Adjust bytes count */
q->byteCount += NbBytesToCopy;
/* Wrap */
curBuffPosition = 0;
/* set NbCopiedBytes bytes with ampount copied */
NbCopiedBytes = NbBytesToCopy;
/* set the rest to copy if wrao , if no wrap will be 0 */
NbBytesToCopy = elementSize - NbBytesToCopy;
/* set the current element Size, will be used to calaculate next last position at beginning of loop */
curElementSize = (elementSize) + elemSizeStorageRoom ;
}
else if (NbBytesToCopy) /* We have a wrap to manage */
{
/* case of CIRCULAR_QUEUE_NO_WRAP_FLAG option */
if (q->optionFlags & CIRCULAR_QUEUE_NO_WRAP_FLAG)
{
/* if element size are variable and NO_WRAP option, Invalidate end of buffer setting 0xFFFF size*/
if (q->elementSize == 0)
{
q->qBuff[curBuffPosition-2] = 0xFF;
q->qBuff[curBuffPosition-1] = 0xFF;
}
q->byteCount += NbBytesToCopy; /* invalid data at the end of buffer are take into account in byteCount */
/* No bytes coped a the end of buffer */
NbCopiedBytes = 0;
/* all element to be copied at the begnning of buffer */
NbBytesToCopy = elementSize;
/* Wrap */
curBuffPosition = 0;
/* if variable size element, invalidate end of buffer setting OxFFFF in element header (size) */
if (q->elementSize == 0)
{
q->qBuff[curBuffPosition++] = NbBytesToCopy & 0xFF;
q->qBuff[curBuffPosition++] = (NbBytesToCopy & 0xFF00) >> 8 ;
q->byteCount += 2;
}
}
/* case of CIRCULAR_QUEUE_SPLIT_IF_WRAPPING_FLAG option */
else if (q->optionFlags & CIRCULAR_QUEUE_SPLIT_IF_WRAPPING_FLAG)
{
if (q->elementSize == 0)
{
/* reset the size of current element to the nb bytes fitting at the end of buffer */
q->qBuff[curBuffPosition-2] = NbBytesToCopy & 0xFF;
q->qBuff[curBuffPosition-1] = (NbBytesToCopy & 0xFF00) >> 8 ;
/* copy the bytes */
memcpy(&q->qBuff[curBuffPosition],&x[i*elementSize],NbBytesToCopy);
q->byteCount += NbBytesToCopy;
/* set the number of copied bytes */
NbCopiedBytes = NbBytesToCopy;
/* set rest of data to be copied to begnning of buffer */
NbBytesToCopy = elementSize - NbBytesToCopy;
/* one element more dur to split in 2 elements */
q->elementCount++;
/* Wrap */
curBuffPosition = 0;
/* Set new size for rest of data */
q->qBuff[curBuffPosition++] = NbBytesToCopy & 0xFF;
q->qBuff[curBuffPosition++] = (NbBytesToCopy & 0xFF00) >> 8 ;
q->byteCount += 2;
}
else
{
/* Should not occur */
/* can not manage split Flag on Fixed size element */
/* Buffer is corrupted */
return NULL;
}
}
curElementSize = (NbBytesToCopy) + elemSizeStorageRoom ;
q->last = 0;
}
/* some remaining byte to copy */
if (NbBytesToCopy)
{
memcpy(&q->qBuff[curBuffPosition],&x[(i*elementSize)+NbCopiedBytes],NbBytesToCopy);
q->byteCount += NbBytesToCopy;
}
/* One more element */
q->elementCount++;
}
ptr = q->qBuff + (MOD((q->last+elemSizeStorageRoom ),q->queueMaxSize));
}
/* for Breakpoint only...to remove */
else
{
return NULL;
}
return ptr;
}
/**
* @brief Remove element from the queue and copy it in provided buffer
* @note This function is used to remove and element from the Circular Queue .
* @param q: pointer on queue structure to be handled
* @param elementSize: Pointer to return Size of element to be removed
* @param buffer: destination buffer where to copy element
* @retval Pointer on removed element. NULL if queue was empty
*/
uint8_t* CircularQueue_Remove_Copy(queue_t *q, uint16_t* elementSize, uint8_t* buffer)
{
return NULL;
}
/**
* @brief Remove element from the queue.
* @note This function is used to remove and element from the Circular Queue .
* @param q: pointer on queue structure to be handled
* @param elementSize: Pointer to return Size of element to be removed (ignored if NULL)
* @retval Pointer on removed element. NULL if queue was empty
*/
uint8_t* CircularQueue_Remove(queue_t *q, uint16_t* elementSize)
{
uint8_t elemSizeStorageRoom = 0;
uint8_t* ptr= NULL;
elemSizeStorageRoom = (q->elementSize == 0) ? 2 : 0;
uint16_t eltSize = 0;
if (q->byteCount > 0)
{
/* retrieve element Size */
eltSize = (q->elementSize == 0) ? q->qBuff[q->first] + ((q->qBuff[MOD((q->first+1), q->queueMaxSize)])<<8) : q->elementSize;
if ((q->optionFlags & CIRCULAR_QUEUE_NO_WRAP_FLAG) && !(q->optionFlags & CIRCULAR_QUEUE_SPLIT_IF_WRAPPING_FLAG))
{
if (((eltSize == 0xFFFF) && q->elementSize == 0 ) ||
((q->first > q->last) && q->elementSize && ((q->queueMaxSize - q->first) < q->elementSize)))
{
/* all data from current position up to the end of buffer are invalid */
q->byteCount -= (q->queueMaxSize - q->first);
/* Adjust first element pos */
q->first = 0;
/* retrieve the right size after the wrap [if variable size element] */
eltSize = (q->elementSize == 0) ? q->qBuff[q->first] + ((q->qBuff[MOD((q->first+1), q->queueMaxSize)])<<8) : q->elementSize;
}
}
/* retrieve element */
ptr = q->qBuff + (MOD((q->first + elemSizeStorageRoom), q->queueMaxSize));
/* adjust byte count */
q->byteCount -= (eltSize + elemSizeStorageRoom) ;
/* Adjust q->first */
if (q->byteCount > 0)
{
q->first = MOD((q->first+ eltSize + elemSizeStorageRoom ), q->queueMaxSize);
}
/* adjust element count */
--q->elementCount;
}
if (elementSize != NULL)
{
*elementSize = eltSize;
}
return ptr;
}
/**
* @brief "Sense" first element of the queue, without removing it and copy it in provided buffer
* @note This function is used to return a pointer on the first element of the queue without removing it.
* @param q: pointer on queue structure to be handled
* @param elementSize: Pointer to return Size of element to be removed
* @param buffer: destination buffer where to copy element
* @retval Pointer on sensed element. NULL if queue was empty
*/
uint8_t* CircularQueue_Sense_Copy(queue_t *q, uint16_t* elementSize, uint8_t* buffer)
{
return NULL;
}
/**
* @brief "Sense" first element of the queue, without removing it.
* @note This function is used to return a pointer on the first element of the queue without removing it.
* @param q: pointer on queue structure to be handled
* @param elementSize: Pointer to return Size of element to be removed (ignored if NULL)
* @retval Pointer on sensed element. NULL if queue was empty
*/
uint8_t* CircularQueue_Sense(queue_t *q, uint16_t* elementSize)
{
uint8_t elemSizeStorageRoom = 0;
uint8_t* x= NULL;
elemSizeStorageRoom = (q->elementSize == 0) ? 2 : 0;
uint16_t eltSize = 0;
uint32_t FirstElemetPos = 0;
if (q->byteCount > 0)
{
FirstElemetPos = q->first;
eltSize = (q->elementSize == 0) ? q->qBuff[q->first] + ((q->qBuff[MOD((q->first+1), q->queueMaxSize)])<<8) : q->elementSize;
if ((q->optionFlags & CIRCULAR_QUEUE_NO_WRAP_FLAG) && !(q->optionFlags & CIRCULAR_QUEUE_SPLIT_IF_WRAPPING_FLAG))
{
if (((eltSize == 0xFFFF) && q->elementSize == 0 ) ||
((q->first > q->last) && q->elementSize && ((q->queueMaxSize - q->first) < q->elementSize)))
{
/* all data from current position up to the end of buffer are invalid */
FirstElemetPos = 0; /* wrap to the begiining of buffer */
/* retrieve the right size after the wrap [if variable size element] */
eltSize = (q->elementSize == 0) ? q->qBuff[FirstElemetPos]+ ((q->qBuff[MOD((FirstElemetPos+1), q->queueMaxSize)])<<8) : q->elementSize;
}
}
/* retrieve element */
x = q->qBuff + (MOD((FirstElemetPos + elemSizeStorageRoom), q->queueMaxSize));
}
if (elementSize != NULL)
{
*elementSize = eltSize;
}
return x;
}
/**
* @brief Check if queue is empty.
* @note This function is used to to check if the queue is empty.
* @param q: pointer on queue structure to be handled
* @retval TRUE (!0) if the queue is empyu otherwise FALSE (0)
*/
int CircularQueue_Empty(queue_t *q)
{
int ret=FALSE;
if (q->byteCount <= 0)
{
ret=TRUE;
}
return ret;
}
int CircularQueue_NbElement(queue_t *q)
{
return q->elementCount;
}
@@ -0,0 +1,59 @@
/**
******************************************************************************
* @file stm_queue.h
* @author MCD Application Team
* @brief Header for stm_queue.c
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM_QUEUE_H
#define __STM_QUEUE_H
/* Includes ------------------------------------------------------------------*/
/* Exported define -----------------------------------------------------------*/
/* Options flags */
#define CIRCULAR_QUEUE_NO_FLAG 0
#define CIRCULAR_QUEUE_NO_WRAP_FLAG 1
#define CIRCULAR_QUEUE_SPLIT_IF_WRAPPING_FLAG 2
/* Exported types ------------------------------------------------------------*/
typedef struct {
uint8_t* qBuff; /* queue buffer, , provided by init fct */
uint32_t queueMaxSize; /* size of the queue, provided by init fct (in bytes)*/
uint16_t elementSize; /* -1 variable. If variable element size the size is stored in the 4 first of the queue element */
uint32_t first; /* position of first element */
uint32_t last; /* position of last element */
uint32_t byteCount; /* number of bytes in the queue */
uint32_t elementCount; /* number of element in the queue */
uint8_t optionFlags; /* option to enable specific features */
} queue_t;
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
int CircularQueue_Init(queue_t *q, uint8_t* queueBuffer, uint32_t queueSize, uint16_t elementSize, uint8_t optionlags);
uint8_t* CircularQueue_Add(queue_t *q, uint8_t* x, uint16_t elementSize, uint32_t nbElements);
uint8_t* CircularQueue_Remove(queue_t *q, uint16_t* elementSize);
uint8_t* CircularQueue_Sense(queue_t *q, uint16_t* elementSize);
int CircularQueue_Empty(queue_t *q);
int CircularQueue_NbElement(queue_t *q);
uint8_t* CircularQueue_Remove_Copy(queue_t *q, uint16_t* elementSize, uint8_t* buffer);
uint8_t* CircularQueue_Sense_Copy(queue_t *q, uint16_t* elementSize, uint8_t* buffer);
#endif /* __STM_QUEUE_H */
@@ -0,0 +1,159 @@
/**
******************************************************************************
* @file utilities_common.h
* @author MCD Application Team
* @brief Common file to utilities
******************************************************************************
* @attention
*
* Copyright (c) 2018-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __UTILITIES_COMMON_H
#define __UTILITIES_COMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "app_conf.h"
/* -------------------------------- *
* Basic definitions *
* -------------------------------- */
#undef NULL
#define NULL 0
#undef FALSE
#define FALSE 0
#undef TRUE
#define TRUE (!0)
/* -------------------------------- *
* Critical Section definition *
* -------------------------------- */
#undef BACKUP_PRIMASK
#define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK()
#undef DISABLE_IRQ
#define DISABLE_IRQ() __disable_irq()
#undef RESTORE_PRIMASK
#define RESTORE_PRIMASK() __set_PRIMASK(primask_bit)
/* -------------------------------- *
* Macro delimiters *
* -------------------------------- */
#undef M_BEGIN
#define M_BEGIN do {
#undef M_END
#define M_END } while(0)
/* -------------------------------- *
* Some useful macro definitions *
* -------------------------------- */
#undef MAX
#define MAX( x, y ) (((x)>(y))?(x):(y))
#undef MIN
#define MIN( x, y ) (((x)<(y))?(x):(y))
#undef MODINC
#define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END
#undef MODDEC
#define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END
#undef MODADD
#define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END
#undef MODSUB
#define MODSUB( a, b, m ) MODADD( a, (m)-(b), m )
#undef ALIGN
#ifdef WIN32
#define ALIGN(n)
#else
#define ALIGN(n) __attribute__((aligned(n)))
#endif
#undef PAUSE
#define PAUSE( t ) M_BEGIN \
volatile int _i; \
for ( _i = t; _i > 0; _i -- ); \
M_END
#undef DIVF
#define DIVF( x, y ) ((x)/(y))
#undef DIVC
#define DIVC( x, y ) (((x)+(y)-1)/(y))
#undef DIVR
#define DIVR( x, y ) (((x)+((y)/2))/(y))
#undef SHRR
#define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1)
#undef BITN
#define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1)
#undef BITNSET
#define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END
/* -------------------------------- *
* Section attribute *
* -------------------------------- */
#define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__)))
/* ----------------------------------- *
* Packed usage (compiler dependent) *
* ----------------------------------- */
#undef PACKED__
#undef PACKED_STRUCT
#if defined ( __CC_ARM )
#if defined ( __GNUC__ )
/* GNU extension */
#define PACKED__ __attribute__((packed))
#define PACKED_STRUCT struct PACKED__
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U)
#define PACKED__ __attribute__((packed))
#define PACKED_STRUCT struct PACKED__
#else
#define PACKED__(TYPE) __packed TYPE
#define PACKED_STRUCT PACKED__(struct)
#endif
#elif defined ( __GNUC__ )
#define PACKED__ __attribute__((packed))
#define PACKED_STRUCT struct PACKED__
#elif defined (__ICCARM__)
#define PACKED_STRUCT __packed struct
#else
#define PACKED_STRUCT __packed struct
#endif
#ifdef __cplusplus
}
#endif
#endif /*__UTILITIES_COMMON_H */