clean, optimize, ...
This commit is contained in:
parent
09bf16766c
commit
7892e875dc
16 changed files with 3701 additions and 2999 deletions
5543
TestTHB2.hex
5543
TestTHB2.hex
File diff suppressed because it is too large
Load diff
|
|
@ -14,7 +14,7 @@
|
|||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.28719871" name="Default" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.dockerdpath=,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.28719871" name="Default" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.dockerdpath=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||
<folderInfo id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.28719871.266191087" name="/" resourcePath="">
|
||||
<toolChain id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.321694806" name="Arm Cross GCC" superClass="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base">
|
||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.2086137351" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.architecture" value="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.arm" valueType="enumerated"/>
|
||||
|
|
@ -308,6 +308,14 @@
|
|||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="erase_and_flash" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>${cross_make}</buildCommand>
|
||||
<buildArguments>-j24</buildArguments>
|
||||
<buildTarget>erase_and_flash</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
</buildTargets>
|
||||
</storageModule>
|
||||
</cproject>
|
||||
|
|
@ -15,8 +15,10 @@ SRC_PRJ += bthome_beacon.c
|
|||
SRC_PRJ += osal_peripheral.c
|
||||
SRC_PRJ += peripheral_main.c
|
||||
SRC_PRJ += sbp_profile_ota.c
|
||||
SRC_PRJ += devinfoservice.c
|
||||
SRC_PRJ += sensors.c
|
||||
SRC_PRJ += thb2_main.c
|
||||
SRC_PRJ += thb2_peripheral.c
|
||||
SRC_PRJ += thservice.c
|
||||
|
||||
INCLUDES = -I$(SRC_PATH)
|
||||
|
|
@ -154,12 +156,12 @@ SRCS += $(SDK_PATH)/components/driver/log/my_printf.c
|
|||
|
||||
#SRCS += $(SDK_PATH)/components/profiles/Roles/central.c
|
||||
#SRCS += $(SDK_PATH)/components/profiles/ota_app/ota_app_service.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/Roles/peripheral.c
|
||||
#SRCS += $(SDK_PATH)/components/profiles/Roles/peripheral.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/Roles/gapbondmgr.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/Roles/gapgattserver.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/Roles/gap.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/GATT/gattservapp.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/DevInfo/devinfoservice.c
|
||||
#SRCS += $(SDK_PATH)/components/profiles/DevInfo/devinfoservice.c
|
||||
|
||||
SRCS += $(SDK_PATH)/components/osal/snv/osal_snv.c
|
||||
SRCS += $(SDK_PATH)/components/libraries/fs/fs.c
|
||||
|
|
@ -217,7 +219,7 @@ OBJS = $(patsubst %, $(OBJ_DIR)/%, $(patsubst ./%, %, $(SRC_O)))
|
|||
DEPENDENCY_LIST = $(OBJS:%o=%d)
|
||||
|
||||
##############################################################################
|
||||
.PHONY: all directory clean size flash
|
||||
.PHONY: all directory clean size flash erase_and_flash
|
||||
|
||||
all: directory $(SRC_O) $(OBJ_DIR)/$(PROJECT_NAME).elf $(OBJ_DIR)/$(PROJECT_NAME).hex $(OBJ_DIR)/$(PROJECT_NAME).asm size
|
||||
|
||||
|
|
@ -261,7 +263,7 @@ directory:
|
|||
|
||||
size: $(OBJ_DIR)/$(PROJECT_NAME).elf
|
||||
@echo size:
|
||||
#@$(SIZE) -t $^
|
||||
@$(SIZE) -t $^
|
||||
@$(READELF) -l $^
|
||||
@echo
|
||||
|
||||
|
|
|
|||
|
|
@ -338,6 +338,8 @@ repeat:
|
|||
|
||||
case 'X':
|
||||
flags |= LARGE;
|
||||
base = 16;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
base = 16;
|
||||
|
|
@ -346,6 +348,7 @@ repeat:
|
|||
case 'd':
|
||||
case 'i':
|
||||
flags |= SIGN;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -12,16 +12,17 @@ uint8_t g_wdt_cycle = 0xFF;//valid value:0~7.0xFF:watchdog disable.
|
|||
|
||||
void hal_WATCHDOG_IRQHandler(void)
|
||||
{
|
||||
volatile uint32_t a;
|
||||
a = AP_WDT->EOI;
|
||||
// volatile uint32_t a;
|
||||
// a = AP_WDT->EOI;
|
||||
(volatile void)AP_WDT->EOI;
|
||||
AP_WDT->CRR = 0x76;
|
||||
//LOG("WDT IRQ[%08x]\n",rtc_get_counter());
|
||||
}
|
||||
|
||||
__ATTR_SECTION_SRAM__ void hal_watchdog_init(void)
|
||||
{
|
||||
volatile uint32_t a;
|
||||
uint8_t delay;
|
||||
//volatile uint32_t a;
|
||||
volatile uint8_t delay;
|
||||
|
||||
if(g_wdt_cycle > 7)
|
||||
return ;
|
||||
|
|
@ -43,7 +44,8 @@ __ATTR_SECTION_SRAM__ void hal_watchdog_init(void)
|
|||
AP_PCR->SW_RESET0 |= 0x04;
|
||||
delay = 20;
|
||||
|
||||
while(delay-->0);
|
||||
while(delay > 0)
|
||||
delay--;
|
||||
}
|
||||
|
||||
if((AP_PCR->SW_RESET2 & 0x04)==0)
|
||||
|
|
@ -57,23 +59,26 @@ __ATTR_SECTION_SRAM__ void hal_watchdog_init(void)
|
|||
AP_PCR->SW_RESET2 &= ~0x20;
|
||||
delay=20;
|
||||
|
||||
while(delay-->0);
|
||||
while(delay > 0)
|
||||
delay--;
|
||||
|
||||
AP_PCR->SW_RESET2 |= 0x20;
|
||||
delay=20;
|
||||
|
||||
while(delay-->0);
|
||||
while(delay > 0)
|
||||
delay--;
|
||||
|
||||
a = AP_WDT->EOI;
|
||||
// a = AP_WDT->EOI;
|
||||
(volatile void)AP_WDT->EOI;
|
||||
AP_WDT->TORR = g_wdt_cycle;
|
||||
#if (HAL_WDG_CFG_MODE==WDG_USE_INT_MODE)
|
||||
#if (HAL_WDG_CFG_MODE==WDG_USE_INT_MODE)
|
||||
NVIC_SetPriority((IRQn_Type)WDT_IRQn, IRQ_PRIO_HAL);
|
||||
NVIC_EnableIRQ((IRQn_Type)WDT_IRQn);
|
||||
JUMP_FUNCTION(WDT_IRQ_HANDLER) = (uint32_t)&hal_WATCHDOG_IRQHandler;
|
||||
AP_WDT->CR = 0x1F;//use int
|
||||
#else
|
||||
#else
|
||||
AP_WDT->CR = 0x1D;//not use int
|
||||
#endif
|
||||
#endif
|
||||
AP_WDT_FEED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,15 +29,15 @@
|
|||
/*********************************************************************
|
||||
MACROS
|
||||
*/
|
||||
#define SYSTEM_ID_ENABLE 0
|
||||
#define MODEL_NUMBER_STR_ENABLE 1
|
||||
#define SYSTEM_ID_ENABLE 1
|
||||
#define MODEL_NUMBER_STR_ENABLE 1
|
||||
#define SERIAL_NUMBER_STR_ENABLE 1
|
||||
#define FIRMWARE_REVISION_ENABLE 1
|
||||
#define HARDWARE_REVISION_ENABLE 1
|
||||
#define SOFTWARE_REVISION_ENABLE 1
|
||||
#define MANUFACTURE_NAME_STR_ENABLE 1
|
||||
#define IEEE_DATA_ENABLE 0
|
||||
#define PNP_ID_ENABLE 0
|
||||
#define IEEE_DATA_ENABLE 1
|
||||
#define PNP_ID_ENABLE 1
|
||||
|
||||
/*********************************************************************
|
||||
CONSTANTS
|
||||
|
|
@ -139,37 +139,37 @@ static uint8 devInfoSystemId[DEVINFO_SYSTEM_ID_LEN] = {0, 0, 0, 0, 0, 0, 0, 0}
|
|||
#if MODEL_NUMBER_STR_ENABLE
|
||||
// Model Number String characteristic
|
||||
static uint8 devInfoModelNumberProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoModelNumber[] = "THB2";
|
||||
static const uint8 devInfoModelNumber[] = "Model Number";
|
||||
#endif
|
||||
|
||||
#if SERIAL_NUMBER_STR_ENABLE
|
||||
// Serial Number String characteristic
|
||||
static uint8 devInfoSerialNumberProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoSerialNumber[] = "0001";
|
||||
static const uint8 devInfoSerialNumber[] = "Serial Number";
|
||||
#endif
|
||||
|
||||
#if FIRMWARE_REVISION_ENABLE
|
||||
// Firmware Revision String characteristic
|
||||
static uint8 devInfoFirmwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoFirmwareRev[] = "github.com/pvvx";
|
||||
static const uint8 devInfoFirmwareRev[] = "Firmware Revision";
|
||||
#endif
|
||||
|
||||
#if HARDWARE_REVISION_ENABLE
|
||||
// Hardware Revision String characteristic
|
||||
static uint8 devInfoHardwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoHardwareRev[] = "0.1";
|
||||
static const uint8 devInfoHardwareRev[] = "Hardware Revision";
|
||||
#endif
|
||||
|
||||
#if SOFTWARE_REVISION_ENABLE
|
||||
// Software Revision String characteristic
|
||||
static uint8 devInfoSoftwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoSoftwareRev[] = "V0.2";
|
||||
static const uint8 devInfoSoftwareRev[] = "Software Revision";
|
||||
#endif
|
||||
|
||||
#if MANUFACTURE_NAME_STR_ENABLE
|
||||
// Manufacturer Name String characteristic
|
||||
static uint8 devInfoMfrNameProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoMfrName[] = "Tuya";
|
||||
static const uint8 devInfoMfrName[] = "Manufacturer Name";
|
||||
#endif
|
||||
|
||||
#if IEEE_DATA_ENABLE
|
||||
|
|
@ -328,8 +328,6 @@ bStatus_t DevInfo_AddService( void )
|
|||
*/
|
||||
bStatus_t DevInfo_SetParameter( uint8 param, uint8 len, void* value )
|
||||
{
|
||||
(void) len;
|
||||
(void) value;
|
||||
bStatus_t ret = SUCCESS;
|
||||
|
||||
switch ( param )
|
||||
|
|
@ -446,7 +444,6 @@ bStatus_t DevInfo_GetParameter( uint8 param, void* value )
|
|||
static uint8 devInfo_ReadAttrCB( uint16 connHandle, gattAttribute_t* pAttr,
|
||||
uint8* pValue, uint16* pLen, uint16 offset, uint8 maxLen )
|
||||
{
|
||||
(void) connHandle;
|
||||
bStatus_t status = SUCCESS;
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
|
||||
|
|
|
|||
|
|
@ -289,15 +289,13 @@ static uint8 gapCentProcessHCICmdEvt( uint16 cmdOpcode, hciEvt_CmdComplete_t* pM
|
|||
{
|
||||
case HCI_LE_SET_SCAN_ENABLE:
|
||||
if ( *(pMsg->pReturnParam) == SUCCESS )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
safeToDealloc = gapSetScanParamStatus( *(pMsg->pReturnParam) );
|
||||
break;
|
||||
/*lint --fallthrough */
|
||||
case HCI_LE_SET_SCAN_PARAM:
|
||||
safeToDealloc = gapSetScanParamStatus( *(pMsg->pReturnParam) );
|
||||
break;
|
||||
|
||||
default:
|
||||
safeToDealloc = FALSE; // send this message to the app
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -415,10 +415,13 @@ static uint8 gapProcessHCICmdCompleteEvt( hciEvt_CmdComplete_t* pMsg )
|
|||
|
||||
case HCI_LE_SET_SCAN_ENABLE:
|
||||
if ( *(pMsg->pReturnParam) == SUCCESS )
|
||||
{
|
||||
break;
|
||||
if ( pfnCentralCBs && pfnCentralCBs->pfnProcessHCICmdEvt )
|
||||
{
|
||||
safeToDealloc = pfnCentralCBs->pfnProcessHCICmdEvt( pMsg->cmdOpcode, pMsg );
|
||||
}
|
||||
|
||||
break;
|
||||
/*lint --fallthrough */
|
||||
case HCI_LE_SET_SCAN_PARAM:
|
||||
if ( pfnCentralCBs && pfnCentralCBs->pfnProcessHCICmdEvt )
|
||||
|
|
|
|||
|
|
@ -862,7 +862,7 @@ static void gattStoreServerInfo( gattServerInfo_t* pServer, uint8 taskId )
|
|||
static bStatus_t gattServerProcessMsgCB( uint16 connHandle, attPacket_t* pPkt )
|
||||
{
|
||||
gattMsg_t msg;
|
||||
uint8 status;
|
||||
uint8 status = SUCCESS;
|
||||
|
||||
// See if this is a confirmation to an indication
|
||||
if ( pPkt->method == ATT_HANDLE_VALUE_CFM )
|
||||
|
|
|
|||
|
|
@ -4594,7 +4594,7 @@ uint8 ll_processBasicIRQ_secondaryInitSRX0(uint32_t irq_status )
|
|||
remainder = (remainder + (remainder >> 1) + (remainder >> 3) + (remainder >> 7)) >> 10; // rough estimate of (x / 625) = (1/1024 + 1/2048 + 1/8192)
|
||||
|
||||
// winoffset should less then conn interval
|
||||
if (g_new_master_delta - 2 > (conn_param[initInfo.connId].curParam.connInterval << 1)) // win_offset should less then conn interval
|
||||
if (g_new_master_delta - 2 > (uint32_t)(conn_param[initInfo.connId].curParam.connInterval << 1)) // win_offset should less then conn interval
|
||||
g_new_master_delta -= conn_param[initInfo.connId].curParam.connInterval << 1;
|
||||
|
||||
win_offset = (remainder - 2) >> 1;
|
||||
|
|
@ -7916,8 +7916,8 @@ __ATTR_SECTION_XIP__ void init_config(void)
|
|||
void ll_patch_slave(void)
|
||||
{
|
||||
JUMP_FUNCTION(LL_SET_ADV_PARAM) = (uint32_t)&LL_SetAdvParam1;
|
||||
JUMP_FUNCTION(LL_CALC_MAX_SCAN_TIME) = (uint32_t)&llCalcMaxScanTime1;
|
||||
JUMP_FUNCTION(LL_SEC_ADV_ALLOW) = (uint32_t)&llSecAdvAllow1;
|
||||
JUMP_FUNCTION(LL_CALC_MAX_SCAN_TIME) = (uint32_t)&llCalcMaxScanTime1;
|
||||
JUMP_FUNCTION(LL_SEC_ADV_ALLOW) = (uint32_t)&llSecAdvAllow1;
|
||||
JUMP_FUNCTION(LL_SET_ADV_CONTROL) = (uint32_t)&LL_SetAdvControl1;
|
||||
JUMP_FUNCTION(LL_SETUP_SEC_ADV_ENTRY) = (uint32_t)&llSetupSecAdvEvt1;
|
||||
JUMP_FUNCTION(LL_SCHEDULER) = (uint32_t)&ll_scheduler2;
|
||||
|
|
@ -7931,8 +7931,8 @@ void ll_patch_master(void)
|
|||
JUMP_FUNCTION(LL_MASTER_EVT_ENDOK) = (uint32_t)&llMasterEvt_TaskEndOk1;
|
||||
JUMP_FUNCTION(LL_SET_SCAN_PARAM) = (uint32_t)&LL_SetScanParam1;
|
||||
JUMP_FUNCTION(LL_SET_SCAN_CTRL) = (uint32_t)&LL_SetScanControl1;
|
||||
//JUMP_FUNCTION(LL_PROCESS_MASTER_CTRL_PKT) = (uint32_t)&llProcessMasterControlPacket1;
|
||||
JUMP_FUNCTION(LL_CREATE_CONN) = (uint32_t)&LL_CreateConn1;
|
||||
//JUMP_FUNCTION(LL_PROCESS_MASTER_CTRL_PKT) = (uint32_t)&llProcessMasterControlPacket1;
|
||||
JUMP_FUNCTION(LL_CREATE_CONN) = (uint32_t)&LL_CreateConn1;
|
||||
JUMP_FUNCTION(LL_START_ENCRYPT) = (uint32_t)&LL_StartEncrypt1;
|
||||
JUMP_FUNCTION(LL_ENC_DECRYPT) = (uint32_t)&LL_ENC_Decrypt1;
|
||||
JUMP_FUNCTION(LL_PROCESS_MASTER_CTRL_PROC) = (uint32_t)&llProcessMasterControlProcedures1;
|
||||
|
|
@ -8002,7 +8002,7 @@ hciStatus_t HCI_LE_SetHostChanClassificationCmd(uint8* chanMap)
|
|||
void pplus_enter_programming_mode(void)
|
||||
{
|
||||
typedef void (*uart_init_t)(int baud, GPIO_Pin_e tx_pin, GPIO_Pin_e rx_pin,uint32_t cb_addr);
|
||||
typedef void (*uart_tx_t)(unsigned char* str);
|
||||
typedef void (*uart_tx_t)(char* str);
|
||||
typedef void (*uart_cmd_t)(void);
|
||||
uart_init_t p_uart_init = (uart_init_t)0x0000b379;
|
||||
uart_tx_t p_uart_tx = (uart_tx_t)0x0000b4f5;
|
||||
|
|
|
|||
|
|
@ -17,13 +17,6 @@
|
|||
Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
//extern const uint32_t _sramscttexts;
|
||||
//extern const uint32_t _sramscttext;
|
||||
//extern const uint32_t _eramscttext;
|
||||
|
||||
//extern const uint32_t _sjtblss;
|
||||
//extern const uint32_t _sjtbls;
|
||||
//extern const uint32_t _ejtbls;
|
||||
extern int main(void);
|
||||
extern const uint32_t _sbss;
|
||||
extern const uint32_t _ebss;
|
||||
|
|
@ -56,8 +49,11 @@ void c_start(void)
|
|||
dest = (uint8_t*)&_sbss;
|
||||
edest = (uint8_t*)&_ebss;
|
||||
osal_memset(dest, 0, edest - dest);
|
||||
/* filled in init_config() */
|
||||
/*
|
||||
dest = (uint8_t*)0x1fff0400;
|
||||
osal_memset(dest, 0, SOFT_PARAMETER_NUM * 4);
|
||||
*/
|
||||
/* Move the initialized data section from his temporary holding spot in
|
||||
FLASH into the correct place in SRAM. The correct place in SRAM is
|
||||
give by _sdata and _edata. The temporary location is in FLASH at the
|
||||
|
|
|
|||
|
|
@ -94,13 +94,17 @@ SECTIONS
|
|||
. = ALIGN(4);
|
||||
_ebss = ABSOLUTE(.);
|
||||
} > sram
|
||||
|
||||
|
||||
/*
|
||||
.int_stack : {
|
||||
. = ALIGN(4);
|
||||
*(int_stack)
|
||||
. = ALIGN(4);
|
||||
_stack_top = ABSOLUTE(.);
|
||||
} > sram
|
||||
*/
|
||||
/* stack 32 kbytes */
|
||||
g_top_irqstack = ORIGIN(sram) + LENGTH(sram);
|
||||
|
||||
.common_text : {
|
||||
_stext = ABSOLUTE(.);
|
||||
|
|
@ -117,9 +121,7 @@ SECTIONS
|
|||
*(.gnu.linkonce.r.*)
|
||||
_etext = ABSOLUTE(.);
|
||||
} > flash
|
||||
|
||||
g_top_irqstack = ORIGIN(sram) + LENGTH(sram);
|
||||
|
||||
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
|
|
@ -133,5 +135,6 @@ SECTIONS
|
|||
.debug_line 0 : { *(.debug_line) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
592
bthome_phy6222/source/devinfoservice.c
Normal file
592
bthome_phy6222/source/devinfoservice.c
Normal file
|
|
@ -0,0 +1,592 @@
|
|||
/**************************************************************************************************
|
||||
*******
|
||||
**************************************************************************************************/
|
||||
|
||||
/**************************************************************************************************
|
||||
Filename: devinfoservice.c
|
||||
Revised: $Date $
|
||||
Revision: $Revision $
|
||||
|
||||
Description: This file contains the Device Information service.
|
||||
|
||||
|
||||
**************************************************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
INCLUDES
|
||||
*/
|
||||
#include "bcomdef.h"
|
||||
#include "OSAL.h"
|
||||
#include "linkdb.h"
|
||||
#include "att.h"
|
||||
#include "gatt.h"
|
||||
#include "gatt_uuid.h"
|
||||
#include "gatt_profile_uuid.h"
|
||||
#include "gattservapp.h"
|
||||
|
||||
#include "devinfoservice.h"
|
||||
|
||||
/*********************************************************************
|
||||
MACROS
|
||||
*/
|
||||
#define SYSTEM_ID_ENABLE 0
|
||||
#define MODEL_NUMBER_STR_ENABLE 1
|
||||
#define SERIAL_NUMBER_STR_ENABLE 1
|
||||
#define FIRMWARE_REVISION_ENABLE 1
|
||||
#define HARDWARE_REVISION_ENABLE 1
|
||||
#define SOFTWARE_REVISION_ENABLE 1
|
||||
#define MANUFACTURE_NAME_STR_ENABLE 1
|
||||
#define IEEE_DATA_ENABLE 0
|
||||
#define PNP_ID_ENABLE 0
|
||||
|
||||
/*********************************************************************
|
||||
CONSTANTS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
GLOBAL VARIABLES
|
||||
*/
|
||||
// Device information service
|
||||
CONST uint8 devInfoServUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(DEVINFO_SERV_UUID), HI_UINT16(DEVINFO_SERV_UUID)
|
||||
};
|
||||
|
||||
// System ID
|
||||
CONST uint8 devInfoSystemIdUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SYSTEM_ID_UUID), HI_UINT16(SYSTEM_ID_UUID)
|
||||
};
|
||||
|
||||
// Model Number String
|
||||
CONST uint8 devInfoModelNumberUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(MODEL_NUMBER_UUID), HI_UINT16(MODEL_NUMBER_UUID)
|
||||
};
|
||||
|
||||
// Serial Number String
|
||||
CONST uint8 devInfoSerialNumberUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SERIAL_NUMBER_UUID), HI_UINT16(SERIAL_NUMBER_UUID)
|
||||
};
|
||||
|
||||
// Firmware Revision String
|
||||
CONST uint8 devInfoFirmwareRevUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(FIRMWARE_REV_UUID), HI_UINT16(FIRMWARE_REV_UUID)
|
||||
};
|
||||
|
||||
// Hardware Revision String
|
||||
CONST uint8 devInfoHardwareRevUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(HARDWARE_REV_UUID), HI_UINT16(HARDWARE_REV_UUID)
|
||||
};
|
||||
|
||||
// Software Revision String
|
||||
CONST uint8 devInfoSoftwareRevUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SOFTWARE_REV_UUID), HI_UINT16(SOFTWARE_REV_UUID)
|
||||
};
|
||||
|
||||
// Manufacturer Name String
|
||||
CONST uint8 devInfoMfrNameUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(MANUFACTURER_NAME_UUID), HI_UINT16(MANUFACTURER_NAME_UUID)
|
||||
};
|
||||
|
||||
// IEEE 11073-20601 Regulatory Certification Data List
|
||||
CONST uint8 devInfo11073CertUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(IEEE_11073_CERT_DATA_UUID), HI_UINT16(IEEE_11073_CERT_DATA_UUID)
|
||||
};
|
||||
|
||||
// PnP ID
|
||||
CONST uint8 devInfoPnpIdUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(PNP_ID_UUID), HI_UINT16(PNP_ID_UUID)
|
||||
};
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
EXTERNAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
EXTERNAL FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
LOCAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
Profile Attributes - variables
|
||||
*/
|
||||
|
||||
// Device Information Service attribute
|
||||
static CONST gattAttrType_t devInfoService = { ATT_BT_UUID_SIZE, devInfoServUUID };
|
||||
|
||||
#if SYSTEM_ID_ENABLE
|
||||
// System ID characteristic
|
||||
static uint8 devInfoSystemIdProps = GATT_PROP_READ;
|
||||
static uint8 devInfoSystemId[DEVINFO_SYSTEM_ID_LEN] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
#endif
|
||||
|
||||
#if MODEL_NUMBER_STR_ENABLE
|
||||
// Model Number String characteristic
|
||||
static uint8 devInfoModelNumberProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoModelNumber[] = "THB2";
|
||||
#endif
|
||||
|
||||
#if SERIAL_NUMBER_STR_ENABLE
|
||||
// Serial Number String characteristic
|
||||
static uint8 devInfoSerialNumberProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoSerialNumber[] = "0001";
|
||||
#endif
|
||||
|
||||
#if FIRMWARE_REVISION_ENABLE
|
||||
// Firmware Revision String characteristic
|
||||
static uint8 devInfoFirmwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoFirmwareRev[] = "github.com/pvvx";
|
||||
#endif
|
||||
|
||||
#if HARDWARE_REVISION_ENABLE
|
||||
// Hardware Revision String characteristic
|
||||
static uint8 devInfoHardwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoHardwareRev[] = "0.1";
|
||||
#endif
|
||||
|
||||
#if SOFTWARE_REVISION_ENABLE
|
||||
// Software Revision String characteristic
|
||||
static uint8 devInfoSoftwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoSoftwareRev[] = "V0.3";
|
||||
#endif
|
||||
|
||||
#if MANUFACTURE_NAME_STR_ENABLE
|
||||
// Manufacturer Name String characteristic
|
||||
static uint8 devInfoMfrNameProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoMfrName[] = "Tuya";
|
||||
#endif
|
||||
|
||||
#if IEEE_DATA_ENABLE
|
||||
// IEEE 11073-20601 Regulatory Certification Data List characteristic
|
||||
static uint8 devInfo11073CertProps = GATT_PROP_READ;
|
||||
static const uint8 devInfo11073Cert[] =
|
||||
{
|
||||
DEVINFO_11073_BODY_EXP, // authoritative body type
|
||||
0x00, // authoritative body structure type
|
||||
// authoritative body data follows below:
|
||||
'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l'
|
||||
};
|
||||
#endif
|
||||
|
||||
#if PNP_ID_ENABLE
|
||||
// System ID characteristic
|
||||
static uint8 devInfoPnpIdProps = GATT_PROP_READ;
|
||||
static uint8 devInfoPnpId[DEVINFO_PNP_ID_LEN] =
|
||||
{
|
||||
1, // Vendor ID source (1=Bluetooth SIG)
|
||||
LO_UINT16(0x0f0f), HI_UINT16(0x0f0f), // Vendor ID
|
||||
LO_UINT16(0x0000), HI_UINT16(0x0000), // Product ID (vendor-specific)
|
||||
LO_UINT16(0x0110), HI_UINT16(0x0110) // Product version (JJ.M.N)
|
||||
};
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
Profile Attributes - Table
|
||||
*/
|
||||
|
||||
static gattAttribute_t devInfoAttrTbl[] =
|
||||
{
|
||||
/* type */ /* permissions */ /* handle */ /* pValue */
|
||||
// Device Information Service
|
||||
{{ ATT_BT_UUID_SIZE, primaryServiceUUID }, GATT_PERMIT_READ, 0, (uint8 *)&devInfoService },
|
||||
|
||||
#if SYSTEM_ID_ENABLE
|
||||
// System ID Declaration
|
||||
{{ ATT_BT_UUID_SIZE, characterUUID }, GATT_PERMIT_READ, 0, &devInfoSystemIdProps },
|
||||
// System ID Value
|
||||
{{ ATT_BT_UUID_SIZE, devInfoSystemIdUUID }, GATT_PERMIT_READ, 0, (uint8 *) devInfoSystemId },
|
||||
#endif
|
||||
|
||||
#if MODEL_NUMBER_STR_ENABLE
|
||||
// Model Number String Declaration
|
||||
{{ ATT_BT_UUID_SIZE, characterUUID }, GATT_PERMIT_READ, 0, &devInfoModelNumberProps },
|
||||
// Model Number Value
|
||||
{{ ATT_BT_UUID_SIZE, devInfoModelNumberUUID }, GATT_PERMIT_READ, 0, (uint8 *) devInfoModelNumber },
|
||||
#endif
|
||||
|
||||
#if SERIAL_NUMBER_STR_ENABLE
|
||||
// Serial Number String Declaration
|
||||
{{ ATT_BT_UUID_SIZE, characterUUID }, GATT_PERMIT_READ, 0, &devInfoSerialNumberProps },
|
||||
// Serial Number Value
|
||||
{{ ATT_BT_UUID_SIZE, devInfoSerialNumberUUID }, GATT_PERMIT_READ, 0, (uint8 *) devInfoSerialNumber },
|
||||
#endif
|
||||
|
||||
#if FIRMWARE_REVISION_ENABLE
|
||||
// Firmware Revision String Declaration
|
||||
{{ ATT_BT_UUID_SIZE, characterUUID }, GATT_PERMIT_READ, 0, &devInfoFirmwareRevProps },
|
||||
// Firmware Revision Value
|
||||
{{ ATT_BT_UUID_SIZE, devInfoFirmwareRevUUID }, GATT_PERMIT_READ, 0, (uint8 *) devInfoFirmwareRev },
|
||||
#endif
|
||||
|
||||
#if HARDWARE_REVISION_ENABLE
|
||||
// Hardware Revision String Declaration
|
||||
{{ ATT_BT_UUID_SIZE, characterUUID }, GATT_PERMIT_READ, 0, &devInfoHardwareRevProps },
|
||||
// Hardware Revision Value
|
||||
{{ ATT_BT_UUID_SIZE, devInfoHardwareRevUUID }, GATT_PERMIT_READ, 0, (uint8 *) devInfoHardwareRev },
|
||||
#endif
|
||||
|
||||
#if SOFTWARE_REVISION_ENABLE
|
||||
// Software Revision String Declaration
|
||||
{{ ATT_BT_UUID_SIZE, characterUUID }, GATT_PERMIT_READ, 0, &devInfoSoftwareRevProps },
|
||||
// Software Revision Value
|
||||
{{ ATT_BT_UUID_SIZE, devInfoSoftwareRevUUID }, GATT_PERMIT_READ, 0, (uint8 *) devInfoSoftwareRev },
|
||||
#endif
|
||||
|
||||
#if MANUFACTURE_NAME_STR_ENABLE
|
||||
// Manufacturer Name String Declaration
|
||||
{{ ATT_BT_UUID_SIZE, characterUUID }, GATT_PERMIT_READ, 0, &devInfoMfrNameProps },
|
||||
// Manufacturer Name Value
|
||||
{{ ATT_BT_UUID_SIZE, devInfoMfrNameUUID }, GATT_PERMIT_READ, 0, (uint8 *) devInfoMfrName },
|
||||
#endif
|
||||
|
||||
#if IEEE_DATA_ENABLE
|
||||
// IEEE 11073-20601 Regulatory Certification Data List Declaration
|
||||
{{ ATT_BT_UUID_SIZE, characterUUID }, GATT_PERMIT_READ, 0, &devInfo11073CertProps },
|
||||
// IEEE 11073-20601 Regulatory Certification Data List Value
|
||||
{{ ATT_BT_UUID_SIZE, devInfo11073CertUUID }, GATT_PERMIT_READ, 0, (uint8 *) devInfo11073Cert },
|
||||
#endif
|
||||
|
||||
#if PNP_ID_ENABLE
|
||||
// PnP ID Declaration
|
||||
{{ ATT_BT_UUID_SIZE, characterUUID }, GATT_PERMIT_READ, 0, &devInfoPnpIdProps },
|
||||
// PnP ID Value
|
||||
{{ ATT_BT_UUID_SIZE, devInfoPnpIdUUID }, GATT_PERMIT_READ, 0, (uint8 *) devInfoPnpId },
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
LOCAL FUNCTIONS
|
||||
*/
|
||||
static uint8 devInfo_ReadAttrCB( uint16 connHandle, gattAttribute_t* pAttr,
|
||||
uint8* pValue, uint16* pLen, uint16 offset, uint8 maxLen );
|
||||
|
||||
/*********************************************************************
|
||||
PROFILE CALLBACKS
|
||||
*/
|
||||
// Device Info Service Callbacks
|
||||
CONST gattServiceCBs_t devInfoCBs =
|
||||
{
|
||||
devInfo_ReadAttrCB, // Read callback function pointer
|
||||
NULL, // Write callback function pointer
|
||||
NULL // Authorization callback function pointer
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
NETWORK LAYER CALLBACKS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
PUBLIC FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
@fn DevInfo_AddService
|
||||
|
||||
@brief Initializes the Device Information service by registering
|
||||
GATT attributes with the GATT server.
|
||||
|
||||
@return Success or Failure
|
||||
*/
|
||||
bStatus_t DevInfo_AddService( void )
|
||||
{
|
||||
// Register GATT attribute list and CBs with GATT Server App
|
||||
return GATTServApp_RegisterService( devInfoAttrTbl,
|
||||
GATT_NUM_ATTRS( devInfoAttrTbl ),
|
||||
&devInfoCBs );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@fn DevInfo_SetParameter
|
||||
|
||||
@brief Set a Device Information parameter.
|
||||
|
||||
@param param - Profile parameter ID
|
||||
@param len - length of data to write
|
||||
@param value - pointer to data to write. This is dependent on
|
||||
the parameter ID and WILL be cast to the appropriate
|
||||
data type (example: data type of uint16 will be cast to
|
||||
uint16 pointer).
|
||||
|
||||
@return bStatus_t
|
||||
*/
|
||||
bStatus_t DevInfo_SetParameter( uint8 param, uint8 len, void* value )
|
||||
{
|
||||
(void) len;
|
||||
(void) value;
|
||||
bStatus_t ret = SUCCESS;
|
||||
|
||||
switch ( param )
|
||||
{
|
||||
#if SYSTEM_ID_ENABLE
|
||||
case DEVINFO_SYSTEM_ID:
|
||||
osal_memcpy(devInfoSystemId, value, len);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( ret );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@fn DevInfo_GetParameter
|
||||
|
||||
@brief Get a Device Information parameter.
|
||||
|
||||
@param param - Profile parameter ID
|
||||
@param value - pointer to data to get. This is dependent on
|
||||
the parameter ID and WILL be cast to the appropriate
|
||||
data type (example: data type of uint16 will be cast to
|
||||
uint16 pointer).
|
||||
|
||||
@return bStatus_t
|
||||
*/
|
||||
bStatus_t DevInfo_GetParameter( uint8 param, void* value )
|
||||
{
|
||||
bStatus_t ret = SUCCESS;
|
||||
|
||||
switch ( param )
|
||||
{
|
||||
#if SYSTEM_ID_ENABLE
|
||||
case DEVINFO_SYSTEM_ID:
|
||||
osal_memcpy(value, devInfoSystemId, sizeof(devInfoSystemId));
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if MODEL_NUMBER_STR_ENABLE
|
||||
case DEVINFO_MODEL_NUMBER:
|
||||
osal_memcpy(value, devInfoModelNumber, sizeof(devInfoModelNumber));
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if SERIAL_NUMBER_STR_ENABLE
|
||||
case DEVINFO_SERIAL_NUMBER:
|
||||
osal_memcpy(value, devInfoSerialNumber, sizeof(devInfoSerialNumber));
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if FIRMWARE_REVISION_ENABLE
|
||||
case DEVINFO_FIRMWARE_REV:
|
||||
osal_memcpy(value, devInfoFirmwareRev, sizeof(devInfoFirmwareRev));
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if HARDWARE_REVISION_ENABLE
|
||||
case DEVINFO_HARDWARE_REV:
|
||||
osal_memcpy(value, devInfoHardwareRev, sizeof(devInfoHardwareRev));
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if SOFTWARE_REVISION_ENABLE
|
||||
case DEVINFO_SOFTWARE_REV:
|
||||
osal_memcpy(value, devInfoSoftwareRev, sizeof(devInfoSoftwareRev));
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if MANUFACTURE_NAME_STR_ENABLE
|
||||
case DEVINFO_MANUFACTURER_NAME:
|
||||
osal_memcpy(value, devInfoMfrName, sizeof(devInfoMfrName));
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if IEEE_DATA_ENABLE
|
||||
case DEVINFO_11073_CERT_DATA:
|
||||
osal_memcpy(value, devInfo11073Cert, sizeof(devInfo11073Cert));
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if PNP_ID_ENABLE
|
||||
case DEVINFO_PNP_ID:
|
||||
osal_memcpy(value, devInfoPnpId, sizeof(devInfoPnpId));
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( ret );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@fn devInfo_ReadAttrCB
|
||||
|
||||
@brief Read an attribute.
|
||||
|
||||
@param connHandle - connection message was received on
|
||||
@param pAttr - pointer to attribute
|
||||
@param pValue - pointer to data to be read
|
||||
@param pLen - length of data to be read
|
||||
@param offset - offset of the first octet to be read
|
||||
@param maxLen - maximum length of data to be read
|
||||
|
||||
@return Success or Failure
|
||||
*/
|
||||
static uint8 devInfo_ReadAttrCB( uint16 connHandle, gattAttribute_t* pAttr,
|
||||
uint8* pValue, uint16* pLen, uint16 offset, uint8 maxLen )
|
||||
{
|
||||
(void) connHandle;
|
||||
bStatus_t status = SUCCESS;
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
|
||||
switch (uuid)
|
||||
{
|
||||
#if SYSTEM_ID_ENABLE
|
||||
case SYSTEM_ID_UUID:
|
||||
// verify offset
|
||||
if (offset >= sizeof(devInfoSystemId)){
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}else{
|
||||
// determine read length
|
||||
*pLen = MIN(maxLen, (sizeof(devInfoSystemId) - offset));
|
||||
// copy data
|
||||
osal_memcpy(pValue, &devInfoSystemId[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if MODEL_NUMBER_STR_ENABLE
|
||||
case MODEL_NUMBER_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoModelNumber) - 1)){
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}else{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoModelNumber) - 1) - offset));
|
||||
// copy data
|
||||
osal_memcpy(pValue, &devInfoModelNumber[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if SERIAL_NUMBER_STR_ENABLE
|
||||
case SERIAL_NUMBER_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoSerialNumber) - 1)){
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}else{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoSerialNumber) - 1) - offset));
|
||||
// copy data
|
||||
osal_memcpy(pValue, &devInfoSerialNumber[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if FIRMWARE_REVISION_ENABLE
|
||||
case FIRMWARE_REV_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoFirmwareRev) - 1)){
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}else{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoFirmwareRev) - 1) - offset));
|
||||
// copy data
|
||||
osal_memcpy(pValue, &devInfoFirmwareRev[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if HARDWARE_REVISION_ENABLE
|
||||
case HARDWARE_REV_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoHardwareRev) - 1)){
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}else{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoHardwareRev) - 1) - offset));
|
||||
// copy data
|
||||
osal_memcpy(pValue, &devInfoHardwareRev[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if SOFTWARE_REVISION_ENABLE
|
||||
case SOFTWARE_REV_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoSoftwareRev) - 1)){
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}else{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoSoftwareRev) - 1) - offset));
|
||||
// copy data
|
||||
osal_memcpy(pValue, &devInfoSoftwareRev[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if MANUFACTURE_NAME_STR_ENABLE
|
||||
case MANUFACTURER_NAME_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoMfrName) - 1)){
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}else{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoMfrName) - 1) - offset));
|
||||
// copy data
|
||||
osal_memcpy(pValue, &devInfoMfrName[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if IEEE_DATA_ENABLE
|
||||
case IEEE_11073_CERT_DATA_UUID:
|
||||
// verify offset
|
||||
if (offset >= sizeof(devInfo11073Cert)){
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}else{
|
||||
// determine read length
|
||||
*pLen = MIN(maxLen, (sizeof(devInfo11073Cert) - offset));
|
||||
// copy data
|
||||
osal_memcpy(pValue, &devInfo11073Cert[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if PNP_ID_ENABLE
|
||||
case PNP_ID_UUID:
|
||||
// verify offset
|
||||
if (offset >= sizeof(devInfoPnpId)){
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}else{
|
||||
// determine read length
|
||||
*pLen = MIN(maxLen, (sizeof(devInfoPnpId) - offset));
|
||||
// copy data
|
||||
osal_memcpy(pValue, &devInfoPnpId[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( status );
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
115
bthome_phy6222/source/devinfoservice.h
Normal file
115
bthome_phy6222/source/devinfoservice.h
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/**************************************************************************************************
|
||||
*******
|
||||
**************************************************************************************************/
|
||||
|
||||
/**************************************************************************************************
|
||||
Filename: devinfoservice.h
|
||||
Revised: $Date $
|
||||
Revision: $Revision $
|
||||
|
||||
Description: This file contains the Device Information service definitions and
|
||||
prototypes.
|
||||
|
||||
|
||||
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef DEVINFOSERVICE_H
|
||||
#define DEVINFOSERVICE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
INCLUDES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
CONSTANTS
|
||||
*/
|
||||
|
||||
// Device Information Service Parameters
|
||||
#define DEVINFO_SYSTEM_ID 0
|
||||
#define DEVINFO_MODEL_NUMBER 1
|
||||
#define DEVINFO_SERIAL_NUMBER 2
|
||||
#define DEVINFO_FIRMWARE_REV 3
|
||||
#define DEVINFO_HARDWARE_REV 4
|
||||
#define DEVINFO_SOFTWARE_REV 5
|
||||
#define DEVINFO_MANUFACTURER_NAME 6
|
||||
#define DEVINFO_11073_CERT_DATA 7
|
||||
#define DEVINFO_PNP_ID 8
|
||||
|
||||
// IEEE 11073 authoritative body values
|
||||
#define DEVINFO_11073_BODY_EMPTY 0
|
||||
#define DEVINFO_11073_BODY_IEEE 1
|
||||
#define DEVINFO_11073_BODY_CONTINUA 2
|
||||
#define DEVINFO_11073_BODY_EXP 254
|
||||
|
||||
// System ID length
|
||||
#define DEVINFO_SYSTEM_ID_LEN 8
|
||||
|
||||
// PnP ID length
|
||||
#define DEVINFO_PNP_ID_LEN 7
|
||||
|
||||
/*********************************************************************
|
||||
TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
Profile Callbacks
|
||||
*/
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
API FUNCTIONS
|
||||
*/
|
||||
|
||||
/*
|
||||
DevInfo_AddService- Initializes the Device Information service by registering
|
||||
GATT attributes with the GATT server.
|
||||
|
||||
*/
|
||||
|
||||
extern bStatus_t DevInfo_AddService( void );
|
||||
|
||||
/*********************************************************************
|
||||
@fn DevInfo_SetParameter
|
||||
|
||||
@brief Set a Device Information parameter.
|
||||
|
||||
@param param - Profile parameter ID
|
||||
@param len - length of data to right
|
||||
@param value - pointer to data to write. This is dependent on
|
||||
the parameter ID and WILL be cast to the appropriate
|
||||
data type (example: data type of uint16 will be cast to
|
||||
uint16 pointer).
|
||||
|
||||
@return bStatus_t
|
||||
*/
|
||||
bStatus_t DevInfo_SetParameter( uint8 param, uint8 len, void* value );
|
||||
|
||||
/*
|
||||
DevInfo_GetParameter - Get a Device Information parameter.
|
||||
|
||||
param - Profile parameter ID
|
||||
value - pointer to data to write. This is dependent on
|
||||
the parameter ID and WILL be cast to the appropriate
|
||||
data type (example: data type of uint16 will be cast to
|
||||
uint16 pointer).
|
||||
*/
|
||||
extern bStatus_t DevInfo_GetParameter( uint8 param, void* value );
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DEVINFOSERVICE_H */
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/**************************************************************************************************
|
||||
*******
|
||||
**************************************************************************************************/
|
||||
*******
|
||||
**************************************************************************************************/
|
||||
|
||||
#include "bus_dev.h"
|
||||
#include "gpio.h"
|
||||
|
|
@ -19,43 +19,41 @@
|
|||
#include "adc.h"
|
||||
#define DEFAULT_UART_BAUD 115200
|
||||
|
||||
/*********************************************************************
|
||||
LOCAL FUNCTION PROTOTYPES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
LOCAL FUNCTION PROTOTYPES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
EXTERNAL FUNCTIONS
|
||||
*/
|
||||
EXTERNAL FUNCTIONS
|
||||
*/
|
||||
|
||||
extern void init_config(void);
|
||||
extern int app_main(void);
|
||||
extern void hal_rom_boot_init(void);
|
||||
/*********************************************************************
|
||||
CONNECTION CONTEXT RELATE DEFINITION
|
||||
*/
|
||||
CONNECTION CONTEXT RELATE DEFINITION
|
||||
*/
|
||||
|
||||
#define BLE_MAX_ALLOW_CONNECTION 1
|
||||
#define BLE_MAX_ALLOW_PKT_PER_EVENT_TX 3
|
||||
#define BLE_MAX_ALLOW_PKT_PER_EVENT_RX 3
|
||||
#define BLE_PKT_VERSION BLE_PKT_VERSION_5_1 // BLE_PKT_VERSION_4_0
|
||||
|
||||
|
||||
/* BLE_MAX_ALLOW_PER_CONNECTION
|
||||
{
|
||||
...
|
||||
struct ll_pkt_desc *tx_conn_desc[MAX_LL_BUF_LEN]; // new Tx data buffer
|
||||
struct ll_pkt_desc *rx_conn_desc[MAX_LL_BUF_LEN];
|
||||
{
|
||||
...
|
||||
struct ll_pkt_desc *tx_conn_desc[MAX_LL_BUF_LEN]; // new Tx data buffer
|
||||
struct ll_pkt_desc *rx_conn_desc[MAX_LL_BUF_LEN];
|
||||
|
||||
struct ll_pkt_desc *tx_not_ack_pkt;
|
||||
struct ll_pkt_desc *tx_ntrm_pkts[MAX_LL_BUF_LEN];
|
||||
...
|
||||
}
|
||||
tx_conn_desc[] + tx_ntrm_pkts[] --> BLE_MAX_ALLOW_PKT_PER_EVENT_TX * BLE_PKT_BUF_SIZE*2
|
||||
rx_conn_desc[] --> BLE_MAX_ALLOW_PKT_PER_EVENT_RX * BLE_PKT_BUF_SIZE
|
||||
tx_not_ack_pkt --> 1*BLE_PKT_BUF_SIZE
|
||||
struct ll_pkt_desc *tx_not_ack_pkt;
|
||||
struct ll_pkt_desc *tx_ntrm_pkts[MAX_LL_BUF_LEN];
|
||||
...
|
||||
}
|
||||
tx_conn_desc[] + tx_ntrm_pkts[] --> BLE_MAX_ALLOW_PKT_PER_EVENT_TX * BLE_PKT_BUF_SIZE*2
|
||||
rx_conn_desc[] --> BLE_MAX_ALLOW_PKT_PER_EVENT_RX * BLE_PKT_BUF_SIZE
|
||||
tx_not_ack_pkt --> 1*BLE_PKT_BUF_SIZE
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
#define BLE_PKT_BUF_SIZE (((BLE_PKT_VERSION == BLE_PKT_VERSION_5_1) ? 1 : 0) * BLE_PKT51_LEN \
|
||||
+ ((BLE_PKT_VERSION == BLE_PKT_VERSION_4_0) ? 1 : 0) * BLE_PKT40_LEN \
|
||||
|
|
@ -67,124 +65,117 @@ extern void hal_rom_boot_init(void);
|
|||
|
||||
#define BLE_CONN_BUF_SIZE (BLE_MAX_ALLOW_CONNECTION * BLE_MAX_ALLOW_PER_CONNECTION)
|
||||
|
||||
|
||||
ALIGN4_U8 g_pConnectionBuffer[BLE_CONN_BUF_SIZE];
|
||||
llConnState_t pConnContext[BLE_MAX_ALLOW_CONNECTION];
|
||||
ALIGN4_U8 g_pConnectionBuffer[BLE_CONN_BUF_SIZE];
|
||||
llConnState_t pConnContext[BLE_MAX_ALLOW_CONNECTION];
|
||||
|
||||
/*********************************************************************
|
||||
CTE IQ SAMPLE BUF config
|
||||
*/
|
||||
CTE IQ SAMPLE BUF config
|
||||
*/
|
||||
//#define BLE_SUPPORT_CTE_IQ_SAMPLE TRUE
|
||||
#ifdef BLE_SUPPORT_CTE_IQ_SAMPLE
|
||||
uint16 g_llCteSampleI[LL_CTE_MAX_SUPP_LEN * LL_CTE_SUPP_LEN_UNIT];
|
||||
uint16 g_llCteSampleQ[LL_CTE_MAX_SUPP_LEN * LL_CTE_SUPP_LEN_UNIT];
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
OSAL LARGE HEAP CONFIG
|
||||
*/
|
||||
OSAL LARGE HEAP CONFIG
|
||||
*/
|
||||
#define LARGE_HEAP_SIZE (4*1024)
|
||||
ALIGN4_U8 g_largeHeap[LARGE_HEAP_SIZE];
|
||||
ALIGN4_U8 g_largeHeap[LARGE_HEAP_SIZE];
|
||||
|
||||
#if 0 // SDK_VER_RELEASE_ID >= 0x030103 ?
|
||||
#define LL_LINKBUF_CFG_NUM 0
|
||||
#define LL_PKT_BUFSIZE 280
|
||||
#define LL_LINK_HEAP_SIZE ( ( BLE_MAX_ALLOW_CONNECTION * 3 + LL_LINKBUF_CFG_NUM ) * LL_PKT_BUFSIZE )//basic Space + configurable Space
|
||||
ALIGN4_U8 g_llLinkHeap[LL_LINK_HEAP_SIZE];
|
||||
ALIGN4_U8 g_llLinkHeap[LL_LINK_HEAP_SIZE];
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
GLOBAL VARIABLES
|
||||
*/
|
||||
GLOBAL VARIABLES
|
||||
*/
|
||||
volatile uint8 g_clk32K_config;
|
||||
volatile sysclk_t g_spif_clk_config;
|
||||
|
||||
/*********************************************************************
|
||||
EXTERNAL VARIABLES
|
||||
*/
|
||||
extern uint32_t __initial_sp;
|
||||
EXTERNAL VARIABLES
|
||||
*/
|
||||
//extern uint32_t __initial_sp;
|
||||
extern int _ebss;
|
||||
|
||||
|
||||
static void hal_low_power_io_init(void)
|
||||
{
|
||||
//========= disable all gpio pullup/down to preserve juice
|
||||
const ioinit_cfg_t ioInit[]=
|
||||
{
|
||||
static void hal_low_power_io_init(void) {
|
||||
//========= disable all gpio pullup/down to preserve juice
|
||||
const ioinit_cfg_t ioInit[] = {
|
||||
#if(SDK_VER_CHIP == __DEF_CHIP_QFN32__)
|
||||
{GPIO_P00, GPIO_PULL_DOWN },
|
||||
{GPIO_P01, GPIO_PULL_DOWN },
|
||||
{GPIO_P02, GPIO_PULL_DOWN },
|
||||
{GPIO_P03, GPIO_PULL_DOWN },
|
||||
{GPIO_P07, GPIO_PULL_UP }, // KEY
|
||||
{GPIO_P09, GPIO_PULL_UP }, // TX
|
||||
{GPIO_P10, GPIO_PULL_UP }, // RX
|
||||
{GPIO_P11, GPIO_FLOATING }, // ADC_VBAT
|
||||
{GPIO_P14, GPIO_PULL_DOWN },
|
||||
{GPIO_P15, GPIO_PULL_DOWN },
|
||||
{GPIO_P16, GPIO_PULL_DOWN },
|
||||
{GPIO_P17, GPIO_PULL_DOWN },
|
||||
{GPIO_P18, GPIO_FLOATING }, // I2C_SDA
|
||||
{GPIO_P20, GPIO_FLOATING }, // I2C_SCL
|
||||
{GPIO_P23, GPIO_PULL_DOWN },
|
||||
{GPIO_P24, GPIO_PULL_DOWN },
|
||||
{GPIO_P25, GPIO_PULL_DOWN },
|
||||
{GPIO_P26, GPIO_FLOATING }, // LED
|
||||
// {GPIO_P27, GPIO_FLOATING },
|
||||
{GPIO_P31, GPIO_PULL_DOWN },
|
||||
{GPIO_P32, GPIO_PULL_DOWN },
|
||||
{GPIO_P33, GPIO_PULL_DOWN },
|
||||
{GPIO_P34, GPIO_PULL_DOWN }
|
||||
{ GPIO_P00, GPIO_PULL_DOWN },
|
||||
{ GPIO_P01, GPIO_PULL_DOWN },
|
||||
{ GPIO_P02, GPIO_PULL_DOWN },
|
||||
{ GPIO_P03, GPIO_PULL_DOWN },
|
||||
{ GPIO_P07, GPIO_PULL_UP }, // KEY
|
||||
{ GPIO_P09, GPIO_PULL_UP }, // TX
|
||||
{ GPIO_P10, GPIO_PULL_UP }, // RX
|
||||
{ GPIO_P11, GPIO_FLOATING }, // ADC_VBAT
|
||||
{ GPIO_P14, GPIO_PULL_DOWN },
|
||||
{ GPIO_P15, GPIO_PULL_DOWN },
|
||||
{ GPIO_P16, GPIO_PULL_DOWN },
|
||||
{ GPIO_P17, GPIO_PULL_DOWN },
|
||||
{ GPIO_P18, GPIO_FLOATING }, // I2C_SDA
|
||||
{ GPIO_P20, GPIO_FLOATING }, // I2C_SCL
|
||||
{ GPIO_P23, GPIO_PULL_DOWN },
|
||||
{ GPIO_P24, GPIO_PULL_DOWN },
|
||||
{ GPIO_P25, GPIO_PULL_DOWN },
|
||||
{ GPIO_P26, GPIO_FLOATING }, // LED
|
||||
// {GPIO_P27, GPIO_FLOATING },
|
||||
{ GPIO_P31, GPIO_PULL_DOWN },
|
||||
{ GPIO_P32, GPIO_PULL_DOWN },
|
||||
{ GPIO_P33, GPIO_PULL_DOWN },
|
||||
{ GPIO_P34, GPIO_PULL_DOWN }
|
||||
#else
|
||||
{GPIO_P02, GPIO_FLOATING },
|
||||
{GPIO_P03, GPIO_FLOATING },
|
||||
{GPIO_P07, GPIO_FLOATING },
|
||||
{GPIO_P09, GPIO_FLOATING },
|
||||
{GPIO_P10, GPIO_FLOATING },
|
||||
{GPIO_P11, GPIO_FLOATING },
|
||||
{GPIO_P14, GPIO_FLOATING },
|
||||
{GPIO_P15, GPIO_FLOATING },
|
||||
{GPIO_P18, GPIO_FLOATING },
|
||||
{GPIO_P20, GPIO_FLOATING },
|
||||
{GPIO_P34, GPIO_FLOATING },
|
||||
{GPIO_P02, GPIO_FLOATING },
|
||||
{GPIO_P03, GPIO_FLOATING },
|
||||
{GPIO_P07, GPIO_FLOATING },
|
||||
{GPIO_P09, GPIO_FLOATING },
|
||||
{GPIO_P10, GPIO_FLOATING },
|
||||
{GPIO_P11, GPIO_FLOATING },
|
||||
{GPIO_P14, GPIO_FLOATING },
|
||||
{GPIO_P15, GPIO_FLOATING },
|
||||
{GPIO_P18, GPIO_FLOATING },
|
||||
{GPIO_P20, GPIO_FLOATING },
|
||||
{GPIO_P34, GPIO_FLOATING },
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
for(uint8_t i=0; i<sizeof(ioInit)/sizeof(ioinit_cfg_t); i++)
|
||||
hal_gpio_pull_set(ioInit[i].pin,ioInit[i].type);
|
||||
for (uint8_t i = 0; i < sizeof(ioInit) / sizeof(ioinit_cfg_t); i++)
|
||||
hal_gpio_pull_set(ioInit[i].pin, ioInit[i].type);
|
||||
|
||||
DCDC_CONFIG_SETTING(0x0a);
|
||||
DCDC_REF_CLK_SETTING(1);
|
||||
DIG_LDO_CURRENT_SETTING(0x01);
|
||||
#if DEBUG_INFO || SDK_VER_RELEASE_ID != 0x03010102
|
||||
hal_pwrmgr_RAM_retention(RET_SRAM0|RET_SRAM1); // RET_SRAM0|RET_SRAM1|RET_SRAM2
|
||||
#else
|
||||
DCDC_CONFIG_SETTING(0x0a);
|
||||
DCDC_REF_CLK_SETTING(1);
|
||||
DIG_LDO_CURRENT_SETTING(0x01);
|
||||
if ((uint32_t) &_ebss >= 0x1fff8000)
|
||||
hal_pwrmgr_RAM_retention(RET_SRAM0 | RET_SRAM1); // RET_SRAM0|RET_SRAM1|RET_SRAM2
|
||||
else
|
||||
hal_pwrmgr_RAM_retention(RET_SRAM0); // RET_SRAM0|RET_SRAM1|RET_SRAM2
|
||||
#endif
|
||||
hal_pwrmgr_RAM_retention_set();
|
||||
hal_pwrmgr_LowCurrentLdo_enable();
|
||||
hal_pwrmgr_RAM_retention_set();
|
||||
hal_pwrmgr_LowCurrentLdo_enable();
|
||||
}
|
||||
|
||||
static void ble_mem_init_config(void)
|
||||
{
|
||||
static void ble_mem_init_config(void) {
|
||||
#if 0 // SDK_VER_RELEASE_ID >= 0x030103 ?
|
||||
//ll linkmem setup
|
||||
extern void ll_osalmem_init(osalMemHdr_t* hdr, uint32 size);
|
||||
ll_osalmem_init((osalMemHdr_t*)g_llLinkHeap, LL_LINK_HEAP_SIZE);
|
||||
#endif
|
||||
osal_mem_set_heap((osalMemHdr_t*)g_largeHeap, LARGE_HEAP_SIZE);
|
||||
LL_InitConnectContext(pConnContext,
|
||||
g_pConnectionBuffer,
|
||||
BLE_MAX_ALLOW_CONNECTION,
|
||||
BLE_MAX_ALLOW_PKT_PER_EVENT_TX,
|
||||
BLE_MAX_ALLOW_PKT_PER_EVENT_RX,
|
||||
BLE_PKT_VERSION);
|
||||
osal_mem_set_heap((osalMemHdr_t*) g_largeHeap, LARGE_HEAP_SIZE);
|
||||
LL_InitConnectContext(pConnContext, g_pConnectionBuffer,
|
||||
BLE_MAX_ALLOW_CONNECTION,
|
||||
BLE_MAX_ALLOW_PKT_PER_EVENT_TX,
|
||||
BLE_MAX_ALLOW_PKT_PER_EVENT_RX,
|
||||
BLE_PKT_VERSION);
|
||||
#if ( MAX_CONNECTION_SLAVE_NUM > 0 )
|
||||
static ALIGN4_U8 g_llDevList[BLE_CONN_LL_DEV_LIST_SIZE];
|
||||
ll_multi_conn_llDevList_Init(g_llDevList);
|
||||
#endif
|
||||
|
||||
|
||||
#if MAX_NUM_LL_CONN > 1
|
||||
Host_InitContext( MAX_NUM_LL_CONN,
|
||||
glinkDB,glinkCBs,
|
||||
|
|
@ -200,57 +191,61 @@ static void ble_mem_init_config(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void hal_rfphy_init(void)
|
||||
{
|
||||
//Watchdog_Init(NULL);
|
||||
//============config the txPower
|
||||
g_rfPhyTxPower = RF_PHY_TX_POWER_0DBM ;
|
||||
//============config BLE_PHY TYPE
|
||||
g_rfPhyPktFmt = PKT_FMT_BLE1M;
|
||||
//============config RF Frequency Offset
|
||||
g_rfPhyFreqOffSet =RF_PHY_FREQ_FOFF_00KHZ;
|
||||
//============config xtal 16M cap
|
||||
XTAL16M_CAP_SETTING(0x09);
|
||||
XTAL16M_CURRENT_SETTING(0x01);
|
||||
static void hal_rfphy_init(void) {
|
||||
//Watchdog_Init(NULL);
|
||||
//============config the txPower
|
||||
g_rfPhyTxPower = RF_PHY_TX_POWER_0DBM;
|
||||
//============config BLE_PHY TYPE
|
||||
g_rfPhyPktFmt = PKT_FMT_BLE1M;
|
||||
//============config RF Frequency Offset
|
||||
g_rfPhyFreqOffSet = RF_PHY_FREQ_FOFF_00KHZ;
|
||||
//============config xtal 16M cap
|
||||
XTAL16M_CAP_SETTING(0x09);
|
||||
XTAL16M_CURRENT_SETTING(0x01);
|
||||
|
||||
hal_rc32k_clk_tracking_init();
|
||||
|
||||
hal_rom_boot_init();
|
||||
NVIC_SetPriority((IRQn_Type)BB_IRQn, IRQ_PRIO_REALTIME);
|
||||
NVIC_SetPriority((IRQn_Type)TIM1_IRQn, IRQ_PRIO_HIGH); //ll_EVT
|
||||
NVIC_SetPriority((IRQn_Type)TIM2_IRQn, IRQ_PRIO_HIGH); //OSAL_TICK
|
||||
NVIC_SetPriority((IRQn_Type)TIM4_IRQn, IRQ_PRIO_HIGH); //LL_EXA_ADV
|
||||
//ble memory init and config
|
||||
ble_mem_init_config();
|
||||
hal_rc32k_clk_tracking_init();
|
||||
|
||||
hal_rom_boot_init();
|
||||
NVIC_SetPriority((IRQn_Type) BB_IRQn, IRQ_PRIO_REALTIME);
|
||||
NVIC_SetPriority((IRQn_Type) TIM1_IRQn, IRQ_PRIO_HIGH); //ll_EVT
|
||||
NVIC_SetPriority((IRQn_Type) TIM2_IRQn, IRQ_PRIO_HIGH); //OSAL_TICK
|
||||
NVIC_SetPriority((IRQn_Type) TIM4_IRQn, IRQ_PRIO_HIGH); //LL_EXA_ADV
|
||||
//ble memory init and config
|
||||
ble_mem_init_config();
|
||||
}
|
||||
|
||||
|
||||
static void hal_init(void)
|
||||
{
|
||||
hal_low_power_io_init();
|
||||
clk_init(g_system_clk); //system init
|
||||
hal_rtc_clock_config((CLK32K_e)g_clk32K_config);
|
||||
hal_pwrmgr_init();
|
||||
xflash_Ctx_t cfg =
|
||||
{
|
||||
static void hal_init(void) {
|
||||
hal_low_power_io_init();
|
||||
clk_init(g_system_clk); //system init
|
||||
hal_rtc_clock_config((CLK32K_e) g_clk32K_config);
|
||||
hal_pwrmgr_init();
|
||||
xflash_Ctx_t cfg = {
|
||||
#if SDK_VER_RELEASE_ID == 0x03010102
|
||||
.spif_ref_clk = SYS_CLK_RC_32M,
|
||||
.spif_ref_clk = SYS_CLK_DLL_64M, // SYS_CLK_RC_32M
|
||||
#endif
|
||||
.rd_instr = XFRD_FCMD_READ_DUAL // XFRD_FCMD_READ_QUAD // XFRD_FCMD_READ_DUAL
|
||||
};
|
||||
hal_spif_cache_init(cfg);
|
||||
hal_gpio_init();
|
||||
LOG_INIT();
|
||||
hal_fs_init(0x1103C000,2);
|
||||
hal_adc_init();
|
||||
.rd_instr = XFRD_FCMD_READ_DUAL // XFRD_FCMD_READ_QUAD // XFRD_FCMD_READ_DUAL
|
||||
};
|
||||
hal_spif_cache_init(cfg);
|
||||
hal_gpio_init();
|
||||
LOG_INIT();
|
||||
hal_fs_init(0x1103C000, 2);
|
||||
hal_adc_init();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
int main(void)
|
||||
{
|
||||
watchdog_config(WDG_2S);
|
||||
g_system_clk = SYS_CLK_XTAL_16M;//SYS_CLK_DBL_32M;//SYS_CLK_XTAL_16M;//SYS_CLK_DLL_64M;
|
||||
g_clk32K_config = CLK_32K_RCOSC;//CLK_32K_XTAL;//CLK_32K_XTAL,CLK_32K_RCOSC
|
||||
int main(void) {
|
||||
g_system_clk = SYS_CLK_XTAL_16M; //SYS_CLK_DBL_32M;//SYS_CLK_XTAL_16M;//SYS_CLK_DLL_64M;
|
||||
g_clk32K_config = CLK_32K_RCOSC; //CLK_32K_XTAL;//CLK_32K_XTAL,CLK_32K_RCOSC
|
||||
|
||||
#if 0 // defined ( __GNUC__ ) // -> *.ld
|
||||
extern const uint32_t *const jump_table_base[];
|
||||
osal_memcpy((void*) 0x1fff0000, (void*) jump_table_base, 1024);
|
||||
#endif
|
||||
|
||||
watchdog_config(WDG_2S);
|
||||
|
||||
// spif_config(SYS_CLK_DLL_64M, 1, XFRD_FCMD_READ_DUAL, 0, 0);
|
||||
|
||||
#if (FLASH_PROTECT_FEATURE == 1)
|
||||
#if SDK_VER_RELEASE_ID == 0x03010102
|
||||
hal_flash_lock();
|
||||
|
|
@ -258,50 +253,26 @@ int main(void)
|
|||
hal_flash_enable_lock(MAIN_INIT);
|
||||
#endif
|
||||
#endif
|
||||
#if defined ( __GNUC__ )
|
||||
extern const uint32_t* const jump_table_base[];
|
||||
osal_memcpy((void*)0x1fff0000, (void*)jump_table_base, 1024);
|
||||
#endif
|
||||
drv_irq_init();
|
||||
init_config();
|
||||
drv_irq_init();
|
||||
init_config();
|
||||
#if ( HOST_CONFIG & OBSERVER_CFG )
|
||||
extern void ll_patch_advscan(void);
|
||||
ll_patch_advscan();
|
||||
#else
|
||||
extern void ll_patch_slave(void);
|
||||
ll_patch_slave();
|
||||
extern void ll_patch_slave(void);
|
||||
ll_patch_slave();
|
||||
#endif
|
||||
hal_rfphy_init();
|
||||
hal_init();
|
||||
hal_rfphy_init();
|
||||
hal_init();
|
||||
|
||||
LOG("SDK Version ID %08x \n",SDK_VER_RELEASE_ID);
|
||||
LOG("rfClk %d rcClk %d sysClk %d tpCap[%02x %02x]\n",g_rfPhyClkSel,g_clk32K_config,g_system_clk,g_rfPhyTpCal0,g_rfPhyTpCal1);
|
||||
LOG("sizeof(struct ll_pkt_desc) = %d, buf size = %d\n", sizeof(struct ll_pkt_desc), BLE_CONN_BUF_SIZE);
|
||||
LOG("sizeof(g_pConnectionBuffer) = %d, sizeof(pConnContext) = %d, sizeof(largeHeap)=%d \n",\
|
||||
sizeof(g_pConnectionBuffer), sizeof(pConnContext),sizeof(g_largeHeap));
|
||||
LOG("[REST CAUSE] %d\n ",g_system_reset_cause);
|
||||
app_main();
|
||||
return 0;
|
||||
LOG("SDK Version ID %08x \n",SDK_VER_RELEASE_ID);
|
||||
LOG("rfClk %d rcClk %d sysClk %d tpCap[%02x %02x]\n",g_rfPhyClkSel,g_clk32K_config,g_system_clk,g_rfPhyTpCal0,g_rfPhyTpCal1);
|
||||
LOG("sizeof(struct ll_pkt_desc) = %d, buf size = %d\n", sizeof(struct ll_pkt_desc), BLE_CONN_BUF_SIZE);
|
||||
LOG("sizeof(g_pConnectionBuffer) = %d, sizeof(pConnContext) = %d, sizeof(largeHeap)=%d \n",
|
||||
sizeof(g_pConnectionBuffer), sizeof(pConnContext),sizeof(g_largeHeap)); LOG("[REST CAUSE] %d\n ",g_system_reset_cause);
|
||||
app_main();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////// end ///////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -217,6 +217,7 @@ static void adv_measure(void) {
|
|||
|
||||
static void posedge_int_wakeup_cb(GPIO_Pin_e pin,IO_Wakeup_Pol_e type)
|
||||
{
|
||||
(void) pin;
|
||||
if(type == POSEDGE)
|
||||
{
|
||||
adv_con_count = 30000/DEF_CON_ADV_INERVAL_MS; // 60 sec
|
||||
|
|
@ -233,6 +234,7 @@ static void posedge_int_wakeup_cb(GPIO_Pin_e pin,IO_Wakeup_Pol_e type)
|
|||
}
|
||||
static void negedge_int_wakeup_cb(GPIO_Pin_e pin,IO_Wakeup_Pol_e type)
|
||||
{
|
||||
(void) pin;
|
||||
if(type == NEGEDGE)
|
||||
{
|
||||
LOG("int or wakeup(neg):gpio:%d type:%d\n",pin,type);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue