Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relicensing requests for BES of partially open sourced files. #93

Open
Tracked by #76
OneDeuxTriSeiGo opened this issue Mar 19, 2024 · 7 comments
Open
Tracked by #76

Comments

@OneDeuxTriSeiGo
Copy link

Parent Issue: #76

The list below are files that have been released in the past by BES. These files are largely similar to those previous releases but include changes that have not been explicitly licensed publicly under an open source license.

Included are the license declared in the SDK, the license we would like the source file relicensed to, and a diff between the reconstruction and the SDK.

Unless indicated otherwise, all files below were previously made public by BES under the Apache-2.0 license.

@OneDeuxTriSeiGo
Copy link
Author

  • apps/common/app_thread.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/apps/common/app_thread.h bes/apps/common/app_thread.h
      index f06729d49b4..c019af10b7c 100644
      --- a/apps/common/app_thread.h
      +++ b/apps/common/app_thread.h
      @@ -19,7 +19,7 @@
       extern "C" {
       #endif
       
      -#define APP_MAILBOX_MAX (50)
      +#define APP_MAILBOX_MAX (20)
       
       enum APP_MODUAL_ID_T {
           APP_MODUAL_KEY = 0,
      @@ -45,7 +45,9 @@ enum APP_MODUAL_ID_T {
       #ifdef VOICE_DETECTOR_EN
           APP_MODUAL_VOICE_DETECTOR,
       #endif
      +    APP_MODUAL_CUSTOM_FUNCTION,
           APP_MODUAL_OHTER,
      +    APP_MODUAL_WNR,
       
           APP_MODUAL_NUM
       };
  • apps/common/app_utils.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/apps/common/app_utils.h bes/apps/common/app_utils.h
      index cffd1348d1b..531b86e83e0 100644
      --- a/apps/common/app_utils.h
      +++ b/apps/common/app_utils.h
      @@ -31,10 +31,13 @@ extern "C" {
       #define APP_SYSFREQ_USER_OTA                APP_SYSFREQ_USER_APP_7
       #define APP_SYSFREQ_USER_PROMPT_MIXER       APP_SYSFREQ_USER_APP_8
       #define APP_SYSFREQ_USER_APP_NT             APP_SYSFREQ_USER_APP_9
      -#define APP_SYSFREQ_USER_VOICE_ASSIST       APP_SYSFREQ_USER_APP_10
      -#define APP_SYSFREQ_USER_TRIGGER            APP_SYSFREQ_USER_APP_11
      -#define APP_SYSFREQ_USER_BIS                APP_SYSFREQ_USER_APP_12
      -#define APP_SYSFREQ_USER_TOTA               APP_SYSFREQ_USER_APP_13
      +#define APP_SYSFREQ_USER_ANC_WNR            APP_SYSFREQ_USER_APP_10
      +#ifdef __RAND_FROM_MIC__
      +#define APP_SYSFREQ_USER_RANDOM             APP_SYSFREQ_USER_APP_11
      +#endif
      +#ifdef __DUAL_MIC_RECORDING__
      +#define APP_SYSFREQ_USER_RECORDING          APP_SYSFREQ_USER_APP_12
      +#endif
       /*
        * Pseudo user, if one of user is belong to qos(quality of service) user,
        * when request cpu freq, it will changed to this user
      @@ -91,6 +94,12 @@ enum APP_WDT_THREAD_CHECK_USER_T {
       
       int app_sysfreq_req(enum APP_SYSFREQ_USER_T user, enum APP_SYSFREQ_FREQ_T freq);
       
      +int app_wdt_open(int seconds);
      +
      +int app_wdt_reopen(int seconds);
      +
      +int app_wdt_close(void);
      +
       #ifdef __cplusplus
       }
       #endif
  • apps/key/app_key.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/apps/key/app_key.h bes/apps/key/app_key.h
      index cf654bf04c1..693aded5c5c 100644
      --- a/apps/key/app_key.h
      +++ b/apps/key/app_key.h
      @@ -59,6 +59,11 @@ enum APP_KEY_EVENT_T {
           APP_KEY_EVENT_TRIPLECLICK        = HAL_KEY_EVENT_TRIPLECLICK,
           APP_KEY_EVENT_ULTRACLICK         = HAL_KEY_EVENT_ULTRACLICK,
           APP_KEY_EVENT_RAMPAGECLICK       = HAL_KEY_EVENT_RAMPAGECLICK,
      +    APP_KEY_EVENT_SIXTHCLICK         = HAL_KEY_EVENT_SIXTHCLICK,
      +    APP_KEY_EVENT_SEVENTHCLICK       = HAL_KEY_EVENT_SEVENTHCLICK,
      +    APP_KEY_EVENT_EIGHTHCLICK        = HAL_KEY_EVENT_EIGHTHCLICK,
      +    APP_KEY_EVENT_NINETHCLICK        = HAL_KEY_EVENT_NINETHCLICK,
      +    APP_KEY_EVENT_TENTHCLICK         = HAL_KEY_EVENT_TENTHCLICK,
           APP_KEY_EVENT_REPEAT             = HAL_KEY_EVENT_REPEAT,
           APP_KEY_EVENT_GROUPKEY_DOWN      = HAL_KEY_EVENT_GROUPKEY_DOWN,
           APP_KEY_EVENT_GROUPKEY_REPEAT    = HAL_KEY_EVENT_GROUPKEY_REPEAT,
      @@ -97,6 +102,7 @@ void app_key_handle_clear(void);
       
       void app_key_simulate_key_event(uint32_t key_code, uint8_t key_event);
       
      +#if defined(_AUTO_TEST_)
       int simul_key_event_process(uint32_t key_code, uint8_t key_event);
       #endif
       #endif//__FMDEC_H__
  • apps/main/apps.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/apps/main/apps.h bes/apps/main/apps.h
      index 43225346564..1755c06b75e 100644
      --- a/apps/main/apps.h
      +++ b/apps/main/apps.h
      @@ -26,7 +26,7 @@ extern "C" {
       
       #include "plat_types.h"
       
      -int app_init(int only_init);
      +int app_init(void);
       
       int app_deinit(int deinit_case);
       
      @@ -66,6 +66,23 @@ bool app_is_power_off_in_progress(void);
       void app_disconnect_all_bt_connections(void);
       bool app_is_stack_ready(void);
       
      +extern uint8_t latency_mode_is_open;
      +bool Curr_Is_Master(void);
      +bool Curr_Is_Slave(void);
      +extern uint8_t get_nv_role(void);
      +extern uint8_t get_curr_role(void);
      +extern uint8_t  app_poweroff_flag;
      +extern bool MobileLinkLose_reboot;
      +extern bool factory_mode_status;
      +extern uint8_t  app_poweroff_flag;
      +extern bool MobileLinkLose_reboot;
      +extern void startclr_info_timer(int ms);
      +extern void app_enterpairing_timer_start(void);
      +extern void app_enterpairing_timer_stop(void);
      +extern void startdelay_report_tone(int ms,APP_STATUS_INDICATION_T status);
      +extern void box_cmd_app_bt_enter_mono_pairing_mode(void);
      +extern int app_nvrecord_rebuild(void);
      +extern void app_bt_power_off_customize();
       ////////////////////
       
       
  • apps/main/app_status_ind.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/apps/main/app_status_ind.h bes/apps/main/app_status_ind.h
      index 4f9ac64d91b..4586fa3a39b 100644
      --- a/apps/main/app_status_ind.h
      +++ b/apps/main/app_status_ind.h
      @@ -56,6 +56,8 @@ typedef enum APP_STATUS_INDICATION_T {
           APP_STATUS_INDICATION_MUTE,
           APP_STATUS_INDICATION_TESTMODE,
           APP_STATUS_INDICATION_TESTMODE1,
      +    APP_STATUS_INDICATION_DU,
      +    APP_STATUS_INDICATION_DUDU,
           APP_STATUS_RING_WARNING,
       #ifdef __INTERACTION__
           APP_STATUS_INDICATION_FINDME,
  • Makefile

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/Makefile bes/Makefile
      index e6c10d60473..f9449e0345f 100644
      --- a/Makefile
      +++ b/Makefile
      @@ -284,7 +284,7 @@ endif # ifneq ($(KBUILD_OUTPUT),)
       endif # ifeq ($(KBUILD_SRC),)
       
       # We process the rest of the Makefile if this is the final invocation of make
      -ifneq ($(skip-makefile),1)
      +ifeq ($(skip-makefile),)
       
       # Do not print "Entering directory ...",
       # but we want to display it when entering to the output directory
      @@ -428,7 +428,7 @@ KBUILD_CFLAGS   += -g
       #C_ONLY_FLAGS   := -std=gnu89
       C_ONLY_FLAGS    := -std=gnu99
       
      -C++_ONLY_FLAGS  := -std=gnu++14 -fno-rtti
      +C++_ONLY_FLAGS  := -std=gnu++98 -fno-rtti
       
       KBUILD_AFLAGS   := -D__ASSEMBLY__
       
      @@ -472,7 +472,6 @@ else
       LDFLAGS_IMAGE   := -X --no-wchar-size-warning
       endif
       
      -include $(srctree)/scripts/include.mk
       # Include target definitions
       include $(srctree)/$(TARGET_CFG_FILE)
       include $(srctree)/$(TARGET_COMMON_FILE)
      @@ -549,6 +548,7 @@ REVISION_INFO := $(GIT_REVISION):$(CUST_TGT_INFO)
       endif
       endif
       
      +include $(srctree)/scripts/include.mk
       
       REVISION_INFO := $(subst $(space),-,$(strip $(REVISION_INFO)))
       SOFTWARE_VERSION := $(subst $(space),-,$(strip $(SOFTWARE_VERSION)))
      @@ -605,8 +605,8 @@ ifeq ($(LST_SECTION_OPTS),)
       IMAGE_LST := $(addsuffix .lst,$(basename $(IMAGE_FILE)))
       else
       IMAGE_LST := $(addsuffix $(LST_SECTION_NAME).lst,$(basename $(IMAGE_FILE)))
      +IMAGE_SEC := $(addsuffix $(LST_SECTION_NAME)$(suffix $(IMAGE_FILE)),$(basename $(IMAGE_FILE)))
       endif
      -append_lst_sec_name = $(addsuffix $(LST_SECTION_NAME)$(suffix $(1)),$(basename $(1)))
       
       LDS_TARGET := _$(notdir $(REAL_LDS_FILE))
       
      @@ -650,7 +650,7 @@ else
             cmd_gen-STR_BIN = $(OBJCOPY) -j .code_start_addr -j .rodata_str  -j .trc_str \
                 --change-section-lma .code_start_addr=0x00000000 \
                 --change-section-lma .rodata_str=0x00000010 \
      -          --change-section-lma .trc_str=0x00030000 \
      +          --change-section-lma .trc_str=0x00008000 \
                 -O binary $< $@
       endif
       quiet_cmd_gen-STR_BIN = GENBIN  $@
      @@ -687,7 +687,7 @@ else
       ifeq ($(LST_SECTION_OPTS),)
             cmd_gen-IMAGE_LST = $(OBJDUMP) -Sldx $< > $@
       else
      -      cmd_gen-IMAGE_LST = $(OBJCOPY) $(LST_SECTION_OPTS) $< $(call append_lst_sec_name,$<) && $(OBJDUMP) -Sldx $(call append_lst_sec_name,$<) > $@
      +      cmd_gen-IMAGE_LST = $(OBJCOPY) $(LST_SECTION_OPTS) $< $(IMAGE_SEC) && $(OBJDUMP) -Sldx $(IMAGE_SEC) > $@
       endif
       endif
       quiet_cmd_gen-IMAGE_LST = GENLST  $@
      @@ -724,7 +724,8 @@ KBUILD_CFLAGS   += $(call cc-option,-Wlogical-op)
       #KBUILD_CFLAGS   += -Wno-address-of-packed-member
       
       KBUILD_CFLAGS   += -Wno-trigraphs \
      -                   -fno-strict-aliasing
      +                   -fno-strict-aliasing \
      +                   -Wno-format-security
       
       #KBUILD_CFLAGS  += Wundef
       
      @@ -788,7 +789,7 @@ endif
       ifneq ($(SOFTWARE_VERSION),)
       BUILD_INFO_FLAGS += -DSOFTWARE_VERSION=$(SOFTWARE_VERSION)
       endif
      -ifneq ($(OTA_BOOT_SIZE),)
      +ifneq ($(OTA_BOOT_SIZE),0)
       BUILD_INFO_FLAGS += -DOTA_BOOT_SIZE=$(OTA_BOOT_SIZE)
       endif
       ifneq ($(OTA_CODE_OFFSET),)
      @@ -996,7 +997,7 @@ endif
       
       HELP_TARGET := 2
       
      -endif # ifneq ($(skip-makefile),1)
      +endif # ifeq ($(skip-makefile),)
       endif # ifneq ($(HELP_TARGET),1)
       
       # Help target
  • platform/cmsis/inc/link_sym_armclang.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/cmsis/inc/link_sym_armclang.h bes/platform/cmsis/inc/link_sym_armclang.h
      index 6329d0236b5..5a35d8eb65a 100644
      --- a/platform/cmsis/inc/link_sym_armclang.h
      +++ b/platform/cmsis/inc/link_sym_armclang.h
      @@ -23,7 +23,7 @@ extern "C" {
       
       #include "plat_addr_map.h"
       
      -#if defined(ROM_BUILD) && !defined(ROM_IN_FLASH)
      +#ifdef ROM_BUILD
       
       #define __rom_got_info_start                Image$$rom_got_info$$Base
       #define __audio_const_rom_start             Image$$rom_audio_const$$Base
      @@ -217,6 +217,8 @@ extern "C" {
       #define __aud_end                           Image$$audio$$ZI$$Limit
       #define __reserved_start                    Image$$reserved$$Base
       #define __reserved_end                      Image$$reserved$$ZI$$Limit
      +#define __hotword_model_start               Image$$hotword_model$$Base
      +#define __hotword_model_end                 Image$$hotword_model$$ZI$$Limit
       #define __factory_start                     Image$$factory$$Base
       #define __factory_end                       Image$$factory$$ZI$$Limit
       
  • platform/cmsis/inc/mpu.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/cmsis/inc/mpu.h bes/platform/cmsis/inc/mpu.h
      index 1ce082a4a32..d1938728614 100644
      --- a/platform/cmsis/inc/mpu.h
      +++ b/platform/cmsis/inc/mpu.h
      @@ -38,6 +38,8 @@ enum MPU_ID_T {
       #define MPU_ID_USER_DATA_SECTION    MPU_ID_1
       #define MPU_ID_FRAM_TEXT1           MPU_ID_2
       #define MPU_ID_FRAM_TEXT2           MPU_ID_3
      +#define MPU_ID_CODE                 MPU_ID_4
      +#define MPU_ID_SRAM_TEXT            MPU_ID_5
       
       /*cp sections */
       #define MPU_ID_CP_FLASHX            MPU_ID_2
      @@ -60,9 +62,9 @@ enum MPU_ATTR_T {
       enum MAIR_ATTR_TYPE_T {
           MAIR_ATTR_FLASH,
           MAIR_ATTR_INT_SRAM,
      -    MAIR_ATTR_EXT_RAM,
      +    MAIR_ATTR_EXT_SRAM,
           MAIR_ATTR_DEVICE,
      -    MAIR_ATTR_NC_MEM,
      +    MAIR_ATTR_4,
           MAIR_ATTR_5,
           MAIR_ATTR_6,
           MAIR_ATTR_7,
  • platform/drivers/ana/analog.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/drivers/ana/analog.h bes/platform/drivers/ana/analog.h
      index 29f5ec5309f..a115469189b 100644
      --- a/platform/drivers/ana/analog.h
      +++ b/platform/drivers/ana/analog.h
      @@ -26,9 +26,10 @@ extern "C" {
       #include "plat_addr_map.h"
       #include CHIP_SPECIFIC_HDR(analog)
       
      -#define ANALOG_DEBUG_TRACE(n, s, ...)       TR_DUMMY(n, s, ##__VA_ARGS__)
      -#define ANALOG_INFO_TRACE_IMM(n, s, ...)    TR_INFO((n) | TR_ATTR_IMM, s, ##__VA_ARGS__)
      -#define ANALOG_INFO_TRACE(n, s, ...)        TR_INFO(n, s, ##__VA_ARGS__)
      +#define ANALOG_DEBUG_TRACE(n, s, ...)
      +//TRACE(n, s, ##__VA_ARGS__)
      +#define ANALOG_DEBUG_TRACE_IMM(n, s, ...)  TRACE_IMM(n, s, ##__VA_ARGS__)
      +#define ANALOG_INFO_TRACE(n, s, ...)       TRACE(n, s, ##__VA_ARGS__)
       
       #ifndef ISPI_ANA_REG
       #define ISPI_ANA_REG(reg)               (reg)
  • platform/drivers/ana/pmu.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/drivers/ana/pmu.h bes/platform/drivers/ana/pmu.h
      index 1f2b9069fcc..10998410065 100644
      --- a/platform/drivers/ana/pmu.h
      +++ b/platform/drivers/ana/pmu.h
      @@ -26,9 +26,10 @@ extern "C" {
       #include "plat_addr_map.h"
       #include CHIP_SPECIFIC_HDR(pmu)
       
      -#define PMU_DEBUG_TRACE(n, s, ...)          TR_DUMMY(n, s, ##__VA_ARGS__)
      -#define PMU_INFO_TRACE_IMM(n, s, ...)       TR_INFO((n) | TR_ATTR_IMM, s, ##__VA_ARGS__)
      -#define PMU_INFO_TRACE(n, s, ...)           TR_INFO(n, s, ##__VA_ARGS__)
      +#define PMU_DEBUG_TRACE(n, s, ...)          LOG_DUMMY(n, s, ##__VA_ARGS__)
      +#define PMU_DEBUG_TRACE_IMM(n, s, ...)      LOG_INFO((n) | LOG_ATTR_IMM, s, ##__VA_ARGS__)
      +#define PMU_INFO_TRACE_IMM(n, s, ...)       LOG_INFO((n) | LOG_ATTR_IMM, s, ##__VA_ARGS__)
      +#define PMU_INFO_TRACE(n, s, ...)           LOG_INFO(n, s, ##__VA_ARGS__)
       
       #ifndef ISPI_PMU_REG
       #define ISPI_PMU_REG(reg)                   (reg)
      @@ -133,7 +134,7 @@ int pmu_get_security_value(union SECURITY_VALUE_T *val);
       
       void pmu_shutdown(void);
       
      -void pmu_reboot(void);
      +void pmu_reset(void);
       
       int pmu_get_efuse(enum PMU_EFUSE_PAGE_T page, unsigned short *efuse);
       
  • platform/drivers/bt/bt_drv.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/drivers/bt/bt_drv.h bes/platform/drivers/bt/bt_drv.h
      index 9dd5c4d3bfd..1bf25d6d559 100644
      --- a/platform/drivers/bt/bt_drv.h
      +++ b/platform/drivers/bt/bt_drv.h
      @@ -29,7 +29,7 @@ extern "C" {
       #include "hal_trace.h"
       
       #define BT_DRV_REG_OP_ENTER()    do{ uint32_t stime, spent_time; stime= hal_sys_timer_get();
      -#define BT_DRV_REG_OP_EXIT()     spent_time = TICKS_TO_US(hal_sys_timer_get()-stime);if (spent_time>500)TRACE(2,"%s exit, %dus",__func__, spent_time);}while(0);
      +#define BT_DRV_REG_OP_EXIT()     spent_time = TICKS_TO_US(hal_sys_timer_get()-stime);if (spent_time>300)TRACE(2,"%s exit, %dus",__func__, spent_time);}while(0);
       
       #define SBC_PKT_TYPE_DM1   0x3
       #define SBC_PKT_TYPE_2EV3  0x6
      @@ -48,12 +48,13 @@ extern "C" {
       
       #define btdrv_delay(ms)                         hal_sys_timer_delay(MS_TO_TICKS(ms))
       
      -#define BTDIGITAL_REG(a)                        (*(volatile uint32_t *)(a))
      -#define BTDIGITAL_REG_WR(addr, value)           (*(volatile uint32_t *)(addr)) = (value)
       
      -#define BTDIGITAL_BT_EM(a)                      (*(volatile uint16_t *)(a))
      +#define BTDIGITAL_REG(a)                        (*(volatile uint32_t *)(uintptr_t)(a))
      +#define BTDIGITAL_REG_WR(addr, value)           (*(volatile uint32_t *)(uintptr_t)(addr)) = (value)
      +
      +#define BTDIGITAL_BT_EM(a)                      (*(volatile uint16_t *)(uintptr_t)(a))
       /// Macro to write a BT control structure field (16-bit wide)
      -#define BTDIGITAL_EM_BT_WR(addr, value)         (*(volatile uint16_t *)(addr)) = (value)
      +#define BTDIGITAL_EM_BT_WR(addr, value)         (*(volatile uint16_t *)(uintptr_t)(addr)) = (value)
       
       #define BTDIGITAL_REG_SET_FIELD(reg, mask, shift, v)\
                                                       do{ \
      @@ -74,9 +75,8 @@ extern "C" {
       #define BT_DRV_TRACE(n, fmt, ...) TRACE(n, fmt, ##__VA_ARGS__)
       #define BT_DRV_DUMP(s,buff,len) DUMP8(s,buff,len)
       #else
      -#define BT_DRV_TRACE(n, fmt, ...) hal_trace_dummy(NULL, ##__VA_ARGS__)
      -#define BT_DRV_DUMP(s,buff,len)
      -#define BT_DRV_TRACE_CRASH_DUMP(n, fmt, ...) hal_trace_dummy(NULL, ##__VA_ARGS__)
      +#define BT_DRV_TRACE(n, fmt, ...) hal_trace_dummy(fmt, ##__VA_ARGS__)
      +#define BT_DRV_DUMP(s,buff,len)   hal_dump_dummy(s, buff, len)
       #endif
       
       #define HCI_HOST_NB_CMP_PKTS_CMD_OPCODE         0x0C35
      @@ -136,7 +136,7 @@ extern "C" {
       #define BT_ERRORTYPESTAT_ADDR   (0xd0220060)
       #define MAX_NB_ACTIVE_ACL                   (3)
       
      -#if defined(CHIP_BEST2300A)
      +#ifdef CHIP_BEST2300A
       #define DEFAULT_XTAL_FCAP                       0x80ad      //8pf crstal No cap by luobin
       #else
       #define DEFAULT_XTAL_FCAP                       0x8080
      @@ -145,10 +145,10 @@ extern "C" {
       #elif defined(__FPGA_BT_1500__)
       #define BT_EM_ADDR_BASE (0xD0215000)
       #define BT_EM_SIZE (104)
      -#define EM_BLE_CS_OFFSET    (0x178)
      +#define BLE_EM_CS_SIZE      (112)
       #define EM_BT_PWRCNTL_ADDR (BT_EM_ADDR_BASE + 0x14)
       #define EM_BT_BT_EXT1_ADDR (BT_EM_ADDR_BASE + 0x60)
      -//#define EM_BT_BITOFF_ADDR  //1501 don't have bitoff reg
      +#define EM_BT_BITOFF_ADDR   //(BT_EM_ADDR_BASE + 0x02)
       #define EM_BT_CLKOFF0_ADDR   (BT_EM_ADDR_BASE + 0x02)
       #define EM_BT_CLKOFF1_ADDR   (BT_EM_ADDR_BASE + 0x04)
       #define EM_BT_WINCNTL_ADDR   (BT_EM_ADDR_BASE + 0x18)
      @@ -159,14 +159,14 @@ extern "C" {
       #define EM_BT_LINKCNTL_ADDR    (BT_EM_ADDR_BASE + 0x6)
       #define EM_BT_RXDESCCNT_ADDR    (BT_EM_ADDR_BASE + 0x5A)
       
      -#define EM_BT_AUDIOBUF_OFF    0xd0218a70
      -#define EM_BT_RXACLBUFPTR_ADDR  0xD0215482
      -#define REG_EM_BT_RXDESC_SIZE 20
      +#define EM_BT_AUDIOBUF_OFF    0xd02144fc
      +#define EM_BT_RXACLBUFPTR_ADDR  0xd02115f8
      +#define REG_EM_BT_RXDESC_SIZE 16
       
       #define LBRT_TX_PWR_FIX     (3)
      -#define BT_CONTROLLER_CRASH_DUMP_ADDR_BASE  (0xc0004050)
      +#define BT_CONTROLLER_CRASH_DUMP_ADDR_BASE  (0xc0000050)
       #define BT_ERRORTYPESTAT_ADDR   (0xd0220460)
      -#define DEFAULT_XTAL_FCAP                       0x1300
      +#define DEFAULT_XTAL_FCAP                       0x8080
       #define MAX_NB_ACTIVE_ACL                   (4)
       #else
       #define BT_EM_ADDR_BASE (0xd0210190)
      @@ -174,11 +174,15 @@ extern "C" {
       #define BT_CONTROLLER_CRASH_DUMP_ADDR_BASE  (0xc00064cc)
       #endif
       
      +#ifndef __FPGA_BT_1500__
      +//#define FPGA_1303
      +#endif
       
       //bt max slot clock
       #define MAX_SLOT_CLOCK      ((1L<<27) - 1)
        // A slot is 625 us
       #define SLOT_SIZE           625
      +#define XTAL_OFFSET           50
       
       
       //#define __PASS_CI_TEST_SETTING__
  • platform/drivers/bt/bt_drv_interface.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/drivers/bt/bt_drv_interface.h bes/platform/drivers/bt/bt_drv_interface.h
      index 5e70dbcce36..9742a76b0e3 100644
      --- a/platform/drivers/bt/bt_drv_interface.h
      +++ b/platform/drivers/bt/bt_drv_interface.h
      @@ -209,13 +209,13 @@ void btdrv_set_bt_pcm_en(uint8_t  en);
       
       uint16_t btdrv_rf_bitoffset_get(uint8_t conidx);
       
      -void  btdrv_syn_clr_trigger(uint8_t trig_route);
      +void  btdrv_syn_clr_trigger(void);
       
       uint32_t btdrv_rf_bit_offset_get(void);
       uint32_t btdrv_syn_get_curr_ticks(void);
       uint32_t bt_syn_get_curr_ticks(uint16_t conhdl);
       int32_t bt_syn_get_offset_ticks(uint16_t conhdl);
      -void bt_syn_set_tg_ticks(uint32_t val,uint16_t conhdl, uint8_t mode, uint8_t trig_route);
      +void bt_syn_set_tg_ticks(uint32_t val,uint16_t conhdl, uint8_t mode);
       void bt_syn_trig_checker(uint16_t conhdl);
       void btdrv_syn_trigger_codec_en(uint32_t v);
       uint32_t btdrv_get_syn_trigger_codec_en(void);
      @@ -228,6 +228,7 @@ void btdrv_disable_playback_triggler(void);
       void btdrv_set_bt_pcm_triggler_en(uint8_t  en);
       void btdrv_set_bt_pcm_triggler_delay(uint8_t  delay);
       void btdrv_set_bt_pcm_triggler_delay_reset(uint8_t  delay);
      +void btdrv_set_pcm_data_ignore_crc(void);
       
       
       uint8_t btdrv_conhdl_to_linkid(uint16_t connect_hdl);
      @@ -246,6 +247,7 @@ void btdrv_enable_one_packet_more_head(bool enable);
       
       #if defined(CHIP_BEST2300) || defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || \
           defined(CHIP_BEST2300P) || defined(CHIP_BEST2001) || defined(CHIP_BEST2300A)
      +void btdrv_linear_format_16bit_set(void);
       void btdrv_pcm_enable(void);
       void btdrv_pcm_disable(void);
       void btdrv_spi_trig_data_change(uint8_t spi_sel, uint8_t index, uint32_t value);
      @@ -288,7 +290,7 @@ void btdrv_open_pcm_fast_mode_disable(void);
       #endif
       
       #if defined(CVSD_BYPASS)
      -void btdrv_cvsd_bypass_enable(void);
      +void btdrv_cvsd_bypass_enable(uint8_t is_msbc);
       #endif
       void bt_drv_reg_op_write_private_public_key(uint8_t* private_key,uint8_t* public_key);
       
      @@ -298,6 +300,7 @@ void bt_drv_reg_op_write_private_public_key(uint8_t* private_key,uint8_t* public
       
       #define IS_ENABLE_BT_DRIVER_REG_DEBUG_READING   0
       
      +void bt_drv_reg_op_acl_tx_silence(uint16_t connHandle, uint8_t on);
       
       int btdrv_slave2master_clkcnt_convert(uint32_t local_clk, uint16_t local_cnt,
                                                      int32_t clk_offset, uint16_t bit_offset,
      @@ -321,6 +324,7 @@ void bt_drv_reg_op_get_ibrt_address(uint8_t *addr);
       void btdrv_enable_rf_sw(int rx_on, int tx_on);
       void btdrv_trigger_coredump(void);
       bool btdrv_is_ecc_enable(void);
      +void bt_drv_adaptive_fa_rx_gain(int8_t rssi);
       void* bt_drv_get_btstack_chip_config(void);
       void btdrv_spi_sel_ble_setf(int elt_idx, uint8_t spiselble);
       bool bt_drv_is_esco_auto_accept_support(void);
      @@ -333,15 +337,15 @@ void btdrv_softbit_enable(uint16_t connhdl, uint8_t type1,uint8_t type2,uint8_t
       
       void btdrv_play_trig_mode_set(uint8_t mode);
       #ifdef __SW_TRIG__
      -void btdrv_sw_trig_master_set(uint32_t Tclk_M, int16_t Tbit_M_h_ori, uint8_t trig_route);
      -void btdrv_sw_trig_slave_calculate_and_set(uint16_t conhdl, uint32_t Tclk_M, int16_t Tbit_M_h_ori, uint8_t trig_route);
      +void btdrv_sw_trig_master_set(uint32_t Tclk_M, int16_t Tbit_M_h_ori);
      +void btdrv_sw_trig_slave_calculate_and_set(uint16_t conhdl, uint32_t Tclk_M, int16_t Tbit_M_h_ori);
       void btdrv_sync_sw_trig_store_tws_role(uint8_t role);
       uint8_t btdrv_sync_sw_trig_get_tws_role(void);
       void btdrv_sync_sw_trig_store_conhdl(uint16_t conhdl);
       uint16_t btdrv_sync_sw_trig_get_conhdl(void);
       void btdrv_sync_sw_trig_store_tws_conhdl(uint16_t conhdl);
       uint16_t btdrv_sync_sw_trig_get_tws_conhdl(void);
      -uint16_t btdrv_sw_trig_tg_finecnt_get(uint8_t trig_route);
      +uint16_t btdrv_sw_trig_tg_finecnt_get(void);
       int32_t bt_syn_get_clkoffset(uint16_t conhdl);
       void btdrv_sync_sw_trig_store_tg_clkoffset(int32_t clkoffset);
       int32_t btdrv_sync_sw_trig_get_tg_clkoffset(void);
  • platform/drivers/bt/bt_drv_internal.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/drivers/bt/bt_drv_internal.h bes/platform/drivers/bt/bt_drv_internal.h
      index d48d7ef8a82..78045438d2b 100644
      --- a/platform/drivers/bt/bt_drv_internal.h
      +++ b/platform/drivers/bt/bt_drv_internal.h
      @@ -48,6 +48,7 @@ typedef uint32_t BT_CONTROLER_TRACE_TYPE;
       #define BT_FA_INVERT_EN   1
       #define BT_FA_INVERT_DISABLE   0
       
      +void bt_drv_set_fa_invert_enable(uint8_t en);
       uint8_t btdrv_rf_init(void);
       void btdrv_test_mode_rf_txpwr_init(void);
       void btdrv_ins_patch_init(void);
  • platform/drivers/bt/bt_drv_reg_op.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/drivers/bt/bt_drv_reg_op.h bes/platform/drivers/bt/bt_drv_reg_op.h
      index d655a6b03a6..7e546390070 100644
      --- a/platform/drivers/bt/bt_drv_reg_op.h
      +++ b/platform/drivers/bt/bt_drv_reg_op.h
      @@ -136,12 +136,28 @@ struct dbg_set_ebq_test
       };
       
       
      +void bt_drv_reg_op_rssi_set(uint16_t rssi);
      +void bt_drv_reg_op_scan_intv_set(uint32_t scan_intv);
      +void bt_drv_reg_op_encryptchange_errcode_reset(uint16_t hci_handle);
      +void bt_drv_reg_op_sco_sniffer_checker(void);
      +void bt_drv_reg_op_trigger_time_checker(void);
      +void bt_drv_reg_op_tws_output_power_fix_separate(uint16_t hci_handle, uint16_t pwr);
      +bool bt_drv_reg_op_ld_sniffer_env_monitored_dev_state_get(void);
      +void bt_drv_reg_op_ld_sniffer_env_monitored_dev_state_set(bool state);
      +void bt_drv_reg_op_ld_sniffer_master_addr_set(uint8_t * addr);
       int bt_drv_reg_op_currentfreeaclbuf_get(void);
       void bt_drv_reg_op_save_mobile_airpath_info(uint16_t hciHandle);
       void bt_drv_reg_op_block_xfer_with_mobile(uint16_t hciHandle);
       void bt_drv_reg_op_resume_xfer_with_mobile(uint16_t hciHandle);
       void bt_drv_reg_op_block_fast_ack_with_mobile(void);
       void bt_drv_reg_op_resume_fast_ack_with_mobile(void);
      +int bt_drv_reg_op_packet_type_checker(uint16_t hciHandle);
      +void bt_drv_reg_op_max_slot_setting_checker(uint16_t hciHandle);
      +void bt_drv_reg_op_force_task_dbg_idle(void);
      +void bt_drv_reg_op_afh_follow_mobile_mobileidx_set(uint16_t hciHandle);
      +void bt_drv_reg_op_afh_follow_mobile_twsidx_set(uint16_t hciHandle);
      +void bt_drv_reg_op_sco_status_store(void);
      +void bt_drv_reg_op_sco_status_restore(void);
       bool bt_drv_reg_op_sco_tx_buf_restore(uint8_t *trigger_test);
       void bt_drv_reg_op_afh_bak_reset(void);
       void bt_drv_reg_op_afh_bak_save(uint8_t role, uint16_t mobileHciHandle);
      @@ -149,6 +165,7 @@ void bt_drv_reg_op_connection_checker(void);
       void bt_drv_reg_op_bt_info_checker(void);
       uint8_t bt_drv_reg_op_get_controller_tx_free_buffer(void);
       uint8_t bt_drv_reg_op_get_controller_ble_tx_free_buffer(void);
      +void bt_drv_reg_op_ble_buffer_cleanup(void);
       bool bt_drv_reg_op_get_dbg_state(void);
       void bt_drv_reg_op_crash_dump(void);
       void bt_drv_reg_op_set_tx_pwr(uint16_t connHandle, uint8_t txpwr);
      @@ -159,12 +176,24 @@ uint16_t bt_drv_reg_op_get_lsto(uint16_t hciHandle);
       void bt_drv_reg_op_enable_emsack_mode(uint16_t connHandle, uint8_t master, uint8_t enable);
       void bt_drv_reg_op_set_accessible_mode(uint8_t mode);
       void bt_drv_reg_op_force_sco_retrans(bool enable);
      +void bt_drv_reg_op_enable_pcm_tx_hw_cal(void);
       void bt_drv_reg_op_monitor_clk(void);
       bool bt_drv_reg_op_read_rssi_in_dbm(uint16_t connHandle,rx_agc_t* rx_val);
       bool bt_drv_reg_op_read_ble_rssi_in_dbm(uint16_t connHandle,rx_agc_t* rx_val);
       void bt_drv_reg_op_set_swagc_mode(uint8_t mode);
      +void bt_drv_reg_op_set_reboot_pairing_mode(uint8_t mode);
       
       void bt_drv_reg_op_acl_silence(uint16_t connHandle, uint8_t silence);
      +void bt_drv_reg_op_call_monitor(uint16_t connHandle, uint8_t tws_role);
      +void bt_drv_reg_op_lock_sniffer_sco_resync(void);
      +void bt_drv_reg_op_unlock_sniffer_sco_resync(void);
      +void bt_drv_reg_op_afh_set_default(void);
      +void bt_drv_reg_op_update_sniffer_bitoffset(uint16_t mobile_conhdl,uint16_t master_conhdl);
      +void bt_drv_reg_op_modify_bitoff_timer(uint16_t time_out);
      +uint16_t em_bt_bitoff_getf(int elt_idx);
      +void bt_drv_reg_op_ble_llm_substate_hacker(void);
      +void bt_drv_reg_op_esco_acl_sniff_delay_cal(uint16_t hciHandle,bool enable);
      +bool  bt_drv_reg_op_check_esco_acl_sniff_conflict(uint16_t hciHandle);
       void bt_drv_reg_op_set_tpoll(uint8_t linkid,uint16_t poll_interval);
       uint8_t  bt_drv_reg_op_get_role(uint8_t linkid);
       int8_t  bt_drv_reg_op_rssi_correction(int8_t rssi);
      @@ -182,6 +211,7 @@ void bt_drv_reg_op_acl_tx_type_trace(uint16_t hciHandle);
       uint8_t bt_drv_reg_op_acl_tx_type_get(uint16_t hciHandle, uint8_t* br_type, uint8_t* edr_type);
       void bt_drv_reg_op_lm_nb_sync_hacker(uint8_t sco_status);
       
      +void bt_drv_reg_op_afh_env_reset(void);
       void bt_drv_reg_op_acl_tx_silence(uint16_t connHandle, uint8_t on);
       void bt_drv_reg_op_acl_tx_silence_clear(uint16_t connHandle);
       
      @@ -284,14 +314,18 @@ void bt_drv_reg_op_set_ibrt_reject_sniff_req(bool en);
       uint8_t bt_drv_reg_op_get_esco_nego_airmode(uint8_t sco_link_id);
       void bt_drv_reg_op_hci_vender_ibrt_ll_monitor(uint8_t* ptr, uint16_t* p_sum_err,uint16_t* p_rx_total);
       uint32_t bt_drv_reg_op_get_host_ref_clk(void);
      +void bt_drv_reg_op_set_accept_new_mobile_enable(void);
      +void bt_drv_reg_op_clear_accept_new_mobile_enable(void);
       void bt_drv_reg_op_ecc_softbit_process(uint16_t* p_conn_handle1,uint16_t* p_conn_handle2, uint16_t length, uint8_t *data);
       void bt_drv_reg_op_ebq_test_setting(void);
       void bt_drv_reg_op_hw_spi_en_setf(int elt_idx, uint8_t hwspien);
       void bt_drv_enhance_fa_mode(bool enable);
       void bt_drv_reg_op_set_rand_seed(uint32_t seed);
       void bt_drv_reg_op_swagc_mode_set(uint8_t mode);
      +void bt_drv_reg_op_set_max_pwr_rcv(uint16_t connHandle);
       void bt_drv_reg_op_key_gen_after_reset(bool enable);
       uint8_t bt_drv_reg_op_bt_sync_swagc_en_get(void);
      +void bt_drv_reg_op_ble_sup_timeout_set(uint16_t ble_conhdl, uint16_t sup_to);
       
       #ifdef __cplusplus
       }
  • platform/drivers/codec/best2300p/codec_best2300p.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/drivers/codec/best2300p/codec_best2300p.h bes/platform/drivers/codec/best2300p/codec_best2300p.h
      index 24a21203202..a857751f9af 100644
      --- a/platform/drivers/codec/best2300p/codec_best2300p.h
      +++ b/platform/drivers/codec/best2300p/codec_best2300p.h
      @@ -19,7 +19,9 @@
       extern "C" {
       #endif
       
      +typedef void (*CODEC_ANC_BOOST_DELAY_FUNC)(uint32_t ms);
       
      +void codec_set_anc_boost_delay_func(CODEC_ANC_BOOST_DELAY_FUNC delay_func);
       
       #ifdef __cplusplus
       }
  • platform/drivers/norflash/norflash_drv.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/drivers/norflash/norflash_drv.h bes/platform/drivers/norflash/norflash_drv.h
      index df761036291..3883998c6c4 100644
      --- a/platform/drivers/norflash/norflash_drv.h
      +++ b/platform/drivers/norflash/norflash_drv.h
      @@ -25,7 +25,9 @@ extern "C" {
       #define NORFLASH_ID_LEN                     3
       
       enum DRV_NORFLASH_ERASE_T {
      +#ifdef PUYA_FLASH_ERASE_PAGE_ENABLE
           DRV_NORFLASH_ERASE_PAGE,
      +#endif
           DRV_NORFLASH_ERASE_SECTOR,
           DRV_NORFLASH_ERASE_BLOCK,
           DRV_NORFLASH_ERASE_CHIP,
      @@ -70,114 +72,114 @@ union DRV_NORFLASH_SEC_REG_CFG_T {
               uint16_t enabled    :1;
               uint16_t base       :2;
               uint16_t size       :2;
      -        uint16_t offset     :1;
      +        uint16_t offset     :2;
               uint16_t cnt        :2;
               uint16_t pp         :2;
               uint16_t lb         :2;
      -        uint16_t reserved   :4;
      +        uint16_t reserved   :3;
           } s;
           uint16_t v;
       };
       
      -typedef int (*NORFLASH_WRITE_STATUS_CB)(enum HAL_FLASH_ID_T id, enum DRV_NORFLASH_W_STATUS_T type, uint32_t param);
      +typedef int (*NORFLASH_WRITE_STATUS_CB)(enum DRV_NORFLASH_W_STATUS_T type, uint32_t param);
       
       struct NORFLASH_CFG_T {
      -    uint8_t id[NORFLASH_ID_LEN];
      -    union DRV_NORFLASH_SPEED_RATIO_T speed_ratio;
      -    uint8_t crm_en_bits;
      -    uint8_t crm_dis_bits;
      -    uint16_t block_protect_mask;
      -    union DRV_NORFLASH_SEC_REG_CFG_T sec_reg_cfg;
      -    uint16_t page_size;
      -    uint16_t sector_size;
      -    uint32_t block_size;
      -    uint32_t total_size;
      -    uint32_t max_speed;
      -    uint32_t mode;
      -    NORFLASH_WRITE_STATUS_CB write_status;
      +    const uint8_t id[NORFLASH_ID_LEN];
      +    const union DRV_NORFLASH_SPEED_RATIO_T speed_ratio;
      +    const uint8_t crm_en_bits;
      +    const uint8_t crm_dis_bits;
      +    const uint16_t block_protect_mask;
      +    const union DRV_NORFLASH_SEC_REG_CFG_T sec_reg_cfg;
      +    const uint16_t page_size;
      +    const uint16_t sector_size;
      +    const uint32_t block_size;
      +    const uint32_t total_size;
      +    const uint32_t max_speed;
      +    const uint32_t mode;
      +    const NORFLASH_WRITE_STATUS_CB write_status;
       };
       
      -uint8_t norflash_read_status_s0_s7(enum HAL_FLASH_ID_T id);
      +uint8_t norflash_read_status_s0_s7(void);
       
      -uint8_t norflash_read_status_s8_s15(enum HAL_FLASH_ID_T id);
      +uint8_t norflash_read_status_s8_s15(void);
       
      -void norflash_status_WEL_0_wait(enum HAL_FLASH_ID_T id);
      +void norflash_status_WEL_0_wait(void);
       
      -enum HAL_NORFLASH_RET_T norflash_status_WIP_1_wait(enum HAL_FLASH_ID_T id, int suspend);
      +enum HAL_NORFLASH_RET_T norflash_status_WIP_1_wait(int suspend);
       
      -uint32_t norflash_get_supported_mode(enum HAL_FLASH_ID_T id);
      +uint32_t norflash_get_supported_mode(void);
       
      -uint32_t norflash_get_current_mode(enum HAL_FLASH_ID_T id);
      +uint32_t norflash_get_current_mode(void);
       
      -union DRV_NORFLASH_SEC_REG_CFG_T norflash_get_security_register_config(enum HAL_FLASH_ID_T id);
      +union DRV_NORFLASH_SEC_REG_CFG_T norflash_get_security_register_config(void);
       
      -uint32_t norflash_get_block_protect_mask(enum HAL_FLASH_ID_T id);
      +uint32_t norflash_get_block_protect_mask(void);
       
      -void norflash_reset(enum HAL_FLASH_ID_T id);
      +void norflash_reset(void);
       
      -int norflash_get_size(enum HAL_FLASH_ID_T id, uint32_t *total_size, uint32_t *block_size, uint32_t *sector_size, uint32_t *page_size);
      +int norflash_get_size(uint32_t *total_size, uint32_t *block_size, uint32_t *sector_size, uint32_t *page_size);
       
      -int norflash_set_mode(enum HAL_FLASH_ID_T id, uint32_t op);
      +int norflash_set_mode(uint32_t op);
       
      -int norflash_pre_operation(enum HAL_FLASH_ID_T id);
      +int norflash_pre_operation(void);
       
      -int norflash_post_operation(enum HAL_FLASH_ID_T id);
      +int norflash_post_operation(void);
       
      -int norflash_read_reg(enum HAL_FLASH_ID_T id, uint8_t cmd, uint8_t *val, uint32_t len);
      +int norflash_read_reg(uint8_t cmd, uint8_t *val, uint32_t len);
       
      -int norflash_read_reg_ex(enum HAL_FLASH_ID_T id, uint8_t cmd, uint8_t *param, uint32_t param_len, uint8_t *val, uint32_t len);
      +int norflash_read_reg_ex(uint8_t cmd, uint8_t *param, uint32_t param_len, uint8_t *val, uint32_t len);
       
      -int norflash_write_reg(enum HAL_FLASH_ID_T id, uint8_t cmd, const uint8_t *val, uint32_t len);
      +int norflash_write_reg(uint8_t cmd, const uint8_t *val, uint32_t len);
       
      -int norflash_init_sample_delay_by_div(enum HAL_FLASH_ID_T id, uint32_t div);
      +int norflash_init_sample_delay_by_div(uint32_t div);
       
      -void norflash_set_sample_delay_index(enum HAL_FLASH_ID_T id, uint32_t index);
      +void norflash_set_sample_delay_index(uint32_t index);
       
      -uint32_t norflash_get_sample_delay_index(enum HAL_FLASH_ID_T id);
      +uint32_t norflash_get_sample_delay_index(void);
       
      -int norflash_sample_delay_calib(enum HAL_FLASH_ID_T id, enum DRV_NORFLASH_CALIB_T type);
      +int norflash_sample_delay_calib(enum DRV_NORFLASH_CALIB_T type);
       
      -void norflash_show_calib_result(enum HAL_FLASH_ID_T id);
      +void norflash_show_calib_result(void);
       
      -int norflash_init_div(enum HAL_FLASH_ID_T id, const struct HAL_NORFLASH_CONFIG_T *cfg);
      +int norflash_init_div(const struct HAL_NORFLASH_CONFIG_T *cfg);
       
      -int norflash_match_chip(enum HAL_FLASH_ID_T id, const uint8_t *dev_id, uint32_t len);
      +int norflash_match_chip(const uint8_t *id, uint32_t len);
       
      -int norflash_get_id(enum HAL_FLASH_ID_T id, uint8_t *value, uint32_t len);
      +int norflash_get_id(uint8_t *value, uint32_t len);
       
      -int norflash_get_unique_id(enum HAL_FLASH_ID_T id, uint8_t *value, uint32_t len);
      +int norflash_get_unique_id(uint8_t *value, uint32_t len);
       
      -enum HAL_NORFLASH_RET_T norflash_erase(enum HAL_FLASH_ID_T id, uint32_t start_address, enum DRV_NORFLASH_ERASE_T type, int suspend);
      +enum HAL_NORFLASH_RET_T norflash_erase(uint32_t start_address, enum DRV_NORFLASH_ERASE_T type, int suspend);
       
      -enum HAL_NORFLASH_RET_T norflash_erase_resume(enum HAL_FLASH_ID_T id, int suspend);
      +enum HAL_NORFLASH_RET_T norflash_erase_resume(int suspend);
       
      -enum HAL_NORFLASH_RET_T norflash_write(enum HAL_FLASH_ID_T id, uint32_t start_address, const uint8_t *buffer, uint32_t len, int suspend);
      +enum HAL_NORFLASH_RET_T norflash_write(uint32_t start_address, const uint8_t *buffer, uint32_t len, int suspend);
       
      -enum HAL_NORFLASH_RET_T norflash_write_resume(enum HAL_FLASH_ID_T id, int suspend);
      +enum HAL_NORFLASH_RET_T norflash_write_resume(int suspend);
       
       int norflash_suspend_check_irq(uint32_t irq_num);
       
      -int norflash_read(enum HAL_FLASH_ID_T id, uint32_t start_address, uint8_t *buffer, uint32_t len);
      +int norflash_read(uint32_t start_address, uint8_t *buffer, uint32_t len);
       
      -void norflash_sleep(enum HAL_FLASH_ID_T id);
      +void norflash_sleep(void);
       
      -void norflash_wakeup(enum HAL_FLASH_ID_T id);
      +void norflash_wakeup(void);
       
      -int norflash_init_status(enum HAL_FLASH_ID_T id, uint32_t status);
      +int norflash_init_status(uint32_t status);
       
      -int norflash_set_block_protection(enum HAL_FLASH_ID_T id, uint32_t bp);
      +int norflash_set_block_protection(uint32_t bp);
       
      -int norflash_security_register_lock(enum HAL_FLASH_ID_T id, uint32_t id_map);
      +int norflash_security_register_lock(uint32_t id);
       
      -enum HAL_NORFLASH_RET_T norflash_security_register_erase(enum HAL_FLASH_ID_T id, uint32_t start_address);
      +enum HAL_NORFLASH_RET_T norflash_security_register_erase(uint32_t start_address);
       
      -enum HAL_NORFLASH_RET_T norflash_security_register_write(enum HAL_FLASH_ID_T id, uint32_t start_address, const uint8_t *buffer, uint32_t len);
      +enum HAL_NORFLASH_RET_T norflash_security_register_write(uint32_t start_address, const uint8_t *buffer, uint32_t len);
       
      -int norflash_security_register_read(enum HAL_FLASH_ID_T id, uint32_t start_address, uint8_t *buffer, uint32_t len);
      +int norflash_security_register_read(uint32_t start_address, uint8_t *buffer, uint32_t len);
       
      -uint32_t norflash_security_register_enable_read(enum HAL_FLASH_ID_T id);
      +uint32_t norflash_security_register_enable_read(void);
       
      -void norflash_security_register_disable_read(enum HAL_FLASH_ID_T id, uint32_t mode);
      +void norflash_security_register_disable_read(uint32_t mode);
       
       #ifdef __cplusplus
       }
  • platform/hal/best2300p/hal_analogif_best2300p.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/hal_analogif_best2300p.c bes/platform/hal/best2300p/hal_analogif_best2300p.c
      index a8593f8a4e2..a4d6d240a73 100644
      --- a/platform/hal/best2300p/hal_analogif_best2300p.c
      +++ b/platform/hal/best2300p/hal_analogif_best2300p.c
      @@ -23,7 +23,7 @@
       #define ANA_CHIP_ID_SHIFT               (4)
       #define ANA_CHIP_ID_MASK                (0xFFF << ANA_CHIP_ID_SHIFT)
       #define ANA_CHIP_ID(n)                  BITFIELD_VAL(ANA_CHIP_ID, n)
      -#define ANA_VAL_CHIP_ID                 0x203
      +#define ANA_VAL_CHIP_ID                 0x18E
       
       // ISPI_ARBITRATOR_ENABLE should be defined when:
       // 1) BT and MCU will access RF register at the same time; or
      @@ -38,42 +38,32 @@
       #define PADDING_CYCLES                  0
       #endif
       
      -#define ANA_READ_CMD(r)                 (((1 << 26) | (((r) & 0x3FF) << 16)) << PADDING_CYCLES)
      -#define ANA_WRITE_CMD(r, v)             (((((r) & 0x3FF) << 16) | ((v) & 0xFFFF)) << PADDING_CYCLES)
      +#define ANA_READ_CMD(r)                 (((1 << 24) | (((r) & 0xFF) << 16)) << PADDING_CYCLES)
      +#define ANA_WRITE_CMD(r, v)             (((((r) & 0xFF) << 16) | ((v) & 0xFFFF)) << PADDING_CYCLES)
       #define ANA_READ_VAL(v)                 (((v) >> PADDING_CYCLES) & 0xFFFF)
       
       #define ANA_PAGE_1                      0xA010
       #define ANA_PAGE_0                      0xA000
      -#define ANA_PAGE_QTY                    2
       
      -#define ISPI_REG_CS(r)                  ((r) >> 12)
      -#define ISPI_REG_OFFSET(r)              ((r) & 0x3FF)
      -
      -enum ANAIF_CS_T {
      -    ANAIF_CS_PMU = 0,
      -    ANAIF_CS_ANA,
      -    ANAIF_CS_BTRF,
      -    ANAIF_CS_WIFIRF,
      -
      -    ANAIF_CS_QTY,
      +static const BOOT_RODATA_SRAM_LOC uint8_t page_reg[3] = {
      +    0x00, 0x60, 0x80,
       };
       
      -static const struct HAL_SPI_CFG_T spi_cfg = {
      +static const BOOT_RODATA_FLASH_LOC struct HAL_SPI_CFG_T spi_cfg = {
           .clk_delay_half = false,
           .clk_polarity = false,
           .slave = false,
           .dma_rx = false,
           .dma_tx = false,
      -    .rx_sep_line = true,
      +    .rx_sep_line = false,
           .cs = 0,
           .rate = 6500000,
      -    .tx_bits = 27 + PADDING_CYCLES,
      -    .rx_bits = 27 + PADDING_CYCLES,
      +    .tx_bits = 25 + PADDING_CYCLES,
      +    .rx_bits = 25 + PADDING_CYCLES,
           .rx_frame_bits = 0,
       };
       
       static bool BOOT_BSS_LOC analogif_inited = false;
      -static uint8_t BOOT_BSS_LOC ana_cs;
       
       static int BOOT_TEXT_SRAM_LOC hal_analogif_rawread(unsigned short reg, unsigned short *val)
       {
      @@ -107,18 +97,45 @@ static int BOOT_TEXT_SRAM_LOC hal_analogif_rawwrite(unsigned short reg, unsigned
       int BOOT_TEXT_SRAM_LOC hal_analogif_reg_read(unsigned short reg, unsigned short *val)
       {
           uint32_t lock;
      -    uint8_t cs;
      +    uint32_t idx;
           int ret;
       
      -    cs = ISPI_REG_CS(reg);
      -    reg = ISPI_REG_OFFSET(reg);
      +#if defined(USE_CYBERON)
      +extern int cyb_efuse_check_status(void);
      +
      +    if (cyb_efuse_check_status()) {
      +        if (reg == 0x5e) {
      +            *val = 49185;
      +            return 0;
      +        }
      +        if (reg == 0x00) {
      +            *val = 0x20e0;
      +            return 0;
      +        }
      +    }
      +#endif
       
      -    lock = int_lock();
      -    if (cs != ana_cs) {
      -        hal_ispi_activate_cs(cs);
      -        ana_cs = cs;
      +    if (reg < 0x100) {
      +        lock = int_lock();
      +        ret = hal_analogif_rawread(reg, val);
      +        int_unlock(lock);
      +        return ret;
      +    } else if (reg >= 0x100 && reg <= 0x15F) {
      +        idx = 0;
      +    } else if (reg >= 0x160 && reg <= 0x17F) {
      +        idx = 1;
      +    } else if (reg >= 0x180 && reg <= 0x1FF) {
      +        idx = 2;
      +    } else {
      +        return -1;
           }
      +
      +    reg &= 0xFF;
      +
      +    lock = int_lock();
      +    hal_analogif_rawwrite(page_reg[idx], ANA_PAGE_1);
           ret = hal_analogif_rawread(reg, val);
      +    hal_analogif_rawwrite(page_reg[idx], ANA_PAGE_0);
           int_unlock(lock);
       
           return ret;
      @@ -127,18 +144,30 @@ int BOOT_TEXT_SRAM_LOC hal_analogif_reg_read(unsigned short reg, unsigned short
       int BOOT_TEXT_SRAM_LOC hal_analogif_reg_write(unsigned short reg, unsigned short val)
       {
           uint32_t lock;
      -    uint8_t cs;
      +    uint32_t idx;
           int ret;
       
      -    cs = ISPI_REG_CS(reg);
      -    reg = ISPI_REG_OFFSET(reg);
      +    if (reg < 0x100) {
      +        lock = int_lock();
      +        ret = hal_analogif_rawwrite(reg, val);
      +        int_unlock(lock);
      +        return ret;
      +    } else if (reg >= 0x100 && reg <= 0x15F) {
      +        idx = 0;
      +    } else if (reg >= 0x160 && reg <= 0x17F) {
      +        idx = 1;
      +    } else if (reg >= 0x180 && reg <= 0x1FF) {
      +        idx = 2;
      +    } else {
      +        return -1;
      +    }
      +
      +    reg &= 0xFF;
       
           lock = int_lock();
      -    if (cs != ana_cs) {
      -        hal_ispi_activate_cs(cs);
      -        ana_cs = cs;
      -    }
      +    hal_analogif_rawwrite(page_reg[idx], ANA_PAGE_1);
           ret = hal_analogif_rawwrite(reg, val);
      +    hal_analogif_rawwrite(page_reg[idx], ANA_PAGE_0);
           int_unlock(lock);
       
           return ret;

@OneDeuxTriSeiGo
Copy link
Author

  • platform/hal/best2300p/hal_cmu_best2300p.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/hal_cmu_best2300p.c bes/platform/hal/best2300p/hal_cmu_best2300p.c
      index 931c69bb481..3c5f9065ef3 100644
      --- a/platform/hal/best2300p/hal_cmu_best2300p.c
      +++ b/platform/hal/best2300p/hal_cmu_best2300p.c
      @@ -23,6 +23,7 @@
       #include "hal_codec.h"
       #include "hal_location.h"
       #include "hal_psc.h"
      +#include "hal_sleep_core_pd.h"
       #include "hal_sysfreq.h"
       #include "hal_timer.h"
       #include "hal_trace.h"
      @@ -30,7 +31,13 @@
       #include "pmu.h"
       #include "system_cp.h"
       
      +#ifdef USB_HIGH_SPEED
      +#ifndef USB_USE_USBPLL
      +#define USB_USE_USBPLL
      +#endif
      +#endif
       
      +#define CODEC_CLK_FROM_ANA
       
       #define HAL_CMU_USB_PLL_CLOCK           (192 * 1000 * 1000)
       #define HAL_CMU_AUD_PLL_CLOCK           (CODEC_FREQ_48K_SERIES * CODEC_CMU_DIV)
      @@ -38,16 +45,25 @@
       #define HAL_CMU_USB_CLOCK_60M           (60 * 1000 * 1000)
       #define HAL_CMU_USB_CLOCK_48M           (48 * 1000 * 1000)
       
      -#define HAL_CMU_PWM_SLOW_CLOCK          (32 * 1000)
       #define HAL_CMU_PLL_LOCKED_TIMEOUT      US_TO_TICKS(200)
      -#define HAL_CMU_26M_READY_TIMEOUT       MS_TO_TICKS(3)
      +#define HAL_CMU_26M_READY_TIMEOUT       MS_TO_TICKS(4)
       #define HAL_CMU_LPU_EXTRA_TIMEOUT       MS_TO_TICKS(1)
       
      +#ifdef CORE_SLEEP_POWER_DOWN
      +#define TIMER1_SEL_LOC                  BOOT_TEXT_SRAM_LOC
      +#else
      +#define TIMER1_SEL_LOC                  BOOT_TEXT_FLASH_LOC
      +#endif
       
       enum CMU_USB_CLK_SRC_T {
      -    CMU_USB_CLK_SRC_PLL_48M         = 0,
      -    CMU_USB_CLK_SRC_PLL_60M         = 1,
      -    CMU_USB_CLK_SRC_OSC_24M_X2      = 2,
      +    CMU_USB_CLK_SRC_PLL_60M         = 0,
      +    CMU_USB_CLK_SRC_PLL_60M_ALT     = 1,
      +    CMU_USB_CLK_SRC_PLL_48M         = 2,
      +    CMU_USB_CLK_SRC_TS              = 3,
      +    CMU_USB_CLK_SRC_OSC_48M         = 4,
      +    CMU_USB_CLK_SRC_OSC_24M_X2      = 5,
      +    CMU_USB_CLK_SRC_OSC_26M_X4      = 6,
      +    CMU_USB_CLK_SRC_OSC_26M_X2      = 7,
       };
       
       enum CMU_AUD_26M_X4_USER_T {
      @@ -70,6 +86,7 @@ enum CMU_DEBUG_REG_SEL_T {
       struct CP_STARTUP_CFG_T {
           __IO uint32_t stack;
           __IO uint32_t reset_hdlr;
      +    __IO uint32_t entry;
       };
       
       static struct CMU_T * const cmu = (struct CMU_T *)CMU_BASE;
      @@ -78,13 +95,23 @@ static struct AONCMU_T * const aoncmu = (struct AONCMU_T *)AON_CMU_BASE;
       
       static struct BTCMU_T * const POSSIBLY_UNUSED btcmu = (struct BTCMU_T *)BT_CMU_BASE;
       
      -static struct WLANCMU_T * const POSSIBLY_UNUSED wlancmu = (struct WLANCMU_T *)WIFI_CMU_BASE;
      +static struct CP_STARTUP_CFG_T * const cp_cfg = (struct CP_STARTUP_CFG_T *)0x200F7FE0;
       
      -static uint32_t cp_entry;
      -
      -static uint8_t BOOT_BSS_LOC pll_user_map[HAL_CMU_PLL_QTY];
      +#define HAL_CMU_PLL_USB_HS              HAL_CMU_PLL_QTY
      +#ifdef USB_USE_USBPLL
      +#define PLL_USER_MAP_NUM                (HAL_CMU_PLL_QTY + 1)
      +#else
      +#define PLL_USER_MAP_NUM                HAL_CMU_PLL_QTY
      +#endif
      +static uint8_t BOOT_BSS_LOC pll_user_map[PLL_USER_MAP_NUM];
       STATIC_ASSERT(HAL_CMU_PLL_USER_QTY <= sizeof(pll_user_map[0]) * 8, "Too many PLL users");
       
      +#ifdef ROM_BUILD
      +static enum HAL_CMU_USB_CLOCK_SEL_T usb_clk_sel;
      +#endif
      +
      +static bool anc_enabled;
      +
       #ifdef __AUDIO_RESAMPLE__
       static bool aud_resample_en = true;
       #ifdef ANA_26M_X4_ENABLE
      @@ -94,7 +121,8 @@ STATIC_ASSERT(CMU_AUD_26M_X4_USER_QTY <= sizeof(aud_26m_x4_map) * 8, "Too many a
       #endif
       
       #ifdef LOW_SYS_FREQ
      -static enum HAL_CMU_FREQ_T BOOT_BSS_LOC cmu_sys_freq;
      +static enum HAL_CMU_LOW_SYS_FREQ_T BOOT_BSS_LOC low_sys_freq;
      +static bool BOOT_BSS_LOC low_sys_freq_en;
       #endif
       
       void hal_cmu_audio_resample_enable(void)
      @@ -128,7 +156,7 @@ static inline void aocmu_reg_update_wait(void)
       
       int hal_cmu_clock_enable(enum HAL_CMU_MOD_ID_T id)
       {
      -    if (id >= HAL_CMU_AON_A7) {
      +    if (id >= HAL_CMU_AON_MCU) {
               return 1;
           }
       
      @@ -136,10 +164,8 @@ int hal_cmu_clock_enable(enum HAL_CMU_MOD_ID_T id)
               cmu->HCLK_ENABLE = (1 << id);
           } else if (id < HAL_CMU_MOD_O_SLEEP) {
               cmu->PCLK_ENABLE = (1 << (id - HAL_CMU_MOD_P_CMU));
      -    } else if (id < HAL_CMU_MOD_Q_NULL) {
      -        cmu->OCLK_ENABLE = (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else if (id < HAL_CMU_AON_A_CMU) {
      -        cmu->QCLK_ENABLE = (1 << (id - HAL_CMU_MOD_Q_NULL));
      +        cmu->OCLK_ENABLE = (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else {
               aoncmu->MOD_CLK_ENABLE = (1 << (id - HAL_CMU_AON_A_CMU));
               aocmu_reg_update_wait();
      @@ -150,21 +176,16 @@ int hal_cmu_clock_enable(enum HAL_CMU_MOD_ID_T id)
       
       int hal_cmu_clock_disable(enum HAL_CMU_MOD_ID_T id)
       {
      -    if (id >= HAL_CMU_AON_A7) {
      +    if (id >= HAL_CMU_AON_MCU) {
               return 1;
           }
       
      -    if (id == HAL_CMU_MOD_P_TZC)
      -        return 0;
      -
           if (id < HAL_CMU_MOD_P_CMU) {
               cmu->HCLK_DISABLE = (1 << id);
           } else if (id < HAL_CMU_MOD_O_SLEEP) {
               cmu->PCLK_DISABLE = (1 << (id - HAL_CMU_MOD_P_CMU));
      -    } else if (id < HAL_CMU_MOD_Q_NULL) {
      -        cmu->OCLK_DISABLE = (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else if (id < HAL_CMU_AON_A_CMU) {
      -        cmu->QCLK_DISABLE = (1 << (id - HAL_CMU_MOD_Q_NULL));
      +        cmu->OCLK_DISABLE = (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else {
               aoncmu->MOD_CLK_DISABLE = (1 << (id - HAL_CMU_AON_A_CMU));
           }
      @@ -176,7 +197,7 @@ enum HAL_CMU_CLK_STATUS_T hal_cmu_clock_get_status(enum HAL_CMU_MOD_ID_T id)
       {
           uint32_t status;
       
      -    if (id >= HAL_CMU_AON_A7) {
      +    if (id >= HAL_CMU_AON_MCU) {
               return HAL_CMU_CLK_DISABLED;
           }
       
      @@ -184,10 +205,8 @@ enum HAL_CMU_CLK_STATUS_T hal_cmu_clock_get_status(enum HAL_CMU_MOD_ID_T id)
               status = cmu->HCLK_ENABLE & (1 << id);
           } else if (id < HAL_CMU_MOD_O_SLEEP) {
               status = cmu->PCLK_ENABLE & (1 << (id - HAL_CMU_MOD_P_CMU));
      -    } else if (id < HAL_CMU_MOD_Q_NULL) {
      -        status = cmu->OCLK_ENABLE & (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else if (id < HAL_CMU_AON_A_CMU) {
      -        status = cmu->QCLK_ENABLE & (1 << (id - HAL_CMU_MOD_Q_NULL));
      +        status = cmu->OCLK_ENABLE & (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else {
               status = aoncmu->MOD_CLK_ENABLE & (1 << (id - HAL_CMU_AON_A_CMU));
           }
      @@ -201,7 +220,7 @@ int hal_cmu_clock_set_mode(enum HAL_CMU_MOD_ID_T id, enum HAL_CMU_CLK_MODE_T mod
           uint32_t val;
           uint32_t lock;
       
      -    if (id >= HAL_CMU_AON_A7) {
      +    if (id >= HAL_CMU_AON_MCU) {
               return 1;
           }
       
      @@ -211,12 +230,9 @@ int hal_cmu_clock_set_mode(enum HAL_CMU_MOD_ID_T id, enum HAL_CMU_CLK_MODE_T mod
           } else if (id < HAL_CMU_MOD_O_SLEEP) {
               reg = &cmu->PCLK_MODE;
               val = (1 << (id - HAL_CMU_MOD_P_CMU));
      -    } else if (id < HAL_CMU_MOD_Q_NULL) {
      +    } else if (id < HAL_CMU_AON_A_CMU) {
               reg = &cmu->OCLK_MODE;
               val = (1 << (id - HAL_CMU_MOD_O_SLEEP));
      -    } else if (id < HAL_CMU_AON_A_CMU) {
      -        reg = &cmu->QCLK_MODE;
      -        val = (1 << (id - HAL_CMU_MOD_Q_NULL));
           } else {
               reg = &aoncmu->MOD_CLK_MODE;
               val = (1 << (id - HAL_CMU_AON_A_CMU));
      @@ -237,7 +253,7 @@ enum HAL_CMU_CLK_MODE_T hal_cmu_clock_get_mode(enum HAL_CMU_MOD_ID_T id)
       {
           uint32_t mode;
       
      -    if (id >= HAL_CMU_AON_A7) {
      +    if (id >= HAL_CMU_AON_MCU) {
               return HAL_CMU_CLK_AUTO;
           }
       
      @@ -245,10 +261,8 @@ enum HAL_CMU_CLK_MODE_T hal_cmu_clock_get_mode(enum HAL_CMU_MOD_ID_T id)
               mode = cmu->HCLK_MODE & (1 << id);
           } else if (id < HAL_CMU_MOD_O_SLEEP) {
               mode = cmu->PCLK_MODE & (1 << (id - HAL_CMU_MOD_P_CMU));
      -    } else if (id < HAL_CMU_MOD_Q_NULL) {
      -        mode = cmu->OCLK_MODE & (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else if (id < HAL_CMU_AON_A_CMU) {
      -        mode = cmu->QCLK_MODE & (1 << (id - HAL_CMU_MOD_Q_NULL));
      +        mode = cmu->OCLK_MODE & (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else {
               mode = aoncmu->MOD_CLK_MODE & (1 << (id - HAL_CMU_AON_A_CMU));
           }
      @@ -262,21 +276,14 @@ int hal_cmu_reset_set(enum HAL_CMU_MOD_ID_T id)
               return 1;
           }
       
      -    if (id == HAL_CMU_MOD_P_TZC)
      -        return 0;
      -
           if (id < HAL_CMU_MOD_P_CMU) {
               cmu->HRESET_SET = (1 << id);
           } else if (id < HAL_CMU_MOD_O_SLEEP) {
               cmu->PRESET_SET = (1 << (id - HAL_CMU_MOD_P_CMU));
      -    } else if (id < HAL_CMU_MOD_Q_NULL) {
      -        cmu->ORESET_SET = (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else if (id < HAL_CMU_AON_A_CMU) {
      -        cmu->QRESET_SET = (1 << (id - HAL_CMU_MOD_Q_NULL));
      -    } else if (id < HAL_CMU_AON_A7) {
      -        aoncmu->RESET_SET = (1 << (id - HAL_CMU_AON_A_CMU));
      +        cmu->ORESET_SET = (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else {
      -        aoncmu->SOFT_RSTN_SET = (1 << (id - HAL_CMU_AON_A7));
      +        aoncmu->RESET_SET = (1 << (id - HAL_CMU_AON_A_CMU));
           }
       
           return 0;
      @@ -290,25 +297,14 @@ int hal_cmu_reset_clear(enum HAL_CMU_MOD_ID_T id)
       
           if (id < HAL_CMU_MOD_P_CMU) {
               cmu->HRESET_CLR = (1 << id);
      -        asm volatile("nop; nop; nop; nop; nop; nop; nop; nop;");
      -        asm volatile("nop; nop; nop; nop;");
      +        asm volatile("nop; nop;");
           } else if (id < HAL_CMU_MOD_O_SLEEP) {
               cmu->PRESET_CLR = (1 << (id - HAL_CMU_MOD_P_CMU));
      -        asm volatile("nop; nop; nop; nop; nop; nop; nop; nop;");
      -        asm volatile("nop; nop; nop; nop;");
      -    } else if (id < HAL_CMU_MOD_Q_NULL) {
      -        cmu->ORESET_CLR = (1 << (id - HAL_CMU_MOD_O_SLEEP));
      -        asm volatile("nop; nop; nop; nop; nop; nop; nop; nop;");
               asm volatile("nop; nop; nop; nop;");
           } else if (id < HAL_CMU_AON_A_CMU) {
      -        cmu->QRESET_CLR = (1 << (id - HAL_CMU_MOD_Q_NULL));
      -        asm volatile("nop; nop; nop; nop; nop; nop; nop; nop;");
      -        asm volatile("nop; nop; nop; nop;");
      -    } else if (id < HAL_CMU_AON_A7) {
      -        aoncmu->RESET_CLR = (1 << (id - HAL_CMU_AON_A_CMU));
      -        aocmu_reg_update_wait();
      +        cmu->ORESET_CLR = (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else {
      -        aoncmu->SOFT_RSTN_CLR = (1 << (id - HAL_CMU_AON_A7));
      +        aoncmu->RESET_CLR = (1 << (id - HAL_CMU_AON_A_CMU));
               aocmu_reg_update_wait();
           }
       
      @@ -327,14 +323,10 @@ enum HAL_CMU_RST_STATUS_T hal_cmu_reset_get_status(enum HAL_CMU_MOD_ID_T id)
               status = cmu->HRESET_SET & (1 << id);
           } else if (id < HAL_CMU_MOD_O_SLEEP) {
               status = cmu->PRESET_SET & (1 << (id - HAL_CMU_MOD_P_CMU));
      -    } else if (id < HAL_CMU_MOD_Q_NULL) {
      -        status = cmu->ORESET_SET & (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else if (id < HAL_CMU_AON_A_CMU) {
      -        status = cmu->QRESET_SET & (1 << (id - HAL_CMU_MOD_Q_NULL));
      -    } else if (id < HAL_CMU_AON_A7) {
      -        status = aoncmu->RESET_SET & (1 << (id - HAL_CMU_AON_A_CMU));
      +        status = cmu->ORESET_SET & (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else {
      -        status = aoncmu->SOFT_RSTN_SET & (1 << (id - HAL_CMU_AON_A7));
      +        status = aoncmu->RESET_SET & (1 << (id - HAL_CMU_AON_A_CMU));
           }
       
           return status ? HAL_CMU_RST_CLR : HAL_CMU_RST_SET;
      @@ -356,20 +348,10 @@ int hal_cmu_reset_pulse(enum HAL_CMU_MOD_ID_T id)
               cmu->HRESET_PULSE = (1 << id);
           } else if (id < HAL_CMU_MOD_O_SLEEP) {
               cmu->PRESET_PULSE = (1 << (id - HAL_CMU_MOD_P_CMU));
      -    } else if (id < HAL_CMU_MOD_Q_NULL) {
      -        cmu->ORESET_PULSE = (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else if (id < HAL_CMU_AON_A_CMU) {
      -        cmu->QRESET_PULSE = (1 << (id - HAL_CMU_MOD_Q_NULL));
      -    } else if (id < HAL_CMU_AON_A7) {
      -        aoncmu->RESET_PULSE = (1 << (id - HAL_CMU_AON_A_CMU));
      -        // Total 3 CLK-26M cycles needed
      -        // AOCMU runs in 26M clock domain and its read operations consume at least 1 26M-clock cycle.
      -        // (Whereas its write operations will finish at 1 HCLK cycle -- finish once in async bridge fifo)
      -        aoncmu->CHIP_ID;
      -        aoncmu->CHIP_ID;
      -        aoncmu->CHIP_ID;
      +        cmu->ORESET_PULSE = (1 << (id - HAL_CMU_MOD_O_SLEEP));
           } else {
      -        aoncmu->SOFT_RSTN_PULSE = (1 << (id - HAL_CMU_AON_A7));
      +        aoncmu->RESET_PULSE = (1 << (id - HAL_CMU_AON_A_CMU));
               // Total 3 CLK-26M cycles needed
               // AOCMU runs in 26M clock domain and its read operations consume at least 1 26M-clock cycle.
               // (Whereas its write operations will finish at 1 HCLK cycle -- finish once in async bridge fifo)
      @@ -415,7 +397,7 @@ int hal_cmu_timer_set_div(enum HAL_CMU_TIMER_ID_T id, uint32_t div)
           return 0;
       }
       
      -void hal_cmu_timer0_select_fast(void)
      +void BOOT_TEXT_FLASH_LOC hal_cmu_timer0_select_fast(void)
       {
           uint32_t lock;
       
      @@ -423,7 +405,7 @@ void hal_cmu_timer0_select_fast(void)
           // 6.5M
           cmu->PERIPH_CLK |= (1 << CMU_SEL_TIMER_FAST_SHIFT);
           // AON Timer
      -    aoncmu->TIMER_CLK |= AON_CMU_SEL_TIMER_FAST;
      +    aoncmu->CLK_SELECT |= AON_CMU_SEL_TIMER_FAST;
           int_unlock(lock);
       }
       
      @@ -435,11 +417,11 @@ void BOOT_TEXT_FLASH_LOC hal_cmu_timer0_select_slow(void)
           // 16K
           cmu->PERIPH_CLK &= ~(1 << CMU_SEL_TIMER_FAST_SHIFT);
           // AON Timer
      -    aoncmu->TIMER_CLK &= ~AON_CMU_SEL_TIMER_FAST;
      +    aoncmu->CLK_SELECT &= ~AON_CMU_SEL_TIMER_FAST;
           int_unlock(lock);
       }
       
      -void BOOT_TEXT_FLASH_LOC hal_cmu_timer1_select_fast(void)
      +void TIMER1_SEL_LOC hal_cmu_timer1_select_fast(void)
       {
           uint32_t lock;
       
      @@ -449,7 +431,7 @@ void BOOT_TEXT_FLASH_LOC hal_cmu_timer1_select_fast(void)
           int_unlock(lock);
       }
       
      -void BOOT_TEXT_FLASH_LOC hal_cmu_timer1_select_slow(void)
      +void TIMER1_SEL_LOC hal_cmu_timer1_select_slow(void)
       {
           uint32_t lock;
       
      @@ -479,46 +461,6 @@ void hal_cmu_timer2_select_slow(void)
           int_unlock(lock);
       }
       
      -void hal_cmu_dsp_timer0_select_fast(void)
      -{
      -    uint32_t lock;
      -
      -    lock = int_lock();
      -    // 6.5M
      -    cmu->DSP_DIV |= (1 << CMU_SEL_TIMER_FAST_AP_SHIFT);
      -    int_unlock(lock);
      -}
      -
      -void hal_cmu_dsp_timer0_select_slow(void)
      -{
      -    uint32_t lock;
      -
      -    lock = int_lock();
      -    // 16K
      -    cmu->DSP_DIV &= ~(1 << CMU_SEL_TIMER_FAST_AP_SHIFT);
      -    int_unlock(lock);
      -}
      -
      -void hal_cmu_dsp_timer1_select_fast(void)
      -{
      -    uint32_t lock;
      -
      -    lock = int_lock();
      -    // 6.5M
      -    cmu->DSP_DIV |= (1 << (CMU_SEL_TIMER_FAST_AP_SHIFT + 1));
      -    int_unlock(lock);
      -}
      -
      -void hal_cmu_dsp_timer1_select_slow(void)
      -{
      -    uint32_t lock;
      -
      -    lock = int_lock();
      -    // 16K
      -    cmu->DSP_DIV &= ~(1 << (CMU_SEL_TIMER_FAST_AP_SHIFT + 1));
      -    int_unlock(lock);
      -}
      -
       int hal_cmu_sdmmc_set_pll_div(uint32_t div)
       {
           uint32_t lock;
      @@ -536,709 +478,317 @@ int hal_cmu_sdmmc_set_pll_div(uint32_t div)
           return 0;
       }
       
      -int BOOT_TEXT_SRAM_LOC hal_cmu_flash_set_freq(enum HAL_CMU_FREQ_T freq)
      -{
      -    uint32_t set;
      -    uint32_t clr;
      -    uint32_t lock;
      -    bool clk_en;
      -
      -    if (freq >= HAL_CMU_FREQ_QTY) {
      -        return 1;
      -    }
      -    if (freq == HAL_CMU_FREQ_32K) {
      -        return 2;
      -    }
      -
      -    switch (freq) {
      -    case HAL_CMU_FREQ_26M:
      -        set = 0;
      -        clr = AON_CMU_RSTN_DIV_FLS | AON_CMU_BYPASS_DIV_FLS | AON_CMU_SEL_FLS_OSCX2 | AON_CMU_SEL_FLS_OSCX4 | AON_CMU_SEL_FLS_PLL;
      -        break;
      -    case HAL_CMU_FREQ_52M:
      -        set = AON_CMU_SEL_FLS_OSCX2;
      -        clr = AON_CMU_RSTN_DIV_FLS | AON_CMU_BYPASS_DIV_FLS | AON_CMU_SEL_FLS_OSCX4 | AON_CMU_SEL_FLS_PLL;
      -        break;
      -    case HAL_CMU_FREQ_78M:
      -    case HAL_CMU_FREQ_104M:
       #ifdef OSC_26M_X4_AUD2BB
      -        set = AON_CMU_SEL_FLS_OSCX4;
      -        clr = AON_CMU_RSTN_DIV_FLS | AON_CMU_BYPASS_DIV_FLS | AON_CMU_SEL_FLS_OSCX2 | AON_CMU_SEL_FLS_PLL;
      -        break;
      -#endif
      -    case HAL_CMU_FREQ_156M:
      -    case HAL_CMU_FREQ_208M:
      -    case HAL_CMU_FREQ_260M:
      -        set = AON_CMU_RSTN_DIV_FLS | AON_CMU_SEL_FLS_PLL;
      -        clr = AON_CMU_CFG_DIV_FLS_MASK | AON_CMU_BYPASS_DIV_FLS | AON_CMU_SEL_FLS_OSCX2 | AON_CMU_SEL_FLS_OSCX4;
      -        if (0) {
      -#ifndef OSC_26M_X4_AUD2BB
      -        } else if (freq <= HAL_CMU_FREQ_78M) {
      -            set |= AON_CMU_CFG_DIV_FLS(3);
      -        } else if (freq <= HAL_CMU_FREQ_104M) {
      -            set |= AON_CMU_CFG_DIV_FLS(2);
      -#endif
      -        } else if (freq <= HAL_CMU_FREQ_156M) {
      -            set |= AON_CMU_CFG_DIV_FLS(1);
      -        } else { // 208M or 260M
      -            set |= AON_CMU_CFG_DIV_FLS(0);
      -        }
      -        break;
      -    case HAL_CMU_FREQ_390M:
      -    case HAL_CMU_FREQ_780M:
      -    default:
      -        set = AON_CMU_BYPASS_DIV_FLS | AON_CMU_SEL_FLS_PLL;
      -        clr = AON_CMU_RSTN_DIV_FLS | AON_CMU_SEL_FLS_OSCX2 | AON_CMU_SEL_FLS_OSCX4;
      -        break;
      -    };
       
      -    lock = int_lock();
      -    clk_en = !!(cmu->OCLK_DISABLE & SYS_OCLK_FLASH);
      -    if (clk_en) {
      -        cmu->OCLK_DISABLE = SYS_OCLK_FLASH;
      -        cmu->HCLK_DISABLE = SYS_HCLK_FLASH;
      -        // Wait at least 2 cycles of flash controller. The min freq is 26M, the same as AON.
      -        aocmu_reg_update_wait();
      -        aocmu_reg_update_wait();
      -    }
      -    aoncmu->FLS_PSR_CLK = (aoncmu->FLS_PSR_CLK & ~clr) | set;
      -    if (clk_en) {
      -        cmu->HCLK_ENABLE = SYS_HCLK_FLASH;
      -        cmu->OCLK_ENABLE = SYS_OCLK_FLASH;
      -    }
      -    int_unlock(lock);
      +// Any of 78M/104M/208M is changed to 26M x4 (104M)
       
      -    return 0;
      +#define SYS_SET_FREQ_FUNC(f, F, CLK_OV) \
      +int hal_cmu_ ##f## _set_freq(enum HAL_CMU_FREQ_T freq) \
      +{ \
      +    uint32_t enable; \
      +    uint32_t disable; \
      +    if (freq >= HAL_CMU_FREQ_QTY) { \
      +        return 1; \
      +    } \
      +    if (freq == HAL_CMU_FREQ_32K) { \
      +        enable = 0; \
      +        disable = CMU_SEL_OSC_ ##F## _DISABLE | CMU_SEL_OSCX2_ ##F## _DISABLE | \
      +            CMU_SEL_PLL_ ##F## _DISABLE | CMU_RSTN_DIV_ ##F## _DISABLE | CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +    } else if (freq == HAL_CMU_FREQ_26M) { \
      +        enable = CMU_SEL_OSC_ ##F## _ENABLE; \
      +        disable = CMU_SEL_OSCX2_ ##F## _DISABLE | \
      +            CMU_SEL_PLL_ ##F## _DISABLE | CMU_RSTN_DIV_ ##F## _DISABLE | CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +    } else if (freq == HAL_CMU_FREQ_52M) { \
      +        enable = CMU_SEL_OSCX2_ ##F## _ENABLE; \
      +        disable = CMU_SEL_PLL_ ##F## _DISABLE | CMU_RSTN_DIV_ ##F## _DISABLE | CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +    } else { \
      +        enable = CMU_SEL_PLL_ ##F## _ENABLE | CMU_BYPASS_DIV_ ##F## _ENABLE; \
      +        disable = CMU_RSTN_DIV_ ##F## _DISABLE; \
      +    } \
      +    if (enable & CMU_SEL_PLL_ ##F## _ENABLE) { \
      +        CLK_OV; \
      +        cmu->SYS_CLK_ENABLE = CMU_RSTN_DIV_ ##F## _ENABLE; \
      +        if (enable & CMU_BYPASS_DIV_ ##F## _ENABLE) { \
      +            cmu->SYS_CLK_ENABLE = CMU_BYPASS_DIV_ ##F## _ENABLE; \
      +        } else { \
      +            cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +        } \
      +    } \
      +    cmu->SYS_CLK_ENABLE = enable; \
      +    if (enable & CMU_SEL_PLL_ ##F## _ENABLE) { \
      +        cmu->SYS_CLK_DISABLE = disable; \
      +    } else { \
      +        cmu->SYS_CLK_DISABLE = disable & ~(CMU_RSTN_DIV_ ##F## _DISABLE | CMU_BYPASS_DIV_ ##F## _DISABLE); \
      +        cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +        cmu->SYS_CLK_DISABLE = CMU_RSTN_DIV_ ##F## _DISABLE; \
      +    } \
      +    return 0; \
       }
       
      -int BOOT_TEXT_SRAM_LOC hal_cmu_flash1_set_freq(enum HAL_CMU_FREQ_T freq)
      -{
      -    aoncmu->FLASH_IOCFG |= AON_CMU_PU_FLASH1_IO;
      -    //TODO: 2003 flash0 and flash1 use same clock source, so don't change clk freq in case of flash0 error
      -#ifdef ROM_BUILD //2003 rom only use one flash
      -    return hal_cmu_flash_set_freq(freq);
      -#else
      -    return 0;
      -#endif
      +#else // !OSC_26M_X4_AUD2BB
      +
      +#define SYS_SET_FREQ_FUNC(f, F, CLK_OV) \
      +int hal_cmu_ ##f## _set_freq(enum HAL_CMU_FREQ_T freq) \
      +{ \
      +    uint32_t lock; \
      +    uint32_t enable; \
      +    uint32_t disable; \
      +    int div = -1; \
      +    if (freq >= HAL_CMU_FREQ_QTY) { \
      +        return 1; \
      +    } \
      +    if (freq == HAL_CMU_FREQ_32K) { \
      +        enable = 0; \
      +        disable = CMU_SEL_OSC_ ##F## _DISABLE | CMU_SEL_OSCX2_ ##F## _DISABLE | \
      +            CMU_SEL_PLL_ ##F## _DISABLE | CMU_RSTN_DIV_ ##F## _DISABLE | CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +    } else if (freq == HAL_CMU_FREQ_26M) { \
      +        enable = CMU_SEL_OSC_ ##F## _ENABLE; \
      +        disable = CMU_SEL_OSCX2_ ##F## _DISABLE | \
      +            CMU_SEL_PLL_ ##F## _DISABLE | CMU_RSTN_DIV_ ##F## _DISABLE | CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +    } else if (freq == HAL_CMU_FREQ_52M) { \
      +        enable = CMU_SEL_OSCX2_ ##F## _ENABLE; \
      +        disable = CMU_SEL_PLL_ ##F## _DISABLE | CMU_RSTN_DIV_ ##F## _DISABLE | CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +    } else if (freq == HAL_CMU_FREQ_78M) { \
      +        enable = CMU_SEL_PLL_ ##F## _ENABLE | CMU_RSTN_DIV_ ##F## _ENABLE; \
      +        disable = CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +        div = 1; \
      +    } else if (freq == HAL_CMU_FREQ_104M) { \
      +        enable = CMU_SEL_PLL_ ##F## _ENABLE | CMU_RSTN_DIV_ ##F## _ENABLE; \
      +        disable = CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +        div = 0; \
      +    } else { \
      +        enable = CMU_SEL_PLL_ ##F## _ENABLE | CMU_BYPASS_DIV_ ##F## _ENABLE; \
      +        disable = CMU_RSTN_DIV_ ##F## _DISABLE; \
      +    } \
      +    if (div >= 0) { \
      +        CLK_OV; \
      +        lock = int_lock(); \
      +        cmu->SYS_DIV = SET_BITFIELD(cmu->SYS_DIV, CMU_CFG_DIV_ ##F, div); \
      +        int_unlock(lock); \
      +    } \
      +    if (enable & CMU_SEL_PLL_ ##F## _ENABLE) { \
      +        cmu->SYS_CLK_ENABLE = CMU_RSTN_DIV_ ##F## _ENABLE; \
      +        if (enable & CMU_BYPASS_DIV_ ##F## _ENABLE) { \
      +            cmu->SYS_CLK_ENABLE = CMU_BYPASS_DIV_ ##F## _ENABLE; \
      +        } else { \
      +            cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +        } \
      +    } \
      +    cmu->SYS_CLK_ENABLE = enable; \
      +    if (enable & CMU_SEL_PLL_ ##F## _ENABLE) { \
      +        cmu->SYS_CLK_DISABLE = disable; \
      +    } else { \
      +        cmu->SYS_CLK_DISABLE = disable & ~(CMU_RSTN_DIV_ ##F## _DISABLE | CMU_BYPASS_DIV_ ##F## _DISABLE); \
      +        cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_ ##F## _DISABLE; \
      +        cmu->SYS_CLK_DISABLE = CMU_RSTN_DIV_ ##F## _DISABLE; \
      +    } \
      +    return 0; \
       }
       
      -int hal_cmu_mem_set_freq(enum HAL_CMU_FREQ_T freq)
      -{
      -    uint32_t set;
      -    uint32_t clr;
      -    uint32_t lock;
      -    bool clk_en;
      +#endif // !OSC_26M_X4_AUD2BB
       
      -    if (freq >= HAL_CMU_FREQ_QTY) {
      -        return 1;
      -    }
      -    if (freq == HAL_CMU_FREQ_32K) {
      -        return 2;
      -    }
      +#ifdef MCU_SYS_CLOCK_400M
      +#define FLASH_DIV_OFFSET                2
      +#elif defined(MCU_SYS_CLOCK_300M)
      +#define FLASH_DIV_OFFSET                1
      +#else
      +#define FLASH_DIV_OFFSET                0
      +#endif
       
      -    // 2003 psram ctrl use 400M clk from bbpsram
      -    switch (freq) {
      -    case HAL_CMU_FREQ_26M:
      -        set = 0;
      -        clr = AON_CMU_RSTN_DIV_PSR | AON_CMU_BYPASS_DIV_PSR | AON_CMU_SEL_PSR_OSCX2 | AON_CMU_SEL_PSR_OSCX4 | AON_CMU_SEL_PSR_PLL;
      -        break;
      -    case HAL_CMU_FREQ_52M:
      -        set = AON_CMU_SEL_PSR_OSCX2;
      -        clr = AON_CMU_RSTN_DIV_PSR | AON_CMU_BYPASS_DIV_PSR | AON_CMU_SEL_PSR_OSCX4 | AON_CMU_SEL_PSR_PLL;
      -        break;
      -    case HAL_CMU_FREQ_78M:
      -    case HAL_CMU_FREQ_104M:
       #ifdef OSC_26M_X4_AUD2BB
      -        set = AON_CMU_SEL_PSR_OSCX4;
      -        clr = AON_CMU_RSTN_DIV_PSR | AON_CMU_BYPASS_DIV_PSR | AON_CMU_SEL_PSR_OSCX2 | AON_CMU_SEL_PSR_PLL;
      -        break;
      -#endif
      -    case HAL_CMU_FREQ_156M:
      -    case HAL_CMU_FREQ_208M:
      -    case HAL_CMU_FREQ_260M:
      -        set = AON_CMU_RSTN_DIV_PSR | AON_CMU_SEL_PSR_PLL | AON_CMU_SEL_PSR_INT;
      -        clr = AON_CMU_CFG_DIV_PSR_MASK | AON_CMU_BYPASS_DIV_PSR | AON_CMU_SEL_PSR_OSCX2 | AON_CMU_SEL_PSR_OSCX4;
      -        if (0) {
      -#ifndef OSC_26M_X4_AUD2BB
      -        } else if (freq <= HAL_CMU_FREQ_78M) {
      -            set |= AON_CMU_CFG_DIV_PSR(3);
      -        } else if (freq <= HAL_CMU_FREQ_104M) {
      -            set |= AON_CMU_CFG_DIV_PSR(2);
      -#endif
      -        } else if (freq <= HAL_CMU_FREQ_156M) {
      -            set |= AON_CMU_CFG_DIV_PSR(1);
      -        } else { // 208M or 260M
      -            set |= AON_CMU_CFG_DIV_PSR(0);
      -        }
      -        break;
      -    case HAL_CMU_FREQ_390M:
      -    case HAL_CMU_FREQ_780M:
      -    default:
      -        set = AON_CMU_BYPASS_DIV_PSR | AON_CMU_SEL_PSR_PLL | AON_CMU_SEL_PSR_INT;
      -        clr = AON_CMU_RSTN_DIV_PSR | AON_CMU_SEL_PSR_OSCX2 | AON_CMU_SEL_PSR_OSCX4;
      -        break;
      -    };
      -
      -    lock = int_lock();
      -    clk_en = !!(cmu->OCLK_DISABLE & SYS_OCLK_PSRAM200);
      -    if (clk_en) {
      -        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PHY_PS_DISABLE;
      -        cmu->OCLK_DISABLE = SYS_OCLK_PSRAM200;
      -        cmu->HCLK_DISABLE = SYS_HCLK_PSRAM200;
      -        // Wait at least 2 cycles of psram controller. The min freq is 26M, the same as AON.
      -        aocmu_reg_update_wait();
      -        aocmu_reg_update_wait();
      -    }
      -    aoncmu->FLS_PSR_CLK = (aoncmu->FLS_PSR_CLK & ~clr) | set;
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PHY_PS_ENABLE;
      -    if (clk_en) {
      -        cmu->HCLK_ENABLE = SYS_HCLK_PSRAM200;
      -        cmu->OCLK_ENABLE = SYS_OCLK_PSRAM200;
      -    }
      -    int_unlock(lock);
      +#define FLASH_FREQ_OV                   { aoncmu->CLK_OUT |= AON_CMU_SEL_X4_FLS; }
      +#else
      +#define FLASH_FREQ_OV                   { div += FLASH_DIV_OFFSET; }
      +#endif
       
      -    return 0;
      -}
      +BOOT_TEXT_SRAM_LOC SYS_SET_FREQ_FUNC(flash, FLS, FLASH_FREQ_OV);
       
      -int hal_cmu_ddr_clock_enable()
      +#ifdef LOW_SYS_FREQ
      +void hal_cmu_low_sys_clock_set(enum HAL_CMU_LOW_SYS_FREQ_T freq)
       {
      -    uint32_t set;
      -    uint32_t clr;
           uint32_t lock;
      -    bool clk_en;
      -
      -    hal_cmu_pll_enable(HAL_CMU_PLL_DDR, HAL_CMU_PLL_USER_PSRAM);
      -#if 1
      -    //pxclk use xclk, works in synchronous mode
      -    //a7 can change sys freq in this mode
      -    cmu->PERIPH_CLK &= ~CMU_SEL_PSRAMX2;
      -    *(volatile uint32_t *)(GPV_PSRAM1G_BASE+0x42020) = 0;
      -#else
      -    //pxclk use psram2, works in asynchronous mode
      -    *(volatile uint32_t *)(GPV_PSRAM1G_BASE+0x42020) = 4;
      -    cmu->PERIPH_CLK |= CMU_SEL_PSRAMX2;
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_PSRAMX2_ENABLE;
      -#endif
      -
      -    // PSRAMUHS can't use ddr pll divider
      -    set = AON_CMU_BYPASS_DIV_DDR | AON_CMU_SEL_DDR_PLL | AON_CMU_CFG_DIV_PSRAMX2(2);
      -    clr = AON_CMU_RSTN_DIV_DDR | AON_CMU_SEL_DDR_OSCX2 | AON_CMU_SEL_DDR_OSCX4 | AON_CMU_CFG_DIV_PSRAMX2_MASK;
       
      -    lock = int_lock();
      -    clk_en = !!(cmu->OCLK_DISABLE & SYS_OCLK_PSRAM1G);
      -    if (clk_en) {
      -        cmu->OCLK_DISABLE = SYS_OCLK_PSRAM1G;
      -        cmu->HCLK_DISABLE = SYS_HCLK_PSRAM1G;
      -        // Wait at least 2 cycles of psram controller. The min freq is 26M, the same as AON.
      -        aocmu_reg_update_wait();
      -        aocmu_reg_update_wait();
      +    if (hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_0) {
      +        return;
           }
      -    aoncmu->DDR_CLK = (aoncmu->DDR_CLK & ~clr) | set;
      -
      -    cmu->XCLK_ENABLE = SYS_XCLK_PSRAM1G | SYS_XCLK_PSRAM1GMX | SYS_XCLK_GPV_PSRAM1G;
      -    cmu->HCLK_ENABLE = SYS_HCLK_PSRAM1G;
      -    cmu->OCLK_ENABLE = SYS_OCLK_PSRAM1G;
       
      +    lock = int_lock();
      +    low_sys_freq = freq;
      +    hal_cmu_sys_set_freq(hal_sysfreq_get_hw_freq());
           int_unlock(lock);
      -
      -    return 0;
      -}
      -
      -void hal_cmu_ddr_clock_disable()
      -{
      -    cmu->XCLK_DISABLE = SYS_XCLK_PSRAM1G | SYS_XCLK_PSRAM1GMX | SYS_XCLK_GPV_PSRAM1G;
      -    cmu->OCLK_DISABLE = SYS_OCLK_PSRAM1G;
      -    cmu->HCLK_DISABLE = SYS_HCLK_PSRAM1G;
      -    hal_cmu_pll_disable(HAL_CMU_PLL_DDR, HAL_CMU_PLL_USER_PSRAM);
      -}
      -
      -void hal_cmu_ddr_reset_set()
      -{
      -    cmu->XRESET_SET = SYS_XRST_PSRAM1G | SYS_XRST_PSRAM1GMX | SYS_XRST_GPV_PSRAM1G;
      -    cmu->ORESET_SET = SYS_ORST_PSRAM1G;
      -    cmu->HRESET_SET = SYS_HRST_PSRAM1G;
      -}
      -
      -void hal_cmu_ddr_reset_clear()
      -{
      -    cmu->XRESET_CLR = SYS_XRST_PSRAM1G | SYS_XRST_PSRAM1GMX | SYS_XRST_GPV_PSRAM1G;
      -    cmu->ORESET_CLR = SYS_ORST_PSRAM1G;
      -    cmu->HRESET_CLR = SYS_HRST_PSRAM1G;
      -}
      -
      -int hal_cmu_dsp_set_freq(enum HAL_CMU_FREQ_T freq);
      -
      -void hal_cmu_dsi_phy_reset_set(void)
      -{
      -    hal_cmu_reset_set(HAL_CMU_MOD_Q_DSI_32K);
      -    hal_cmu_reset_set(HAL_CMU_MOD_Q_DSI_PN);
      -    hal_cmu_reset_set(HAL_CMU_MOD_Q_DSI_TV);
      -    hal_cmu_reset_set(HAL_CMU_MOD_Q_DSI_PIX);
      -    hal_cmu_reset_set(HAL_CMU_MOD_Q_DSI_DSI);
       }
       
      -void hal_cmu_dsi_phy_reset_clear(void)
      -{
      -    // TODO: Move clock enable APIs out
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_32K);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_PN);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_TV);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_PIX);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_DSI);
      -
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_32K);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_PN);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_TV);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_PIX);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_DSI);
      -}
      -
      -void hal_cmu_dsi_clock_enable(void)
      -{
      -#if !defined(DSP_ENABLE) && !defined(CHIP_BEST2003_DSP)
      -    hal_cmu_dsp_clock_enable();
      -    hal_cmu_dsp_reset_clear();
      -    hal_sys_timer_delay(US_TO_TICKS(10));
      -#endif
      -    hal_cmu_dsp_set_freq(HAL_CMU_FREQ_780M);
      -    cmu->DSP_DIV = SET_BITFIELD(cmu->DSP_DIV, CMU_CFG_DIV_APCLK, 0x0);
      -    hal_cmu_pll_enable(HAL_CMU_PLL_DSI, HAL_CMU_PLL_USER_DSI);
      -    cmu->APCLK_ENABLE = SYS_APCLK_DISPLAY;
      -    aoncmu->MIPI_CLK = AON_CMU_EN_CLK_PIX_DSI | AON_CMU_POL_CLK_DSI_IN |
      -        SET_BITFIELD(aoncmu->MIPI_CLK, AON_CMU_CFG_DIV_PIX_DSI, 0x4);
      -    cmu->QCLK_ENABLE = SYS_QCLK_DSI_DSI | SYS_QCLK_DSI_PIX;
      -    hal_sys_timer_delay_us(10);
      -    hal_cmu_dsi_reset_set();//QR DSI/PIX CLK bit 4/5; APR APB CLK bit 8
      -    hal_sys_timer_delay(US_TO_TICKS(10));
      -    hal_cmu_dsi_reset_clear();
      -}
      -
      -void hal_cmu_dsi_clock_enable_v2(uint8_t pixel_div)
      -{
      -    hal_cmu_dsp_set_freq(HAL_CMU_FREQ_780M);
      -    cmu->DSP_DIV = SET_BITFIELD(cmu->DSP_DIV, CMU_CFG_DIV_APCLK, 0x0);
      -    hal_cmu_pll_enable(HAL_CMU_PLL_DSI, HAL_CMU_PLL_USER_DSI);
      -    cmu->APCLK_ENABLE = SYS_APCLK_DISPLAY;
      -    aoncmu->MIPI_CLK = AON_CMU_EN_CLK_PIX_DSI | AON_CMU_POL_CLK_DSI_IN |
      -        SET_BITFIELD(aoncmu->MIPI_CLK, AON_CMU_CFG_DIV_PIX_DSI, pixel_div);
      -    cmu->QCLK_ENABLE = SYS_QCLK_DSI_DSI | SYS_QCLK_DSI_PIX;
      -    hal_sys_timer_delay_us(10);
      -}
      -
      -void hal_cmu_dsi_clock_disable(void)
      -{
      -    aoncmu->MIPI_CLK &= ~(AON_CMU_EN_CLK_PIX_DSI | AON_CMU_POL_CLK_DSI_IN);
      -    cmu->QCLK_DISABLE = SYS_QCLK_DSI_DSI | SYS_QCLK_DSI_PIX;
      -    cmu->APCLK_DISABLE = SYS_APCLK_DISPLAY;
      -    hal_cmu_pll_disable(HAL_CMU_PLL_DSI, HAL_CMU_PLL_USER_DSI);
      -}
      -
      -void hal_cmu_dsi_reset_set(void)
      -{
      -    cmu->QRESET_SET = SYS_QRST_DSI_DSI | SYS_QRST_DSI_PIX;
      -    cmu->APRESET_SET = SYS_APRST_DISPLAY;
      -}
      -
      -void hal_cmu_dsi_reset_clear(void)
      -{
      -    cmu->APRESET_CLR = SYS_APRST_DISPLAY;
      -    cmu->QRESET_CLR = SYS_QRST_DSI_DSI | SYS_QRST_DSI_PIX;
      -    hal_sys_timer_delay_us(10);
      -}
      -
      -void hal_cmu_dsi_sleep(void)
      -{
      -    hal_cmu_dsi_clock_disable();
      -}
      -
      -void hal_cmu_dsi_wakeup(void)
      -{
      -    hal_cmu_dsi_clock_enable();
      -}
      -
      -void hal_cmu_lcdc_clock_enable(void)
      -{
      -    hal_cmu_lcdc_reset_clear();
      -    cmu->XCLK_ENABLE = SYS_XCLK_DSI | SYS_XCLK_DISPLAYX | SYS_XCLK_DISPLAYH;
      -    cmu->QCLK_ENABLE = SYS_QCLK_DSI_32K | SYS_QCLK_DSI_PN | SYS_QCLK_DSI_TV;
      -
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_32K);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_PN);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_TV);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_PIX);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_Q_DSI_DSI);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_32K);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_PN);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_TV);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_PIX);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_Q_DSI_DSI);
      -}
      -
      -void hal_cmu_lcdc_clock_disable(void)
      -{
      -    cmu->QCLK_DISABLE = SYS_QCLK_DSI_32K | SYS_QCLK_DSI_PN | SYS_QCLK_DSI_TV;
      -    cmu->XCLK_DISABLE = SYS_XCLK_DSI | SYS_XCLK_DISPLAYX | SYS_XCLK_DISPLAYH;
      -}
      -
      -void hal_cmu_lcdc_reset_set(void)
      -{
      -    cmu->QRESET_SET = SYS_QRST_DSI_32K | SYS_QRST_DSI_PN | SYS_QRST_DSI_TV;
      -    cmu->XRESET_SET = SYS_XRST_DSI | SYS_XRST_DISPLAYX | SYS_XRST_DISPLAYH;
      -}
      -
      -void hal_cmu_lcdc_reset_clear(void)
      -{
      -    cmu->XRESET_CLR = SYS_XRST_DSI | SYS_XRST_DISPLAYX | SYS_XRST_DISPLAYH;
      -    cmu->QRESET_CLR = SYS_QRST_DSI_32K | SYS_QRST_DSI_PN | SYS_QRST_DSI_TV;
      -    hal_sys_timer_delay_us(10);
      -}
      -
      -void hal_cmu_lcdc_sleep(void)
      -{
      -    hal_cmu_lcdc_clock_disable();
      -}
      -
      -void hal_cmu_lcdc_wakeup(void)
      -{
      -    hal_cmu_lcdc_clock_enable();
      -}
      -void hal_cmu_csi_clock_enable(void)
      -{
      -    cmu->DSP_DIV = SET_BITFIELD(cmu->DSP_DIV, CMU_CFG_DIV_APCLK, 0x0);
      -    aoncmu->MIPI_CLK = AON_CMU_EN_CLK_PIX_CSI | AON_CMU_POL_CLK_CSI_IN |
      -        SET_BITFIELD(aoncmu->MIPI_CLK, AON_CMU_CFG_DIV_PIX_CSI, 0x7); //0xa:240M 1lane
      -    cmu->APCLK_ENABLE = SYS_APCLK_CSI;
      -    cmu->XCLK_ENABLE = SYS_XCLK_CSI;
      -    cmu->QCLK_ENABLE = SYS_QCLK_CSI_LANE | SYS_QCLK_CSI_PIX | SYS_QCLK_CSI_LANG;
      -
      -    hal_cmu_clock_set_mode(HAL_CMU_MOD_Q_CSI_LANE, HAL_CMU_CLK_AUTO);
      -    hal_cmu_clock_set_mode(HAL_CMU_MOD_Q_CSI_PIX, HAL_CMU_CLK_AUTO);
      -    hal_cmu_clock_set_mode(HAL_CMU_MOD_Q_CSI_LANG, HAL_CMU_CLK_AUTO);
      -}
      -
      -void hal_cmu_csi_clock_disable(void)
      -{
      -    cmu->XCLK_DISABLE = SYS_XCLK_CSI;
      -    cmu->QCLK_ENABLE = SYS_QCLK_CSI_LANE | SYS_QCLK_CSI_PIX | SYS_QCLK_CSI_LANG;
      -    cmu->APCLK_DISABLE = SYS_APCLK_CSI;
      -    aoncmu->MIPI_CLK &= ~(AON_CMU_EN_CLK_PIX_CSI | AON_CMU_POL_CLK_CSI_IN);
      -}
      -
      -void hal_cmu_csi_reset_set(void)
      +int hal_cmu_fast_timer_offline(void)
       {
      -    cmu->XRESET_SET = SYS_XRST_CSI;
      -    cmu->QRESET_SET = SYS_QRST_CSI_LANE | SYS_QRST_CSI_PIX | SYS_QRST_CSI_LANG;
      -    cmu->APRESET_SET = SYS_APRST_CSI;
      +    return low_sys_freq_en && low_sys_freq != HAL_CMU_LOW_SYS_FREQ_13M;
       }
       
      -void hal_cmu_csi_reset_clear(void)
      +static void hal_cmu_osc_to_dig_x4_enable(void)
       {
      -    cmu->APRESET_CLR = SYS_APRST_CSI;
      -    cmu->XRESET_CLR = SYS_XRST_CSI;
      -    cmu->QRESET_CLR = SYS_QRST_CSI_LANE | SYS_QRST_CSI_PIX | SYS_QRST_CSI_LANG;
      -    hal_sys_timer_delay_us(10);
      +    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_X4_ANA_ENABLE;
      +    aoncmu->CLK_SELECT |= AON_CMU_SEL_X4_SYS;
      +    aoncmu->CLK_SELECT |= AON_CMU_SEL_X4_DIG;
      +    aoncmu->RESERVED_03C |= AON_CMU_OSC_TO_DIG_X4;
       }
       
      -#ifdef LOW_SYS_FREQ
      -#ifdef LOW_SYS_FREQ_6P5M
      -int hal_cmu_fast_timer_offline(void)
      +static void hal_cmu_osc_to_dig_x4_disable(void)
       {
      -    return (cmu_sys_freq == HAL_CMU_FREQ_6P5M);
      -}
      +    aoncmu->CLK_SELECT &= ~AON_CMU_SEL_X4_DIG;
      +    aoncmu->RESERVED_03C &= ~AON_CMU_OSC_TO_DIG_X4;
      +#ifndef OSC_26M_X4_AUD2BB
      +    aoncmu->CLK_SELECT &= ~AON_CMU_SEL_X4_SYS;
       #endif
      +#ifndef ANA_26M_X4_ENABLE
      +    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_X4_ANA_DISABLE;
       #endif
      -
      -#ifdef CHIP_BEST2003_DSP
      -
      -int hal_cmu_sys_set_freq(enum HAL_CMU_FREQ_T freq) __attribute__((alias("hal_cmu_dsp_set_freq")));
      -
      -enum HAL_CMU_FREQ_T hal_cmu_sys_get_freq(void) __attribute__((alias("hal_cmu_dsp_get_freq")));
      -
      -#else // !CHIP_BEST2003_DSP
      +}
       
       int hal_cmu_sys_set_freq(enum HAL_CMU_FREQ_T freq)
       {
      +    uint32_t lock;
           uint32_t enable;
           uint32_t disable;
      -    int div;
      -    uint32_t lock;
      +    int div = -1;
      +    bool low_sys_set, low_sys_clr;
       
           if (freq >= HAL_CMU_FREQ_QTY) {
               return 1;
           }
       
      -#ifdef LOW_SYS_FREQ
      -    cmu_sys_freq = freq;
      -#endif
      -
      -    div = -1;
      -
      -    switch (freq) {
      -    case HAL_CMU_FREQ_32K:
      -        enable = 0;
      -        disable = CMU_RSTN_DIV_MCU_DISABLE | CMU_BYPASS_DIV_MCU_DISABLE | CMU_SEL_MCU_OSC_4_DISABLE | CMU_SEL_MCU_OSC_2_DISABLE |
      -            CMU_SEL_MCU_OSCX4_DISABLE | CMU_SEL_MCU_SLOW_DISABLE | CMU_SEL_MCU_FAST_DISABLE | CMU_SEL_MCU_PLL_DISABLE;
      -        break;
      -    case HAL_CMU_FREQ_6P5M:
      -#if defined(LOW_SYS_FREQ) && defined(LOW_SYS_FREQ_6P5M)
      -        enable = CMU_SEL_MCU_OSC_4_ENABLE;
      -        disable = CMU_RSTN_DIV_MCU_DISABLE | CMU_BYPASS_DIV_MCU_DISABLE |
      -            CMU_SEL_MCU_OSCX4_DISABLE | CMU_SEL_MCU_SLOW_DISABLE | CMU_SEL_MCU_FAST_DISABLE | CMU_SEL_MCU_PLL_DISABLE;
      -        break;
      -#endif
      -    case HAL_CMU_FREQ_13M:
      -#ifdef LOW_SYS_FREQ
      -        enable = CMU_SEL_MCU_OSC_2_ENABLE | CMU_SEL_MCU_SLOW_ENABLE;
      -        disable = CMU_RSTN_DIV_MCU_DISABLE | CMU_BYPASS_DIV_MCU_DISABLE |
      -            CMU_SEL_MCU_OSCX4_DISABLE | CMU_SEL_MCU_FAST_DISABLE | CMU_SEL_MCU_PLL_DISABLE;
      -        break;
      -#endif
      -    case HAL_CMU_FREQ_26M:
      -        enable = CMU_SEL_MCU_SLOW_ENABLE;
      -        disable = CMU_RSTN_DIV_MCU_DISABLE | CMU_BYPASS_DIV_MCU_DISABLE | CMU_SEL_MCU_OSC_2_ENABLE |
      -            CMU_SEL_MCU_OSCX4_DISABLE | CMU_SEL_MCU_FAST_DISABLE | CMU_SEL_MCU_PLL_DISABLE;
      -        break;
      -    case HAL_CMU_FREQ_52M:
      -        enable = CMU_SEL_MCU_FAST_ENABLE;
      -        disable = CMU_RSTN_DIV_MCU_DISABLE | CMU_BYPASS_DIV_MCU_DISABLE |
      -            CMU_SEL_MCU_OSCX4_DISABLE | CMU_SEL_MCU_PLL_DISABLE;
      -        break;
      -    case HAL_CMU_FREQ_78M:
      -    case HAL_CMU_FREQ_104M:
      -#ifdef OSC_26M_X4_AUD2BB
      -        enable = CMU_SEL_MCU_OSCX4_ENABLE | CMU_SEL_MCU_FAST_ENABLE;
      -        disable = CMU_RSTN_DIV_MCU_DISABLE | CMU_BYPASS_DIV_MCU_DISABLE | CMU_SEL_MCU_PLL_DISABLE;
      -        break;
      -#endif
      -    case HAL_CMU_FREQ_156M:
      -    case HAL_CMU_FREQ_208M:
      -    case HAL_CMU_FREQ_260M:
      -        enable = CMU_RSTN_DIV_MCU_ENABLE | CMU_SEL_MCU_PLL_ENABLE;
      -        disable = CMU_BYPASS_DIV_MCU_DISABLE;
      -        if (0) {
      -#ifndef OSC_26M_X4_AUD2BB
      -        } else if (freq <= HAL_CMU_FREQ_78M) {
      -            div = 3;
      -        } else if (freq <= HAL_CMU_FREQ_104M) {
      -            div = 2;
      -#endif
      -        } else if (freq <= HAL_CMU_FREQ_156M) {
      -            div = 1;
      -        } else { // 208M or 260M
      -            div = 0;
      -        }
      -        break;
      -    case HAL_CMU_FREQ_390M:
      -    case HAL_CMU_FREQ_780M:
      -    default:
      -        enable = CMU_BYPASS_DIV_MCU_ENABLE | CMU_SEL_MCU_PLL_ENABLE;
      -        disable = CMU_RSTN_DIV_MCU_DISABLE;
      -        break;
      -    };
      +    low_sys_set = false;
      +    low_sys_clr = false;
       
      -    if (div >= 0) {
      -        lock = int_lock();
      -        cmu->SYS_DIV = SET_BITFIELD(cmu->SYS_DIV, CMU_CFG_DIV_MCU, div);
      -        int_unlock(lock);
      -    }
      +    lock = int_lock();
       
      -    if (enable & CMU_SEL_MCU_PLL_ENABLE) {
      -        cmu->SYS_CLK_ENABLE = CMU_RSTN_DIV_MCU_ENABLE;
      -        if (enable & CMU_BYPASS_DIV_MCU_ENABLE) {
      -            cmu->SYS_CLK_ENABLE = CMU_BYPASS_DIV_MCU_ENABLE;
      -        } else {
      -            cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_MCU_DISABLE;
      +    if (low_sys_freq == HAL_CMU_LOW_SYS_FREQ_NONE) {
      +        if (aoncmu->RESERVED_03C & AON_CMU_OSC_TO_DIG_X4) {
      +            low_sys_clr = true;
               }
      -    }
      -    cmu->SYS_CLK_ENABLE = enable;
      -    if (enable & CMU_SEL_MCU_PLL_ENABLE) {
      -        cmu->SYS_CLK_DISABLE = disable;
           } else {
      -        cmu->SYS_CLK_DISABLE = disable & ~(CMU_RSTN_DIV_MCU_DISABLE | CMU_BYPASS_DIV_MCU_DISABLE);
      -        cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_MCU_DISABLE;
      -        cmu->SYS_CLK_DISABLE = CMU_RSTN_DIV_MCU_DISABLE;
      -    }
      -
      -    return 0;
      -}
      -
      -enum HAL_CMU_FREQ_T BOOT_TEXT_SRAM_LOC hal_cmu_sys_get_freq(void)
      -{
      -    uint32_t sys_clk;
      -    uint32_t div;
      -
      -    sys_clk = cmu->SYS_CLK_ENABLE;
      -
      -    if (sys_clk & CMU_SEL_MCU_PLL_ENABLE) {
      -        if (sys_clk & CMU_BYPASS_DIV_MCU_ENABLE) {
      -            // 384M
      -            return HAL_CMU_FREQ_390M;
      -        } else {
      -            div = GET_BITFIELD(cmu->SYS_DIV, CMU_CFG_DIV_MCU);
      -            if (div == 0) {
      -                // 192M
      -                return HAL_CMU_FREQ_208M;
      -            } else if (div == 1) {
      -                // 128M
      -                return HAL_CMU_FREQ_156M;
      -            } else if (div == 2) {
      -                // 96M
      -                return HAL_CMU_FREQ_104M;
      -            } else { // div == 3
      -                // 76.8M
      -                return HAL_CMU_FREQ_78M;
      +        if (freq == HAL_CMU_FREQ_26M) {
      +            low_sys_set = true;
      +        } else if (freq > HAL_CMU_FREQ_26M) {
      +            if (aoncmu->RESERVED_03C & AON_CMU_OSC_TO_DIG_X4) {
      +                low_sys_clr = true;
                   }
               }
      -    } else if (sys_clk & CMU_SEL_MCU_FAST_ENABLE) {
      -        if (sys_clk & CMU_SEL_MCU_OSCX4_ENABLE) {
      -            return HAL_CMU_FREQ_104M;
      -        } else {
      -            return HAL_CMU_FREQ_52M;
      -        }
      -    } else if (sys_clk & CMU_SEL_MCU_SLOW_ENABLE) {
      -        return HAL_CMU_FREQ_26M;
      -    } else {
      -        return HAL_CMU_FREQ_32K;
           }
      -}
      -
      -#endif // !CHIP_BEST2003_DSP
      -
      -int hal_cmu_dsp_set_freq(enum HAL_CMU_FREQ_T freq)
      -{
      -    uint32_t enable;
      -    uint32_t disable;
      -    int div;
      -    uint32_t lock;
       
      -    if (freq >= HAL_CMU_FREQ_QTY) {
      -        return 1;
      +    if (low_sys_clr) {
      +        low_sys_freq_en = false;
      +        cmu->SYS_CLK_ENABLE = CMU_SEL_OSC_SYS_ENABLE;
      +        cmu->SYS_CLK_DISABLE = CMU_SEL_OSCX2_SYS_DISABLE | CMU_SEL_PLL_SYS_DISABLE;
      +        hal_cmu_osc_to_dig_x4_disable();
      +    }
      +    if (low_sys_set) {
      +        low_sys_freq_en = true;
      +        cmu->SYS_CLK_ENABLE = CMU_SEL_OSC_SYS_ENABLE;
      +        cmu->SYS_CLK_DISABLE = CMU_SEL_OSCX2_SYS_DISABLE | CMU_SEL_PLL_SYS_DISABLE;
      +        hal_cmu_osc_to_dig_x4_enable();
      +        freq = HAL_CMU_FREQ_208M;
           }
       
      -#ifdef CHIP_BEST2003_DSP
      -#ifdef LOW_SYS_FREQ
      -    cmu_sys_freq = freq;
      -#endif
      -#endif
      -
      -    div = -1;
      -
      -    switch (freq) {
      -    case HAL_CMU_FREQ_32K:
      +    if (freq == HAL_CMU_FREQ_32K) {
               enable = 0;
      -        disable = CMU_RSTN_DIV_A7_DISABLE | CMU_BYPASS_DIV_A7_DISABLE | CMU_SEL_A7_OSC_4_DISABLE | CMU_SEL_A7_OSC_2_DISABLE |
      -            CMU_SEL_A7_OSCX4_DISABLE | CMU_SEL_A7_SLOW_DISABLE | CMU_SEL_A7_FAST_DISABLE | CMU_SEL_A7_PLL_DISABLE;
      -        break;
      -    case HAL_CMU_FREQ_6P5M:
      -#if defined(LOW_SYS_FREQ) && defined(LOW_SYS_FREQ_6P5M)
      -        enable = CMU_SEL_A7_OSC_4_ENABLE;
      -        disable = CMU_RSTN_DIV_A7_DISABLE | CMU_BYPASS_DIV_A7_DISABLE |
      -            CMU_SEL_A7_OSCX4_DISABLE | CMU_SEL_A7_SLOW_DISABLE | CMU_SEL_A7_FAST_DISABLE | CMU_SEL_A7_PLL_DISABLE;
      -        break;
      -#endif
      -    case HAL_CMU_FREQ_13M:
      -#ifdef LOW_SYS_FREQ
      -        enable = CMU_SEL_A7_OSC_2_ENABLE | CMU_SEL_A7_SLOW_ENABLE;
      -        disable = CMU_RSTN_DIV_A7_DISABLE | CMU_BYPASS_DIV_A7_DISABLE |
      -            CMU_SEL_A7_OSCX4_DISABLE | CMU_SEL_A7_FAST_DISABLE | CMU_SEL_A7_PLL_DISABLE;
      -        break;
      -#endif
      -    case HAL_CMU_FREQ_26M:
      -        enable = CMU_SEL_A7_SLOW_ENABLE;
      -        disable = CMU_RSTN_DIV_A7_DISABLE | CMU_BYPASS_DIV_A7_DISABLE | CMU_SEL_A7_OSC_2_DISABLE |
      -            CMU_SEL_A7_OSCX4_DISABLE | CMU_SEL_A7_FAST_DISABLE | CMU_SEL_A7_PLL_DISABLE;
      -        break;
      -    case HAL_CMU_FREQ_52M:
      -        enable = CMU_SEL_A7_FAST_ENABLE;
      -        disable = CMU_RSTN_DIV_A7_DISABLE | CMU_BYPASS_DIV_A7_DISABLE |
      -            CMU_SEL_A7_OSCX4_DISABLE | CMU_SEL_A7_PLL_DISABLE;
      -        break;
      -    case HAL_CMU_FREQ_78M:
      -    case HAL_CMU_FREQ_104M:
      -#ifdef OSC_26M_X4_AUD2BB
      -        enable = CMU_SEL_A7_OSCX4_ENABLE | CMU_SEL_A7_FAST_ENABLE;
      -        disable = CMU_RSTN_DIV_A7_DISABLE | CMU_BYPASS_DIV_A7_DISABLE | CMU_SEL_A7_PLL_DISABLE;
      -        break;
      -#endif
      -    case HAL_CMU_FREQ_156M:
      -    case HAL_CMU_FREQ_208M:
      -    case HAL_CMU_FREQ_260M:
      -    case HAL_CMU_FREQ_390M:
      -        enable = CMU_RSTN_DIV_A7_ENABLE | CMU_SEL_A7_PLL_ENABLE;
      -        disable = CMU_BYPASS_DIV_A7_DISABLE;
      -        if (0) {
      -        } else if (freq <= HAL_CMU_FREQ_156M) {
      -            div = 3;
      -        } else if (freq <= HAL_CMU_FREQ_208M) {
      -            div = 2;
      -        } else if (freq <= HAL_CMU_FREQ_260M) {
      -            div = 1;
      -        } else { // 390M
      -            div = 0;
      +        disable = CMU_SEL_OSC_SYS_DISABLE | CMU_SEL_OSCX2_SYS_DISABLE |
      +            CMU_SEL_PLL_SYS_DISABLE | CMU_RSTN_DIV_SYS_DISABLE | CMU_BYPASS_DIV_SYS_DISABLE;
      +    } else if (freq == HAL_CMU_FREQ_26M) {
      +        enable = CMU_SEL_OSC_SYS_ENABLE;
      +        disable = CMU_SEL_OSCX2_SYS_DISABLE |
      +            CMU_SEL_PLL_SYS_DISABLE | CMU_RSTN_DIV_SYS_DISABLE | CMU_BYPASS_DIV_SYS_DISABLE;
      +    } else if (freq == HAL_CMU_FREQ_52M) {
      +        enable = CMU_SEL_OSCX2_SYS_ENABLE;
      +        disable = CMU_SEL_PLL_SYS_DISABLE | CMU_RSTN_DIV_SYS_DISABLE | CMU_BYPASS_DIV_SYS_DISABLE;
      +#ifndef OSC_26M_X4_AUD2BB
      +    } else if (freq == HAL_CMU_FREQ_78M) {
      +        enable = CMU_SEL_PLL_SYS_ENABLE | CMU_RSTN_DIV_SYS_ENABLE;
      +        disable = CMU_BYPASS_DIV_SYS_DISABLE;
      +        div = 1;
      +    } else if (freq == HAL_CMU_FREQ_104M) {
      +        enable = CMU_SEL_PLL_SYS_ENABLE | CMU_RSTN_DIV_SYS_ENABLE;
      +        disable = CMU_BYPASS_DIV_SYS_DISABLE;
      +        div = 0;
      +#endif
      +    } else {
      +        if (low_sys_set) {
      +            if (low_sys_freq == HAL_CMU_LOW_SYS_FREQ_13M) {
      +                enable = CMU_SEL_PLL_SYS_ENABLE | CMU_BYPASS_DIV_SYS_ENABLE;
      +                disable = CMU_RSTN_DIV_SYS_DISABLE;
      +            } else {
      +                enable = CMU_SEL_PLL_SYS_ENABLE | CMU_RSTN_DIV_SYS_ENABLE;
      +                disable = CMU_BYPASS_DIV_SYS_DISABLE;
      +                if (low_sys_freq == HAL_CMU_LOW_SYS_FREQ_6P5M) {
      +                    div = 0;
      +                } else if (low_sys_freq == HAL_CMU_LOW_SYS_FREQ_4P33M) {
      +                    div = 1;
      +                } else {
      +                    div = 2;
      +                }
      +            }
      +        } else {
      +            enable = CMU_SEL_PLL_SYS_ENABLE | CMU_BYPASS_DIV_SYS_ENABLE;
      +            disable = CMU_RSTN_DIV_SYS_DISABLE;
               }
      -        break;
      -    case HAL_CMU_FREQ_780M:
      -    default:
      -        enable = CMU_BYPASS_DIV_A7_ENABLE | CMU_SEL_A7_PLL_ENABLE;
      -        disable = CMU_RSTN_DIV_A7_DISABLE;
      -        break;
      -    };
      -
      +    }
           if (div >= 0) {
      -        lock = int_lock();
      -        cmu->DSP_DIV = SET_BITFIELD(cmu->DSP_DIV, CMU_CFG_DIV_A7, div);
      -        int_unlock(lock);
      +        cmu->SYS_DIV = SET_BITFIELD(cmu->SYS_DIV, CMU_CFG_DIV_SYS, div);
           }
      -
      -    if (enable & CMU_SEL_A7_PLL_ENABLE) {
      -        cmu->SYS_CLK_ENABLE = CMU_RSTN_DIV_A7_ENABLE;
      -        if (enable & CMU_BYPASS_DIV_A7_ENABLE) {
      -            cmu->SYS_CLK_ENABLE = CMU_BYPASS_DIV_A7_ENABLE;
      +    if (enable & CMU_SEL_PLL_SYS_ENABLE) {
      +        cmu->SYS_CLK_ENABLE = CMU_RSTN_DIV_SYS_ENABLE;
      +        if (enable & CMU_BYPASS_DIV_SYS_ENABLE) {
      +            cmu->SYS_CLK_ENABLE = CMU_BYPASS_DIV_SYS_ENABLE;
               } else {
      -            cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_A7_DISABLE;
      +            cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_SYS_DISABLE;
               }
           }
           cmu->SYS_CLK_ENABLE = enable;
      -    if (enable & CMU_SEL_A7_PLL_ENABLE) {
      +    if (enable & CMU_SEL_PLL_SYS_ENABLE) {
               cmu->SYS_CLK_DISABLE = disable;
           } else {
      -        cmu->SYS_CLK_DISABLE = disable & ~(CMU_RSTN_DIV_A7_DISABLE | CMU_BYPASS_DIV_A7_DISABLE);
      -        cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_A7_DISABLE;
      -        cmu->SYS_CLK_DISABLE = CMU_RSTN_DIV_A7_DISABLE;
      +        cmu->SYS_CLK_DISABLE = disable & ~(CMU_RSTN_DIV_SYS_DISABLE | CMU_BYPASS_DIV_SYS_DISABLE);
      +        cmu->SYS_CLK_DISABLE = CMU_BYPASS_DIV_SYS_DISABLE;
      +        cmu->SYS_CLK_DISABLE = CMU_RSTN_DIV_SYS_DISABLE;
           }
       
      +    int_unlock(lock);
      +
           return 0;
       }
      +#else
      +SYS_SET_FREQ_FUNC(sys, SYS, {});
      +#endif
       
      -enum HAL_CMU_FREQ_T BOOT_TEXT_SRAM_LOC hal_cmu_dsp_get_freq(void)
      +int hal_cmu_mem_set_freq(enum HAL_CMU_FREQ_T freq)
      +{
      +    return 0;
      +}
      +
      +enum HAL_CMU_FREQ_T BOOT_TEXT_SRAM_LOC hal_cmu_sys_get_freq(void)
       {
           uint32_t sys_clk;
           uint32_t div;
       
           sys_clk = cmu->SYS_CLK_ENABLE;
       
      -    if (sys_clk & CMU_SEL_A7_PLL_ENABLE) {
      -        if (sys_clk & CMU_BYPASS_DIV_A7_ENABLE) {
      -            return HAL_CMU_FREQ_780M;
      +    if (sys_clk & CMU_SEL_PLL_SYS_ENABLE) {
      +        if (sys_clk & CMU_BYPASS_DIV_SYS_ENABLE) {
      +            return HAL_CMU_FREQ_208M;
               } else {
      -            div = GET_BITFIELD(cmu->DSP_DIV, CMU_CFG_DIV_A7);
      +            div = GET_BITFIELD(cmu->SYS_DIV, CMU_CFG_DIV_SYS);
                   if (div == 0) {
      -                return HAL_CMU_FREQ_390M;
      +                return HAL_CMU_FREQ_104M;
                   } else if (div == 1) {
      -                return HAL_CMU_FREQ_260M;
      -            } else if (div == 2) {
      -                return HAL_CMU_FREQ_208M;
      -            } else { // div == 3
      -                return HAL_CMU_FREQ_156M;
      +                // (div == 1): 69M
      +                return HAL_CMU_FREQ_78M;
      +            } else {
      +                // (div == 2): 52M
      +                // (div == 3): 42M
      +                return HAL_CMU_FREQ_52M;
                   }
               }
      -    } else if (sys_clk & CMU_SEL_A7_FAST_ENABLE) {
      -        if (sys_clk & CMU_SEL_A7_OSCX4_ENABLE) {
      -            return HAL_CMU_FREQ_104M;
      -        } else {
      -            return HAL_CMU_FREQ_52M;
      -        }
      -    } else if (sys_clk & CMU_SEL_A7_SLOW_ENABLE) {
      +    } else if (sys_clk & CMU_SEL_OSCX2_SYS_ENABLE) {
      +        return HAL_CMU_FREQ_52M;
      +    } else if (sys_clk & CMU_SEL_OSC_SYS_ENABLE) {
               return HAL_CMU_FREQ_26M;
           } else {
               return HAL_CMU_FREQ_32K;
      @@ -1247,113 +797,47 @@ enum HAL_CMU_FREQ_T BOOT_TEXT_SRAM_LOC hal_cmu_dsp_get_freq(void)
       
       int BOOT_TEXT_SRAM_LOC hal_cmu_flash_select_pll(enum HAL_CMU_PLL_T pll)
       {
      -    return 0;
      -}
      -
      -int BOOT_TEXT_SRAM_LOC hal_cmu_flash1_select_pll(enum HAL_CMU_PLL_T pll)
      -{
      -    return 0;
      +    return hal_cmu_sys_select_pll(pll);
       }
       
       int hal_cmu_mem_select_pll(enum HAL_CMU_PLL_T pll)
       {
      -    return 0;
      +    return hal_cmu_sys_select_pll(pll);
       }
       
      -int hal_cmu_dsp_select_pll(enum HAL_CMU_PLL_T pll)
      +// hal_cmu_flash_select_pll() requires in BOOT_TEXT_SRAM_LOC
      +int BOOT_TEXT_SRAM_LOC hal_cmu_sys_select_pll(enum HAL_CMU_PLL_T pll)
       {
           uint32_t lock;
      -    uint32_t set;
      -    uint32_t clr;
      -
      -    if (pll == HAL_CMU_PLL_USB) {
      -        set = AON_CMU_SEL_A7_PLLUSB | AON_CMU_SEL_A7_PLLBB;
      -        clr = 0;
      -    } else if (pll == HAL_CMU_PLL_DSP) {
      -        set = 0;
      -        clr = AON_CMU_SEL_A7_PLLUSB | AON_CMU_SEL_A7_PLLBB;
      -    } else if (pll == HAL_CMU_PLL_BB) {
      -        set = AON_CMU_SEL_A7_PLLBB;
      -        clr = AON_CMU_SEL_A7_PLLUSB;
      -    } else {
      -        // == HAL_CMU_PLL_DDR or == HAL_CMU_PLL_BB_PSRAM or >= HAL_CMU_PLL_QTY
      -        return 1;
      -    }
      -
      -    lock = int_lock();
      -    aoncmu->DSP_PLL_SELECT = (aoncmu->DSP_PLL_SELECT & ~clr) | set;
      -    int_unlock(lock);
      -
      -    return 0;
      -}
      +    uint32_t sel;
       
      -int BOOT_TEXT_FLASH_LOC hal_cmu_sys_select_pll(enum HAL_CMU_PLL_T pll)
      -{
      -    uint32_t lock;
      -    uint32_t set;
      -    uint32_t clr;
      -
      -    if (pll == HAL_CMU_PLL_USB) {
      -        set = AON_CMU_SEL_MCU_PLLUSB | AON_CMU_SEL_MCU_PLLA7USB;
      -        clr = AON_CMU_SEL_MCU_PLLBB_PS;
      -    } else if (pll == HAL_CMU_PLL_DSP) {
      -        set = AON_CMU_SEL_MCU_PLLA7USB;
      -        clr = AON_CMU_SEL_MCU_PLLBB_PS | AON_CMU_SEL_MCU_PLLUSB;
      -    } else if (pll == HAL_CMU_PLL_BB) {
      -        set = 0;
      -        clr = AON_CMU_SEL_MCU_PLLBB_PS | AON_CMU_SEL_MCU_PLLUSB | AON_CMU_SEL_MCU_PLLA7USB;
      -    } else if (pll == HAL_CMU_PLL_BB_PSRAM) {
      -        set = AON_CMU_SEL_MCU_PLLBB_PS;
      -        clr = AON_CMU_SEL_MCU_PLLUSB | AON_CMU_SEL_MCU_PLLA7USB;
      -    } else {
      -        // == HAL_CMU_PLL_DDR or >= HAL_CMU_PLL_QTY
      +    if (pll >= HAL_CMU_PLL_QTY) {
               return 1;
           }
       
           lock = int_lock();
      -    aoncmu->FLS_PSR_CLK = (aoncmu->FLS_PSR_CLK & ~clr) | set;
      +    // 0/1:bbpll, 2:audpll, 3:usbpll
      +    sel = (pll == HAL_CMU_PLL_AUD) ? 2 : 0;
      +    aoncmu->CLK_SELECT = SET_BITFIELD(aoncmu->CLK_SELECT, AON_CMU_SEL_PLL_SYS, sel);
           int_unlock(lock);
       
           return 0;
       }
       
      -int BOOT_TEXT_FLASH_LOC hal_cmu_audio_select_pll(enum HAL_CMU_PLL_T pll)
      -{
      -    if (pll == HAL_CMU_PLL_BB) {
      -        aoncmu->PCM_I2S_CLK &= ~AON_CMU_SEL_AUD_PLLUSB;
      -    } else {
      -        aoncmu->PCM_I2S_CLK |= AON_CMU_SEL_AUD_PLLUSB;
      -    }
      -
      -    return 0;
      -}
      -
       int hal_cmu_get_pll_status(enum HAL_CMU_PLL_T pll)
       {
      -    bool en;
      -
      -    if (pll == HAL_CMU_PLL_USB) {
      -        en = !!(aoncmu->TOP_CLK_ENABLE & AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE);
      -    } else if (pll == HAL_CMU_PLL_DDR) {
      -        en = !!(aoncmu->TOP_CLK_ENABLE & AON_CMU_EN_CLK_TOP_PLLDDR_ENABLE);
      -    } else if (pll == HAL_CMU_PLL_DSP) {
      -        en = !!(aoncmu->TOP_CLK_ENABLE & AON_CMU_EN_CLK_TOP_PLLA7_ENABLE);
      -    } else if (pll == HAL_CMU_PLL_BB) {
      -        en = !!(aoncmu->TOP_CLK_ENABLE & AON_CMU_EN_CLK_TOP_PLLBB_ENABLE);
      -    } else if (pll == HAL_CMU_PLL_BB_PSRAM) {
      -        en = !!(aoncmu->TOP_CLK_ENABLE & AON_CMU_EN_CLK_TOP_PLLBB_PS_ENABLE);
      -    } else {
      -        en = false;
      -    }
      -
      -    return en;
      +    return !!(aoncmu->TOP_CLK_ENABLE & ((pll == HAL_CMU_PLL_AUD) ? AON_CMU_EN_CLK_TOP_PLLAUD_ENABLE : AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE));
       }
       
      -int BOOT_TEXT_FLASH_LOC hal_cmu_pll_enable(enum HAL_CMU_PLL_T pll, enum HAL_CMU_PLL_USER_T user)
      +int hal_cmu_pll_enable(enum HAL_CMU_PLL_T pll, enum HAL_CMU_PLL_USER_T user)
       {
           uint32_t pu_val;
           uint32_t en_val;
      +    uint32_t check;
           uint32_t lock;
      +    uint32_t sel;
      +    uint32_t start;
      +    uint32_t timeout;
       
           if (pll >= HAL_CMU_PLL_QTY) {
               return 1;
      @@ -1362,66 +846,80 @@ int BOOT_TEXT_FLASH_LOC hal_cmu_pll_enable(enum HAL_CMU_PLL_T pll, enum HAL_CMU_
               return 2;
           }
       
      -    if (pll == HAL_CMU_PLL_USB) {
      -        pu_val = AON_CMU_PU_PLLDSI_ENABLE | AON_CMU_PU_PLLDSI_DIV_PS_ENABLE;
      -        en_val = AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE;
      -    } else if (pll == HAL_CMU_PLL_DDR) {
      -        pu_val = AON_CMU_PU_PLLDDR_ENABLE;
      -        en_val = AON_CMU_EN_CLK_TOP_PLLDDR_ENABLE;
      -    } else if (pll == HAL_CMU_PLL_DSP) {
      -        pu_val = AON_CMU_PU_PLLA7_ENABLE;
      -        en_val = AON_CMU_EN_CLK_TOP_PLLA7_ENABLE;
      -    } else if (pll == HAL_CMU_PLL_BB) {
      -#ifdef BBPLL_USE_DSI_MCUPLL
      -        pu_val = AON_CMU_PU_PLLDSI_ENABLE | AON_CMU_PU_PLLDSI_DIV_MCU_ENABLE;
      -#else
      -        pu_val = AON_CMU_PU_PLLBB_ENABLE | AON_CMU_PU_PLLBB_DIV_MCU_ENABLE;
      +#ifdef USB_USE_USBPLL
      +    if (pll == HAL_CMU_PLL_USB && user == HAL_CMU_PLL_USER_USB) {
      +        pll = HAL_CMU_PLL_USB_HS;
      +    }
       #endif
      -        en_val = AON_CMU_EN_CLK_TOP_PLLBB_ENABLE;
      -    } else if (pll == HAL_CMU_PLL_BB_PSRAM) {
      -#ifdef BB_PSRAMPLL_USE_DSI_PSRAMPLL
      -        pu_val = AON_CMU_PU_PLLDSI_ENABLE | AON_CMU_PU_PLLDSI_DIV_PS_ENABLE;
      -#else
      -        pu_val = AON_CMU_PU_PLLBB_ENABLE | AON_CMU_PU_PLLBB_DIV_PS_ENABLE;
      +
      +    if (pll == HAL_CMU_PLL_AUD) {
      +        pu_val = AON_CMU_PU_PLLAUD_ENABLE;
      +        en_val = AON_CMU_EN_CLK_TOP_PLLAUD_ENABLE;
      +        check = AON_CMU_LOCK_PLLAUD;
      +#ifdef USB_USE_USBPLL
      +    } else if (pll == HAL_CMU_PLL_USB_HS) {
      +        pu_val = AON_CMU_PU_PLLUSB_ENABLE;
      +        en_val = AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE;
      +        check = AON_CMU_LOCK_PLLUSB;
       #endif
      -        en_val = AON_CMU_EN_CLK_TOP_PLLBB_PS_ENABLE;
      -    } else if (pll == HAL_CMU_PLL_DSI) {
      -        pu_val = AON_CMU_PU_PLLDSI_ENABLE;
      -        en_val = 0;
           } else {
      -        pu_val = 0;
      -        en_val = 0;
      +        pu_val = AON_CMU_PU_PLLBB_ENABLE;
      +        en_val = AON_CMU_EN_CLK_TOP_PLLBB_ENABLE;
      +        check = AON_CMU_LOCK_PLLBB;
           }
       
           lock = int_lock();
      -
           if (pll_user_map[pll] == 0 || user == HAL_CMU_PLL_USER_ALL) {
       #ifndef ROM_BUILD
               pmu_pll_div_reset_set(pll);
       #endif
      -        aoncmu->PLL_ENABLE = pu_val;
      +        aoncmu->TOP_CLK_ENABLE = pu_val;
       #ifndef ROM_BUILD
               hal_sys_timer_delay_us(20);
               pmu_pll_div_reset_clear(pll);
               // Wait at least 10us for clock ready
      -        hal_sys_timer_delay_us(10);
       #endif
      -        aoncmu->TOP_CLK_ENABLE = en_val;
      +    } else {
      +        check = 0;
           }
           if (user < HAL_CMU_PLL_USER_QTY) {
               pll_user_map[pll] |= (1 << user);
      -    } else if (user == HAL_CMU_PLL_USER_ALL) {
      -        pll_user_map[pll] |= ((1 << user) - 1);
           }
      +    if (user == HAL_CMU_PLL_USER_AUD) {
      +        // 0/1:audpll, 2:bbpll, 3:usbpll
      +        sel = (pll == HAL_CMU_PLL_AUD) ? 0 : 2;
      +        aoncmu->CLK_SELECT = SET_BITFIELD(aoncmu->CLK_SELECT, AON_CMU_SEL_PLL_AUD, sel);
      +    }
      +    // HAL_CMU_PLL_USER_SYS selects PLL in hal_cmu_sys_select_pll()
           int_unlock(lock);
       
      -    return 0;
      +    start = hal_sys_timer_get();
      +    timeout = HAL_CMU_PLL_LOCKED_TIMEOUT;
      +    do {
      +        if (check) {
      +            if (aoncmu->CODEC_DIV & check) {
      +                //break;
      +            }
      +        } else {
      +            if (aoncmu->TOP_CLK_ENABLE & en_val) {
      +                break;
      +            }
      +        }
      +    } while ((hal_sys_timer_get() - start) < timeout);
      +
      +    aoncmu->TOP_CLK_ENABLE = en_val;
      +
      +#ifndef USB_USE_USBPLL
      +    if (pll == HAL_CMU_PLL_USB && user == HAL_CMU_PLL_USER_USB) {
      +        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLBB2_ENABLE;
      +    }
      +#endif
      +
      +    return (aoncmu->CODEC_DIV & check) ? 0 : 2;
       }
       
      -int BOOT_TEXT_FLASH_LOC hal_cmu_pll_disable(enum HAL_CMU_PLL_T pll, enum HAL_CMU_PLL_USER_T user)
      +int hal_cmu_pll_disable(enum HAL_CMU_PLL_T pll, enum HAL_CMU_PLL_USER_T user)
       {
      -    uint32_t pu_val;
      -    uint32_t en_val;
           uint32_t lock;
       
           if (pll >= HAL_CMU_PLL_QTY) {
      @@ -1431,75 +929,31 @@ int BOOT_TEXT_FLASH_LOC hal_cmu_pll_disable(enum HAL_CMU_PLL_T pll, enum HAL_CMU
               return 2;
           }
       
      -    if (pll == HAL_CMU_PLL_USB) {
      -        pu_val = 0;
      -        en_val = AON_CMU_EN_CLK_TOP_PLLUSB_DISABLE;
      -    } else if (pll == HAL_CMU_PLL_DDR) {
      -        pu_val = AON_CMU_PU_PLLDDR_DISABLE;
      -        en_val = AON_CMU_EN_CLK_TOP_PLLDDR_DISABLE;
      -    } else if (pll == HAL_CMU_PLL_DSP) {
      -        pu_val = AON_CMU_PU_PLLA7_DISABLE;
      -        en_val = AON_CMU_EN_CLK_TOP_PLLA7_DISABLE;
      -    } else if (pll == HAL_CMU_PLL_BB) {
      -#ifdef BBPLL_USE_DSI_MCUPLL
      -        pu_val = AON_CMU_PU_PLLDSI_DIV_MCU_DISABLE;
      -#else
      -        pu_val = AON_CMU_PU_PLLBB_DIV_MCU_DISABLE;
      -#endif
      -        en_val = AON_CMU_EN_CLK_TOP_PLLBB_DISABLE;
      -    } else if (pll == HAL_CMU_PLL_BB_PSRAM) {
      -#ifdef BB_PSRAMPLL_USE_DSI_PSRAMPLL
      -        pu_val = AON_CMU_PU_PLLDSI_DIV_PS_DISABLE;
      +    if (pll == HAL_CMU_PLL_USB && user == HAL_CMU_PLL_USER_USB) {
      +#ifdef USB_USE_USBPLL
      +        pll = HAL_CMU_PLL_USB_HS;
       #else
      -        pu_val = AON_CMU_PU_PLLBB_DIV_PS_DISABLE;
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLBB2_DISABLE;
       #endif
      -        en_val = AON_CMU_EN_CLK_TOP_PLLBB_PS_DISABLE;
      -    } else if (pll == HAL_CMU_PLL_DSI) {
      -        pu_val = 0;
      -        en_val = 0;
      -    } else {
      -        pu_val = 0;
      -        en_val = 0;
           }
       
           lock = int_lock();
           if (user < HAL_CMU_PLL_USER_ALL) {
               pll_user_map[pll] &= ~(1 << user);
      -    } else if (user == HAL_CMU_PLL_USER_ALL) {
      -        pll_user_map[pll] = 0;
           }
           if (pll_user_map[pll] == 0 || user == HAL_CMU_PLL_USER_ALL) {
      -#if defined(BBPLL_USE_DSI_MCUPLL) && defined(BB_PSRAMPLL_USE_DSI_PSRAMPLL)
      -        if (pll_user_map[HAL_CMU_PLL_BB] == 0 && pll_user_map[HAL_CMU_PLL_BB_PSRAM] == 0 &&
      -            pll_user_map[HAL_CMU_PLL_USB] == 0 && pll_user_map[HAL_CMU_PLL_DSI] == 0)
      -            pu_val |= AON_CMU_PU_PLLBB_DISABLE;
      -#elif defined(BBPLL_USE_DSI_MCUPLL) && !defined(BB_PSRAMPLL_USE_DSI_PSRAMPLL)
      -        if (pll == HAL_CMU_PLL_BB || pll == HAL_CMU_PLL_USB || pll == HAL_CMU_PLL_DSI) {
      -            if (pll_user_map[HAL_CMU_PLL_BB] == 0 && pll_user_map[HAL_CMU_PLL_USB] == 0 &&
      -                    pll_user_map[HAL_CMU_PLL_DSI] == 0)
      -                pu_val |= AON_CMU_PU_PLLDSI_DISABLE;
      -        } else if (pll == HAL_CMU_PLL_BB_PSRAM) {
      -            pu_val |= AON_CMU_PU_PLLBB_DISABLE;
      -        }
      -#elif !defined(BBPLL_USE_DSI_MCUPLL) && defined(BB_PSRAMPLL_USE_DSI_PSRAMPLL)
      -        if (pll == HAL_CMU_PLL_BB_PSRAM || pll == HAL_CMU_PLL_USB || pll == HAL_CMU_PLL_DSI) {
      -            if (pll_user_map[HAL_CMU_PLL_BB_PSRAM] == 0 && pll_user_map[HAL_CMU_PLL_USB] == 0 &&
      -                    pll_user_map[HAL_CMU_PLL_DSI] == 0)
      -                pu_val |= AON_CMU_PU_PLLDSI_DISABLE;
      -        } else if (pll == HAL_CMU_PLL_BB) {
      -            pu_val |= AON_CMU_PU_PLLBB_DISABLE;
      -        }
      -#else
      -        if (pll == HAL_CMU_PLL_USB || pll == HAL_CMU_PLL_DSI) {
      -            if (pll_user_map[HAL_CMU_PLL_USB] == 0 && pll_user_map[HAL_CMU_PLL_DSI] == 0)
      -                pu_val |= AON_CMU_PU_PLLDSI_DISABLE;
      -        } else if (pll == HAL_CMU_PLL_BB || pll == HAL_CMU_PLL_BB_PSRAM) {
      -            if (pll_user_map[HAL_CMU_PLL_BB] == 0 && pll_user_map[HAL_CMU_PLL_BB_PSRAM] == 0)
      -                pu_val |= AON_CMU_PU_PLLBB_DISABLE;
      -        }
      +        if (pll == HAL_CMU_PLL_AUD) {
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLAUD_DISABLE;
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_PU_PLLAUD_DISABLE;
      +#ifdef USB_USE_USBPLL
      +        } else if (pll == HAL_CMU_PLL_USB_HS) {
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLUSB_DISABLE;
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_PU_PLLUSB_DISABLE;
       #endif
      -        aoncmu->TOP_CLK_DISABLE = en_val;
      -        aoncmu->PLL_DISABLE = pu_val;
      +        } else {
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLBB_DISABLE;
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_PU_PLLBB_DISABLE;
      +        }
           }
           int_unlock(lock);
       
      @@ -1508,159 +962,119 @@ int BOOT_TEXT_FLASH_LOC hal_cmu_pll_disable(enum HAL_CMU_PLL_T pll, enum HAL_CMU
       
       void BOOT_TEXT_FLASH_LOC hal_cmu_low_freq_mode_init(void)
       {
      +#if defined(MCU_HIGH_PERFORMANCE_MODE)
      +    hal_cmu_sys_select_pll(HAL_CMU_PLL_USB);
      +#else
      +    // No need to switch to USB PLL, for there is a clock gate and a clock mux
      +    // in front of the AUD/USB switch
      +    hal_cmu_sys_select_pll(HAL_CMU_PLL_AUD);
      +#endif
      +
      +//#ifdef FLASH_LOW_SPEED
      +#ifdef OSC_26M_X4_AUD2BB
      +    aoncmu->CLK_SELECT &= ~AON_CMU_SEL_X4_SYS;
      +#endif
      +//#endif
       }
       
       void hal_cmu_low_freq_mode_enable(enum HAL_CMU_FREQ_T old_freq, enum HAL_CMU_FREQ_T new_freq)
       {
      -    enum HAL_CMU_PLL_T pll;
      -    enum HAL_CMU_FREQ_T switch_freq;
      -
      -    // TODO: Select the PLL used by sys
      -    pll = HAL_CMU_PLL_BB;
      +    // TODO: Need to lock irq?
      +    enum HAL_CMU_PLL_T POSSIBLY_UNUSED pll;
       
      -#ifdef OSC_26M_X4_AUD2BB
      -    switch_freq = HAL_CMU_FREQ_104M;
      +#if defined(MCU_HIGH_PERFORMANCE_MODE)
      +    pll = HAL_CMU_PLL_USB;
       #else
      -    switch_freq = HAL_CMU_FREQ_52M;
      +    pll = HAL_CMU_PLL_AUD;
       #endif
       
      -    if (old_freq > switch_freq && new_freq <= switch_freq) {
      +#ifdef OSC_26M_X4_AUD2BB
      +    if (new_freq <= HAL_CMU_FREQ_52M) {
      +        aoncmu->CLK_SELECT &= ~AON_CMU_SEL_X4_SYS;
      +    }
      +    if (new_freq <= HAL_CMU_FREQ_104M && old_freq > HAL_CMU_FREQ_104M) {
      +        if (new_freq > HAL_CMU_FREQ_52M) {
      +            // PLL is in use now. Switch to X2 first.
      +            hal_cmu_sys_set_freq(HAL_CMU_FREQ_52M);
      +            aoncmu->CLK_SELECT |= AON_CMU_SEL_X4_SYS;
      +            // X4 is in use now
      +            hal_cmu_sys_set_freq(new_freq);
      +        }
      +        hal_cmu_pll_disable(pll, HAL_CMU_PLL_USER_SYS);
      +    }
      +#else
      +#ifdef FLASH_LOW_SPEED
      +    if (old_freq > HAL_CMU_FREQ_52M && new_freq <= HAL_CMU_FREQ_52M) {
               hal_cmu_pll_disable(pll, HAL_CMU_PLL_USER_SYS);
           }
      +#endif
      +#endif
       }
       
       void hal_cmu_low_freq_mode_disable(enum HAL_CMU_FREQ_T old_freq, enum HAL_CMU_FREQ_T new_freq)
       {
      -    enum HAL_CMU_PLL_T pll;
      -    enum HAL_CMU_FREQ_T switch_freq;
      -
      -    // TODO: Select the PLL used by sys
      -    pll = HAL_CMU_PLL_BB;
      +    // TODO: Need to lock irq?
      +    enum HAL_CMU_PLL_T POSSIBLY_UNUSED pll;
       
      -#ifdef OSC_26M_X4_AUD2BB
      -    switch_freq = HAL_CMU_FREQ_104M;
      +#if defined(MCU_HIGH_PERFORMANCE_MODE)
      +    pll = HAL_CMU_PLL_USB;
       #else
      -    switch_freq = HAL_CMU_FREQ_52M;
      +    pll = HAL_CMU_PLL_AUD;
       #endif
       
      -    if (old_freq <= switch_freq && new_freq > switch_freq) {
      +#ifdef OSC_26M_X4_AUD2BB
      +    if (new_freq <= HAL_CMU_FREQ_52M) {
      +        aoncmu->CLK_SELECT &= ~AON_CMU_SEL_X4_SYS;
      +    } else if (new_freq <= HAL_CMU_FREQ_104M) {
      +        aoncmu->CLK_SELECT |= AON_CMU_SEL_X4_SYS;
      +    } else {
      +        if (old_freq <= HAL_CMU_FREQ_104M) {
      +            hal_cmu_pll_enable(pll, HAL_CMU_PLL_USER_SYS);
      +            if (old_freq > HAL_CMU_FREQ_52M) {
      +                // X4 is in use now. Switch to X2 before stopping X4
      +                hal_cmu_sys_set_freq(HAL_CMU_FREQ_52M);
      +            }
      +            aoncmu->CLK_SELECT &= ~AON_CMU_SEL_X4_SYS;
      +        }
      +    }
      +#else
      +#ifdef FLASH_LOW_SPEED
      +    if (old_freq <= HAL_CMU_FREQ_52M && new_freq > HAL_CMU_FREQ_52M) {
               hal_cmu_pll_enable(pll, HAL_CMU_PLL_USER_SYS);
           }
      -}
      -
      -void hal_cmu_rom_enable_pll(void)
      -{
      -    hal_cmu_sys_select_pll(HAL_CMU_PLL_BB);
      -    hal_cmu_pll_enable(HAL_CMU_PLL_BB, HAL_CMU_PLL_USER_SYS);
      -
      -#if defined(PSRAM_ENABLE) && !defined(PSRAM_LOW_SPEED)
      -    hal_cmu_pll_enable(HAL_CMU_PLL_BB_PSRAM, HAL_CMU_PLL_USER_PSRAM);
      +#endif
       #endif
       }
       
      -void BOOT_TEXT_FLASH_LOC hal_cmu_sram_init()
      +int hal_cmu_codec_adc_set_div(uint32_t div)
       {
      -    uint32_t mcu_ram_size;
      -
      -#if defined(ARM_CMSE)
      -    mcu_ram_size = RAM5_BASE + RAM5_SIZE - RAM0_BASE;
      -#elif defined(ARM_CMNS)
      -    mcu_ram_size = RAM_SIZE + RAM_S_SIZE;
      -#else
      -    mcu_ram_size = RAM_SIZE;
      -#endif
      -#if defined(CHIP_HAS_CP) && ((RAMCP_SIZE > 0) || (RAMCPX_SIZE > 0))
      -    mcu_ram_size += (RAMCP_SIZE + RAMCPX_SIZE);
      -#endif
      -#ifdef __BT_RAMRUN__
      -    mcu_ram_size += BT_RAMRUN_SIZE;
      -#endif
      +    uint32_t lock;
       
      -    switch (mcu_ram_size) {
      -    case RAM1_BASE - RAM0_BASE: //RAM0
      -        cmu->WAKEUP_CLK_CFG = SET_BITFIELD(cmu->WAKEUP_CLK_CFG, CMU_CFG_SRAM_IN_M33, 0x0);
      -        break;
      -    case RAM2_BASE - RAM0_BASE: //RAM0,1
      -        cmu->WAKEUP_CLK_CFG = SET_BITFIELD(cmu->WAKEUP_CLK_CFG, CMU_CFG_SRAM_IN_M33, 0x1);
      -        break;
      -    case RAM3_BASE - RAM0_BASE: //RAM0,1,2
      -        cmu->WAKEUP_CLK_CFG = SET_BITFIELD(cmu->WAKEUP_CLK_CFG, CMU_CFG_SRAM_IN_M33, 0x3);
      -        break;
      -    case RAM4_BASE - RAM0_BASE: //RAM0,1,2,3
      -        cmu->WAKEUP_CLK_CFG = SET_BITFIELD(cmu->WAKEUP_CLK_CFG, CMU_CFG_SRAM_IN_M33, 0x7);
      -        break;
      -    case RAM5_BASE - RAM0_BASE: //RAM0,1,2,3,4
      -        cmu->WAKEUP_CLK_CFG = SET_BITFIELD(cmu->WAKEUP_CLK_CFG, CMU_CFG_SRAM_IN_M33, 0xF);
      -        break;
      -    case (RAM5_BASE + RAM5_SIZE - RAM0_BASE): //RAM0,1,2,3,4,5
      -    default:
      -        cmu->WAKEUP_CLK_CFG = SET_BITFIELD(cmu->WAKEUP_CLK_CFG, CMU_CFG_SRAM_IN_M33, 0x1F);
      -        break;
      +    if (div < 2) {
      +        return 1;
           }
      -}
       
      -void hal_cmu_programmer_enable_pll(void)
      -{
      -    hal_cmu_sram_init();
      -    hal_cmu_dma_req_init();
      -
      -    hal_cmu_flash_select_pll(HAL_CMU_PLL_BB);
      -    hal_cmu_sys_select_pll(HAL_CMU_PLL_BB);
      -    hal_cmu_pll_enable(HAL_CMU_PLL_BB, HAL_CMU_PLL_USER_SYS);
      +    div -= 2;
      +    lock = int_lock();
      +    aoncmu->CODEC_DIV = SET_BITFIELD(aoncmu->CODEC_DIV, AON_CMU_CFG_DIV_CODEC, div);
      +    int_unlock(lock);
       
      -#if defined(PSRAM_ENABLE) && !defined(PSRAM_LOW_SPEED)
      -    hal_cmu_pll_enable(HAL_CMU_PLL_BB_PSRAM, HAL_CMU_PLL_USER_PSRAM);
      -#endif
      +    return 0;
       }
       
      -void BOOT_TEXT_FLASH_LOC hal_cmu_init_pll_selection(void)
      +uint32_t hal_cmu_codec_adc_get_div(void)
       {
      -    enum HAL_CMU_PLL_T sys;
      -
      -#if !defined(ARM_CMNS)
      -    // Disable the PLL which might be enabled in ROM
      -    hal_cmu_pll_disable(HAL_CMU_PLL_BB, HAL_CMU_PLL_USER_ALL);
      -#endif
      -
      -#ifdef BBPLL_USE_DSI_MCUPLL
      -    aoncmu->FLS_PSR_CLK |= AON_CMU_SEL_MCU_PLLDSI;
      -#endif
      -
      -#ifdef BB_PSRAMPLL_USE_DSI_PSRAMPLL
      -    aoncmu->FLS_PSR_CLK |= AON_CMU_SEL_PSR_PLLDSI;
      -#endif
      -
      -#ifdef SYS_USE_USBPLL
      -    sys = HAL_CMU_PLL_USB;
      -#elif defined(SYS_USE_BB_PSRAMPLL)
      -    sys = HAL_CMU_PLL_BB_PSRAM;
      -#elif defined(SYS_USE_DSPPLL)
      -    sys = HAL_CMU_PLL_DSP;
      -#else
      -    sys = HAL_CMU_PLL_BB;
      -#endif
      -    hal_cmu_sys_select_pll(sys);
      -
      -#ifdef AUDIO_USE_BBPLL
      -    hal_cmu_audio_select_pll(HAL_CMU_PLL_BB);
      -#else
      -    hal_cmu_audio_select_pll(HAL_CMU_PLL_USB);
      -#endif
      +    return GET_BITFIELD(aoncmu->CODEC_DIV, AON_CMU_CFG_DIV_CODEC) + 2;
      +}
       
      -#ifndef ULTRA_LOW_POWER
      -    hal_cmu_pll_enable(sys, HAL_CMU_PLL_USER_SYS);
      -#endif
      -#if !(defined(FLASH_LOW_SPEED) || defined(OSC_26M_X4_AUD2BB))
      -    hal_cmu_pll_enable(HAL_CMU_PLL_BB, HAL_CMU_PLL_USER_FLASH);
      -#endif
      -#if defined(PSRAM_ENABLE) && !defined(PSRAM_LOW_SPEED)
      -    hal_cmu_pll_enable(HAL_CMU_PLL_BB_PSRAM, HAL_CMU_PLL_USER_PSRAM);
      -#endif
      +int hal_cmu_codec_dac_set_div(uint32_t div)
      +{
      +    return hal_cmu_codec_adc_set_div(div);
      +}
       
      -    hal_cmu_dsp_timer0_select_slow();
      -#ifdef TIMER1_BASE
      -    hal_cmu_dsp_timer1_select_fast();
      -#endif
      +uint32_t hal_cmu_codec_dac_get_div(void)
      +{
      +    return hal_cmu_codec_adc_get_div();;
       }
       
       #if defined(__AUDIO_RESAMPLE__) && defined(ANA_26M_X4_ENABLE)
      @@ -1675,7 +1089,7 @@ void hal_cmu_audio_26m_x4_enable(enum CMU_AUD_26M_X4_USER_T user)
           lock = int_lock();
       
           if (aud_26m_x4_map == 0) {
      -        aoncmu->PCM_I2S_CLK |= AON_CMU_SEL_AUD_X4;
      +        aoncmu->CLK_SELECT |= AON_CMU_SEL_X4_AUD;
           }
           aud_26m_x4_map |= (1 << user);
       
      @@ -1695,7 +1109,7 @@ void hal_cmu_audio_26m_x4_disable(enum CMU_AUD_26M_X4_USER_T user)
           if (aud_26m_x4_map & (1 << user)) {
               aud_26m_x4_map &= ~(1 << user);
               if (aud_26m_x4_map == 0) {
      -            aoncmu->PCM_I2S_CLK &= ~AON_CMU_SEL_AUD_X4;
      +            aoncmu->CLK_SELECT &= ~AON_CMU_SEL_X4_AUD;
               }
           }
       
      @@ -1711,14 +1125,14 @@ void hal_cmu_codec_iir_enable(uint32_t speed)
           uint32_t div;
           uint32_t cfg_speed = 0;
       
      -    mask = AON_CMU_SEL_CODECIIR_OSC | AON_CMU_SEL_CODECIIR_OSCX2 | AON_CMU_BYPASS_DIV_CODECIIR;
      +    mask = AON_CMU_SEL_OSC_CODECIIR | AON_CMU_SEL_OSCX2_CODECIIR | AON_CMU_BYPASS_DIV_CODECIIR;
           val = 0;
       
           if (speed <= 26000000) {
      -        val |= AON_CMU_SEL_CODECIIR_OSC | AON_CMU_SEL_CODECIIR_OSCX2;
      +        val |= AON_CMU_SEL_OSC_CODECIIR | AON_CMU_SEL_OSCX2_CODECIIR;
               cfg_speed = 26000000;
           } else if (speed <= 52000000) {
      -        val |= AON_CMU_SEL_CODECIIR_OSCX2;
      +        val |= AON_CMU_SEL_OSCX2_CODECIIR;
               cfg_speed = 52000000;
           } else {
       #if defined(__AUDIO_RESAMPLE__) && defined(ANA_26M_X4_ENABLE)
      @@ -1739,11 +1153,7 @@ void hal_cmu_codec_iir_enable(uint32_t speed)
                       val |= AON_CMU_BYPASS_DIV_CODECIIR;
                       cfg_speed = HAL_CMU_AUD_PLL_CLOCK;
                   }
      -            analog_aud_freq_pll_config(CODEC_FREQ_48K_SERIES, CODEC_PLL_DIV);
      -            analog_aud_pll_open(ANA_AUD_PLL_USER_IIR);
               }
      -
      -       //pmu_iir_freq_config(cfg_speed);
           }
       
           ASSERT(speed <= cfg_speed, "%s: speed %u should <= cfg_speed %u", __func__, speed, cfg_speed);
      @@ -1752,7 +1162,7 @@ void hal_cmu_codec_iir_enable(uint32_t speed)
           aoncmu->CODEC_IIR = (aoncmu->CODEC_IIR & ~mask) | val;
           int_unlock(lock);
       
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_CODECIIR_ENABLE;
      +    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_CODEC_IIR_ENABLE;
       
           aocmu_reg_update_wait();
       }
      @@ -1761,26 +1171,18 @@ void hal_cmu_codec_iir_disable(void)
       {
           uint32_t lock;
           uint32_t val;
      -    bool high_speed;
       
      -    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODECIIR_DISABLE;
      +    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODEC_IIR_DISABLE;
       
       #if defined(__AUDIO_RESAMPLE__) && defined(ANA_26M_X4_ENABLE)
           hal_cmu_audio_26m_x4_disable(CMU_AUD_26M_X4_USER_IIR);
       #endif
       
      -    high_speed = !(aoncmu->CODEC_IIR & AON_CMU_SEL_CODECIIR_OSC);
      -
      -    val = AON_CMU_SEL_CODECIIR_OSC | AON_CMU_SEL_CODECIIR_OSCX2;
      +    val = AON_CMU_SEL_OSC_CODECIIR | AON_CMU_SEL_OSCX2_CODECIIR;
       
           lock = int_lock();
           aoncmu->CODEC_IIR |= val;
           int_unlock(lock);
      -
      -    if (high_speed) {
      -        //pmu_iir_freq_config(0);
      -    }
      -    analog_aud_pll_close(ANA_AUD_PLL_USER_IIR);
       }
       
       int hal_cmu_codec_iir_set_div(uint32_t div)
      @@ -1807,24 +1209,20 @@ void hal_cmu_codec_rs_enable(uint32_t speed)
           uint32_t div;
           uint32_t cfg_speed = 0;
       
      -    mask = AON_CMU_SEL_CODECRS0_OSC | AON_CMU_SEL_CODECRS0_OSCX2 | AON_CMU_BYPASS_DIV_CODECRS0;
      -    mask |= AON_CMU_SEL_CODECRS1_OSC | AON_CMU_SEL_CODECRS1_OSCX2 | AON_CMU_BYPASS_DIV_CODECRS1;
      +    mask = AON_CMU_SEL_OSC_CODECRS | AON_CMU_SEL_OSCX2_CODECRS | AON_CMU_BYPASS_DIV_CODECRS;
           val = 0;
       
           if (speed <= 26000000) {
      -        val |= AON_CMU_SEL_CODECRS0_OSC | AON_CMU_SEL_CODECRS0_OSCX2;
      -        val |= AON_CMU_SEL_CODECRS1_OSC | AON_CMU_SEL_CODECRS1_OSCX2;
      +        val |= AON_CMU_SEL_OSC_CODECRS | AON_CMU_SEL_OSCX2_CODECRS;
               cfg_speed = 26000000;
           } else if (speed <= 52000000) {
      -        val |= AON_CMU_SEL_CODECRS0_OSCX2;
      -        val |= AON_CMU_SEL_CODECRS1_OSCX2;
      +        val |= AON_CMU_SEL_OSCX2_CODECRS;
               cfg_speed = 52000000;
           } else {
       #if defined(__AUDIO_RESAMPLE__) && defined(ANA_26M_X4_ENABLE)
               if (hal_cmu_get_audio_resample_status()) {
                   hal_cmu_audio_26m_x4_enable(CMU_AUD_26M_X4_USER_RS);
      -            val |= AON_CMU_BYPASS_DIV_CODECRS0;
      -            val |= AON_CMU_BYPASS_DIV_CODECRS1;
      +            val |= AON_CMU_BYPASS_DIV_CODECRS;
                   cfg_speed = 104000000;
               }
               else
      @@ -1836,13 +1234,12 @@ void hal_cmu_codec_rs_enable(uint32_t speed)
                       hal_cmu_codec_rs_set_div(div);
                       cfg_speed = HAL_CMU_AUD_PLL_CLOCK / div;
                   } else {
      -                val |= AON_CMU_BYPASS_DIV_CODECRS0;
      -                val |= AON_CMU_BYPASS_DIV_CODECRS1;
      +                val |= AON_CMU_BYPASS_DIV_CODECRS;
                       cfg_speed = HAL_CMU_AUD_PLL_CLOCK;
                   }
      -            analog_aud_freq_pll_config(CODEC_FREQ_48K_SERIES, CODEC_PLL_DIV);
      -            analog_aud_pll_open(ANA_AUD_PLL_USER_RS);
               }
      +
      +        pmu_rs_freq_config(cfg_speed);
           }
       
           ASSERT(speed <= cfg_speed, "%s: speed %u should <= cfg_speed %u", __func__, speed, cfg_speed);
      @@ -1851,7 +1248,7 @@ void hal_cmu_codec_rs_enable(uint32_t speed)
           aoncmu->CODEC_IIR = (aoncmu->CODEC_IIR & ~mask) | val;
           int_unlock(lock);
       
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_CODECRS0_ENABLE | AON_CMU_EN_CLK_CODECRS1_ENABLE;
      +    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_CODEC_RS_ENABLE;
       
           aocmu_reg_update_wait();
       }
      @@ -1859,19 +1256,23 @@ void hal_cmu_codec_rs_enable(uint32_t speed)
       void hal_cmu_codec_rs_disable(void)
       {
           uint32_t lock;
      -    //bool high_speed;
      +    bool high_speed;
       
      -    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODECRS0_DISABLE | AON_CMU_EN_CLK_CODECRS1_DISABLE;
      +    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODEC_RS_DISABLE;
       
       #if defined(__AUDIO_RESAMPLE__) && defined(ANA_26M_X4_ENABLE)
           hal_cmu_audio_26m_x4_disable(CMU_AUD_26M_X4_USER_RS);
       #endif
       
      +    high_speed = !(aoncmu->CODEC_IIR & AON_CMU_SEL_OSC_CODECRS);
      +
           lock = int_lock();
      -    aoncmu->CODEC_IIR |= AON_CMU_SEL_CODECRS0_OSC | AON_CMU_SEL_CODECRS0_OSCX2 | AON_CMU_SEL_CODECRS1_OSC | AON_CMU_SEL_CODECRS1_OSCX2;
      +    aoncmu->CODEC_IIR |= AON_CMU_SEL_OSC_CODECRS | AON_CMU_SEL_OSCX2_CODECRS;
           int_unlock(lock);
       
      -    analog_aud_pll_close(ANA_AUD_PLL_USER_RS);
      +    if (high_speed) {
      +        pmu_rs_freq_config(0);
      +    }
       }
       
       int hal_cmu_codec_rs_set_div(uint32_t div)
      @@ -1884,69 +1285,106 @@ int hal_cmu_codec_rs_set_div(uint32_t div)
       
           div -= 2;
           lock = int_lock();
      -    aoncmu->CODEC_IIR = (aoncmu->CODEC_IIR & ~(AON_CMU_CFG_DIV_CODECRS0_MASK | AON_CMU_CFG_DIV_CODECRS1_MASK)) |
      -        AON_CMU_CFG_DIV_CODECRS0(div) | AON_CMU_CFG_DIV_CODECRS1(div);
      +    aoncmu->CODEC_IIR = SET_BITFIELD(aoncmu->CODEC_IIR, AON_CMU_CFG_DIV_CODECRS, div);
           int_unlock(lock);
       
           return 0;
       }
       
      -void hal_cmu_codec_clock_enable(void)
      +void hal_cmu_anc_enable(enum HAL_CMU_ANC_CLK_USER_T user)
       {
      -    uint32_t lock;
      -
      -    lock = int_lock();
      -    aoncmu->CODEC_DIV = (aoncmu->CODEC_DIV & ~(AON_CMU_SEL_CODEC_OSC | AON_CMU_SEL_CODECHCLK_OSCX2 | AON_CMU_SEL_CODEC_ANA_2 | AON_CMU_SEL_CODECHCLK_PLL)) |
      -       AON_CMU_SEL_CODEC_OSC_2;
      -    int_unlock(lock);
      +    anc_enabled = true;
      +}
       
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_CODECHCLK_ENABLE | AON_CMU_EN_CLK_CODEC_ENABLE;
      -    hal_cmu_clock_enable(HAL_CMU_MOD_H_CODEC);
      +void hal_cmu_anc_disable(enum HAL_CMU_ANC_CLK_USER_T user)
      +{
      +    anc_enabled = false;
       }
       
      -void hal_cmu_codec_clock_disable(void)
      +int hal_cmu_anc_get_status(enum HAL_CMU_ANC_CLK_USER_T user)
       {
      -    hal_cmu_clock_disable(HAL_CMU_MOD_H_CODEC);
      -    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODECHCLK_DISABLE | AON_CMU_EN_CLK_CODEC_DISABLE;
      +    return anc_enabled;
       }
       
      -void hal_cmu_codec_vad_clock_enable(int type)
      +void hal_cmu_codec_clock_enable(void)
       {
      -    uint32_t lock;
      +    uint32_t clk;
       
      -    lock = int_lock();
      -    aoncmu->CODEC_DIV |= (AON_CMU_EN_VAD_IIR | AON_CMU_EN_VAD_RS);
      -    int_unlock(lock);
      +#ifdef CODEC_CLK_FROM_ANA
      +    // Always use ANA clock
      +    clk = AON_CMU_EN_CLK_CODEC_HCLK_ENABLE | AON_CMU_EN_CLK_CODEC_ENABLE;
      +#else
      +#ifdef __AUDIO_RESAMPLE__
      +    if (hal_cmu_get_audio_resample_status()) {
      +        uint32_t lock;
      +        lock = int_lock();
      +        aoncmu->CODEC_DIV |= AON_CMU_SEL_OSC_CODEC;
      +        int_unlock(lock);
       
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_OSC_ENABLE | AON_CMU_EN_CLK_VAD32K_ENABLE;
      -    if (type == AUD_VAD_TYPE_MIX) {
      -        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODEC_DISABLE;
      +#ifdef RESAMPLE_CODEC_CLK_ANA
      +        clk = AON_CMU_EN_CLK_CODEC_HCLK_ENABLE | AON_CMU_EN_CLK_CODEC_ENABLE;
      +#else
      +        clk = AON_CMU_EN_CLK_PLL_CODEC_ENABLE | AON_CMU_EN_CLK_CODEC_HCLK_ENABLE | AON_CMU_EN_CLK_CODEC_ENABLE;
      +        if (hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_0) {
      +            // Force codec to use analog clock
      +            clk &= ~AON_CMU_EN_CLK_PLL_CODEC_ENABLE;
      +        }
      +#endif
      +    }
      +    else
      +#endif
      +    {
      +        clk = AON_CMU_EN_CLK_PLL_CODEC_ENABLE | AON_CMU_EN_CLK_CODEC_HCLK_ENABLE | AON_CMU_EN_CLK_CODEC_ENABLE;
           }
      +#endif
      +    aoncmu->TOP_CLK_ENABLE = clk;
      +    hal_cmu_clock_enable(HAL_CMU_MOD_H_CODEC);
       }
       
      -void hal_cmu_codec_vad_clock_disable(int type)
      +void hal_cmu_codec_clock_disable(void)
       {
      -    uint32_t lock;
      +    uint32_t clk;
       
      -    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_OSC_DISABLE | AON_CMU_EN_CLK_VAD32K_DISABLE;
      -    if (type == AUD_VAD_TYPE_MIX) {
      -        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_CODEC_ENABLE;
      +    hal_cmu_clock_disable(HAL_CMU_MOD_H_CODEC);
      +
      +#ifdef CODEC_CLK_FROM_ANA
      +    clk = AON_CMU_EN_CLK_CODEC_HCLK_DISABLE | AON_CMU_EN_CLK_CODEC_DISABLE;
      +#else
      +#ifdef __AUDIO_RESAMPLE__
      +    if (hal_cmu_get_audio_resample_status()) {
      +        uint32_t lock;
      +        lock = int_lock();
      +        aoncmu->CODEC_DIV &= ~AON_CMU_SEL_OSC_CODEC;
      +        int_unlock(lock);
      +
      +        clk = AON_CMU_EN_CLK_CODEC_HCLK_DISABLE | AON_CMU_EN_CLK_CODEC_DISABLE;
           }
      +    else
      +#endif
      +    {
      +        clk = AON_CMU_EN_CLK_PLL_CODEC_DISABLE | AON_CMU_EN_CLK_CODEC_HCLK_DISABLE | AON_CMU_EN_CLK_CODEC_DISABLE;
      +    }
      +#endif
      +    aoncmu->TOP_CLK_DISABLE = clk;
      +}
       
      -    lock = int_lock();
      -    aoncmu->CODEC_DIV &= ~(AON_CMU_EN_VAD_IIR | AON_CMU_EN_VAD_RS);
      -    int_unlock(lock);
      +void hal_cmu_codec_vad_clock_enable(uint32_t enabled)
      +{
      +    if (enabled) {
      +        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_OSC_ENABLE | AON_CMU_EN_CLK_32K_CODEC_ENABLE;
      +    } else {
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_OSC_DISABLE | AON_CMU_EN_CLK_32K_CODEC_DISABLE;
      +    }
       }
       
       void hal_cmu_codec_reset_set(void)
       {
      -    aoncmu->SOFT_RSTN_SET = AON_CMU_SOFT_RSTN_CODEC_SET;
      +    aoncmu->RESET_SET = AON_CMU_SOFT_RSTN_CODEC_SET;
       }
       
       void hal_cmu_codec_reset_clear(void)
       {
      -    hal_cmu_reset_clear(HAL_CMU_MOD_H_CODEC);
      -    aoncmu->SOFT_RSTN_CLR = AON_CMU_SOFT_RSTN_CODEC_CLR;
      +    aoncmu->RESET_CLR = AON_CMU_SOFT_RSTN_CODEC_CLR;
           aocmu_reg_update_wait();
       }
       
      @@ -2247,22 +1685,9 @@ void hal_cmu_usb_set_host_mode(void)
       }
       
       #ifdef ROM_BUILD
      -enum HAL_CMU_USB_CLOCK_SEL_T hal_cmu_usb_rom_select_clock_source(int pll_en, unsigned int crystal)
      -{
      -    enum HAL_CMU_USB_CLOCK_SEL_T sel;
      -
      -    if (crystal == 24000000) {
      -        sel = HAL_CMU_USB_CLOCK_SEL_24M_X2;
      -    } else {
      -        sel = HAL_CMU_USB_CLOCK_SEL_PLL;
      -    }
      -
      -    hal_cmu_usb_rom_set_clock_source(sel);
      -
      -    return sel;
      -}
       void hal_cmu_usb_rom_set_clock_source(enum HAL_CMU_USB_CLOCK_SEL_T sel)
       {
      +    usb_clk_sel = sel;
       }
       #endif
       
      @@ -2270,17 +1695,53 @@ static uint32_t hal_cmu_usb_get_clock_source(void)
       {
           uint32_t src;
       
      +#if defined(USB_CLK_SRC_26M_X4) || defined(USB_CLK_SRC_26M_X2) || defined(USB_CLK_SRC_24M_X2) || defined(USB_CLK_SRC_48M)
       #ifdef USB_HIGH_SPEED
      +#error "USB HIGH-SPEED must use PLL"
      +#endif
      +#if defined(USB_CLK_SRC_26M_X4) && !defined(ANA_26M_X4_ENABLE)
      +#error "USB_CLK_SRC_26M_X4 must use ANA_26M_X4_ENABLE"
      +#endif
      +#endif
      +
      +#ifdef ROM_BUILD
      +
      +#ifdef USB_USE_USBPLL
           src = CMU_USB_CLK_SRC_PLL_60M;
       #else
      -#ifndef USB_USE_USBPLL
      -    if (hal_cmu_get_crystal_freq() == 24000000)
      +    if (usb_clk_sel == HAL_CMU_USB_CLOCK_SEL_24M_X2) {
               src = CMU_USB_CLK_SRC_OSC_24M_X2;
      -    else
      -#endif
      +    } else if (usb_clk_sel == HAL_CMU_USB_CLOCK_SEL_48M) {
      +        src = CMU_USB_CLK_SRC_OSC_48M;
      +    } else if (usb_clk_sel == HAL_CMU_USB_CLOCK_SEL_26M_X2) {
      +        src = CMU_USB_CLK_SRC_OSC_26M_X2;
      +    } else if (usb_clk_sel == HAL_CMU_USB_CLOCK_SEL_26M_X4) {
      +        src = CMU_USB_CLK_SRC_OSC_26M_X4;
      +    } else {
               src = CMU_USB_CLK_SRC_PLL_48M;
      +    }
      +#endif
      +
      +#else // !ROM_BUILD
      +
      +#ifdef USB_USE_USBPLL
      +    src = CMU_USB_CLK_SRC_PLL_60M;
      +#else
      +#ifdef USB_CLK_SRC_24M_X2
      +    src = CMU_USB_CLK_SRC_OSC_24M_X2;
      +#elif defined(USB_CLK_SRC_48M)
      +    src = CMU_USB_CLK_SRC_OSC_48M;
      +#elif defined(USB_CLK_SRC_26M_X4)
      +    src = CMU_USB_CLK_SRC_OSC_26M_X4;
      +#elif defined(USB_CLK_SRC_26M_X2)
      +    src = CMU_USB_CLK_SRC_OSC_26M_X2;
      +#else
      +    src = CMU_USB_CLK_SRC_PLL_48M;
      +#endif
       #endif
       
      +#endif // !ROM_BUILD
      +
           return src;
       }
       
      @@ -2289,38 +1750,20 @@ void hal_cmu_usb_clock_enable(void)
           enum HAL_CMU_PLL_T pll;
           uint32_t lock;
           uint32_t src;
      -    POSSIBLY_UNUSED uint32_t div;
       
      -#if !defined(USB_HIGH_SPEED) && defined(USB_USE_USBPLL)
           pll = HAL_CMU_PLL_USB;
      -#else
      -    pll = HAL_CMU_PLL_BB;
      -#endif
           src = hal_cmu_usb_get_clock_source();
      -    if (src != CMU_USB_CLK_SRC_OSC_24M_X2)
      +
      +    if (src == CMU_USB_CLK_SRC_PLL_60M || src == CMU_USB_CLK_SRC_PLL_60M_ALT ||
      +            src == CMU_USB_CLK_SRC_PLL_48M) {
               hal_cmu_pll_enable(pll, HAL_CMU_PLL_USER_USB);
      +    }
       
           lock = int_lock();
      -#ifdef USB_HIGH_SPEED
      -    cmu->SYS_DIV = SET_BITFIELD(cmu->SYS_DIV, CMU_SEL_USB_SRC, 1);
      -#else
      -    cmu->SYS_DIV = SET_BITFIELD(cmu->SYS_DIV, CMU_SEL_USB_SRC, 0);
      -    if (src == CMU_USB_CLK_SRC_OSC_24M_X2) {
      -        aoncmu->CLK_SELECT |= AON_CMU_SEL_USB_OSCX2;
      -    } else {
      -#ifdef USB_USE_USBPLL
      -        aoncmu->CLK_SELECT |= AON_CMU_SEL_USB_PLLUSB;
      -        // DSI PSRAMPLL to dig: ?
      -        div = 8;///TODO:
      -#else // USB usb BBPLL
      -        aoncmu->CLK_SELECT &= ~AON_CMU_SEL_USB_PLLUSB;
      -        // BBPLL to dig: 384M
      -        div = 8;
      -#endif
      -        aoncmu->CLK_SELECT = SET_BITFIELD(aoncmu->CLK_SELECT, AON_CMU_CFG_DIV_USB, div-2);
      -        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_USB_PLL_ENABLE;
      -    }
      -#endif /*USB_HIGH_SPEED*/
      +#ifdef USB_CLK_SRC_26M_X4
      +    aoncmu->CLK_SELECT |= AON_CMU_SEL_X4_USB;
      +#endif
      +    cmu->SYS_DIV = SET_BITFIELD(cmu->SYS_DIV, CMU_SEL_USB_SRC, src);
           int_unlock(lock);
           hal_cmu_clock_enable(HAL_CMU_MOD_H_USBC);
       #ifdef USB_HIGH_SPEED
      @@ -2346,12 +1789,10 @@ void hal_cmu_usb_clock_enable(void)
       void hal_cmu_usb_clock_disable(void)
       {
           enum HAL_CMU_PLL_T pll;
      +    uint32_t src;
       
      -#if !defined(USB_HIGH_SPEED) && defined(USB_USE_USBPLL)
           pll = HAL_CMU_PLL_USB;
      -#else
      -    pll = HAL_CMU_PLL_BB;
      -#endif
      +    src = hal_cmu_usb_get_clock_source();
       
           hal_cmu_reset_set(HAL_CMU_MOD_O_USB);
           hal_cmu_reset_set(HAL_CMU_MOD_O_USB32K);
      @@ -2365,18 +1806,17 @@ void hal_cmu_usb_clock_disable(void)
           hal_cmu_clock_disable(HAL_CMU_MOD_H_USBH);
       #endif
           hal_cmu_clock_disable(HAL_CMU_MOD_H_USBC);
      -#ifndef USB_HIGH_SPEED
      -    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_USB_PLL_DISABLE;
      -#endif
       
      -    if (hal_cmu_usb_get_clock_source() != CMU_USB_CLK_SRC_OSC_24M_X2)
      +    if (src == CMU_USB_CLK_SRC_PLL_60M || src == CMU_USB_CLK_SRC_PLL_60M_ALT ||
      +            src == CMU_USB_CLK_SRC_PLL_48M) {
               hal_cmu_pll_disable(pll, HAL_CMU_PLL_USER_USB);
      +    }
       }
       #endif
       
       void BOOT_TEXT_FLASH_LOC hal_cmu_apb_init_div(void)
       {
      -    // Divider defaults to 2 (div = reg_val + 2)
      +    // Divider defaults to 2 (reg_val = div - 2)
           //cmu->SYS_DIV = SET_BITFIELD(cmu->SYS_DIV, CMU_CFG_DIV_PCLK, 0);
       }
       
      @@ -2386,7 +1826,10 @@ int hal_cmu_periph_set_div(uint32_t div)
           int ret = 0;
       
           if (div == 0 || div > ((AON_CMU_CFG_DIV_PER_MASK >> AON_CMU_CFG_DIV_PER_SHIFT) + 2)) {
      -        ret = 1;
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_PLL_PER_DISABLE;
      +        if (div > ((AON_CMU_CFG_DIV_PER_MASK >> AON_CMU_CFG_DIV_PER_SHIFT) + 2)) {
      +            ret = 1;
      +        }
           } else {
               lock = int_lock();
               if (div == 1) {
      @@ -2397,6 +1840,7 @@ int hal_cmu_periph_set_div(uint32_t div)
                       AON_CMU_CFG_DIV_PER(div);
               }
               int_unlock(lock);
      +        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_PLL_PER_ENABLE;
           }
       
           return ret;
      @@ -2424,9 +1868,8 @@ int hal_cmu_ ##f## _set_div(uint32_t div) \
       PERPH_SET_DIV_FUNC(uart0, UART0, UART_CLK);
       PERPH_SET_DIV_FUNC(uart1, UART1, UART_CLK);
       PERPH_SET_DIV_FUNC(uart2, UART2, UART_CLK);
      -PERPH_SET_DIV_FUNC(uart3, UART3, UART_CLK);
      -PERPH_SET_DIV_FUNC(spi, SPI0, SYS_DIV);
      -PERPH_SET_DIV_FUNC(slcd, SPI1, SYS_DIV);
      +PERPH_SET_DIV_FUNC(spi, SPI1, SYS_DIV);
      +PERPH_SET_DIV_FUNC(slcd, SPI0, SYS_DIV);
       PERPH_SET_DIV_FUNC(sdmmc, SDMMC, PERIPH_CLK);
       PERPH_SET_DIV_FUNC(i2c, I2C, I2C_CLK);
       
      @@ -2450,9 +1893,8 @@ int hal_cmu_ ##f## _set_freq(enum HAL_CMU_PERIPH_FREQ_T freq) \
       PERPH_SET_FREQ_FUNC(uart0, UART0, UART_CLK);
       PERPH_SET_FREQ_FUNC(uart1, UART1, UART_CLK);
       PERPH_SET_FREQ_FUNC(uart2, UART2, UART_CLK);
      -PERPH_SET_FREQ_FUNC(uart3, UART3, UART_CLK);
      -PERPH_SET_FREQ_FUNC(spi, SPI0, SYS_DIV);
      -PERPH_SET_FREQ_FUNC(slcd, SPI1, SYS_DIV);
      +PERPH_SET_FREQ_FUNC(spi, SPI1, SYS_DIV);
      +PERPH_SET_FREQ_FUNC(slcd, SPI0, SYS_DIV);
       PERPH_SET_FREQ_FUNC(sdmmc, SDMMC, PERIPH_CLK);
       PERPH_SET_FREQ_FUNC(i2c, I2C, I2C_CLK);
       
      @@ -2474,22 +1916,6 @@ int hal_cmu_ispi_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq)
           return ret;
       }
       
      -void hal_cmu_sec_eng_clock_enable(void)
      -{
      -    hal_cmu_clock_enable(HAL_CMU_MOD_H_SEC_ENG);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_P_SEC_ENG);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_H_SEC_ENG);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_P_SEC_ENG);
      -}
      -
      -void hal_cmu_sec_eng_clock_disable(void)
      -{
      -    hal_cmu_reset_set(HAL_CMU_MOD_H_SEC_ENG);
      -    hal_cmu_reset_set(HAL_CMU_MOD_P_SEC_ENG);
      -    hal_cmu_clock_disable(HAL_CMU_MOD_H_SEC_ENG);
      -    hal_cmu_clock_disable(HAL_CMU_MOD_P_SEC_ENG);
      -}
      -
       int hal_cmu_clock_out_enable(enum HAL_CMU_CLOCK_OUT_ID_T id)
       {
           uint32_t lock;
      @@ -2501,7 +1927,6 @@ int hal_cmu_clock_out_enable(enum HAL_CMU_CLOCK_OUT_ID_T id)
               CMU_CLK_OUT_SEL_CODEC   = 1,
               CMU_CLK_OUT_SEL_BT      = 2,
               CMU_CLK_OUT_SEL_MCU     = 3,
      -        CMU_CLK_OUT_SEL_WF      = 4,
       
               CMU_CLK_OUT_SEL_QTY
           };
      @@ -2512,7 +1937,7 @@ int hal_cmu_clock_out_enable(enum HAL_CMU_CLOCK_OUT_ID_T id)
           if (id <= HAL_CMU_CLOCK_OUT_AON_SYS) {
               sel = CMU_CLK_OUT_SEL_AON;
               cfg = id - HAL_CMU_CLOCK_OUT_AON_32K;
      -    } else if (HAL_CMU_CLOCK_OUT_MCU_32K <= id && id <= HAL_CMU_CLOCK_OUT_MCU_I2S1) {
      +    } else if (HAL_CMU_CLOCK_OUT_MCU_32K <= id && id <= HAL_CMU_CLOCK_OUT_MCU_SPI1) {
               sel = CMU_CLK_OUT_SEL_MCU;
               lock = int_lock();
               cmu->PERIPH_CLK = SET_BITFIELD(cmu->PERIPH_CLK, CMU_CFG_CLK_OUT, id - HAL_CMU_CLOCK_OUT_MCU_32K);
      @@ -2520,12 +1945,9 @@ int hal_cmu_clock_out_enable(enum HAL_CMU_CLOCK_OUT_ID_T id)
           } else if (HAL_CMU_CLOCK_OUT_CODEC_ADC_ANA <= id && id <= HAL_CMU_CLOCK_OUT_CODEC_HCLK) {
               sel = CMU_CLK_OUT_SEL_CODEC;
               hal_codec_select_clock_out(id - HAL_CMU_CLOCK_OUT_CODEC_ADC_ANA);
      -    } else if (HAL_CMU_CLOCK_OUT_BT_NONE <= id && id <= HAL_CMU_CLOCK_OUT_BT_DACD8) {
      +    } else if (HAL_CMU_CLOCK_OUT_BT_32K <= id && id <= HAL_CMU_CLOCK_OUT_BT_26M) {
               sel = CMU_CLK_OUT_SEL_BT;
      -        btcmu->CLK_OUT = SET_BITFIELD(btcmu->CLK_OUT, BT_CMU_CFG_CLK_OUT, id - HAL_CMU_CLOCK_OUT_BT_NONE);
      -    } else if (HAL_CMU_CLOCK_OUT_WF_32K <= id && id <= HAL_CMU_CLOCK_OUT_WF_BBDIGFIFO) {
      -        sel = CMU_CLK_OUT_SEL_WF;
      -        wlancmu->CLK_OUT = SET_BITFIELD(wlancmu->CLK_OUT, WLAN_CMU_CFG_CLK_OUT, id - HAL_CMU_CLOCK_OUT_WF_32K);
      +        btcmu->CLK_OUT = SET_BITFIELD(btcmu->CLK_OUT, BT_CMU_CFG_CLK_OUT, id - HAL_CMU_CLOCK_OUT_BT_32K);
           }
       
           if (sel < CMU_CLK_OUT_SEL_QTY) {
      @@ -2554,7 +1976,7 @@ int hal_cmu_i2s_mclk_enable(enum HAL_CMU_I2S_MCLK_ID_T id)
           uint32_t lock;
       
           lock = int_lock();
      -    aoncmu->CODEC_DIV = SET_BITFIELD(aoncmu->CODEC_DIV, AON_CMU_SEL_I2S_MCLK, id) | AON_CMU_EN_I2S_MCLK;
      +    aoncmu->PCM_I2S_CLK = SET_BITFIELD(aoncmu->PCM_I2S_CLK, AON_CMU_SEL_I2S_MCLK, id) | AON_CMU_EN_I2S_MCLK;
           int_unlock(lock);
       
           return 0;
      @@ -2565,7 +1987,7 @@ void hal_cmu_i2s_mclk_disable(void)
           uint32_t lock;
       
           lock = int_lock();
      -    aoncmu->CODEC_DIV &= ~AON_CMU_EN_I2S_MCLK;
      +    aoncmu->PCM_I2S_CLK &= ~AON_CMU_EN_I2S_MCLK;
           int_unlock(lock);
       }
       
      @@ -2586,42 +2008,28 @@ int hal_cmu_pwm_set_freq(enum HAL_PWM_ID_T id, uint32_t freq)
               clk_32k = 0;
               div = hal_cmu_get_crystal_freq() / freq;
               if (div < 2) {
      -            return -1;
      +            return 1;
               }
       
               div -= 2;
               if ((div & (AON_CMU_CFG_DIV_PWM0_MASK >> AON_CMU_CFG_DIV_PWM0_SHIFT)) != div) {
      -            return -2;
      +            return 1;
               }
           }
       
           lock = int_lock();
           if (id == HAL_PWM_ID_0) {
      -        aoncmu->PWM01_CLK = (aoncmu->PWM01_CLK & ~(AON_CMU_CFG_DIV_PWM0_MASK | AON_CMU_SEL_PWM0_OSC | AON_CMU_EN_CLK_PWM0_OSC)) |
      -            AON_CMU_CFG_DIV_PWM0(div) | (clk_32k ? 0 : (AON_CMU_SEL_PWM0_OSC | AON_CMU_EN_CLK_PWM0_OSC));
      +        aoncmu->PWM01_CLK = (aoncmu->PWM01_CLK & ~(AON_CMU_CFG_DIV_PWM0_MASK | AON_CMU_SEL_OSC_PWM0 | AON_CMU_EN_OSC_PWM0)) |
      +            AON_CMU_CFG_DIV_PWM0(div) | (clk_32k ? 0 : (AON_CMU_SEL_OSC_PWM0 | AON_CMU_EN_OSC_PWM0));
           } else if (id == HAL_PWM_ID_1) {
      -        aoncmu->PWM01_CLK = (aoncmu->PWM01_CLK & ~(AON_CMU_CFG_DIV_PWM1_MASK | AON_CMU_SEL_PWM1_OSC | AON_CMU_EN_CLK_PWM1_OSC)) |
      -            AON_CMU_CFG_DIV_PWM1(div) | (clk_32k ? 0 : (AON_CMU_SEL_PWM1_OSC | AON_CMU_EN_CLK_PWM1_OSC));
      +        aoncmu->PWM01_CLK = (aoncmu->PWM01_CLK & ~(AON_CMU_CFG_DIV_PWM1_MASK | AON_CMU_SEL_OSC_PWM1 | AON_CMU_EN_OSC_PWM1)) |
      +            AON_CMU_CFG_DIV_PWM1(div) | (clk_32k ? 0 : (AON_CMU_SEL_OSC_PWM1 | AON_CMU_EN_OSC_PWM1));
           } else if (id == HAL_PWM_ID_2) {
      -        aoncmu->PWM23_CLK = (aoncmu->PWM23_CLK & ~(AON_CMU_CFG_DIV_PWM2_MASK | AON_CMU_SEL_PWM2_OSC | AON_CMU_EN_CLK_PWM2_OSC)) |
      -            AON_CMU_CFG_DIV_PWM2(div) | (clk_32k ? 0 : (AON_CMU_SEL_PWM2_OSC | AON_CMU_EN_CLK_PWM2_OSC));
      -    } else if (id == HAL_PWM_ID_3) {
      -        aoncmu->PWM23_CLK = (aoncmu->PWM23_CLK & ~(AON_CMU_CFG_DIV_PWM3_MASK | AON_CMU_SEL_PWM3_OSC | AON_CMU_EN_CLK_PWM3_OSC)) |
      -            AON_CMU_CFG_DIV_PWM3(div) | (clk_32k ? 0 : (AON_CMU_SEL_PWM3_OSC | AON_CMU_EN_CLK_PWM3_OSC));
      -    } else if (id == HAL_PWM1_ID_0) {
      -        aoncmu->PWM45_CLK = (aoncmu->PWM45_CLK & ~(AON_CMU_CFG_DIV_PWM4_MASK | AON_CMU_SEL_PWM4_OSC | AON_CMU_EN_CLK_PWM4_OSC)) |
      -            AON_CMU_CFG_DIV_PWM4(div) | (clk_32k ? 0 : (AON_CMU_SEL_PWM4_OSC | AON_CMU_EN_CLK_PWM4_OSC));
      -    } else if (id == HAL_PWM1_ID_1) {
      -        aoncmu->PWM45_CLK = (aoncmu->PWM45_CLK & ~(AON_CMU_CFG_DIV_PWM5_MASK | AON_CMU_SEL_PWM5_OSC | AON_CMU_EN_CLK_PWM5_OSC)) |
      -            AON_CMU_CFG_DIV_PWM5(div) | (clk_32k ? 0 : (AON_CMU_SEL_PWM5_OSC | AON_CMU_EN_CLK_PWM5_OSC));
      -    } else if (id == HAL_PWM1_ID_2) {
      -        aoncmu->PWM67_CLK = (aoncmu->PWM67_CLK & ~(AON_CMU_CFG_DIV_PWM6_MASK | AON_CMU_SEL_PWM6_OSC | AON_CMU_EN_CLK_PWM6_OSC)) |
      -            AON_CMU_CFG_DIV_PWM6(div) | (clk_32k ? 0 : (AON_CMU_SEL_PWM6_OSC | AON_CMU_EN_CLK_PWM6_OSC));
      -    } else if (id == HAL_PWM1_ID_3) {
      -        aoncmu->PWM67_CLK = (aoncmu->PWM67_CLK & ~(AON_CMU_CFG_DIV_PWM7_MASK | AON_CMU_SEL_PWM7_OSC | AON_CMU_EN_CLK_PWM7_OSC)) |
      -            AON_CMU_CFG_DIV_PWM7(div) | (clk_32k ? 0 : (AON_CMU_SEL_PWM7_OSC | AON_CMU_EN_CLK_PWM7_OSC));
      +        aoncmu->PWM23_CLK = (aoncmu->PWM23_CLK & ~(AON_CMU_CFG_DIV_PWM2_MASK | AON_CMU_SEL_OSC_PWM2 | AON_CMU_EN_OSC_PWM2)) |
      +            AON_CMU_CFG_DIV_PWM2(div) | (clk_32k ? 0 : (AON_CMU_SEL_OSC_PWM2 | AON_CMU_EN_OSC_PWM2));
           } else {
      -        ASSERT(0,"PWM id error!");
      +        aoncmu->PWM23_CLK = (aoncmu->PWM23_CLK & ~(AON_CMU_CFG_DIV_PWM3_MASK | AON_CMU_SEL_OSC_PWM3 | AON_CMU_EN_OSC_PWM3)) |
      +            AON_CMU_CFG_DIV_PWM3(div) | (clk_32k ? 0 : (AON_CMU_SEL_OSC_PWM3 | AON_CMU_EN_OSC_PWM3));
           }
           int_unlock(lock);
           return 0;
      @@ -2655,26 +2063,14 @@ void hal_cmu_jtag_clock_disable(void)
           aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_JTAG_DISABLE;
       }
       
      -void hal_cmu_jtag_set_cp(void)
      -{
      -    cmu->PERIPH_CLK |= CMU_JTAG_SEL_CP;
      -}
      -
      -void hal_cmu_jtag_set_a7(void)
      -{
      -    cmu->PERIPH_CLK |= CMU_JTAG_SEL_A7;
      -}
      -
       void hal_cmu_rom_clock_init(void)
       {
      -    aoncmu->CODEC_DIV = (aoncmu->CODEC_DIV & ~AON_CMU_SEL_AON_OSCX2) | AON_CMU_SEL_AON_OSC;
      +    aoncmu->CODEC_DIV = (aoncmu->CODEC_DIV & ~AON_CMU_SEL_CLK_OSCX2) |
      +        AON_CMU_BYPASS_LOCK_PLLBB | AON_CMU_BYPASS_LOCK_PLLAUD | AON_CMU_SEL_CLK_OSC;
           // Enable PMU fast clock
      -    //aoncmu->CLK_OUT = (aoncmu->CLK_OUT & ~AON_CMU_SEL_DCDC_PLL) | AON_CMU_SEL_DCDC_OSC | AON_CMU_BYPASS_DIV_DCDC | AON_CMU_EN_CLK_DCDC0;
      -
      -    hal_cmu_dma_req_init();
      -
      -    // Debug Select CMU REG F4
      -    cmu->MCU_TIMER = SET_BITFIELD(cmu->MCU_TIMER, CMU_DEBUG_REG_SEL, CMU_DEBUG_REG_SEL_DEBUG);
      +    aoncmu->CLK_OUT &= ~(AON_CMU_SEL_DCDC_PLL | AON_CMU_SEL_DCDC_OSCX2);
      +    aoncmu->CLK_OUT |= AON_CMU_BYPASS_DIV_DCDC;
      +    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_DCDC0_ENABLE;
       }
       
       void hal_cmu_init_chip_feature(uint16_t feature)
      @@ -2686,238 +2082,155 @@ void BOOT_TEXT_FLASH_LOC hal_cmu_osc_x2_enable(void)
       {
           // Debug Select CMU REG F4
           cmu->MCU_TIMER = SET_BITFIELD(cmu->MCU_TIMER, CMU_DEBUG_REG_SEL, CMU_DEBUG_REG_SEL_DEBUG);
      -    // Power on OSCX2
      -    aoncmu->PLL_ENABLE = AON_CMU_PU_OSCX2_ENABLE;
      -    // Disable DIG OSCX2
      -    aoncmu->CLK_SELECT &= ~AON_CMU_SEL_OSCX2_DIG;
      -    // Enable OSCX2
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_OSCX2_ENABLE | AON_CMU_EN_CLK_MCU_OSCX2_ENABLE;
      +    // Enable OSCX2 for MCU peripheral
      +    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_OSCX2_MCU_ENABLE;
       }
       
       void BOOT_TEXT_FLASH_LOC hal_cmu_osc_x4_enable(void)
       {
       #ifdef ANA_26M_X4_ENABLE
      -    // Power on OSCX4
      -    aoncmu->PLL_ENABLE = AON_CMU_PU_OSCX4_ENABLE;
      -    // Disable DIG OSCX4
      -    aoncmu->CLK_SELECT &= ~AON_CMU_SEL_OSCX4_DIG;
      -    // Enable OSCX4
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_OSCX4_ENABLE;
      +    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_X4_ANA_ENABLE;
      +#endif
      +#ifdef OSC_26M_X4_AUD2BB
      +    aoncmu->CLK_SELECT |= AON_CMU_SEL_X4_SYS;
      +    aoncmu->CLK_SELECT &= ~AON_CMU_SEL_X4_DIG;
       #endif
       }
       
      -struct CMU_DMA_PER_2_REQ_T {
      -    enum HAL_DMA_PERIPH_T periph;
      -    enum CMU_DMA_REQ_T req;
      -};
      -const static BOOT_RODATA_FLASH_LOC struct CMU_DMA_PER_2_REQ_T periph_map[] = {
      -    {HAL_DMA_PERIPH_NULL,   CMU_DMA_REQ_NULL},
      -    {HAL_AUDMA_CODEC_RX,    CMU_DMA_REQ_CODEC_RX},
      -    {HAL_AUDMA_CODEC_TX,    CMU_DMA_REQ_CODEC_TX},
      -    {HAL_AUDMA_DSD_RX,      CMU_DMA_REQ_DSD_RX},
      -    {HAL_AUDMA_DSD_TX,      CMU_DMA_REQ_DSD_TX},
      -    {HAL_GPDMA_IR_RX,       CMU_DMA_REQ_IR_RX},
      -    {HAL_GPDMA_IR_TX,       CMU_DMA_REQ_IR_TX},
      -    {HAL_GPDMA_FLASH1,      CMU_DMA_REQ_FLS1},
      -    {HAL_GPDMA_FLASH0,      CMU_DMA_REQ_FLS0},
      -    {HAL_AUDMA_BTDUMP,      CMU_DMA_REQ_BTDUMP},
      -    {HAL_GPDMA_SDMMC,       CMU_DMA_REQ_SDEMMC},
      -    {HAL_GPDMA_I2C0_RX,     CMU_DMA_REQ_I2C0_RX},
      -    {HAL_GPDMA_I2C0_TX,     CMU_DMA_REQ_I2C0_TX},
      -    {HAL_GPDMA_I2C1_RX,     CMU_DMA_REQ_I2C1_RX},
      -    {HAL_GPDMA_I2C1_TX,     CMU_DMA_REQ_I2C1_TX},
      -    {HAL_GPDMA_I2C2_RX,     CMU_DMA_REQ_I2C2_RX},
      -    {HAL_GPDMA_I2C2_TX,     CMU_DMA_REQ_I2C2_TX},
      -    {HAL_GPDMA_SPI_RX,      CMU_DMA_REQ_SPILCD0_RX},
      -    {HAL_GPDMA_SPI_TX,      CMU_DMA_REQ_SPILCD0_TX},
      -    {HAL_GPDMA_SPILCD_RX,   CMU_DMA_REQ_SPILCD1_RX},
      -    {HAL_GPDMA_SPILCD_TX,   CMU_DMA_REQ_SPILCD1_TX},
      -    {HAL_GPDMA_ISPI_RX,     CMU_DMA_REQ_SPI_ITN_RX},
      -    {HAL_GPDMA_ISPI_TX,     CMU_DMA_REQ_SPI_ITN_TX},
      -    {HAL_GPDMA_UART0_RX,    CMU_DMA_REQ_UART0_RX},
      -    {HAL_GPDMA_UART0_TX,    CMU_DMA_REQ_UART0_TX},
      -    {HAL_GPDMA_UART1_RX,    CMU_DMA_REQ_UART1_RX},
      -    {HAL_GPDMA_UART1_TX,    CMU_DMA_REQ_UART1_TX},
      -    {HAL_GPDMA_UART2_RX,    CMU_DMA_REQ_UART2_RX},
      -    {HAL_GPDMA_UART2_TX,    CMU_DMA_REQ_UART2_TX},
      -    {HAL_GPDMA_UART3_RX,    CMU_DMA_REQ_UART3_RX},
      -    {HAL_GPDMA_UART3_TX,    CMU_DMA_REQ_UART3_TX},
      -    {HAL_AUDMA_BTPCM_RX,    CMU_DMA_REQ_PCM_RX},
      -    {HAL_AUDMA_BTPCM_TX,    CMU_DMA_REQ_PCM_TX},
      -    {HAL_AUDMA_I2S0_RX,     CMU_DMA_REQ_I2S0_RX},
      -    {HAL_AUDMA_I2S0_TX,     CMU_DMA_REQ_I2S0_TX},
      -    {HAL_AUDMA_I2S1_RX,     CMU_DMA_REQ_I2S1_RX},
      -    {HAL_AUDMA_I2S1_TX,     CMU_DMA_REQ_I2S1_TX},
      -    {HAL_AUDMA_SPDIF0_RX,   CMU_DMA_REQ_SPDIF0_RX},
      -    {HAL_AUDMA_SPDIF0_TX,   CMU_DMA_REQ_SPDIF0_TX},
      -};
      -
      -enum CMU_DMA_REQ_T BOOT_TEXT_FLASH_LOC hal_dma_periph_2_idx(enum HAL_DMA_PERIPH_T periph)
      +void BOOT_TEXT_FLASH_LOC hal_cmu_module_init_state(void)
       {
      -    uint32_t i;
      -    for (i=0; i<ARRAY_SIZE(periph_map); ++i)
      -        if (periph_map[i].periph == periph)
      -            return periph_map[i].req;
      -    return CMU_DMA_REQ_NULL;
      -}
      +    aoncmu->CODEC_DIV = (aoncmu->CODEC_DIV & ~AON_CMU_SEL_CLK_OSCX2) |
      +        AON_CMU_BYPASS_LOCK_PLLBB | AON_CMU_BYPASS_LOCK_PLLAUD | AON_CMU_SEL_CLK_OSC;
      +    // Slow down PMU fast clock
      +    aoncmu->CLK_OUT = (aoncmu->CLK_OUT & ~(AON_CMU_BYPASS_DIV_DCDC | AON_CMU_CFG_DIV_DCDC_MASK)) | AON_CMU_CFG_DIV_DCDC(2);
       
      -void BOOT_TEXT_FLASH_LOC hal_cmu_dma_req_init(void)
      -{
           // DMA channel config
           cmu->ADMA_CH0_4_REQ =
      -        CMU_ADMA_CH0_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[0])) |
      -        CMU_ADMA_CH1_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[1])) |
      -        CMU_ADMA_CH2_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[2])) |
      -        CMU_ADMA_CH3_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[3])) |
      -        CMU_ADMA_CH4_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[4]));
      +        // codec
      +        CMU_ADMA_CH0_REQ_IDX(0) | CMU_ADMA_CH1_REQ_IDX(1) |
      +#ifdef CODEC_DSD
      +        // codec_dsd
      +        CMU_ADMA_CH2_REQ_IDX(16) | CMU_ADMA_CH3_REQ_IDX(17) |
      +#else
      +        // btpcm
      +        CMU_ADMA_CH2_REQ_IDX(2) | CMU_ADMA_CH3_REQ_IDX(3) |
      +#endif
      +        // i2s0
      +        CMU_ADMA_CH4_REQ_IDX(4);
           cmu->ADMA_CH5_9_REQ =
      -        CMU_ADMA_CH5_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[5])) |
      -        CMU_ADMA_CH6_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[6])) |
      -        CMU_ADMA_CH7_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[7])) |
      -        CMU_ADMA_CH8_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[8])) |
      -        CMU_ADMA_CH9_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[9]));
      +        // i2s0
      +        CMU_ADMA_CH5_REQ_IDX(5) |
      +        // fir
      +        CMU_ADMA_CH6_REQ_IDX(6) | CMU_ADMA_CH7_REQ_IDX(7) |
      +        // spdif
      +        CMU_ADMA_CH8_REQ_IDX(8) | CMU_ADMA_CH9_REQ_IDX(9);
           cmu->ADMA_CH10_14_REQ =
      -        CMU_ADMA_CH10_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[10])) |
      -        CMU_ADMA_CH11_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[11])) |
      -        CMU_ADMA_CH12_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[12])) |
      -        CMU_ADMA_CH13_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[13])) |
      -        CMU_ADMA_CH14_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[14]));
      +        // iir
      +        CMU_ADMA_CH10_REQ_IDX(10) | CMU_ADMA_CH11_REQ_IDX(11) |
      +        // btdump
      +        CMU_ADMA_CH12_REQ_IDX(12) |
      +        // mc
      +        CMU_ADMA_CH13_REQ_IDX(13) |
      +        // i2s1
      +        CMU_ADMA_CH14_REQ_IDX(18);
           cmu->ADMA_CH15_REQ =
      -        CMU_ADMA_CH15_REQ_IDX(hal_dma_periph_2_idx(bes2003_audma_fifo_periph[15]));
      -
      +        // i2s1
      +        CMU_ADMA_CH15_REQ_IDX(19);
           cmu->GDMA_CH0_4_REQ =
      -        CMU_GDMA_CH0_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[0])) |
      -        CMU_GDMA_CH1_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[1])) |
      -        CMU_GDMA_CH2_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[2])) |
      -        CMU_GDMA_CH3_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[3])) |
      -        CMU_GDMA_CH4_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[4]));
      +        // flash
      +        CMU_GDMA_CH0_REQ_IDX(20) |
      +        // sdmmc
      +        CMU_GDMA_CH1_REQ_IDX(21) |
      +        // i2c0
      +        CMU_GDMA_CH2_REQ_IDX(22) | CMU_GDMA_CH3_REQ_IDX(23) |
      +        // spi
      +        CMU_GDMA_CH4_REQ_IDX(24);
           cmu->GDMA_CH5_9_REQ =
      -        CMU_GDMA_CH5_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[5])) |
      -        CMU_GDMA_CH6_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[6])) |
      -        CMU_GDMA_CH7_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[7])) |
      -        CMU_GDMA_CH8_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[8])) |
      -        CMU_GDMA_CH9_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[9]));
      +        // spi
      +        CMU_GDMA_CH5_REQ_IDX(25) |
      +        // spilcd
      +        CMU_GDMA_CH6_REQ_IDX(26) | CMU_GDMA_CH7_REQ_IDX(27) |
      +        // uart0
      +        CMU_GDMA_CH8_REQ_IDX(28) | CMU_GDMA_CH9_REQ_IDX(29);
           cmu->GDMA_CH10_14_REQ =
      -        CMU_GDMA_CH10_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[10])) |
      -        CMU_GDMA_CH11_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[11])) |
      -        CMU_GDMA_CH12_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[12])) |
      -        CMU_GDMA_CH13_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[13])) |
      -        CMU_GDMA_CH14_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[14]));
      +        // uart1
      +        CMU_GDMA_CH10_REQ_IDX(30) | CMU_GDMA_CH11_REQ_IDX(31) |
      +        // i2c1
      +        CMU_GDMA_CH12_REQ_IDX(32) | CMU_GDMA_CH13_REQ_IDX(33) |
      +        // uart2
      +        CMU_GDMA_CH14_REQ_IDX(34);
           cmu->GDMA_CH15_REQ =
      -        CMU_GDMA_CH15_REQ_IDX(hal_dma_periph_2_idx(bes2003_gpdma_fifo_periph[15]));
      -}
      -
      -void BOOT_TEXT_FLASH_LOC hal_cmu_module_init_state(void)
      -{
      -    aoncmu->CLK_OUT = AON_CMU_EN_CLK_DCDC0 | AON_CMU_CFG_DIV_DCDC(1);
      -    aoncmu->CODEC_DIV = (aoncmu->CODEC_DIV & ~AON_CMU_SEL_AON_OSCX2) | AON_CMU_SEL_AON_OSC;
      -    // Slow down PMU fast clock
      -    //aoncmu->CLK_OUT = (aoncmu->CLK_OUT & ~(AON_CMU_BYPASS_DIV_DCDC | AON_CMU_CFG_DIV_DCDC_MASK)) | AON_CMU_CFG_DIV_DCDC(2);
      -
      -    hal_cmu_sram_init();
      -
      -    hal_cmu_dma_req_init();
      +        // uart2
      +        CMU_GDMA_CH15_REQ_IDX(35);
       
       #ifndef SIMU
      -    cmu->ORESET_SET = SYS_ORST_USB | SYS_ORST_USB32K | SYS_ORST_PSRAM1G | SYS_ORST_PSRAM200 | SYS_ORST_SDMMC |
      -        SYS_ORST_WDT | SYS_ORST_TIMER2 | SYS_ORST_I2C0 | SYS_ORST_I2C1 | SYS_ORST_I2C2 | SYS_ORST_SPI | SYS_ORST_SLCD | SYS_ORST_SPI_PHY |
      -#ifndef ARM_CMNS
      -        SYS_ORST_UART0 |
      -#endif
      -        SYS_ORST_UART1 | SYS_ORST_UART2 | SYS_ORST_UART3 | SYS_ORST_PCM | SYS_ORST_I2S0 | SYS_ORST_I2S1 |
      -        SYS_ORST_SPDIF0 | SYS_ORST_A7 | SYS_ORST_TSF | SYS_ORST_WDT_AP | SYS_ORST_TIMER0_AP | SYS_ORST_TIMER1_AP | SYS_ORST_FLASH1;
      -    cmu->PRESET_SET = SYS_PRST_WDT | SYS_PRST_TIMER2 | SYS_PRST_I2C0 | SYS_PRST_I2C1 | SYS_PRST_I2C2 | SYS_PRST_IR |
      +    cmu->ORESET_SET = SYS_ORST_USB | SYS_ORST_SDMMC | SYS_ORST_WDT | SYS_ORST_TIMER2 |
      +        SYS_ORST_I2C0 | SYS_ORST_I2C1 | SYS_ORST_SPI | SYS_ORST_SLCD | SYS_ORST_SPI_PHY |
      +        SYS_ORST_UART0 | SYS_ORST_UART1 | SYS_ORST_UART2 | SYS_ORST_I2S0 | SYS_ORST_SPDIF0 | SYS_ORST_PCM |
      +        SYS_ORST_USB32K | SYS_ORST_I2S1;
      +    cmu->PRESET_SET = SYS_PRST_WDT | SYS_PRST_TIMER2 | SYS_PRST_I2C0 | SYS_PRST_I2C1 |
               SYS_PRST_SPI | SYS_PRST_SLCD | SYS_PRST_SPI_PHY |
      -#ifndef ARM_CMNS
      -        SYS_PRST_UART0 |
      -#endif
      -        SYS_PRST_UART1 | SYS_PRST_UART2 | SYS_PRST_UART3 |
      -        SYS_PRST_PCM | SYS_PRST_I2S0 | SYS_PRST_I2S1 | SYS_PRST_SPDIF0 | SYS_PRST_TQWF | SYS_PRST_TQA7;
      -    cmu->HRESET_SET = SYS_HRST_CORE1 | SYS_HRST_BCM | SYS_HRST_USBC | SYS_HRST_USBH | SYS_HRST_CODEC |
      -        SYS_HRST_AX2H_A7 | SYS_HRST_PSRAM1G | SYS_HRST_PSRAM200 | SYS_HRST_BT_DUMP | SYS_HRST_WF_DUMP | SYS_HRST_SDMMC |
      -        SYS_HRST_CHECKSUM | SYS_HRST_CRC | SYS_HRST_FLASH1;
      -    cmu->XRESET_SET = SYS_XRST_DMA | SYS_XRST_NIC | SYS_XRST_IMEMLO | SYS_XRST_IMEMHI | SYS_XRST_PSRAM1G | SYS_XRST_PER |
      -        SYS_XRST_PDBG | SYS_XRST_CORE0 | SYS_XRST_CORE1 | SYS_XRST_CORE2 | SYS_XRST_CORE3 | SYS_XRST_DBG | SYS_XRST_SCU |
      -        SYS_XRST_DISPLAYX | SYS_XRST_DISPLAYH | SYS_XRST_CSI | SYS_XRST_DSI | SYS_XRST_PSRAM1GMX | SYS_XRST_GPV_MAIN | SYS_XRST_GPV_PSRAM1G;
      -    cmu->APRESET_SET = SYS_APRST_BOOTREG | SYS_APRST_WDT| SYS_APRST_TIMER0 | SYS_APRST_TIMER1 | SYS_APRST_TQ | SYS_APRST_DAP |
      -        SYS_APRST_DISPLAY | SYS_APRST_CSI;
      -    cmu->QRESET_SET = SYS_QRST_DSI_32K | SYS_QRST_DSI_PN | SYS_QRST_DSI_TV | SYS_QRST_DSI_PIX |
      -        SYS_QRST_DSI_DSI | SYS_QRST_CSI_LANE | SYS_QRST_CSI_PIX | SYS_QRST_CSI_LANG | SYS_QRST_IR;
      -
      -    cmu->OCLK_DISABLE = SYS_OCLK_USB | SYS_OCLK_USB32K | SYS_OCLK_PSRAM1G | SYS_OCLK_PSRAM200 | SYS_OCLK_SDMMC |
      -        SYS_OCLK_WDT | SYS_OCLK_TIMER2 | SYS_OCLK_I2C0 | SYS_OCLK_I2C1 | SYS_OCLK_I2C2 | SYS_OCLK_SPI | SYS_OCLK_SLCD | SYS_OCLK_SPI_PHY |
      -#ifndef ARM_CMNS
      -        SYS_OCLK_UART0 |
      -#endif
      -        SYS_OCLK_UART1 | SYS_OCLK_UART2 | SYS_OCLK_UART3 | SYS_OCLK_PCM | SYS_OCLK_I2S0 | SYS_OCLK_I2S1 |
      -        SYS_OCLK_SPDIF0 | SYS_OCLK_A7 | SYS_OCLK_TSF | SYS_OCLK_WDT_AP | SYS_OCLK_TIMER0_AP | SYS_OCLK_TIMER1_AP | SYS_OCLK_FLASH1;
      -    cmu->PCLK_DISABLE = SYS_PCLK_WDT | SYS_PCLK_TIMER2 | SYS_PCLK_I2C0 | SYS_PCLK_I2C1 | SYS_PCLK_I2C2 | SYS_PCLK_IR |
      +        SYS_PRST_UART0 | SYS_PRST_UART1 | SYS_PRST_UART2 |
      +        SYS_PRST_PCM | SYS_PRST_I2S0 | SYS_PRST_SPDIF0 | SYS_PRST_I2S1 | SYS_PRST_BCM;
      +    cmu->HRESET_SET = SYS_HRST_SDMMC | SYS_HRST_USBC | SYS_HRST_CODEC | SYS_HRST_FFT |
      +        SYS_HRST_USBH | SYS_HRST_SENSOR_HUB | SYS_HRST_BT_DUMP | SYS_HRST_CP | SYS_HRST_BCM | SYS_HRST_ICACHE0;
      +
      +    cmu->OCLK_DISABLE = SYS_OCLK_USB | SYS_OCLK_SDMMC | SYS_OCLK_WDT | SYS_OCLK_TIMER2 |
      +        SYS_OCLK_I2C0 | SYS_OCLK_I2C1 | SYS_OCLK_SPI | SYS_OCLK_SLCD | SYS_OCLK_SPI_PHY |
      +        SYS_OCLK_UART0 | SYS_OCLK_UART1 | SYS_OCLK_UART2 | SYS_OCLK_I2S0 | SYS_OCLK_SPDIF0 | SYS_OCLK_PCM |
      +        SYS_OCLK_USB32K | SYS_OCLK_I2S1;
      +    cmu->PCLK_DISABLE = SYS_PCLK_WDT | SYS_PCLK_TIMER2 | SYS_PCLK_I2C0 | SYS_PCLK_I2C1 |
               SYS_PCLK_SPI | SYS_PCLK_SLCD | SYS_PCLK_SPI_PHY |
      -#ifndef ARM_CMNS
      -        SYS_PCLK_UART0 |
      -#endif
      -        SYS_PCLK_UART1 | SYS_PCLK_UART2 | SYS_PCLK_UART3 |
      -        SYS_PCLK_PCM | SYS_PCLK_I2S0 | SYS_PCLK_I2S1 | SYS_PCLK_SPDIF0 | SYS_PCLK_TQWF | SYS_PCLK_TQA7;
      -    cmu->HCLK_DISABLE = SYS_HCLK_CORE1 | SYS_HCLK_BCM | SYS_HCLK_USBC | SYS_HCLK_USBH | SYS_HCLK_CODEC |
      -        SYS_HCLK_AX2H_A7 | SYS_HCLK_PSRAM1G | SYS_HCLK_PSRAM200 | SYS_HCLK_BT_DUMP | SYS_HCLK_WF_DUMP | SYS_HCLK_SDMMC |
      -        SYS_HCLK_CHECKSUM | SYS_HCLK_CRC | SYS_HCLK_FLASH1;
      -    cmu->XCLK_DISABLE = SYS_XCLK_DMA | SYS_XCLK_NIC | SYS_XCLK_IMEMLO | SYS_XCLK_IMEMHI | SYS_XCLK_PSRAM1G | SYS_XCLK_PER |
      -        SYS_XCLK_PDBG | SYS_XCLK_CORE0 | SYS_XCLK_CORE1 | SYS_XCLK_CORE2 | SYS_XCLK_CORE3 | SYS_XCLK_DBG | SYS_XCLK_SCU |
      -        SYS_XCLK_DISPLAYX | SYS_XCLK_DISPLAYH | SYS_XCLK_CSI | SYS_XCLK_DSI | SYS_XCLK_PSRAM1GMX | SYS_XCLK_GPV_MAIN | SYS_XCLK_GPV_PSRAM1G;;
      -    cmu->APCLK_DISABLE = SYS_APCLK_BOOTREG | SYS_APCLK_WDT| SYS_APCLK_TIMER0 | SYS_APCLK_TIMER1 | SYS_APCLK_TQ | SYS_APCLK_DAP |
      -        SYS_APCLK_DISPLAY | SYS_APCLK_CSI;
      -    cmu->QCLK_DISABLE = SYS_QCLK_DSI_32K | SYS_QCLK_DSI_PN | SYS_QCLK_DSI_TV | SYS_QCLK_DSI_PIX |
      -        SYS_QCLK_DSI_DSI | SYS_QCLK_CSI_LANE | SYS_QCLK_CSI_PIX | SYS_QCLK_CSI_LANG | SYS_QCLK_IR;
      -
      -    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODEC_DISABLE | AON_CMU_EN_CLK_CODECIIR_DISABLE | AON_CMU_EN_CLK_CODECRS0_DISABLE |
      -        AON_CMU_EN_CLK_CODECRS1_DISABLE | AON_CMU_EN_CLK_CODECHCLK_DISABLE | AON_CMU_EN_CLK_VAD32K_DISABLE |
      -        AON_CMU_EN_CLK_BT_DISABLE | AON_CMU_EN_CLK_WF_DISABLE;
      -
      -    aoncmu->RESET_SET = AON_CMU_ARESETN_SET(AON_ARST_PWM | AON_ARST_PWM1) |
      -        AON_CMU_ORESETN_SET(AON_ORST_PWM0 | AON_ORST_PWM1 | AON_ORST_PWM2 | AON_ORST_PWM3 |
      -            AON_ORST_PWM4 | AON_ORST_PWM5 | AON_ORST_PWM6 | AON_ORST_PWM7 | AON_ORST_BTAON);
      -
      -    aoncmu->SOFT_RSTN_SET = AON_CMU_SOFT_RSTN_CODEC_SET |
      -        AON_CMU_SOFT_RSTN_A7_SET | AON_CMU_SOFT_RSTN_A7CPU_SET |
      -        AON_CMU_SOFT_RSTN_WF_SET | AON_CMU_SOFT_RSTN_WFCPU_SET |
      -        AON_CMU_SOFT_RSTN_BT_SET | AON_CMU_SOFT_RSTN_BTCPU_SET;
      +        SYS_PCLK_UART0 | SYS_PCLK_UART1 | SYS_PCLK_UART2 |
      +        SYS_PCLK_PCM | SYS_PCLK_I2S0 | SYS_PCLK_SPDIF0 | SYS_PCLK_I2S1 | SYS_PCLK_BCM;
      +    cmu->HCLK_DISABLE = SYS_HCLK_SDMMC | SYS_HCLK_USBC | SYS_HCLK_CODEC | SYS_HCLK_FFT |
      +        SYS_HCLK_USBH | SYS_HCLK_SENSOR_HUB | SYS_HCLK_BT_DUMP | SYS_HCLK_CP | SYS_HCLK_BCM | SYS_HCLK_ICACHE0;
      +
      +    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_PLL_CODEC_DISABLE | AON_CMU_EN_CLK_CODEC_HCLK_DISABLE | AON_CMU_EN_CLK_CODEC_DISABLE |
      +        AON_CMU_EN_CLK_CODEC_IIR_DISABLE | AON_CMU_EN_CLK_PLL_BT_DISABLE |
      +        AON_CMU_EN_CLK_60M_BT_DISABLE | AON_CMU_EN_CLK_OSCX2_BT_DISABLE | AON_CMU_EN_CLK_OSC_BT_DISABLE |
      +        AON_CMU_EN_CLK_32K_BT_DISABLE | AON_CMU_EN_CLK_PLL_PER_DISABLE;
      +
      +    aoncmu->RESET_SET = AON_CMU_ARESETN_SET(AON_ARST_PWM) |
      +        AON_CMU_ORESETN_SET(AON_ORST_PWM0 | AON_ORST_PWM1 | AON_ORST_PWM2 | AON_ORST_PWM3) |
      +        AON_CMU_SOFT_RSTN_CODEC_SET | AON_CMU_SOFT_RSTN_BT_SET | AON_CMU_SOFT_RSTN_BTCPU_SET;
       
           aoncmu->MOD_CLK_DISABLE = AON_CMU_MANUAL_ACLK_DISABLE(AON_ACLK_PWM) |
      -        AON_CMU_MANUAL_OCLK_DISABLE(AON_OCLK_PWM0 | AON_OCLK_PWM1 | AON_OCLK_PWM2 | AON_OCLK_PWM3 | AON_OCLK_BTAON);
      +        AON_CMU_MANUAL_OCLK_DISABLE(AON_OCLK_PWM0 | AON_OCLK_PWM1 | AON_OCLK_PWM2 | AON_OCLK_PWM3);
       
           aoncmu->MOD_CLK_MODE &= ~AON_CMU_MODE_ACLK(AON_ACLK_CMU | AON_ACLK_GPIO_INT | AON_ACLK_WDT | AON_ACLK_PWM |
      -        AON_ACLK_TIMER | AON_ACLK_IOMUX);
      +        AON_ACLK_TIMER | AON_ACLK_PSC | AON_ACLK_IOMUX);
           cmu->PCLK_MODE &= ~(SYS_PCLK_CMU | SYS_PCLK_WDT | SYS_PCLK_TIMER0 | SYS_PCLK_TIMER1 | SYS_PCLK_TIMER2);
       
      -    aoncmu->MIPI_CLK &= ~(AON_CMU_EN_CLK_PIX_DSI | AON_CMU_EN_CLK_PIX_CSI | AON_CMU_POL_CLK_DSI_IN |
      -        AON_CMU_POL_CLK_CSI_IN);
      -
           //cmu->HCLK_MODE = 0;
           //cmu->PCLK_MODE = SYS_PCLK_UART0 | SYS_PCLK_UART1 | SYS_PCLK_UART2;
           //cmu->OCLK_MODE = 0;
       #endif
      +
      +#ifdef CORE_SLEEP_POWER_DOWN
      +    hal_cmu_set_wakeup_pc((uint32_t)hal_sleep_core_power_up);
      +#endif
           hal_psc_init();
       }
       
       void BOOT_TEXT_FLASH_LOC hal_cmu_ema_init(void)
       {
      -    // Never change EMA
      +    // Never change EMA in best2300
       }
       
       void hal_cmu_lpu_wait_26m_ready(void)
       {
      -    while ((cmu->WAKEUP_CLK_CFG & (CMU_LPU_AUTO_SWITCH26 | CMU_LPU_STATUS_26M)) ==
      -            CMU_LPU_AUTO_SWITCH26);
      +    while ((cmu->WAKEUP_CLK_CFG & CMU_LPU_STATUS_26M) == 0);
       }
       
       int hal_cmu_lpu_busy(void)
       {
      -    if ((cmu->WAKEUP_CLK_CFG & (CMU_LPU_AUTO_SWITCH26 | CMU_LPU_STATUS_26M)) ==
      -            CMU_LPU_AUTO_SWITCH26) {
      +    if ((cmu->WAKEUP_CLK_CFG & CMU_LPU_AUTO_SWITCH26) &&
      +        (cmu->WAKEUP_CLK_CFG & CMU_LPU_STATUS_26M) == 0) {
               return 1;
           }
      -    if ((cmu->WAKEUP_CLK_CFG & (CMU_LPU_AUTO_SWITCHPLL | CMU_LPU_STATUS_PLL)) ==
      -            CMU_LPU_AUTO_SWITCHPLL) {
      +    if ((cmu->WAKEUP_CLK_CFG & CMU_LPU_AUTO_SWITCHPLL) &&
      +        (cmu->WAKEUP_CLK_CFG & CMU_LPU_STATUS_PLL) == 0) {
               return 1;
           }
           return 0;
      @@ -2944,183 +2257,328 @@ int BOOT_TEXT_FLASH_LOC hal_cmu_lpu_init(enum HAL_CMU_LPU_CLK_CFG_T cfg)
           if (hal_cmu_lpu_busy()) {
               return -1;
           }
      -    lpu_clk = cmu->WAKEUP_CLK_CFG;
      -    lpu_clk &= ~(CMU_LPU_EN_MCU | CMU_LPU_EN_A7 | CMU_LPU_AUTO_SWITCHPLL | CMU_LPU_AUTO_SWITCH26);
       
           if (cfg == HAL_CMU_LPU_CLK_26M) {
      -        lpu_clk |= CMU_LPU_EN_MCU | CMU_LPU_EN_A7 | CMU_LPU_AUTO_SWITCH26;
      +        lpu_clk = CMU_LPU_AUTO_SWITCH26;
           } else if (cfg == HAL_CMU_LPU_CLK_PLL) {
      -        lpu_clk |= CMU_LPU_EN_MCU | CMU_LPU_EN_A7 | CMU_LPU_AUTO_SWITCHPLL | CMU_LPU_AUTO_SWITCH26;
      +        lpu_clk = CMU_LPU_AUTO_SWITCHPLL | CMU_LPU_AUTO_SWITCH26;
           } else {
      +        lpu_clk = 0;
           }
       
           if (lpu_clk & CMU_LPU_AUTO_SWITCH26) {
               // Disable RAM wakeup early
               cmu->MCU_TIMER &= ~CMU_RAM_RETN_UP_EARLY;
               // MCU/ROM/RAM auto clock gating (which depends on RAM gating signal)
      -        cmu->HCLK_MODE &= ~(SYS_HCLK_CORE0 | SYS_HCLK_ROM0 | SYS_HCLK_RAM0 | SYS_HCLK_RAM1 |
      -            SYS_HCLK_RAM2 | SYS_HCLK_RAM3 | SYS_HCLK_RAM4 | SYS_HCLK_RAM5);
      +        cmu->HCLK_MODE &= ~(SYS_HCLK_MCU | SYS_HCLK_ROM0 | SYS_HCLK_ROM1 | SYS_HCLK_ROM2 |
      +            SYS_HCLK_RAM0 | SYS_HCLK_RAM1 | SYS_HCLK_RAM2 | SYS_HCLK_RAMRET | SYS_HCLK_RAM3 |
      +            SYS_HCLK_RAM4 | SYS_HCLK_RAM5 | SYS_HCLK_RAM6);
               // AON_CMU enable auto switch 26M (AON_CMU must have selected 26M and disabled 52M/32K already)
      -        aoncmu->CODEC_DIV |= AON_CMU_LPU_AUTO_SWITCH26;
      +        aoncmu->CLK_SELECT |= AON_CMU_LPU_AUTO_SWITCH26;
           } else {
               // AON_CMU disable auto switch 26M
      -        aoncmu->CODEC_DIV &= ~AON_CMU_LPU_AUTO_SWITCH26;
      +        aoncmu->CLK_SELECT &= ~AON_CMU_LPU_AUTO_SWITCH26;
           }
       
      -    lpu_clk |= CMU_TIMER_WT26(timer_26m);
      +    cmu->WAKEUP_CLK_CFG = CMU_TIMER_WT26(timer_26m) | CMU_TIMER_WTPLL(0) | lpu_clk;
           if (timer_pll) {
      -        lpu_clk |= CMU_TIMER_WTPLL(timer_pll);
               hal_sys_timer_delay(US_TO_TICKS(60));
      -        cmu->WAKEUP_CLK_CFG = lpu_clk;
      -    } else {
      -        lpu_clk |= CMU_TIMER_WTPLL(0);
      -        cmu->WAKEUP_CLK_CFG = lpu_clk;
      +        cmu->WAKEUP_CLK_CFG = CMU_TIMER_WT26(timer_26m) | CMU_TIMER_WTPLL(timer_pll) | lpu_clk;
           }
      +    return 0;
      +}
       
      -#ifndef ARM_CMNS
      -    hal_sec_init(); //need metal_id
      +#ifdef CORE_SLEEP_POWER_DOWN
      +
      +static int SRAM_TEXT_LOC hal_cmu_lpu_sleep_pd(void)
      +{
      +    uint32_t start;
      +    uint32_t timeout;
      +    uint32_t saved_hclk;
      +    uint32_t saved_oclk;
      +    uint32_t saved_top_clk;
      +    uint32_t saved_clk_cfg;
      +    uint32_t saved_periph_clk;
      +    uint32_t saved_sys_div;
      +    uint32_t saved_uart_clk;
      +    uint32_t saved_codec_div;
      +    uint32_t pll_locked;
      +    uint32_t saved_cpu_regs[50];
      +    register uint32_t sp asm("sp");
      +    uint32_t stack_limit;
      +
      +#ifdef ROM_BUILD
      +    extern uint32_t __rom_StackLimit[];
      +    stack_limit = (uint32_t)__rom_StackLimit;
      +#else
      +    extern uint32_t __StackLimit[];
      +    stack_limit = (uint32_t)__StackLimit;
       #endif
      +    if (sp < stack_limit + 20 * 4) {
      +        do {
      +            asm volatile("nop; nop; nop; nop");
      +        } while (1);
      +    }
       
      -    if (hal_get_chip_metal_id() >= HAL_CHIP_METAL_ID_4) {
      -        cmu->CMU_REMAP = CMU_REMAP(0xF); //psram cache and flash cache
      -    } else {
      -        cmu->CMU_REMAP = CMU_REMAP(0xC); //psram cache
      +    NVIC_PowerDownSleep(saved_cpu_regs, ARRAY_SIZE(saved_cpu_regs));
      +
      +    saved_hclk = cmu->HCLK_ENABLE;
      +    saved_oclk = cmu->OCLK_ENABLE;
      +    saved_periph_clk = cmu->PERIPH_CLK;
      +    saved_sys_div = cmu->SYS_DIV;
      +    saved_uart_clk = cmu->UART_CLK;
      +    saved_codec_div = aoncmu->CODEC_DIV;
      +
      +    saved_top_clk = aoncmu->TOP_CLK_ENABLE;
      +    saved_clk_cfg = cmu->SYS_CLK_ENABLE;
      +
      +    // Switch VAD clock to AON and disable codec HCLK
      +    aoncmu->CODEC_DIV |= AON_CMU_SEL_CODEC_HCLK_AON;
      +    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODEC_HCLK_DISABLE;
      +
      +    // Disable memory/flash clock
      +    cmu->OCLK_DISABLE = SYS_OCLK_FLASH;
      +    cmu->HCLK_DISABLE = SYS_HCLK_FLASH;
      +
      +#ifndef ROM_BUILD
      +    // Reset pll div if pll is enabled
      +    if (saved_top_clk & AON_CMU_PU_PLLAUD_ENABLE) {
      +        pmu_pll_div_reset_set(HAL_CMU_PLL_AUD);
      +    }
      +    if (saved_top_clk & AON_CMU_PU_PLLBB_ENABLE) {
      +        pmu_pll_div_reset_set(HAL_CMU_PLL_USB);
      +    }
      +#endif
      +
      +    // Switch system freq to 26M
      +    cmu->SYS_CLK_ENABLE = CMU_SEL_OSC_SYS_ENABLE;
      +    cmu->SYS_CLK_DISABLE = CMU_SEL_OSCX2_SYS_DISABLE | CMU_SEL_PLL_SYS_DISABLE;
      +    cmu->SYS_CLK_DISABLE = CMU_RSTN_DIV_SYS_DISABLE;
      +
      +    // Shutdown PLLs
      +    if (saved_top_clk & AON_CMU_PU_PLLAUD_ENABLE) {
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLAUD_DISABLE;
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_PU_PLLAUD_DISABLE;
      +    }
      +    if (saved_top_clk & AON_CMU_PU_PLLBB_ENABLE) {
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLBB_DISABLE;
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_PU_PLLBB_DISABLE;
      +    }
      +    if (saved_top_clk & AON_CMU_PU_PLLUSB_ENABLE) {
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLUSB_DISABLE;
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_PU_PLLUSB_DISABLE;
      +    }
      +
      +    // Set power down wakeup bootmode
      +    aoncmu->BOOTMODE = (aoncmu->BOOTMODE | HAL_SW_BOOTMODE_POWER_DOWN_WAKEUP) & HAL_SW_BOOTMODE_MASK;
      +    // Set AON_CMU clock to 32K
      +    aoncmu->CODEC_DIV &= ~(AON_CMU_SEL_CLK_OSC | AON_CMU_SEL_CLK_OSCX2);
      +
      +    hal_sleep_core_power_down();
      +
      +    while ((cmu->WAKEUP_CLK_CFG & CMU_LPU_STATUS_26M) == 0);
      +
      +    // Restore AON_CMU clock
      +    aoncmu->CODEC_DIV = saved_codec_div;
      +    // Clear power down wakeup bootmode
      +    aoncmu->BOOTMODE = (aoncmu->BOOTMODE & ~HAL_SW_BOOTMODE_POWER_DOWN_WAKEUP) & HAL_SW_BOOTMODE_MASK;
      +
      +    // Disable memory/flash clock
      +    cmu->OCLK_DISABLE = SYS_OCLK_FLASH;
      +    cmu->HCLK_DISABLE = SYS_HCLK_FLASH;
      +
      +    // Restore PLLs
      +    if (saved_top_clk & (AON_CMU_PU_PLLAUD_ENABLE | AON_CMU_PU_PLLUSB_ENABLE | AON_CMU_PU_PLLBB_ENABLE)) {
      +        pll_locked = 0;
      +        if (saved_top_clk & AON_CMU_PU_PLLAUD_ENABLE) {
      +            aoncmu->TOP_CLK_ENABLE = AON_CMU_PU_PLLAUD_ENABLE;
      +            pll_locked |= AON_CMU_LOCK_PLLAUD;
      +        }
      +        if (saved_top_clk & AON_CMU_PU_PLLBB_ENABLE) {
      +            aoncmu->TOP_CLK_ENABLE = AON_CMU_PU_PLLBB_ENABLE;
      +            pll_locked |= AON_CMU_LOCK_PLLBB;
      +        }
      +        if (saved_top_clk & AON_CMU_PU_PLLUSB_ENABLE) {
      +            aoncmu->TOP_CLK_ENABLE = AON_CMU_PU_PLLUSB_ENABLE;
      +            pll_locked |= AON_CMU_LOCK_PLLUSB;
      +        }
      +#ifndef ROM_BUILD
      +        hal_sys_timer_delay_us(10);
      +        // Clear pll div reset if pll is enabled
      +        if (saved_top_clk & AON_CMU_PU_PLLAUD_ENABLE) {
      +            pmu_pll_div_reset_clear(HAL_CMU_PLL_AUD);
      +        }
      +        if (saved_top_clk & AON_CMU_PU_PLLBB_ENABLE) {
      +            pmu_pll_div_reset_clear(HAL_CMU_PLL_USB);
      +        }
      +#endif
      +        start = hal_sys_timer_get();
      +        timeout = HAL_CMU_PLL_LOCKED_TIMEOUT;
      +        while (//(aoncmu->CODEC_DIV & pll_locked) != pll_locked &&
      +                (hal_sys_timer_get() - start) < timeout);
      +        if (saved_top_clk & AON_CMU_EN_CLK_TOP_PLLAUD_ENABLE) {
      +            aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLAUD_ENABLE;
      +        }
      +        if (saved_top_clk & AON_CMU_EN_CLK_TOP_PLLBB_ENABLE) {
      +            aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLBB_ENABLE;
      +        }
      +        if (saved_top_clk & AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE) {
      +            aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE;
      +        }
      +    }
      +
      +    // Restore system freq
      +    cmu->SYS_CLK_ENABLE = saved_clk_cfg &
      +        (CMU_RSTN_DIV_FLS_ENABLE | CMU_RSTN_DIV_SYS_ENABLE);
      +    cmu->SYS_CLK_ENABLE = saved_clk_cfg;
      +    // The original system freq are at least 26M
      +    //cmu->SYS_CLK_DISABLE = ~saved_clk_cfg;
      +
      +    cmu->PERIPH_CLK = saved_periph_clk;
      +    cmu->SYS_DIV = saved_sys_div;
      +    cmu->UART_CLK = saved_uart_clk;
      +
      +    // Switch VAD clock to MCU and enable codec HCLK if it is on before entering sleep
      +    //aoncmu->CODEC_DIV &= ~AON_CMU_SEL_CODEC_HCLK_AON;
      +    aoncmu->TOP_CLK_ENABLE = saved_top_clk & AON_CMU_EN_CLK_CODEC_HCLK_ENABLE;
      +
      +    int_lock();
      +
      +    NVIC_PowerDownWakeup(saved_cpu_regs, ARRAY_SIZE(saved_cpu_regs));
      +
      +    // TODO:
      +    // 1) Restore hardware modules, e.g., timer, cache, flash, psram, dma, usb, uart, spi, i2c, sdmmc, codec
      +    // 2) Recover system timer in rt_suspend() and rt_resume()
      +    // 3) Dynamically select 32K sleep or power down sleep
      +
      +    if (saved_oclk & SYS_OCLK_FLASH) {
      +        // Enable memory/flash clock
      +        cmu->HCLK_ENABLE = saved_hclk;
      +        cmu->OCLK_ENABLE = saved_oclk;
      +        // Wait until memory/flash clock ready
      +        hal_sys_timer_delay_us(2);
           }
       
           return 0;
       }
       
      +#endif
      +
       __STATIC_FORCEINLINE void cpu_sleep(uint32_t wakeup_cfg)
       {
           __DSB();
       
           if (wakeup_cfg & (CMU_LPU_AUTO_SWITCHPLL | CMU_LPU_AUTO_SWITCH26)) {
               // 1) Avoid race condition between LPU state machine entry and IRQ wakeup:
      -        //    Wait 4 (at least 2) cycles of 32K clock, or 3248 cycles of 26M clock.
      +        //    wait 4 (at least 2) cycles of 32K clock, or 3248 cycles of 26M clock
               // 2) Avoid race condition between CPU clock gating and RAM access when waiting:
      -        //    No consecutive RAM access is allowed.
      -        //    This is related to instruction width/alignment, pipeline state, branch prediction state, etc.
      -        //    Unfortunately, it is too hard to control all of these, especially on M33.
      -        __WFI();
      +        //    No consecutive RAM access is allowed (all instructions must be 16-bit and must have no data access)
      +        asm volatile (
      +            "wfi;"
      +            "movs.n r0, #0x3;"
      +            "lsls r0, #8;"
      +            "adds.n r0, #0x2c;"
      +            "1:;"
      +            "nop;"
      +            "nop;"
      +            "subs r0, 1;"
      +            "bne.n 1b;"
      +            :
      +            :
      +            : "r0", "cc" );
           } else {
               __WFI();
           }
       }
       
      -int SRAM_TEXT_LOC hal_cmu_lpu_sleep(enum HAL_CMU_LPU_SLEEP_MODE_T mode)
      +static int SRAM_TEXT_LOC hal_cmu_lpu_sleep_normal(enum HAL_CMU_LPU_SLEEP_MODE_T mode)
       {
           uint32_t start;
           uint32_t timeout;
      -    uint32_t saved_pll_cfg;
      +    uint32_t saved_hclk;
      +    uint32_t saved_oclk;
      +    uint32_t saved_top_clk;
           uint32_t saved_clk_cfg;
           uint32_t saved_codec_div;
      -    uint32_t saved_top_clk;
           uint32_t wakeup_cfg;
      -    uint32_t saved_hclk;
      -    uint32_t saved_oclk;
      +    bool pd_aud_pll;
      +    bool pd_bb_pll;
      +    bool wait_pll_locked;
       
      +    pd_aud_pll = true;
      +    pd_bb_pll = true;
      +
      +    saved_hclk = cmu->HCLK_ENABLE;
      +    saved_oclk = cmu->OCLK_ENABLE;
           saved_codec_div = aoncmu->CODEC_DIV;
           saved_top_clk = aoncmu->TOP_CLK_ENABLE;
      -    saved_pll_cfg = aoncmu->PLL_ENABLE;
           saved_clk_cfg = cmu->SYS_CLK_ENABLE;
      -    saved_hclk = cmu->HCLK_ENABLE;
      -    saved_oclk = cmu->OCLK_ENABLE;
       
      -    // Switch VAD clock to AON and disable codec HCLK
      -    aoncmu->CODEC_DIV |= AON_CMU_SEL_CODECHCLK_MCU;
           if (mode == HAL_CMU_LPU_SLEEP_MODE_CHIP) {
      -        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODECHCLK_DISABLE;
      +        wakeup_cfg = cmu->WAKEUP_CLK_CFG;
           } else {
      -        // Avoid auto-gating OSC and OSCX2
      -        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_OSCX2_ENABLE | AON_CMU_EN_CLK_TOP_OSC_ENABLE;
      +        wakeup_cfg = 0;
      +        if (pll_user_map[HAL_CMU_PLL_AUD] & (1 << HAL_CMU_PLL_USER_AUD)) {
      +            pd_aud_pll = false;
      +        }
      +        if (pll_user_map[HAL_CMU_PLL_USB] & (1 << HAL_CMU_PLL_USER_AUD)) {
      +            pd_bb_pll = false;
      +        }
           }
       
      +    // Switch VAD clock to AON and disable codec HCLK
      +    aoncmu->CODEC_DIV |= AON_CMU_SEL_CODEC_HCLK_AON;
           if (mode == HAL_CMU_LPU_SLEEP_MODE_CHIP) {
      -        wakeup_cfg = cmu->WAKEUP_CLK_CFG;
      -    } else {
      -        wakeup_cfg = 0;
      +        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_CODEC_HCLK_DISABLE;
           }
       
      -    // Disable memory/flash freq
      -    cmu->OCLK_DISABLE = SYS_OCLK_PSRAM1G | SYS_OCLK_PSRAM200 | SYS_OCLK_FLASH;
      -    cmu->HCLK_DISABLE = SYS_HCLK_PSRAM1G | SYS_HCLK_PSRAM200 | SYS_HCLK_FLASH;
      +    // Disable memory/flash clock
      +    cmu->OCLK_DISABLE = SYS_OCLK_FLASH;
      +    cmu->HCLK_DISABLE = SYS_HCLK_FLASH;
       
       #ifndef ROM_BUILD
           // Reset pll div if pll is enabled
      -    if (saved_pll_cfg & AON_CMU_PU_PLLUSB_ENABLE) {
      -        pmu_pll_div_reset_set(HAL_CMU_PLL_USB);
      +    if (pd_aud_pll && (saved_top_clk & AON_CMU_PU_PLLAUD_ENABLE)) {
      +        pmu_pll_div_reset_set(HAL_CMU_PLL_AUD);
           }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLDDR_ENABLE) {
      -        pmu_pll_div_reset_set(HAL_CMU_PLL_DDR);
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLA7_ENABLE) {
      -        pmu_pll_div_reset_set(HAL_CMU_PLL_DSP);
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_MCU_ENABLE) {
      -        pmu_pll_div_reset_set(HAL_CMU_PLL_BB);
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_PS_ENABLE) {
      -        pmu_pll_div_reset_set(HAL_CMU_PLL_BB_PSRAM);
      +    if (pd_bb_pll && (saved_top_clk & AON_CMU_PU_PLLBB_ENABLE)) {
      +        pmu_pll_div_reset_set(HAL_CMU_PLL_USB);
           }
       #endif
       
           // Setup wakeup mask
      -#ifdef __ARM_ARCH_ISA_ARM
      -    cmu->WAKEUP_MASK0 = GICDistributor->ISENABLER[0];
      -    cmu->WAKEUP_MASK1 = GICDistributor->ISENABLER[1];
      -    cmu->WAKEUP_MASK2 = GICDistributor->ISENABLER[2];
      -#else
           cmu->WAKEUP_MASK0 = NVIC->ISER[0];
           cmu->WAKEUP_MASK1 = NVIC->ISER[1];
      -    cmu->WAKEUP_MASK2 = NVIC->ISER[2];
      -#endif
      -
      -    // Switch system freq to 26M
      -    cmu->SYS_CLK_ENABLE = CMU_SEL_MCU_SLOW_ENABLE;
      -    cmu->SYS_CLK_DISABLE = CMU_SEL_MCU_OSC_4_DISABLE | CMU_SEL_MCU_OSC_2_DISABLE |
      -        CMU_SEL_MCU_OSCX4_DISABLE | CMU_SEL_MCU_FAST_DISABLE | CMU_SEL_MCU_PLL_DISABLE;
      -    cmu->SYS_CLK_DISABLE = CMU_RSTN_DIV_MCU_DISABLE;
      -    // Shutdown PLLs
      -    if (saved_pll_cfg & AON_CMU_PU_PLLUSB_ENABLE) {
      -        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLUSB_DISABLE;
      -        aoncmu->PLL_DISABLE = AON_CMU_PU_PLLUSB_DISABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLDDR_ENABLE) {
      -        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLDDR_DISABLE;
      -        aoncmu->PLL_DISABLE = AON_CMU_PU_PLLDDR_DISABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLA7_ENABLE) {
      -        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLA7_DISABLE;
      -        aoncmu->PLL_DISABLE = AON_CMU_PU_PLLA7_DISABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_MCU_ENABLE) {
      -        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLBB_DISABLE;
      -        aoncmu->PLL_DISABLE = AON_CMU_PU_PLLBB_DIV_MCU_DISABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_PS_ENABLE) {
      -        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLBB_PS_DISABLE;
      -        aoncmu->PLL_DISABLE = AON_CMU_PU_PLLBB_DIV_PS_DISABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_ENABLE) {
      -        aoncmu->PLL_DISABLE = AON_CMU_PU_PLLBB_DISABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_OSCX4_ENABLE) {
      -        aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_OSCX4_DISABLE;
      -        aoncmu->PLL_DISABLE = AON_CMU_PU_OSCX4_DISABLE;
      -    }
       
           if (wakeup_cfg & CMU_LPU_AUTO_SWITCHPLL) {
               // Do nothing
               // Hardware will switch system freq to 32K and shutdown PLLs automatically
           } else {
      +        // Switch system freq to 26M
      +        cmu->SYS_CLK_ENABLE = CMU_SEL_OSC_SYS_ENABLE;
      +        cmu->SYS_CLK_DISABLE = CMU_SEL_OSCX2_SYS_DISABLE | CMU_SEL_PLL_SYS_DISABLE;
      +        cmu->SYS_CLK_DISABLE = CMU_RSTN_DIV_SYS_DISABLE;
      +        // Shutdown PLLs
      +        if (pd_aud_pll && (saved_top_clk & AON_CMU_PU_PLLAUD_ENABLE)) {
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLAUD_DISABLE;
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_PU_PLLAUD_DISABLE;
      +        }
      +        if (pd_bb_pll && (saved_top_clk & AON_CMU_PU_PLLBB_ENABLE)) {
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLBB_DISABLE;
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_PU_PLLBB_DISABLE;
      +        }
      +        if (saved_top_clk & AON_CMU_PU_PLLUSB_ENABLE) {
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_TOP_PLLUSB_DISABLE;
      +            aoncmu->TOP_CLK_DISABLE = AON_CMU_PU_PLLUSB_DISABLE;
      +        }
               if (wakeup_cfg & CMU_LPU_AUTO_SWITCH26) {
                   // Do nothing
                   // Hardware will switch system freq to 32K automatically
               } else {
                   // Manually switch AON_CMU clock to 32K
      -            aoncmu->CODEC_DIV &= ~(AON_CMU_SEL_AON_OSC | AON_CMU_SEL_AON_OSCX2);
      +            aoncmu->CODEC_DIV &= ~(AON_CMU_SEL_CLK_OSC | AON_CMU_SEL_CLK_OSCX2);
                   // Switch system freq to 32K
      -            cmu->SYS_CLK_DISABLE = CMU_SEL_MCU_SLOW_DISABLE;
      +            cmu->SYS_CLK_DISABLE = CMU_SEL_OSC_SYS_DISABLE;
               }
           }
       
      @@ -3134,13 +2592,11 @@ int SRAM_TEXT_LOC hal_cmu_lpu_sleep(enum HAL_CMU_LPU_SLEEP_MODE_T mode)
                   CMU_DEEPSLEEP_EN | CMU_MANUAL_RAM_RETN | CMU_DEEPSLEEP_START;
           }
       
      -#ifndef __ARM_ARCH_ISA_ARM
           if (mode == HAL_CMU_LPU_SLEEP_MODE_CHIP) {
               SCB->SCR = SCB_SCR_SLEEPDEEP_Msk;
           } else {
               SCB->SCR = 0;
           }
      -#endif
       
           cpu_sleep(wakeup_cfg);
       
      @@ -3149,7 +2605,18 @@ int SRAM_TEXT_LOC hal_cmu_lpu_sleep(enum HAL_CMU_LPU_SLEEP_MODE_T mode)
               timeout = HAL_CMU_26M_READY_TIMEOUT + HAL_CMU_PLL_LOCKED_TIMEOUT + HAL_CMU_LPU_EXTRA_TIMEOUT;
               while ((cmu->WAKEUP_CLK_CFG & CMU_LPU_STATUS_PLL) == 0 &&
                   (hal_sys_timer_get() - start) < timeout);
      -        // Hardware will switch system to PLL divider and enable PLLs automatically
      +        // !!! CAUTION !!!
      +        // Hardware will switch system freq to PLL divider and enable PLLs automatically
      +#ifndef ROM_BUILD
      +        hal_sys_timer_delay_us(10);
      +        // Clear pll div reset if pll is enabled
      +        if (saved_top_clk & AON_CMU_PU_PLLAUD_ENABLE) {
      +            pmu_pll_div_reset_clear(HAL_CMU_PLL_AUD);
      +        }
      +        if (saved_top_clk & AON_CMU_PU_PLLBB_ENABLE) {
      +            pmu_pll_div_reset_clear(HAL_CMU_PLL_USB);
      +        }
      +#endif
           } else {
               // Wait for 26M ready
               if (wakeup_cfg & CMU_LPU_AUTO_SWITCH26) {
      @@ -3164,86 +2631,67 @@ int SRAM_TEXT_LOC hal_cmu_lpu_sleep(enum HAL_CMU_LPU_SLEEP_MODE_T mode)
                       hal_sys_timer_delay(timeout);
                   }
                   // Switch system freq to 26M
      -            cmu->SYS_CLK_ENABLE = CMU_SEL_MCU_SLOW_ENABLE;
      +            cmu->SYS_CLK_ENABLE = CMU_SEL_OSC_SYS_ENABLE;
                   // Restore AON_CMU clock
                   aoncmu->CODEC_DIV = saved_codec_div;
               }
      -    }
      -
      -    // System freq is 26M now and will be restored later
      -    // Restore PLLs
      -    if (saved_pll_cfg & AON_CMU_PU_PLLUSB_ENABLE) {
      -        aoncmu->PLL_ENABLE = AON_CMU_PU_PLLUSB_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLDDR_ENABLE) {
      -        aoncmu->PLL_ENABLE = AON_CMU_PU_PLLDDR_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLA7_ENABLE) {
      -        aoncmu->PLL_ENABLE = AON_CMU_PU_PLLA7_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_MCU_ENABLE) {
      -        aoncmu->PLL_ENABLE = AON_CMU_PU_PLLBB_ENABLE | AON_CMU_PU_PLLBB_DIV_MCU_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_PS_ENABLE) {
      -        aoncmu->PLL_ENABLE = AON_CMU_PU_PLLBB_ENABLE | AON_CMU_PU_PLLBB_DIV_PS_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_OSCX4_ENABLE) {
      -        aoncmu->PLL_ENABLE = AON_CMU_PU_OSCX4_ENABLE;
      -    }
      +        // System freq is 26M now and will be restored later
      +        // Restore PLLs
      +        if (saved_top_clk & (AON_CMU_PU_PLLAUD_ENABLE | AON_CMU_PU_PLLUSB_ENABLE | AON_CMU_PU_PLLBB_ENABLE)) {
      +            wait_pll_locked = false;
      +            if (pd_aud_pll && (saved_top_clk & AON_CMU_PU_PLLAUD_ENABLE)) {
      +                aoncmu->TOP_CLK_ENABLE = AON_CMU_PU_PLLAUD_ENABLE;
      +                wait_pll_locked = true;
      +            }
      +            if (pd_bb_pll && (saved_top_clk & AON_CMU_PU_PLLBB_ENABLE)) {
      +                aoncmu->TOP_CLK_ENABLE = AON_CMU_PU_PLLBB_ENABLE;
      +                wait_pll_locked = true;
      +            }
      +            if (saved_top_clk & AON_CMU_PU_PLLUSB_ENABLE) {
      +                aoncmu->TOP_CLK_ENABLE = AON_CMU_PU_PLLUSB_ENABLE;
      +                wait_pll_locked = true;
      +            }
      +            if (wait_pll_locked) {
       #ifndef ROM_BUILD
      -    hal_sys_timer_delay_us(20);
      -    // Clear pll div reset if pll is enabled
      -    if (saved_pll_cfg & AON_CMU_PU_PLLUSB_ENABLE) {
      -        pmu_pll_div_reset_clear(HAL_CMU_PLL_USB);
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLDDR_ENABLE) {
      -        pmu_pll_div_reset_clear(HAL_CMU_PLL_DDR);
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLA7_ENABLE) {
      -        pmu_pll_div_reset_clear(HAL_CMU_PLL_DSP);
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_MCU_ENABLE) {
      -        pmu_pll_div_reset_clear(HAL_CMU_PLL_BB);
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_PS_ENABLE) {
      -        pmu_pll_div_reset_clear(HAL_CMU_PLL_BB_PSRAM);
      -    }
      -    hal_sys_timer_delay_us(10);
      -#endif
      -    if (saved_pll_cfg & AON_CMU_PU_PLLUSB_ENABLE) {
      -        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLDDR_ENABLE) {
      -        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLDDR_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLA7_ENABLE) {
      -        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLA7_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_MCU_ENABLE) {
      -        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLBB_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_PLLBB_DIV_PS_ENABLE) {
      -        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLBB_PS_ENABLE;
      -    }
      -    if (saved_pll_cfg & AON_CMU_PU_OSCX4_ENABLE) {
      -        aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_OSCX4_ENABLE;
      +                hal_sys_timer_delay_us(10);
      +                // Clear pll div reset if pll is enabled
      +                if (pd_aud_pll && (saved_top_clk & AON_CMU_PU_PLLAUD_ENABLE)) {
      +                    pmu_pll_div_reset_clear(HAL_CMU_PLL_AUD);
      +                }
      +                if (pd_bb_pll && (saved_top_clk & AON_CMU_PU_PLLBB_ENABLE)) {
      +                    pmu_pll_div_reset_clear(HAL_CMU_PLL_USB);
      +                }
      +#endif
      +                start = hal_sys_timer_get();
      +                timeout = HAL_CMU_PLL_LOCKED_TIMEOUT;
      +                while ((hal_sys_timer_get() - start) < timeout);
      +            }
      +            if (pd_aud_pll && (saved_top_clk & AON_CMU_EN_CLK_TOP_PLLAUD_ENABLE)) {
      +                aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLAUD_ENABLE;
      +            }
      +            if (pd_bb_pll && (saved_top_clk & AON_CMU_EN_CLK_TOP_PLLBB_ENABLE)) {
      +                aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLBB_ENABLE;
      +            }
      +            if (saved_top_clk & AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE) {
      +                aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE;
      +            }
      +        }
           }
      +
           // Restore system freq
      -    cmu->SYS_CLK_ENABLE = saved_clk_cfg & CMU_RSTN_DIV_MCU_ENABLE;
      +    cmu->SYS_CLK_ENABLE = saved_clk_cfg &
      +        (CMU_RSTN_DIV_FLS_ENABLE | CMU_RSTN_DIV_SYS_ENABLE);
           cmu->SYS_CLK_ENABLE = saved_clk_cfg;
           // The original system freq are at least 26M
           //cmu->SYS_CLK_DISABLE = ~saved_clk_cfg;
       
           // Switch VAD clock to MCU and enable codec HCLK if it is on before entering sleep
      -    aoncmu->CODEC_DIV &= ~AON_CMU_SEL_CODECHCLK_MCU;
      +    aoncmu->CODEC_DIV &= ~AON_CMU_SEL_CODEC_HCLK_AON;
           if (mode == HAL_CMU_LPU_SLEEP_MODE_CHIP) {
      -        aoncmu->TOP_CLK_ENABLE = saved_top_clk & AON_CMU_EN_CLK_CODECHCLK_ENABLE;
      -    } else {
      -        // Restore the original top clock settings
      -        aoncmu->TOP_CLK_DISABLE = ~saved_top_clk;
      +        aoncmu->TOP_CLK_ENABLE = saved_top_clk & AON_CMU_EN_CLK_CODEC_HCLK_ENABLE;
           }
       
      -    if (saved_oclk & (SYS_OCLK_PSRAM1G | SYS_OCLK_PSRAM200 | SYS_OCLK_FLASH)) {
      +    if (saved_oclk & SYS_OCLK_FLASH) {
               // Enable memory/flash clock
               cmu->HCLK_ENABLE = saved_hclk;
               cmu->OCLK_ENABLE = saved_oclk;
      @@ -3254,36 +2702,46 @@ int SRAM_TEXT_LOC hal_cmu_lpu_sleep(enum HAL_CMU_LPU_SLEEP_MODE_T mode)
           return 0;
       }
       
      +int SRAM_TEXT_LOC hal_cmu_lpu_sleep(enum HAL_CMU_LPU_SLEEP_MODE_T mode)
      +{
      +#ifdef CORE_SLEEP_POWER_DOWN
      +    if (mode == HAL_CMU_LPU_SLEEP_MODE_POWER_DOWN) {
      +        return hal_cmu_lpu_sleep_pd();
      +    }
      +#endif
      +    return hal_cmu_lpu_sleep_normal(mode);
      +}
      +
       volatile uint32_t *hal_cmu_get_bootmode_addr(void)
       {
           return &aoncmu->BOOTMODE;
       }
       
      +SRAM_TEXT_LOC
      +volatile uint32_t *hal_cmu_get_memsc_addr(void)
      +{
      +    return &aoncmu->MEMSC[0];
      +}
      +
       void hal_cmu_bt_clock_enable(void)
       {
      -    aoncmu->MOD_CLK_ENABLE = AON_CMU_MANUAL_OCLK_ENABLE(AON_OCLK_BTAON);
      -    aocmu_reg_update_wait();
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_BT_ENABLE;
      +    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_OSCX2_BT_ENABLE | AON_CMU_EN_CLK_OSC_BT_ENABLE | AON_CMU_EN_CLK_32K_BT_ENABLE;
           aocmu_reg_update_wait();
       }
       
       void hal_cmu_bt_clock_disable(void)
       {
      -    aoncmu->MOD_CLK_DISABLE = AON_CMU_MANUAL_OCLK_DISABLE(AON_OCLK_BTAON);
      -    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_BT_DISABLE;
      +    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_OSCX2_BT_DISABLE | AON_CMU_EN_CLK_OSC_BT_DISABLE | AON_CMU_EN_CLK_32K_BT_DISABLE;
       }
       
       void hal_cmu_bt_reset_set(void)
       {
      -    aoncmu->RESET_SET = AON_CMU_ORESETN_SET(AON_ORST_BTAON);
      -    aoncmu->SOFT_RSTN_SET = AON_CMU_SOFT_RSTN_BT_SET | AON_CMU_SOFT_RSTN_BTCPU_SET;
      +    aoncmu->RESET_SET = AON_CMU_SOFT_RSTN_BT_SET | AON_CMU_SOFT_RSTN_BTCPU_SET;
       }
       
       void hal_cmu_bt_reset_clear(void)
       {
      -    aoncmu->RESET_CLR = AON_CMU_ORESETN_CLR(AON_ORST_BTAON);
      -    aocmu_reg_update_wait();
      -    aoncmu->SOFT_RSTN_CLR = AON_CMU_SOFT_RSTN_BT_CLR | AON_CMU_SOFT_RSTN_BTCPU_CLR;
      +    aoncmu->RESET_CLR = AON_CMU_SOFT_RSTN_BT_CLR | AON_CMU_SOFT_RSTN_BTCPU_CLR;
           aocmu_reg_update_wait();
       }
       
      @@ -3292,206 +2750,6 @@ void hal_cmu_bt_module_init(void)
           //btcmu->CLK_MODE = 0;
       }
       
      -void hal_cmu_wifi_clock_enable(void)
      -{
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_CLK_WF_ENABLE;
      -    aocmu_reg_update_wait();
      -}
      -
      -void hal_cmu_wifi_clock_disable(void)
      -{
      -    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_CLK_WF_DISABLE;
      -}
      -
      -void hal_cmu_wifi_reset_set(void)
      -{
      -    aoncmu->SOFT_RSTN_SET = AON_CMU_SOFT_RSTN_WF_SET | AON_CMU_SOFT_RSTN_WFCPU_SET;
      -}
      -
      -void hal_cmu_wifi_reset_clear(void)
      -{
      -    aoncmu->SOFT_RSTN_CLR = AON_CMU_SOFT_RSTN_WF_CLR | AON_CMU_SOFT_RSTN_WFCPU_CLR;
      -    aocmu_reg_update_wait();
      -}
      -
      -void BOOT_TEXT_FLASH_LOC hal_cmu_wlan_set_sleep_allow(uint32_t auto_mode)
      -{
      -    if (auto_mode) { //controlled by wifi sleep signal
      -        aoncmu->RESERVED_0E8 = aoncmu->RESERVED_0E8 & (~((1<<4)|(1<<6)));
      -    } else { //force allow cmu sleep
      -        aoncmu->RESERVED_0E8 = (aoncmu->RESERVED_0E8 & (~((1<<5)|(1<<7)))) | ((1<<4)|(1<<6));
      -    }
      -}
      -
      -static void GPV_init(void)
      -{
      -#ifdef GPV_MAIN_BASE
      -    volatile uint32_t *gpv_ctrl_psram = (volatile uint32_t *)(GPV_MAIN_BASE+0x6000);
      -    volatile uint32_t *gpv_ctrl_x2h = (volatile uint32_t *)(GPV_MAIN_BASE+0x7000);
      -    gpv_ctrl_psram[17] |= 0x2; //0x50306044
      -    gpv_ctrl_x2h[17] |= 0x2; //0x50307044
      -#endif
      -}
      -
      -void hal_cmu_dsp_clock_enable(void)
      -{
      -    enum HAL_CMU_PLL_T dsp;
      -#ifdef DSP_ENABLE
      -    hal_psc_a7_enable();
      -#endif
      -    // DSP AXI clock divider defaults to 4 (div = reg_val + 2)
      -    cmu->DSP_DIV = SET_BITFIELD(cmu->DSP_DIV, CMU_CFG_DIV_XCLK, 2);
      -    cmu->XCLK_ENABLE = SYS_XCLK_DMA | SYS_XCLK_NIC | SYS_XCLK_IMEMLO | SYS_XCLK_IMEMHI | SYS_XCLK_PER |
      -        SYS_XCLK_PDBG | SYS_XCLK_CORE0 | SYS_XCLK_CORE1 | SYS_XCLK_CORE2 | SYS_XCLK_CORE3 | SYS_XCLK_DBG | SYS_XCLK_SCU |
      -        SYS_XCLK_GPV_MAIN;
      -    cmu->APCLK_ENABLE = SYS_APCLK_BOOTREG | SYS_APCLK_WDT| SYS_APCLK_TIMER0 | SYS_APCLK_TIMER1 | SYS_APCLK_TQ | SYS_APCLK_DAP;
      -    cmu->HCLK_ENABLE = SYS_HCLK_AX2H_A7;
      -
      -    cmu->DSP_CFG0 |= CMU_CA7_DBGEN_MASK | CMU_CA7_SPIDEN_MASK | CMU_CA7_NIDEN_MASK | CMU_CA7_SPNIDEN_MASK;
      -
      -    cmu->PERIPH_CLK |= CMU_A7_ALLIRQ_MASK;
      -    cmu->DSP_CFG0 |= CMU_A7TOM33_IRQS_MASK(8);
      -
      -#ifdef DSP_USE_BBPLL
      -    dsp = HAL_CMU_PLL_BB;
      -#elif defined(DSP_USE_USBPLL)
      -    dsp = HAL_CMU_PLL_USB;
      -#else
      -    dsp = HAL_CMU_PLL_DSP;
      -#endif
      -    hal_cmu_dsp_select_pll(dsp);
      -    hal_cmu_pll_enable(dsp, HAL_CMU_PLL_USER_DSP);
      -
      -    hal_cmu_dsp_set_freq(HAL_CMU_FREQ_780M);
      -
      -#ifdef DSP_ENABLE
      -    hal_cmu_clock_enable(HAL_CMU_MOD_O_A7);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_O_WDT_AP);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_O_TIMER0_AP);
      -    hal_cmu_clock_enable(HAL_CMU_MOD_O_TIMER1_AP);
      -#ifndef ARM_CMNS
      -    ///TODO: add cmse interface if trustzone is enabled
      -    GPV_init();
      -#endif
      -#endif
      -}
      -
      -void hal_cmu_dsp_clock_disable(void)
      -{
      -    enum HAL_CMU_PLL_T dsp;
      -
      -    hal_cmu_clock_disable(HAL_CMU_MOD_O_A7);
      -
      -#ifdef DSP_USE_BBPLL
      -    dsp = HAL_CMU_PLL_BB;
      -#elif defined(DSP_USE_USBPLL)
      -    dsp = HAL_CMU_PLL_USB;
      -#else
      -    dsp = HAL_CMU_PLL_DSP;
      -#endif
      -    hal_cmu_pll_disable(dsp, HAL_CMU_PLL_USER_DSP);
      -
      -    cmu->XCLK_DISABLE = SYS_XCLK_DMA | SYS_XCLK_NIC | SYS_XCLK_IMEMLO | SYS_XCLK_IMEMHI | SYS_XCLK_PER |
      -        SYS_XCLK_PDBG | SYS_XCLK_CORE0 | SYS_XCLK_CORE1 | SYS_XCLK_CORE2 | SYS_XCLK_CORE3 | SYS_XCLK_DBG | SYS_XCLK_SCU |
      -        SYS_XCLK_GPV_MAIN;
      -    cmu->APCLK_DISABLE = SYS_APCLK_BOOTREG | SYS_APCLK_WDT| SYS_APCLK_TIMER0 | SYS_APCLK_TIMER1 | SYS_APCLK_TQ | SYS_APCLK_DAP;
      -    cmu->OCLK_DISABLE = SYS_OCLK_WDT_AP | SYS_OCLK_TIMER0_AP | SYS_OCLK_TIMER1_AP;
      -    cmu->HCLK_DISABLE = SYS_HCLK_AX2H_A7;
      -
      -    hal_psc_a7_disable();
      -}
      -
      -void hal_cmu_dsp_reset_set(void)
      -{
      -    aoncmu->SOFT_RSTN_SET = AON_CMU_SOFT_RSTN_A7_SET | AON_CMU_SOFT_RSTN_A7CPU_SET;
      -    cmu->ORESET_SET = SYS_ORST_WDT_AP | SYS_ORST_TIMER0_AP | SYS_ORST_TIMER1_AP;
      -    cmu->XRESET_SET = SYS_XRST_DMA | SYS_XRST_NIC | SYS_XRST_IMEMLO | SYS_XRST_IMEMHI | SYS_XRST_PER |
      -        SYS_XRST_PDBG | SYS_XRST_CORE0 | SYS_XRST_CORE1 | SYS_XRST_CORE2 | SYS_XRST_CORE3 | SYS_XRST_DBG | SYS_XRST_SCU |
      -        SYS_XRST_GPV_MAIN;
      -    cmu->APRESET_SET = SYS_APRST_BOOTREG | SYS_APRST_WDT | SYS_APRST_TIMER0 | SYS_APRST_TIMER1 | SYS_APRST_TQ | SYS_APRST_DAP;
      -    cmu->HRESET_SET = SYS_HRST_AX2H_A7;
      -}
      -
      -void hal_cmu_dsp_reset_clear(void)
      -{
      -    cmu->APRESET_CLR = SYS_APCLK_BOOTREG | SYS_APCLK_WDT| SYS_APCLK_TIMER0 | SYS_APCLK_TIMER1 | SYS_APCLK_TQ | SYS_APCLK_DAP;
      -    cmu->XRESET_CLR = SYS_XRST_DMA | SYS_XRST_NIC | SYS_XRST_IMEMLO | SYS_XRST_IMEMHI | SYS_XRST_PER |
      -        SYS_XRST_PDBG | SYS_XRST_CORE0 | SYS_XRST_CORE1 | SYS_XRST_CORE2 | SYS_XRST_CORE3 | SYS_XRST_DBG | SYS_XRST_SCU |
      -        SYS_XRST_GPV_MAIN;
      -    cmu->ORESET_CLR = SYS_ORST_WDT_AP | SYS_ORST_TIMER0_AP | SYS_ORST_TIMER1_AP;
      -    cmu->HRESET_CLR = SYS_HRST_AX2H_A7;
      -    aoncmu->SOFT_RSTN_CLR = AON_CMU_SOFT_RSTN_A7_CLR;
      -    aocmu_reg_update_wait();
      -}
      -
      -void hal_cmu_dsp_reset_hold(void)
      -{
      -    aoncmu->SOFT_RSTN_SET = AON_CMU_SOFT_RSTN_A7_SET | AON_CMU_SOFT_RSTN_A7CPU_SET;
      -    cmu->HRESET_SET = SYS_HRST_AX2H_A7 | SYS_HRST_PSRAM1G;
      -    cmu->ORESET_SET = SYS_ORST_PSRAM1G;
      -    cmu->ORESET_SET = SYS_ORST_WDT_AP | SYS_ORST_TIMER1_AP;
      -}
      -
      -void hal_cmu_dsp_reset_release(void)
      -{
      -    cmu->ORESET_CLR = SYS_ORST_WDT_AP | SYS_ORST_TIMER1_AP;
      -    cmu->ORESET_CLR = SYS_ORST_PSRAM1G;
      -    cmu->HRESET_CLR = SYS_HRST_AX2H_A7 | SYS_HRST_PSRAM1G;
      -    aoncmu->SOFT_RSTN_CLR = AON_CMU_SOFT_RSTN_A7_CLR;
      -    aocmu_reg_update_wait();
      -}
      -
      -void hal_cmu_dsp_init_boot_reg(uint32_t entry)
      -{
      -    int i;
      -    volatile uint32_t *boot = (volatile uint32_t *)DSP_BOOT_REG;
      -
      -    // Unlock
      -    boot[32] = 0xCAFE0001;
      -    __DMB();
      -
      -    for (i = 0; i < 8; i++) {
      -        // ldr pc, [pc, #24]
      -        boot[0 + i] = 0xE59FF018;
      -        // Init_Handler
      -        boot[8 + i] = 0x00000040;
      -    }
      -    // b   40
      -    boot[16] = 0xEAFFFFFE;
      -
      -    // Update reset handler
      -    boot[8] = entry;
      -
      -    // Lock
      -    __DMB();
      -    boot[32] = 0xCAFE0000;
      -    __DMB();
      -}
      -
      -void hal_cmu_dsp_start_cpu(void)
      -{
      -    hal_cmu_dsp_set_freq(HAL_CMU_FREQ_156M);//div 5
      -    aoncmu->SOFT_RSTN_CLR = AON_CMU_SOFT_RSTN_A7CPU_CLR;
      -}
      -
      -void hal_cmu_dsp_stop_cpu(void)
      -{
      -    uint32_t lock;
      -    lock = int_lock();
      -#ifdef PSRAMUHS_ENABLE
      -    hal_psramuhs_hold();
      -#endif
      -    hal_cmu_dsp_reset_hold();
      -    //hal_cmu_dsp_clock_disable();
      -
      -#ifdef PSRAMUHS_ENABLE
      -    //hal_cmu_dsp_clock_enable();
      -    hal_cmu_dsp_reset_release();
      -    hal_psramuhs_release();
      -#endif
      -    int_unlock(lock);
      -}
      -
       uint32_t hal_cmu_get_aon_chip_id(void)
       {
           return aoncmu->CHIP_ID;
      @@ -3504,18 +2762,9 @@ uint32_t hal_cmu_get_aon_revision_id(void)
       
       void hal_cmu_cp_enable(uint32_t sp, uint32_t entry)
       {
      -    struct CP_STARTUP_CFG_T * cp_cfg;
      -    uint32_t cfg_addr;
      -
      -    // Use (sp - 128) as the default vector. The Address must aligned to 128-byte boundary.
      -    cfg_addr = (sp - (1 << 7)) & ~((1 << 7) - 1);
      -
      -    cmu->CP_VTOR = cfg_addr;
      -    cp_cfg = (struct CP_STARTUP_CFG_T *)cfg_addr;
      -
           cp_cfg->stack = sp;
           cp_cfg->reset_hdlr = (uint32_t)system_cp_reset_handler;
      -    cp_entry = entry;
      +    cp_cfg->entry = entry;
       
           hal_cmu_clock_enable(HAL_CMU_MOD_H_CP);
           hal_cmu_reset_clear(HAL_CMU_MOD_H_CP);
      @@ -3529,153 +2778,5 @@ void hal_cmu_cp_disable(void)
       
       uint32_t hal_cmu_cp_get_entry_addr(void)
       {
      -    return cp_entry;
      -}
      -
      -void hal_cmu_cp_boot(uint32_t entry)
      -{
      -    cmu->CP_VTOR = entry;
      -
      -    hal_cmu_clock_enable(HAL_CMU_MOD_H_CACHE1);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_H_CACHE1);
      -
      -    hal_cmu_clock_enable(HAL_CMU_MOD_H_CP);
      -    hal_cmu_reset_clear(HAL_CMU_MOD_H_CP);
      -}
      -
      -void hal_cmu_jtag_sel(enum HAL_CMU_JTAG_SEL_T sel)
      -{
      -    uint32_t lock;
      -
      -    lock = int_lock();
      -    cmu->PERIPH_CLK &= ~CMU_JTAG_SEL_MASK;
      -    switch (sel) {
      -        case HAL_CMU_JTAG_SEL_CP:
      -            cmu->PERIPH_CLK |= CMU_JTAG_SEL_CP;
      -            break;
      -        case HAL_CMU_JTAG_SEL_A7:
      -            cmu->PERIPH_CLK |= CMU_JTAG_SEL_A7;
      -            break;
      -        default:
      -            break;
      -    }
      -    int_unlock(lock);
      -}
      -
      -void hal_cmu_dsp_setup(void)
      -{
      -    hal_sys_timer_open();
      -
      -    hal_sysfreq_req(HAL_SYSFREQ_USER_INIT, HAL_CMU_FREQ_390M);
      -
      -}
      -
      -void hal_cmu_flash0_dual_die()
      -{
      -    cmu->MCU_TIMER &= ~CMU_FLS1_IO_SEL;
      -}
      -
      -void hal_cmu_flash1_enable()
      -{
      -    //aoncmu->FLASH_IOCFG |= AON_CMU_PU_FLASH1_IO;
      -    aoncmu->FLASH_IOCFG = SET_BITFIELD(aoncmu->FLASH_IOCFG, AON_CMU_FLASH1_IODRV, 0x7) | AON_CMU_PU_FLASH1_IO;
      -}
      -
      -void hal_cmu_set_flash0_x8_mode(uint32_t en)
      -{
      -    if (en)
      -        cmu->MCU_TIMER |= CMU_FLS0_X8_SEL;
      -    else
      -        cmu->MCU_TIMER &= ~CMU_FLS0_X8_SEL;
      -}
      -
      -void hal_cmu_set_flash0_size(enum HAL_FLASH0_SIZE_CFG cfg)
      -{
      -    *(volatile uint32_t *)(ICACHE_CTRL_BASE + 0x44) = cfg;
      -}
      -
      -uint32_t hal_cmu_get_osc_ready_cycle_cnt(void)
      -{
      -    uint32_t cnt=10;
      -
      -
      -
      -    return cnt;
      -}
      -
      -uint32_t hal_cmu_get_osc_switch_overhead(void)
      -{
      -        return 6;
      -}
      -
      -void hal_cmu_bt_sys_set_freq(enum HAL_CMU_FREQ_T freq)
      -{
      -
      -}
      -
      -void hal_cmu_bt_sys_clock_force_on(void)
      -{
      -    uint32_t lock;
      -
      -    lock = int_lock();
      -    hal_psc_dslp_force_on_bt_enable();
      -    aoncmu->TOP_CLK_ENABLE = AON_CMU_EN_BT_CLK_SYS_ENABLE;
      -    int_unlock(lock);
      -    aocmu_reg_update_wait();
      -}
      -
      -void hal_cmu_bt_sys_clock_auto(void)
      -{
      -    uint32_t lock;
      -
      -    lock = int_lock();
      -    aoncmu->TOP_CLK_DISABLE = AON_CMU_EN_BT_CLK_SYS_DISABLE;
      -    hal_psc_dslp_force_on_bt_disable();
      -    int_unlock(lock);
      -}
      -
      -#ifdef REUSE_WIFI_CALI_RESULT
      -extern void save_wifi_cali_result();
      -#endif
      -
      -void hal_cmu_shutdown_hook(void)
      -{
      -    int_lock();
      -    hal_cmu_codec_clock_disable();
      -    hal_cmu_codec_rs_disable();
      -
      -    hal_cmu_dsp_reset_set();
      -    hal_cmu_dsp_clock_disable();
      -
      -#ifdef REUSE_WIFI_CALI_RESULT
      -    save_wifi_cali_result();
      -#endif
      -
      -    hal_cmu_wifi_reset_set();
      -    hal_cmu_wifi_clock_disable();
      -    hal_cmu_cp_disable();
      -    hal_cmu_bt_reset_set();
      -    hal_cmu_bt_clock_disable();
      -
      -    // hal_norflash_deinit();
      -
      -    hal_cmu_mem_set_freq(HAL_CMU_FREQ_26M);
      -    hal_cmu_sys_set_freq(HAL_CMU_FREQ_26M);
      -
      -    // psramuhsphy_sleep();
      -    // hal_psram_phy_sleep();
      -    // hal_cmu_pll_disable(HAL_CMU_PLL_BB, HAL_CMU_PLL_USER_ALL);
      -    // hal_cmu_pll_disable(HAL_CMU_PLL_BB_PSRAM, HAL_CMU_PLL_USER_ALL);
      -    // hal_cmu_pll_disable(HAL_CMU_PLL_DDR, HAL_CMU_PLL_USER_ALL);
      -    // hal_cmu_pll_disable(HAL_CMU_PLL_DSP, HAL_CMU_PLL_USER_ALL);
      -    // hal_cmu_pll_disable(HAL_CMU_PLL_USB, HAL_CMU_PLL_USER_ALL);
      -}
      -
      -void hal_cmu_sys_reboot(void)
      -{
      -#if defined(FLASH_SUSPEND) && defined(FLASH_API_GUARD_THREAD)
      -    norflash_api_flush_all();
      -#endif
      -    hal_cmu_shutdown_hook();
      -    hal_cmu_reset_set(HAL_CMU_MOD_GLOBAL);
      +    return cp_cfg->entry;
       }
  • platform/hal/best2300p/hal_cmu_best2300p.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/hal_cmu_best2300p.h bes/platform/hal/best2300p/hal_cmu_best2300p.h
      index aafdb5fb036..3ac2ef6ad59 100644
      --- a/platform/hal/best2300p/hal_cmu_best2300p.h
      +++ b/platform/hal/best2300p/hal_cmu_best2300p.h
      @@ -19,131 +19,120 @@
       extern "C" {
       #endif
       
      -#define HAL_CMU_VALID_CRYSTAL_FREQ          { 24000000, 40000000, }
      +#define HAL_CMU_VALID_CRYSTAL_FREQ          { 26000000, 24000000, 40000000, 48000000, }
       
       enum HAL_CMU_MOD_ID_T {
           // HCLK/HRST
           HAL_CMU_MOD_H_MCU,          // 0
      -    HAL_CMU_MOD_H_CACHE0,       // 1
      -    HAL_CMU_MOD_H_CP,           // 2
      -    HAL_CMU_MOD_H_CACHE1,       // 3
      -    HAL_CMU_MOD_H_ADMA,         // 4
      -    HAL_CMU_MOD_H_GDMA,         // 5
      -    HAL_CMU_MOD_H_SEC_ENG,      // 6
      -    HAL_CMU_MOD_H_USBC,         // 7
      -    HAL_CMU_MOD_H_USBH,         // 8
      -    HAL_CMU_MOD_H_I2C_SLAVE,    // 9
      -    HAL_CMU_MOD_H_AX2H_A7,      // 10
      -    HAL_CMU_MOD_H_AH2H_WF,      // 11
      -    HAL_CMU_MOD_H_AH2H_BT,      // 12
      -    HAL_CMU_MOD_H_CODEC,        // 13
      -    HAL_CMU_MOD_H_AHB1,         // 14
      -    HAL_CMU_MOD_H_AHB0,         // 15
      -    HAL_CMU_MOD_H_PSRAM1G,      // 16
      -    HAL_CMU_MOD_H_PSRAM200,     // 17
      -    HAL_CMU_MOD_H_FLASH,        // 18
      -    HAL_CMU_MOD_H_RAM5,         // 19
      -    HAL_CMU_MOD_H_RAM4,         // 20
      -    HAL_CMU_MOD_H_RAM3,         // 21
      -    HAL_CMU_MOD_H_RAM2,         // 22
      -    HAL_CMU_MOD_H_RAM1,         // 23
      -    HAL_CMU_MOD_H_RAM0,         // 24
      -    HAL_CMU_MOD_H_ROM0,         // 25
      -    HAL_CMU_MOD_H_BT_DUMP,      // 26
      -    HAL_CMU_MOD_H_WF_DUMP,      // 27
      -    HAL_CMU_MOD_H_SDMMC,        // 28
      -    HAL_CMU_MOD_H_CHECKSUM,     // 29
      -    HAL_CMU_MOD_H_CRC,          // 30
      -    HAL_CMU_MOD_H_FLASH1,       // 31
      +    HAL_CMU_MOD_H_ROM0,         // 1
      +    HAL_CMU_MOD_H_ROM1,         // 2
      +    HAL_CMU_MOD_H_ROM2,         // 3
      +    HAL_CMU_MOD_H_RAM0,         // 4
      +    HAL_CMU_MOD_H_RAM1,         // 5
      +    HAL_CMU_MOD_H_RAM2,         // 6
      +    HAL_CMU_MOD_H_RAMRET,       // 7
      +    HAL_CMU_MOD_H_AHB0,         // 8
      +    HAL_CMU_MOD_H_AHB1,         // 9
      +    HAL_CMU_MOD_H_AH2H_BT,      // 10
      +    HAL_CMU_MOD_H_ADMA,         // 11
      +    HAL_CMU_MOD_H_GDMA,         // 12
      +    HAL_CMU_MOD_H_CACHE,        // 13
      +    HAL_CMU_MOD_H_FLASH,        // 14
      +    HAL_CMU_MOD_H_SDMMC,        // 15
      +    HAL_CMU_MOD_H_USBC,         // 16
      +    HAL_CMU_MOD_H_CODEC,        // 17
      +    HAL_CMU_MOD_H_FFT,          // 18
      +    HAL_CMU_MOD_H_I2C_SLAVE,    // 19
      +    HAL_CMU_MOD_H_USBH,         // 20
      +    HAL_CMU_MOD_H_SENSOR_ENG,   // 21
      +    HAL_CMU_MOD_H_BT_DUMP,      // 22
      +    HAL_CMU_MOD_H_CP,           // 23
      +    HAL_CMU_MOD_H_RAM3,         // 24
      +    HAL_CMU_MOD_H_RAM4,         // 25
      +    HAL_CMU_MOD_H_RAM5,         // 26
      +    HAL_CMU_MOD_H_RAM6,         // 27
      +    HAL_CMU_MOD_H_SEC_ENG,      // 28
      +    HAL_CMU_MOD_H_ICACHE0,      // 29
      +    HAL_CMU_MOD_H_ICACHE1,      // 30
           // PCLK/PRST
      -    HAL_CMU_MOD_P_CMU,          // 0
      -    HAL_CMU_MOD_P_WDT,          // 1
      -    HAL_CMU_MOD_P_TIMER0,       // 2
      -    HAL_CMU_MOD_P_TIMER1,       // 3
      -    HAL_CMU_MOD_P_TIMER2,       // 4
      -    HAL_CMU_MOD_P_I2C0,         // 5
      -    HAL_CMU_MOD_P_I2C1,         // 6
      -    HAL_CMU_MOD_P_SPI,          // 7
      -    HAL_CMU_MOD_P_SLCD,         // 8
      -    HAL_CMU_MOD_P_SPI_ITN,      // 9
      -    HAL_CMU_MOD_P_SPI_PHY,      // 10
      -    HAL_CMU_MOD_P_UART0,        // 11
      -    HAL_CMU_MOD_P_UART1,        // 12
      -    HAL_CMU_MOD_P_UART2,        // 13
      -    HAL_CMU_MOD_P_PCM,          // 14
      -    HAL_CMU_MOD_P_I2S0,         // 15
      -    HAL_CMU_MOD_P_SPDIF0,       // 16
      -    HAL_CMU_MOD_P_SEC_ENG,      // 20
      -    HAL_CMU_MOD_P_I2S1,         // 25
      +    HAL_CMU_MOD_P_CMU,          // 31
      +    HAL_CMU_MOD_P_WDT,          // 32
      +    HAL_CMU_MOD_P_TIMER0,       // 33
      +    HAL_CMU_MOD_P_TIMER1,       // 34
      +    HAL_CMU_MOD_P_TIMER2,       // 35
      +    HAL_CMU_MOD_P_I2C0,         // 36
      +    HAL_CMU_MOD_P_I2C1,         // 37
      +    HAL_CMU_MOD_P_SPI,          // 38
      +    HAL_CMU_MOD_P_SLCD,         // 39
      +    HAL_CMU_MOD_P_SPI_ITN,      // 40
      +    HAL_CMU_MOD_P_SPI_PHY,      // 41
      +    HAL_CMU_MOD_P_UART0,        // 42
      +    HAL_CMU_MOD_P_UART1,        // 43
      +    HAL_CMU_MOD_P_UART2,        // 44
      +    HAL_CMU_MOD_P_PCM,          // 45
      +    HAL_CMU_MOD_P_I2S0,         // 46
      +    HAL_CMU_MOD_P_SPDIF0,       // 47
      +    HAL_CMU_MOD_P_I2S1,         // 48
      +    HAL_CMU_MOD_P_SEC_ENG,      // 49
           // OCLK/ORST
      -    HAL_CMU_MOD_O_SLEEP,        // 0
      -    HAL_CMU_MOD_O_USB,          // 1
      -    HAL_CMU_MOD_O_USB32K,       // 2
      -    HAL_CMU_MOD_O_PSRAM1G,      // 3
      -    HAL_CMU_MOD_O_PSRAM200,     // 4
      -    HAL_CMU_MOD_O_FLASH,        // 5
      -    HAL_CMU_MOD_O_SDMMC,        // 6
      -    HAL_CMU_MOD_O_WDT,          // 7
      -    HAL_CMU_MOD_O_TIMER0,       // 8
      -    HAL_CMU_MOD_O_TIMER1,       // 9
      -    HAL_CMU_MOD_O_TIMER2,       // 10
      -    HAL_CMU_MOD_O_I2C0,         // 11
      -    HAL_CMU_MOD_O_I2C1,         // 12
      -    HAL_CMU_MOD_O_SPI,          // 13
      -    HAL_CMU_MOD_O_SLCD,         // 14
      -    HAL_CMU_MOD_O_SPI_ITN,      // 15
      -    HAL_CMU_MOD_O_SPI_PHY,      // 16
      -    HAL_CMU_MOD_O_UART0,        // 17
      -    HAL_CMU_MOD_O_UART1,        // 18
      -    HAL_CMU_MOD_O_UART2,        // 19
      -    HAL_CMU_MOD_O_PCM,          // 20
      -    HAL_CMU_MOD_O_I2S0,         // 21
      -    HAL_CMU_MOD_O_SPDIF0,       // 22
      -    HAL_CMU_MOD_O_I2S1,         // 23
      -    HAL_CMU_MOD_O_A7,           // 24
      -    HAL_CMU_MOD_O_TSF,          // 25
      -    HAL_CMU_MOD_O_WDT_AP,       // 26
      -    HAL_CMU_MOD_O_TIMER0_AP,    // 27
      -    HAL_CMU_MOD_O_TIMER1_AP,    // 28
      -    HAL_CMU_MOD_O_FLASH1,       // 29
      -    HAL_CMU_MOD_O_I2C2,         // 30
      -    HAL_CMU_MOD_O_UART3,        // 31
      +    HAL_CMU_MOD_O_SLEEP,        // 50
      +    HAL_CMU_MOD_O_FLASH,        // 51
      +    HAL_CMU_MOD_O_USB,          // 52
      +    HAL_CMU_MOD_O_SDMMC,        // 53
      +    HAL_CMU_MOD_O_WDT,          // 54
      +    HAL_CMU_MOD_O_TIMER0,       // 55
      +    HAL_CMU_MOD_O_TIMER1,       // 56
      +    HAL_CMU_MOD_O_TIMER2,       // 57
      +    HAL_CMU_MOD_O_I2C0,         // 58
      +    HAL_CMU_MOD_O_I2C1,         // 59
      +    HAL_CMU_MOD_O_SPI,          // 60
      +    HAL_CMU_MOD_O_SLCD,         // 61
      +    HAL_CMU_MOD_O_SPI_ITN,      // 62
      +    HAL_CMU_MOD_O_SPI_PHY,      // 63
      +    HAL_CMU_MOD_O_UART0,        // 64
      +    HAL_CMU_MOD_O_UART1,        // 65
      +    HAL_CMU_MOD_O_UART2,        // 66
      +    HAL_CMU_MOD_O_I2S0,         // 67
      +    HAL_CMU_MOD_O_SPDIF0,       // 68
      +    HAL_CMU_MOD_O_PCM,          // 69
      +    HAL_CMU_MOD_O_USB32K,       // 70
      +    HAL_CMU_MOD_O_I2S1,         // 71
       
           // AON ACLK/ARST
      -    HAL_CMU_AON_A_CMU,          // 0
      -    HAL_CMU_AON_A_GPIO,         // 1
      -    HAL_CMU_AON_A_GPIO_INT,     // 2
      -    HAL_CMU_AON_A_WDT,          // 3
      -    HAL_CMU_AON_A_PWM,          // 4
      -    HAL_CMU_AON_A_TIMER,        // 5
      -    HAL_CMU_AON_A_IOMUX,        // 6
      -    HAL_CMU_AON_A_APBC,         // 8
      -    HAL_CMU_AON_A_H2H_MCU,      // 9
      -    HAL_CMU_AON_A_PSC,          // 10
      +    HAL_CMU_AON_A_CMU,          // 72
      +    HAL_CMU_AON_A_GPIO,         // 73
      +    HAL_CMU_AON_A_GPIO_INT,     // 74
      +    HAL_CMU_AON_A_WDT,          // 75
      +    HAL_CMU_AON_A_PWM,          // 76
      +    HAL_CMU_AON_A_TIMER,        // 77
      +    HAL_CMU_AON_A_PSC,          // 78
      +    HAL_CMU_AON_A_IOMUX,        // 79
      +    HAL_CMU_AON_A_APBC,         // 80
      +    HAL_CMU_AON_A_H2H_MCU,      // 81
           // AON OCLK/ORST
      -    HAL_CMU_AON_O_WDT,          // 13
      -    HAL_CMU_AON_O_TIMER,        // 14
      -    HAL_CMU_AON_O_GPIO,         // 15
      -    HAL_CMU_AON_O_PWM0,         // 16
      -    HAL_CMU_AON_O_PWM1,         // 17
      -    HAL_CMU_AON_O_PWM2,         // 18
      -    HAL_CMU_AON_O_PWM3,         // 19
      -    HAL_CMU_AON_O_IOMUX,        // 20
      -    HAL_CMU_AON_O_SLP32K,       // 21
      -    HAL_CMU_AON_O_SLP26M,       // 22
      -    HAL_CMU_AON_O_SPIDPD,       // 23
      -    HAL_CMU_AON_O_WLAN32K,      // 24
      -    HAL_CMU_AON_O_WLAN26M,      // 25
      -    HAL_CMU_AON_O_BTAON,        // 26
      +    HAL_CMU_AON_O_WDT,          // 82
      +    HAL_CMU_AON_O_TIMER,        // 83
      +    HAL_CMU_AON_O_GPIO,         // 84
      +    HAL_CMU_AON_O_PWM0,         // 85
      +    HAL_CMU_AON_O_PWM1,         // 86
      +    HAL_CMU_AON_O_PWM2,         // 87
      +    HAL_CMU_AON_O_PWM3,         // 88
      +    HAL_CMU_AON_O_IOMUX,        // 89
      +    HAL_CMU_AON_O_SLP32K,       // 90
      +    HAL_CMU_AON_O_SLP26M,       // 91
      +    HAL_CMU_AON_RESERVED0,      // 92
      +    HAL_CMU_AON_RESERVED1,      // 93
      +    HAL_CMU_AON_RESERVED2,      // 94
      +    HAL_CMU_AON_RESERVED3,      // 95
           // AON SUBSYS
      -    HAL_CMU_AON_MCU,            // 2
      -    HAL_CMU_AON_CODEC,          // 3
      -    HAL_CMU_AON_WF,             // 4
      -    HAL_CMU_AON_BT,             // 5
      -    HAL_CMU_AON_MCUCPU,         // 6
      -    HAL_CMU_AON_WFCPU,          // 7
      -    HAL_CMU_AON_BTCPU,          // 8
      -    HAL_CMU_AON_GLOBAL,         // 9
      +    HAL_CMU_AON_MCU,            // 96
      +    HAL_CMU_AON_CODEC,          // 97
      +    HAL_CMU_AON_RESERVED4,      // 98
      +    HAL_CMU_AON_BT,             // 99
      +    HAL_CMU_AON_MCUCPU,         // 100
      +    HAL_CMU_AON_RESERVED5,      // 101
      +    HAL_CMU_AON_BTCPU,          // 102
      +    HAL_CMU_AON_GLOBAL,         // 103
       
           HAL_CMU_MOD_QTY,
       
      @@ -156,43 +145,48 @@ enum HAL_CMU_MOD_ID_T {
           HAL_CMU_MOD_O_PWM1 = HAL_CMU_AON_O_PWM1,
           HAL_CMU_MOD_O_PWM2 = HAL_CMU_AON_O_PWM2,
           HAL_CMU_MOD_O_PWM3 = HAL_CMU_AON_O_PWM3,
      -    HAL_CMU_H_DCACHE = HAL_CMU_MOD_H_CACHE0,
      -    HAL_CMU_H_ICACHE = HAL_CMU_MOD_H_CACHE1,
       
      +    HAL_CMU_H_ICACHECP = HAL_CMU_MOD_H_ICACHE0,
      +    HAL_CMU_H_DCACHECP = HAL_CMU_MOD_QTY,
      +
      +    // TO BE REMOVED
      +    HAL_CMU_MOD_P_CODEC = HAL_CMU_MOD_QTY,
      +    HAL_CMU_MOD_O_CODEC_DA = HAL_CMU_MOD_QTY,
      +    HAL_CMU_MOD_O_CODEC_AD = HAL_CMU_MOD_QTY,
       };
       
       enum HAL_CMU_CLOCK_OUT_ID_T {
           HAL_CMU_CLOCK_OUT_AON_32K           = 0x00,
      -    HAL_CMU_CLOCK_OUT_AON_OSC           = 0x01,
      -    HAL_CMU_CLOCK_OUT_AON_OSCX2         = 0x02,
      -    HAL_CMU_CLOCK_OUT_AON_DIG_OSCX2     = 0x03,
      -    HAL_CMU_CLOCK_OUT_AON_DIG_OSCX4     = 0x04,
      +    HAL_CMU_CLOCK_OUT_AON_26M           = 0x01,
      +    HAL_CMU_CLOCK_OUT_AON_52M           = 0x02,
      +    HAL_CMU_CLOCK_OUT_AON_DIG_52M       = 0x03,
      +    HAL_CMU_CLOCK_OUT_AON_DIG_104M      = 0x04,
           HAL_CMU_CLOCK_OUT_AON_PER           = 0x05,
           HAL_CMU_CLOCK_OUT_AON_USB           = 0x06,
      -    HAL_CMU_CLOCK_OUT_AON_DCDC0         = 0x07,
      +    HAL_CMU_CLOCK_OUT_AON_DCDC          = 0x07,
           HAL_CMU_CLOCK_OUT_AON_CHCLK         = 0x08,
           HAL_CMU_CLOCK_OUT_AON_SPDIF0        = 0x09,
           HAL_CMU_CLOCK_OUT_AON_MCU           = 0x0A,
           HAL_CMU_CLOCK_OUT_AON_FLASH         = 0x0B,
      -    HAL_CMU_CLOCK_OUT_AON_SYS           = 0x17,
      -
      -    HAL_CMU_CLOCK_OUT_BT_NONE           = 0x40,
      -    HAL_CMU_CLOCK_OUT_BT_32K            = 0x41,
      -    HAL_CMU_CLOCK_OUT_BT_SYS            = 0x42,
      -    HAL_CMU_CLOCK_OUT_BT_OSCX2          = 0x43,
      -    HAL_CMU_CLOCK_OUT_BT_OSC_2          = 0x44,
      -    HAL_CMU_CLOCK_OUT_BT_ADC            = 0x45,
      -    HAL_CMU_CLOCK_OUT_BT_ADCD3          = 0x46,
      -    HAL_CMU_CLOCK_OUT_BT_DAC            = 0x47,
      -    HAL_CMU_CLOCK_OUT_BT_DACD2          = 0x48,
      -    HAL_CMU_CLOCK_OUT_BT_DACD4          = 0x49,
      +    HAL_CMU_CLOCK_OUT_AON_SYS           = 0x0C,
      +
      +    HAL_CMU_CLOCK_OUT_BT_32K            = 0x40,
      +    HAL_CMU_CLOCK_OUT_BT_SYS            = 0x41,
      +    HAL_CMU_CLOCK_OUT_BT_52M            = 0x42,
      +    HAL_CMU_CLOCK_OUT_BT_26MI           = 0x43,
      +    HAL_CMU_CLOCK_OUT_BT_13M            = 0x44,
      +    HAL_CMU_CLOCK_OUT_BT_12M            = 0x45,
      +    HAL_CMU_CLOCK_OUT_BT_ADC            = 0x46,
      +    HAL_CMU_CLOCK_OUT_BT_ADC2           = 0x47,
      +    HAL_CMU_CLOCK_OUT_BT_24M            = 0x48,
      +    HAL_CMU_CLOCK_OUT_BT_26M            = 0x49,
       
           HAL_CMU_CLOCK_OUT_MCU_32K           = 0x60,
           HAL_CMU_CLOCK_OUT_MCU_SYS           = 0x61,
           HAL_CMU_CLOCK_OUT_MCU_FLASH         = 0x62,
           HAL_CMU_CLOCK_OUT_MCU_USB           = 0x63,
           HAL_CMU_CLOCK_OUT_MCU_PCLK          = 0x64,
      -    HAL_CMU_CLOCK_OUT_MCU_I2S0          = 0x65,
      +    HAL_CMU_CLOCK_OUT_MCU_I2S           = 0x65,
           HAL_CMU_CLOCK_OUT_MCU_PCM           = 0x66,
           HAL_CMU_CLOCK_OUT_MCU_SPDIF0        = 0x67,
           HAL_CMU_CLOCK_OUT_MCU_SDMMC         = 0x68,
      @@ -203,9 +197,8 @@ enum HAL_CMU_CLOCK_OUT_ID_T {
           HAL_CMU_CLOCK_OUT_CODEC_ADC_ANA     = 0x80,
           HAL_CMU_CLOCK_OUT_CODEC_CODEC       = 0x81,
           HAL_CMU_CLOCK_OUT_CODEC_IIR         = 0x82,
      -    HAL_CMU_CLOCK_OUT_CODEC_RS_DAC      = 0x83,
      -    HAL_CMU_CLOCK_OUT_CODEC_RS_ADC      = 0x84,
      -    HAL_CMU_CLOCK_OUT_CODEC_HCLK        = 0x85,
      +    HAL_CMU_CLOCK_OUT_CODEC_RS          = 0x83,
      +    HAL_CMU_CLOCK_OUT_CODEC_HCLK        = 0x84,
       };
       
       enum HAL_CMU_I2S_MCLK_ID_T {
      @@ -227,17 +220,31 @@ enum HAL_I2S_ID_T {
       };
       #define HAL_I2S_ID_T                        HAL_I2S_ID_T
       
      +enum HAL_CMU_ANC_CLK_USER_T {
      +    HAL_CMU_ANC_CLK_USER_ANC,
       
      +    HAL_CMU_ANC_CLK_USER_QTY
       };
       
      +enum HAL_CMU_LOW_SYS_FREQ_T {
      +    HAL_CMU_LOW_SYS_FREQ_NONE,
      +    HAL_CMU_LOW_SYS_FREQ_13M,
      +    HAL_CMU_LOW_SYS_FREQ_6P5M,
      +    HAL_CMU_LOW_SYS_FREQ_4P33M,
      +    HAL_CMU_LOW_SYS_FREQ_3P25M,
       };
       
      +void hal_cmu_low_sys_clock_set(enum HAL_CMU_LOW_SYS_FREQ_T freq);
       
       int hal_cmu_fast_timer_offline(void);
       
      +void hal_cmu_anc_enable(enum HAL_CMU_ANC_CLK_USER_T user);
       
      +void hal_cmu_anc_disable(enum HAL_CMU_ANC_CLK_USER_T user);
       
      +int hal_cmu_anc_get_status(enum HAL_CMU_ANC_CLK_USER_T user);
       
      +void hal_cmu_codec_vad_clock_enable(uint32_t enabled);
       
       uint32_t hal_cmu_get_aon_chip_id(void);
       
  • platform/hal/best2300p/hal_dmacfg_best2300p.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/hal_dmacfg_best2300p.h bes/platform/hal/best2300p/hal_dmacfg_best2300p.h
      index 08ff5d483fd..3d2a4f69968 100644
      --- a/platform/hal/best2300p/hal_dmacfg_best2300p.h
      +++ b/platform/hal/best2300p/hal_dmacfg_best2300p.h
      @@ -24,118 +24,90 @@
       #define AUDMA_CHAN_START                        (0)
       #define GPDMA_CHAN_START                        (0)
       
      -static const uint32_t gpdma_fifo_addr[AUDMA_PERIPH_NUM] = {
      +static const uint32_t audma_fifo_addr[AUDMA_PERIPH_NUM] = {
           CODEC_BASE + 0x01C,     // CODEC RX
           CODEC_BASE + 0x01C,     // CODEC TX
      +#ifdef CODEC_DSD
           CODEC_BASE + 0x034,     // DSD RX
           CODEC_BASE + 0x034,     // DSD TX
      -    CODEC_BASE + 0x058,     // CODEC TX2
      -#ifdef AF_DEVICE_I2S
      -    I2S1_BASE + 0x200,      // I2S0 RX
      -    I2S1_BASE + 0x240,      // I2S0 TX
      -    I2S0_BASE + 0x200,      // I2S0 RX
      -    I2S0_BASE + 0x240,      // I2S0 TX
       #else
      -    I2C1_BASE + 0x010,      // I2C1 RX
      -    I2C1_BASE + 0x010,      // I2C1 TX
      -    SPI_BASE + 0x008,       // SPI RX
      -    SPI_BASE + 0x008,       // SPI TX
      -#endif
      -    SDMMC_BASE + 0x200,     // SDMMC
           BTPCM_BASE + 0x1C0,     // BTPCM RX
           BTPCM_BASE + 0x1C8,     // BTPCM TX
      -    UART2_BASE + 0x000,     // UART2 RX
      -    UART2_BASE + 0x000,     // UART2 TX
      -    UART1_BASE + 0x000,     // UART1 RX
      -    UART1_BASE + 0x000,     // UART1 TX
      +#endif
      +    I2S0_BASE + 0x200,      // I2S0 RX
      +    I2S0_BASE + 0x240,      // I2S0 TX
      +    0,                      // FIR RX
      +    0,                      // FIR TX
      +    SPDIF0_BASE + 0x1C0,    // SPDIF0 RX
      +    SPDIF0_BASE + 0x1C8,    // SPDIF0 TX
      +    CODEC_BASE + 0x03C,     // IIR RX
      +    CODEC_BASE + 0x03C,     // IIR TX
      +    BTDUMP_BASE + 0x34,     // BTDUMP
      +    CODEC_BASE + 0x038,     // MC RX
      +    I2S1_BASE + 0x200,      // I2S1 RX
      +    I2S1_BASE + 0x240,      // I2S1 TX
       };
       
      -static const enum HAL_DMA_PERIPH_T gpdma_fifo_periph[AUDMA_PERIPH_NUM] = {
      +static const enum HAL_DMA_PERIPH_T audma_fifo_periph[AUDMA_PERIPH_NUM] = {
           HAL_AUDMA_CODEC_RX,
           HAL_AUDMA_CODEC_TX,
      +#ifdef CODEC_DSD
           HAL_AUDMA_DSD_RX,
           HAL_AUDMA_DSD_TX,
      -    HAL_DMA_PERIPH_NULL,
      -#ifdef AF_DEVICE_I2S
      +#else
      +    HAL_AUDMA_BTPCM_RX,
      +    HAL_AUDMA_BTPCM_TX,
      +#endif
           HAL_AUDMA_I2S0_RX,
           HAL_AUDMA_I2S0_TX,
      +    HAL_AUDMA_FIR_RX,
      +    HAL_AUDMA_FIR_TX,
      +    HAL_AUDMA_SPDIF0_RX,
      +    HAL_AUDMA_SPDIF0_TX,
      +    HAL_AUDMA_IIR_RX,
      +    HAL_AUDMA_IIR_TX,
      +    HAL_AUDMA_BTDUMP,
      +    HAL_AUDMA_MC_RX,
           HAL_AUDMA_I2S1_RX,
           HAL_AUDMA_I2S1_TX,
      -#else
      -    HAL_GPDMA_I2C1_RX,
      -    HAL_GPDMA_I2C1_TX,
      -    HAL_GPDMA_SPI_RX,
      -    HAL_GPDMA_SPI_TX,
      -#endif
      -    HAL_GPDMA_SDMMC,
      -    HAL_AUDMA_BTPCM_RX,
      -    HAL_AUDMA_BTPCM_TX,
      -    HAL_GPDMA_UART2_RX,
      -    HAL_GPDMA_UART2_TX,
      -    HAL_GPDMA_UART1_RX,
      -    HAL_GPDMA_UART1_TX,
       };
       
      -static const uint32_t audma_fifo_addr[GPDMA_PERIPH_NUM] = {
      -    CODEC_BASE + 0x01C,     // CODEC RX
      -    CODEC_BASE + 0x01C,     // CODEC TX
      -    IRDA_BASE + 0x000,      // IR RX
      -    IRDA_BASE + 0x004,      // IR TX
      -    UART0_BASE + 0x000,     // UART0 RX
      -    UART0_BASE + 0x000,     // UART0 TX
      -    UART2_BASE + 0x000,     // UART2 RX
      -    UART2_BASE + 0x000,     // UART2 TX
      -#ifndef SPILCD_DMA_ENABLE
      -    BTDUMP_BASE + 0x34,     // BTDUMP
      -    0,                      // NULL
      -#else
      +static const uint32_t gpdma_fifo_addr[GPDMA_PERIPH_NUM] = {
      +    FLASH_CTRL_BASE + 0x008, // FLASH CTRL
      +    SDMMC_BASE + 0x200,     // SDMMC
      +    I2C0_BASE + 0x010,      // I2C0 RX
      +    I2C0_BASE + 0x010,      // I2C0 TX
      +    SPI_BASE + 0x008,       // SPI RX
      +    SPI_BASE + 0x008,       // SPI TX
           SPILCD_BASE + 0x008,    // SPILCD RX
           SPILCD_BASE + 0x008,    // SPILCD TX
      -#endif
      -#ifdef AF_DEVICE_I2S
      -    I2S0_BASE + 0x200,      // I2S0 RX
      -    I2S0_BASE + 0x240,      // I2S0 TX
      -    I2S1_BASE + 0x200,      // I2S1 RX
      -    I2S1_BASE + 0x240,      // I2S1 TX
      -#else
      -    BTPCM_BASE + 0x1C0,     // BTPCM RX
      -    BTPCM_BASE + 0x1C8,     // BTPCM TX
      +    UART0_BASE + 0x000,     // UART0 RX
      +    UART0_BASE + 0x000,     // UART0 TX
           UART1_BASE + 0x000,     // UART1 RX
           UART1_BASE + 0x000,     // UART1 TX
      -#endif
      -    FLASH_CTRL_BASE + 0x008,// FLASH0
      -    FLASH1_CTRL_BASE + 0x008,// FLASH0
      +    I2C1_BASE + 0x010,      // I2C1 RX
      +    I2C1_BASE + 0x010,      // I2C1 TX
      +    UART2_BASE + 0x000,     // UART2 RX
      +    UART2_BASE + 0x000,     // UART2 TX
       };
       
      -static const enum HAL_DMA_PERIPH_T audma_fifo_periph[GPDMA_PERIPH_NUM] = {
      -    HAL_AUDMA_CODEC_RX,
      -    HAL_AUDMA_CODEC_TX,
      -    HAL_GPDMA_IR_RX,
      -    HAL_GPDMA_IR_TX,
      -    HAL_GPDMA_UART0_RX,
      -    HAL_GPDMA_UART0_TX,
      -    HAL_GPDMA_UART2_RX,
      -    HAL_GPDMA_UART2_TX,
      -#ifndef SPILCD_DMA_ENABLE
      -    HAL_AUDMA_BTDUMP,
      -    HAL_DMA_PERIPH_NULL,
      -#else
      +static const enum HAL_DMA_PERIPH_T gpdma_fifo_periph[GPDMA_PERIPH_NUM] = {
      +    HAL_GPDMA_FLASH_TX,
      +    HAL_GPDMA_SDMMC,
      +    HAL_GPDMA_I2C0_RX,
      +    HAL_GPDMA_I2C0_TX,
      +    HAL_GPDMA_SPI_RX,
      +    HAL_GPDMA_SPI_TX,
           HAL_GPDMA_SPILCD_RX,
           HAL_GPDMA_SPILCD_TX,
      -#endif
      -#ifdef AF_DEVICE_I2S
      -    HAL_AUDMA_I2S0_RX,      // I2S0 RX
      -    HAL_AUDMA_I2S0_TX,      // I2S0 TX
      -    HAL_AUDMA_I2S1_RX,
      -    HAL_AUDMA_I2S1_TX,
      -#else
      -    HAL_AUDMA_BTPCM_RX,
      -    HAL_AUDMA_BTPCM_TX,
      +    HAL_GPDMA_UART0_RX,
      +    HAL_GPDMA_UART0_TX,
           HAL_GPDMA_UART1_RX,
           HAL_GPDMA_UART1_TX,
      -#endif
      -    HAL_GPDMA_FLASH0,
      -    HAL_GPDMA_FLASH1,
      +    HAL_GPDMA_I2C1_RX,
      +    HAL_GPDMA_I2C1_TX,
      +    HAL_GPDMA_UART2_RX,
      +    HAL_GPDMA_UART2_TX,
       };
       
       #endif
  • platform/hal/best2300p/hal_iomux_best2300p.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/hal_iomux_best2300p.c bes/platform/hal/best2300p/hal_iomux_best2300p.c
      index c0961dcc167..097f3da6b96 100644
      --- a/platform/hal/best2300p/hal_iomux_best2300p.c
      +++ b/platform/hal/best2300p/hal_iomux_best2300p.c
      @@ -28,6 +28,11 @@
       #define I2S0_VOLTAGE_SEL                    HAL_IOMUX_PIN_VOLTAGE_VIO
       #endif
       
      +#ifdef I2S1_VOLTAGE_VMEM
      +#define I2S1_VOLTAGE_SEL                    HAL_IOMUX_PIN_VOLTAGE_MEM
      +#else
      +#define I2S1_VOLTAGE_SEL                    HAL_IOMUX_PIN_VOLTAGE_VIO
      +#endif
       
       #ifdef SPDIF0_VOLTAGE_VMEM
       #define SPDIF0_VOLTAGE_SEL                  HAL_IOMUX_PIN_VOLTAGE_MEM
      @@ -71,19 +76,28 @@
       #define CLKOUT_VOLTAGE_SEL                  HAL_IOMUX_PIN_VOLTAGE_VIO
       #endif
       
      +#ifndef I2S0_IOMUX_INDEX
      +#define I2S0_IOMUX_INDEX                    0
      +#endif
       
      +#ifndef I2S1_IOMUX_INDEX
      +#define I2S1_IOMUX_INDEX                    0
      +#endif
       
       #ifndef I2S_MCLK_IOMUX_INDEX
      -#define I2S_MCLK_IOMUX_INDEX                04
      +#define I2S_MCLK_IOMUX_INDEX                0
       #endif
       
      +#ifndef SPDIF0_IOMUX_INDEX
      +#define SPDIF0_IOMUX_INDEX                  0
      +#endif
       
      -#ifndef SPDIF0_I_IOMUX_INDEX
      -#define SPDIF0_I_IOMUX_INDEX                02
      +#ifndef DIG_MIC2_CK_IOMUX_INDEX
      +#define DIG_MIC2_CK_IOMUX_INDEX             0
       #endif
       
      -#ifndef SPDIF0_O_IOMUX_INDEX
      -#define SPDIF0_O_IOMUX_INDEX                03
      +#ifndef DIG_MIC3_CK_IOMUX_INDEX
      +#define DIG_MIC3_CK_IOMUX_INDEX             0
       #endif
       
       #ifndef DIG_MIC_CK_IOMUX_PIN
      @@ -103,7 +117,7 @@
       #endif
       
       #ifndef SPI_IOMUX_INDEX
      -#define SPI_IOMUX_INDEX                    04
      +#define SPI_IOMUX_INDEX                     0
       #endif
       
       #ifndef SPILCD_IOMUX_INDEX
      @@ -111,157 +125,121 @@
       #endif
       
       #ifndef I2C0_IOMUX_INDEX
      -#define I2C0_IOMUX_INDEX                    4
      +#define I2C0_IOMUX_INDEX                    0
       #endif
       
       #ifndef I2C1_IOMUX_INDEX
      -#define I2C1_IOMUX_INDEX                    22
      +#define I2C1_IOMUX_INDEX                    0
       #endif
       
       #ifndef CLKOUT_IOMUX_INDEX
      -#define CLKOUT_IOMUX_INDEX                  20
      +#define CLKOUT_IOMUX_INDEX                  0
       #endif
       
      -#define IOMUX_FUNC_VAL_GPIO                 15
      +#define IOMUX_FUNC_VAL_GPIO                 0
       
      -#define IOMUX_ALT_FUNC_NUM                  11
      +#define IOMUX_ALT_FUNC_NUM                  6
       
      -// Other func values: 2 -> uart rtx/ctx, 12 -> btdm, 13 -> wf_fem, 14 -> tport, 15 -> gpio
      -static const uint8_t index_to_func_val[IOMUX_ALT_FUNC_NUM] = {
      -    0,  1,  3,  4,
      -    5,  6,  7,  8,
      -    9,  10, 11
      -};
      +// Other func values: 0 -> gpio, 6 -> rf_ana, 7 -> jtag/btdm, 9 -> clk_req, 10 -> ana_test
      +static const uint8_t index_to_func_val[IOMUX_ALT_FUNC_NUM] = { 1, 2, 3, 4, 5, 8, };
       
       static const enum HAL_IOMUX_FUNCTION_T pin_func_map[HAL_IOMUX_PIN_NUM][IOMUX_ALT_FUNC_NUM] = {
           // P0_0
      -    { HAL_IOMUX_FUNC_PWM0, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_FUNC_I2C_M0_SCL, HAL_IOMUX_FUNC_SPILCD_DI0,
      -      HAL_IOMUX_FUNC_SPILCD_DCN, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE,
      -      HAL_IOMUX_FUNC_IR_RX, HAL_IOMUX_FUNC_PDM0_CK, HAL_IOMUX_FUNC_I2S0_SDI0, },
      +    { HAL_IOMUX_FUNC_I2S0_SDI0, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_FUNC_PCM_DI, HAL_IOMUX_FUNC_SPILCD_DI0,
      +      HAL_IOMUX_FUNC_PDM0_CK, HAL_IOMUX_FUNC_SPILCD_DCN, },
           // P0_1
      -    { HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_FUNC_I2C_M0_SDA, HAL_IOMUX_FUNC_SPILCD_DIO,
      -      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE,
      -      HAL_IOMUX_FUNC_IR_TX, HAL_IOMUX_FUNC_PDM0_D, HAL_IOMUX_FUNC_I2S0_SDO0, },
      +    { HAL_IOMUX_FUNC_I2S0_SDO, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_FUNC_PCM_DO, HAL_IOMUX_FUNC_SPILCD_DIO,
      +      HAL_IOMUX_FUNC_PDM0_D, HAL_IOMUX_FUNC_NONE, },
           // P0_2
      -    { HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_UART1_RX, HAL_IOMUX_FUNC_I2C_M1_SCL, HAL_IOMUX_FUNC_SPILCD_CS0,
      -      HAL_IOMUX_FUNC_SPILCD_DI1, HAL_IOMUX_FUNC_SPDIF0_DI, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_DISPLAY_BL_EN,
      -      HAL_IOMUX_FUNC_IR_RX, HAL_IOMUX_FUNC_PDM1_D, HAL_IOMUX_FUNC_I2S0_WS, },
      +    { HAL_IOMUX_FUNC_I2S0_WS, HAL_IOMUX_FUNC_I2C_M1_SCL, HAL_IOMUX_FUNC_PCM_FSYNC, HAL_IOMUX_FUNC_SPILCD_CS0,
      +      HAL_IOMUX_FUNC_PDM1_D, HAL_IOMUX_FUNC_NONE, },
           // P0_3
      -    { HAL_IOMUX_FUNC_PWM3, HAL_IOMUX_FUNC_UART1_TX, HAL_IOMUX_FUNC_I2C_M1_SDA, HAL_IOMUX_FUNC_SPILCD_CLK,
      -      HAL_IOMUX_FUNC_SPILCD_DI2, HAL_IOMUX_FUNC_SPDIF0_DO, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_DISPLAY_BL_PWM,
      -      HAL_IOMUX_FUNC_IR_TX, HAL_IOMUX_FUNC_PDM2_D, HAL_IOMUX_FUNC_I2S0_SCK, },
      +    { HAL_IOMUX_FUNC_I2S0_SCK, HAL_IOMUX_FUNC_I2C_M1_SDA, HAL_IOMUX_FUNC_PCM_CLK, HAL_IOMUX_FUNC_SPILCD_CLK,
      +      HAL_IOMUX_FUNC_PDM2_D, HAL_IOMUX_FUNC_NONE, },
           // P0_4
      -    { HAL_IOMUX_FUNC_PWM4, HAL_IOMUX_FUNC_UART3_RX, HAL_IOMUX_FUNC_I2C_M0_SCL, HAL_IOMUX_FUNC_SPI_DI0,
      -      HAL_IOMUX_FUNC_SPILCD_DI3, HAL_IOMUX_FUNC_I2S_MCLK, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_SPI_DCN,
      -      HAL_IOMUX_FUNC_SDMMC_DATA7, HAL_IOMUX_FUNC_PDM1_CK, HAL_IOMUX_FUNC_I2S0_SDO3, },
      +    { HAL_IOMUX_FUNC_SDMMC_DATA7, HAL_IOMUX_FUNC_SPI_DI0, HAL_IOMUX_FUNC_I2S0_MCLK, HAL_IOMUX_FUNC_CLK_OUT,
      +      HAL_IOMUX_FUNC_PDM1_CK, HAL_IOMUX_FUNC_SPI_DCN, },
           // P0_5
      -    { HAL_IOMUX_FUNC_PWM5, HAL_IOMUX_FUNC_UART3_TX, HAL_IOMUX_FUNC_I2C_M0_SDA, HAL_IOMUX_FUNC_SPI_CLK,
      -      HAL_IOMUX_FUNC_SPILCD_CS1, HAL_IOMUX_FUNC_DISPLAY_SPI_CLK, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_DISPLAY_TE,
      -      HAL_IOMUX_FUNC_SDMMC_DATA6, HAL_IOMUX_FUNC_PDM0_D, HAL_IOMUX_FUNC_I2S0_SDO2, },
      +    { HAL_IOMUX_FUNC_SDMMC_DATA6, HAL_IOMUX_FUNC_SPI_CLK, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPILCD_CS1,
      +      HAL_IOMUX_FUNC_PDM1_D, HAL_IOMUX_FUNC_NONE, },
           // P0_6
      -    { HAL_IOMUX_FUNC_PWM6, HAL_IOMUX_FUNC_UART3_RX, HAL_IOMUX_FUNC_I2C_M1_SCL, HAL_IOMUX_FUNC_SPI_CS0,
      -      HAL_IOMUX_FUNC_SPILCD_CS2, HAL_IOMUX_FUNC_DISPLAY_SPI_CS, HAL_IOMUX_FUNC_WF_WAKE_HOST, HAL_IOMUX_FUNC_IR_RX,
      -      HAL_IOMUX_FUNC_SDMMC_DATA5, HAL_IOMUX_FUNC_PDM1_D, HAL_IOMUX_FUNC_I2S0_SDO1, },
      +    { HAL_IOMUX_FUNC_SDMMC_DATA5, HAL_IOMUX_FUNC_SPI_CS0, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPILCD_CS2,
      +      HAL_IOMUX_FUNC_PDM0_D, HAL_IOMUX_FUNC_NONE, },
           // P0_7
      -    { HAL_IOMUX_FUNC_PWM7, HAL_IOMUX_FUNC_UART3_TX, HAL_IOMUX_FUNC_I2C_M1_SDA, HAL_IOMUX_FUNC_SPI_DIO,
      -      HAL_IOMUX_FUNC_SPILCD_CS3, HAL_IOMUX_FUNC_DISPLAY_SPI_DIO, HAL_IOMUX_FUNC_SPDIF0_DO, HAL_IOMUX_FUNC_IR_TX,
      -      HAL_IOMUX_FUNC_SDMMC_DATA4, HAL_IOMUX_FUNC_PDM2_D, HAL_IOMUX_FUNC_I2S0_SDO0, },
      +    { HAL_IOMUX_FUNC_SDMMC_DATA4, HAL_IOMUX_FUNC_SPI_DIO, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPILCD_CS3,
      +      HAL_IOMUX_FUNC_PDM2_D, HAL_IOMUX_FUNC_NONE, },
           // P1_0
      -    { HAL_IOMUX_FUNC_PWM0, HAL_IOMUX_FUNC_UART1_RX, HAL_IOMUX_FUNC_I2C_M2_SCL, HAL_IOMUX_FUNC_SPILCD_CLK,
      -      HAL_IOMUX_FUNC_SPI_CS1, HAL_IOMUX_FUNC_DISPLAY_SPI_DO1_DCN, HAL_IOMUX_FUNC_IR_RX, HAL_IOMUX_FUNC_WF_SDIO_CLK,
      -      HAL_IOMUX_FUNC_SDMMC_DATA2, HAL_IOMUX_FUNC_SPDIF0_DI, HAL_IOMUX_FUNC_I2S0_SDI3, },
      +    { HAL_IOMUX_FUNC_SDMMC_DATA2, HAL_IOMUX_FUNC_I2S1_SCK, HAL_IOMUX_FUNC_SPILCD_CLK, HAL_IOMUX_FUNC_SPI_CS1,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P1_1
      -    { HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_UART1_TX, HAL_IOMUX_FUNC_I2C_M2_SDA, HAL_IOMUX_FUNC_SPILCD_CS0,
      -      HAL_IOMUX_FUNC_SPI_CS2, HAL_IOMUX_FUNC_DISPLAY_SPI_DO2, HAL_IOMUX_FUNC_IR_TX, HAL_IOMUX_FUNC_WF_SDIO_CMD,
      -      HAL_IOMUX_FUNC_SDMMC_DATA3, HAL_IOMUX_FUNC_SPDIF0_DO, HAL_IOMUX_FUNC_I2S0_SDI2, },
      +    { HAL_IOMUX_FUNC_SDMMC_DATA3, HAL_IOMUX_FUNC_I2S1_WS, HAL_IOMUX_FUNC_SPILCD_CS0, HAL_IOMUX_FUNC_SPI_CS2,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P1_2
      -    { HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_FUNC_I2C_M2_SCL, HAL_IOMUX_FUNC_SPILCD_CS1,
      -      HAL_IOMUX_FUNC_SPI_CS3, HAL_IOMUX_FUNC_DISPLAY_SPI_DO3, HAL_IOMUX_FUNC_CLK_32K_IN, HAL_IOMUX_FUNC_WF_SDIO_DATA0,
      -      HAL_IOMUX_FUNC_SDMMC_CMD, HAL_IOMUX_FUNC_IR_RX, HAL_IOMUX_FUNC_I2S0_SDI1, },
      +    { HAL_IOMUX_FUNC_SDMMC_CMD, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPILCD_CS1, HAL_IOMUX_FUNC_SPI_CS3,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P1_3
      -    { HAL_IOMUX_FUNC_PWM3, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_FUNC_I2C_M2_SDA, HAL_IOMUX_FUNC_SPILCD_DCN,
      -      HAL_IOMUX_FUNC_SPI_DI1, HAL_IOMUX_FUNC_I2S_MCLK, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_WF_SDIO_DATA1,
      -      HAL_IOMUX_FUNC_SDMMC_CLK, HAL_IOMUX_FUNC_IR_TX, HAL_IOMUX_FUNC_I2S0_SDI0, },
      +    { HAL_IOMUX_FUNC_SDMMC_CLK, HAL_IOMUX_FUNC_I2S0_MCLK, HAL_IOMUX_FUNC_SPILCD_DCN, HAL_IOMUX_FUNC_CLK_OUT,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P1_4
      -    { HAL_IOMUX_FUNC_PWM4, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_FUNC_I2C_M1_SCL, HAL_IOMUX_FUNC_SPILCD_DI0,
      -      HAL_IOMUX_FUNC_SPI_DI2, HAL_IOMUX_FUNC_DISPLAY_SPI_DI, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_WF_SDIO_DATA2,
      -      HAL_IOMUX_FUNC_SDMMC_DATA0, HAL_IOMUX_FUNC_IR_RX, HAL_IOMUX_FUNC_DISPLAY_TE, },
      +    { HAL_IOMUX_FUNC_SDMMC_DATA0, HAL_IOMUX_FUNC_I2S1_SDI0, HAL_IOMUX_FUNC_SPILCD_DI0, HAL_IOMUX_FUNC_NONE,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P1_5
      -    { HAL_IOMUX_FUNC_PWM5, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_FUNC_I2C_M1_SDA, HAL_IOMUX_FUNC_SPILCD_DIO,
      -      HAL_IOMUX_FUNC_SPI_DI3, HAL_IOMUX_FUNC_I2S_MCLK, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_WF_SDIO_DATA3,
      -      HAL_IOMUX_FUNC_SDMMC_DATA1, HAL_IOMUX_FUNC_IR_TX, HAL_IOMUX_FUNC_DISPLAY_TE, },
      +    { HAL_IOMUX_FUNC_SDMMC_DATA1, HAL_IOMUX_FUNC_I2S1_SDO, HAL_IOMUX_FUNC_SPILCD_DIO, HAL_IOMUX_FUNC_I2S0_MCLK,
      +      HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_NONE, },
           // P1_6
      -    { HAL_IOMUX_FUNC_PWM6, HAL_IOMUX_FUNC_UART0_RX, HAL_IOMUX_FUNC_I2C_M0_SCL, HAL_IOMUX_FUNC_NONE,
      -      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_WF_WAKE_HOST,
      -      HAL_IOMUX_FUNC_BT_UART_RX, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
      +    { HAL_IOMUX_FUNC_UART0_RX, HAL_IOMUX_FUNC_I2C_M0_SCL, HAL_IOMUX_FUNC_BT_UART_RX, HAL_IOMUX_FUNC_NONE,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P1_7
      -    { HAL_IOMUX_FUNC_PWM7, HAL_IOMUX_FUNC_UART0_TX, HAL_IOMUX_FUNC_I2C_M0_SDA, HAL_IOMUX_FUNC_NONE,
      -      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE,
      -      HAL_IOMUX_FUNC_BT_UART_TX, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
      +    { HAL_IOMUX_FUNC_UART0_TX, HAL_IOMUX_FUNC_I2C_M0_SDA, HAL_IOMUX_FUNC_BT_UART_TX, HAL_IOMUX_FUNC_NONE,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P2_0
      -    { HAL_IOMUX_FUNC_PWM0, HAL_IOMUX_FUNC_UART1_RX, HAL_IOMUX_FUNC_I2C_M0_SCL, HAL_IOMUX_FUNC_SPILCD_DI0,
      -      HAL_IOMUX_FUNC_SPILCD_DCN, HAL_IOMUX_FUNC_I2S_MCLK, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_WF_UART_RX,
      -      HAL_IOMUX_FUNC_BT_UART_RX, HAL_IOMUX_FUNC_SPDIF0_DI, HAL_IOMUX_FUNC_I2S1_SDI0, },
      +    { HAL_IOMUX_FUNC_UART1_RX, HAL_IOMUX_FUNC_I2C_M0_SCL, HAL_IOMUX_FUNC_BT_UART_RX, HAL_IOMUX_FUNC_SPDIF0_DI,
      +      HAL_IOMUX_FUNC_PWM0, HAL_IOMUX_FUNC_I2S0_MCLK, },
           // P2_1
      -    { HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_UART1_TX, HAL_IOMUX_FUNC_I2C_M0_SDA, HAL_IOMUX_FUNC_SPILCD_DIO,
      -      HAL_IOMUX_FUNC_IR_TX, HAL_IOMUX_FUNC_DISPLAY_TE, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_WF_UART_TX,
      -      HAL_IOMUX_FUNC_BT_UART_TX, HAL_IOMUX_FUNC_SPDIF0_DO, HAL_IOMUX_FUNC_I2S1_SDO0, },
      +    { HAL_IOMUX_FUNC_UART1_TX, HAL_IOMUX_FUNC_I2C_M0_SDA, HAL_IOMUX_FUNC_BT_UART_TX, HAL_IOMUX_FUNC_SPDIF0_DO,
      +      HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_CLK_OUT, },
           // P2_2
      -    { HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_FUNC_I2C_M1_SCL, HAL_IOMUX_FUNC_SPILCD_CS0,
      -      HAL_IOMUX_FUNC_DISPLAY_BL_EN, HAL_IOMUX_FUNC_I2S_MCLK, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_WF_UART_CTS,
      -      HAL_IOMUX_FUNC_BT_UART_CTS, HAL_IOMUX_FUNC_IR_RX, HAL_IOMUX_FUNC_I2S1_WS, },
      +    { HAL_IOMUX_FUNC_I2C_M1_SCL, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_FUNC_UART1_CTS, HAL_IOMUX_FUNC_BT_UART_CTS,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_I2S0_MCLK, },
           // P2_3
      -    { HAL_IOMUX_FUNC_PWM3, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_FUNC_I2C_M1_SDA, HAL_IOMUX_FUNC_SPILCD_CLK,
      -      HAL_IOMUX_FUNC_SPI_DCN, HAL_IOMUX_FUNC_DISPLAY_BL_PWM, HAL_IOMUX_FUNC_PCM_DI, HAL_IOMUX_FUNC_WF_UART_RTS,
      -      HAL_IOMUX_FUNC_BT_UART_RTS, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_I2S1_SCK, },
      +    { HAL_IOMUX_FUNC_I2C_M1_SDA, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_FUNC_UART1_RTS, HAL_IOMUX_FUNC_BT_UART_RTS,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_CLK_OUT, },
           // P2_4
      -    { HAL_IOMUX_FUNC_PWM4, HAL_IOMUX_FUNC_UART3_RX, HAL_IOMUX_FUNC_I2C_M2_SCL, HAL_IOMUX_FUNC_SPI_DI0,
      -      HAL_IOMUX_FUNC_SPI_DI3, HAL_IOMUX_FUNC_SPI_DCN, HAL_IOMUX_FUNC_PCM_DO, HAL_IOMUX_FUNC_SPDIF0_DI,
      -      HAL_IOMUX_FUNC_WF_SDIO_CLK, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_I2S1_SDO3, },
      +    { HAL_IOMUX_FUNC_PWM0, HAL_IOMUX_FUNC_CLK_REQ_OUT, HAL_IOMUX_FUNC_SPI_DI3, HAL_IOMUX_FUNC_NONE,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P2_5
      -    { HAL_IOMUX_FUNC_PWM5, HAL_IOMUX_FUNC_UART3_TX, HAL_IOMUX_FUNC_I2C_M2_SDA, HAL_IOMUX_FUNC_SPI_DIO,
      -      HAL_IOMUX_FUNC_SPI_CS3, HAL_IOMUX_FUNC_DISPLAY_TE, HAL_IOMUX_FUNC_PCM_FSYNC, HAL_IOMUX_FUNC_NONE,
      -      HAL_IOMUX_FUNC_WF_SDIO_CMD, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_I2S1_SDO2, },
      +    { HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_CLK_REQ_IN, HAL_IOMUX_FUNC_SPI_CS3, HAL_IOMUX_FUNC_NONE,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P2_6
      -    { HAL_IOMUX_FUNC_PWM6, HAL_IOMUX_FUNC_UART3_RX, HAL_IOMUX_FUNC_I2C_M0_SCL, HAL_IOMUX_FUNC_SPI_CS0,
      -      HAL_IOMUX_FUNC_SPILCD_DI1, HAL_IOMUX_FUNC_CLK_32K_IN, HAL_IOMUX_FUNC_PCM_CLK, HAL_IOMUX_FUNC_IR_RX,
      -      HAL_IOMUX_FUNC_WF_SDIO_DATA0, HAL_IOMUX_FUNC_SPDIF0_DI, HAL_IOMUX_FUNC_I2S1_SDO1, },
      +    { HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_SPILCD_DI1, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPDIF0_DI,
      +      HAL_IOMUX_FUNC_CLK_32K_IN, HAL_IOMUX_FUNC_NONE, },
           // P2_7
      -    { HAL_IOMUX_FUNC_PWM7, HAL_IOMUX_FUNC_UART3_TX, HAL_IOMUX_FUNC_I2C_M0_SDA, HAL_IOMUX_FUNC_SPI_CLK,
      -      HAL_IOMUX_FUNC_SPILCD_CS1, HAL_IOMUX_FUNC_I2S_MCLK, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_IR_TX,
      -      HAL_IOMUX_FUNC_WF_SDIO_DATA1, HAL_IOMUX_FUNC_SPDIF0_DO, HAL_IOMUX_FUNC_I2S1_SDO0, },
      +    { HAL_IOMUX_FUNC_PWM3, HAL_IOMUX_FUNC_SPILCD_CS1, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPDIF0_DO,
      +      HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_NONE, },
           // P3_0
      -    { HAL_IOMUX_FUNC_PWM0, HAL_IOMUX_FUNC_UART1_RX, HAL_IOMUX_FUNC_I2C_M1_SCL, HAL_IOMUX_FUNC_SPI_DI0,
      -      HAL_IOMUX_FUNC_SPILCD_DI2, HAL_IOMUX_FUNC_SPI_DCN, HAL_IOMUX_FUNC_WF_UART_RX, HAL_IOMUX_FUNC_SPILCD_CS1,
      -      HAL_IOMUX_FUNC_WF_SDIO_DATA2, HAL_IOMUX_FUNC_PDM0_D, HAL_IOMUX_FUNC_I2S1_SDI3, },
      +    { HAL_IOMUX_FUNC_SPILCD_DI2, HAL_IOMUX_FUNC_I2S1_SCK, HAL_IOMUX_FUNC_SPILCD_CS1, HAL_IOMUX_FUNC_NONE,
      +      HAL_IOMUX_FUNC_PDM0_D, HAL_IOMUX_FUNC_NONE, },
           // P3_1
      -    { HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_UART1_TX, HAL_IOMUX_FUNC_I2C_M1_SDA, HAL_IOMUX_FUNC_SPI_DIO,
      -      HAL_IOMUX_FUNC_WF_SDIO_DATA0, HAL_IOMUX_FUNC_DISPLAY_SPI_DI, HAL_IOMUX_FUNC_WF_UART_TX, HAL_IOMUX_FUNC_IR_RX,
      -      HAL_IOMUX_FUNC_WF_SDIO_DATA3, HAL_IOMUX_FUNC_PDM1_D, HAL_IOMUX_FUNC_I2S1_SDI2, },
      +    { HAL_IOMUX_FUNC_SPILCD_CS2, HAL_IOMUX_FUNC_I2S1_WS, HAL_IOMUX_FUNC_SPILCD_CS3, HAL_IOMUX_FUNC_NONE,
      +      HAL_IOMUX_FUNC_PDM1_D, HAL_IOMUX_FUNC_NONE, },
           // P3_2
      -    { HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_UART1_RX, HAL_IOMUX_FUNC_I2C_M2_SCL, HAL_IOMUX_FUNC_SPI_CS0,
      -      HAL_IOMUX_FUNC_SPILCD_CS3, HAL_IOMUX_FUNC_DISPLAY_SPI_DO3, HAL_IOMUX_FUNC_WF_UART_CTS, HAL_IOMUX_FUNC_IR_TX,
      -      HAL_IOMUX_FUNC_WF_WAKE_HOST, HAL_IOMUX_FUNC_PDM2_D, HAL_IOMUX_FUNC_I2S1_SDI1, },
      +    { HAL_IOMUX_FUNC_SPILCD_CS3, HAL_IOMUX_FUNC_I2S1_SDI0, HAL_IOMUX_FUNC_SPILCD_CS3, HAL_IOMUX_FUNC_NONE,
      +      HAL_IOMUX_FUNC_PDM2_D, HAL_IOMUX_FUNC_NONE, },
           // P3_3
      -    { HAL_IOMUX_FUNC_PWM3, HAL_IOMUX_FUNC_UART1_TX, HAL_IOMUX_FUNC_I2C_M2_SDA, HAL_IOMUX_FUNC_SPI_CLK,
      -      HAL_IOMUX_FUNC_SPILCD_DI3, HAL_IOMUX_FUNC_DISPLAY_SPI_DO2, HAL_IOMUX_FUNC_WF_UART_RTS, HAL_IOMUX_FUNC_SPILCD_DCN,
      -      HAL_IOMUX_FUNC_IR_RX, HAL_IOMUX_FUNC_PDM2_CK, HAL_IOMUX_FUNC_I2S1_SDI0, },
      +    { HAL_IOMUX_FUNC_SPILCD_DI3, HAL_IOMUX_FUNC_I2S1_SDO, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE,
      +      HAL_IOMUX_FUNC_PDM2_CK, HAL_IOMUX_FUNC_NONE, },
           // P3_4
      -    { HAL_IOMUX_FUNC_PWM4, HAL_IOMUX_FUNC_UART3_RX, HAL_IOMUX_FUNC_I2C_M0_SCL, HAL_IOMUX_FUNC_SPILCD_DI0,
      -      HAL_IOMUX_FUNC_SPI_DI1, HAL_IOMUX_FUNC_DISPLAY_SPI_DO1_DCN, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_SPILCD_DCN,
      -      HAL_IOMUX_FUNC_IR_TX, HAL_IOMUX_FUNC_PDM0_CK, HAL_IOMUX_FUNC_I2S0_SDI3, },
      +    { HAL_IOMUX_FUNC_PWM0, HAL_IOMUX_FUNC_SPI_DI1, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPILCD_DI0,
      +      HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_SPILCD_DCN, },
           // P3_5
      -    { HAL_IOMUX_FUNC_PWM5, HAL_IOMUX_FUNC_UART3_TX, HAL_IOMUX_FUNC_I2C_M0_SDA, HAL_IOMUX_FUNC_SPILCD_DIO,
      -      HAL_IOMUX_FUNC_SPI_CS1, HAL_IOMUX_FUNC_DISPLAY_SPI_DIO, HAL_IOMUX_FUNC_CLK_32K_IN, HAL_IOMUX_FUNC_NONE,
      -      HAL_IOMUX_FUNC_DISPLAY_TE, HAL_IOMUX_FUNC_PDM0_D, HAL_IOMUX_FUNC_I2S0_SDI2, },
      +    { HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_SPI_CS1, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPILCD_DIO,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P3_6
      -    { HAL_IOMUX_FUNC_PWM6, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_FUNC_I2C_M2_SCL, HAL_IOMUX_FUNC_SPILCD_CS0,
      -      HAL_IOMUX_FUNC_SPI_DI2, HAL_IOMUX_FUNC_DISPLAY_SPI_CS, HAL_IOMUX_FUNC_CLK_REQ_OUT, HAL_IOMUX_FUNC_SPDIF0_DI,
      -      HAL_IOMUX_FUNC_IR_RX, HAL_IOMUX_FUNC_PDM1_D, HAL_IOMUX_FUNC_I2S0_SDI1, },
      +    { HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_SPI_DI2, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPILCD_CS0,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
           // P3_7
      -    { HAL_IOMUX_FUNC_PWM7, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_FUNC_I2C_M2_SDA, HAL_IOMUX_FUNC_SPILCD_CLK,
      -      HAL_IOMUX_FUNC_SPI_CS2, HAL_IOMUX_FUNC_DISPLAY_SPI_CLK, HAL_IOMUX_FUNC_CLK_REQ_IN, HAL_IOMUX_FUNC_SPDIF0_DO,
      -      HAL_IOMUX_FUNC_IR_TX, HAL_IOMUX_FUNC_PDM2_D, HAL_IOMUX_FUNC_I2S0_SDI0, },
      +    { HAL_IOMUX_FUNC_PWM3, HAL_IOMUX_FUNC_SPI_CS2, HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_SPILCD_CLK,
      +      HAL_IOMUX_FUNC_NONE, HAL_IOMUX_FUNC_NONE, },
       };
       
       static struct IOMUX_T * const iomux = (struct IOMUX_T *)IOMUX_BASE;
      @@ -278,6 +256,9 @@ static OPT_TYPE enum HAL_IOMUX_PIN_T digmic_d0_pin = DIG_MIC_D0_IOMUX_PIN;
       static OPT_TYPE enum HAL_IOMUX_PIN_T digmic_d1_pin = DIG_MIC_D1_IOMUX_PIN;
       static OPT_TYPE enum HAL_IOMUX_PIN_T digmic_d2_pin = DIG_MIC_D2_IOMUX_PIN;
       
      +static enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T BOOT_DATA_LOC uart0_volt = HAL_IOMUX_PIN_VOLTAGE_VIO;
      +// UART1 is tied to vmem domain
      +
       void hal_iomux_set_default_config(void)
       {
           uint32_t i;
      @@ -335,6 +316,28 @@ uint32_t hal_iomux_init(const struct HAL_IOMUX_PIN_FUNCTION_MAP *map, uint32_t c
           return 0;
       }
       
      +#ifdef ANC_PROD_TEST
      +void hal_iomux_set_dig_mic_clock_pin(enum HAL_IOMUX_PIN_T pin)
      +{
      +    digmic_ck_pin = pin;
      +}
      +void hal_iomux_set_dig_mic_data0_pin(enum HAL_IOMUX_PIN_T pin)
      +{
      +    digmic_d0_pin = pin;
      +}
      +
      +void hal_iomux_set_dig_mic_data1_pin(enum HAL_IOMUX_PIN_T pin)
      +{
      +    digmic_d1_pin = pin;
      +}
      +
      +void hal_iomux_set_dig_mic_data2_pin(enum HAL_IOMUX_PIN_T pin)
      +{
      +    digmic_d2_pin = pin;
      +}
      +#endif
      +
      +
       uint32_t hal_iomux_set_function(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_FUNCTION_T func, enum HAL_IOMUX_OP_TYPE_T type)
       {
           int i;
      @@ -350,7 +353,7 @@ uint32_t hal_iomux_set_function(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_FUNCTIO
           }
       
           if (pin == HAL_IOMUX_PIN_P1_6 || pin == HAL_IOMUX_PIN_P1_7) {
      -        if (func ==  HAL_IOMUX_FUNC_I2C_M0_SCL || func == HAL_IOMUX_FUNC_I2C_M0_SDA) {
      +        if (func ==  HAL_IOMUX_FUNC_I2C_SCL || func == HAL_IOMUX_FUNC_I2C_SDA) {
                   // Enable analog I2C slave
                   iomux->REG_050 &= ~IOMUX_GPIO_I2C_MODE;
                   // Set mcu GPIO func
      @@ -433,7 +436,7 @@ uint32_t hal_iomux_set_io_pull_select(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_P
               return 1;
           }
       
      -    if (pin < HAL_IOMUX_PIN_NUM) {
      +    if (pin < HAL_IOMUX_PIN_LED1) {
               iomux->REG_02C &= ~(1 << pin);
               iomux->REG_030 &= ~(1 << pin);
               if (pull_sel == HAL_IOMUX_PIN_PULLUP_ENABLE) {
      @@ -454,6 +457,7 @@ void hal_iomux_set_sdmmc_dt_n_out_group(int enable)
       
       void hal_iomux_set_uart0_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt)
       {
      +    uart0_volt = volt;
       }
       
       void hal_iomux_set_uart1_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt)
      @@ -478,6 +482,12 @@ bool hal_iomux_uart0_connected(void)
           iomux->REG_008 = SET_BITFIELD(iomux->REG_008, IOMUX_GPIO_P16_SEL, IOMUX_FUNC_VAL_GPIO);
       
           mask = (1 << HAL_IOMUX_PIN_P1_6);
      +    // Set voltage domain
      +    if (uart0_volt == HAL_IOMUX_PIN_VOLTAGE_VIO) {
      +        iomux->REG_070 |= (1 << (IOMUX_GPIO_P1_PWS_SHIFT + 1));
      +    } else {
      +        iomux->REG_070 &= ~(1 << (IOMUX_GPIO_P1_PWS_SHIFT + 1));
      +    }
           // Clear pullup
           iomux->REG_02C &= ~mask;
           // Setup pulldown
      @@ -547,6 +557,12 @@ void hal_iomux_set_uart0(void)
               IOMUX_GPIO_P16_SEL(1) | IOMUX_GPIO_P17_SEL(1);
       
           mask = (1 << HAL_IOMUX_PIN_P1_6) | (1 << HAL_IOMUX_PIN_P1_7);
      +    // Set voltage domain
      +    if (uart0_volt == HAL_IOMUX_PIN_VOLTAGE_VIO) {
      +        iomux->REG_070 |= (1 << (IOMUX_GPIO_P1_PWS_SHIFT + 1));
      +    } else {
      +        iomux->REG_070 &= ~(1 << (IOMUX_GPIO_P1_PWS_SHIFT + 1));
      +    }
           // Setup pullup
           iomux->REG_02C |= (1 << HAL_IOMUX_PIN_P1_6);
           iomux->REG_02C &= ~(1 << HAL_IOMUX_PIN_P1_7);
      @@ -556,20 +572,18 @@ void hal_iomux_set_uart0(void)
       
       void hal_iomux_set_uart1(void)
       {
      -    uint32_t mask_pd_c, mask_pu, mask_pu_c;
      +    uint32_t mask;
       
           // Set uart1 func
           iomux->REG_00C = (iomux->REG_00C & ~(IOMUX_GPIO_P20_SEL_MASK | IOMUX_GPIO_P21_SEL_MASK)) |
               IOMUX_GPIO_P20_SEL(1) | IOMUX_GPIO_P21_SEL(1);
       
      -    mask_pd_c = (1 << HAL_IOMUX_PIN_P2_0) | (1 << HAL_IOMUX_PIN_P2_1);
      -    mask_pu = (1 << HAL_IOMUX_PIN_P2_0);
      -    mask_pu_c = (1 << HAL_IOMUX_PIN_P2_1);
      +    mask = (1 << HAL_IOMUX_PIN_P2_0) | (1 << HAL_IOMUX_PIN_P2_1);
           // Setup pullup
      -    iomux->REG_02C |= mask_pu;
      -    iomux->REG_02C &= ~(mask_pu_c);
      +    iomux->REG_02C |= (1 << HAL_IOMUX_PIN_P2_0);
      +    iomux->REG_02C &= ~(1 << HAL_IOMUX_PIN_P2_1);
           // Clear pulldown
      -    iomux->REG_030 &= ~mask_pd_c;
      +    iomux->REG_030 &= ~mask;
       }
       
       void hal_iomux_set_uart2(void)
      @@ -584,11 +598,17 @@ void hal_iomux_set_analog_i2c(void)
           iomux->REG_050 |= IOMUX_I2C0_M_SEL_GPIO;
           // Set mcu GPIO func
           iomux->REG_008 = (iomux->REG_008 & ~(IOMUX_GPIO_P16_SEL_MASK | IOMUX_GPIO_P17_SEL_MASK)) |
      -        IOMUX_GPIO_P16_SEL(0xF) | IOMUX_GPIO_P17_SEL(0xF);
      +        IOMUX_GPIO_P16_SEL(0) | IOMUX_GPIO_P17_SEL(0);
           // Enable analog I2C slave
           iomux->REG_050 &= ~IOMUX_GPIO_I2C_MODE;
       
           mask = (1 << HAL_IOMUX_PIN_P1_6) | (1 << HAL_IOMUX_PIN_P1_7);
      +    // Set voltage domain
      +    if (uart0_volt == HAL_IOMUX_PIN_VOLTAGE_VIO) {
      +        iomux->REG_070 |= (1 << (IOMUX_GPIO_P1_PWS_SHIFT + 1));
      +    } else {
      +        iomux->REG_070 &= ~(1 << (IOMUX_GPIO_P1_PWS_SHIFT + 1));
      +    }
           // Setup pullup
           iomux->REG_02C |= mask;
           // Clear pulldown
      @@ -601,27 +621,27 @@ void hal_iomux_set_jtag(void)
           uint32_t val;
       
           // SWCLK/TCK, SWDIO/TMS
      -    mask = IOMUX_GPIO_P01_SEL_MASK | IOMUX_GPIO_P00_SEL_MASK;
      -    val = IOMUX_GPIO_P01_SEL(7) | IOMUX_GPIO_P00_SEL(7);
      +    mask = IOMUX_GPIO_P01_SEL_MASK | IOMUX_GPIO_P02_SEL_MASK;
      +    val = IOMUX_GPIO_P01_SEL(7) | IOMUX_GPIO_P02_SEL(7);
       
           // TDI, TDO
       #ifdef JTAG_TDI_TDO_PIN
      -    mask |= IOMUX_GPIO_P02_SEL_MASK | IOMUX_GPIO_P03_SEL_MASK;
      -    val |= IOMUX_GPIO_P02_SEL(7) | IOMUX_GPIO_P03_SEL(7);
      +    mask |= IOMUX_GPIO_P00_SEL_MASK | IOMUX_GPIO_P03_SEL_MASK;
      +    val |= IOMUX_GPIO_P00_SEL(7) | IOMUX_GPIO_P03_SEL(7);
       #endif
           iomux->REG_004 = (iomux->REG_004 & ~mask) | val;
       
           // RESET
       #if defined(JTAG_RESET_PIN) || defined(JTAG_TDI_TDO_PIN)
      -    iomux->REG_004 = (iomux->REG_004 & ~(IOMUX_GPIO_P05_SEL_MASK)) | IOMUX_GPIO_P05_SEL(7);
      +    iomux->REG_00C = (iomux->REG_00C & ~(IOMUX_GPIO_P20_SEL_MASK)) | IOMUX_GPIO_P20_SEL(7);
       #endif
       
      -    mask = (1 << HAL_IOMUX_PIN_P0_1) | (1 << HAL_IOMUX_PIN_P0_0);
      +    mask = (1 << HAL_IOMUX_PIN_P0_1) | (1 << HAL_IOMUX_PIN_P0_2);
       #ifdef JTAG_TDI_TDO_PIN
      -    mask |= (1 << HAL_IOMUX_PIN_P0_2) | (1 << HAL_IOMUX_PIN_P0_3);
      +    mask |= (1 << HAL_IOMUX_PIN_P0_0) | (1 << HAL_IOMUX_PIN_P0_3);
       #endif
       #if defined(JTAG_RESET_PIN) || defined(JTAG_TDI_TDO_PIN)
      -    mask |= (1 << HAL_IOMUX_PIN_P0_5);
      +    mask |= (1 << HAL_IOMUX_PIN_P2_0);
       #endif
           // Clear pullup
           iomux->REG_02C &= ~mask;
      @@ -658,10 +678,10 @@ void hal_iomux_ispi_access_init(void)
       void hal_iomux_set_i2s0(void)
       {
           static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_i2s[] = {
      +        {HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_I2S0_SDI0, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_I2S0_SDO,  I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
               {HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_I2S0_WS,   I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
               {HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_I2S0_SCK,  I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_I2S0_SDI0, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_I2S0_SDO0,  I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
           };
       
           hal_iomux_init(pinmux_i2s, ARRAY_SIZE(pinmux_i2s));
      @@ -670,65 +690,34 @@ void hal_iomux_set_i2s0(void)
       void hal_iomux_set_i2s1(void)
       {
           static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_i2s[] = {
      -        {HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_I2S1_WS,   I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P2_3, HAL_IOMUX_FUNC_I2S1_SCK,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#if (I2S1_I_IOMUX_INDEX == 20)
      -        {HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_I2S1_SDI0, I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (I2S1_I_IOMUX_INDEX == 33)
      -        {HAL_IOMUX_PIN_P3_3, HAL_IOMUX_FUNC_I2S1_SDI0, I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#if (I2S1_IOMUX_INDEX == 30)
      +        {HAL_IOMUX_PIN_P3_2, HAL_IOMUX_FUNC_I2S1_SDI0, I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P3_3, HAL_IOMUX_FUNC_I2S1_SDO,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P3_1, HAL_IOMUX_FUNC_I2S1_WS,   I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P3_0, HAL_IOMUX_FUNC_I2S1_SCK,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #else
      -#error "Unsupported I2S1_I_IOMUX_INDEX"
      -#endif
      -#if (I2S1_I1_IOMUX_INDEX == 32)
      -        {HAL_IOMUX_PIN_P3_2, HAL_IOMUX_FUNC_I2S1_SDI1, I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      -#if (I2S1_I2_IOMUX_INDEX == 31)
      -        {HAL_IOMUX_PIN_P3_1, HAL_IOMUX_FUNC_I2S1_SDI2, I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      -#if (I2S1_I3_IOMUX_INDEX == 30)
      -        {HAL_IOMUX_PIN_P3_0, HAL_IOMUX_FUNC_I2S1_SDI3, I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      -
      -#if (I2S1_O_IOMUX_INDEX == 21)
      -        {HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_I2S1_SDO0,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (I2S1_O_IOMUX_INDEX == 27)
      -        {HAL_IOMUX_PIN_P2_7, HAL_IOMUX_FUNC_I2S1_SDO0,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#else
      -#error "Unsupported I2S1_O_IOMUX_INDEX"
      -#endif
      -#if (I2S1_O1_IOMUX_INDEX == 26)
      -        {HAL_IOMUX_PIN_P2_6, HAL_IOMUX_FUNC_I2S1_SDO1,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      -#if (I2S1_O2_IOMUX_INDEX == 25)
      -        {HAL_IOMUX_PIN_P2_5, HAL_IOMUX_FUNC_I2S1_SDO2,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      -#if (I2S1_O3_IOMUX_INDEX == 24)
      -        {HAL_IOMUX_PIN_P2_4, HAL_IOMUX_FUNC_I2S1_SDO3,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      +        {HAL_IOMUX_PIN_P1_4, HAL_IOMUX_FUNC_I2S1_SDI0, I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_I2S1_SDO,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_I2S1_WS,   I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_I2S1_SCK,  I2S1_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
           };
      -
      +#endif
           hal_iomux_init(pinmux_i2s, ARRAY_SIZE(pinmux_i2s));
       }
       
       void hal_iomux_set_i2s_mclk(void)
       {
           static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux[] = {
      -#if (I2S_MCLK_IOMUX_INDEX == 04)
      -        {HAL_IOMUX_PIN_P0_4, HAL_IOMUX_FUNC_I2S_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (I2S_MCLK_IOMUX_INDEX == 13)
      -        {HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_I2S_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#if (I2S_MCLK_IOMUX_INDEX == 13)
      +        {HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_I2S0_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #elif (I2S_MCLK_IOMUX_INDEX == 15)
      -        {HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_I2S_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_I2S0_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #elif (I2S_MCLK_IOMUX_INDEX == 20)
      -        {HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_I2S_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_I2S0_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #elif (I2S_MCLK_IOMUX_INDEX == 22)
      -        {HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_I2S_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (I2S_MCLK_IOMUX_INDEX == 27)
      -        {HAL_IOMUX_PIN_P2_7, HAL_IOMUX_FUNC_I2S_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (I2S_MCLK_IOMUX_INDEX == 34)
      -        {HAL_IOMUX_PIN_P3_4, HAL_IOMUX_FUNC_I2S_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_I2S0_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #else
      -#error "Unsupported I2S_MCLK_IOMUX_INDEX"
      +        {HAL_IOMUX_PIN_P0_4, HAL_IOMUX_FUNC_I2S0_MCLK, I2S0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
           };
       
      @@ -738,41 +727,24 @@ void hal_iomux_set_i2s_mclk(void)
       void hal_iomux_set_spdif0(void)
       {
           static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_spdif[] = {
      -#if (SPDIF0_I_IOMUX_INDEX == 02)
      -        {HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_SPDIF0_DI, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
      -#elif (SPDIF0_I_IOMUX_INDEX == 10)
      -        {HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_SPDIF0_DI, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
      -#elif (SPDIF0_I_IOMUX_INDEX == 20)
      +#if (SPDIF0_IOMUX_INDEX == 20)
               {HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_SPDIF0_DI, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
      -#elif (SPDIF0_I_IOMUX_INDEX == 26)
      -        {HAL_IOMUX_PIN_P2_6, HAL_IOMUX_FUNC_SPDIF0_DI, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
      -#elif (SPDIF0_I_IOMUX_INDEX == 37)
      -        {HAL_IOMUX_PIN_P3_7, HAL_IOMUX_FUNC_SPDIF0_DI, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
      -#elif (SPDIF0_I_IOMUX_INDEX == 24)
      -        {HAL_IOMUX_PIN_P2_4, HAL_IOMUX_FUNC_SPDIF0_DI, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
      -#else
      -#error "Unsupported SPDIF0_I_IOMUX_INDEX"
      -#endif
      -
      -#if (SPDIF0_O_IOMUX_INDEX == 03)
      -        {HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_SPDIF0_DO, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPDIF0_O_IOMUX_INDEX == 11)
      -        {HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_SPDIF0_DO, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPDIF0_O_IOMUX_INDEX == 21)
               {HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_SPDIF0_DO, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPDIF0_O_IOMUX_INDEX == 27)
      +#elif (SPDIF0_IOMUX_INDEX == 26)
      +        {HAL_IOMUX_PIN_P2_6, HAL_IOMUX_FUNC_SPDIF0_DI, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
               {HAL_IOMUX_PIN_P2_7, HAL_IOMUX_FUNC_SPDIF0_DO, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPDIF0_O_IOMUX_INDEX == 37)
      -        {HAL_IOMUX_PIN_P3_7, HAL_IOMUX_FUNC_SPDIF0_DO, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPDIF0_O_IOMUX_INDEX == 07)
      -        {HAL_IOMUX_PIN_P0_7, HAL_IOMUX_FUNC_SPDIF0_DO, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #else
      -#error "Unsupported SPDIF0_O_IOMUX_INDEX"
      +        {HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_SPDIF0_DI, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
      +        {HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_SPDIF0_DO, SPDIF0_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
           };
      +
           hal_iomux_init(pinmux_spdif, ARRAY_SIZE(pinmux_spdif));
       }
       
      +void hal_iomux_set_spdif1(void)
      +{
      +}
       
       void hal_iomux_set_dig_mic(uint32_t map)
       {
      @@ -798,29 +770,22 @@ void hal_iomux_set_dig_mic(uint32_t map)
           } else if (digmic_ck_pin == HAL_IOMUX_PIN_P3_3) {
               pinmux_digitalmic_clk[0].pin = HAL_IOMUX_PIN_P3_3;
               pinmux_digitalmic_clk[0].function = HAL_IOMUX_FUNC_PDM2_CK;
      -    } else if (digmic_ck_pin == HAL_IOMUX_PIN_P3_4) {
      -        pinmux_digitalmic_clk[0].pin = HAL_IOMUX_PIN_P3_4;
      -        pinmux_digitalmic_clk[0].function = HAL_IOMUX_FUNC_PDM0_CK;
           }
       
           if (digmic_d0_pin == HAL_IOMUX_PIN_P0_1) {
               pinmux_digitalmic0[0].pin = HAL_IOMUX_PIN_P0_1;
      -    } else if (digmic_d0_pin == HAL_IOMUX_PIN_P0_5) {
      -        pinmux_digitalmic0[0].pin = HAL_IOMUX_PIN_P0_5;
      +    } else if (digmic_d0_pin == HAL_IOMUX_PIN_P0_6) {
      +        pinmux_digitalmic0[0].pin = HAL_IOMUX_PIN_P0_6;
           } else if (digmic_d0_pin == HAL_IOMUX_PIN_P3_0) {
               pinmux_digitalmic0[0].pin = HAL_IOMUX_PIN_P3_0;
      -    } else if (digmic_d0_pin == HAL_IOMUX_PIN_P3_5) {
      -        pinmux_digitalmic0[0].pin = HAL_IOMUX_PIN_P3_5;
           }
       
           if (digmic_d1_pin == HAL_IOMUX_PIN_P0_2) {
               pinmux_digitalmic1[0].pin = HAL_IOMUX_PIN_P0_2;
      -    } else if (digmic_d1_pin == HAL_IOMUX_PIN_P0_6) {
      -        pinmux_digitalmic1[0].pin = HAL_IOMUX_PIN_P0_6;
      +    } else if (digmic_d1_pin == HAL_IOMUX_PIN_P0_5) {
      +        pinmux_digitalmic1[0].pin = HAL_IOMUX_PIN_P0_5;
           } else if (digmic_d1_pin == HAL_IOMUX_PIN_P3_1) {
               pinmux_digitalmic1[0].pin = HAL_IOMUX_PIN_P3_1;
      -    } else if (digmic_d1_pin == HAL_IOMUX_PIN_P3_6) {
      -        pinmux_digitalmic1[0].pin = HAL_IOMUX_PIN_P3_6;
           }
       
           if (digmic_d2_pin == HAL_IOMUX_PIN_P0_3) {
      @@ -829,8 +794,6 @@ void hal_iomux_set_dig_mic(uint32_t map)
               pinmux_digitalmic2[0].pin = HAL_IOMUX_PIN_P0_7;
           } else if (digmic_d2_pin == HAL_IOMUX_PIN_P3_2) {
               pinmux_digitalmic2[0].pin = HAL_IOMUX_PIN_P3_2;
      -    } else if (digmic_d2_pin == HAL_IOMUX_PIN_P3_7) {
      -        pinmux_digitalmic2[0].pin = HAL_IOMUX_PIN_P3_7;
           }
       
           if ((map & 0xF) == 0) {
      @@ -850,163 +813,140 @@ void hal_iomux_set_dig_mic(uint32_t map)
       
       void hal_iomux_set_spi(void)
       {
      -    static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_spi[] = {
      -#if (SPI_IOMUX_INDEX == 04)
      -#ifdef SPI_IOMUX_4WIRE
      -        {HAL_IOMUX_PIN_P0_4, HAL_IOMUX_FUNC_SPI_DI0, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      +    static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_spi_3wire[3] = {
               {HAL_IOMUX_PIN_P0_5, HAL_IOMUX_FUNC_SPI_CLK, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
               {HAL_IOMUX_PIN_P0_6, HAL_IOMUX_FUNC_SPI_CS0,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
               {HAL_IOMUX_PIN_P0_7, HAL_IOMUX_FUNC_SPI_DIO, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -
      -#elif (SPI_IOMUX_INDEX == 24)
      -#ifdef SPI_IOMUX_4WIRE
      -        {HAL_IOMUX_PIN_P2_4, HAL_IOMUX_FUNC_SPI_DI0, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      -        {HAL_IOMUX_PIN_P2_7, HAL_IOMUX_FUNC_SPI_CLK, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P2_6, HAL_IOMUX_FUNC_SPI_CS0,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P2_5, HAL_IOMUX_FUNC_SPI_DIO, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -
      -#elif (SPI_IOMUX_INDEX == 30)
      -#ifdef SPI_IOMUX_4WIRE
      -        {HAL_IOMUX_PIN_P3_0, HAL_IOMUX_FUNC_SPI_DI0, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      -        {HAL_IOMUX_PIN_P3_3, HAL_IOMUX_FUNC_SPI_CLK, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P3_2, HAL_IOMUX_FUNC_SPI_CS0,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P3_1, HAL_IOMUX_FUNC_SPI_DIO, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#ifdef SPI_IOMUX_CS1_INDEX
      +#if (SPI_IOMUX_CS1_INDEX == 35)
      +        {HAL_IOMUX_PIN_P3_5, HAL_IOMUX_FUNC_SPI_CS1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #else
      -#error "Unsupported SPI_IOMUX_INDEX"
      -#endif
      -
      -#if (SPI_IOMUX_CS1_INDEX == 10)
               {HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_SPI_CS1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPI_IOMUX_CS1_INDEX == 35)
      -        {HAL_IOMUX_PIN_P3_5, HAL_IOMUX_FUNC_SPI_CS1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -#if (SPI_IOMUX_CS2_INDEX == 11)
      -        {HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_SPI_CS2,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPI_IOMUX_CS2_INDEX == 37)
      +#endif
      +#ifdef SPI_IOMUX_CS2_INDEX
      +#if (SPI_IOMUX_CS2_INDEX == 37)
               {HAL_IOMUX_PIN_P3_7, HAL_IOMUX_FUNC_SPI_CS2,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#else
      +        {HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_SPI_CS2,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -#if (SPI_IOMUX_CS3_INDEX == 12)
      -        {HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_SPI_CS3,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPI_IOMUX_CS3_INDEX == 25)
      +#endif
      +#ifdef SPI_IOMUX_CS3_INDEX
      +#if (SPI_IOMUX_CS3_INDEX == 25)
               {HAL_IOMUX_PIN_P2_5, HAL_IOMUX_FUNC_SPI_CS3,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#else
      +        {HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_SPI_CS3,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -
      -#ifdef SPI_IOMUX_4WIRE
      -#if (SPI_IOMUX_DI1_INDEX == 13)
      -        {HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_SPI_DI1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPI_IOMUX_DI1_INDEX == 34)
      -        {HAL_IOMUX_PIN_P3_4, HAL_IOMUX_FUNC_SPI_DI1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -#if (SPI_IOMUX_DI2_INDEX == 14)
      -        {HAL_IOMUX_PIN_P1_4, HAL_IOMUX_FUNC_SPI_DI2,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPI_IOMUX_DI2_INDEX == 36)
      -        {HAL_IOMUX_PIN_P3_6, HAL_IOMUX_FUNC_SPI_DI2,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +    };
      +#ifdef SPI_IOMUX_4WIRE
      +    static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_spi_4wire[1] = {
      +        {HAL_IOMUX_PIN_P0_4, HAL_IOMUX_FUNC_SPI_DI0, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#ifdef SPI_IOMUX_DI1_INDEX
      +        {HAL_IOMUX_PIN_P3_4, HAL_IOMUX_FUNC_SPI_DI1, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -#if (SPI_IOMUX_DI3_INDEX == 15)
      -        {HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_SPI_DI3,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPI_IOMUX_DI3_INDEX == 24)
      -        {HAL_IOMUX_PIN_P2_4, HAL_IOMUX_FUNC_SPI_DI3,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#ifdef SPI_IOMUX_DI2_INDEX
      +        {HAL_IOMUX_PIN_P3_6, HAL_IOMUX_FUNC_SPI_DI2, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      +#ifdef SPI_IOMUX_DI3_INDEX
      +        {HAL_IOMUX_PIN_P2_4, HAL_IOMUX_FUNC_SPI_DI3, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
           };
      +#endif
       
      -    hal_iomux_init(pinmux_spi, ARRAY_SIZE(pinmux_spi));
      -}
      -
      -void hal_iomux_set_spilcd_slave(void)
      -{
      -    iomux->REG_050 |= IOMUX_SPILCD1_MASTER_N;
      +    hal_iomux_init(pinmux_spi_3wire, ARRAY_SIZE(pinmux_spi_3wire));
      +#ifdef SPI_IOMUX_4WIRE
      +    hal_iomux_init(pinmux_spi_4wire, ARRAY_SIZE(pinmux_spi_4wire));
      +#endif
       }
       
       void hal_iomux_set_spilcd(void)
       {
      -    static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_spilcd[] = {
      -#if (SPILCD_IOMUX_INDEX == 00)
      -#ifdef SPILCD_IOMUX_4WIRE
      -        {HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_SPILCD_DI0, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      -        {HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_SPILCD_CLK, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_SPILCD_CS0,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_SPILCD_DIO, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -
      -#elif (SPILCD_IOMUX_INDEX == 10)
      -#ifdef SPILCD_IOMUX_4WIRE
      -        {HAL_IOMUX_PIN_P1_4, HAL_IOMUX_FUNC_SPILCD_DI0, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +    static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_spilcd_3wire[] = {
      +#if (SPILCD_IOMUX_INDEX == 10)
      +        {HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_SPILCD_CLK, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_SPILCD_CS0, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_SPILCD_DIO, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#elif (SPILCD_IOMUX_INDEX == 35)
      +        {HAL_IOMUX_PIN_P3_7, HAL_IOMUX_FUNC_SPILCD_CLK, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P3_6, HAL_IOMUX_FUNC_SPILCD_CS0, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P3_5, HAL_IOMUX_FUNC_SPILCD_DIO, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#else
      +        {HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_SPILCD_CLK, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_SPILCD_CS0, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_SPILCD_DIO, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -        {HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_SPILCD_CLK, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_SPILCD_CS0,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_SPILCD_DIO, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -
      -#elif (SPILCD_IOMUX_INDEX == 20)
      -#ifdef SPILCD_IOMUX_4WIRE
      -        {HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_SPILCD_DI0, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#ifdef SPILCD_IOMUX_CS1_INDEX
      +#if (SPILCD_IOMUX_CS1_INDEX == 12)
      +        {HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_SPILCD_CS1, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#elif (SPILCD_IOMUX_CS1_INDEX == 27)
      +        {HAL_IOMUX_PIN_P2_7, HAL_IOMUX_FUNC_SPILCD_CS1, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#elif (SPILCD_IOMUX_CS1_INDEX == 30)
      +        {HAL_IOMUX_PIN_P3_0, HAL_IOMUX_FUNC_SPILCD_CS1, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#else
      +        {HAL_IOMUX_PIN_P0_5, HAL_IOMUX_FUNC_SPILCD_CS1, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -        {HAL_IOMUX_PIN_P2_3, HAL_IOMUX_FUNC_SPILCD_CLK, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_SPILCD_CS0,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_SPILCD_DIO, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -
      -#elif (SPILCD_IOMUX_INDEX == 34)
      -#ifdef SPILCD_IOMUX_4WIRE
      -        {HAL_IOMUX_PIN_P3_4, HAL_IOMUX_FUNC_SPILCD_DI0, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -        {HAL_IOMUX_PIN_P3_7, HAL_IOMUX_FUNC_SPILCD_CLK, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P3_6, HAL_IOMUX_FUNC_SPILCD_CS0,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -        {HAL_IOMUX_PIN_P3_5, HAL_IOMUX_FUNC_SPILCD_DIO, SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#ifdef SPILCD_IOMUX_CS2_INDEX
      +#if (SPILCD_IOMUX_CS2_INDEX == 31)
      +        {HAL_IOMUX_PIN_P3_1, HAL_IOMUX_FUNC_SPILCD_CS2, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #else
      -#error "Unsupported SPILCD_IOMUX_INDEX"
      +        {HAL_IOMUX_PIN_P0_6, HAL_IOMUX_FUNC_SPILCD_CS2, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -
      -#if (SPILCD_IOMUX_CS1_INDEX == 05)
      -        {HAL_IOMUX_PIN_P0_5, HAL_IOMUX_FUNC_SPILCD_CS1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPILCD_IOMUX_CS1_INDEX == 12)
      -        {HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_SPILCD_CS1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPILCD_IOMUX_CS1_INDEX == 27)
      -        {HAL_IOMUX_PIN_P2_7, HAL_IOMUX_FUNC_SPILCD_CS1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -#if (SPILCD_IOMUX_CS2_INDEX == 06)
      -        {HAL_IOMUX_PIN_P0_6, HAL_IOMUX_FUNC_SPILCD_CS2,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPILCD_IOMUX_CS2_INDEX == 31)
      -        {HAL_IOMUX_PIN_P3_1, HAL_IOMUX_FUNC_SPILCD_CS2,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#endif
      -#if (SPILCD_IOMUX_CS3_INDEX == 07)
      -        {HAL_IOMUX_PIN_P0_7, HAL_IOMUX_FUNC_SPILCD_CS3,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#ifdef SPILCD_IOMUX_CS3_INDEX
      +#if (SPILCD_IOMUX_CS3_INDEX == 31)
      +        {HAL_IOMUX_PIN_P3_1, HAL_IOMUX_FUNC_SPILCD_CS3, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #elif (SPILCD_IOMUX_CS3_INDEX == 32)
      -        {HAL_IOMUX_PIN_P3_2, HAL_IOMUX_FUNC_SPILCD_CS3,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +        {HAL_IOMUX_PIN_P3_2, HAL_IOMUX_FUNC_SPILCD_CS3, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#else
      +        {HAL_IOMUX_PIN_P0_7, HAL_IOMUX_FUNC_SPILCD_CS3, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -
      +#endif
      +    };
       #ifdef SPILCD_IOMUX_4WIRE
      -#if (SPILCD_IOMUX_DI1_INDEX == 02)
      -        {HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_SPILCD_DI1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPILCD_IOMUX_DI1_INDEX == 26)
      -        {HAL_IOMUX_PIN_P2_6, HAL_IOMUX_FUNC_SPILCD_DI1,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +    static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_spilcd_4wire[] = {
      +#ifdef SPILCD_IOMUX_DI0_INDEX
      +#if (SPILCD_IOMUX_DI0_INDEX == 14)
      +        {HAL_IOMUX_PIN_P1_4, HAL_IOMUX_FUNC_SPILCD_DI0, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#elif (SPILCD_IOMUX_DI0_INDEX == 34)
      +        {HAL_IOMUX_PIN_P3_4, HAL_IOMUX_FUNC_SPILCD_DI0, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#else
      +        {HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_SPILCD_DI0, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#endif
       #endif
      -#if (SPILCD_IOMUX_DI2_INDEX == 03)
      -        {HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_SPILCD_DI2,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPILCD_IOMUX_DI2_INDEX == 30)
      -        {HAL_IOMUX_PIN_P3_0, HAL_IOMUX_FUNC_SPILCD_DI2,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#ifdef SPILCD_IOMUX_DI1_INDEX
      +        {HAL_IOMUX_PIN_P2_6, HAL_IOMUX_FUNC_SPILCD_DI1, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      -#if (SPILCD_IOMUX_DI3_INDEX == 04)
      -        {HAL_IOMUX_PIN_P0_4, HAL_IOMUX_FUNC_SPILCD_DI3,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      -#elif (SPILCD_IOMUX_DI3_INDEX == 33)
      -        {HAL_IOMUX_PIN_P3_3, HAL_IOMUX_FUNC_SPILCD_DI3,  SPI_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
      +#ifdef SPILCD_IOMUX_DI2_INDEX
      +        {HAL_IOMUX_PIN_P3_0, HAL_IOMUX_FUNC_SPILCD_DI2, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
      +#ifdef SPILCD_IOMUX_DI3_INDEX
      +        {HAL_IOMUX_PIN_P3_3, HAL_IOMUX_FUNC_SPILCD_DI3, SPILCD_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
           };
      +#endif
       
      -    hal_iomux_init(pinmux_spilcd, ARRAY_SIZE(pinmux_spilcd));
      +    hal_iomux_init(pinmux_spilcd_3wire, ARRAY_SIZE(pinmux_spilcd_3wire));
      +#ifdef SPILCD_IOMUX_4WIRE
      +    hal_iomux_init(pinmux_spilcd_4wire, ARRAY_SIZE(pinmux_spilcd_4wire));
      +#endif
       }
       
       void hal_iomux_set_i2c0(void)
       {
      +#if (I2C0_IOMUX_INDEX == 16)
      +    hal_iomux_set_analog_i2c();
      +    // IOMUX_GPIO_I2C_MODE should be kept in disabled state
      +    iomux->REG_050 &= ~IOMUX_I2C0_M_SEL_GPIO;
      +#else
           static const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_i2c[] = {
               {HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_I2C_M0_SCL, I2C0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
               {HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_I2C_M0_SDA, I2C0_VOLTAGE_SEL, HAL_IOMUX_PIN_PULLUP_ENABLE},
           };
      +
           hal_iomux_init(pinmux_i2c, ARRAY_SIZE(pinmux_i2c));
      -    iomux->REG_050 |= IOMUX_I2C0_M_SEL_GPIO;
      +#endif
       }
       
       void hal_iomux_set_i2c1(void)
      @@ -1041,7 +981,7 @@ void hal_iomux_set_clock_out(void)
       #elif (CLKOUT_IOMUX_INDEX == 34)
               {HAL_IOMUX_PIN_P3_4, HAL_IOMUX_FUNC_CLK_OUT, CLKOUT_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #else
      -#error "Unsupported CLKOUT_IOMUX_INDEX"
      +        {HAL_IOMUX_PIN_P0_4, HAL_IOMUX_FUNC_CLK_OUT, CLKOUT_VOLTAGE_SEL, HAL_IOMUX_PIN_NOPULL},
       #endif
           };
       
      @@ -1061,9 +1001,15 @@ void hal_iomux_set_bt_tport(void)
           // P0_0 ~ P0_3,
           iomux->REG_004 = (iomux->REG_004 & ~(IOMUX_GPIO_P00_SEL_MASK | IOMUX_GPIO_P01_SEL_MASK | IOMUX_GPIO_P02_SEL_MASK | IOMUX_GPIO_P03_SEL_MASK)) |
           IOMUX_GPIO_P00_SEL(0xA) | IOMUX_GPIO_P01_SEL(0xA) | IOMUX_GPIO_P02_SEL(0xA) |IOMUX_GPIO_P03_SEL(0xA);
      +#ifdef TPORTS_KEY_COEXIST
      +    //P1_1 ~ P1_2,
      +    iomux->REG_008 = (iomux->REG_008 & ~(IOMUX_GPIO_P11_SEL_MASK | IOMUX_GPIO_P12_SEL_MASK)) |
      +    IOMUX_GPIO_P11_SEL(0xA) | IOMUX_GPIO_P12_SEL(0xA);
      +#else
           //P1_0 ~ P1_3,
           iomux->REG_008 = (iomux->REG_008 & ~(IOMUX_GPIO_P10_SEL_MASK | IOMUX_GPIO_P11_SEL_MASK | IOMUX_GPIO_P12_SEL_MASK | IOMUX_GPIO_P13_SEL_MASK )) |
           IOMUX_GPIO_P10_SEL(0xA) | IOMUX_GPIO_P11_SEL(0xA) | IOMUX_GPIO_P12_SEL(0xA) | IOMUX_GPIO_P13_SEL(0xA);
      +#endif
           // ANA TEST DIR
           iomux->REG_014 = 0x0f0f;
           // ANA TEST SEL
      @@ -1102,9 +1048,7 @@ int WEAK hal_pwrkey_set_irq(enum HAL_PWRKEY_IRQ_T type)
       
       bool WEAK hal_pwrkey_pressed(void)
       {
      -    uint32_t v = iomux->REG_040;
      -    return !!(v & IOMUX_POWER_ON_FEEDOUT);
      -
      +    return 0;
       }
       
       bool hal_pwrkey_startup_pressed(void)
      @@ -1115,9 +1059,38 @@ bool hal_pwrkey_startup_pressed(void)
       enum HAL_PWRKEY_IRQ_T WEAK hal_pwrkey_get_irq_state(void)
       {
           enum HAL_PWRKEY_IRQ_T state = HAL_PWRKEY_IRQ_NONE;
      +
           return state;
       }
       
      +const struct HAL_IOMUX_PIN_FUNCTION_MAP iomux_tport[] = {
      +/*    {HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},*/
      +    {HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
      +};
      +
      +int hal_iomux_tportopen(void)
      +{
      +    int i;
      +
      +    for (i=0;i<sizeof(iomux_tport)/sizeof(struct HAL_IOMUX_PIN_FUNCTION_MAP);i++){
      +        hal_iomux_init((struct HAL_IOMUX_PIN_FUNCTION_MAP *)&iomux_tport[i], 1);
      +        hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)iomux_tport[i].pin, HAL_GPIO_DIR_OUT, 0);
      +    }
      +    return 0;
      +}
      +
      +int hal_iomux_tportset(int port)
      +{
      +    hal_gpio_pin_set((enum HAL_GPIO_PIN_T)iomux_tport[port].pin);
      +    return 0;
      +}
      +
      +int hal_iomux_tportclr(int port)
      +{
      +    hal_gpio_pin_clr((enum HAL_GPIO_PIN_T)iomux_tport[port].pin);
      +    return 0;
      +}
      +
       void hal_iomux_set_codec_gpio_trigger(enum HAL_IOMUX_PIN_T pin, bool polarity)
       {
           iomux->REG_064 = SET_BITFIELD(iomux->REG_064, IOMUX_CFG_CODEC_TRIG_SEL, pin);
  • platform/hal/best2300p/hal_iomux_best2300p.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/hal_iomux_best2300p.h bes/platform/hal/best2300p/hal_iomux_best2300p.h
      index c1f1c68b621..52d5a8f8a08 100644
      --- a/platform/hal/best2300p/hal_iomux_best2300p.h
      +++ b/platform/hal/best2300p/hal_iomux_best2300p.h
      @@ -130,29 +130,18 @@ enum HAL_IOMUX_FUNCTION_T {
           HAL_IOMUX_FUNC_I2C_M0_SCL,
           HAL_IOMUX_FUNC_I2C_M0_SDA,
           HAL_IOMUX_FUNC_I2C_M1_SCL,
      -    HAL_IOMUX_FUNC_I2C_M2_SCL,
      -    HAL_IOMUX_FUNC_I2C_M2_SDA,
           HAL_IOMUX_FUNC_I2C_M1_SDA,
      -    HAL_IOMUX_FUNC_I2S_MCLK,
      +    HAL_IOMUX_FUNC_I2C_SCL,
      +    HAL_IOMUX_FUNC_I2C_SDA,
      +    HAL_IOMUX_FUNC_I2S0_MCLK,
           HAL_IOMUX_FUNC_I2S0_SCK,
           HAL_IOMUX_FUNC_I2S0_SDI0,
      -    HAL_IOMUX_FUNC_I2S0_SDI1,
      -    HAL_IOMUX_FUNC_I2S0_SDI2,
      -    HAL_IOMUX_FUNC_I2S0_SDI3,
      -    HAL_IOMUX_FUNC_I2S0_SDO0,
      -    HAL_IOMUX_FUNC_I2S0_SDO1,
      -    HAL_IOMUX_FUNC_I2S0_SDO2,
      -    HAL_IOMUX_FUNC_I2S0_SDO3,
      +    HAL_IOMUX_FUNC_I2S0_SDO,
           HAL_IOMUX_FUNC_I2S0_WS,
      +    HAL_IOMUX_FUNC_I2S1_MCLK,
           HAL_IOMUX_FUNC_I2S1_SCK,
           HAL_IOMUX_FUNC_I2S1_SDI0,
      -    HAL_IOMUX_FUNC_I2S1_SDI1,
      -    HAL_IOMUX_FUNC_I2S1_SDI2,
      -    HAL_IOMUX_FUNC_I2S1_SDI3,
      -    HAL_IOMUX_FUNC_I2S1_SDO0,
      -    HAL_IOMUX_FUNC_I2S1_SDO1,
      -    HAL_IOMUX_FUNC_I2S1_SDO2,
      -    HAL_IOMUX_FUNC_I2S1_SDO3,
      +    HAL_IOMUX_FUNC_I2S1_SDO,
           HAL_IOMUX_FUNC_I2S1_WS,
           HAL_IOMUX_FUNC_PCM_CLK,
           HAL_IOMUX_FUNC_PCM_DI,
      @@ -231,8 +220,11 @@ void hal_iomux_set_mcu_clock_out(void);
       
       void hal_iomux_set_bt_clock_out(void);
       
      +int hal_iomux_tportopen(void);
       
      +int hal_iomux_tportclr(int port);
       
      +int hal_iomux_tportset(int port);
       
       #ifdef __cplusplus
       }

@OneDeuxTriSeiGo
Copy link
Author

  • platform/hal/best2300p/hal_psc_best2300p.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/hal_psc_best2300p.c bes/platform/hal/best2300p/hal_psc_best2300p.c
      index 3ff9c39821a..216f189cbe0 100644
      --- a/platform/hal/best2300p/hal_psc_best2300p.c
      +++ b/platform/hal/best2300p/hal_psc_best2300p.c
      @@ -25,12 +25,22 @@ static struct AONPSC_T * const psc = (struct AONPSC_T *)AON_PSC_BASE;
       
       void BOOT_TEXT_FLASH_LOC hal_psc_init(void)
       {
      -    // Setup MCU wakeup mask
      -    psc->REG_080 = 0;
      -    psc->REG_084 = 0;
      +    // Setup wakeup mask
      +    psc->REG_080 = 0xFFFFFFFF;
      +    psc->REG_084 = 0xFFFFFFFF;
       }
       
      +void SRAM_TEXT_LOC hal_psc_core_auto_power_down(void)
      +{
      +    psc->REG_018 = PSC_WRITE_ENABLE | 0;
      +    psc->REG_000 = PSC_WRITE_ENABLE | PSC_AON_MCU_PG_AUTO_EN;
      +    psc->REG_010 = PSC_WRITE_ENABLE | PSC_AON_MCU_POWERDN_START;
      +}
       
      +void SRAM_TEXT_LOC hal_psc_mcu_auto_power_up(void)
      +{
      +    psc->REG_014 = PSC_WRITE_ENABLE | PSC_AON_MCU_POWERUP_START;
      +}
       
       void BOOT_TEXT_FLASH_LOC hal_psc_codec_enable(void)
       {
      @@ -90,10 +100,18 @@ void BOOT_TEXT_FLASH_LOC hal_psc_bt_enable(void)
               PSC_AON_BT_ISO_EN_DR |
               PSC_AON_BT_CLK_STOP_DR;
       
      +#ifdef JTAG_BT
      +    psc->REG_064 |= PSC_AON_CODEC_RESERVED(1 << 3);
      +    psc->REG_064 &= ~PSC_AON_CODEC_RESERVED(1 << 2);
      +#endif
       }
       
       void BOOT_TEXT_FLASH_LOC hal_psc_bt_disable(void)
       {
      +#ifdef JTAG_BT
      +    psc->REG_064 &= ~PSC_AON_CODEC_RESERVED(1 << 3);
      +    psc->REG_064 |= PSC_AON_CODEC_RESERVED(1 << 2);
      +#endif
       
           psc->REG_038 = PSC_WRITE_ENABLE |
               PSC_AON_BT_PSW_EN_DR | PSC_AON_BT_PSW_EN_REG |
  • platform/hal/best2300p/Makefile

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/Makefile bes/platform/hal/best2300p/Makefile
      index 498ac0276ea..68478398fd4 100644
      --- a/platform/hal/best2300p/Makefile
      +++ b/platform/hal/best2300p/Makefile
      @@ -27,8 +27,31 @@ ifeq ($(USB_USE_USBPLL),1)
       CMU_CFG_FLAGS += -DUSB_USE_USBPLL
       endif
       
      +ifeq ($(USB_CLK_SRC_24M_X2),1)
      +CMU_CFG_FLAGS += -DUSB_CLK_SRC_24M_X2
      +else
      +ifeq ($(USB_CLK_SRC_48M),1)
      +CMU_CFG_FLAGS += -DUSB_CLK_SRC_48M
      +else
      +ifeq ($(USB_CLK_SRC_26M_X4),1)
      +CMU_CFG_FLAGS += -DUSB_CLK_SRC_26M_X4
      +else
      +ifeq ($(USB_CLK_SRC_26M_X2),1)
      +CMU_CFG_FLAGS += -DUSB_CLK_SRC_26M_X2
      +endif
      +endif
      +endif
      +endif
       
      +ifeq ($(RESAMPLE_CODEC_CLK_ANA),1)
      +CMU_CFG_FLAGS += -DRESAMPLE_CODEC_CLK_ANA
      +endif
       
      +ifeq ($(LOW_SYS_FREQ),1)
      +ifneq ($(FLASH_LOW_SPEED),1)
      +$(error FLASH_LOW_SPEED should be enabled along with LOW_SYS_FREQ)
      +endif
      +endif
       
       ifeq ($(DAC_CLASSG_ENABLE),1)
       CODEC_CFG_FLAGS += -DDAC_CLASSG_ENABLE
      @@ -40,6 +63,7 @@ endif
       
       ifeq ($(JTAG_BT),1)
       PSC_CFG_FLAGS += -DJTAG_BT
      +JTAG_TDI_TDO_PIN ?= 1
       endif
       
       ifeq ($(JTAG_TDI_TDO_PIN),1)
  • platform/hal/best2300p/plat_addr_map_best2300p.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/plat_addr_map_best2300p.h bes/platform/hal/best2300p/plat_addr_map_best2300p.h
      index ef4ca25946d..95c277b27c1 100644
      --- a/platform/hal/best2300p/plat_addr_map_best2300p.h
      +++ b/platform/hal/best2300p/plat_addr_map_best2300p.h
      @@ -19,172 +19,81 @@
       extern "C" {
       #endif
       
      -#define ROM_BASE                                0x00020000
      -#define ROMD_BASE                               0x24020000
      +#define ROM_BASE                                0x00000000
       
       #ifndef ROM_SIZE
      -#ifdef FPGA
      -#define ROM_SIZE                                0x00020000
      -#else
      -#define ROM_SIZE                                0x00010000
      +#define ROM_SIZE                                0x0000C000
       #endif
      +
      +#define RAMRET_BASE                             0x200D8000
      +#define RAMXRET_BASE                            0x002D8000
      +
      +#ifndef RAMRET_SIZE
      +#define RAMRET_SIZE                             0x00020000
       #endif
       
       #define RAM0_BASE                               0x20000000
       #define RAMX0_BASE                              0x00200000
      -#define RAM1_BASE                               0x20040000
      -#define RAMX1_BASE                              0x00240000
      -#define RAM2_BASE                               0x20080000
      -#define RAMX2_BASE                              0x00280000
      -#define RAM3_BASE                               0x20100000
      -#define RAMX3_BASE                              0x00300000
      -#define RAM4_BASE                               0x20180000
      -#define RAMX4_BASE                              0x00380000
      -#define RAM5_BASE                               0x201C0000
      -#define RAMX5_BASE                              0x003C0000
      +#define RAM1_BASE                               0x20020000
      +#define RAMX1_BASE                              0x00220000
      +#define RAM2_BASE                               0x20040000
      +#define RAMX2_BASE                              0x00240000
      +#define RAM3_BASE                               0x20060000
      +#define RAMX3_BASE                              0x00260000
      +#define RAM4_BASE                               0x20080000
      +#define RAMX4_BASE                              0x00280000
      +#define RAM5_BASE                               0x200A0000
      +#define RAMX5_BASE                              0x002A0000
      +#define RAM6_BASE                               0x200C0000
      +#define RAMX6_BASE                              0x002C0000
       #define RAM_BASE                                RAM0_BASE
       #define RAMX_BASE                               RAMX0_BASE
       
      -#define RAM5_SIZE                               0x00040000
      -
      -/* total ramv size is 0x30000 */
      -#define RAMV_BASE                               0x20200000
      -#ifndef RAMV_SIZE
      -#define RAMV_SIZE                               0x00000000
      -#endif
      -
      -#ifdef __BT_RAMRUN__
      -#define BT_RAMRUN_BASE                           RAM3_BASE
      -#define BT_RAMRUNX_BASE                          RAMX3_BASE
      -#endif
      -
      -#ifndef CP_FLASH_SIZE
      -#define CP_FLASH_SIZE 0
      -#endif
      -
       #ifdef CHIP_HAS_CP
      -#if (CP_FLASH_SIZE > 0)
      -#define CP_FLASH_BASE                           (FLASH_BASE + FLASH_SIZE - CP_FLASH_SIZE)
      -#define CP_FLASHX_BASE                          (FLASHX_BASE + FLASH_SIZE - CP_FLASH_SIZE)
      -#endif
      -
      -#ifdef LARGE_RAM
      -/*MCU use RAM0/1/2/3, CPX use RAM4, and CP use RAM5*/
      -#define RAMCP_TOP                               (RAM5_BASE + RAM5_SIZE)
      +#define RAMCP_TOP                               (RAMRET_BASE + RAMRET_SIZE - 0x20)
       
       #ifndef RAMCP_SIZE
      -#define RAMCP_SIZE                              RAM5_SIZE
      +#define RAMCP_SIZE                              (RAMRET_SIZE - 0x20)
       #endif
      -
      -#ifndef RAMCP_BASE
       #define RAMCP_BASE                              (RAMCP_TOP - RAMCP_SIZE)
      -#endif
       
       #ifndef RAMCPX_SIZE
      -#define RAMCPX_SIZE                             (RAM5_BASE - RAM4_BASE)
      +#define RAMCPX_SIZE                             (RAMXRET_BASE - RAMX6_BASE)
       #endif
      -
       #ifndef RAMCPX_BASE
       #define RAMCPX_BASE                             (RAM_TO_RAMX(RAMCP_BASE) - RAMCPX_SIZE)
       #endif
      -
      -#else /*LARGE_RAM*/
      -/*MCU use RAM0, CP and CPX use RAM1*/
      -#define RAMCP_TOP                               RAM2_BASE
      -
      -#ifndef RAMCP_SIZE
      -#define RAMCP_SIZE                              0x20000
      -#endif
      -
      -#ifndef RAMCP_BASE
      -#define RAMCP_BASE                              (RAMCP_TOP - RAMCP_SIZE)
      -#endif
      -
      -#ifndef RAMCPX_SIZE
      -#define RAMCPX_SIZE                             (RAMX2_BASE - RAMX1_BASE - RAMCP_SIZE)
      -#endif
      -
      -#ifndef RAMCPX_BASE
      -#define RAMCPX_BASE                             (RAM_TO_RAMX(RAMCP_BASE) - RAMCPX_SIZE)
      -#endif
      -
      -#endif /*LARGE_RAM*/
       #endif
       
      -#define RAM_TOTAL_SIZE                          (RAM5_BASE + RAM5_SIZE - RAM0_BASE) // 0x00200000
      -
      -#if defined(ARM_CMSE) || defined(ARM_CMNS)
      -#undef RAM_BASE
      -#undef RAMX_BASE
      -
      -/*MPC: SRAM block size: 0x8000, FLASH block size 0x40000*/
      -#ifndef RAM_S_SIZE
      -#define RAM_S_SIZE                              0x00020000
      -#endif
      -#define RAM_NSC_SIZE                            0
      -#ifndef FLASH_S_SIZE
      -#define FLASH_S_SIZE                            0x00040000
      -#endif
      -
      -#define RAM_NS_BASE                             (RAM0_BASE + RAM_S_SIZE)
      -#define RAMX_NS_BASE                            (RAMX0_BASE + RAM_S_SIZE)
      -
      -#if defined(ARM_CMNS)
      -#define RAM_BASE                                RAM_NS_BASE
      -#define RAMX_BASE                               RAMX_NS_BASE
      -#else
      -#if ((RAM_S_SIZE) & (0x8000-1))
      -#error "RAM_S_SIZE should be 0x8000 aligned"
      -#endif
      -#if (FLASH_S_SIZE & (0x40000-1))
      -#error "FLASH_S_SIZE should be 0x40000 aligned"
      -#endif
      -#define RAM_BASE                                RAM0_BASE
      -#define RAMX_BASE                               RAMX0_BASE
      -#define RAM_SIZE                                RAM_S_SIZE
      -#ifndef NS_APP_START_OFFSET
      -#define NS_APP_START_OFFSET                     (FLASH_S_SIZE)
      -#endif
      -#ifndef FLASH_REGION_SIZE
      -#define FLASH_REGION_SIZE                       FLASH_S_SIZE
      -#endif
      -#endif
      -#endif /* defined(ARM_CMSE) || defined(ARM_CMNS) */
      -
      -#ifndef RAM_MCU_SIZE
      -/* secure and non-secure ram size */
      -#ifdef LARGE_RAM
      +#ifndef RAM_SIZE
       #ifdef CHIP_HAS_CP
      -#define RAM_MCU_SIZE                            (RAMCPX_BASE - RAMX_BASE)
      +#define RAM_SIZE                                (RAMCPX_BASE - RAMX_BASE) // 0X000C0000
       #else
      -#define RAM_MCU_SIZE                            (RAM5_BASE + RAM5_SIZE - RAM_BASE)
      -#endif
      -#else
      -#ifdef CHIP_HAS_CP
      -#define RAM_MCU_SIZE                            (RAMCPX_BASE - RAMX_BASE)
      +#ifdef LARGE_RAM
      +#define RAM_SIZE                                (RAMRET_BASE + RAMRET_SIZE - RAM_BASE) // 0x000F8000
       #else
      -#define RAM_MCU_SIZE                            (RAM2_BASE - RAM_BASE) // 0x00080000
      -#endif
      -#endif
      -#endif /*RAM_MCU_SIZE*/
      -
      -#if defined(ARM_CMSE)
      -#ifndef RAM_NS_SIZE
      -#define RAM_NS_SIZE                             (RAM_BASE + RAM_MCU_SIZE - RAM_NS_BASE)
      -#endif /*RAM_NS_SIZE*/
      +#define RAM_SIZE                                (RAMRET_BASE - RAM_BASE) // 0x000D8000
       #endif
      +#endif /* !CHIP_HAS_CP */
      +#endif /* !RAM_SIZE */
       
      -#ifndef RAM_SIZE
      -#define RAM_SIZE                                RAM_MCU_SIZE
      +#if defined(ROM_BUILD) && defined(CORE_SLEEP_POWER_DOWN)
      +#undef RAM_BASE
      +#undef RAMX_BASE
      +#undef RAM_SIZE
      +#define RAM_BASE                                RAMRET_BASE
      +#define RAMX_BASE                               RAMXRET_BASE
      +#define RAM_SIZE                                RAMRET_SIZE
       #endif
       
      -#define FLASH_BASE                              0x2C000000
      -#define FLASH_NC_BASE                           0x28000000
      +#define FLASH_BASE                              0x3C000000
      +#define FLASH_NC_BASE                           0x38000000
       #define FLASHX_BASE                             0x0C000000
       #define FLASHX_NC_BASE                          0x08000000
       
      -#define DCACHE_CTRL_BASE                        0x27FFA000
      -#define ICACHE_CTRL_BASE                        0x27FFC000
      +#define ICACHE_CTRL_BASE                        0x07FFE000
      +#define ICACHECP_CTRL_BASE                      0x07FFA000
      +/* No data cache */
       
       #define CMU_BASE                                0x40000000
       #define MCU_WDT_BASE                            0x40001000
      @@ -203,42 +112,42 @@ extern "C" {
       #define BTPCM_BASE                              0x4000E000
       #define I2S0_BASE                               0x4000F000
       #define SPDIF0_BASE                             0x40010000
      -#define I2S1_BASE                               0x40017000
      +#define I2S1_BASE                               0x40011000
       #define SEC_ENG_BASE                            0x40020000
       
       #define AON_CMU_BASE                            0x40080000
       #define AON_GPIO_BASE                           0x40081000
       #define AON_WDT_BASE                            0x40082000
      -#define AON_PWM0_BASE                           0x40083000
      +#define AON_PWM_BASE                            0x40083000
       #define AON_TIMER_BASE                          0x40084000
      -#define AON_PSC_BASE                            0x40088000
      +#define AON_PSC_BASE                            0x40085000
       #define AON_IOMUX_BASE                          0x40086000
       
      -#define CHECKSUM_BASE                           0x40100000
      -#define CRC_BASE                                0x40108000
       #define SDMMC_BASE                              0x40110000
      -#define BES2003_AUDMA_BASE                      0x40120000
      -#define BES2003_GPDMA_BASE                      0x40130000
      +#define AUDMA_BASE                              0x40120000
      +#define GPDMA_BASE                              0x40130000
       #define FLASH_CTRL_BASE                         0x40140000
      -#define BTDUMP_BASE                             0x401E0000
      +#define BTDUMP_BASE                             0x40150000
       #define I2C_SLAVE_BASE                          0x40160000
      +#define SENSOR_ENG_BASE                         0x40170000
       #define USB_BASE                                0x40180000
       #define SEDMA_BASE                              0x401D0000
       
      -#define CODEC_BASE                              0x40380000
      +#define CODEC_BASE                              0x40300000
       
       #define BT_SUBSYS_BASE                          0xA0000000
       #define BT_RAM_BASE                             0xC0000000
       #define BT_RAM_SIZE                             0x00008000
      +#define BT_EXCH_MEM_BASE                        0xD0210000
      +#define BT_EXCH_MEM_SIZE                        0x00008000
       #define BT_UART_BASE                            0xD0300000
       #define BT_CMU_BASE                             0xD0330000
       
       #define IOMUX_BASE                              AON_IOMUX_BASE
       #define GPIO_BASE                               AON_GPIO_BASE
      -#define PWM_BASE                                AON_PWM0_BASE
      -
      -#ifdef CHIP_BEST2003_DSP
      -#define TIMER0_BASE                             DSP_TIMER0_BASE
      +#define PWM_BASE                                AON_PWM_BASE
      +#ifdef CORE_SLEEP_POWER_DOWN
      +#define TIMER0_BASE                             AON_TIMER_BASE
       #else
       #define TIMER0_BASE                             MCU_TIMER0_BASE
       #endif
      @@ -247,14 +156,15 @@ extern "C" {
       
       /* For linker scripts */
       
      -#define VECTOR_SECTION_SIZE                     360
      +#define VECTOR_SECTION_SIZE                     320
       #define REBOOT_PARAM_SECTION_SIZE               64
       #define ROM_BUILD_INFO_SECTION_SIZE             40
       #define ROM_EXPORT_FN_SECTION_SIZE              128
      +#define BT_INTESYS_MEM_OFFSET                   0x00000000
       
       /* For boot struct version */
       #ifndef SECURE_BOOT_VER
      -#define SECURE_BOOT_VER                         4
      +#define SECURE_BOOT_VER                         2
       #endif
       
       #ifdef __cplusplus
  • platform/hal/best2300p/reg_aoncmu_best2300p.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/reg_aoncmu_best2300p.h bes/platform/hal/best2300p/reg_aoncmu_best2300p.h
      index 5018183c962..ba7e71e4f31 100644
      --- a/platform/hal/best2300p/reg_aoncmu_best2300p.h
      +++ b/platform/hal/best2300p/reg_aoncmu_best2300p.h
      @@ -30,7 +30,7 @@ struct AONCMU_T {
           __IO uint32_t MEMSC[4];         // 0x24
           __I  uint32_t MEMSC_STATUS;     // 0x34
           __IO uint32_t BOOTMODE;         // 0x38
      -    __IO uint32_t FLS_PSR_CLK;      // 0x3C
      +    __IO uint32_t RESERVED_03C;     // 0x3C
           __IO uint32_t MOD_CLK_ENABLE;   // 0x40
           __IO uint32_t MOD_CLK_DISABLE;  // 0x44
           __IO uint32_t MOD_CLK_MODE;     // 0x48
      @@ -38,7 +38,7 @@ struct AONCMU_T {
           __IO uint32_t TIMER_CLK;        // 0x50
           __IO uint32_t PWM01_CLK;        // 0x54
           __IO uint32_t PWM23_CLK;        // 0x58
      -    __IO uint32_t LNA_CFG;          // 0x5C
      +    __IO uint32_t RAM_CFG;          // 0x5C
           __IO uint32_t RESERVED_060;     // 0x60
           __IO uint32_t PCM_I2S_CLK;      // 0x64
           __IO uint32_t SPDIF_CLK;        // 0x68
      @@ -49,7 +49,7 @@ struct AONCMU_T {
           __IO uint32_t SE_WLOCK;         // 0x7C
           __IO uint32_t SE_RLOCK;         // 0x80
           __IO uint32_t PD_STAB_TIMER;    // 0x84
      -    __IO uint32_t TIMER_WDT;        // 0x88
      +         uint32_t RESERVED_088[0x1A]; // 0x88
           __IO uint32_t WAKEUP_PC;        // 0xF0
           __IO uint32_t DEBUG_RES[2];     // 0xF4
           __IO uint32_t CHIP_FEATURE;     // 0xFC
      @@ -64,65 +64,75 @@ struct AONCMU_T {
       #define AON_CMU_REVISION_ID_SHIFT               (16)
       
       // reg_04
      -#define AON_CMU_EN_CLK_TOP_OSC_ENABLE           (1 << 0)
      -#define AON_CMU_EN_CLK_TOP_OSCX2_ENABLE         (1 << 1)
      -#define AON_CMU_EN_CLK_TOP_OSCX4_ENABLE         (1 << 2)
      -#define AON_CMU_EN_CLK_TOP_PLLBB_ENABLE         (1 << 3)
      -#define AON_CMU_EN_CLK_TOP_PLLA7_ENABLE         (1 << 4)
      -#define AON_CMU_EN_CLK_TOP_PLLDDR_ENABLE        (1 << 5)
      +#define AON_CMU_EN_CLK_TOP_PLLBB_ENABLE         (1 << 0)
      +#define AON_CMU_EN_CLK_TOP_PLLAUD_ENABLE        (1 << 1)
      +#define AON_CMU_EN_CLK_TOP_OSCX2_ENABLE         (1 << 2)
      +#define AON_CMU_EN_CLK_TOP_OSC_ENABLE           (1 << 3)
      +#define AON_CMU_EN_CLK_TOP_JTAG_ENABLE          (1 << 4)
      +#define AON_CMU_EN_CLK_TOP_PLLBB2_ENABLE        (1 << 5)
       #define AON_CMU_EN_CLK_TOP_PLLUSB_ENABLE        (1 << 6)
      -#define AON_CMU_EN_CLK_TOP_PLLBB_PS_ENABLE      (1 << 7)
      -#define AON_CMU_EN_CLK_TOP_PLLBB_WF_ENABLE      (1 << 8)
      -#define AON_CMU_EN_CLK_TOP_PHY_PS_ENABLE        (1 << 9)
      -#define AON_CMU_EN_CLK_TOP_JTAG_ENABLE          (1 << 10)
      -#define AON_CMU_EN_CLK_USB_PLL_ENABLE           (1 << 11)
      -#define AON_CMU_EN_CLK_BT_ENABLE                (1 << 12)
      -#define AON_CMU_EN_CLK_WF_ENABLE                (1 << 13)
      -#define AON_CMU_EN_CLK_CODEC_ENABLE             (1 << 14)
      -#define AON_CMU_EN_CLK_CODECIIR_ENABLE          (1 << 15)
      -#define AON_CMU_EN_CLK_CODECRS0_ENABLE          (1 << 16)
      -#define AON_CMU_EN_CLK_CODECRS1_ENABLE          (1 << 17)
      -#define AON_CMU_EN_CLK_CODECHCLK_ENABLE         (1 << 18)
      -#define AON_CMU_EN_CLK_VAD32K_ENABLE            (1 << 19)
      -#define AON_CMU_EN_CLK_MCU_32K_ENABLE           (1 << 20)
      -#define AON_CMU_EN_CLK_MCU_OSC_ENABLE           (1 << 21)
      -#define AON_CMU_EN_CLK_MCU_OSCX2_ENABLE         (1 << 22)
      -#define AON_CMU_EN_X2_DIG_ENABLE                (1 << 23)
      -#define AON_CMU_EN_X4_DIG_ENABLE                (1 << 24)
      -#define AON_CMU_EN_BT_CLK_SYS_ENABLE            (1 << 25)
      -#define AON_CMU_EN_CLK_PSRAMX2_ENABLE           (1 << 26)
      +#define AON_CMU_EN_CLK_PLL_CODEC_ENABLE         (1 << 7)
      +#define AON_CMU_EN_CLK_CODEC_HCLK_ENABLE        (1 << 8)
      +#define AON_CMU_EN_CLK_CODEC_RS_ENABLE          (1 << 9)
      +#define AON_CMU_EN_CLK_CODEC_ENABLE             (1 << 10)
      +#define AON_CMU_EN_CLK_CODEC_IIR_ENABLE         (1 << 11)
      +#define AON_CMU_EN_CLK_OSCX2_MCU_ENABLE         (1 << 12)
      +#define AON_CMU_EN_CLK_OSC_MCU_ENABLE           (1 << 13)
      +#define AON_CMU_EN_CLK_32K_MCU_ENABLE           (1 << 14)
      +#define AON_CMU_EN_CLK_PLL_BT_ENABLE            (1 << 15)
      +#define AON_CMU_EN_CLK_60M_BT_ENABLE            (1 << 16)
      +#define AON_CMU_EN_CLK_OSCX2_BT_ENABLE          (1 << 17)
      +#define AON_CMU_EN_CLK_OSC_BT_ENABLE            (1 << 18)
      +#define AON_CMU_EN_CLK_32K_BT_ENABLE            (1 << 19)
      +#define AON_CMU_EN_CLK_PLL_PER_ENABLE           (1 << 20)
      +#define AON_CMU_EN_CLK_DCDC0_ENABLE             (1 << 21)
      +#define AON_CMU_EN_CLK_DCDC1_ENABLE             (1 << 22)
      +#define AON_CMU_EN_CLK_DCDC2_ENABLE             (1 << 23)
      +#define AON_CMU_EN_X2_DIG_ENABLE                (1 << 24)
      +#define AON_CMU_EN_X4_DIG_ENABLE                (1 << 25)
      +#define AON_CMU_PU_PLLBB_ENABLE                 (1 << 26)
      +#define AON_CMU_PU_PLLUSB_ENABLE                (1 << 27)
      +#define AON_CMU_PU_PLLAUD_ENABLE                (1 << 28)
      +#define AON_CMU_PU_OSC_ENABLE                   (1 << 29)
      +#define AON_CMU_EN_X4_ANA_ENABLE                (1 << 30)
      +#define AON_CMU_EN_CLK_32K_CODEC_ENABLE         (1 << 31)
       
       // reg_08
      -#define AON_CMU_EN_CLK_TOP_OSC_DISABLE          (1 << 0)
      -#define AON_CMU_EN_CLK_TOP_OSCX2_DISABLE        (1 << 1)
      -#define AON_CMU_EN_CLK_TOP_OSCX4_DISABLE        (1 << 2)
      -#define AON_CMU_EN_CLK_TOP_PLLBB_DISABLE        (1 << 3)
      -#define AON_CMU_EN_CLK_TOP_PLLA7_DISABLE        (1 << 4)
      -#define AON_CMU_EN_CLK_TOP_PLLDDR_DISABLE       (1 << 5)
      +#define AON_CMU_EN_CLK_TOP_PLLBB_DISABLE        (1 << 0)
      +#define AON_CMU_EN_CLK_TOP_PLLAUD_DISABLE       (1 << 1)
      +#define AON_CMU_EN_CLK_TOP_OSCX2_DISABLE        (1 << 2)
      +#define AON_CMU_EN_CLK_TOP_OSC_DISABLE          (1 << 3)
      +#define AON_CMU_EN_CLK_TOP_JTAG_DISABLE         (1 << 4)
      +#define AON_CMU_EN_CLK_TOP_PLLBB2_DISABLE       (1 << 5)
       #define AON_CMU_EN_CLK_TOP_PLLUSB_DISABLE       (1 << 6)
      -#define AON_CMU_EN_CLK_TOP_PLLBB_PS_DISABLE     (1 << 7)
      -#define AON_CMU_EN_CLK_TOP_PLLBB_WF_DISABLE     (1 << 8)
      -#define AON_CMU_EN_CLK_TOP_PHY_PS_DISABLE       (1 << 9)
      -#define AON_CMU_EN_CLK_TOP_JTAG_DISABLE         (1 << 10)
      -#define AON_CMU_EN_CLK_USB_PLL_DISABLE          (1 << 11)
      -#define AON_CMU_EN_CLK_BT_DISABLE               (1 << 12)
      -#define AON_CMU_EN_CLK_WF_DISABLE               (1 << 13)
      -#define AON_CMU_EN_CLK_CODEC_DISABLE            (1 << 14)
      -#define AON_CMU_EN_CLK_CODECIIR_DISABLE         (1 << 15)
      -#define AON_CMU_EN_CLK_CODECRS0_DISABLE         (1 << 16)
      -#define AON_CMU_EN_CLK_CODECRS1_DISABLE         (1 << 17)
      -#define AON_CMU_EN_CLK_CODECHCLK_DISABLE        (1 << 18)
      -#define AON_CMU_EN_CLK_VAD32K_DISABLE           (1 << 19)
      -#define AON_CMU_EN_CLK_MCU_32K_DISABLE          (1 << 20)
      -#define AON_CMU_EN_CLK_MCU_OSC_DISABLE          (1 << 21)
      -#define AON_CMU_EN_CLK_MCU_OSCX2_DISABLE        (1 << 22)
      -#define AON_CMU_EN_X2_DIG_DISABLE               (1 << 23)
      -#define AON_CMU_EN_X4_DIG_DISABLE               (1 << 24)
      -#define AON_CMU_EN_BT_CLK_SYS_DISABLE           (1 << 25)
      -#define AON_CMU_EN_CLK_PSRAMX2_DISABLE          (1 << 26)
      -
      -#define AON_ARST_NUM                            13
      -#define AON_ORST_NUM                            18
      +#define AON_CMU_EN_CLK_PLL_CODEC_DISABLE        (1 << 7)
      +#define AON_CMU_EN_CLK_CODEC_HCLK_DISABLE       (1 << 8)
      +#define AON_CMU_EN_CLK_CODEC_RS_DISABLE         (1 << 9)
      +#define AON_CMU_EN_CLK_CODEC_DISABLE            (1 << 10)
      +#define AON_CMU_EN_CLK_CODEC_IIR_DISABLE        (1 << 11)
      +#define AON_CMU_EN_CLK_OSCX2_MCU_DISABLE        (1 << 12)
      +#define AON_CMU_EN_CLK_OSC_MCU_DISABLE          (1 << 13)
      +#define AON_CMU_EN_CLK_32K_MCU_DISABLE          (1 << 14)
      +#define AON_CMU_EN_CLK_PLL_BT_DISABLE           (1 << 15)
      +#define AON_CMU_EN_CLK_60M_BT_DISABLE           (1 << 16)
      +#define AON_CMU_EN_CLK_OSCX2_BT_DISABLE         (1 << 17)
      +#define AON_CMU_EN_CLK_OSC_BT_DISABLE           (1 << 18)
      +#define AON_CMU_EN_CLK_32K_BT_DISABLE           (1 << 19)
      +#define AON_CMU_EN_CLK_PLL_PER_DISABLE          (1 << 20)
      +#define AON_CMU_EN_CLK_DCDC0_DISABLE            (1 << 21)
      +#define AON_CMU_EN_CLK_DCDC1_DISABLE            (1 << 22)
      +#define AON_CMU_EN_CLK_DCDC2_DISABLE            (1 << 23)
      +#define AON_CMU_EN_X2_DIG_DISABLE               (1 << 24)
      +#define AON_CMU_EN_X4_DIG_DISABLE               (1 << 25)
      +#define AON_CMU_PU_PLLBB_DISABLE                (1 << 26)
      +#define AON_CMU_PU_PLLUSB_DISABLE               (1 << 27)
      +#define AON_CMU_PU_PLLAUD_DISABLE               (1 << 28)
      +#define AON_CMU_PU_OSC_DISABLE                  (1 << 29)
      +#define AON_CMU_EN_X4_ANA_DISABLE               (1 << 30)
      +#define AON_CMU_EN_CLK_32K_CODEC_DISABLE        (1 << 31)
      +
      +#define AON_ARST_NUM                            10
      +#define AON_ORST_NUM                            10
       #define AON_ACLK_NUM                            AON_ARST_NUM
       #define AON_OCLK_NUM                            AON_ORST_NUM
       
      @@ -133,6 +143,14 @@ struct AONCMU_T {
       #define AON_CMU_ORESETN_PULSE(n)                (((n) & 0xFFFFFFFF) << AON_ARST_NUM)
       #define AON_CMU_ORESETN_PULSE_MASK              (0xFFFFFFFF << AON_ARST_NUM)
       #define AON_CMU_ORESETN_PULSE_SHIFT             (AON_ARST_NUM)
      +#define AON_CMU_SOFT_RSTN_MCU_PULSE             (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1-1))
      +#define AON_CMU_SOFT_RSTN_CODEC_PULSE           (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1-1))
      +#define AON_CMU_SOFT_RSTN_WF_PULSE              (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_BT_PULSE              (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_MCUCPU_PULSE          (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_WFCPU_PULSE           (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_BTCPU_PULSE           (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1+1+1-1))
      +#define AON_CMU_GLOBAL_RESETN_PULSE             (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1+1+1+1-1))
       
       // reg_10
       #define AON_CMU_ARESETN_SET(n)                  (((n) & 0xFFFFFFFF) << 0)
      @@ -141,6 +159,14 @@ struct AONCMU_T {
       #define AON_CMU_ORESETN_SET(n)                  (((n) & 0xFFFFFFFF) << AON_ARST_NUM)
       #define AON_CMU_ORESETN_SET_MASK                (0xFFFFFFFF << AON_ARST_NUM)
       #define AON_CMU_ORESETN_SET_SHIFT               (AON_ARST_NUM)
      +#define AON_CMU_SOFT_RSTN_MCU_SET               (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1-1))
      +#define AON_CMU_SOFT_RSTN_CODEC_SET             (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1-1))
      +#define AON_CMU_SOFT_RSTN_WF_SET                (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_BT_SET                (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_MCUCPU_SET            (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_WFCPU_SET             (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_BTCPU_SET             (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1+1+1-1))
      +#define AON_CMU_GLOBAL_RESETN_SET               (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1+1+1+1-1))
       
       // reg_14
       #define AON_CMU_ARESETN_CLR(n)                  (((n) & 0xFFFFFFFF) << 0)
      @@ -149,57 +175,70 @@ struct AONCMU_T {
       #define AON_CMU_ORESETN_CLR(n)                  (((n) & 0xFFFFFFFF) << AON_ARST_NUM)
       #define AON_CMU_ORESETN_CLR_MASK                (0xFFFFFFFF << AON_ARST_NUM)
       #define AON_CMU_ORESETN_CLR_SHIFT               (AON_ARST_NUM)
      +#define AON_CMU_SOFT_RSTN_MCU_CLR               (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1-1))
      +#define AON_CMU_SOFT_RSTN_CODEC_CLR             (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1-1))
      +#define AON_CMU_SOFT_RSTN_WF_CLR                (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_BT_CLR                (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_MCUCPU_CLR            (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_WFCPU_CLR             (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1+1-1))
      +#define AON_CMU_SOFT_RSTN_BTCPU_CLR             (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1+1+1-1))
      +#define AON_CMU_GLOBAL_RESETN_CLR               (1 << (AON_ARST_NUM+AON_ORST_NUM+32-8-AON_ARST_NUM-AON_ORST_NUM+1+1+1+1+1+1+1+1-1))
       
       // reg_18
       #define AON_CMU_BYPASS_DIV_BTSYS                (1 << 0)
       #define AON_CMU_CFG_DIV_BTSYS(n)                (((n) & 0x3) << 1)
       #define AON_CMU_CFG_DIV_BTSYS_MASK              (0x3 << 1)
       #define AON_CMU_CFG_DIV_BTSYS_SHIFT             (1)
      -#define AON_CMU_SEL_BT_PLL                      (1 << 3)
      -#define AON_CMU_EN_BT_2M                        (1 << 4)
      -#define AON_CMU_SEL_USB_PLLUSB                  (1 << 5)
      -#define AON_CMU_CFG_DIV_USB(n)                  (((n) & 0x7) << 6)
      -#define AON_CMU_CFG_DIV_USB_MASK                (0x7 << 6)
      -#define AON_CMU_CFG_DIV_USB_SHIFT               (6)
      -#define AON_CMU_SEL_USB_OSCX2                   (1 << 9)
      -#define AON_CMU_CFG_DIV_PER(n)                  (((n) & 0x3) << 10)
      -#define AON_CMU_CFG_DIV_PER_MASK                (0x3 << 10)
      -#define AON_CMU_CFG_DIV_PER_SHIFT               (10)
      -#define AON_CMU_BYPASS_DIV_PER                  (1 << 12)
      -#define AON_CMU_RSTN_DIV_PER                    (1 << 13)
      -#define AON_CMU_SEL_OSCX2_DIG                   (1 << 14)
      -#define AON_CMU_SEL_X2_PHASE(n)                 (((n) & 0x1F) << 15)
      -#define AON_CMU_SEL_X2_PHASE_MASK               (0x1F << 15)
      -#define AON_CMU_SEL_X2_PHASE_SHIFT              (15)
      -#define AON_CMU_SEL_OSCX4_DIG                   (1 << 20)
      -#define AON_CMU_SEL_X4_PHASE(n)                 (((n) & 0x1F) << 21)
      -#define AON_CMU_SEL_X4_PHASE_MASK               (0x1F << 21)
      -#define AON_CMU_SEL_X4_PHASE_SHIFT              (21)
      -#define AON_CMU_PU_MCU_PLLBB_MASK               (1 << 26)
      -#define AON_CMU_PU_MCU_PLLUSB_MASK              (1 << 27)
      -#define AON_CMU_PU_MCU_PLLA7_MASK               (1 << 28)
      -#define AON_CMU_PU_MCU_PLLDSI_MASK              (1 << 29)
      +#define AON_CMU_CFG_DIV_BT60M(n)                (((n) & 0x3) << 3)
      +#define AON_CMU_CFG_DIV_BT60M_MASK              (0x3 << 3)
      +#define AON_CMU_CFG_DIV_BT60M_SHIFT             (3)
      +#define AON_CMU_SEL_PLL_SYS(n)                  (((n) & 0x3) << 5)
      +#define AON_CMU_SEL_PLL_SYS_MASK                (0x3 << 5)
      +#define AON_CMU_SEL_PLL_SYS_SHIFT               (5)
      +#define AON_CMU_SEL_PLL_AUD(n)                  (((n) & 0x3) << 7)
      +#define AON_CMU_SEL_PLL_AUD_MASK                (0x3 << 7)
      +#define AON_CMU_SEL_PLL_AUD_SHIFT               (7)
      +#define AON_CMU_SEL_OSCX2_DIG                   (1 << 9)
      +#define AON_CMU_SEL_X2_PHASE(n)                 (((n) & 0x1F) << 10)
      +#define AON_CMU_SEL_X2_PHASE_MASK               (0x1F << 10)
      +#define AON_CMU_SEL_X2_PHASE_SHIFT              (10)
      +#define AON_CMU_SEL_X4_SYS                      (1 << 15)
      +#define AON_CMU_SEL_X4_AUD                      (1 << 16)
      +#define AON_CMU_SEL_X4_USB                      (1 << 17)
      +#define AON_CMU_SEL_X4_PHASE(n)                 (((n) & 0x1F) << 18)
      +#define AON_CMU_SEL_X4_PHASE_MASK               (0x1F << 18)
      +#define AON_CMU_SEL_X4_PHASE_SHIFT              (18)
      +#define AON_CMU_SEL_X4_DIG                      (1 << 23)
      +#define AON_CMU_CFG_DIV_PER(n)                  (((n) & 0x3) << 24)
      +#define AON_CMU_CFG_DIV_PER_MASK                (0x3 << 24)
      +#define AON_CMU_CFG_DIV_PER_SHIFT               (24)
      +#define AON_CMU_BYPASS_DIV_PER                  (1 << 26)
      +#define AON_CMU_SEL_32K_TIMER                   (1 << 27)
      +#define AON_CMU_SEL_32K_WDT                     (1 << 28)
      +#define AON_CMU_SEL_TIMER_FAST                  (1 << 29)
      +#define AON_CMU_LPU_AUTO_SWITCH26               (1 << 30)
      +#define AON_CMU_EN_MCU_WDG_RESET                (1 << 31)
       
       // reg_1c
       #define AON_CMU_EN_CLK_OUT                      (1 << 0)
      -#define AON_CMU_SEL_CLK_OUT(n)                  (((n) & 0x7) << 1)
      -#define AON_CMU_SEL_CLK_OUT_MASK                (0x7 << 1)
      +#define AON_CMU_SEL_CLK_OUT(n)                  (((n) & 0x3) << 1)
      +#define AON_CMU_SEL_CLK_OUT_MASK                (0x3 << 1)
       #define AON_CMU_SEL_CLK_OUT_SHIFT               (1)
      -#define AON_CMU_CFG_CLK_OUT(n)                  (((n) & 0x1F) << 4)
      -#define AON_CMU_CFG_CLK_OUT_MASK                (0x1F << 4)
      -#define AON_CMU_CFG_CLK_OUT_SHIFT               (4)
      -#define AON_CMU_CFG_DIV_DCDC(n)                 (((n) & 0xF) << 9)
      -#define AON_CMU_CFG_DIV_DCDC_MASK               (0xF << 9)
      -#define AON_CMU_CFG_DIV_DCDC_SHIFT              (9)
      -#define AON_CMU_BYPASS_DIV_DCDC                 (1 << 13)
      -#define AON_CMU_SEL_DCDC_OSC                    (1 << 14)
      -#define AON_CMU_SEL_DCDC_PLL                    (1 << 15)
      -#define AON_CMU_CLK_DCDC_DRV(n)                 (((n) & 0x3) << 16)
      -#define AON_CMU_CLK_DCDC_DRV_MASK               (0x3 << 16)
      -#define AON_CMU_CLK_DCDC_DRV_SHIFT              (16)
      -#define AON_CMU_SEL_DCDC_PHASE0(n)              (((n) & 0x1F) << 18)
      -#define AON_CMU_SEL_DCDC_PHASE0_MASK            (0x1F << 18)
      -#define AON_CMU_SEL_DCDC_PHASE0_SHIFT           (18)
      +#define AON_CMU_CFG_CLK_OUT(n)                  (((n) & 0xF) << 3)
      +#define AON_CMU_CFG_CLK_OUT_MASK                (0xF << 3)
      +#define AON_CMU_CFG_CLK_OUT_SHIFT               (3)
      +#define AON_CMU_CFG_DIV_DCDC(n)                 (((n) & 0xF) << 7)
      +#define AON_CMU_CFG_DIV_DCDC_MASK               (0xF << 7)
      +#define AON_CMU_CFG_DIV_DCDC_SHIFT              (7)
      +#define AON_CMU_BYPASS_DIV_DCDC                 (1 << 11)
      +#define AON_CMU_SEL_DCDC_PLL                    (1 << 12)
      +#define AON_CMU_SEL_DCDC_OSCX2                  (1 << 13)
      +#define AON_CMU_CLK_DCDC_DRV(n)                 (((n) & 0x3) << 14)
      +#define AON_CMU_CLK_DCDC_DRV_MASK               (0x3 << 14)
      +#define AON_CMU_CLK_DCDC_DRV_SHIFT              (14)
      +#define AON_CMU_EN_VOD_IIR                      (1 << 16)
      +#define AON_CMU_EN_VOD_RS                       (1 << 17)
      +#define AON_CMU_SEL_X4_FLS                      (1 << 18)
       
       // reg_20
       #define AON_CMU_WRITE_UNLOCK_H                  (1 << 0)
      @@ -233,10 +272,10 @@ struct AONCMU_T {
       #define AON_CMU_SOFT_BOOT_MODE_SHIFT            (4)
       
       // reg_3c
      -#define AON_CMU_SEL_MCU_PLLBB_PS                (1 << 0)
      -#define AON_CMU_SEL_MCU_PLLUSB                  (1 << 1)
      -#define AON_CMU_SEL_MCU_PLLA7USB                (1 << 2)
      -#define AON_CMU_RSTN_DIV_FLS                    (1 << 3)
      +#define AON_CMU_RESERVED(n)                     (((n) & 0xFFFFFFFF) << 0)
      +#define AON_CMU_RESERVED_MASK                   (0xFFFFFFFF << 0)
      +#define AON_CMU_RESERVED_SHIFT                  (0)
      +#define AON_CMU_OSC_TO_DIG_X4                   (1 << 1)
       
       // reg_40
       #define AON_CMU_MANUAL_ACLK_ENABLE(n)           (((n) & 0xFFFFFFFF) << 0)
      @@ -263,30 +302,29 @@ struct AONCMU_T {
       #define AON_CMU_MODE_OCLK_SHIFT                 (AON_ACLK_NUM)
       
       // reg_4c
      -#define AON_CMU_SEL_AON_OSC                     (1 << 0)
      -#define AON_CMU_SEL_AON_OSCX2                   (1 << 1)
      -#define AON_CMU_SEL_AON_SPI_OSCX2               (1 << 2)
      -#define AON_CMU_SEL_CODEC_ANA_2                 (1 << 3)
      -#define AON_CMU_SEL_CODEC_OSC_2                 (1 << 4)
      -#define AON_CMU_SEL_CODEC_OSC                   (1 << 5)
      -#define AON_CMU_SEL_CODECHCLK_OSCX2             (1 << 6)
      -#define AON_CMU_SEL_CODECHCLK_PLL               (1 << 7)
      -#define AON_CMU_SEL_CODECHCLK_MCU               (1 << 8)
      -#define AON_CMU_EN_I2S_MCLK                     (1 << 9)
      -#define AON_CMU_SEL_I2S_MCLK(n)                 (((n) & 0xF) << 10)
      -#define AON_CMU_SEL_I2S_MCLK_MASK               (0xF << 10)
      -#define AON_CMU_SEL_I2S_MCLK_SHIFT              (10)
      +#define AON_CMU_SEL_CLK_OSC                     (1 << 0)
      +#define AON_CMU_SEL_CLK_OSCX2                   (1 << 1)
      +#define AON_CMU_CFG_DIV_CODEC(n)                (((n) & 0x1F) << 2)
      +#define AON_CMU_CFG_DIV_CODEC_MASK              (0x1F << 2)
      +#define AON_CMU_CFG_DIV_CODEC_SHIFT             (2)
      +#define AON_CMU_SEL_OSC_CODEC                   (1 << 7)
      +#define AON_CMU_SEL_OSCX2_CODECHCLK             (1 << 8)
      +#define AON_CMU_SEL_PLL_CODECHCLK               (1 << 9)
      +#define AON_CMU_SEL_CODEC_HCLK_AON              (1 << 10)
      +#define AON_CMU_BYPASS_LOCK_PLLUSB              (1 << 11)
      +#define AON_CMU_BYPASS_LOCK_PLLBB               (1 << 12)
      +#define AON_CMU_BYPASS_LOCK_PLLAUD              (1 << 13)
       #define AON_CMU_POL_SPI_CS(n)                   (((n) & 0x7) << 14)
       #define AON_CMU_POL_SPI_CS_MASK                 (0x7 << 14)
       #define AON_CMU_POL_SPI_CS_SHIFT                (14)
       #define AON_CMU_CFG_SPI_ARB(n)                  (((n) & 0x7) << 17)
       #define AON_CMU_CFG_SPI_ARB_MASK                (0x7 << 17)
       #define AON_CMU_CFG_SPI_ARB_SHIFT               (17)
      -#define AON_CMU_PU_FLASH0_IO                     (1 << 20)
      -#define AON_CMU_EN_VAD_IIR                      (1 << 21)
      -#define AON_CMU_EN_VAD_RS                       (1 << 22)
      -#define AON_CMU_EN_MCU_PLLBB_MASK               (1 << 23)
      -#define AON_CMU_EN_MCU_PLLUSB_MASK              (1 << 24)
      +#define AON_CMU_PU_FLASH_IO                     (1 << 20)
      +#define AON_CMU_POR_SLEEP_MODE                  (1 << 21)
      +#define AON_CMU_LOCK_PLLBB                      (1 << 22)
      +#define AON_CMU_LOCK_PLLUSB                     (1 << 23)
      +#define AON_CMU_LOCK_PLLAUD                     (1 << 24)
       
       // reg_50
       #define AON_CMU_CFG_DIV_TIMER0(n)               (((n) & 0xFFFF) << 0)
      @@ -300,57 +338,70 @@ struct AONCMU_T {
       #define AON_CMU_CFG_DIV_PWM0(n)                 (((n) & 0xFFF) << 0)
       #define AON_CMU_CFG_DIV_PWM0_MASK               (0xFFF << 0)
       #define AON_CMU_CFG_DIV_PWM0_SHIFT              (0)
      -#define AON_CMU_SEL_PWM0_OSC                    (1 << 12)
      -#define AON_CMU_EN_CLK_PWM0_OSC                 (1 << 13)
      +#define AON_CMU_SEL_OSC_PWM0                    (1 << 12)
      +#define AON_CMU_EN_OSC_PWM0                     (1 << 13)
       #define AON_CMU_CFG_DIV_PWM1(n)                 (((n) & 0xFFF) << 16)
       #define AON_CMU_CFG_DIV_PWM1_MASK               (0xFFF << 16)
       #define AON_CMU_CFG_DIV_PWM1_SHIFT              (16)
      -#define AON_CMU_SEL_PWM1_OSC                    (1 << 28)
      -#define AON_CMU_EN_CLK_PWM1_OSC                 (1 << 29)
      +#define AON_CMU_SEL_OSC_PWM1                    (1 << 28)
      +#define AON_CMU_EN_OSC_PWM1                     (1 << 29)
       
       // reg_58
       #define AON_CMU_CFG_DIV_PWM2(n)                 (((n) & 0xFFF) << 0)
       #define AON_CMU_CFG_DIV_PWM2_MASK               (0xFFF << 0)
       #define AON_CMU_CFG_DIV_PWM2_SHIFT              (0)
      -#define AON_CMU_SEL_PWM2_OSC                    (1 << 12)
      -#define AON_CMU_EN_CLK_PWM2_OSC                 (1 << 13)
      +#define AON_CMU_SEL_OSC_PWM2                    (1 << 12)
      +#define AON_CMU_EN_OSC_PWM2                     (1 << 13)
       #define AON_CMU_CFG_DIV_PWM3(n)                 (((n) & 0xFFF) << 16)
       #define AON_CMU_CFG_DIV_PWM3_MASK               (0xFFF << 16)
       #define AON_CMU_CFG_DIV_PWM3_SHIFT              (16)
      -#define AON_CMU_SEL_PWM3_OSC                    (1 << 28)
      -#define AON_CMU_EN_CLK_PWM3_OSC                 (1 << 29)
      +#define AON_CMU_SEL_OSC_PWM3                    (1 << 28)
      +#define AON_CMU_EN_OSC_PWM3                     (1 << 29)
       
       // reg_5c
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP0(n)        (((n) & 0x7) << 0)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP0_MASK      (0x7 << 0)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP0_SHIFT     (0)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP1(n)        (((n) & 0x7) << 3)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP1_MASK      (0x7 << 3)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP1_SHIFT     (3)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP2(n)        (((n) & 0x7) << 6)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP2_MASK      (0x7 << 6)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP2_SHIFT     (6)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP3(n)        (((n) & 0x7) << 9)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP3_MASK      (0x7 << 9)
      -#define AON_CMU_EXT_LNA_AT_GAIN_STEP3_SHIFT     (9)
      -#define AON_CMU_EXT_LNA_ENABLE                  (1 << 12)
      -#define AON_CMU_EXT_LNA_ENABLE_DR               (1 << 13)
      -#define AON_CMU_EXT_LNA_EN_BYPASS_RXON          (1 << 14)
      -#define AON_CMU_FEM_SWTCH_WF_MUX_CFG(n)         (((n) & 0x3) << 15)
      -#define AON_CMU_FEM_SWTCH_WF_MUX_CFG_MASK       (0x3 << 15)
      -#define AON_CMU_FEM_SWTCH_WF_MUX_CFG_SHIFT      (15)
      +#define AON_CMU_RAM_EMA(n)                      (((n) & 0x7) << 0)
      +#define AON_CMU_RAM_EMA_MASK                    (0x7 << 0)
      +#define AON_CMU_RAM_EMA_SHIFT                   (0)
      +#define AON_CMU_RAM_EMAW(n)                     (((n) & 0x3) << 3)
      +#define AON_CMU_RAM_EMAW_MASK                   (0x3 << 3)
      +#define AON_CMU_RAM_EMAW_SHIFT                  (3)
      +#define AON_CMU_RAM_WABL                        (1 << 5)
      +#define AON_CMU_RAM_WABLM(n)                    (((n) & 0x3) << 6)
      +#define AON_CMU_RAM_WABLM_MASK                  (0x3 << 6)
      +#define AON_CMU_RAM_WABLM_SHIFT                 (6)
      +#define AON_CMU_RAM_RET1N0(n)                   (((n) & 0x7) << 8)
      +#define AON_CMU_RAM_RET1N0_MASK                 (0x7 << 8)
      +#define AON_CMU_RAM_RET1N0_SHIFT                (8)
      +#define AON_CMU_RAM_RET2N0(n)                   (((n) & 0x7) << 11)
      +#define AON_CMU_RAM_RET2N0_MASK                 (0x7 << 11)
      +#define AON_CMU_RAM_RET2N0_SHIFT                (11)
      +#define AON_CMU_RAM_PGEN0(n)                    (((n) & 0x7) << 14)
      +#define AON_CMU_RAM_PGEN0_MASK                  (0x7 << 14)
      +#define AON_CMU_RAM_PGEN0_SHIFT                 (14)
      +#define AON_CMU_RAM_RET1N1(n)                   (((n) & 0x7) << 17)
      +#define AON_CMU_RAM_RET1N1_MASK                 (0x7 << 17)
      +#define AON_CMU_RAM_RET1N1_SHIFT                (17)
      +#define AON_CMU_RAM_RET2N1(n)                   (((n) & 0x7) << 20)
      +#define AON_CMU_RAM_RET2N1_MASK                 (0x7 << 20)
      +#define AON_CMU_RAM_RET2N1_SHIFT                (20)
      +#define AON_CMU_RAM_PGEN1(n)                    (((n) & 0x7) << 23)
      +#define AON_CMU_RAM_PGEN1_MASK                  (0x7 << 23)
      +#define AON_CMU_RAM_PGEN1_SHIFT                 (23)
      +#define AON_CMU_RAM_EMAS                        (1 << 26)
       
       // reg_64
       #define AON_CMU_CFG_DIV_PCM(n)                  (((n) & 0x1FFF) << 0)
       #define AON_CMU_CFG_DIV_PCM_MASK                (0x1FFF << 0)
       #define AON_CMU_CFG_DIV_PCM_SHIFT               (0)
      -#define AON_CMU_EN_CLK_PLL_PCM                  (1 << 13)
      +#define AON_CMU_SEL_I2S_MCLK(n)                 (((n) & 0x7) << 13)
      +#define AON_CMU_SEL_I2S_MCLK_MASK               (0x7 << 13)
      +#define AON_CMU_SEL_I2S_MCLK_SHIFT              (13)
       #define AON_CMU_CFG_DIV_I2S0(n)                 (((n) & 0x1FFF) << 16)
       #define AON_CMU_CFG_DIV_I2S0_MASK               (0x1FFF << 16)
       #define AON_CMU_CFG_DIV_I2S0_SHIFT              (16)
       #define AON_CMU_EN_CLK_PLL_I2S0                 (1 << 29)
      -#define AON_CMU_SEL_AUD_PLLUSB                  (1 << 30)
      -#define AON_CMU_SEL_AUD_X4                      (1 << 31)
      +#define AON_CMU_EN_CLK_PLL_PCM                  (1 << 30)
      +#define AON_CMU_EN_I2S_MCLK                     (1 << 31)
       
       // reg_68
       #define AON_CMU_CFG_DIV_SPDIF0(n)               (((n) & 0x1FFF) << 0)
      @@ -383,15 +434,15 @@ struct AONCMU_T {
       #define AON_CMU_CFG_DIV_CODECIIR(n)             (((n) & 0xF) << 0)
       #define AON_CMU_CFG_DIV_CODECIIR_MASK           (0xF << 0)
       #define AON_CMU_CFG_DIV_CODECIIR_SHIFT          (0)
      -#define AON_CMU_SEL_CODECIIR_OSC                (1 << 4)
      -#define AON_CMU_SEL_CODECIIR_OSCX2              (1 << 5)
      +#define AON_CMU_SEL_OSC_CODECIIR                (1 << 4)
      +#define AON_CMU_SEL_OSCX2_CODECIIR              (1 << 5)
       #define AON_CMU_BYPASS_DIV_CODECIIR             (1 << 6)
      -#define AON_CMU_CFG_DIV_CODECRS0(n)             (((n) & 0xF) << 8)
      -#define AON_CMU_CFG_DIV_CODECRS0_MASK           (0xF << 8)
      -#define AON_CMU_CFG_DIV_CODECRS0_SHIFT          (8)
      -#define AON_CMU_SEL_CODECRS0_OSC                (1 << 12)
      -#define AON_CMU_SEL_CODECRS0_OSCX2              (1 << 13)
      -#define AON_CMU_BYPASS_DIV_CODECRS0             (1 << 14)
      +#define AON_CMU_CFG_DIV_CODECRS(n)              (((n) & 0xF) << 8)
      +#define AON_CMU_CFG_DIV_CODECRS_MASK            (0xF << 8)
      +#define AON_CMU_CFG_DIV_CODECRS_SHIFT           (8)
      +#define AON_CMU_SEL_OSC_CODECRS                 (1 << 12)
      +#define AON_CMU_SEL_OSCX2_CODECRS               (1 << 13)
      +#define AON_CMU_BYPASS_DIV_CODECRS              (1 << 14)
       
       // reg_7c
       #define AON_CMU_OTP_WR_LOCK(n)                  (((n) & 0xFFFF) << 0)
      @@ -445,10 +496,10 @@ struct AONCMU_T {
       #define AON_ARST_PWM                    (1 << 4)
       #define AON_ACLK_TIMER                  (1 << 5)
       #define AON_ARST_TIMER                  (1 << 5)
      -#define AON_ACLK_PSC                    (1 << 10)
      -#define AON_ARST_PSC                    (1 << 10)
      -#define AON_ACLK_IOMUX                  (1 << 6)
      -#define AON_ARST_IOMUX                  (1 << 6)
      +#define AON_ACLK_PSC                    (1 << 6)
      +#define AON_ARST_PSC                    (1 << 6)
      +#define AON_ACLK_IOMUX                  (1 << 7)
      +#define AON_ARST_IOMUX                  (1 << 7)
       #define AON_ACLK_APBC                   (1 << 8)
       #define AON_ARST_APBC                   (1 << 8)
       #define AON_ACLK_H2H_MCU                (1 << 9)
  • platform/hal/best2300p/reg_cmu_best2300p.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/reg_cmu_best2300p.h bes/platform/hal/best2300p/reg_cmu_best2300p.h
      index c0039582067..4404306c922 100644
      --- a/platform/hal/best2300p/reg_cmu_best2300p.h
      +++ b/platform/hal/best2300p/reg_cmu_best2300p.h
      @@ -27,7 +27,7 @@ struct CMU_T {
           __IO uint32_t HCLK_MODE;        // 0x18
           __IO uint32_t PCLK_MODE;        // 0x1C
           __IO uint32_t OCLK_MODE;        // 0x20
      -    __IO uint32_t RESERVED_024;     // 0x24
      +    __IO uint32_t RAM_CFG3;         // 0x24
           __IO uint32_t HRESET_PULSE;     // 0x28
           __IO uint32_t PRESET_PULSE;     // 0x2C
           __IO uint32_t ORESET_PULSE;     // 0x30
      @@ -126,13 +126,32 @@ struct CMU_T {
       #define CMU_MODE_OCLK_MASK                      (0xFFFFFFFF << 0)
       #define CMU_MODE_OCLK_SHIFT                     (0)
       
      +// reg_24
      +#define CMU_RAM3_RET1N0(n)                      (((n) & 0x1F) << 0)
      +#define CMU_RAM3_RET1N0_MASK                    (0x1F << 0)
      +#define CMU_RAM3_RET1N0_SHIFT                   (0)
      +#define CMU_RAM3_RET2N0(n)                      (((n) & 0x1F) << 5)
      +#define CMU_RAM3_RET2N0_MASK                    (0x1F << 5)
      +#define CMU_RAM3_RET2N0_SHIFT                   (5)
      +#define CMU_RAM3_PGEN0(n)                       (((n) & 0x1F) << 10)
      +#define CMU_RAM3_PGEN0_MASK                     (0x1F << 10)
      +#define CMU_RAM3_PGEN0_SHIFT                    (10)
      +#define CMU_RAM3_RET1N1(n)                      (((n) & 0x1F) << 15)
      +#define CMU_RAM3_RET1N1_MASK                    (0x1F << 15)
      +#define CMU_RAM3_RET1N1_SHIFT                   (15)
      +#define CMU_RAM3_RET2N1(n)                      (((n) & 0x1F) << 20)
      +#define CMU_RAM3_RET2N1_MASK                    (0x1F << 20)
      +#define CMU_RAM3_RET2N1_SHIFT                   (20)
      +#define CMU_RAM3_PGEN1(n)                       (((n) & 0x1F) << 25)
      +#define CMU_RAM3_PGEN1_MASK                     (0x1F << 25)
      +#define CMU_RAM3_PGEN1_SHIFT                    (25)
       
       // reg_28
       #define CMU_HRESETN_PULSE(n)                    (((n) & 0xFFFFFFFF) << 0)
       #define CMU_HRESETN_PULSE_MASK                  (0xFFFFFFFF << 0)
       #define CMU_HRESETN_PULSE_SHIFT                 (0)
       
      -#define SYS_PRST_NUM                            26
      +#define SYS_PRST_NUM                            19
       
       // reg_2c
       #define CMU_PRESETN_PULSE(n)                    (((n) & 0xFFFFFFFF) << 0)
      @@ -218,7 +237,7 @@ struct CMU_T {
       #define CMU_DEEPSLEEP_START                     (1 << 28)
       #define CMU_DEEPSLEEP_MODE                      (1 << 29)
       #define CMU_PU_OSC                              (1 << 30)
      -#define CMU_WAKEDOWN_DEEPSLEEP_L                (1 << 31)
      +#define CMU_WAKEUP_DEEPSLEEP_L                  (1 << 31)
       
       // reg_5c
       #define CMU_CFG_DIV_SDMMC(n)                    (((n) & 0xF) << 0)
      @@ -244,32 +263,32 @@ struct CMU_T {
       #define CMU_JTAG_SEL_CP                         (1 << 25)
       
       // reg_60
      -#define CMU_RSTN_DIV_MCU_ENABLE                 (1 << 0)
      -#define CMU_BYPASS_DIV_MCU_ENABLE               (1 << 1)
      -#define CMU_SEL_MCU_OSC_4_ENABLE                (1 << 2)
      -#define CMU_SEL_MCU_OSC_2_ENABLE                (1 << 3)
      -#define CMU_SEL_MCU_OSCX4_ENABLE                (1 << 4)
      -#define CMU_SEL_MCU_SLOW_ENABLE                 (1 << 5)
      -#define CMU_SEL_MCU_FAST_ENABLE                 (1 << 6)
      -#define CMU_SEL_MCU_PLL_ENABLE                  (1 << 7)
      -#define CMU_RSTN_DIV_A7_ENABLE                  (1 << 8)
      -#define CMU_BYPASS_DIV_A7_ENABLE                (1 << 9)
      -#define CMU_SEL_A7_OSC_4_ENABLE                 (1 << 10)
      -#define CMU_SEL_A7_OSC_2_ENABLE                 (1 << 11)
      +#define CMU_RSTN_DIV_FLS_ENABLE                 (1 << 0)
      +#define CMU_SEL_OSC_FLS_ENABLE                  (1 << 1)
      +#define CMU_SEL_OSCX2_FLS_ENABLE                (1 << 2)
      +#define CMU_SEL_PLL_FLS_ENABLE                  (1 << 3)
      +#define CMU_BYPASS_DIV_FLS_ENABLE               (1 << 4)
      +#define CMU_RSTN_DIV_SYS_ENABLE                 (1 << 5)
      +#define CMU_SEL_OSC_SYS_ENABLE                  (1 << 6)
      +#define CMU_SEL_OSCX2_SYS_ENABLE                (1 << 7)
      +#define CMU_SEL_PLL_SYS_ENABLE                  (1 << 8)
      +#define CMU_BYPASS_DIV_SYS_ENABLE               (1 << 9)
      +#define CMU_EN_PLL_ENABLE                       (1 << 10)
      +#define CMU_PU_PLL_ENABLE                       (1 << 11)
       
       // reg_64
      -#define CMU_RSTN_DIV_MCU_DISABLE                (1 << 0)
      -#define CMU_BYPASS_DIV_MCU_DISABLE              (1 << 1)
      -#define CMU_SEL_MCU_OSC_4_DISABLE               (1 << 2)
      -#define CMU_SEL_MCU_OSC_2_DISABLE               (1 << 3)
      -#define CMU_SEL_MCU_OSCX4_DISABLE               (1 << 4)
      -#define CMU_SEL_MCU_SLOW_DISABLE                (1 << 5)
      -#define CMU_SEL_MCU_FAST_DISABLE                (1 << 6)
      -#define CMU_SEL_MCU_PLL_DISABLE                 (1 << 7)
      -#define CMU_RSTN_DIV_A7_DISABLE                 (1 << 8)
      -#define CMU_BYPASS_DIV_A7_DISABLE               (1 << 9)
      -#define CMU_SEL_A7_OSC_4_DISABLE                (1 << 10)
      -#define CMU_SEL_A7_OSC_2_DISABLE                (1 << 11)
      +#define CMU_RSTN_DIV_FLS_DISABLE                (1 << 0)
      +#define CMU_SEL_OSC_FLS_DISABLE                 (1 << 1)
      +#define CMU_SEL_OSCX2_FLS_DISABLE               (1 << 2)
      +#define CMU_SEL_PLL_FLS_DISABLE                 (1 << 3)
      +#define CMU_BYPASS_DIV_FLS_DISABLE              (1 << 4)
      +#define CMU_RSTN_DIV_SYS_DISABLE                (1 << 5)
      +#define CMU_SEL_OSC_SYS_DISABLE                 (1 << 6)
      +#define CMU_SEL_OSCX2_SYS_DISABLE               (1 << 7)
      +#define CMU_SEL_PLL_SYS_DISABLE                 (1 << 8)
      +#define CMU_BYPASS_DIV_SYS_DISABLE              (1 << 9)
      +#define CMU_EN_PLL_DISABLE                      (1 << 10)
      +#define CMU_PU_PLL_DISABLE                      (1 << 11)
       
       // reg_68
       #define CMU_ADMA_CH15_REQ_IDX(n)                (((n) & 0x3F) << 0)
      @@ -281,39 +300,37 @@ struct CMU_T {
       #define CMU_ROM_EMA_MASK                        (0x7 << 0)
       #define CMU_ROM_EMA_SHIFT                       (0)
       #define CMU_ROM_KEN                             (1 << 3)
      -#define CMU_ROM_PGEN(n)                         (((n) & 0x3) << 4)
      -#define CMU_ROM_PGEN_MASK                       (0x3 << 4)
      +#define CMU_ROM_PGEN(n)                         (((n) & 0x7) << 4)
      +#define CMU_ROM_PGEN_MASK                       (0x7 << 4)
       #define CMU_ROM_PGEN_SHIFT                      (4)
      -#define CMU_RAM_EMA(n)                          (((n) & 0x7) << 6)
      -#define CMU_RAM_EMA_MASK                        (0x7 << 6)
      -#define CMU_RAM_EMA_SHIFT                       (6)
      -#define CMU_RAM_EMAW(n)                         (((n) & 0x3) << 9)
      -#define CMU_RAM_EMAW_MASK                       (0x3 << 9)
      -#define CMU_RAM_EMAW_SHIFT                      (9)
      -#define CMU_RAM_EMAS                            (1 << 11)
      +#define CMU_RAM_EMA(n)                          (((n) & 0x7) << 7)
      +#define CMU_RAM_EMA_MASK                        (0x7 << 7)
      +#define CMU_RAM_EMA_SHIFT                       (7)
      +#define CMU_RAM_EMAW(n)                         (((n) & 0x3) << 10)
      +#define CMU_RAM_EMAW_MASK                       (0x3 << 10)
      +#define CMU_RAM_EMAW_SHIFT                      (10)
       #define CMU_RAM_WABL                            (1 << 12)
       #define CMU_RAM_WABLM(n)                        (((n) & 0x3) << 13)
       #define CMU_RAM_WABLM_MASK                      (0x3 << 13)
       #define CMU_RAM_WABLM_SHIFT                     (13)
      -#define CMU_RAM_RAWL                            (1 << 15)
      -#define CMU_RAM_RAWLM(n)                        (((n) & 0x3) << 16)
      -#define CMU_RAM_RAWLM_MASK                      (0x3 << 16)
      -#define CMU_RAM_RAWLM_SHIFT                     (16)
      -#define CMU_RF_EMA(n)                           (((n) & 0x7) << 18)
      -#define CMU_RF_EMA_MASK                         (0x7 << 18)
      -#define CMU_RF_EMA_SHIFT                        (18)
      -#define CMU_RF_EMAW(n)                          (((n) & 0x3) << 21)
      -#define CMU_RF_EMAW_MASK                        (0x3 << 21)
      -#define CMU_RF_EMAW_SHIFT                       (21)
      -#define CMU_RF_EMAS                             (1 << 23)
      -#define CMU_RF_WABL                             (1 << 24)
      -#define CMU_RF_WABLM(n)                         (((n) & 0x3) << 25)
      -#define CMU_RF_WABLM_MASK                       (0x3 << 25)
      -#define CMU_RF_WABLM_SHIFT                      (25)
      -#define CMU_RF_RAWL                             (1 << 27)
      -#define CMU_RF_RAWLM(n)                         (((n) & 0x3) << 28)
      -#define CMU_RF_RAWLM_MASK                       (0x3 << 28)
      -#define CMU_RF_RAWLM_SHIFT                      (28)
      +#define CMU_RAM_EMAS                            (1 << 15)
      +#define CMU_RF_EMA(n)                           (((n) & 0x7) << 16)
      +#define CMU_RF_EMA_MASK                         (0x7 << 16)
      +#define CMU_RF_EMA_SHIFT                        (16)
      +#define CMU_RF_EMAW(n)                          (((n) & 0x3) << 19)
      +#define CMU_RF_EMAW_MASK                        (0x3 << 19)
      +#define CMU_RF_EMAW_SHIFT                       (19)
      +#define CMU_RF_WABL                             (1 << 21)
      +#define CMU_RF_WABLM(n)                         (((n) & 0x3) << 22)
      +#define CMU_RF_WABLM_MASK                       (0x3 << 22)
      +#define CMU_RF_WABLM_SHIFT                      (22)
      +#define CMU_RF_EMAS                             (1 << 24)
      +#define CMU_RF_RET1N0                           (1 << 25)
      +#define CMU_RF_RET2N0                           (1 << 26)
      +#define CMU_RF_PGEN0                            (1 << 27)
      +#define CMU_RF_RET1N1                           (1 << 28)
      +#define CMU_RF_RET2N1                           (1 << 29)
      +#define CMU_RF_PGEN1                            (1 << 30)
       
       // reg_70
       #define CMU_CFG_DIV_UART0(n)                    (((n) & 0x1F) << 0)
      @@ -360,14 +377,26 @@ struct CMU_T {
       #define CMU_POL_CLK_I2S1_OUT                    (1 << 26)
       
       // reg_78
      -#define CMU_RAM_RET1N0(n)                       (((n) & 0xFFFFFFFF) << 0)
      -#define CMU_RAM_RET1N0_MASK                     (0xFFFFFFFF << 0)
      +#define CMU_RAM_RET1N0(n)                       (((n) & 0x3FF) << 0)
      +#define CMU_RAM_RET1N0_MASK                     (0x3FF << 0)
       #define CMU_RAM_RET1N0_SHIFT                    (0)
      +#define CMU_RAM_RET2N0(n)                       (((n) & 0x3FF) << 10)
      +#define CMU_RAM_RET2N0_MASK                     (0x3FF << 10)
      +#define CMU_RAM_RET2N0_SHIFT                    (10)
      +#define CMU_RAM_PGEN0(n)                        (((n) & 0x3FF) << 20)
      +#define CMU_RAM_PGEN0_MASK                      (0x3FF << 20)
      +#define CMU_RAM_PGEN0_SHIFT                     (20)
       
       // reg_7c
      -#define CMU_RAM_RET1N1(n)                       (((n) & 0xFFFFFFFF) << 0)
      -#define CMU_RAM_RET1N1_MASK                     (0xFFFFFFFF << 0)
      +#define CMU_RAM_RET1N1(n)                       (((n) & 0x3FF) << 0)
      +#define CMU_RAM_RET1N1_MASK                     (0x3FF << 0)
       #define CMU_RAM_RET1N1_SHIFT                    (0)
      +#define CMU_RAM_RET2N1(n)                       (((n) & 0x3FF) << 10)
      +#define CMU_RAM_RET2N1_MASK                     (0x3FF << 10)
      +#define CMU_RAM_RET2N1_SHIFT                    (10)
      +#define CMU_RAM_PGEN1(n)                        (((n) & 0x3FF) << 20)
      +#define CMU_RAM_PGEN1_MASK                      (0x3FF << 20)
      +#define CMU_RAM_PGEN1_SHIFT                     (20)
       
       // reg_80
       #define CMU_WRITE_UNLOCK_H                      (1 << 0)
      @@ -379,8 +408,8 @@ struct CMU_T {
       #define CMU_WAKEUP_IRQ_MASK0_SHIFT              (0)
       
       // reg_88
      -#define CMU_WAKEUP_IRQ_MASK1(n)                 (((n) & 0xFFFFFFFF) << 0)
      -#define CMU_WAKEUP_IRQ_MASK1_MASK               (0xFFFFFFFF << 0)
      +#define CMU_WAKEUP_IRQ_MASK1(n)                 (((n) & 0xFFFFF) << 0)
      +#define CMU_WAKEUP_IRQ_MASK1_MASK               (0xFFFFF << 0)
       #define CMU_WAKEUP_IRQ_MASK1_SHIFT              (0)
       
       // reg_8c
      @@ -446,35 +475,38 @@ struct CMU_T {
       #define CMU_BT_ALLIRQ_MASK_CLR                  (1 << 4)
       
       // reg_a8
      -#define CMU_CFG_DIV_MCU(n)                      (((n) & 0x3) << 0)
      -#define CMU_CFG_DIV_MCU_MASK                    (0x3 << 0)
      -#define CMU_CFG_DIV_MCU_SHIFT                   (0)
      -#define CMU_SEL_SMP_MCU(n)                      (((n) & 0x7) << 2)
      -#define CMU_SEL_SMP_MCU_MASK                    (0x7 << 2)
      +#define CMU_CFG_DIV_SYS(n)                      (((n) & 0x3) << 0)
      +#define CMU_CFG_DIV_SYS_MASK                    (0x3 << 0)
      +#define CMU_CFG_DIV_SYS_SHIFT                   (0)
      +#define CMU_SEL_SMP_MCU(n)                      (((n) & 0x3) << 2)
      +#define CMU_SEL_SMP_MCU_MASK                    (0x3 << 2)
       #define CMU_SEL_SMP_MCU_SHIFT                   (2)
      -#define CMU_SEL_USB_6M                          (1 << 5)
      -#define CMU_SEL_USB_SRC(n)                      (((n) & 0x7) << 6)
      -#define CMU_SEL_USB_SRC_MASK                    (0x7 << 6)
      -#define CMU_SEL_USB_SRC_SHIFT                   (6)
      -#define CMU_POL_CLK_USB                         (1 << 9)
      -#define CMU_USB_ID                              (1 << 10)
      -#define CMU_CFG_DIV_PCLK(n)                     (((n) & 0x3) << 11)
      -#define CMU_CFG_DIV_PCLK_MASK                   (0x3 << 11)
      -#define CMU_CFG_DIV_PCLK_SHIFT                  (11)
      -#define CMU_CFG_DIV_SPI0(n)                     (((n) & 0xF) << 13)
      -#define CMU_CFG_DIV_SPI0_MASK                   (0xF << 13)
      -#define CMU_CFG_DIV_SPI0_SHIFT                  (13)
      -#define CMU_SEL_OSCX2_SPI0                      (1 << 17)
      -#define CMU_SEL_PLL_SPI0                        (1 << 18)
      -#define CMU_EN_PLL_SPI0                         (1 << 19)
      -#define CMU_CFG_DIV_SPI1(n)                     (((n) & 0xF) << 20)
      -#define CMU_CFG_DIV_SPI1_MASK                   (0xF << 20)
      -#define CMU_CFG_DIV_SPI1_SHIFT                  (20)
      -#define CMU_SEL_OSCX2_SPI1                      (1 << 24)
      -#define CMU_SEL_PLL_SPI1                        (1 << 25)
      -#define CMU_EN_PLL_SPI1                         (1 << 26)
      -#define CMU_SEL_OSCX2_SPI2                      (1 << 27)
      -#define CMU_DSD_PCM_DMAREQ_SEL                  (1 << 28)
      +#define CMU_CFG_DIV_FLS(n)                      (((n) & 0x3) << 4)
      +#define CMU_CFG_DIV_FLS_MASK                    (0x3 << 4)
      +#define CMU_CFG_DIV_FLS_SHIFT                   (4)
      +#define CMU_SEL_USB_6M                          (1 << 6)
      +#define CMU_SEL_USB_SRC(n)                      (((n) & 0x7) << 7)
      +#define CMU_SEL_USB_SRC_MASK                    (0x7 << 7)
      +#define CMU_SEL_USB_SRC_SHIFT                   (7)
      +#define CMU_POL_CLK_USB                         (1 << 10)
      +#define CMU_USB_ID                              (1 << 11)
      +#define CMU_CFG_DIV_PCLK(n)                     (((n) & 0x3) << 12)
      +#define CMU_CFG_DIV_PCLK_MASK                   (0x3 << 12)
      +#define CMU_CFG_DIV_PCLK_SHIFT                  (12)
      +#define CMU_CFG_DIV_SPI0(n)                     (((n) & 0xF) << 14)
      +#define CMU_CFG_DIV_SPI0_MASK                   (0xF << 14)
      +#define CMU_CFG_DIV_SPI0_SHIFT                  (14)
      +#define CMU_SEL_OSCX2_SPI0                      (1 << 18)
      +#define CMU_SEL_PLL_SPI0                        (1 << 19)
      +#define CMU_EN_PLL_SPI0                         (1 << 20)
      +#define CMU_CFG_DIV_SPI1(n)                     (((n) & 0xF) << 21)
      +#define CMU_CFG_DIV_SPI1_MASK                   (0xF << 21)
      +#define CMU_CFG_DIV_SPI1_SHIFT                  (21)
      +#define CMU_SEL_OSCX2_SPI1                      (1 << 25)
      +#define CMU_SEL_PLL_SPI1                        (1 << 26)
      +#define CMU_EN_PLL_SPI1                         (1 << 27)
      +#define CMU_SEL_OSCX2_SPI2                      (1 << 28)
      +#define CMU_DSD_PCM_DMAREQ_SEL                  (1 << 29)
       
       // reg_ac
       #define CMU_DMA_HANDSHAKE_SWAP(n)               (((n) & 0xFFFF) << 0)
      @@ -490,8 +522,8 @@ struct CMU_T {
       #define CMU_MCU2BT_INTISR_MASK0_SHIFT           (0)
       
       // reg_b4
      -#define CMU_MCU2BT_INTISR_MASK1(n)              (((n) & 0xFFFFFFFF) << 0)
      -#define CMU_MCU2BT_INTISR_MASK1_MASK            (0xFFFFFFFF << 0)
      +#define CMU_MCU2BT_INTISR_MASK1(n)              (((n) & 0xFFFFF) << 0)
      +#define CMU_MCU2BT_INTISR_MASK1_MASK            (0xFFFFF << 0)
       #define CMU_MCU2BT_INTISR_MASK1_SHIFT           (0)
       
       // reg_b8
      @@ -666,70 +698,68 @@ struct CMU_T {
       #define CMU_DCODE_ACC_SECROM_EN                 (1 << 5)
       
       // MCU System AHB Clocks:
      -#define SYS_HCLK_CORE0                  (1 << 0)
      -#define SYS_HRST_CORE0                  (1 << 0)
      -#define SYS_HCLK_CACHE0                 (1 << 1)
      -#define SYS_HRST_CACHE0                 (1 << 1)
      -#define SYS_HCLK_CORE1                  (1 << 2)
      -#define SYS_HRST_CORE1                  (1 << 2)
      -#define SYS_HCLK_CACHE1                 (1 << 3)
      -#define SYS_HRST_CACHE1                 (1 << 3)
      -#define SYS_HCLK_ADMA                   (1 << 4)
      -#define SYS_HRST_ADMA                   (1 << 4)
      -#define SYS_HCLK_GDMA                   (1 << 5)
      -#define SYS_HRST_GDMA                   (1 << 5)
      -#define SYS_HCLK_BCM                    (1 << 6)
      -#define SYS_HRST_BCM                    (1 << 6)
      -#define SYS_HCLK_USBC                   (1 << 7)
      -#define SYS_HRST_USBC                   (1 << 7)
      -#define SYS_HCLK_USBH                   (1 << 8)
      -#define SYS_HRST_USBH                   (1 << 8)
      -#define SYS_HCLK_I2C_SLAVE              (1 << 9)
      -#define SYS_HRST_I2C_SLAVE              (1 << 9)
      -#define SYS_HCLK_AX2H_A7                (1 << 10)
      -#define SYS_HRST_AX2H_A7                (1 << 10)
      -#define SYS_HCLK_AH2H_WF                (1 << 11)
      -#define SYS_HRST_AH2H_WF                (1 << 11)
      -#define SYS_HCLK_AH2H_BT                (1 << 12)
      -#define SYS_HRST_AH2H_BT                (1 << 12)
      -#define SYS_HCLK_CODEC                  (1 << 13)
      -#define SYS_HRST_CODEC                  (1 << 13)
      -#define SYS_HCLK_AHB1                   (1 << 14)
      -#define SYS_HRST_AHB1                   (1 << 14)
      -#define SYS_HCLK_AHB0                   (1 << 15)
      -#define SYS_HRST_AHB0                   (1 << 15)
      -#define SYS_HCLK_PSRAM1G                (1 << 16)
      -#define SYS_HRST_PSRAM1G                (1 << 16)
      -#define SYS_HCLK_PSRAM200               (1 << 17)
      -#define SYS_HRST_PSRAM200               (1 << 17)
      -#define SYS_HCLK_FLASH                  (1 << 18)
      -#define SYS_HRST_FLASH                  (1 << 18)
      -#define SYS_HCLK_RAM5                   (1 << 19)
      -#define SYS_HRST_RAM5                   (1 << 19)
      -#define SYS_HCLK_RAM4                   (1 << 20)
      -#define SYS_HRST_RAM4                   (1 << 20)
      -#define SYS_HCLK_RAM3                   (1 << 21)
      -#define SYS_HRST_RAM3                   (1 << 21)
      -#define SYS_HCLK_RAM2                   (1 << 22)
      -#define SYS_HRST_RAM2                   (1 << 22)
      -#define SYS_HCLK_RAM1                   (1 << 23)
      -#define SYS_HRST_RAM1                   (1 << 23)
      -#define SYS_HCLK_RAM0                   (1 << 24)
      -#define SYS_HRST_RAM0                   (1 << 24)
      -#define SYS_HCLK_ROM0                   (1 << 25)
      -#define SYS_HRST_ROM0                   (1 << 25)
      -#define SYS_HCLK_BT_DUMP                (1 << 26)
      -#define SYS_HRST_BT_DUMP                (1 << 26)
      -#define SYS_HCLK_WF_DUMP                (1 << 27)
      -#define SYS_HRST_WF_DUMP                (1 << 27)
      -#define SYS_HCLK_SDMMC                  (1 << 28)
      -#define SYS_HRST_SDMMC                  (1 << 28)
      -#define SYS_HCLK_CHECKSUM               (1 << 29)
      -#define SYS_HRST_CHECKSUM               (1 << 29)
      -#define SYS_HCLK_CRC                    (1 << 30)
      -#define SYS_HRST_CRC                    (1 << 30)
      -#define SYS_HCLK_FLASH1                 (1 << 31)
      -#define SYS_HRST_FLASH1                 (1 << 31)
      +#define SYS_HCLK_MCU                    (1 << 0)
      +#define SYS_HRST_MCU                    (1 << 0)
      +#define SYS_HCLK_ROM0                   (1 << 1)
      +#define SYS_HRST_ROM0                   (1 << 1)
      +#define SYS_HCLK_ROM1                   (1 << 2)
      +#define SYS_HRST_ROM1                   (1 << 2)
      +#define SYS_HCLK_ROM2                   (1 << 3)
      +#define SYS_HRST_ROM2                   (1 << 3)
      +#define SYS_HCLK_RAM0                   (1 << 4)
      +#define SYS_HRST_RAM0                   (1 << 4)
      +#define SYS_HCLK_RAM1                   (1 << 5)
      +#define SYS_HRST_RAM1                   (1 << 5)
      +#define SYS_HCLK_RAM2                   (1 << 6)
      +#define SYS_HRST_RAM2                   (1 << 6)
      +#define SYS_HCLK_RAMRET                 (1 << 7)
      +#define SYS_HRST_RAMRET                 (1 << 7)
      +#define SYS_HCLK_AHB0                   (1 << 8)
      +#define SYS_HRST_AHB0                   (1 << 8)
      +#define SYS_HCLK_AHB1                   (1 << 9)
      +#define SYS_HRST_AHB1                   (1 << 9)
      +#define SYS_HCLK_AH2H_BT                (1 << 10)
      +#define SYS_HRST_AH2H_BT                (1 << 10)
      +#define SYS_HCLK_ADMA                   (1 << 11)
      +#define SYS_HRST_ADMA                   (1 << 11)
      +#define SYS_HCLK_GDMA                   (1 << 12)
      +#define SYS_HRST_GDMA                   (1 << 12)
      +#define SYS_HCLK_EXTMEM                 (1 << 13)
      +#define SYS_HRST_EXTMEM                 (1 << 13)
      +#define SYS_HCLK_FLASH                  (1 << 14)
      +#define SYS_HRST_FLASH                  (1 << 14)
      +#define SYS_HCLK_SDMMC                  (1 << 15)
      +#define SYS_HRST_SDMMC                  (1 << 15)
      +#define SYS_HCLK_USBC                   (1 << 16)
      +#define SYS_HRST_USBC                   (1 << 16)
      +#define SYS_HCLK_CODEC                  (1 << 17)
      +#define SYS_HRST_CODEC                  (1 << 17)
      +#define SYS_HCLK_FFT                    (1 << 18)
      +#define SYS_HRST_FFT                    (1 << 18)
      +#define SYS_HCLK_I2C_SLAVE              (1 << 19)
      +#define SYS_HRST_I2C_SLAVE              (1 << 19)
      +#define SYS_HCLK_USBH                   (1 << 20)
      +#define SYS_HRST_USBH                   (1 << 20)
      +#define SYS_HCLK_SENSOR_HUB             (1 << 21)
      +#define SYS_HRST_SENSOR_HUB             (1 << 21)
      +#define SYS_HCLK_BT_DUMP                (1 << 22)
      +#define SYS_HRST_BT_DUMP                (1 << 22)
      +#define SYS_HCLK_CP                     (1 << 23)
      +#define SYS_HRST_CP                     (1 << 23)
      +#define SYS_HCLK_RAM3                   (1 << 24)
      +#define SYS_HRST_RAM3                   (1 << 24)
      +#define SYS_HCLK_RAM4                   (1 << 25)
      +#define SYS_HRST_RAM4                   (1 << 25)
      +#define SYS_HCLK_RAM5                   (1 << 26)
      +#define SYS_HRST_RAM5                   (1 << 26)
      +#define SYS_HCLK_RAM6                   (1 << 27)
      +#define SYS_HRST_RAM6                   (1 << 27)
      +#define SYS_HCLK_BCM                    (1 << 28)
      +#define SYS_HRST_BCM                    (1 << 28)
      +#define SYS_HCLK_ICACHE0                (1 << 29)
      +#define SYS_HRST_ICACHE0                (1 << 29)
      +#define SYS_HCLK_ICACHE1                (1 << 30)
      +#define SYS_HRST_ICACHE1                (1 << 30)
       
       // MCU System APB Clocks:
       #define SYS_PCLK_CMU                    (1 << 0)
      @@ -766,55 +796,55 @@ struct CMU_T {
       #define SYS_PRST_I2S0                   (1 << 15)
       #define SYS_PCLK_SPDIF0                 (1 << 16)
       #define SYS_PRST_SPDIF0                 (1 << 16)
      -#define SYS_PCLK_BCM                    (1 << 20)
      -#define SYS_PRST_BCM                    (1 << 20)
      -#define SYS_PCLK_I2S1                   (1 << 25)
      -#define SYS_PRST_I2S1                   (1 << 25)
      +#define SYS_PCLK_I2S1                   (1 << 17)
      +#define SYS_PRST_I2S1                   (1 << 17)
      +#define SYS_PCLK_BCM                    (1 << 18)
      +#define SYS_PRST_BCM                    (1 << 18)
       
       // MCU System Other Clocks:
       #define SYS_OCLK_SLEEP                  (1 << 0)
       #define SYS_ORST_SLEEP                  (1 << 0)
      -#define SYS_OCLK_USB                    (1 << 1)
      -#define SYS_ORST_USB                    (1 << 1)
      -#define SYS_OCLK_USB32K                 (1 << 2)
      -#define SYS_ORST_USB32K                 (1 << 2)
      -#define SYS_OCLK_FLASH                  (1 << 5)
      -#define SYS_ORST_FLASH                  (1 << 5)
      -#define SYS_OCLK_SDMMC                  (1 << 6)
      -#define SYS_ORST_SDMMC                  (1 << 6)
      -#define SYS_OCLK_WDT                    (1 << 7)
      -#define SYS_ORST_WDT                    (1 << 7)
      -#define SYS_OCLK_TIMER0                 (1 << 8)
      -#define SYS_ORST_TIMER0                 (1 << 8)
      -#define SYS_OCLK_TIMER1                 (1 << 9)
      -#define SYS_ORST_TIMER1                 (1 << 9)
      -#define SYS_OCLK_TIMER2                 (1 << 10)
      -#define SYS_ORST_TIMER2                 (1 << 10)
      -#define SYS_OCLK_I2C0                   (1 << 11)
      -#define SYS_ORST_I2C0                   (1 << 11)
      -#define SYS_OCLK_I2C1                   (1 << 12)
      -#define SYS_ORST_I2C1                   (1 << 12)
      -#define SYS_OCLK_SPI                    (1 << 13)
      -#define SYS_ORST_SPI                    (1 << 13)
      -#define SYS_OCLK_SLCD                   (1 << 14)
      -#define SYS_ORST_SLCD                   (1 << 14)
      -#define SYS_OCLK_SPI_ITN                (1 << 15)
      -#define SYS_ORST_SPI_ITN                (1 << 15)
      -#define SYS_OCLK_SPI_PHY                (1 << 16)
      -#define SYS_ORST_SPI_PHY                (1 << 16)
      -#define SYS_OCLK_UART0                  (1 << 17)
      -#define SYS_ORST_UART0                  (1 << 17)
      -#define SYS_OCLK_UART1                  (1 << 18)
      -#define SYS_ORST_UART1                  (1 << 18)
      -#define SYS_OCLK_UART2                  (1 << 19)
      -#define SYS_ORST_UART2                  (1 << 19)
      -#define SYS_OCLK_PCM                    (1 << 20)
      -#define SYS_ORST_PCM                    (1 << 20)
      -#define SYS_OCLK_I2S0                   (1 << 21)
      -#define SYS_ORST_I2S0                   (1 << 21)
      -#define SYS_OCLK_SPDIF0                 (1 << 22)
      -#define SYS_ORST_SPDIF0                 (1 << 22)
      -#define SYS_OCLK_I2S1                   (1 << 23)
      -#define SYS_ORST_I2S1                   (1 << 23)
      +#define SYS_OCLK_FLASH                  (1 << 1)
      +#define SYS_ORST_FLASH                  (1 << 1)
      +#define SYS_OCLK_USB                    (1 << 2)
      +#define SYS_ORST_USB                    (1 << 2)
      +#define SYS_OCLK_SDMMC                  (1 << 3)
      +#define SYS_ORST_SDMMC                  (1 << 3)
      +#define SYS_OCLK_WDT                    (1 << 4)
      +#define SYS_ORST_WDT                    (1 << 4)
      +#define SYS_OCLK_TIMER0                 (1 << 5)
      +#define SYS_ORST_TIMER0                 (1 << 5)
      +#define SYS_OCLK_TIMER1                 (1 << 6)
      +#define SYS_ORST_TIMER1                 (1 << 6)
      +#define SYS_OCLK_TIMER2                 (1 << 7)
      +#define SYS_ORST_TIMER2                 (1 << 7)
      +#define SYS_OCLK_I2C0                   (1 << 8)
      +#define SYS_ORST_I2C0                   (1 << 8)
      +#define SYS_OCLK_I2C1                   (1 << 9)
      +#define SYS_ORST_I2C1                   (1 << 9)
      +#define SYS_OCLK_SPI                    (1 << 10)
      +#define SYS_ORST_SPI                    (1 << 10)
      +#define SYS_OCLK_SLCD                   (1 << 11)
      +#define SYS_ORST_SLCD                   (1 << 11)
      +#define SYS_OCLK_SPI_ITN                (1 << 12)
      +#define SYS_ORST_SPI_ITN                (1 << 12)
      +#define SYS_OCLK_SPI_PHY                (1 << 13)
      +#define SYS_ORST_SPI_PHY                (1 << 13)
      +#define SYS_OCLK_UART0                  (1 << 14)
      +#define SYS_ORST_UART0                  (1 << 14)
      +#define SYS_OCLK_UART1                  (1 << 15)
      +#define SYS_ORST_UART1                  (1 << 15)
      +#define SYS_OCLK_UART2                  (1 << 16)
      +#define SYS_ORST_UART2                  (1 << 16)
      +#define SYS_OCLK_I2S0                   (1 << 17)
      +#define SYS_ORST_I2S0                   (1 << 17)
      +#define SYS_OCLK_SPDIF0                 (1 << 18)
      +#define SYS_ORST_SPDIF0                 (1 << 18)
      +#define SYS_OCLK_PCM                    (1 << 19)
      +#define SYS_ORST_PCM                    (1 << 19)
      +#define SYS_OCLK_USB32K                 (1 << 20)
      +#define SYS_ORST_USB32K                 (1 << 20)
      +#define SYS_OCLK_I2S1                   (1 << 21)
      +#define SYS_ORST_I2S1                   (1 << 21)
       
       #endif
  • platform/hal/best2300p/reg_codec_best2300p.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/reg_codec_best2300p.h bes/platform/hal/best2300p/reg_codec_best2300p.h
      index cfe2da003af..c7842879075 100644
      --- a/platform/hal/best2300p/reg_codec_best2300p.h
      +++ b/platform/hal/best2300p/reg_codec_best2300p.h
      @@ -171,9 +171,9 @@ struct CODEC_T {
       #define CODEC_ADC_ENABLE_CH4                                (1 << 6)
       #define CODEC_ADC_ENABLE_CH5                                (1 << 7)
       #define CODEC_ADC_ENABLE_CH6                                (1 << 8)
      -#define CODEC_DAC_ENABLE                                    (1 << 10)
      -#define CODEC_DMACTRL_RX                                    (1 << 11)
      -#define CODEC_DMACTRL_TX                                    (1 << 12)
      +#define CODEC_DAC_ENABLE                                    (1 << 9)
      +#define CODEC_DMACTRL_RX                                    (1 << 10)
      +#define CODEC_DMACTRL_TX                                    (1 << 11)
       
       // reg_04
       #define CODEC_RX_FIFO_FLUSH_CH0                             (1 << 0)
      @@ -183,9 +183,12 @@ struct CODEC_T {
       #define CODEC_RX_FIFO_FLUSH_CH4                             (1 << 4)
       #define CODEC_RX_FIFO_FLUSH_CH5                             (1 << 5)
       #define CODEC_RX_FIFO_FLUSH_CH6                             (1 << 6)
      -#define CODEC_TX_FIFO_FLUSH                                 (1 << 8)
      -#define CODEC_DSD_RX_FIFO_FLUSH                             (1 << 9)
      -#define CODEC_DSD_TX_FIFO_FLUSH                             (1 << 10)
      +#define CODEC_TX_FIFO_FLUSH                                 (1 << 7)
      +#define CODEC_DSD_RX_FIFO_FLUSH                             (1 << 8)
      +#define CODEC_DSD_TX_FIFO_FLUSH                             (1 << 9)
      +#define CODEC_MC_FIFO_FLUSH                                 (1 << 10)
      +#define CODEC_IIR_RX_FIFO_FLUSH                             (1 << 11)
      +#define CODEC_IIR_TX_FIFO_FLUSH                             (1 << 12)
       
       // reg_08
       #define CODEC_CODEC_RX_THRESHOLD(n)                         (((n) & 0xF) << 0)
      @@ -200,50 +203,71 @@ struct CODEC_T {
       #define CODEC_DSD_TX_THRESHOLD(n)                           (((n) & 0x7) << 12)
       #define CODEC_DSD_TX_THRESHOLD_MASK                         (0x7 << 12)
       #define CODEC_DSD_TX_THRESHOLD_SHIFT                        (12)
      +#define CODEC_MC_THRESHOLD(n)                               (((n) & 0xF) << 15)
      +#define CODEC_MC_THRESHOLD_MASK                             (0xF << 15)
      +#define CODEC_MC_THRESHOLD_SHIFT                            (15)
      +#define CODEC_IIR_RX_THRESHOLD(n)                           (((n) & 0x3F) << 19)
      +#define CODEC_IIR_RX_THRESHOLD_MASK                         (0x3F << 19)
      +#define CODEC_IIR_RX_THRESHOLD_SHIFT                        (19)
      +#define CODEC_IIR_TX_THRESHOLD(n)                           (((n) & 0x3F) << 25)
      +#define CODEC_IIR_TX_THRESHOLD_MASK                         (0x3F << 25)
      +#define CODEC_IIR_TX_THRESHOLD_SHIFT                        (25)
       
       // reg_0c
      -#define CODEC_CODEC_RX_OVERFLOW(n)                          (((n) & 0xFF) << 0)
      -#define CODEC_CODEC_RX_OVERFLOW_MASK                        (0xFF << 0)
      +#define CODEC_CODEC_RX_OVERFLOW(n)                          (((n) & 0x1F) << 0)
      +#define CODEC_CODEC_RX_OVERFLOW_MASK                        (0x1F << 0)
       #define CODEC_CODEC_RX_OVERFLOW_SHIFT                       (0)
      -#define CODEC_CODEC_RX_UNDERFLOW(n)                         (((n) & 0xFF) << 8)
      -#define CODEC_CODEC_RX_UNDERFLOW_MASK                       (0xFF << 8)
      -#define CODEC_CODEC_RX_UNDERFLOW_SHIFT                      (8)
      -#define CODEC_CODEC_TX_OVERFLOW                             (1 << 16)
      -#define CODEC_CODEC_TX_UNDERFLOW                            (1 << 17)
      -#define CODEC_DSD_RX_OVERFLOW                               (1 << 18)
      -#define CODEC_DSD_RX_UNDERFLOW                              (1 << 19)
      -#define CODEC_DSD_TX_OVERFLOW                               (1 << 20)
      -#define CODEC_DSD_TX_UNDERFLOW                              (1 << 21)
      +#define CODEC_CODEC_RX_UNDERFLOW(n)                         (((n) & 0x1F) << 5)
      +#define CODEC_CODEC_RX_UNDERFLOW_MASK                       (0x1F << 5)
      +#define CODEC_CODEC_RX_UNDERFLOW_SHIFT                      (5)
      +#define CODEC_CODEC_TX_OVERFLOW                             (1 << 10)
      +#define CODEC_CODEC_TX_UNDERFLOW                            (1 << 11)
      +#define CODEC_DSD_RX_OVERFLOW                               (1 << 12)
      +#define CODEC_DSD_RX_UNDERFLOW                              (1 << 13)
      +#define CODEC_DSD_TX_OVERFLOW                               (1 << 14)
      +#define CODEC_DSD_TX_UNDERFLOW                              (1 << 15)
      +#define CODEC_MC_OVERFLOW                                   (1 << 16)
      +#define CODEC_MC_UNDERFLOW                                  (1 << 17)
      +#define CODEC_IIR_RX_OVERFLOW                               (1 << 18)
      +#define CODEC_IIR_RX_UNDERFLOW                              (1 << 19)
      +#define CODEC_IIR_TX_OVERFLOW                               (1 << 20)
      +#define CODEC_IIR_TX_UNDERFLOW                              (1 << 21)
       #define CODEC_EVENT_TRIGGER                                 (1 << 22)
      -#define CODEC_VAD_FIND                                      (1 << 23)
      -#define CODEC_VAD_NOT_FIND                                  (1 << 24)
      -#define CODEC_BT_TRIGGER                                    (1 << 25)
      -#define CODEC_TSF_TRIGGER                                   (1 << 26)
      -#define CODEC_ADC_MAX_OVERFLOW                              (1 << 27)
      -#define CODEC_TIME_TRIGGER                                  (1 << 28)
      -#define CODEC_BT_TRIGGER1                                   (1 << 29)
      +#define CODEC_FB_CHECK_ERROR_TRIG_CH0                       (1 << 23)
      +#define CODEC_FB_CHECK_ERROR_TRIG_CH1                       (1 << 24)
      +#define CODEC_VAD_FIND                                      (1 << 25)
      +#define CODEC_VAD_NOT_FIND                                  (1 << 26)
      +#define CODEC_BT_TRIGGER                                    (1 << 27)
      +#define CODEC_ADC_MAX_OVERFLOW                              (1 << 28)
      +#define CODEC_TIME_TRIGGER_STATUS                           (1 << 29)
       
       // reg_10
      -#define CODEC_CODEC_RX_OVERFLOW_MSK(n)                      (((n) & 0xFF) << 0)
      -#define CODEC_CODEC_RX_OVERFLOW_MSK_MASK                    (0xFF << 0)
      +#define CODEC_CODEC_RX_OVERFLOW_MSK(n)                      (((n) & 0x1F) << 0)
      +#define CODEC_CODEC_RX_OVERFLOW_MSK_MASK                    (0x1F << 0)
       #define CODEC_CODEC_RX_OVERFLOW_MSK_SHIFT                   (0)
      -#define CODEC_CODEC_RX_UNDERFLOW_MSK(n)                     (((n) & 0xFF) << 8)
      -#define CODEC_CODEC_RX_UNDERFLOW_MSK_MASK                   (0xFF << 8)
      -#define CODEC_CODEC_RX_UNDERFLOW_MSK_SHIFT                  (8)
      -#define CODEC_CODEC_TX_OVERFLOW_MSK                         (1 << 16)
      -#define CODEC_CODEC_TX_UNDERFLOW_MSK                        (1 << 17)
      -#define CODEC_DSD_RX_OVERFLOW_MSK                           (1 << 18)
      -#define CODEC_DSD_RX_UNDERFLOW_MSK                          (1 << 19)
      -#define CODEC_DSD_TX_OVERFLOW_MSK                           (1 << 20)
      -#define CODEC_DSD_TX_UNDERFLOW_MSK                          (1 << 21)
      +#define CODEC_CODEC_RX_UNDERFLOW_MSK(n)                     (((n) & 0x1F) << 5)
      +#define CODEC_CODEC_RX_UNDERFLOW_MSK_MASK                   (0x1F << 5)
      +#define CODEC_CODEC_RX_UNDERFLOW_MSK_SHIFT                  (5)
      +#define CODEC_CODEC_TX_OVERFLOW_MSK                         (1 << 10)
      +#define CODEC_CODEC_TX_UNDERFLOW_MSK                        (1 << 11)
      +#define CODEC_DSD_RX_OVERFLOW_MSK                           (1 << 12)
      +#define CODEC_DSD_RX_UNDERFLOW_MSK                          (1 << 13)
      +#define CODEC_DSD_TX_OVERFLOW_MSK                           (1 << 14)
      +#define CODEC_DSD_TX_UNDERFLOW_MSK                          (1 << 15)
      +#define CODEC_MC_OVERFLOW_MSK                               (1 << 16)
      +#define CODEC_MC_UNDERFLOW_MSK                              (1 << 17)
      +#define CODEC_IIR_RX_OVERFLOW_MSK                           (1 << 18)
      +#define CODEC_IIR_RX_UNDERFLOW_MSK                          (1 << 19)
      +#define CODEC_IIR_TX_OVERFLOW_MSK                           (1 << 20)
      +#define CODEC_IIR_TX_UNDERFLOW_MSK                          (1 << 21)
       #define CODEC_EVENT_TRIGGER_MSK                             (1 << 22)
      -#define CODEC_VAD_FIND_MSK                                  (1 << 23)
      -#define CODEC_VAD_NOT_FIND_MSK                              (1 << 24)
      -#define CODEC_BT_TRIGGER_MSK                                (1 << 25)
      -#define CODEC_TSF_TRIGGER_MSK                               (1 << 26)
      -#define CODEC_ADC_MAX_OVERFLOW_MSK                          (1 << 27)
      -#define CODEC_TIME_TRIGGER_MSK                              (1 << 28)
      -#define CODEC_BT_TRIGGER1_MSK                               (1 << 29)
      +#define CODEC_FB_CHECK_ERROR_TRIG_CH0_MSK                   (1 << 23)
      +#define CODEC_FB_CHECK_ERROR_TRIG_CH1_MSK                   (1 << 24)
      +#define CODEC_VAD_FIND_MSK                                  (1 << 25)
      +#define CODEC_VAD_NOT_FIND_MSK                              (1 << 26)
      +#define CODEC_BT_TRIGGER_MSK                                (1 << 27)
      +#define CODEC_ADC_MAX_OVERFLOW_MSK                          (1 << 28)
      +#define CODEC_TIME_TRIGGER_MSK                              (1 << 29)
       
       // reg_14
       #define CODEC_FIFO_COUNT_CH0(n)                             (((n) & 0xF) << 0)
      @@ -261,26 +285,35 @@ struct CODEC_T {
       #define CODEC_FIFO_COUNT_CH4(n)                             (((n) & 0xF) << 16)
       #define CODEC_FIFO_COUNT_CH4_MASK                           (0xF << 16)
       #define CODEC_FIFO_COUNT_CH4_SHIFT                          (16)
      -#define CODEC_FIFO_COUNT_CH5(n)                             (((n) & 0xF) << 20)
      -#define CODEC_FIFO_COUNT_CH5_MASK                           (0xF << 20)
      -#define CODEC_FIFO_COUNT_CH5_SHIFT                          (20)
      -#define CODEC_FIFO_COUNT_CH6(n)                             (((n) & 0xF) << 24)
      -#define CODEC_FIFO_COUNT_CH6_MASK                           (0xF << 24)
      -#define CODEC_FIFO_COUNT_CH6_SHIFT                          (24)
      +#define CODEC_FIFO_COUNT_RX_DSD(n)                          (((n) & 0xF) << 20)
      +#define CODEC_FIFO_COUNT_RX_DSD_MASK                        (0xF << 20)
      +#define CODEC_FIFO_COUNT_RX_DSD_SHIFT                       (20)
      +#define CODEC_FIFO_COUNT_RX_IIR(n)                          (((n) & 0x3F) << 24)
      +#define CODEC_FIFO_COUNT_RX_IIR_MASK                        (0x3F << 24)
      +#define CODEC_FIFO_COUNT_RX_IIR_SHIFT                       (24)
       
       // reg_18
       #define CODEC_FIFO_COUNT_TX(n)                              (((n) & 0xF) << 0)
       #define CODEC_FIFO_COUNT_TX_MASK                            (0xF << 0)
       #define CODEC_FIFO_COUNT_TX_SHIFT                           (0)
      -#define CODEC_STATE_RX_CH(n)                                (((n) & 0x1FF) << 4)
      -#define CODEC_STATE_RX_CH_MASK                              (0x1FF << 4)
      +#define CODEC_STATE_RX_CH(n)                                (((n) & 0x3F) << 4)
      +#define CODEC_STATE_RX_CH_MASK                              (0x3F << 4)
       #define CODEC_STATE_RX_CH_SHIFT                             (4)
      -#define CODEC_FIFO_COUNT_TX_DSD(n)                          (((n) & 0x7) << 13)
      -#define CODEC_FIFO_COUNT_TX_DSD_MASK                        (0x7 << 13)
      -#define CODEC_FIFO_COUNT_TX_DSD_SHIFT                       (13)
      -#define CODEC_FIFO_COUNT_RX_DSD(n)                          (((n) & 0xF) << 16)
      -#define CODEC_FIFO_COUNT_RX_DSD_MASK                        (0xF << 16)
      -#define CODEC_FIFO_COUNT_RX_DSD_SHIFT                       (16)
      +#define CODEC_FIFO_COUNT_TX_DSD(n)                          (((n) & 0x7) << 10)
      +#define CODEC_FIFO_COUNT_TX_DSD_MASK                        (0x7 << 10)
      +#define CODEC_FIFO_COUNT_TX_DSD_SHIFT                       (10)
      +#define CODEC_MC_FIFO_COUNT(n)                              (((n) & 0xF) << 13)
      +#define CODEC_MC_FIFO_COUNT_MASK                            (0xF << 13)
      +#define CODEC_MC_FIFO_COUNT_SHIFT                           (13)
      +#define CODEC_FIFO_COUNT_TX_IIR(n)                          (((n) & 0x3F) << 17)
      +#define CODEC_FIFO_COUNT_TX_IIR_MASK                        (0x3F << 17)
      +#define CODEC_FIFO_COUNT_TX_IIR_SHIFT                       (17)
      +#define CODEC_FIFO_COUNT_CH5(n)                             (((n) & 0xF) << 23)
      +#define CODEC_FIFO_COUNT_CH5_MASK                           (0xF << 23)
      +#define CODEC_FIFO_COUNT_CH5_SHIFT                          (23)
      +#define CODEC_FIFO_COUNT_CH6(n)                             (((n) & 0xF) << 27)
      +#define CODEC_FIFO_COUNT_CH6_MASK                           (0xF << 27)
      +#define CODEC_FIFO_COUNT_CH6_SHIFT                          (27)
       
       // reg_1c
       #define CODEC_RX_FIFO_DATA(n)                               (((n) & 0xFFFFFFFF) << 0)
      @@ -313,24 +346,30 @@ struct CODEC_T {
       #define CODEC_RX_FIFO_DATA_SHIFT                            (0)
       
       // reg_34
      -#define CODEC_RX_FIFO_DATA(n)                               (((n) & 0xFFFFFFFF) << 0)
      -#define CODEC_RX_FIFO_DATA_MASK                             (0xFFFFFFFF << 0)
      -#define CODEC_RX_FIFO_DATA_SHIFT                            (0)
      +#define CODEC_RX_FIFO_DATA_DSD(n)                           (((n) & 0xFFFFFFFF) << 0)
      +#define CODEC_RX_FIFO_DATA_DSD_MASK                         (0xFFFFFFFF << 0)
      +#define CODEC_RX_FIFO_DATA_DSD_SHIFT                        (0)
       
       // reg_38
      -#define CODEC_RX_FIFO_DATA(n)                               (((n) & 0xFFFFFFFF) << 0)
      -#define CODEC_RX_FIFO_DATA_MASK                             (0xFFFFFFFF << 0)
      -#define CODEC_RX_FIFO_DATA_SHIFT                            (0)
      +#define CODEC_MC_FIFO_DATA(n)                               (((n) & 0xFFFFFFFF) << 0)
      +#define CODEC_MC_FIFO_DATA_MASK                             (0xFFFFFFFF << 0)
      +#define CODEC_MC_FIFO_DATA_SHIFT                            (0)
       
       // reg_3c
      -#define CODEC_RX_FIFO_DATA(n)                               (((n) & 0xFFFFFFFF) << 0)
      -#define CODEC_RX_FIFO_DATA_MASK                             (0xFFFFFFFF << 0)
      -#define CODEC_RX_FIFO_DATA_SHIFT                            (0)
      +#define CODEC_RX_FIFO_DATA_IIR(n)                           (((n) & 0xFFFFFFFF) << 0)
      +#define CODEC_RX_FIFO_DATA_IIR_MASK                         (0xFFFFFFFF << 0)
      +#define CODEC_RX_FIFO_DATA_IIR_SHIFT                        (0)
       
       // reg_40
      -#define CODEC_MODE_16BIT_ADC                                (1 << 0)
      -#define CODEC_MODE_24BIT_ADC                                (1 << 1)
      -#define CODEC_MODE_32BIT_ADC                                (1 << 2)
      +#define CODEC_MODE_16BIT_ADC_CH0                            (1 << 0)
      +#define CODEC_MODE_16BIT_ADC_CH1                            (1 << 1)
      +#define CODEC_MODE_16BIT_ADC_CH2                            (1 << 2)
      +#define CODEC_MODE_16BIT_ADC_CH3                            (1 << 3)
      +#define CODEC_MODE_16BIT_ADC_CH4                            (1 << 4)
      +#define CODEC_MODE_16BIT_ADC_CH5                            (1 << 5)
      +#define CODEC_MODE_16BIT_ADC_CH6                            (1 << 6)
      +#define CODEC_MODE_24BIT_ADC                                (1 << 7)
      +#define CODEC_MODE_32BIT_ADC                                (1 << 8)
       
       // reg_44
       #define CODEC_DUAL_CHANNEL_DAC                              (1 << 0)
      @@ -351,9 +390,15 @@ struct CODEC_T {
       #define CODEC_DSD_IN_16BIT                                  (1 << 9)
       
       // reg_4c
      -#define CODEC_RX_FIFO_DATA_DSD(n)                           (((n) & 0xFFFFFFFF) << 0)
      -#define CODEC_RX_FIFO_DATA_DSD_MASK                         (0xFFFFFFFF << 0)
      -#define CODEC_RX_FIFO_DATA_DSD_SHIFT                        (0)
      +#define CODEC_MC_ENABLE                                     (1 << 0)
      +#define CODEC_DUAL_CHANNEL_MC                               (1 << 1)
      +#define CODEC_MODE_16BIT_MC                                 (1 << 2)
      +#define CODEC_DMA_CTRL_MC                                   (1 << 3)
      +#define CODEC_MC_DELAY(n)                                   (((n) & 0xFF) << 4)
      +#define CODEC_MC_DELAY_MASK                                 (0xFF << 4)
      +#define CODEC_MC_DELAY_SHIFT                                (4)
      +#define CODEC_MC_RATE_SEL                                   (1 << 12)
      +#define CODEC_MODE_32BIT_MC                                 (1 << 13)
       
       // reg_50
       #define CODEC_CODEC_COUNT_KEEP(n)                           (((n) & 0xFFFFFFFF) << 0)
      @@ -375,45 +420,53 @@ struct CODEC_T {
       #define CODEC_CODEC_ADC_ENABLE_SEL_SHIFT                    (6)
       #define CODEC_GPIO_TRIGGER_DB_ENABLE                        (1 << 8)
       #define CODEC_STAMP_CLR_USED                                (1 << 9)
      -#define CODEC_EVENT_SEL(n)                                  (((n) & 0x3) << 10)
      -#define CODEC_EVENT_SEL_MASK                                (0x3 << 10)
      -#define CODEC_EVENT_SEL_SHIFT                               (10)
      -#define CODEC_EVENT_FOR_CAPTURE                             (1 << 12)
      -#define CODEC_EVENT_FOR_EN                                  (1 << 13)
      -#define CODEC_TSF_EVENT_SEL                                 (1 << 14)
      -#define CODEC_TEST_PORT_SEL(n)                              (((n) & 0x7) << 15)
      -#define CODEC_TEST_PORT_SEL_MASK                            (0x7 << 15)
      -#define CODEC_TEST_PORT_SEL_SHIFT                           (15)
      +#define CODEC_EVENT_SEL                                     (1 << 10)
      +#define CODEC_EVENT_FOR_CAPTURE                             (1 << 11)
      +#define CODEC_TEST_PORT_SEL(n)                              (((n) & 0x7) << 12)
      +#define CODEC_TEST_PORT_SEL_MASK                            (0x7 << 12)
      +#define CODEC_TEST_PORT_SEL_SHIFT                           (12)
      +#define CODEC_PLL_OSC_TRIGGER_SEL(n)                        (((n) & 0x3) << 15)
      +#define CODEC_PLL_OSC_TRIGGER_SEL_MASK                      (0x3 << 15)
      +#define CODEC_PLL_OSC_TRIGGER_SEL_SHIFT                     (15)
      +#define CODEC_FAULT_MUTE_DAC_ENABLE                         (1 << 17)
       
       // reg_58
      +#define CODEC_RX_FIFO_DATA(n)                               (((n) & 0xFFFFFFFF) << 0)
      +#define CODEC_RX_FIFO_DATA_MASK                             (0xFFFFFFFF << 0)
      +#define CODEC_RX_FIFO_DATA_SHIFT                            (0)
      +
      +// reg_5c
      +#define CODEC_RX_FIFO_DATA(n)                               (((n) & 0xFFFFFFFF) << 0)
      +#define CODEC_RX_FIFO_DATA_MASK                             (0xFFFFFFFF << 0)
      +#define CODEC_RX_FIFO_DATA_SHIFT                            (0)
       
       // reg_60
      -#define CODEC_EN_CLK_ADC_ANA(n)                             (((n) & 0x7) << 0)
      -#define CODEC_EN_CLK_ADC_ANA_MASK                           (0x7 << 0)
      +#define CODEC_EN_CLK_ADC_ANA(n)                             (((n) & 0x1F) << 0)
      +#define CODEC_EN_CLK_ADC_ANA_MASK                           (0x1F << 0)
       #define CODEC_EN_CLK_ADC_ANA_SHIFT                          (0)
      -#define CODEC_EN_CLK_ADC(n)                                 (((n) & 0x1FF) << 3)
      -#define CODEC_EN_CLK_ADC_MASK                               (0x1FF << 3)
      -#define CODEC_EN_CLK_ADC_SHIFT                              (3)
      -#define CODEC_EN_CLK_DAC                                    (1 << 12)
      -#define CODEC_POL_ADC_ANA(n)                                (((n) & 0x7) << 13)
      -#define CODEC_POL_ADC_ANA_MASK                              (0x7 << 13)
      -#define CODEC_POL_ADC_ANA_SHIFT                             (13)
      -#define CODEC_POL_DAC_OUT                                   (1 << 16)
      -#define CODEC_CFG_CLK_OUT(n)                                (((n) & 0x7) << 17)
      -#define CODEC_CFG_CLK_OUT_MASK                              (0x7 << 17)
      -#define CODEC_CFG_CLK_OUT_SHIFT                             (17)
      +#define CODEC_EN_CLK_ADC(n)                                 (((n) & 0x3F) << 5)
      +#define CODEC_EN_CLK_ADC_MASK                               (0x3F << 5)
      +#define CODEC_EN_CLK_ADC_SHIFT                              (5)
      +#define CODEC_EN_CLK_DAC                                    (1 << 11)
      +#define CODEC_POL_ADC_ANA(n)                                (((n) & 0x1F) << 12)
      +#define CODEC_POL_ADC_ANA_MASK                              (0x1F << 12)
      +#define CODEC_POL_ADC_ANA_SHIFT                             (12)
      +#define CODEC_POL_DAC_OUT                                   (1 << 17)
      +#define CODEC_CFG_CLK_OUT(n)                                (((n) & 0x7) << 18)
      +#define CODEC_CFG_CLK_OUT_MASK                              (0x7 << 18)
      +#define CODEC_CFG_CLK_OUT_SHIFT                             (18)
       
       // reg_64
      -#define CODEC_SOFT_RSTN_ADC_ANA(n)                          (((n) & 0x7) << 0)
      -#define CODEC_SOFT_RSTN_ADC_ANA_MASK                        (0x7 << 0)
      +#define CODEC_SOFT_RSTN_ADC_ANA(n)                          (((n) & 0x1F) << 0)
      +#define CODEC_SOFT_RSTN_ADC_ANA_MASK                        (0x1F << 0)
       #define CODEC_SOFT_RSTN_ADC_ANA_SHIFT                       (0)
      -#define CODEC_SOFT_RSTN_ADC(n)                              (((n) & 0x1FF) << 3)
      -#define CODEC_SOFT_RSTN_ADC_MASK                            (0x1FF << 3)
      -#define CODEC_SOFT_RSTN_ADC_SHIFT                           (3)
      -#define CODEC_SOFT_RSTN_DAC                                 (1 << 12)
      -#define CODEC_SOFT_RSTN_RS0                                 (1 << 13)
      -#define CODEC_SOFT_RSTN_IIR                                 (1 << 15)
      -#define CODEC_SOFT_RSTN_32K                                 (1 << 16)
      +#define CODEC_SOFT_RSTN_ADC(n)                              (((n) & 0x3F) << 5)
      +#define CODEC_SOFT_RSTN_ADC_MASK                            (0x3F << 5)
      +#define CODEC_SOFT_RSTN_ADC_SHIFT                           (5)
      +#define CODEC_SOFT_RSTN_DAC                                 (1 << 11)
      +#define CODEC_SOFT_RSTN_RS                                  (1 << 12)
      +#define CODEC_SOFT_RSTN_IIR                                 (1 << 13)
      +#define CODEC_SOFT_RSTN_32K                                 (1 << 14)
       
       // reg_68
       #define CODEC_RET1N_RF                                      (1 << 0)
      @@ -452,16 +505,35 @@ struct CODEC_T {
       #define CODEC_PGEN_ROM_1                                    (1 << 29)
       
       // reg_6c
      -#define CODEC_CODEC_DAC_HBF4_DELAY_SEL                      (1 << 0)
      -#define CODEC_TRIG_TIME(n)                                  (((n) & 0x3FFFFF) << 1)
      -#define CODEC_TRIG_TIME_MASK                                (0x3FFFFF << 1)
      -#define CODEC_TRIG_TIME_SHIFT                               (1)
      -#define CODEC_TRIG_TIME_ENABLE                              (1 << 23)
      -#define CODEC_GET_CNT_TRIG                                  (1 << 24)
      +#define CODEC_CODEC_RX5_6_OVERFLOW(n)                       (((n) & 0x3) << 0)
      +#define CODEC_CODEC_RX5_6_OVERFLOW_MASK                     (0x3 << 0)
      +#define CODEC_CODEC_RX5_6_OVERFLOW_SHIFT                    (0)
      +#define CODEC_CODEC_RX5_6_UNDERFLOW(n)                      (((n) & 0x3) << 2)
      +#define CODEC_CODEC_RX5_6_UNDERFLOW_MASK                    (0x3 << 2)
      +#define CODEC_CODEC_RX5_6_UNDERFLOW_SHIFT                   (2)
       
       // reg_70
      +#define CODEC_CODEC_RX5_6_OVERFLOW_MSK(n)                   (((n) & 0x3) << 0)
      +#define CODEC_CODEC_RX5_6_OVERFLOW_MSK_MASK                 (0x3 << 0)
      +#define CODEC_CODEC_RX5_6_OVERFLOW_MSK_SHIFT                (0)
      +#define CODEC_CODEC_RX5_6_UNDERFLOW_MSK(n)                  (((n) & 0x3) << 2)
      +#define CODEC_CODEC_RX5_6_UNDERFLOW_MSK_MASK                (0x3 << 2)
      +#define CODEC_CODEC_RX5_6_UNDERFLOW_MSK_SHIFT               (2)
       
       // reg_78
      +#define CODEC_CODEC_SIDE_TONE_CH_SEL                        (1 << 0)
      +#define CODEC_CODEC_ADC_IIR_CH0_SEL(n)                      (((n) & 0x7) << 1)
      +#define CODEC_CODEC_ADC_IIR_CH0_SEL_MASK                    (0x7 << 1)
      +#define CODEC_CODEC_ADC_IIR_CH0_SEL_SHIFT                   (1)
      +#define CODEC_CODEC_ADC_IIR_CH1_SEL(n)                      (((n) & 0x7) << 4)
      +#define CODEC_CODEC_ADC_IIR_CH1_SEL_MASK                    (0x7 << 4)
      +#define CODEC_CODEC_ADC_IIR_CH1_SEL_SHIFT                   (4)
      +#define CODEC_CODEC_DAC_HBF4_DELAY_SEL                      (1 << 7)
      +#define CODEC_TRIG_TIME(n)                                  (((n) & 0x3FFFFF) << 8)
      +#define CODEC_TRIG_TIME_MASK                                (0x3FFFFF << 8)
      +#define CODEC_TRIG_TIME_SHIFT                               (8)
      +#define CODEC_TRIG_TIME_ENABLE                              (1 << 30)
      +#define CODEC_GET_CNT_TRIG                                  (1 << 31)
       
       // reg_7c
       #define CODEC_RESERVED_REG1(n)                              (((n) & 0xFFFFFFFF) << 0)
      @@ -475,20 +547,20 @@ struct CODEC_T {
       #define CODEC_CODEC_ADC_EN_CH2                              (1 << 3)
       #define CODEC_CODEC_ADC_EN_CH3                              (1 << 4)
       #define CODEC_CODEC_ADC_EN_CH4                              (1 << 5)
      -#define CODEC_CODEC_SIDE_TONE_GAIN(n)                       (((n) & 0x1F) << 9)
      -#define CODEC_CODEC_SIDE_TONE_GAIN_MASK                     (0x1F << 9)
      -#define CODEC_CODEC_SIDE_TONE_GAIN_SHIFT                    (9)
      -#define CODEC_CODEC_SIDE_TONE_MIC_SEL(n)                    (((n) & 0x7) << 14)
      -#define CODEC_CODEC_ADC_LOOP                                (1 << 17)
      -#define CODEC_CODEC_LOOP_SEL_L(n)                           (((n) & 0x7) << 18)
      -#define CODEC_CODEC_LOOP_SEL_L_MASK                         (0x7 << 18)
      -#define CODEC_CODEC_LOOP_SEL_L_SHIFT                        (18)
      -#define CODEC_CODEC_LOOP_SEL_R(n)                           (((n) & 0x7) << 21)
      -#define CODEC_CODEC_LOOP_SEL_R_MASK                         (0x7 << 21)
      -#define CODEC_CODEC_LOOP_SEL_R_SHIFT                        (21)
      -#define CODEC_CODEC_TEST_PORT_SEL(n)                        (((n) & 0x1F) << 24)
      -#define CODEC_CODEC_TEST_PORT_SEL_MASK                      (0x1F << 24)
      -#define CODEC_CODEC_TEST_PORT_SEL_SHIFT                     (24)
      +#define CODEC_CODEC_SIDE_TONE_GAIN(n)                       (((n) & 0x1F) << 6)
      +#define CODEC_CODEC_SIDE_TONE_GAIN_MASK                     (0x1F << 6)
      +#define CODEC_CODEC_SIDE_TONE_GAIN_SHIFT                    (6)
      +#define CODEC_CODEC_SIDE_TONE_MIC_SEL                       (1 << 11)
      +#define CODEC_CODEC_ADC_LOOP                                (1 << 12)
      +#define CODEC_CODEC_LOOP_SEL_L(n)                           (((n) & 0x7) << 13)
      +#define CODEC_CODEC_LOOP_SEL_L_MASK                         (0x7 << 13)
      +#define CODEC_CODEC_LOOP_SEL_L_SHIFT                        (13)
      +#define CODEC_CODEC_LOOP_SEL_R(n)                           (((n) & 0x7) << 16)
      +#define CODEC_CODEC_LOOP_SEL_R_MASK                         (0x7 << 16)
      +#define CODEC_CODEC_LOOP_SEL_R_SHIFT                        (16)
      +#define CODEC_CODEC_TEST_PORT_SEL(n)                        (((n) & 0x1F) << 19)
      +#define CODEC_CODEC_TEST_PORT_SEL_MASK                      (0x1F << 19)
      +#define CODEC_CODEC_TEST_PORT_SEL_SHIFT                     (19)
       
       // reg_84
       #define CODEC_CODEC_ADC_SIGNED_CH0                          (1 << 0)
      @@ -548,34 +620,42 @@ struct CODEC_T {
       #define CODEC_CODEC_ADC_HBF3_SEL_CH2_SHIFT                  (30)
       
       // reg_90
      -#define CODEC_CODEC_ADC_DOWN_SEL_CH3(n)                     (((n) & 0x3) << 0)
      -#define CODEC_CODEC_ADC_DOWN_SEL_CH3_MASK                   (0x3 << 0)
      -#define CODEC_CODEC_ADC_DOWN_SEL_CH3_SHIFT                  (0)
      -#define CODEC_CODEC_ADC_HBF3_BYPASS_CH3                     (1 << 2)
      -#define CODEC_CODEC_ADC_HBF2_BYPASS_CH3                     (1 << 3)
      -#define CODEC_CODEC_ADC_HBF1_BYPASS_CH3                     (1 << 4)
      -#define CODEC_CODEC_ADC_GAIN_SEL_CH3                        (1 << 5)
      -#define CODEC_CODEC_ADC_GAIN_CH3(n)                         (((n) & 0xFFFFF) << 6)
      -#define CODEC_CODEC_ADC_GAIN_CH3_MASK                       (0xFFFFF << 6)
      -#define CODEC_CODEC_ADC_GAIN_CH3_SHIFT                      (6)
      -#define CODEC_CODEC_ADC_HBF3_SEL_CH3(n)                     (((n) & 0x3) << 26)
      -#define CODEC_CODEC_ADC_HBF3_SEL_CH3_MASK                   (0x3 << 26)
      -#define CODEC_CODEC_ADC_HBF3_SEL_CH3_SHIFT                  (26)
      +#define CODEC_CODEC_ADC_SIGNED_CH3                          (1 << 0)
      +#define CODEC_CODEC_ADC_IN_SEL_CH3(n)                       (((n) & 0x7) << 1)
      +#define CODEC_CODEC_ADC_IN_SEL_CH3_MASK                     (0x7 << 1)
      +#define CODEC_CODEC_ADC_IN_SEL_CH3_SHIFT                    (1)
      +#define CODEC_CODEC_ADC_DOWN_SEL_CH3(n)                     (((n) & 0x3) << 4)
      +#define CODEC_CODEC_ADC_DOWN_SEL_CH3_MASK                   (0x3 << 4)
      +#define CODEC_CODEC_ADC_DOWN_SEL_CH3_SHIFT                  (4)
      +#define CODEC_CODEC_ADC_HBF3_BYPASS_CH3                     (1 << 6)
      +#define CODEC_CODEC_ADC_HBF2_BYPASS_CH3                     (1 << 7)
      +#define CODEC_CODEC_ADC_HBF1_BYPASS_CH3                     (1 << 8)
      +#define CODEC_CODEC_ADC_GAIN_SEL_CH3                        (1 << 9)
      +#define CODEC_CODEC_ADC_GAIN_CH3(n)                         (((n) & 0xFFFFF) << 10)
      +#define CODEC_CODEC_ADC_GAIN_CH3_MASK                       (0xFFFFF << 10)
      +#define CODEC_CODEC_ADC_GAIN_CH3_SHIFT                      (10)
      +#define CODEC_CODEC_ADC_HBF3_SEL_CH3(n)                     (((n) & 0x3) << 30)
      +#define CODEC_CODEC_ADC_HBF3_SEL_CH3_MASK                   (0x3 << 30)
      +#define CODEC_CODEC_ADC_HBF3_SEL_CH3_SHIFT                  (30)
       
       // reg_94
      -#define CODEC_CODEC_ADC_DOWN_SEL_CH4(n)                     (((n) & 0x3) << 0)
      -#define CODEC_CODEC_ADC_DOWN_SEL_CH4_MASK                   (0x3 << 0)
      -#define CODEC_CODEC_ADC_DOWN_SEL_CH4_SHIFT                  (0)
      -#define CODEC_CODEC_ADC_HBF3_BYPASS_CH4                     (1 << 2)
      -#define CODEC_CODEC_ADC_HBF2_BYPASS_CH4                     (1 << 3)
      -#define CODEC_CODEC_ADC_HBF1_BYPASS_CH4                     (1 << 4)
      -#define CODEC_CODEC_ADC_GAIN_SEL_CH4                        (1 << 5)
      -#define CODEC_CODEC_ADC_GAIN_CH4(n)                         (((n) & 0xFFFFF) << 6)
      -#define CODEC_CODEC_ADC_GAIN_CH4_MASK                       (0xFFFFF << 6)
      -#define CODEC_CODEC_ADC_GAIN_CH4_SHIFT                      (6)
      -#define CODEC_CODEC_ADC_HBF3_SEL_CH4(n)                     (((n) & 0x3) << 26)
      -#define CODEC_CODEC_ADC_HBF3_SEL_CH4_MASK                   (0x3 << 26)
      -#define CODEC_CODEC_ADC_HBF3_SEL_CH4_SHIFT                  (26)
      +#define CODEC_CODEC_ADC_SIGNED_CH4                          (1 << 0)
      +#define CODEC_CODEC_ADC_IN_SEL_CH4(n)                       (((n) & 0x7) << 1)
      +#define CODEC_CODEC_ADC_IN_SEL_CH4_MASK                     (0x7 << 1)
      +#define CODEC_CODEC_ADC_IN_SEL_CH4_SHIFT                    (1)
      +#define CODEC_CODEC_ADC_DOWN_SEL_CH4(n)                     (((n) & 0x3) << 4)
      +#define CODEC_CODEC_ADC_DOWN_SEL_CH4_MASK                   (0x3 << 4)
      +#define CODEC_CODEC_ADC_DOWN_SEL_CH4_SHIFT                  (4)
      +#define CODEC_CODEC_ADC_HBF3_BYPASS_CH4                     (1 << 6)
      +#define CODEC_CODEC_ADC_HBF2_BYPASS_CH4                     (1 << 7)
      +#define CODEC_CODEC_ADC_HBF1_BYPASS_CH4                     (1 << 8)
      +#define CODEC_CODEC_ADC_GAIN_SEL_CH4                        (1 << 9)
      +#define CODEC_CODEC_ADC_GAIN_CH4(n)                         (((n) & 0xFFFFF) << 10)
      +#define CODEC_CODEC_ADC_GAIN_CH4_MASK                       (0xFFFFF << 10)
      +#define CODEC_CODEC_ADC_GAIN_CH4_SHIFT                      (10)
      +#define CODEC_CODEC_ADC_HBF3_SEL_CH4(n)                     (((n) & 0x3) << 30)
      +#define CODEC_CODEC_ADC_HBF3_SEL_CH4_MASK                   (0x3 << 30)
      +#define CODEC_CODEC_ADC_HBF3_SEL_CH4_SHIFT                  (30)
       
       // reg_98
       #define CODEC_CODEC_DAC_EN                                  (1 << 0)
      @@ -604,9 +684,11 @@ struct CODEC_T {
       #define CODEC_CODEC_DAC_LR_SWAP                             (1 << 24)
       #define CODEC_CODEC_DAC_SDM_H4_6M_CH0                       (1 << 25)
       #define CODEC_CODEC_DAC_SDM_H4_6M_CH1                       (1 << 26)
      -#define CODEC_CODEC_DAC_SDM_CLOSE                           (1 << 27)
      -#define CODEC_CODEC_DAC_USE_HBF4                            (1 << 28)
      -#define CODEC_CODEC_DAC_USE_HBF5                            (1 << 29)
      +#define CODEC_CODEC_DAC_L_FIR_UPSAMPLE                      (1 << 27)
      +#define CODEC_CODEC_DAC_R_FIR_UPSAMPLE                      (1 << 28)
      +#define CODEC_CODEC_DAC_SDM_CLOSE                           (1 << 29)
      +#define CODEC_CODEC_DAC_USE_HBF4                            (1 << 30)
      +#define CODEC_CODEC_DAC_USE_HBF5                            (1 << 31)
       
       // reg_9c
       #define CODEC_CODEC_DAC_GAIN_CH0(n)                         (((n) & 0xFFFFF) << 0)
      @@ -619,9 +701,9 @@ struct CODEC_T {
       #define CODEC_CODEC_ADC_GAIN_UPDATE_CH2                     (1 << 24)
       #define CODEC_CODEC_ADC_GAIN_UPDATE_CH3                     (1 << 25)
       #define CODEC_CODEC_ADC_GAIN_UPDATE_CH4                     (1 << 26)
      -#define CODEC_CODEC_DAC_GAIN_TRIGGER_SEL(n)                 (((n) & 0x3) << 30)
      -#define CODEC_CODEC_DAC_GAIN_TRIGGER_SEL_MASK               (0x3 << 30)
      -#define CODEC_CODEC_DAC_GAIN_TRIGGER_SEL_SHIFT              (30)
      +#define CODEC_CODEC_DAC_GAIN_TRIGGER_SEL(n)                 (((n) & 0x3) << 27)
      +#define CODEC_CODEC_DAC_GAIN_TRIGGER_SEL_MASK               (0x3 << 27)
      +#define CODEC_CODEC_DAC_GAIN_TRIGGER_SEL_SHIFT              (27)
       
       // reg_a0
       #define CODEC_CODEC_DAC_GAIN_CH1(n)                         (((n) & 0xFFFFF) << 0)
      @@ -645,12 +727,11 @@ struct CODEC_T {
       // reg_a4
       #define CODEC_CODEC_PDM_ENABLE                              (1 << 0)
       #define CODEC_CODEC_PDM_DATA_INV                            (1 << 1)
      -#define CODEC_CODEC_PDM_RATE_SEL(n)                         (((n) & 0x3) << 2)
      -#define CODEC_CODEC_PDM_RATE_SEL_MASK                       (0x3 << 2)
      -#define CODEC_CODEC_PDM_RATE_SEL_SHIFT                      (2)
      -#define CODEC_CODEC_PDM_ADC_SEL_CH0                         (1 << 4)
      -#define CODEC_CODEC_PDM_ADC_SEL_CH1                         (1 << 5)
      -#define CODEC_CODEC_PDM_ADC_SEL_CH2                         (1 << 6)
      +#define CODEC_CODEC_PDM_ADC_SEL_CH0                         (1 << 2)
      +#define CODEC_CODEC_PDM_ADC_SEL_CH1                         (1 << 3)
      +#define CODEC_CODEC_PDM_ADC_SEL_CH2                         (1 << 4)
      +#define CODEC_CODEC_PDM_ADC_SEL_CH3                         (1 << 5)
      +#define CODEC_CODEC_PDM_ADC_SEL_CH4                         (1 << 6)
       
       // reg_a8
       #define CODEC_CODEC_PDM_MUX_CH0(n)                          (((n) & 0x7) << 0)
      @@ -668,28 +749,41 @@ struct CODEC_T {
       #define CODEC_CODEC_PDM_MUX_CH4(n)                          (((n) & 0x7) << 12)
       #define CODEC_CODEC_PDM_MUX_CH4_MASK                        (0x7 << 12)
       #define CODEC_CODEC_PDM_MUX_CH4_SHIFT                       (12)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH0(n)                    (((n) & 0x3) << 18)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH0_MASK                  (0x3 << 18)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH0_SHIFT                 (18)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH1(n)                    (((n) & 0x3) << 20)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH1_MASK                  (0x3 << 20)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH1_SHIFT                 (20)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH2(n)                    (((n) & 0x3) << 22)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH2_MASK                  (0x3 << 22)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH2_SHIFT                 (22)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH3(n)                    (((n) & 0x3) << 24)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH3_MASK                  (0x3 << 24)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH3_SHIFT                 (24)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH4(n)                    (((n) & 0x3) << 26)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH4_MASK                  (0x3 << 26)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH4_SHIFT                 (26)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH5(n)                    (((n) & 0x3) << 28)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH5_MASK                  (0x3 << 28)
      -#define CODEC_CODEC_PDM_CAP_PHASE_CH5_SHIFT                 (28)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH0(n)                    (((n) & 0x3) << 15)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH0_MASK                  (0x3 << 15)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH0_SHIFT                 (15)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH1(n)                    (((n) & 0x3) << 17)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH1_MASK                  (0x3 << 17)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH1_SHIFT                 (17)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH2(n)                    (((n) & 0x3) << 19)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH2_MASK                  (0x3 << 19)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH2_SHIFT                 (19)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH3(n)                    (((n) & 0x3) << 21)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH3_MASK                  (0x3 << 21)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH3_SHIFT                 (21)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH4(n)                    (((n) & 0x3) << 23)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH4_MASK                  (0x3 << 23)
      +#define CODEC_CODEC_PDM_CAP_PHASE_CH4_SHIFT                 (23)
       
       // reg_b0
      +#define CODEC_CODEC_CLASSG_EN                               (1 << 0)
      +#define CODEC_CODEC_CLASSG_QUICK_DOWN                       (1 << 1)
      +#define CODEC_CODEC_CLASSG_STEP_3_4N                        (1 << 2)
      +#define CODEC_CODEC_CLASSG_LR                               (1 << 3)
      +#define CODEC_CODEC_CLASSG_WINDOW(n)                        (((n) & 0xFFF) << 4)
      +#define CODEC_CODEC_CLASSG_WINDOW_MASK                      (0xFFF << 4)
      +#define CODEC_CODEC_CLASSG_WINDOW_SHIFT                     (4)
       
       // reg_b4
      +#define CODEC_CODEC_CLASSG_THD0(n)                          (((n) & 0xFF) << 0)
      +#define CODEC_CODEC_CLASSG_THD0_MASK                        (0xFF << 0)
      +#define CODEC_CODEC_CLASSG_THD0_SHIFT                       (0)
      +#define CODEC_CODEC_CLASSG_THD1(n)                          (((n) & 0xFF) << 8)
      +#define CODEC_CODEC_CLASSG_THD1_MASK                        (0xFF << 8)
      +#define CODEC_CODEC_CLASSG_THD1_SHIFT                       (8)
      +#define CODEC_CODEC_CLASSG_THD2(n)                          (((n) & 0xFF) << 16)
      +#define CODEC_CODEC_CLASSG_THD2_MASK                        (0xFF << 16)
      +#define CODEC_CODEC_CLASSG_THD2_SHIFT                       (16)
       
       // reg_b8
       #define CODEC_CODEC_DSD_ENABLE_L                            (1 << 0)
      @@ -700,106 +794,140 @@ struct CODEC_T {
       #define CODEC_CODEC_DSD_SAMPLE_RATE_SHIFT                   (3)
       
       // reg_bc
      +#define CODEC_CODEC_ADC_MC_EN_CH0                           (1 << 0)
      +#define CODEC_CODEC_ADC_MC_EN_CH1                           (1 << 1)
      +#define CODEC_CODEC_FEEDBACK_MC_EN_CH0                      (1 << 2)
      +#define CODEC_CODEC_FEEDBACK_MC_EN_CH1                      (1 << 3)
       
       // reg_c0
       #define CODEC_CODEC_DRE_ENABLE_CH0                          (1 << 0)
      -#define CODEC_CODEC_DRE_STEP_MODE_CH0(n)                    (((n) & 0x7) << 1)
      -#define CODEC_CODEC_DRE_STEP_MODE_CH0_MASK                  (0x7 << 1)
      +#define CODEC_CODEC_DRE_STEP_MODE_CH0(n)                    (((n) & 0x3) << 1)
      +#define CODEC_CODEC_DRE_STEP_MODE_CH0_MASK                  (0x3 << 1)
       #define CODEC_CODEC_DRE_STEP_MODE_CH0_SHIFT                 (1)
      -#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH0(n)                 (((n) & 0xF) << 4)
      -#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH0_MASK               (0xF << 4)
      -#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH0_SHIFT              (4)
      -#define CODEC_CODEC_DRE_DELAY_CH0(n)                        (((n) & 0xFF) << 8)
      -#define CODEC_CODEC_DRE_DELAY_CH0_MASK                      (0xFF << 8)
      -#define CODEC_CODEC_DRE_DELAY_CH0_SHIFT                     (8)
      -#define CODEC_CODEC_DRE_AMP_HIGH_CH0(n)                     (((n) & 0xFFFF) << 16)
      -#define CODEC_CODEC_DRE_AMP_HIGH_CH0_MASK                   (0xFFFF << 16)
      -#define CODEC_CODEC_DRE_AMP_HIGH_CH0_SHIFT                  (16)
      -#define CODEC_CODEC_DRE_THD_DB_OFFSET_SIGN_CH0              (1 << 25)
      -#define CODEC_CODEC_DRE_GAIN_OFFSET_CH0(n)                  (((n) & 0x1F) << 26)
      -#define CODEC_CODEC_DRE_GAIN_OFFSET_CH0_MASK                (0x1F << 26)
      -#define CODEC_CODEC_DRE_GAIN_OFFSET_CH0_SHIFT               (26)
      +#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH0(n)                (((n) & 0xF) << 3)
      +#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH0_MASK              (0xF << 3)
      +#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH0_SHIFT             (3)
      +#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH0(n)                 (((n) & 0xF) << 7)
      +#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH0_MASK               (0xF << 7)
      +#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH0_SHIFT              (7)
      +#define CODEC_CODEC_DRE_DELAY_CH0(n)                        (((n) & 0x3F) << 11)
      +#define CODEC_CODEC_DRE_DELAY_CH0_MASK                      (0x3F << 11)
      +#define CODEC_CODEC_DRE_DELAY_CH0_SHIFT                     (11)
      +#define CODEC_CODEC_DRE_THD_DB_OFFSET_SIGN_CH0              (1 << 17)
      +#define CODEC_CODEC_DRE_GAIN_OFFSET_CH0(n)                  (((n) & 0x7) << 18)
      +#define CODEC_CODEC_DRE_GAIN_OFFSET_CH0_MASK                (0x7 << 18)
      +#define CODEC_CODEC_DRE_GAIN_OFFSET_CH0_SHIFT               (18)
       
       // reg_c4
      -#define CODEC_CODEC_DRE_WINDOW_CH0(n)                       (((n) & 0x1FFFFF) << 0)
      -#define CODEC_CODEC_DRE_WINDOW_CH0_MASK                     (0x1FFFFF << 0)
      -#define CODEC_CODEC_DRE_WINDOW_CH0_SHIFT                    (0)
      -#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH0(n)                (((n) & 0xF) << 21)
      -#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH0_MASK              (0xF << 21)
      -#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH0_SHIFT             (21)
      +#define CODEC_CODEC_DRE_AMP_HIGH_CH0(n)                     (((n) & 0x7FF) << 0)
      +#define CODEC_CODEC_DRE_AMP_HIGH_CH0_MASK                   (0x7FF << 0)
      +#define CODEC_CODEC_DRE_AMP_HIGH_CH0_SHIFT                  (0)
      +#define CODEC_CODEC_DRE_WINDOW_CH0(n)                       (((n) & 0x1FFFFF) << 11)
      +#define CODEC_CODEC_DRE_WINDOW_CH0_MASK                     (0x1FFFFF << 11)
      +#define CODEC_CODEC_DRE_WINDOW_CH0_SHIFT                    (11)
       
       // reg_c8
       #define CODEC_CODEC_DRE_ENABLE_CH1                          (1 << 0)
      -#define CODEC_CODEC_DRE_STEP_MODE_CH1(n)                    (((n) & 0x7) << 1)
      -#define CODEC_CODEC_DRE_STEP_MODE_CH1_MASK                  (0x7 << 1)
      +#define CODEC_CODEC_DRE_STEP_MODE_CH1(n)                    (((n) & 0x3) << 1)
      +#define CODEC_CODEC_DRE_STEP_MODE_CH1_MASK                  (0x3 << 1)
       #define CODEC_CODEC_DRE_STEP_MODE_CH1_SHIFT                 (1)
      -#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH1(n)                 (((n) & 0xF) << 4)
      -#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH1_MASK               (0xF << 4)
      -#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH1_SHIFT              (4)
      -#define CODEC_CODEC_DRE_DELAY_CH1(n)                        (((n) & 0xFF) << 8)
      -#define CODEC_CODEC_DRE_DELAY_CH1_MASK                      (0xFF << 8)
      -#define CODEC_CODEC_DRE_DELAY_CH1_SHIFT                     (8)
      -#define CODEC_CODEC_DRE_AMP_HIGH_CH1(n)                     (((n) & 0xFFFF) << 16)
      -#define CODEC_CODEC_DRE_AMP_HIGH_CH1_MASK                   (0xFFFF << 16)
      -#define CODEC_CODEC_DRE_AMP_HIGH_CH1_SHIFT                  (16)
      -#define CODEC_CODEC_DRE_THD_DB_OFFSET_SIGN_CH1              (1 << 25)
      -#define CODEC_CODEC_DRE_GAIN_OFFSET_CH1(n)                  (((n) & 0x1F) << 26)
      -#define CODEC_CODEC_DRE_GAIN_OFFSET_CH1_MASK                (0x1F << 26)
      -#define CODEC_CODEC_DRE_GAIN_OFFSET_CH1_SHIFT               (26)
      +#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH1(n)                (((n) & 0xF) << 3)
      +#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH1_MASK              (0xF << 3)
      +#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH1_SHIFT             (3)
      +#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH1(n)                 (((n) & 0xF) << 7)
      +#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH1_MASK               (0xF << 7)
      +#define CODEC_CODEC_DRE_INI_ANA_GAIN_CH1_SHIFT              (7)
      +#define CODEC_CODEC_DRE_DELAY_CH1(n)                        (((n) & 0x3F) << 11)
      +#define CODEC_CODEC_DRE_DELAY_CH1_MASK                      (0x3F << 11)
      +#define CODEC_CODEC_DRE_DELAY_CH1_SHIFT                     (11)
      +#define CODEC_CODEC_DRE_THD_DB_OFFSET_SIGN_CH1              (1 << 17)
      +#define CODEC_CODEC_DRE_GAIN_OFFSET_CH1(n)                  (((n) & 0x7) << 18)
      +#define CODEC_CODEC_DRE_GAIN_OFFSET_CH1_MASK                (0x7 << 18)
      +#define CODEC_CODEC_DRE_GAIN_OFFSET_CH1_SHIFT               (18)
       
       // reg_cc
      -#define CODEC_CODEC_DRE_WINDOW_CH1(n)                       (((n) & 0x1FFFFF) << 0)
      -#define CODEC_CODEC_DRE_WINDOW_CH1_MASK                     (0x1FFFFF << 0)
      -#define CODEC_CODEC_DRE_WINDOW_CH1_SHIFT                    (0)
      -#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH1(n)                (((n) & 0xF) << 21)
      -#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH1_MASK              (0xF << 21)
      -#define CODEC_CODEC_DRE_THD_DB_OFFSET_CH1_SHIFT             (21)
      +#define CODEC_CODEC_DRE_AMP_HIGH_CH1(n)                     (((n) & 0x7FF) << 0)
      +#define CODEC_CODEC_DRE_AMP_HIGH_CH1_MASK                   (0x7FF << 0)
      +#define CODEC_CODEC_DRE_AMP_HIGH_CH1_SHIFT                  (0)
      +#define CODEC_CODEC_DRE_WINDOW_CH1(n)                       (((n) & 0x1FFFFF) << 11)
      +#define CODEC_CODEC_DRE_WINDOW_CH1_MASK                     (0x1FFFFF << 11)
      +#define CODEC_CODEC_DRE_WINDOW_CH1_SHIFT                    (11)
       
       // reg_d0
      -#define CODEC_CODEC_DRE_ANA_GAIN_CH0_SYNC(n)                (((n) & 0x1F) << 0)
      -#define CODEC_CODEC_DRE_ANA_GAIN_CH0_SYNC_MASK              (0x1F << 0)
      -#define CODEC_CODEC_DRE_ANA_GAIN_CH0_SYNC_SHIFT             (0)
      -#define CODEC_CODEC_DRE_COUNT_CH0_SYNC(n)                   (((n) & 0x1FFFFF) << 5)
      -#define CODEC_CODEC_DRE_COUNT_CH0_SYNC_MASK                 (0x1FFFFF << 5)
      -#define CODEC_CODEC_DRE_COUNT_CH0_SYNC_SHIFT                (5)
      +#define CODEC_CODEC_ANC_ENABLE_CH0                          (1 << 0)
      +#define CODEC_CODEC_ANC_ENABLE_CH1                          (1 << 1)
      +#define CODEC_CODEC_DUAL_ANC_CH0                            (1 << 2)
      +#define CODEC_CODEC_DUAL_ANC_CH1                            (1 << 3)
      +#define CODEC_CODEC_ANC_MUTE_CH0                            (1 << 4)
      +#define CODEC_CODEC_ANC_MUTE_CH1                            (1 << 5)
      +#define CODEC_CODEC_FF_CH0_FIR_EN                           (1 << 6)
      +#define CODEC_CODEC_FF_CH1_FIR_EN                           (1 << 7)
      +#define CODEC_CODEC_FB_CH0_FIR_EN                           (1 << 8)
      +#define CODEC_CODEC_FB_CH1_FIR_EN                           (1 << 9)
      +#define CODEC_CODEC_ANC_RATE_SEL                            (1 << 10)
      +#define CODEC_CODEC_ANC_FF_SR_SEL(n)                        (((n) & 0x3) << 11)
      +#define CODEC_CODEC_ANC_FF_SR_SEL_MASK                      (0x3 << 11)
      +#define CODEC_CODEC_ANC_FF_SR_SEL_SHIFT                     (11)
      +#define CODEC_CODEC_ANC_FF_IN_PHASE_SEL(n)                  (((n) & 0x7) << 13)
      +#define CODEC_CODEC_ANC_FF_IN_PHASE_SEL_MASK                (0x7 << 13)
      +#define CODEC_CODEC_ANC_FF_IN_PHASE_SEL_SHIFT               (13)
      +#define CODEC_CODEC_ANC_FB_SR_SEL(n)                        (((n) & 0x3) << 16)
      +#define CODEC_CODEC_ANC_FB_SR_SEL_MASK                      (0x3 << 16)
      +#define CODEC_CODEC_ANC_FB_SR_SEL_SHIFT                     (16)
      +#define CODEC_CODEC_ANC_FB_IN_PHASE_SEL(n)                  (((n) & 0x7) << 18)
      +#define CODEC_CODEC_ANC_FB_IN_PHASE_SEL_MASK                (0x7 << 18)
      +#define CODEC_CODEC_ANC_FB_IN_PHASE_SEL_SHIFT               (18)
      +#define CODEC_CODEC_FEEDBACK_CH0                            (1 << 21)
      +#define CODEC_CODEC_FEEDBACK_CH1                            (1 << 22)
      +#define CODEC_CODEC_ADC_FIR_DS_EN_CH2                       (1 << 23)
      +#define CODEC_CODEC_ADC_FIR_DS_SEL_CH2                      (1 << 24)
      +#define CODEC_CODEC_ADC_FIR_DS_EN_CH3                       (1 << 25)
      +#define CODEC_CODEC_ADC_FIR_DS_SEL_CH3                      (1 << 26)
       
       // reg_d4
      -#define CODEC_CODEC_DRE_ANA_GAIN_CH1_SYNC(n)                (((n) & 0x1F) << 0)
      -#define CODEC_CODEC_DRE_ANA_GAIN_CH1_SYNC_MASK              (0x1F << 0)
      -#define CODEC_CODEC_DRE_ANA_GAIN_CH1_SYNC_SHIFT             (0)
      -#define CODEC_CODEC_DRE_COUNT_CH1_SYNC(n)                   (((n) & 0x1FFFFF) << 5)
      -#define CODEC_CODEC_DRE_COUNT_CH1_SYNC_MASK                 (0x1FFFFF << 5)
      -#define CODEC_CODEC_DRE_COUNT_CH1_SYNC_SHIFT                (5)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FF_CH0(n)                 (((n) & 0xFFF) << 0)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FF_CH0_MASK               (0xFFF << 0)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FF_CH0_SHIFT              (0)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FF_CH1(n)                 (((n) & 0xFFF) << 12)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FF_CH1_MASK               (0xFFF << 12)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FF_CH1_SHIFT              (12)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_PASS0_FF_CH0              (1 << 24)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_PASS0_FF_CH1              (1 << 25)
       
       // reg_d8
      -#define CODEC_CODEC_DEQ_IIR_GAIN_EXT_TH(n)                  (((n) & 0xFFFFFFFF) << 0)
      -#define CODEC_CODEC_DEQ_IIR_GAIN_EXT_TH_MASK                (0xFFFFFFFF << 0)
      -#define CODEC_CODEC_DEQ_IIR_GAIN_EXT_TH_SHIFT               (0)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FB_CH0(n)                 (((n) & 0xFFF) << 0)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FB_CH0_MASK               (0xFFF << 0)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FB_CH0_SHIFT              (0)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FB_CH1(n)                 (((n) & 0xFFF) << 12)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FB_CH1_MASK               (0xFFF << 12)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_FB_CH1_SHIFT              (12)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_PASS0_FB_CH0              (1 << 24)
      +#define CODEC_CODEC_ANC_MUTE_GAIN_PASS0_FB_CH1              (1 << 25)
       
       // reg_dc
      -#define CODEC_CODEC_DEQ_IIR_ENABLE                          (1 << 0)
      -#define CODEC_CODEC_DEQ_IIR_IIRA_ENABLE                     (1 << 1)
      -#define CODEC_CODEC_DEQ_IIR_IIRB_ENABLE                     (1 << 2)
      -#define CODEC_CODEC_DEQ_IIR_CH0_BYPASS                      (1 << 3)
      -#define CODEC_CODEC_DEQ_IIR_CH1_BYPASS                      (1 << 4)
      -#define CODEC_CODEC_DEQ_IIR_GAINCAL_EXT_CH0_BYPASS          (1 << 5)
      -#define CODEC_CODEC_DEQ_IIR_GAINCAL_EXT_CH1_BYPASS          (1 << 6)
      -#define CODEC_CODEC_DEQ_IIR_GAINUSE_EXT_CH0_BYPASS          (1 << 7)
      -#define CODEC_CODEC_DEQ_IIR_GAINUSE_EXT_CH1_BYPASS          (1 << 8)
      -#define CODEC_CODEC_DEQ_IIR_COUNT_CH0(n)                    (((n) & 0x3F) << 9)
      -#define CODEC_CODEC_DEQ_IIR_COUNT_CH0_MASK                  (0x3F << 9)
      -#define CODEC_CODEC_DEQ_IIR_COUNT_CH0_SHIFT                 (9)
      -#define CODEC_CODEC_DEQ_IIR_COUNT_CH1(n)                    (((n) & 0x3F) << 15)
      -#define CODEC_CODEC_DEQ_IIR_COUNT_CH1_MASK                  (0x3F << 15)
      -#define CODEC_CODEC_DEQ_IIR_COUNT_CH1_SHIFT                 (15)
      -#define CODEC_CODEC_DEQ_IIR_COEF_SWAP                       (1 << 21)
      -#define CODEC_CODEC_DEQ_IIR_AUTO_STOP                       (1 << 22)
      -#define CODEC_CODEC_DEQ_IIR_GAIN_EXT_UPDATE_CH0             (1 << 23)
      -#define CODEC_CODEC_DEQ_IIR_GAIN_EXT_UPDATE_CH1             (1 << 24)
      -#define CODEC_CODEC_DEQ_IIR_GAIN_EXT_SEL_CH0                (1 << 25)
      -#define CODEC_CODEC_DEQ_IIR_GAIN_EXT_SEL_CH1                (1 << 26)
      -#define CODEC_CODEC_DAC_L_IIR_ENABLE                        (1 << 27)
      -#define CODEC_CODEC_DAC_R_IIR_ENABLE                        (1 << 28)
      +#define CODEC_CODEC_IIR_ENABLE                              (1 << 0)
      +#define CODEC_CODEC_IIR_CH0_BYPASS                          (1 << 1)
      +#define CODEC_CODEC_IIR_CH1_BYPASS                          (1 << 2)
      +#define CODEC_CODEC_IIR_CH2_BYPASS                          (1 << 3)
      +#define CODEC_CODEC_IIR_CH3_BYPASS                          (1 << 4)
      +#define CODEC_CODEC_IIR_COUNT_CH0(n)                        (((n) & 0xF) << 5)
      +#define CODEC_CODEC_IIR_COUNT_CH0_MASK                      (0xF << 5)
      +#define CODEC_CODEC_IIR_COUNT_CH0_SHIFT                     (5)
      +#define CODEC_CODEC_IIR_COUNT_CH1(n)                        (((n) & 0xF) << 9)
      +#define CODEC_CODEC_IIR_COUNT_CH1_MASK                      (0xF << 9)
      +#define CODEC_CODEC_IIR_COUNT_CH1_SHIFT                     (9)
      +#define CODEC_CODEC_IIR_COUNT_CH2(n)                        (((n) & 0xF) << 13)
      +#define CODEC_CODEC_IIR_COUNT_CH2_MASK                      (0xF << 13)
      +#define CODEC_CODEC_IIR_COUNT_CH2_SHIFT                     (13)
      +#define CODEC_CODEC_IIR_COUNT_CH3(n)                        (((n) & 0xF) << 17)
      +#define CODEC_CODEC_IIR_COUNT_CH3_MASK                      (0xF << 17)
      +#define CODEC_CODEC_IIR_COUNT_CH3_SHIFT                     (17)
      +#define CODEC_CODEC_DAC_L_IIR_ENABLE                        (1 << 21)
      +#define CODEC_CODEC_DAC_R_IIR_ENABLE                        (1 << 22)
      +#define CODEC_CODEC_ADC_CH0_IIR_ENABLE                      (1 << 23)
      +#define CODEC_CODEC_ADC_CH1_IIR_ENABLE                      (1 << 24)
      +#define CODEC_CODEC_IIR_COEF_SWAP                           (1 << 25)
      +#define CODEC_CODEC_IIR_COEF_SWAP_STATUS                    (1 << 26)
       
       // reg_e0
       #define CODEC_CODEC_DAC_DC_CH0(n)                           (((n) & 0x7FFFF) << 0)
      @@ -816,22 +944,22 @@ struct CODEC_T {
       #define CODEC_CODEC_RESAMPLE_DAC_ENABLE                     (1 << 0)
       #define CODEC_CODEC_RESAMPLE_DAC_L_ENABLE                   (1 << 1)
       #define CODEC_CODEC_RESAMPLE_DAC_R_ENABLE                   (1 << 2)
      -#define CODEC_CODEC_RESAMPLE_DAC_FIFO_ENABLE                (1 << 3)
      -#define CODEC_CODEC_RESAMPLE_ADC_ENABLE                     (1 << 4)
      -#define CODEC_CODEC_RESAMPLE_ADC_CH_CNT(n)                  (((n) & 0x7) << 5)
      -#define CODEC_CODEC_RESAMPLE_ADC_CH_CNT_MASK                (0x7 << 5)
      -#define CODEC_CODEC_RESAMPLE_ADC_CH_CNT_SHIFT               (5)
      -#define CODEC_CODEC_RESAMPLE_DAC_PHASE_UPDATE               (1 << 8)
      -#define CODEC_CODEC_RESAMPLE_DAC_UPDATE_TRIGGER_SEL(n)      (((n) & 0x3) << 9)
      -#define CODEC_CODEC_RESAMPLE_DAC_UPDATE_TRIGGER_SEL_MASK    (0x3 << 9)
      -#define CODEC_CODEC_RESAMPLE_DAC_UPDATE_TRIGGER_SEL_SHIFT   (9)
      -#define CODEC_CODEC_RESAMPLE_ADC_PHASE_UPDATE               (1 << 11)
      -#define CODEC_CODEC_RESAMPLE_ADC_UPDATE_TRIGGER_SEL(n)      (((n) & 0x3) << 12)
      -#define CODEC_CODEC_RESAMPLE_ADC_UPDATE_TRIGGER_SEL_MASK    (0x3 << 12)
      -#define CODEC_CODEC_RESAMPLE_ADC_UPDATE_TRIGGER_SEL_SHIFT   (12)
      -#define CODEC_CODEC_RESAMPLE_DAC_ENABLE_TRIGGER_SEL(n)      (((n) & 0x3) << 14)
      -#define CODEC_CODEC_RESAMPLE_DAC_ENABLE_TRIGGER_SEL_MASK    (0x3 << 14)
      -#define CODEC_CODEC_RESAMPLE_DAC_ENABLE_TRIGGER_SEL_SHIFT   (14)
      +#define CODEC_CODEC_RESAMPLE_ADC_ENABLE                     (1 << 3)
      +#define CODEC_CODEC_RESAMPLE_ADC_DUAL_CH                    (1 << 4)
      +#define CODEC_CODEC_RESAMPLE_ADC_CH0_SEL(n)                 (((n) & 0x7) << 5)
      +#define CODEC_CODEC_RESAMPLE_ADC_CH0_SEL_MASK               (0x7 << 5)
      +#define CODEC_CODEC_RESAMPLE_ADC_CH0_SEL_SHIFT              (5)
      +#define CODEC_CODEC_RESAMPLE_ADC_CH1_SEL(n)                 (((n) & 0x7) << 8)
      +#define CODEC_CODEC_RESAMPLE_ADC_CH1_SEL_MASK               (0x7 << 8)
      +#define CODEC_CODEC_RESAMPLE_ADC_CH1_SEL_SHIFT              (8)
      +#define CODEC_CODEC_RESAMPLE_DAC_PHASE_UPDATE               (1 << 11)
      +#define CODEC_CODEC_RESAMPLE_DAC_TRIGGER_SEL(n)             (((n) & 0x3) << 12)
      +#define CODEC_CODEC_RESAMPLE_DAC_TRIGGER_SEL_MASK           (0x3 << 12)
      +#define CODEC_CODEC_RESAMPLE_DAC_TRIGGER_SEL_SHIFT          (12)
      +#define CODEC_CODEC_RESAMPLE_ADC_PHASE_UPDATE               (1 << 14)
      +#define CODEC_CODEC_RESAMPLE_ADC_TRIGGER_SEL(n)             (((n) & 0x3) << 15)
      +#define CODEC_CODEC_RESAMPLE_ADC_TRIGGER_SEL_MASK           (0x3 << 15)
      +#define CODEC_CODEC_RESAMPLE_ADC_TRIGGER_SEL_SHIFT          (15)
       
       // reg_e8
       #define CODEC_CODEC_DAC_DC_CH1(n)                           (((n) & 0x7FFFF) << 0)
      @@ -848,19 +976,21 @@ struct CODEC_T {
       #define CODEC_CODEC_RAMP_STEP_CH0(n)                        (((n) & 0xFFF) << 0)
       #define CODEC_CODEC_RAMP_STEP_CH0_MASK                      (0xFFF << 0)
       #define CODEC_CODEC_RAMP_STEP_CH0_SHIFT                     (0)
      -#define CODEC_CODEC_RAMP_EN_CH0                             (1 << 12)
      -#define CODEC_CODEC_RAMP_INTERVAL_CH0(n)                    (((n) & 0x7) << 13)
      -#define CODEC_CODEC_RAMP_INTERVAL_CH0_MASK                  (0x7 << 13)
      -#define CODEC_CODEC_RAMP_INTERVAL_CH0_SHIFT                 (13)
      +#define CODEC_CODEC_RAMP_DIRECT_CH0                         (1 << 12)
      +#define CODEC_CODEC_RAMP_EN_CH0                             (1 << 13)
      +#define CODEC_CODEC_RAMP_INTERVAL_CH0(n)                    (((n) & 0x7) << 14)
      +#define CODEC_CODEC_RAMP_INTERVAL_CH0_MASK                  (0x7 << 14)
      +#define CODEC_CODEC_RAMP_INTERVAL_CH0_SHIFT                 (14)
       
       // reg_f0
       #define CODEC_CODEC_RAMP_STEP_CH1(n)                        (((n) & 0xFFF) << 0)
       #define CODEC_CODEC_RAMP_STEP_CH1_MASK                      (0xFFF << 0)
       #define CODEC_CODEC_RAMP_STEP_CH1_SHIFT                     (0)
      -#define CODEC_CODEC_RAMP_EN_CH1                             (1 << 12)
      -#define CODEC_CODEC_RAMP_INTERVAL_CH1(n)                    (((n) & 0x7) << 13)
      -#define CODEC_CODEC_RAMP_INTERVAL_CH1_MASK                  (0x7 << 13)
      -#define CODEC_CODEC_RAMP_INTERVAL_CH1_SHIFT                 (13)
      +#define CODEC_CODEC_RAMP_DIRECT_CH1                         (1 << 12)
      +#define CODEC_CODEC_RAMP_EN_CH1                             (1 << 13)
      +#define CODEC_CODEC_RAMP_INTERVAL_CH1(n)                    (((n) & 0x7) << 14)
      +#define CODEC_CODEC_RAMP_INTERVAL_CH1_MASK                  (0x7 << 14)
      +#define CODEC_CODEC_RAMP_INTERVAL_CH1_SHIFT                 (14)
       
       // reg_f4
       #define CODEC_CODEC_RESAMPLE_DAC_PHASE_INC(n)               (((n) & 0xFFFFFFFF) << 0)
      @@ -873,38 +1003,246 @@ struct CODEC_T {
       #define CODEC_CODEC_RESAMPLE_ADC_PHASE_INC_SHIFT            (0)
       
       // reg_100
      +#define CODEC_FIR_STREAM_ENABLE_CH0                         (1 << 0)
      +#define CODEC_FIR_STREAM_ENABLE_CH1                         (1 << 1)
      +#define CODEC_FIR_STREAM_ENABLE_CH2                         (1 << 2)
      +#define CODEC_FIR_STREAM_ENABLE_CH3                         (1 << 3)
      +#define CODEC_FIR_ENABLE_CH0                                (1 << 4)
      +#define CODEC_FIR_ENABLE_CH1                                (1 << 5)
      +#define CODEC_FIR_ENABLE_CH2                                (1 << 6)
      +#define CODEC_FIR_ENABLE_CH3                                (1 << 7)
      +#define CODEC_DMA_CTRL_RX_FIR                               (1 << 8)
      +#define CODEC_DMA_CTRL_TX_FIR                               (1 << 9)
      +#define CODEC_FIR_UPSAMPLE_CH0                              (1 << 10)
      +#define CODEC_FIR_UPSAMPLE_CH1                              (1 << 11)
      +#define CODEC_FIR_UPSAMPLE_CH2                              (1 << 12)
      +#define CODEC_FIR_UPSAMPLE_CH3                              (1 << 13)
      +#define CODEC_MODE_32BIT_FIR                                (1 << 14)
      +#define CODEC_FIR_RESERVED_REG0                             (1 << 15)
      +#define CODEC_MODE_16BIT_FIR_TX_CH0                         (1 << 16)
      +#define CODEC_MODE_16BIT_FIR_RX_CH0                         (1 << 17)
      +#define CODEC_MODE_16BIT_FIR_TX_CH1                         (1 << 18)
      +#define CODEC_MODE_16BIT_FIR_RX_CH1                         (1 << 19)
      +#define CODEC_MODE_16BIT_FIR_TX_CH2                         (1 << 20)
      +#define CODEC_MODE_16BIT_FIR_RX_CH2                         (1 << 21)
      +#define CODEC_MODE_16BIT_FIR_TX_CH3                         (1 << 22)
      +#define CODEC_MODE_16BIT_FIR_RX_CH3                         (1 << 23)
       
       // reg_104
      +#define CODEC_FIR_ACCESS_OFFSET_CH0(n)                      (((n) & 0x7) << 0)
      +#define CODEC_FIR_ACCESS_OFFSET_CH0_MASK                    (0x7 << 0)
      +#define CODEC_FIR_ACCESS_OFFSET_CH0_SHIFT                   (0)
      +#define CODEC_FIR_ACCESS_OFFSET_CH1(n)                      (((n) & 0x7) << 3)
      +#define CODEC_FIR_ACCESS_OFFSET_CH1_MASK                    (0x7 << 3)
      +#define CODEC_FIR_ACCESS_OFFSET_CH1_SHIFT                   (3)
      +#define CODEC_FIR_ACCESS_OFFSET_CH2(n)                      (((n) & 0x7) << 6)
      +#define CODEC_FIR_ACCESS_OFFSET_CH2_MASK                    (0x7 << 6)
      +#define CODEC_FIR_ACCESS_OFFSET_CH2_SHIFT                   (6)
      +#define CODEC_FIR_ACCESS_OFFSET_CH3(n)                      (((n) & 0x7) << 9)
      +#define CODEC_FIR_ACCESS_OFFSET_CH3_MASK                    (0x7 << 9)
      +#define CODEC_FIR_ACCESS_OFFSET_CH3_SHIFT                   (9)
       
       // reg_108
      +#define CODEC_STREAM0_FIR1_CH0                              (1 << 0)
      +#define CODEC_FIR_MODE_CH0(n)                               (((n) & 0x3) << 1)
      +#define CODEC_FIR_MODE_CH0_MASK                             (0x3 << 1)
      +#define CODEC_FIR_MODE_CH0_SHIFT                            (1)
      +#define CODEC_FIR_ORDER_CH0(n)                              (((n) & 0x3FF) << 3)
      +#define CODEC_FIR_ORDER_CH0_MASK                            (0x3FF << 3)
      +#define CODEC_FIR_ORDER_CH0_SHIFT                           (3)
      +#define CODEC_FIR_SAMPLE_START_CH0(n)                       (((n) & 0x1FF) << 13)
      +#define CODEC_FIR_SAMPLE_START_CH0_MASK                     (0x1FF << 13)
      +#define CODEC_FIR_SAMPLE_START_CH0_SHIFT                    (13)
      +#define CODEC_FIR_SAMPLE_NUM_CH0(n)                         (((n) & 0x1FF) << 22)
      +#define CODEC_FIR_SAMPLE_NUM_CH0_MASK                       (0x1FF << 22)
      +#define CODEC_FIR_SAMPLE_NUM_CH0_SHIFT                      (22)
      +#define CODEC_FIR_DO_REMAP_CH0                              (1 << 31)
       
       // reg_10c
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH0(n)                   (((n) & 0x1FF) << 0)
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH0_MASK                 (0x1FF << 0)
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH0_SHIFT                (0)
      +#define CODEC_FIR_SLIDE_OFFSET_CH0(n)                       (((n) & 0x3F) << 9)
      +#define CODEC_FIR_SLIDE_OFFSET_CH0_MASK                     (0x3F << 9)
      +#define CODEC_FIR_SLIDE_OFFSET_CH0_SHIFT                    (9)
      +#define CODEC_FIR_BURST_LENGTH_CH0(n)                       (((n) & 0x3F) << 15)
      +#define CODEC_FIR_BURST_LENGTH_CH0_MASK                     (0x3F << 15)
      +#define CODEC_FIR_BURST_LENGTH_CH0_SHIFT                    (15)
      +#define CODEC_FIR_GAIN_SEL_CH0(n)                           (((n) & 0xF) << 21)
      +#define CODEC_FIR_GAIN_SEL_CH0_MASK                         (0xF << 21)
      +#define CODEC_FIR_GAIN_SEL_CH0_SHIFT                        (21)
      +#define CODEC_FIR_LOOP_NUM_CH0(n)                           (((n) & 0x7F) << 25)
      +#define CODEC_FIR_LOOP_NUM_CH0_MASK                         (0x7F << 25)
      +#define CODEC_FIR_LOOP_NUM_CH0_SHIFT                        (25)
       
       // reg_110
      +#define CODEC_STREAM0_FIR1_CH1                              (1 << 0)
      +#define CODEC_FIR_MODE_CH1(n)                               (((n) & 0x3) << 1)
      +#define CODEC_FIR_MODE_CH1_MASK                             (0x3 << 1)
      +#define CODEC_FIR_MODE_CH1_SHIFT                            (1)
      +#define CODEC_FIR_ORDER_CH1(n)                              (((n) & 0x3FF) << 3)
      +#define CODEC_FIR_ORDER_CH1_MASK                            (0x3FF << 3)
      +#define CODEC_FIR_ORDER_CH1_SHIFT                           (3)
      +#define CODEC_FIR_SAMPLE_START_CH1(n)                       (((n) & 0x1FF) << 13)
      +#define CODEC_FIR_SAMPLE_START_CH1_MASK                     (0x1FF << 13)
      +#define CODEC_FIR_SAMPLE_START_CH1_SHIFT                    (13)
      +#define CODEC_FIR_SAMPLE_NUM_CH1(n)                         (((n) & 0x1FF) << 22)
      +#define CODEC_FIR_SAMPLE_NUM_CH1_MASK                       (0x1FF << 22)
      +#define CODEC_FIR_SAMPLE_NUM_CH1_SHIFT                      (22)
      +#define CODEC_FIR_DO_REMAP_CH1                              (1 << 31)
       
       // reg_114
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH1(n)                   (((n) & 0x1FF) << 0)
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH1_MASK                 (0x1FF << 0)
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH1_SHIFT                (0)
      +#define CODEC_FIR_SLIDE_OFFSET_CH1(n)                       (((n) & 0x3F) << 9)
      +#define CODEC_FIR_SLIDE_OFFSET_CH1_MASK                     (0x3F << 9)
      +#define CODEC_FIR_SLIDE_OFFSET_CH1_SHIFT                    (9)
      +#define CODEC_FIR_BURST_LENGTH_CH1(n)                       (((n) & 0x3F) << 15)
      +#define CODEC_FIR_BURST_LENGTH_CH1_MASK                     (0x3F << 15)
      +#define CODEC_FIR_BURST_LENGTH_CH1_SHIFT                    (15)
      +#define CODEC_FIR_GAIN_SEL_CH1(n)                           (((n) & 0xF) << 21)
      +#define CODEC_FIR_GAIN_SEL_CH1_MASK                         (0xF << 21)
      +#define CODEC_FIR_GAIN_SEL_CH1_SHIFT                        (21)
      +#define CODEC_FIR_LOOP_NUM_CH1(n)                           (((n) & 0x7F) << 25)
      +#define CODEC_FIR_LOOP_NUM_CH1_MASK                         (0x7F << 25)
      +#define CODEC_FIR_LOOP_NUM_CH1_SHIFT                        (25)
       
       // reg_118
      +#define CODEC_STREAM0_FIR1_CH2                              (1 << 0)
      +#define CODEC_FIR_MODE_CH2(n)                               (((n) & 0x3) << 1)
      +#define CODEC_FIR_MODE_CH2_MASK                             (0x3 << 1)
      +#define CODEC_FIR_MODE_CH2_SHIFT                            (1)
      +#define CODEC_FIR_ORDER_CH2(n)                              (((n) & 0x3FF) << 3)
      +#define CODEC_FIR_ORDER_CH2_MASK                            (0x3FF << 3)
      +#define CODEC_FIR_ORDER_CH2_SHIFT                           (3)
      +#define CODEC_FIR_SAMPLE_START_CH2(n)                       (((n) & 0x1FF) << 13)
      +#define CODEC_FIR_SAMPLE_START_CH2_MASK                     (0x1FF << 13)
      +#define CODEC_FIR_SAMPLE_START_CH2_SHIFT                    (13)
      +#define CODEC_FIR_SAMPLE_NUM_CH2(n)                         (((n) & 0x1FF) << 22)
      +#define CODEC_FIR_SAMPLE_NUM_CH2_MASK                       (0x1FF << 22)
      +#define CODEC_FIR_SAMPLE_NUM_CH2_SHIFT                      (22)
      +#define CODEC_FIR_DO_REMAP_CH2                              (1 << 31)
       
       // reg_11c
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH2(n)                   (((n) & 0x1FF) << 0)
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH2_MASK                 (0x1FF << 0)
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH2_SHIFT                (0)
      +#define CODEC_FIR_SLIDE_OFFSET_CH2(n)                       (((n) & 0x3F) << 9)
      +#define CODEC_FIR_SLIDE_OFFSET_CH2_MASK                     (0x3F << 9)
      +#define CODEC_FIR_SLIDE_OFFSET_CH2_SHIFT                    (9)
      +#define CODEC_FIR_BURST_LENGTH_CH2(n)                       (((n) & 0x3F) << 15)
      +#define CODEC_FIR_BURST_LENGTH_CH2_MASK                     (0x3F << 15)
      +#define CODEC_FIR_BURST_LENGTH_CH2_SHIFT                    (15)
      +#define CODEC_FIR_GAIN_SEL_CH2(n)                           (((n) & 0xF) << 21)
      +#define CODEC_FIR_GAIN_SEL_CH2_MASK                         (0xF << 21)
      +#define CODEC_FIR_GAIN_SEL_CH2_SHIFT                        (21)
      +#define CODEC_FIR_LOOP_NUM_CH2(n)                           (((n) & 0x7F) << 25)
      +#define CODEC_FIR_LOOP_NUM_CH2_MASK                         (0x7F << 25)
      +#define CODEC_FIR_LOOP_NUM_CH2_SHIFT                        (25)
       
       // reg_120
      +#define CODEC_STREAM0_FIR1_CH3                              (1 << 0)
      +#define CODEC_FIR_MODE_CH3(n)                               (((n) & 0x3) << 1)
      +#define CODEC_FIR_MODE_CH3_MASK                             (0x3 << 1)
      +#define CODEC_FIR_MODE_CH3_SHIFT                            (1)
      +#define CODEC_FIR_ORDER_CH3(n)                              (((n) & 0x3FF) << 3)
      +#define CODEC_FIR_ORDER_CH3_MASK                            (0x3FF << 3)
      +#define CODEC_FIR_ORDER_CH3_SHIFT                           (3)
      +#define CODEC_FIR_SAMPLE_START_CH3(n)                       (((n) & 0x1FF) << 13)
      +#define CODEC_FIR_SAMPLE_START_CH3_MASK                     (0x1FF << 13)
      +#define CODEC_FIR_SAMPLE_START_CH3_SHIFT                    (13)
      +#define CODEC_FIR_SAMPLE_NUM_CH3(n)                         (((n) & 0x1FF) << 22)
      +#define CODEC_FIR_SAMPLE_NUM_CH3_MASK                       (0x1FF << 22)
      +#define CODEC_FIR_SAMPLE_NUM_CH3_SHIFT                      (22)
      +#define CODEC_FIR_DO_REMAP_CH3                              (1 << 31)
       
       // reg_124
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH3(n)                   (((n) & 0x1FF) << 0)
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH3_MASK                 (0x1FF << 0)
      +#define CODEC_FIR_RESULT_BASE_ADDR_CH3_SHIFT                (0)
      +#define CODEC_FIR_SLIDE_OFFSET_CH3(n)                       (((n) & 0x3F) << 9)
      +#define CODEC_FIR_SLIDE_OFFSET_CH3_MASK                     (0x3F << 9)
      +#define CODEC_FIR_SLIDE_OFFSET_CH3_SHIFT                    (9)
      +#define CODEC_FIR_BURST_LENGTH_CH3(n)                       (((n) & 0x3F) << 15)
      +#define CODEC_FIR_BURST_LENGTH_CH3_MASK                     (0x3F << 15)
      +#define CODEC_FIR_BURST_LENGTH_CH3_SHIFT                    (15)
      +#define CODEC_FIR_GAIN_SEL_CH3(n)                           (((n) & 0xF) << 21)
      +#define CODEC_FIR_GAIN_SEL_CH3_MASK                         (0xF << 21)
      +#define CODEC_FIR_GAIN_SEL_CH3_SHIFT                        (21)
      +#define CODEC_FIR_LOOP_NUM_CH3(n)                           (((n) & 0x7F) << 25)
      +#define CODEC_FIR_LOOP_NUM_CH3_MASK                         (0x7F << 25)
      +#define CODEC_FIR_LOOP_NUM_CH3_SHIFT                        (25)
       
       // reg_128
      +#define CODEC_AHB_IIR_ENABLE                                (1 << 0)
      +#define CODEC_DO_SAMPLE_INI                                 (1 << 1)
      +#define CODEC_USE_SAMPLE_HIGH_HALF                          (1 << 2)
      +#define CODEC_AHB_IIR_IF_EN                                 (1 << 3)
      +#define CODEC_DMA_CTRL_RX_IIR                               (1 << 4)
      +#define CODEC_DMA_CTRL_TX_IIR                               (1 << 5)
      +#define CODEC_MODE_32BIT_IIR                                (1 << 6)
      +#define CODEC_MODE_16BIT_IIR                                (1 << 7)
      +#define CODEC_AHB_IIR_MAX_CNT(n)                            (((n) & 0xF) << 8)
      +#define CODEC_AHB_IIR_MAX_CNT_MASK                          (0xF << 8)
      +#define CODEC_AHB_IIR_MAX_CNT_SHIFT                         (8)
      +#define CODEC_IIR_MULTI_CYCLE_MODE(n)                       (((n) & 0x3) << 12)
      +#define CODEC_IIR_MULTI_CYCLE_MODE_MASK                     (0x3 << 12)
      +#define CODEC_IIR_MULTI_CYCLE_MODE_SHIFT                    (12)
       
       // reg_130
      +#define CODEC_CODEC_FB_CHECK_ENABLE_CH0                     (1 << 0)
      +#define CODEC_CODEC_FB_CHECK_ACC_SAMPLE_RATE_CH0(n)         (((n) & 0x3) << 1)
      +#define CODEC_CODEC_FB_CHECK_ACC_SAMPLE_RATE_CH0_MASK       (0x3 << 1)
      +#define CODEC_CODEC_FB_CHECK_ACC_SAMPLE_RATE_CH0_SHIFT      (1)
      +#define CODEC_CODEC_FB_CHECK_SRC_SEL_CH0(n)                 (((n) & 0x3) << 3)
      +#define CODEC_CODEC_FB_CHECK_SRC_SEL_CH0_MASK               (0x3 << 3)
      +#define CODEC_CODEC_FB_CHECK_SRC_SEL_CH0_SHIFT              (3)
      +#define CODEC_CODEC_FB_CHECK_KEEP_SEL_CH0                   (1 << 5)
      +#define CODEC_CODEC_FB_CHECK_ACC_WINDOW_CH0(n)              (((n) & 0xFFF) << 6)
      +#define CODEC_CODEC_FB_CHECK_ACC_WINDOW_CH0_MASK            (0xFFF << 6)
      +#define CODEC_CODEC_FB_CHECK_ACC_WINDOW_CH0_SHIFT           (6)
      +#define CODEC_CODEC_FB_CHECK_TRIG_WINDOW_CH0(n)             (((n) & 0x3FF) << 18)
      +#define CODEC_CODEC_FB_CHECK_TRIG_WINDOW_CH0_MASK           (0x3FF << 18)
      +#define CODEC_CODEC_FB_CHECK_TRIG_WINDOW_CH0_SHIFT          (18)
      +#define CODEC_CODEC_FB_CHECK_KEEP_CH0                       (1 << 28)
       
       // reg_134
      +#define CODEC_CODEC_FB_CHECK_ENABLE_CH1                     (1 << 0)
      +#define CODEC_CODEC_FB_CHECK_ACC_SAMPLE_RATE_CH1(n)         (((n) & 0x3) << 1)
      +#define CODEC_CODEC_FB_CHECK_ACC_SAMPLE_RATE_CH1_MASK       (0x3 << 1)
      +#define CODEC_CODEC_FB_CHECK_ACC_SAMPLE_RATE_CH1_SHIFT      (1)
      +#define CODEC_CODEC_FB_CHECK_SRC_SEL_CH1(n)                 (((n) & 0x3) << 3)
      +#define CODEC_CODEC_FB_CHECK_SRC_SEL_CH1_MASK               (0x3 << 3)
      +#define CODEC_CODEC_FB_CHECK_SRC_SEL_CH1_SHIFT              (3)
      +#define CODEC_CODEC_FB_CHECK_KEEP_SEL_CH1                   (1 << 5)
      +#define CODEC_CODEC_FB_CHECK_ACC_WINDOW_CH1(n)              (((n) & 0xFFF) << 6)
      +#define CODEC_CODEC_FB_CHECK_ACC_WINDOW_CH1_MASK            (0xFFF << 6)
      +#define CODEC_CODEC_FB_CHECK_ACC_WINDOW_CH1_SHIFT           (6)
      +#define CODEC_CODEC_FB_CHECK_TRIG_WINDOW_CH1(n)             (((n) & 0x3FF) << 18)
      +#define CODEC_CODEC_FB_CHECK_TRIG_WINDOW_CH1_MASK           (0x3FF << 18)
      +#define CODEC_CODEC_FB_CHECK_TRIG_WINDOW_CH1_SHIFT          (18)
      +#define CODEC_CODEC_FB_CHECK_KEEP_CH1                       (1 << 28)
       
       // reg_138
      +#define CODEC_CODEC_FB_CHECK_THRESHOLD_CH0(n)               (((n) & 0xFFFFFFFF) << 0)
      +#define CODEC_CODEC_FB_CHECK_THRESHOLD_CH0_MASK             (0xFFFFFFFF << 0)
      +#define CODEC_CODEC_FB_CHECK_THRESHOLD_CH0_SHIFT            (0)
       
       // reg_13c
      +#define CODEC_CODEC_FB_CHECK_THRESHOLD_CH1(n)               (((n) & 0xFFFFFFFF) << 0)
      +#define CODEC_CODEC_FB_CHECK_THRESHOLD_CH1_MASK             (0xFFFFFFFF << 0)
      +#define CODEC_CODEC_FB_CHECK_THRESHOLD_CH1_SHIFT            (0)
       
       // reg_140
      +#define CODEC_CODEC_FB_CHECK_DATA_AVG_KEEP_CH0(n)           (((n) & 0xFFFFFFFF) << 0)
      +#define CODEC_CODEC_FB_CHECK_DATA_AVG_KEEP_CH0_MASK         (0xFFFFFFFF << 0)
      +#define CODEC_CODEC_FB_CHECK_DATA_AVG_KEEP_CH0_SHIFT        (0)
       
       // reg_144
      +#define CODEC_CODEC_FB_CHECK_DATA_AVG_KEEP_CH1(n)           (((n) & 0xFFFFFFFF) << 0)
      +#define CODEC_CODEC_FB_CHECK_DATA_AVG_KEEP_CH1_MASK         (0xFFFFFFFF << 0)
      +#define CODEC_CODEC_FB_CHECK_DATA_AVG_KEEP_CH1_SHIFT        (0)
       
       // reg_148
       #define CODEC_VAD_EN                                        (1 << 0)
      @@ -912,7 +1250,7 @@ struct CODEC_T {
       #define CODEC_VAD_DC_CANCEL_BYPASS                          (1 << 2)
       #define CODEC_VAD_PRE_BYPASS                                (1 << 3)
       #define CODEC_VAD_DIG_MODE                                  (1 << 4)
      -#define CODEC_VAD_FINISH                                    (1 << 24)
      +#define CODEC_VAD_FINISH                                    (1 << 5)
       
       // reg_14c
       #define CODEC_VAD_U_DC(n)                                   (((n) & 0xF) << 0)
      @@ -970,9 +1308,12 @@ struct CODEC_T {
       #define CODEC_VAD_PSD_TH2_SHIFT                             (0)
       
       // reg_160
      -#define CODEC_VAD_MEM_ADDR_CNT(n)                           (((n) & 0x1FFFF) << 0)
      -#define CODEC_VAD_MEM_ADDR_CNT_MASK                         (0x1FFFF << 0)
      -#define CODEC_VAD_MEM_ADDR_CNT_SHIFT                        (0)
      +#define CODEC_VAD_MEM_ADDR_CNT(n)                           (((n) & 0x1FFF) << 1)
      +#define CODEC_VAD_MEM_ADDR_CNT_MASK                         (0x1FFF << 1)
      +#define CODEC_VAD_MEM_ADDR_CNT_SHIFT                        (1)
      +#define CODEC_VAD_MEM_DATA_CNT(n)                           (((n) & 0x1FFF) << 15)
      +#define CODEC_VAD_MEM_DATA_CNT_MASK                         (0x1FFF << 15)
      +#define CODEC_VAD_MEM_DATA_CNT_SHIFT                        (15)
       
       // reg_164
       #define CODEC_SMIN_SYC(n)                                   (((n) & 0x7FFFFFF) << 0)
      @@ -985,6 +1326,18 @@ struct CODEC_T {
       #define CODEC_PSD_SYC_SHIFT                                 (0)
       
       // reg_170
      +#define CODEC_FIR_CH0_STATE(n)                              (((n) & 0xFF) << 0)
      +#define CODEC_FIR_CH0_STATE_MASK                            (0xFF << 0)
      +#define CODEC_FIR_CH0_STATE_SHIFT                           (0)
      +#define CODEC_FIR_CH1_STATE(n)                              (((n) & 0xFF) << 8)
      +#define CODEC_FIR_CH1_STATE_MASK                            (0xFF << 8)
      +#define CODEC_FIR_CH1_STATE_SHIFT                           (8)
      +#define CODEC_FIR_CH2_STATE(n)                              (((n) & 0xFF) << 16)
      +#define CODEC_FIR_CH2_STATE_MASK                            (0xFF << 16)
      +#define CODEC_FIR_CH2_STATE_SHIFT                           (16)
      +#define CODEC_FIR_CH3_STATE(n)                              (((n) & 0xFF) << 24)
      +#define CODEC_FIR_CH3_STATE_MASK                            (0xFF << 24)
      +#define CODEC_FIR_CH3_STATE_SHIFT                           (24)
       
       // reg_174
       #define CODEC_CODEC_ADC_DC_DOUT_CH0_SYNC(n)                 (((n) & 0x1FFFFF) << 0)
      @@ -1042,96 +1395,96 @@ struct CODEC_T {
       #define CODEC_CODEC_ADC_DC_UPDATE_CH4                       (1 << 15)
       
       // reg_1a0
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP0_CH0(n)               (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP0_CH0_MASK             (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP0_CH0_SHIFT            (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP1_CH0(n)               (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP1_CH0_MASK             (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP1_CH0_SHIFT            (14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP0(n)                   (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP0_MASK                 (0x3FFF << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP0_SHIFT                (0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP1(n)                   (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP1_MASK                 (0x3FFF << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP1_SHIFT                (14)
       
       // reg_1a4
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP2_CH0(n)               (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP2_CH0_MASK             (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP2_CH0_SHIFT            (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP3_CH0(n)               (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP3_CH0_MASK             (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP3_CH0_SHIFT            (14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP2(n)                   (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP2_MASK                 (0x3FFF << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP2_SHIFT                (0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP3(n)                   (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP3_MASK                 (0x3FFF << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP3_SHIFT                (14)
       
       // reg_1a8
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP4_CH0(n)               (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP4_CH0_MASK             (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP4_CH0_SHIFT            (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP5_CH0(n)               (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP5_CH0_MASK             (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP5_CH0_SHIFT            (14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP4(n)                   (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP4_MASK                 (0x3FFF << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP4_SHIFT                (0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP5(n)                   (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP5_MASK                 (0x3FFF << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP5_SHIFT                (14)
       
       // reg_1ac
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP6_CH0(n)               (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP6_CH0_MASK             (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP6_CH0_SHIFT            (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP7_CH0(n)               (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP7_CH0_MASK             (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP7_CH0_SHIFT            (14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP6(n)                   (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP6_MASK                 (0x3FFF << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP6_SHIFT                (0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP7(n)                   (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP7_MASK                 (0x3FFF << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP7_SHIFT                (14)
       
       // reg_1b0
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP8_CH0(n)               (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP8_CH0_MASK             (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP8_CH0_SHIFT            (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP9_CH0(n)               (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP9_CH0_MASK             (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP9_CH0_SHIFT            (14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP8(n)                   (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP8_MASK                 (0x3FFF << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP8_SHIFT                (0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP9(n)                   (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP9_MASK                 (0x3FFF << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP9_SHIFT                (14)
       
       // reg_1b4
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP10_CH0(n)              (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP10_CH0_MASK            (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP10_CH0_SHIFT           (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP11_CH0(n)              (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP11_CH0_MASK            (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP11_CH0_SHIFT           (14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP10(n)                  (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP10_MASK                (0x3FFF << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP10_SHIFT               (0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP11(n)                  (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP11_MASK                (0x3FFF << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP11_SHIFT               (14)
       
       // reg_1b8
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP12_CH0(n)              (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP12_CH0_MASK            (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP12_CH0_SHIFT           (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP13_CH0(n)              (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP13_CH0_MASK            (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP13_CH0_SHIFT           (14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP12(n)                  (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP12_MASK                (0x3FFF << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP12_SHIFT               (0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP13(n)                  (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP13_MASK                (0x3FFF << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP13_SHIFT               (14)
       
       // reg_1bc
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP14_CH0(n)              (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP14_CH0_MASK            (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP14_CH0_SHIFT           (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP15_CH0(n)              (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP15_CH0_MASK            (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP15_CH0_SHIFT           (14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP14(n)                  (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP14_MASK                (0x3FFF << 0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP14_SHIFT               (0)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP15(n)                  (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP15_MASK                (0x3FFF << 14)
      +#define CODEC_CODEC_DAC_DRE_GAIN_STEP15_SHIFT               (14)
       
       // reg_1c0
       #define CODEC_CODEC_ADC_DRE_ENABLE_CH0                      (1 << 0)
      -#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH0(n)                (((n) & 0x7) << 1)
      -#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH0_MASK              (0x7 << 1)
      +#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH0(n)                (((n) & 0x3) << 1)
      +#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH0_MASK              (0x3 << 1)
       #define CODEC_CODEC_ADC_DRE_STEP_MODE_CH0_SHIFT             (1)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH0(n)            (((n) & 0xF) << 4)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH0_MASK          (0xF << 4)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH0_SHIFT         (4)
      -#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH0(n)             (((n) & 0xF) << 8)
      -#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH0_MASK           (0xF << 8)
      -#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH0_SHIFT          (8)
      -#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH0(n)                (((n) & 0x7) << 12)
      -#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH0_MASK              (0x7 << 12)
      -#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH0_SHIFT             (12)
      -#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH0(n)                (((n) & 0x1F) << 15)
      -#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH0_MASK              (0x1F << 15)
      -#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH0_SHIFT             (15)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_SIGN_CH0          (1 << 20)
      -#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH0(n)                  (((n) & 0x3) << 21)
      -#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH0_MASK                (0x3 << 21)
      -#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH0_SHIFT               (21)
      -#define CODEC_CODEC_ADC_DRE_OVERFLOW_MUTE_EN_CH0            (1 << 23)
      -#define CODEC_CODEC_ADC_DRE_MUTE_MODE_CH0                   (1 << 24)
      -#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH0(n)           (((n) & 0x3) << 25)
      -#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH0_MASK         (0x3 << 25)
      -#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH0_SHIFT        (25)
      -#define CODEC_CODEC_ADC_DRE_MUTE_STATUS_CH0_SYNC            (1 << 27)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH0(n)            (((n) & 0xF) << 3)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH0_MASK          (0xF << 3)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH0_SHIFT         (3)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH0(n)             (((n) & 0xF) << 7)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH0_MASK           (0xF << 7)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH0_SHIFT          (7)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH0(n)                (((n) & 0x7) << 11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH0_MASK              (0x7 << 11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH0_SHIFT             (11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH0(n)                (((n) & 0x1F) << 14)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH0_MASK              (0x1F << 14)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH0_SHIFT             (14)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_SIGN_CH0          (1 << 19)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH0(n)                  (((n) & 0x3) << 20)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH0_MASK                (0x3 << 20)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH0_SHIFT               (20)
      +#define CODEC_CODEC_ADC_DRE_OVERFLOW_MUTE_EN_CH0            (1 << 22)
      +#define CODEC_CODEC_ADC_DRE_MUTE_MODE_CH0                   (1 << 23)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH0(n)           (((n) & 0x3) << 24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH0_MASK         (0x3 << 24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH0_SHIFT        (24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_STATUS_CH0                 (1 << 26)
       
       // reg_1c4
       #define CODEC_CODEC_ADC_DRE_AMP_HIGH_CH0(n)                 (((n) & 0x7FF) << 0)
      @@ -1143,31 +1496,31 @@ struct CODEC_T {
       
       // reg_1c8
       #define CODEC_CODEC_ADC_DRE_ENABLE_CH1                      (1 << 0)
      -#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH1(n)                (((n) & 0x7) << 1)
      -#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH1_MASK              (0x7 << 1)
      +#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH1(n)                (((n) & 0x3) << 1)
      +#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH1_MASK              (0x3 << 1)
       #define CODEC_CODEC_ADC_DRE_STEP_MODE_CH1_SHIFT             (1)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH1(n)            (((n) & 0xF) << 4)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH1_MASK          (0xF << 4)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH1_SHIFT         (4)
      -#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH1(n)             (((n) & 0xF) << 8)
      -#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH1_MASK           (0xF << 8)
      -#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH1_SHIFT          (8)
      -#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH1(n)                (((n) & 0x7) << 12)
      -#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH1_MASK              (0x7 << 12)
      -#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH1_SHIFT             (12)
      -#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH1(n)                (((n) & 0x1F) << 15)
      -#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH1_MASK              (0x1F << 15)
      -#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH1_SHIFT             (15)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_SIGN_CH1          (1 << 20)
      -#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH1(n)                  (((n) & 0x3) << 21)
      -#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH1_MASK                (0x3 << 21)
      -#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH1_SHIFT               (21)
      -#define CODEC_CODEC_ADC_DRE_OVERFLOW_MUTE_EN_CH1            (1 << 23)
      -#define CODEC_CODEC_ADC_DRE_MUTE_MODE_CH1                   (1 << 24)
      -#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH1(n)           (((n) & 0x3) << 25)
      -#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH1_MASK         (0x3 << 25)
      -#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH1_SHIFT        (25)
      -#define CODEC_CODEC_ADC_DRE_MUTE_STATUS_CH1_SYNC            (1 << 27)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH1(n)            (((n) & 0xF) << 3)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH1_MASK          (0xF << 3)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH1_SHIFT         (3)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH1(n)             (((n) & 0xF) << 7)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH1_MASK           (0xF << 7)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH1_SHIFT          (7)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH1(n)                (((n) & 0x7) << 11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH1_MASK              (0x7 << 11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH1_SHIFT             (11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH1(n)                (((n) & 0x1F) << 14)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH1_MASK              (0x1F << 14)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH1_SHIFT             (14)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_SIGN_CH1          (1 << 19)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH1(n)                  (((n) & 0x3) << 20)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH1_MASK                (0x3 << 20)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH1_SHIFT               (20)
      +#define CODEC_CODEC_ADC_DRE_OVERFLOW_MUTE_EN_CH1            (1 << 22)
      +#define CODEC_CODEC_ADC_DRE_MUTE_MODE_CH1                   (1 << 23)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH1(n)           (((n) & 0x3) << 24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH1_MASK         (0x3 << 24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH1_SHIFT        (24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_STATUS_CH1                 (1 << 26)
       
       // reg_1cc
       #define CODEC_CODEC_ADC_DRE_AMP_HIGH_CH1(n)                 (((n) & 0x7FF) << 0)
      @@ -1179,31 +1532,31 @@ struct CODEC_T {
       
       // reg_1d0
       #define CODEC_CODEC_ADC_DRE_ENABLE_CH2                      (1 << 0)
      -#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH2(n)                (((n) & 0x7) << 1)
      -#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH2_MASK              (0x7 << 1)
      +#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH2(n)                (((n) & 0x3) << 1)
      +#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH2_MASK              (0x3 << 1)
       #define CODEC_CODEC_ADC_DRE_STEP_MODE_CH2_SHIFT             (1)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH2(n)            (((n) & 0xF) << 4)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH2_MASK          (0xF << 4)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH2_SHIFT         (4)
      -#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH2(n)             (((n) & 0xF) << 8)
      -#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH2_MASK           (0xF << 8)
      -#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH2_SHIFT          (8)
      -#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH2(n)                (((n) & 0x7) << 12)
      -#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH2_MASK              (0x7 << 12)
      -#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH2_SHIFT             (12)
      -#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH2(n)                (((n) & 0x1F) << 15)
      -#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH2_MASK              (0x1F << 15)
      -#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH2_SHIFT             (15)
      -#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_SIGN_CH2          (1 << 20)
      -#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH2(n)                  (((n) & 0x3) << 21)
      -#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH2_MASK                (0x3 << 21)
      -#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH2_SHIFT               (21)
      -#define CODEC_CODEC_ADC_DRE_OVERFLOW_MUTE_EN_CH2            (1 << 23)
      -#define CODEC_CODEC_ADC_DRE_MUTE_MODE_CH2                   (1 << 24)
      -#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH2(n)           (((n) & 0x3) << 25)
      -#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH2_MASK         (0x3 << 25)
      -#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH2_SHIFT        (25)
      -#define CODEC_CODEC_ADC_DRE_MUTE_STATUS_CH2_SYNC            (1 << 27)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH2(n)            (((n) & 0xF) << 3)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH2_MASK          (0xF << 3)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH2_SHIFT         (3)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH2(n)             (((n) & 0xF) << 7)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH2_MASK           (0xF << 7)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH2_SHIFT          (7)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH2(n)                (((n) & 0x7) << 11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH2_MASK              (0x7 << 11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH2_SHIFT             (11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH2(n)                (((n) & 0x1F) << 14)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH2_MASK              (0x1F << 14)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH2_SHIFT             (14)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_SIGN_CH2          (1 << 19)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH2(n)                  (((n) & 0x3) << 20)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH2_MASK                (0x3 << 20)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH2_SHIFT               (20)
      +#define CODEC_CODEC_ADC_DRE_OVERFLOW_MUTE_EN_CH2            (1 << 22)
      +#define CODEC_CODEC_ADC_DRE_MUTE_MODE_CH2                   (1 << 23)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH2(n)           (((n) & 0x3) << 24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH2_MASK         (0x3 << 24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH2_SHIFT        (24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_STATUS_CH2                 (1 << 26)
       
       // reg_1d4
       #define CODEC_CODEC_ADC_DRE_AMP_HIGH_CH2(n)                 (((n) & 0x7FF) << 0)
      @@ -1214,8 +1567,40 @@ struct CODEC_T {
       #define CODEC_CODEC_ADC_DRE_WINDOW_CH2_SHIFT                (11)
       
       // reg_1d8
      +#define CODEC_CODEC_ADC_DRE_ENABLE_CH3                      (1 << 0)
      +#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH3(n)                (((n) & 0x3) << 1)
      +#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH3_MASK              (0x3 << 1)
      +#define CODEC_CODEC_ADC_DRE_STEP_MODE_CH3_SHIFT             (1)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH3(n)            (((n) & 0xF) << 3)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH3_MASK          (0xF << 3)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_CH3_SHIFT         (3)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH3(n)             (((n) & 0xF) << 7)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH3_MASK           (0xF << 7)
      +#define CODEC_CODEC_ADC_DRE_INI_ANA_GAIN_CH3_SHIFT          (7)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH3(n)                (((n) & 0x7) << 11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH3_MASK              (0x7 << 11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_DIG_CH3_SHIFT             (11)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH3(n)                (((n) & 0x1F) << 14)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH3_MASK              (0x1F << 14)
      +#define CODEC_CODEC_ADC_DRE_DELAY_ANA_CH3_SHIFT             (14)
      +#define CODEC_CODEC_ADC_DRE_THD_DB_OFFSET_SIGN_CH3          (1 << 19)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH3(n)                  (((n) & 0x3) << 20)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH3_MASK                (0x3 << 20)
      +#define CODEC_CODEC_ADC_DRE_BIT_SEL_CH3_SHIFT               (20)
      +#define CODEC_CODEC_ADC_DRE_OVERFLOW_MUTE_EN_CH3            (1 << 22)
      +#define CODEC_CODEC_ADC_DRE_MUTE_MODE_CH3                   (1 << 23)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH3(n)           (((n) & 0x3) << 24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH3_MASK         (0x3 << 24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_RANGE_SEL_CH3_SHIFT        (24)
      +#define CODEC_CODEC_ADC_DRE_MUTE_STATUS_CH3                 (1 << 26)
       
       // reg_1dc
      +#define CODEC_CODEC_ADC_DRE_AMP_HIGH_CH3(n)                 (((n) & 0x7FF) << 0)
      +#define CODEC_CODEC_ADC_DRE_AMP_HIGH_CH3_MASK               (0x7FF << 0)
      +#define CODEC_CODEC_ADC_DRE_AMP_HIGH_CH3_SHIFT              (0)
      +#define CODEC_CODEC_ADC_DRE_WINDOW_CH3(n)                   (((n) & 0xFFFFF) << 11)
      +#define CODEC_CODEC_ADC_DRE_WINDOW_CH3_MASK                 (0xFFFFF << 11)
      +#define CODEC_CODEC_ADC_DRE_WINDOW_CH3_SHIFT                (11)
       
       // reg_1e0
       #define CODEC_CODEC_ADC_DRE_GAIN_STEP0_CH0(n)               (((n) & 0x3FFF) << 0)
      @@ -1234,28 +1619,52 @@ struct CODEC_T {
       #define CODEC_CODEC_ADC_DRE_GAIN_STEP3_CH0_SHIFT            (14)
       
       // reg_1e8
      -#define CODEC_CODEC_ADC_DRE_DC_STEP0_CH0(n)                 (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP0_CH0_MASK               (0x3FFF << 0)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP0_CH0_SHIFT              (0)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP1_CH0(n)                 (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP1_CH0_MASK               (0x3FFF << 14)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP1_CH0_SHIFT              (14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP4_CH0(n)               (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP4_CH0_MASK             (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP4_CH0_SHIFT            (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP5_CH0(n)               (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP5_CH0_MASK             (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP5_CH0_SHIFT            (14)
       
       // reg_1ec
      -#define CODEC_CODEC_ADC_DRE_DC_STEP2_CH0(n)                 (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP2_CH0_MASK               (0x3FFF << 0)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP2_CH0_SHIFT              (0)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP3_CH0(n)                 (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP3_CH0_MASK               (0x3FFF << 14)
      -#define CODEC_CODEC_ADC_DRE_DC_STEP3_CH0_SHIFT              (14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP6_CH0(n)               (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP6_CH0_MASK             (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP6_CH0_SHIFT            (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP7_CH0(n)               (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP7_CH0_MASK             (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP7_CH0_SHIFT            (14)
       
       // reg_1f0
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP8_CH0(n)               (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP8_CH0_MASK             (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP8_CH0_SHIFT            (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP9_CH0(n)               (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP9_CH0_MASK             (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP9_CH0_SHIFT            (14)
       
       // reg_1f4
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP10_CH0(n)              (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP10_CH0_MASK            (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP10_CH0_SHIFT           (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP11_CH0(n)              (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP11_CH0_MASK            (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP11_CH0_SHIFT           (14)
       
       // reg_1f8
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP12_CH0(n)              (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP12_CH0_MASK            (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP12_CH0_SHIFT           (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP13_CH0(n)              (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP13_CH0_MASK            (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP13_CH0_SHIFT           (14)
       
       // reg_1fc
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP14_CH0(n)              (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP14_CH0_MASK            (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP14_CH0_SHIFT           (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP15_CH0(n)              (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP15_CH0_MASK            (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP15_CH0_SHIFT           (14)
       
       // reg_200
       #define CODEC_CODEC_ADC_DRE_GAIN_STEP0_CH1(n)               (((n) & 0x3FFF) << 0)
      @@ -1274,52 +1683,52 @@ struct CODEC_T {
       #define CODEC_CODEC_ADC_DRE_GAIN_STEP3_CH1_SHIFT            (14)
       
       // reg_208
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP4_CH1(n)               (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP4_CH1_MASK             (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP4_CH1_SHIFT            (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP5_CH1(n)               (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP5_CH1_MASK             (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP5_CH1_SHIFT            (14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP4_CH1(n)               (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP4_CH1_MASK             (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP4_CH1_SHIFT            (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP5_CH1(n)               (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP5_CH1_MASK             (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP5_CH1_SHIFT            (14)
       
       // reg_20c
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP6_CH1(n)               (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP6_CH1_MASK             (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP6_CH1_SHIFT            (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP7_CH1(n)               (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP7_CH1_MASK             (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP7_CH1_SHIFT            (14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP6_CH1(n)               (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP6_CH1_MASK             (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP6_CH1_SHIFT            (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP7_CH1(n)               (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP7_CH1_MASK             (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP7_CH1_SHIFT            (14)
       
       // reg_210
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP8_CH1(n)               (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP8_CH1_MASK             (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP8_CH1_SHIFT            (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP9_CH1(n)               (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP9_CH1_MASK             (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP9_CH1_SHIFT            (14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP8_CH1(n)               (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP8_CH1_MASK             (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP8_CH1_SHIFT            (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP9_CH1(n)               (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP9_CH1_MASK             (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP9_CH1_SHIFT            (14)
       
       // reg_214
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP10_CH1(n)              (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP10_CH1_MASK            (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP10_CH1_SHIFT           (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP11_CH1(n)              (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP11_CH1_MASK            (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP11_CH1_SHIFT           (14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP10_CH1(n)              (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP10_CH1_MASK            (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP10_CH1_SHIFT           (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP11_CH1(n)              (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP11_CH1_MASK            (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP11_CH1_SHIFT           (14)
       
       // reg_218
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP12_CH1(n)              (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP12_CH1_MASK            (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP12_CH1_SHIFT           (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP13_CH1(n)              (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP13_CH1_MASK            (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP13_CH1_SHIFT           (14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP12_CH1(n)              (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP12_CH1_MASK            (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP12_CH1_SHIFT           (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP13_CH1(n)              (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP13_CH1_MASK            (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP13_CH1_SHIFT           (14)
       
       // reg_21c
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP14_CH1(n)              (((n) & 0x3FFF) << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP14_CH1_MASK            (0x3FFF << 0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP14_CH1_SHIFT           (0)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP15_CH1(n)              (((n) & 0x3FFF) << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP15_CH1_MASK            (0x3FFF << 14)
      -#define CODEC_CODEC_DAC_DRE_GAIN_STEP15_CH1_SHIFT           (14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP14_CH1(n)              (((n) & 0x3FFF) << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP14_CH1_MASK            (0x3FFF << 0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP14_CH1_SHIFT           (0)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP15_CH1(n)              (((n) & 0x3FFF) << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP15_CH1_MASK            (0x3FFF << 14)
      +#define CODEC_CODEC_ADC_DRE_GAIN_STEP15_CH1_SHIFT           (14)
       
       // reg_220
       #define CODEC_VAD_DELAY1(n)                                 (((n) & 0x3FF) << 0)
      @@ -1332,9 +1741,44 @@ struct CODEC_T {
       #define CODEC_VAD_DELAY2_SHIFT                              (0)
       
       // reg_228
      +#define CODEC_CODEC_MC_ENABLE_CH0                           (1 << 0)
      +#define CODEC_CODEC_MC_SEL_CH0                              (1 << 1)
      +#define CODEC_CODEC_DOWN_SEL_MC_CH0(n)                      (((n) & 0x3) << 2)
      +#define CODEC_CODEC_DOWN_SEL_MC_CH0_MASK                    (0x3 << 2)
      +#define CODEC_CODEC_DOWN_SEL_MC_CH0_SHIFT                   (2)
      +#define CODEC_CODEC_MC_SINC_BYPASS_CH0                      (1 << 4)
      +#define CODEC_CODEC_MC_ENABLE_CH1                           (1 << 5)
      +#define CODEC_CODEC_MC_SEL_CH1                              (1 << 6)
      +#define CODEC_CODEC_DOWN_SEL_MC_CH1(n)                      (((n) & 0x3) << 7)
      +#define CODEC_CODEC_DOWN_SEL_MC_CH1_MASK                    (0x3 << 7)
      +#define CODEC_CODEC_DOWN_SEL_MC_CH1_SHIFT                   (7)
      +#define CODEC_CODEC_MC_SINC_BYPASS_CH1                      (1 << 9)
      +#define CODEC_CODEC_RESAMPLE_MC_ENABLE                      (1 << 10)
      +#define CODEC_CODEC_RESAMPLE_MC_DUAL_CH                     (1 << 11)
       
       // reg_22c
      +#define CODEC_CODEC_TT_ENABLE                               (1 << 0)
      +#define CODEC_CODEC_MUTE_GAIN_COEF_TT(n)                    (((n) & 0xFFF) << 1)
      +#define CODEC_CODEC_MUTE_GAIN_COEF_TT_MASK                  (0xFFF << 1)
      +#define CODEC_CODEC_MUTE_GAIN_COEF_TT_SHIFT                 (1)
      +#define CODEC_CODEC_MUTE_GAIN_PASS0_TT                      (1 << 13)
      +#define CODEC_CODEC_MM_ENABLE                               (1 << 14)
      +#define CODEC_CODEC_MUTE_GAIN_COEF_MM(n)                    (((n) & 0xFFF) << 15)
      +#define CODEC_CODEC_MUTE_GAIN_COEF_MM_MASK                  (0xFFF << 15)
      +#define CODEC_CODEC_MUTE_GAIN_COEF_MM_SHIFT                 (15)
      +#define CODEC_CODEC_MUTE_GAIN_PASS0_MM                      (1 << 27)
       
       // reg_230
      +#define CODEC_CODEC_MM_FIFO_EN                              (1 << 0)
      +#define CODEC_CODEC_MM_FIFO_BYPASS                          (1 << 1)
      +#define CODEC_CODEC_MM_DELAY_UPDATE                         (1 << 2)
      +#define CODEC_CODEC_MM_DELAY(n)                             (((n) & 0x1F) << 3)
      +#define CODEC_CODEC_MM_DELAY_MASK                           (0x1F << 3)
      +#define CODEC_CODEC_MM_DELAY_SHIFT                          (3)
      +#define CODEC_VAD_EXT_EN                                    (1 << 8)
      +#define CODEC_VAD_SRC_SEL                                   (1 << 9)
      +#define CODEC_VAD_DATA_EXT_SWAP                             (1 << 10)
      +#define CODEC_MC_EN_SEL                                     (1 << 11)
      +#define CODEC_MC_RATE_SRC_SEL                               (1 << 12)
       
       #endif
  • platform/hal/best2300p/reg_iomux_best2300p.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/best2300p/reg_iomux_best2300p.h bes/platform/hal/best2300p/reg_iomux_best2300p.h
      index 9610b1208c5..de4a2fd867f 100644
      --- a/platform/hal/best2300p/reg_iomux_best2300p.h
      +++ b/platform/hal/best2300p/reg_iomux_best2300p.h
      @@ -263,16 +263,16 @@ struct IOMUX_T {
       #define IOMUX_GPIO_PCM_MODE                     (1 << 2)
       #define IOMUX_BT_RXTX_SW_EN                     (1 << 3)
       #define IOMUX_I2C1_M_SEL_GPIO                   (1 << 4)
      -#define IOMUX_SPILCD0_WM3                       (1 << 6)
      -#define IOMUX_SPILCD1_WM3                       (1 << 7)
      -#define IOMUX_CFG_EN_CLK_REQIN                  (1 << 10)
      -#define IOMUX_CFG_POL_CLK_REQIN                 (1 << 11)
      -#define IOMUX_CFG_EN_CLK_REQOUT                 (1 << 12)
      -#define IOMUX_CFG_POL_CLK_REQOUT                (1 << 13)
      -#define IOMUX_BT_UART_HALFN                     (1 << 14)
      -#define IOMUX_UART0_HALFN                       (1 << 15)
      -#define IOMUX_UART1_HALFN                       (1 << 16)
      -#define IOMUX_UART2_HALFN                       (1 << 17)
      +#define IOMUX_SPILCD0_WM3                       (1 << 5)
      +#define IOMUX_SPILCD1_WM3                       (1 << 6)
      +#define IOMUX_CFG_EN_CLK_REQIN                  (1 << 7)
      +#define IOMUX_CFG_POL_CLK_REQIN                 (1 << 8)
      +#define IOMUX_CFG_EN_CLK_REQOUT                 (1 << 9)
      +#define IOMUX_CFG_POL_CLK_REQOUT                (1 << 10)
      +#define IOMUX_BT_UART_HALFN                     (1 << 11)
      +#define IOMUX_UART0_HALFN                       (1 << 12)
      +#define IOMUX_UART1_HALFN                       (1 << 13)
      +#define IOMUX_UART2_HALFN                       (1 << 14)
       
       // reg_54
       #define IOMUX_CFG_GPIO_OENB_P0_POL(n)           (((n) & 0xFF) << 0)
  • platform/hal/hal_aud.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_aud.h bes/platform/hal/hal_aud.h
      index 0a97765a049..77f862a4d1e 100644
      --- a/platform/hal/hal_aud.h
      +++ b/platform/hal/hal_aud.h
      @@ -70,10 +70,10 @@ extern "C" {
       #define CODEC_CMU_DIV                       8
       #define CODEC_PLAYBACK_BIT_DEPTH            20
       
      -#elif defined(CHIP_BEST2003)
      +#elif defined(CHIP_BEST2001)
       
      -#define CODEC_PLL_DIV                       156
      -#define CODEC_CMU_DIV                       13
      +#define CODEC_PLL_DIV                       38
      +#define CODEC_CMU_DIV                       8
       #define CODEC_PLAYBACK_BIT_DEPTH            20
       
       #else
      @@ -135,8 +135,10 @@ enum AUD_SAMPRATE_T {
           AUD_SAMPRATE_352800 = 352800,
           AUD_SAMPRATE_384000 = 384000,
           AUD_SAMPRATE_406250 = 406250,     // 26M / 64
      +    AUD_SAMPRATE_512000 = 512000,
           AUD_SAMPRATE_705600 = 705600,
           AUD_SAMPRATE_768000 = 768000,
      +    AUD_SAMPRATE_1024000 = 1024000,
       };
       
       enum AUD_CHANNEL_NUM_T {
      @@ -202,7 +204,9 @@ enum AUD_STREAM_ID_T {
           AUD_STREAM_ID_0 = 0,
           AUD_STREAM_ID_1,
           AUD_STREAM_ID_2,
      +#ifdef __ANC_ASSIST__
           AUD_STREAM_ID_3,
      +#endif
           AUD_STREAM_ID_NUM,
       };
       
      @@ -223,8 +227,11 @@ enum AUD_IO_PATH_T {
           AUD_INPUT_PATH_ASRMIC,
           AUD_INPUT_PATH_LINEIN,
           AUD_INPUT_PATH_NTMIC,
      +    AUD_INPUT_PATH_ANC_WNR,
           AUD_INPUT_PATH_USBAUDIO,
      -    AUD_INPUT_PATH_ANC_ASSIST,
      +#ifdef __ANC_ASSIST__
      +    AUD_INPUT_PATH_AF_ANC,
      +#endif
           // Output path
           AUD_OUTPUT_PATH_SPEAKER,
       };
      @@ -235,11 +242,11 @@ struct AUD_IO_PATH_CFG_T {
       };
       
       enum ANC_TYPE_T {
      -    ANC_NOTYPE          = 0,
      -    ANC_FEEDFORWARD     = (1 << 0),
      -    ANC_FEEDBACK        = (1 << 1),
      -    ANC_TALKTHRU        = (1 << 2),
      -    ANC_MUSICCANCLE     = (1 << 3),
      +    ANC_NOTYPE          = (1 << 0),
      +    ANC_FEEDFORWARD     = (1 << 1),
      +    ANC_FEEDBACK        = (1 << 2),
      +    ANC_TALKTHRU        = (1 << 3),
      +    ANC_MUSICCANCLE     = (1 << 4),
       };
       
       struct CODEC_DAC_VOL_T {
      @@ -251,7 +258,10 @@ struct CODEC_DAC_VOL_T {
       typedef signed char CODEC_ADC_VOL_T;
       
       enum TGT_VOLUME_LEVEL_T {
      -    TGT_VOLUME_LEVEL_MUTE = 0,
      +    TGT_VOLUME_LEVEL_WARNINGTONE = 0,
      +
      +    TGT_VOLUME_LEVEL_MUTE,
      +    TGT_VOLUME_LEVEL_0,
           TGT_VOLUME_LEVEL_1,
           TGT_VOLUME_LEVEL_2,
           TGT_VOLUME_LEVEL_3,
      @@ -272,7 +282,7 @@ enum TGT_VOLUME_LEVEL_T {
       };
       
       enum TGT_ADC_VOL_LEVEL_T {
      -    TGT_ADC_VOL_LEVEL_0 = 0,
      +    TGT_ADC_VOL_LEVEL_0,
           TGT_ADC_VOL_LEVEL_1,
           TGT_ADC_VOL_LEVEL_2,
           TGT_ADC_VOL_LEVEL_3,

@OneDeuxTriSeiGo
Copy link
Author

  • platform/hal/hal_bootmode.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_bootmode.h bes/platform/hal/hal_bootmode.h
      index ef563375207..924972d7dbd 100644
      --- a/platform/hal/hal_bootmode.h
      +++ b/platform/hal/hal_bootmode.h
      @@ -52,7 +52,7 @@ extern "C" {
       
       #define HAL_SW_BOOTMODE_ENTER_HIDE_BOOT         (1 << 23)
       
      -#define HAL_SW_BOOTMODE_CUSTOM_OP1_AFTER_REBOOT (1 << 24)
      +#define HAL_SW_BOOTMODE_RESERVED_BIT24          (1 << 24)
       #define HAL_SW_BOOTMODE_REBOOT_FROM_CRASH       (1 << 25)
       #define HAL_SW_BOOTMODE_SINGLE_LINE_DOWNLOAD    (1 << 26)
       
  • platform/hal/hal_btpcm.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_btpcm.h bes/platform/hal/hal_btpcm.h
      index 48bed597318..878ef2d7a9f 100644
      --- a/platform/hal/hal_btpcm.h
      +++ b/platform/hal/hal_btpcm.h
      @@ -40,7 +40,7 @@ int hal_btpcm_close(enum HAL_BTPCM_ID_T id, enum AUD_STREAM_T stream);
       int hal_btpcm_start_stream(enum HAL_BTPCM_ID_T id, enum AUD_STREAM_T stream);
       int hal_btpcm_stop_stream(enum HAL_BTPCM_ID_T id, enum AUD_STREAM_T stream);
       int hal_btpcm_setup_stream(enum HAL_BTPCM_ID_T id, enum AUD_STREAM_T stream, struct HAL_BTPCM_CONFIG_T *cfg);
      -int hal_btpcm_send(enum HAL_BTPCM_ID_T id, const uint8_t *value, uint32_t value_len);
      +int hal_btpcm_send(enum HAL_BTPCM_ID_T id, uint8_t *value, uint32_t value_len);
       uint8_t hal_btpcm_recv(enum HAL_BTPCM_ID_T id, uint8_t *value, uint32_t value_len);
       
       #ifdef __cplusplus
  • platform/hal/hal_cmu_common.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_cmu_common.c bes/platform/hal/hal_cmu_common.c
      index 12fd1c0ab2a..ed978c56b94 100644
      --- a/platform/hal/hal_cmu_common.c
      +++ b/platform/hal/hal_cmu_common.c
      @@ -127,9 +127,10 @@ uint32_t hal_cmu_simu_get_val(void)
       
       void hal_cmu_set_wakeup_pc(uint32_t pc)
       {
      +#ifdef RAMRET_BASE
           uint32_t *wake_pc =
       #ifdef CHIP_BEST2000
      -        (uint32_t *)REGRET_BASE;
      +        (uint32_t *)RAMRET_BASE;
       #else
               (uint32_t *)&aoncmu->WAKEUP_PC;
       
      @@ -137,15 +138,17 @@ void hal_cmu_set_wakeup_pc(uint32_t pc)
       #endif
       
           *wake_pc = pc;
      +#endif
       }
       
       void hal_cmu_rom_wakeup_check(void)
       {
      +#ifdef RAMRET_BASE
           union HAL_HW_BOOTMODE_T hw;
           uint32_t sw;
           HAL_POWER_DOWN_WAKEUP_HANDLER *wake_fn =
       #ifdef CHIP_BEST2000
      -        (HAL_POWER_DOWN_WAKEUP_HANDLER *)REGRET_BASE;
      +        (HAL_POWER_DOWN_WAKEUP_HANDLER *)RAMRET_BASE;
       #else
               (HAL_POWER_DOWN_WAKEUP_HANDLER *)&aoncmu->WAKEUP_PC;
       #endif
      @@ -168,18 +171,18 @@ void hal_cmu_rom_enable_pll(void)
       #ifdef CHIP_HAS_USB
           hal_cmu_pll_enable(HAL_CMU_PLL_USB, HAL_CMU_PLL_USER_SYS);
           hal_cmu_sys_select_pll(HAL_CMU_PLL_USB);
      -    hal_cmu_flash_all_select_pll(HAL_CMU_PLL_USB);
      +    hal_cmu_flash_select_pll(HAL_CMU_PLL_USB);
       #else
           hal_cmu_pll_enable(HAL_CMU_PLL_AUD, HAL_CMU_PLL_USER_SYS);
           hal_cmu_sys_select_pll(HAL_CMU_PLL_AUD);
      -    hal_cmu_flash_all_select_pll(HAL_CMU_PLL_AUD);
      +    hal_cmu_flash_select_pll(HAL_CMU_PLL_AUD);
       #endif
       }
       
       void hal_cmu_programmer_enable_pll(void)
       {
           hal_cmu_pll_enable(HAL_CMU_PLL_AUD, HAL_CMU_PLL_USER_SYS);
      -    hal_cmu_flash_all_select_pll(HAL_CMU_PLL_AUD);
      +    hal_cmu_flash_select_pll(HAL_CMU_PLL_AUD);
           hal_cmu_sys_select_pll(HAL_CMU_PLL_AUD);
       }
       
      @@ -211,11 +214,11 @@ void BOOT_TEXT_FLASH_LOC hal_cmu_init_pll_selection(void)
       #ifdef CHIP_HAS_USB
           // Switch flash clock to USB PLL, and then shutdown USB PLL,
           // to save power consumed in clock divider
      -    hal_cmu_flash_all_select_pll(HAL_CMU_PLL_USB);
      +    hal_cmu_flash_select_pll(HAL_CMU_PLL_USB);
       #endif
       #else
           // Switch flash clock to audio PLL
      -    hal_cmu_flash_all_select_pll(HAL_CMU_PLL_AUD);
      +    hal_cmu_flash_select_pll(HAL_CMU_PLL_AUD);
       #endif
       
       #ifdef CHIP_HAS_PSRAM
      @@ -281,19 +284,26 @@ static void BOOT_TEXT_FLASH_LOC hal_cmu_init_periph_clock(void)
       
       void hal_cmu_rom_setup(void)
       {
      -    int reset_flash;
           hal_cmu_lpu_wait_26m_ready();
           hal_cmu_simu_init();
           hal_cmu_rom_clock_init();
      +    hal_cmu_timer0_select_slow();
      +#ifdef TIMER1_BASE
      +    hal_cmu_timer1_select_fast();
      +#endif
           hal_sys_timer_open();
       
           // Init sys clock
           hal_cmu_sys_set_freq(HAL_CMU_FREQ_26M);
       
           // Init flash clock (this should be done before load_boot_settings, for security register read)
      -    hal_cmu_flash_all_set_freq(HAL_CMU_FREQ_26M);
      -    reset_flash = true;
      -    hal_cmu_flash_all_reset_clear(reset_flash);
      +    hal_cmu_flash_set_freq(HAL_CMU_FREQ_26M);
      +    // Reset flash controller (for JTAG reset and run)
      +    // Enable flash controller (flash controller is reset by default since BEST1400)
      +    hal_cmu_reset_set(HAL_CMU_MOD_O_FLASH);
      +    hal_cmu_reset_set(HAL_CMU_MOD_H_FLASH);
      +    hal_cmu_reset_clear(HAL_CMU_MOD_H_FLASH);
      +    hal_cmu_reset_clear(HAL_CMU_MOD_O_FLASH);
       
           // Disable cache (for JTAG reset and run)
           hal_cache_disable(HAL_CACHE_ID_I_CACHE);
      @@ -305,14 +315,14 @@ void hal_cmu_rom_setup(void)
       
       void hal_cmu_programmer_setup(void)
       {
      +    hal_cmu_ema_init();
      +    hal_sys_timer_open();
       
       #ifdef JTAG_ENABLE
           hal_iomux_set_jtag();
           hal_cmu_jtag_clock_enable();
       #endif
       
      -    hal_cmu_ema_init();
      -    hal_sys_timer_open();
       #ifndef FPGA
           int ret;
           // Open analogif (ISPI)
      @@ -336,6 +346,7 @@ void hal_cmu_programmer_setup(void)
       
       void BOOT_TEXT_FLASH_LOC hal_cmu_fpga_setup(void)
       {
      +    hal_cmu_timer0_select_slow();
           hal_sys_timer_open();
       
           hal_sysfreq_req(HAL_SYSFREQ_USER_INIT, HAL_CMU_FREQ_52M);
      @@ -347,8 +358,8 @@ void BOOT_TEXT_FLASH_LOC hal_cmu_fpga_setup(void)
           hal_cmu_init_periph_clock();
       
           hal_norflash_init();
      - #if defined(CHIP_BEST1501SIMU)
      -    hal_cmu_module_init_state();
      +#if defined(CHIP_HAS_PSRAM) && defined(PSRAM_ENABLE)
      +    hal_psram_init();
       #endif
       }
       
      @@ -356,7 +367,7 @@ void BOOT_TEXT_FLASH_LOC hal_cmu_fpga_setup(void)
       
       void BOOT_TEXT_FLASH_LOC hal_cmu_setup(void)
       {
      -    POSSIBLY_UNUSED int ret;
      +    int ret;
           enum HAL_CMU_FREQ_T freq;
       
           hal_iomux_set_default_config();
      @@ -364,14 +375,18 @@ void BOOT_TEXT_FLASH_LOC hal_cmu_setup(void)
           hal_iomux_set_jtag();
           hal_cmu_jtag_clock_enable();
       #endif
      -    hal_cmu_ema_init();
           hal_cmu_module_init_state();
      +    hal_cmu_ema_init();
      +    hal_cmu_timer0_select_slow();
      +#ifdef TIMER1_BASE
      +    hal_cmu_timer1_select_fast();
      +#endif
           hal_sys_timer_open();
           hal_hw_bootmode_init();
       
           // Init system/flash/memory clocks before initializing clock setting
           // and before switching PLL
      -    hal_norflash_set_boot_freq(HAL_CMU_FREQ_26M);
      +    hal_norflash_set_freq(HAL_CMU_FREQ_26M);
           hal_cmu_mem_set_freq(HAL_CMU_FREQ_26M);
           hal_cmu_sys_set_freq(HAL_CMU_FREQ_26M);
       
  • platform/hal/hal_codec.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_codec.h bes/platform/hal/hal_codec.h
      index b6a8963ac55..86f58c772ea 100644
      --- a/platform/hal/hal_codec.h
      +++ b/platform/hal/hal_codec.h
      @@ -30,6 +30,30 @@ enum HAL_CODEC_ID_T {
           HAL_CODEC_ID_NUM,
       };
       
      +struct HAL_CODEC_CONFIG_T {
      +    enum AUD_BITS_T bits;
      +    enum AUD_SAMPRATE_T sample_rate;
      +    enum AUD_CHANNEL_NUM_T channel_num;
      +    enum AUD_CHANNEL_MAP_T channel_map;
      +
      +    uint32_t use_dma:1;
      +    uint32_t vol:5;
      +
      +    enum AUD_IO_PATH_T io_path;
      +
      +    uint32_t set_flag;
      +};
      +
      +struct dac_classg_cfg {
      +    uint8_t thd2;
      +    uint8_t thd1;
      +    uint8_t thd0;
      +    uint8_t lr;
      +    uint8_t step_4_3n;
      +    uint8_t quick_down;
      +    uint16_t wind_width;
      +};
      +
       enum HAL_CODEC_CONFIG_FLAG_T{
           HAL_CODEC_CONFIG_NULL = 0x00,
       
      @@ -63,6 +87,13 @@ enum HAL_CODEC_PERF_TEST_POWER_T {
           HAL_CODEC_PERF_TEST_QTY
       };
       
      +enum HAL_CODEC_IIR_USER_T {
      +    HAL_CODEC_IIR_USER_ANC,
      +    HAL_CODEC_IIR_USER_EQ,
      +
      +    HAL_CODEC_IIR_USER_QTY,
      +};
      +
       enum HAL_CODEC_TIMER_TRIG_MODE_T {
           HAL_CODEC_TIMER_TRIG_MODE_DAC,
           HAL_CODEC_TIMER_TRIG_MODE_ADC,
      @@ -165,8 +196,8 @@ void hal_codec_set_bt_trigger_callback(HAL_CODEC_BT_TRIGGER_CALLBACK callback);
       int hal_codec_bt_trigger_start(void);
       int hal_codec_bt_trigger_stop(void);
       
      -void hal_codec_iir_enable(uint32_t speed);
      -void hal_codec_iir_disable(void);
      +int hal_codec_iir_enable(enum HAL_CODEC_IIR_USER_T user, uint32_t speed);
      +int hal_codec_iir_disable(enum HAL_CODEC_IIR_USER_T user);
       
       void hal_codec_min_phase_mode_enable(enum AUD_STREAM_T stream);
       void hal_codec_min_phase_mode_disable(enum AUD_STREAM_T stream);
  • platform/hal/hal_dma.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_dma.c bes/platform/hal/hal_dma.c
      index 9e9ffe99ea7..960c2d2ce38 100644
      --- a/platform/hal/hal_dma.c
      +++ b/platform/hal/hal_dma.c
      @@ -588,6 +588,7 @@ uint32_t hal_dma_cancel(uint8_t ch)
       {
           enum HAL_DMA_INST_T inst;
           uint8_t hwch;
      +    uint32_t remains;
       
           inst = get_inst_from_chan(ch);
           hwch = get_hwch_from_chan(ch);
      @@ -598,6 +599,10 @@ uint32_t hal_dma_cancel(uint8_t ch)
           dma[inst]->CH[hwch].CONFIG &= ~DMA_CONFIG_EN;
           dma[inst]->INTTCCLR = DMA_STAT_CHAN(hwch);
           dma[inst]->INTERRCLR = DMA_STAT_CHAN(hwch);
      +
      +    remains = GET_BITFIELD(dma[inst]->CH[hwch].CONTROL, DMA_CONTROL_TRANSFERSIZE);
      +
      +    return remains;
       }
       
       uint32_t hal_dma_stop(uint8_t ch)
      @@ -989,7 +994,7 @@ void hal_dma_open(void)
               return;
           }
       
      -    for (inst = HAL_DMA_INST_AUDMA; inst < HAL_DMA_INST_QTY; inst++) {
      +    for (inst = 0; inst < HAL_DMA_INST_QTY; inst++) {
               hal_dma_open_inst(inst);
           }
       
  • platform/hal/hal_gpadc.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_gpadc.c bes/platform/hal/hal_gpadc.c
      index 53528b5eae2..fb8964022c3 100644
      --- a/platform/hal/hal_gpadc.c
      +++ b/platform/hal/hal_gpadc.c
      @@ -14,7 +14,7 @@
        */
       #include "plat_addr_map.h"
       
      -#if !defined(GPADC_CHIP_SPECIFIC) && !defined(CHIP_SUBSYS_SENS)
      +#ifndef GPADC_CHIP_SPECIFIC
       
       #include "stddef.h"
       #include "cmsis_nvic.h"
      @@ -30,13 +30,13 @@
       #define gpadc_reg_read(reg,val)             pmu_read(reg,val)
       #define gpadc_reg_write(reg,val)            pmu_write(reg,val)
       
      -#ifdef GPADC_DYNAMIC_DATA_BITS
      -#define GPADC_VALUE_BITS                    gpadc_data_bits
      -#elif defined(CHIP_BEST1305) || defined(CHIP_BEST2002) || defined(CHIP_BEST2003)
      -#define GPADC_VALUE_BITS                    16
      -#else
      -#define GPADC_VALUE_BITS                    10
      -#endif
      +// Battery voltage = gpadc voltage * 4
      +// adc rate 0~2v(10bit)
      +// Battery_voltage:Adc_rate = 4:1
      +#define HAL_GPADC_MVOLT_A                   800
      +#define HAL_GPADC_MVOLT_B                   1050
      +#define HAL_GPADC_CALIB_DEFAULT_A           428
      +#define HAL_GPADC_CALIB_DEFAULT_B           565
       
       #if 0
       #elif defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || \
      @@ -151,7 +151,7 @@ enum GPADC_REG_T {
       
       // GPADC_REG_CH0_DATA
       #define DATA_CHAN0_SHIFT                    0
      -#define DATA_CHAN0_MASK                     (((1 << GPADC_VALUE_BITS) - 1) << DATA_CHAN0_SHIFT)
      +#define DATA_CHAN0_MASK                     (0x3FF << DATA_CHAN0_SHIFT)
       #define DATA_CHAN0(n)                       BITFIELD_VAL(DATA_CHAN0, n)
       
       #elif defined(CHIP_BEST1000)
      @@ -237,17 +237,17 @@ enum GPADC_REG_T {
       
       // GPADC_REG_CH0_DATA
       #define DATA_CHAN0_SHIFT                    0
      -#define DATA_CHAN0_MASK                     (((1 << GPADC_VALUE_BITS) - 1) << DATA_CHAN0_SHIFT)
      +#define DATA_CHAN0_MASK                     (0x3FF << DATA_CHAN0_SHIFT)
       #define DATA_CHAN0(n)                       BITFIELD_VAL(DATA_CHAN0, n)
       
       #else
       #error "Please update GPADC register definitions"
       #endif
       
      -static ADC_COEF_T g_adcSlope = 0;
      -static ADC_COEF_T g_adcIntcpt = 0;
      -static bool gpadc_irq_enabled = false;
      -static bool adckey_irq_enabled = false;
      +static int32_t g_adcSlope = 0;
      +static int32_t g_adcIntcpt = 0;
      +static bool gpadc_enabled = false;
      +static bool adckey_enabled = false;
       static bool irq_enabled = false;
       static bool g_adcCalibrated = false;
       static HAL_GPADC_EVENT_CB_T gpadc_event_cb[HAL_GPADC_CHAN_QTY];
      @@ -292,28 +292,27 @@ static void hal_gpadc_update_atp(void)
       
       static int hal_gpadc_adc2volt_calib(void)
       {
      -    ADC_COEF_T y1, y2, x1, x2;
      +    int32_t y1, y2, x1, x2;
           unsigned short efuse_a = 0;
           unsigned short efuse_b = 0;
       
           if (!g_adcCalibrated)
           {
      -        y1 = (ADC_COEF_T)HAL_GPADC_MVOLT_A;
      -        y2 = (ADC_COEF_T)HAL_GPADC_MVOLT_B;
      +        y1 = HAL_GPADC_MVOLT_A*1000;
      +        y2 = HAL_GPADC_MVOLT_B*1000;
       
               pmu_get_efuse(PMU_EFUSE_PAGE_BATTER_LV, &efuse_a);
       
      -        x1 = (ADC_COEF_T)(efuse_a > 0 ? efuse_a : HAL_GPADC_CALIB_DEFAULT_A);
      +        x1 = efuse_a > 0 ? efuse_a : HAL_GPADC_CALIB_DEFAULT_A;
       
               pmu_get_efuse(PMU_EFUSE_PAGE_BATTER_HV, &efuse_b);
      -        x2 = (ADC_COEF_T)(efuse_b > 0 ? efuse_b : HAL_GPADC_CALIB_DEFAULT_B);
      +        x2 = efuse_b > 0 ? efuse_b : HAL_GPADC_CALIB_DEFAULT_B;
       
      -        g_adcSlope = (y2 - y1) * ADC_CALC_FACTOR / (x2 - x1);
      -        g_adcIntcpt = ((y1 * x2) - (x1 * y2)) / ((x2 - x1));
      +        g_adcSlope = (y2-y1)/(x2-x1);
      +        g_adcIntcpt = ((y1*x2)-(x1*y2))/((x2-x1)*1000);
               g_adcCalibrated = true;
       
      -        TRACE(7,"%s efuse:%d/%d LV=%d, HV=%d, Slope:%d Intcpt:%d", __func__,
      -            efuse_a, efuse_b, (int32_t)x1, (int32_t)x2, (int32_t)g_adcSlope, (int32_t)g_adcIntcpt);
      +        TRACE(7,"%s efuse:%d/%d LV=%d, HV=%d, Slope:%d Intcpt:%d",__func__, efuse_a, efuse_b, x1, x2, g_adcSlope, g_adcIntcpt);
           }
       
           return 0;
      @@ -332,7 +331,7 @@ static HAL_GPADC_MV_T hal_gpadc_adc2volt(uint16_t gpadcVal)
           }
           else
           {
      -        voltage = (int32_t)(((g_adcSlope * gpadcVal) / ADC_CALC_FACTOR) + (g_adcIntcpt));
      +        voltage = (((g_adcSlope*gpadcVal)/1000) + (g_adcIntcpt));
       
               return (voltage < 0) ? 0 : voltage;
           }
      @@ -351,13 +350,13 @@ static void hal_gpadc_irq_handler(GPADC_IRQ_HDLR_PARAM)
           uint16_t adc_val;
           HAL_GPADC_MV_T volt;
       
      -#ifdef PMU_IRQ_UNIFIED
      -    irq_status &= hal_gpadc_get_cur_masked_irq();
      -#else
      +#ifndef PMU_IRQ_UNIFIED
           unsigned short irq_status;
       
           gpadc_reg_read(GPADC_REG_INT_MSKED_STS, &irq_status);
      -    irq_status &= hal_gpadc_get_cur_masked_irq();
      +    irq_status &= (CHAN_DATA_INTR_MSKED_MASK|SAMPLE_DONE_INTR_MSKED|
      +        KEY_RELEASE_INTR_MSKED|KEY_PRESS_INTR_MSKED|
      +        KEY_ERR0_INTR_MSKED|KEY_ERR1_INTR_MSKED);
           gpadc_reg_write(GPADC_REG_INT_CLR, irq_status);
       #endif
       
      @@ -393,7 +392,6 @@ static void hal_gpadc_irq_handler(GPADC_IRQ_HDLR_PARAM)
                               gpadc_reg_read(GPADC_REG_INT_MASK, &read_val);
                               read_val &= ~CHAN_DATA_INTR_MSK(1<<ch);
                               gpadc_reg_write(GPADC_REG_INT_MASK, read_val);
      -                        gpadc_irq_mask = read_val;
       
                               // Int enable
                               gpadc_reg_read(GPADC_REG_INT_EN, &read_val);
      @@ -404,7 +402,6 @@ static void hal_gpadc_irq_handler(GPADC_IRQ_HDLR_PARAM)
                               gpadc_reg_read(GPADC_REG_CH_EN, &read_val);
                               read_val &= ~CHAN_EN_REG(1<<ch);
                               gpadc_reg_write(GPADC_REG_CH_EN, read_val);
      -                        gpadc_chan_en = read_val;
       
                               int_unlock(lock);
                           }
      @@ -418,7 +415,8 @@ static void hal_gpadc_irq_handler(GPADC_IRQ_HDLR_PARAM)
       
           // Disable GPADC (GPADC_START will be cleared automatically unless in interval mode)
           lock = int_lock();
      -    if ((gpadc_chan_en & CHAN_EN_REG((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6))) == 0) {
      +    gpadc_reg_read(GPADC_REG_CH_EN, &read_val);
      +    if ((read_val & CHAN_EN_REG((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6))) == 0) {
               gpadc_reg_read(GPADC_REG_START, &read_val);
               read_val &= ~GPADC_START;
               gpadc_reg_write(GPADC_REG_START, read_val);
      @@ -452,7 +450,6 @@ static void hal_gpadc_irq_handler(GPADC_IRQ_HDLR_PARAM)
                       gpadc_reg_read(GPADC_REG_INT_MASK, &read_val);
                       read_val &= ~CHAN_DATA_INTR_MSK(1<<7);
                       gpadc_reg_write(GPADC_REG_INT_MASK, read_val);
      -                gpadc_irq_mask = read_val;
       
                       // Int enable
                       gpadc_reg_read(GPADC_REG_INT_EN, &read_val);
      @@ -467,7 +464,7 @@ static void hal_gpadc_irq_handler(GPADC_IRQ_HDLR_PARAM)
                   } else {
                       adc_val = HAL_GPADC_BAD_VALUE;
                   }
      -            adc_val = hal_gpadc_adc2volt(adc_val);
      +
                   ((HAL_ADCKEY_EVENT_CB_T)gpadc_event_cb[HAL_GPADC_CHAN_ADCKEY])(adckey_irq, adc_val);
               }
           }
      @@ -499,7 +496,7 @@ bool hal_gpadc_get_volt(enum HAL_GPADC_CHAN_T ch, HAL_GPADC_MV_T *volt)
       
       static void hal_gpadc_irq_control(void)
       {
      -    if (gpadc_irq_enabled || adckey_irq_enabled) {
      +    if (gpadc_enabled || adckey_enabled) {
               if (!irq_enabled) {
                   irq_enabled = true;
       #ifdef PMU_IRQ_UNIFIED
      @@ -552,7 +549,6 @@ int hal_gpadc_open(enum HAL_GPADC_CHAN_T channel, enum HAL_GPADC_ATP_T atp, HAL_
                   // GPADC VBAT needs 10us to be stable and consumes 13mA current
                   hal_sys_timer_delay_us(20);
       #endif
      -            // FALLTHROUGH
               case HAL_GPADC_CHAN_0:
               case HAL_GPADC_CHAN_2:
               case HAL_GPADC_CHAN_3:
      @@ -575,8 +571,7 @@ int hal_gpadc_open(enum HAL_GPADC_CHAN_T channel, enum HAL_GPADC_ATP_T atp, HAL_
                       gpadc_reg_read(GPADC_REG_INT_MASK, &val);
                       val |= CHAN_DATA_INTR_MSK(1<<channel);
                       gpadc_reg_write(GPADC_REG_INT_MASK, val);
      -                gpadc_irq_mask = val;
      -                gpadc_irq_enabled = true;
      +                gpadc_enabled = true;
                       hal_gpadc_irq_control();
                   }
       
      @@ -596,12 +591,10 @@ int hal_gpadc_open(enum HAL_GPADC_CHAN_T channel, enum HAL_GPADC_ATP_T atp, HAL_
                       reg_start_mask = GPADC_START;
                       if (GPADC_REG_START == GPADC_REG_CH_EN) {
                           reg_start_mask |= CHAN_EN_REG(1<<channel);
      -                    gpadc_chan_en = reg_start_mask;
                       } else {
                           gpadc_reg_read(GPADC_REG_CH_EN, &val);
                           val |= CHAN_EN_REG(1<<channel);
                           gpadc_reg_write(GPADC_REG_CH_EN, val);
      -                    gpadc_chan_en = val;
                       }
                   }
       
      @@ -658,7 +651,6 @@ int hal_gpadc_close(enum HAL_GPADC_CHAN_T channel)
                   gpadc_reg_read(GPADC_REG_INT_MASK, &val);
                   val &= ~CHAN_DATA_INTR_MSK(1<<channel);
                   gpadc_reg_write(GPADC_REG_INT_MASK, val);
      -            gpadc_irq_mask = val;
       
                   // Int enable
                   gpadc_reg_read(GPADC_REG_INT_EN, &chan_int_en);
      @@ -672,14 +664,13 @@ int hal_gpadc_close(enum HAL_GPADC_CHAN_T channel)
                   } else {
                       if (GPADC_REG_START == GPADC_REG_CH_EN) {
                           reg_start &= ~CHAN_EN_REG(1<<channel);
      -                    gpadc_chan_en = reg_start;
      +                    val = reg_start;
                       } else {
                           gpadc_reg_read(GPADC_REG_CH_EN, &val);
                           val &= ~CHAN_EN_REG(1<<channel);
                           gpadc_reg_write(GPADC_REG_CH_EN, val);
      -                    gpadc_chan_en = val;
                       }
      -                if (gpadc_chan_en & CHAN_EN_REG((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6))) {
      +                if (val & CHAN_EN_REG((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6))) {
                           hal_gpadc_update_atp();
                       } else {
                           reg_start &= ~GPADC_START;
      @@ -687,8 +678,8 @@ int hal_gpadc_close(enum HAL_GPADC_CHAN_T channel)
                   }
                   gpadc_reg_write(GPADC_REG_START, reg_start);
       
      -            if ((gpadc_irq_mask & CHAN_DATA_INTR_MSK((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7))) == 0) {
      -                gpadc_irq_enabled = false;
      +            if ((chan_int_en & CHAN_DATA_INTR_EN((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7))) == 0) {
      +                gpadc_enabled = false;
                       hal_gpadc_irq_control();
                   }
       
      @@ -720,13 +711,15 @@ void hal_gpadc_wakeup(void)
       {
           unsigned short val;
       
      -#if defined(CHIP_BEST1305) || defined(CHIP_BEST1501) || defined(CHIP_BEST1600) || \
      -        defined(CHIP_BEST2300) || defined(CHIP_BEST2300P) || defined(CHIP_BEST2300A)
      +#if defined(CHIP_BEST2300) || defined(CHIP_BEST2300P) || defined(CHIP_BEST2300A)
           return;
       #endif
       
      -    if (gpadc_chan_en & CHAN_EN_REG((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6))) {
      -        gpadc_reg_read(GPADC_REG_START, &val);
      +    gpadc_reg_read(GPADC_REG_CH_EN, &val);
      +    if (val & CHAN_EN_REG((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6))) {
      +        if (GPADC_REG_START != GPADC_REG_CH_EN) {
      +            gpadc_reg_read(GPADC_REG_START, &val);
      +        }
               val |= GPADC_START;
               gpadc_reg_write(GPADC_REG_START, val);
           }
      @@ -753,23 +746,23 @@ int hal_adckey_set_irq(enum HAL_ADCKEY_IRQ_T type)
           if (type == HAL_ADCKEY_IRQ_NONE) {
               clr_mask = KEY_RELEASE_INTR_MSK | KEY_PRESS_INTR_MSK | KEY_ERR0_INTR_MSK | KEY_ERR1_INTR_MSK;
               clr_en = KEY_RELEASE_INTR_EN | KEY_PRESS_INTR_EN | KEY_ERR0_INTR_EN | KEY_ERR1_INTR_EN;
      -        adckey_irq_enabled = false;
      +        adckey_enabled = false;
           } else if (type == HAL_ADCKEY_IRQ_PRESSED) {
               set_mask = KEY_PRESS_INTR_MSK | KEY_ERR0_INTR_MSK | KEY_ERR1_INTR_MSK;
               clr_mask = KEY_RELEASE_INTR_MSK;
               set_en = KEY_PRESS_INTR_EN | KEY_ERR0_INTR_EN | KEY_ERR1_INTR_EN;
               clr_en = KEY_RELEASE_INTR_EN;
      -        adckey_irq_enabled = true;
      +        adckey_enabled = true;
           } else if (type == HAL_ADCKEY_IRQ_RELEASED) {
               set_mask = KEY_RELEASE_INTR_MSK | KEY_ERR0_INTR_MSK | KEY_ERR1_INTR_MSK;
               clr_mask = KEY_PRESS_INTR_MSK;
               set_en = KEY_RELEASE_INTR_EN | KEY_ERR0_INTR_EN | KEY_ERR1_INTR_EN;
               clr_en = KEY_PRESS_INTR_EN;
      -        adckey_irq_enabled = true;
      +        adckey_enabled = true;
           } else if (type == HAL_ADCKEY_IRQ_BOTH) {
               set_mask = KEY_RELEASE_INTR_MSK | KEY_PRESS_INTR_MSK | KEY_ERR0_INTR_MSK | KEY_ERR1_INTR_MSK;
               set_en = KEY_RELEASE_INTR_EN | KEY_PRESS_INTR_EN | KEY_ERR0_INTR_EN | KEY_ERR1_INTR_EN;
      -        adckey_irq_enabled = true;
      +        adckey_enabled = true;
           } else {
               return 1;
           }
      @@ -780,7 +773,6 @@ int hal_adckey_set_irq(enum HAL_ADCKEY_IRQ_T type)
           val &= ~clr_mask;
           val |= set_mask;
           gpadc_reg_write(GPADC_REG_INT_MASK, val);
      -    gpadc_irq_mask = val;
       
           gpadc_reg_read(GPADC_REG_INT_EN, &val);
           val &= ~clr_en;
  • platform/hal/hal_gpio.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_gpio.c bes/platform/hal/hal_gpio.c
      index eb89b8157b7..8ef8ba7de2f 100644
      --- a/platform/hal/hal_gpio.c
      +++ b/platform/hal/hal_gpio.c
      @@ -12,16 +12,21 @@
        * See the License for the specific language governing permissions and
        * limitations under the License.
        */
      +#include "stdarg.h"
      +#include "stdio.h"
      +#include "plat_types.h"
       #include "plat_addr_map.h"
       #include "hal_gpio.h"
      -#include "reg_gpio_v1.h"
      +#include "reg_gpio.h"
       #include "hal_trace.h"
       #include "cmsis_nvic.h"
      +#include "hal_uart.h"
       #ifdef PMU_HAS_LED_PIN
       #include "pmu.h"
       #endif
       
       #define HAL_GPIO_BANK_NUM 1
      +#define HAL_GPIO_PORT_NUM 1
       
       #define HAL_GPIO_PIN_NUM_EACH_PORT (32)
       #define HAL_GPIO_PIN_NUM_EACH_BANK (HAL_GPIO_PORT_NUM*HAL_GPIO_PIN_NUM_EACH_PORT)
      @@ -48,6 +53,28 @@
       
       typedef void (* _HAL_GPIO_IRQ_HANDLER)(void);
       
      +struct GPIO_PORT_T {
      +    __IO uint32_t GPIO_DR;                              // 0x00
      +    __IO uint32_t GPIO_DDR;                             // 0x04
      +    __IO uint32_t GPIO_CTL;                             // 0x08
      +};
      +
      +struct GPIO_BANK_T {
      +    struct GPIO_PORT_T port[HAL_GPIO_PORT_NUM];
      +    struct GPIO_PORT_T _port_reserved[3];
      +    __IO uint32_t GPIO_INTEN;                           // 0x30
      +    __IO uint32_t GPIO_INTMASK;                         // 0x34
      +    __IO uint32_t GPIO_INTTYPE_LEVEL;                   // 0x38
      +    __IO uint32_t GPIO_INT_POLARITY;                    // 0x3C
      +    __I  uint32_t GPIO_INTSTATUS;                       // 0x40
      +    __I  uint32_t GPIO_RAW_INTSTATUS;                   // 0x44
      +    __IO uint32_t GPIO_DEBOUNCE;                        // 0x48
      +    __IO uint32_t GPIO_PORTA_EOI;                       // 0x4C
      +    __I  uint32_t GPIO_EXT_PORT[HAL_GPIO_PORT_NUM];     // 0x50
      +    __I  uint32_t GPIO_EXT_PORT_reserved[3];
      +    __IO uint32_t GPIO_LS_SYNC;                         // 0x60
      +};
      +
       void _hal_gpio_bank0_irq_handler(void);
       
       static struct GPIO_BANK_T * const gpio_bank[HAL_GPIO_BANK_NUM] = { (struct GPIO_BANK_T *)GPIO_BASE, };
  • platform/hal/hal_i2c.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_i2c.h bes/platform/hal/hal_i2c.h
      index 19890954521..19741e920eb 100644
      --- a/platform/hal/hal_i2c.h
      +++ b/platform/hal/hal_i2c.h
      @@ -210,6 +210,9 @@ uint32_t hal_gpio_i2c_simple_send(uint32_t device_addr, const uint8_t *tx_buf, u
       uint32_t hal_gpio_i2c_simple_recv(uint32_t device_addr, const uint8_t *tx_buf, uint16_t tx_len, uint8_t *rx_buf, uint16_t rx_len);
       
       
      +int app_i2c_demo_init(void);
      +unsigned char I2C_WriteByte(unsigned char reg, unsigned char data);
      +unsigned char I2C_ReadByte(unsigned char reg, unsigned char* data);
       #ifdef __cplusplus
       }
       #endif
  • platform/hal/hal_key.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_key.c bes/platform/hal/hal_key.c
      index d1927a5802c..1e9f2d9902d 100644
      --- a/platform/hal/hal_key.c
      +++ b/platform/hal/hal_key.c
      @@ -213,7 +213,7 @@ static enum HAL_KEY_CODE_T hal_adckey_findkey(uint16_t volt)
           }
       #endif
       
      -    if (CFG_HW_ADCKEY_ADC_KEYVOLT_BASE <= volt && volt < CFG_HW_ADCKEY_ADC_MAXVOLT) {
      +    if (CFG_HW_ADCKEY_ADC_KEYVOLT_BASE < volt && volt < CFG_HW_ADCKEY_ADC_MAXVOLT) {
               for (index = 0; index < CFG_HW_ADCKEY_NUMBER; index++) {
                   if (volt <= adckey_volt_table[index]) {
                       return CFG_HW_ADCKEY_MAP_TABLE[index];
      @@ -275,6 +275,7 @@ static void hal_adckey_open(void)
           uint16_t i;
           uint32_t basevolt;
       
      +    HAL_KEY_TRACE(1,"%s\n", __func__);
       
           hal_adckey_reset();
       
      @@ -385,7 +386,7 @@ static void hal_pwrkey_handle_irq_state(enum HAL_PWRKEY_IRQ_T state)
                       pwr_key.dither = true;
                   }
               }
      -        // pwr_key.time = time;
      +       // pwr_key.time = time;
           }
       
       #ifdef CHIP_BEST1000
      @@ -1109,7 +1110,7 @@ int hal_key_open(int checkPwrKey, int (* cb)(uint32_t, uint8_t))
       
               cnt = 10;
               do {
      -            hal_sys_timer_delay(MS_TO_TICKS(20));
      +            hal_sys_timer_delay(MS_TO_TICKS(150));
                   if (!hal_pwrkey_startup_pressed()) {
                       HAL_KEY_TRACE(0,"pwr_key init DITHERING");
                       nRet = -1;
  • platform/hal/hal_key.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_key.h bes/platform/hal/hal_key.h
      index 49823a5718c..048a554db4f 100644
      --- a/platform/hal/hal_key.h
      +++ b/platform/hal/hal_key.h
      @@ -56,6 +56,11 @@ enum HAL_KEY_EVENT_T {
           HAL_KEY_EVENT_TRIPLECLICK,
           HAL_KEY_EVENT_ULTRACLICK,
           HAL_KEY_EVENT_RAMPAGECLICK,
      +    HAL_KEY_EVENT_SIXTHCLICK,
      +    HAL_KEY_EVENT_SEVENTHCLICK,
      +    HAL_KEY_EVENT_EIGHTHCLICK,
      +    HAL_KEY_EVENT_NINETHCLICK,
      +    HAL_KEY_EVENT_TENTHCLICK,
           HAL_KEY_EVENT_REPEAT,
           HAL_KEY_EVENT_GROUPKEY_DOWN,
           HAL_KEY_EVENT_GROUPKEY_REPEAT,
  • platform/hal/hal_location.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_location.h bes/platform/hal/hal_location.h
      index b1f1ca7a056..e4cc36299af 100644
      --- a/platform/hal/hal_location.h
      +++ b/platform/hal/hal_location.h
      @@ -144,8 +144,8 @@ extern "C" {
       #define SYNC_FLAGS_LOC                  HAL_SEC_LOC(.sync_flags)
       #define SYNC_FLAGS_DEF(n)               HAL_SEC_DEF(.sync_flags, n)
       #else
      -#define SYNC_FLAGS_LOC                  HAL_SEC_LOC(.sram_bss)
      -#define SYNC_FLAGS_DEF(n)               HAL_SEC_DEF(.sram_bss, n)
      +#define SYNC_FLAGS_LOC
      +#define SYNC_FLAGS_DEF(n)               n
       #endif
       
       #if defined(__ARM_ARCH_ISA_ARM)
  • platform/hal/hal_mcu2cp.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_mcu2cp.h bes/platform/hal/hal_mcu2cp.h
      index 4971aab58d3..c19d29f52a7 100644
      --- a/platform/hal/hal_mcu2cp.h
      +++ b/platform/hal/hal_mcu2cp.h
      @@ -24,19 +24,27 @@ extern "C" {
       enum HAL_MCU2CP_ID_T {
           HAL_MCU2CP_ID_0,
           HAL_MCU2CP_ID_1,
      +
           HAL_MCU2CP_ID_QTY
       };
       
      +enum HAL_MCU2CP_MSG_TYPE_T {
      +    HAL_MCU2CP_MSG_TYPE_0,
      +    HAL_MCU2CP_MSG_TYPE_1,
      +
      +    HAL_MCU2CP_MSG_TYPE_QTY
      +};
      +
       typedef unsigned int (*HAL_MCU2CP_RX_IRQ_HANDLER)(const unsigned char *data, unsigned int len);
       typedef void (*HAL_MCU2CP_TX_IRQ_HANDLER)(const unsigned char *data, unsigned int len);
       
      -int hal_mcu2cp_open_mcu(enum HAL_MCU2CP_ID_T id,
      +int hal_mcu2cp_open_mcu(enum HAL_MCU2CP_ID_T id, enum HAL_MCU2CP_MSG_TYPE_T type,
                               HAL_MCU2CP_RX_IRQ_HANDLER rxhandler, HAL_MCU2CP_TX_IRQ_HANDLER txhandler, bool rx_flowctrl);
      -int hal_mcu2cp_open_cp (enum HAL_MCU2CP_ID_T id,
      +int hal_mcu2cp_open_cp (enum HAL_MCU2CP_ID_T id, enum HAL_MCU2CP_MSG_TYPE_T type,
                               HAL_MCU2CP_RX_IRQ_HANDLER rxhandler, HAL_MCU2CP_TX_IRQ_HANDLER txhandler, bool rx_flowctrl);
       
      -int hal_mcu2cp_close_mcu(enum HAL_MCU2CP_ID_T id);
      -int hal_mcu2cp_close_cp (enum HAL_MCU2CP_ID_T id);
      +int hal_mcu2cp_close_mcu(enum HAL_MCU2CP_ID_T id,enum HAL_MCU2CP_MSG_TYPE_T type);
      +int hal_mcu2cp_close_cp (enum HAL_MCU2CP_ID_T id,enum HAL_MCU2CP_MSG_TYPE_T type);
       
       int hal_mcu2cp_start_recv_mcu(enum HAL_MCU2CP_ID_T id);
       int hal_mcu2cp_start_recv_cp (enum HAL_MCU2CP_ID_T id);
      @@ -44,9 +52,9 @@ int hal_mcu2cp_start_recv_cp (enum HAL_MCU2CP_ID_T id);
       int hal_mcu2cp_stop_recv_mcu(enum HAL_MCU2CP_ID_T id);
       int hal_mcu2cp_stop_recv_cp (enum HAL_MCU2CP_ID_T id);
       
      -int hal_mcu2cp_send_mcu(enum HAL_MCU2CP_ID_T id,
      +int hal_mcu2cp_send_mcu(enum HAL_MCU2CP_ID_T id, enum HAL_MCU2CP_MSG_TYPE_T type,
                           const unsigned char *data, unsigned int len);
      -int hal_mcu2cp_send_cp (enum HAL_MCU2CP_ID_T id,
      +int hal_mcu2cp_send_cp (enum HAL_MCU2CP_ID_T id, enum HAL_MCU2CP_MSG_TYPE_T type,
                           const unsigned char *data, unsigned int len);
       
       void hal_mcu2cp_rx_done_mcu(enum HAL_MCU2CP_ID_T id);
  • platform/hal/hal_memsc.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_memsc.c bes/platform/hal/hal_memsc.c
      index 54dd3d9fd9f..551ba2ea529 100644
      --- a/platform/hal/hal_memsc.c
      +++ b/platform/hal/hal_memsc.c
      @@ -13,34 +13,32 @@
        * limitations under the License.
        */
       #include "plat_addr_map.h"
      -#include "hal_cmu.h"
       #include "hal_memsc.h"
      -#include CHIP_SPECIFIC_HDR(reg_cmu)
      -static struct CMU_T * const cmu = (struct CMU_T *)CMU_BASE;
      +#include "hal_cmu.h"
       
       int hal_memsc_lock(enum HAL_MEMSC_ID_T id)
       {
      -    if (id >= ARRAY_SIZE(cmu->MEMSC)) {
      +    if (id >= HAL_MEMSC_ID_QTY) {
               return 0;
           }
       
      -    return cmu->MEMSC[id];
      +    return (hal_cmu_get_memsc_addr())[id];
       }
       
       void hal_memsc_unlock(enum HAL_MEMSC_ID_T id)
       {
      -    if (id >= ARRAY_SIZE(cmu->MEMSC)) {
      +    if (id >= HAL_MEMSC_ID_QTY) {
               return;
           }
       
      -    cmu->MEMSC[id] = 1;
      +    (hal_cmu_get_memsc_addr())[id] = 1;
       }
       
       bool hal_memsc_avail(enum HAL_MEMSC_ID_T id)
       {
      -    if (id >= ARRAY_SIZE(cmu->MEMSC)) {
      +    if (id >= HAL_MEMSC_ID_QTY) {
               return false;
           }
       
      -    return !!(cmu->MEMSC_STATUS & (1 << id));
      +    return !!((hal_cmu_get_memsc_addr())[4] & (1 << id));
       }
  • platform/hal/hal_psram_v2.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_psram_v2.c bes/platform/hal/hal_psram_v2.c
      index 00684438ad0..fca8a146ab9 100644
      --- a/platform/hal/hal_psram_v2.c
      +++ b/platform/hal/hal_psram_v2.c
      @@ -12,7 +12,7 @@
        * See the License for the specific language governing permissions and
        * limitations under the License.
        */
      -#if defined(CHIP_HAS_PSRAM) && (CHIP_PSRAM_CTRL_VER == 2 || CHIP_PSRAM_CTRL_VER == 3)
      +#if defined(CHIP_HAS_PSRAM) && (CHIP_PSRAM_CTRL_VER >= 2)
       
       #include "plat_types.h"
       #include "plat_addr_map.h"
      @@ -30,7 +30,7 @@
       //#define PSRAM_DUAL_8BIT
       //#define PSRAM_WRAP_ENABLE
       
      -//
      +//#define PSRAM_DEBUG
       #ifdef PSRAM_DEBUG
       #define PSRAM_TRACE TRACE_IMM
       #else
      @@ -145,10 +145,12 @@ enum MEMIF_CMD_T {
       static struct PSRAM_MC_T * const psram_mc = (struct PSRAM_MC_T *)PSRAM_CTRL_BASE;
       static struct PSRAM_PHY_T * const psram_phy = (struct PSRAM_PHY_T *)(PSRAM_CTRL_BASE + 0x8000);
       
      +static const uint32_t psram_cfg_clk = 48*1000*1000;
      +
       #if (PSRAM_SPEED != 0)
       static const uint32_t psram_run_clk = PSRAM_SPEED*1000*1000;
       #else
      -#error "invalid PSRAM_SPEED"
      +#error "invalid PSRAMUHS_SPEED"
       #endif
       
       static void psram_chip_timing_config(uint32_t clk, bool psram_first);
      @@ -227,14 +229,14 @@ void hal_psramip_xfer_addr_len(uint32_t addr, uint32_t len)
       
       void hal_psramip_write_fifo(uint32_t *data, uint32_t len)
       {
      -    for (uint32_t i = 0; i < len; i++) {
      +    for (int i = 0; i < len; i++) {
               psram_mc->REG_014 = *data++;
           }
       }
       
       void hal_psramip_read_fifo(uint32_t *data, uint32_t len)
       {
      -    for (uint32_t i = 0; i < len; i++) {
      +    for (int i = 0; i < len; i++) {
               *data++ = psram_mc->REG_018;
           }
       }
      @@ -305,7 +307,7 @@ static void psram_set_timing(uint32_t clk)
           uint32_t reg;
           uint32_t val;
       
      -#ifdef PSRAM_XCCELA_MODE
      +#if PSRAMSIZE == 0x800000
           reg = 8;
       #ifdef PSRAM_WRAP_ENABLE
           // Wrap 32
      @@ -360,7 +362,7 @@ static void hal_psram_phy_dll_config(uint32_t clk)
           } else if (phy_clk <= 300000000 / 2) {
               range = 1;
           } else {
      -        range = 1;
      +        range = 0;
           }
           val = SET_BITFIELD(val, PSRAM_ULP_PHY_REG_DLL_RANGE, range);
           psram_phy->REG_050 = val;
      @@ -377,9 +379,9 @@ static void hal_psram_phy_init(uint32_t clk)
           hal_sys_timer_delay_us(10);
       
           val &= ~PSRAM_ULP_PHY_REG_LDO_PRECHARGE;
      -    val = SET_BITFIELD(val, PSRAM_ULP_PHY_REG_LDO_IEN1, 0xd);
      -    val = SET_BITFIELD(val, PSRAM_ULP_PHY_REG_LDO_IEN2, 0x7);
      -    val = SET_BITFIELD(val, PSRAM_ULP_PHY_REG_LDO_VTUNE, 0x2);
      +    val = SET_BITFIELD(val, PSRAM_ULP_PHY_REG_LDO_IEN1, 0xc);
      +    val = SET_BITFIELD(val, PSRAM_ULP_PHY_REG_LDO_IEN2, 0x5);
      +    val = SET_BITFIELD(val, PSRAM_ULP_PHY_REG_LDO_VTUNE, 0x0);
           psram_phy->REG_048 = val;
       
           val = psram_phy->REG_04C;
      @@ -401,7 +403,7 @@ static void hal_psram_phy_init(uint32_t clk)
           hal_psram_phy_dll_config(clk);
       }
       
      -static void hal_psram_mc_set_timing(uint32_t clk, bool init)
      +static void hal_psram_mc_set_timing(uint32_t clk)
       {
           uint32_t val;
       
      @@ -411,6 +413,7 @@ static void hal_psram_mc_set_timing(uint32_t clk, bool init)
               val = PSRAM_ULP_MC_WRITE_LATENCY(2);
           }
           psram_mc->REG_028 = val;
      +#if (CHIP_PSRAM_CTRL_VER == 2)
           if (clk <= 66000000) {
               val = PSRAM_ULP_MC_READ_LATENCY(2);
           } else if (clk <= 109000000) {
      @@ -423,6 +426,10 @@ static void hal_psram_mc_set_timing(uint32_t clk, bool init)
               val = PSRAM_ULP_MC_READ_LATENCY(6);
           }
           psram_mc->REG_02C = val;
      +#else
      +    // Min latency: 2 cycles
      +    psram_mc->REG_02C = PSRAM_ULP_MC_READ_LATENCY(2);
      +#endif
           // tRC >= 55 ns
           val = (clk / 1000000 * 55 + (1000 - 1)) / 1000;
           psram_mc->REG_050 = PSRAM_ULP_MC_T_RC(val);
      @@ -431,7 +438,7 @@ static void hal_psram_mc_set_timing(uint32_t clk, bool init)
           psram_mc->REG_068 = PSRAM_ULP_MC_T_MRR(val);
           val = 6;
           psram_mc->REG_060 = PSRAM_ULP_MC_T_CPHW(val);
      -#if CHIP_PSRAM_CTRL_VER == 2
      +#ifdef CHIP_BEST2001
           val += 1;
       #endif
           psram_mc->REG_06C = PSRAM_ULP_MC_T_MRS(val);
      @@ -441,17 +448,17 @@ static void hal_psram_mc_set_timing(uint32_t clk, bool init)
           // tRST >= 2 us
           val = clk / 1000000 * 2 + 1;
           psram_mc->REG_074 = PSRAM_ULP_MC_T_RST(val);
      -    // tHS >= 2 us
      -    val = clk / 1000000 * 2 + 1;
      +    // tHS >= 4 us
      +    val = clk / 1000000 * 4 + 1;
           psram_mc->REG_080 = PSRAM_ULP_MC_T_HS(val);
      -    // tXPHS in [60 ns, 2 us]
      +    // tXPHS in [60 ns, 4 us]
           val = (clk / 1000000 * 60 + (1000 - 1)) / 1000;
           psram_mc->REG_084 = PSRAM_ULP_MC_T_XPHS(val);
      -    // tXHS >= 100 us
      -    val = clk / 1000000 * 100 + 1;
      +    // tXHS >= 70 us
      +    val = clk / 1000000 * 70 + 1;
           psram_mc->REG_088 = PSRAM_ULP_MC_T_XHS(val);
           psram_mc->REG_09C = PSRAM_ULP_MC_WR_DMY_CYC(1);
      -    // NOP dummy cycles, same as tXPHS in [60 ns, 2 us]
      +    // NOP dummy cycles, same as tXPHS in [60 ns, 4 us]
           val = (clk / 1000000 * 60 + (1000 - 1)) / 1000;
           psram_mc->REG_0A0 = PSRAM_ULP_MC_STOP_CLK_IN_NOP | PSRAM_ULP_MC_NOP_DMY_CYC(val);
           psram_mc->REG_0A4 = PSRAM_ULP_MC_QUEUE_IDLE_CYCLE(5000);
      @@ -461,7 +468,7 @@ static void hal_psram_init_calib(void)
       {
           uint32_t delay;
       
      -    hal_psram_phy_wait_lock();
      +    while ((psram_phy->REG_058 & PSRAM_ULP_PHY_DLL_LOCK) == 0);
       
           delay = GET_BITFIELD(psram_phy->REG_058, PSRAM_ULP_PHY_DLL_DLY_IN);
           //ASSERT(delay < (PSRAM_ULP_PHY_DLL_DLY_IN_MASK >> PSRAM_ULP_PHY_DLL_DLY_IN_SHIFT),
      @@ -474,14 +481,14 @@ static void hal_psram_init_calib(void)
       
       static void hal_psram_mc_init(uint32_t clk)
       {
      -#if defined(PSRAM_DUAL_8BIT)
      -    psram_mc->REG_000 |= PSRAM_ULP_MC_CHIP_BIT;
      +#ifdef PSRAM_DUAL_8BIT
      +    psram_mc->REG_000 = PSRAM_ULP_MC_CHIP_BIT;
       #else
           psram_mc->REG_000 = 0;
       #endif
           psram_mc->REG_020 = 0;
           psram_mc->REG_024 =
      -#if CHIP_PSRAM_CTRL_VER >= 3
      +#ifndef CHIP_BEST2001
               PSRAM_ULP_MC_ENTRY_SLEEP_IDLE |
       #endif
               PSRAM_ULP_MC_AUTOWAKEUP_EN |
      @@ -490,12 +497,14 @@ static void hal_psram_mc_init(uint32_t clk)
           // Burst len: 32 bytes, page: 1K
           psram_mc->REG_034 = PSRAM_ULP_MC_BURST_LENGTH(1) | PSRAM_ULP_MC_PAGE_BOUNDARY(0);
       #else
      +    // 8MB psram
      +    // Burst len: 1K, page: 1K
           psram_mc->REG_034 = PSRAM_ULP_MC_BURST_LENGTH(4) | PSRAM_ULP_MC_PAGE_BOUNDARY(0);
       #endif
           // AHB bus width: 32 bits
           psram_mc->REG_038 = 0;
           // Write buffer level with high priority: 0~7
      -    psram_mc->REG_03C = PSRAM_ULP_MC_HIGH_PRI_LEVEL(1);
      +    psram_mc->REG_03C = PSRAM_ULP_MC_HIGH_PRI_LEVEL(4);
       #ifdef PSRAM_WRAP_ENABLE
           psram_mc->REG_040 = PSRAM_ULP_MC_CP_WRAP_EN;
       #else
      @@ -506,17 +515,18 @@ static void hal_psram_mc_init(uint32_t clk)
       
           hal_psramip_set_reg_data_mask();
       
      -    hal_psram_mc_set_timing(clk, true);
      +    hal_psram_mc_set_timing(clk);
       
           psram_mc->REG_400 = PSRAM_ULP_MC_INIT_COMPLETE;
       
      +    hal_psram_init_calib();
       }
       
       void hal_psram_sleep(void)
       {
           hal_psramip_mc_busy_wait();
           if (!hal_psramip_mc_in_sleep()) {
      -#if CHIP_PSRAM_CTRL_VER >= 3
      +#ifndef CHIP_BEST2001
               psram_mc->REG_024 &= ~PSRAM_ULP_MC_ENTRY_SLEEP_IDLE;
       #endif
               hal_psramip_mc_busy_wait();
      @@ -528,7 +538,7 @@ void hal_psram_sleep(void)
       void hal_psram_wakeup(void)
       {
           hal_psramip_mc_busy_wait();
      -#if CHIP_PSRAM_CTRL_VER >= 3
      +#ifndef CHIP_BEST2001
           psram_mc->REG_024 |= PSRAM_ULP_MC_ENTRY_SLEEP_IDLE;
       #endif
       }
      @@ -542,7 +552,7 @@ static void psram_chip_timing_config(uint32_t clk, bool update_psram_first)
           } else if (clk <= 104000000) {
               freq = HAL_CMU_FREQ_208M;
           } else {
      -#ifdef HAL_CMU_FREQ_390M
      +#ifdef HAL_CMU_FREQ_T
               freq = HAL_CMU_FREQ_390M;
       #else
               freq = HAL_CMU_FREQ_208M;
      @@ -554,10 +564,10 @@ static void psram_chip_timing_config(uint32_t clk, bool update_psram_first)
           }
       
           hal_cmu_mem_set_freq(freq);
      -    hal_sys_timer_delay_us(500);
      +    hal_sys_timer_delay_us(3);
           hal_psram_phy_dll_config(clk);
           hal_psram_init_calib();
      -    hal_psram_mc_set_timing(clk, false);
      +    hal_psram_mc_set_timing(clk);
           if (!update_psram_first) {
               psram_set_timing(clk);
           }
      @@ -565,29 +575,20 @@ static void psram_chip_timing_config(uint32_t clk, bool update_psram_first)
       
       static bool psramphy_check_write_valid()
       {
      -    uint32_t i;
      -    uint32_t val, val0, val1;
      -    uint32_t val2, val3;
      +    int i;
           volatile uint32_t *psram_base = (volatile uint32_t *)PSRAM_NC_BASE;
      -
      -    for (i = 0; i < 0x100; ++i) {
      +    for (i = 0; i < 0x8; ++i) {
               *(psram_base + i) = 0xffffffff;
           }
      -    for (i = 0; i < 0x100; ++i) {
      -        val = i & 0xFF;
      -        val = val | (val << 8) | (val << 16) | (val << 24);
      -        val0 = (val & 0x00FF00FF) | ((~val) & 0xFF00FF00);
      -        *(psram_base + i) = val0;
      +    for (i = 0; i < 0x8; ++i) {
      +        *(psram_base + i) = ((i << 0) | (i << 8) | (i << 16) | (i << 24));
           }
           hal_psramip_wb_busy_wait();
           hal_psramip_mc_busy_wait();
      -    for (i = 0; i < 0x100; ++i) {
      -        val = i & 0xFF;
      -        val = val | (val << 8) | (val << 16) | (val << 24);
      -        val0 = (val & 0x00FF00FF) | ((~val) & 0xFF00FF00);
      -        val2 = *(psram_base + i);
      -        if (val2 != val0) {
      -            //PSRAM_TRACE(3, "%s, i:%d, 0x%x, 0x%x", __FUNCTION__, i, val2, val0);
      +    for (i = 0; i < 0x8; ++i) {
      +        uint32_t check_val = *(psram_base+i);
      +        if (check_val != ((i << 0) | (i << 8) | (i << 16) | (i << 24))) {
      +            //PSRAM_TRACE(2,"write fail, %p = 0x%x", (uint32_t)(psram_base+i), check_val);
                   return false;
               }
           }
      @@ -598,25 +599,23 @@ static void hal_psram_calib_range(uint32_t range)
       {
           uint32_t val;
           uint32_t delay;
      -    POSSIBLY_UNUSED uint8_t tx_dqs, rx_dqs, tx_ceb, tx_clk;
      +    uint8_t tx_dqs, rx_dqs;
           uint8_t inc_delay, volume;
      -    #define BUFFER_SIZE  0x20
      -    bool cali_valid[BUFFER_SIZE][BUFFER_SIZE];
      -    uint8_t cali_value[BUFFER_SIZE][BUFFER_SIZE];
      +    uint8_t cali_valid[0x20][0x20];
      +    uint8_t cali_value[0x20][0x20];
       
      -    ASSERT(range <= (PSRAM_ULP_PHY_REG_DLL_RANGE_MASK >> PSRAM_ULP_PHY_REG_DLL_RANGE_SHIFT), "ERROR, bad ana phy range:%d", range);
      +    ASSERT(range <= (PSRAM_ULP_PHY_DLL_DLY_IN_MASK >> PSRAM_ULP_PHY_DLL_DLY_IN_SHIFT), "ERROR, bad ana phy range:%d", range);
       
           val = psram_phy->REG_050;
           val &= ~(PSRAM_ULP_PHY_REG_DLL_RESETB | PSRAM_ULP_PHY_REG_DLL_CK_RDY);
           psram_phy->REG_050 = val;
           val = SET_BITFIELD(val, PSRAM_ULP_PHY_REG_DLL_RANGE, range);
           psram_phy->REG_050 = val;
      -    hal_sys_timer_delay_us(100);
           val |= (PSRAM_ULP_PHY_REG_DLL_RESETB | PSRAM_ULP_PHY_REG_DLL_CK_RDY);
           psram_phy->REG_050 = val;
       
           hal_sys_timer_delay_us(100);
      -    hal_psram_phy_wait_lock();
      +    while ((psram_phy->REG_058 & PSRAM_ULP_PHY_DLL_LOCK) == 0);
       
           val = psram_phy->REG_058;
           if ((val & PSRAM_ULP_PHY_DLL_ALL_ONE)) {
      @@ -627,7 +626,7 @@ static void hal_psram_calib_range(uint32_t range)
           delay = GET_BITFIELD(val, PSRAM_ULP_PHY_DLL_DLY_IN);
           PSRAM_TRACE(4, "%s, range:%d, T/4 = 0x%x(psram_phy->REG_058:0x%x)", __func__, range, delay / 2, val);
           if (delay > (PSRAM_ULP_PHY_REG_PSRAM_TX_DQS_DLY_MASK >> PSRAM_ULP_PHY_REG_PSRAM_TX_DQS_DLY_SHIFT) && range < 3) {
      -        PSRAM_TRACE(2, "%s: bad delay (T/2 > 0x1f). increase range=%d", __func__, range + 1);
      +        PSRAM_TRACE("%s: bad delay (T/2 > 0x1f). increase range=%d", __func__, range + 1);
               return hal_psram_calib_range(range + 1);
           }
       
      @@ -640,44 +639,41 @@ static void hal_psram_calib_range(uint32_t range)
       
           PSRAM_TRACE(2, "volume:%d, inc_delay:%d", volume, inc_delay);
       
      -    tx_ceb = delay / 2;
      -    tx_clk = delay / 2 + 2;
      -
           uint8_t all_valid = 1;
       
           memset(cali_valid, 0, sizeof(cali_valid));
           for (tx_dqs = 0; tx_dqs <= volume; tx_dqs++) {
               for (rx_dqs = 0; rx_dqs <= volume; rx_dqs++) {
      -            psram_phy->REG_054 = PSRAM_ULP_PHY_REG_PSRAM_TX_CEB_DLY(tx_ceb) | PSRAM_ULP_PHY_REG_PSRAM_TX_CLK_DLY(tx_clk) |
      +            psram_phy->REG_054 = PSRAM_ULP_PHY_REG_PSRAM_TX_CEB_DLY(delay / 2) | PSRAM_ULP_PHY_REG_PSRAM_TX_CLK_DLY(delay / 2) |
                                        PSRAM_ULP_PHY_REG_PSRAM_TX_DQS_DLY(tx_dqs * inc_delay) | PSRAM_ULP_PHY_REG_PSRAM_RX_DQS_DLY(rx_dqs * inc_delay);
                   cali_valid[tx_dqs][rx_dqs] = psramphy_check_write_valid();
      -            if (cali_valid[tx_dqs][rx_dqs] == false)
      +            if (cali_valid[tx_dqs][rx_dqs] == 0)
                       all_valid = 0;
               }
           }
       
           if (all_valid && range < (PSRAM_ULP_PHY_DLL_DLY_IN_MASK >> PSRAM_ULP_PHY_DLL_DLY_IN_SHIFT)) {
      -        //PSRAM_TRACE(2, "%s: all valid increase range=%d", __func__, range+1);
      +        PSRAM_TRACE(2,"%s: all valid increase range=%d", __func__, range+1);
               //return hal_psram_calib_range(range+1);
           }
       
           memset(cali_value, 0, sizeof(cali_value));
      -    PSRAM_TRACENOCRLF_NOTS(0, "\r\n\r\n ---------------------------------------------------------------------- \r\n");
      -    PSRAM_TRACENOCRLF_NOTS(0, "    rx_dqs");
      +    PSRAM_TRACENOCRLF_NOTS("\r\n\r\n ---------------------------------------------------------------------- \r\n");
      +    PSRAM_TRACENOCRLF_NOTS("    rx_dqs");
           for (tx_dqs = 0; tx_dqs <= volume; tx_dqs++) {
      -        PSRAM_TRACENOCRLF_NOTS(1, " %2d ", tx_dqs * inc_delay);
      +        PSRAM_TRACENOCRLF_NOTS(" %2d ", tx_dqs*inc_delay);
           }
      -    PSRAM_TRACENOCRLF_NOTS(0, "\r\n");
      +    PSRAM_TRACENOCRLF_NOTS("\r\n");
           for (tx_dqs = 0; tx_dqs <= volume; tx_dqs++) {
      -        PSRAM_TRACENOCRLF_NOTS(1, "tx_dqs:%2d ", tx_dqs * inc_delay);
      +        PSRAM_TRACENOCRLF_NOTS("tx_dqs:%2d ", tx_dqs*inc_delay);
               for (rx_dqs = 0; rx_dqs <= volume; rx_dqs++) {
      -            PSRAM_TRACENOCRLF_NOTS(1, "  %d ", cali_valid[tx_dqs][rx_dqs]);
      +            PSRAM_TRACENOCRLF_NOTS("  %d ", cali_valid[tx_dqs][rx_dqs]);
                   if (cali_valid[tx_dqs][rx_dqs]) {
                       uint8_t len_from_zero;
                       int8_t p;
                       p = tx_dqs;
                       while (p >= 0) {
      -                    if (cali_valid[p][rx_dqs] == false)
      +                    if (cali_valid[p][rx_dqs] == 0)
                               break;
                           p--;
                       }
      @@ -686,7 +682,7 @@ static void hal_psram_calib_range(uint32_t range)
       
                       p = tx_dqs;
                       while (p <= volume) {
      -                    if (cali_valid[p][rx_dqs] == false)
      +                    if (cali_valid[p][rx_dqs] == 0)
                               break;
                           p++;
                       }
      @@ -695,7 +691,7 @@ static void hal_psram_calib_range(uint32_t range)
       
                       p = rx_dqs;
                       while (p >= 0) {
      -                    if (cali_valid[tx_dqs][p] == false)
      +                    if (cali_valid[tx_dqs][p] == 0)
                               break;
                           p--;
                       }
      @@ -704,7 +700,7 @@ static void hal_psram_calib_range(uint32_t range)
       
                       p = rx_dqs;
                       while (p <= volume) {
      -                    if (cali_valid[tx_dqs][p] == false)
      +                    if (cali_valid[tx_dqs][p] == 0)
                               break;
                           p++;
                       }
      @@ -712,25 +708,25 @@ static void hal_psram_calib_range(uint32_t range)
                       cali_value[tx_dqs][rx_dqs] = MIN(cali_value[tx_dqs][rx_dqs], len_from_zero);
                   }
               }
      -        PSRAM_TRACENOCRLF_NOTS(0, "\r\n");
      +        PSRAM_TRACENOCRLF_NOTS("\r\n");
           }
      -    PSRAM_TRACENOCRLF_NOTS(0, " -------------------------------------------------------------------------- \r\n");
      +    PSRAM_TRACENOCRLF_NOTS(" -------------------------------------------------------------------------- \r\n");
       
       #if 0
      -    PSRAM_TRACENOCRLF_NOTS(0, "\r\n\r\n ---------------------------------------------------------------------- \r\n");
      -    PSRAM_TRACENOCRLF_NOTS(0, "    rx_dqs");
      +    PSRAM_TRACENOCRLF_NOTS("\r\n\r\n ---------------------------------------------------------------------- \r\n");
      +    PSRAM_TRACENOCRLF_NOTS("    rx_dqs");
           for (tx_dqs = 0; tx_dqs <= volume; tx_dqs++) {
      -        PSRAM_TRACENOCRLF_NOTS(1, " %2d ", tx_dqs * inc_delay);
      +        PSRAM_TRACENOCRLF_NOTS(" %2d ", tx_dqs * inc_delay);
           }
      -    PSRAM_TRACENOCRLF_NOTS(0, "\r\n");
      +    PSRAM_TRACENOCRLF_NOTS("\r\n");
           for (tx_dqs = 0; tx_dqs <= volume; tx_dqs++) {
      -        PSRAM_TRACENOCRLF_NOTS(1, "tx_dqs:%2d ", tx_dqs * inc_delay);
      +        PSRAM_TRACENOCRLF_NOTS("tx_dqs:%2d ", tx_dqs * inc_delay);
               for (rx_dqs = 0; rx_dqs <= volume; rx_dqs++) {
      -            PSRAM_TRACENOCRLF_NOTS(1, "  %d ", cali_value[tx_dqs][rx_dqs]);
      +            PSRAM_TRACENOCRLF_NOTS("  %d ", cali_value[tx_dqs][rx_dqs]);
               }
      -        PSRAM_TRACENOCRLF_NOTS(0, "\r\n");
      +        PSRAM_TRACENOCRLF_NOTS("\r\n");
           }
      -    PSRAM_TRACENOCRLF_NOTS(0, " -------------------------------------------------------------------------- \r\n");
      +    PSRAM_TRACENOCRLF_NOTS(" -------------------------------------------------------------------------- \r\n");
       #endif
       
           uint32_t position = 0;
      @@ -743,20 +739,20 @@ static void hal_psram_calib_range(uint32_t range)
                   }
               }
           }
      -    PSRAM_TRACENOCRLF_NOTS(1, "position:%d\r\n", position);
      +    PSRAM_TRACENOCRLF_NOTS("position:%d\r\n", position);
           tx_dqs = position / (volume + 1) * inc_delay;
           rx_dqs = (position % (volume + 1)) * inc_delay;
      -    PSRAM_TRACENOCRLF_NOTS(2, "most optimal position. tx_dqs:%d, rx_dqs:%d\r\n", tx_dqs, rx_dqs);
      +    PSRAM_TRACENOCRLF_NOTS("most optimal position. tx_dqs:%d, rx_dqs:%d\r\n", tx_dqs, rx_dqs);
       
      -    psram_phy->REG_054 = PSRAM_ULP_PHY_REG_PSRAM_TX_CEB_DLY(tx_ceb) | PSRAM_ULP_PHY_REG_PSRAM_TX_CLK_DLY(tx_clk) |
      +    psram_phy->REG_054 = PSRAM_ULP_PHY_REG_PSRAM_TX_CEB_DLY(delay / 2) | PSRAM_ULP_PHY_REG_PSRAM_TX_CLK_DLY(delay / 2) |
                                PSRAM_ULP_PHY_REG_PSRAM_TX_DQS_DLY(tx_dqs) | PSRAM_ULP_PHY_REG_PSRAM_RX_DQS_DLY(rx_dqs);
       
       }
      -void hal_psram_calib(uint32_t clk)
      +static void hal_psram_calib(uint32_t clk)
       {
           uint32_t phy_clk;
           uint32_t range;
      -    PSRAM_TRACE(2, "%s, speed:%d", __func__, clk);
      +    PSRAM_TRACE("%s, speed:%d", __func__, clk);
           phy_clk = clk;
           if (phy_clk <= 100000000 / 2) {
               range = 3;
      @@ -765,7 +761,7 @@ void hal_psram_calib(uint32_t clk)
           } else if (phy_clk <= 300000000 / 2) {
               range = 1;
           } else {
      -        range = 1;
      +        range = 0;
           }
           hal_psram_calib_range(range);
       }
      @@ -790,7 +786,7 @@ void hal_psram_init(void)
           hal_cmu_reset_clear(HAL_CMU_MOD_H_PSRAM);
       
           hal_psram_phy_init(psram_cfg_clk);
      -    hal_sys_timer_delay_us(100);
      +    hal_sys_timer_delay_us(30);
           hal_psram_mc_init(psram_cfg_clk);
       
       #ifdef PSRAM_RESET
  • platform/hal/hal_pwm.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_pwm.c bes/platform/hal/hal_pwm.c
      index 43fcb4df052..7a6a7c20ca4 100644
      --- a/platform/hal/hal_pwm.c
      +++ b/platform/hal/hal_pwm.c
      @@ -29,22 +29,22 @@
       
       static struct PWM_T * const pwm[] = {
           (struct PWM_T *)PWM_BASE,
      -#if defined(CHIP_BEST2000)
      -    (struct PWM_T *)PWM1_BASE,
      +#ifdef CHIP_BEST2000
      +    (struct PWM_T *)AON_PWM_BASE,
       #endif
       };
       
       static const enum HAL_CMU_MOD_ID_T pwm_o_mod[] = {
           HAL_CMU_MOD_O_PWM0,
      -#if defined(CHIP_BEST2000)
      -    HAL_CMU_MOD_O_PWM4,
      +#ifdef CHIP_BEST2000
      +    HAL_CMU_AON_O_PWM0,
       #endif
       };
       
       static const enum HAL_CMU_MOD_ID_T pwm_p_mod[] = {
           HAL_CMU_MOD_P_PWM,
      -#if defined(CHIP_BEST2000)
      -    HAL_CMU_MOD_P_PWM1,
      +#ifdef CHIP_BEST2000
      +    HAL_CMU_AON_A_PWM,
       #endif
       };
       
      @@ -105,23 +105,20 @@ int hal_pwm_enable(enum HAL_PWM_ID_T id, const struct HAL_PWM_CFG_T *cfg)
               toggle = PWM_MAX_VALUE - toggle;
           }
       
      -#if defined(CHIP_BEST2000)
      -    if (id < HAL_PWM1_ID_0) {
      +#ifdef CHIP_BEST2000
      +    if (id < HAL_PWM2_ID_0) {
               index = 0;
               offset = id - HAL_PWM_ID_0;
           } else {
               index = 1;
      -        offset = id - HAL_PWM1_ID_0;
      +        offset = id - HAL_PWM2_ID_0;
           }
       #else
           index = 0;
           offset = id - HAL_PWM_ID_0;
       #endif
       
      -    lock = int_lock();
      -
      -    if ((pwm_map & (1 << id)) == 0) {
      -        pwm_map |= (1 << id);
      +    if (hal_cmu_reset_get_status(pwm_o_mod[index] + offset) == HAL_CMU_RST_SET) {
               hal_cmu_clock_enable(pwm_o_mod[index] + offset);
               hal_cmu_clock_enable(pwm_p_mod[index]);
               hal_cmu_reset_clear(pwm_o_mod[index] + offset);
      @@ -132,10 +129,12 @@ int hal_pwm_enable(enum HAL_PWM_ID_T id, const struct HAL_PWM_CFG_T *cfg)
       
           if (ratio == 0) {
               // Output 0 when disabled
      -        goto _exit;
      +        return 0;
           }
       
      -    hal_cmu_pwm_set_freq(id, (mod_freq == PWM_FAST_CLOCK) ? mod_freq : 0);
      +    hal_cmu_pwm_set_freq(id, mod_freq);
      +
      +    lock = int_lock();
       
           if (offset == 0) {
               pwm[index]->LOAD01 = SET_BITFIELD(pwm[index]->LOAD01, PWM_LOAD01_0, load);
      @@ -159,7 +158,6 @@ int hal_pwm_enable(enum HAL_PWM_ID_T id, const struct HAL_PWM_CFG_T *cfg)
       
           pwm[index]->EN |= (1 << offset);
       
      -_exit:
           int_unlock(lock);
       
           return 0;
      @@ -174,13 +172,13 @@ int hal_pwm_disable(enum HAL_PWM_ID_T id)
               return 1;
           }
       
      -#if defined(CHIP_BEST2000)
      -    if (id < HAL_PWM1_ID_0) {
      +#ifdef CHIP_BEST2000
      +    if (id < HAL_PWM2_ID_0) {
               index = 0;
               offset = id - HAL_PWM_ID_0;
           } else {
               index = 1;
      -        offset = id - HAL_PWM1_ID_0;
      +        offset = id - HAL_PWM2_ID_0;
           }
       #else
           index = 0;
      @@ -188,12 +186,15 @@ int hal_pwm_disable(enum HAL_PWM_ID_T id)
       #endif
       
           if (hal_cmu_reset_get_status(pwm_o_mod[index] + offset) == HAL_CMU_RST_SET) {
      -        hal_cmu_clock_enable(pwm_o_mod[index] + offset);
      -        hal_cmu_clock_enable(pwm_p_mod[index]);
      -        hal_cmu_reset_clear(pwm_o_mod[index] + offset);
      -        hal_cmu_reset_clear(pwm_p_mod[index]);
      -    } else {
      -        pwm[index]->EN &= ~(1 << offset);
      +        return 0;
      +    }
      +
      +    pwm[index]->EN &= ~(1 << offset);
      +    hal_cmu_reset_set(pwm_o_mod[index] + offset);
      +    hal_cmu_clock_disable(pwm_o_mod[index] + offset);
      +    if (pwm[index]->EN == 0) {
      +        hal_cmu_reset_set(pwm_p_mod[index]);
      +        hal_cmu_clock_disable(pwm_p_mod[index]);
           }
       
           return 0;
  • platform/hal/hal_sleep.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_sleep.c bes/platform/hal/hal_sleep.c
      index f56f9396713..ad0257d0a1d 100644
      --- a/platform/hal/hal_sleep.c
      +++ b/platform/hal/hal_sleep.c
      @@ -96,7 +96,23 @@ int hal_sleep_get_stats(struct CPU_USAGE_T *usage)
           return ret;
       }
       
      +static int hal_sleep_cpu_busy(void)
      +{
      +    if (cpu_wake_lock_map || hal_cmu_lpu_busy()) {
      +        return 1;
      +    } else {
      +        return 0;
      +    }
      +}
       
      +static int hal_sleep_sys_busy(void)
      +{
      +    if (sys_wake_lock_map || hal_sysfreq_busy() || hal_dma_busy()) {
      +        return 1;
      +    } else {
      +        return 0;
      +    }
      +}
       
       int hal_sleep_set_sleep_hook(enum HAL_SLEEP_HOOK_USER_T user, HAL_SLEEP_HOOK_HANDLER handler)
       {
      @@ -207,15 +223,19 @@ int SRAM_TEXT_LOC hal_sleep_specific_irq_pending(const uint32_t *irq, uint32_t c
           return 0;
       }
       
      +void WEAK bt_drv_sleep(void)
      +{
      +}
       
      +void WEAK bt_drv_wakeup(void)
      +{
      +}
       
       static enum HAL_SLEEP_STATUS_T SRAM_TEXT_LOC hal_sleep_lowpower_mode(void)
       {
           enum HAL_SLEEP_STATUS_T ret;
           enum HAL_CMU_LPU_SLEEP_MODE_T mode;
      -    uint32_t prev_time = 0;
      -    uint32_t cur_time;
      -    uint32_t interval;
      +    uint32_t time = 0;
       
           ret = HAL_SLEEP_STATUS_LIGHT;
       
      @@ -225,21 +245,23 @@ static enum HAL_SLEEP_STATUS_T SRAM_TEXT_LOC hal_sleep_lowpower_mode(void)
           }
       
           if (stats_started) {
      -        prev_time = hal_sys_timer_get();
      +        time = hal_sys_timer_get();
           }
       
      -    // Stop modules (except for psram and flash, spi)
      +    // Modules (except for psram and flash) sleep
           hal_gpadc_sleep();
           if (chip_wake_lock_map == 0) {
               analog_sleep();
               pmu_sleep();
           }
      -    // End of stopping modules
      +    bt_drv_sleep();
       
      +    // End of sleep
       
      -    //hal_psram_sleep();
      -    hal_norflash_sleep(HAL_FLASH_ID_0);
      +    //psram_sleep();
      +    hal_norflash_sleep(HAL_NORFLASH_ID_0);
       
      +    // Now neither psram nor flash are usable
       
           if (!hal_sleep_irq_pending()) {
               if (chip_wake_lock_map) {
      @@ -251,26 +273,28 @@ static enum HAL_SLEEP_STATUS_T SRAM_TEXT_LOC hal_sleep_lowpower_mode(void)
               ret = HAL_SLEEP_STATUS_DEEP;
           }
       
      -    hal_norflash_wakeup(HAL_FLASH_ID_0);
      -    //hal_psram_wakeup();
      +    hal_norflash_wakeup(HAL_NORFLASH_ID_0);
      +    //psram_wakeup();
       
      +    // Now both psram and flash are usable
       
           if (chip_wake_lock_map == 0) {
               pmu_wakeup();
               analog_wakeup();
           }
      +    bt_drv_wakeup();
       
           hal_gpadc_wakeup();
      +    // Modules (except for psram and flash) wakeup
       
      -    // End of restoring modules
      +    // End of wakeup
       
           if (stats_started) {
      -        cur_time = hal_sys_timer_get();
      -        interval = cur_time - prev_time;
      +        time = hal_sys_timer_get() - time;
               if (chip_wake_lock_map) {
      -            sys_deep_sleep_time += interval;
      +            sys_deep_sleep_time += time;
               } else {
      -            chip_deep_sleep_time += interval;
      +            chip_deep_sleep_time += time;
               }
           }
       
      @@ -283,17 +307,13 @@ static enum HAL_SLEEP_STATUS_T SRAM_TEXT_LOC hal_sleep_lowpower_mode(void)
       static enum HAL_SLEEP_STATUS_T SRAM_TEXT_LOC NOINLINE USED hal_sleep_proc(int light_sleep)
       {
           enum HAL_SLEEP_STATUS_T ret;
      -    uint32_t prev_time = 0;
      -    uint32_t cur_time;
      +    uint32_t time = 0;
           uint32_t interval;
      -    bool lpu_busy = false;
      -    bool dma_busy = false;
      -    POSSIBLY_UNUSED bool trace_busy = false;
       
           ret = HAL_SLEEP_STATUS_LIGHT;
       
           // Check the sleep conditions in interrupt-locked context
      -    if (cpu_wake_lock_map || (lpu_busy = hal_cmu_lpu_busy())) {
      +    if (hal_sleep_cpu_busy()) {
               // Cannot sleep
           } else {
               // Sleep hook
      @@ -301,11 +321,11 @@ static enum HAL_SLEEP_STATUS_T SRAM_TEXT_LOC NOINLINE USED hal_sleep_proc(int li
                   goto _exit_sleep;
               }
       
      -        if (sys_wake_lock_map || hal_sysfreq_busy() || (dma_busy = hal_dma_busy())) {
      +        if (hal_sleep_sys_busy()) {
                   // Light sleep
       
                   if (stats_started) {
      -                prev_time = hal_sys_timer_get();
      +                time = hal_sys_timer_get();
                   }
       
       #ifdef NO_LIGHT_SLEEP
      @@ -320,15 +340,14 @@ static enum HAL_SLEEP_STATUS_T SRAM_TEXT_LOC NOINLINE USED hal_sleep_proc(int li
       #endif
       
                   if (stats_started) {
      -                cur_time = hal_sys_timer_get();
      -                light_sleep_time += cur_time - prev_time;
      +                light_sleep_time += hal_sys_timer_get() - time;
                   }
       #ifdef DEBUG
      -        } else if ((trace_busy = hal_trace_busy())) {
      +        } else if (hal_trace_busy()) {
                   // Light sleep with trace busy only
       
                   if (stats_started) {
      -                prev_time = hal_sys_timer_get();
      +                time = hal_sys_timer_get();
                   }
       
                   // No irq will be generated when trace becomes idle, so the trace status should
      @@ -336,8 +355,7 @@ static enum HAL_SLEEP_STATUS_T SRAM_TEXT_LOC NOINLINE USED hal_sleep_proc(int li
                   while (!hal_sleep_irq_pending() && hal_trace_busy());
       
                   if (stats_started) {
      -                cur_time = hal_sys_timer_get();
      -                light_sleep_time += cur_time - prev_time;
      +                light_sleep_time += hal_sys_timer_get() - time;
                   }
       
                   if (!hal_sleep_irq_pending()) {
      @@ -359,8 +377,8 @@ _deep_sleep: POSSIBLY_UNUSED;
       
       _exit_sleep:
           if (stats_started) {
      -        cur_time = hal_sys_timer_get();
      -        interval = cur_time - stats_start_time;
      +        time = hal_sys_timer_get();
      +        interval = time - stats_start_time;
               if (interval >= stats_interval) {
                   if (light_sleep_time > UINT32_MAX / 100) {
                       light_sleep_ratio = (uint64_t)light_sleep_time * 100 / interval;
      @@ -381,22 +399,20 @@ _exit_sleep:
                   light_sleep_time = 0;
                   sys_deep_sleep_time = 0;
                   chip_deep_sleep_time = 0;
      -            stats_start_time = cur_time;
      +            stats_start_time = time;
               }
       #ifdef SLEEP_STATS_TRACE
               if (stats_valid && stats_trace_interval) {
      -            if (cur_time - stats_trace_time >= stats_trace_interval) {
      -                TRACE(0, "CPU USAGE: busy=%d light=%d sys_deep=%d chip_deep=%d",
      +            uint32_t time = hal_sys_timer_get();
      +            if (time - stats_trace_time >= stats_trace_interval) {
      +                TRACE(4,"CPU USAGE: busy=%d light=%d sys_deep=%d chip_deep=%d",
                           100 - (light_sleep_ratio + sys_deep_sleep_ratio + chip_deep_sleep_ratio),
                           light_sleep_ratio, sys_deep_sleep_ratio, chip_deep_sleep_ratio);
      -                stats_trace_time = cur_time;
      +                stats_trace_time = time;
       #ifdef DEBUG_SLEEP_USER
      -                TRACE(0, "SLEEP USER: cpu=0x%X sys=0x%X chip=0x%X irq=0x%08X_%08X",
      -                    cpu_wake_lock_map, sys_wake_lock_map, chip_wake_lock_map,
      -                    (NVIC->ICPR[1] & NVIC->ISER[1]), (NVIC->ICPR[0] & NVIC->ISER[0]));
      -                TRACE(0, "BUSY: LPU=%d DMA=%d TRACE=%d", lpu_busy, dma_busy, trace_busy);
      -                hal_sysfreq_print_user_freq();
      -                hal_dma_print_busy_chan();
      +                TRACE(4,"SLEEP_USER: cpulock=0x%X syslock=0x%X irq=0x%08X_%08X",
      +                    cpu_wake_lock_map, sys_wake_lock_map, (NVIC->ICPR[1] & NVIC->ISER[1]), (NVIC->ICPR[0] & NVIC->ISER[0]));
      +                hal_sysfreq_print();
       #endif
                   }
               }
  • platform/hal/hal_sleep_core_pd.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_sleep_core_pd.h bes/platform/hal/hal_sleep_core_pd.h
      index 0ddad1f9cfc..9db08b05c1e 100644
      --- a/platform/hal/hal_sleep_core_pd.h
      +++ b/platform/hal/hal_sleep_core_pd.h
      @@ -23,7 +23,7 @@ extern "C" {
       
       void hal_sleep_core_power_down(void);
       
      -void NORETURN hal_sleep_core_power_up(void);
      +void hal_sleep_core_power_up(void);
       
       #ifdef __cplusplus
       }
  • platform/hal/hal_sleep.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_sleep.h bes/platform/hal/hal_sleep.h
      index a2d6ddfc6d0..f52f3aa4c1e 100644
      --- a/platform/hal/hal_sleep.h
      +++ b/platform/hal/hal_sleep.h
      @@ -64,7 +64,7 @@ enum HAL_SYS_WAKE_LOCK_USER_T {
           HAL_SYS_WAKE_LOCK_USER_2,
           HAL_SYS_WAKE_LOCK_USER_3,
           HAL_SYS_WAKE_LOCK_USER_4,
      -    HAL_SYS_WAKE_LOCK_USER_TRANSQ,
      +    HAL_SYS_WAKE_LOCK_USER_5,
           HAL_SYS_WAKE_LOCK_USER_6,
           HAL_SYS_WAKE_LOCK_USER_7,
           HAL_SYS_WAKE_LOCK_USER_8,
  • platform/hal/hal_spi.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_spi.c bes/platform/hal/hal_spi.c
      index 05612544b67..8c8b9fce161 100644
      --- a/platform/hal/hal_spi.c
      +++ b/platform/hal/hal_spi.c
      @@ -155,7 +155,7 @@ static HAL_SPI_DMA_HANDLER_T BOOT_BSS_LOC spi_rxdma_handler[HAL_SPI_ID_QTY];
       static uint8_t BOOT_BSS_LOC spi_txdma_chan[HAL_SPI_ID_QTY];
       static uint8_t BOOT_BSS_LOC spi_rxdma_chan[HAL_SPI_ID_QTY];
       
      -static enum HAL_SPI_MOD_CLK_SEL_T BOOT_BSS_LOC clk_sel[HAL_SPI_ID_QTY];
      +static enum HAL_SPI_MOD_CLK_SEL_T clk_sel[HAL_SPI_ID_QTY];
       
       static bool BOOT_BSS_LOC spi_init_done = false;
       
      @@ -481,31 +481,31 @@ static int POSSIBLY_UNUSED hal_spi_close_id(enum HAL_SPI_ID_T id, uint32_t cs)
           return ret;
       }
       
      -static void POSSIBLY_UNUSED ISPI_API_LOC hal_spi_set_cs_id(enum HAL_SPI_ID_T id, uint32_t cs)
      +static void POSSIBLY_UNUSED hal_spi_set_cs_id(enum HAL_SPI_ID_T id, uint32_t cs)
       {
           spi[id]->SSPCR1 = SET_BITFIELD(spi[id]->SSPCR1, SPI_SLAVE_ID, cs);
       }
       
      -static bool ISPI_API_LOC hal_spi_busy_id(enum HAL_SPI_ID_T id)
      +static bool hal_spi_busy_id(enum HAL_SPI_ID_T id)
       {
           return ((spi[id]->SSPCR1 & SPI_SSPCR1_SSE) && (spi[id]->SSPSR & SPI_SSPSR_BSY));
       }
       
      -static void ISPI_API_LOC hal_spi_enable_slave_output_id(enum HAL_SPI_ID_T id)
      +static void hal_spi_enable_slave_output_id(enum HAL_SPI_ID_T id)
       {
           if (spi[id]->SSPCR1 & SPI_SSPCR1_MS) {
               spi[id]->SSPCR1 &= ~SPI_SSPCR1_SOD;
           }
       }
       
      -static void ISPI_API_LOC hal_spi_disable_slave_output_id(enum HAL_SPI_ID_T id)
      +static void hal_spi_disable_slave_output_id(enum HAL_SPI_ID_T id)
       {
           if (spi[id]->SSPCR1 & SPI_SSPCR1_MS) {
               spi[id]->SSPCR1 |= SPI_SSPCR1_SOD;
           }
       }
       
      -static int ISPI_API_LOC hal_spi_send_id(enum HAL_SPI_ID_T id, const void *data, uint32_t len)
      +static int hal_spi_send_id(enum HAL_SPI_ID_T id, const void *data, uint32_t len)
       {
           uint8_t cnt;
           uint32_t sent, value;
      @@ -548,7 +548,7 @@ static int ISPI_API_LOC hal_spi_send_id(enum HAL_SPI_ID_T id, const void *data,
           return ret;
       }
       
      -static int ISPI_API_LOC hal_spi_recv_id(enum HAL_SPI_ID_T id, const void *cmd, void *data, uint32_t len)
      +static int hal_spi_recv_id(enum HAL_SPI_ID_T id, const void *cmd, void *data, uint32_t len)
       {
           uint8_t cnt;
           uint32_t sent, recv, value;
      @@ -623,7 +623,7 @@ int hal_ispi_rom_open(const struct HAL_SPI_CFG_T *cfg)
       
       void hal_ispi_rom_activate_cs(uint32_t cs)
       {
      -    SPI_ASSERT(cs < ISPI_CS_QTY, "ISPI_ROM: SPI cs bad: %d", cs);
      +    SPI_ASSERT(cs < HAL_SPI_CS_QTY, "ISPI_ROM: SPI cs bad: %d", cs);
       
           hal_spi_set_cs_id(HAL_SPI_ID_INTERNAL, cs);
       }
      @@ -731,6 +731,8 @@ static int POSSIBLY_UNUSED hal_spi_enable_and_send_id(enum HAL_SPI_ID_T id, cons
           int ret;
           struct HAL_SPI_CTRL_T saved;
       
      +    //SPI_ASSERT(id < HAL_SPI_ID_QTY, invalid_id, id);
      +
           if (set_bool_flag(&in_use[id])) {
               return -31;
           }
      @@ -1165,7 +1167,7 @@ void hal_spi_stop_dma_recv_id(enum HAL_SPI_ID_T id)
       // ISPI functions
       //------------------------------------------------------------
       
      -int BOOT_TEXT_FLASH_LOC hal_ispi_open(const struct HAL_SPI_CFG_T *cfg)
      +int hal_ispi_open(const struct HAL_SPI_CFG_T *cfg)
       {
           SPI_ASSERT(cfg->tx_bits == cfg->rx_bits && cfg->rx_frame_bits == 0, "ISPI: Bad bits cfg");
       
      @@ -1177,9 +1179,9 @@ int hal_ispi_close(uint32_t cs)
           return hal_spi_close_id(HAL_SPI_ID_INTERNAL, cs);
       }
       
      -void ISPI_API_LOC hal_ispi_activate_cs(uint32_t cs)
      +void hal_ispi_activate_cs(uint32_t cs)
       {
      -    SPI_ASSERT(cs < ISPI_CS_QTY, "ISPI: SPI cs bad: %d", cs);
      +    SPI_ASSERT(cs < HAL_SPI_CS_QTY, "ISPI: SPI cs bad: %d", cs);
       
           hal_spi_set_cs_id(HAL_SPI_ID_INTERNAL, cs);
       }
      @@ -1189,7 +1191,7 @@ int hal_ispi_busy(void)
           return hal_spi_busy_id(HAL_SPI_ID_INTERNAL);
       }
       
      -int ISPI_API_LOC hal_ispi_send(const void *data, uint32_t len)
      +int hal_ispi_send(const void *data, uint32_t len)
       {
           int ret;
       
      @@ -1204,7 +1206,7 @@ int ISPI_API_LOC hal_ispi_send(const void *data, uint32_t len)
           return ret;
       }
       
      -int ISPI_API_LOC hal_ispi_recv(const void *cmd, void *data, uint32_t len)
      +int hal_ispi_recv(const void *cmd, void *data, uint32_t len)
       {
           int ret;
       
  • platform/hal/hal_sysfreq.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_sysfreq.c bes/platform/hal/hal_sysfreq.c
      index c0af1939c3e..a9631cacaf5 100644
      --- a/platform/hal/hal_sysfreq.c
      +++ b/platform/hal/hal_sysfreq.c
      @@ -17,10 +17,7 @@
       #include "hal_location.h"
       #include "hal_trace.h"
       #include "cmsis.h"
      -#if !(defined(ROM_BUILD)
      -#define PMU_CTRL_ENABLE
      -#endif
      -#ifdef PMU_CTRL_ENABLE
      +#ifndef ROM_BUILD
       #include "pmu.h"
       #endif
       
      @@ -30,14 +27,11 @@ static uint8_t * const sysfreq_per_user = (uint8_t *)&sysfreq_bundle[0];
       
       static enum HAL_SYSFREQ_USER_T BOOT_DATA_LOC top_user = HAL_SYSFREQ_USER_QTY;
       
      -static enum HAL_CMU_FREQ_T BOOT_DATA_LOC min_sysfreq = HAL_CMU_FREQ_32K;
      +static enum HAL_CMU_FREQ_T BOOT_DATA_LOC min_sysfreq = HAL_CMU_FREQ_26M;
       
       static enum HAL_CMU_FREQ_T hal_sysfreq_revise_freq(enum HAL_CMU_FREQ_T freq)
       {
      -    if (freq == HAL_CMU_FREQ_32K) {
      -        freq = HAL_CMU_FREQ_26M;
      -    }
      -    return (freq > min_sysfreq) ? freq : min_sysfreq;
      +    return freq > min_sysfreq ? freq : min_sysfreq;
       }
       
       void hal_sysfreq_set_min_freq(enum HAL_CMU_FREQ_T freq)
      @@ -59,9 +53,7 @@ void hal_sysfreq_set_min_freq(enum HAL_CMU_FREQ_T freq)
       int hal_sysfreq_req(enum HAL_SYSFREQ_USER_T user, enum HAL_CMU_FREQ_T freq)
       {
           uint32_t lock;
      -    enum HAL_CMU_FREQ_T cur_freq;
      -    enum HAL_CMU_FREQ_T real_freq;
      -    enum HAL_CMU_FREQ_T real_cur_freq;
      +    enum HAL_CMU_FREQ_T cur_sys_freq;
           int i;
       
           if (user >= HAL_SYSFREQ_USER_QTY) {
      @@ -73,26 +65,24 @@ int hal_sysfreq_req(enum HAL_SYSFREQ_USER_T user, enum HAL_CMU_FREQ_T freq)
       
           lock = int_lock();
       
      -    cur_freq = hal_sysfreq_get();
      +    cur_sys_freq = hal_sysfreq_get();
       
           sysfreq_per_user[user] = freq;
       
      -    if (freq == cur_freq) {
      +    if (freq == cur_sys_freq) {
               top_user = user;
      -    } else if (freq > cur_freq) {
      +    } else if (freq > cur_sys_freq) {
               top_user = user;
      -        real_freq = hal_sysfreq_revise_freq(freq);
      -        real_cur_freq = hal_sysfreq_revise_freq(cur_freq);
      -        if (real_freq != real_cur_freq) {
      -#ifdef PMU_CTRL_ENABLE
      -        pmu_sys_freq_config(real_freq);
      -#endif
      +        freq = hal_sysfreq_revise_freq(freq);
      +#ifndef ROM_BUILD
      +        pmu_sys_freq_config(freq);
       #ifdef ULTRA_LOW_POWER
               // Enable PLL if required
      -        hal_cmu_low_freq_mode_disable(real_cur_freq, real_freq);
      +        hal_cmu_low_freq_mode_disable(hal_sysfreq_revise_freq(cur_sys_freq), freq);
      +#endif
       #endif
      -        hal_cmu_sys_set_freq(real_freq);
      -    } else /* if (freq < cur_freq) */ {
      +        hal_cmu_sys_set_freq(freq);
      +    } else /* if (freq < cur_sys_freq) */ {
               if (top_user == user || top_user == HAL_SYSFREQ_USER_QTY) {
                   if (top_user == user) {
                       freq = sysfreq_per_user[0];
      @@ -105,15 +95,15 @@ int hal_sysfreq_req(enum HAL_SYSFREQ_USER_T user, enum HAL_CMU_FREQ_T freq)
                       }
                   }
                   top_user = user;
      -            if (freq != cur_freq) {
      -                real_freq = hal_sysfreq_revise_freq(freq);
      -                real_cur_freq = hal_sysfreq_revise_freq(cur_freq);
      +            if (freq != cur_sys_freq) {
      +                freq = hal_sysfreq_revise_freq(freq);
      +                hal_cmu_sys_set_freq(freq);
      +#ifndef ROM_BUILD
       #ifdef ULTRA_LOW_POWER
                       // Disable PLL if capable
      -                hal_cmu_low_freq_mode_enable(real_cur_freq, real_freq);
      +                hal_cmu_low_freq_mode_enable(hal_sysfreq_revise_freq(cur_sys_freq), freq);
       #endif
      -#ifdef PMU_CTRL_ENABLE
      -                pmu_sys_freq_config(real_freq);
      +                pmu_sys_freq_config(freq);
       #endif
                   }
               }
      @@ -155,14 +145,14 @@ int hal_sysfreq_busy(void)
           return 0;
       }
       
      -void hal_sysfreq_print_user_freq(void)
      +void hal_sysfreq_print(void)
       {
           int i;
       
           for (i = 0; i < HAL_SYSFREQ_USER_QTY; i++) {
               if (sysfreq_per_user[i] != 0) {
      -            TRACE(TR_ATTR_NO_TS,"\t[%2u] f=%2u", i, sysfreq_per_user[i]);
      +            TRACE(2,"*** SYSFREQ user=%d freq=%d", i, sysfreq_per_user[i]);
               }
           }
      -    TRACE(TR_ATTR_NO_TS,"\ttop_user=%2u", top_user);
      +    TRACE(1,"*** SYSFREQ top_user=%d", top_user);
       }
  • platform/hal/hal_tdm.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_tdm.h bes/platform/hal/hal_tdm.h
      index cbad9c39bc2..7c80638ef3c 100644
      --- a/platform/hal/hal_tdm.h
      +++ b/platform/hal/hal_tdm.h
      @@ -73,8 +73,8 @@ struct HAL_TDM_CONFIG_T {
           enum HAL_TDM_CYCLES_T cycles;
           enum HAL_TDM_FS_CYCLES fs_cycles;
           enum HAL_TDM_SLOT_CYCLES_T slot_cycles;
      +    uint32_t data_offset;
           bool sync_start;
      -    uint8_t data_offset;
       };
       
       int32_t hal_tdm_open(enum HAL_I2S_ID_T i2s_id,enum AUD_STREAM_T stream,enum HAL_I2S_MODE_T mode);
  • platform/hal/hal_timer.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_timer.c bes/platform/hal/hal_timer.c
      index 460702f9421..5f4960f9388 100644
      --- a/platform/hal/hal_timer.c
      +++ b/platform/hal/hal_timer.c
      @@ -21,20 +21,21 @@
       #include "hal_cmu.h"
       #include "cmsis_nvic.h"
       
      +//#define ELAPSED_TIMER_ENABLED
       
       #if defined(CHIP_BEST3001) || defined(CHIP_BEST3003) || defined(CHIP_BEST3005) || defined(CHIP_BEST1400) || defined(CHIP_BEST1402)
       #define CLOCK_SYNC_WORKAROUND
       #endif
       
      -#if defined(TIMER1_BASE) && defined(LOW_SYS_FREQ) && defined(LOW_SYS_FREQ_6P5M)
      +#ifdef LOW_SYS_FREQ
       #if defined(CHIP_BEST1305) || defined(CHIP_BEST1501) || \
      -        defined(CHIP_BEST2300A) || defined(CHIP_BEST2300P)
      +        defined(CHIP_BEST2300) || defined(CHIP_BEST2300P) || defined(CHIP_BEST2300A)
       #define FAST_TIMER_WORKAROUND
       #endif
       #endif
       
      -#if !(defined(__FPU_USED) && (__FPU_USED == 1))
      -#undef TIMER_USE_FPU
      +#if defined(__FPU_USED) && (__FPU_USED == 1)
      +//#define TIMER_USE_FPU
       #endif
       
       #define SLOW_TIMER_VAL_DELTA        1
      @@ -44,7 +45,7 @@
       #ifdef CALIB_SLOW_TIMER
       #define MAX_CALIB_SYSTICK_HZ        (CONFIG_SYSTICK_HZ_NOMINAL * 2)
       
      -#define MIN_CALIB_TICKS             (30 * (CONFIG_SYSTICK_HZ_NOMINAL / 1000))
      +#define MIN_CALIB_TICKS             (10 * (CONFIG_SYSTICK_HZ_NOMINAL / 1000))
       
       #define MAX_CALIB_TICKS             (30 * CONFIG_SYSTICK_HZ_NOMINAL)
       
      @@ -53,26 +54,18 @@ static uint32_t BOOT_BSS_LOC slow_val;
       static uint32_t BOOT_BSS_LOC fast_val;
       #endif
       
      -#define FAST_TICK_RATIO_NUM                 3
      -static float BOOT_BSS_LOC fast_tick_ratio_avg;
      -static float BOOT_BSS_LOC fast_tick_ratio[FAST_TICK_RATIO_NUM];
      -
      -static struct DUAL_TIMER_T * const BOOT_RODATA_SRAM_LOC dual_timer[] = {
      -    (struct DUAL_TIMER_T *)TIMER0_BASE,
      -    (struct DUAL_TIMER_T *)TIMER1_BASE,
      -};
      -
      -static IRQn_Type irq_num[ARRAY_SIZE(dual_timer)][2] = {
      -    { TIMER00_IRQn, TIMER01_IRQn, },
      -    { INVALID_IRQn, TIMER11_IRQn, },
      -};
      +static struct DUAL_TIMER_T * const BOOT_RODATA_SRAM_LOC dual_timer0 = (struct DUAL_TIMER_T *)TIMER0_BASE;
      +#ifdef TIMER1_BASE
      +static struct DUAL_TIMER_T * const BOOT_RODATA_SRAM_LOC dual_timer1 = (struct DUAL_TIMER_T *)TIMER1_BASE;
      +#endif
       
      -static HAL_TIMER_IRQ_HANDLER_T irq_handler[ARRAY_SIZE(dual_timer)][2];
      +static HAL_TIMER_IRQ_HANDLER_T irq_handler = NULL;
       
      -static uint32_t start_time[ARRAY_SIZE(dual_timer)][2];
      +//static uint32_t load_value = 0;
      +static uint32_t start_time;
       
      -static uint32_t hal_timer_common_get_elapsed_time(uint32_t id, uint32_t sub_id);
      -static int hal_timer_common_irq_pending(uint32_t id, uint32_t sub_id);
      +static void POSSIBLY_UNUSED hal_timer00_irq_handler(void);
      +static void hal_timer01_irq_handler(void);
       
       __STATIC_FORCEINLINE uint32_t get_timer_value(struct TIMER_T *timer, uint32_t delta)
       {
      @@ -121,37 +114,37 @@ __STATIC_FORCEINLINE void set_timer_load(struct TIMER_T *timer, uint32_t load, u
       #endif
       }
       
      -__STATIC_FORCEINLINE void fast_sys_timer_open(void)
      +__STATIC_FORCEINLINE void fast_timer_open(void)
       {
       #ifdef TIMER1_BASE
           hal_cmu_timer1_select_fast();
      -    dual_timer[1]->timer[0].Control = TIMER_CTRL_EN | TIMER_CTRL_PRESCALE_DIV_1 | TIMER_CTRL_SIZE_32_BIT;
      +    dual_timer1->timer[0].Control = TIMER_CTRL_EN | TIMER_CTRL_PRESCALE_DIV_1 | TIMER_CTRL_SIZE_32_BIT;
       #endif
       }
       
       void BOOT_TEXT_FLASH_LOC hal_sys_timer_open(void)
       {
           hal_cmu_timer0_select_slow();
      -    dual_timer[0]->timer[0].Control = TIMER_CTRL_EN | TIMER_CTRL_PRESCALE_DIV_1 | TIMER_CTRL_SIZE_32_BIT;
      -    fast_sys_timer_open();
      +    dual_timer0->timer[0].Control = TIMER_CTRL_EN | TIMER_CTRL_PRESCALE_DIV_1 | TIMER_CTRL_SIZE_32_BIT;
      +    fast_timer_open();;
       }
       
       #ifdef CORE_SLEEP_POWER_DOWN
       void SRAM_TEXT_LOC hal_sys_timer_wakeup(void)
       {
      -    fast_sys_timer_open();
      +    fast_timer_open();;
       }
       #endif
       
       uint32_t BOOT_TEXT_SRAM_LOC hal_sys_timer_get(void)
       {
      -    return -get_timer_value(&dual_timer[0]->timer[0], SLOW_TIMER_VAL_DELTA);
      +    return -get_timer_value(&dual_timer0->timer[0], SLOW_TIMER_VAL_DELTA);
       }
       
       #ifdef CLOCK_SYNC_WORKAROUND
       uint32_t SRAM_TEXT_LOC hal_sys_timer_get_in_sleep(void)
       {
      -    return -get_timer_value(&dual_timer[0]->timer[0], SLOW_TIMER_VAL_DELTA_SLEEP);
      +    return -get_timer_value(&dual_timer0->timer[0], SLOW_TIMER_VAL_DELTA_SLEEP);
       }
       #else
       uint32_t hal_sys_timer_get_in_sleep(void) __attribute__((alias("hal_sys_timer_get")));
      @@ -159,7 +152,7 @@ uint32_t hal_sys_timer_get_in_sleep(void) __attribute__((alias("hal_sys_timer_ge
       
       uint32_t BOOT_TEXT_FLASH_LOC flash_hal_sys_timer_get(void)
       {
      -    return -get_timer_value(&dual_timer[0]->timer[0], SLOW_TIMER_VAL_DELTA);
      +    return -get_timer_value(&dual_timer0->timer[0], SLOW_TIMER_VAL_DELTA);
       }
       
       uint32_t BOOT_TEXT_SRAM_LOC hal_sys_ms_get(void)
      @@ -167,23 +160,19 @@ uint32_t BOOT_TEXT_SRAM_LOC hal_sys_ms_get(void)
           return GET_CURRENT_MS();
       }
       
      -#ifdef TIMER1_BASE
      -__STATIC_FORCEINLINE uint32_t BOOT_TEXT_SRAM_LOC _real_fast_sys_timer_get(void)
      -{
      -    return -get_timer_value(&dual_timer[1]->timer[0], FAST_TIMER_VAL_DELTA);
      -}
      -#endif
      -
       uint32_t BOOT_TEXT_SRAM_LOC hal_fast_sys_timer_get(void)
       {
      +#ifdef TIMER1_BASE
       #ifdef FAST_TIMER_WORKAROUND
      +    if (hal_cmu_fast_timer_offline()) {
       #ifdef TIMER_USE_FPU
      -    return (uint32_t)(hal_sys_timer_get() * ((float)CONFIG_FAST_SYSTICK_HZ / CONFIG_SYSTICK_HZ));
      +        return (uint32_t)(hal_sys_timer_get() * ((float)CONFIG_FAST_SYSTICK_HZ / CONFIG_SYSTICK_HZ));
       #else
      -    return (uint32_t)(hal_sys_timer_get() * (uint64_t)CONFIG_FAST_SYSTICK_HZ / CONFIG_SYSTICK_HZ);
      +        return (uint32_t)(hal_sys_timer_get() * (uint64_t)CONFIG_FAST_SYSTICK_HZ / CONFIG_SYSTICK_HZ);
       #endif
      -#elif defined(TIMER1_BASE)
      -    return _real_fast_sys_timer_get();
      +    }
      +#endif // FAST_TIMER_WORKAROUND
      +    return -get_timer_value(&dual_timer1->timer[0], FAST_TIMER_VAL_DELTA);
       #else
           return 0;
       #endif
      @@ -221,7 +210,16 @@ void BOOT_TEXT_FLASH_LOC flash_hal_sys_timer_delay(uint32_t ticks)
       
       void BOOT_TEXT_SRAM_LOC hal_sys_timer_delay_us(uint32_t us)
       {
      -#if defined(TIMER1_BASE) && !defined(FAST_TIMER_WORKAROUND)
      +#ifdef TIMER1_BASE
      +#ifdef FAST_TIMER_WORKAROUND
      +    if (hal_cmu_fast_timer_offline()) {
      +        uint32_t start = hal_sys_timer_get();
      +        uint32_t ticks = US_TO_TICKS(us);
      +
      +        while (hal_sys_timer_get() - start < ticks);
      +    }
      +#endif // FAST_TIMER_WORKAROUND
      +
           uint32_t start = hal_fast_sys_timer_get();
           uint32_t ticks = US_TO_FAST_TICKS(us);
       
      @@ -257,7 +255,16 @@ void BOOT_TEXT_SRAM_LOC hal_sys_timer_delay_us(uint32_t us)
       
       void SRAM_TEXT_LOC hal_sys_timer_delay_ns(uint32_t ns)
       {
      -#if defined(TIMER1_BASE) && !defined(FAST_TIMER_WORKAROUND)
      +#ifdef TIMER1_BASE
      +#ifdef FAST_TIMER_WORKAROUND
      +    if (hal_cmu_fast_timer_offline()) {
      +        uint32_t start = hal_sys_timer_get();
      +        uint32_t ticks = US_TO_TICKS((ns + (1000 - 1)) / 1000);
      +
      +        while (hal_sys_timer_get() - start < ticks);
      +    }
      +#endif // FAST_TIMER_WORKAROUND
      +
           uint32_t start = hal_fast_sys_timer_get();
           uint32_t ticks = NS_TO_FAST_TICKS(ns);
       
      @@ -298,16 +305,16 @@ static uint32_t NOINLINE SRAM_TEXT_DEF(measure_cpu_freq_interval)(uint32_t cnt)
           uint32_t delta;
       
       #ifdef TIMER1_BASE
      -    t = dual_timer[1];
      +    t = dual_timer1;
           delta = FAST_TIMER_VAL_DELTA;
       #ifdef FAST_TIMER_WORKAROUND
           if (hal_cmu_fast_timer_offline()) {
      -        t = dual_timer[0];
      +        t = dual_timer0;
               delta = SLOW_TIMER_VAL_DELTA;
           }
       #endif // FAST_TIMER_WORKAROUND
       #else
      -    t = dual_timer[0];
      +    t = dual_timer0;
           delta = SLOW_TIMER_VAL_DELTA;
       #endif
       
      @@ -400,7 +407,7 @@ uint32_t hal_sys_timer_calc_cpu_freq(uint32_t interval_ms, int high_res)
       }
       
       #ifdef CALIB_SLOW_TIMER
      -void BOOT_TEXT_SRAM_LOC hal_sys_timer_calib_start(void)
      +void hal_sys_timer_calib_start(void)
       {
           uint32_t lock;
           uint32_t slow;
      @@ -409,14 +416,14 @@ void BOOT_TEXT_SRAM_LOC hal_sys_timer_calib_start(void)
           lock = int_lock();
           slow = hal_sys_timer_get();
           while (hal_sys_timer_get() == slow);
      -    fast = _real_fast_sys_timer_get();
      +    fast = hal_fast_sys_timer_get();
           int_unlock(lock);
       
           slow_val = slow + 1;
           fast_val = fast;
       }
       
      -int BOOT_TEXT_SRAM_LOC hal_sys_timer_calib_end(void)
      +int hal_sys_timer_calib_end(void)
       {
           uint32_t lock;
           uint32_t slow;
      @@ -426,7 +433,7 @@ int BOOT_TEXT_SRAM_LOC hal_sys_timer_calib_end(void)
           lock = int_lock();
           slow = hal_sys_timer_get();
           while (hal_sys_timer_get() == slow);
      -    fast = _real_fast_sys_timer_get();
      +    fast = hal_fast_sys_timer_get();
           int_unlock(lock);
       
           slow += 1;
      @@ -442,17 +449,15 @@ int BOOT_TEXT_SRAM_LOC hal_sys_timer_calib_end(void)
           }
       
       #ifdef TIMER_USE_FPU
      -    sys_tick_hz = (float)CONFIG_FAST_SYSTICK_HZ / (fast - fast_val) * slow_diff;
      +    sys_tick_hz = (uint32_t)((float)CONFIG_FAST_SYSTICK_HZ / (fast - fast_val) * slow_diff);
       #else
           uint64_t mul;
      -    uint32_t fast_diff;
       
      -    fast_diff = fast - fast_val;
      -    mul = (uint64_t)CONFIG_FAST_SYSTICK_HZ * slow_diff + fast_diff / 2;
      +    mul = (uint64_t)CONFIG_FAST_SYSTICK_HZ * slow_diff;
           if ((mul >> 32) == 0) {
      -        sys_tick_hz = (uint32_t)mul / fast_diff;
      +        sys_tick_hz = (uint32_t)mul / (fast - fast_val);
           } else {
      -        sys_tick_hz = mul / fast_diff;
      +        sys_tick_hz = mul / (fast - fast_val);
           }
       #endif
       
      @@ -463,7 +468,7 @@ int BOOT_TEXT_SRAM_LOC hal_sys_timer_calib_end(void)
           return 0;
       }
       
      -void BOOT_TEXT_SRAM_LOC hal_sys_timer_calib(void)
      +void hal_sys_timer_calib(void)
       {
           hal_sys_timer_calib_start();
           hal_sys_timer_delay(MIN_CALIB_TICKS);
      @@ -478,59 +483,51 @@ uint32_t BOOT_TEXT_SRAM_LOC hal_sys_timer_systick_hz(void)
       uint32_t BOOT_TEXT_SRAM_LOC hal_sys_timer_ms_to_ticks(uint32_t ms)
       {
           if (ms <= (~0UL / MAX_CALIB_SYSTICK_HZ)) {
      -        return ((ms * sys_tick_hz + 1000 - 1) / 1000);
      +        return (ms * sys_tick_hz / 1000);
           } else {
       #ifdef TIMER_USE_FPU
      -        return (uint32_t)((float)ms / 1000 * sys_tick_hz + 0.99);
      +        return (uint32_t)((float)ms / 1000 * sys_tick_hz);
       #else
      -        return (((uint64_t)ms * sys_tick_hz + 1000 - 1) / 1000);
      +        return ((uint64_t)ms * sys_tick_hz / 1000);
       #endif
           }
       }
       
       uint32_t BOOT_TEXT_SRAM_LOC hal_sys_timer_us_to_ticks(uint32_t us)
       {
      -    uint32_t ticks;
           if (us <= (~0UL / MAX_CALIB_SYSTICK_HZ)) {
      -        ticks = ((us * sys_tick_hz / 1000 + 1000 - 1) / 1000);
      +        return ((us * sys_tick_hz / 1000 + 1000 - 1) / 1000 + 1);
           } else {
       #ifdef TIMER_USE_FPU
      -        ticks = (uint32_t)((float)us / (1000 * 1000) * sys_tick_hz + 0.99);
      +        return (uint32_t)((float)us / (1000 * 1000) * sys_tick_hz + 1 + 1);
       #else
      -        ticks = (((uint64_t)us * sys_tick_hz / 1000 + 1000 - 1) / 1000);
      +        return (((uint64_t)us * sys_tick_hz / 1000 + 1000 - 1) / 1000 + 1);
       #endif
           }
      -
      -    if (ticks <= 1) {
      -        ticks += 1;
      -    }
      -    return ticks;
       }
       
       uint32_t BOOT_TEXT_SRAM_LOC hal_sys_timer_ticks_to_ms(uint32_t tick)
       {
      -    uint32_t hz = sys_tick_hz;
           if (tick <= (~0UL / 1000)) {
      -        return (tick * 1000 + hz / 2) / hz;
      +        return tick * 1000 / CONFIG_SYSTICK_HZ;
           } else {
       #ifdef TIMER_USE_FPU
      -        return (uint32_t)((float)tick / sys_tick_hz * 1000 + 0.5);
      +        return (uint32_t)((float)tick / CONFIG_SYSTICK_HZ * 1000);
       #else
      -        return ((uint64_t)tick * 1000 + hz / 2) / hz;
      +        return (uint64_t)tick * 1000 / CONFIG_SYSTICK_HZ;
       #endif
           }
       }
       
       uint32_t BOOT_TEXT_SRAM_LOC hal_sys_timer_ticks_to_us(uint32_t tick)
       {
      -    uint32_t hz = sys_tick_hz;
           if (tick <= (~0UL / (1000 * 1000))) {
      -        return (tick * (1000 * 1000) + hz / 2) / hz;
      +        return tick * (1000 * 1000) / CONFIG_SYSTICK_HZ;
           } else {
       #ifdef TIMER_USE_FPU
      -        return (uint32_t)((float)tick / sys_tick_hz * (1000 * 1000) + 0.5);
      +        return (uint32_t)((float)tick / CONFIG_SYSTICK_HZ * (1000 * 1000));
       #else
      -        return ((uint64_t)tick * (1000 * 1000) + hz / 2) / hz;
      +        return (uint64_t)tick * (1000 * 1000) / CONFIG_SYSTICK_HZ;
       #endif
           }
       }
      @@ -544,38 +541,15 @@ int osDelay(uint32_t ms)
       }
       #endif
       
      -__STATIC_FORCEINLINE int timer_is_slow(uint32_t id)
      -{
      -    return (id == 0);
      -}
      -
      -static void hal_timer_common_irq_handler(uint32_t id, uint32_t sub_id)
      -{
      -    uint32_t elapsed;
      -
      -    clear_timer_irq(&dual_timer[id]->timer[sub_id]);
      -    if (irq_handler[id][sub_id]) {
      -        elapsed = hal_timer_common_get_elapsed_time(id, sub_id);
      -        irq_handler[id][sub_id](elapsed);
      -    } else {
      -        dual_timer[id]->timer[sub_id].Control &= ~TIMER_CTRL_INTEN;
      -    }
      -}
      -
      -static void hal_timer_slow_irq_handler(void)
      +static void hal_timer00_irq_handler(void)
       {
      -    hal_timer_common_irq_handler(0, SLOW_TIMER_SUB_ID_WITH_IRQ);
      +    clear_timer_irq(&dual_timer0->timer[0]);
      +    dual_timer0->timer[0].Control &= ~TIMER_CTRL_INTEN;
       }
       
      -static const uint32_t irq_entry[ARRAY_SIZE(dual_timer)][2] = {
      -    { (uint32_t)hal_timer_slow_irq_handler, (uint32_t)hal_timer_slow_irq_handler, },
      -    { 0, (uint32_t)hal_timer11_irq_handler, },
      -};
      -
      -static void hal_timer_common_setup(uint32_t id, uint32_t sub_id, enum HAL_TIMER_TYPE_T type, HAL_TIMER_IRQ_HANDLER_T handler)
      +void hal_timer_setup(enum HAL_TIMER_TYPE_T type, HAL_TIMER_IRQ_HANDLER_T handler)
       {
           uint32_t mode;
      -    uint32_t irq_en;
       
           if (type == HAL_TIMER_TYPE_ONESHOT) {
               mode = TIMER_CTRL_ONESHOT;
      @@ -585,150 +559,124 @@ static void hal_timer_common_setup(uint32_t id, uint32_t sub_id, enum HAL_TIMER_
               mode = 0;
           }
       
      -    irq_handler[id][sub_id] = handler;
      -
      -    clear_timer_irq(&dual_timer[id]->timer[sub_id]);
      +    irq_handler = handler;
       
      -    irq_en = (handler && irq_entry[id][sub_id]);
      +    clear_timer_irq(&dual_timer0->timer[1]);
      +#ifdef ELAPSED_TIMER_ENABLED
      +    dual_timer0->elapsed_timer[1].ElapsedCtrl = TIMER_ELAPSED_CTRL_CLR;
      +#endif
       
      -    if (irq_en) {
      -        NVIC_SetVector(irq_num[id][sub_id], irq_entry[id][sub_id]);
      -        NVIC_SetPriority(irq_num[id][sub_id], IRQ_PRIORITY_NORMAL);
      -        NVIC_ClearPendingIRQ(irq_num[id][sub_id]);
      -        NVIC_EnableIRQ(irq_num[id][sub_id]);
      +    if (handler) {
      +        NVIC_SetVector(TIMER01_IRQn, (uint32_t)hal_timer01_irq_handler);
      +        NVIC_SetPriority(TIMER01_IRQn, IRQ_PRIORITY_NORMAL);
      +        NVIC_ClearPendingIRQ(TIMER01_IRQn);
      +        NVIC_EnableIRQ(TIMER01_IRQn);
           }
       
      -    dual_timer[id]->timer[sub_id].Control = mode |
      -                                   (irq_en ? TIMER_CTRL_INTEN : 0) |
      +    dual_timer0->timer[1].Control = mode |
      +                                   (handler ? TIMER_CTRL_INTEN : 0) |
                                          TIMER_CTRL_PRESCALE_DIV_1 |
                                          TIMER_CTRL_SIZE_32_BIT;
       }
       
      -static void hal_timer_common_reload(uint32_t id, uint32_t sub_id, uint32_t load)
      -{
      -    uint32_t delta;
      -
      -    delta = timer_is_slow(id) ? SLOW_TIMER_VAL_DELTA : FAST_TIMER_VAL_DELTA;
      -    if (load > HAL_TIMER_LOAD_DELTA) {
      -        load -= HAL_TIMER_LOAD_DELTA;
      -    } else {
      -        load = HAL_TIMER_LOAD_DELTA;
      -    }
      -    set_timer_load(&dual_timer[id]->timer[sub_id], load, delta);
      -}
      -
      -POSSIBLY_UNUSED static uint32_t hal_timer_common_get_load(uint32_t id, uint32_t sub_id)
      -{
      -    return dual_timer[id]->timer[sub_id].Load + HAL_TIMER_LOAD_DELTA;
      -}
      -
      -POSSIBLY_UNUSED static void hal_timer_common_bgload(uint32_t id, uint32_t sub_id, uint32_t load)
      -{
      -    if (load > HAL_TIMER_LOAD_DELTA) {
      -        load -= HAL_TIMER_LOAD_DELTA;
      -    } else {
      -        load = HAL_TIMER_LOAD_DELTA;
      -    }
      -    dual_timer[id]->timer[sub_id].BGLoad = load;
      -}
      -
      -POSSIBLY_UNUSED static void hal_timer_common_pause(uint32_t id, uint32_t sub_id)
      -{
      -    dual_timer[id]->timer[sub_id].Control &= ~TIMER_CTRL_EN;
      -}
      -
      -static void hal_timer_common_continue(uint32_t id, uint32_t sub_id)
      -{
      -    dual_timer[id]->timer[sub_id].Control |= TIMER_CTRL_EN;
      -}
      -
      -static void hal_timer_common_start(uint32_t id, uint32_t sub_id, uint32_t load)
      +void hal_timer_start(uint32_t load)
       {
      -    start_time[id][sub_id] = timer_is_slow(id) ? hal_sys_timer_get() : hal_fast_sys_timer_get();
      -    hal_timer_common_reload(id, sub_id, load);
      -    hal_timer_common_continue(id, sub_id);
      +    start_time = hal_sys_timer_get();
      +    hal_timer_reload(load);
      +    hal_timer_continue();
       }
       
      -static void hal_timer_common_stop(uint32_t id, uint32_t sub_id)
      +void hal_timer_stop(void)
       {
      -    dual_timer[id]->timer[sub_id].Control &= ~TIMER_CTRL_EN;
      -    clear_timer_irq(&dual_timer[id]->timer[sub_id]);
      -    NVIC_ClearPendingIRQ(irq_num[id][sub_id]);
      +    dual_timer0->timer[1].Control &= ~TIMER_CTRL_EN;
      +#ifdef ELAPSED_TIMER_ENABLED
      +    dual_timer0->elapsed_timer[1].ElapsedCtrl = TIMER_ELAPSED_CTRL_CLR;
      +#endif
      +    clear_timer_irq(&dual_timer0->timer[1]);
      +    NVIC_ClearPendingIRQ(TIMER01_IRQn);
       }
       
      -static int hal_timer_common_is_enabled(uint32_t id, uint32_t sub_id)
      +void hal_timer_continue(void)
       {
      -    return !!(dual_timer[id]->timer[sub_id].Control & TIMER_CTRL_EN);
      +#ifdef ELAPSED_TIMER_ENABLED
      +    dual_timer0->elapsed_timer[1].ElapsedCtrl = TIMER_ELAPSED_CTRL_EN | TIMER_ELAPSED_CTRL_CLR;
      +#endif
      +    dual_timer0->timer[1].Control |= TIMER_CTRL_EN;
       }
       
      -static uint32_t hal_timer_common_get_raw_value(uint32_t id, uint32_t sub_id)
      +int hal_timer_is_enabled(void)
       {
      -    uint32_t delta;
      -
      -    delta = timer_is_slow(id) ? SLOW_TIMER_VAL_DELTA : FAST_TIMER_VAL_DELTA;
      -    return get_timer_value(&dual_timer[id]->timer[sub_id], delta);
      +    return !!(dual_timer0->timer[1].Control & TIMER_CTRL_EN);
       }
       
      -static int hal_timer_common_irq_active(uint32_t id, uint32_t sub_id)
      +void hal_timer_reload(uint32_t load)
       {
      -    return NVIC_GetActive(irq_num[id][sub_id]);
      +    if (load > HAL_TIMER_LOAD_DELTA) {
      +        //load_value = load;
      +        load -= HAL_TIMER_LOAD_DELTA;
      +    } else {
      +        //load_value = HAL_TIMER_LOAD_DELTA + 1;
      +        load = 1;
      +    }
      +    set_timer_load(&dual_timer0->timer[1], load, SLOW_TIMER_VAL_DELTA);
       }
       
      -static int hal_timer_common_irq_pending(uint32_t id, uint32_t sub_id)
      +uint32_t hal_timer_get(void)
       {
      -    return (dual_timer[id]->timer[sub_id].MIS & TIMER_MIS_MIS);
      +    return get_timer_value(&dual_timer0->timer[1], SLOW_TIMER_VAL_DELTA);
       }
       
      -static uint32_t hal_timer_common_get_elapsed_time(uint32_t id, uint32_t sub_id)
      -{
      -    uint32_t time;
      -
      -    time = timer_is_slow(id) ? hal_sys_timer_get() : hal_fast_sys_timer_get();
      -    return time - start_time[id][sub_id];
      -}
      -
      -void hal_timer_setup(enum HAL_TIMER_TYPE_T type, HAL_TIMER_IRQ_HANDLER_T handler)
      +int hal_timer_irq_active(void)
       {
      -    hal_timer_common_setup(0, SLOW_TIMER_SUB_ID_WITH_IRQ, type, handler);
      +    return NVIC_GetActive(TIMER01_IRQn);
       }
       
      -void hal_timer_start(uint32_t load)
      +int hal_timer_irq_pending(void)
       {
      -    hal_timer_common_start(0, SLOW_TIMER_SUB_ID_WITH_IRQ, load);
      +    // Or NVIC_GetPendingIRQ(TIMER2_IRQn) ?
      +    return (dual_timer0->timer[1].MIS & TIMER_MIS_MIS);
       }
       
      -void hal_timer_stop(void)
      +uint32_t hal_timer_get_overrun_time(void)
       {
      -    hal_timer_common_stop(0, SLOW_TIMER_SUB_ID_WITH_IRQ);
      -}
      +#ifdef ELAPSED_TIMER_ENABLED
      +    uint32_t extra;
       
      -void hal_timer_continue(void)
      -{
      -    hal_timer_common_continue(0, SLOW_TIMER_SUB_ID_WITH_IRQ);
      -}
      +    if (dual_timer0->elapsed_timer[1].ElapsedCtrl & TIMER_ELAPSED_CTRL_EN) {
      +        extra = dual_timer0->elapsed_timer[1].ElapsedVal;
      +    } else {
      +        extra = 0;
      +    }
       
      -int hal_timer_is_enabled(void)
      -{
      -    return hal_timer_common_is_enabled(0, SLOW_TIMER_SUB_ID_WITH_IRQ);
      +    return extra;
      +#else
      +    return 0;
      +#endif
       }
       
      -uint32_t hal_timer_get_raw_value(void)
      +uint32_t hal_timer_get_elapsed_time(void)
       {
      -    return hal_timer_common_get_raw_value(0, SLOW_TIMER_SUB_ID_WITH_IRQ);
      +    //return load_value + hal_timer_get_overrun_time();
      +    return hal_sys_timer_get() - start_time;
       }
       
      -int hal_timer_irq_active(void)
      +static void hal_timer01_irq_handler(void)
       {
      -    return hal_timer_common_irq_active(0, SLOW_TIMER_SUB_ID_WITH_IRQ);
      -}
      +    uint32_t elapsed;
       
      -int hal_timer_irq_pending(void)
      -{
      -    return hal_timer_common_irq_pending(0, SLOW_TIMER_SUB_ID_WITH_IRQ);
      +    clear_timer_irq(&dual_timer0->timer[1]);
      +    if (irq_handler) {
      +        elapsed = hal_timer_get_elapsed_time();
      +        irq_handler(elapsed);
      +    } else {
      +        dual_timer0->timer[1].Control &= ~TIMER_CTRL_INTEN;
      +    }
       }
       
      -uint32_t hal_timer_get_elapsed_time(void)
      +uint32_t hal_timer_get_passed_ticks(uint32_t curr_ticks, uint32_t prev_ticks)
       {
      -    return hal_timer_common_get_elapsed_time(0, SLOW_TIMER_SUB_ID_WITH_IRQ);
      +    if(curr_ticks < prev_ticks)
      +        return ((0xffffffff  - prev_ticks + 1) + curr_ticks);
      +    else
      +        return (curr_ticks - prev_ticks);
       }
      -
  • platform/hal/hal_trace.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_trace.c bes/platform/hal/hal_trace.c
      index e76792090ff..4bcde176ff4 100644
      --- a/platform/hal/hal_trace.c
      +++ b/platform/hal/hal_trace.c
      @@ -41,6 +41,7 @@
       #endif
       
       extern const char sys_build_info[];
      +extern void nv_record_flash_flush(void);
       
       #ifdef FAULT_DUMP
       void hal_trace_fault_dump(const uint32_t *regs, const uint32_t *extra, uint32_t extra_len);
      @@ -52,13 +53,13 @@ static void hal_trace_fault_handler(void);
       #if !(defined(ROM_BUILD) || defined(PROGRAMMER))
       #define ASSERT_MUTE_CODEC
       #define CRASH_DUMP_ENABLE
      -#if !(defined(NO_TRACE_TIME_STAMP) || defined(AUDIO_DEBUG))
      +#if !(defined(NO_TRACE_TIME_STAMP) || defined(AUDIO_DEBUG_V0_1_0))
       #define TRACE_TIME_STAMP
       #endif
      -#if (defined(DUMP_LOG_ENABLE) || defined(DUMP_CRASH_LOG) || defined(RESUME_MUSIC_AFTER_CRASH_REBOOT))
      +#if (defined(DUMP_LOG_ENABLE) || defined(DUMP_CRASH_ENABLE))
       #define TRACE_TO_APP
       #endif
      -#if defined(CHIP_HAS_CP) && !defined(CP_BOOT) && !defined(CP_BUILD) && !defined(CONFIG_SMP) && !defined(CONFIG_BES_DUALCORE_AMP) && !defined(I2C_PA_CHANNEL_SUPPORT)
      +#ifdef CHIP_HAS_CP
       #define CP_TRACE_ENABLE
       #endif
       #endif
      @@ -70,14 +71,10 @@ static void hal_trace_fault_handler(void);
       #endif
       
       #ifndef TRACE_BUF_SIZE
      -#define TRACE_BUF_SIZE                  (4 * 1024)
      -#endif
      -
       #ifdef AUDIO_DEBUG
      -// Fix baudrate and buffer size
      -#if TRACE_BUF_SIZE < (16 * 1024)
      -#undef TRACE_BUF_SIZE
      -#define TRACE_BUF_SIZE                  (16 * 1024)
      +#define TRACE_BUF_SIZE                  (6 * 1024)
      +#else
      +#define TRACE_BUF_SIZE                  (4 * 1024)
       #endif
       #endif
       
      @@ -105,6 +102,8 @@ static void hal_trace_fault_handler(void);
       
       #define TRACE_NEAR_FULL_THRESH          200
       
      +#define TRACE_CRLF
      +
       #ifdef TRACE_CRLF
       #define NEW_LINE_STR                    "\r\n"
       #else
      @@ -114,6 +113,8 @@ static void hal_trace_fault_handler(void);
       #define HAL_TRACE_ASSERT_ID             0xBE57AAAA
       #define HAL_TRACE_EXCEPTION_ID          0xBE57EEEE
       
      +#define HAL_MEMSC_ID_TRACE              HAL_MEMSC_ID_0
      +
       #define TRACE_BUF_LOC                   SYNC_FLAGS_LOC
       
       struct ASSERT_INFO_T {
      @@ -195,7 +196,11 @@ static const struct HAL_UART_CFG_T uart_cfg = {
           .tx_level = HAL_UART_FIFO_LEVEL_1_2,
           .rx_level = HAL_UART_FIFO_LEVEL_1_2,
           .baud = TRACE_BAUD_RATE,
      +#ifdef HAL_TRACE_RX_ENABLE
           .dma_rx = true,
      +#else
      +    .dma_rx = false,
      +#endif
       #if (TRACE_IDLE_OUTPUT == 0)
           .dma_tx = true,
       #else
      @@ -207,15 +212,15 @@ static const struct HAL_UART_CFG_T uart_cfg = {
       #if (TRACE_IDLE_OUTPUT == 0)
       static const enum HAL_DMA_PERIPH_T uart_periph[] = {
           HAL_GPDMA_UART0_TX,
      -#if (CHIP_HAS_UART >= 2)
      +#if (CHIP_HAS_UART > 1)
           HAL_GPDMA_UART1_TX,
       #endif
      -#if (CHIP_HAS_UART >= 3)
      +#if (CHIP_HAS_UART > 2)
           HAL_GPDMA_UART2_TX,
       #endif
       };
       
      -static const struct HAL_UART_CFG_T uart_cfg = {
      +static const struct HAL_UART_CFG_T uart_rx_enable_cfg = {
           .parity = HAL_UART_PARITY_NONE,
           .stop = HAL_UART_STOP_BITS_1,
           .data = HAL_UART_DATA_BITS_8,
      @@ -242,7 +247,6 @@ static enum HAL_UART_ID_T trace_uart;
       
       TRACE_BUF_LOC
       static struct HAL_TRACE_BUF_T trace;
      -static struct HAL_TRACE_BUF_T *p_trace = &trace;
       
       POSSIBLY_UNUSED
       static const char newline[] = NEW_LINE_STR;
      @@ -253,23 +257,21 @@ static const uint32_t max_discards = 99999;
       static char discards_buf[sizeof(discards_prefix) - 1 + 7];
       static const unsigned char discards_digit_start = sizeof(discards_prefix) - 1;
       
      +static bool crash_dump_onprocess = false;
       
       #ifdef CRASH_DUMP_ENABLE
       static HAL_TRACE_CRASH_DUMP_CB_T crash_dump_cb_list[HAL_TRACE_CRASH_DUMP_MODULE_END];
      -static bool in_crash_dump = false;
      +static bool crash_handling;
       #ifdef TRACE_TO_APP
      -static HAL_TRACE_APP_NOTIFY_T app_notify_cb[HAL_TRACE_APP_REG_ID_QTY];
      -static HAL_TRACE_APP_OUTPUT_T app_output_cb[HAL_TRACE_APP_REG_ID_QTY];
      +static HAL_TRACE_APP_NOTIFY_T app_notify_cb = NULL;
      +static HAL_TRACE_APP_OUTPUT_T app_output_cb = NULL;
       static HAL_TRACE_APP_OUTPUT_T app_crash_custom_cb = NULL;
      -static bool app_output_cb_valid = false;
       static bool app_output_enabled =
      -#ifdef DUMP_LOG_ENABLE
      +#if defined(DUMP_LOG_ENABLE)
           true;
       #else
           false;
       #endif
      -
      -static void hal_trace_app_output_callback(const unsigned char *buf, unsigned int buf_len);
       #endif // TRACE_TO_APP
       #endif // CRASH_DUMP_ENABLE
       #ifdef CP_TRACE_ENABLE
      @@ -277,20 +279,20 @@ static HAL_TRACE_APP_NOTIFY_T cp_notify_cb = NULL;
       static HAL_TRACE_BUF_CTRL_T cp_buffer_cb = NULL;
       #endif
       
      -#ifdef AUDIO_DEBUG
      +#ifdef AUDIO_DEBUG_V0_1_0
       static const char trace_head_buf[] = "[trace]";
       #endif
       
      -static enum TR_LEVEL_T trace_max_level;
      -static uint32_t trace_mod_map[(TR_MODULE_QTY + 31) / 32];
      +static enum LOG_LEVEL_T trace_max_level;
      +static uint32_t trace_mod_map[(LOG_MODULE_QTY + 31) / 32];
       
       static bool hal_trace_is_uart_transport(enum HAL_TRACE_TRANSPORT_T transport)
       {
           if (transport == HAL_TRACE_TRANSPORT_UART0
      -#if (CHIP_HAS_UART >= 2)
      +#if (CHIP_HAS_UART > 1)
                   || transport == HAL_TRACE_TRANSPORT_UART1
       #endif
      -#if (CHIP_HAS_UART >= 3)
      +#if (CHIP_HAS_UART > 2)
                   || transport == HAL_TRACE_TRANSPORT_UART2
       #endif
                   ) {
      @@ -309,15 +311,15 @@ static void hal_trace_uart_send(void)
       
           lock = int_lock();
       
      -    wptr = p_trace->wptr;
      -    rptr = p_trace->rptr;
      +    wptr = trace.wptr;
      +    rptr = trace.rptr;
       
           // There is a race condition if we do not check s/w flag, but only check the h/w status.
      -    // [e.g., hal_dma_chan_busy(dma_cfg.ch)]
      +    // [e.g., hal_gpdma_chan_busy(dma_cfg.ch)]
           // When the DMA is done, but DMA IRQ handler is still pending due to interrupt lock
           // or higher priority IRQ, it will have a chance to send the same content twice.
      -    if (!p_trace->sending && wptr != rptr) {
      -        p_trace->sending = true;
      +    if (!trace.sending && wptr != rptr) {
      +        trace.sending = true;
       
               sends[1] = 0;
               if (wptr > rptr) {
      @@ -336,26 +338,26 @@ static void hal_trace_uart_send(void)
                   sends[1] = HAL_DMA_MAX_DESC_XFER_SIZE;
               }
       
      -        dma_cfg.src = (uint32_t)&p_trace->buf[rptr];
      +        dma_cfg.src = (uint32_t)&trace.buf[rptr];
               if (sends[1] == 0) {
                   dma_cfg.src_tsize = sends[0];
      -            hal_dma_init_desc(p_dma_desc[0], &dma_cfg, NULL, 1);
      +            hal_gpdma_init_desc(&dma_desc[0], &dma_cfg, NULL, 1);
               } else {
                   dma_cfg.src_tsize = sends[0];
      -            hal_dma_init_desc(p_dma_desc[0], &dma_cfg, p_dma_desc[1], 0);
      +            hal_gpdma_init_desc(&dma_desc[0], &dma_cfg, &dma_desc[1], 0);
       
                   if (rptr + sends[0] < TRACE_BUF_SIZE) {
      -                dma_cfg.src = (uint32_t)&p_trace->buf[rptr + sends[0]];
      +                dma_cfg.src = (uint32_t)&trace.buf[rptr + sends[0]];
                   } else {
      -                dma_cfg.src = (uint32_t)&p_trace->buf[0];
      +                dma_cfg.src = (uint32_t)&trace.buf[0];
                   }
                   dma_cfg.src_tsize = sends[1];
      -            hal_dma_init_desc(p_dma_desc[1], &dma_cfg, NULL, 1);
      +            hal_gpdma_init_desc(&dma_desc[1], &dma_cfg, NULL, 1);
               }
      -        p_trace->sends[0] = sends[0];
      -        p_trace->sends[1] = sends[1];
      +        trace.sends[0] = sends[0];
      +        trace.sends[1] = sends[1];
       
      -        hal_dma_sg_start(p_dma_desc[0], &dma_cfg);
      +        hal_gpdma_sg_start(&dma_desc[0], &dma_cfg);
           }
       
           int_unlock(lock);
      @@ -368,8 +370,8 @@ static void hal_trace_uart_xfer_done(uint8_t chan, uint32_t remain_tsize, uint32
       
           lock = int_lock();
       
      -    sends[0] = p_trace->sends[0];
      -    sends[1] = p_trace->sends[1];
      +    sends[0] = trace.sends[0];
      +    sends[1] = trace.sends[1];
       
           if (error) {
               if (lli || sends[1] == 0) {
      @@ -388,19 +390,31 @@ static void hal_trace_uart_xfer_done(uint8_t chan, uint32_t remain_tsize, uint32
               }
           }
       
      -    p_trace->rptr += sends[0] + sends[1];
      -    if (p_trace->rptr >= TRACE_BUF_SIZE) {
      -        p_trace->rptr -= TRACE_BUF_SIZE;
      +    trace.rptr += sends[0] + sends[1];
      +    if (trace.rptr >= TRACE_BUF_SIZE) {
      +        trace.rptr -= TRACE_BUF_SIZE;
           }
      -    p_trace->sends[0] = 0;
      -    p_trace->sends[1] = 0;
      -    p_trace->sending = false;
      +    trace.sends[0] = 0;
      +    trace.sends[1] = 0;
      +    trace.sending = false;
       
           hal_trace_uart_send();
       
           int_unlock(lock);
       }
       
      +static void hal_trace_send(void)
      +{
      +#ifdef CP_TRACE_ENABLE
      +    if (get_cpu_id()) {
      +        return;
      +    }
      +#endif
      +
      +    if (hal_trace_is_uart_transport(trace_transport)) {
      +        hal_trace_uart_send();
      +    }
      +}
       
       #else // TRACE_IDLE_OUTPUT
       
      @@ -411,8 +425,8 @@ static void hal_trace_uart_idle_send(void)
           unsigned short wptr, rptr;
       
           lock = int_lock();
      -    wptr = p_trace->wptr;
      -    rptr = p_trace->rptr;
      +    wptr = trace.wptr;
      +    rptr = trace.rptr;
           int_unlock(lock);
       
           if (wptr == rptr) {
      @@ -421,22 +435,22 @@ static void hal_trace_uart_idle_send(void)
       
           if (wptr < rptr) {
               for (i = rptr; i < TRACE_BUF_SIZE; i++) {
      -            hal_uart_blocked_putc(trace_uart, p_trace->buf[i]);
      +            hal_uart_blocked_putc(trace_uart, trace.buf[i]);
               }
               rptr = 0;
           }
       
           for (i = rptr; i < wptr; i++) {
      -        hal_uart_blocked_putc(trace_uart, p_trace->buf[i]);
      +        hal_uart_blocked_putc(trace_uart, trace.buf[i]);
           }
       
      -    p_trace->rptr = wptr;
      -    if (p_trace->rptr >= TRACE_BUF_SIZE) {
      -        p_trace->rptr -= TRACE_BUF_SIZE;
      +    trace.rptr = wptr;
      +    if (trace.rptr >= TRACE_BUF_SIZE) {
      +        trace.rptr -= TRACE_BUF_SIZE;
           }
       }
       
      -void hal_trace_send(void)
      +void hal_trace_idle_send(void)
       {
           if (hal_trace_is_uart_transport(trace_transport)) {
               hal_trace_uart_idle_send();
      @@ -449,14 +463,15 @@ int hal_trace_open(enum HAL_TRACE_TRANSPORT_T transport)
       {
           int ret;
       
      +    crash_dump_onprocess = false;
       
      -#if (CHIP_HAS_UART >= 2)
      +#if (CHIP_HAS_UART > 1)
       #ifdef FORCE_TRACE_UART1
           transport = HAL_TRACE_TRANSPORT_UART1;
       #endif
       #endif
       
      -#if (CHIP_HAS_UART >= 3)
      +#if (CHIP_HAS_UART > 2)
       #ifdef FORCE_TRACE_UART2
           transport = HAL_TRACE_TRANSPORT_UART2;
       #endif
      @@ -475,19 +490,19 @@ int hal_trace_open(enum HAL_TRACE_TRANSPORT_T transport)
               return hal_trace_switch(transport);
           }
       
      -    trace_max_level = TR_LEVEL_INFO;
      +    trace_max_level = LOG_LEVEL_INFO;
           for (int i = 0; i < ARRAY_SIZE(trace_mod_map); i++) {
               trace_mod_map[i] = ~0;
           }
       
           memcpy(discards_buf, discards_prefix, discards_digit_start);
       
      -    p_trace->wptr = 0;
      -    p_trace->rptr = 0;
      -    p_trace->discards = 0;
      -    p_trace->sending = false;
      -    p_trace->in_trace = false;
      -    p_trace->wrapped = false;
      +    trace.wptr = 0;
      +    trace.rptr = 0;
      +    trace.discards = 0;
      +    trace.sending = false;
      +    trace.in_trace = false;
      +    trace.wrapped = false;
       
           if (hal_trace_is_uart_transport(transport)) {
               trace_uart = HAL_UART_ID_0 + (transport - HAL_TRACE_TRANSPORT_UART0);
      @@ -497,8 +512,8 @@ int hal_trace_open(enum HAL_TRACE_TRANSPORT_T transport)
               }
       
       #if (TRACE_IDLE_OUTPUT == 0)
      -        p_trace->sends[0] = 0;
      -        p_trace->sends[1] = 0;
      +        trace.sends[0] = 0;
      +        trace.sends[1] = 0;
       
               memset(&dma_cfg, 0, sizeof(dma_cfg));
               dma_cfg.dst = 0; // useless
      @@ -511,7 +526,7 @@ int hal_trace_open(enum HAL_TRACE_TRANSPORT_T transport)
               dma_cfg.src_width = HAL_DMA_WIDTH_BYTE;
               dma_cfg.type = HAL_DMA_FLOW_M2P_DMA;
               dma_cfg.try_burst = 0;
      -        dma_cfg.ch = hal_dma_get_chan(dma_cfg.dst_periph, HAL_DMA_HIGH_PRIO);
      +        dma_cfg.ch = hal_gpdma_get_chan(dma_cfg.dst_periph, HAL_DMA_HIGH_PRIO);
       
               ASSERT(dma_cfg.ch != HAL_DMA_CHAN_NONE, "Failed to get DMA channel");
       #endif
      @@ -527,37 +542,37 @@ int hal_trace_open(enum HAL_TRACE_TRANSPORT_T transport)
       
           trace_transport = transport;
       
      -#ifdef CRASH_DUMP_ENABLE
      -    in_crash_dump = false;
      +#ifdef HAL_TRACE_RX_ENABLE
      +    hal_trace_rx_open();
       #endif
       
           // Show build info
      -    hal_trace_output((const unsigned char *)newline, sizeof(newline) - 1);
      -    hal_trace_output((const unsigned char *)newline, sizeof(newline) - 1);
      -    hal_trace_output((unsigned char *)sys_build_info, strlen(sys_build_info));
      +    static const char dbl_new_line[] = NEW_LINE_STR NEW_LINE_STR;
      +    hal_trace_output((unsigned char *)dbl_new_line, sizeof(dbl_new_line));
      +    hal_trace_output((unsigned char *)sys_build_info, strlen(sys_build_info)+1);
       
           char buf[50];
           int len;
           len = snprintf(buf, sizeof(buf),
               NEW_LINE_STR NEW_LINE_STR "------" NEW_LINE_STR "METAL_ID: %d" NEW_LINE_STR "------" NEW_LINE_STR NEW_LINE_STR,
               hal_get_chip_metal_id());
      -    hal_trace_output((unsigned char *)buf, len);
      +    hal_trace_output((unsigned char *)buf, len+1);
       
           return 0;
       }
       
       int hal_trace_switch(enum HAL_TRACE_TRANSPORT_T transport)
       {
      -    uint32_t lock;
      +    uint32_t POSSIBLY_UNUSED lock;
           int ret;
       
      -#if (CHIP_HAS_UART >= 2)
      +#if (CHIP_HAS_UART > 1)
       #ifdef FORCE_TRACE_UART1
           transport = HAL_TRACE_TRANSPORT_UART1;
       #endif
       #endif
       
      -#if (CHIP_HAS_UART >= 3)
      +#if (CHIP_HAS_UART > 2)
       #ifdef FORCE_TRACE_UART2
           transport = HAL_TRACE_TRANSPORT_UART2;
       #endif
      @@ -580,14 +595,14 @@ int hal_trace_switch(enum HAL_TRACE_TRANSPORT_T transport)
       
           ret = 0;
       
      -#if (CHIP_HAS_UART >= 2)
      +#if (CHIP_HAS_UART > 1)
       
           lock = int_lock();
       
           if (hal_trace_is_uart_transport(trace_transport)) {
       #if (TRACE_IDLE_OUTPUT == 0)
               if (dma_cfg.ch != HAL_DMA_CHAN_NONE) {
      -            hal_dma_cancel(dma_cfg.ch);
      +            hal_gpdma_cancel(dma_cfg.ch);
               }
       #endif
               hal_uart_close(trace_uart);
      @@ -597,13 +612,13 @@ int hal_trace_switch(enum HAL_TRACE_TRANSPORT_T transport)
               trace_uart = HAL_UART_ID_0 + (transport - HAL_TRACE_TRANSPORT_UART0);
       #if (TRACE_IDLE_OUTPUT == 0)
               dma_cfg.dst_periph = uart_periph[trace_uart - HAL_UART_ID_0];
      -        p_trace->sends[0] = 0;
      -        p_trace->sends[1] = 0;
      +        trace.sends[0] = 0;
      +        trace.sends[1] = 0;
       #endif
               ret = hal_uart_open(trace_uart, &uart_cfg);
               if (ret) {
       #if (TRACE_IDLE_OUTPUT == 0)
      -            hal_dma_free_chan(dma_cfg.ch);
      +            hal_gpdma_free_chan(dma_cfg.ch);
                   dma_cfg.ch = HAL_DMA_CHAN_NONE;
       #endif
                   trace_transport = HAL_TRACE_TRANSPORT_QTY;
      @@ -611,14 +626,14 @@ int hal_trace_switch(enum HAL_TRACE_TRANSPORT_T transport)
               }
           }
       
      -    p_trace->sending = false;
      +    trace.sending = false;
       
           trace_transport = transport;
       
      -_exit: POSSIBLY_UNUSED;
      +_exit:
           int_unlock(lock);
       
      -#endif // (CHIP_HAS_UART >= 2)
      +#endif // CHIP_HAS_UART > 1
       
           return ret;
       }
      @@ -637,8 +652,8 @@ int hal_trace_close(void)
           if (hal_trace_is_uart_transport(trace_transport)) {
       #if (TRACE_IDLE_OUTPUT == 0)
               if (dma_cfg.ch != HAL_DMA_CHAN_NONE) {
      -            hal_dma_cancel(dma_cfg.ch);
      -            hal_dma_free_chan(dma_cfg.ch);
      +            hal_gpdma_cancel(dma_cfg.ch);
      +            hal_gpdma_free_chan(dma_cfg.ch);
                   dma_cfg.ch = HAL_DMA_CHAN_NONE;
               }
       #endif
      @@ -651,9 +666,9 @@ _exit:
           return 0;
       }
       
      -int hal_trace_enable_log_module(enum TR_MODULE_T module)
      +int hal_trace_enable_log_module(enum LOG_MODULE_T module)
       {
      -    if (module >= TR_MODULE_QTY) {
      +    if (module >= LOG_MODULE_QTY) {
               return 1;
           }
       
      @@ -661,9 +676,9 @@ int hal_trace_enable_log_module(enum TR_MODULE_T module)
           return 0;
       }
       
      -int hal_trace_disable_log_module(enum TR_MODULE_T module)
      +int hal_trace_disable_log_module(enum LOG_MODULE_T module)
       {
      -    if (module >= TR_MODULE_QTY) {
      +    if (module >= LOG_MODULE_QTY) {
               return 1;
           }
       
      @@ -686,9 +701,9 @@ int hal_trace_set_log_module(const uint32_t *map, uint32_t word_cnt)
           return 0;
       }
       
      -int hal_trace_set_log_level(enum TR_LEVEL_T level)
      +int hal_trace_set_log_level(enum LOG_LEVEL_T level)
       {
      -    if (level >= TR_LEVEL_QTY) {
      +    if (level >= LOG_LEVEL_QTY) {
               return 1;
           }
       
      @@ -696,7 +711,7 @@ int hal_trace_set_log_level(enum TR_LEVEL_T level)
           return 0;
       }
       
      -void hal_trace_get_history_buffer(const uint8_t **buf1, uint32_t *len1, const uint8_t **buf2, uint32_t *len2)
      +void hal_trace_get_history_buffer(const unsigned char **buf1, unsigned int *len1, const unsigned char **buf2, unsigned int *len2)
       {
           uint32_t lock;
           uint8_t *b1, *b2;
      @@ -707,15 +722,15 @@ void hal_trace_get_history_buffer(const uint8_t **buf1, uint32_t *len1, const ui
       
           lock = int_lock();
       
      -    if (TRACE_BUF_SIZE > p_trace->wptr) {
      -        if (p_trace->wrapped) {
      -            b1 = &p_trace->buf[p_trace->wptr];
      -            l1 = TRACE_BUF_SIZE - p_trace->wptr;
      -            b2 = &p_trace->buf[0];
      -            l2 = p_trace->wptr;
      +    if (TRACE_BUF_SIZE > trace.wptr) {
      +        if (trace.wrapped) {
      +            b1 = &trace.buf[trace.wptr];
      +            l1 = TRACE_BUF_SIZE - trace.wptr;
      +            b2 = &trace.buf[0];
      +            l2 = trace.wptr;
               } else {
      -            b1 = &p_trace->buf[0];
      -            l1 = p_trace->wptr;
      +            b1 = &trace.buf[0];
      +            l1 = trace.wptr;
                   b2 = NULL;
                   l2 = 0;
               }
      @@ -739,10 +754,8 @@ void hal_trace_get_history_buffer(const uint8_t **buf1, uint32_t *len1, const ui
       
       static void hal_trace_print_discards(uint32_t discards)
       {
      -    const uint8_t base = 10;
      -    char digit[10];
      -    char *d;
      -    char *out;
      +    static const uint8_t base = 10;
      +    char digit[5], *d, *out;
           uint16_t len;
           uint16_t size;
       
      @@ -765,21 +778,21 @@ static void hal_trace_print_discards(uint32_t discards)
           *out++ = '\n';
           len = out - &discards_buf[0];
       
      -    size = TRACE_BUF_SIZE - p_trace->wptr;
      +    size = TRACE_BUF_SIZE - trace.wptr;
           if (size >= len) {
               size = len;
           }
      -    memcpy(&p_trace->buf[p_trace->wptr], &discards_buf[0], size);
      +    memcpy(&trace.buf[trace.wptr], &discards_buf[0], size);
           if (size < len) {
      -        memcpy(&p_trace->buf[0], &discards_buf[size], len - size);
      +        memcpy(&trace.buf[0], &discards_buf[size], len - size);
           }
      -    p_trace->wptr += len;
      -    if (p_trace->wptr >= TRACE_BUF_SIZE) {
      -        p_trace->wptr -= TRACE_BUF_SIZE;
      +    trace.wptr += len;
      +    if (trace.wptr >= TRACE_BUF_SIZE) {
      +        trace.wptr -= TRACE_BUF_SIZE;
           }
       }
       
      -#ifdef AUDIO_DEBUG
      +#ifdef AUDIO_DEBUG_V0_1_0
       static void hal_trace_print_head(void)
       {
           uint16_t len;
      @@ -787,17 +800,17 @@ static void hal_trace_print_head(void)
       
           len = sizeof(trace_head_buf) - 1;
       
      -    size = TRACE_BUF_SIZE - p_trace->wptr;
      +    size = TRACE_BUF_SIZE - trace.wptr;
           if (size >= len) {
               size = len;
           }
      -    memcpy(&p_trace->buf[p_trace->wptr], &trace_head_buf[0], size);
      +    memcpy(&trace.buf[trace.wptr], &trace_head_buf[0], size);
           if (size < len) {
      -        memcpy(&p_trace->buf[0], &trace_head_buf[size], len - size);
      +        memcpy(&trace.buf[0], &trace_head_buf[size], len - size);
           }
      -    p_trace->wptr += len;
      -    if (p_trace->wptr >= TRACE_BUF_SIZE) {
      -        p_trace->wptr -= TRACE_BUF_SIZE;
      +    trace.wptr += len;
      +    if (trace.wptr >= TRACE_BUF_SIZE) {
      +        trace.wptr -= TRACE_BUF_SIZE;
           }
       }
       #endif
      @@ -809,39 +822,36 @@ int hal_trace_output(const unsigned char *buf, unsigned int buf_len)
           uint32_t avail;
           uint32_t out_len;
           uint16_t size;
      -#ifdef CP_TRACE_ENABLE
      -    uint8_t cpu_id = get_cpu_id() ? 1 : 0;
      -#endif
       
           ret = 0;
       
           lock = int_lock();
       #ifdef CP_TRACE_ENABLE
      -    hal_trace_cp_lock(cpu_id);
      +    while (hal_memsc_lock(HAL_MEMSC_ID_TRACE) == 0);
       #endif
       
           // Avoid troubles when NMI occurs during trace
      -    if (!p_trace->in_trace) {
      -        p_trace->in_trace = true;
      +    if (!trace.in_trace) {
      +        trace.in_trace = true;
       
      -        if (p_trace->wptr >= p_trace->rptr) {
      -            avail = TRACE_BUF_SIZE - (p_trace->wptr - p_trace->rptr) - 1;
      +        if (trace.wptr >= trace.rptr) {
      +            avail = TRACE_BUF_SIZE - (trace.wptr - trace.rptr) - 1;
               } else {
      -            avail = (p_trace->rptr - p_trace->wptr) - 1;
      +            avail = (trace.rptr - trace.wptr) - 1;
               }
       
               out_len = buf_len;
      -#ifdef AUDIO_DEBUG
      +#ifdef AUDIO_DEBUG_V0_1_0
               out_len += sizeof(trace_head_buf) - 1;
       #endif
      -        if (p_trace->discards) {
      +        if (trace.discards) {
                   out_len += sizeof(discards_buf);
               }
       
               if (avail < out_len) {
                   ret = 1;
      -            if (p_trace->discards < (1 << (sizeof(p_trace->discards) * 8)) - 1) {
      -                p_trace->discards++;
      +            if (trace.discards < (1 << (sizeof(trace.discards) * 8)) - 1) {
      +                trace.discards++;
                   }
       #ifdef CP_TRACE_ENABLE
       #if (TRACE_IDLE_OUTPUT == 0)
      @@ -849,27 +859,27 @@ int hal_trace_output(const unsigned char *buf, unsigned int buf_len)
       #endif
       #endif
               } else {
      -#ifdef AUDIO_DEBUG
      +#ifdef AUDIO_DEBUG_V0_1_0
                   hal_trace_print_head();
       #endif
       
      -            if (p_trace->discards) {
      -                hal_trace_print_discards(p_trace->discards);
      -                p_trace->discards = 0;
      +            if (trace.discards) {
      +                hal_trace_print_discards(trace.discards);
      +                trace.discards = 0;
                   }
       
      -            size = TRACE_BUF_SIZE - p_trace->wptr;
      +            size = TRACE_BUF_SIZE - trace.wptr;
                   if (size >= buf_len) {
                       size = buf_len;
                   }
      -            memcpy(&p_trace->buf[p_trace->wptr], &buf[0], size);
      +            memcpy(&trace.buf[trace.wptr], &buf[0], size);
                   if (size < buf_len) {
      -                memcpy(&p_trace->buf[0], &buf[size], buf_len - size);
      +                memcpy(&trace.buf[0], &buf[size], buf_len - size);
                   }
      -            p_trace->wptr += buf_len;
      -            if (p_trace->wptr >= TRACE_BUF_SIZE) {
      -                p_trace->wptr -= TRACE_BUF_SIZE;
      -                p_trace->wrapped = true;
      +            trace.wptr += buf_len;
      +            if (trace.wptr >= TRACE_BUF_SIZE) {
      +                trace.wptr -= TRACE_BUF_SIZE;
      +                trace.wrapped = true;
                   }
       #if (TRACE_IDLE_OUTPUT == 0)
                   hal_trace_send();
      @@ -877,7 +887,7 @@ int hal_trace_output(const unsigned char *buf, unsigned int buf_len)
               }
       
       #ifdef CP_TRACE_ENABLE
      -        if (cpu_id) {
      +        if (get_cpu_id()) {
                   if (cp_buffer_cb) {
                       if (avail < out_len) {
                           cp_buffer_cb(HAL_TRACE_BUF_STATE_FULL);
      @@ -888,36 +898,26 @@ int hal_trace_output(const unsigned char *buf, unsigned int buf_len)
               }
       #endif
       
      -#ifdef CP_TRACE_ENABLE
      -        hal_trace_cp_unlock(cpu_id);
      -#endif
      +        trace.in_trace = false;
       
       #ifdef CRASH_DUMP_ENABLE
       #ifdef TRACE_TO_APP
      -        bool app_output;
      -        app_output = app_output_cb_valid && app_output_enabled;
      -#ifdef CP_TRACE_ENABLE
      -        if (cpu_id) {
      -            app_output = false;
      -        }
      -#endif
      -        if (app_output) {
      +        if (app_output_cb && app_output_enabled) {
      +            bool saved_output_state;
       
      +            saved_output_state = app_output_enabled;
                   app_output_enabled = false;
       
      -            hal_trace_app_output_callback(buf, buf_len);
      +            app_output_cb(buf, buf_len);
       
      -            app_output_enabled = true;
      +            app_output_enabled = saved_output_state;
               }
       #endif
       #endif
           }
       
      -#if defined(CP_TRACE_ENABLE) && defined(CP_MEMSC_TIMEOUT_CHECK)
      -    if (memsc_timeout[cpu_id] == 1) {
      -        memsc_timeout[cpu_id] = 2;
      -        ASSERT(false, "TRACE-%u: Wait memsc timeout", cpu_id);
      -    }
      +#ifdef CP_TRACE_ENABLE
      +    hal_memsc_unlock(HAL_MEMSC_ID_TRACE);
       #endif
           int_unlock(lock);
       
      @@ -927,14 +927,11 @@ int hal_trace_output(const unsigned char *buf, unsigned int buf_len)
       //define USE_CRC_CHECK
       //#define LITE_VERSION
       
      -#define TRACE_ID_MAX_ARG_NUM                15
      -
       typedef struct {
           uint32_t crc:6;
           uint32_t count:4;
           uint32_t tskid:5;
      -    uint32_t rfu:17;    //!< reserved for future use
      -    uint32_t addr;      //!< enough for trace string address
      +    uint32_t addr:17; //127 KB trace space support
       }trace_info_t;
       
       typedef struct {
      @@ -949,10 +946,7 @@ typedef struct {
           trace_info_t trace_info;
       }__attribute__((packed)) LOG_DATA_T;
       
      -struct PACKED LOG_BODY_T {
      -    LOG_DATA_T hdr;
      -    uint32_t arg[TRACE_ID_MAX_ARG_NUM];
      -};
      +extern const char *unkonw_str;
       
       extern uint32_t __trc_str_start__[];
       extern uint32_t __trc_str_end__[];
      @@ -993,62 +987,66 @@ uint8_t crc6(uint8_t *data, uint32_t length)
       }
       
       
      -static int hal_trace_format_id(uint32_t attr, struct LOG_BODY_T *log, const char *fmt, va_list ap)
      +static int hal_trace_format_id(uint32_t attr, char *buf, uint32_t size, const char *fmt, va_list ap)
       {
           uint8_t num;
      +    unsigned int value[10];
      +    LOG_DATA_T trace;
      +
      +    if (size < sizeof(trace) + sizeof(value)) {
      +        return -1;
      +    }
       
      -    num = GET_BITFIELD(attr, TR_ATTR_ARG_NUM);
      -    if (num > TRACE_ID_MAX_ARG_NUM) {
      -        num = TRACE_ID_MAX_ARG_NUM;
      +    num = GET_BITFIELD(attr, LOG_ATTR_ARG_NUM);
      +    if (num > 10) {
      +        num = 10;
           }
           for (int i = 0; i < num; i++) {
      -        log->arg[i] = va_arg(ap, unsigned long);
      +        value[i] = va_arg(ap, unsigned long);
           }
       
      +    //memset(buf, 0, size);
       
      -    log->hdr.trace_info.count = num;
      -    log->hdr.trace_info.addr = (uint32_t)fmt-(uint32_t)0xFFFC0000; //(uint32_t)fmt-(uint32_t)__trc_str_start__;
      -    log->hdr.trace_info.tskid = osGetThreadIntId();
      -    log->hdr.trace_info.crc = 0x2A;
      +    trace.trace_info.count = num;
      +    trace.trace_info.addr = (uint32_t)fmt-(uint32_t)0xFFFC0000;//(uint32_t)fmt-(uint32_t)__trc_str_start__;
      +    trace.trace_info.tskid = osGetThreadIntId();
      +    trace.trace_info.crc = 0x2A;
       #ifndef LITE_VERSION
      -    log->hdr.trace_head.timestamp = TICKS_TO_MS(hal_sys_timer_get());
      +    trace.trace_head.timestamp = TICKS_TO_MS(hal_sys_timer_get());
       #ifdef USE_CRC_CHECK
      -    log->hdr.trace_head.crc = crc8(((uint8_t *)&log->hdr) + 1, 7);
      +    trace.trace_head.crc = crc8(((uint8_t *)&trace)+1,7);
       #else
      -    log->hdr.trace_head.crc = 0xBE;
      +    trace.trace_head.crc = 0xBE;
       #endif
       #else
      -    log->hdr.trace_info.crc = crc6(((uint8_t *)&log->hdr) + 1, 3);
      +    trace.trace_info.crc = crc6(((uint8_t *)&trace)+1,3);
       #endif
      +    memcpy(buf, &trace, sizeof(trace));
      +    if (num != 0) {
      +        memcpy(buf + sizeof(trace), value, 4*num);
      +    }
       
      -    return sizeof(log->hdr) + sizeof(log->arg[0]) * num;
      +    return sizeof(trace) + 4*num;
       }
       #endif
       
      -static int hal_trace_print_time(enum TR_LEVEL_T level, enum TR_MODULE_T module, char *buf, unsigned int size)
      +static int hal_trace_print_time(enum LOG_LEVEL_T level, enum LOG_MODULE_T module, char *buf, unsigned int size)
       {
       #ifdef TRACE_TIME_STAMP
      -#ifdef CONFIG_SMP
      -#define PRINT_CPU_ID
      -#else
      -#define PRINT_MODE_LEVEL
      -#endif
      -#ifdef PRINT_MODE_LEVEL
           static const char level_ch[] = { 'C', 'E', 'W', 'N', 'I', 'D', 'V', '-', };
      -    const char *mod_name;
      -    int i;
      -#endif
           char ctx[10];
           int len;
      +    int i;
      +    const char *mod_name;
       
       #ifdef CRASH_DUMP_ENABLE
      -    if (in_crash_dump) {
      +    if (crash_handling) {
               return 0;
           }
       #endif
       
           if (0) {
      -#if defined(CP_TRACE_ENABLE) && !defined(CONFIG_SMP)
      +#ifdef CP_TRACE_ENABLE
           } else if (get_cpu_id()) {
               ctx[0] = ' ';
               ctx[1] = 'C';
      @@ -1066,12 +1064,12 @@ static int hal_trace_print_time(enum TR_LEVEL_T level, enum TR_MODULE_T module,
               }
           } else {
       #ifdef RTOS
      -#if defined(KERNEL_RHINO) || defined(KERNEL_RTX5)
      +#ifdef KERNEL_RTX5
               /* const char *thread_name = osGetThreadName(); */
               /* snprintf(ctx, sizeof(ctx), "%.9s", thread_name ? (char *)thread_name : "NULL"); */
               ctx[0] = ' ';
               ctx[1] = ' ';
      -        ctx[2] = '0';
      +        ctx[2] = 't';
               ctx[3] = '\0';
       #else
               snprintf(ctx, sizeof(ctx), "%3d", osGetThreadIntId());
      @@ -1085,7 +1083,7 @@ static int hal_trace_print_time(enum TR_LEVEL_T level, enum TR_MODULE_T module,
           }
           ctx[ARRAY_SIZE(ctx) - 1] = '\0';
           len = 0;
      -    len += snprintf(&buf[len], size - len, "%9u/", (unsigned)__SLIM_TICKS_TO_MS(hal_sys_timer_get()));
      +    len += snprintf(&buf[len], size - len, "%9u/", (unsigned)TICKS_TO_MS(hal_sys_timer_get()));
           if (size > len + 2) {
               buf[len++] = level_ch[level];
               buf[len++] = '/';
      @@ -1115,7 +1113,7 @@ static inline int hal_trace_format_va(uint32_t attr, char *buf, unsigned int siz
           int len;
       
           len = vsnprintf(&buf[0], size, fmt, ap);
      -    if ((attr & TR_ATTR_NO_LF) == 0) {
      +    if ((attr & LOG_ATTR_NO_LF) == 0) {
       #ifdef TRACE_CRLF
               if (len + 2 < size) {
                   buf[len++] = '\r';
      @@ -1130,49 +1128,38 @@ static inline int hal_trace_format_va(uint32_t attr, char *buf, unsigned int siz
           return len;
       }
       
      -int hal_trace_printf_internal(uint32_t attr, const char *fmt, va_list ap)
      +static int hal_trace_printf_internal(uint32_t attr, const char *fmt, va_list ap)
       {
       #ifdef USE_TRACE_ID
      -    struct PACKED LOG_CONTAINER_T {
      -        char prefix[4];
      -        struct LOG_BODY_T body;
      -    };
      -    union LOG_BUF_T {
      -        char buf[60];
      -        struct LOG_CONTAINER_T container;
      -        uint32_t align;
      -    };
      -
      -    union LOG_BUF_T log_buf;
      -    char *buf = (char *)&log_buf;
      +    char buf[60];
       #else
      -    char buf[TRACE_PRINTF_LEN];
      +    char buf[120];
       #endif
           int len = 0;
      -    enum TR_LEVEL_T level;
      -    enum TR_MODULE_T module;
      +    enum LOG_LEVEL_T level;
      +    enum LOG_MODULE_T module;
       
      -    level = GET_BITFIELD(attr, TR_ATTR_LEVEL);
      -    module = GET_BITFIELD(attr, TR_ATTR_MOD);
      +    level = GET_BITFIELD(attr, LOG_ATTR_LEVEL);
      +    module = GET_BITFIELD(attr, LOG_ATTR_MOD);
       
       #ifdef CRASH_DUMP_ENABLE
      -    if (!in_crash_dump)
      +    if (!crash_handling)
       #endif
           {
               if (level > trace_max_level) {
                   return 0;
               }
      -        if (level > TR_LEVEL_CRITICAL && (trace_mod_map[module >> 5] & (1 << (module & 0x1F))) == 0) {
      +        if (level > LOG_LEVEL_CRITICAL && (trace_mod_map[module >> 5] & (1 << (module & 0x1F))) == 0) {
                   return 0;
               }
           }
       
       #ifdef USE_TRACE_ID
      -    if ((attr & TR_ATTR_NO_ID) || !(len = hal_trace_format_id(attr, &log_buf.container.body, fmt, ap)) > 0) {
      +    if ((attr & LOG_ATTR_NO_ID) || (len = hal_trace_format_id(attr, buf, sizeof(buf), fmt, ap)) < 0)
       #endif
           {
               len = 0;
      -        if ((attr & TR_ATTR_NO_TS) == 0) {
      +        if ((attr & LOG_ATTR_NO_TS) == 0) {
                   len += hal_trace_print_time(level, module, &buf[len], sizeof(buf) - len);
               }
               len += hal_trace_format_va(attr, &buf[len], sizeof(buf) - len, fmt, ap);
      @@ -1186,7 +1173,7 @@ int hal_trace_printf(uint32_t attr, const char *fmt, ...)
           int ret;
           va_list ap;
       
      -    if (attr & TR_ATTR_IMM) {
      +    if (attr & LOG_ATTR_IMM) {
               hal_trace_flush_buffer();
           }
       
      @@ -1194,7 +1181,7 @@ int hal_trace_printf(uint32_t attr, const char *fmt, ...)
           ret = hal_trace_printf_internal(attr, fmt, ap);
           va_end(ap);
       
      -    if (attr & TR_ATTR_IMM) {
      +    if (attr & LOG_ATTR_IMM) {
               hal_trace_flush_buffer();
           }
       
      @@ -1203,7 +1190,7 @@ int hal_trace_printf(uint32_t attr, const char *fmt, ...)
       
       int hal_trace_dump(const char *fmt, unsigned int size,  unsigned int count, const void *buffer)
       {
      -    char buf[TRACE_DUMP_LEN];
      +    char buf[255]={0};
           int len=0, n=0, i=0;
       
           switch( size )
      @@ -1218,7 +1205,7 @@ int hal_trace_dump(const char *fmt, unsigned int size,  unsigned int count, cons
               case sizeof(uint16_t):
                       while(i<count && len<sizeof(buf))
                       {
      -                    len += snprintf(&buf[len], sizeof(buf) - len, fmt, *(uint16_t *)((uint16_t *)buffer+i));
      +                    len += snprintf(&buf[len], sizeof(buf) - len, fmt, *(int16_t *)((int16_t *)buffer+i));
                           i++;
                       }
                       break;
      @@ -1241,7 +1228,7 @@ int hal_trace_dump(const char *fmt, unsigned int size,  unsigned int count, cons
               buf[len++] = '\n';
           }
       
      -    n = hal_trace_output((unsigned char *)buf, len);
      +    n = hal_trace_output((unsigned char *)buf, len+1);
       
           return n;
       }
      @@ -1262,7 +1249,7 @@ int hal_trace_busy(void)
       int hal_trace_pause(void)
       {
           if (hal_trace_is_uart_transport(trace_transport)) {
      -        return hal_uart_pause(trace_uart, HAL_UART_XFER_TYPE_TX);
      +        return hal_uart_pause(trace_uart);
           }
           return 1;
       }
      @@ -1270,7 +1257,7 @@ int hal_trace_pause(void)
       int hal_trace_continue(void)
       {
           if (hal_trace_is_uart_transport(trace_transport)) {
      -        return hal_uart_continue(trace_uart, HAL_UART_XFER_TYPE_TX);
      +        return hal_uart_continue(trace_uart);
           }
           return 1;
       }
      @@ -1279,10 +1266,10 @@ int hal_trace_flush_buffer(void)
       {
           uint32_t lock;
           uint32_t time;
      -    int ret = 0;
      +    int ret;
           enum HAL_DMA_RET_T dma_ret;
       
      -    if (trace_transport >= HAL_TRACE_TRANSPORT_QTY)  {
      +    if (!hal_trace_is_uart_transport(trace_transport)) {
               return -1;
           }
       
      @@ -1295,24 +1282,25 @@ int hal_trace_flush_buffer(void)
           }
       #endif
       
      +    hal_uart_continue(trace_uart);
       
           lock = int_lock();
       
           time = hal_sys_timer_get();
      -    while (p_trace->wptr != p_trace->rptr &&
      -            (hal_sys_timer_get() - time) < TRACE_FLUSH_TIMEOUT) {
      +    while (trace.wptr != trace.rptr &&
      +            hal_sys_timer_get() - time < TRACE_FLUSH_TIMEOUT) {
       #if (TRACE_IDLE_OUTPUT == 0)
      -        while (hal_dma_chan_busy(dma_cfg.ch));
      -        dma_ret = hal_dma_irq_run_chan(dma_cfg.ch);
      +        while (hal_gpdma_chan_busy(dma_cfg.ch));
      +        dma_ret = hal_gpdma_irq_run_chan(dma_cfg.ch);
               if (dma_ret != HAL_DMA_OK) {
                   hal_trace_send();
               }
       #else
      -        hal_trace_send();
      +        hal_trace_idle_send();
       #endif
           }
       
      -    ret = (p_trace->wptr == p_trace->rptr) ? 0 : 1;
      +    ret = (trace.wptr == trace.rptr) ? 0 : 1;
       
           int_unlock(lock);
       
      @@ -1361,13 +1349,13 @@ uint32_t hal_trace_get_backtrace_addr(uint32_t addr)
       }
       
       #ifndef __ARM_ARCH_ISA_ARM
      -void hal_trace_print_special_stack_registers(uint32_t msp, uint32_t psp)
      +void hal_trace_print_special_stack_registers(void)
       {
           int len;
       
           hal_trace_output((const unsigned char *)newline, sizeof(newline) - 1);
       
      -    len = snprintf(crash_buf, sizeof(crash_buf), "MSP=%08X, PSP=%08X" NEW_LINE_STR, (unsigned)msp, (unsigned)psp);
      +    len = snprintf(crash_buf, sizeof(crash_buf), "MSP=%08X, PSP=%08X" NEW_LINE_STR, (unsigned)__get_MSP(), (unsigned)__get_PSP());
           hal_trace_output((unsigned char *)crash_buf, len);
       
       #ifdef __ARM_ARCH_8M_MAIN__
      @@ -1454,7 +1442,7 @@ void hal_trace_print_backtrace(uint32_t addr, uint32_t search_cnt, uint32_t prin
           }
       
           hal_trace_output((const unsigned char *)newline, sizeof(newline));
      -    hal_trace_output((const unsigned char *)bt_title, sizeof(bt_title) - 1);
      +    hal_trace_output((const unsigned char *)bt_title, sizeof(bt_title));
       
           stack = (uint32_t *)addr;
           for (i = 0, j = 0; i < search_cnt && j < print_cnt; i++) {
      @@ -1464,7 +1452,7 @@ void hal_trace_print_backtrace(uint32_t addr, uint32_t search_cnt, uint32_t prin
               call_addr = hal_trace_get_backtrace_addr(stack[i]);
               if (call_addr) {
                   len = snprintf(crash_buf, sizeof(crash_buf), "%8X" NEW_LINE_STR, (unsigned)call_addr);
      -            hal_trace_output((unsigned char *)crash_buf, len);
      +            hal_trace_output((unsigned char *)crash_buf, len+1);
                   j++;
               }
           }
      @@ -1475,9 +1463,9 @@ uint32_t hal_trace_get_baudrate(void)
           return uart_cfg.baud;
       }
       
      -bool hal_trace_in_crash_dump(void)
      +bool hal_trace_crash_dump_onprocess(void)
       {
      -    return in_crash_dump;
      +    return crash_dump_onprocess;
       }
       
       int hal_trace_crash_dump_register(enum HAL_TRACE_CRASH_DUMP_MODULE_T module, HAL_TRACE_CRASH_DUMP_CB_T cb)
      @@ -1490,11 +1478,11 @@ int hal_trace_crash_dump_register(enum HAL_TRACE_CRASH_DUMP_MODULE_T module, HAL
       }
       
       #ifdef CRASH_DUMP_ENABLE
      -void hal_trace_crash_dump_callback(void)
      +static void hal_trace_crash_dump_callback(void)
       {
           int i;
       
      -    in_crash_dump = true;
      +    crash_handling = true;
       
           for (i = 0; i < ARRAY_SIZE(crash_dump_cb_list); i++) {
               if (crash_dump_cb_list[i]) {
      @@ -1504,74 +1492,27 @@ void hal_trace_crash_dump_callback(void)
       }
       #endif
       
      -#ifdef CRASH_DUMP_ENABLE
      -#ifdef TRACE_TO_APP
      -void hal_trace_app_notify_callback(enum HAL_TRACE_STATE_T state)
      +void hal_trace_app_register(HAL_TRACE_APP_NOTIFY_T notify_cb, HAL_TRACE_APP_OUTPUT_T output_cb)
       {
      -    if (state == HAL_TRACE_STATE_CRASH_ASSERT_START) {
      -        app_output_enabled = true;
      -    } else if (state == HAL_TRACE_STATE_CRASH_FAULT_START) {
      -        if (app_crash_custom_cb == NULL) {
      -            app_output_enabled = true;
      -        }
      -    }
      -    for (int i = 0; i < HAL_TRACE_APP_REG_ID_QTY; i++) {
      -        if (app_notify_cb[i]) {
      -            app_notify_cb[i](state);
      -        }
      -    }
      -}
      -
      -static void hal_trace_app_output_callback(const unsigned char *buf, unsigned int buf_len)
      -{
      -    for (int i = 0; i < HAL_TRACE_APP_REG_ID_QTY; i++) {
      -        if (app_output_cb[i]) {
      -            app_output_cb[i](buf, buf_len);
      -        }
      -    }
      -}
      -#endif
      -#endif
      -
      -int hal_trace_app_register(enum HAL_TRACE_APP_REG_ID_T id, HAL_TRACE_APP_NOTIFY_T notify_cb, HAL_TRACE_APP_OUTPUT_T output_cb)
      -{
      -    if (id >= HAL_TRACE_APP_REG_ID_QTY) {
      -        return 1;
      -    }
       #ifdef TRACE_TO_APP
      -    bool output_valid = false;
      -    uint32_t lock;
      -
      -    lock = int_lock();
      -
      -    app_notify_cb[id] = notify_cb;
      -    app_output_cb[id] = output_cb;
      -
      -    for (int i = 0; i < HAL_TRACE_APP_REG_ID_QTY; i++) {
      -        if (app_output_cb[i]) {
      -            output_valid = true;
      -            break;
      -        }
      -    }
      -    app_output_cb_valid = output_valid;
      -
      -    int_unlock(lock);
      +    app_notify_cb = notify_cb;
      +    app_output_cb = output_cb;
       #endif
      -    return 0;
       }
       
       void hal_trace_app_custom_register(HAL_TRACE_APP_NOTIFY_T notify_cb, HAL_TRACE_APP_OUTPUT_T output_cb, HAL_TRACE_APP_OUTPUT_T crash_custom_cb)
       {
       #ifdef TRACE_TO_APP
      -    hal_trace_app_register(HAL_TRACE_APP_REG_ID_0, notify_cb, output_cb);
      +    hal_trace_app_register(notify_cb, output_cb);
           app_crash_custom_cb = crash_custom_cb;
       #endif
       }
       
      -void hal_trace_global_tag_register(HAL_TRACE_GLOBAL_TAG_CB_T tag_cb)
      +void hal_trace_cp_register(HAL_TRACE_APP_NOTIFY_T notify_cb, HAL_TRACE_BUF_CTRL_T buf_cb)
       {
      -#ifdef TRACE_GLOBAL_TAG
      -    gbl_tag_cb = tag_cb;
      +#ifdef CP_TRACE_ENABLE
      +    cp_notify_cb = notify_cb;
      +    cp_buffer_cb = buf_cb;
       #endif
       }
       
      @@ -1592,7 +1533,7 @@ int hal_trace_open(enum HAL_TRACE_TRANSPORT_T transport)
       
       #endif // !(DEBUG || REL_TRACE_ENABLE)
       
      -int hal_trace_open_cp(HAL_TRACE_BUF_CTRL_T buf_cb, HAL_TRACE_APP_NOTIFY_T notify_cb)
      +int hal_trace_open_cp(void)
       {
       #ifdef CP_TRACE_ENABLE
       #ifdef FAULT_DUMP
      @@ -1607,32 +1548,32 @@ int hal_trace_address_writable(uint32_t addr)
           if (RAM_BASE < addr && addr < RAM_BASE + RAM_SIZE) {
               return 1;
           }
      -#if defined(PSRAM_BASE) && (PSRAM_SIZE > 0)
      +#ifdef PSRAM_BASE
           if (PSRAM_BASE < addr && addr < PSRAM_BASE + PSRAM_SIZE) {
               return 1;
           }
       #endif
      -#if defined(PSRAM_NC_BASE) && (PSRAM_SIZE > 0)
      +#ifdef PSRAM_NC_BASE
           if (PSRAM_NC_BASE < addr && addr < PSRAM_NC_BASE + PSRAM_SIZE) {
               return 1;
           }
       #endif
      -#if defined(PSRAMUHS_BASE) && (PSRAMUHS_SIZE > 0)
      +#ifdef PSRAMUHS_BASE
           if (PSRAMUHS_BASE < addr && addr < PSRAMUHS_BASE + PSRAMUHS_SIZE) {
               return 1;
           }
       #endif
      -#if defined(PSRAMUHS_NC_BASE) && (PSRAMUHS_SIZE > 0)
      +#ifdef PSRAMUHS_NC_BASE
           if (PSRAMUHS_NC_BASE < addr && addr < PSRAMUHS_NC_BASE + PSRAMUHS_SIZE) {
               return 1;
           }
       #endif
      -#if defined(RAMRET_BASE) && (RAMRET_SIZE > 0)
      +#ifdef RAMRET_BASE
           if (RAMRET_BASE < addr && addr < RAMRET_BASE + RAMRET_SIZE) {
               return 1;
           }
       #endif
      -#if defined(RAMCP_BASE) && (RAMCP_SIZE > 0)
      +#ifdef RAMCP_BASE
           if (RAMCP_BASE < addr && addr < RAMCP_BASE + RAMCP_SIZE) {
               return 1;
           }
      @@ -1650,49 +1591,34 @@ int hal_trace_address_executable(uint32_t addr)
               return 0;
           }
           // Check location
      -    if ((RAMX_BASE + X_ADDR_OFFSET) < addr && addr < (RAMX_BASE + RAM_SIZE)) {
      +    if (RAMX_BASE + X_ADDR_OFFSET < addr && addr < RAMX_BASE + RAM_SIZE) {
               return 1;
           }
      -#ifndef NO_FLASH_BASE_ACCESS
      -#ifdef OTA_CODE_OFFSET
      -#define FLASH_EXEC_START                    (FLASHX_BASE + OTA_CODE_OFFSET)
      -#define FLASH_EXEC_SIZE                     (FLASH_SIZE - OTA_CODE_OFFSET)
      -#else
      -#define FLASH_EXEC_START                    (FLASHX_BASE)
      -#define FLASH_EXEC_SIZE                     (FLASH_SIZE)
      -#endif
      -#ifdef FLASH_REGION_SIZE
      -#undef FLASH_EXEC_SIZE
      -#define FLASH_EXEC_SIZE                     (FLASH_REGION_SIZE)
      -#endif
      -    if ((FLASH_EXEC_START + X_ADDR_OFFSET) < addr && addr < (FLASH_EXEC_START + FLASH_EXEC_SIZE)) {
      +    if (FLASHX_BASE + X_ADDR_OFFSET < addr && addr < FLASHX_BASE + FLASH_SIZE) {
               return 1;
           }
      -#endif
      -#if defined(PSRAMX_BASE) && (PSRAM_SIZE > 0)
      -    if ((PSRAMX_BASE + X_ADDR_OFFSET) < addr && addr < (PSRAMX_BASE + PSRAM_SIZE)) {
      +#ifdef PSRAMX_BASE
      +    if (PSRAMX_BASE + X_ADDR_OFFSET < addr && addr < PSRAMX_BASE + PSRAM_SIZE) {
               return 1;
           }
       #endif
      -#if defined(PSRAMUHSX_BASE) && (PSRAMUHS_SIZE > 0)
      -    if ((PSRAMUHSX_BASE + X_ADDR_OFFSET) < addr && addr < (PSRAMUHSX_BASE + PSRAMUHS_SIZE)) {
      +#ifdef PSRAMUHSX_BASE
      +    if (PSRAMUHSX_BASE + X_ADDR_OFFSET < addr && addr < PSRAMUHSX_BASE + PSRAMUHS_SIZE) {
               return 1;
           }
       #endif
      -#if defined(RAMXRET_BASE) && (RAMRET_SIZE > 0)
      -    if ((RAMXRET_BASE + X_ADDR_OFFSET) < addr && addr < (RAMXRET_BASE + RAMRET_SIZE)) {
      +#ifdef RAMXRET_BASE
      +    if (RAMXRET_BASE < addr && addr < RAMXRET_BASE + RAMRET_SIZE) {
               return 1;
           }
       #endif
       
       //#define CHECK_ROM_CODE
       #ifdef CHECK_ROM_CODE
      -#ifdef ROM_EXT_SIZE
      -#define ROM_TOTAL_SIZE                      (ROM_SIZE + ROM_EXT_SIZE)
      -#else
      -#define ROM_TOTAL_SIZE                      (ROM_SIZE)
      +#ifndef USED_ROM_SIZE
      +#define USED_ROM_SIZE                   ROM_SIZE
       #endif
      -    if ((ROMX_BASE + (NVIC_USER_IRQ_OFFSET * 4)) < addr && addr < (ROMX_BASE + ROM_TOTAL_SIZE)) {
      +    if (ROM_BASE + (NVIC_USER_IRQ_OFFSET * 4) < addr && addr < ROM_BASE + USED_ROM_SIZE) {
               return 1;
           }
       #endif
      @@ -1729,12 +1655,12 @@ int hal_trace_address_readable(uint32_t addr)
           if (FLASH_NC_BASE < addr && addr < FLASH_NC_BASE + FLASH_SIZE) {
               return 1;
           }
      -#if defined(PSRAM_NC_BASE) && (PSRAM_SIZE > 0)
      +#ifdef PSRAM_NC_BASE
           if (PSRAM_NC_BASE < addr && addr < PSRAM_NC_BASE + PSRAM_SIZE) {
               return 1;
           }
       #endif
      -#if defined(PSRAMUHS_NC_BASE) && (PSRAMUHS_SIZE > 0)
      +#ifdef PSRAMUHS_NC_BASE
           if (PSRAMUHS_NC_BASE < addr && addr < PSRAMUHS_NC_BASE + PSRAMUHS_SIZE) {
               return 1;
           }
      @@ -1752,10 +1678,15 @@ static void NORETURN hal_trace_crash_end(void)
       
           // Tag failure for simulation environment
           hal_cmu_simu_fail();
      +#ifndef PROGRAMMER
      +#ifndef __BES_OTA_MODE__
      +    nv_record_flash_flush();
      +#endif
      +#endif
       #ifdef CRASH_REBOOT
       
           hal_sw_bootmode_set(HAL_SW_BOOTMODE_REBOOT|HAL_SW_BOOTMODE_REBOOT_FROM_CRASH);
      -    pmu_reboot();
      +    hal_cmu_sys_reboot();
       #else
           hal_iomux_set_analog_i2c();
           hal_iomux_set_jtag();
      @@ -1784,13 +1715,13 @@ static void NORETURN USED hal_trace_assert_dump_internal(ASSERT_DUMP_ARGS)
           struct ASSERT_INFO_T info;
           int i;
       
      -    int_lock_global();
      -
      +    // MUST SAVE REGISTERS FIRST!
           p_regs = (const uint32_t *)crash_buf;
           for (i = 0; i < ARRAY_SIZE(info.R); i++) {
               info.R[i] = p_regs[i];
           }
       
      +    int_lock_global();
       
           info.ID = HAL_TRACE_ASSERT_ID;
           info.CPU_ID = get_cpu_id_tag();
      @@ -1815,6 +1746,8 @@ static void NORETURN USED hal_trace_assert_dump_internal(ASSERT_DUMP_ARGS)
       #endif
           info.FMT = fmt;
       #ifndef __ARM_ARCH_ISA_ARM
      +    info.MSP = __get_MSP();
      +    info.PSP = __get_PSP();
           info.CONTROL = __get_CONTROL();
       #ifdef __ARM_ARCH_8M_MAIN__
           info.MSPLIM = __get_MSPLIM();
      @@ -1859,8 +1792,18 @@ static void NORETURN USED hal_trace_assert_dump_internal(ASSERT_DUMP_ARGS)
       
           if (full_dump) {
       #ifdef TRACE_TO_APP
      -        hal_trace_app_notify_callback(HAL_TRACE_STATE_CRASH_ASSERT_START);
      +        if (app_notify_cb) {
      +            app_notify_cb(HAL_TRACE_STATE_CRASH_ASSERT_START);
      +        }
      +        app_output_enabled = true;
       #endif
      +
      +        crash_dump_onprocess = true;
      +        for (uint8_t i = 0; i < 10; i++){
      +            REL_TRACE_IMM(0,"                                                                        ");
      +            REL_TRACE_IMM(0,"                                                                        " NEW_LINE_STR);
      +            hal_sys_timer_delay(MS_TO_TICKS(50));
      +        }
           }
       #endif
       
      @@ -1868,7 +1811,7 @@ static void NORETURN USED hal_trace_assert_dump_internal(ASSERT_DUMP_ARGS)
       
           hal_sysfreq_req(HAL_SYSFREQ_USER_INIT, HAL_CMU_FREQ_52M);
       
      -    len = hal_trace_print_time(TR_LEVEL_CRITICAL, TR_MODULE_NONE, &crash_buf[0], sizeof(crash_buf));
      +    len = hal_trace_print_time(LOG_LEVEL_CRITICAL, LOG_MODULE_NONE, &crash_buf[0], sizeof(crash_buf));
           if (len > 0) {
               hal_trace_output((const unsigned char *)newline, sizeof(newline));
               hal_trace_output((unsigned char *)crash_buf, len);
      @@ -1885,23 +1828,23 @@ static void NORETURN USED hal_trace_assert_dump_internal(ASSERT_DUMP_ARGS)
       #endif
       
       #if defined(ASSERT_SHOW_FILE_FUNC) || defined(ASSERT_SHOW_FILE)
      -    hal_trace_output((const unsigned char *)desc_file, sizeof(desc_file) - 1);
      -    hal_trace_output((const unsigned char *)file, strlen(file));
      +    hal_trace_output((const unsigned char *)desc_file, sizeof(desc_file));
      +    hal_trace_output((const unsigned char *)file, strlen(file)+1);
           hal_trace_output((const unsigned char *)newline, sizeof(newline));
       #endif
       
       #if defined(ASSERT_SHOW_FILE_FUNC) || defined(ASSERT_SHOW_FUNC)
      -    hal_trace_output((const unsigned char *)desc_func, sizeof(desc_func) - 1);
      -    hal_trace_output((const unsigned char *)func, strlen(func));
      +    hal_trace_output((const unsigned char *)desc_func, sizeof(desc_func));
      +    hal_trace_output((const unsigned char *)func, strlen(func)+!);
           hal_trace_output((const unsigned char *)newline, sizeof(newline));
       #endif
       
      -    hal_trace_output((const unsigned char *)desc_line, sizeof(desc_func) - 1);
      +    hal_trace_output((const unsigned char *)desc_line, sizeof(desc_func));
           len = snprintf(crash_buf, sizeof(crash_buf), "%u", line);
           hal_trace_output((const unsigned char *)crash_buf, len);
           hal_trace_output((const unsigned char *)newline, sizeof(newline));
       
      -    hal_trace_output((unsigned char *)separate_line, sizeof(separate_line) - 1);
      +    hal_trace_output((unsigned char *)separate_line, sizeof(separate_line));
       
           hal_trace_flush_buffer();
       #endif
      @@ -1915,7 +1858,7 @@ static void NORETURN USED hal_trace_assert_dump_internal(ASSERT_DUMP_ARGS)
           hal_trace_flush_buffer();
       
           hal_trace_print_common_registers(info.R);
      -    hal_trace_print_special_stack_registers(info.MSP, info.PSP);
      +    hal_trace_print_special_stack_registers();
       
           hal_trace_print_stack(info.R[13]);
       
      @@ -1932,41 +1875,14 @@ static void NORETURN USED hal_trace_assert_dump_internal(ASSERT_DUMP_ARGS)
               hal_sys_timer_delay(MS_TO_TICKS(5));
       
       #ifdef CORE_DUMP
      -        {
      -            static CrashCatcherAssertRegisters regs;
      -
      -            regs.msp = info.MSP;
      -            regs.psp = info.PSP;
      -            regs.assertPSR = __get_xPSR();
      -            regs.R.r0 = info.R[0];
      -            regs.R.r1 = info.R[1];
      -            regs.R.r2 = info.R[2];
      -            regs.R.r3 = info.R[3];
      -            regs.R.r4 = info.R[4];
      -            regs.R.r5 = info.R[5];
      -            regs.R.r6 = info.R[6];
      -            regs.R.r7 = info.R[7];
      -            regs.R.r8 = info.R[8];
      -            regs.R.r9 = info.R[9];
      -            regs.R.r10 = info.R[10];
      -            regs.R.r11 = info.R[11];
      -            regs.R.r12 = info.R[12];
      -            regs.R.sp = info.R[13];
      -            regs.R.lr = info.R[14];
      -            /*
      -             * ASSERT's pc is not important, but who calling it is more important,
      -             * and just setting it to lr as normal assert dump.
      -             */
      -            regs.R.pc = info.R[14];
      -            regs.R.psr = regs.assertPSR;
      -
      -            AssertCatcher_Entry(&regs);
      -        }
      +        AssertCatcher_Entry();
               hal_sys_timer_delay(MS_TO_TICKS(5));
       #endif
       
       #ifdef TRACE_TO_APP
      -        hal_trace_app_notify_callback(HAL_TRACE_STATE_CRASH_END);
      +        if (app_notify_cb) {
      +            app_notify_cb(HAL_TRACE_STATE_CRASH_END);
      +        }
       #endif
           }
       
      @@ -1985,23 +1901,23 @@ static void NORETURN USED hal_trace_assert_dump_internal(ASSERT_DUMP_ARGS)
           hal_trace_crash_end();
       }
       
      -void NORETURN NAKED WEAK hal_trace_assert_dump(ASSERT_DUMP_ARGS)
      +void NORETURN NAKED hal_trace_assert_dump(ASSERT_DUMP_ARGS)
       {
           asm volatile (
      -        "sub sp, sp, #4*(2+" TO_STRING(ASSERT_STACK_RESERVED) ");"
      -        ".cfi_def_cfa_offset 4*(2+" TO_STRING(ASSERT_STACK_RESERVED) ");"
      -        "push {r0-r5};"
      +        "subs sp, sp, #4*" TO_STRING(STACK_DUMP_CNT_PREV) ";"
      +        ".cfi_def_cfa_offset 4*" TO_STRING(STACK_DUMP_CNT_PREV) ";"
      +        "push {r0, r1};"
               "ldr r0, =crash_buf;"
               "ldr r1, [sp];"
      -        "str r1, [r0], #4;"
      -        "ldr r1, [sp, #4];"
      -        "str r1, [r0], #4;"
      +        "str r1, [r0], 4;"
      +        "ldr r1, [sp, 4];"
      +        "str r1, [r0], 4;"
               "stmia r0!, {r2-r12};"
      -        "add r1, sp, #4*(6+2+" TO_STRING(ASSERT_STACK_RESERVED) ");"
      -        "str r1, [r0], #4;"
      -        "str lr, [r0], #4;"
      -        "pop {r0-r5};"
      -        "bl hal_trace_assert_dump_internal;"
      +        "add r1, sp, #4*(2+" TO_STRING(STACK_DUMP_CNT_PREV) ");"
      +        "str r1, [r0], 4;"
      +        "str lr, [r0], 4;"
      +        "pop {r0, r1};"
      +        "b.w hal_trace_assert_dump_internal;"
           );
       }
       
      @@ -2015,12 +1931,12 @@ static void hal_trace_fill_exception_info(struct EXCEPTION_INFO_T *info, const u
           info->extra = extra;
           info->extra_len = extra_len;
       #else
      -    info->MSP = regs[18];
      +    info->MSP = __get_MSP();
           info->PSP = __get_PSP();
      -    info->PRIMASK = (regs[17] & 0xFF);
      -    info->FAULTMASK = ((regs[17] >> 8) & 0xFF);
      -    info->BASEPRI = ((regs[17] >> 16) & 0xFF);
      -    info->CONTROL = ((regs[17] >> 24) & 0xFF);
      +    info->PRIMASK = regs[17];
      +    info->FAULTMASK = __get_FAULTMASK();
      +    info->BASEPRI = __get_BASEPRI();
      +    info->CONTROL = __get_CONTROL();
           info->ICSR = SCB->ICSR;
           info->AIRCR = SCB->AIRCR;
           info->SCR = SCB->SCR;
      @@ -2119,26 +2035,27 @@ static void hal_trace_print_fault_info_cm(const struct EXCEPTION_INFO_T *info)
           const uint32_t *regs;
           int len;
           uint32_t val;
      +    uint32_t primask;
       
           regs = info->REGS;
      +    primask = regs[17];
       
           len = snprintf(crash_buf, sizeof(crash_buf), "PC =%08X", (unsigned)regs[15]);
           val = __get_IPSR();
           if (val == 0) {
      -        len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, ", ThreadMode");
      +        len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, ", ThreadMode" NEW_LINE_STR);
           } else {
      -        len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, ", ExceptionNumber=D'%d", (int)val - 16);
      +        len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, ", ExceptionNumber=%d" NEW_LINE_STR, (int)val - 16);
           }
      -    len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, ", EXC_RETURN=%08X" NEW_LINE_STR, regs[19]);
           hal_trace_output((unsigned char *)crash_buf, len);
       
           hal_trace_print_common_registers(regs);
      -    hal_trace_print_special_stack_registers(info->MSP, info->PSP);
      +    hal_trace_print_special_stack_registers();
       
           hal_trace_output((const unsigned char *)newline, sizeof(newline));
       
           len = snprintf(crash_buf, sizeof(crash_buf), "PRIMASK=%02X, FAULTMASK=%02X, BASEPRI=%02X, CONTROL=%02X" NEW_LINE_STR,
      -        (unsigned)info->PRIMASK, (unsigned)info->FAULTMASK, (unsigned)info->BASEPRI, (unsigned)info->CONTROL);
      +        (unsigned)primask, (unsigned)__get_FAULTMASK(), (unsigned)__get_BASEPRI(), (unsigned)__get_CONTROL());
           hal_trace_output((unsigned char *)crash_buf, len);
           len = snprintf(crash_buf, sizeof(crash_buf), "XPSR=%08X", (unsigned)regs[16]);
           len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, ", APSR=%c%c%c%c%c",
      @@ -2148,8 +2065,8 @@ static void hal_trace_print_fault_info_cm(const struct EXCEPTION_INFO_T *info)
               (regs[16] & (1 << 28)) ? 'V' : 'v',
               (regs[16] & (1 << 27)) ? 'Q' : 'q'
               );
      -    val = regs[16] & 0x1FF;
      -    len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, ", EPSR=%08X, IPSR=%03X", (unsigned)(regs[16] & 0x0700FC00), (unsigned)val);
      +    val = regs[16] & 0xFF;
      +    len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, ", EPSR=%08X, IPSR=%02X", (unsigned)(regs[16] & 0x0700FC00), (unsigned)val);
           if (val == 0) {
               len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, " (NoException)");
           }
      @@ -2167,10 +2084,8 @@ static void hal_trace_print_fault_info_cm(const struct EXCEPTION_INFO_T *info)
               (unsigned)info->SHCSR, (unsigned)info->CFSR, (unsigned)info->HFSR, (unsigned)info->AFSR);
           hal_trace_output((unsigned char *)crash_buf, len);
       
      -    len = snprintf(crash_buf, sizeof(crash_buf), "MMFAR=%08X, BFAR =%08X",
      -        (unsigned)info->MMFAR, (unsigned)info->BFAR);
      +    len = snprintf(crash_buf, sizeof(crash_buf), "MMFAR=%08X, BFAR =%08X" NEW_LINE_STR, (unsigned)info->MMFAR, (unsigned)info->BFAR);
           hal_trace_output((unsigned char *)crash_buf, len);
      -    hal_trace_output((const unsigned char *)newline, sizeof(newline));
       
           if (info->HFSR & (1 << 30)) {
               len = snprintf(crash_buf, sizeof(crash_buf), "(Escalation HardFault)" NEW_LINE_STR);
      @@ -2178,7 +2093,7 @@ static void hal_trace_print_fault_info_cm(const struct EXCEPTION_INFO_T *info)
           }
       
           len = snprintf(crash_buf, sizeof(crash_buf), "FaultInfo :");
      -    if ((info->SHCSR & 0x13F) == 0) {
      +    if ((info->SHCSR & 0x3F) == 0) {
               len += snprintf(&crash_buf[len], sizeof(crash_buf) - len, " (None)");
           } else {
               if (info->SHCSR & (1 << 0)) {
      @@ -2330,8 +2245,20 @@ void hal_trace_fault_dump(const uint32_t *regs, const uint32_t *extra, uint32_t
       
           if (full_dump) {
       #ifdef TRACE_TO_APP
      -        hal_trace_app_notify_callback(HAL_TRACE_STATE_CRASH_FAULT_START);
      +        if (app_notify_cb) {
      +            app_notify_cb(HAL_TRACE_STATE_CRASH_FAULT_START);
      +        }
      +        if (app_crash_custom_cb == NULL) {
      +            app_output_enabled = true;
      +        }
       #endif
      +
      +        crash_dump_onprocess = true;
      +        for (uint8_t i = 0; i < 10; i++) {
      +            REL_TRACE_IMM(0,"                                                                        ");
      +            REL_TRACE_IMM(0,"                                                                        " NEW_LINE_STR);
      +            hal_sys_timer_delay(MS_TO_TICKS(50));
      +        }
           }
       #endif
       
      @@ -2339,7 +2266,7 @@ void hal_trace_fault_dump(const uint32_t *regs, const uint32_t *extra, uint32_t
       
           hal_sysfreq_req(HAL_SYSFREQ_USER_INIT, HAL_CMU_FREQ_52M);
       
      -    len = hal_trace_print_time(TR_LEVEL_CRITICAL, TR_MODULE_NONE, &crash_buf[0], sizeof(crash_buf));
      +    len = hal_trace_print_time(LOG_LEVEL_CRITICAL, LOG_MODULE_NONE, &crash_buf[0], sizeof(crash_buf));
           if (len > 0) {
               hal_trace_output((const unsigned char *)newline, sizeof(newline));
               hal_trace_output((unsigned char *)crash_buf, len);
      @@ -2393,14 +2320,16 @@ void hal_trace_fault_dump(const uint32_t *regs, const uint32_t *extra, uint32_t
                   eregs.r9 = regs[9];
                   eregs.r10 = regs[10];
                   eregs.r11 = regs[11];
      -            eregs.exceptionLR = regs[19];
      +            eregs.exceptionLR = regs[14];
                   CrashCatcher_Entry( &eregs);
               }
       #endif
       #endif // !__ARM_ARCH_ISA_ARM
       
       #ifdef TRACE_TO_APP
      -        hal_trace_app_notify_callback(HAL_TRACE_STATE_CRASH_END);
      +        if (app_notify_cb) {
      +            app_notify_cb(HAL_TRACE_STATE_CRASH_END);
      +        }
       #endif
           }
       
      @@ -2424,14 +2353,13 @@ static void NAKED hal_trace_fault_handler(void)
       {
           // TODO: Save FP registers (and check lazy Floating-point context preservation)
           asm volatile (
      -        // Check EXC_RETURN.MODE (bit[3]) and EXC_RETURN.SPSEL (bit[2])
      -        "and r3, lr, #0x0C;"
      -        "teq r3, #0x0C;"
      +        // Check EXC_RETURN.SPSEL (bit[2])
      +        "tst lr, #0x04;"
               "ite eq;"
               // Using MSP
      -        "mrsne r3, msp;"
      +        "mrseq r3, msp;"
               // Using PSP
      -        "mrseq r3, psp;"
      +        "mrsne r3, psp;"
               // Check EXC_RETURN.FType (bit[4])
               "tst lr, #0x10;"
               "ite eq;"
      @@ -2440,100 +2368,105 @@ static void NAKED hal_trace_fault_handler(void)
               // No FPU context
               "movne r1, #0;"
       #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
      -        // Check EXC_RETURN.S (bit[6])
      +        "mov, r0, #0;"
      +        // -- Check EXC_RETURN.S (bit[6])
               "tst lr, #0x40;"
      -        "bne _get_sec_sp;"
      -        // EXC_RETURN.ES must be 1 here
      -        // Check EXC_RETURN.MODE (bit[3]) and CONTROL.SPSEL (bit[1])
      -        "ubfx r3, lr, #3, #1;"
      -        "mrs r2, control_ns;"
      -        "ubfx r2, r2, #1, #1;"
      -        "ands r3, r2;"
      -        "ite ne;"
      -        // Using PSP_NS
      -        "mrsne r3, psp_ns;"
      -        // Using MSP_NS
      -        "mrseq r3, msp_ns;"
      -        "b _save_msp_lr;"
      -        "_get_sec_sp:;"
      -#endif
      -        // Make room for r0-r15,psr,special_regs(primask/faultmask/basepri/control)
      -        "sub sp, #4*18;"
      -        ".cfi_adjust_cfa_offset 4*18;"
      +        "beq _done_sec_cntx;"
      +        // -- Check EXC_RETURN.ES (bit[0])
      +        "tst lr, #0x01;"
      +        "bne _done_sec_cntx;"
      +        // -- Check EXC_RETURN.DCRS (bit[5])
      +        "tst lr, #0x20;"
      +        "bne _done_sec_cntx;"
      +        "mov, r0, #1;"
      +        "push {r4-r11};"
      +        "add r3, #2*4;"
      +        "ldm r3!, {r4-r11};"
      +        "_done_sec_cntx:;"
      +        "push {r0};"
      +#endif
      +        // Make room for r0-r15,psr,primask
      +        "sub sp, #18*4;"
      +        ".cfi_def_cfa_offset 18*4;"
               // Save r4-r11
               "add r0, sp, #4*4;"
               "stm r0, {r4-r11};"
      -        ".cfi_rel_offset r4, 4*4;"
      -        ".cfi_rel_offset r5, 4*5;"
      -        ".cfi_rel_offset r6, 4*6;"
      -        ".cfi_rel_offset r7, 4*7;"
      -        ".cfi_rel_offset r8, 4*8;"
      -        ".cfi_rel_offset r9, 4*9;"
      -        ".cfi_rel_offset r10, 4*10;"
      -        ".cfi_rel_offset r11, 4*11;"
      +        ".cfi_offset r4, -14*4;"
      +        ".cfi_offset r5, -13*4;"
      +        ".cfi_offset r6, -12*4;"
      +        ".cfi_offset r7, -11*4;"
      +        ".cfi_offset r8, -10*4;"
      +        ".cfi_offset r9, -9*4;"
      +        ".cfi_offset r10, -8*4;"
      +        ".cfi_offset r11, -7*4;"
               // Save r0-r3
               "ldm r3, {r4-r7};"
               "stm sp, {r4-r7};"
      -        ".cfi_rel_offset r0, 4*0;"
      -        ".cfi_rel_offset r1, 4*1;"
      -        ".cfi_rel_offset r2, 4*2;"
      -        ".cfi_rel_offset r3, 4*3;"
      +        ".cfi_offset r0, -18*4;"
      +        ".cfi_offset r1, -17*4;"
      +        ".cfi_offset r2, -16*4;"
      +        ".cfi_offset r3, -15*4;"
               // Save r12
               "ldr r0, [r3, #4*4];"
      -        "str r0, [sp, #4*12];"
      -        ".cfi_rel_offset r12, 4*12;"
      +        "str r0, [sp, #12*4];"
      +        ".cfi_offset r12, -6*4;"
               // Save sp
               "teq r1, 0;"
               "itt eq;"
      -        "addeq r0, r3, #4*8;"
      +        "addeq r0, r3, #8*4;"
               "beq _done_stack_frame;"
      -        "add r0, r3, #4*(8+18);"
      +        "add r0, r3, #(8+18)*4;"
       #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
      -        // -- Check EXC_RETURN.DCRS (bit[5])
      -        "tst lr, #0x20;"
      -        "beq _get_callee_saved_regs;"
      -        // -- Check EXC_RETURN.ES (bit[0])
      -        "tst lr, #0x01;"
      -        "bne _check_fp_cntx;"
      -        "_get_callee_saved_regs:;"
      -        "add r3, #4*2;"
      -        "ldm r3!, {r4-r11};"
      +        // -- Check EXC_RETURN.S (bit[6])
      +        "tst lr, #0x40;"
      +        "beq _done_stack_frame;"
      +        // -- Check FPCCR_S.TS (bit[26])
      +        "ldr r4, =0xE000EF34;"
      +        "ldr r4, [r4];"
      +        "tst r4, #(1 << 26);"
      +        "it ne;"
      +        "addne r3, #16*4;"
       #endif
               "_done_stack_frame:;"
               // -- Check RETPSR.SPREALIGN (bit[9])
      -        "ldr r4, [r3, #4*7];"
      +        "ldr r4, [r3, #7*4];"
               "tst r4, #(1 << 9);"
               "it ne;"
               "addne r0, #4;"
      -        "str r0, [sp, #4*13];"
      +        "str r0, [sp, #13*4];"
               // Save lr
      -        "ldr r0, [r3, #4*5];"
      -        "str r0, [sp, #4*14];"
      +        "ldr r0, [r3, #5*4];"
      +        "str r0, [sp, #14*4];"
               // Save pc
      -        "ldr r0, [r3, #4*6];"
      -        "str r0, [sp, #4*15];"
      +        "ldr r0, [r3, #6*4];"
      +        "str r0, [sp, #15*4];"
               // Save PSR
      -        "ldr r0, [r3, #4*7];"
      -        "str r0, [sp, #4*16];"
      -        // Save special_regs(primask/faultmask/basepri/control)
      -        "str r12, [sp, #4*17];"
      -        "_call_fault_handler:;"
      +        "ldr r0, [r3, #7*4];"
      +        "str r0, [sp, #16*4];"
      +        // Save primask
      +        "mrs r0, primask;"
      +        "str r0, [sp, #17*4];"
      +        // Save current exception lr
      +        "mov r4, lr;"
      +        ".cfi_register lr, r4;"
               // Invoke the fault handler
               "mov r0, sp;"
      -        "mov r1, 0;"
      -        "mov r2, 0;"
      -        "ldr r3, =hal_trace_fault_dump;"
      -        "blx r3;"
      +        "ldr r2, =hal_trace_fault_dump;"
      +        "blx r2;"
      +        // Restore current exception lr
      +        "mov lr, r4;"
               // Restore r4-r7
               "add r0, sp, #4*4;"
               "ldm r0, {r4-r7};"
      +        "mov r0, r3;"
               // Restore sp
               "add sp, #18*4;"
      -        ".cfi_adjust_cfa_offset -4*18;"
      -        "pop {r0, lr};"
      -        ".cfi_adjust_cfa_offset -4*2;"
      -        ".cfi_restore lr;"
      -        ".cfi_def_cfa_offset 0;"
      +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
      +        "pop {r0};"
      +        "cmp r0, #1;"
      +        "it eq;"
      +        "popeq {r4-r11};"
      +#endif
               "bx lr;"
               ""
               );
      @@ -2541,26 +2474,261 @@ static void NAKED hal_trace_fault_handler(void)
       #endif
       #endif
       
      +#define HAL_TRACE_RX_HEAD_SIZE   4
      +#define HAL_TRACE_RX_NAME_SIZE   20
      +#define HAL_TRACE_RX_BUF_SIZE    1024
      +#define HAL_TRACE_RX_ROLE_NUM    6
      +
      +#define HAL_TRACE_RX_HEAD       '['
      +#define HAL_TRACE_RX_END        ']'
      +#define HAL_TRACE_RX_SEPARATOR  ','
      +
      +//static struct HAL_DMA_CH_CFG_T dma_cfg_rx;
       #if (defined(DEBUG) || defined(REL_TRACE_ENABLE))
      -enum HAL_TRACE_RX_STATE_T {
      -    HAL_TRACE_RX_STATE_CLOSED = 0,
      -    HAL_TRACE_RX_STATE_OPENED,
      -    HAL_TRACE_RX_STATE_SLEEP,
      -};
      +static struct HAL_DMA_DESC_T dma_desc_rx;
      +#endif
      +
      +typedef struct{
      +    char *name;
      +    uint32_t len;
      +    uint8_t  *buf;
      +}HAL_TRACE_RX_CFG_T;
      +
      +typedef struct{
      +    char name[HAL_TRACE_RX_NAME_SIZE];
      +    HAL_TRACE_RX_CALLBACK_T callback;
      +}HAL_TRACE_RX_LIST_T;
      +
      +typedef struct{
      +    uint32_t list_num;
      +    HAL_TRACE_RX_LIST_T list[HAL_TRACE_RX_ROLE_NUM];
      +
      +    uint32_t rx_enable;
      +    uint32_t pos;
      +    uint8_t  buf[HAL_TRACE_RX_BUF_SIZE];
      +}HAL_TRACE_RX_T;
       
      -static enum HAL_TRACE_RX_STATE_T trace_rx_state;
      -static uint8_t *trace_rx_buf;
      -static uint32_t trace_rx_len;
      -static HAL_TRACE_RX_CALLBACK_T trace_rx_cb;
      +#if defined(_AUTO_TEST_)
      +extern int auto_test_prase(uint8_t *cmd);
       #endif
       
      +HAL_TRACE_RX_T hal_trace_rx;
      +
      +int hal_trace_rx_dump_list(void)
      +{
      +    for(int i=0;i<HAL_TRACE_RX_ROLE_NUM;i++)
      +    {
      +        TRACE(2,"%d: %s", i, hal_trace_rx.list[i].name);
      +    }
      +    return 0;
      +}
      +
      +int hal_trace_rx_is_in_list(const char *name)
      +{
      +    for(int i=0;i<HAL_TRACE_RX_ROLE_NUM;i++)
      +    {
      +        if(!strcmp(hal_trace_rx.list[i].name, name))
      +        {
      +            return i;
      +        }
      +    }
      +    hal_trace_rx_dump_list();
      +    // TRACE(1,"%s", hal_trace_rx.list[0].name);
      +    // TRACE(1,"%s", name);
      +    // TRACE(1,"%d", strlen(hal_trace_rx.list[0].name));
      +    // TRACE(1,"%d", strlen(name));
      +    // TRACE(1,"%d", strcmp(hal_trace_rx.list[0].name, name));
      +    return -1;
      +}
      +
      +int hal_trace_rx_add_item_to_list(const char *name, HAL_TRACE_RX_CALLBACK_T callback)
      +{
      +    for(int i=0;i<HAL_TRACE_RX_ROLE_NUM;i++)
      +    {
      +        if(hal_trace_rx.list[i].name[0] == 0)
      +        {
      +            memcpy(hal_trace_rx.list[i].name, name, strlen(name));
      +            hal_trace_rx.list[i].callback = callback;
      +            hal_trace_rx.list_num++;
      +            return 0;
      +        }
      +    }
      +
      +    return 1;
      +}
      +
      +int hal_trace_rx_del_item_to_list(int id)
      +{
      +    memset(hal_trace_rx.list[id].name, 0, sizeof(hal_trace_rx.list[id].name));
      +    hal_trace_rx.list[id].callback = NULL;
      +    hal_trace_rx.list_num--;
      +
      +    return 0;
      +}
      +
      +int hal_trace_rx_register(const char *name, HAL_TRACE_RX_CALLBACK_T callback)
      +{
      +    TRACE(2,"[%s] Add %s", __func__, name);
      +    if(hal_trace_rx_is_in_list(name) == -1)
      +    {
      +        hal_trace_rx_add_item_to_list(name, callback);
      +        return 0;
      +    }
      +    else
      +    {
      +        return 0;
      +    }
      +}
      +
      +int hal_trace_rx_deregister(const char *name)
      +{
      +    int id = 0;
      +
      +    id = hal_trace_rx_is_in_list(name);
      +
      +    if(id != -1)
      +    {
      +        hal_trace_rx_del_item_to_list(id);
      +        return 0;
      +    }
      +    else
      +    {
      +        return 1;
      +    }
      +}
      +
      +#if (defined(DEBUG) || defined(REL_TRACE_ENABLE))
      +static int hal_trace_rx_reset(void)
      +{
      +
      +    hal_trace_rx.pos = 0;
      +    memset(hal_trace_rx.buf, 0, HAL_TRACE_RX_BUF_SIZE);
      +
      +    return 0;
      +}
      +#endif
      +// [test,12,102.99]
      +static int hal_trace_rx_parse(int8_t *buf, HAL_TRACE_RX_CFG_T *cfg)
      +{
      +    // TRACE(1,"[%s] Start...", __func__);
      +    int pos = 0;
      +    int len = 0;
      +
      +    for(; pos<HAL_TRACE_RX_HEAD_SIZE; pos++)
      +    {
      +        if(buf[pos] == HAL_TRACE_RX_HEAD)
      +        {
      +            buf[pos] = 0;
      +            break;
      +        }
      +    }
      +
      +    if(pos == HAL_TRACE_RX_HEAD_SIZE)
      +    {
      +        return 3;
      +    }
      +
      +    pos++;
      +
      +    cfg->name = (char *)(buf+pos);
      +    for(; pos<HAL_TRACE_RX_NAME_SIZE+HAL_TRACE_RX_HEAD_SIZE; pos++)
      +    {
      +        if(buf[pos] == HAL_TRACE_RX_SEPARATOR)
      +        {
      +            buf[pos] = 0;
      +            break;
      +        }
      +    }
      +
      +    // TRACE(1,"Step1: %s", cfg->name);
      +    // TRACE(1,"%d", strlen(cfg->name));
      +
      +    if(pos == HAL_TRACE_RX_NAME_SIZE)
      +    {
      +        return 1;
      +    }
      +
      +    pos++;
      +
      +    len = 0;
      +    cfg->buf = (uint8_t*)(buf+pos);
      +    for(; pos<HAL_TRACE_RX_BUF_SIZE; pos++)
      +    {
      +        if(buf[pos] == HAL_TRACE_RX_END)
      +        {
      +            buf[pos] = 0;
      +            break;
      +        }
      +        len++;
      +    }
      +    cfg->len = len;
      +    if(pos == HAL_TRACE_RX_BUF_SIZE)
      +    {
      +        return 2;
      +    }
      +
      +    return 0;
      +}
      +
      +#if defined(IBRT)
      +void app_ibrt_peripheral_automate_test(const char* ibrt_cmd, uint32_t cmd_len);
      +void app_ibrt_peripheral_perform_test(const char* ibrt_cmd);
      +#endif
      +
      +int hal_trace_rx_process(uint8_t *buf, uint32_t len)
      +{
      +    HAL_TRACE_RX_CFG_T cfg;
      +    int id = 0;
      +    int res = 0;
      +
      +#if defined(IBRT)
      +    if(buf && strlen((char*)buf) >= 10 &&((strncmp((char*)buf, "auto_test:", 10) == 0)||(strncmp((char*)buf, "ibrt_test:", 10) == 0)))
      +    {
      +#ifdef BES_AUTOMATE_TEST
      +        app_ibrt_peripheral_automate_test((char*)(buf + 10), len - 10);
      +#else
      +        app_ibrt_peripheral_perform_test((char*)(buf + 10));
      +#endif
      +        return 0;
      +    }
      +#endif
      +
      +    res = hal_trace_rx_parse((int8_t*)buf, &cfg);
      +
      +    if(res)
      +    {
      +        TRACE(1,"ERROR: hal_trace_rx_parse %d", res);
      +        return 1;
      +    }
      +    else
      +    {
      +        // TRACE(1,"%s rx OK", cfg.name);
      +    }
      +
      +    id = hal_trace_rx_is_in_list(cfg.name);
      +
      +    if(id == -1)
      +    {
      +        TRACE(1,"%s is invalid", cfg.name);
      +        return -1;
      +    }
      +
      +    if(hal_trace_rx.list[id].callback)
      +    {
      +        hal_trace_rx.list[id].callback(cfg.buf, cfg.len);
      +    }
      +    else
      +    {
      +        TRACE(1,"%s has not callback", hal_trace_rx.list[id].name);
      +    }
      +
      +    return 0;
      +}
       #if (defined(DEBUG) || defined(REL_TRACE_ENABLE))
      -static void hal_trace_rx_start(void)
      +void hal_trace_rx_start(void)
       {
           uint32_t desc_cnt = 1;
           union HAL_UART_IRQ_T mask;
      -    struct HAL_DMA_DESC_T dma_desc_rx;
      -    int ret;
       
           mask.reg = 0;
           mask.BE = 0;
      @@ -2569,45 +2737,66 @@ static void hal_trace_rx_start(void)
           mask.PE = 0;
           mask.RT = 1;
       
      -    ret = hal_uart_dma_recv_mask(trace_uart, trace_rx_buf, trace_rx_len, &dma_desc_rx, &desc_cnt, &mask);
      -    ASSERT(ret == 0, "%s: Failed to start dma rx: %d", __func__, ret);
      +    hal_uart_dma_recv_mask(trace_uart, hal_trace_rx.buf, HAL_TRACE_RX_BUF_SIZE, &dma_desc_rx, &desc_cnt, &mask);
       }
       
      -static void hal_trace_rx_irq_handler(uint32_t xfer_size, int dma_error, union HAL_UART_IRQ_T status)
      +void hal_trace_rx_irq_handler(uint32_t xfer_size, int dma_error, union HAL_UART_IRQ_T status)
       {
      -    POSSIBLY_UNUSED int res = 0;
      +    int res;
      +    // TRACE(4,"[%s] %d, %d, %d", __func__, xfer_size, dma_error, status);
       
           if (xfer_size)
           {
      -        res = trace_rx_cb(trace_rx_buf, xfer_size);
      -        //TRACE(0, "%s: trace_rx_cb (%p) prase data error: %d", __func__, trace_rx_cb, res);
      -    }
      -    if (xfer_size || status.RT) {
      -        if (trace_rx_state == HAL_TRACE_RX_STATE_OPENED) {
      -            hal_trace_rx_start();
      +        hal_trace_rx.buf[xfer_size] = 0;
      + #if defined(_AUTO_TEST_)
      +        res = auto_test_prase(hal_trace_rx.buf);
      +        if(res)
      +        {
      +            TRACE(2,"%s:auto_test_prase prase data error, err_code = %d", __func__, res);
               }
      + #else
      +        //TRACE(2,"[%s] RX = %s", __func__, hal_trace_rx.buf);
      +        res = hal_trace_rx_process(hal_trace_rx.buf, xfer_size);
      +        if(res)
      +        {
      +            TRACE(2,"%s:hal_trace_rx_process prase data error, err_code = %d",__func__, res);
      +        }
      + #endif
      +        hal_trace_rx_reset();
      +        hal_trace_rx_start();
           }
       }
       
      +uint32_t app_test_callback(unsigned char *buf, uint32_t len)
      +{
      +    TRACE(2,"[%s] len = %d", __func__, len);
       
      +    // Process string
      +    int num_int = 0;
      +    int num_float = 0.0;
      +    TRACE(2,"[%s] %s", __func__, buf);
      +    hal_trace_rx_parser((char*)buf, "%d,%d", &num_int, &num_float);
       
      +    TRACE(3,"[%s] %d:%d", __func__, num_int, num_float);
       
      +    return 0;
      +}
       
      -int hal_trace_rx_open(unsigned char *buf, unsigned int len, HAL_TRACE_RX_CALLBACK_T rx_callback)
      +int hal_trace_rx_open()
       {
      -    trace_rx_buf = buf;
      -    trace_rx_len = len;
      -    trace_rx_cb = rx_callback;
      -
           hal_uart_irq_set_dma_handler(trace_uart, hal_trace_rx_irq_handler, NULL);
      +    hal_trace_rx_start();
       
      -    if (trace_rx_state != HAL_TRACE_RX_STATE_OPENED) {
      -        trace_rx_state = HAL_TRACE_RX_STATE_OPENED;
      -        hal_trace_rx_start();
      -    }
      +    hal_trace_rx_register("test", (HAL_TRACE_RX_CALLBACK_T)app_test_callback);
       
           return 0;
       }
       
      +int hal_trace_rx_reopen()
      +{
      +    hal_uart_reopen(trace_uart, &uart_rx_enable_cfg);
      +    hal_trace_rx_open();
       
      +    return 0;
      +}
       #endif

@OneDeuxTriSeiGo
Copy link
Author

  • platform/hal/hal_trace.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_trace.h bes/platform/hal/hal_trace.h
      index 36edbe14b91..65685b3742e 100644
      --- a/platform/hal/hal_trace.h
      +++ b/platform/hal/hal_trace.h
      @@ -20,6 +20,7 @@ extern "C" {
       #endif
       
       #include "plat_types.h"
      +#include "hal_trace_mod.h"
       
       #if 0
       #define AUDIO_DEBUG
      @@ -40,94 +41,149 @@ extern "C" {
       #endif
       
       #if defined(__BT_DEBUG_TPORTS__) || defined(AUDIO_DEBUG_V0_1_0)
      +#ifndef TPORTS_KEY_COEXIST
      +#ifndef HAL_TRACE_RX_ENABLE
       #define HAL_TRACE_RX_ENABLE
      +#endif
      +#ifndef CRASH_REBOOT
       #define CRASH_REBOOT
       #endif
      +#endif
      +#endif
       
       /*
        * Total number of core registers stored
        */
      -#define CRASH_DUMP_REGISTERS_NUM    17
      -#define CRASH_DUMP_REGISTERS_NUM_BYTES ((CRASH_DUMP_REGISTERS_NUM)*4)
      +#define CRASH_DUMP_REGISTERS_NUM            17
      +#define CRASH_DUMP_REGISTERS_NUM_BYTES      ((CRASH_DUMP_REGISTERS_NUM)*4)
       
       /*
        * Number bytes to store from stack
        *   - this is total, not per PSP/MSP
        */
      -#define CRASH_DUMP_STACK_NUM_BYTES  384
      -
      -enum PRINTF_FLAG_T {
      -    PRINTF_FLAG_LINE_FEED   = (1 << 0),
      -    PRINTF_FLAG_TIME_STAMP  = (1 << 1),
      -    PRINTF_FLAG_CHECK_CRLR  = (1 << 2),
      -};
      +#define CRASH_DUMP_STACK_NUM_BYTES          384
      +
      +// Log Attributes
      +#define LOG_ATTR_ARG_NUM_SHIFT              0
      +#define LOG_ATTR_ARG_NUM_MASK               (0xF << LOG_ATTR_ARG_NUM_SHIFT)
      +#define LOG_ATTR_ARG_NUM(n)                 BITFIELD_VAL(LOG_ATTR_ARG_NUM, n)
      +#define LOG_ATTR_LEVEL_SHIFT                4
      +#define LOG_ATTR_LEVEL_MASK                 (0x7 << LOG_ATTR_LEVEL_SHIFT)
      +#define LOG_ATTR_LEVEL(n)                   BITFIELD_VAL(LOG_ATTR_LEVEL, n)
      +#define LOG_ATTR_MOD_SHIFT                  7
      +#define LOG_ATTR_MOD_MASK                   (0x7F << LOG_ATTR_MOD_SHIFT)
      +#define LOG_ATTR_MOD(n)                     BITFIELD_VAL(LOG_ATTR_MOD, n)
      +#define LOG_ATTR_IMM                        (1 << 14)
      +#define LOG_ATTR_NO_LF                      (1 << 15)
      +#define LOG_ATTR_NO_TS                      (1 << 16)
      +#define LOG_ATTR_NO_ID                      (1 << 17)
      +
      +// Count variadic argument number
      +#define _VAR_ARG_12(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, ...) a12
      +#define COUNT_ARG_NUM(...)                  _VAR_ARG_12(unused, ##__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
       
       #if defined(TRACE_STR_SECTION) && !(defined(ROM_BUILD) || defined(PROGRAMMER) || defined(FPGA))
      -#define CONCAT_(x,y)                x##y
      -#define CONCATS(x,y)                 CONCAT_(x,y)
      -
      -#define __trcname                   CONCATS(__trc, __LINE__)
      -
      -#define TRC_STR_LOC                 __attribute__((section(TO_STRING(CONCATS(.trc_str.,__LINE__)))))
      -#define TRC_STR(s)                  (({ static const char TRC_STR_LOC __trcname[] = (s); __trcname; }))
      +#define CONCAT_(x,y)                        x##y
      +#define CONCATS(x,y)                        CONCAT_(x,y)
      +#define __trcname                           CONCATS(__trc, __LINE__)
      +#define TRC_STR_LOC                         __attribute__((section(TO_STRING(CONCATS(.trc_str,__LINE__)))))
      +#define TRC_STR(s)                          (({ static const char TRC_STR_LOC __trcname[] = (s); __trcname; }))
       #else
       #define TRC_STR_LOC
      -#define TRC_STR(s)                  ((char *)s)
      +#define TRC_STR(s)                          (s)
       #endif
       
      -#define TRACE_DUMMY(str, ...)       hal_trace_dummy(str, ##__VA_ARGS__)
      +#define LOG_DUMMY(attr, str, ...)           hal_trace_dummy(str, ##__VA_ARGS__)
       
       #if (defined(DEBUG) || defined(REL_TRACE_ENABLE)) && !defined(NO_REL_TRACE)
      -#define REL_TRACE(str, ...)         hal_trace_printf(TRC_STR(str), ##__VA_ARGS__)
      -#define REL_TRACE_IMM(str, ...)     hal_trace_printf_imm(str, ##__VA_ARGS__)
      -#define REL_TRACE_NOCRLF(str, ...)  hal_trace_printf_without_crlf(str, ##__VA_ARGS__)
      -#define REL_TRACE_NOTS(str, ...)    hal_trace_printf_without_ts(TRC_STR(str), ##__VA_ARGS__)
      -#define REL_TRACE_IMM_NOTS(str, ...) hal_trace_printf_imm_without_ts(str, ##__VA_ARGS__)
      -#define REL_TRACE_NOCRLF_NOTS(str, ...) hal_trace_printf_without_crlf_ts(str, ##__VA_ARGS__)
      -#define REL_TRACE_OUTPUT(str, len)  hal_trace_output(str, len)
      -#define REL_TRACE_FLUSH()           hal_trace_flush_buffer()
      -#define REL_FUNC_ENTRY_TRACE()      hal_trace_printf(__FUNCTION__)
      -#define REL_DUMP8(str, buf, cnt)    hal_trace_dump(str, sizeof(uint8_t), cnt, buf)
      -#define REL_DUMP16(str, buf, cnt)   hal_trace_dump(str, sizeof(uint16_t), cnt, buf)
      -#define REL_DUMP32(str, buf, cnt)   hal_trace_dump(str, sizeof(uint32_t), cnt, buf)
      +#define REL_LOG(attr, str, ...)             hal_trace_printf(((attr) & ~LOG_ATTR_ARG_NUM_MASK) | \
      +                                                            LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)), \
      +                                                            TRC_STR(str), ##__VA_ARGS__)
      +#define REL_LOG_RAW_OUTPUT(str, len)        hal_trace_output(str, len)
      +#define REL_LOG_FLUSH()                     hal_trace_flush_buffer()
      +#define REL_DUMP8(str, buf, cnt)            hal_trace_dump(str, sizeof(uint8_t), cnt, buf)
      +#define REL_DUMP16(str, buf, cnt)           hal_trace_dump(str, sizeof(uint16_t), cnt, buf)
      +#define REL_DUMP32(str, buf, cnt)           hal_trace_dump(str, sizeof(uint32_t), cnt, buf)
       #else
      -#define REL_TRACE(str, ...)         hal_trace_dummy(str, ##__VA_ARGS__)
      -#define REL_TRACE_IMM(str, ...)     hal_trace_dummy(str, ##__VA_ARGS__)
      -#define REL_TRACE_NOCRLF(str, ...)  hal_trace_dummy(str, ##__VA_ARGS__)
      -#define REL_TRACE_NOTS(str, ...)    hal_trace_dummy(str, ##__VA_ARGS__)
      -#define REL_TRACE_IMM_NOTS(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define REL_TRACE_NOCRLF_NOTS(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define REL_TRACE_OUTPUT(str, len)  hal_trace_dummy((const char *)str, len)
      -#define REL_TRACE_FLUSH()           hal_trace_dummy(NULL)
      -#define REL_FUNC_ENTRY_TRACE()      hal_trace_dummy(NULL)
      -#define REL_DUMP8(str, buf, cnt)    hal_dump_dummy(str, buf, cnt)
      -#define REL_DUMP16(str, buf, cnt)   hal_dump_dummy(str, buf, cnt)
      -#define REL_DUMP32(str, buf, cnt)   hal_dump_dummy(str, buf, cnt)
      +#define REL_LOG(attr, str, ...)             hal_trace_dummy(str, ##__VA_ARGS__)
      +#define REL_LOG_RAW_OUTPUT(str, len)        hal_trace_dummy((const char *)str, len)
      +#define REL_LOG_FLUSH()                     hal_trace_dummy(NULL)
      +#define REL_DUMP8(str, buf, cnt)            hal_dump_dummy(str, buf, cnt)
      +#define REL_DUMP16(str, buf, cnt)           hal_dump_dummy(str, buf, cnt)
      +#define REL_DUMP32(str, buf, cnt)           hal_dump_dummy(str, buf, cnt)
       #endif
       
       #if (!defined(DEBUG) && defined(REL_TRACE_ENABLE)) && !defined(NO_TRACE)
       // To avoid warnings on unused variables
      -#define TRACE(str, ...)             hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_IMM(str, ...)         hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_NOCRLF(str, ...)      hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_OUTPUT(str, len)      hal_trace_dummy((const char *)str, len)
      -#define TRACE_FLUSH()               hal_trace_dummy(NULL)
      -#define FUNC_ENTRY_TRACE()          hal_trace_dummy(NULL)
      -#define DUMP8(str, buf, cnt)        hal_dump_dummy(str, buf, cnt)
      -#define DUMP16(str, buf, cnt)       hal_dump_dummy(str, buf, cnt)
      -#define DUMP32(str, buf, cnt)       hal_dump_dummy(str, buf, cnt)
      +#define NORM_LOG(num,str, ...)              hal_trace_dummy(str, ##__VA_ARGS__)
      +#define NORM_LOG_RAW_OUTPUT(str, len)       hal_trace_dummy((const char *)str, len)
      +#define NORM_LOG_FLUSH()                    hal_trace_dummy(NULL)
      +#define DUMP8(str, buf, cnt)                hal_dump_dummy(str, buf, cnt)
      +#define DUMP16(str, buf, cnt)               hal_dump_dummy(str, buf, cnt)
      +#define DUMP32(str, buf, cnt)               hal_dump_dummy(str, buf, cnt)
       #else
      -#define TRACE                       REL_TRACE
      -#define TRACE_IMM                   REL_TRACE_IMM
      -#define TRACE_NOCRLF                REL_TRACE_NOCRLF
      -#define TRACE_OUTPUT                REL_TRACE_OUTPUT
      -#define TRACE_FLUSH                 REL_TRACE_FLUSH
      -#define FUNC_ENTRY_TRACE            REL_FUNC_ENTRY_TRACE
      -#define DUMP8                       REL_DUMP8
      -#define DUMP16                      REL_DUMP16
      -#define DUMP32                      REL_DUMP32
      +#define NORM_LOG                            REL_LOG
      +#define NORM_LOG_RAW_OUTPUT                 REL_LOG_RAW_OUTPUT
      +#define NORM_LOG_FLUSH                      REL_TRACE_FLUSH
      +#define DUMP8                               REL_DUMP8
      +#define DUMP16                              REL_DUMP16
      +#define DUMP32                              REL_DUMP32
       #endif
       
      +#define RLOG_CRITICAL(attr, str, ...)       REL_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_CRITICAL), \
      +                                                    str, ##__VA_ARGS__)
      +#define RLOG_ERROR(attr, str, ...)          REL_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_ERROR), \
      +                                                    str, ##__VA_ARGS__)
      +#define RLOG_WARN(attr, str, ...)           REL_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_WARN), \
      +                                                    str, ##__VA_ARGS__)
      +#define RLOG_NOTIF(attr, str, ...)          REL_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_NOTIF), \
      +                                                    str, ##__VA_ARGS__)
      +#define RLOG_INFO(attr, str, ...)           REL_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_INFO), \
      +                                                    str, ##__VA_ARGS__)
      +#define RLOG_DEBUG(attr, str, ...)          REL_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_DEBUG), \
      +                                                    str, ##__VA_ARGS__)
      +#define RLOG_VERBOSE(attr, str, ...)        REL_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_VERBOSE), \
      +                                                    str, ##__VA_ARGS__)
      +
      +#define LOG_CRITICAL(attr, str, ...)        NORM_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_CRITICAL), \
      +                                                    str, ##__VA_ARGS__)
      +#define LOG_ERROR(attr, str, ...)           NORM_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_ERROR), \
      +                                                    str, ##__VA_ARGS__)
      +#define LOG_WARN(attr, str, ...)            NORM_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_WARN), \
      +                                                    str, ##__VA_ARGS__)
      +#define LOG_NOTIF(attr, str, ...)           NORM_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_NOTIF), \
      +                                                    str, ##__VA_ARGS__)
      +#define LOG_INFO(attr, str, ...)            NORM_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_INFO), \
      +                                                    str, ##__VA_ARGS__)
      +#define LOG_DEBUG(attr, str, ...)           NORM_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_DEBUG), \
      +                                                    str, ##__VA_ARGS__)
      +#define LOG_VERBOSE(attr, str, ...)         NORM_LOG(((attr) & ~LOG_ATTR_LEVEL_MASK) | LOG_ATTR_LEVEL(LOG_LEVEL_VERBOSE), \
      +                                                    str, ##__VA_ARGS__)
      +
      +#define REL_TRACE(attr, str, ...)           RLOG_NOTIF(attr, str, ##__VA_ARGS__)
      +#define REL_TRACE_IMM(attr, str, ...)       RLOG_NOTIF((attr) | LOG_ATTR_IMM, str, ##__VA_ARGS__)
      +#define REL_TRACE_NOCRLF(attr, str, ...)    RLOG_NOTIF((attr) | LOG_ATTR_NO_LF, str, ##__VA_ARGS__)
      +#define REL_TRACE_NOTS(attr, str, ...)      RLOG_NOTIF((attr) | LOG_ATTR_NO_TS, str, ##__VA_ARGS__)
      +#define REL_TRACE_IMM_NOTS(attr, str, ...)  RLOG_NOTIF((attr) | LOG_ATTR_IMM | LOG_ATTR_NO_TS, str, ##__VA_ARGS__)
      +#define REL_TRACE_NOCRLF_NOTS(attr, str, ...) RLOG_NOTIF((attr) | LOG_ATTR_NO_LF | LOG_ATTR_NO_TS, str, ##__VA_ARGS__)
      +#define REL_FUNC_ENTRY_TRACE()              RLOG_NOTIF(1, "%s", __FUNCTION__)
      +#define REL_TRACE_OUTPUT(str, len)          REL_LOG_RAW_OUTPUT(str, len)
      +#define REL_TRACE_FLUSH()                   REL_LOG_FLUSH()
      +
      +#define TRACE(attr, str, ...)               LOG_INFO(attr, str, ##__VA_ARGS__)
      +#define TRACE_IMM(attr, str, ...)           LOG_INFO((attr) | LOG_ATTR_IMM, str, ##__VA_ARGS__)
      +#define TRACE_NOCRLF(attr, str, ...)        LOG_INFO((attr) | LOG_ATTR_NO_LF, str, ##__VA_ARGS__)
      +#define FUNC_ENTRY_TRACE()                  LOG_INFO(1, "%s", __FUNCTION__)
      +#define TRACE_OUTPUT(str, len)              NORM_LOG_RAW_OUTPUT(str, len)
      +#define TRACE_FLUSH()                       NORM_LOG_FLUSH()
      +#ifdef BES_AUTOMATE_TEST
      +#define AUTO_TEST_TRACE(attr, str, ...)     LOG_INFO(attr, "_AT_"str, ##__VA_ARGS__)
      +#else
      +#define AUTO_TEST_TRACE(attr, str, ...)     LOG_INFO(attr, str, ##__VA_ARGS__)
      +#endif
      +
      +#define TRACE_DUMMY(attr, str, ...)         LOG_DUMMY(attr, str, ##__VA_ARGS__)
      +
       #if (defined(DEBUG) || defined(REL_TRACE_ENABLE)) && defined(ASSERT_SHOW_FILE_FUNC)
       #define ASSERT(cond, str, ...)      { if (!(cond)) { hal_trace_assert_dump(__FILE__, __FUNCTION__, __LINE__, str, ##__VA_ARGS__); } }
       #define ASSERT_DUMP_ARGS            const char *file, const char *func, unsigned int line, const char *fmt, ...
      @@ -210,59 +266,17 @@ enum HAL_TRACE_CRASH_DUMP_MODULE_T {
           HAL_TRACE_CRASH_DUMP_MODULE_END = 5,
       };
       
      -enum HAL_TRACE_MODUAL {
      -    HAL_TRACE_LEVEL_0  = 1<<0,
      -    HAL_TRACE_LEVEL_1  = 1<<1,
      -    HAL_TRACE_LEVEL_2  = 1<<2,
      -    HAL_TRACE_LEVEL_3  = 1<<3,
      -    HAL_TRACE_LEVEL_4  = 1<<4,
      -    HAL_TRACE_LEVEL_5  = 1<<5,
      -    HAL_TRACE_LEVEL_6  = 1<<6,
      -    HAL_TRACE_LEVEL_7  = 1<<7,
      -    HAL_TRACE_LEVEL_8  = 1<<8,
      -    HAL_TRACE_LEVEL_9  = 1<<9,
      -    HAL_TRACE_LEVEL_10 = 1<<10,
      -    HAL_TRACE_LEVEL_11 = 1<<11,
      -    HAL_TRACE_LEVEL_12 = 1<<12,
      -    HAL_TRACE_LEVEL_13 = 1<<13,
      -    HAL_TRACE_LEVEL_14 = 1<<14,
      -    HAL_TRACE_LEVEL_15 = 1<<15,
      -    HAL_TRACE_LEVEL_16 = 1<<16,
      -    HAL_TRACE_LEVEL_17 = 1<<17,
      -    HAL_TRACE_LEVEL_18 = 1<<18,
      -    HAL_TRACE_LEVEL_19 = 1<<19,
      -    HAL_TRACE_LEVEL_20 = 1<<20,
      -    HAL_TRACE_LEVEL_21 = 1<<21,
      -    HAL_TRACE_LEVEL_22 = 1<<22,
      -    HAL_TRACE_LEVEL_23 = 1<<23,
      -    HAL_TRACE_LEVEL_24 = 1<<24,
      -    HAL_TRACE_LEVEL_25 = 1<<25,
      -    HAL_TRACE_LEVEL_26 = 1<<26,
      -    HAL_TRACE_LEVEL_27 = 1<<27,
      -    HAL_TRACE_LEVEL_28 = 1<<28,
      -    HAL_TRACE_LEVEL_29 = 1<<29,
      -    HAL_TRACE_LEVEL_30 = 1<<30,
      -    HAL_TRACE_LEVEL_31 = 1<<31,
      -    HAL_TRACE_LEVEL_ALL = 0XFFFFFFFF,
      -};
      +enum LOG_LEVEL_T {
      +    LOG_LEVEL_CRITICAL  = 0,
      +    LOG_LEVEL_ERROR     = 1,
      +    LOG_LEVEL_WARN      = 2,
      +    LOG_LEVEL_NOTIF     = 3,
      +    LOG_LEVEL_INFO      = 4,
      +    LOG_LEVEL_DEBUG     = 5,
      +    LOG_LEVEL_VERBOSE   = 6,
       
      -typedef enum {
      -    LOG_LV_NONE,
      -    LOG_LV_FATAL,
      -    LOG_LV_ERROR,
      -    LOG_LV_WARN,
      -    LOG_LV_INFO,
      -    LOG_LV_DEBUG,
      -} LOG_LEVEL_T;
      -
      -typedef enum {
      -    LOG_MOD_NONE,
      -    LOG_MOD_OS,
      -    LOG_MOD_BT_STACK,
      -    LOG_MOD_SYS,
      -    LOG_MOD_MEDIA,
      -    LOG_MOD_APP,
      -} LOG_MODULE_T;
      +    LOG_LEVEL_QTY,
      +};
       
       typedef void (*HAL_TRACE_CRASH_DUMP_CB_T)(void);
       
      @@ -272,54 +286,30 @@ typedef void (*HAL_TRACE_APP_OUTPUT_T)(const unsigned char *buf, unsigned int bu
       
       typedef void (*HAL_TRACE_BUF_CTRL_T)(enum HAL_TRACE_BUF_STATE_T buf_ctrl);
       
      -#include "stdarg.h"
      -typedef int (*HAL_TRACE_PRINTF_HOOK_T)(const char *tag, const char *fmt, enum PRINTF_FLAG_T flag, va_list ap);
      -
       int hal_trace_open(enum HAL_TRACE_TRANSPORT_T transport);
       
      -void hal_trace_register_hook(HAL_TRACE_PRINTF_HOOK_T hook);
      -
      -void hal_trace_unregister_hook(HAL_TRACE_PRINTF_HOOK_T hook);
      -
       int hal_trace_open_cp(void);
       
       TRACE_FUNC_DECLARE(int hal_trace_switch(enum HAL_TRACE_TRANSPORT_T transport), return 0);
       
       TRACE_FUNC_DECLARE(int hal_trace_close(void), return 0);
       
      -TRACE_FUNC_DECLARE(void hal_trace_get_history_buffer(const unsigned char **buf1, unsigned int *len1, \
      -    const unsigned char **buf2, unsigned int *len2), \
      -    { if (buf1) { *buf1 = NULL; } if (len1) { *len1 = 0; } if (buf2) { *buf2 = NULL; } if (len2) { *len2 = 0; } });
      +TRACE_FUNC_DECLARE(int hal_trace_enable_log_module(enum LOG_MODULE_T module), return 0);
       
      -TRACE_FUNC_DECLARE(int hal_trace_output(const unsigned char *buf, unsigned int buf_len), return 0);
      +TRACE_FUNC_DECLARE(int hal_trace_disable_log_module(enum LOG_MODULE_T module), return 0);
       
      -TRC_FMT_CHK(2, 3)
      -TRACE_FUNC_DECLARE(int hal_trace_printf_with_lvl(unsigned int lvl, const char *fmt, ...), return 0);
      +TRACE_FUNC_DECLARE(int hal_trace_set_log_module(const uint32_t *map, uint32_t word_cnt), return 0);
       
      -TRC_FMT_CHK(1, 2)
      -TRACE_FUNC_DECLARE(int hal_trace_printf(const char *fmt, ...), return 0);
      -
      -TRC_FMT_CHK(1, 2)
      -TRACE_FUNC_DECLARE(int hal_trace_printf_without_ts(const char *fmt, ...), return 0);
      -
      -TRC_FMT_CHK(1, 2)
      -TRACE_FUNC_DECLARE(void hal_trace_printf_imm(const char *fmt, ...), return);
      +TRACE_FUNC_DECLARE(int hal_trace_set_log_level(enum LOG_LEVEL_T level), return 0);
       
      -TRC_FMT_CHK(1, 2)
      -TRACE_FUNC_DECLARE(void hal_trace_printf_imm_without_ts(const char *fmt, ...), return);
      +TRACE_FUNC_DECLARE(void hal_trace_get_history_buffer(const unsigned char **buf1, unsigned int *len1, \
      +    const unsigned char **buf2, unsigned int *len2), \
      +    { if (buf1) { *buf1 = NULL; } if (len1) { *len1 = 0; } if (buf2) { *buf2 = NULL; } if (len2) { *len2 = 0; } });
       
      -TRC_FMT_CHK(1, 2)
      -TRACE_FUNC_DECLARE(int hal_trace_printf_without_crlf(const char *fmt, ...), return 0);
      -TRACE_FUNC_DECLARE(int hal_trace_printf_no_ts(const char *fmt, ...), return 0);
      -TRC_FMT_CHK(1, 2)
      -TRACE_FUNC_DECLARE(int hal_trace_printf_without_crlf_ts(const char *fmt, ...), return 0);
      -TRACE_FUNC_DECLARE(int hal_trace_printf_without_crlf_cmd(const char *fmt, ...), return 0);
      -TRACE_FUNC_DECLARE(int hal_trace_printf_no_ts_cmd(const char *fmt, ...), return 0);
      +TRACE_FUNC_DECLARE(int hal_trace_output(const unsigned char *buf, unsigned int buf_len), return 0);
       
       TRC_FMT_CHK(2, 3)
      -TRACE_FUNC_DECLARE(int hal_trace_printf_with_tag(const char *tag, const char *fmt, ...), return 0);
      -
      -TRACE_FUNC_DECLARE(int hal_trace_printf_without_crlf_fix_arg(const char *fmt), return 0);
      +TRACE_FUNC_DECLARE(int hal_trace_printf(uint32_t attr, const char *fmt, ...), return 0);
       
       TRACE_FUNC_DECLARE(int hal_trace_dump(const char *fmt, unsigned int size,  unsigned int count, const void *buffer), return 0);
       
      @@ -343,8 +333,6 @@ TRACE_FUNC_DECLARE(void hal_trace_cp_register(HAL_TRACE_APP_NOTIFY_T notify_cb,
       
       TRACE_FUNC_DECLARE(void hal_trace_print_backtrace(uint32_t addr, uint32_t search_cnt, uint32_t print_cnt), return);
       
      -TRACE_FUNC_DECLARE(void hal_trace_print_a7(const unsigned char *buf, unsigned int buf_len), return);
      -
       TRACE_FUNC_DECLARE(bool hal_trace_crash_dump_onprocess(void), return false);
       
       TRACE_FUNC_DECLARE(uint32_t hal_trace_get_baudrate(void), return 0);
      @@ -365,9 +353,6 @@ int hal_trace_address_executable(uint32_t addr);
       
       int hal_trace_address_readable(uint32_t addr);
       
      -int32_t cli_printf(const char *buffer, ...);
      -
      -int hal_trace_output_block(const unsigned char *buf, unsigned int len);
       
       //==============================================================================
       // AUDIO_DEBUG
      @@ -377,7 +362,7 @@ int hal_trace_output_block(const unsigned char *buf, unsigned int len);
       #define AUDIO_DEBUG_TRACE(str, ...)         hal_trace_printf(str, ##__VA_ARGS__)
       #define AUDIO_DEBUG_DUMP(buf, cnt)          hal_trace_output(buf, cnt)
       #endif
      -#define print_addr(k) TRACE("***addr:%02x:%02x:%02x:%02x:%02x:%02x\n", (k)[0],(k)[1],(k)[2],(k)[3],(k)[4],(k)[5])
      +
       
       //==============================================================================
       // INTERSYS_RAW_DATA_ONLY
      @@ -394,13 +379,13 @@ int hal_trace_output_block(const unsigned char *buf, unsigned int len);
       //==============================================================================
       
       #if defined(_AUTO_TEST_)
      +#ifndef HAL_TRACE_RX_ENABLE
       #define HAL_TRACE_RX_ENABLE
      +#endif
       extern int auto_test_send(char *resp);
       #define AUTO_TEST_SEND(str)         auto_test_send((char*)str)
       #endif
       
      -#ifdef HAL_TRACE_RX_ENABLE
      -
       #include "stdio.h"
       
       #define hal_trace_rx_parser(buf, str, ...)  sscanf(buf, str, ##__VA_ARGS__)
      @@ -409,16 +394,9 @@ typedef unsigned int (*HAL_TRACE_RX_CALLBACK_T)(unsigned char *buf, unsigned int
       
       int hal_trace_rx_register(const char *name, HAL_TRACE_RX_CALLBACK_T callback);
       int hal_trace_rx_deregister(const char *name);
      +int hal_trace_rx_reopen();
      +int hal_trace_rx_open();
       
      -#endif
      -
      -#define printf                         hal_trace_printf_without_crlf
      -#define printf_no_ts                   hal_trace_printf_no_ts
      -#define cmd_printf                     hal_trace_printf_without_crlf_cmd
      -#define cmd_printf_no_ts               hal_trace_printf_no_ts_cmd
      -#define printf_raw                     hal_trace_printf_without_crlf_ts
      -#define print_addr(k) TRACE("***addr:%02x:%02x:%02x:%02x:%02x:%02x\n", (k)[0],(k)[1],(k)[2],(k)[3],(k)[4],(k)[5])
      -#define uart_printf(...)                //hal_trace_printf(__VA_ARGS__)
       
       #ifdef __cplusplus
       }
  • platform/hal/hal_trace_mod.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_trace_mod.c bes/platform/hal/hal_trace_mod.c
      index efe03852927..55c4be6d017 100644
      --- a/platform/hal/hal_trace_mod.c
      +++ b/platform/hal/hal_trace_mod.c
      @@ -15,14 +15,14 @@
       #include "hal_trace_mod.h"
       #include "plat_types.h"
       
      -#undef _TR_MODULE_DEF_A
      -#define _TR_MODULE_DEF_A(p, m)              # m
      +#undef _LOG_MODULE_DEF_A
      +#define _LOG_MODULE_DEF_A(p, m)             # m
       
       static const char * mod_desc[] = {
      -    _TR_MODULE_LIST
      +    _LOG_MODULE_LIST
       };
       
      -const char *hal_trace_get_log_module_desc(enum TR_MODULE_T module)
      +const char *hal_trace_get_log_module_desc(enum LOG_MODULE_T module)
       {
           if (module < ARRAY_SIZE(mod_desc)) {
               return mod_desc[module];
  • platform/hal/hal_trace_mod.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_trace_mod.h bes/platform/hal/hal_trace_mod.h
      index f7cecb2fda2..86afa241155 100644
      --- a/platform/hal/hal_trace_mod.h
      +++ b/platform/hal/hal_trace_mod.h
      @@ -19,57 +19,49 @@
       extern "C" {
       #endif
       
      -#define TR_MOD(m)                           TR_ATTR_MOD(TR_MODULE_ ## m)
      +#define LOG_MOD(m)                          LOG_ATTR_MOD(LOG_MODULE_ ## m)
       
      -#define _TR_MODULE_DEF_A(p, m)              p ## m
      -#define _TR_MODULE_DEF(m)                   _TR_MODULE_DEF_A(TR_MODULE_, m)
      +#define _LOG_MODULE_DEF_A(p, m)             p ## m
      +#define _LOG_MODULE_DEF(m)                  _LOG_MODULE_DEF_A(LOG_MODULE_, m)
       
      -#define _TR_MODULE_LIST                     \
      -    _TR_MODULE_DEF(NONE),                   \
      -    _TR_MODULE_DEF(HAL),                    \
      -    _TR_MODULE_DEF(DRVANA),                 \
      -    _TR_MODULE_DEF(DRVCODEC),               \
      -    _TR_MODULE_DEF(DRVBT),                  \
      -    _TR_MODULE_DEF(DRVFLS),                 \
      -    _TR_MODULE_DEF(DRVSEC),                 \
      -    _TR_MODULE_DEF(DRVUSB),                 \
      -    _TR_MODULE_DEF(AUDFLG),                 \
      -    _TR_MODULE_DEF(MAIN),                   \
      -    _TR_MODULE_DEF(RT_OS),                  \
      -    _TR_MODULE_DEF(BTPRF),                  \
      -    _TR_MODULE_DEF(BLEPRF),                 \
      -    _TR_MODULE_DEF(BTAPP),                  \
      -    _TR_MODULE_DEF(BLEAPP),                 \
      -    _TR_MODULE_DEF(TWSAPP),                 \
      -    _TR_MODULE_DEF(IBRTAPP),                \
      -    _TR_MODULE_DEF(APPMAIN),                \
      -    _TR_MODULE_DEF(APPTHREAD),              \
      -    _TR_MODULE_DEF(PLAYER),                 \
      -    _TR_MODULE_DEF(TEST),                   \
      -    _TR_MODULE_DEF(AUD),                    \
      -    _TR_MODULE_DEF(OTA),                    \
      -    _TR_MODULE_DEF(NV_SEC),                 \
      -    _TR_MODULE_DEF(AI_GVA),                 \
      -    _TR_MODULE_DEF(AI_VOC),                 \
      -    _TR_MODULE_DEF(AI_AMA),                 \
      -    _TR_MODULE_DEF(AI_GMA),                 \
      -    _TR_MODULE_DEF(AI_BIXBY),               \
      -    _TR_MODULE_DEF(AOB_SM),                 \
      -    _TR_MODULE_DEF(SPEECH),                 \
      -    _TR_MODULE_DEF(WIFI),                   \
      -    _TR_MODULE_DEF(NET),                    \
      -    _TR_MODULE_DEF(VOICE_COMPRESS),         \
      -    _TR_MODULE_DEF(BT_ADAPTOR),             \
      +#define _LOG_MODULE_LIST                    \
      +    _LOG_MODULE_DEF(NONE),                  \
      +    _LOG_MODULE_DEF(HAL),                   \
      +    _LOG_MODULE_DEF(DRVANA),                \
      +    _LOG_MODULE_DEF(DRVCODEC),              \
      +    _LOG_MODULE_DEF(DRVBT),                 \
      +    _LOG_MODULE_DEF(DRVFLS),                \
      +    _LOG_MODULE_DEF(DRVSEC),                \
      +    _LOG_MODULE_DEF(DRVUSB),                \
      +    _LOG_MODULE_DEF(AUDFLG),                \
      +    _LOG_MODULE_DEF(MAIN),                  \
      +    _LOG_MODULE_DEF(RT_OS),                 \
      +    _LOG_MODULE_DEF(BTPRF),                 \
      +    _LOG_MODULE_DEF(BLEPRF),                \
      +    _LOG_MODULE_DEF(BTAPP),                 \
      +    _LOG_MODULE_DEF(BLEAPP),                \
      +    _LOG_MODULE_DEF(TWSAPP),                \
      +    _LOG_MODULE_DEF(IBRTAPP),               \
      +    _LOG_MODULE_DEF(APPMAIN),               \
      +    _LOG_MODULE_DEF(APPTHREAD),             \
      +    _LOG_MODULE_DEF(PLAYER),                \
      +    _LOG_MODULE_DEF(TEST),                  \
      +    _LOG_MODULE_DEF(AUD),                   \
      +    _LOG_MODULE_DEF(OTA),                   \
      +    _LOG_MODULE_DEF(NV_SEC),                \
      +    _LOG_MODULE_DEF(AI_GVA),                \
      +    _LOG_MODULE_DEF(AI_AMA),                \
      +    _LOG_MODULE_DEF(AI_GMA),                \
       
       
      -enum TR_MODULE_T {
      -    _TR_MODULE_LIST
      +enum LOG_MODULE_T {
      +    _LOG_MODULE_LIST
       
           // Should <= 128
      -    TR_MODULE_QTY,
      +    LOG_MODULE_QTY,
       };
       
      -const char *hal_trace_get_log_module_desc(enum TR_MODULE_T module);
      +const char *hal_trace_get_log_module_desc(enum LOG_MODULE_T module);
       
       #ifdef __cplusplus
       }
  • platform/hal/hal_uart.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_uart.c bes/platform/hal/hal_uart.c
      index 94984ad6e73..2868d3985e9 100644
      --- a/platform/hal/hal_uart.c
      +++ b/platform/hal/hal_uart.c
      @@ -53,7 +53,7 @@ static const struct HAL_UART_HW_DESC_T uart[HAL_UART_ID_QTY] = {
               .rx_periph = HAL_GPDMA_UART0_RX,
               .tx_periph = HAL_GPDMA_UART0_TX,
           },
      -#if (CHIP_HAS_UART >= 2)
      +#if (CHIP_HAS_UART > 1)
           {
               .base = (struct UART_T *)UART1_BASE,
               .irq = UART1_IRQn,
      @@ -63,7 +63,7 @@ static const struct HAL_UART_HW_DESC_T uart[HAL_UART_ID_QTY] = {
               .tx_periph = HAL_GPDMA_UART1_TX,
           },
       #endif
      -#if (CHIP_HAS_UART >= 3)
      +#if (CHIP_HAS_UART > 2)
           {
               .base = (struct UART_T *)UART2_BASE,
               .irq = UART2_IRQn,
      @@ -125,23 +125,22 @@ static void set_baud_rate(enum HAL_UART_ID_T id, uint32_t rate)
           uint32_t mod_clk;
           uint32_t ibrd, fbrd;
           uint32_t div;
      -    uint32_t over_sample_ratio = 16;
       
           mod_clk = 0;
       #ifdef PERIPH_PLL_FREQ
           if (PERIPH_PLL_FREQ / 2 > 2 * hal_cmu_get_crystal_freq()) {
               // Init to OSC_X2
      -        mod_clk = 2 * hal_cmu_get_crystal_freq() / over_sample_ratio;
      -        if (rate > mod_clk) {
      -            mod_clk = PERIPH_PLL_FREQ / 2 / over_sample_ratio;
      +        mod_clk = 2 * hal_cmu_get_crystal_freq() / 16;
      +        if (cfg->baud > mod_clk) {
      +            mod_clk = PERIPH_PLL_FREQ / 2 / 16;
       
                   if (id == HAL_UART_ID_0) {
                       hal_cmu_uart0_set_div(2);
      -#if (CHIP_HAS_UART >= 2)
      +#if (CHIP_HAS_UART > 1)
                   } else if (id == HAL_UART_ID_1) {
                       hal_cmu_uart1_set_div(2);
       #endif
      -#if (CHIP_HAS_UART >= 3)
      +#if (CHIP_HAS_UART > 2)
                   } else if (id == HAL_UART_ID_2) {
                       hal_cmu_uart2_set_div(2);
       #endif
      @@ -155,7 +154,7 @@ static void set_baud_rate(enum HAL_UART_ID_T id, uint32_t rate)
               enum HAL_CMU_PERIPH_FREQ_T periph_freq;
       
               // Init to OSC
      -        mod_clk = hal_cmu_get_crystal_freq() / over_sample_ratio;
      +        mod_clk = hal_cmu_get_crystal_freq() / 16;
               if (rate > mod_clk) {
                   mod_clk *= 2;
                   periph_freq = HAL_CMU_PERIPH_FREQ_52M;
      @@ -165,11 +164,11 @@ static void set_baud_rate(enum HAL_UART_ID_T id, uint32_t rate)
       
               if (id == HAL_UART_ID_0) {
                   hal_cmu_uart0_set_freq(periph_freq);
      -#if (CHIP_HAS_UART >= 2)
      +#if (CHIP_HAS_UART > 1)
               } else if (id == HAL_UART_ID_1) {
                   hal_cmu_uart1_set_freq(periph_freq);
       #endif
      -#if (CHIP_HAS_UART >= 3)
      +#if (CHIP_HAS_UART > 2)
               } else if (id == HAL_UART_ID_2) {
                   hal_cmu_uart2_set_freq(periph_freq);
       #endif
      @@ -217,8 +216,7 @@ int hal_uart_open(enum HAL_UART_ID_T id, const struct HAL_UART_CFG_T *cfg)
           hal_cmu_reset_clear(uart[id].mod);
           hal_cmu_reset_clear(uart[id].apb);
       
      -    cr = 0;
      -    lcr = 0;
      +    cr = lcr = 0;
       
           switch (cfg->parity) {
               case HAL_UART_PARITY_NONE:
      @@ -464,7 +462,7 @@ int hal_uart_change_baud_rate(enum HAL_UART_ID_T id, uint32_t rate)
           return 0;
       }
       
      -int hal_uart_pause(enum HAL_UART_ID_T id, enum HAL_UART_XFER_TYPE_T type)
      +int hal_uart_pause(enum HAL_UART_ID_T id)
       {
           ASSERT(id < HAL_UART_ID_QTY, err_invalid_id, id);
           if (hal_uart_opened(id)) {
      @@ -474,7 +472,7 @@ int hal_uart_pause(enum HAL_UART_ID_T id, enum HAL_UART_XFER_TYPE_T type)
           return 1;
       }
       
      -int hal_uart_continue(enum HAL_UART_ID_T id, enum HAL_UART_XFER_TYPE_T type)
      +int hal_uart_continue(enum HAL_UART_ID_T id)
       {
           ASSERT(id < HAL_UART_ID_QTY, err_invalid_id, id);
           if (hal_uart_opened(id)) {
      @@ -611,10 +609,10 @@ union HAL_UART_IRQ_T hal_uart_irq_set_mask(enum HAL_UART_ID_T id, union HAL_UART
           union HAL_UART_IRQ_T old_mask;
       
           ASSERT(id < HAL_UART_ID_QTY, err_invalid_id, id);
      -    old_mask.reg = uart[id].base->UARTIMSC;
      -    if (old_mask.RT == 0 && mask.RT) {
      +    if (mask.RT) {
               ASSERT(recv_dma_chan[id] == HAL_DMA_CHAN_NONE, err_recv_dma_api, __FUNCTION__);
           }
      +    old_mask.reg = uart[id].base->UARTIMSC;
           uart[id].base->UARTIMSC = mask.reg;
       
           return old_mask;
      @@ -634,9 +632,14 @@ HAL_UART_IRQ_HANDLER_T hal_uart_irq_set_handler(enum HAL_UART_ID_T id, HAL_UART_
       static void dma_mode_uart_irq_handler(enum HAL_UART_ID_T id, union HAL_UART_IRQ_T status)
       {
           uint32_t xfer = 0;
      +    uint32_t lock;
       
           if (status.RT || status.FE || status.OE || status.PE || status.BE) {
               if (recv_dma_mode[id] == UART_RX_DMA_MODE_NORMAL) {
      +            // Restore the traditional RT behaviour
      +            lock = int_lock();
      +            uart[id].base->UARTLCR_H &= ~UARTLCR_H_DMA_RT_EN;
      +            int_unlock(lock);
               }
       
               if (rxdma_handler[id]) {
      @@ -692,6 +695,7 @@ static void recv_dma_irq_handler(uint8_t chan, uint32_t remain_tsize, uint32_t e
               hal_gpdma_free_chan(chan);
           } else {
               xfer = 0;
      +        status.reg = 0;
           }
       
           if (rxdma_handler[id]) {
      @@ -705,7 +709,6 @@ static void recv_dma_irq_handler(uint8_t chan, uint32_t remain_tsize, uint32_t e
               } else if (recv_dma_mode[id] == UART_RX_DMA_MODE_PINGPANG) {
                   xfer = recv_dma_size[id] / 2;
               }
      -        status.reg = 0;
               rxdma_handler[id](xfer, error, status);
           }
       }
      @@ -830,7 +833,6 @@ static int start_recv_dma_with_mask(enum HAL_UART_ID_T id, const struct HAL_UART
           uint32_t cnt;
           uint32_t i;
           enum HAL_DMA_PERIPH_T periph;
      -    enum HAL_DMA_BSIZE_T src_bsize = HAL_DMA_BSIZE_8;
       
           ASSERT(id < HAL_UART_ID_QTY, err_invalid_id, id);
           ASSERT(uart[id].irq != INVALID_IRQn, "DMA not supported on UART %d", id);
      @@ -908,21 +910,32 @@ static int start_recv_dma_with_mask(enum HAL_UART_ID_T id, const struct HAL_UART
               *desc_cnt = (cnt == 1) ? 0 : cnt;
           }
       
      +    periph = uart[id].rx_periph;
      +
      +    lock = int_lock();
           if (recv_dma_chan[id] != HAL_DMA_CHAN_NONE) {
      +        int_unlock(lock);
               return 1;
           }
      +    recv_dma_chan[id] = hal_gpdma_get_chan(periph, HAL_DMA_HIGH_PRIO);
      +    if (recv_dma_chan[id] == HAL_DMA_CHAN_NONE) {
      +        int_unlock(lock);
      +        return 2;
      +    }
      +    int_unlock(lock);
       
      -    periph = uart[id].rx_periph;
      -
      +    recv_dma_mode[id] = mode;
      +    recv_dma_size[id] = len;
       
           memset(&dma_cfg, 0, sizeof(dma_cfg));
      +    dma_cfg.ch = recv_dma_chan[id];
           dma_cfg.dst = (uint32_t)buf;
           dma_cfg.dst_bsize = HAL_DMA_BSIZE_32;
           dma_cfg.dst_periph = 0; // useless
           dma_cfg.dst_width = HAL_DMA_WIDTH_BYTE;
           dma_cfg.handler = recv_dma_irq_handler;
           dma_cfg.src = 0; // useless
      -    dma_cfg.src_bsize = src_bsize;
      +    dma_cfg.src_bsize = HAL_DMA_BSIZE_8;
           dma_cfg.src_periph = periph;
           dma_cfg.src_tsize = len;
           dma_cfg.src_width = HAL_DMA_WIDTH_BYTE;
      @@ -930,6 +943,7 @@ static int start_recv_dma_with_mask(enum HAL_UART_ID_T id, const struct HAL_UART
           dma_cfg.try_burst = 0;
       
           if (mask) {
      +        recv_mask[id] = *mask;
               dma_cfg.start_cb = recv_dma_start_callback;
           } else {
               union HAL_UART_IRQ_T irq_mask;
      @@ -938,53 +952,37 @@ static int start_recv_dma_with_mask(enum HAL_UART_ID_T id, const struct HAL_UART
               ASSERT(irq_mask.RT == 0, err_recv_dma_api, __FUNCTION__);
           }
       
      +    // Activate DMA RT behaviour
      +    lock = int_lock();
      +    uart[id].base->UARTLCR_H |= UARTLCR_H_DMA_RT_EN;
      +    int_unlock(lock);
      +
           if (cnt == 1) {
      -        ret = hal_dma_init_desc(desc, &dma_cfg, NULL, 1);
      -        if (ret != HAL_DMA_OK) {
      -            ret = 1;
      -        }
      +        ret = hal_gpdma_start(&dma_cfg);
           } else {
               if (mode == UART_RX_DMA_MODE_BUF_LIST) {
                   ret = fill_buf_list_dma_desc(desc, cnt, &dma_cfg, ubuf, ucnt, step);
               } else {
                   ret = fill_dma_desc(desc, cnt, &dma_cfg, len, mode, step);
               }
      -    }
      -    if (ret) {
      -        return 2;
      +        if (ret) {
      +            goto _err_exit;
      +        }
      +        ret = hal_gpdma_sg_start(desc, &dma_cfg);
           }
       
      -    lock = int_lock();
      -    if (recv_dma_chan[id] != HAL_DMA_CHAN_NONE) {
      -        int_unlock(lock);
      -        return 3;
      -    }
      -    dma_cfg.ch = hal_gpdma_get_chan(periph, HAL_DMA_HIGH_PRIO);
      -    if (dma_cfg.ch == HAL_DMA_CHAN_NONE) {
      +    if (ret != HAL_DMA_OK) {
      +_err_exit:
      +        // Restore the traditional RT behaviour
      +        lock = int_lock();
      +        uart[id].base->UARTLCR_H &= ~UARTLCR_H_DMA_RT_EN;
               int_unlock(lock);
      -        return 4;
      -    }
      -    recv_dma_chan[id] = dma_cfg.ch;
      -    recv_dma_mode[id] = mode;
      -    recv_dma_size[id] = len;
      -    if (mask) {
      -        recv_mask[id] = *mask;
      -    }
      -
      -    // Clear previous RT interrupt if any
      -    uart[id].base->UARTICR = UARTINTERRUPT_RT;
      -
      -    ret = hal_gpdma_sg_start(desc, &dma_cfg);
      -    if (ret == HAL_DMA_OK) {
      -        ret = 0;
      -    } else {
               hal_gpdma_free_chan(recv_dma_chan[id]);
               recv_dma_chan[id] = HAL_DMA_CHAN_NONE;
      -        ret = 5;
      +        return 3;
           }
      -    int_unlock(lock);
       
      -    return ret;
      +    return 0;
       }
       
       // Safe API to trigger receive timeout IRQ and DMA IRQ
      @@ -1095,6 +1093,8 @@ uint32_t hal_uart_stop_dma_recv(enum HAL_UART_ID_T id)
           lock = int_lock();
           chan = recv_dma_chan[id];
           recv_dma_chan[id] = HAL_DMA_CHAN_NONE;
      +    // Restore the traditional RT behaviour
      +    uart[id].base->UARTLCR_H &= ~UARTLCR_H_DMA_RT_EN;
           int_unlock(lock);
       
           if (chan == HAL_DMA_CHAN_NONE) {
      @@ -1290,12 +1290,10 @@ static void hal_uart_irq_handler(void)
       #include "stdarg.h"
       #include "stdio.h"
       
      -#if (CHIP_HAS_UART >= 2) && (DEBUG_PORT == 2)
      -#define UART_PRINTF_ID                  HAL_UART_ID_1
      -#elif (DEBUG_PORT == 1)
      +#if !defined(DEBUG_PORT) || (DEBUG_PORT == 1)
       #define UART_PRINTF_ID                  HAL_UART_ID_0
       #else
      -#define UART_PRINTF_ID                  HAL_UART_ID_QTY
      +#define UART_PRINTF_ID                  HAL_UART_ID_1
       #endif
       
       #ifndef TRACE_BAUD_RATE
      @@ -1328,7 +1326,7 @@ int hal_uart_printf_init(void)
       
       void hal_uart_printf(const char *fmt, ...)
       {
      -    char buf[120];
      +    char buf[200];
           int ret;
           int i;
           va_list ap;
  • platform/hal/hal_wdt.c

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/hal_wdt.c bes/platform/hal/hal_wdt.c
      index 8a4df56e2e7..a7e778caac9 100644
      --- a/platform/hal/hal_wdt.c
      +++ b/platform/hal/hal_wdt.c
      @@ -229,7 +229,7 @@ void hal_wdt_set_irq_callback(enum HAL_WDT_ID_T id, HAL_WDT_IRQ_CALLBACK cb)
               default:
               case HAL_WDT_ID_0:
                   NVIC_SetVector(WDT_IRQn, (uint32_t)hal_wdt_irq_handler[id]);
      -            NVIC_SetPriority(WDT_IRQn, IRQ_PRIORITY_REALTIME);
      +            NVIC_SetPriority(WDT_IRQn, IRQ_PRIORITY_NORMAL);
                   NVIC_ClearPendingIRQ(WDT_IRQn);
                   NVIC_EnableIRQ(WDT_IRQn);
               break;
  • platform/hal/Makefile

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/Makefile bes/platform/hal/Makefile
      index 6a2631a6008..9bc7b19c034 100644
      --- a/platform/hal/Makefile
      +++ b/platform/hal/Makefile
      @@ -31,6 +31,9 @@ else
       CFLAGS_hal_cache.o += -DCHIP_CACHE_VER=$(CHIP_CACHE_VER)
       endif
       
      +ifeq ($(USB_EQ_TUNING), 1)
      +CFLAGS_hal_cmd.o += -DUSB_EQ_TUNING
      +endif
       
       ifeq ($(PC_CMD_UART), 1)
       CFLAGS_hal_cmd.o += -D__PC_CMD_UART__
      @@ -93,8 +96,8 @@ endif
       ifeq ($(I2C_DEBUG),1)
       CFLAGS_hal_i2c.o += -DI2C_DEBUG
       endif
      -ifeq ($(I2C_FSP_MODE),1)
      -CFLAGS_hal_i2c.o += -DI2C_FSP_MODE
      +ifeq ($(I2S_FSP_MODE),1)
      +CFLAGS_hal_i2c.o += -DI2S_FSP_MODE
       endif
       
       ifeq ($(I2S_MCLK_FROM_SPDIF),1)
      @@ -107,8 +110,8 @@ CFLAGS_hal_i2s.o += -DI2S_MCLK_DIV=$(I2S_MCLK_DIV)
       endif
       endif
       
      -ifeq ($(I2S_RESAMPLE),1)
      -CFLAGS_hal_i2s.o += -DI2S_RESAMPLE
      +ifeq ($(BONE_SENSOR_TDM),1)
      +CFLAGS_hal_i2s.o += -DI2S_MCLK_PIN
       endif
       
       ifeq ($(CHIP_HAS_SPDIF),1)
      @@ -193,6 +196,9 @@ endif
       ifneq ($(FLASH_SIZE),)
       CFLAGS_hal_norflash.o += -DFLASH_SIZE=$(FLASH_SIZE)
       endif
      +ifeq ($(OTA_BARE_BOOT),1)
      +CFLAGS_hal_norflash.o += -DOTA_BARE_BOOT
      +endif
       ifeq ($(OTA_PROGRAMMER),1)
       CFLAGS_hal_norflash.o += -DOTA_PROGRAMMER
       endif
      @@ -260,7 +266,14 @@ endif
       ifeq ($(CHIP_HAS_SDMMC),1)
       CFLAGS_hal_sdmmc.o += -DCHIP_HAS_SDMMC
       endif
      +ifeq ($(CHIP_HAS_SDIO),1)
      +CFLAGS_hal_sdio.o += -DCHIP_HAS_SDIO
      +endif
       
      +SLEEP_STATS_TRACE ?= 1
      +ifeq ($(SLEEP_STATS_TRACE),1)
      +CFLAGS_hal_sleep.o += -DSLEEP_STATS_TRACE
      +endif
       
       ifeq ($(NO_SLEEP),1)
       CFLAGS_hal_sleep.o += -DNO_SLEEP
      @@ -324,8 +337,8 @@ endif
       ifeq ($(USE_TRACE_ID),1)
       CFLAGS_hal_trace.o += -DUSE_TRACE_ID
       endif
      -ifeq ($(DUMP_LOG_ENABLE),1)
      -CFLAGS_hal_trace.o += -DDUMP_LOG_ENABLE
      +ifeq ($(DUMP_NORMAL_LOG),1)
      +CFLAGS_hal_trace.o += -DDUMP_NORMAL_LOG
       endif
       ifeq ($(FAULT_DUMP),1)
       CFLAGS_hal_trace.o += -DFAULT_DUMP
      @@ -345,9 +358,12 @@ CFLAGS_hal_trace.o += -DTRACE_CRLF
       CFLAGS_hal_uart.o += -DTRACE_CRLF
       endif
       
      -ifeq ($(UART_CLK_DIV_4),1)
      -CFLAGS_hal_uart.o += -DUART_CLK_DIV_4
      +ifeq ($(CORE_DUMP),1)
      +CFLAGS_hal_trace.o += -Iutils/crash_catcher/include -DCORE_DUMP
      +endif
       
      +ifneq ($(UART_FREQ),)
      +CFLAGS_hal_uart.o += -DUART_FREQ=$(UART_FREQ)
       endif
       ifneq ($(DEBUG_PORT),)
       CFLAGS_hal_uart.o += -DDEBUG_PORT=$(DEBUG_PORT)
      @@ -675,3 +691,7 @@ endif
       ifneq ($(BT_CLKOUT_IOMUX_INDEX),)
       IOMUX_CFG_FLAGS += -DBT_CLKOUT_IOMUX_INDEX=$(BT_CLKOUT_IOMUX_INDEX)
       endif
      +
      +ifeq ($(BONE_SENSOR_TDM),1)
      +IOMUX_CFG_FLAGS += -DI2S_MCLK_IOMUX_INDEX=13
      +endif
  • platform/hal/reg_i2cip.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/reg_i2cip.h bes/platform/hal/reg_i2cip.h
      index 83885b7d619..ee9576fe304 100644
      --- a/platform/hal/reg_i2cip.h
      +++ b/platform/hal/reg_i2cip.h
      @@ -226,7 +226,7 @@
       #define I2CIP_INT_MASK_RX_OVER_MASK ((0x1)<<I2CIP_INT_MASK_RX_OVER_SHIFT)
       #define I2CIP_INT_MASK_RX_UNDER_SHIFT (0)
       #define I2CIP_INT_MASK_RX_UNDER_MASK ((0x1)<<I2CIP_INT_MASK_RX_UNDER_SHIFT)
      -#define I2CIP_INT_MASK_NONE (0)
      +#define I2CIP_INT_UNMASK_ALL (0)
       #define I2CIP_INT_MASK_ALL \
           (I2CIP_INT_MASK_GEN_CALL_MASK | \
            I2CIP_INT_MASK_START_DET_MASK | \
  • platform/hal/reg_norflaship_v2.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/reg_norflaship_v2.h bes/platform/hal/reg_norflaship_v2.h
      index c1471b94c40..0fbbd28d07a 100644
      --- a/platform/hal/reg_norflaship_v2.h
      +++ b/platform/hal/reg_norflaship_v2.h
      @@ -38,10 +38,9 @@ struct NORFLASH_CTRL_T {
           __IO uint32_t REG_034;
       #if !defined(CHIP_BEST2300)
           __IO uint32_t REG_038;
      -    __IO uint32_t REG_03C;
      +    __IO uint32_t RESERVED_03C;
           __IO uint32_t REG_040;
      -    __IO uint32_t REG_044;
      -    __IO uint32_t RESERVED_048[2];
      +    __IO uint32_t RESERVED_044[3];
           __IO uint32_t REG_050;
           __IO uint32_t REG_054;
           __IO uint32_t REG_058;
      @@ -183,8 +182,8 @@ struct NORFLASH_CTRL_T {
       #define REG_014_RAM_QUADMODE                (1 << 4)
       #define REG_014_FOUR_BYTE_ADDR_EN           (1 << 3)
       #define REG_014_RES2                        (1 << 2)
      -#define REG_014_WPROPIN                     (1 << 1)
      -#define REG_014_HOLDPIN                     (1 << 0)
      +#define REG_014_HOLDPIN                     (1 << 1)
      +#define REG_014_WPROPIN                     (1 << 0)
       
       // REG_018
       #define REG_018_RES_SHIFT                   2
      @@ -243,12 +242,12 @@ struct NORFLASH_CTRL_T {
       #define REG_02C_FETCH_EN                    (1 << 0)
       
       // REG_030
      -#define REG_030_RES_SHIFT                   8
      -#define REG_030_RES_MASK                    (0xFFFFFF << REG_030_RES_SHIFT)
      +#define REG_030_RES_SHIFT                   2
      +#define REG_030_RES_MASK                    (0x3FFFFFFF << REG_030_RES_SHIFT)
       #define REG_030_RES(n)                      BITFIELD_VAL(REG_030_RES, n)
      -#define REG_030_ADDR_31_24_SHIFT            0
      -#define REG_030_ADDR_31_24_MASK             (0xFF << REG_030_ADDR_31_24_SHIFT)
      -#define REG_030_ADDR_31_24(n)               BITFIELD_VAL(REG_030_ADDR_31_24, n)
      +#define REG_030_ADDR_25_24_SHIFT            0
      +#define REG_030_ADDR_25_24_MASK             (0x3 << REG_030_ADDR_25_24_SHIFT)
      +#define REG_030_ADDR_25_24(n)               BITFIELD_VAL(REG_030_ADDR_25_24, n)
       
       // REG_034
       #define REG_034_RES_SHIFT                   22
      @@ -286,15 +285,15 @@ struct NORFLASH_CTRL_T {
       
       #if (CHIP_FLASH_CTRL_VER >= 3)
       // REG_40
      -#define REG_040_RES_31_6_SHIFT              6
      -#define REG_040_RES_31_6_MASK               (0x3FFFFFF << REG_040_RES_31_6_SHIFT)
      -#define REG_040_RES_31_6(n)                 BITFIELD_VAL(REG_040_RES_31_6, n)
      -#define REG_040_SPH                         (1 << 5)
      -#define REG_040_RES_4                       (1 << 4)
      -#define REG_040_DQS_MODE                    (1 << 3)
      -#define REG_040_DTR_MODE                    (1 << 2)
      -#define REG_040_OPI_MODE                    (1 << 1)
      -#define REG_040_QPI_MODE                    (1 << 0)
      +#define REG_40_RES_31_6_SHIFT               6
      +#define REG_40_RES_31_6_MASK                (0x3FFFFFF << REG_40_RES_31_6_SHIFT)
      +#define REG_40_RES_31_6(n)                  BITFIELD_VAL(REG_40_RES_31_6, n)
      +#define REG_40_SPH                          (1 << 5)
      +#define REG_40_RES_4                        (1 << 4)
      +#define REG_40_DQS_MODE                     (1 << 3)
      +#define REG_40_DTR_MODE                     (1 << 2)
      +#define REG_40_OPI_MODE                     (1 << 1)
      +#define REG_40_QPI_MODE                     (1 << 0)
       #endif
       
       // REG_058
  • platform/hal/reg_psram_mc_v2.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/reg_psram_mc_v2.h bes/platform/hal/reg_psram_mc_v2.h
      index 72213d006b8..583a343ba18 100644
      --- a/platform/hal/reg_psram_mc_v2.h
      +++ b/platform/hal/reg_psram_mc_v2.h
      @@ -106,7 +106,7 @@ struct PSRAM_MC_T {
       // reg_00
       #define PSRAM_ULP_MC_CHIP_BIT                    (1 << 0)
       #define PSRAM_ULP_MC_CHIP_TYPE                   (1 << 1)
      -#define PSRAM_ULP_MC_CHIP_X16                    (1 << 2)
      +#define PSRAM_ULP_MC_RES_3_2_REG00               (1 << 2)
       #define PSRAM_ULP_MC_CHIP_CA_PATTERN(n)          (((n) & 0x7) << 3)
       #define PSRAM_ULP_MC_CHIP_CA_PATTERN_MASK        (0x7 << 3)
       #define PSRAM_ULP_MC_CHIP_CA_PATTERN_SHIFT       (3)
  • platform/hal/reg_psram_phy_v2.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/reg_psram_phy_v2.h bes/platform/hal/reg_psram_phy_v2.h
      index a29329f0abc..9b1ae74ee08 100644
      --- a/platform/hal/reg_psram_phy_v2.h
      +++ b/platform/hal/reg_psram_phy_v2.h
      @@ -79,7 +79,7 @@ struct PSRAM_PHY_T {
       #define PSRAM_ULP_PHY_CMD_CONFLICT_CLR           (1 << 0)
       
       // reg_40
      -#define PSRAM_ULP_PHY_PHY_RX_BYPASS              (1 << 0)
      +#define PSRAM_ULP_PHY_PHY_CFG_UPDATE             (1 << 0)
       
       // reg_44
       #define PSRAM_ULP_PHY_CMD_CONFLICT_STS           (1 << 0)
  • platform/hal/reg_psramuhs_mc.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/reg_psramuhs_mc.h bes/platform/hal/reg_psramuhs_mc.h
      index 7693083afec..9bd40594c00 100644
      --- a/platform/hal/reg_psramuhs_mc.h
      +++ b/platform/hal/reg_psramuhs_mc.h
      @@ -163,9 +163,9 @@ struct PSRAMUHS_MC_T {
       #define PSRAM_UHS_MC_ENTRY_SELF_REFRESH_IDLE     (1 << 1)
       #define PSRAM_UHS_MC_STOP_CLK_IDLE               (1 << 2)
       #define PSRAM_UHS_MC_AUTOWAKEUP_EN               (1 << 3)
      -#define PSRAM_UHS_MC_SELF_RFR_LP_EN(n)           (((n) & 0xF) << 4)
      -#define PSRAM_UHS_MC_SELF_RFR_LP_EN_MASK         (0xF << 4)
      -#define PSRAM_UHS_MC_SELF_RFR_LP_EN_SHIFT        (4)
      +#define PSRAM_UHS_MC_RES_7_4_REG24(n)            (((n) & 0xF) << 4)
      +#define PSRAM_UHS_MC_RES_7_4_REG24_MASK          (0xF << 4)
      +#define PSRAM_UHS_MC_RES_7_4_REG24_SHIFT         (4)
       #define PSRAM_UHS_MC_PD_MR(n)                    (((n) & 0xFF) << 8)
       #define PSRAM_UHS_MC_PD_MR_MASK                  (0xFF << 8)
       #define PSRAM_UHS_MC_PD_MR_SHIFT                 (8)
      @@ -363,9 +363,9 @@ struct PSRAMUHS_MC_T {
       #define PSRAM_UHS_MC_T_NEW_HOLD_SHIFT            (0)
       
       // reg_bc
      -#define PSRAM_UHS_MC_NEW_CMD_CTRL(n)             (((n) & 0x7) << 0)
      -#define PSRAM_UHS_MC_NEW_CMD_CTRL_MASK           (0x7 << 0)
      -#define PSRAM_UHS_MC_NEW_CMD_CTRL_SHIFT          (0)
      +#define PSRAM_UHS_MC_NEW_CMD_OP(n)               (((n) & 0x7) << 0)
      +#define PSRAM_UHS_MC_NEW_CMD_OP_MASK             (0x7 << 0)
      +#define PSRAM_UHS_MC_NEW_CMD_OP_SHIFT            (0)
       
       // reg_140
       #define PSRAM_UHS_MC_CMD_TABLE_ARRAY_RD(n)       (((n) & 0xFF) << 0)
      @@ -523,6 +523,7 @@ struct PSRAMUHS_MC_T {
       #define PSRAM_UHS_MC_CA_MAP_BIT32_MASK           (0x1F << 10)
       #define PSRAM_UHS_MC_CA_MAP_BIT32_SHIFT          (10)
       
      +// reg_190
       
       // reg_400
       #define PSRAM_UHS_MC_INIT_COMPLETE               (1 << 0)
      @@ -610,7 +611,7 @@ struct PSRAMUHS_MC_T {
       #define PSRAM_UHS_MC_PHY_CTRL_DELAY(n)           (((n) & 0x3) << 0)
       #define PSRAM_UHS_MC_PHY_CTRL_DELAY_MASK         (0x3 << 0)
       #define PSRAM_UHS_MC_PHY_CTRL_DELAY_SHIFT        (0)
      -#define PSRAM_UHS_MC_PHY_CS_POLARITY             (1 << 2)
      +#define PSRAM_UHS_MC_RESERVED_2_REG840           (1 << 2)
       #define PSRAM_UHS_MC_PHY_RX_DLY_EN               (1 << 3)
       #define PSRAM_UHS_MC_ANA_LOOPBACK_EN             (1 << 4)
       #define PSRAM_UHS_MC_ANA_TEST_TXFIFO             (1 << 5)
  • platform/hal/reg_uart.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/platform/hal/reg_uart.h bes/platform/hal/reg_uart.h
      index 48daa9263f1..484c75e35a7 100644
      --- a/platform/hal/reg_uart.h
      +++ b/platform/hal/reg_uart.h
      @@ -38,7 +38,7 @@ struct UART_T {
           __I  uint32_t UARTMIS;          // 0x040
           __O  uint32_t UARTICR;          // 0x044
           __IO uint32_t UARTDMACR;        // 0x048
      -    __IO uint32_t UARTOVSAMP;       // 0x04C
      +    uint32_t RESERVED_04C[997];     // 0x04C
           __I  uint32_t UARTPID0;         // 0xFE0
           __I  uint32_t UARTPID1;         // 0xFE4
           __I  uint32_t UARTPID2;         // 0xFE8
  • scripts/build.mk

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/scripts/build.mk bes/scripts/build.mk
      index 78cc1fb1f22..57d80dd4a09 100644
      --- a/scripts/build.mk
      +++ b/scripts/build.mk
      @@ -130,7 +130,7 @@ ifeq ($(filter $(obj)/built-in.lst,$(lst_target)),)
       # Just compile some of the object files
       buildsubdir-y := $(call get_subdirs,$(subdir-y),$(cur_submods))
       buildobj-y := $(filter $(cur_submods) $(addsuffix /built-in$(built_in_suffix),$(buildsubdir-y)),$(obj-y))
      -buildobj-y += $(foreach m,$(multi-used-y),$(if $(filter $(cur_submods),$(call get_multi_objs,$m)),$m,))
      +buildobj-y += $(foreach m,$(multi-used-y),$(if $(filter $(cur_submods),$(call get_multi_objs,$m))),$m,)
       
       else
       
      @@ -183,25 +183,15 @@ buildextra-y := $(extra-y)
       buildobj-y := $(obj-y)
       buildlib-y := $(lib-y)
       
      -buildobj-y      := $(if $(filter-obj),$(filter-out $(filter-obj),$(buildobj-y)),$(buildobj-y))
       endif # SUBMODS
       
      -ifeq ($(LIB_BIN_IN_SRC_DIR),1)
      -archive-bin-path := $(srctree)/$(src)/lib
      -else ifeq ($(LIB_BIN_IN_TOP_WITH_SRC_DIR),1)
      -archive-bin-path := $(srctree)/lib/$(src)
      -else
      -LIB_BIN_DIR ?= $(BES_LIB_DIR)
      -archive-bin-path := $(srctree)/$(LIB_BIN_DIR)
      -endif
      -
       archive-src-target :=
       archive-custom-target :=
       ifeq ($(GEN_LIB),1)
      -archive-src-target := $(archive-src-y:$(obj)/%=$(archive-bin-path)/%)
      +archive-src-target := $(addprefix $(srctree)/$(src)/lib/,$(notdir $(archive-src-y)))
       archive-src-target += $(archive-custom-valid)
       archive-src-target := $(strip $(archive-src-target))
      -archive-custom-target := $(archive-custom-valid:$(obj)/%=$(archive-bin-path)/%)
      +archive-custom-target := $(addprefix $(srctree)/$(src)/lib/,$(notdir $(archive-custom-valid)))
       endif
       
       __build: $(builtin-target) $(lib-target) $(buildextra-y) $(buildsubdir-y) $(lst_target) $(archive-src-target) $(archive-custom-target) $(always)
      @@ -323,6 +313,25 @@ $(obj)/%.lst: $(obj)/%.o
       # To build objects in subdirs, we need to descend into the directories
       $(sort $(subdir-obj-y)): $(buildsubdir-y) ;
       
      +# Archive command
      +
      +ifeq ($(TOOLCHAIN),armclang)
      +archive-cmd = $(AR) --create --debug_symbols $@ $(1)
      +else
      +ifeq ($(WIN_PLAT),y)
      +archive-cmd = ( ( echo create $@ && \
      +  echo addmod $(subst $(space),$(comma),$(strip $(filter-out %.a,$(1)))) && \
      +  $(foreach o,$(filter %.a,$(1)),echo addlib $o && ) \
      +  echo save && \
      +  echo end ) | $(AR) -M )
      +else
      +# Command "/bin/echo -e" cannot work on Apple Mac machines, so we use "/usr/bin/printf" instead
      +archive-cmd = ( /usr/bin/printf 'create $@\n\
      +  addmod $(subst $(space),$(comma),$(strip $(filter-out %.a,$(1))))\n\
      +  $(foreach o,$(filter %.a,$(1)),addlib $o\n)save\nend' | $(AR) -M )
      +endif
      +endif
      +
       # Archive check
       
       ifeq ($(CHECK_LIB_SRC),1)
      @@ -334,11 +343,6 @@ endif
       
       ifneq ($(archive-src-y),)
       $(info )
      -$(foreach m, $(archive-src-y), \
      -    $(eval $(info $(m) :) \
      -    $(eval tmp_list=$(call get-archive-src,$(patsubst $(obj)/%,%,$(m)))) \
      -    $(eval $(foreach k, $(tmp_list), $(info $(empty)    $(k))))))
      -$(info )
       $(error Error: The source files exist for libraries: $(archive-src-y))
       endif
       endif
      @@ -356,7 +360,7 @@ $(warning WARNING: No source files found for libraries: $(archive-bin-y))
       $(info )
       endif
       
      -$(archive-bin-y): $(obj)/%: $(archive-bin-path)/% FORCE
      +$(archive-bin-y): $(obj)/%: $(srctree)/$(src)/lib/% FORCE
       ifeq ($(FORCE_TO_USE_LIB),1)
       	$(call cmd,use_lib_file)
       else
  • scripts/clean.mk

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/scripts/clean.mk bes/scripts/clean.mk
      index 27f42a5768b..93dc760e1bd 100644
      --- a/scripts/clean.mk
      +++ b/scripts/clean.mk
      @@ -49,24 +49,11 @@ subdir-ymn      := $(sort $(subdir-ym) $(subdir-))
       obj-ymn         := $(obj-y) $(obj-m) $(obj-)
       lib-ymn         := $(lib-y) $(lib-m) $(lib-)
       
      -archive-ymn     := $(filter %.a, $(obj-ymn))
      -archive-src-ymn := $(foreach m, $(archive-ymn), $(if $(wildcard $(addprefix $(srctree)/$(src)/,$($(m:.a=-y):.o=.*))), $(m)))
      -archive-obj-ymn := $(foreach m, $(archive-src-ymn), $($(m:.a=-y)))
      -
      -obj-ymn         += $(filter %.o %.a, $(archive-obj-ymn))
      -subdir-ymn      += $(filter %/, $(archive-obj-ymn))
      -
       # if $(foo-objs) exists, foo.o is a composite object
       multi-used-ymn  := $(sort $(foreach m,$(obj-ymn), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
       multi-objs-ymn  := $(foreach m, $(multi-used-ymn), $($(m:.o=-objs)) $($(m:.o=-y)))
       
      -multi-objs-subdir-ymn   := $(patsubst %/,%,$(filter %/, $(multi-objs-ymn)))
      -subdir-ymn      += $(multi-objs-subdir-ymn)
      -multi-objs-ymn  := $(filter-out %/, $(multi-objs-ymn))
      -
      -obj-ymn         := $(filter-out %/, $(obj-ymn))
      -obj-ymn         += $(addsuffix /built-in.o, $(subdir-ymn))
      -obj-ymn         += $(addsuffix /built-in.a, $(subdir-ymn))
      +obj-ymn         := $(patsubst %/, %/built-in.o %/built-in.a, $(obj-y) $(obj-m) $(obj-))
       
       extra-ymn       := $(extra-y) $(extra-m) $(extra-)
       
  • scripts/lib.mk

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/scripts/lib.mk bes/scripts/lib.mk
      index d4fb3ac4263..5e260279d03 100644
      --- a/scripts/lib.mk
      +++ b/scripts/lib.mk
      @@ -46,8 +46,7 @@ else
       archive-y       := $(filter-out $(archive-custom-valid), $(archive-y))
       
       # Extract archives that have source files available
      -get-archive-src = $(wildcard $(addprefix $(srctree)/$(src)/,$($(1:.a=-y):.o=.*)))
      -archive-src-y   := $(foreach m, $(archive-y), $(if $(call get-archive-src,$(m)), $(m)))
      +archive-src-y   := $(foreach m, $(archive-y), $(if $(wildcard $(addprefix $(srctree)/$(src)/,$($(m:.a=-y):.o=.*))), $(m)))
       
       # Extract archives that do NOT have source files
       archive-bin-y   := $(filter-out $(archive-src-y), $(archive-y))
  • scripts/submods_init.mk

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/scripts/submods_init.mk bes/scripts/submods_init.mk
      index bcd007a9d7b..3b7a08ea2ef 100644
      --- a/scripts/submods_init.mk
      +++ b/scripts/submods_init.mk
      @@ -18,7 +18,7 @@ ifeq ($(WIN_PLAT),y)
       SUBMODGOALS := $(sort $(foreach m, $(MAKECMDGOALS), \
         $(if $(filter-out ./,$(wildcard $(dir $(subst \,/,$m)) $(subst \,/,$m))),$m,)))
       else
      -  SUBMODGOALS := $(sort $(foreach m, $(filter-out lib,$(MAKECMDGOALS)), \
      +  SUBMODGOALS := $(sort $(foreach m, $(MAKECMDGOALS), \
         $(if $(filter-out ./,$(wildcard $(dir $m) $m)),$m,)))
       endif
       
  • scripts/submods.mk

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/scripts/submods.mk bes/scripts/submods.mk
      index f8f9be31b9b..25831e439d7 100644
      --- a/scripts/submods.mk
      +++ b/scripts/submods.mk
      @@ -20,5 +20,5 @@ get_submodgoals = $(foreach m, \
         $(patsubst $(1)/%,%,$(filter $(1)/%,$(2))), \
         $(addprefix $(1)/,$(firstword $(subst /,$(space),$m))))
       
      -get_multi_objs = $(addprefix $(obj)/, $($(subst $(obj)/,,$(1:.o=-y))) \
      +get_multi_objs = $(addprefix $(obj)/, $($(subst $(obj)/,,$(1:.o=-objs))) \
         $($(subst $(obj)/,,$(1:.o=-objs))))
  • services/audio_dump/include/audio_dump.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/audio_dump/include/audio_dump.h bes/services/audio_dump/include/audio_dump.h
      index cb23afa497d..cd985b900e6 100644
      --- a/services/audio_dump/include/audio_dump.h
      +++ b/services/audio_dump/include/audio_dump.h
      @@ -24,11 +24,14 @@ extern "C" {
       #endif
       
       void audio_dump_init(int frame_len, int sample_bytes, int channel_num);
      +void audio_dump_deinit(void);
       void audio_dump_clear_up(void);
      +void audio_dump_add_channel_data_from_multi_channels(int channel_id, void *pcm_buf, int pcm_len, int channel_num, int channel_index);
       void audio_dump_add_channel_data(int channel_id, void *pcm_buf, int pcm_len);
       void audio_dump_run(void);
       
       void data_dump_init(void);
      +void data_dump_deinit(void);
       void data_dump_run(const char *str, void *data_buf, uint32_t data_len);
       
       #ifdef __cplusplus
  • services/audioflinger/audioflinger.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/audioflinger/audioflinger.h bes/services/audioflinger/audioflinger.h
      index 7f86883c968..31ec64bc848 100644
      --- a/services/audioflinger/audioflinger.h
      +++ b/services/audioflinger/audioflinger.h
      @@ -25,7 +25,7 @@ extern "C" {
       
       typedef uint32_t (*AF_STREAM_HANDLER_T)(uint8_t *buf, uint32_t len);
       typedef void (*AF_IRQ_NOTIFICATION_T)(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
      -typedef void (*AF_CODEC_PLAYBACK_POST_HANDLER_T)(uint8_t *buf, uint32_t len, void *cfg);
      +typedef void (*AF_CODEC_PLAYBACK_POST_HANDLER_T)(uint8_t *buf, uint32_t len, void *config);
       
       //pingpong machine
       enum AF_PP_T{
      @@ -51,7 +51,7 @@ struct AF_STREAM_CONFIG_T {
           enum AUD_STREAM_USE_DEVICE_T device;
           enum AUD_IO_PATH_T io_path;
           bool chan_sep_buf;
      -    bool i2s_master_clk_wait;
      +    bool sync_start;
           uint8_t slot_cycles;
           uint16_t fs_cycles;
           AF_STREAM_HANDLER_T handler;
      @@ -103,6 +103,7 @@ void af_codec_direct_tune(enum AUD_STREAM_T stream, float ratio);
       void af_codec_set_perf_test_power(int type);
       void af_codec_set_noise_reduction(bool enable);
       void af_codec_swap_output(bool swap);
      +void af_codec_set_playback_post_handler(AF_CODEC_PLAYBACK_POST_HANDLER_T hdlr);
       
       enum AF_CODEC_SYNC_TYPE_T {
           AF_CODEC_SYNC_TYPE_NONE,
      @@ -111,11 +112,17 @@ enum AF_CODEC_SYNC_TYPE_T {
           AF_CODEC_SYNC_TYPE_WIFI,
       };
       
      +enum AF_I2S_SYNC_TYPE_T {
      +    AF_I2S_SYNC_TYPE_NONE,
      +    AF_I2S_SYNC_TYPE_BT,
      +    AF_I2S_SYNC_TYPE_GPIO,
      +};
       
       
       void af_codec_sync_config(enum AUD_STREAM_T stream, enum AF_CODEC_SYNC_TYPE_T type, bool enable);
       void af_codec_sync_resample_rate_config(enum AUD_STREAM_T stream, enum AF_CODEC_SYNC_TYPE_T type, bool enable);
       void af_codec_sync_gain_config(enum AUD_STREAM_T stream, enum AF_CODEC_SYNC_TYPE_T type, bool enable);
      +void af_i2s_sync_config(enum AUD_STREAM_T stream, enum AF_I2S_SYNC_TYPE_T type, bool enable);
       
       typedef void (*AF_ANC_HANDLER)(enum AUD_STREAM_T stream, enum AUD_SAMPRATE_T rate, enum AUD_SAMPRATE_T *new_play, enum AUD_SAMPRATE_T *new_cap);
       
      @@ -127,6 +134,7 @@ int af_vad_close(void);
       int af_vad_start(void);
       int af_vad_stop(void);
       uint32_t af_vad_get_data(uint8_t *buf, uint32_t len);
      +void af_vad_get_data_info(struct CODEC_VAD_BUF_INFO_T * vad_buf_info);
       
       void af_dsd_enable(void);
       void af_dsd_disable(void);
      @@ -134,6 +142,9 @@ void af_dsd_disable(void);
       typedef void (*AF_CODEC_BT_TRIGGER_CALLBACK)(void);
       void af_codec_bt_trigger_config(bool en, AF_CODEC_BT_TRIGGER_CALLBACK callback);
       
      +#ifdef __RAND_FROM_MIC__
      +uint8_t random_mic_is_on(uint8_t *deviceId);
      +#endif
       
       #ifdef __cplusplus
       }
  • services/audio_process/audio_process.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/audio_process/audio_process.h bes/services/audio_process/audio_process.h
      index c4e557b22aa..2aabab73c1b 100644
      --- a/services/audio_process/audio_process.h
      +++ b/services/audio_process/audio_process.h
      @@ -31,7 +31,7 @@ typedef enum {
       } AUDIO_EQ_TYPE_T;
       
       int audio_process_init(void);
      -int audio_process_open(enum AUD_SAMPRATE_T sample_rate, enum AUD_BITS_T sample_bits,enum AUD_CHANNEL_NUM_T ch_num, int32_t frame_size, void *eq_buf, uint32_t len);
      +int audio_process_open(enum AUD_SAMPRATE_T sample_rate, enum AUD_BITS_T sample_bits,enum AUD_CHANNEL_NUM_T sw_ch_num, enum AUD_CHANNEL_NUM_T hw_ch_num,int32_t frame_size, void *eq_buf, uint32_t len);
       int audio_process_run(uint8_t *buf, uint32_t len);
       int audio_process_close(void);
       
  • services/ble_app/app_main/app_ble_core.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_app/app_main/app_ble_core.h bes/services/ble_app/app_main/app_ble_core.h
      index 1cc0b227efc..3ac5abb961d 100644
      --- a/services/ble_app/app_main/app_ble_core.h
      +++ b/services/ble_app/app_main/app_ble_core.h
      @@ -26,10 +26,10 @@
        *
        */
       typedef enum{
      -    BLE_CONNECT_EVENT                   = 0,
      -    BLE_DISCONNECT_EVENT                = 6,
      -    BLE_CONN_PARAM_UPDATE_REQ_EVENT     = 7,
      -    BLE_SET_RANDOM_BD_ADDR_EVENT        = 10,
      +    BLE_CONNECT_EVENT       = 0,
      +    BLE_DISCONNECT_EVENT,
      +    BLE_CONN_PARAM_UPDATE_REQ_EVENT,
      +    BLE_SET_RANDOM_BD_ADDR_EVENT,
       
           BLE_EVENT_NUM_MAX,
       } ble_evnet_type_e;
      @@ -47,42 +47,31 @@ typedef enum{
           BLE_CALLBACK_EVENT_NUM_MAX,
       } ble_callback_evnet_type_e;
       
      -typedef struct {
      -    uint8_t conidx;
      -    ble_bdaddr_t peer_bdaddr;
      -} connect_handled_t;
      -
      -typedef struct {
      -    uint8_t conidx;
      -    uint8_t errCode;
      -} disconnect_handled_t;
      -
      -typedef struct {
      -    /// Connection interval minimum
      -    uint16_t intv_min;
      -    /// Connection interval maximum
      -    uint16_t intv_max;
      -    /// Latency
      -    uint16_t latency;
      -    /// Supervision timeout
      -    uint16_t time_out;
      -} conn_param_update_req_handled_t;
      -
      -typedef struct {
      -    uint8_t *new_bdaddr;
      -} set_random_bd_addr_handled_t;
      -
      -typedef union {
      -    connect_handled_t connect_handled;
      -    disconnect_handled_t disconnect_handled;
      -    conn_param_update_req_handled_t conn_param_update_req_handled;
      -    set_random_bd_addr_handled_t set_random_bd_addr_handled;
      -} ble_event_handled_t;
      -
       typedef struct {
           ble_evnet_type_e evt_type;
      -    ble_event_handled_t p;
      -} ble_event_t;
      +    union {
      +        struct {
      +            uint8_t conidx;
      +            const uint8_t *peer_bdaddr;
      +        } connect_handled;
      +        struct {
      +            uint8_t conidx;
      +        } disconnect_handled;
      +        struct {
      +            /// Connection interval minimum
      +            uint16_t intv_min;
      +            /// Connection interval maximum
      +            uint16_t intv_max;
      +            /// Latency
      +            uint16_t latency;
      +            /// Supervision timeout
      +            uint16_t time_out;
      +        } conn_param_update_req_handled;
      +        struct {
      +            uint8_t *new_bdaddr;
      +        } set_random_bd_addr_handled;
      +    } p;
      +} ble_evnet_t;
       
       typedef struct {
           ble_callback_evnet_type_e evt_type;
      @@ -97,10 +86,11 @@ typedef struct {
                   uint8_t event;
               } ibrt_event_entry_handled;
           } p;
      -} ble_callback_event_t;
      +} ble_callback_evnet_t;
      +
      +typedef void (*APP_BLE_CORE_GLOBAL_HANDLER_FUNC)(ble_evnet_t *, void *);
      +typedef void (*APP_BLE_CORE_GLOBAL_CALLBACK_HANDLER_FUNC)(ble_callback_evnet_t *, void *);
       
      -typedef void (*APP_BLE_CORE_GLOBAL_HANDLER_FUNC)(ble_event_t *, void *);
      -typedef void (*APP_BLE_CORE_GLOBAL_CALLBACK_HANDLER_FUNC)(ble_callback_event_t *, void *);
       
       // Element of a message handler table.
       typedef struct {
      @@ -165,7 +155,7 @@ void app_ble_core_register_global_callback_handle_ind(APP_BLE_CORE_GLOBAL_CALLBA
        * Return:
        *    uint32_t
        */
      -void app_ble_core_global_handle(ble_event_t *event, void *output);
      +void app_ble_core_global_handle(ble_evnet_t *event, void *output);
       
       /*---------------------------------------------------------------------------
        *            app_ble_core_global_callback_event
      @@ -180,7 +170,7 @@ void app_ble_core_global_handle(ble_event_t *event, void *output);
        * Return:
        *    void
        */
      -void app_ble_core_global_callback_event(ble_callback_event_t *event, void *output);
      +void app_ble_core_global_callback_event(ble_callback_evnet_t *event, void *output);
       
       /*---------------------------------------------------------------------------
        *            app_ble_stub_user_init
      @@ -230,19 +220,26 @@ void app_ble_mode_tws_sync_init(void);
       
       /****************************function declearation**************************/
       /*---------------------------------------------------------------------------
      - *            app_ble_core_print_ble_state
      + *            ble_adv_data_parse
        *---------------------------------------------------------------------------
        *
        *Synopsis:
      - *    print ble state
      + *    for ble core to parse adv data
        *
        * Parameters:
      - *    void
      + *    bleBdAddr -- ble address
      + *    rssi      -- ble rssi
      + *    adv_buf   -- adv data
      + *    len       -- adv data length
        *
        * Return:
        *    void
        */
      -void app_ble_core_print_ble_state(void);
      +void ble_adv_data_parse(uint8_t *bleBdAddr,
      +                               int8_t rssi,
      +                               unsigned char *adv_buf,
      +                               unsigned char len);
      +
       
       #ifdef __cplusplus
       }
  • services/ble_app/app_main/app_ble_mode_switch.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_app/app_main/app_ble_mode_switch.h bes/services/ble_app/app_main/app_ble_mode_switch.h
      index 35d53253a68..28dedb632f2 100644
      --- a/services/ble_app/app_main/app_ble_mode_switch.h
      +++ b/services/ble_app/app_main/app_ble_mode_switch.h
      @@ -22,7 +22,7 @@ extern "C" {
       
       /*****************************header include********************************/
       #include "bluetooth.h"
      -#include "app_ble_param_config.h"
      +#include "co_bt_defines.h"
       
       /******************************macro defination*****************************/
       #define BLE_ADV_DATA_STRUCT_HEADER_LEN (2)
      @@ -30,9 +30,6 @@ extern "C" {
       #ifndef BLE_CONNECTION_MAX
       #define BLE_CONNECTION_MAX (1)
       #endif
      -#ifndef ADV_DATA_LEN
      -#define ADV_DATA_LEN                    0x1F
      -#endif
       
       // the default interval is 160ms, note that for Bisto user case, to
       // let GVA iOS version pop-out notification smoothly, the maximum interval should be this value
      @@ -112,13 +109,13 @@ enum BLE_SCAN_FILTER_POLICY {
       };
       
       typedef struct {
      -    bool withFlags;
      +    bool withFlag;
           uint8_t advType;
           uint16_t advInterval;
           uint8_t advDataLen;
      -    uint8_t advData[ADV_DATA_LEN];
      +    uint8_t advData[BLE_DATA_LEN];
           uint8_t scanRspDataLen;
      -    uint8_t scanRspData[ADV_DATA_LEN];
      +    uint8_t scanRspData[BLE_DATA_LEN];
       } BLE_ADV_PARAM_T;
       
       typedef void (*BLE_DATA_FILL_FUNC_T)(void *advParam);
      @@ -130,7 +127,7 @@ typedef struct {
       } BLE_SCAN_PARAM_T;
       
       typedef struct {
      -    uint32_t advSwitch;         //one bit represent one user
      +    uint32_t advSwitch;
           uint8_t state;
           uint8_t op;
           uint8_t bleAddrToConnect[BTIF_BD_ADDR_SIZE];
      @@ -204,6 +201,15 @@ void app_ble_data_fill_enable(enum BLE_ADV_USER_E user, bool enable);
        *            app_ble_get_data_fill_enable
        *---------------------------------------------------------------------------
        *
      + *Synopsis:
      + *    get if specific user is enabled to fill adv/scan response data
      + *
      + * Parameters:
      + *    user : user
      + *
      + * Return:
      + *    true - user is enabled to fill data
      + *    false - user is disabled to fill data
        */
       bool app_ble_get_data_fill_enable(enum BLE_ADV_USER_E user);
       
      @@ -252,7 +258,7 @@ void app_ble_refresh_adv_state(uint16_t advInterval);
        * Return:
        *    void
        */
      -void app_ble_force_switch_adv(enum BLE_ADV_SWITCH_USER_E user, bool onOff);
      +void app_ble_force_switch_adv(uint8_t user, bool onOff);
       
       /*---------------------------------------------------------------------------
        *            app_ble_start_scan
      @@ -352,7 +358,15 @@ void app_ble_disconnect_all(void);
        *            app_ble_stop_activities
        *---------------------------------------------------------------------------
        *
      + *Synopsis:
      + *    stop all BLE activities
      + *    NOTE: will not disconnect the existed connections
      + *
      + * Parameters:
      + *    void
        *
      + * Return:
      + *    void
        */
       void app_ble_stop_activities(void);
       
      @@ -387,7 +401,35 @@ bool app_ble_is_in_advertising_state(void);
        */
       uint32_t app_ble_get_user_register(void);
       
      +/*---------------------------------------------------------------------------
      + *            app_ble_get_current_state
      + *---------------------------------------------------------------------------
      + *
      + *Synopsis:
      + *    to get current ble state
      + *
      + * Parameters:
      + *    void
      + *
      + * Return:
      + *    enum BLE_STATE_E -- ble state
      + */
      +enum BLE_STATE_E app_ble_get_current_state(void);
       
      +/*---------------------------------------------------------------------------
      + *            app_ble_get_current_operation
      + *---------------------------------------------------------------------------
      + *
      + *Synopsis:
      + *    to get current ble operation
      + *
      + * Parameters:
      + *    void
      + *
      + * Return:
      + *    enum BLE_OP_E -- ble operation
      + */
      +enum BLE_OP_E app_ble_get_current_operation(void);
       
       /*---------------------------------------------------------------------------
        *            app_ble_get_runtime_adv_param
  • services/ble_app/app_main/app.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_app/app_main/app.h bes/services/ble_app/app_main/app.h
      index 6a56e375097..dff97040b1c 100644
      --- a/services/ble_app/app_main/app.h
      +++ b/services/ble_app/app_main/app.h
      @@ -32,18 +32,14 @@
        */
       
       #include "rwip_config.h"     // SW configuration
      -#include "app_ble_mode_switch.h"
      -#include "app_ble_param_config.h"
      -#include "co_bt_defines.h"
       
       #ifdef  BLE_APP_PRESENT
       
       #include <stdint.h>          // Standard Integer Definition
       #include <co_bt.h>           // Common BT Definitions
       #include "arch.h"            // Platform Definitions
      -#include "gapc_msg.h"       // GAPC Definitions
      -#include "gapm_msg.h"
      -#include "gap.h"
      +#include "gapc.h"            // GAPC Definitions
      +#include "gapm_task.h"
       #if (NVDS_SUPPORT)
       #include "nvds.h"
       #endif // (NVDS_SUPPORT)
      @@ -97,11 +93,11 @@ typedef enum
           BLE_CONN_PARAM_PRIORITY_HIGH,
       } BLE_CONN_PARAM_PRIORITY_E;
       
      -typedef enum BLE_CONNECT_STATE {
      +enum BLE_CONNECT_STATE {
           BLE_DISCONNECTED  = 0,
           BLE_DISCONNECTING = 1,
           BLE_CONNECTED     = 2,
      -}BLE_CONNECT_STATE_E;
      +};
       
       typedef struct
       {
      @@ -110,12 +106,14 @@ typedef struct
           uint16_t    conn_param_interval;    // in the unit of 1.25ms
       } BLE_CONN_PARAM_CONFIG_T;
       
      +#define BLE_CONN_PARAM_SLAVE_LATENCY_CNT        0
      +#define BLE_CONN_PARAM_SUPERVISE_TIMEOUT_MS     6000
       
       /// Application environment structure
       typedef struct {
           /// Connection handle
           uint16_t conhdl;
      -    BLE_CONNECT_STATE_E connectStatus;
      +    uint8_t connectStatus;
           uint8_t isFeatureExchanged;
           /// Bonding status
           uint8_t bonded;
      @@ -124,12 +122,7 @@ typedef struct {
           uint8_t isGotSolvedBdAddr;
           uint8_t bdAddr[BD_ADDR_LEN];
           uint8_t solvedBdAddr[BD_ADDR_LEN];
      -    /// ble connection param record
      -    APP_BLE_CONN_PARAM_T connParam;
      -    /// ble connection pending param
      -    APP_BLE_CONN_PARAM_T connPendindParam;
      -    /// ble connection param update times
      -    uint8_t conn_param_update_times;
      +    uint16_t connInterval;
       
       } APP_BLE_CONN_CONTEXT_T;
       
      @@ -151,7 +144,25 @@ struct app_env_tag
           APP_BLE_CONN_CONTEXT_T context[BLE_CONNECTION_MAX];
       };
       
      +// TODO:
      +typedef struct
      +{
      +   uint8_t role                         :2;
      +   uint8_t earSide                      :1;
      +   uint8_t isConnectedWithMobile        :1;
      +   uint8_t isConnectedWithTWS           :1;
      +   uint8_t reserved                     :3;
      +}__attribute__((__packed__)) BLE_ADV_CURRENT_STATE_T;
       
      +typedef struct
      +{
      +    ///Connection interval value
      +    uint16_t            con_interval;
      +    ///Connection latency value
      +    uint16_t            con_latency;
      +    ///Supervision timeout
      +    uint16_t            sup_to;
      +} APP_BLE_NEGOTIATED_CONN_PARAM_T;
       
       // max adv data length is 31, and 3 byte is used for adv type flag(0x01)
       #define ADV_DATA_MAX_LEN                            (28)
      @@ -199,7 +210,7 @@ void appm_start_advertising(void *param);
        * @brief Put the device in non discoverable and non connectable mode
        ****************************************************************************************
        */
      -void appm_stop_advertising(uint8_t actv_idx);
      +void appm_stop_advertising(void);
       
       /**
        ****************************************************************************************
      @@ -247,7 +258,7 @@ bool app_sec_get_bond_status(void);
        * Return:
        *    void
        */
      -void app_ble_connected_evt_handler(uint8_t conidx, gap_bdaddr_t *pPeerBdAddress);
      +void app_ble_connected_evt_handler(uint8_t conidx, const uint8_t* pPeerBdAddress);
       
       /*---------------------------------------------------------------------------
        *            app_ble_disconnected_evt_handler
      @@ -262,15 +273,15 @@ void app_ble_connected_evt_handler(uint8_t conidx, gap_bdaddr_t *pPeerBdAddress)
        * Return:
        *    void
        */
      -void app_ble_disconnected_evt_handler(uint8_t conidx, uint8_t errCode);
      +void app_ble_disconnected_evt_handler(uint8_t conidx);
       
       void l2cap_update_param(uint8_t  conidx,
                               uint32_t min_interval_in_ms,
                               uint32_t max_interval_in_ms,
                               uint32_t supervision_timeout_in_ms,
      -                        uint8_t  slaveLatency);
      +                        uint8_t  slaveLantency);
       
      -void appm_start_connecting(BLE_INIT_PARAM_T *init_param);
      +void appm_start_connecting(struct gap_bdaddr* ptBdAddr);
       
       void appm_stop_connecting(void);
       
      @@ -282,23 +293,25 @@ void appm_create_advertising(void);
       
       void appm_create_connecting(void);
       
      -void app_advertising_stopped(uint8_t actv_idx);
      +void app_advertising_stopped(void);
       
      -void app_advertising_starting_failed(uint8_t actv_idx, uint8_t err_code);
      +void app_advertising_starting_failed(void);
       
      +void app_adv_data_updated(void);
       
       void app_scanning_stopped(void);
       
      -void app_scanning_starting_failed(uint8_t actv_idx, uint8_t err_code);
      +void app_scanning_starting_failed(void);
       
      -void app_connecting_stopped(gap_bdaddr_t *peer_addr);
      +void app_connecting_stopped(void);
       
      -void app_connecting_failed(uint8_t actv_idx, uint8_t err_code);
      +void app_connecting_failed(void);
       
       void appm_exchange_mtu(uint8_t conidx);
       
       void app_ble_system_ready(void);
       
      +void app_adv_reported_scanned(struct gapm_adv_report_ind* ptInd);
       
       void appm_set_private_bd_addr(uint8_t* bdAddr);
       
      @@ -306,9 +319,9 @@ void appm_add_dev_into_whitelist(struct gap_bdaddr* ptBdAddr);
       
       void app_scanning_started(void);
       
      -void app_advertising_started(uint8_t actv_idx);
      +void app_advertising_started(void);
       
      -void app_connecting_stopped(gap_bdaddr_t *peer_addr);
      +void app_connecting_stopped(void);
       
       void app_connecting_started(void);
       
      @@ -352,12 +365,12 @@ void app_ble_reset_conn_param_mode(uint8_t conidx);
       
       void appm_refresh_ble_irk(void);
       
      -bool app_ble_get_conn_param(uint8_t conidx,  APP_BLE_CONN_PARAM_T* pConnParam);
      +void app_ble_save_negotiated_conn_param(uint8_t conidx, APP_BLE_NEGOTIATED_CONN_PARAM_T* pConnParam);
       
      -void app_ble_update_param_successful(uint8_t conidx, APP_BLE_CONN_PARAM_T* pConnParam);
      -void app_ble_update_param_failed(uint8_t conidx, uint8_t errCode);
      +bool app_ble_get_connection_interval(uint8_t conidx,  APP_BLE_NEGOTIATED_CONN_PARAM_T* pConnParam);
       
      -void appm_update_adv_data(void *param);
      +void appm_update_adv_data(uint8_t* pAdvData, uint32_t advDataLen,
      +    uint8_t* pScanRspData, uint32_t scanRspDataLen);
       
       bool gattc_check_if_notification_processing_is_busy(uint8_t conidx);
       
      @@ -366,7 +379,9 @@ void fp_update_ble_connect_param_start(uint8_t ble_conidx);
       void fp_update_ble_connect_param_stop(uint8_t ble_conidx);
       #endif
       
      +bool app_ble_is_parameter_mode_enabled(uint8_t conidx, BLE_CONN_PARAM_MODE_E mode);
       
      +void app_ble_parameter_mode_clear(uint8_t conidx, BLE_CONN_PARAM_MODE_E mode);
       
       #ifdef __cplusplus
       }
  • services/ble_app/app_main/app_task.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_app/app_main/app_task.h bes/services/ble_app/app_main/app_task.h
      index baea3ca7959..736d7f080a2 100644
      --- a/services/ble_app/app_main/app_task.h
      +++ b/services/ble_app/app_main/app_task.h
      @@ -79,10 +79,12 @@ enum appm_state
       
       
       /// APP Task messages
      -enum app_msg_id
      +enum appm_msg
       {
           APPM_DUMMY_MSG = TASK_FIRST_MSG(TASK_ID_APP),
       
      +    /// Timer used to automatically stop advertising
      +    APP_ADV_TIMEOUT_TIMER,
       
           #if (BLE_APP_HT)
           /// Timer used to refresh the temperature measurement value
  • services/ble_stack/ble_ip/arch.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/ble_ip/arch.h bes/services/ble_stack/ble_ip/arch.h
      index 97ab33410e6..f6b17cf7bc3 100644
      --- a/services/ble_stack/ble_ip/arch.h
      +++ b/services/ble_stack/ble_ip/arch.h
      @@ -17,10 +17,10 @@
       
       /**
        ****************************************************************************************
      - * @defgroup BLUEGRIP
      - * @brief BlueGRiP IP Platform
      + * @defgroup REFIP
      + * @brief Reference IP Platform
        *
      - * This module contains reference platform components - RICOW.
      + * This module contains reference platform components - REFIP.
        *
        *
        * @{
      @@ -30,7 +30,7 @@
       /**
        ****************************************************************************************
        * @defgroup DRIVERS
      - * @ingroup BLUEGRIP
      + * @ingroup REFIP
        * @brief Reference IP Platform Drivers
        *
        * This module contains the necessary drivers to run the platform with the
      @@ -47,20 +47,22 @@
        * INCLUDE FILES
        ****************************************************************************************
        */
      +#include <stdint.h>        // standard integer definition
      +//#include "compiler.h"      // inline functions
       #include "hal_trace.h"
       
       /*
        * CPU WORD SIZE
        ****************************************************************************************
        */
      -/// APS3 is a 32-bit CPU
      +/// ARM is a 32-bit CPU
       #define CPU_WORD_SIZE   4
       
       /*
        * CPU Endianness
        ****************************************************************************************
        */
      -/// APS3 is little endian
      +/// ARM is little endian
       #define CPU_LE          1
       
       /*
      @@ -144,7 +146,7 @@ uint16_t get_stack_usage(void);
        */
       void platform_reset(uint32_t error);
       
      -#if (PLF_DEBUG)
      +#if PLF_DEBUG
       /**
        ****************************************************************************************
        * @brief Print the assertion error reason and loop forever.
      @@ -182,6 +184,15 @@ void assert_param(int param0, int param1, const char * file, int line);
       void assert_warn(int param0, int param1, const char * file, int line);
       
       
      +/**
      + ****************************************************************************************
      + * @brief Dump data value into FW.
      + *
      + * @param data start pointer of the data.
      + * @param length data size to dump
      + ****************************************************************************************
      + */
      +void dump_data(uint8_t* data, uint16_t length);
       #endif //PLF_DEBUG
       
       
      @@ -194,10 +205,10 @@ void assert_warn(int param0, int param1, const char * file, int line);
       #define ASSERT_ERR(cond)                             { if (!(cond)) { TRACE(2,"line is %d file is %s", __LINE__, __FILE__); } }
       
       /// Assertions showing a critical error that could require a full system reset
      -#define ASSERT_INFO(cond, param0, param1)            { if (!(cond)) { TRACE(4,"line is %d file is %s, %d, %d", __LINE__, __FILE__, param0, param1); } }
      +#define ASSERT_INFO(cond, param0, param1)            { if (!(cond)) { TRACE(2,"line is %d file is %s", __LINE__, __FILE__); } }
       
       /// Assertions showing a non-critical problem that has to be fixed by the SW
      -#define ASSERT_WARN(cond, param0, param1)            { if (!(cond)) { TRACE(4,"line is %d file is %s, %d, %d", __LINE__, __FILE__, param0, param1); } }
      +#define ASSERT_WARN(cond, param0, param1)            { if (!(cond)) { TRACE(2,"line is %d file is %s", __LINE__, __FILE__); } }
       
       #define DUMP_DATA(data, length) \
          // dump_data((uint8_t*)data, length)
      @@ -214,7 +225,7 @@ void assert_warn(int param0, int param1, const char * file, int line);
       
       /// DUMP data array present in the SW.
       #define DUMP_DATA(data, length)
      -#endif
      +#endif //PLF_DEBUG
       
       /// @} DRIVERS
       #endif // _ARCH_H_
  • services/ble_stack/ble_ip/compiler.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/ble_ip/compiler.h bes/services/ble_stack/ble_ip/compiler.h
      index 7794c628240..558091cbc10 100644
      --- a/services/ble_stack/ble_ip/compiler.h
      +++ b/services/ble_stack/ble_ip/compiler.h
      @@ -22,20 +22,29 @@
       /// define the static keyword for this compiler
       #define __STATIC static
       
      -/// define the BT IRQ handler attribute for this compiler
      +/// define the BLE IRQ handler attribute for this compiler
       #define __BTIRQ
       
       /// define the BLE IRQ handler attribute for this compiler
       #define __BLEIRQ
       
       /// define size of an empty array (used to declare structure with an array size not defined)
      -#define __ARRAY_EMPTY
      +#define __ARRAY_EMPTY 1
       
      +/// Function returns struct in registers (4 in rvds, var with gnuarm).
      +/// With Gnuarm, feature depends on command line options and
      +/// impacts ALL functions returning 2-words max structs
      +/// (check -freg-struct-return and -mabi=xxx)
      +#define __VIR
       
      +/// function has no side effect and return depends only on arguments
      +#define __PURE __attribute__((const))
       
      +/// Align instantiated lvalue or struct member on 4 bytes
      +#define __ALIGN4 __attribute__((aligned(4)))
       
       /// __MODULE__ comes from the RVDS compiler that supports it
      -#define __MODULE__ __BASENAME_FILE__
      +#define __MODULE__ __BASE_FILE__
       
       /// Pack a structure field
       #ifndef __PACKED
  • services/ble_stack/ble_ip/rwapp_config.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/ble_ip/rwapp_config.h bes/services/ble_stack/ble_ip/rwapp_config.h
      index 9f08718bccc..0bcfc5ab7e5 100644
      --- a/services/ble_stack/ble_ip/rwapp_config.h
      +++ b/services/ble_stack/ble_ip/rwapp_config.h
      @@ -63,13 +63,16 @@
       
       #ifdef VOICE_DATAPATH
       #define CFG_APP_VOICEPATH
      +#ifndef CFG_APP_SEC
      +#define CFG_APP_SEC
      +#endif
       #endif
       
       #ifdef TILE_DATAPATH
       #define CFG_APP_TILE
       #endif
       
      -#ifdef BES_OTA
      +#ifdef BES_OTA_BASIC
       #define CFG_APP_OTA
       #endif
       
      @@ -77,12 +80,27 @@
       #define CFG_APP_TOTA
       #endif
       
      +#ifdef __AI_VOICE__
       #ifndef CFG_APP_SEC
       #define CFG_APP_SEC
       #endif
      +#ifndef CFG_SEC_CON
      +#define CFG_SEC_CON
      +#endif
       
      +#define CFG_APP_AI_VOICE
      +#endif
       
      +#if defined(VOICE_DATAPATH) && defined(BISTO_ENABLED)
      +#define ANCS_PROXY_ENABLE 1
      +#else
      +#define ANCS_PROXY_ENABLE 0
      +#endif
       
      +#if ANCS_PROXY_ENABLE
      +#define CFG_APP_AMS
      +#define CFG_APP_ANCC
      +#endif
       
       #ifdef CHIP_FPGA1000
       #ifndef CFG_APP_SEC
      @@ -131,11 +149,11 @@
       #endif // defined(CFG_APP_TIME)
       
       /// Battery Service Application
      -#if defined(CFG_APP_BAS)
      +#if (BLE_APP_HID)
       #define BLE_APP_BATT          1
      -#else // defined(BLE_APP_BATT)
      +#else
       #define BLE_APP_BATT          0
      -#endif // defined(BLE_APP_BATT)
      +#endif // (BLE_APP_HID)
       
       /// Security Application
       #if (defined(CFG_APP_SEC) || BLE_APP_HID || defined(BLE_APP_AM0))
      @@ -171,18 +189,18 @@
       #endif // defined(CFG_APP_TOTA)
       
       /// ANCC Application
      -#if defined(ANCC_ENABLED)
      +#if defined(CFG_APP_ANCC)
       #define BLE_APP_ANCC    1
      -#else // defined(ANCC_ENABLED)
      +#else // defined(CFG_APP_ANCC)
       #define BLE_APP_ANCC    0
      -#endif // defined(ANCC_ENABLED)
      +#endif // defined(CFG_APP_ANCC)
       
       /// AMS Application
      -#if defined(AMS_ENABLED)
      +#if defined(CFG_APP_AMS)
       #define BLE_APP_AMS    1
      -#else // defined(AMS_ENABLED)
      +#else // defined(CFG_APP_AMS)
       #define BLE_APP_AMS    0
      -#endif // defined(AMS_ENABLED)
      +#endif // defined(CFG_APP_AMS)
       /// GFPS Application
       #if defined(CFG_APP_GFPS)
       #define BLE_APP_GFPS          1
  • services/ble_stack/ble_ip/rwble_hl_config.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/ble_ip/rwble_hl_config.h bes/services/ble_stack/ble_ip/rwble_hl_config.h
      index 5d9ac2292ae..5741c96753c 100644
      --- a/services/ble_stack/ble_ip/rwble_hl_config.h
      +++ b/services/ble_stack/ble_ip/rwble_hl_config.h
      @@ -20,8 +20,8 @@
       
       #define CFG_PRF
       #define CFG_NB_PRF (BLE_APP_OTA + BLE_APP_GFPS  + BLE_VOICEPATH + BLE_BMS + \
      -    BLE_ANC_CLIENT + BLE_AMS_CLIENT + BLE_ANCS_PROXY + BLE_AMS_PROXY + \
      -    BLE_APP_DATAPATH_SERVER + BLE_SMART_VOICE + BLE_APP_TOTA + BLE_APP_TILE)
      +    BLE_ANC_CLIENT + BLE_AMS_CLIENT + (ANCS_PROXY_ENABLE ? 2 : 0) + \
      +    BLE_APP_DATAPATH_SERVER + BLE_AI_VOICE + BLE_APP_TOTA + BLE_APP_TILE)
       
       /**
        ****************************************************************************************
      @@ -46,10 +46,8 @@
       
       #if BLE_APP_PRESENT
       #define APP_MAIN_TASK       TASK_APP
      -#elif AHI_TL_SUPPORT
      +#else // BLE_APP_PRESENT
       #define APP_MAIN_TASK       TASK_AHI
      -#else
      -#define APP_MAIN_TASK       TASK_NONE
       #endif // BLE_APP_PRESENT
       
       // Host Controller Interface (Host side)
      @@ -71,31 +69,58 @@
       #define BLE_GAPM                    1
       #if (BLE_CENTRAL || BLE_PERIPHERAL)
       #define BLE_GAPC                    1
      -// must be equals to sizeof(gapc_con_t)
      -#define BLE_GAPC_HEAP_ENV_SIZE      (120 + KE_HEAP_MEM_RESERVED)
      +#define BLE_GAPC_HEAP_ENV_SIZE      (sizeof(struct gapc_env_tag)  + KE_HEAP_MEM_RESERVED)
       #else //(BLE_CENTRAL || BLE_PERIPHERAL)
       #define BLE_GAPC                    0
       #define BLE_GAPC_HEAP_ENV_SIZE      0
       #endif //(BLE_CENTRAL || BLE_PERIPHERAL)
       
       #if (BLE_CENTRAL || BLE_PERIPHERAL)
      -#define BLE_L2CAP                   (1)
      -#define BLE_GATT_CLI                8
      -#define BLE_GATT                    8
      +#define BLE_L2CM                    1
      +#define BLE_L2CC                    1
      +#define BLE_ATTM                    1
      +#define BLE_GATTM                   1
      +#define BLE_GATTC                   1
      +#define BLE_GATTC_HEAP_ENV_SIZE     (sizeof(struct gattc_env_tag)  + KE_HEAP_MEM_RESERVED)
      +#define BLE_L2CC_HEAP_ENV_SIZE      (sizeof(struct l2cc_env_tag)   + KE_HEAP_MEM_RESERVED)
       #else //(BLE_CENTRAL || BLE_PERIPHERAL)
      -#define BLE_L2CAP                   0
      -#define BLE_GATT                    0
      -#define BLE_GATT_CLI                0
      -#define BLE_GATT_HEAP_ENV_SIZE      0
      -#define BLE_L2CAP_HEAP_ENV_SIZE     0
      +#define BLE_L2CM                    0
      +#define BLE_L2CC                    0
      +#define BLE_ATTC                    0
      +#define BLE_ATTS                    0
      +#define BLE_ATTM                    0
      +#define BLE_GATTM                   0
      +#define BLE_GATTC                   0
      +#define BLE_GATTC_HEAP_ENV_SIZE     0
      +#define BLE_L2CC_HEAP_ENV_SIZE      0
       #endif //(BLE_CENTRAL || BLE_PERIPHERAL)
       
      +#define BLE_SMPM                    1
      +#if (BLE_CENTRAL || BLE_PERIPHERAL)
      +#define BLE_SMPC                    1
      +#else //(BLE_CENTRAL || BLE_PERIPHERAL)
      +#define BLE_SMPC                    0
      +#endif //(BLE_CENTRAL || BLE_PERIPHERAL)
       
       
       /******************************************************************************************/
      -/* --------------------------   GATT              ----------------------------------------*/
      +/* --------------------------   ATT DB            ----------------------------------------*/
       /******************************************************************************************/
       
      +//ATT DB,Testing and Qualification related flags
      +#if (BLE_CENTRAL || BLE_PERIPHERAL)
      +    /// Support of External DB Management
      +    #if defined(CFG_EXT_DB)
      +        #define BLE_EXT_ATT_DB         1
      +    #else
      +        #define BLE_EXT_ATT_DB         0
      +    #endif // defined(CFG_EXT_DB)
      +#else
      +    #define BLE_EXT_ATT_DB         0
      +#endif // (BLE_CENTRAL || BLE_PERIPHERAL)
      +/******************************************************************************************/
      +/* --------------------------   PROFILES          ----------------------------------------*/
      +/******************************************************************************************/
       #ifdef CFG_PRF
       #define BLE_PROFILES      (1)
       /// Number of Profile tasks managed by GAP manager.
      @@ -107,10 +132,49 @@
       #define BLE_NB_PROFILES   (0)
       #endif // CFG_PRF
       
      +
      +#ifndef   BLE_ATTS
      +#if (BLE_CENTRAL || BLE_PERIPHERAL || defined(CFG_ATTS))
      +#define BLE_ATTS                    1
      +#else
      +#define BLE_ATTS                    0
      +#endif // (BLE_CENTRAL || BLE_PERIPHERAL || defined(CFG_ATTS))
      +#endif // BLE_ATTS
      +
      +
      +#ifndef   BLE_ATTC
      +#if (BLE_CENTRAL || defined(CFG_ATTC))
      +#define BLE_ATTC                    1
      +#else
      +#define BLE_ATTC                    0
      +#endif // (BLE_CENTRAL || defined(CFG_ATTC))
      +#endif // BLE_ATTC
      +
      +#ifndef   BLE_LECB
      +#if (BLE_CENTRAL || BLE_PERIPHERAL)
      +#define BLE_LECB                    1
      +#else
      +#define BLE_LECB                    0
      +#endif // (BLE_CENTRAL || defined(CFG_ATTC))
      +#endif // BLE_ATTC
      +
      +
      +/// Attribute Server
      +#if (BLE_ATTS)
      +#define BLE_ATTS                    1
      +#else
      +#define BLE_ATTS                    0
      +#endif //(BLE_ATTS)
      +
      +
       /// Size of the heap
       #if (BLE_CENTRAL || BLE_PERIPHERAL)
      -    /// Can be tuned based on supported profiles
      -    #define BLEHL_HEAP_DB_SIZE                     (3072)
      +    /// some heap must be reserved for attribute database
      +    #if (BLE_ATTS || BLE_ATTC)
      +        #define BLEHL_HEAP_DB_SIZE                 (1024)
      +    #else
      +        #define BLEHL_HEAP_DB_SIZE                 (0)
      +    #endif /* (BLE_ATTS || BLE_ATTC) */
       
       #define BLEHL_HEAP_MSG_SIZE                    (2048 + 256 * BLE_CONNECTION_MAX)
       #else
      @@ -126,8 +190,8 @@
       
       /// Size of environment variable needed on BLE Host Stack for one link
       #define BLEHL_HEAP_ENV_SIZE ( BLE_GAPC_HEAP_ENV_SIZE       +  \
      -                              BLE_GATT_HEAP_ENV_SIZE       +  \
      -                              BLE_L2CAP_HEAP_ENV_SIZE)
      +                              BLE_GATTC_HEAP_ENV_SIZE      +  \
      +                              BLE_L2CC_HEAP_ENV_SIZE)
       
       
       
      @@ -141,37 +205,43 @@
        */
       /// Maximum time to remain advertising when in the Limited
       /// Discover able mode: TGAP(lim_adv_timeout)
      -/// required value: 180s: (18000 in 10 ms step)
      -#define GAP_TMR_LIM_ADV_TIMEOUT                             0x4650 //(18000)
      +/// required value: 180s: (18000 for ke timer)
      +#define GAP_TMR_LIM_ADV_TIMEOUT                             0x4650
       
       /// Minimum time to perform scanning when performing
      -/// the General Discovery procedure on 1M PHY: TGAP(gen_disc_scan_min)
      -/// recommended value: 10.24s: (1024 in 10 ms step)
      -#define GAP_TMR_GEN_DISC_SCAN_1M                            0x0400 //(1024)
      +/// the General Discovery procedure: TGAP(gen_disc_scan_min)
      +/// recommended value: 10.24s: (1024 for ke timer)
      +#define GAP_TMR_GEN_DISC_SCAN                               0x0300
       
       /// Minimum time to perform scanning when performing the
      -/// Limited Discovery procedure on 1M PHY: TGAP(lim_disc_scan_min)
      -/// recommended value: 10.24s: (1024 in 10 ms step)
      -#define GAP_TMR_LIM_DISC_SCAN_1M                            0x0400 //(1024)
      +/// Limited Discovery procedure: TGAP(lim_disc_scan_min)
      +/// recommended value: 10.24s: (1024 for ke timer)
      +#define GAP_TMR_LIM_DISC_SCAN                               0x0300
       
       /// Minimum time interval between private address change
       /// TGAP(private_addr_int)
      -/// recommended value: 15 minutes
      -/// Minimum value 1s
      -#define GAP_TMR_PRIV_ADDR_MIN                             (0x0001)
      +/// recommended value: 15 minutes; 0x01F4 for PTS
      +/// 0x3A98 is 150 seconds; 0xEA60 is 10 minutes
      +#define GAP_TMR_PRIV_ADDR_INT                               0x3A98
       
       
      -/// L2CAP Signaling transaction Timer duration in milliseconds
      +/// Timer used in connection parameter update procedure
       /// TGAP(conn_param_timeout)
      -/// recommended value: 30 s: (30 000 ms)
      -#define GAP_SIG_TRANS_TIMEOUT_MS                          0x0BB8 //(30000)
      +/// recommended value: 30 s: (3000 for ke timer)
      +#define GAP_TMR_CONN_PARAM_TIMEOUT                          0x0BB8
       
      -/// SMP L2CAP transaction Timer duration in milliseconds  30 s: (30 000 ms)
      -#define GAP_SMP_TRANS_TIMEOUT_MS                          0x0BB8 //(30000)
      +/// Timer used in LE credit based connection procedure
      +/// TGAP(lecb_conn_timeout)
      +/// recommended value: 30 s: (3000 for ke timer)
      +#define GAP_TMR_LECB_CONN_TIMEOUT                           0x0BB8
       
      +/// Timer used in LE credit based disconnection procedure
      +/// TGAP(lecb_disconn_timeout)
      +/// recommended value: 30 s: (3000 for ke timer)
      +#define GAP_TMR_LECB_DISCONN_TIMEOUT                        0x0BB8
       
       /// Maximal authorized MTU value
      -#define GAP_LE_MTU_MAX                                     (2048)
      +#define GAP_MAX_LE_MTU                                     (2048)
       
       /// Maximum GAP device name size
       #define GAP_MAX_NAME_SIZE                                  (0x20)
      @@ -179,12 +249,16 @@
       
       
       
      -/// 30 seconds transaction timer (30000 ms)
      -#define GATT_TRANSACTION_TIMEOUT                           (0x0BB8) //(30000)
      +/// Maximum Transmission Unit
      +#define ATT_DEFAULT_MTU                                 (23)
      +/// 30 seconds transaction timer
      +#define ATT_TRANS_RTX                                   (0x0BB8)
      +/// Acceptable encryption key size - strict access
      +#define ATT_SEC_ENC_KEY_SIZE                            (0x10)
       
       
       /// Maximum attribute value length
      -#define GATT_MAX_VALUE                                     (GAP_LE_MTU_MAX)
      +#define ATT_MAX_VALUE                                   (GAP_MAX_LE_MTU)
       
       
       /// @} BLE stack configuration
  • services/ble_stack/ble_ip/rwble_hl.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/ble_ip/rwble_hl.h bes/services/ble_stack/ble_ip/rwble_hl.h
      index 765108f6530..736c5dc74d0 100644
      --- a/services/ble_stack/ble_ip/rwble_hl.h
      +++ b/services/ble_stack/ble_ip/rwble_hl.h
      @@ -46,13 +46,15 @@
        * @brief Initialize the BLE Host stack.
        ****************************************************************************************
        */
      -void rwble_hl_init(uint8_t init_type);
      +void rwble_hl_init(void);
       
       /**
        ****************************************************************************************
      + * @brief Initialize the host (reset requested)
        *
        ****************************************************************************************
        */
      +void rwble_hl_reset(void);
       
       /// @} RWBLE_HL
       
  • services/ble_stack/ble_ip/rwip_config.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/ble_ip/rwip_config.h bes/services/ble_stack/ble_ip/rwip_config.h
      index 8c3464b5e83..f660daa12e8 100644
      --- a/services/ble_stack/ble_ip/rwip_config.h
      +++ b/services/ble_stack/ble_ip/rwip_config.h
      @@ -44,8 +44,9 @@
       #include "cmsis.h"
       #include "besble_debug.h"
       
      +//#if (__IAG_BLE_INCLUDE__ == XA_ENABLED)
       
      -#if defined(__IAG_BLE_INCLUDE__)
      +#ifdef __IAG_BLE_INCLUDE__
       #ifndef FPGA
       #define _BLE_NVDS_
       #endif
      @@ -53,6 +54,10 @@
       #define CFG_HOST
       #define CFG_APP
       
      +#if defined(BISTO_ENABLED)
      +#ifndef CFG_APP_SEC
      +#define CFG_APP_SEC
      +#endif
       
       #define CFG_SEC_CON
       #endif
      @@ -62,42 +67,62 @@
       #define GLOBAL_INT_RESTORE() int_unlock(lock); } while(0);
       
       /******************************************************************************************/
      -/* -------------------------   STACK PARTITIONING      -----------------------------------*/
      +/* --------------------------   GENERAL SETUP       --------------------------------------*/
       /******************************************************************************************/
       
      +/// Flag indicating if stack is compiled in dual or single mode
       #if defined(CFG_BT)
      -#define BT_EMB_PRESENT              1
      -#else // defined(CFG_BT)
      -#define BT_EMB_PRESENT              0
      -#endif // defined(CFG_BT)
      -
      -#if defined(CFG_BLE) && defined(CFG_EMB)
      -#define BLE_EMB_PRESENT             1
      -#else // defined(CFG_BLE) && defined(CFG_EMB)
      -#define BLE_EMB_PRESENT             0
      -#endif // defined(CFG_BLE) && defined(CFG_EMB)
      -
      -#if defined(CFG_BLE) && defined(CFG_HOST)
      -#define BLE_HOST_PRESENT            1
      -#else // defined(CFG_BLE) && defined(CFG_HOST)
      -#define BLE_HOST_PRESENT            0
      -#endif // defined(CFG_BLE) && defined(CFG_HOST)
      -
      -#if defined(CFG_BLE) && defined(CFG_APP)
      -#define BLE_APP_PRESENT             1
      -#else // defined(CFG_BLE) && defined(CFG_APP)
      -#define BLE_APP_PRESENT             0
      -#endif // defined(CFG_BLE) && defined(CFG_APP)
      -
      -#define BT_DUAL_MODE                (BT_EMB_PRESENT && BLE_EMB_PRESENT)
      -#define HCI_PRESENT                 1
      -
      -/// Flag indicating that Mesh is supported
      -#if defined(CFG_BLE_MESH)
      -#define BLE_MESH      1
      -#else  // !defined(CFG_BLE_MESH)
      -#define BLE_MESH      0
      -#endif // defined(CFG_BLE_MESH)
      +    #define BLE_STD_MODE                     0
      +    #if defined(CFG_BLE)
      +        #define BT_DUAL_MODE                 1
      +        #define BT_STD_MODE                  0
      +    #else // CFG_BLE
      +        #define BT_DUAL_MODE                 0
      +        #define BT_STD_MODE                  1
      +    #endif // CFG_BLE
      +#elif defined(CFG_BLE)
      +    #define BT_DUAL_MODE                     0
      +    #define BT_STD_MODE                      0
      +    #define BLE_STD_MODE                     1
      +#endif // CFG_BT
      +
      +/******************************************************************************************/
      +/* -------------------------   STACK PARTITIONING      -----------------------------------*/
      +/******************************************************************************************/
      +
      +#if (BT_DUAL_MODE)
      +    #define BT_EMB_PRESENT              1
      +    #define BLE_EMB_PRESENT             1
      +    #define HCI_PRESENT                 1
      +    #define BLE_HOST_PRESENT            0
      +    #define BLE_APP_PRESENT             0
      +#elif (BT_STD_MODE)
      +    #define BT_EMB_PRESENT              1
      +    #define BLE_EMB_PRESENT             0
      +    #define HCI_PRESENT                 1
      +    #define BLE_HOST_PRESENT            0
      +    #define BLE_APP_PRESENT             0
      +#elif (BLE_STD_MODE)
      +    #define BT_EMB_PRESENT              0
      +    #define HCI_PRESENT                 1
      +    #if defined(CFG_EMB)
      +        #define BLE_EMB_PRESENT         1
      +    #else
      +        #define BLE_EMB_PRESENT         0
      +    #endif //CFG_EMB
      +    #if defined(CFG_HOST)
      +        #define BLE_HOST_PRESENT        1
      +    #else
      +        #define BLE_HOST_PRESENT        0
      +    #endif //CFG_HOST
      +    #if defined(CFG_APP)
      +        #define BLE_APP_PRESENT         1
      +    #else
      +        #define BLE_APP_PRESENT         0
      +    #endif //CFG_APP
      +#endif // BT_DUAL_MODE / BT_STD_MODE / BLE_STD_MODE
      +
      +#define EA_PRESENT                      (BT_EMB_PRESENT || BLE_EMB_PRESENT)
       
       /******************************************************************************************/
       /* -------------------------   INTERFACES DEFINITIONS      -------------------------------*/
      @@ -122,11 +147,17 @@
       
       
       #if BLE_HOST_PRESENT
      -#define H4TL_SUPPORT      ((AHI_TL_SUPPORT) + (HCI_TL_SUPPORT))
      +#if BLE_EMB_PRESENT
      +#define H4TL_SUPPORT      (AHI_TL_SUPPORT)
      +#else // !BLE_EMB_PRESENT
      +#define H4TL_SUPPORT      0//((AHI_TL_SUPPORT) + (HCI_TL_SUPPORT))
      +#endif // BLE_EMB_PRESENT
       #else // !BLE_HOST_PRESENT
       #define H4TL_SUPPORT      (HCI_TL_SUPPORT)
       #endif // BLE_HOST_PRESENT
       
      +/// TCI LMP trace support
      +#define TCI_LMP_ENABLED                             0
       
       /******************************************************************************************/
       /* --------------------------   BLE COMMON DEFINITIONS      ------------------------------*/
      @@ -135,46 +166,59 @@
       #define KE_HEAP_MEM_RESERVED        (4)
       
       #define CFG_ALLROLES
      -#define CFG_PERIPHERAL
       
       #if defined(CFG_BLE)
      +/// Application role definitions
      +#define BLE_BROADCASTER  (defined(CFG_BROADCASTER) || defined(CFG_PERIPHERAL) || defined(CFG_ALLROLES))
      +#define BLE_OBSERVER     (defined(CFG_OBSERVER)    || defined(CFG_CENTRAL)    || defined(CFG_ALLROLES))
      +#define BLE_PERIPHERAL   (defined(CFG_PERIPHERAL)  || defined(CFG_ALLROLES))
      +#define BLE_CENTRAL      (defined(CFG_CENTRAL)     || defined(CFG_ALLROLES))
       
      -/// Broadcaster
      -#if (defined(CFG_BROADCASTER) || defined(CFG_PERIPHERAL) || defined(CFG_ALLROLES))
      -#define BLE_BROADCASTER      1
      -#else
      -#define BLE_BROADCASTER      0
      -#endif // (defined(CFG_BROADCASTER) || defined(CFG_PERIPHERAL) || defined(CFG_ALLROLES))
      -/// Observer
      -#if (defined(CFG_OBSERVER) || defined(CFG_CENTRAL) || defined(CFG_ALLROLES))
      -#define BLE_OBSERVER      1
      -#else
      -#define BLE_OBSERVER      0
      -#endif // (defined(CFG_OBSERVER) || defined(CFG_CENTRAL) || defined(CFG_ALLROLES))
      -/// Peripheral
      -#if (defined(CFG_PERIPHERAL) || defined(CFG_ALLROLES))
      -#define BLE_PERIPHERAL      1
      -#else
      -#define BLE_PERIPHERAL      0
      -#endif // (defined(CFG_PERIPHERAL) || defined(CFG_ALLROLES))
      -/// Central
      -#if (defined(CFG_CENTRAL) || defined(CFG_ALLROLES))
      -#define BLE_CENTRAL      1
      -#else
      -#define BLE_CENTRAL      0
      -#endif // (defined(CFG_CENTRAL) || defined(CFG_ALLROLES))
      -
      -#if ((BLE_BROADCASTER+BLE_OBSERVER+BLE_PERIPHERAL+BLE_CENTRAL) == 0)
      +#if (!BLE_BROADCASTER) && (!BLE_OBSERVER) && (!BLE_PERIPHERAL) && (!BLE_CENTRAL)
           #error "No application role defined"
      -#endif // ((BLE_BROADCASTER+BLE_OBSERVER+BLE_PERIPHERAL+BLE_CENTRAL) == 0)
      +#endif /* #if (!BLE_BROADCASTER) && (!BLE_OBSERVER) && (!BLE_PERIPHERAL) && (!BLE_CENTRAL) */
       
       /// Maximum number of simultaneous BLE activities (scan, connection, advertising, initiating)
      -#define BLE_ACTIVITY_MAX          (BES_BLE_ACTIVITY_MAX)
      +#define BLE_ACTIVITY_MAX        (BLE_CONNECTION_MAX)
       
      +/// Maximum number of audio connections
      +#if defined(CFG_AUDIO)
      +#if (BLE_CENTRAL || BLE_PERIPHERAL)
      +#define BLE_AUDIO      (1)
      +#define BLE_AUDIO_CONNECT_MAX    (CFG_AUDIO_CON)
      +#else
      +#define BLE_AUDIO      (0)
      +#endif /*(BLE_CENTRAL || BLE_PERIPHERAL)*/
      +#else
      +#define BLE_AUDIO      (0)
      +#endif /*defined(CFG_AUDIO)*/
       
       /// Max advertising reports before sending the info to the host
      -#define BLE_ADV_REPORTS_MAX             (1)
      -
      +#define BLE_ADV_REPORTS_MAX             1
      +
      +/// Define Number of AUDIO TX/RX buffers per voice channel
      +#if (BLE_AUDIO)
      +    #if defined(CFG_AUDIO_AOAHI)
      +        // 3 buffers per connection using audio over AHI TL
      +        #define BLE_NB_INPUT_BUFF_PER_VC          (3)
      +        #define BLE_NB_OUTPUT_BUFF_PER_VC         (3)
      +    #else // defined(CFG_AUDIO_AOAHI)
      +        // 2 buffers if a codec is available
      +        #define BLE_NB_INPUT_BUFF_PER_VC          (2)
      +        #define BLE_NB_OUTPUT_BUFF_PER_VC         (2)
      +    #endif // defined(CFG_AUDIO_AOAHI)
      +    // add one more buffer for fake reception and fake transmit
      +    #define BLE_TX_AUDIO_BUFFER_CNT   ((BLE_AUDIO_CONNECT_MAX * BLE_NB_INPUT_BUFF_PER_VC)  + 1)
      +    #define BLE_RX_AUDIO_BUFFER_CNT   ((BLE_AUDIO_CONNECT_MAX * BLE_NB_OUTPUT_BUFF_PER_VC) + 1)
      +#endif // (BLE_AUDIO)
      +
      +#define CFG_DEPRECATED_API
      +/// Support of Legacy Air Operations
      +#if defined(CFG_DEPRECATED_API)
      +#define BLE_DEPRECATED_API      (1)
      +#else //defined(CFG_DEPRECATED_API)
      +#define BLE_DEPRECATED_API      (0)
      +#endif //defined(CFG_DEPRECATED_API)
       #endif //defined(CFG_BLE)
       
       
      @@ -199,7 +243,7 @@
       #define RTC_SUPPORT      1
       #else
       #define RTC_SUPPORT      0
      -#endif //CFG_RTC
      +#endif //CFG_DISPLAY
       
       /******************************************************************************************/
       /* --------------------------      PS2 SETUP         -------------------------------------*/
      @@ -229,7 +273,7 @@
       /******************************************************************************************/
       
       /// Use 32K Hz Clock if set to 1 else 32,768k is used
      -#define HZ32000                                     (GAIA_SUPPORT)
      +#define HZ32000                                     0
       
       /// Time to wake-up Radio Module (in us)
       #define SLEEP_RM_WAKEUP_DELAY                       625
      @@ -254,10 +298,10 @@
       #if defined(CFG_RF_ATLAS)
       #define BLE_PHY_1MBPS_SUPPORT                       1
       #define BLE_PHY_2MBPS_SUPPORT                       1
      -#define BLE_PHY_CODED_SUPPORT                       1
      -#else // RIPPLE
      +#define BLE_PHY_CODED_SUPPORT                       0
      +#else
       #define BLE_PHY_1MBPS_SUPPORT                       1
      -#define BLE_PHY_2MBPS_SUPPORT                       0
      +#define BLE_PHY_2MBPS_SUPPORT                       1
       #define BLE_PHY_CODED_SUPPORT                       1
       #endif
       
      @@ -283,7 +327,19 @@
           #define RW_MWS_COEX_TEST            0
       #endif // defined(CFG_MWS_COEX)
       
      +/******************************************************************************************/
      +/* -------------------------   DM ARBITRATION SETUP      ---------------------------------*/
      +/******************************************************************************************/
       
      +#if BT_DUAL_MODE
      +/**
      + * Dual mode arbitration margin (in us)
      + *
      + * BREDRMARGIN/BLEMARGIN corresponding to a timing value that allows the RF to power-down properly before any other
      + * activity. This is radio dependent.
      + */
      +#define DM_ARB_MARGIN      40
      +#endif //BT_DUAL_MODE
       
       /******************************************************************************************/
       /* --------------------   SECURE CONNECTIONS SETUP  --------------------------------------*/
      @@ -340,6 +396,10 @@
           #define RW_DEBUG_STACK_PROF             0
       #endif // defined (CFG_DBG_STACK_PROF)
       
      +/// Modem back to back setup
      +#define MODEM2MODEM                          0
      +/// Special clock testing
      +#define CLK_WRAPPING                         0
       
       /******************************************************************************************/
       /* --------------------------      NVDS SETUP       --------------------------------------*/
      @@ -358,11 +418,17 @@
       /// Manufacturer: RivieraWaves SAS
       #define RW_COMP_ID                           0x0060
       
      +/// Bluetooth technologies version
      +#define RW_BT40_VERSION                      (6)
      +#define RW_BT41_VERSION                      (7)
      +#define RW_BT42_VERSION                      (8)
      +#define RW_BT50_VERSION                      (9)
       
       /******************************************************************************************/
       /* -------------------------   BT / BLE / BLE HL CONFIG    -------------------------------*/
       /******************************************************************************************/
       
      +#if 0
       #if (BT_EMB_PRESENT)
       #include "rwbt_config.h"    // bt stack configuration
       #endif //BT_EMB_PRESENT
      @@ -370,13 +436,18 @@
       #if (BLE_EMB_PRESENT)
       #include "rwble_config.h"   // ble stack configuration
       #endif //BLE_EMB_PRESENT
      +#endif
       
       #if (BLE_HOST_PRESENT)
       #include "rwble_hl_config.h"  // ble Host stack configuration
       #endif //BLE_HOST_PRESENT
       
      +#if defined(CFG_AUDIO_AM0)
      +#include "rwam0_config.h"     // Audio Mode 0 configuration
      +#endif // defined(CFG_AUDIO_AM0)
      +
       #if defined(CFG_APP)
      -//#include "rwapp_config.h"     // Application configuration
      +//#include "rwapp_config.h"     // Audio Mode 0 configuration
       #endif // defined(CFG_APP)
       
       #define BLE_INVALID_CONNECTION_INDEX    0xFF
      @@ -399,13 +470,21 @@
       /// Event types definition
       enum KE_EVENT_TYPE
       {
      +    KE_EVENT_KE_MESSAGE      ,
           KE_EVENT_KE_TIMER        ,
           #if (TRACER_PRESENT)
           KE_EVENT_TRC             ,
           #endif /*(TRACER_PRESENT)*/
       
      -    KE_EVENT_KE_MESSAGE      ,
      +    #if (AHI_TL_SUPPORT)
      +    KE_EVENT_AHI_TX_DONE     ,
      +    #endif //(AHI_TL_SUPPORT)
       
      +    #if (BLE_HOST_PRESENT)
      +    #if (BLE_L2CC)
      +    KE_EVENT_L2CAP_TX        ,
      +    #endif //(BLE_L2CC)
      +    #endif// (BLE_HOST_PRESENT)
       
           KE_EVENT_MAX             ,
       };
      @@ -418,14 +497,18 @@ enum KE_TASK_TYPE
       #endif // (BLE_APP_PRESENT)
       
       #if (BLE_HOST_PRESENT)
      -    TASK_L2CAP,   // L2CAP Task
      -    TASK_GATT,    // Generic Attribute Profile
      -    TASK_GAPM,    // Generic Access Profile Manager
      +    TASK_L2CC,    // L2CAP Controller Task
      +    TASK_GATTM,   // Generic Attribute Profile Manager Task
      +    TASK_GATTC,   // Generic Attribute Profile Controller Task
      +    TASK_GAPM,    // Generic Access Profile Manager, 4
           TASK_GAPC,    // Generic Access Profile Controller
       
           // allocate a certain number of profiles task
           TASK_PRF_MAX = (TASK_GAPC + BLE_NB_PROFILES),
       
      +    #ifdef BLE_AUDIO_AM0_TASK
      +    TASK_AM0,     // BLE Audio Mode 0 Task
      +    #endif // BLE_AUDIO_AM0_TASK
       #endif // (BLE_HOST_PRESENT)
       
       #if (AHI_TL_SUPPORT)
      @@ -433,13 +516,13 @@ enum KE_TASK_TYPE
       #endif // (AHI_TL_SUPPORT)
       
           /// Maximum number of tasks
      -    TASK_MAX,
      +    TASK_MAX = 0xFE,
       
           TASK_NONE = 0xFF,
       };
       
       /// Kernel memory heaps types.
      -enum KE_MEM_HEAP
      +enum
       {
           /// Memory allocated for environment variables
           KE_MEM_ENV,
      @@ -488,35 +571,24 @@ enum KE_MEM_HEAP
                                           BLE_HEAP_MSG_SIZE_     + \
                                           BLEHL_HEAP_MSG_SIZE_      )
       
      +/// Number of link in kernel environment
      +#define KE_NB_LINK_IN_HEAP_ENV   4
       
       /// Size of Environment heap
       #define RWIP_HEAP_ENV_SIZE         ( BT_HEAP_ENV_SIZE_         + \
      -                                     BLE_HEAP_ENV_SIZE_      + \
      -                                     BLEHL_HEAP_ENV_SIZE_ )
      -
      +                                     ( BLE_HEAP_ENV_SIZE_      + \
      +                                       BLEHL_HEAP_ENV_SIZE_ )    \
      +                                     * KE_NB_LINK_IN_HEAP_ENV )
       
       /// Size of Attribute database heap
      -#define RWIP_HEAP_DB_SIZE         (  BLEHL_HEAP_DB_SIZE_  )
      +#define RWIP_HEAP_DB_SIZE         (  BLEHL_HEAP_DB_SIZE  )
       
      -/**
      - * Size of non-retention heap
      - *
      - * This heap can be used to split the RAM into 2 parts:
      - *    - an always-on part that can handle a certain number of links
      - *    - a secondary memory that could be powered-off when not used, and retained only when used
      - *
      - * With such mechanism, the previous heaps need to be reduced so that they can contain all required data
      - * in a light scenario (few connections, few profiles). Then the non-retention heap is sized in order to
      - * cover the worst case scenario (max connections, max profiles, etc ...)
      - *
      - * The current size show what is already known as not needing to be retained during deep sleep.
      - */
      -#if (BT_EMB_PRESENT || BLE_EMB_PRESENT)
      -#define ECC_HEAP_NON_RET_SIZE_   (328*2) // Could only have 2 ECC computations simultaneously
      -#else // (BT_EMB_PRESENT || BLE_EMB_PRESENT)
      -#define ECC_HEAP_NON_RET_SIZE_   (0)
      -#endif // (BT_EMB_PRESENT || BLE_EMB_PRESENT)
      -#define RWIP_HEAP_NON_RET_SIZE    ( ECC_HEAP_NON_RET_SIZE_ )
      +/// Size of non retention heap - 512 bytes per ble link plus 4096 bytes for data throughput should be sufficient and should be tuned
      +#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
      +#define RWIP_HEAP_NON_RET_SIZE    (( 512 * BLE_CONNECTION_MAX ) + 4096)
      +#else
      +#define RWIP_HEAP_NON_RET_SIZE    ( 1024 )
      +#endif
       
       /// Minimum sleep time to enter in deep sleep (in half slot).
       #define RWIP_MINIMUM_SLEEP_TIME                (1)
      @@ -533,12 +605,14 @@ enum PARAM_ID
           PARAM_ID_BD_ADDRESS                 = 0x01,
           /// Device Name
           PARAM_ID_DEVICE_NAME                = 0x02,
      -    /// Low Power Clock Drift
      +    /// Radio Drift
           PARAM_ID_LPCLK_DRIFT                = 0x07,
      -    /// Low Power Clock Jitter
      -    /// Active Clock Drift
      -    PARAM_ID_ACTCLK_DRIFT               = 0x09,
      +    /// Radio Jitter
           PARAM_ID_LPCLK_JITTER               = 0x08,
      +    /// Radio Class
      +    PARAM_ID_RADIO_CLASS                = 0x09,
      +    /// Bluejay specific Settings
      +    PARAM_ID_BJ_TXCNTL1                 = 0x0A,
           /// External wake-up time
           PARAM_ID_EXT_WAKEUP_TIME            = 0x0D,
           /// Oscillator wake-up time
      @@ -555,6 +629,15 @@ enum PARAM_ID
           PARAM_ID_SP_PRIVATE_KEY_P192        = 0x13,
           /// SP Public Key 192
           PARAM_ID_SP_PUBLIC_KEY_P192         = 0x14,
      +    /// Errata adopted check
      +    PARAM_ID_ERRATA_ADOPTED             = 0x15,
      +    /// CQDDR Tags
      +    PARAM_ID_BASIC_THRESHOLD            = 0x16,
      +    PARAM_ID_EDR_THRESHOLD              = 0x17,
      +    PARAM_ID_BASIC_ALGORITHM            = 0x18,
      +    PARAM_ID_EDR_ALGORITHM              = 0x19,
      +    PARAM_ID_BASIC_PACKET_LUT           = 0x2A,
      +    PARAM_ID_EDR_PACKET_LUT             = 0x2B,
           /// Synchronous links configuration
           PARAM_ID_SYNC_CONFIG                = 0x2C,
           /// PCM Settings
      @@ -573,7 +656,22 @@ enum PARAM_ID
           PARAM_ID_RSSI_LOW_THR               = 0x3B,
           PARAM_ID_RSSI_INTERF_THR            = 0x3C,
       
      +    /// BLE Channel Assessment tags
      +    PARAM_ID_BLE_CA_TIMER_DUR           = 0x40,
      +    PARAM_ID_BLE_CRA_TIMER_CNT          = 0x41,
      +    PARAM_ID_BLE_CA_MIN_THR             = 0x42,
      +    PARAM_ID_BLE_CA_MAX_THR             = 0x43,
      +    PARAM_ID_BLE_CA_NOISE_THR           = 0x44,
       
      +    /// AFH algorithm tags
      +    PARAM_ID_AFH_REASS_NBCH             = 0x51,
      +    PARAM_ID_AFH_WINLGTH                = 0x52,
      +    PARAM_ID_AFH_RSSIMIN                = 0x53,
      +    PARAM_ID_AFH_PERTHRESBAD            = 0x54,
      +    PARAM_ID_AFH_REASS_INT              = 0x55,
      +    PARAM_ID_AFH_NMIN                   = 0x56,
      +    PARAM_ID_AFH_MAXADAPT               = 0x57,
      +    PARAM_ID_AFH_THSMIN                 = 0x58,
       
       
           PARAM_ID_BT_LINK_KEY_FIRST          = 0x60,
      @@ -609,8 +707,10 @@ enum PARAM_LEN
            PARAM_LEN_LPCLK_DRIFT                = 2,
            /// Low power clock jitter
            PARAM_LEN_LPCLK_JITTER               = 1,
      -     /// Active clock drift
      -     PARAM_LEN_ACTCLK_DRIFT               = 1,
      +     /// Radio Class
      +     PARAM_LEN_RADIO_CLASS                = 1,
      +     /// Bluejay specific Settings
      +     PARAM_LEN_BJ_TXCNTL1                 = 4,
       
       
            /// External wake-up time
      @@ -629,6 +729,15 @@ enum PARAM_LEN
            PARAM_LEN_SP_PRIVATE_KEY_P192        = 24,
            /// SP Public Key 192
            PARAM_LEN_SP_PUBLIC_KEY_P192         = 48,
      +     /// Errata adopted check
      +     PARAM_LEN_ERRATA_ADOPTED             = 1,
      +     /// CQDDR Tags
      +     PARAM_LEN_BASIC_THRESHOLD            = 70,
      +     PARAM_LEN_EDR_THRESHOLD              = 70,
      +     PARAM_LEN_BASIC_ALGORITHM            = 21,
      +     PARAM_LEN_EDR_ALGORITHM              = 21,
      +     PARAM_LEN_BASIC_PACKET_LUT           = 16,
      +     PARAM_LEN_EDR_PACKET_LUT             = 16,
            /// Synchronous links configuration
            PARAM_LEN_SYNC_CONFIG                = 2,
            /// PCM Settings
      @@ -642,7 +751,21 @@ enum PARAM_LEN
            PARAM_LEN_RSSI_THR                   = 1,
       
       
      -
      +     PARAM_LEN_BLE_CA_TIMER_DUR           = 2,
      +     PARAM_LEN_BLE_CRA_TIMER_CNT          = 1,
      +     PARAM_LEN_BLE_CA_MIN_THR             = 1,
      +     PARAM_LEN_BLE_CA_MAX_THR             = 1,
      +     PARAM_LEN_BLE_CA_NOISE_THR           = 1,
      +
      +     /// AFH algorithm tags
      +     PARAM_LEN_AFH_REASS_NBCH             = 1,
      +     PARAM_LEN_AFH_WINLGTH                = 1,
      +     PARAM_LEN_AFH_RSSIMIN                = 1,
      +     PARAM_LEN_AFH_PERTHRESBAD            = 1,
      +     PARAM_LEN_AFH_REASS_INT              = 1,
      +     PARAM_LEN_AFH_NMIN                   = 1,
      +     PARAM_LEN_AFH_MAXADAPT               = 1,
      +     PARAM_LEN_AFH_THSMIN                 = 1,
            /// Link keys
            PARAM_LEN_BT_LINK_KEY                = 22,
            PARAM_LEN_BLE_LINK_KEY               = 48,
      @@ -683,13 +806,19 @@ enum PARAM_LEN
       /// Do not abort busy position
       #define RWIP_DNABORT_POS        2
       
      -/// SAM disabled
      -#define RWIP_SAM_DIS            0
      -/// SAM enabled
      -#define RWIP_SAM_EN             1
      -/// SAM enable position
      -#define RWIP_SAMEN_POS          3
      +///Allows Tx operation in the current frame.
      +#define RWIP_MWS_TXEN           0
      +///Prevent from any Tx operation in the current frame.
      +#define RWIP_MWS_TXDIS          1
      +/// MWS transmit disable position
      +#define RWIP_MWSTXDSB_POS       3
       
      +///Allows Rx operation in the current frame.
      +#define RWIP_MWS_RXEN           0
      +///Prevent from any Rx operation in the current frame.
      +#define RWIP_MWS_RXDIS          1
      +/// MWS transmit disable position
      +#define RWIP_MWSRXDSB_POS       4
       
       /// Bit masking
       #define RWIP_COEX_BIT_MASK      1
      @@ -774,10 +903,10 @@ enum rwip_prio_idx
           RWIP_PRIO_SCAN_IDX,
           /// Default priority for initiating events
           RWIP_PRIO_INIT_IDX,
      -    /// LE connection events default priority
      -    RWIP_PRIO_CONNECT_DFT_IDX,
      -    /// LE connection events priority with activity
      -    RWIP_PRIO_CONNECT_ACT_IDX,
      +    /// Default priority for master connect events
      +    RWIP_PRIO_MCONNECT_IDX,
      +    /// Default priority for slave connect events
      +    RWIP_PRIO_SCONNECT_IDX,
           /// Default priority for advertising events
           RWIP_PRIO_ADV_IDX,
           /// Default priority for advertising high duty cycle events
      @@ -792,125 +921,125 @@ enum rwip_prio_dft
       {
           #if (BT_EMB_PRESENT)
           /// ACL event default priority
      -    RWIP_PRIO_ACL_DFT               = 40,
      +    RWIP_PRIO_ACL_DFT               = 5,
           /// ACL event priority with activity
      -    RWIP_PRIO_ACL_ACT               = 80,
      +    RWIP_PRIO_ACL_ACT               = 10,
           /// ACL Role Switch event default priority
      -    RWIP_PRIO_ACL_RSW               = 160,
      +    RWIP_PRIO_ACL_RSW               = 20,
           /// ACL sniff event default priority
      -    RWIP_PRIO_ACL_SNIFF_DFT         = 120,
      +    RWIP_PRIO_ACL_SNIFF_DFT         = 15,
           /// ACL sniff transition event default priority
      -    RWIP_PRIO_ACL_SNIFF_TRANS       = 80,
      +    RWIP_PRIO_ACL_SNIFF_TRANS       = 10,
           #if MAX_NB_SYNC
           /// SCO event default priority
      -    RWIP_PRIO_SCO_DFT               = 144,
      +    RWIP_PRIO_SCO_DFT               = 18,
           #endif //MAX_NB_SYNC
           /// Broadcast ACL event default priority
      -    RWIP_PRIO_BCST_DFT              = 40,
      +    RWIP_PRIO_BCST_DFT              = 5,
           /// Broadcast ACL event with LMP activity priority
      -    RWIP_PRIO_BCST_ACT              = 80,
      +    RWIP_PRIO_BCST_ACT              = 10,
           /// CSB RX event default priority
      -    RWIP_PRIO_CSB_RX_DFT            = 80,
      +    RWIP_PRIO_CSB_RX_DFT            = 10,
           /// CSB TX event default priority
      -    RWIP_PRIO_CSB_TX_DFT            = 80,
      +    RWIP_PRIO_CSB_TX_DFT            = 10,
           /// Inquiry event default priority
      -    RWIP_PRIO_INQ_DFT               = 40,
      +    RWIP_PRIO_INQ_DFT               = 5,
           /// Inquiry Scan event default priority
      -    RWIP_PRIO_ISCAN_DFT             = 40,
      +    RWIP_PRIO_ISCAN_DFT             = 5,
           /// Page event default priority
      -    RWIP_PRIO_PAGE_DFT              = 64,
      +    RWIP_PRIO_PAGE_DFT              = 8,
           /// Page first packet event default priority
      -    RWIP_PRIO_PAGE_1ST_PKT          = 160,
      +    RWIP_PRIO_PAGE_1ST_PKT          = 20,
           /// PCA event default priority
      -    RWIP_PRIO_PCA_DFT               = 160,
      +    RWIP_PRIO_PCA_DFT               = 20,
           /// Page scan event default priority
      -    RWIP_PRIO_PSCAN_DFT             = 64,
      +    RWIP_PRIO_PSCAN_DFT             = 8,
           /// Page scan event priority increment when canceled
      -    RWIP_PRIO_PSCAN_1ST_PKT         = 160,
      +    RWIP_PRIO_PSCAN_1ST_PKT         = 20,
           /// Synchronization Scan event default priority
      -    RWIP_PRIO_SSCAN_DFT             = 80,
      +    RWIP_PRIO_SSCAN_DFT             = 10,
           /// Synchronization Train event default priority
      -    RWIP_PRIO_STRAIN_DFT            = 80,
      +    RWIP_PRIO_STRAIN_DFT            = 10,
           #endif //#if (BT_EMB_PRESENT)
           #if (BLE_EMB_PRESENT)
           /// Default priority for scanning events
      -    RWIP_PRIO_SCAN_DFT              = 40,
      +    RWIP_PRIO_SCAN_DFT              = 5,
           /// Default priority for initiating events
      -    RWIP_PRIO_INIT_DFT              = 80,
      -    /// LE connection events default priority
      -    RWIP_PRIO_CONNECT_DFT           = 112,
      -    /// LE connection events priority with activity
      -    RWIP_PRIO_CONNECT_ACT           = 128,
      +    RWIP_PRIO_INIT_DFT              = 10,
      +    /// Default priority for master connect events
      +    RWIP_PRIO_MCONNECT_DFT          = 15,
      +    /// Default priority for slave connect events
      +    RWIP_PRIO_SCONNECT_DFT          = 15,
           /// Default priority for advertising events
      -    RWIP_PRIO_ADV_DFT               = 40,
      +    RWIP_PRIO_ADV_DFT               = 5,
           /// Default priority for advertising high duty cycle events
      -    RWIP_PRIO_ADV_HDC_DFT           = 80,
      +    RWIP_PRIO_ADV_HDC_DFT           = 10,
           /// Default priority for resolvable private addresses renewal event
      -    RWIP_PRIO_RPA_RENEW_DFT         = 80,
      +    RWIP_PRIO_RPA_RENEW_DFT         = 10,
           #endif // #if (BLE_EMB_PRESENT)
           /// Max priority
      -    RWIP_PRIO_MAX                   = 255,
      +    RWIP_PRIO_MAX                   = 31,
       };
       /// Default increment value definition
       enum rwip_incr_dft
       {
           #if (BT_EMB_PRESENT)
           /// ACL event default increment
      -    RWIP_INCR_ACL_DFT               = 8,
      +    RWIP_INCR_ACL_DFT               = 1,
           /// ACL event increment with activity
      -    RWIP_INCR_ACL_ACT               = 8,
      +    RWIP_INCR_ACL_ACT               = 1,
           /// ACL Role Switch event default increment
      -    RWIP_INCR_ACL_RSW               = 8,
      +    RWIP_INCR_ACL_RSW               = 1,
           /// ACL sniff event default increment
      -    RWIP_INCR_ACL_SNIFF_DFT         = 8,
      +    RWIP_INCR_ACL_SNIFF_DFT         = 1,
           /// ACL sniff transition event default increment
      -    RWIP_INCR_ACL_SNIFF_TRANS       = 8,
      +    RWIP_INCR_ACL_SNIFF_TRANS       = 1,
           #if MAX_NB_SYNC
           /// SCO event default increment
      -    RWIP_INCR_SCO_DFT               = 8,
      +    RWIP_INCR_SCO_DFT               = 1,
           #endif //MAX_NB_SYNC
           /// Broadcast ACL event default increment
      -    RWIP_INCR_BCST_DFT              = 8,
      +    RWIP_INCR_BCST_DFT              = 1,
           /// Broadcast ACL event with LMP activity increment
      -    RWIP_INCR_BCST_ACT              = 8,
      +    RWIP_INCR_BCST_ACT              = 1,
           /// CSB RX event default increment
      -    RWIP_INCR_CSB_RX_DFT            = 8,
      +    RWIP_INCR_CSB_RX_DFT            = 1,
           /// CSB TX event default increment
      -    RWIP_INCR_CSB_TX_DFT            = 8,
      +    RWIP_INCR_CSB_TX_DFT            = 1,
           /// Inquiry event default increment
      -    RWIP_INCR_INQ_DFT               = 8,
      +    RWIP_INCR_INQ_DFT               = 1,
           /// Inquiry Scan event default increment
      -    RWIP_INCR_ISCAN_DFT             = 8,
      +    RWIP_INCR_ISCAN_DFT             = 1,
           /// Page event default increment
      -    RWIP_INCR_PAGE_DFT              = 8,
      +    RWIP_INCR_PAGE_DFT              = 1,
           /// Page event default increment
      -    RWIP_INCR_PAGE_1ST_PKT          = 12,
      +    RWIP_INCR_PAGE_1ST_PKT          = 2,
           /// Page first packet event default increment
      -    RWIP_INCR_PCA_DFT               = 8,
      +    RWIP_INCR_PCA_DFT               = 1,
           /// Page scan event default increment
      -    RWIP_INCR_PSCAN_DFT             = 8,
      +    RWIP_INCR_PSCAN_DFT             = 1,
           /// Page scan event increment increment when canceled
      -    RWIP_INCR_PSCAN_1ST_PKT         = 8,
      +    RWIP_INCR_PSCAN_1ST_PKT         = 1,
           /// Synchronization Scan event default increment
      -    RWIP_INCR_SSCAN_DFT             = 8,
      +    RWIP_INCR_SSCAN_DFT             = 1,
           /// Synchronization Train event default increment
      -    RWIP_INCR_STRAIN_DFT            = 8,
      +    RWIP_INCR_STRAIN_DFT            = 1,
           #endif //#if (BT_EMB_PRESENT)
           #if (BLE_EMB_PRESENT)
           /// Default increment for scanning events
      -    RWIP_INCR_SCAN_DFT              = 8,
      +    RWIP_INCR_SCAN_DFT              = 1,
           /// Default increment for initiating events
      -    RWIP_INCR_INIT_DFT              = 8,
      -    /// LE connection events default increment
      -    RWIP_INCR_CONNECT_DFT           = 8,
      -    /// LE connection events increment with activity
      -    RWIP_INCR_CONNECT_ACT           = 8,
      +    RWIP_INCR_INIT_DFT              = 1,
      +    /// Default increment for master connect events
      +    RWIP_INCR_MCONNECT_DFT          = 1,
      +    /// Default increment for slave connect events
      +    RWIP_INCR_SCONNECT_DFT          = 1,
           /// Default increment for advertising events
      -    RWIP_INCR_ADV_DFT               = 8,
      +    RWIP_INCR_ADV_DFT               = 1,
           /// Default increment for advertising high duty cycle events
      -    RWIP_INCR_ADV_HDC_PRIO_DFT      = 8,
      +    RWIP_INCR_ADV_HDC_PRIO_DFT      = 1,
           /// Default increment for resolvable private addresses renewal event
      -    RWIP_INCR_RPA_RENEW_DFT         = 8,
      +    RWIP_INCR_RPA_RENEW_DFT         = 1,
           #endif // #if (BLE_EMB_PRESENT)
       };
       #endif //#if (BLE_EMB_PRESENT || BT_EMB_PRESENT)
  • services/ble_stack/ble_ip/rwip.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/ble_ip/rwip.h bes/services/ble_stack/ble_ip/rwip.h
      index 3e117f58cc4..65f7381c96b 100644
      --- a/services/ble_stack/ble_ip/rwip.h
      +++ b/services/ble_stack/ble_ip/rwip.h
      @@ -42,9 +42,13 @@
        ****************************************************************************************
        */
       /// Maximum value of a Bluetooth clock (in 312.5us half slots)
      -#define RWIP_MAX_CLOCK_TIME              ((1L<<28) - 1)
      +#define RWIP_MAX_CLOCK_TIME              ((1L<<32) - 1)
       /// Maximum value of a 10ms Bluetooth clock
      -#define RWIP_MAX_10MS_TIME               ((1L<<23) - 1)
      +#define RWIP_MAX_10MS_TIME               ((1L<<25) - 1)
      +/// retrieve 10ms time according to clock time
      +#define RWIP_CLOCK_TO_10MS_TIME(clock)   ((clock) >> 5)
      +/// retrieve clock time according to 10ms time
      +#define RWIP_10MS_TIME_TO_CLOCK(time)    ((time)  << 5)
       /// Invalid target time
       #define RWIP_INVALID_TARGET_TIME         (0xFFFFFFFFL)
       
      @@ -70,8 +74,8 @@ enum prevent_sleep
           RW_TL_TX_ONGOING                   = 0x0002,
           /// Flag indicating that an RX transfer is ongoing on Transport Layer
           RW_TL_RX_ONGOING                   = 0x0004,
      -    /// Flag indicating the IP is in sleep, to avoid running sleep algorithm while already entering sleep
      -    RW_DEEP_SLEEP                      = 0x0008,
      +    /// Flag indicating HCI timeout is ongoing
      +    RW_AHI_TIMEOUT                     = 0x0008,
           /// Flag indicating that an encryption is ongoing
           RW_CRYPT_ONGOING                   = 0x0010,
           /// Flag indicating that controller shall not sleep due to not CSB LPO_Allowed
      @@ -149,12 +153,10 @@ enum rwip_rf_mod
       /// Time information
       typedef struct
       {
      -    /// Integer part of the time (in half-slot)
      -    uint32_t hs;
      -    /// Fractional part of the time (in half-us) (range: 0-624)
      -    uint16_t hus;
      -    /// Bluetooth timestamp value (in us) 32 bits counter
      -    uint32_t bts;
      +    /// Time in 312.5 us step.
      +    uint32_t time;
      +    /// number of half us before getting next tick
      +    uint32_t next_tick;
       } rwip_time_t;
       
       
      @@ -173,15 +175,15 @@ struct rwip_rf_api
           /// Function called when TX power has to be set to max for a specific link id
           void (*txpwr_max_set)(uint8_t);
           /// Function called to convert a TX power CS power field into the corresponding value in dBm
      -    int8_t (*txpwr_dbm_get)(uint8_t, uint8_t);
      +    uint8_t (*txpwr_dbm_get)(uint8_t, uint8_t);
           /// Function called to convert a power in dBm into a control structure tx power field
      -    uint8_t (*txpwr_cs_get)(int8_t, uint8_t);
      +    uint8_t (*txpwr_cs_get)(int8_t, bool);
           /// Function called to convert the RSSI read from the control structure into a real RSSI
           int8_t (*rssi_convert)(uint8_t);
           /// Function used to read a RF register
      -    uint32_t (*reg_rd)(uint32_t);
      +    uint32_t (*reg_rd)(uint16_t);
           /// Function used to write a RF register
      -    void (*reg_wr)(uint32_t, uint32_t);
      +    void (*reg_wr)(uint16_t, uint32_t);
           /// Function called to put the RF in deep sleep mode
           void (*sleep)(void);
           /// Index of minimum TX power
      @@ -204,7 +206,7 @@ struct rwip_param_api
           /**
            * Get a parameter value
            * @param[in]      param_id     Parameter identifier
      -     * @param[in/out]  lengthPtr    Pointer to the length of the parameter (input: contain max length, output contain the effective param length, in bytes)
      +     * @param[in/out]  lengthPtr    Pointer to the length of the parameter (input: contain max length, output contain the effective param length)
            * @param[out]     buf          Pointer to the buffer be filled with the parameter value
            * @return  status              0: success | >0 : error
            */
      @@ -213,7 +215,7 @@ struct rwip_param_api
           /**
            * Set a parameter value
            * @param[in]      param_id     Parameter identifier
      -     * @param[in/out]  length       Length of the parameter (in bytes)
      +     * @param[in/out]  length       Length of the parameter
            * @param[out]     buf          Pointer to the buffer containing the parameter value
            * @return  status              0: success | >0 : error
            */
      @@ -303,7 +305,7 @@ extern struct rwip_param_api rwip_param;
       #if (BLE_EMB_PRESENT || BT_EMB_PRESENT)
       /// API for dual mode priority
       extern const struct rwip_prio rwip_priority[RWIP_PRIO_IDX_MAX];
      -#endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT)
      +#endif //#if (BLE_EMB_PRESENT || BT_EMB_PRESENT)
       
       #if (BT_EMB_PRESENT || BLE_EMB_PRESENT)
       #if (RW_WLAN_COEX)
      @@ -322,7 +324,7 @@ extern const uint8_t rwip_coex_cfg[RWIP_COEX_CFG_MAX];
       #if (RW_WLAN_COEX)
       #define RWIP_COEX_GET(coex_cfg_idx, bit_field) \
                       (uint8_t)(((rwip_coex_cfg[RWIP_COEX_ ## coex_cfg_idx ##_IDX]) >> RWIP_ ## bit_field ## _POS ) & RWIP_COEX_BIT_MASK)
      -#else //!(RW_WLAN_COEX)
      +#else //(RW_WLAN_COEX)
       #define RWIP_COEX_GET(coex_cfg_idx, bit_field) 0
       #endif //(RW_WLAN_COEX)
       #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT)
      @@ -392,19 +394,29 @@ bool rwip_pca_clock_dragging_only(void);
       
       /**
        ****************************************************************************************
      - * @brief Function to implement in platform in order to retrieve each external interface API
      + * @brief Function to implement in platform in order to retrieve expected external
      + * interface such as UART for Host Control Interface.
        *
      - * @param[in] idx External interface index
      + * @param[in] type external interface type (@see rwip_eif_types)
        *
        * @return External interface api structure
        ****************************************************************************************
        */
      -extern const struct rwip_eif_api* rwip_eif_get(uint8_t idx);
      +extern const struct rwip_eif_api* rwip_eif_get(uint8_t type);
       
      +#if RW_DEBUG
       /**
        ****************************************************************************************
      + * @brief Raises an assertion message to the control interface (if present)
      + *
      + * @param[in] file    File name
      + * @param[in] line    Line number
      + * @param[in] param0  Parameter 0 (custom value given by the assert instruction)
      + * @param[in] param1  Parameter 1 (custom value given by the assert instruction)
        ****************************************************************************************
        */
      +void rwip_assert_err(const char * file, int line, int param0, int param1);
      +#endif //RW_DEBUG
       
       
       /* **************************************************************************************
      @@ -414,7 +426,7 @@ extern const struct rwip_eif_api* rwip_eif_get(uint8_t idx);
       
       /**
        ****************************************************************************************
      - * @brief Retrieved sampled time
      + * @brief Retrieved sampled current time in half slot and next tick time in half us.
        *
        * @note Shall be called within a critical section
        *
      @@ -448,8 +460,11 @@ void rwip_timer_hs_set(uint32_t target);
       
       /**
        ****************************************************************************************
      + * @brief Gives FW/HW versions of RW-BT stack.
      + *
        ****************************************************************************************
        */
      +//void rwip_version(uint8_t* fw_version, uint8_t* hw_version);
       
       /**
        ****************************************************************************************
      @@ -459,10 +474,10 @@ void rwip_timer_hs_set(uint32_t target);
        * This function expect to be called from a BLE Module
        *
        * @param[in] key           AES Encryption key must be 16 bytes
      - * @param[in] val           16 bytes value array to encrypt using AES
      + * @param[in] data_em_ptr   Exchange memory data pointer of data to encrypt
        ****************************************************************************************
        */
      -//void rwip_aes_encrypt(const uint8_t *key, const uint8_t* val);
      +//void rwip_aes_encrypt(uint8_t *key, uint16_t data_em_ptr);
       
       /**
        ****************************************************************************************
      @@ -473,8 +488,11 @@ void rwip_timer_hs_set(uint32_t target);
       
       /**
        ****************************************************************************************
      + * @brief Schedule all pending events.
      + *
        ****************************************************************************************
        */
      +//void rwip_schedule(void);
       
       /**
        ****************************************************************************************
      @@ -488,9 +506,11 @@ void rwip_timer_hs_set(uint32_t target);
       /**
        ****************************************************************************************
        * @brief Handle the common core interrupts.
      + *
      + * @param[in] current IRQ status
        ****************************************************************************************
        */
      -//void rwip_isr(void);
      +//void rwip_isr(uint32_t irq_stat);
       
       /**
        ****************************************************************************************
  • services/ble_stack/ble_ip/rwip_task.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/ble_ip/rwip_task.h bes/services/ble_stack/ble_ip/rwip_task.h
      index a93c578b54d..5bef8e1905e 100644
      --- a/services/ble_stack/ble_ip/rwip_task.h
      +++ b/services/ble_stack/ble_ip/rwip_task.h
      @@ -42,33 +42,37 @@
       #define TASK_BUILD(type, index) ((uint16_t)(((index) << 8)|(type)) )
       
       /// Retrieves task type from task id.
      -#define TASK_TYPE_GET(ke_task_id) (((uint16_t)ke_task_id) & 0xFF)
      +#define TASK_TYPE_GET(ke_task_id) ((uint16_t) & 0xFF)
       
       /// Retrieves task index number from task id.
      -#define TASK_IDX_GET(ke_task_id) ((((uint16_t)ke_task_id) >> 8) & 0xFF)
      +#define TASK_IDX_GET(ke_task_id) (((uint16_t) >> 8) & 0xFF)
       
       
       /// Tasks types definition, this value shall be in [0-254] range
       enum TASK_API_ID
       {
           // Link Layer Tasks
      -    TASK_ID_LLM          = 0,   // BLE Link manager
      -    TASK_ID_LLC          = 1,   // BLE Link controller
      -    TASK_ID_LLD          = 2,   // BLE Link driver
      -    TASK_ID_LLI          = 3,   // BLE Link ISO
      +    TASK_ID_LLM          = 0,
      +    TASK_ID_LLC          = 1,
      +    TASK_ID_LLD          = 2,
      +    TASK_ID_DBG          = 3,
       
           // BT Controller Tasks
      -    TASK_ID_LM           = 5,   // BT Link manager
      -    TASK_ID_LC           = 6,   // BT Link controller
      -    TASK_ID_LB           = 7,   // BT Broadcast
      -    TASK_ID_LD           = 8,   // BT Link driver
      +    TASK_ID_LM           = 4,
      +    TASK_ID_LC           = 5,
      +    TASK_ID_LB           = 6,
      +    TASK_ID_LD           = 7,
      +
      +    TASK_ID_HCI          = 8,
      +    TASK_ID_DISPLAY      = 9,
       
           // -----------------------------------------------------------------------------------
           // --------------------- BLE HL TASK API Identifiers ---------------------------------
           // -----------------------------------------------------------------------------------
       
      -    TASK_ID_L2CAP        = 10,   // L2CAP Task
      -    TASK_ID_GATT         = 11,   // Generic Attribute Profile Task
      +    TASK_ID_L2CC         = 10,   // L2CAP Controller Task
      +    TASK_ID_GATTM        = 11,   // Generic Attribute Profile Manager Task
      +    TASK_ID_GATTC        = 12,   // Generic Attribute Profile Controller Task
           TASK_ID_GAPM         = 13,   // Generic Access Profile Manager
           TASK_ID_GAPC         = 14,   // Generic Access Profile Controller
       
      @@ -170,7 +174,9 @@ enum TASK_API_ID
       
           TASK_ID_TILE         = 77,   // skull tile task
       
      -    TASK_ID_AM0          = 240,  // BLE Audio Mode 0
      +    /* 240 -> 241 reserved for Audio Mode 0 */
      +    TASK_ID_AM0          = 240,  // BLE Audio Mode 0 Task
      +    TASK_ID_AM0_HAS      = 241,  // BLE Audio Mode 0 Hearing Aid Service Task
       
           TASK_ID_INVALID      = 0xFF, // Invalid Task Identifier
       };
  • services/ble_stack/ble_ip/rwprf_config.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/ble_ip/rwprf_config.h bes/services/ble_stack/ble_ip/rwprf_config.h
      index ab5860bfcdc..6d440f2b2ec 100644
      --- a/services/ble_stack/ble_ip/rwprf_config.h
      +++ b/services/ble_stack/ble_ip/rwprf_config.h
      @@ -29,11 +29,11 @@
       #define CFG_PRF_DATAPATH_SERVER
       #endif
       
      -#ifdef __AI_VOICE_BLE_ENABLE__
      +#ifdef __AI_VOICE__
       #define CFG_AI_VOICE
       #endif
       
      -#ifdef BES_OTA
      +#ifdef BES_OTA_BASIC
       #define CFG_OTA
       #endif
       
      @@ -45,12 +45,19 @@
       #define CFG_TILE
       #endif
       
      +#if defined(VOICE_DATAPATH) && defined(BISTO_ENABLED)
      +#define CFG_BMS
      +#if ANCS_PROXY_ENABLE
      +#define CFG_PRF_AMS
      +#define CFG_PRF_ANCC
      +#endif
       
      +#endif
       
       /**
        ****************************************************************************************
        * @addtogroup PRF_CONFIG
      - * @ingroup Profile
      + * @ingroup PROFILE
        * @brief Profile configuration
        *
        * @{
      @@ -411,25 +418,25 @@
       #define BLE_TOTA            0
       #endif  // defined(CFG_TOTA)
       
      -#if defined(BMS_ENABLED)
      +#if defined(CFG_BMS)
       #define BLE_BMS     1
       #else
       #define BLE_BMS     0
      -#endif  // defined(BMS_ENABLED)
      +#endif  // defined(BLE_BMS)
       
       /// ANCS Profile Client Role
      -#if defined(ANCC_ENABLED)
      +#if defined(CFG_PRF_ANCC)
       #define BLE_ANC_CLIENT           1
       #else
       #define BLE_ANC_CLIENT           0
      -#endif // defined(ANCC_ENABLED)
      +#endif // defined(CFG_PRF_ANCC)
       
       /// AMS Profile Client Role
      -#if defined(AMSC_ENABLED)
      +#if defined(CFG_PRF_AMS)
       #define BLE_AMS_CLIENT           1
       #else
       #define BLE_AMS_CLIENT           0
      -#endif // defined(AMSC_ENABLED)
      +#endif // defined(CFG_PRF_AMS)
       #if defined(CFG_PRF_GFPS_PROVIDER)
       #define BLE_GFPS_PROVIDER       1
       #else

@OneDeuxTriSeiGo
Copy link
Author

  • services/ble_stack/common/api/co_bt_defines.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/common/api/co_bt_defines.h bes/services/ble_stack/common/api/co_bt_defines.h
      index dab73a6e60e..e0be03c3f5d 100644
      --- a/services/ble_stack/common/api/co_bt_defines.h
      +++ b/services/ble_stack/common/api/co_bt_defines.h
      @@ -55,12 +55,12 @@
       #define BD_NAME_SIZE        0xF8 // Was 0x20 for BLE HL
       #define ADV_DATA_LEN        0x1F
       #define EXT_ADV_DATA_MAX_LEN    229 // HCI:7.7.65.13
      -#define PER_ADV_DATA_MAX_LEN    247 // 248 // HCI:7.7.65.16
      -#define SCAN_RSP_DATA_LEN               0x1F
      +#define PER_ADV_DATA_MAX_LEN    248 // HCI:7.7.65.16
      +#define BLE_DATA_LEN                    0x1F
       #define BLE_ADV_FLAG_PART_LEN           0x03
      -#define BLE_ADV_DATA_WITHOUT_FLAG_LEN   (ADV_DATA_LEN)
      -#define BLE_ADV_DATA_WITH_FLAG_LEN      (ADV_DATA_LEN - BLE_ADV_FLAG_PART_LEN)
      -#define SCAN_RSP_DATA_LEN               0x1F
      +#define BLE_ADV_DATA_WITHOUT_FLAG_LEN   (BLE_DATA_LEN)
      +#define BLE_ADV_DATA_WITH_FLAG_LEN      (BLE_DATA_LEN - BLE_ADV_FLAG_PART_LEN)
      +#define SCAN_RSP_DATA_LEN               (BLE_DATA_LEN)
       #define CONNECT_REQ_DATA_LEN    0x16
       #define LE_CHNL_MAP_LEN     0x05
       #define CHNL_MAP_LEN        0x0A
      @@ -149,31 +149,43 @@
       #define ADV_ADDR_LEN        BD_ADDR_LEN
       #define ADV_DATA_OFFSET    (ADV_ADDR_OFFSET + ADV_ADDR_LEN)
       
      -/// List of supported BLE Features LL:4.6
      +/// BLE supported features
      +//byte 0
      +#define BLE_ENC_FEAT                     0x01
      +#define BLE_CON_PARAM_REQ_PROC_FEAT      0x02
      +#define BLE_REJ_IND_EXT_FEAT             0x04
      +#define BLE_SLAVE_INIT_EXCHG_FEAT        0x08
      +#define BLE_PING_FEAT                    0x10
      +#define BLE_LENGTH_EXT_FEAT              0x20
      +#define BLE_LL_PRIVACY_FEAT              0x40
      +#define BLE_EXT_SCAN_POLICY_FEAT         0x80
      +
      +//byte 1
      +#define BLE_2M_PHY_FEAT                  0x01
      +#define BLE_STABLE_MOD_IDX_TX_FEAT       0x02
      +#define BLE_STABLE_MOD_IDX_RX_FEAT       0x04
      +#define BLE_CODED_PHY_FEAT               0x08
      +#define BLE_EXT_ADV_FEAT                 0x10
      +#define BLE_PER_ADV_FEAT                 0x20
      +#define BLE_CHAN_SEL_ALGO_2_FEAT         0x40
      +#define BLEPWR_CLASS_1_FEAT              0x80
      +
      +//byte 2
      +#define BLE_MIN_NUM_USED_CHAN_PROC          0x01
      +
      +// List of supported BLE Features
       enum ble_feature
       {
      -    //byte 0
           BLE_FEAT_ENC                       = (0),
           BLE_FEAT_CON_PARAM_REQ_PROC        = (1),
      -    BLE_FEAT_EXT_REJ_IND               = (2),
      -    BLE_FEAT_SLAVE_INIT_FEAT_EXCHG     = (3),
      +    BLE_FEAT_REJ_IND_EXT               = (2),
      +    BLE_FEAT_SLAVE_INIT_EXCHG          = (3),
           BLE_FEAT_PING                      = (4),
      -    BLE_FEAT_DATA_PKT_LEN_EXT          = (5),
      +    BLE_FEAT_LENGTH_EXT                = (5),
           BLE_FEAT_LL_PRIVACY                = (6),
      -    BLE_FEAT_EXT_SCAN_FILT_POLICY      = (7),
      -
      -    //byte 1
      -    BLE_FEAT_2M_PHY                    = (8),
      -    BLE_FEAT_STABLE_MOD_IDX_TX         = (9),
      -    BLE_FEAT_STABLE_MOD_IDX_RX         = (10),
      -    BLE_FEAT_CODED_PHY                 = (11),
      -    BLE_FEAT_EXT_ADV                   = (12),
      -    BLE_FEAT_PER_ADV                   = (13),
      -    BLE_FEAT_CHAN_SEL_ALGO_2           = (14),
      -    BLE_FEAT_PWR_CLASS_1               = (15),
      -
      -    //byte 2
      -    BLE_FEAT_MIN_NUM_USED_CHAN_PROC    = (16),
      +    BLE_FEAT_EXT_SCAN_POLICY           = (7),
      +    BLE_FEAT_2MBPS                     = (8),
      +    BLE_FEAT_STABLE_MOD                = (9),
       };
       
       /// BLE supported states
      @@ -247,6 +259,7 @@ enum ble_feature
       //byte14
       #define BLE_RD_LOC_VERS_CMD         0x08
       #define BLE_RD_LOC_SUP_FEAT_CMD     0x20
      +#define BLE_RD_BUF_SIZE_CMD         0x80
       //byte15
       #define BLE_RD_BD_ADDR_CMD          0x02
       #define BLE_RD_RSSI_CMD             0x20
      @@ -279,12 +292,12 @@ enum ble_feature
       #define BLE_LE_ENCRYPT_CMD          0x40
       #define BLE_LE_RAND_CMD             0x80
       //byte28
      -#define BLE_LE_EN_ENC_CMD           0x01
      +#define BLE_LE_START_ENC_CMD        0x01
       #define BLE_LE_LTK_REQ_RPLY_CMD     0x02
       #define BLE_LE_LTK_REQ_NEG_RPLY_CMD 0x04
       #define BLE_LE_RD_SUPP_STATES_CMD   0x08
      -#define BLE_LE_RX_TEST_V1_CMD       0x10
      -#define BLE_LE_TX_TEST_V1_CMD       0x20
      +#define BLE_LE_RX_TEST_CMD          0x10
      +#define BLE_LE_TX_TEST_CMD          0x20
       #define BLE_LE_STOP_TEST_CMD        0x40
       
       //byte32
      @@ -301,7 +314,7 @@ enum ble_feature
       //byte34
       #define BLE_LE_WR_SUGGTED_DFT_DATA_LEN_CMD      0x01
       #define BLE_LE_RD_LOC_P256_PUB_KEY_CMD          0x02
      -#define BLE_LE_GEN_DHKEY_V1_CMD                 0x04
      +#define BLE_LE_GEN_DH_KEY_CMD                   0x04
       #define BLE_LE_ADD_DEV_TO_RESOLV_LIST_CMD       0x08
       #define BLE_LE_REM_DEV_FROM_RESOLV_LIST_CMD     0x10
       #define BLE_LE_CLEAR_RESOLV_LIST_CMD            0x20
      @@ -784,7 +797,7 @@ enum ble_feature
       /// LMP Response Timeout (in sec)
       #define LMP_RSP_TO             30
       /// LLCP Response Timeout (in units of 10 ms)
      -#define LLCP_RSP_TO            4000 // 40 secs
      +#define LLCP_RSP_TO            3000 // 30 secs
       
       /// Athenticated Payload Timeout (in units of 10 ms)
       #define AUTH_PAYL_TO_DFT       0x0BB8  // 30 secs
      @@ -1166,11 +1179,11 @@ enum ble_feature
       #define FLOW_DIR_OUT                0x00
       #define FLOW_DIR_IN                 0x01
       
      -/// Drift and Jitter default value LMP 5.2 (in ppm)
      -#define BLE_MAX_DRIFT_SLEEP             500
      -#define BT_MAX_DRIFT_SLEEP              250
      +/// Drift and Jitter default value LMP 5.2
      +#define DRIFT_BLE_DFT                   500
      +#define DRIFT_BT_DFT                    250
       #define JITTER_DFT                      10
      -#define BT_MAX_DRIFT_ACTIVE             20 // BB:2.2.5
      +#define DRIFT_BT_ACTIVE_MAX             20 // BB:2.2.5
       
       /// Read Stored Link Key HCI:4.7.8
       #define LINK_KEY_BD_ADDR                0x00
      @@ -1346,7 +1359,11 @@ enum ble_feature
       #define SP_PASSKEY_CLEARED          0x03
       #define SP_PASSKEY_COMPLETED        0x04
       
      +/// Low Power Mode
      +#define PARK_BEACON_MIN             0x000E
       
      +/// RWBT Device can be slave of 2 master at max
      +#define MAX_SLAVES_FOR_DIFFERENT_MASTERS    2
       // Flags for ld_util_get_nb_acl function
       /// Flag for master link
       #define MASTER_FLAG       0x01
      @@ -1366,32 +1383,32 @@ enum ble_feature
       /// BLE event mask
       enum le_evt_mask
       {
      -    LE_EVT_MASK_CON_CMP_EVT_BIT                     = 0,
      -    LE_EVT_MASK_CON_CMP_EVT_MSK                     = 0x00000001,
      -    LE_EVT_MASK_ADV_REP_EVT_BIT                     = 1,
      -    LE_EVT_MASK_ADV_REP_EVT_MSK                     = 0x00000002,
      -    LE_EVT_MASK_CON_UPD_EVT_BIT                     = 2,
      -    LE_EVT_MASK_CON_UPD_EVT_MSK                     = 0x00000004,
      -    LE_EVT_MASK_CON_RD_REM_FEAT_EVT_BIT             = 3,
      -    LE_EVT_MASK_CON_RD_REM_FEAT_EVT_MSK             = 0x00000008,
      -    LE_EVT_MASK_LG_TR_KEY_REQ_EVT_BIT               = 4,
      -    LE_EVT_MASK_LG_TR_KEY_REQ_EVT_MSK               = 0x00000010,
      -    LE_EVT_MASK_REM_CON_PARA_REQ_EVT_BIT            = 5,
      -    LE_EVT_MASK_REM_CON_PARA_REQ_EVT_MSK            = 0x00000020,
      -    LE_EVT_MASK_DATA_LEN_CHG_EVT_BIT                = 6,
      -    LE_EVT_MASK_DATA_LEN_CHG_EVT_MSK                = 0x00000040,
      -    LE_EVT_MASK_RD_LOC_P256_PUB_KEY_CMP_EVT_BIT     = 7,
      -    LE_EVT_MASK_RD_LOC_P256_PUB_KEY_CMP_EVT_MSK     = 0x00000080,
      -    LE_EVT_MASK_GEN_DHKEY_CMP_EVT_BIT               = 8,
      -    LE_EVT_MASK_GEN_DHKEY_CMP_EVT_MSK               = 0x00000100,
      -    LE_EVT_MASK_ENH_CON_CMP_EVT_BIT                 = 9,
      -    LE_EVT_MASK_ENH_CON_CMP_EVT_MSK                 = 0x00000200,
      -    LE_EVT_MASK_DIR_ADV_REP_EVT_BIT                 = 10,
      -    LE_EVT_MASK_DIR_ADV_REP_EVT_MSK                 = 0x00000400,
      -    LE_EVT_MASK_PHY_UPD_CMP_EVT_BIT                 = 11,
      -    LE_EVT_MASK_PHY_UPD_CMP_EVT_MSK                 = 0x00000800,
      -
      -    LE_EVT_MASK_DFT                                 = 0x0000001F,
      +    LE_EVT_MASK_CON_CMP_EVT_BIT                     = 0,     //!< LE_EVT_MASK_CON_CMP_EVT_BIT
      +    LE_EVT_MASK_CON_CMP_EVT_MSK                     = 0x0001,//!< LE_EVT_MASK_CON_CMP_EVT_MSK
      +    LE_EVT_MASK_ADV_REP_EVT_BIT                     = 1,     //!< LE_EVT_MASK_ADV_REP_EVT_BIT
      +    LE_EVT_MASK_ADV_REP_EVT_MSK                     = 0x0002,//!< LE_EVT_MASK_ADV_REP_EVT_MSK
      +    LE_EVT_MASK_CON_UPD_EVT_BIT                     = 2,     //!< LE_EVT_MASK_CON_UPD_EVT_BIT
      +    LE_EVT_MASK_CON_UPD_EVT_MSK                     = 0x0004,//!< LE_EVT_MASK_CON_UPD_EVT_MSK
      +    LE_EVT_MASK_CON_RD_REM_FEAT_EVT_BIT             = 3,     //!< LE_EVT_MASK_CON_RD_REM_FEAT_EVT_BIT
      +    LE_EVT_MASK_CON_RD_REM_FEAT_EVT_MSK             = 0x0008,//!< LE_EVT_MASK_CON_RD_REM_FEAT_EVT_MSK
      +    LE_EVT_MASK_LG_TR_KEY_REQ_EVT_BIT               = 4,     //!< LE_EVT_MASK_LG_TR_KEY_REQ_EVT_BIT
      +    LE_EVT_MASK_LG_TR_KEY_REQ_EVT_MSK               = 0x0010,//!< LE_EVT_MASK_LG_TR_KEY_REQ_EVT_MSK
      +    LE_EVT_MASK_REM_CON_PARA_REQ_EVT_BIT            = 5,     //!< LE_EVT_MASK_REM_CON_PARA_REQ_EVT_BIT
      +    LE_EVT_MASK_REM_CON_PARA_REQ_EVT_MSK            = 0x0020,//!< LE_EVT_MASK_REM_CON_PARA_REQ_EVT_MSK
      +    LE_EVT_MASK_DATA_LEN_CHG_EVT_BIT                = 6,     //!< LE_EVT_MASK_DATA_LEN_CHG_EVT_BIT
      +    LE_EVT_MASK_DATA_LEN_CHG_EVT_MSK                = 0x0040,//!< LE_EVT_MASK_DATA_LEN_CHG_EVT_MSK
      +    LE_EVT_MASK_RD_LOC_P256_PUB_KEY_CMP_EVT_BIT     = 7,     //!< LE_EVT_MASK_RD_LOC_P256_PUB_KEY_CMP_EVT_BIT
      +    LE_EVT_MASK_RD_LOC_P256_PUB_KEY_CMP_EVT_MSK     = 0x0080,//!< LE_EVT_MASK_RD_LOC_P256_PUB_KEY_CMP_EVT_MSK
      +    LE_EVT_MASK_GEN_DHKEY_CMP_EVT_BIT               = 8,     //!< LE_EVT_MASK_GEN_DHKEY_CMP_EVT_BIT
      +    LE_EVT_MASK_GEN_DHKEY_CMP_EVT_MSK               = 0x0100,//!< LE_EVT_MASK_GEN_DHKEY_CMP_EVT_MSK
      +    LE_EVT_MASK_ENH_CON_CMP_EVT_BIT                 = 9,     //!< LE_EVT_MASK_ENH_CON_CMP_EVT_BIT
      +    LE_EVT_MASK_ENH_CON_CMP_EVT_MSK                 = 0x0200,//!< LE_EVT_MASK_ENH_CON_CMP_EVT_MSK
      +    LE_EVT_MASK_DIR_ADV_REP_EVT_BIT                 = 10,    //!< LE_EVT_MASK_DIR_ADV_REP_EVT_BIT
      +    LE_EVT_MASK_DIR_ADV_REP_EVT_MSK                 = 0x0400,//!< LE_EVT_MASK_DIR_ADV_REP_EVT_MSK
      +    LE_EVT_MASK_PHY_UPD_CMP_EVT_BIT                 = 11,    //!< LE_EVT_MASK_PHY_UPD_CMP_EVT_BIT
      +    LE_EVT_MASK_PHY_UPD_CMP_EVT_MSK                 = 0x0800,//!< LE_EVT_MASK_PHY_UPD_CMP_EVT_MSK
      +
      +    LE_EVT_MASK_DFT                                 = 0x001F,//!< LE_EVT_MASK_DFT
       };
       
       /// Enhanced Synchronous Connection HCI:7.1.41 & 7.1.42
      @@ -1507,6 +1524,23 @@ enum le_evt_mask
       #define CSB_RX_KO        0x01
       
       
      +/// HCI 7.8.18 LE Connection Update Command
      +/// Connection interval min (N*1.250ms)
      +#define LE_CNX_INTERVAL_MIN            6       //(0x06)
      +/// Connection interval Max (N*1.250ms)
      +#define LE_CNX_INTERVAL_MAX            3200    //(0xC80)
      +/// Connection latency min (N*cnx evt)
      +#define LE_CNX_LATENCY_MIN             0       //(0x00)
      +/// Connection latency Max (N*cnx evt
      +#define LE_CNX_LATENCY_MAX             500     //(0x1F4)
      +/// Supervision TO min (N*10ms)
      +#define LE_CNX_SUP_TO_MIN              10      //(0x0A)
      +/// Supervision TO Max (N*10ms)
      +#define LE_CNX_SUP_TO_MAX              3200    //(0xC80)
      +/// Connection event length min (N*0.625ms)
      +#define LE_CNX_CE_LGTH_MIN             0       //(0x00)
      +/// Connection event length  Max (N*0.625ms)
      +#define LE_CNX_CE_LGTH_MAX             65535   //(0xFFFF)'
       
       
       /// HCI 7.8.33 LE Set Data Length Command
      @@ -1528,12 +1562,17 @@ enum le_evt_mask
       #define RPA_TO_DFT         0x0384 // 900 seconds or 15 minutes
       #define RPA_TO_MIN         0x0001 // 1 second
       
      +/// Scan/Init PHYs (bit fields, as defined in HCI:7.8.64, HCI:7.8.66).
      +#define LE_1M_PHY_BIT_POS        0
      +#define LE_1M_PHY_BIT_MSK        0x01
      +#define LE_CODED_PHY_BIT_POS     2
      +#define LE_CODED_PHY_BIT_MSK     0x04
       
       /// Max scanning PHYs which can be set HCI:7.8.64
       #define MAX_SCAN_PHYS     2
       
       /// Max initiatng PHYs which can be set HCI:7.8.66
      -#define MAX_INIT_PHYS     3
      +#define MAX_INIT_PHYS     2
       
       /// Ext Scanning interval (in 625us slot) (chapter 2.E.7.8.64)
       #define EXT_SCAN_INTERVAL_MIN     0x0004 //(2.5 ms)
      @@ -1543,6 +1582,10 @@ enum le_evt_mask
       #define EXT_SCAN_WINDOW_MIN     0x0004 //(2.5 ms)
       #define EXT_SCAN_WINDOW_MAX     0xFFFF //(40.96 sec)
       
      +/// Advertiser PHY definitions for Ext Adv report Evts  HCI:7.7.65.13
      +#define HCI_ADV_PHY_1M              1
      +#define HCI_ADV_PHY_2M              2
      +#define HCI_ADV_PHY_CODED           3
       
       /// Duration of 1MBPS PDU of specified payload length in microseconds (chapter 6.B.2.1)
       #define PDU_1MBPS_LEN_US(n_bytes) ((8 + (2 + n_bytes))*8) // (1 + 4 + (2 + payload_len) + 3)*8
      @@ -1579,7 +1622,7 @@ enum le_evt_mask
        * ENUMERATIONS
        ****************************************************************************************
        */
      -/// Specify if Host has no preference into all_phys parameter HCI:7.8.48 / HCI:7.8.49
      +/// BLE 2MBPS HCI:7.8.x
       enum le_phys_preference
       {
           /// The Host has no preference among the transmitter PHYs supported by the Controller
      @@ -1591,13 +1634,13 @@ enum le_phys_preference
       enum le_phy_value
       {
           /// The Host prefers to use the LE 1M transmitter/receiver PHY (possibly among others)
      -    PHY_1MBPS_BIT      = (1<<0),
      +    PHY_1MBPS      = (1<<0),
           /// The Host prefers to use the LE 2M transmitter/receiver PHY (possibly among others)
      -    PHY_2MBPS_BIT      = (1<<1),
      +    PHY_2MBPS      = (1<<1),
           /// The Host prefers to use the LE Coded transmitter/receiver PHY (possibly among others)
      -    PHY_CODED_BIT      = (1<<2),
      +    PHY_LE_CODED   = (1<<2),
           /// The Host prefers to use the LE Coded transmitter/receiver PHY (possibly among others)
      -    PHY_ALL        = (PHY_1MBPS_BIT | PHY_2MBPS_BIT | PHY_CODED_BIT),
      +    PHY_ALL        = (PHY_1MBPS | PHY_2MBPS | PHY_LE_CODED),
       };
       
       enum le_phy_opt
      @@ -1618,7 +1661,7 @@ enum le_phy_mode
           PHYS_MOD_MAX,
       };
       
      -///Transmit Power level types.  HCI:7.3.35
      +///Transmit Power level types
       enum
       {
           ///Current Power Level
      @@ -1723,7 +1766,7 @@ enum
       };
       
       ///BD address type
      -enum addr_type
      +enum
       {
           ///Public BD address
           ADDR_PUBLIC                   = 0x00,
      @@ -1785,11 +1828,11 @@ enum adv_filter_policy
       {
           ///Allow both scan and connection requests from anyone
           ADV_ALLOW_SCAN_ANY_CON_ANY    = 0x00,
      -    ///Allow scan req from White List devices only and connection req from anyone
      +    ///Allow both scan req from White List devices only and connection req from anyone
           ADV_ALLOW_SCAN_WLST_CON_ANY,
      -    ///Allow scan req from anyone and connection req from White List devices only
      +    ///Allow both scan req from anyone and connection req from White List devices only
           ADV_ALLOW_SCAN_ANY_CON_WLST,
      -    ///Allow both scan and connection requests from White List devices only
      +    ///Allow scan and connection requests from White List devices only
           ADV_ALLOW_SCAN_WLST_CON_WLST,
       };
       
      @@ -1884,7 +1927,7 @@ enum
       };
       
       /// Constant clock accuracy
      -enum SCA
      +enum
       {
           ///Clock accuracy at 500PPM
           SCA_500PPM,
      @@ -1943,7 +1986,7 @@ enum ble_adv_type
           BLE_AUX_CONNECT_RSP        = 0x08,
       
           /// Reserved
      -    BLE_RESERVED_PDU_TYPE,
      +    BLE_RESERVED_PDU_TYPES,
       };
       
       
      @@ -1964,7 +2007,7 @@ enum
           RESERVED_ADV_EVT_TYPES,
       };
       
      -/// LE Extended Advertising Report Event Type Bit Mask HCI:7.7.65.13
      +/// LE Extended Advertising Report Event Type Bit Mask HCI:7.765.13
       
       /// Connectable advertising event
       #define CON_ADV_EVT_MSK            0x01
      @@ -1991,9 +2034,9 @@ enum
       #define LGCY_SCAN_RSP_TO_ADV_SCAN_IND_EVT   0x1A //LGCY_ADV_EVT_MSK|SCAN_RSP_EVT_MSK|SCAN_ADV_EVT_MSK
       
       /// Offset of data status field in event type value
      -#define ADV_EVT_DATA_STATUS_LSB                 5
      +#define ADV_EVT_DATA_STATUS_OFFSET              5
       /// Mask for data status field in event type value
      -#define ADV_EVT_DATA_STATUS_MASK                0x0060
      +#define ADV_EVT_DATA_STATUS_MASK                0x0003
       /// Data status of extended advertising event - Complete
       #define ADV_EVT_DATA_STATUS_COMPLETE            0
       /// Data status of extended advertising event - Incomplete, more data to come
      @@ -2045,8 +2088,8 @@ enum
       #define BLE_EXT_ADV_HEADER_FLAGS_LEN         (1)
       /// size of the extended header in bytes (pre-header + flags)
       #define BLE_EXT_ADV_HEADER_LEN               (2)
      -/// Size of CTE info in extended header
      -#define BLE_EXT_CTE_INFO_LEN                 (1)
      +/// Size of supplemental info in extended header
      +#define BLE_EXT_SUP_INFO_LEN                 (1)
       /// Size of ADV Data Info in extended header
       #define BLE_EXT_ADI_LEN                      (2)
       /// Size of Aux Pointer info in extended header
      @@ -2310,8 +2353,8 @@ struct adv_report
           uint8_t        data_len;
           ///Data of advertising packet
           uint8_t        data[ADV_DATA_LEN];
      -    ///RSSI value for advertising packet (in dBm, between -127 and +20 dBm)
      -    int8_t         rssi;
      +    ///RSSI value for advertising packet
      +    uint8_t        rssi;
       };
       
       ///Direct Advertising report structure
      @@ -2328,8 +2371,8 @@ struct dir_adv_report
           uint8_t        dir_addr_type;
           ///Direct address value
           struct bd_addr dir_addr;
      -    ///RSSI value for advertising packet (in dBm, between -127 and +20 dBm)
      -    int8_t         rssi;
      +    ///RSSI value for advertising packet
      +    uint8_t        rssi;
       };
       
       ///Exteneded Advertising report structure
      @@ -2349,8 +2392,8 @@ struct ext_adv_report
           uint8_t        adv_sid;
           ///Tx Power
           uint8_t        tx_power;
      -    ///RSSI value for advertising packet (in dBm, between -127 and +20 dBm)
      -    int8_t         rssi;
      +    ///RSSI value for advertising packet
      +    uint8_t        rssi;
           ///Periodic Advertising interval (Time=N*1.25ms)
           uint16_t       interval;
           ///Direct address type
      @@ -2533,8 +2576,8 @@ typedef struct t_public_key
       
       } t_public_key;
       
      -/// structure connection request LLData
      -struct pdu_con_req_lldata
      +/// structure connection request
      +struct pdu_con_req
       {
           /// access address
           struct access_addr  aa;
      @@ -2542,28 +2585,43 @@ struct pdu_con_req_lldata
           /// CRC init
           struct crc_init     crcinit;
       
      -    /// Window size (in units of 1,25 ms, i.e. 2 slots)
      +    /// window size
           uint8_t             winsize;
       
      -    /// Window offset (in units of 1,25 ms, i.e. 2 slots)
      +    /// window offset
           uint16_t            winoffset;
       
      -    /// Interval (in units of 1,25 ms, i.e. 2 slots)
      +    /// interval
           uint16_t            interval;
       
      -    /// Latency
      +    /// latency
           uint16_t            latency;
       
      -    /// Timeout (in units of 10 ms, i.e. 16 slots)
      +    /// timeout
           uint16_t            timeout;
       
      -    /// Channel mapping
      +    /// channel mapping
           struct le_chnl_map  chm;
       
      -    /// Hopping
      +    /// hopping
           uint8_t             hop_sca;
       };
       
      +/// Device specific link preferences
      +typedef struct
      +{
      +    // **** Data Length Management ****
      +    /// Suggested value for the Controller's maximum transmitted number of payload octets
      +    uint16_t   suggested_max_tx_octets;
      +    /// Suggested value for the Controller's maximum packet transmission time (in us)
      +    uint16_t   suggested_max_tx_time;
      +
      +    // ****    PHY  Management     ****
      +    /// Default TX preferred PHY to use (@see enum le_phy_value)
      +    uint8_t    tx_phys;
      +    /// Default RX preferred PHY to use (@see enum le_phy_value)
      +    uint8_t    rx_phys;
      +} link_pref_t;
       
       
       /// @} CO_BT_DEFINES
  • services/ble_stack/common/api/co_error.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/common/api/co_error.h bes/services/ble_stack/common/api/co_error.h
      index c3296a67970..a6f46f77451 100644
      --- a/services/ble_stack/common/api/co_error.h
      +++ b/services/ble_stack/common/api/co_error.h
      @@ -46,7 +46,7 @@ enum co_error
           CO_ERROR_CON_TIMEOUT                     = 0x08,
           CO_ERROR_CON_LIMIT_EXCEED                = 0x09,
           CO_ERROR_SYNC_CON_LIMIT_DEV_EXCEED       = 0x0A,
      -    CO_ERROR_CON_ALREADY_EXISTS              = 0x0B,
      +    CO_ERROR_ACL_CON_EXISTS                  = 0x0B,
           CO_ERROR_COMMAND_DISALLOWED              = 0x0C,
           CO_ERROR_CONN_REJ_LIMITED_RESOURCES      = 0x0D,
           CO_ERROR_CONN_REJ_SECURITY_REASONS       = 0x0E,
      @@ -91,7 +91,7 @@ enum co_error
           CO_ERROR_HOST_BUSY_PAIRING               = 0x38,
           CO_ERROR_CONTROLLER_BUSY                 = 0x3A,
           CO_ERROR_UNACCEPTABLE_CONN_PARAM         = 0x3B,
      -    CO_ERROR_ADV_TO                          = 0x3C,
      +    CO_ERROR_DIRECT_ADV_TO                   = 0x3C,
           CO_ERROR_TERMINATED_MIC_FAILURE          = 0x3D,
           CO_ERROR_CONN_FAILED_TO_BE_EST           = 0x3E,
           CO_ERROR_CCA_REJ_USE_CLOCK_DRAG          = 0x40,
  • services/ble_stack/common/api/co_hci.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/common/api/co_hci.h bes/services/ble_stack/common/api/co_hci.h
      index c0aef3a2a26..690e3a96d4c 100644
      --- a/services/ble_stack/common/api/co_hci.h
      +++ b/services/ble_stack/common/api/co_hci.h
      @@ -34,6 +34,7 @@
       #include "rwip_config.h"   // IP configuration
       
       #include "compiler.h"      // compiler definitions
      +#include "hci_api.h"
       
       /*
        * DEFINES
      @@ -60,8 +61,8 @@
       ///UART header: event message type
       #define HCI_EVT_MSG_TYPE                            0x04
       
      -///UART header: ISO data message type
      -#define HCI_ISO_MSG_TYPE                            0x05
      +///UART header: event message type
      +#define HCI_TCI_MSG_TYPE                            0xFF
       
       /******************************************************************************************/
       /* -------------------------   HCI DEFINITIONS Part II.E     -----------------------------*/
      @@ -97,8 +98,8 @@ enum  hci_acl_hdr_fields
           HCI_ACL_HDR_BC_FLAG_MASK   = (0xC000),
       
           /// Packet boundary and Broadcast flags
      -    HCI_ACL_HDR_DATA_FLAGS_LSB  = (12),
      -    HCI_ACL_HDR_DATA_FLAGS_MASK = (0xF000),
      +    HCI_ACL_HDR_DATA_FLAG_LSB  = (12),
      +    HCI_ACL_HDR_DATA_FLAG_MASK = (0xF000),
       };
       
       #define HCI_ACL_HDR_HDL_FLAGS_POS  (0)
      @@ -113,19 +114,14 @@ enum  hci_acl_hdr_fields
       /// HCI Synchronous header: handle and flags decoding
       #define HCI_SYNC_HDR_HDL_FLAGS_POS  (0)
       #define HCI_SYNC_HDR_HDL_FLAGS_LEN  (2)
      -
      -enum hci_syn_hdr_fields
      -{
      -    /// bits[00:11]: Connection handle
      -    HCI_SYNC_HDR_HDL_LSB   = (0),
      -    HCI_SYNC_HDR_HDL_MASK  = (0x0FFF),
      -    /// bits[12:13]: Packet status flag
      -    HCI_SYNC_HDR_PSF_LSB   = (12),
      -    HCI_SYNC_HDR_PSF_MASK  = (0x3000),
      -    /// bits[14:15]: RFU
      -    HCI_SYNC_HDR_RFU_LSB   = (14),
      -    HCI_SYNC_HDR_RFU_MASK  = (0xC000),
      -};
      +#define HCI_SYNC_HDR_HDL_POS        (0)
      +#define HCI_SYNC_HDR_HDL_MASK       (0x0FFF)
      +#define HCI_SYNC_HDR_PSF_FLAG_POS   (12)
      +#define HCI_SYNC_HDR_PSF_FLAG_MASK  (0x3000)
      +#define HCI_SYNC_HDR_RES_FLAG_POS   (14)
      +#define HCI_SYNC_HDR_RES_FLAG_MASK  (0xC000)
      +#define HCI_SYNC_HDR_DATA_FLAG_POS  (12)
      +#define HCI_SYNC_HDR_DATA_FLAG_MASK (0xF000)
       
       /// HCI Synchronous header: data length field length
       #define HCI_SYNC_HDR_DATA_LEN_POS   (HCI_SYNC_HDR_HDL_FLAGS_LEN)
      @@ -169,7 +165,7 @@ enum hci_syn_hdr_fields
       #define HCI_OPCODE(ocf, ogf)      (((ogf) << 10) | ocf)
       
       /// Maximum length of HCI advertising data fragments
      -#define HCI_ADV_DATA_FRAG_MAX_LEN        251
      +#define HCI_ADV_DATA_FRAG_MAX_LEN        252
       
       
       /**************************************************************************************
      @@ -379,7 +375,7 @@ enum hci_opcode
           HCI_RD_LOCAL_SUPP_CMDS_CMD_OPCODE         = 0x1002,
           HCI_RD_LOCAL_SUPP_FEATS_CMD_OPCODE        = 0x1003,
           HCI_RD_LOCAL_EXT_FEATS_CMD_OPCODE         = 0x1004,
      -    HCI_RD_BUF_SIZE_CMD_OPCODE                = 0x1005,
      +    HCI_RD_BUFF_SIZE_CMD_OPCODE               = 0x1005,
           HCI_RD_BD_ADDR_CMD_OPCODE                 = 0x1009,
           HCI_RD_LOCAL_SUPP_CODECS_CMD_OPCODE       = 0x100B,
       
      @@ -401,7 +397,7 @@ enum hci_opcode
       
           /// LE Commands Opcodes
           HCI_LE_SET_EVT_MASK_CMD_OPCODE                 = 0x2001,
      -    HCI_LE_RD_BUF_SIZE_CMD_OPCODE                  = 0x2002,
      +    HCI_LE_RD_BUFF_SIZE_CMD_OPCODE                 = 0x2002,
           HCI_LE_RD_LOCAL_SUPP_FEATS_CMD_OPCODE          = 0x2003,
           HCI_LE_SET_RAND_ADDR_CMD_OPCODE                = 0x2005,
           HCI_LE_SET_ADV_PARAM_CMD_OPCODE                = 0x2006,
      @@ -423,12 +419,12 @@ enum hci_opcode
           HCI_LE_RD_REM_FEATS_CMD_OPCODE                 = 0x2016,
           HCI_LE_ENC_CMD_OPCODE                          = 0x2017,
           HCI_LE_RAND_CMD_OPCODE                         = 0x2018,
      -    HCI_LE_EN_ENC_CMD_OPCODE                       = 0x2019,
      +    HCI_LE_START_ENC_CMD_OPCODE                    = 0x2019,
           HCI_LE_LTK_REQ_REPLY_CMD_OPCODE                = 0x201A,
           HCI_LE_LTK_REQ_NEG_REPLY_CMD_OPCODE            = 0x201B,
           HCI_LE_RD_SUPP_STATES_CMD_OPCODE               = 0x201C,
      -    HCI_LE_RX_TEST_V1_CMD_OPCODE                   = 0x201D,
      -    HCI_LE_TX_TEST_V1_CMD_OPCODE                   = 0x201E,
      +    HCI_LE_RX_TEST_CMD_OPCODE                      = 0x201D,
      +    HCI_LE_TX_TEST_CMD_OPCODE                      = 0x201E,
           HCI_LE_TEST_END_CMD_OPCODE                     = 0x201F,
           HCI_LE_REM_CON_PARAM_REQ_REPLY_CMD_OPCODE      = 0x2020,
           HCI_LE_REM_CON_PARAM_REQ_NEG_REPLY_CMD_OPCODE  = 0x2021,
      @@ -436,7 +432,7 @@ enum hci_opcode
           HCI_LE_RD_SUGGTED_DFT_DATA_LEN_CMD_OPCODE      = 0x2023,
           HCI_LE_WR_SUGGTED_DFT_DATA_LEN_CMD_OPCODE      = 0x2024,
           HCI_LE_RD_LOC_P256_PUB_KEY_CMD_OPCODE          = 0x2025,
      -    HCI_LE_GEN_DHKEY_V1_CMD_OPCODE                 = 0x2026,
      +    HCI_LE_GEN_DHKEY_CMD_OPCODE                    = 0x2026,
           HCI_LE_ADD_DEV_TO_RSLV_LIST_CMD_OPCODE         = 0x2027,
           HCI_LE_RMV_DEV_FROM_RSLV_LIST_CMD_OPCODE       = 0x2028,
           HCI_LE_CLEAR_RSLV_LIST_CMD_OPCODE              = 0x2029,
      @@ -449,8 +445,8 @@ enum hci_opcode
           HCI_LE_RD_PHY_CMD_OPCODE                       = 0x2030,
           HCI_LE_SET_DFT_PHY_CMD_OPCODE                  = 0x2031,
           HCI_LE_SET_PHY_CMD_OPCODE                      = 0x2032,
      -    HCI_LE_RX_TEST_V2_CMD_OPCODE                   = 0x2033,
      -    HCI_LE_TX_TEST_V2_CMD_OPCODE                   = 0x2034,
      +    HCI_LE_ENH_RX_TEST_CMD_OPCODE                  = 0x2033,
      +    HCI_LE_ENH_TX_TEST_CMD_OPCODE                  = 0x2034,
           HCI_LE_SET_ADV_SET_RAND_ADDR_CMD_OPCODE        = 0x2035,
           HCI_LE_SET_EXT_ADV_PARAM_CMD_OPCODE            = 0x2036,
           HCI_LE_SET_EXT_ADV_DATA_CMD_OPCODE             = 0x2037,
      @@ -477,7 +473,7 @@ enum hci_opcode
           HCI_LE_RD_RF_PATH_COMP_CMD_OPCODE              = 0x204C,
           HCI_LE_WR_RF_PATH_COMP_CMD_OPCODE              = 0x204D,
           HCI_LE_SET_PRIV_MODE_CMD_OPCODE                = 0x204E,
      -    HCI_LE_RX_TEST_V3_CMD_OPCODE                   = 0x204F,
      +    HCI_LE_SET_MIN_NUM_USED_CHAN_CMD_OPCODE        = 0x204F,
       
           ///Debug commands - OGF = 0x3F (spec)
           HCI_DBG_RD_MEM_CMD_OPCODE                   = 0xFC01,
      @@ -495,20 +491,39 @@ enum hci_opcode
           HCI_DBG_RD_KE_STATS_CMD_OPCODE              = 0xFC10,
           HCI_DBG_PLF_RESET_CMD_OPCODE                = 0xFC11,
           HCI_DBG_RD_MEM_INFO_CMD_OPCODE              = 0xFC12,
      -    HCI_VS_SET_PREF_SLAVE_LATENCY_CMD_OPCODE    = 0xFC13,
      -    HCI_VS_SET_PREF_SLAVE_EVT_DUR_CMD_OPCODE    = 0xFC14,
      -    HCI_VS_SET_MAX_RX_SIZE_AND_TIME_CMD_OPCODE  = 0xFC15,
      -    HCI_DBG_BLE_REG_RD_CMD_OPCODE               = 0xFC30,
      -    HCI_DBG_BLE_REG_WR_CMD_OPCODE               = 0xFC31,
      -    HCI_DBG_SEND_LLCP_CMD_OPCODE                = 0xFC35,
      +    HCI_DBG_HW_REG_RD_CMD_OPCODE                = 0xFC30,
      +    HCI_DBG_HW_REG_WR_CMD_OPCODE                = 0xFC31,
      +    HCI_DBG_SET_BD_ADDR_CMD_OPCODE              = 0xFC32,
      +    HCI_DBG_SET_TYPE_PUB_CMD_OPCODE             = 0xFC33,
      +    HCI_DBG_SET_TYPE_RAND_CMD_OPCODE            = 0xFC34,
      +    HCI_DBG_SET_CRC_CMD_OPCODE                  = 0xFC35,
           HCI_DBG_LLCP_DISCARD_CMD_OPCODE             = 0xFC36,
      +    HCI_DBG_RESET_RX_CNT_CMD_OPCODE             = 0xFC37,
      +    HCI_DBG_RESET_TX_CNT_CMD_OPCODE             = 0xFC38,
           HCI_DBG_RF_REG_RD_CMD_OPCODE                = 0xFC39,
           HCI_DBG_RF_REG_WR_CMD_OPCODE                = 0xFC3A,
      +    HCI_DBG_SET_TX_PW_CMD_OPCODE                = 0xFC3B,
           HCI_DBG_RF_SWITCH_CLK_CMD_OPCODE            = 0xFC3C,
           HCI_DBG_RF_WR_DATA_TX_CMD_OPCODE            = 0xFC3D,
           HCI_DBG_RF_RD_DATA_RX_CMD_OPCODE            = 0xFC3E,
           HCI_DBG_RF_CNTL_TX_CMD_OPCODE               = 0xFC3F,
           HCI_DBG_RF_SYNC_P_CNTL_CMD_OPCODE           = 0xFC40,
      +    HCI_TESTER_SET_LE_PARAMS_CMD_OPCODE         = 0xFC40,
      +    HCI_DBG_WR_DLE_DFT_VALUE_CMD_OPCODE         = 0xFC41,
      +#if (BLE_EMB_PRESENT)
      +#if (BLE_TESTER)
      +    HCI_DBG_BLE_TST_LLCP_PT_EN_CMD_OPCODE       = 0xFC42,
      +    HCI_DBG_BLE_TST_SEND_LLCP_CMD_OPCODE        = 0xFC43,
      +#endif // (BLE_TESTER)
      +#if (BLE_AUDIO)
      +    HCI_DBG_AUDIO_CONFIGURE_CMD_OPCODE          = 0xFC50,
      +    HCI_DBG_AUDIO_SET_MODE_CMD_OPCODE           = 0xFC51,
      +    HCI_DBG_AUDIO_RESET_CMD_OPCODE              = 0xFC52,
      +    HCI_DBG_AUDIO_SET_POINTER_CMD_OPCODE        = 0xFC53,
      +    HCI_DBG_AUDIO_ALLOCATE_CMD_OPCODE           = 0xFC54,
      +    HCI_DBG_AUDIO_GET_VX_CH_CMD_OPCODE          = 0xFC55,
      +#endif
      +#endif // (BLE_EMB_PRESENT)
       
           #if (RW_DEBUG && BT_EMB_PRESENT)
           HCI_DBG_BT_DISCARD_LMP_EN_CMD_OPCODE        = 0xFC44,
      @@ -588,7 +603,7 @@ enum hci_evt_code
           HCI_SLV_PAGE_RSP_TO_EVT_CODE               = 0x54,
           HCI_CON_SLV_BCST_CH_MAP_CHG_EVT_CODE       = 0x55,
           HCI_AUTH_PAYL_TO_EXP_EVT_CODE              = 0x57,
      -    HCI_MAX_EVT_MSK_PAGE_2_CODE                = 0x59,
      +    HCI_MAX_EVT_MSK_PAGE_2_CODE                = 0x58,
           HCI_DBG_META_EVT_CODE                      = 0xFF,
       
           /// LE Events Subcodes
      @@ -605,16 +620,20 @@ enum hci_evt_code
           HCI_LE_DIR_ADV_REP_EVT_SUBCODE             = 0x0B,
           HCI_LE_PHY_UPD_CMP_EVT_SUBCODE             = 0x0C,
           HCI_LE_EXT_ADV_REPORT_EVT_SUBCODE          = 0x0D,
      -    HCI_LE_PER_ADV_SYNC_EST_EVT_SUBCODE        = 0x0E,
      -    HCI_LE_PER_ADV_REPORT_EVT_SUBCODE          = 0x0F,
      -    HCI_LE_PER_ADV_SYNC_LOST_EVT_SUBCODE       = 0x10,
      +    HCI_LE_PERIODIC_ADV_SYNC_EST_EVT_SUBCODE   = 0x0E,
      +    HCI_LE_PERIODIC_ADV_REPORT_EVT_SUBCODE     = 0x0F,
      +    HCI_LE_PERIODIC_ADV_SYNC_LOST_EVT_SUBCODE  = 0x10,
           HCI_LE_SCAN_TIMEOUT_EVT_SUBCODE            = 0x11,
           HCI_LE_ADV_SET_TERMINATED_EVT_SUBCODE      = 0x12,
           HCI_LE_SCAN_REQ_RCVD_EVT_SUBCODE           = 0x13,
           HCI_LE_CH_SEL_ALGO_EVT_SUBCODE             = 0x14,
       
      +    /// DBG Events Subcodes
      +    #if (BLE_EMB_PRESENT && BLE_TESTER)
      +    HCI_DBG_BLE_TST_LLCP_RECV_EVT_SUBCODE      = 0x01,
      +    #endif // (BLE_EMB_PRESENT && BLE_TESTER)
           #if (RW_DEBUG)
      -    HCI_DBG_ASSERT_EVT_SUBCODE              = 0x02,
      +    HCI_DBG_ASSERT_ERR_EVT_SUBCODE             = 0x02,
           #endif //(RW_DEBUG)
       };
       
      @@ -633,8 +652,8 @@ enum hci_evt_mask_page
           HCI_PAGE_LE,
       };
       
      -/// HCI ACL data packet structure
      -struct hci_acl_data
      +/// HCI ACL data RX  packet structure
      +struct hci_ble_acl_data_rx
       {
           /// bits[00:11]: Connection handle
           /// bits[12:13]: Packet boundary flag
      @@ -648,19 +667,56 @@ struct hci_acl_data
           void *hcibuffer;
       };
       
      -/// HCI Synchronous data packet structure
      -struct hci_sync_data
      +/// HCI ACL data TX packet structure
      +struct hci_ble_acl_data_tx
       {
           /// bits[00:11]: Connection handle
      -    /// bits[12:13]: Packet status flag
      -    uint16_t  conhdl_psf;
      +    /// bits[12:13]: Packet boundary flag
      +    /// bits[14:15]: Broadcast flag
      +    uint16_t  conhdl_pb_bc_flag;
           /// length of the data
      -    uint8_t  length;
      +    uint16_t  length;
      +    /// Memory Pointer address
      +    uint32_t  buf_ptr;
      +};
      +
      +#if (BT_EMB_PRESENT)
      +/// HCI ACL data packet structure
      +struct hci_bt_acl_data_tx
      +{
      +    /// Buffer element
      +    struct bt_em_acl_buf_elt* buf_elt;
      +};
      +
      +/// HCI ACL data Rx packet structure
      +struct hci_bt_acl_data_rx
      +{
           /// EM buffer pointer
      -    uint16_t  buf_ptr;
      +    uint16_t buf_ptr;
      +    /// Data length + Data Flags (PBF + BF)
      +    uint16_t data_len_flags;
       };
       
      +/// HCI Synchronous data packet structure
      +struct hci_bt_sync_data_tx
      +{
      +    /// Buffer element
      +    struct bt_em_sync_buf_elt* buf_elt;
      +};
       
      +/// HCI Synchronous data Rx packet structure
      +struct hci_bt_sync_data_rx
      +{
      +    /// EM buffer pointer
      +    uint16_t buf_ptr;
      +    /// Data length
      +    uint8_t data_len;
      +    /// Packet status flag
      +    uint8_t packet_status_flag;
      +    /// Synchronous link identifier
      +    uint8_t sync_link_id;
      +};
      +#endif // (BT_EMB_PRESENT)
       
       
       /*
      @@ -873,13 +929,13 @@ struct hci_sniff_mode_cmd
       {
           ///Connection handle
           uint16_t    conhdl;
      -    /// Maximum interval (in slots)
      +    ///Sniff max interval
           uint16_t    max_int;
      -    /// Minimum interval (in slots)
      +    ///Sniff min interval
           uint16_t    min_int;
      -    /// Attempts (number of receive slots) (in slots)
      +    ///Sniff attempt
           uint16_t    attempt;
      -    /// Timeout (number of receive slots) (in slots)
      +    ///Sniff timeout
           uint16_t    timeout;
       };
       
      @@ -888,11 +944,11 @@ struct hci_sniff_sub_cmd
       {
           ///Connection handle
           uint16_t    conhdl;
      -    /// Maximum latency used to calculate the maximum sniff subrate that the remote device may use (in slots)
      +    ///Sniff max latency
           uint16_t    max_lat;
      -    /// Minimum base sniff subrate timeout that the remote device may use (in slots)
      +    ///Minimun remote TO
           uint16_t    min_rem_to;
      -    /// Minimum base sniff subrate timeout that the local device may use (in slots)
      +    ///Minimun local TO
           uint16_t    min_loc_to;
       };
       
      @@ -993,11 +1049,11 @@ struct hci_rd_enh_tx_pwr_lvl_cmd_cmp_evt
           ///Connection handle
           uint16_t conhdl;
           ///Transmit power GFSK
      -    int8_t pw_gfsk;
      +    uint8_t pw_gfsk;
           ///Transmit power DQPSK
      -    int8_t pw_dqpsk;
      +    uint8_t pw_dqpsk;
           ///Transmit power 8DPSK
      -    int8_t pw_8dpsk;
      +    uint8_t pw_8dpsk;
       };
       
       
      @@ -1012,7 +1068,7 @@ struct hci_inq_cmd
       {
           ///Lap
           struct lap  lap;
      -    ///Inquiry Length in units of 1.28 s
      +    ///Inquiry Length
           uint8_t     inq_len;
           ///Number of response
           uint8_t     nb_rsp;
      @@ -1025,7 +1081,7 @@ struct hci_per_inq_mode_cmd
           uint16_t min_per_len;
           ///lap
           struct lap lap;
      -    ///Inquiry length in units of 1.28 s
      +    ///Inquiry length
           uint8_t inq_len;
           ///Number of response
           uint8_t nb_rsp;
      @@ -1330,7 +1386,7 @@ struct hci_rem_oob_ext_data_req_reply_cmd
       };
       
       
      -struct hci_le_gen_dhkey_v1_cmd
      +struct hci_le_generate_dh_key_cmd
       {
           uint8_t public_key[64];
       };
      @@ -1759,9 +1815,9 @@ struct hci_host_nb_cmp_pkts_cmd
           ///Number of handles for which the completed packets number is given
           uint8_t     nb_of_hdl;
           ///Array of connection handles
      -    uint16_t    con_hdl[BLE_ACTIVITY_MAX+1];     // ensure that at least 1 element is present
      +    uint16_t    con_hdl[BLE_CONNECTION_MAX+1];     // ensure that at least 1 element is present
           ///Array of number of completed packets values for connection handles.
      -    uint16_t    nb_comp_pkt[BLE_ACTIVITY_MAX+1]; // ensure that at least 1 element is present
      +    uint16_t    nb_comp_pkt[BLE_CONNECTION_MAX+1]; // ensure that at least 1 element is present
       };
       #endif //BLE_EMB_PRESENT || BLE_HOST_PRESENT
       
      @@ -2003,8 +2059,10 @@ struct hci_set_external_frame_config_cmd
           uint16_t ext_fr_sync_assert_jitter;
           /// Ext_Frame_Num_Periods
           uint8_t ext_fr_num_periods;
      -    /// Period Durations & Types
      -    struct ext_fr_period period[1/*__ARRAY_EMPTY*/];
      +    /// Period_Duration[i]
      +    uint16_t period_duration[__ARRAY_EMPTY];
      +    /// Period_Type[i]
      +    //uint8_t period_type[__ARRAY_EMPTY];
       };
       
       /// HCI Set MWS Signaling command
      @@ -2097,8 +2155,10 @@ struct hci_set_mws_scan_freq_table_cmd
       {
           ///Num_Scan_Frequencies
           uint8_t num_scan_frequencies;
      -    ///Scan_Frequencys Low & High
      -    struct mws_scan_freq scan_freq[1/*__ARRAY_EMPTY*/];
      +    ///Scan_Frequency_Low[i]
      +    uint16_t scan_frequency_low[1/*__ARRAY_EMPTY*/];
      +    ///Scan_Frequency_High[i]
      +    uint16_t scan_frequency_high[1/*__ARRAY_EMPTY*/];
       };
       
       /// HCI Set MWS Pattern Configuration command
      @@ -2107,9 +2167,11 @@ struct hci_set_mws_pattern_config_cmd
           ///MWS_PATTERN_Index
           uint8_t mws_pattern_index;
           ///MWS_PATTERN_NumIntervals
      -    uint8_t num_intervals;
      -    ///MWS_PATTERN_Interval Duration & Type
      -    struct mws_pattern_intv intv[1/*__ARRAY_EMPTY*/];
      +    uint8_t mws_pattern_num_intervals;
      +    ///MWS_PATTERN_IntervalDuration[i]
      +    uint16_t mws_pattern_interval_duration[1/*__ARRAY_EMPTY*/];
      +    ///MWS_PATTERN_IntervalType[i]
      +    uint8_t mws_pattern_interval_type[1/*__ARRAY_EMPTY*/];
       };
       
       /// Hci Get MWS Transport Layer Configuration command complete event
      @@ -2119,8 +2181,14 @@ struct hci_get_mws_transport_layer_config_cmd_cmp_evt
           uint8_t status;
           ///Num_Transports
           uint8_t num_transports;
      -    ///Transport_Layers
      -    struct mws_transport tran[1/*__ARRAY_EMPTY*/];
      +    ///Transport_Layer[i]
      +    uint8_t transport_layer[1/*__ARRAY_EMPTY*/];
      +    ///Num_Baud_Rates[i]
      +    uint8_t num_baud_rates[1/*__ARRAY_EMPTY*/];
      +    ///To_MWS_Baud_Rate[k]
      +    uint32_t to_mws_baud_rate[1/*__ARRAY_EMPTY*/];
      +    ///From_MWS_Baud_Rate[k]
      +    uint32_t from_mws_baud_rate[1/*__ARRAY_EMPTY*/];
       };
       
       /// HCI read Secure Connections Host Support complete event
      @@ -2368,7 +2436,7 @@ struct hci_rd_local_ext_feats_cmd_cmp_evt
       };
       
       ///HCI command complete event structure for the Read Buffer Size Command
      -struct hci_rd_buf_size_cmd_cmp_evt
      +struct hci_rd_buff_size_cmd_cmp_evt
       {
           /// Status of the command reception
           uint8_t     status;
      @@ -2416,7 +2484,7 @@ struct hci_rd_rssi_cmd_cmp_evt
           ///Connection handle
           uint16_t conhdl;
           ///RSSI value
      -    int8_t rssi;
      +    uint8_t rssi;
       };
       
       struct hci_rd_clk_cmd
      @@ -2467,8 +2535,38 @@ struct hci_wr_sp_dbg_mode_cmd
       };
       
       
      +/// * TCI Event subcodes
      +enum tci_evt_subcode
      +{
      +     TCI_LMP_TX_EVENT    = 0x22,
      +     TCI_LMP_RX_EVENT    = 0x23,
      +     TCI_LC_TX_EVENT     = 0x24,
      +     TCI_LC_RX_EVENT     = 0x25,
      +     TCI_BB_TX_EVENT     = 0x26,
      +     TCI_BB_RX_EVENT     = 0x27,
      +     TCI_HW_ERROR_EVENT  = 0x28,
      +     TCI_RADIO_EVENT     = 0x30,
      +     TCI_INTERRUPT_EVENT = 0x40,
      +};
       
      +/// LMP direction
      +#define TCI_LMP_DIR_TX  0
      +#define TCI_LMP_DIR_RX  1
       
      +/// HCI tci lmp exchange event structure
      +struct hci_tci_lmp_evt
      +{
      +    ///code
      +    uint8_t  tci_code;
      +    ///length
      +    uint8_t  evt_len;
      +    ///subcode
      +    uint8_t  subcode;
      +    ///evt direction
      +    uint8_t  direction;
      +    ///lmp evt body
      +    uint8_t  body[17];
      +};
       
       /*
        * HCI LE CONTROLLER COMMANDS PARAMETERS
      @@ -2556,7 +2654,7 @@ struct hci_le_set_scan_en_cmd
           ///Scan enable - 0=disabled, 1=enabled
           uint8_t        scan_en;
           ///Enable for duplicates filtering - 0 =disabled/ 1=enabled
      -    uint8_t        filter_duplic;
      +    uint8_t        filter_duplic_en;
       };
       
       ///HCI LE Create Connection Command parameters structure
      @@ -2633,10 +2731,10 @@ struct hci_le_set_ext_scan_en_cmd
           ///Scan enable - 0=disabled, 1=enabled
           uint8_t             scan_en;
           ///Filter duplicates - 0=disabled, 1=enabled, 2=enabled & reset each scan period
      -    uint8_t             filter_duplic;
      -    ///Scan duration (Time=N*10ms)  | 0x0000: Scan continuously until explicitly disable
      +    uint8_t             filter_duplic_en;
      +    ///Scan duration (Time=N*10ms)
           uint16_t            duration;
      -    ///Scan period (Time=N*1.28sec) | 0x0000: Periodic scanning disabled
      +    ///Scan period (Time=N*1.28sec)
           uint16_t            period;
       };
       
      @@ -2678,8 +2776,8 @@ struct hci_le_ext_create_con_cmd
       ///HCI LE Periodic Advertising Create Sync Command parameters strucutre
       struct hci_le_per_adv_create_sync_cmd
       {
      -    /// Options (@see enum per_sync_opt)
      -    uint8_t         options;
      +    ///Filter policy
      +    uint8_t         filter_policy;
           ///Advertising SID
           uint8_t         adv_sid;
           ///Advertising address type
      @@ -2740,22 +2838,22 @@ struct hci_le_set_host_ch_class_cmd
       };
       
       
      -///HCI LE Receiver Test v1 Command parameters structure
      -struct hci_le_rx_test_v1_cmd
      +///HCI LE Receiver Test Command parameters structure
      +struct hci_le_rx_test_cmd
       {
      -    /// RX channel, range: 0x00 to 0x27
      -    uint8_t        rx_channel;
      +    ///RX frequency for Rx test
      +    uint8_t        rx_freq;
       };
       
      -///HCI LE Transmitter Test v1 Command parameters structure
      -struct hci_le_tx_test_v1_cmd
      +///HCI LE Transmitter Test Command parameters structure
      +struct hci_le_tx_test_cmd
       {
      -    /// TX channel, range: 0x00 to 0x27
      -    uint8_t        tx_channel;
      -    /// Length of test data in bytes, range: 0x00 to 0xFF
      +    ///TX frequency for Tx test
      +    uint8_t        tx_freq;
      +    ///TX test data length
           uint8_t        test_data_len;
      -    /// Packet payload
      -    uint8_t        pkt_payl;
      +    ///TX test payload type - see enum
      +    uint8_t        pk_payload_type;
       };
       
       ///HCI LE Encrypt Command parameters structure
      @@ -2786,8 +2884,8 @@ struct hci_le_con_update_cmd
           uint16_t       ce_len_max;
       };
       
      -/// HCI LE Enable Encryption Command parameters structure
      -struct hci_le_en_enc_cmd
      +/// HCI LE Start Encryption Command parameters structure
      +struct hci_le_start_enc_cmd
       {
           ///Connection handle
           uint16_t        conhdl;
      @@ -2970,7 +3068,7 @@ struct hci_inq_res_with_rssi_evt
           ///Clock Offset
           uint16_t     clk_off;
           ///Rssi
      -    int8_t       rssi;
      +    uint8_t      rssi;
       
       };
       
      @@ -2990,7 +3088,7 @@ struct hci_ext_inq_res_evt
           ///Clock Offset
           uint16_t        clk_off;
           ///RSSi
      -    int8_t          rssi;
      +    uint8_t         rssi;
           ///Extended inquiry response data
           struct eir      eir;
       };
      @@ -3563,7 +3661,7 @@ struct hci_le_rd_wlst_size_cmd_cmp_evt
       };
       
       ///HCI command complete event structure for the Read Buffer Size Command
      -struct hci_le_rd_buf_size_cmd_cmp_evt
      +struct hci_le_rd_buff_size_cmd_cmp_evt
       {
           /// Status of the command reception
           uint8_t     status;
      @@ -3583,7 +3681,7 @@ struct hci_le_rand_cmd_cmp_evt
       };
       
       ///HCI command complete event structure for Read Supported States Command
      -struct hci_le_rd_supp_states_cmd_cmp_evt
      +struct hci_rd_supp_states_cmd_cmp_evt
       {
           /// Status of the command reception
           uint8_t             status;
      @@ -3591,6 +3689,16 @@ struct hci_le_rd_supp_states_cmd_cmp_evt
           struct le_states    states;
       };
       
      +///HCI command complete event structure for Read Transmit Power Command
      +struct hci_rd_tx_pwr_cmd_cmp_evt
      +{
      +    /// Status of the command reception
      +    uint8_t             status;
      +    /// Minimum transmit power
      +    uint8_t             min_tx_pwr;
      +    /// Maximum transmit power
      +    uint8_t             max_tx_pwr;
      +};
       
       ///HCI command complete event structure for Test End
       struct hci_test_end_cmd_cmp_evt
      @@ -3648,11 +3756,11 @@ struct hci_le_per_adv_sync_est_evt
           uint8_t             adv_addr_type;
           ///Advertising address value
           struct bd_addr      adv_addr;
      -    /// Advertiser PHY (@enum le_phy_value)
      +    /// Advertiser PHY
           uint8_t             phy;
           /// Advertising interval (Time=N*1.25ms)
           uint16_t            interval;
      -    /// Advertiser clock accuracy (@see enum SCA)
      +    /// Advertiser clock accuracy
           uint8_t             adv_ca;
       };
       
      @@ -3666,13 +3774,15 @@ struct hci_le_per_adv_report_evt
           /// Tx Power
           uint8_t             tx_power;
           /// RSSI
      -    int8_t              rssi;
      +    uint8_t             rssi;
           /// Data Status
           uint8_t             status;
           ///Data length in advertising packet
           uint8_t             data_len;
           ///Data of advertising packet
           uint8_t             data[PER_ADV_DATA_MAX_LEN];
      +    ///Unused
      +    uint8_t             unused;
       };
       
       ///HCI LE periodic advertising sync lost event structure
      @@ -3872,7 +3982,7 @@ struct hci_rd_tx_pwr_lvl_cmd_cmp_evt
           ///Connection handle
           uint16_t conhdl;
           ///Value of TX power level
      -    int8_t     tx_pow_lvl;
      +    uint8_t     tx_pow_lvl;
       };
       
       /// HCI read remote information version command parameters structure
      @@ -4055,7 +4165,7 @@ struct hci_con_slv_bcst_ch_map_chg_evt
       };
       
       
      -struct hci_le_gen_dhkey_cmp_evt
      +struct hci_le_generate_dhkey_cmp_evt
       {
           ///LE Subevent code
           uint8_t      subcode;
      @@ -4063,7 +4173,7 @@ struct hci_le_gen_dhkey_cmp_evt
           uint8_t      dh_key[32];
       };
       
      -struct hci_le_rd_loc_p256_pub_key_cmp_evt
      +struct hci_le_generate_p256_public_key_cmp_evt
       {
           ///LE Subevent code
           uint8_t       subcode;
      @@ -4264,7 +4374,7 @@ struct hci_dbg_plf_reset_cmd
       };
       
       #if (RW_DEBUG && BT_EMB_PRESENT)
      -/// Send LMP Packets
      +/// Discard LMP Packets
       struct hci_dbg_bt_send_lmp_cmd
       {
           /// Connection handle
      @@ -4318,14 +4428,14 @@ struct hci_dbg_mws_coextst_scen_cmd
       #endif //RW_MWS_COEX
       
       ///HCI Debug HW Register Read command parameters - vendor specific
      -struct hci_dbg_ble_reg_rd_cmd
      +struct hci_dbg_hw_reg_rd_cmd
       {
           /// register address
           uint16_t reg_addr;
       };
       
       ///HCI Debug HW Register write command parameters - vendor specific
      -struct hci_dbg_ble_reg_wr_cmd
      +struct hci_dbg_hw_reg_wr_cmd
       {
           /// register address
           uint16_t reg_addr;
      @@ -4336,7 +4446,7 @@ struct hci_dbg_ble_reg_wr_cmd
       };
       
       ///HCI Debug HW Register Read Complete event parameters - vendor specific
      -struct hci_dbg_ble_reg_rd_cmd_cmp_evt
      +struct hci_dbg_hw_reg_rd_cmd_cmp_evt
       {
           /// status
           uint8_t  status;
      @@ -4347,7 +4457,7 @@ struct hci_dbg_ble_reg_rd_cmd_cmp_evt
       };
       
       ///HCI Debug HW Register Write Complete event parameters - vendor specific
      -struct hci_dbg_ble_reg_wr_cmd_cmp_evt
      +struct hci_dbg_hw_reg_wr_cmd_cmp_evt
       {
           /// status
           uint8_t  status;
      @@ -4355,9 +4465,36 @@ struct hci_dbg_ble_reg_wr_cmd_cmp_evt
           uint16_t reg_addr;
       };
       
      +///HCI Debug write DLE default value command parameters - vendor specific
      +struct hci_dbg_wr_dle_dft_value_cmd
      +{
      +    /// Max transmit packet size supported
      +    uint16_t suppted_max_tx_octets;
      +    /// Max transmit packet time supported
      +    uint16_t suppted_max_tx_time;
      +    /// Max receive packet size supported
      +    uint16_t suppted_max_rx_octets;
      +    /// Max receive packet time supported
      +    uint16_t suppted_max_rx_time;
       
      +};
       
      +#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
      +///HCI Debug bd address write command parameters - vendor specific
      +struct hci_dbg_set_bd_addr_cmd
      +{
      +    ///bd address to set
      +    struct bd_addr addr;
      +};
       
      +///HCI Debug crc write command parameters - vendor specific
      +struct hci_dbg_set_crc_cmd
      +{
      +    /// Handle pointing to the connection for which CRC has to be modified
      +    uint16_t conhdl;
      +    /// CRC to set
      +    struct crc_init crc;
      +};
       
       ///HCI Debug LLC discard command parameters - vendor specific
       struct hci_dbg_llcp_discard_cmd
      @@ -4368,22 +4505,159 @@ struct hci_dbg_llcp_discard_cmd
           uint8_t enable;
       };
       
      +///HCI Debug reset RX counter command parameters - vendor specific
      +struct hci_dbg_reset_rx_cnt_cmd
      +{
      +    /// Handle pointing to the connection for which the counter have to be reseted
      +    uint16_t conhdl;
      +};
       
      +///HCI Debug reset TX counter command parameters - vendor specific
      +struct hci_dbg_reset_tx_cnt_cmd
      +{
      +    /// Handle pointing to the connection for which the counter have to be reseted
      +    uint16_t conhdl;
      +};
       
      +///HCI Debug Set TX Power Level Command parameters
      +struct hci_dbg_set_tx_pw_cmd
      +{
      +    /// Connection handle
      +    uint16_t conhdl;
      +    /// Power level
      +    uint8_t  pw_lvl;
      +};
       
      +///HCI Debug configure audio command parameters - vendor specific
       
      +struct hci_dbg_audio_configure_audio_cmd
      +{
      +    /// Voice channel to be updated
      +    uint8_t     voice_channel;
      +    /// Configure transmitter size in bytes
      +    uint8_t     tx_size;
      +    /// Configure receiver size in bytes
      +    uint8_t     rx_size;
      +    /// Configure transmitter rate
      +    uint8_t     tx_rate;
      +    /// Configure receiver rate
      +    uint8_t     rx_rate;
      +    /// Configure number of retransmission
      +    uint8_t     nb_retx;
      +    /// Audio link priority
      +    uint8_t     priority;
      +    /// Encryption mode
      +    uint8_t     mode;
      +    /// Channel and mute configuration (@see enum audio_cfg)
      +    uint8_t     chan_mute_cfg;
      +    /// Mute Pattern
      +    uint8_t     mute_pattern;
      +};
       
      +struct hci_dbg_audio_set_pointer_cmd
      +{
      +    /// Voice channel to be updated
      +    uint8_t voice_channel;
      +    /// Rx or Tx selection
      +    uint8_t rx_tx_select;
      +    /// Tog to be updated
      +    uint8_t tog;
      +    /// Exchange memory pointer
      +    uint16_t    em_ptr;
      +};
      +///HCI Debug set audio mode command parameters - vendor specific
      +struct hci_audio_set_mode_cmd
      +{
      +    /// Voice channel to be updated
      +    uint8_t voice_channel;
      +    /// Mode
      +    uint8_t   mode;
      +};
       
      +///HCI Debug set audio mode command parameters - vendor specific
      +struct hci_dbg_audio_reset_cmd
      +{
      +    /// Voice channel to be updated
      +    uint8_t voice_channel;
      +};
       
      +///HCI Debug set audio mode command parameters - vendor specific
      +struct hci_dbg_audio_allocate_cmd
      +{
      +    /// Connection handle
      +    uint16_t conhdl;
      +    /// Audio mode
      +    uint8_t mode;
      +};
       
      +///HCI Debug set audio mode command parameters - vendor specific
      +struct hci_dbg_audio_get_vx_ch_cmd
      +{
      +    /// Connection handle
      +    uint16_t conhdl;
      +};
      +///HCI Tester set LE parameters
      +struct hci_tester_set_le_params_cmd
      +{
      +    /// Connection handle
      +    uint16_t conhdl;
      +    /// Tester features
      +    uint8_t  tester_feats;
      +    /// Preferred periodicity
      +    uint8_t  pref_period;
      +    /// Offset0
      +    uint16_t  offset0;
      +    /// Offset1
      +    uint16_t  offset1;
      +    /// Offset2
      +    uint16_t  offset2;
      +    /// Offset3
      +    uint16_t  offset3;
      +    /// Offset4
      +    uint16_t  offset4;
      +    /// Offset5
      +    uint16_t  offset5;
      +};
      +
      +/// HCI BLE Tester: enable LLCP pass through mechanism
      +struct hci_dbg_ble_tst_llcp_pt_en_cmd
      +{
      +    /// Connection handle
      +    uint16_t conhdl;
      +    /// Enable or not LLCP pass through mechanism
      +    uint8_t  enable;
      +};
       
      +/// HCI BLE Tester: send an LLCP PDU
      +struct hci_dbg_ble_tst_send_llcp_cmd
      +{
      +    /// Connection handle
      +    uint16_t conhdl;
      +    /// length of LLCP PDU
      +    uint8_t  length;
      +    /// LLCP PDU data
      +    uint8_t data[26];
      +};
       
       
      +/// HCI DBG Meta Event trigg when LLCP message received with LLCP pass through mechanism
      +struct hci_dbg_ble_tst_llcp_recv_evt
      +{
      +    ///DBG Subevent code
      +    uint8_t             subcode;
      +    ///Connection handle
      +    uint16_t            conhdl;
      +    /// length of LLCP message
      +    uint8_t             length;
      +    /// LLCP data
      +    uint8_t             data[26];
      +};
       
      +#endif //BLE_EMB_PRESENT || BLE_HOST_PRESENT
       
       #if (RW_DEBUG)
      -/// HCI DBG Meta Event indicating a SW assertion
      -struct hci_dbg_assert_evt
      +/// HCI DBG Meta Event indicating a SW assertion error
      +struct hci_dbg_assert_err_evt
       {
           ///DBG Subevent code
           uint8_t             subcode;
      @@ -4437,31 +4711,31 @@ struct hci_le_set_ext_adv_param_cmd_cmp_evt
           /// Status
           uint8_t            status;
           /// Selected Tx power
      -    int8_t             sel_tx_pwr;
      +    uint8_t            sel_tx_pwr;
       };
       
      -/// HCI LE Receiver Test v2 Command
      -struct hci_le_rx_test_v2_cmd
      +/// HCI LE Enhanced Receiver Test Command
      +struct hci_le_enh_rx_test_cmd
       {
      -    /// RX channel, range: 0x00 to 0x27
      -    uint8_t            rx_channel;
      -    /// PHY (@enum le_phy_value)
      -    uint8_t            phy;
      -    /// Modulation index (0: standard | 1: stable)
      -    uint8_t            mod_idx;
      +    /// Reception channel value
      +    uint8_t            channel;
      +    /// Reception PHY rate
      +    uint8_t            phys;
      +    /// Modulation index
      +    uint8_t            modulation_idx;
       };
       
      -/// HCI LE Transmitter Test v2 Command
      -struct hci_le_tx_test_v2_cmd
      +/// HCI LE Enhanced Transmitter Test Command
      +struct hci_le_enh_tx_test_cmd
       {
      -    /// TX channel, range: 0x00 to 0x27
      -    uint8_t            tx_channel;
      -    /// Length of test data in bytes, range: 0x00 to 0xFF
      -    uint8_t            test_data_len;
      -    /// Packet payload
      -    uint8_t            pkt_payl;
      -    /// PHY (@enum le_phy_value)
      -    uint8_t            phy;
      +    /// Transmit channel value
      +    uint8_t            channel;
      +    /// Length of the data to be transmitted in a packet
      +    uint8_t            payload_length;
      +    /// Type of the data contained in a packet
      +    uint8_t            payload_type;
      +    /// Transmit PHY rate
      +    uint8_t            phys;
       };
       
       ///HCI LE Set Advertising Set Random Address Command parameters structure
      @@ -4564,7 +4838,7 @@ struct hci_le_set_ext_scan_rsp_data_cmd
           uint8_t data[__ARRAY_EMPTY];
       };
       
      -///HCI LE Set Extended Advertising Enable Command parameters structure
      +///HCI LE Set Extended Advertising Enbale Command parameters structure
       struct hci_le_set_ext_adv_en_cmd
       {
           /// Enable
      @@ -4609,9 +4883,9 @@ struct hci_le_set_per_adv_param_cmd
       {
           /// Advertising handle
           uint8_t adv_hdl;
      -    /// Minimum advertising interval for periodic advertising (units of 1.25 ms)
      +    /// Minimum advertising interval for periodic advertising
           uint16_t adv_intv_min;
      -    /// Maximum advertising interval for periodic advertising (units of 1.25 ms)
      +    /// Maximum advertising interval for periodic advertising
           uint16_t adv_intv_max;
           /// Advertising properties
           uint16_t adv_prop;
      @@ -4707,8 +4981,8 @@ struct hci_le_rd_phy_cmd_cmp_evt
           uint8_t             rx_phy;
       };
       
      -/// HCI LE PHY Update Complete event
      -struct hci_le_phy_upd_cmp_evt
      +/// HCI command complete event structure for HCI LE PHY Update Command
      +struct hci_le_phy_update_cmp_evt
       {
           ///LE Subevent code
           uint8_t             subcode;
  • services/ble_stack/common/api/co_list.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/common/api/co_list.h bes/services/ble_stack/common/api/co_list.h
      index 56b07f37179..9437e782f66 100644
      --- a/services/ble_stack/common/api/co_list.h
      +++ b/services/ble_stack/common/api/co_list.h
      @@ -42,6 +42,13 @@
        * DEFINES
        ****************************************************************************************
        */
      +///list type
      +enum
      +{
      +    POOL_LINKED_LIST    = 0x00,
      +    RING_LINKED_LIST,
      +    LINK_TYPE_END
      +};
       
       /// structure of a list element header
       struct co_list_hdr
      @@ -84,18 +91,23 @@ void co_list_init(struct co_list *list);
       
       /**
        ****************************************************************************************
      - * @brief Construct a list of free elements representing a pool
      + * @brief Initialize a pool to default values, and initialize the relative free list.
        *
        * @param list           Pointer to the list structure
        * @param pool           Pointer to the pool to be initialized
      - * @param elmt_size      Size of one element of the pool (in bytes)
      - * @param elmt_cnt       Number of elements available in the pool
      + * @param elmt_size      Size of one element of the pool
      + * @param elmt_cnt       Nb of elements available in the pool
      + * @param default_value  Pointer to the default value of each element (may be NULL)
      + * @param list_type      Determine if the it is a ring list or not
      + *
        ****************************************************************************************
        */
       void co_list_pool_init(struct co_list *list,
                              void *pool,
                              size_t elmt_size,
      -                       uint32_t elmt_cnt);
      +                       uint32_t elmt_cnt,
      +                       void *default_value,
      +                       uint8_t list_type);
       
       /**
        ****************************************************************************************
      @@ -250,7 +262,7 @@ uint16_t co_list_size(struct co_list *list);
        * @return true if the list is empty, false else otherwise.
        ****************************************************************************************
        */
      -__INLINE bool co_list_is_empty(const struct co_list *const list)
      +__STATIC __INLINE bool co_list_is_empty(const struct co_list *const list)
       {
           bool listempty;
           listempty = (list->first == NULL);
      @@ -281,7 +293,7 @@ __STATIC __INLINE struct co_list_hdr *co_list_pick(const struct co_list *const l
        * @return The pointer to the next element.
        ****************************************************************************************
        */
      -__INLINE struct co_list_hdr *co_list_next(const struct co_list_hdr *const list_hdr)
      +__STATIC __INLINE struct co_list_hdr *co_list_next(const struct co_list_hdr *const list_hdr)
       {
           return(list_hdr->next);
       }
  • services/ble_stack/common/api/co_llcp.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/common/api/co_llcp.h bes/services/ble_stack/common/api/co_llcp.h
      index e1a760d85ea..7fb789beed8 100644
      --- a/services/ble_stack/common/api/co_llcp.h
      +++ b/services/ble_stack/common/api/co_llcp.h
      @@ -41,94 +41,96 @@
       /// Control packet op_code
       enum co_llcp_op_code
       {
      -    ///
      -    LL_CONNECTION_UPDATE_IND_OPCODE = 0x00,
      -    ///
      -    LL_CHANNEL_MAP_IND_OPCODE       = 0x01,
      -    ///
      -    LL_TERMINATE_IND_OPCODE         = 0x02,
      -    ///
      -    LL_ENC_REQ_OPCODE               = 0x03,
      -    ///
      -    LL_ENC_RSP_OPCODE               = 0x04,
      -    ///
      -    LL_START_ENC_REQ_OPCODE         = 0x05,
      -    ///
      -    LL_START_ENC_RSP_OPCODE         = 0x06,
      -    ///
      -    LL_UNKNOWN_RSP_OPCODE           = 0x07,
      -    ///
      -    LL_FEATURE_REQ_OPCODE           = 0x08,
      -    ///
      -    LL_FEATURE_RSP_OPCODE           = 0x09,
      -    ///
      -    LL_PAUSE_ENC_REQ_OPCODE         = 0x0A,
      -    ///
      -    LL_PAUSE_ENC_RSP_OPCODE         = 0x0B,
      -    ///
      -    LL_VERSION_IND_OPCODE           = 0x0C,
      -    ///
      -    LL_REJECT_IND_OPCODE            = 0x0D,
      -    ///
      -    LL_SLAVE_FEATURE_REQ_OPCODE     = 0x0E,
      -    ///
      -    LL_CONNECTION_PARAM_REQ_OPCODE  = 0x0F,
      -    ///
      -    LL_CONNECTION_PARAM_RSP_OPCODE  = 0x10,
      -    ///
      -    LL_REJECT_EXT_IND_OPCODE        = 0x11,
      -    ///
      -    LL_PING_REQ_OPCODE              = 0x12,
      -    ///
      -    LL_PING_RSP_OPCODE              = 0x13,
      -    ///
      -    LL_LENGTH_REQ_OPCODE            = 0x14,
      -    ///
      -    LL_LENGTH_RSP_OPCODE            = 0x15,
      -    ///
      -    LL_PHY_REQ_OPCODE               = 0x16,
      -    ///
      -    LL_PHY_RSP_OPCODE               = 0x17,
      -    ///
      -    LL_PHY_UPDATE_IND_OPCODE        = 0x18,
      -    ///
      -    LL_MIN_USED_CHANNELS_IND_OPCODE = 0x19,
      +    /// Connection update request
      +    LLCP_CONNECTION_UPDATE_IND_OPCODE,
      +    /// Channel map request
      +    LLCP_CHANNEL_MAP_IND_OPCODE,
      +    /// Termination indication
      +    LLCP_TERMINATE_IND_OPCODE,
      +    /// Encryption request
      +    LLCP_ENC_REQ_OPCODE,
      +    /// Encryption response
      +    LLCP_ENC_RSP_OPCODE,
      +    /// Start encryption request
      +    LLCP_START_ENC_REQ_OPCODE,
      +    /// Start encryption response
      +    LLCP_START_ENC_RSP_OPCODE,
      +    /// Unknown response
      +    LLCP_UNKNOWN_RSP_OPCODE,
      +    /// Feature request
      +    LLCP_FEATURE_REQ_OPCODE,
      +    /// Feature response
      +    LLCP_FEATURE_RSP_OPCODE,
      +    /// Pause encryption request
      +    LLCP_PAUSE_ENC_REQ_OPCODE,
      +    /// Pause encryption response
      +    LLCP_PAUSE_ENC_RSP_OPCODE,
      +    /// Version indication
      +    LLCP_VERSION_IND_OPCODE,
      +    /// Reject indication
      +    LLCP_REJECT_IND_OPCODE,
      +    /// Slave feature request
      +    LLCP_SLAVE_FEATURE_REQ_OPCODE,
      +    /// Connection parameters request
      +    LLCP_CONNECTION_PARAM_REQ_OPCODE,
      +    /// Connection parameters response
      +    LLCP_CONNECTION_PARAM_RSP_OPCODE,
      +    /// Reject indication extended
      +    LLCP_REJECT_IND_EXT_OPCODE,
      +    /// Ping request
      +    LLCP_PING_REQ_OPCODE,
      +    /// Ping response
      +    LLCP_PING_RSP_OPCODE,
      +    /// Ping request
      +    LLCP_LENGTH_REQ_OPCODE,
      +    /// Ping response
      +    LLCP_LENGTH_RSP_OPCODE,
      +    /// Phy request
      +    LLCP_PHY_REQ_OPCODE,
      +    /// Phy response
      +    LLCP_PHY_RSP_OPCODE,
      +    /// Phy update indication
      +    LLCP_PHY_UPD_IND_OPCODE,
      +    /// Min used channels indication
      +    LLCP_MIN_USED_CHANNELS_IND_OPCODE,
           /// Opcode length
      -    LL_OPCODE_MAX_OPCODE,
      +    LLCP_OPCODE_MAX_OPCODE,
       
      -    LL_OPCODE_DEBUG = 0xFF,
      +    #if (BLE_TESTER)
      +    LLCP_OPCODE_DEBUG = 0xFF,
      +    #endif // (BLE_TESTER)
       };
       
       /// LLCP PDU lengths (including op_code)
       enum co_llcp_length
       {
      -   LL_CONNECTION_UPDATE_IND_LEN     = 12,
      -   LL_CHANNEL_MAP_IND_LEN           = 8,
      -   LL_TERMINATE_IND_LEN             = 2,
      -   LL_ENC_REQ_LEN                   = 23,
      -   LL_ENC_RSP_LEN                   = 13,
      -   LL_START_ENC_REQ_LEN             = 1,
      -   LL_START_ENC_RSP_LEN             = 1,
      -   LL_UNKNOWN_RSP_LEN               = 2,
      -   LL_FEATURE_REQ_LEN               = 9,
      -   LL_FEATURE_RSP_LEN               = 9,
      -   LL_PAUSE_ENC_REQ_LEN             = 1,
      -   LL_PAUSE_ENC_RSP_LEN             = 1,
      -   LL_VERSION_IND_LEN               = 6,
      -   LL_REJECT_IND_LEN                = 2,
      -   LL_SLAVE_FEATURE_REQ_LEN         = 9,
      -   LL_REJECT_EXT_IND_LEN            = 3,
      -   LL_CONNECTION_PARAM_REQ_LEN      = 24,
      -   LL_CONNECTION_PARAM_RSP_LEN      = 24,
      -   LL_PING_REQ_LEN                  = 1,
      -   LL_PING_RSP_LEN                  = 1,
      -   LL_LENGTH_REQ_LEN                = 9,
      -   LL_LENGTH_RSP_LEN                = 9,
      -   LL_PHY_REQ_LEN                   = 3,
      -   LL_PHY_RSP_LEN                   = 3,
      -   LL_PHY_UPDATE_IND_LEN            = 5,
      -   LL_MIN_USED_CHANNELS_IND_LEN     = 3,
      -   LL_PDU_LENGTH_MAX                = 35,
      +   LLCP_CON_UPDATE_IND_LEN    = 12,
      +   LLCP_CHANNEL_MAP_IND_LEN   = 8,
      +   LLCP_TERM_IND_LEN          = 2,
      +   LLCP_ENC_REQ_LEN           = 23,
      +   LLCP_ENC_RSP_LEN           = 13,
      +   LLCP_ST_ENC_REQ_LEN        = 1,
      +   LLCP_ST_ENC_RSP_LEN        = 1,
      +   LLCP_UNKN_RSP_LEN          = 2,
      +   LLCP_FEAT_REQ_LEN          = 9,
      +   LLCP_FEAT_RSP_LEN          = 9,
      +   LLCP_PA_ENC_REQ_LEN        = 1,
      +   LLCP_PA_ENC_RSP_LEN        = 1,
      +   LLCP_VERS_IND_LEN          = 6,
      +   LLCP_REJ_IND_LEN           = 2,
      +   LLCP_SLAVE_FEATURE_REQ_LEN = 9,
      +   LLCP_REJECT_IND_EXT_LEN    = 3,
      +   LLCP_CON_PARAM_REQ_LEN     = 24,
      +   LLCP_CON_PARAM_RSP_LEN     = 24,
      +   LLCP_PING_REQ_LEN          = 1,
      +   LLCP_PING_RSP_LEN          = 1,
      +   LLCP_LENGTH_REQ_LEN        = 9,
      +   LLCP_LENGTH_RSP_LEN        = 9,
      +   LLCP_PHY_REQ_LEN           = 3,
      +   LLCP_PHY_RSP_LEN           = 3,
      +   LLCP_PHY_UPD_IND_LEN       = 5,
      +   LLCP_MIN_USED_CH_IND_LEN   = 3,
      +   LLCP_PDU_LENGTH_MAX        = 34
       };
       
       /// PDU lengths
      @@ -144,8 +146,8 @@ enum co_pdu_length
        ****************************************************************************************
        */
       
      -/// LL_CONNECTION_UPDATE_IND structure.
      -struct  ll_connection_update_ind
      +/// LLCP_CONNECTION_UPDATE_IND structure.
      +struct  llcp_con_update_ind
       {
           /// op_code
           uint8_t         op_code;
      @@ -163,8 +165,8 @@ struct  ll_connection_update_ind
           uint16_t        instant;
       };
       
      -/// LL_CHANNEL_MAP_IND structure.
      -struct  ll_channel_map_ind
      +/// LLCP_CHANNEL_MAP_IND structure.
      +struct  llcp_channel_map_ind
       {
           /// op_code
           uint8_t            op_code;
      @@ -174,8 +176,8 @@ struct  ll_channel_map_ind
           uint16_t           instant;
       };
       
      -/// LL_TERMINATE_IND structure.
      -struct  ll_terminate_ind
      +/// LLCP_TERMINATE_IND structure.
      +struct  llcp_terminate_ind
       {
           /// op_code
           uint8_t         op_code;
      @@ -183,8 +185,8 @@ struct  ll_terminate_ind
           uint8_t         err_code;
       };
       
      -/// LL_ENC_REQ structure.
      -struct  ll_enc_req
      +/// LLCP_ENC_REQ structure.
      +struct  llcp_enc_req
       {
           /// op_code
           uint8_t               op_code;
      @@ -198,8 +200,8 @@ struct  ll_enc_req
           struct init_vect      ivm;
       };
       
      -/// LL_ENC_RSP structure.
      -struct  ll_enc_rsp
      +/// LLCP_ENC_RSP structure.
      +struct  llcp_enc_rsp
       {
           /// op_code
           uint8_t             op_code;
      @@ -209,22 +211,22 @@ struct  ll_enc_rsp
           struct init_vect    ivs;
       };
       
      -/// LL_START_ENC_REQ structure.
      -struct  ll_start_enc_req
      +/// LLCP_START_ENC_REQ structure.
      +struct  llcp_start_enc_req
       {
           /// op_code
           uint8_t             op_code;
       };
       
      -/// LL_START_ENC_RSP structure.
      -struct  ll_start_enc_rsp
      +/// LLCP_START_ENC_RSP structure.
      +struct  llcp_start_enc_rsp
       {
           /// op_code
           uint8_t             op_code;
       };
       
      -/// LL_UNKNOWN_RSP structure.
      -struct  ll_unknown_rsp
      +/// LLCP_UNKNOWN_RSP structure.
      +struct  llcp_unknown_rsp
       {
           /// op_code
           uint8_t         op_code;
      @@ -232,8 +234,8 @@ struct  ll_unknown_rsp
           uint8_t         unk_type;
       };
       
      -/// LL_FEATURE_REQ structure.
      -struct  ll_feature_req
      +/// LLCP_FEATURE_REQ structure.
      +struct  llcp_feats_req
       {
           /// op_code
           uint8_t             op_code;
      @@ -242,8 +244,8 @@ struct  ll_feature_req
       };
       
       
      -/// LL_FEATURE_RSP structure.
      -struct  ll_feature_rsp
      +/// LLCP_FEATURE_RSP structure.
      +struct  llcp_feats_rsp
       {
           /// op_code
           uint8_t             op_code;
      @@ -251,22 +253,22 @@ struct  ll_feature_rsp
           struct le_features  feats;
       };
       
      -/// LL_PAUSE_ENC_REQ structure.
      -struct  ll_pause_enc_req
      +/// LLCP_PAUSE_ENC_REQ structure.
      +struct  llcp_pause_enc_req
       {
           /// op_code
           uint8_t             op_code;
       };
       
      -/// LL_PAUSE_ENC_RSP structure.
      -struct  ll_pause_enc_rsp
      +/// LLCP_PAUSE_ENC_RSP structure.
      +struct  llcp_pause_enc_rsp
       {
           /// op_code
           uint8_t             op_code;
       };
       
      -/// LL_VERSION_IND structure
      -struct ll_version_ind
      +/// LLCP_VERS_IND structure
      +struct llcp_vers_ind
       {
           /// op_code
           uint8_t     op_code;
      @@ -278,8 +280,8 @@ struct ll_version_ind
           uint16_t    subvers;
       };
       
      -/// LL_REJECT_IND structure.
      -struct  ll_reject_ind
      +/// LLCP_REJECT_IND structure.
      +struct  llcp_reject_ind
       {
           /// op_code
           uint8_t         op_code;
      @@ -287,8 +289,8 @@ struct  ll_reject_ind
           uint8_t         err_code;
       };
       
      -/// LL_SLAVE_FEATURE_REQ structure.
      -struct  ll_slave_feature_req
      +/// LLCP_SLAVE_FEATURE_REQ structure.
      +struct  llcp_slave_feature_req
       {
           /// op_code
           uint8_t             op_code;
      @@ -296,8 +298,8 @@ struct  ll_slave_feature_req
           struct le_features  feats;
       };
       
      -/// LL_CONNECTION_PARAM_REQ structure.
      -struct  ll_connection_param_req
      +/// LLCP_CONNECTION_PARAM_REQ structure.
      +struct  llcp_con_param_req
       {
           /// op_code
           uint8_t         op_code;
      @@ -327,8 +329,8 @@ struct  ll_connection_param_req
           uint16_t        offset5;
       };
       
      -/// LL_CONNECTION_PARAM_RSP structure.
      -struct  ll_connection_param_rsp
      +/// LLCP_CONNECTION_PARAM_RSP structure.
      +struct  llcp_con_param_rsp
       {
           /// op_code
           uint8_t          op_code;
      @@ -358,8 +360,8 @@ struct  ll_connection_param_rsp
           uint16_t        offset5;
       };
       
      -/// LL_REJECT_EXT_IND structure.
      -struct  ll_reject_ext_ind
      +/// LLCP_REJECT_IND structure.
      +struct  llcp_reject_ind_ext
       {
           /// op_code
           uint8_t         op_code;
      @@ -369,22 +371,22 @@ struct  ll_reject_ext_ind
           uint8_t         err_code;
       };
       
      -/// LL_PING_REQ structure.
      -struct  ll_ping_req
      +/// LLCP_PING_REQ structure.
      +struct  llcp_ping_req
       {
           /// op_code
           uint8_t         op_code;
       };
       
      -/// LL_PING_RSP structure.
      -struct  ll_ping_rsp
      +/// LLCP_PING_RSP structure.
      +struct  llcp_ping_rsp
       {
           /// op_code
           uint8_t         op_code;
       };
       
      -/// LL_LENGTH_REQ structure.
      -struct  ll_length_req
      +/// LLCP_LENGTH_REQ structure.
      +struct  llcp_length_req
       {
           /// op_code
           uint8_t     op_code;
      @@ -398,8 +400,8 @@ struct  ll_length_req
           uint16_t    max_tx_time;
       };
       
      -/// LL_LENGTH_RSP structure.
      -struct  ll_length_rsp
      +/// LLCP_LENGTH_RSP structure.
      +struct  llcp_length_rsp
       {
           /// op_code
           uint8_t     op_code;
      @@ -412,8 +414,8 @@ struct  ll_length_rsp
           /// The max time in transmission (unit of microsecond)
           uint16_t    max_tx_time;
       };
      -/// LL_PHY_REQ structure.
      -struct  ll_phy_req
      +/// LLCP_PHY_REQ structure.
      +struct  llcp_phy_req
       {
           /// op_code
           uint8_t    op_code;
      @@ -423,8 +425,8 @@ struct  ll_phy_req
           uint8_t    rx_phys;
       };
       
      -/// LL_PHY_RSP structure.
      -struct  ll_phy_rsp
      +/// LLCP_PHY_RSP structure.
      +struct  llcp_phy_rsp
       {
           /// op_code
           uint8_t    op_code;
      @@ -434,8 +436,8 @@ struct  ll_phy_rsp
           uint8_t    rx_phys;
       };
       
      -/// LL_PHY_UPDATE_IND structure.
      -struct  ll_phy_update_ind
      +/// LLCP_PHY_UPD_IND structure.
      +struct  llcp_phy_upd_ind
       {
           /// op_code
           uint8_t    op_code;
      @@ -447,8 +449,8 @@ struct  ll_phy_update_ind
           uint16_t   instant;
       };
       
      -/// LL_MIN_USED_CHANNELS_IND structure.
      -struct  ll_min_used_channels_ind
      +/// LLCP_MIN_USED_CHANNELS_IND structure.
      +struct  llcp_min_used_ch_ind
       {
           /// op_code
           uint8_t    op_code;
      @@ -464,31 +466,31 @@ union llcp_pdu
           /// op_code
           uint8_t  op_code;
       
      -    struct ll_connection_update_ind con_update_ind;
      -    struct ll_channel_map_ind       channel_map_ind;
      -    struct ll_terminate_ind         terminate_ind;
      -    struct ll_enc_req               enc_req;
      -    struct ll_enc_rsp               enc_rsp;
      -    struct ll_start_enc_req         start_enc_req;
      -    struct ll_start_enc_rsp         start_enc_rsp;
      -    struct ll_unknown_rsp           unknown_rsp;
      -    struct ll_feature_req           feats_req;
      -    struct ll_feature_rsp           feats_rsp;
      -    struct ll_pause_enc_req         pause_enc_req;
      -    struct ll_pause_enc_rsp         pause_enc_rsp;
      -    struct ll_version_ind           vers_ind;
      -    struct ll_reject_ind            reject_ind;
      -    struct ll_slave_feature_req     slave_feature_req;
      -    struct ll_connection_param_req  con_param_req;
      -    struct ll_connection_param_rsp  con_param_rsp;
      -    struct ll_reject_ext_ind        reject_ind_ext;
      -    struct ll_ping_req              ping_req;
      -    struct ll_ping_rsp              ping_rsp;
      -    struct ll_length_req            length_req;
      -    struct ll_length_rsp            length_rsp;
      -    struct ll_phy_req               phy_req;
      -    struct ll_phy_rsp               phy_rsp;
      -    struct ll_phy_update_ind        phy_upd_ind;
      +    struct llcp_con_update_ind    con_update_ind;
      +    struct llcp_channel_map_ind   channel_map_ind;
      +    struct llcp_terminate_ind     terminate_ind;
      +    struct llcp_enc_req           enc_req;
      +    struct llcp_enc_rsp           enc_rsp;
      +    struct llcp_start_enc_req     start_enc_req;
      +    struct llcp_start_enc_rsp     start_enc_rsp;
      +    struct llcp_unknown_rsp       unknown_rsp;
      +    struct llcp_feats_req         feats_req;
      +    struct llcp_feats_rsp         feats_rsp;
      +    struct llcp_pause_enc_req     pause_enc_req;
      +    struct llcp_pause_enc_rsp     pause_enc_rsp;
      +    struct llcp_vers_ind          vers_ind;
      +    struct llcp_reject_ind        reject_ind;
      +    struct llcp_slave_feature_req slave_feature_req;
      +    struct llcp_con_param_req     con_param_req;
      +    struct llcp_con_param_rsp     con_param_rsp;
      +    struct llcp_reject_ind_ext    reject_ind_ext;
      +    struct llcp_ping_req          ping_req;
      +    struct llcp_ping_rsp          ping_rsp;
      +    struct llcp_length_req        length_req;
      +    struct llcp_length_rsp        length_rsp;
      +    struct llcp_phy_req           phy_req;
      +    struct llcp_phy_rsp           phy_rsp;
      +    struct llcp_phy_upd_ind       phy_upd_ind;
       };
       
       /// @} CO_BT
  • services/ble_stack/common/api/co_lmp.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/common/api/co_lmp.h bes/services/ble_stack/common/api/co_lmp.h
      index d623a38f46f..10e7117f8dd 100644
      --- a/services/ble_stack/common/api/co_lmp.h
      +++ b/services/ble_stack/common/api/co_lmp.h
      @@ -34,130 +34,205 @@
        */
       
       //LMP Opcodes
      -
      -
      +#define LMP_NAME_REQ_OPCODE                1
      +#define LMP_NAME_RES_OPCODE                2
      +#define LMP_ACCEPTED_OPCODE                3
      +#define LMP_NOT_ACCEPTED_OPCODE            4
      +#define LMP_CLK_OFF_REQ_OPCODE             5
      +#define LMP_CLK_OFF_RES_OPCODE             6
      +#define LMP_DETACH_OPCODE                  7
      +#define LMP_INRAND_OPCODE                  8
      +#define LMP_COMBKEY_OPCODE                 9
      +#define LMP_UNITKEY_OPCODE                10
      +#define LMP_AURAND_OPCODE                 11
      +#define LMP_SRES_OPCODE                   12
      +#define LMP_TEMPRAND_OPCODE               13
      +#define LMP_TEMPKEY_OPCODE                14
      +#define LMP_ENC_MODE_REQ_OPCODE           15
      +#define LMP_ENC_KEY_SIZE_REQ_OPCODE       16
      +#define LMP_START_ENC_REQ_OPCODE          17
      +#define LMP_STOP_ENC_REQ_OPCODE           18
      +#define LMP_SWITCH_REQ_OPCODE             19
      +#define LMP_HOLD_OPCODE                   20
      +#define LMP_HOLD_REQ_OPCODE               21
      +#define LMP_SNIFF_REQ_OPCODE              23
      +#define LMP_UNSNIFF_REQ_OPCODE            24
      +#define LMP_PARK_REQ_OPCODE               25
      +#define LMP_SET_BSWIN_OPCODE              27
      +#define LMP_MODIF_BEACON_OPCODE           28
      +#define LMP_UNPARK_BD_REQ_OPCODE          29
      +#define LMP_UNPARK_PM_REQ_OPCODE          30
      +#define LMP_INCR_PWR_REQ_OPCODE           31
      +#define LMP_DECR_PWR_REQ_OPCODE           32
      +#define LMP_MAX_PWR_OPCODE                33
      +#define LMP_MIN_PWR_OPCODE                34
      +#define LMP_AUTO_RATE_OPCODE              35
      +#define LMP_PREF_RATE_OPCODE              36
      +#define LMP_VER_REQ_OPCODE                37
      +#define LMP_VER_RES_OPCODE                38
      +#define LMP_FEATS_REQ_OPCODE              39
      +#define LMP_FEATS_RES_OPCODE              40
      +#define LMP_QOS_OPCODE                    41
      +#define LMP_QOS_REQ_OPCODE                42
      +#define LMP_SCO_LINK_REQ_OPCODE           43
      +#define LMP_RMV_SCO_LINK_REQ_OPCODE       44
      +#define LMP_MAX_SLOT_OPCODE               45
      +#define LMP_MAX_SLOT_REQ_OPCODE           46
      +#define LMP_TIMING_ACCU_REQ_OPCODE        47
      +#define LMP_TIMING_ACCU_RES_OPCODE        48
      +#define LMP_SETUP_CMP_OPCODE              49
      +#define LMP_USE_SEMI_PERM_KEY_OPCODE      50
      +#define LMP_HOST_CON_REQ_OPCODE           51
      +#define LMP_SLOT_OFF_OPCODE               52
      +#define LMP_PAGE_MODE_REQ_OPCODE          53
      +#define LMP_PAGE_SCAN_MODE_REQ_OPCODE     54
      +#define LMP_SUPV_TO_OPCODE                55
      +#define LMP_TEST_ACTIVATE_OPCODE          56
      +#define LMP_TEST_CTRL_OPCODE              57
      +#define LMP_ENC_KEY_SIZE_MASK_REQ_OPCODE  58
      +#define LMP_ENC_KEY_SIZE_MASK_RES_OPCODE  59
      +#define LMP_SET_AFH_OPCODE                60
      +#define LMP_ENCAPS_HDR_OPCODE             61
      +#define LMP_ENCAPS_PAYL_OPCODE            62
      +#define LMP_SP_CFM_OPCODE                 63
      +#define LMP_SP_NB_OPCODE                  64
      +#define LMP_DHKEY_CHK_OPCODE              65
      +#define LMP_PAUSE_ENC_AES_REQ_OPCODE      66
      +
      +#define LMP_ESC1_OPCODE                   124
      +#define LMP_ESC2_OPCODE                   125
      +#define LMP_ESC3_OPCODE                   126
      +#define LMP_ESC4_OPCODE                   127
      +
      +///LMP Escape 4 Extended Opcodes
      +#define LMP_ACCEPTED_EXT_EXTOPCODE         1
      +#define LMP_NOT_ACCEPTED_EXT_EXTOPCODE     2
      +#define LMP_FEATS_REQ_EXT_EXTOPCODE        3
      +#define LMP_FEATS_RES_EXT_EXTOPCODE        4
      +#define LMP_CLK_ADJ_EXTOPCODE              5
      +#define LMP_CLK_ADJ_ACK_EXTOPCODE          6
      +#define LMP_CLK_ADJ_REQ_EXTOPCODE          7
      +#define LMP_PKT_TYPE_TBL_REQ_EXTOPCODE    11
      +#define LMP_ESCO_LINK_REQ_EXTOPCODE       12
      +#define LMP_RMV_ESCO_LINK_REQ_EXTOPCODE   13
      +#define LMP_CH_CLASS_REQ_EXTOPCODE        16
      +#define LMP_CH_CLASS_EXTOPCODE            17
      +#define LMP_SSR_REQ_EXTOPCODE             21
      +#define LMP_SSR_RES_EXTOPCODE             22
      +#define LMP_PAUSE_ENC_REQ_EXTOPCODE       23
      +#define LMP_RESUME_ENC_REQ_EXTOPCODE      24
      +#define LMP_IO_CAP_REQ_EXTOPCODE          25
      +#define LMP_IO_CAP_RES_EXTOPCODE          26
      +#define LMP_NUM_COMPARISON_FAIL_EXTOPCODE 27
      +#define LMP_PASSKEY_FAIL_EXTOPCODE        28
      +#define LMP_OOB_FAIL_EXTOPCODE            29
      +#define LMP_KEYPRESS_NOTIF_EXTOPCODE      30
      +#define LMP_PWR_CTRL_REQ_EXTOPCODE        31
      +#define LMP_PWR_CTRL_RES_EXTOPCODE        32
      +#define LMP_PING_REQ_EXTOPCODE            33
      +#define LMP_PING_RES_EXTOPCODE            34
       
       /// PDU lengths (including opcode)
      -enum co_lmp_pdu_length
      -{
      -    LMP_NAME_REQ_LEN              = 2 ,
      -    LMP_NAME_RES_LEN              = 17,
      -    LMP_ACCEPTED_LEN              = 2 ,
      -    LMP_NOT_ACCEPTED_LEN          = 3 ,
      -    LMP_CLK_OFF_REQ_LEN           = 1 ,
      -    LMP_CLK_OFF_RES_LEN           = 3 ,
      -    LMP_DETACH_LEN                = 2 ,
      -    LMP_INRAND_LEN                = 17,
      -    LMP_COMBKEY_LEN               = 17,
      -    LMP_UNITKEY_LEN               = 17,
      -    LMP_AURAND_LEN                = 17,
      -    LMP_SRES_LEN                  = 5 ,
      -    LMP_TEMPRAND_LEN              = 17,
      -    LMP_TEMPKEY_LEN               = 17,
      -    LMP_ENC_MODE_REQ_LEN          = 2 ,
      -    LMP_ENC_KEY_SIZE_REQ_LEN      = 2 ,
      -    LMP_START_ENC_REQ_LEN         = 17,
      -    LMP_STOP_ENC_REQ_LEN          = 1 ,
      -    LMP_SWITCH_REQ_LEN            = 5 ,
      -    LMP_HOLD_LEN                  = 7 ,
      -    LMP_HOLD_REQ_LEN              = 7 ,
      -    LMP_SNIFF_REQ_LEN             = 10,
      -    LMP_UNSNIFF_REQ_LEN           = 1 ,
      -    LMP_PARK_REQ_LEN              = 17,
      -    LMP_INCR_PWR_REQ_LEN          = 2 ,
      -    LMP_DECR_PWR_REQ_LEN          = 2 ,
      -    LMP_MAX_PWR_LEN               = 1 ,
      -    LMP_MIN_PWR_LEN               = 1 ,
      -    LMP_AUTO_RATE_LEN             = 1 ,
      -    LMP_PREF_RATE_LEN             = 2 ,
      -    LMP_VER_REQ_LEN               = 6 ,
      -    LMP_VER_RES_LEN               = 6 ,
      -    LMP_FEATS_REQ_LEN             = 9 ,
      -    LMP_FEATS_RES_LEN             = 9 ,
      -    LMP_QOS_LEN                   = 4 ,
      -    LMP_QOS_REQ_LEN               = 4 ,
      -    LMP_SCO_LINK_REQ_LEN          = 7 ,
      -    LMP_RMV_SCO_LINK_REQ_LEN      = 3 ,
      -    LMP_MAX_SLOT_LEN              = 2 ,
      -    LMP_MAX_SLOT_REQ_LEN          = 2 ,
      -    LMP_TIMING_ACCU_REQ_LEN       = 1 ,
      -    LMP_TIMING_ACCU_RES_LEN       = 3 ,
      -    LMP_SETUP_CMP_LEN             = 1 ,
      -    LMP_USE_SEMI_PERM_KEY_LEN     = 1 ,
      -    LMP_HOST_CON_REQ_LEN          = 1 ,
      -    LMP_SLOT_OFF_LEN              = 9 ,
      -    LMP_PAGE_MODE_REQ_LEN         = 3 ,
      -    LMP_PAGE_SCAN_MODE_REQ_LEN    = 3 ,
      -    LMP_SUPV_TO_LEN               = 3 ,
      -    LMP_TEST_ACTIVATE_LEN         = 1 ,
      -    LMP_TEST_CTRL_LEN             = 10,
      -    LMP_ENC_KEY_SIZE_MASK_REQ_LEN = 1 ,
      -    LMP_ENC_KEY_SIZE_MASK_RES_LEN = 3 ,
      -    LMP_SET_AFH_LEN               = 16,
      -    LMP_ENCAPS_HDR_LEN            = 4 ,
      -    LMP_ENCAPS_PAYL_LEN           = 17,
      -    LMP_SP_CFM_LEN                = 17,
      -    LMP_SP_NB_LEN                 = 17,
      -    LMP_DHKEY_CHK_LEN             = 17,
      -    LMP_PAUSE_ENC_AES_REQ_LEN     = 17,
      -};
      +#define LMP_NAME_REQ_LEN                    2
      +#define LMP_NAME_RES_LEN                    17
      +#define LMP_ACCEPTED_LEN                    2
      +#define LMP_NOT_ACCEPTED_LEN                3
      +#define LMP_CLK_OFF_REQ_LEN                 1
      +#define LMP_CLK_OFF_RES_LEN                 3
      +#define LMP_DETACH_LEN                      2
      +#define LMP_INRAND_LEN                      17
      +#define LMP_COMBKEY_LEN                     17
      +#define LMP_UNITKEY_LEN                     17
      +#define LMP_AURAND_LEN                      17
      +#define LMP_SRES_LEN                        5
      +#define LMP_TEMPRAND_LEN                    17
      +#define LMP_TEMPKEY_LEN                     17
      +#define LMP_ENC_MODE_REQ_LEN                2
      +#define LMP_ENC_KEY_SIZE_REQ_LEN            2
      +#define LMP_START_ENC_REQ_LEN               17
      +#define LMP_STOP_ENC_REQ_LEN                1
      +#define LMP_SWITCH_REQ_LEN                  5
      +#define LMP_HOLD_LEN                        7
      +#define LMP_HOLD_REQ_LEN                    7
      +#define LMP_SNIFF_REQ_LEN                   10
      +#define LMP_UNSNIFF_REQ_LEN                 1
      +#define LMP_PARK_REQ_LEN                    17
      +#define LMP_INCR_PWR_REQ_LEN                2
      +#define LMP_DECR_PWR_REQ_LEN                2
      +#define LMP_MAX_PWR_LEN                     1
      +#define LMP_MIN_PWR_LEN                     1
      +#define LMP_AUTO_RATE_LEN                   1
      +#define LMP_PREF_RATE_LEN                   2
      +#define LMP_VER_REQ_LEN                     6
      +#define LMP_VER_RES_LEN                     6
      +#define LMP_FEATS_REQ_LEN                   9
      +#define LMP_FEATS_RES_LEN                   9
      +#define LMP_QOS_LEN                         4
      +#define LMP_QOS_REQ_LEN                     4
      +#define LMP_SCO_LINK_REQ_LEN                7
      +#define LMP_RMV_SCO_LINK_REQ_LEN            3
      +#define LMP_MAX_SLOT_LEN                    2
      +#define LMP_MAX_SLOT_REQ_LEN                2
      +#define LMP_TIMING_ACCU_REQ_LEN             1
      +#define LMP_TIMING_ACCU_RES_LEN             3
      +#define LMP_SETUP_CMP_LEN                   1
      +#define LMP_USE_SEMI_PERM_KEY_LEN           1
      +#define LMP_HOST_CON_REQ_LEN                1
      +#define LMP_SLOT_OFF_LEN                    9
      +#define LMP_PAGE_MODE_REQ_LEN               3
      +#define LMP_PAGE_SCAN_MODE_REQ_LEN          3
      +#define LMP_SUPV_TO_LEN                     3
      +#define LMP_TEST_ACTIVATE_LEN               1
      +#define LMP_TEST_CTRL_LEN                   10
      +#define LMP_ENC_KEY_SIZE_MASK_REQ_LEN       1
      +#define LMP_ENC_KEY_SIZE_MASK_RES_LEN       3
      +#define LMP_SET_AFH_LEN                     16
      +#define LMP_ENCAPS_HDR_LEN                  4
      +#define LMP_ENCAPS_PAYL_LEN                 17
      +#define LMP_SP_CFM_LEN                      17
      +#define LMP_SP_NB_LEN                       17
      +#define LMP_DHKEY_CHK_LEN                   17
      +#define LMP_PAUSE_ENC_AES_REQ_LEN           17
       
       /// LMP Escape 4 Extended PDU length (including opcode and ext opcode)
      -enum co_lmp_ext_pdu_length
      -{
      -    LMP_ACCEPTED_EXT_LEN        = 4 ,
      -    LMP_NOT_ACCEPTED_EXT_LEN    = 5 ,
      -    LMP_FEATS_REQ_EXT_LEN       = 12,
      -    LMP_FEATS_RES_EXT_LEN       = 12,
      -    LMP_CLK_ADJ_LEN             = 15,
      -    LMP_CLK_ADJ_ACK_LEN         = 3 ,
      -    LMP_CLK_ADJ_REQ_LEN         = 6 ,
      -    LMP_PKT_TYPE_TBL_REQ_LEN    = 3 ,
      -    LMP_ESCO_LINK_REQ_LEN       = 16,
      -    LMP_RMV_ESCO_LINK_REQ_LEN   = 4 ,
      -    LMP_CH_CLASS_REQ_LEN        = 7 ,
      -    LMP_CH_CLASS_LEN            = 12,
      -    LMP_SSR_REQ_LEN             = 9 ,
      -    LMP_SSR_RES_LEN             = 9 ,
      -    LMP_PAUSE_ENC_REQ_LEN       = 2 ,
      -    LMP_RESUME_ENC_REQ_LEN      = 2 ,
      -    LMP_IO_CAP_REQ_LEN          = 5 ,
      -    LMP_IO_CAP_RES_LEN          = 5 ,
      -    LMP_NUM_COMPARISON_FAIL_LEN = 2 ,
      -    LMP_PASSKEY_FAIL_LEN        = 2 ,
      -    LMP_OOB_FAIL_LEN            = 2 ,
      -    LMP_KEYPRESS_NOTIF_LEN      = 3 ,
      -    LMP_PWR_CTRL_REQ_LEN        = 3 ,
      -    LMP_PWR_CTRL_RES_LEN        = 3 ,
      -    LMP_PING_REQ_LEN            = 2 ,
      -    LMP_PING_RES_LEN            = 2 ,
      -    LMP_SAM_SET_TYPE0_LEN       = 17,
      -    LMP_SAM_DEFINE_MAP_LEN      = 17,
      -    LMP_SAN_SWITCH_LEN          = 9,
      -};
      +#define LMP_ACCEPTED_EXT_LEN                4
      +#define LMP_NOT_ACCEPTED_EXT_LEN            5
      +#define LMP_FEATS_REQ_EXT_LEN               12
      +#define LMP_FEATS_RES_EXT_LEN               12
      +#define LMP_CLK_ADJ_LEN                     15
      +#define LMP_CLK_ADJ_ACK_LEN                 3
      +#define LMP_CLK_ADJ_REQ_LEN                 6
      +#define LMP_PKT_TYPE_TBL_REQ_LEN            3
      +#define LMP_ESCO_LINK_REQ_LEN               16
      +#define LMP_RMV_ESCO_LINK_REQ_LEN           4
      +#define LMP_CH_CLASS_REQ_LEN                7
      +#define LMP_CH_CLASS_LEN                    12
      +#define LMP_SSR_REQ_LEN                     9
      +#define LMP_SSR_RES_LEN                     9
      +#define LMP_PAUSE_ENC_REQ_LEN               2
      +#define LMP_RESUME_ENC_REQ_LEN              2
      +#define LMP_IO_CAP_REQ_LEN                  5
      +#define LMP_IO_CAP_RES_LEN                  5
      +#define LMP_NUM_COMPARISON_FAIL_LEN         2
      +#define LMP_PASSKEY_FAIL_LEN                2
      +#define LMP_OOB_FAIL_LEN                    2
      +#define LMP_KEYPRESS_NOTIF_LEN              3
      +#define LMP_PWR_CTRL_REQ_LEN                3
      +#define LMP_PWR_CTRL_RES_LEN                3
      +#define LMP_PING_REQ_LEN                    2
      +#define LMP_PING_RES_LEN                    2
       
       /// Maximum LMP PDU size (including opcode and ext opcode)
       #define LMP_MAX_PDU_SIZE         DM1_PACKET_SIZE
       
      -/**
      - * Opcode and TrID in the first byte
      - *
      - *   7    6     5    4    3    2    1    0
      - * +----+----+----+----+----+----+----+----+
      - * |              opcode              | Tid|
      - * +----+----+----+----+----+----+----+----+
      - */
      -enum lmp_opcode_trid
      -{
      -    /// Position of transaction ID in 1st byte
      -    LMP_TR_ID_POS       = 0,
      -    LMP_TR_ID_BIT       = 0x01,
      -    /// Position of opcode in 1st byte
      -    LMP_OPCODE_LSB      = 1,
      -    LMP_OPCODE_MASK     = 0xFE,
      -};
      +/// Position of transaction ID in 1st byte
      +#define LMP_TR_ID_POS        0
      +#define LMP_TR_ID_MASK       0x01
      +/// Position of opcode in 1st byte
      +#define LMP_OPCODE_POS       1
      +#define LMP_OPCODE_MASK      0xFE
       
      -#define LMP_OPCODE(opcode, tr_id) (((opcode << LMP_OPCODE_LSB) & LMP_OPCODE_MASK) | ((tr_id << LMP_TR_ID_POS) & LMP_TR_ID_BIT))
      +#define LMP_OPCODE(opcode, tr_id) (((opcode << LMP_OPCODE_POS) & LMP_OPCODE_MASK) | ((tr_id << LMP_TR_ID_POS) & LMP_TR_ID_MASK))
       /*
        * MESSAGES
        ****************************************************************************************
      @@ -341,15 +416,15 @@ struct lmp_sniff_req
       {
           ///Opcode (including transaction ID)
           uint8_t  opcode;
      -    /// Timing Control Flags (bit 1: initialization method 1 or 2)
      +    ///Timing Control Flags
           uint8_t  flags;
      -    /// Offset (in slots)
      +    ///Dsniff
           uint16_t d_sniff;
      -    /// Interval (in slots)
      +    ///Tsniff
           uint16_t t_sniff;
      -    /// Attempts (number of receive slots) (in slots)
      +    ///Sniff attempt
           uint16_t sniff_attempt;
      -    /// Timeout (number of receive slots) (in slots)
      +    ///Sniff Timeout
           uint16_t sniff_to;
       };
       
      @@ -536,9 +611,9 @@ struct lmp_timing_accu_res
       {
           ///Opcode (including transaction ID)
           uint8_t  opcode;
      -    ///Drift (in ppm)
      +    ///Drift
           uint8_t  drift;
      -    ///Jitter (in us)
      +    ///Jitter
           uint8_t  jitter;
       };
       
      @@ -601,7 +676,7 @@ struct lmp_supv_to
       {
           ///Opcode (including transaction ID)
           uint8_t  opcode;
      -    /// Supervision Timeout (in slots, 0 means infinite timeout)
      +    ///Supervision Timeout
           uint16_t supv_to;
       };
       
      @@ -872,7 +947,7 @@ struct lmp_esco_link_req
           ///Air Mode
           uint8_t  air_mode;
           ///Negotiation state
      -    uint8_t  nego_state;
      +    uint8_t  negt_st;
       };
       
       ///LMP_remove_eSCO_link_req PDU structure
      @@ -921,12 +996,12 @@ struct lmp_ssr_req
           uint8_t  opcode;
           ///Extended opcode
           uint8_t  ext_opcode;
      -    /// Maximum sniff sub-rate (in number of sniff events)
      +    ///Maximum sniff sub-rate
           uint8_t  max_subrate;
      -    /// Minimum sniff mode timeout (in slots)
      +    ///Minimum sniff mode timeout
           uint16_t min_to;
      -    /// Sniff sub-rating instant (in slots, master clock value)
      -    uint32_t instant;
      +    ///Sniff sub-rating instant
      +    uint32_t inst;
       };
       
       ///LMP_sniff_subrating_res PDU structure
      @@ -936,12 +1011,12 @@ struct lmp_ssr_res
           uint8_t  opcode;
           ///Extended opcode
           uint8_t  ext_opcode;
      -    /// Maximum sniff sub-rate (in number of sniff events)
      +    ///Maximum sniff sub-rate
           uint8_t  max_subrate;
      -    /// Minimum sniff mode timeout (in slots)
      +    ///Minimum sniff mode timeout
           uint16_t min_to;
      -    /// Sniff sub-rating instant (in slots, master clock value)
      -    uint32_t instant;
      +    ///Sniff sub-rating instant
      +    uint32_t inst;
       };
       
       ///LMP_pause_encryption_req PDU structure
      @@ -1073,7 +1148,7 @@ struct lmp_ping_res
       };
       
       /// Union of all the LMP message structures
      -union lmp_pdu
      +union lmp_pdu_data
       {
           struct lmp_name_req                name_req              ;
           struct lmp_name_res                name_res              ;
  • services/ble_stack/common/api/co_math.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/common/api/co_math.h bes/services/ble_stack/common/api/co_math.h
      index 9e672ef345f..bd288cb158a 100644
      --- a/services/ble_stack/common/api/co_math.h
      +++ b/services/ble_stack/common/api/co_math.h
      @@ -103,7 +103,7 @@ extern int rand (void);
        * @return Number of leading zeros when value is written as 32 bits.
        ****************************************************************************************
        */
      -__INLINE uint32_t co_clz(uint32_t val)
      +__STATIC __INLINE uint32_t co_clz(uint32_t val)
       {
           #if defined(__arm__)
           return __builtin_clz(val);
      @@ -130,7 +130,7 @@ __INLINE uint32_t co_clz(uint32_t val)
        * @param[in] seed The seed number to use to generate the random sequence.
        ****************************************************************************************
        */
      -__INLINE void co_random_init(uint32_t seed)
      +__STATIC __INLINE void co_random_init(uint32_t seed)
       {
           srand(seed);
       }
      @@ -141,7 +141,7 @@ __INLINE void co_random_init(uint32_t seed)
        * @return Random byte value.
        ****************************************************************************************
        */
      -__INLINE uint8_t co_rand_byte(void)
      +__STATIC __INLINE uint8_t co_rand_byte(void)
       {
           return (uint8_t)(rand() & 0xFF);
       }
      @@ -152,7 +152,7 @@ __INLINE uint8_t co_rand_byte(void)
        * @return Random half word value.
        ****************************************************************************************
        */
      -__INLINE uint16_t co_rand_hword(void)
      +__STATIC __INLINE uint16_t co_rand_hword(void)
       {
           return (uint16_t)(rand() & 0xFFFF);
       }
      @@ -163,7 +163,7 @@ __INLINE uint16_t co_rand_hword(void)
        * @return Random word value.
        ****************************************************************************************
        */
      -__INLINE uint32_t co_rand_word(void)
      +__STATIC __INLINE uint32_t co_rand_word(void)
       {
           return (uint32_t)rand();
       }
      @@ -174,7 +174,7 @@ __INLINE uint32_t co_rand_word(void)
        * @return The smallest value.
        ****************************************************************************************
        */
      -__INLINE uint32_t co_min(uint32_t a, uint32_t b)
      +__STATIC __INLINE uint32_t co_min(uint32_t a, uint32_t b)
       {
           return a < b ? a : b;
       }
      @@ -185,7 +185,7 @@ __INLINE uint32_t co_min(uint32_t a, uint32_t b)
        * @return The greatest value.
        ****************************************************************************************
        */
      -__INLINE uint32_t co_max(uint32_t a, uint32_t b)
      +__STATIC __INLINE uint32_t co_max(uint32_t a, uint32_t b)
       {
           return a > b ? a : b;
       }
      @@ -196,9 +196,9 @@ __INLINE uint32_t co_max(uint32_t a, uint32_t b)
        * @return The absolute value.
        ****************************************************************************************
        */
      -__INLINE int co_abs(int val)
      +__STATIC __INLINE int co_abs(int val)
       {
      -    return (val < 0) ? (0 - val) : val;
      +    return val < 0 ? val*(-1) : val;
       }
       
       /// @} CO_MATH
  • services/ble_stack/common/api/co_utils.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/common/api/co_utils.h bes/services/ble_stack/common/api/co_utils.h
      index 7848bc51079..600bcd654e4 100644
      --- a/services/ble_stack/common/api/co_utils.h
      +++ b/services/ble_stack/common/api/co_utils.h
      @@ -62,7 +62,7 @@
                                                                                       ke_task_id_t const dest_id)
       
       /// Macro for HCI message handler function declaration or definition (for multi-instantiated tasks)
      -#define HCI_CMD_HANDLER_C(cmd_name, param_struct)   __STATIC int hci_##cmd_name##_cmd_lc_handler(param_struct const *param,  \
      +#define HCI_CMD_HANDLER_C(cmd_name, param_struct)   __STATIC int hci_##cmd_name##_cmd_handler(param_struct const *param,  \
                                                                                       ke_task_id_t const dest_id,  \
                                                                                       uint16_t opcode)
       
      @@ -79,7 +79,7 @@
       
       
       /// Macro to get a structure from one of its structure field
      -//#define CONTAINER_OF(ptr, type, member)    ((type *)( (char *)ptr - OFFSETOF(type,member) ))
      +//#define CONTAINER_OF(ptr, type, member)    ((type *)( (char *)ptr - offsetof(type,member) ))
       
       
       /*
      @@ -136,9 +136,9 @@ extern const struct bd_addr co_default_bdaddr;
        ****************************************************************************************
        * @brief Clocks addition with 2 operands
        *
      - * @param[in]   clock_a   1st operand value (in BT half-slots)
      - * @param[in]   clock_b   2nd operand value (in BT half-slots)
      - * @return      result    operation result (in BT half-slots)
      + * @param[in]   clock_a   1st operand value (in BT slots)
      + * @param[in]   clock_b   2nd operand value (in BT slots)
      + * @return      result    operation result (in BT slots)
        ****************************************************************************************
        */
       #define CLK_ADD_2(clock_a, clock_b)     ((uint32_t)(((clock_a) + (clock_b)) & RWIP_MAX_CLOCK_TIME))
      @@ -147,10 +147,10 @@ extern const struct bd_addr co_default_bdaddr;
        ****************************************************************************************
        * @brief Clocks addition with 3 operands
        *
      - * @param[in]   clock_a   1st operand value (in BT half-slots)
      - * @param[in]   clock_b   2nd operand value (in BT half-slots)
      - * @param[in]   clock_c   3rd operand value (in BT half-slots)
      - * @return      result    operation result (in BT half-slots)
      + * @param[in]   clock_a   1st operand value (in BT slots)
      + * @param[in]   clock_b   2nd operand value (in BT slots)
      + * @param[in]   clock_c   3rd operand value (in BT slots)
      + * @return      result    operation result (in BT slots)
        ****************************************************************************************
        */
       #define CLK_ADD_3(clock_a, clock_b, clock_c)     ((uint32_t)(((clock_a) + (clock_b) + (clock_c)) & RWIP_MAX_CLOCK_TIME))
      @@ -215,10 +215,21 @@ extern const struct bd_addr co_default_bdaddr;
       /// @param[in] __v value to put in field
       #define SETB(__r, __b, __v)                                                      \
           do {                                                                         \
      -        ASSERT_ERR( ( ( ( (__v ? 1 : 0) << (__b##_POS) ) & ( ~(__b##_BIT) ) ) ) == 0 ); \
      -        __r = (((__r) & ~(__b##_BIT)) | (__v ? 1 : 0) << (__b##_POS));                  \
      +        ASSERT_ERR( ( ( ( (__v) << (__b##_POS) ) & ( ~(__b##_BIT) ) ) ) == 0 ); \
      +        __r = (((__r) & ~(__b##_BIT)) | (__v) << (__b##_POS));                  \
           } while (0)
       
      +#if (BLE_EMB_PRESENT)
      +/**
      + ******************************************************************************
      + * @brief Compare 2 BLE instants (connection event counter)
      + * @param[in]   instant_a   1st operand value (connection event counter)
      + * @param[in]   instant_b   2nd operand value (connection event counter)
      + * @return      result      True: B is greater or equal to A | False: B is smaller than A
      + ******************************************************************************
      + */
      +#define CO_BLE_INSTANT_PASSED(instant_a, instant_b)    ((uint16_t)(instant_b - instant_a) < 32767)
      +#endif //BLE_EMB_PRESENT
       
       
       /*
      @@ -378,7 +389,7 @@ __STATIC __INLINE void co_write16p(void const *ptr16, uint16_t value)
           *ptr = (value&0xff00)>>8;
       }
       
      -#if (RW_DEBUG || DISPLAY_SUPPORT)
      +#if RW_DEBUG
       /**
        ****************************************************************************************
        * @brief Convert bytes to hexadecimal string
      @@ -389,7 +400,7 @@ __STATIC __INLINE void co_write16p(void const *ptr16, uint16_t value)
        ****************************************************************************************
        */
       void co_bytes_to_string(char* dest, uint8_t* src, uint8_t nb_bytes);
      -#endif //(RW_DEBUG || DISPLAY_SUPPORT)
      +#endif //RW_DEBUG
       
       /**
        ****************************************************************************************
      @@ -405,6 +416,17 @@ void co_bytes_to_string(char* dest, uint8_t* src, uint8_t nb_bytes);
        */
       bool co_bdaddr_compare(struct bd_addr const *bd_address1, struct bd_addr const *bd_address2);
       
      +#if (BLE_EMB_PRESENT)
      +/**
      + ******************************************************************************
      + * @brief Count the number of good channels in a LE map
      + * @param[in]  map  Channel Map (bit fields for the 40 BT RF channels)
      + * @return  Number of good channels
      + ******************************************************************************
      + */
      +uint8_t co_nb_good_le_channels(const struct le_chnl_map* map);
      +#endif //BLE_EMB_PRESENT
      +
       #if (BT_EMB_PRESENT)
       
       /**
      @@ -414,7 +436,7 @@ bool co_bdaddr_compare(struct bd_addr const *bd_address1, struct bd_addr const *
        * @return  Duration (in number of ticks).
        ******************************************************************************
        */
      -uint32_t co_slot_to_duration(uint32_t slot_cnt);
      +uint32_t co_slot_to_duration(uint16_t slot_cnt);
       
       /**
        ******************************************************************************
      @@ -454,7 +476,7 @@ uint8_t co_nb_good_channels(const struct chnl_map* map);
        * @return  Status of the packing operation
        *****************************************************************************************
        */
      -uint8_t co_util_pack(uint8_t* out, uint8_t* in, uint16_t* out_len, uint16_t in_len, const char* format);
      +enum CO_UTIL_PACK_STATUS co_util_pack(uint8_t* out, uint8_t* in, uint16_t* out_len, uint16_t in_len, const char* format);
       
       /**
        ****************************************************************************************
      @@ -486,7 +508,7 @@ uint8_t co_util_pack(uint8_t* out, uint8_t* in, uint16_t* out_len, uint16_t in_l
        * @return  Status of the unpacking operation
        *****************************************************************************************
        */
      -uint8_t co_util_unpack(uint8_t* out, uint8_t* in, uint16_t* out_len, uint16_t in_len, const char* format);
      +enum CO_UTIL_PACK_STATUS co_util_unpack(uint8_t* out, uint8_t* in, uint16_t* out_len, uint16_t in_len, const char* format);
       
       /// @} CO_UTILS
       
  • services/ble_stack/common/api/co_version.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/common/api/co_version.h bes/services/ble_stack/common/api/co_version.h
      index 9fcbfecd1e5..37168596fa7 100644
      --- a/services/ble_stack/common/api/co_version.h
      +++ b/services/ble_stack/common/api/co_version.h
      @@ -28,14 +28,14 @@
        * INCLUDE FILES
        ****************************************************************************************
        */
      -#include "co_bt.h"           // BT standard definitions
      +#include "rwip_config.h"        // SW configuration options
       
       /// RWBT SW Major Version
      -#define RWBT_SW_VERSION_MAJOR                   (BT52_VERSION)
      +#define RWBT_SW_VERSION_MAJOR                   (RW_BT50_VERSION)
       /// RWBT SW Minor Version
       #define RWBT_SW_VERSION_MINOR                   0
       /// RWBT SW Build Version
      -#define RWBT_SW_VERSION_BUILD                   4
      +#define RWBT_SW_VERSION_BUILD                   3
       
       /// RWBT SW Major Version
       #define RWBT_SW_VERSION_SUB_BUILD               0
  • services/ble_stack/hl/api/gap.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/hl/api/gap.h bes/services/ble_stack/hl/api/gap.h
      index 6753dd6318b..c9b9523b73e 100644
      --- a/services/ble_stack/hl/api/gap.h
      +++ b/services/ble_stack/hl/api/gap.h
      @@ -66,19 +66,16 @@
       
       
       ///***** AD Type Flag - Bit set *******/
      -enum gap_ad_type_flag
      -{
      -    /// Limited discovery flag - AD Flag
      -    GAP_LE_LIM_DISCOVERABLE_FLG_BIT     = 0x01,
      -    /// General discovery flag - AD Flag
      -    GAP_LE_GEN_DISCOVERABLE_FLG_BIT     = 0x02,
      -    /// Legacy BT not supported - AD Flag
      -    GAP_BR_EDR_NOT_SUPPORTED_BIT        = 0x04,
      -    /// Dual mode for controller supported (BR/EDR/LE) - AD Flag
      -    GAP_SIMUL_BR_EDR_LE_CONTROLLER_BIT  = 0x08,
      -    /// Dual mode for host supported (BR/EDR/LE) - AD Flag
      -    GAP_SIMUL_BR_EDR_LE_HOST_BIT        = 0x10,
      -};
      +/// Limited discovery flag - AD Flag
      +#define GAP_LE_LIM_DISCOVERABLE_FLG             0x01
      +/// General discovery flag - AD Flag
      +#define GAP_LE_GEN_DISCOVERABLE_FLG             0x02
      +/// Legacy BT not supported - AD Flag
      +#define GAP_BR_EDR_NOT_SUPPORTED                0x04
      +/// Dual mode for controller supported (BR/EDR/LE) - AD Flag
      +#define GAP_SIMUL_BR_EDR_LE_CONTROLLER          0x08
      +/// Dual mode for host supported (BR/EDR/LE) - AD Flag
      +#define GAP_SIMUL_BR_EDR_LE_HOST                0x10
       
       /*********** GAP Miscellaneous Defines *************/
       /// Invalid connection index
      @@ -300,6 +297,16 @@ enum gap_ad_type
       };
       
       
      +/// Random Address type
      +enum gap_rnd_addr_type
      +{
      +    /// Static random address           - 11 (MSB->LSB)
      +    GAP_STATIC_ADDR     = 0xC0,
      +    /// Private non resolvable address  - 01 (MSB->LSB)
      +    GAP_NON_RSLV_ADDR   = 0x00,
      +    /// Private resolvable address      - 01 (MSB->LSB)
      +    GAP_RSLV_ADDR       = 0x40,
      +};
       
       /// Boolean value set
       enum
      @@ -311,6 +318,21 @@ enum
       };
       
       
      +/// GAP Attribute database handles
      +/// Generic Access Profile Service
      +enum
      +{
      +    GAP_IDX_PRIM_SVC,
      +    GAP_IDX_CHAR_DEVNAME,
      +    GAP_IDX_DEVNAME,
      +    GAP_IDX_CHAR_ICON,
      +    GAP_IDX_ICON,
      +    GAP_IDX_CHAR_SLAVE_PREF_PARAM,
      +    GAP_IDX_SLAVE_PREF_PARAM,
      +    GAP_IDX_CHAR_CNT_ADDR_RESOL,
      +    GAP_IDX_CNT_ADDR_RESOL,
      +    GAP_IDX_NUMBER
      +};
       
       
       
      @@ -335,9 +357,35 @@ enum gap_role
           /// Device has all role, both peripheral and central
           GAP_ROLE_ALL         = (GAP_ROLE_CENTRAL | GAP_ROLE_PERIPHERAL),
       
      +    /// Debug mode used to force LL configuration on BLE 4.0
      +    GAP_ROLE_DBG_LE_4_0      = 0x80,
       };
       
      +/// Advertising mode
      +enum gap_adv_mode
      +{
      +    /// Mode in non-discoverable
      +    GAP_NON_DISCOVERABLE,
      +    /// Mode in general discoverable
      +    GAP_GEN_DISCOVERABLE,
      +    /// Mode in limited discoverable
      +    GAP_LIM_DISCOVERABLE,
      +    /// Broadcaster mode which is a non discoverable and non connectable mode.
      +    GAP_BROADCASTER_MODE
      +};
       
      +/// Scan mode
      +enum gap_scan_mode
      +{
      +    /// Mode in general discovery
      +    GAP_GEN_DISCOVERY,
      +    /// Mode in limited discovery
      +    GAP_LIM_DISCOVERY,
      +    /// Observer mode
      +    GAP_OBSERVER_MODE,
      +    /// Invalid mode
      +    GAP_INVALID_MODE
      +};
       
       
       
      @@ -394,16 +442,16 @@ enum gap_auth_mask
       };
       
       /// Security Link Level
      -enum gap_sec_lvl
      +enum gap_lk_sec_lvl
       {
      -    /// Service accessible through an un-encrypted link
      -    GAP_SEC_NOT_ENC             = 0,
      -    /// Service require an unauthenticated pairing (just work pairing)
      -    GAP_SEC_UNAUTH,
      -    /// Service require an authenticated pairing (Legacy pairing with pin code or OOB)
      -    GAP_SEC_AUTH,
      -    /// Service require a secure connection pairing
      -    GAP_SEC_SECURE_CON,
      +    /// No authentication
      +    GAP_LK_NO_AUTH             = 0,
      +    /// Unauthenticated link
      +    GAP_LK_UNAUTH,
      +    /// Authenticated link
      +    GAP_LK_AUTH,
      +    /// Secure Connection link
      +    GAP_LK_SEC_CON,
       };
       
       /// Authentication Requirements
      @@ -418,9 +466,9 @@ enum gap_auth
           /// MITM and Bonding
           GAP_AUTH_REQ_MITM_BOND        = (GAP_AUTH_MITM | GAP_AUTH_BOND),
           /// SEC_CON and No Bonding
      -    GAP_AUTH_REQ_SEC_CON_NO_BOND  = (GAP_AUTH_SEC_CON | GAP_AUTH_MITM),
      +    GAP_AUTH_REQ_SEC_CON_NO_BOND  = (GAP_AUTH_SEC_CON),
           /// SEC_CON and Bonding
      -    GAP_AUTH_REQ_SEC_CON_BOND     = (GAP_AUTH_SEC_CON | GAP_AUTH_MITM | GAP_AUTH_BOND),
      +    GAP_AUTH_REQ_SEC_CON_BOND     = (GAP_AUTH_SEC_CON | GAP_AUTH_BOND),
       
           GAP_AUTH_REQ_LAST,
       
      @@ -462,32 +510,261 @@ enum gap_sec_req
           GAP_SEC1_SEC_CON_PAIR_ENC,
       };
       
      -/// Bit field use to select the preferred TX or RX LE PHY. 0 means no preferences
      -enum gap_phy
      +/// Bit field use to select the preferred TX or RX LE PHY Rate. 0 means no preferences
      +enum gap_rate
      +{
      +    /// No preferred rate
      +    GAP_RATE_ANY               = 0x00,
      +    /// LE PHY 1mb/s preferred rate for an active link
      +    GAP_RATE_LE_1MBPS          = (1 << 0),
      +    /// LE PHY 2mb/s preferred rate for an active link
      +    GAP_RATE_LE_2MBPS          = (1 << 1),
      +};
      +
      +/// API settings bit field values
      +enum gap_api_settings
      +{
      +    /// Use deprecated API and do not use extended air operations
      +    GAP_ADD_INFO_USE_DEPRECATED_API_BIT = (1 << 0),
      +};
      +
      +/// Privacy configuration
      +enum gap_priv_cfg
      +{
      +    /// Indicate if public or static private random address must be used by default
      +    GAP_PRIV_CFG_PRIV_ADDR_BIT = (1 << 0),
      +    /// Bit 1 is reserved
      +    GAP_PRIV_CFG_RSVD          = (1 << 1),
      +    /// Indicate if controller privacy is enabled
      +    GAP_PRIV_CFG_CTNL_PRIV_BIT = (1 << 2),
      +};
      +
      +/// Type of own address
      +enum gap_own_addr_type
      +{
      +    /// Use address configured using GAPM_SET_DEV_CONFIG_CMD.
      +    /// Can be either a public address or a random static address
      +    GAP_OWN_ADDR_TYPE_DEFAULT = 0,
      +    /// Use a non-resolvable private address
      +    GAP_OWN_ADDR_TYPE_NRPA,
      +    /// Use a resolvable private address
      +    GAP_OWN_ADDR_TYPE_RPA,
      +};
      +
      +/// Type of activities that can be created
      +enum gap_actv_type
      +{
      +    /// Advertising activity
      +    GAP_ACTV_TYPE_ADV = 0,
      +    /// Scanning activity
      +    GAP_ACTV_TYPE_SCAN,
      +    /// Initiating activity
      +    GAP_ACTV_TYPE_INIT,
      +    /// Periodic synchronization activity
      +    GAP_ACTV_TYPE_PERIOD_SYNC,
      +};
      +
      +/// Type of advertising that can be created
      +enum gap_adv_type
      +{
      +    /// Legacy advertising
      +    GAP_ADV_TYPE_LEGACY = 0,
      +    /// Extended advertising
      +    GAP_ADV_TYPE_EXTENDED,
      +    /// Periodic advertising
      +    GAP_ADV_TYPE_PERIODIC,
      +};
      +
      +/// Advertising report type
      +enum gap_adv_report_type
      +{
      +    /// Extended advertising report
      +    GAP_REPORT_TYPE_ADV_EXT = 0,
      +    /// Legacy advertising report
      +    GAP_REPORT_TYPE_ADV_LEG,
      +    /// Extended scan response report
      +    GAP_REPORT_TYPE_SCAN_RSP_EXT,
      +    /// Legacy scan response report
      +    GAP_REPORT_TYPE_SCAN_RSP_LEG,
      +    /// Periodic advertising report
      +    GAP_REPORT_TYPE_PER_ADV,
      +};
      +
      +/// Advertising properties bit field bit value
      +enum gap_adv_prop
      +{
      +    /// Indicate that advertising is connectable, reception of CONNECT_REQ or AUX_CONNECT_REQ
      +    /// PDUs is accepted. Not applicable for periodic advertising.
      +    GAP_ADV_PROP_CONNECTABLE_BIT     = (1 << 0),
      +    /// Indicate that advertising is scannable, reception of SCAN_REQ or AUX_SCAN_REQ PDUs is
      +    /// accepted
      +    GAP_ADV_PROP_SCANNABLE_BIT       = (1 << 1),
      +    /// Indicate that advertising targets a specific device. Only apply in following cases:
      +    ///   - Legacy advertising: if connectable
      +    ///   - Extended advertising: connectable or (non connectable and non discoverable)
      +    GAP_ADV_PROP_DIRECTED_BIT        = (1 << 2),
      +    /// Indicate that High Duty Cycle has to be used for advertising on primary channel
      +    /// Apply only if created advertising is not an extended advertising
      +    GAP_ADV_PROP_HDC_BIT             = (1 << 3),
      +    /// Bit 4 is reserved
      +    GAP_ADV_PROP_RESERVED_4_BIT      = (1 << 4),
      +    /// Enable anonymous mode. Device address won't appear in send PDUs
      +    /// Valid only if created advertising is an extended advertising
      +    GAP_ADV_PROP_ANONYMOUS_BIT       = (1 << 5),
      +    /// Include TX Power in the extended header of the advertising PDU.
      +    /// Valid only if created advertising is not a legacy advertising
      +    GAP_ADV_PROP_TX_PWR_BIT          = (1 << 6),
      +    /// Include TX Power in the periodic advertising PDU.
      +    /// Valid only if created advertising is a periodic advertising
      +    GAP_ADV_PROP_PER_TX_PWR_BIT      = (1 << 7),
      +    /// Indicate if application must be informed about received scan requests PDUs
      +    GAP_ADV_PROP_SCAN_REQ_NTF_EN_BIT = (1 << 8),
      +};
      +
      +/// PHY Type
      +enum gap_phy_type
      +{
      +    /// LE 1M
      +    GAP_PHY_TYPE_LE_1M = 0,
      +    /// LE 2M
      +    GAP_PHY_TYPE_LE_2M,
      +    /// LE Coded
      +    GAP_PHY_TYPE_LE_CODED,
      +};
      +
      +/// Advertising discovery mode
      +enum gap_adv_disc_mode
      +{
      +    /// Mode in non-discoverable
      +    GAP_ADV_MODE_NON_DISC = 0,
      +    /// Mode in general discoverable
      +    GAP_ADV_MODE_GEN_DISC,
      +    /// Mode in limited discoverable
      +    GAP_ADV_MODE_LIM_DISC,
      +};
      +
      +/// Scanning Types
      +enum gap_scan_type
      +{
      +    /// General discovery
      +    GAP_SCAN_TYPE_GEN_DISC = 0,
      +    /// Limited discovery
      +    GAP_SCAN_TYPE_LIM_DISC,
      +    /// Observer
      +    GAP_SCAN_TYPE_OBSERVER,
      +    /// Selective observer
      +    GAP_SCAN_TYPE_SEL_OBSERVER,
      +    /// Connectable discovery
      +    GAP_SCAN_TYPE_CONN_DISC,
      +    /// Selective connectable discovery
      +    GAP_SCAN_TYPE_SEL_CONN_DISC,
      +};
      +
      +/// Scanning properties bit field bit value
      +enum gap_scan_prop
      +{
      +    /// Scan advertisement on the LE 1M PHY
      +    GAP_SCAN_PROP_PHY_1M_BIT       = (1 << 0),
      +    /// Scan advertisement on the LE Coded PHY
      +    GAP_SCAN_PROP_PHY_CODED_BIT    = (1 << 1),
      +    /// Active scan on LE 1M PHY (Scan Request PDUs may be sent)
      +    GAP_SCAN_PROP_ACTIVE_1M_BIT    = (1 << 2),
      +    /// Active scan on LE Coded PHY (Scan Request PDUs may be sent)
      +    GAP_SCAN_PROP_ACTIVE_CODED_BIT = (1 << 3),
      +    /// Accept directed advertising packets if we use a RPA and target address cannot be solved by the
      +    /// controller
      +    GAP_SCAN_PROP_ACCEPT_RPA_BIT   = (1 << 4),
      +    /// Filter truncated advertising or scan response reports
      +    GAP_SCAN_PROP_FILT_TRUNC_BIT   = (1 << 5),
      +};
      +
      +/// Initiating Types
      +enum gap_init_type
      +{
      +    /// Direct connection establishment, establish a connection with an indicated device
      +    GAPM_INIT_TYPE_DIRECT_CONN_EST = 0,
      +    /// Automatic connection establishment, establish a connection with all devices whose address is
      +    /// present in the white list
      +    GAPM_INIT_TYPE_AUTO_CONN_EST,
      +    /// Name discovery, Establish a connection with an indicated device in order to read content of its
      +    /// Device Name characteristic. Connection is closed once this operation is stopped.
      +    GAPM_INIT_TYPE_NAME_DISC,
      +};
      +
      +/// Initiating Properties
      +enum gap_init_prop
      +{
      +    /// Scan connectable advertisements on the LE 1M PHY. Connection parameters for the LE 1M PHY are provided
      +    GAPM_INIT_PROP_1M_BIT       = (1 << 0),
      +    /// Connection parameters for the LE 2M PHY are provided
      +    GAPM_INIT_PROP_2M_BIT       = (1 << 1),
      +    /// Scan connectable advertisements on the LE Coded PHY. Connection parameters for the LE Coded PHY are provided
      +    GAPM_INIT_PROP_CODED_BIT    = (1 << 2),
      +};
      +
      +/// Advertising report information
      +enum gap_adv_report_info
      +{
      +    /// Report Type
      +    GAP_REPORT_INFO_REPORT_TYPE         = 0x07,
      +    /// Report is complete
      +    GAP_REPORT_INFO_COMPLETE            = (1 << 3),
      +    /// Connectable advertising
      +    GAP_REPORT_INFO_CONN_ADV            = (1 << 4),
      +    /// Scannable advertising
      +    GAP_REPORT_INFO_SCAN_ADV            = (1 << 5),
      +    /// Directed advertising
      +    GAP_REPORT_INFO_DIR_ADV             = (1 << 6),
      +};
      +
      +/// Filtering policy for duplicated packets
      +enum gap_dup_filter_pol
      +{
      +    /// Disable filtering of duplicated packets
      +    GAP_DUP_FILT_DIS = 0,
      +    /// Enable filtering of duplicated packets
      +    GAP_DUP_FILT_EN,
      +    /// Enable filtering of duplicated packets, reset for each scan period
      +    GAP_DUP_FILT_EN_PERIOD,
      +};
      +
      +/*
      + * Masks for advertising properties
      + ****************************************************************************************
      + */
      +
      +/// Advertising properties configurations for legacy advertising
      +enum gap_leg_adv_prop
       {
      -    /// No preferred PHY
      -    GAP_PHY_ANY               = 0x00,
      -    /// LE 1M PHY preferred for an active link
      -    GAP_PHY_LE_1MBPS          = (1 << 0),
      -    /// LE 2M PHY preferred for an active link
      -    GAP_PHY_LE_2MBPS          = (1 << 1),
      -    /// LE Coded PHY preferred for an active link
      -    GAP_PHY_LE_CODED          = (1 << 2),
      +    /// Non connectable non scannable advertising
      +    GAP_ADV_PROP_NON_CONN_NON_SCAN_MASK  = 0x0000,
      +    /// Broadcast non scannable advertising - Discovery mode must be Non Discoverable
      +    GAP_ADV_PROP_BROADCAST_NON_SCAN_MASK = GAP_ADV_PROP_NON_CONN_NON_SCAN_MASK,
      +    /// Non connectable scannable advertising
      +    GAP_ADV_PROP_NON_CONN_SCAN_MASK      = GAP_ADV_PROP_SCANNABLE_BIT,
      +    /// Broadcast non scannable advertising - Discovery mode must be Non Discoverable
      +    GAP_ADV_PROP_BROADCAST_SCAN_MASK     = GAP_ADV_PROP_NON_CONN_SCAN_MASK,
      +    /// Undirected connectable advertising
      +    GAP_ADV_PROP_UNDIR_CONN_MASK         = GAP_ADV_PROP_CONNECTABLE_BIT | GAP_ADV_PROP_SCANNABLE_BIT,
      +    /// Directed connectable advertising
      +    GAP_ADV_PROP_DIR_CONN_MASK           = GAP_ADV_PROP_DIRECTED_BIT | GAP_ADV_PROP_CONNECTABLE_BIT,
      +    /// Directed connectable with Low Duty Cycle
      +    GAP_ADV_PROP_DIR_CONN_LDC_MASK       = GAP_ADV_PROP_DIR_CONN_MASK,
      +    /// Directed connectable with High Duty Cycle
      +    GAP_ADV_PROP_DIR_CONN_HDC_MASK       = GAP_ADV_PROP_DIR_CONN_MASK | GAP_ADV_PROP_HDC_BIT,
       };
       
      -/// Enumeration of TX/RX PHY values
      -enum gap_phy_val
      +/// Advertising properties configurations for extended advertising
      +enum gap_ext_adv_prop
       {
      -    /// LE 1M PHY (TX or RX)
      -    GAP_PHY_1MBPS        = 1,
      -    /// LE 2M PHY (TX or RX)
      -    GAP_PHY_2MBPS        = 2,
      -    /// LE Coded PHY (RX Only)
      -    GAP_PHY_CODED        = 3,
      -    /// LE Coded PHY with S=8 data coding (TX Only)
      -    GAP_PHY_125KBPS      = 3,
      -    /// LE Coded PHY with S=2 data coding (TX Only)
      -    GAP_PHY_500KBPS      = 4,
      +    /// Non connectable non scannable extended advertising
      +    GAP_EXT_ADV_PROP_NON_CONN_NON_SCAN_MASK = 0x0000,
      +    /// Non connectable scannable extended advertising
      +    GAP_EXT_ADV_PROP_NON_CONN_SCAN_MASK     = GAP_ADV_PROP_SCANNABLE_BIT,
      +    /// Undirected connectable extended advertising
      +    GAP_EXT_ADV_PROP_UNDIR_CONN_MASK        = GAP_ADV_PROP_CONNECTABLE_BIT,
      +    /// Directed connectable extended advertising
      +    GAP_EXT_ADV_PROP_DIR_CONN_MASK          = GAP_ADV_PROP_CONNECTABLE_BIT | GAP_ADV_PROP_DIRECTED_BIT,
       };
       
       /*************** GAP Structures ********************/
      @@ -495,14 +772,14 @@ enum gap_phy_val
       /// Device name
       struct gap_dev_name
       {
      -    /// Length of provided value
      -    uint16_t value_length;
      -    /// name value starting from offset to maximum length
      -    uint8_t  value[__ARRAY_EMPTY];
      +    /// name length
      +    uint16_t length;
      +    /// name value
      +    uint8_t value[__ARRAY_EMPTY];
       };
       
       /// Slave preferred connection parameters
      -typedef struct gap_slv_pref
      +struct gap_slv_pref
       {
           /// Connection interval minimum
           uint16_t con_intv_min;
      @@ -512,13 +789,15 @@ typedef struct gap_slv_pref
           uint16_t slave_latency;
           /// Connection supervision timeout multiplier
           uint16_t conn_timeout;
      -} gap_slv_pref_t;
      +};
       
      -/// Bluetooth address
      -typedef struct gap_addr {
      -    /// BD Address of device
      -    uint8_t addr[GAP_BD_ADDR_LEN];
      -} gap_addr_t;
      +///BD Address structure
      +#define BLE_BD_ADDR_T
      +typedef struct
      +{
      +    ///6-byte array address value
      +    uint8_t  addr[GAP_BD_ADDR_LEN];
      +} bd_addr_t;
       
       ///Channel map structure
       typedef struct
      @@ -535,6 +814,26 @@ typedef struct
           uint8_t     nb[GAP_RAND_NB_LEN];
       } rand_nb_t;
       
      +///Advertising report structure
      +typedef struct
      +{
      +    ///Event type:
      +    /// - ADV_CONN_UNDIR: Connectable Undirected advertising
      +    /// - ADV_CONN_DIR: Connectable directed advertising
      +    /// - ADV_DISC_UNDIR: Discoverable undirected advertising
      +    /// - ADV_NONCONN_UNDIR: Non-connectable undirected advertising
      +    uint8_t        evt_type;
      +    ///Advertising address type: public/random
      +    uint8_t        adv_addr_type;
      +    ///Advertising address value
      +    bd_addr_t      adv_addr;
      +    ///Data length in advertising packet
      +    uint8_t        data_len;
      +    ///Data of advertising packet
      +    uint8_t        data[GAP_ADV_DATA_LEN];
      +    ///RSSI value for advertising packet
      +    uint8_t        rssi;
      +} adv_report_t;
       
       
       /// P256 Public key data format
      @@ -545,25 +844,31 @@ typedef struct
           /// X Coordinate of the key
           uint8_t y[GAP_P256_KEY_LEN];
       } public_key_t;
      +/// P256 private key data format
      +typedef struct
      +{
      +    ///MSB->LSB
      +    uint8_t Secrt_key[GAP_P256_KEY_LEN];
      +} private_key_t;
       
       
       
       /// Address information about a device address
      -typedef struct gap_bdaddr
      +struct gap_bdaddr
       {
           /// BD Address of device
      -    uint8_t addr[GAP_BD_ADDR_LEN];
      +    bd_addr_t addr;
           /// Address type of the device 0=public/1=private random
           uint8_t addr_type;
      -} gap_bdaddr_t;
      +};
       
       /// Resolving list device information
       struct gap_ral_dev_info
       {
      -    /// Device identity
      -    gap_bdaddr_t addr;
      -    /// Privacy Mode
      -    uint8_t      priv_mode;
      +    /// Address type of the device 0=public/1=private random
      +    uint8_t addr_type;
      +    /// BD Address of device
      +    bd_addr_t addr;
           /// Peer IRK
           uint8_t peer_irk[GAP_KEY_LEN];
           /// Local IRK
      @@ -571,31 +876,186 @@ struct gap_ral_dev_info
       };
       
       /// Generic Security key structure
      -typedef struct gap_sec_key
      +struct gap_sec_key
       {
           /// Key value MSB -> LSB
           uint8_t key[GAP_KEY_LEN];
      -} gap_sec_key_t;
      +};
       
      -/// Connection parameters information
      -typedef struct gap_con_param
      +/// Configuration for advertising on primary channel
      +struct gap_adv_prim_cfg
       {
      -    /// Connection interval in 1.25ms unit
      -    uint16_t            con_interval;
      -    /// Connection latency value (in number of connection events)
      -    uint16_t            con_latency;
      -    /// Supervision timeout in 10ms unit
      -    uint16_t            sup_to;
      -} gap_con_param_t;
      +    /// Minimum advertising interval (in unit of 625us). Must be greater than 20ms
      +    uint32_t adv_intv_min;
      +    /// Maximum advertising interval (in unit of 625us). Must be greater than 20ms
      +    uint32_t adv_intv_max;
      +    /// Bit field indicating the channel mapping
      +    uint8_t chnl_map;
      +    /// Indicate on which PHY primary advertising has to be performed (@see enum gap_phy_type)
      +    /// Note that LE 2M PHY is not allowed and that legacy advertising only support LE 1M PHY
      +    uint8_t phy;
      +};
       
      -/// Periodic advertising address information
      -typedef struct gap_per_adv_bdaddr
      +/// Configuration for advertising on secondary channel
      +struct gap_adv_second_cfg
       {
      -    /// BD Address of device
      -    uint8_t addr[GAP_BD_ADDR_LEN];
      -    /// Address type of the device 0=public/1=private random
      -    uint8_t addr_type;
      -} gap_per_adv_bdaddr_t;
      +    /// Maximum number of advertising events the controller can skip before sending the
      +    /// AUX_ADV_IND packets. 0 means that AUX_ADV_IND PDUs shall be sent prior each
      +    /// advertising events
      +    uint8_t max_skip;
      +    /// Indicate on which PHY secondary advertising has to be performed (@see enum gap_phy_type)
      +    uint8_t phy;
      +    /// Advertising SID
      +    uint8_t adv_sid;
      +};
      +
      +/// Configuration for periodic advertising
      +struct gap_adv_period_cfg
      +{
      +    /// Minimum advertising interval (in unit of 1.25ms). Must be greater than 20ms
      +    uint16_t adv_intv_min;
      +    /// Maximum advertising interval (in unit of 1.25ms). Must be greater than 20ms
      +    uint16_t adv_intv_max;
      +};
      +
      +/// Advertising parameters
      +struct gap_adv_param
      +{
      +    /// Advertising type (@see enum gap_adv_type)
      +    uint8_t type;
      +    /// Discovery mode (@see enum gap_adv_mode)
      +    uint8_t disc_mode;
      +    /// Bit field value provided advertising properties (@see enum gap_adv_prop for bit signification)
      +    uint16_t prop;
      +    /// Maximum power level at which the advertising packets have to be transmitted
      +    /// (between -127 and 126 dBm)
      +    int8_t max_tx_pwr;
      +    /// Advertising filtering policy
      +    uint8_t filter_pol;
      +    /// Peer address configuration (only used in case of directed advertising)
      +    struct gap_bdaddr peer_addr;
      +    /// Configuration for primary advertising
      +    struct gap_adv_prim_cfg prim_cfg;
      +    /// Configuration for secondary advertising (valid only if advertising type is
      +    /// GAPM_ADV_TYPE_EXTENDED or GAPM_ADV_TYPE_PERIODIC)
      +    struct gap_adv_second_cfg second_cfg;
      +    /// Configuration for periodic advertising (valid only if advertising type os
      +    /// GAPM_ADV_TYPE_PERIODIC)
      +    struct gap_adv_period_cfg period_cfg;
      +};
      +
      +/// Additional advertising parameters
      +struct gap_adv_add_param
      +{
      +    /// Advertising duration (in unit of 10ms). 0 means that advertising continues
      +    /// until the host disable it
      +    uint16_t duration;
      +    /// Maximum number of extended advertising events the controller shall attempt to send prior to
      +    /// terminating the extending advertising
      +    /// Valid only if extended advertising
      +    uint8_t max_adv_evt;
      +};
      +
      +/// Scan Window operation parameters
      +struct gap_scan_wd_op_param
      +{
      +    /// Scan interval
      +    uint16_t scan_intv;
      +    /// Scan window
      +    uint16_t scan_wd;
      +};
      +
      +/// Scanning parameters
      +struct gap_scan_param
      +{
      +    /// Type of scanning to be started (@see enum gap_scan_type)
      +    uint8_t type;
      +    /// Properties for the scan procedure (@see enum gap_scan_prop for bit signification)
      +    uint8_t prop;
      +    /// Duplicate packet filtering policy
      +    uint8_t dup_filt_pol;
      +    /// Reserved for future use
      +    uint8_t rsvd;
      +    /// Scan window opening parameters for LE 1M PHY
      +    struct gap_scan_wd_op_param scan_param_1m;
      +    /// Scan window opening parameters for LE Coded PHY
      +    struct gap_scan_wd_op_param scan_param_coded;
      +    /// Scan duration (in unit of 10ms). 0 means that the controller will scan continuously until
      +    /// reception of a stop command from the application
      +    uint16_t duration;
      +    /// Scan period (in unit of 1.28s). Time interval betweem two consequent starts of a scan duration
      +    /// by the controller. 0 means that the scan procedure is not periodic
      +    uint16_t period;
      +};
      +
      +/// Connection parameters
      +struct gap_conn_param
      +{
      +    /// Minimum value for the connection interval (in unit of 1.25ms). Shall be less than or equal to
      +    /// conn_intv_max value. Allowed range is 7.5ms to 4s.
      +    uint16_t conn_intv_min;
      +    /// Maximum value for the connection interval (in unit of 1.25ms). Shall be greater than or equal to
      +    /// conn_intv_min value. Allowed range is 7.5ms to 4s.
      +    uint16_t conn_intv_max;
      +    /// Slave latency. Number of events that can be missed by a connected slave device
      +    uint16_t conn_latency;
      +    /// Link supervision timeout (in unit of 10ms). Allowed range is 100ms to 32s
      +    uint16_t supervision_to;
      +    /// Recommended minimum duration of connection events (in unit of 625us)
      +    uint16_t ce_len_min;
      +    /// Recommended maximum duration of connection events (in unit of 625us)
      +    uint16_t ce_len_max;
      +};
      +
      +/// Initiating parameters
      +struct gap_init_param
      +{
      +    /// Initiating type (@see enum gap_init_type)
      +    uint8_t type;
      +    /// Properties for the initiating procedure (@see enum gap_init_prop for bit signification)
      +    uint8_t prop;
      +    /// Timeout for automatic connection establishment (in unit of 10ms). Cancel the procedure if not all
      +    /// indicated devices have been connected when the timeout occurs. 0 means there is no timeout
      +    uint16_t conn_to;
      +    /// Scan window opening parameters for LE 1M PHY
      +    struct gap_scan_wd_op_param scan_param_1m;
      +    /// Scan window opening parameters for LE Coded PHY
      +    struct gap_scan_wd_op_param scan_param_coded;
      +    /// Connection parameters for LE 1M PHY
      +    struct gap_conn_param conn_param_1m;
      +    /// Connection parameters for LE 2M PHY
      +    struct gap_conn_param conn_param_2m;
      +    /// Connection parameters for LE Coded PHY
      +    struct gap_conn_param conn_param_coded;
      +    /// Address of peer device in case white list is not used for connection
      +    struct gap_bdaddr peer_addr;
      +};
      +
      +/// Periodic advertising information
      +struct gap_period_adv_addr_cfg
      +{
      +    /// Advertiser address information
      +    struct gap_bdaddr addr;
      +    /// Advertising SID
      +    uint8_t adv_sid;
      +};
      +
      +/// Periodic synchronization parameters
      +struct gap_period_sync_param
      +{
      +    /// Number of periodic advertising that can be skipped after a successful receive. Maximum authorized
      +    /// value is 499
      +    uint16_t skip;
      +    /// Synchronization timeout for the periodic advertising (in unit of 10ms between 100ms and 163.84s)
      +    uint16_t sync_to;
      +    /// Indicate if Periodic Advertiser List has to be used to determine which advertiser to listen to, else
      +    /// provided advertiser information are used
      +    uint8_t use_pal;
      +    /// Reserved for future used
      +    uint8_t rsvd;
      +    /// Address of advertiser with which synchronization has to be established (used only if use_pal is false)
      +    struct gap_period_adv_addr_cfg adv_addr;
      +};
       
       /// @} GAP
       #endif // GAP_H_
  • services/ble_stack/hl/api/prf_types.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/hl/api/prf_types.h bes/services/ble_stack/hl/api/prf_types.h
      index f9eddcd78dc..1183fa11ab8 100644
      --- a/services/ble_stack/hl/api/prf_types.h
      +++ b/services/ble_stack/hl/api/prf_types.h
      @@ -18,7 +18,7 @@
       /**
        ****************************************************************************************
        * @addtogroup PRF_TYPES
      - * @ingroup Profile
      + * @ingroup PROFILE
        * @brief Definitions of shared profiles types
        *
        * @{
      @@ -29,15 +29,18 @@
        * INCLUDE FILES
        ****************************************************************************************
        */
      -#include "gatt.h"
      +#include "att.h"
       #include "compiler.h"
      -#include <stdint.h>
       
       /*
        * DEFINES
        ****************************************************************************************
        */
       
      +/// Attribute is mandatory
      +#define ATT_MANDATORY   (0xFF)
      +/// Attribute is optional
      +#define ATT_OPTIONAL    (0x00)
       
       /// Characteristic Presentation Format Descriptor Size
       #define PRF_CHAR_PRES_FMT_SIZE  (7)
      @@ -49,9 +52,9 @@ enum prf_cli_conf
           /// Stop notification/indication
           PRF_CLI_STOP_NTFIND = 0x0000,
           /// Start notification
      -    PRF_CLI_START_NTF   = 0x0001,
      +    PRF_CLI_START_NTF,
           /// Start indication
      -    PRF_CLI_START_IND   = 0x0002,
      +    PRF_CLI_START_IND,
       };
       
       /// Possible values for setting server configuration characteristics
      @@ -60,7 +63,7 @@ enum prf_srv_conf
           /// Stop Broadcast
           PRF_SRV_STOP_BCST = 0x0000,
           /// Start Broadcast
      -    PRF_SRV_START_BCST = 0x0001,
      +    PRF_SRV_START_BCST,
       };
       
       /// Connection type
      @@ -87,6 +90,7 @@ enum prf_svc_type
        * Characteristic Presentation Format Descriptor structure
        * Packed size is PRF_CHAR_PRES_FMT_SIZE
        */
      +/// characteristic presentation information
       struct prf_char_pres_fmt
       {
           /// Unit (The Unit is a UUID)
      @@ -135,19 +139,23 @@ typedef uint16_t prf_sfloat;
       
       
       
      -/// utf8_s string
      -struct prf_utf_8
      +/// Attribute information
      +struct prf_att_info
       {
      -    /// value length
      +    /// Attribute Handle
      +    uint16_t handle;
      +    /// Attribute length
           uint16_t length;
      -    /// Value string in UTF8 format
      -    uint8_t  str[__ARRAY_EMPTY];
      +    /// Status of request
      +    uint8_t  status;
      +    /// Attribute value
      +    uint8_t value[__ARRAY_EMPTY];
       };
       
       
       
       
      -/// Service information structure
      +/// service handles
       struct prf_svc
       {
           /// start handle
      @@ -156,7 +164,7 @@ struct prf_svc
           uint16_t ehdl;
       };
       
      -/// Included Service information structure
      +/// service handles
       struct prf_incl_svc
       {
           /// attribute handle
      @@ -168,20 +176,24 @@ struct prf_incl_svc
           /// UUID length
           uint8_t uuid_len;
           /// UUID
      -    uint8_t uuid[GATT_UUID_128_LEN];
      +    uint8_t uuid[ATT_UUID_128_LEN];
       };
       
      -/// Characteristic information structure
      -struct prf_char
      +/// characteristic info
      +struct prf_char_inf
       {
      +    /// Characteristic handle
      +    uint16_t char_hdl;
           /// Value handle
           uint16_t val_hdl;
           /// Characteristic properties
           uint8_t prop;
      +    /// End of characteristic offset
      +    uint8_t char_ehdl_off;
       };
       
      -/// Descriptor information structure
      -struct prf_desc
      +/// characteristic description
      +struct prf_char_desc_inf
       {
           /// Descriptor handle
           uint16_t desc_hdl;
      @@ -193,26 +205,40 @@ struct prf_char_def
       {
           /// Characteristic UUID
           uint16_t uuid;
      -    /// Requirement bit field
      -    uint8_t req_bf;
      +    /// Requirement Attribute Flag
      +    uint8_t req_flag;
           /// Mandatory Properties
           uint8_t prop_mand;
       };
       
       /// Characteristic Descriptor definition
      -struct prf_desc_def
      +struct prf_char_desc_def
       {
           /// Characteristic Descriptor uuid
           uint16_t uuid;
      -    /// Requirement bit field
      -    uint8_t req_bf;
      +    /// requirement attribute flag
      +    uint8_t req_flag;
           /// Corresponding characteristic code
           uint8_t char_code;
       };
       
      +/// Message structure used to inform APP that a profile client role has been disabled
      +struct prf_client_disable_ind
      +{
      +    /// Status
      +    uint8_t status;
      +};
       
       
       
      +/// Message structure used to inform APP that an error has occured in the profile server role task
      +struct prf_server_error_ind
      +{
      +    /// Message ID
      +    uint16_t msg_id;
      +    /// Status
      +    uint8_t status;
      +};
       
       
       /// @} PRF_TYPES
  • services/ble_stack/hl/api/rwble_hl_error.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/hl/api/rwble_hl_error.h bes/services/ble_stack/hl/api/rwble_hl_error.h
      index cf741e5ca4d..e1c0f25d8f6 100644
      --- a/services/ble_stack/hl/api/rwble_hl_error.h
      +++ b/services/ble_stack/hl/api/rwble_hl_error.h
      @@ -48,7 +48,9 @@ enum hl_err
           // ----------------------------------------------------------------------------------
           // -------------------------  ATT Specific Error ------------------------------------
           // ----------------------------------------------------------------------------------
      -    /// 0x01: H_andle is invalid
      +    /// No error
      +    ATT_ERR_NO_ERROR                                                               = 0x00,
      +    /// 0x01: Handle is invalid
           ATT_ERR_INVALID_HANDLE                                                         = 0x01,
           /// 0x02: Read permission disabled
           ATT_ERR_READ_NOT_PERMITTED                                                     = 0x02,
      @@ -86,38 +88,38 @@ enum hl_err
           ATT_ERR_APP_ERROR                                                              = 0x80,
       
           // ----------------------------------------------------------------------------------
      -    // ------------------------- L2CAP Specific Error -----------------------------------
      +    // -------------------------- L2C Specific Error ------------------------------------
           // ----------------------------------------------------------------------------------
           /// Message cannot be sent because connection lost. (disconnected)
      -    L2CAP_ERR_CONNECTION_LOST                                                      = 0x30,
      -    /// MTU size exceed or invalid MTU proposed
      -    L2CAP_ERR_INVALID_MTU                                                          = 0x31,
      -    /// MPS size exceed or invalid MPS proposed
      -    L2CAP_ERR_INVALID_MPS                                                          = 0x32,
      +    L2C_ERR_CONNECTION_LOST                                                        = 0x30,
      +    /// Invalid PDU length exceed MTU
      +    L2C_ERR_INVALID_MTU_EXCEED                                                     = 0x31,
      +    /// Invalid PDU length exceed MPS
      +    L2C_ERR_INVALID_MPS_EXCEED                                                     = 0x32,
           /// Invalid Channel ID
      -    L2CAP_ERR_INVALID_CID                                                          = 0x33,
      +    L2C_ERR_INVALID_CID                                                            = 0x33,
           /// Invalid PDU
      -    L2CAP_ERR_INVALID_PDU                                                          = 0x34,
      -    /// Connection refused - unacceptable parameters
      -    L2CAP_ERR_UNACCEPTABLE_PARAM                                                   = 0x35,
      +    L2C_ERR_INVALID_PDU                                                            = 0x34,
      +    /// Connection refused - no resources available
      +    L2C_ERR_NO_RES_AVAIL                                                           = 0x35,
           /// Connection refused - insufficient authentication
      -    L2CAP_ERR_INSUFF_AUTHEN                                                        = 0x36,
      +    L2C_ERR_INSUFF_AUTHEN                                                          = 0x36,
           /// Connection refused - insufficient authorization
      -    L2CAP_ERR_INSUFF_AUTHOR                                                        = 0x37,
      +    L2C_ERR_INSUFF_AUTHOR                                                          = 0x37,
           /// Connection refused - insufficient encryption key size
      -    L2CAP_ERR_INSUFF_ENC_KEY_SIZE                                                  = 0x38,
      +    L2C_ERR_INSUFF_ENC_KEY_SIZE                                                    = 0x38,
           /// Connection Refused - insufficient encryption
      -    L2CAP_ERR_INSUFF_ENC                                                           = 0x39,
      -    /// Connection refused - SPSM not supported
      -    L2CAP_ERR_SPSM_NOT_SUPP                                                        = 0x3A,
      +    L2C_ERR_INSUFF_ENC                                                             = 0x39,
      +    /// Connection refused - LE_PSM not supported
      +    L2C_ERR_LEPSM_NOT_SUPP                                                         = 0x3A,
           /// No more credit
      -    L2CAP_ERR_INSUFF_CREDIT                                                        = 0x3B,
      +    L2C_ERR_INSUFF_CREDIT                                                          = 0x3B,
           /// Command not understood by peer device
      -    L2CAP_ERR_NOT_UNDERSTOOD                                                       = 0x3C,
      +    L2C_ERR_NOT_UNDERSTOOD                                                         = 0x3C,
           /// Credit error, invalid number of credit received
      -    L2CAP_ERR_CREDIT_ERROR                                                         = 0x3D,
      +    L2C_ERR_CREDIT_ERROR                                                           = 0x3D,
           /// Channel identifier already allocated
      -    L2CAP_ERR_CID_ALREADY_ALLOC                                                    = 0x3E,
      +    L2C_ERR_CID_ALREADY_ALLOC                                                      = 0x3E,
       
       
           // ----------------------------------------------------------------------------------
      @@ -151,8 +153,8 @@ enum hl_err
           GAP_ERR_UNEXPECTED                                                             = 0x4C,
           /// Feature mismatch
           GAP_ERR_MISMATCH                                                               = 0x4D,
      -    /// Buffer cannot be used due to invalid header or tail length
      -    GAP_ERR_INVALID_BUFFER                                                         = 0x4E,
      +    /// Limit Reached
      +    GAP_ERR_LIMIT_REACHED                                                          = 0x4E,
       
           // ----------------------------------------------------------------------------------
           // ------------------------- GATT Specific Error ------------------------------------
      @@ -177,87 +179,87 @@ enum hl_err
           // ----------------------------------------------------------------------------------
           // SMP Protocol Errors detected on local device
           /// The user input of pass key failed, for example, the user canceled the operation.
      -    SMP_ERR_LOC_PASSKEY_ENTRY_FAILED                                               = 0x61,
      +    SMP_ERROR_LOC_PASSKEY_ENTRY_FAILED                                             = 0x61,
           /// The OOB Data is not available.
      -    SMP_ERR_LOC_OOB_NOT_AVAILABLE                                                  = 0x62,
      +    SMP_ERROR_LOC_OOB_NOT_AVAILABLE                                                = 0x62,
           /// The pairing procedure cannot be performed as authentication requirements cannot be met
           /// due to IO capabilities of one or both devices.
      -    SMP_ERR_LOC_AUTH_REQ                                                           = 0x63,
      +    SMP_ERROR_LOC_AUTH_REQ                                                         = 0x63,
           /// The confirm value does not match the calculated confirm value.
      -    SMP_ERR_LOC_CONF_VAL_FAILED                                                    = 0x64,
      +    SMP_ERROR_LOC_CONF_VAL_FAILED                                                  = 0x64,
           /// Pairing is not supported by the device.
      -    SMP_ERR_LOC_PAIRING_NOT_SUPP                                                   = 0x65,
      +    SMP_ERROR_LOC_PAIRING_NOT_SUPP                                                 = 0x65,
           /// The resultant encryption key size is insufficient for the security requirements of
           /// this device.
      -    SMP_ERR_LOC_ENC_KEY_SIZE                                                       = 0x66,
      +    SMP_ERROR_LOC_ENC_KEY_SIZE                                                     = 0x66,
           /// The SMP command received is not supported on this device.
      -    SMP_ERR_LOC_CMD_NOT_SUPPORTED                                                  = 0x67,
      +    SMP_ERROR_LOC_CMD_NOT_SUPPORTED                                                = 0x67,
           /// Pairing failed due to an unspecified reason.
      -    SMP_ERR_LOC_UNSPECIFIED_REASON                                                 = 0x68,
      +    SMP_ERROR_LOC_UNSPECIFIED_REASON                                               = 0x68,
           /// Pairing or Authentication procedure is disallowed because too little time has elapsed
           /// since last pairing request or security request.
      -    SMP_ERR_LOC_REPEATED_ATTEMPTS                                                  = 0x69,
      +    SMP_ERROR_LOC_REPEATED_ATTEMPTS                                                = 0x69,
           /// The command length is invalid or a parameter is outside of the specified range.
      -    SMP_ERR_LOC_INVALID_PARAM                                                      = 0x6A,
      +    SMP_ERROR_LOC_INVALID_PARAM                                                    = 0x6A,
           /// Indicates to the remote device that the DHKey Check value received doesn't
           /// match the one calculated by the local device.
      -    SMP_ERR_LOC_DHKEY_CHECK_FAILED                                                 = 0x6B,
      +    SMP_ERROR_LOC_DHKEY_CHECK_FAILED                                               = 0x6B,
           /// Indicates that the confirm values in the numeric comparison protocol do not match.
      -    SMP_ERR_LOC_NUMERIC_COMPARISON_FAILED                                          = 0x6C,
      +    SMP_ERROR_LOC_NUMERIC_COMPARISON_FAILED                                        = 0x6C,
           /// Indicates that the pairing over the LE transport failed due to a Pairing Request sent
           /// over the BR/EDR transport in process.
      -    SMP_ERR_LOC_BREDR_PAIRING_IN_PROGRESS                                          = 0x6D,
      +    SMP_ERROR_LOC_BREDR_PAIRING_IN_PROGRESS                                        = 0x6D,
           /// Indicates that the BR/EDR Link Key generated on the BR/EDR transport cannot be
           /// used to derive and distribute keys for the LE transport.
      -    SMP_ERR_LOC_CROSS_TRANSPORT_KEY_GENERATION_NOT_ALLOWED                         = 0x6E,
      +    SMP_ERROR_LOC_CROSS_TRANSPORT_KEY_GENERATION_NOT_ALLOWED                       = 0x6E,
           // SMP Protocol Errors detected by remote device
           /// The user input of passkey failed, for example, the user canceled the operation.
      -    SMP_ERR_REM_PASSKEY_ENTRY_FAILED                                               = 0x71,
      +    SMP_ERROR_REM_PASSKEY_ENTRY_FAILED                                             = 0x71,
           /// The OOB Data is not available.
      -    SMP_ERR_REM_OOB_NOT_AVAILABLE                                                  = 0x72,
      +    SMP_ERROR_REM_OOB_NOT_AVAILABLE                                                = 0x72,
           /// The pairing procedure cannot be performed as authentication requirements cannot be
           /// met due to IO capabilities of one or both devices.
      -    SMP_ERR_REM_AUTH_REQ                                                           = 0x73,
      +    SMP_ERROR_REM_AUTH_REQ                                                         = 0x73,
           /// The confirm value does not match the calculated confirm value.
      -    SMP_ERR_REM_CONF_VAL_FAILED                                                    = 0x74,
      +    SMP_ERROR_REM_CONF_VAL_FAILED                                                  = 0x74,
           /// Pairing is not supported by the device.
      -    SMP_ERR_REM_PAIRING_NOT_SUPP                                                   = 0x75,
      +    SMP_ERROR_REM_PAIRING_NOT_SUPP                                                 = 0x75,
           /// The resultant encryption key size is insufficient for the security requirements of
           /// this device.
      -    SMP_ERR_REM_ENC_KEY_SIZE                                                       = 0x76,
      +    SMP_ERROR_REM_ENC_KEY_SIZE                                                     = 0x76,
           /// The SMP command received is not supported on this device.
      -    SMP_ERR_REM_CMD_NOT_SUPPORTED                                                  = 0x77,
      +    SMP_ERROR_REM_CMD_NOT_SUPPORTED                                                = 0x77,
           /// Pairing failed due to an unspecified reason.
      -    SMP_ERR_REM_UNSPECIFIED_REASON                                                 = 0x78,
      +    SMP_ERROR_REM_UNSPECIFIED_REASON                                               = 0x78,
           /// Pairing or Authentication procedure is disallowed because too little time has elapsed
           /// since last pairing request or security request.
      -    SMP_ERR_REM_REPEATED_ATTEMPTS                                                  = 0x79,
      +    SMP_ERROR_REM_REPEATED_ATTEMPTS                                                = 0x79,
           /// The command length is invalid or a parameter is outside of the specified range.
      -    SMP_ERR_REM_INVALID_PARAM                                                      = 0x7A,
      +    SMP_ERROR_REM_INVALID_PARAM                                                    = 0x7A,
           /// Indicates to the remote device that the DHKey Check value received doesn't
           /// match the one calculated by the local device.
      -    SMP_ERR_REM_DHKEY_CHECK_FAILED                                                 = 0x7B,
      +    SMP_ERROR_REM_DHKEY_CHECK_FAILED                                               = 0x7B,
           /// Indicates that the confirm values in the numeric comparison protocol do not match.
      -    SMP_ERR_REM_NUMERIC_COMPARISON_FAILED                                          = 0x7C,
      +    SMP_ERROR_REM_NUMERIC_COMPARISON_FAILED                                        = 0x7C,
           /// Indicates that the pairing over the LE transport failed due to a Pairing Request sent
           /// over the BR/EDR transport in process.
      -    SMP_ERR_REM_BREDR_PAIRING_IN_PROGRESS                                          = 0x7D,
      +    SMP_ERROR_REM_BREDR_PAIRING_IN_PROGRESS                                        = 0x7D,
           /// Indicates that the BR/EDR Link Key generated on the BR/EDR transport cannot be
           /// used to derive and distribute keys for the LE transport.
      -    SMP_ERR_REM_CROSS_TRANSPORT_KEY_GENERATION_NOT_ALLOWED                         = 0x7E,
      +    SMP_ERROR_REM_CROSS_TRANSPORT_KEY_GENERATION_NOT_ALLOWED                       = 0x7E,
           // SMP Errors triggered by local device
           /// The provided resolvable address has not been resolved.
      -    SMP_ERR_ADDR_RESOLV_FAIL                                                       = 0x20,
      +    SMP_ERROR_ADDR_RESOLV_FAIL                                                     = 0xD0,
           /// The Signature Verification Failed
      -    SMP_ERR_SIGN_VERIF_FAIL                                                        = 0x21,
      +    SMP_ERROR_SIGN_VERIF_FAIL                                                      = 0xD1,
           /// The encryption procedure failed because the slave device didn't find the LTK
           /// needed to start an encryption session.
      -    SMP_ERR_ENC_KEY_MISSING                                                        = 0x22,
      +    SMP_ERROR_ENC_KEY_MISSING                                                      = 0xD2,
           /// The encryption procedure failed because the slave device doesn't support the
           /// encryption feature.
      -    SMP_ERR_ENC_NOT_SUPPORTED                                                      = 0x23,
      +    SMP_ERROR_ENC_NOT_SUPPORTED                                                    = 0xD3,
           /// A timeout has occurred during the start encryption session.
      -    SMP_ERR_ENC_TIMEOUT                                                            = 0x24,
      +    SMP_ERROR_ENC_TIMEOUT                                                          = 0xD4,
       
           // ----------------------------------------------------------------------------------
           //------------------------ Profiles specific error codes ----------------------------
  • services/ble_stack/hl/inc/prf_utils_128.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/hl/inc/prf_utils_128.h bes/services/ble_stack/hl/inc/prf_utils_128.h
      index dc4ad756ca2..747603018bd 100644
      --- a/services/ble_stack/hl/inc/prf_utils_128.h
      +++ b/services/ble_stack/hl/inc/prf_utils_128.h
      @@ -21,7 +21,7 @@
       /**
        ****************************************************************************************
        * @addtogroup PRF_UTILS
      - * @ingroup Profile
      + * @ingroup PROFILE
        *
        * @brief Definitions of shared profiles functions that can be used by several profiles
        *
      @@ -35,12 +35,15 @@
        ****************************************************************************************
        */
       
      -#include "ke_task.h"
      +#if (BLE_CLIENT_PRF)
      +#include "ke_msg.h"
       #include "prf.h"
       #include "prf_types.h"
      -#include "gatt.h"
      +#include "gattc_task.h"
       #include "gapc.h"
      -#include "gapc_msg.h"
      +#include "gapc_task.h"
      +#include "attm_db.h"
      +#endif /* (BLE_CLIENT_PRF) */
       
       /*
        * MACROS
      @@ -55,38 +58,53 @@
       
       #if (BLE_CLIENT_PRF)
       
      +/// Characteristic definition
      +struct prf_char_def_128
      +{
      +    /// Characteristic UUID
      +    uint8_t uuid[ATT_UUID_128_LEN];
      +    /// Requirement Attribute Flag
      +    uint8_t req_flag;
      +    /// Mandatory Properties
      +    uint8_t prop_mand;
      +};
       
       /**
        ****************************************************************************************
      + * @brief Request service discovery with 128-bit UUID on peer device.
        *
      + * This request will be used to retrieve start and end handles of the service.
        *
      + * @param con_info Pointer to connection information (connection handle, app task id,
      + *                 profile task id)
        *
      + * @param uuid_128 128-bit service UUID
        ****************************************************************************************
        */
      +void prf_disc_svc_send_128(prf_env_t *prf_env, uint8_t conidx, uint8_t *uuid_128);
       
       /**
        ****************************************************************************************
      - * @brief Check 128-bit service characteristic validity
      + * @brief Check validity for service characteristic with 128-bit UUID
        *
        * For each characteristic in service it verifies handles.
        *
        * If some handles are not present, it checks if they shall be present or they are optional.
        *
      - * @param nb_chars     Number of Characteristics in the service
      - * @param p_chars      Characteristics values (char handles, val handles, properties)
      - * @param p_chars_req  Characteristics requirements.
      + * @param nb_chars   Number of Characteristics in the service
      + * @param chars      Characteristics values (char handles, val handles, properties)
      + * @param chars_req  Characteristics requirements.
        *
      - * @return Execution status (@see enum hl_err)
      + * @return 0x1 if service is valid, 0x00 else.
        ****************************************************************************************
        */
      +uint8_t prf_check_svc_char_validity_128(uint8_t nb_chars,
      +                                    const struct prf_char_inf* chars,
      +                                    const struct prf_char_def_128* chars_req);
       
      -uint16_t prf_check_svc128_char_validity(uint8_t nb_chars,
      -                                    const prf_char_t* p_chars,
      -                                    const prf_char128_def_t* p_chars_req);
      -
      -void prf_extract_svc128_info(uint16_t first_hdl, uint8_t nb_att, const gatt_svc_att_t* p_atts,
      -        uint8_t nb_chars, const prf_char128_def_t* p_chars_req, prf_char_t* p_chars,
      -        uint8_t nb_descs, const prf_desc_def_t* p_descs_req, prf_desc_t* p_descs);
      +void prf_extract_svc_info_128(const struct gattc_sdp_svc_ind* param,
      +        uint8_t nb_chars, const struct prf_char_def_128* chars_req, struct prf_char_inf* chars,
      +        uint8_t nb_descs, const struct prf_char_desc_def* descs_req, struct prf_char_desc_inf* descs);
       
       #endif //(BLE_CLIENT_PRF)
       
  • services/ble_stack/hl/inc/prf_utils.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ble_stack/hl/inc/prf_utils.h bes/services/ble_stack/hl/inc/prf_utils.h
      index c4e85e57c05..cd6b0fcef54 100644
      --- a/services/ble_stack/hl/inc/prf_utils.h
      +++ b/services/ble_stack/hl/inc/prf_utils.h
      @@ -18,7 +18,7 @@
       /**
        ****************************************************************************************
        * @addtogroup PRF_UTILS
      - * @ingroup Profile
      + * @ingroup PROFILE
        *
        * @brief Definitions of shared profiles functions that can be used by several profiles
        *
      @@ -33,12 +33,15 @@
        */
       
       #include "rwip_config.h"
      -#include "ke_task.h"
      +#if (BLE_SERVER_PRF || BLE_CLIENT_PRF)
      +#include "ke_msg.h"
       #include "prf_types.h"
      -#include "gatt.h"
      +#include "gattc_task.h"
       #include "gapc.h"
      -#include "gapc_msg.h"
      +#include "gapc_task.h"
      +#include "attm.h"
       #include "prf.h"
      +#endif /* (BLE_SERVER_PRF || BLE_CLIENT_PRF) */
       
       /*
        * MACROS
      @@ -53,9 +56,8 @@
        * @param type      Profile task type (In lower case, ex: htpc, disc, ...)
        ****************************************************************************************
        */
      -#define PRF_ENV_T(type)           type##_env_t
      -#define PRF_ENV_TAG(type)         struct type##_env_tag
      -#define PRF_ENV_GET(prf_id, type) ((type##_env_t *)prf_env_get((PRF_ID_##prf_id)))
      +#define PRF_ENV_GET(prf_id, type) \
      +        ((struct type ## _env_tag *)prf_env_get((TASK_ID_##prf_id)))
       
       
       
      @@ -72,7 +74,7 @@
        * @brief Pack Characteristic Presentation Format descriptor value
        ****************************************************************************************
        */
      -void prf_pack_char_pres_fmt(co_buf_t* p_buf, const prf_char_pres_fmt_t* char_pres_fmt);
      +void prf_pack_char_pres_fmt(uint8_t *packed_val, const struct prf_char_pres_fmt* char_pres_fmt);
       #endif // (BLE_BATT_SERVER)
       
       #if (BLE_BATT_CLIENT)
      @@ -81,43 +83,70 @@ void prf_pack_char_pres_fmt(co_buf_t* p_buf, const prf_char_pres_fmt_t* char_pre
        * @brief Unpack Characteristic Presentation Format descriptor value
        ****************************************************************************************
        */
      -void prf_unpack_char_pres_fmt(co_buf_t* p_buf, prf_char_pres_fmt_t* char_pres_fmt);
      +void prf_unpack_char_pres_fmt(const uint8_t *packed_val, struct prf_char_pres_fmt* char_pres_fmt);
       #endif // (BLE_BATT_CLIENT)
       
       #if (BLE_CLIENT_PRF)
       /**
        ****************************************************************************************
      + * @brief Request  peer device to read an attribute
        *
      + * @param[in] prf_env Pointer to profile information
        *
      + * @param conidx   Connection index
      + * @param shdl     Search Start Handle
      + * @param ehdl     Search End Handle
        *
      + * @param valhdl   Value Handle
        *
      + * @note: if attribute is invalid, nothing is registered
        ****************************************************************************************
        */
      +void prf_read_char_send(prf_env_t *prf_env, uint8_t conidx,
      +                        uint16_t shdl, uint16_t ehdl, uint16_t valhdl);
       
       
       /**
        ****************************************************************************************
      + * @brief register attribute handle in GATT
        *
      + * @param[in] prf_env Pointer to profile information
        *
      + * @param conidx   Connection index
      + * @param svc   Service to register
        *
      + * @note: if attribute is invalid, nothing is registered
        ****************************************************************************************
        */
      +void prf_register_atthdl2gatt(prf_env_t *prf_env, uint8_t conidx, struct prf_svc *svc);
       
       /**
        ****************************************************************************************
      + * @brief Unregister attribute handle in GATT
        *
      + * @param[in] prf_env Pointer to profile information
        *
      + * @param conidx   Connection index
      + * @param svc   Service to register
        *
      + * @note: if attribute is invalid, nothing is registered
        ****************************************************************************************
        */
      +void prf_unregister_atthdl2gatt(prf_env_t *prf_env, uint8_t conidx, struct prf_svc *svc);
       
       /**
        ****************************************************************************************
      + * @brief Request service discovery on peer device.
        *
      + * This request will be used to retrieve start and end handles of the service.
        *
      + * @param[in] prf_env Pointer to profile information
        *
      + * @param conidx   Connection index
      + * @param uuid     Service UUID
        ****************************************************************************************
        */
      +void prf_disc_svc_send(prf_env_t *prf_env,uint8_t conidx,  uint16_t uuid);
       
       
       /**
      @@ -126,27 +155,32 @@ void prf_unpack_char_pres_fmt(co_buf_t* p_buf, prf_char_pres_fmt_t* char_pres_fm
        *
        * It will request write modification of peer handle
        *
      - * @param[in] conidx        Connection index
      - * @param[in] user_lid      GATT Client User Local Identifier
      - * @param[in] dummy         Dummy parameter returned in procedure completion
      - * @param[in] write_type    GATT Write Type (@see gatt_write_type)
      - * @param[in] hdl           Peer handle to modify
      - * @param[in] length        Value length
      - * @param[in] p_data        Pointer to data value
      - *
      - * @return Execution status (@see enum hl_err)
      + * @param[in] prf_env Pointer to profile information
      + * @param[in] conidx   Connection index
      + * @param[in] handle Peer handle to modify
      + * @param[in] value  New Peer handle value
      + * @param[in] length Value length
        ****************************************************************************************
        */
      -uint16_t prf_gatt_write(uint8_t conidx, uint8_t user_lid, uint16_t dummy, uint8_t write_type,
      -                        uint16_t hdl, uint16_t length, const uint8_t* p_data);
      +void prf_gatt_write(prf_env_t *prf_env, uint8_t conidx,
      +                    uint16_t handle, uint8_t* value, uint16_t length, uint8_t operation);
       
       /**
        ****************************************************************************************
      + * @brief Modify peer client configuration descriptor using GATT
        *
      + * It will request write modification of peer client configuration descriptor handle
        *
      + * @param[in] prf_env Pointer to profile information
        *
      + * @param[in] conidx   Connection index
      + * @param[in] handle Peer client configuration descriptor handle to modify
      + *
      + * @param[in] ntf_ind_cfg  Indication/Notification configuration
        ****************************************************************************************
        */
      +void prf_gatt_write_ntf_ind(prf_env_t *prf_env, uint8_t conidx, uint16_t handle,
      +        uint16_t ntf_ind_cfg);
       
       /**
        ****************************************************************************************
      @@ -156,16 +190,16 @@ uint16_t prf_gatt_write(uint8_t conidx, uint8_t user_lid, uint16_t dummy, uint8_
        *
        * If some handles are not present, it checks if they shall be present or they are optional.
        *
      - * @param nb_chars      Number of Characteristics in the service
      - * @param p_chars       Characteristics values (char handles, val handles, properties)
      - * @param p_chars_req   Characteristics requirements.
      + * @param nb_chars   Number of Characteristics in the service
      + * @param chars      Characteristics values (char handles, val handles, properties)
      + * @param chars_req  Characteristics requirements.
        *
      - * @return Execution status (@see enum hl_err)
      + * @return 0x1 if service is valid, 0x00 else.
        ****************************************************************************************
        */
      -uint16_t prf_check_svc_char_validity(uint8_t nb_chars,
      -                                    const prf_char_t* p_chars,
      -                                    const prf_char_def_t* p_chars_req);
      +uint8_t prf_check_svc_char_validity(uint8_t nb_chars,
      +                                    const struct prf_char_inf* chars,
      +                                    const struct prf_char_def* chars_req);
       
       /**
        ****************************************************************************************
      @@ -176,68 +210,80 @@ uint16_t prf_check_svc_char_validity(uint8_t nb_chars,
        * If some handles are not present, according to characteristic properties it verify if
        * descriptor is optional or not.
        *
      - * @param nb_descs       Number of Characteristic descriptors in the service
      - * @param p_descs        Characteristic descriptors values (handles)
      - * @param p_descs_req    Characteristics descriptors requirements.
      + * @param descs_size Number of Characteristic descriptors in the service
      + * @param descs      Characteristic descriptors values (handles)
      + * @param descs_req  Characteristics descriptors requirements.
        *
      - * @return Execution status (@see enum hl_err)
      + * @return 0x1 if service is valid, 0x00 else.
        ****************************************************************************************
        */
      -uint16_t prf_check_svc_desc_validity(uint8_t nb_descs,
      -                                        const prf_desc_t* p_descs,
      -                                        const prf_desc_def_t* p_descs_req,
      -                                        const prf_char_t* p_chars);
      +uint8_t prf_check_svc_char_desc_validity(uint8_t descs_size,
      +                                        const struct prf_char_desc_inf* descs,
      +                                        const struct prf_char_desc_def* descs_req,
      +                                        const struct prf_char_inf* chars);
       
       /**
        ****************************************************************************************
        * @brief Extract information of the service according to the service description
        *
      - * @param[in]     first_hdl    First handle value of following list
      - * @param[in]     nb_att       Number of attributes
      - * @param[in]     p_atts       Pointer to attribute information present in a service
      - * @param[in]     nb_chars     Length of provided arrays (chars and chars_req)
      - * @param[in]     p_chars_req    Characteristics requirements
      - * @param[in|out] p_chars            Characteristics
      - * @param[in]     nb_descs         Length of provided arrays (descs and descs_req)
      - * @param[in]     p_descs_req        Descriptors requirements
      - * @param[in|out] p_descs            Descriptors
      + * @param param            Service information
      + * @param nb_chars         Length of provided arrays (chars and chars_req)
      + * @param chars_req        Characteristics requirements
      + * @param chars            Characteristics
      + * @param nb_descs         Length of provided arrays (descs and descs_req)
      + * @param descs_req        Descriptors requirements
      + * @param descs            Descriptors
        ****************************************************************************************
        */
      -void prf_extract_svc_info(uint16_t first_hdl, uint8_t nb_att, const gatt_svc_att_t* p_atts,
      -        uint8_t nb_chars, const prf_char_def_t* p_chars_req, prf_char_t* p_chars,
      -        uint8_t nb_descs, const prf_desc_def_t* p_descs_req, prf_desc_t* p_descs);
      +void prf_extract_svc_info(const struct gattc_sdp_svc_ind* param,
      +        uint8_t nb_chars, const struct prf_char_def* chars_req, struct prf_char_inf* chars,
      +        uint8_t nb_descs, const struct prf_char_desc_def* descs_req, struct prf_char_desc_inf* descs);
       
       #endif //(BLE_CLIENT_PRF)
       
       
      +#if (BLE_CLIENT_PRF || BLE_TIP_SERVER || BLE_AN_SERVER || BLE_PAS_SERVER)
       
       /**
        ****************************************************************************************
      + * @brief The function is used to send information about peer attribute value
        *
      + * @param[in] prf_env       Pointer to the profile environment variable
      + * @param[in] conidx        Connection index
      + * @param[in] msg_id        Profile message ID to trigger
      + * @param[in] status        Response status code
      + * @param[in] read_ind      GATT read message indication
        ****************************************************************************************
        */
      +void prf_client_att_info_rsp(prf_env_t *prf_env, uint8_t conidx, uint16_t msg_id,
      +                             uint8_t status, struct gattc_read_ind const* read_ind);
       
      +#endif //(BLE_CLIENT_PRF || BLE_TIP_SERVER || BLE_AN_SERVER || BLE_PAS_SERVER)
       
       #if (BLE_SERVER_PRF || BLE_CLIENT_PRF)
       /**
        ****************************************************************************************
        * @brief Pack date time value
        *
      - * @param[in] p_buf       Pointer to the output buffer
      - * @param[in] p_date_time Pointer to structure date time
      + * @param[out] packed_date packed date time
      + * @param[in] date_time structure date time
      + *
      + * @return size of packed value
        ****************************************************************************************
        */
      -void prf_pack_date_time(co_buf_t*p_buf, const prf_date_time_t* p_date_time);
      +uint8_t prf_pack_date_time(uint8_t *packed_date, const struct prf_date_time* date_time);
       
       /**
        ****************************************************************************************
        * @brief Unpack date time value
        *
      - * @param[in]  p_buf       Pointer to input buffer
      - * @param[out] p_date_time Pointer to structure date time
      + * @param[in] packed_date packed date time
      + * @param[out] date_time structure date time
      + *
      + * @return size of packed value
        ****************************************************************************************
        */
      -void prf_unpack_date_time(co_buf_t* p_buf, prf_date_time_t* p_date_time);
      +uint8_t prf_unpack_date_time(uint8_t *packed_date, struct prf_date_time* date_time);
       
       #endif /* (BLE_SERVER_PRF || BLE_CLIENT_PRF) */
       

@OneDeuxTriSeiGo
Copy link
Author

  • services/bt_app/a2dp_codecs/include/app_a2dp_codecs.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/a2dp_codecs/include/app_a2dp_codecs.h bes/services/bt_app/a2dp_codecs/include/app_a2dp_codecs.h
      index 4687f708eda..7420ea55103 100644
      --- a/services/bt_app/a2dp_codecs/include/app_a2dp_codecs.h
      +++ b/services/bt_app/a2dp_codecs/include/app_a2dp_codecs.h
      @@ -26,6 +26,8 @@
       extern "C" {
       #endif
       
      +int a2dp_codec_init(void);
      +uint8_t a2dp_codec_confirm_stream_state(uint8_t index, uint8_t old_state, uint8_t new_state);
       
       #if defined(__cplusplus)
       }
  • services/bt_app/app_a2dp.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_a2dp.h bes/services/bt_app/app_a2dp.h
      index bedba4cff52..c8be88cec02 100644
      --- a/services/bt_app/app_a2dp.h
      +++ b/services/bt_app/app_a2dp.h
      @@ -20,12 +20,17 @@
       extern "C" {
       #endif
       
      +#define A2DP_NON_CODEC_TYPE_NON         0
      +#define A2DP_NON_CODEC_TYPE_LHDC        1
      +#define A2DP_NON_CODEC_TYPE_LDAC        2
      +#define A2DP_NON_CODEC_TYPE_SCALABLE    3
       
      +uint8_t a2dp_get_current_codec_type(uint8_t *elements);
       
       bool a2dp_is_music_ongoing(void);
      -bool app_bt_a2dp_send_volume_change(int device_id);
      +int a2dp_volume_set(enum BT_DEVICE_ID_T id, uint8_t vol);
       #if defined(A2DP_LDAC_ON)
      -void app_ibrt_restore_ldac_info(uint8_t device_id, uint8_t sample_freq);
      +void app_ibrt_restore_ldac_info(uint8_t sample_freq);
       #endif
       #ifdef __cplusplus
       }
  • services/bt_app/app_bt_func.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_bt_func.h bes/services/bt_app/app_bt_func.h
      index c314551fc4b..1361d3be781 100644
      --- a/services/bt_app/app_bt_func.h
      +++ b/services/bt_app/app_bt_func.h
      @@ -45,6 +45,13 @@ typedef enum _bt_fn_req {
               HF_DisconnectAudioLink_req                  = 15,
               HF_EnableSniffMode_req                      = 16,
               HF_SetMasterRole_req                        = 17,
      +#if defined (__HSP_ENABLE__)
      +        HS_CreateServiceLink_req                    = 18,
      +        HS_CreateAudioLink_req                      = 19,
      +        HS_DisconnectAudioLink_req                  = 20,
      +        HS_EnableSniffMode_req                      = 21,
      +        HS_DisconnectServiceLink_req                = 22,
      +#endif
               BT_Control_SleepMode_req                    = 23,
               BT_Custom_Func_req                          = 24,
               ME_StartSniff_req                           = 25,
      @@ -59,7 +66,7 @@ typedef enum _bt_fn_req {
               Write_Controller_Memory_Test              = 32,
               Read_Controller_Memory_Test              = 33,
       }bt_fn_req;
      -typedef void (*APP_BT_REQ_CUSTOMER_CALl_CB_T)(void *, void *, void *, void *);
      +typedef void (*APP_BTTHREAD_REQ_CUSTOMER_CALL_CB_T)(void *, void *);
       
       typedef union _bt_fn_param {
           // BtStatus Me_switch_sco(uint16_t  scohandle)
      @@ -103,6 +110,7 @@ typedef union _bt_fn_param {
           //BtStatus ME_SetAccessibleMode(btif_accessible_mode_t mode, const btif_access_mode_info_t *info)
           struct {
               btif_accessible_mode_t mode;
      +        btif_access_mode_info_t info;
           } ME_SetAccessibleMode_param;
       
           //BtStatus Me_SetLinkPolicy(btif_remote_device_t *remDev, btif_link_policy_t policy)
      @@ -132,7 +140,7 @@ typedef union _bt_fn_param {
           //BtStatus A2DP_OpenStream(a2dp_stream_t *Stream, bt_bdaddr_t *Addr)
           struct {
               a2dp_stream_t *Stream;
      -        bt_bdaddr_t Addr;
      +        bt_bdaddr_t *Addr;
           } A2DP_OpenStream_param;
       
           //BtStatus A2DP_CloseStream(a2dp_stream_t *Stream);
      @@ -148,34 +156,34 @@ typedef union _bt_fn_param {
       
           //BtStatus HF_CreateServiceLink(HfChannel *Chan, bt_bdaddr_t *Addr)
           struct {
      -        btif_hf_channel_t* Chan;
      -        bt_bdaddr_t Addr;
      +        hf_chan_handle_t Chan;
      +        bt_bdaddr_t *Addr;
           } HF_CreateServiceLink_param;
       
      -    //bt_status_t HF_DisconnectServiceLink(btif_hf_channel_t* Chan)
      +    //bt_status_t HF_DisconnectServiceLink(hf_chan_handle_t Chan)
           struct {
      -        btif_hf_channel_t* Chan;
      +        hf_chan_handle_t Chan;
           } HF_DisconnectServiceLink_param;
       
      -    //bt_status_t HF_CreateAudioLink(btif_hf_channel_t* Chan)
      +    //bt_status_t HF_CreateAudioLink(hf_chan_handle_t Chan)
           struct {
      -        btif_hf_channel_t* Chan;
      +        hf_chan_handle_t Chan;
           } HF_CreateAudioLink_param;
       
      -    //bt_status_t HF_DisconnectAudioLink(btif_hf_channel_t* Chan)
      +    //bt_status_t HF_DisconnectAudioLink(hf_chan_handle_t Chan)
           struct {
      -        btif_hf_channel_t* Chan;
      +        hf_chan_handle_t Chan;
           } HF_DisconnectAudioLink_param;
       
      -    //bt_status_t HF_EnableSniffMode(btif_hf_channel_t* Chan, BOOL Enable)
      +    //bt_status_t HF_EnableSniffMode(hf_chan_handle_t Chan, BOOL Enable)
           struct {
      -        btif_hf_channel_t* Chan;
      +        hf_chan_handle_t Chan;
               BOOL Enable;
           } HF_EnableSniffMode_param;
       
      -    //bt_status_t HF_SetMasterRole(btif_hf_channel_t* Chan, BOOL Flag);
      +    //bt_status_t HF_SetMasterRole(hf_chan_handle_t Chan, BOOL Flag);
           struct {
      -        btif_hf_channel_t* Chan;
      +        hf_chan_handle_t Chan;
               BOOL Flag;
           } HF_SetMasterRole_param;
       
      @@ -186,6 +194,35 @@ typedef union _bt_fn_param {
           } DIP_QuryService_param;
       #endif
       
      +#if defined (__HSP_ENABLE__)
      +    //bt_status_t HS_CreateServiceLink(HsChannel *Chan, bt_bdaddr_t *Addr)
      +    struct {
      +        HsChannel *Chan;
      +        bt_bdaddr_t *Addr;
      +    } HS_CreateServiceLink_param;
      +
      +    //BtStatus HS_CreateAudioLink(HsChannel *Chan)
      +    struct {
      +        HsChannel *Chan;
      +    } HS_CreateAudioLink_param;
      +
      +    //BtStatus HS_DisconnectAudioLink(HsChannel *Chan)
      +    struct {
      +        HsChannel *Chan;
      +    } HS_DisconnectAudioLink_param;
      +
      +    //BtStatus HS_DisconnectServiceLink(HsChannel *Chan)
      +    struct {
      +        HsChannel *Chan;
      +    } HS_DisconnectServiceLink_param;
      +
      +    //BtStatus HS_EnableSniffMode(HsChannel *Chan, BOOL Enable)
      +    struct {
      +        HsChannel *Chan;
      +        BOOL Enable;
      +    } HS_EnableSniffMode_param;
      +#endif
      +
           struct {
               uint32_t func_ptr;
               uint32_t param0;
      @@ -247,17 +284,17 @@ int app_bt_A2DP_CloseStream(a2dp_stream_t *Stream);
       
       int app_bt_A2DP_SetMasterRole(a2dp_stream_t *Stream, BOOL Flag);
       
      -int app_bt_HF_CreateServiceLink(btif_hf_channel_t* Chan, bt_bdaddr_t *Addr);
      +int app_bt_HF_CreateServiceLink(hf_chan_handle_t Chan, bt_bdaddr_t *Addr);
       
      -int app_bt_HF_DisconnectServiceLink(btif_hf_channel_t* Chan);
      +int app_bt_HF_DisconnectServiceLink(hf_chan_handle_t Chan);
       
      -int app_bt_HF_CreateAudioLink(btif_hf_channel_t* Chan);
      +int app_bt_HF_CreateAudioLink(hf_chan_handle_t Chan);
       
      -int app_bt_HF_DisconnectAudioLink(btif_hf_channel_t* Chan);
      +int app_bt_HF_DisconnectAudioLink(hf_chan_handle_t Chan);
       
      -int app_bt_HF_EnableSniffMode(btif_hf_channel_t* Chan, BOOL Enable);
      +int app_bt_HF_EnableSniffMode(hf_chan_handle_t Chan, BOOL Enable);
       
      -int app_bt_HF_SetMasterRole(btif_hf_channel_t* Chan, BOOL Flag);
      +int app_bt_HF_SetMasterRole(hf_chan_handle_t Chan, BOOL Flag);
       
       void app_bt_accessible_manager_process(const btif_event_t *Event);
       void app_bt_role_manager_process(const btif_event_t* Event);
      @@ -270,6 +307,18 @@ int app_bt_ME_ControlSleepMode(bool isEnabled);
       int app_bt_dip_QuryService(btif_dip_client_t *client, btif_remote_device_t* rem);
       #endif
       
      +#if defined (__HSP_ENABLE__)
      +int app_bt_HS_CreateServiceLink(HsChannel *Chan, bt_bdaddr_t *Addr);
      +
      +int app_bt_HS_CreateAudioLink(HsChannel *Chan);
      +
      +int app_bt_HS_DisconnectAudioLink(HsChannel *Chan);
      +
      +int app_bt_HS_DisconnectServiceLink(HsChannel *Chan);
      +
      +int app_bt_HS_EnableSniffMode(HsChannel *Chan, BOOL Enable);
      +
      +#endif
       bool app_is_access_mode_set_pending(void);
       void app_set_pending_access_mode(void);
       void app_bt_set_linkpolicy(btif_remote_device_t *remDev, btif_link_policy_t policy);
  • services/bt_app/app_bt.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_bt.h bes/services/bt_app/app_bt.h
      index cb1c43a63a6..350da2bc09f 100644
      --- a/services/bt_app/app_bt.h
      +++ b/services/bt_app/app_bt.h
      @@ -37,8 +37,14 @@ enum APP_BT_GOLBAL_HANDLE_HOOK_USER_T {
       typedef void (*APP_BT_REQ_CONNECT_PROFILE_FN_T)(void *, void *);
       typedef bt_status_t  (*APP_BT_REQ_HF_OP_FN_T)(void *);
       typedef void (*APP_BT_GOLBAL_HANDLE_HOOK_HANDLER)(const btif_event_t*Event);
      +typedef void (*APP_APPTHREAD_REQ_CUSTOMER_CALL_FN_T)(void *, void *);
       
      -#define app_bt_accessmode_set_req(accmode) do{app_bt_send_request(APP_BT_REQ_ACCESS_MODE_SET, accmode, 0, 0,0);}while(0)
      +#define app_bt_accessmode_set_req(accmode) do{app_bt_send_request(APP_BT_REQ_ACCESS_MODE_SET, accmode, 0, 0);}while(0)
      +typedef enum
      +{
      +    APP_BT_IDLE_STATE = 0,
      +    APP_BT_IN_CONNECTING_PROFILES_STATE // acl link is created and in the process of connecting profiles
      +} APP_BT_CONNECTING_STATE_E;
       
       typedef enum
       {
      @@ -80,7 +86,7 @@ void app_bt_opening_reconnect(void);
       
       void app_bt_accessmode_set(  btif_accessible_mode_t mode);
       
      -int app_bt_send_request(uint32_t message_id, uint32_t param0, uint32_t param1, uint32_t param2,uint32_t ptr);
      +void app_bt_send_request(uint32_t message_id, uint32_t param0, uint32_t param1, uint32_t ptr);
       
       void app_bt_init(void);
       
      @@ -88,6 +94,7 @@ int app_bt_state_checker(void);
       
       void *app_bt_profile_active_store_ptr_get(uint8_t *bdAddr);
       
      +void app_bt_profile_connect_manager_open(void);
       
       void app_bt_profile_connect_manager_opening_reconnect(void);
       
      @@ -97,19 +104,27 @@ int app_bt_global_handle_hook_set(enum APP_BT_GOLBAL_HANDLE_HOOK_USER_T user, AP
       
       APP_BT_GOLBAL_HANDLE_HOOK_HANDLER app_bt_global_handle_hook_get(enum APP_BT_GOLBAL_HANDLE_HOOK_USER_T user);
       
      -bool app_is_hfp_service_connected(uint8_t device_id);
      +bool app_is_hfp_service_connected(void);
       #if defined(IBRT)
       void app_bt_ibrt_reconnect_mobile_profile_flag_set(void);
       void app_bt_ibrt_reconnect_mobile_profile_flag_clear(void);
       bool app_bt_ibrt_reconnect_mobile_profile_flag_get(void);
       #endif
      +#if defined(__BT_SELECT_PROF_DEVICE_ID__)
      +int8_t app_bt_a2dp_is_same_stream(a2dp_stream_t *src_Stream, a2dp_stream_t *dst_Stream);
       
      +void app_bt_a2dp_find_same_unused_stream(a2dp_stream_t *in_Stream, a2dp_stream_t **out_Stream, uint32_t device_id);
       
      +int8_t app_bt_a2dp_is_stream_on_device_id(a2dp_stream_t *in_Stream, uint32_t device_id);
       
      +int8_t app_bt_hfp_is_chan_on_device_id(hf_chan_handle_t chan, uint32_t device_id);
       
      +int8_t app_bt_is_any_profile_connected(uint32_t device_id);
       
      -bool app_bt_is_a2dp_connected(uint8_t device_id);
      +int8_t app_bt_is_a2dp_connected(uint32_t device_id);
       
      +btif_remote_device_t *app_bt_get_connected_profile_remdev(uint32_t device_id);
      +#endif
       
       void app_bt_stay_active(uint8_t deviceId);
       
      @@ -127,10 +142,11 @@ void app_bt_stay_active_rem_dev(btif_remote_device_t* pRemDev);
       
       void app_check_pending_stop_sniff_op(void);
       
      +void app_bt_reset_reconnect_timer(bt_bdaddr_t *pBdAddr);
       
      -uint8_t app_bt_count_connected_device(void);
      +uint8_t app_bt_get_num_of_connected_dev(void);
       
      -bool app_bt_is_hfp_connected(uint8_t device_id);
      +bool btapp_hfp_is_dev_call_active(uint8_t devId);
       
       void app_bt_pause_media_player_again(uint8_t deviceId);
       
      @@ -140,9 +156,13 @@ bool app_bt_pause_music_player(uint8_t deviceId);
       
       void app_bt_resume_music_player(uint8_t deviceId);
       
      +bool app_bt_is_to_resume_music_player(uint8_t deviceId);
       
      +void app_bt_reset_music_player_resume_state(void);
       
      +bool app_bt_is_device_connected(uint8_t deviceId);
       
      +void app_bt_set_music_player_resume_device(uint8_t deviceId);
       
       bool app_bt_is_a2dp_streaming(uint8_t deviceId);
       
      @@ -152,13 +172,17 @@ bool app_bt_get_device_bdaddr(uint8_t deviceId, uint8_t* btAddr);
       
       void fast_pair_enter_pairing_mode_handler(void);
       
      +void app_hfp_start_voice_media(uint8_t devId);
       
      +void app_hfp_resume_pending_voice_media(void);
       
      +bool app_hfp_is_starting_media_pending(void);
       
       bool app_bt_is_in_reconnecting(void);
       
       bool btapp_hfp_is_dev_sco_connected(uint8_t devId);
       
      +uint8_t a2dp_get_latest_paused_device(void);
       
       bool app_bt_is_in_connecting_profiles_state(void);
       
      @@ -166,13 +190,18 @@ void app_bt_clear_connecting_profiles_state(uint8_t devId);
       
       void app_bt_set_connecting_profiles_state(uint8_t devId);
       
      +void app_a2dp_hold_mute();
       
      +void app_a2dp_unhold_mute();
       
      +void app_bt_set_mobile_a2dp_stream(uint32_t deviceId,a2dp_stream_t *stream);
       
       #if defined(__INTERCONNECTION__)
       btif_accessible_mode_t app_bt_get_current_access_mode(void);
       
      +bool app_bt_is_connected();
       #endif
      +bool app_device_bt_is_connected();
       bool app_bt_is_hfp_audio_on(void);
       
       btif_remote_device_t* app_bt_get_connected_mobile_device_ptr(void);
      @@ -186,18 +215,24 @@ void app_set_disconnecting_all_bt_connections(bool isEnable);
       void app_bt_start_search(void);
       
       #if defined(IBRT)
      +#if defined(ENHANCED_STACK)
       uint32_t app_bt_save_a2dp_app_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      -uint32_t app_bt_restore_a2dp_app_ctx(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len);
      +uint32_t app_bt_restore_a2dp_app_ctx(uint8_t *buf, uint32_t buf_len);
       uint32_t app_bt_save_avrcp_app_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      -uint32_t app_bt_restore_avrcp_app_ctx(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len);
      +uint32_t app_bt_restore_avrcp_app_ctx(uint8_t *buf, uint32_t buf_len);
       uint32_t app_bt_save_hfp_app_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      -uint32_t app_bt_restore_hfp_app_ctx(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len);
      -uint32_t app_bt_save_spp_app_ctx(uint64_t app_id,btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      -uint32_t app_bt_restore_spp_app_ctx(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len, uint64_t app_id);
      -#ifdef BT_MAP_SUPPORT
      +uint32_t app_bt_restore_hfp_app_ctx(uint8_t *buf, uint32_t buf_len);
      +uint32_t app_bt_save_spp_app_ctx(uint32_t app_id,btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      +uint32_t app_bt_restore_spp_app_ctx(uint8_t *buf, uint32_t buf_len, uint32_t app_id);
      +#ifdef __BTMAP_ENABLE__
       uint32_t app_bt_save_map_app_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      -uint32_t app_bt_restore_map_app_ctx(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len);
      +uint32_t app_bt_restore_map_app_ctx(uint8_t *buf, uint32_t buf_len);
      +#endif
      +#ifdef BTIF_HID_DEVICE
      +uint32_t app_bt_save_hid_app_ctx(uint8_t *buf);
      +uint32_t app_bt_restore_hid_app_ctx(uint8_t *buf);
       #endif
      +#endif /* ENHANCED_STACK */
       #endif
       
       void app_stop_fast_connectable_ble_adv_timer(void);
      @@ -206,6 +241,11 @@ int8_t app_bt_get_rssi(void);
       #ifdef  TILE_DATAPATH
       int8_t app_tile_get_ble_rssi(void);
       #endif
      +void app_bt_prepare_for_ota(void);
      +void hfp_reconnecting_timer_stop_callback(const btif_event_t *event);
      +int app_bt_start_custom_function_in_app_thread(
      +                                    uint32_t param0, uint32_t param1, uint32_t funcPtr);
      +uint8_t app_bt_get_a2dp_state();
       
       #ifdef __cplusplus
       }
  • services/bt_app/app_bt_hid.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_bt_hid.h bes/services/bt_app/app_bt_hid.h
      index 5d65692227c..7e89702c48f 100644
      --- a/services/bt_app/app_bt_hid.h
      +++ b/services/bt_app/app_bt_hid.h
      @@ -15,7 +15,7 @@
       #ifndef __APP_BT_HID_H__
       #define __APP_BT_HID_H__
       
      -#ifdef BT_HID_DEVICE
      +#ifdef BTIF_HID_DEVICE
       
       #include "bluetooth.h"
       
      @@ -65,12 +65,12 @@ void app_bt_hid_enter_shutter_mode(void);
       
       void app_bt_hid_exit_shutter_mode(void);
       
      -void app_bt_hid_send_capture(void);
      +void app_bt_hid_send_capture(hid_channel_t chnl);
       
       #ifdef __cplusplus
       }
       #endif
       
      -#endif /* BT_HID_DEVICE */
      +#endif /* BTIF_HID_DEVICE */
       
       #endif /* __APP_BT_HID_H__ */
  • services/bt_app/app_bt_media_manager.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_bt_media_manager.h bes/services/bt_app/app_bt_media_manager.h
      index 9999ce45acb..752025dd677 100644
      --- a/services/bt_app/app_bt_media_manager.h
      +++ b/services/bt_app/app_bt_media_manager.h
      @@ -35,11 +35,16 @@ extern "C" {
       #define  BT_STREAM_RBCODEC      0x10    //from rockbox decoder
       #endif
       
      +// direction is in
      +#ifdef VOICE_DATAPATH
      +#define BT_STREAM_CAPTURE       0x100
      +#endif
       
       #ifdef __AI_VOICE__
       #define BT_STREAM_AI_VOICE      0x200
       #endif
       
      +#define BT_STREAM_THIRDPARTY_VOICE 0x400
       
       #define BT_STREAM_TYPE_MASK   (BT_STREAM_SBC | BT_STREAM_MEDIA | BT_STREAM_VOICE)
       
      @@ -47,6 +52,7 @@ extern "C" {
       enum APP_BT_MEDIA_MANAGER_ID_T {
           APP_BT_STREAM_MANAGER_START = 0,
           APP_BT_STREAM_MANAGER_STOP,
      +    APP_BT_STREAM_MANAGER_SWITCHTO_SCO,
           APP_BT_STREAM_MANAGER_STOP_MEDIA,
           APP_BT_STREAM_MANAGER_UPDATE_MEDIA,
           APP_BT_STREAM_MANAGER_SWAP_SCO,
      @@ -70,7 +76,7 @@ enum APP_AUDIO_MANAGER_VOLUME_CTRL_T {
           APP_AUDIO_MANAGER_VOLUME_CTRL_NUM,
       };
       
      -typedef void (*APP_AUDIO_MANAGER_CALLBACK_T)(uint8_t device_id, uint32_t status, uint32_t param);
      +typedef void (*APP_AUDIO_MANAGER_CALLBACK_T)(uint32_t status, uint32_t param);
       
       #define APP_AUDIO_MANAGER_SET_MESSAGE(appevt, id, stream_type) (appevt = (((uint32_t)id&0xffff)<<16)|(stream_type&0xffff))
       #define APP_AUDIO_MANAGER_SET_MESSAGE0(appmsg, device_id,aud_id) (appmsg = (((uint32_t)device_id&0xffff)<<16)|(aud_id&0xffff))
      @@ -87,12 +93,14 @@ int app_audio_manager_sendrequest_need_callback(
       void app_audio_manager_open(void);
       
       void  bt_media_start(uint16_t stream_type,enum BT_DEVICE_ID_T device_id,uint16_t media_id);
      -void bt_media_stop(uint16_t stream_type,enum BT_DEVICE_ID_T device_id,uint16_t media_id);
      +void bt_media_stop(uint16_t stream_type,enum BT_DEVICE_ID_T device_id);
      +void bt_media_switch_to_voice(uint16_t stream_type,enum BT_DEVICE_ID_T device_id);
      +uint16_t bt_media_get_media_active(enum BT_DEVICE_ID_T device_id);
       uint8_t bt_media_is_media_active_by_type(uint16_t media_type);
       void bt_media_volume_ptr_update_by_mediatype(uint16_t stream_type);
       int app_audio_manager_set_active_sco_num(enum BT_DEVICE_ID_T id);
       int app_audio_manager_get_active_sco_num(void);
      -btif_hf_channel_t* app_audio_manager_get_active_sco_chnl(void);
      +hf_chan_handle_t* app_audio_manager_get_active_sco_chnl(void);
       int app_audio_manager_swap_sco(enum BT_DEVICE_ID_T id);
       uint8_t bt_media_is_media_active_by_device(uint16_t media_type,enum BT_DEVICE_ID_T device_id);
       uint16_t bt_media_get_current_media(void);
      @@ -103,7 +111,7 @@ bool app_audio_manager_capture_is_active(void);
       bool app_audio_manager_media_is_active(void);
       bool app_audio_manager_hfp_is_active(enum BT_DEVICE_ID_T id);
       int app_audio_manager_set_scocodecid(enum BT_DEVICE_ID_T dev_id, uint16_t codec_id);
      -hfp_sco_codec_t app_audio_manager_get_scocodecid(void);
      +int app_audio_manager_get_scocodecid(void);
       bool bt_media_is_media_idle(void);
       uint8_t bt_media_device_enumerate_media_type_by_prior();
       void bt_media_clean_up(void);
      @@ -120,7 +128,7 @@ void app_rbcodec_toggle_play_stop(void);
       
       void app_stop_a2dp_media_stream(uint8_t devId);
       void app_stop_sco_media_stream(uint8_t devId);
      -int app_audio_manager_ctrl_volume(enum APP_AUDIO_MANAGER_VOLUME_CTRL_T volume_ctrl, uint16_t volume_level);
      +int app_audio_manager_ctrl_volume(APP_AUDIO_MANAGER_VOLUME_CTRL_T volume_ctrl, uint16_t volume_level);
       int app_audio_manager_tune_samplerate_ratio(enum AUD_STREAM_T stream, float ratio);
       bool bt_media_cur_is_bt_stream_media(void);
       bool bt_media_is_sbc_media_active(void);
  • services/bt_app/app_bt_stream.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_bt_stream.h bes/services/bt_app/app_bt_stream.h
      index 90b6ec9bb64..47a1c410f7c 100644
      --- a/services/bt_app/app_bt_stream.h
      +++ b/services/bt_app/app_bt_stream.h
      @@ -66,18 +66,24 @@ extern "C" {
       #ifdef AUDIO_LINEIN
       #define APP_PLAY_LINEIN_AUDIO               (1 << 9)
       #endif
      -#ifdef BT_SOURCE
      +#if defined(APP_LINEIN_A2DP_SOURCE)||defined(__APP_A2DP_SOURCE__)||(APP_I2S_A2DP_SOURCE)
       #define APP_A2DP_SOURCE_LINEIN_AUDIO        (1 << 10)
       #define APP_A2DP_SOURCE_I2S_AUDIO           (1 << 11)
       #endif
       
       
       // input streams
      +#ifdef VOICE_DATAPATH
      +#define APP_BT_STREAM_VOICEPATH             (1 << APP_BT_STREAM_BORDER_BIT_OFFSET)
      +#endif
       
       #ifdef __AI_VOICE__
      -#define APP_BT_STREAM_AI_VOICE             (1 << APP_BT_STREAM_BORDER_BIT_OFFSET)
      +#define APP_BT_STREAM_AI_VOICE             (1 << (APP_BT_STREAM_BORDER_BIT_OFFSET+1))
       #endif
       
      +#ifdef __THIRDPARTY
      +#define APP_BT_STREAM_THIRDPARTY_VOICE        (1 << (APP_BT_STREAM_BORDER_BIT_OFFSET+2))
      +#endif
       
       #define APP_BT_STREAM_INVALID               0
       
      @@ -129,9 +135,9 @@ bool app_bt_stream_isrun(uint16_t player);
       
       void app_bt_set_volume(uint16_t type,uint8_t level);
       
      -void app_bt_stream_bt_volumeup(void);
      +void app_bt_stream_volumeup(void);
       
      -void app_bt_stream_bt_volumedown(void);
      +void app_bt_stream_volumedown(void);
       
       void app_bt_stream_volume_ptr_update(uint8_t *bdAddr);
       
      @@ -196,6 +202,9 @@ struct APP_RESAMPLE_T *app_playback_resample_any_open_with_pre_allocated_buffer(
               APP_RESAMPLE_ITER_CALLBACK cb, uint32_t iter_len,
               float ratio_step, uint8_t* ptrBuf, uint32_t bufSize);
       
      +struct APP_RESAMPLE_T *app_capture_resample_14k7_to_16k(enum AUD_CHANNEL_NUM_T chans,
      +        APP_RESAMPLE_ITER_CALLBACK cb, uint32_t iter_len,
      +        float ratio_step, uint8_t* ptrBuf, uint32_t bufSize);
       
       int app_playback_resample_close(struct APP_RESAMPLE_T *resamp);
       int app_playback_resample_run(struct APP_RESAMPLE_T *resamp, uint8_t *buf, uint32_t len);
      @@ -218,6 +227,9 @@ void app_bt_stream_volumeset_handler(int8_t vol);
       void store_encode_frame2buff();
       #endif
       
      +#ifdef BONE_SENSOR_TDM
      +void bt_sco_get_tdm_buffer(uint8_t **buf, uint32_t *len);
      +#endif
       int app_bt_stream_local_volume_get(void);
       
       bool bt_is_playback_triggered(void);
  • services/bt_app/app_bt_trace.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_bt_trace.h bes/services/bt_app/app_bt_trace.h
      index a184616ab6a..478b431c432 100644
      --- a/services/bt_app/app_bt_trace.h
      +++ b/services/bt_app/app_bt_trace.h
      @@ -19,50 +19,58 @@
       
       #ifdef ENABLE_COMPRESS_LOG
       #define TRACE_AUD_MGR_D(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_AUD_MGR_I(str, ...) TR_INFO(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][MGR]"str, ##__VA_ARGS__)
      -#define TRACE_AUD_MGR_W(str, ...) TR_WARN(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][MGR][WARN]"str, ##__VA_ARGS__)
      -#define TRACE_AUD_MGR_E(str, ...) TR_ERROR(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][MGR][ERR]"str, ##__VA_ARGS__)
      +//LOG_DEBUG(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][MGR][DBG]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_MGR_I(str, ...) LOG_INFO(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][MGR]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_MGR_W(str, ...) LOG_WARN(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][MGR][WARN]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_MGR_E(str, ...) LOG_ERROR(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][MGR][ERR]"str, ##__VA_ARGS__)
       #else
       #define TRACE_AUD_MGR_D(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_AUD_MGR_I(str, ...) TR_INFO(TR_MOD(AUDFLG),     str, ##__VA_ARGS__)
      -#define TRACE_AUD_MGR_W(str, ...) TR_WARN(TR_MOD(AUDFLG),     str, ##__VA_ARGS__)
      -#define TRACE_AUD_MGR_E(str, ...) TR_ERROR(TR_MOD(AUDFLG),    str, ##__VA_ARGS__)
      +//LOG_DEBUG(LOG_MOD(AUDFLG),    "[AUD][MGR][DBG]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_MGR_I(str, ...) LOG_INFO(LOG_MOD(AUDFLG),     "[AUD][MGR]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_MGR_W(str, ...) LOG_WARN(LOG_MOD(AUDFLG),     "[AUD][MGR][WARN]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_MGR_E(str, ...) LOG_ERROR(LOG_MOD(AUDFLG),    "[AUD][MGR][ERR]"str, ##__VA_ARGS__)
       #endif
       
       #ifdef ENABLE_COMPRESS_LOG
       #define TRACE_AUD_HDL_D(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_AUD_HDL_I(str, ...) TR_INFO(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][HDL]"str, ##__VA_ARGS__)
      -#define TRACE_AUD_HDL_W(str, ...) TR_WARN(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][HDL][WARN]"str, ##__VA_ARGS__)
      -#define TRACE_AUD_HDL_E(str, ...) TR_ERROR(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][HDL][ERR]"str, ##__VA_ARGS__)
      +//LOG_DEBUG(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][HDL][DBG]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_HDL_I(str, ...) LOG_INFO(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][HDL]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_HDL_W(str, ...) LOG_WARN(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][HDL][WARN]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_HDL_E(str, ...) LOG_ERROR(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][HDL][ERR]"str, ##__VA_ARGS__)
       #else
       #define TRACE_AUD_HDL_D(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_AUD_HDL_I(str, ...) TR_INFO(TR_MOD(AUDFLG),     str, ##__VA_ARGS__)
      -#define TRACE_AUD_HDL_W(str, ...) TR_WARN(TR_MOD(AUDFLG),     str, ##__VA_ARGS__)
      -#define TRACE_AUD_HDL_E(str, ...) TR_ERROR(TR_MOD(AUDFLG),    str, ##__VA_ARGS__)
      +//LOG_DEBUG(LOG_MOD(AUDFLG),    "[AUD][HDL][DBG]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_HDL_I(str, ...) LOG_INFO(LOG_MOD(AUDFLG),     "[AUD][HDL]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_HDL_W(str, ...) LOG_WARN(LOG_MOD(AUDFLG),     "[AUD][HDL][WARN]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_HDL_E(str, ...) LOG_ERROR(LOG_MOD(AUDFLG),    "[AUD][HDL][ERR]"str, ##__VA_ARGS__)
       #endif
       
       #ifdef ENABLE_COMPRESS_LOG
       #define TRACE_AUD_STREAM_D(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_AUD_STREAM_I(str, ...) TR_INFO(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     str, ##__VA_ARGS__)
      -#define TRACE_AUD_STREAM_W(str, ...) TR_WARN(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     str, ##__VA_ARGS__)
      -#define TRACE_AUD_STREAM_E(str, ...) TR_ERROR(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    str, ##__VA_ARGS__)
      +//LOG_DEBUG(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][STRM][DBG]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_STREAM_I(str, ...) LOG_INFO(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][STRM]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_STREAM_W(str, ...) LOG_WARN(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][STRM][WARN]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_STREAM_E(str, ...) LOG_ERROR(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][STRM][ERR]"str, ##__VA_ARGS__)
       #else
       #define TRACE_AUD_STREAM_D(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_AUD_STREAM_I(str, ...) TR_INFO(TR_MOD(AUDFLG),     str, ##__VA_ARGS__)
      -#define TRACE_AUD_STREAM_W(str, ...) TR_WARN(TR_MOD(AUDFLG),     str, ##__VA_ARGS__)
      -#define TRACE_AUD_STREAM_E(str, ...) TR_ERROR(TR_MOD(AUDFLG),    str, ##__VA_ARGS__)
      +//LOG_DEBUG(LOG_MOD(AUDFLG),    "[AUD][STRM][DBG]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_STREAM_I(str, ...) LOG_INFO(LOG_MOD(AUDFLG),     "[AUD][STRM]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_STREAM_W(str, ...) LOG_WARN(LOG_MOD(AUDFLG),     "[AUD][STRM][WARN]"str, ##__VA_ARGS__)
      +#define TRACE_AUD_STREAM_E(str, ...) LOG_ERROR(LOG_MOD(AUDFLG),    "[AUD][STRM][ERR]"str, ##__VA_ARGS__)
       #endif
       
       #ifdef ENABLE_COMPRESS_LOG
       #define TRACE_MEDIA_PLAYER_D(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_MEDIA_PLAYESTREAM_I(str, ...) TR_INFO(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     str, ##__VA_ARGS__)
      -#define TRACE_MEDIA_PLAYESTREAM_W(str, ...) TR_WARN(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     str, ##__VA_ARGS__)
      -#define TRACE_MEDIA_PLAYESTREAM_E(str, ...) TR_ERROR(TR_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    str, ##__VA_ARGS__)
      +//LOG_DEBUG(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][STRM][DBG]"str, ##__VA_ARGS__)
      +#define TRACE_MEDIA_PLAYESTREAM_I(str, ...) LOG_INFO(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][STRM]"str, ##__VA_ARGS__)
      +#define TRACE_MEDIA_PLAYESTREAM_W(str, ...) LOG_WARN(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),     "[AUD][STRM][WARN]"str, ##__VA_ARGS__)
      +#define TRACE_MEDIA_PLAYESTREAM_E(str, ...) LOG_ERROR(LOG_ATTR_ARG_NUM(COUNT_ARG_NUM(unused, ##__VA_ARGS__)),    "[AUD][STRM][ERR]"str, ##__VA_ARGS__)
       #else
       #define TRACE_MEDIA_PLAYESTREAM_D(str, ...) hal_trace_dummy(str, ##__VA_ARGS__)
      -#define TRACE_MEDIA_PLAYESTREAM_I(str, ...) TR_INFO(TR_MOD(AUDFLG),     str, ##__VA_ARGS__)
      -#define TRACE_MEDIA_PLAYESTREAM_W(str, ...) TR_WARN(TR_MOD(AUDFLG),     str, ##__VA_ARGS__)
      -#define TRACE_MEDIA_PLAYESTREAM_E(str, ...) TR_ERROR(TR_MOD(AUDFLG),    str, ##__VA_ARGS__)
      +//LOG_DEBUG(LOG_MOD(AUDFLG),    "[AUD][STRM][DBG]"str, ##__VA_ARGS__)
      +#define TRACE_MEDIA_PLAYESTREAM_I(str, ...) LOG_INFO(LOG_MOD(AUDFLG),     "[AUD][STRM]"str, ##__VA_ARGS__)
      +#define TRACE_MEDIA_PLAYESTREAM_W(str, ...) LOG_WARN(LOG_MOD(AUDFLG),     "[AUD][STRM][WARN]"str, ##__VA_ARGS__)
      +#define TRACE_MEDIA_PLAYESTREAM_E(str, ...) LOG_ERROR(LOG_MOD(AUDFLG),    "[AUD][STRM][ERR]"str, ##__VA_ARGS__)
       #endif
       
       #endif
  • services/bt_app/app_hfp.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_hfp.h bes/services/bt_app/app_hfp.h
      index 5852d5a6aab..010cc4156a3 100644
      --- a/services/bt_app/app_hfp.h
      +++ b/services/bt_app/app_hfp.h
      @@ -65,10 +65,12 @@ uint8_t btapp_hfp_need_mute(void);
       #ifdef __INTERCONNECTION__
       uint8_t ask_is_selfdefined_battery_report_AT_command_support(void);
       
      -uint8_t send_selfdefined_battery_report_AT_command(uint8_t device_id);
      +uint8_t send_selfdefined_battery_report_AT_command(void);
       #endif
       
      -bool app_hfp_curr_audio_up(btif_hf_channel_t* hfp_chnl);
      +uint8_t  app_hfp_get_chnl_via_remDev(hf_chan_handle_t * p_hfp_chnl);
      +bool app_hfp_curr_audio_up(hf_chan_handle_t hfp_chnl);
      +int hfp_volume_set(enum BT_DEVICE_ID_T id, int vol);
       
       
       #ifdef __cplusplus
  • services/bt_app/app_media_player.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_media_player.h bes/services/bt_app/app_media_player.h
      index 7f6eee42af1..e22fd6283a5 100644
      --- a/services/bt_app/app_media_player.h
      +++ b/services/bt_app/app_media_player.h
      @@ -18,7 +18,7 @@
       #include "resources.h"
       #include "app_bt_stream.h"
       
      -#define MEDIA_DEFAULT_LANGUAGE (LANGUAGE_ID_EN - 1)
      +#define MEDIA_DEFAULT_LANGUAGE (0)
       
       typedef enum
       {
      @@ -41,8 +41,8 @@ typedef enum
       #define PROMPT_CHNLSEl_FROM_ID_VALUE(promptIdVal) ((promptIdVal)&PROMOT_ID_BIT_MASK_CHNLSEl_ALL)
       #define PROMPT_PRAM_FROM_ID_VALUE(promptIdVal)    ((promptIdVal)&PROMOT_ID_BIT_MASK)
       #define IS_PROMPT_CHNLSEl_ALL(promptId)           (((promptId)&PROMOT_ID_BIT_MASK_CHNLSEl_ALL) == PROMOT_ID_BIT_MASK_CHNLSEl_ALL  ? true : false)
      -#define IS_PROMPT_CHNLSEl_LCHNL(promptId)         (((promptId)&PROMOT_ID_BIT_MASK_CHNLSEl_ALL) == PROMOT_ID_BIT_MASK_CHNLSEl_LCHNL  ? true : false)
      -#define IS_PROMPT_CHNLSEl_RCHNL(promptId)         (((promptId)&PROMOT_ID_BIT_MASK_CHNLSEl_ALL) == PROMOT_ID_BIT_MASK_CHNLSEl_RCHNL  ? true : false)
      +#define IS_PROMPT_CHNLSEl_LCHNL(promptId)         (((promptId)&PROMOT_ID_BIT_MASK_CHNLSEl_ALL) == PROMOT_ID_BIT_MASK_CHNLSEl_RCHNL  ? true : false)
      +#define IS_PROMPT_CHNLSEl_RCHNL(promptId)         (((promptId)&PROMOT_ID_BIT_MASK_CHNLSEl_ALL) == PROMOT_ID_BIT_MASK_CHNLSEl_LCHNL  ? true : false)
       
       typedef struct
       {
      @@ -87,10 +87,12 @@ extern uint32_t __mixprompt_property_table_end[];
       extern "C" {
       #endif
       
      +//uint32_t media_playAudioSideSelect(AUD_ID_ENUM id,uint8_t device_id, uint8_t side_select);
       // Prompt will be played on the both sides if they're connected.
       // If there are music/phone call on-going, the prompt will be mixed.
      -void media_PlayAudio(AUD_ID_ENUM id,uint8_t device_id);
      +uint32_t media_PlayAudio(AUD_ID_ENUM id,uint8_t device_id);
       
      +uint32_t media_playAudioSideSelect(AUD_ID_ENUM id,uint8_t device_id, uint16_t side_select);
       
       // Prompt will be played locally no matter whether earbuds are connected or not
       // If there are music/phone call on-going, the prompt will be mixed.
  • services/bt_app/app_rfcomm_mgr.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_rfcomm_mgr.h bes/services/bt_app/app_rfcomm_mgr.h
      index 96174677b16..a929dc6ba01 100644
      --- a/services/bt_app/app_rfcomm_mgr.h
      +++ b/services/bt_app/app_rfcomm_mgr.h
      @@ -41,16 +41,16 @@ typedef enum
           RFCOMM_UNKNOWN_EVENT
       } RFCOMM_EVENT_E;
       
      -typedef bool (*rfcomm_callback_func)(uint8_t device_id, RFCOMM_EVENT_E event, uint8_t serviceIndex,
      +typedef bool (*rfcomm_callback_func)(RFCOMM_EVENT_E event, uint8_t serviceIndex,
           uint16_t connHandle, uint8_t* pBtAddr, uint8_t* pSentDataBuf, uint16_t sentDataLen);
       
      -typedef int (*spp_handle_data_event_func_t)(uint8_t device_id, void *pDev, uint8_t process, uint8_t *pData, uint16_t dataLen);
      +typedef int (*spp_handle_data_event_func_t)(void *pDev, uint8_t process, uint8_t *pData, uint16_t dataLen);
       
       typedef struct
       {
           uint8_t     rfcomm_ch;
           uint8_t     tx_pkt_cnt;
      -    uint64_t    app_id;
      +    uint32_t    app_id;
           const uint8_t*          rfcomm_128bit_uuid;
           rfcomm_callback_func    callback;
           spp_handle_data_event_func_t spp_handle_data_event_func;
  • services/bt_app/app_spp.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/app_spp.h bes/services/bt_app/app_spp.h
      index dc5ed132a17..0f72b600437 100644
      --- a/services/bt_app/app_spp.h
      +++ b/services/bt_app/app_spp.h
      @@ -31,8 +31,21 @@ extern "C" {
       #define SPP_RECV_BUFFER_SIZE   L2CAP_MTU*4
       #define SPP_MAX_DATA_PACKET_SIZE    L2CAP_MTU
       
      +#ifdef ENHANCED_STACK
      +#define    BTIF_APP_SPP_SERVER_GSOUND_CTL_ID    BTIF_APP_SPP_SERVER_ID_1
      +#define    BTIF_APP_SPP_SERVER_GSOUND_AUD_ID    BTIF_APP_SPP_SERVER_ID_2
      +#define    BTIF_APP_SPP_SERVER_TOTA_ID          BTIF_APP_SPP_SERVER_ID_3
      +#define    BTIF_APP_SPP_SERVER_BES_OTA_ID       BTIF_APP_SPP_SERVER_ID_4
      +#define    BTIF_APP_SPP_SERVER_AI_VOICE_ID      BTIF_APP_SPP_SERVER_ID_5
      +#define    BTIF_APP_SPP_SERVER_GREEN_ID         BTIF_APP_SPP_SERVER_ID_6
      +#define    BTIF_APP_SPP_SERVER_RED_ID           BTIF_APP_SPP_SERVER_ID_7
      +#define    BTIF_APP_SPP_SERVER_FP_RFCOMM_ID     BTIF_APP_SPP_SERVER_ID_8
      +#define    BTIF_APP_SPP_SERVER_TOTA_GENERAL_ID  BTIF_APP_SPP_SERVER_ID_9
       
       
      +#define    BTIF_APP_SPP_CLIENT_AI_VOICE_ID      BTIF_APP_SPP_CLIENT_ID_1
      +#define    BTIF_APP_SPP_CLIENT_CCMP_ID          BTIF_APP_SPP_CLIENT_ID_2
      +#define    BTIF_APP_SPP_CLIENT_RED_ID           BTIF_APP_SPP_CLIENT_ID_3
       
       /*---------------------------------------------------------------------------
        * rfcomm channel number
      @@ -47,10 +60,16 @@ enum RFCOMM_CHANNEL_NUM {
           RFCOMM_CHANNEL_GREEN        = RFCOMM_CHANNEL_6,
           RFCOMM_CHANNEL_RED          = RFCOMM_CHANNEL_7,
           RFCOMM_CHANNEL_FP           = RFCOMM_CHANNEL_8,
      -    RFCOMM_CHANNEL_AMA          = RFCOMM_CHANNEL_9,
      +    RFCOMM_CHANNEL_TOTA_GENERAL = RFCOMM_CHANNEL_9,
       };
      +#endif
       
       struct spp_device *app_create_spp_device(void);
      +#if 0
      +void app_spp_register_connect_callback(struct spp_device *osDev_t, spp_event_callback_t callback);
      +void app_spp_register_disconnect_callback(struct spp_device *osDev_t, spp_event_callback_t callback);
      +void app_spp_register_tx_done(struct spp_device *osDev_t, spp_event_callback_t callback);
      +#endif
       bt_status_t app_spp_send_data(struct spp_device *osDev_t, uint8_t* ptrData, uint16_t *length);
       void app_spp_open(struct spp_device *osDev_t, btif_remote_device_t  *btDevice, btif_sdp_record_param_t *param, osMutexId mid, uint8_t service_id, spp_callback_t callback);
       
  • services/bt_app/audio_prompt_sbc.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/audio_prompt_sbc.h bes/services/bt_app/audio_prompt_sbc.h
      index 8bde2e9eac0..b929692cef5 100644
      --- a/services/bt_app/audio_prompt_sbc.h
      +++ b/services/bt_app/audio_prompt_sbc.h
      @@ -65,7 +65,7 @@ typedef struct
       #define AUDIO_PROMPT_SBC_CHANNEL_MODE           (BTIF_SBC_CHNL_MODE_MONO)
       
       #define AUDIO_PROMPT_SOURCE_PCM_BUFFER_SIZE     (512)
      -#define AUDIO_PROMPT_TARGET_PCM_BUFFER_SIZE     (AUDIO_PROMPT_SOURCE_PCM_BUFFER_SIZE*4)
      +#define AUDIO_PROMPT_TARGET_PCM_BUFFER_SIZE     (AUDIO_PROMPT_SOURCE_PCM_BUFFER_SIZE*3)
       #define AUDIO_PROMPT_PCM_BUFFER_SIZE            (AUDIO_PROMPT_SOURCE_PCM_BUFFER_SIZE*4)
       
       #define AUDIO_PROMPT_SBC_BLOCK_SIZE             40
      @@ -104,7 +104,7 @@ bool audio_prompt_start_playing(uint16_t promptId, uint32_t targetSampleRate);
       
       void audio_prompt_stop_playing(void);
       
      -void audio_prompt_processing_handler(uint8_t device_id, uint32_t acquiredPcmDataLen,
      +void audio_prompt_processing_handler(uint32_t acquiredPcmDataLen,
                                            uint8_t *pcmDataToMerge);
       
       bool audio_prompt_check_on_stopping_stream(uint8_t pendingStopOp, uint8_t deviceId);
      @@ -118,7 +118,7 @@ uint16_t audio_prompt_get_prompt_id(void);
       uint32_t audio_prompt_get_sample_rate(void);
       
       #ifdef TWS_PROMPT_SYNC
      -void tws_playback_ticks_check_for_mix_prompt(uint8_t device_id);
      +void tws_playback_ticks_check_for_mix_prompt(void);
       void app_tws_cmd_sync_mix_prompt_req_handler(uint8_t *ptrParam, uint16_t paramLen);
       #endif
       
  • services/bt_app/besbt_cfg.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/besbt_cfg.h bes/services/bt_app/besbt_cfg.h
      index 191cbf7cb65..627096dd47b 100644
      --- a/services/bt_app/besbt_cfg.h
      +++ b/services/bt_app/besbt_cfg.h
      @@ -24,8 +24,9 @@ extern "C" {
       struct besbt_cfg_t{
           bool sniff;
           bool force_use_cvsd;
      +    bool one_bring_two;
           bool avdtp_cp_enable;
      -    bool bt_source_enable;
      +    bool source_enable;
           bool lhdc_v3;
       };
       extern struct besbt_cfg_t besbt_cfg;
  • services/bt_app/btapp.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/btapp.h bes/services/bt_app/btapp.h
      index e208dcbbbea..24f0c5165cf 100644
      --- a/services/bt_app/btapp.h
      +++ b/services/bt_app/btapp.h
      @@ -19,10 +19,10 @@
       #include "hfp_api.h"
       #include "a2dp_api.h"
       #include "app_a2dp_codecs.h"
      -#ifdef BT_HID_DEVICE
      +#ifdef BTIF_HID_DEVICE
       #include "app_bt_hid.h"
       #endif
      -#if defined(BT_MAP_SUPPORT)
      +#if defined(__BTMAP_ENABLE__)
       #include "map_api.h"
       #endif
       
      @@ -74,12 +74,12 @@
       #define A2D_SBC_IE_SAMP_FREQ_48     0x10    /* b4:48  kHz */
       
       #ifdef A2DP_SCALABLE_ON
      -#define A2D_SBC_IE_SAMP_FREQ_96     0x08    /* b4:48  kHz */
      +#define A2D_SBC_IE_SAMP_FREQ_96     0x08    /* b4:96  kHz */
       #endif
       
       #ifdef A2DP_LHDC_ON
       #ifndef A2D_SBC_IE_SAMP_FREQ_96
      -#define A2D_SBC_IE_SAMP_FREQ_96     0x08    /* b4:48  kHz */
      +#define A2D_SBC_IE_SAMP_FREQ_96     0x08    /* b4:96  kHz */
       #endif
       #endif
       
      @@ -155,12 +155,14 @@ extern const unsigned char a2dp_codec_elements[];
       #define HFP_KEY_THREEWAY_HOLD_REL_INCOMING            17
       #define HFP_KEY_THREEWAY_HOLD_ADD_HELD_CALL           18
       
      +#ifdef __BT_ONE_BRING_TWO__
       #define HFP_KEY_DUAL_HF_HANGUP_ANOTHER      19
       #define HFP_KEY_DUAL_HF_HANGUP_CURR_ANSWER_ANOTHER  20
       #define HFP_KEY_DUAL_HF_HOLD_CURR_ANSWER_ANOTHER    21
       #define HFP_KEY_DUAL_HF_CHANGETOPHONE_ANSWER_ANOTHER  22
       #define HFP_KEY_DUAL_HF_CHANGETOPHONE_ANOTHER_ADDTOEARPHONE 23
       #define HFP_KEY_DUAL_HF_HANGUP_ANOTHER_ADDTOEARPHONE 24
      +#endif
       
       //hsp
       #define HSP_KEY_CKPD_CONTROL        21
      @@ -197,86 +199,137 @@ typedef enum
           HFCALL_NEXT_STA_NUM
       } HFCALL_NEXT_STA_ENUM;
       
      +#if defined (__HSP_ENABLE__)
      +void hsp_callback(HsChannel *Chan, HsCallbackParms *Info);
      +#endif
       
       #define APP_REPORT_SPEAKER_VOL_CMD  0x01
       #define APP_CPKD_CMD                0x02
       #define SPP_MAX_TX_PACKET_NUM   5
      +#define AVRCP_PDU_PARAM_MAX_LEN 40
       
       
      -#ifndef BT_DEVICE_NUM
      -#if defined(IBRT_V2_MULTIPOINT)
      -#define BT_DEVICE_NUM 2
      -#elif defined(__BT_ONE_BRING_TWO__)
      -#define BT_DEVICE_NUM 2
      -#else
      -#define BT_DEVICE_NUM 1
      -#endif
      -#endif
      -
      -enum BT_DEVICE_ID_T {
      +enum BT_DEVICE_ID_T{
           BT_DEVICE_ID_1 = 0,
      -    BT_DEVICE_ID_2 = 1,
      -    BT_DEVICE_ID_3 = 2
      +#ifdef __BT_ONE_BRING_TWO__
      +    BT_DEVICE_ID_2,
      +#endif
      +    BT_DEVICE_NUM
       };
       
      -#ifdef BT_SOURCE
      -#if defined(BT_MULTI_SOURCE)
      -#define BT_SOURCE_DEVICE_NUM 2
      -#else
      -#define BT_SOURCE_DEVICE_NUM 1
      -#endif
      +#if defined(APP_LINEIN_A2DP_SOURCE)||defined(APP_I2S_A2DP_SOURCE)
      +enum BT_DEVICE_SRC_SNK_T{
      +    BT_DEVICE_SNK=0,
      +    BT_DEVICE_SRC
      +};
      +#if defined(APP_LINEIN_A2DP_SOURCE)||defined(APP_I2S_A2DP_SOURCE)
      +#define APP_BD_ADDR_SIZE    6
      +typedef struct APP_BT_BD_ADDR {
      +    U8    addr[APP_BD_ADDR_SIZE];
      +} APP_BT_BD_ADDR;
       #endif
      -
      -#ifndef BT_SOURCE_DEVICE_NUM
      -#define BT_SOURCE_DEVICE_NUM 0
       #endif
       
      -#define BT_AVDTP_CP_VALUE_SIZE 10
      +struct BT_DEVICE_T{
      +    btif_a2dp_stream_t*  a2dp_stream[BT_DEVICE_NUM];
      +    uint8_t avdtp_cp[BT_DEVICE_NUM];
      +    btif_a2dp_stream_t* a2dp_lhdc_stream[BT_DEVICE_NUM];
      +    uint8_t a2dp_lhdc_llc[BT_DEVICE_NUM];
       
      -struct BT_DEVICE_T {
      -    btif_a2dp_stream_t *btif_a2dp_stream;
      -    bool avdtp_cp;
      -    btif_avdtp_content_prot_t a2dp_avdtp_cp;
      -    uint8_t a2dp_avdtp_cp_security_data[BT_AVDTP_CP_VALUE_SIZE];
      -    uint8_t a2dp_lhdc_llc;
      +    btif_a2dp_stream_t* a2dp_ldac_stream[BT_DEVICE_NUM];
      +    int channel_mode;
       
      -    uint8_t channel_mode;
      +     btif_a2dp_stream_t* a2dp_aac_stream[BT_DEVICE_NUM];
       
      +     btif_a2dp_stream_t* a2dp_scalable_stream[BT_DEVICE_NUM];
       
      +#if defined(APP_LINEIN_A2DP_SOURCE)||defined(APP_I2S_A2DP_SOURCE)
      +    uint8_t src_or_snk;//src or snk fkag
      +    uint8_t input_onoff;
      +    APP_BT_BD_ADDR         inquried_snk_bdAddr;           /* Device Address */
      +    //BT_BD_ADDR         rmt_bdAddr;           /* Device Address */
      +#endif
       
      -    a2dp_stream_t *a2dp_connected_stream;
      -    bt_bdaddr_t remote;
      +    a2dp_stream_t * a2dp_connected_stream[BT_DEVICE_NUM];
      +    a2dp_stream_t * a2dp_outconfiged_stream[BT_DEVICE_NUM];
      +    btif_remote_device_t * a2dp_outconfiged_rem[BT_DEVICE_NUM];
      +    enum BT_DEVICE_ID_T curr_a2dp_stream_id;
      +    uint16_t current_a2dp_conhdl;
       
       
      -    uint8_t a2dp_conn_flag;
      -    uint8_t a2dp_streamming;
      +    uint8_t a2dp_state[BT_DEVICE_NUM];
      +    uint8_t a2dp_streamming[BT_DEVICE_NUM];
           uint8_t a2dp_play_pause_flag;
      -    uint8_t volume_report;
      -    btif_avdtp_codec_type_t codec_type;
      -
      -    uint8_t sample_rate;
      -    uint8_t sample_bit;
      -    btif_avrcp_channel_t *avrcp_channel;
      -
      -    btif_hf_channel_t* hf_channel;
      -#if defined (BT_MAP_SUPPORT)
      -    btif_map_session_handle_t map_session_handle;
      +    uint8_t avrcpPendingKey;
      +    uint8_t latestPausedDevId;
      +    uint8_t avrcpPressedKey;
      +    uint8_t avrcpVolumeSync;
      +    btif_avdtp_codec_type_t codec_type[BT_DEVICE_NUM];
      +
      +    uint8_t sample_rate[BT_DEVICE_NUM];
      +    uint8_t sample_bit[BT_DEVICE_NUM];
      +    uint8_t avrcp_state[BT_DEVICE_NUM];
      +    btif_avrcp_channel_t*  avrcp_channel[BT_DEVICE_NUM];
      +
      +    hf_chan_handle_t hf_channel[BT_DEVICE_NUM];
      +#if defined (__HSP_ENABLE__)
      +    HsChannel hs_channel[BT_DEVICE_NUM];
       #endif
      -    btif_hf_call_setup_t hfchan_callSetup;
      -    btif_hf_call_active_t hfchan_call;
      -    btif_audio_state_t hf_audio_state;
      -    btif_hf_call_held_state hf_callheld;
      -
      -    uint8_t hf_conn_flag;
      -
      -#ifdef BT_HID_DEVICE
      -    hid_channel_t hid_channel;
      +#if defined (__BTMAP_ENABLE__)
      +    btif_map_session_handle_t map_session_handle[BT_DEVICE_NUM];
      +#endif
      +    enum BT_DEVICE_ID_T curr_hf_channel_id;
      +    btif_hf_call_setup_t hfchan_callSetup[BT_DEVICE_NUM];
      +    btif_hf_call_active_t hfchan_call[BT_DEVICE_NUM];
      +    btif_audio_state_t hf_audio_state[BT_DEVICE_NUM];
      +    btif_hf_call_held_state hf_callheld[BT_DEVICE_NUM];
      +    uint32_t hf_callsetup_time[BT_DEVICE_NUM];
      +#if defined (__HSP_ENABLE__)
      +    enum BT_DEVICE_ID_T curr_hs_channel_id;
      +    HsCallActiveState hschan_call[BT_DEVICE_NUM];
      +    HsAudioConnectState hs_audio_state[BT_DEVICE_NUM];
      +#endif
      +#ifdef BTIF_AVRCP_ADVANCED_CONTROLLER
      +    uint32_t avrcp_advancedPdu_size;
      +    void *avrcp_cmd1[BT_DEVICE_NUM];
      +    void *avrcp_cmd2[BT_DEVICE_NUM];
      +    void *avrcp_get_capabilities_rsp[BT_DEVICE_NUM];
      +    void *avrcp_control_rsp[BT_DEVICE_NUM];
      +    void *avrcp_notify_rsp[BT_DEVICE_NUM];
      +    uint8_t volume_report[BT_DEVICE_NUM];
      +    void *avrcp_volume_cmd[BT_DEVICE_NUM];
      +
      +    void *avrcp_custom_cmd[BT_DEVICE_NUM];
      +#ifdef AVRCP_TRACK_CHANGED
      +    uint8_t track_changed[BT_DEVICE_NUM];
      +#endif
      +#endif
      +    uint8_t hf_conn_flag[BT_DEVICE_NUM];
      +    uint8_t hf_voice_en[BT_DEVICE_NUM];
      +    uint8_t hf_endcall_dis[BT_DEVICE_NUM];
      +    uint8_t hf_mute_flag;
      +    uint8_t phone_earphone_mark;
      +#if defined (__HSP_ENABLE__)
      +    uint8_t hs_conn_flag[BT_DEVICE_NUM];
      +    uint8_t hs_voice_en[BT_DEVICE_NUM];
      +    uint8_t hs_mute_flag;
      +#endif
      +#ifdef BTIF_HID_DEVICE
      +    hid_channel_t  hid_channel[BT_DEVICE_NUM];
       #endif
       
      +    uint8_t callSetupBitRec;
       };
       
       
       
      +struct BT_DEVICE_ID_DIFF{
      +    enum BT_DEVICE_ID_T id;
      +#ifdef __BT_ONE_BRING_TWO__
      +    enum BT_DEVICE_ID_T id_other;
      +#endif
      +};
      +
       /////app key handle include
       void a2dp_handleKey(uint8_t a2dp_key);
       void hfp_handle_key(uint8_t hfp_key);
      @@ -302,14 +355,33 @@ void bt_key_init(void);
       void bt_key_send(APP_KEY_STATUS *status);
       void bt_key_handle(void);
       
      -void a2dp_callback(uint8_t device_id, a2dp_stream_t *Stream, const a2dp_callback_parms_t *Info);
      +void a2dp_callback(a2dp_stream_t *Stream, const a2dp_callback_parms_t *Info);
       void avrcp_init(void);
      +//void avrcp_callback(AvrcpChannel *chnl, const AvrcpCallbackParms *Parms);
       
      -uint8_t a2dp_volume_get(enum BT_DEVICE_ID_T id);
      +void avrcp_callback_CT(btif_avrcp_chnl_handle_t  chnl, const avrcp_callback_parms_t *Parms);
      +void avrcp_callback_TG(btif_avrcp_chnl_handle_t chnl, const avrcp_callback_parms_t *Parms);
      +int a2dp_volume_get(enum BT_DEVICE_ID_T id);
      +int a2dp_volume_get_tws(void);
       bool avrcp_get_tg_play_status_play_pause(void);
      +#if defined(APP_LINEIN_A2DP_SOURCE)||defined(APP_I2S_A2DP_SOURCE) || defined(__APP_A2DP_SOURCE__)
      +#ifdef __TWS__
      +//void avrcp_set_slave_volume(uint8_t transid,int8_t volume);
      +#endif
       
       
      +//#define AVRCP_TRACK_CHANGED
      +void a2dp_set_config_codec(btif_avdtp_codec_t *config_codec,const btif_a2dp_callback_parms_t *Info);
       
      +void a2dp_callback_source(a2dp_stream_t *Stream, const a2dp_callback_parms_t *Info);
      +void app_a2dp_source_init(void);
      +void app_source_init(void);
      +
      +void app_a2dp_source_find_sink(void);
      +void avrcp_source_callback_TG(btif_avrcp_chnl_handle_t chnl, const avrcp_callback_parms_t *Parms);
      +void app_a2dp_start_stream(void);
      +void app_a2dp_suspend_stream(void);
      +#endif
       
       /**
        * Convert BES BD_ADDR to virtual
      @@ -330,12 +402,18 @@ int bt_ldac_player_get_channelmode(void);
       int bt_get_ladc_sample_rate(void);
       #endif
       
      -uint8_t app_bt_avrcp_get_volume_change_trans_id(uint8_t device_id);
      -void app_bt_avrcp_set_volume_change_trans_id(uint8_t device_id, uint8_t trans_id);
      -uint8_t app_bt_avrcp_get_ctl_trans_id(uint8_t device_id);
      -void app_bt_avrcp_set_ctl_trans_id(uint8_t device_id, uint8_t trans_id);
      +uint8_t app_bt_avrcp_get_notify_trans_id(void);
      +void app_bt_avrcp_set_notify_trans_id(uint8_t trans_id);
      +uint8_t app_bt_avrcp_get_ctl_trans_id(void);
      +void app_bt_avrcp_set_ctl_trans_id(uint8_t trans_id);
       
       
      +#if defined(IBRT)
      +#if defined(ENHANCED_STACK)
      +uint32_t app_avrcp_save_ctxs(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      +uint32_t app_avrcp_restore_ctxs(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      +#endif /* ENHANCED_STACK */
      +#endif
       
       #ifdef __cplusplus
       }
  • services/bt_app/res_audio_data.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/res_audio_data.h bes/services/bt_app/res_audio_data.h
      index bc64a8ece51..8be9d483049 100644
      --- a/services/bt_app/res_audio_data.h
      +++ b/services/bt_app/res_audio_data.h
      @@ -139,8 +139,8 @@ const uint8_t EN_BT_GSOUND_MIC_CLOSE[] = {
       #include "res/en/SOUND_GSOUND_MIC_CLOSE.txt"
       };
       
      -const uint8_t EN_BT_MUTE[] = {
      -#include "res/SOUND_MUTE.txt"
      +const uint8_t EN_BT_DUDU[] = {
      +#include "res/en/dudu.txt"
       };
       const uint8_t EN_BT_GSOUND_NC[] = {
       #include "res/en/SOUND_GSOUND_NC.txt"
  • services/bt_app/res_audio_ring.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_app/res_audio_ring.h bes/services/bt_app/res_audio_ring.h
      index dcf1d011f03..1fab6d23479 100644
      --- a/services/bt_app/res_audio_ring.h
      +++ b/services/bt_app/res_audio_ring.h
      @@ -13,6 +13,7 @@
        * limitations under the License.
        */
       
      +const int16_t RES_AUD_RING_SAMPRATE_8000 [] = {
       #include "res/ring/SOUND_RING_8000.txt"
       };
       #ifdef __BT_WARNING_TONE_MERGE_INTO_STREAM_SBC__
  • services/bt_if_enhanced/inc/a2dp_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/a2dp_api.h bes/services/bt_if_enhanced/inc/a2dp_api.h
      index b85171ff4f2..6418aa977ad 100644
      --- a/services/bt_if_enhanced/inc/a2dp_api.h
      +++ b/services/bt_if_enhanced/inc/a2dp_api.h
      @@ -21,6 +21,13 @@
       #include "conmgr_api.h"
       #include "codec_sbc.h"
       
      +typedef enum{
      +    BTIF_DEVICE_ID_1 = 0,
      +#ifdef __BT_ONE_BRING_TWO__
      +    BTIF_DEVICE_ID_2,
      +#endif
      +    BTIF_DEVICE_NUM
      +}btif_dev_it_e;
       
       typedef void a2dp_stream_t;
       typedef void a2dp_callback_parms_t;
      @@ -342,7 +349,7 @@ typedef uint8_t btif_a2dp_stream_state_t;
       /* Unknown state */
       #define BTIF_A2DP_STREAM_STATE_UNKNOWN    0xFF
       
      -typedef void (*btif_a2dp_callback)(uint8_t device_id, a2dp_stream_t * Stream, const a2dp_callback_parms_t * Info);
      +typedef void (*btif_a2dp_callback) (a2dp_stream_t * Stream, const a2dp_callback_parms_t * Info);
       
       
       typedef void btif_av_device_t;
      @@ -356,6 +363,7 @@ struct btif_get_codec_cap_t
       
       typedef struct {
           btif_a2dp_event_t event;
      +    uint8_t  subevt;
           uint16_t len;
           I8 status;
           btif_a2dp_error_t error;
      @@ -386,6 +394,9 @@ typedef struct {
       } btif_a2dp_streamInfo_t;
       
       typedef struct {
      +#if defined(__TWS__)
      +    btif_avdtp_codec_t setconfig_codec;
      +#endif /*  */
           bool free;
           uint8_t state;
           a2dp_stream_t *a2dp_stream; //stack A2dpStream  object
      @@ -399,36 +410,45 @@ extern "C" {
       
           void btif_a2dp_init(void);
       
      +    int a2dp_hid_init(void);
       
      -    btif_a2dp_stream_t *btif_a2dp_alloc_sink_stream(void);
      -    btif_a2dp_stream_t *btif_a2dp_alloc_source_stream(void);
      +    btif_a2dp_stream_t *btif_a2dp_alloc_stream(void);
       
           uint16_t btif_avdtp_parse_mediaHeader(btif_media_header_t * header,
                                                 btif_a2dp_callback_parms_t * Info, uint8_t avdtp_cp);
       
      +    void btif_app_a2dp_avrcpadvancedpdu_mempool_init();
       
      +    void btif_app_a2dp_avrcpadvancedpdu_mempool_calloc(void **buf);
       
      +    void btif_app_a2dp_avrcpadvancedpdu_mempool_free(void *buf);
       
           void a2dp_set_config_codec(btif_avdtp_codec_t * config_codec,
                                      const btif_a2dp_callback_parms_t * Info);
       
      -    void btif_a2dp_stream_init(btif_a2dp_stream_t *Stream, btif_a2dp_endpoint_type_t stream_type);
      -
      +    btif_avdtp_codec_type_t btif_a2dp_get_stream_register_codec_type(a2dp_stream_t *stream);
       
      -    bt_status_t btif_a2dp_register(btif_a2dp_stream_t *Stream,
      -                                   btif_a2dp_endpoint_type_t sep_type,
      -                                   btif_avdtp_codec_t *sep_codec,
      -                                   btif_avdtp_content_prot_t *sep_cp,
      -                                   uint8_t sep_priority,
      +    bt_status_t btif_a2dp_register(a2dp_stream_t *Stream,
      +                                   btif_a2dp_endpoint_type_t stream_type,
      +                                   btif_avdtp_codec_t *Codec,
      +                                   btif_avdtp_content_prot_t *Prot,
      +                                   uint8_t Priority,
      +                                   uint8_t Device_id,
                                          btif_a2dp_callback Callback);
       
      +    bt_status_t btif_a2dp_add_content_protection(a2dp_stream_t *Stream, btif_avdtp_content_prot_t *Prot);
       
      -    bt_status_t btif_a2dp_deregister(btif_a2dp_stream_t *Stream, uint8_t codec_type);
      +    bt_status_t btif_a2dp_deregister(a2dp_stream_t * Stream);
       
      +    int8_t btif_a2dp_is_register_codec_same(a2dp_stream_t *src_stream, a2dp_stream_t *dst_stream);
       
      +    void btif_a2dp_lhdc_config_tws_audio(const a2dp_callback_parms_t * info);
       
      +    void btif_a2dp_aac_config_tws_audio(const a2dp_callback_parms_t * info);
       
      +    void btif_a2dp_sbc_config_tws_audio(const a2dp_callback_parms_t * info);
       
      +    void btif_a2dp_tws_set_mobile_codec_info(const a2dp_callback_parms_t * info);
       
           void btif_a2dp_set_copy_protection_enable(a2dp_stream_t *stream, bool enable);
       
      @@ -463,8 +483,9 @@ extern "C" {
                                                   btif_avdtp_codec_t * Codec,
                                                   btif_avdtp_content_prot_t * Cp);
       
      -    bt_status_t btif_a2dp_open_stream(btif_avdtp_codec_t *prev_conn_codec, bt_bdaddr_t * Addr);
      +    bt_status_t btif_a2dp_open_stream(a2dp_stream_t * Stream, bt_bdaddr_t * Addr);
       
      +    bt_status_t btif_a2dp_disc_stream(a2dp_stream_t * Stream);
       
           bt_status_t btif_a2dp_start_stream(a2dp_stream_t * Stream);
       
      @@ -501,12 +522,15 @@ extern "C" {
       
           btif_avdtp_stream_state_t btif_a2dp_get_stream_state(a2dp_stream_t * Stream);
       
      +    uint8_t btif_a2dp_get_stream_loc_strmId(a2dp_stream_t * Stream);
       
      +    uint8_t btif_a2dp_get_stream_rem_strmId(a2dp_stream_t * Stream);
       
           uint16_t btif_a2dp_get_stream_chnl_sigchnl_l2ChannelId(a2dp_stream_t * Stream);
       
           void btif_a2dp_set_stream_state(a2dp_stream_t * Stream, btif_avdtp_stream_state_t state);
       
      +    void btif_a2dp_reset_stream_state(a2dp_stream_t *stream);
       
           void btif_a2dp_set_stream_conn_l2ChannelId(a2dp_stream_t * Stream, uint16_t id);
       
      @@ -518,16 +542,19 @@ extern "C" {
       
           void btif_a2dp_set_stream_remote_streamId(a2dp_stream_t * Stream, uint8_t id);
       
      +    void btif_a2dp_discover(a2dp_stream_t* Stream);
       
           BOOL btif_a2dp_is_stream_device_has_delay_reporting(a2dp_stream_t * Stream);
       
           btif_avdtp_codec_t *btif_a2dp_get_stream_codec(a2dp_stream_t * Stream);
       
      +    btif_avdtp_codec_t *btif_a2dp_get_stream_codecCfg(a2dp_stream_t * Stream);
       
           uint16_t btif_a2dp_get_stream_conn_remDev_hciHandle(a2dp_stream_t * Stream);
       
           uint16_t btif_a2dp_get_stream_device_cmgrhandler_remDev_hciHandle(a2dp_stream_t * Stream);
       
      +    btif_avdtp_codec_t *btif_a2dp_get_avdtp_setconfig_codec(a2dp_stream_t * stream);
       
           bt_status_t btif_a2dp_get_stream_capabilities(a2dp_stream_t * Stream);
       
      @@ -545,6 +572,7 @@ extern "C" {
       
           btif_remote_device_t *btif_a2dp_get_stream_conn_remDev(a2dp_stream_t * stream);
       
      +    uint8_t btif_a2dp_get_stream_codec_element(a2dp_stream_t * stream,uint8_t index);
       
           bt_status_t btif_a2dp_set_master_role(a2dp_stream_t * Stream, BOOL Flag);
       
      @@ -554,36 +582,50 @@ extern "C" {
       
           int tws_if_get_a2dpbuff_available(void);
       
      +    int a2dp_codec_init(void);
      +    void  btif_a2dp_lock_same_deviceid_endpoint(a2dp_stream_t  * Stream,btif_remote_device_t   *remDev);
      +    void  btif_a2dp_unlock_same_deviceid_endpoint(a2dp_stream_t  * Stream,btif_remote_device_t   *remDev);
      +    void  btif_a2dp_unlock_the_connected_stream_byRemdev(btif_remote_device_t* RemDev);
       
      +    uint8_t btif_a2dp_trylock_the_other_id_by_configedid(btif_remote_device_t* RemDev);
       
           uint8_t btif_a2dp_confirm_stream_state(a2dp_stream_t *Stream, uint8_t old_state, uint8_t new_state);
       
      +    void  btif_a2dp_lock_deviceid_endpoint(uint8_t id);
       
      +    void  btif_a2dp_unlock_deviceid_endpoint(uint8_t unused_id);
       
           bool btif_a2dp_is_disconnected(a2dp_stream_t *Stream);
       
      +    uint8_t btif_a2dp_get_avrcpadvancedpdu_trans_id(void* pdu);
      +    void btif_a2dp_set_avrcpadvancedpdu_trans_id(void* pdu, uint8_t trans_id);
       
           btif_remote_device_t *btif_a2dp_get_remote_device_from_cbparms(a2dp_stream_t *Stream, const a2dp_callback_parms_t *info);
       
           btif_avdtp_codec_type_t btif_a2dp_get_codec_type(const a2dp_callback_parms_t *info);
      -    void btif_a2dp_set_codec_info_func(void (*func)(uint8_t dev_num, const uint8_t *codec));
      -    void btif_a2dp_get_codec_info_func(void (*func)(uint8_t dev_num, uint8_t *codec));
      +    void btif_a2dp_set_codec_info_func(void (*func)(btif_dev_it_e dev_num, const uint8_t *codec));
      +    void btif_a2dp_get_codec_info_func(void (*func)(btif_dev_it_e dev_num, uint8_t *codec));
       
       #if defined(IBRT)
      -    void btif_a2dp_set_codec_info(uint8_t dev_num, const uint8_t *codec);
      -    void btif_a2dp_get_codec_info(uint8_t dev_num, uint8_t *codec);
      +    void btif_reset_app_bt_device_streaming(uint8_t bt_dev_idx, uint8_t rm_detbl_idx , uint8_t avd_ctx_device_idx);
      +    void btif_a2dp_set_codec_info(btif_dev_it_e dev_num, const uint8_t *codec);
      +    void btif_a2dp_get_codec_info(btif_dev_it_e dev_num, uint8_t *codec);
       #endif
       #if defined(IBRT)
      +#if defined(ENHANCED_STACK)
           uint32_t btif_a2dp_profile_save_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      -    uint32_t btif_a2dp_profile_restore_ctx(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len);
      +    uint32_t btif_a2dp_profile_restore_ctx(uint8_t *buf, uint32_t buf_len);
           uint8_t btif_a2dp_is_critical_avdtp_cmd_handling(void);
           void btif_a2dp_critical_avdtp_cmd_timeout(void);
      +#endif /* *ENHANCED_STACK */
       #endif /* IBRT */
       
           /* Callout functions, do not call directly */
           uint8_t a2dp_stream_confirm_stream_state(uint8_t index, uint8_t old_state, uint8_t new_state);
           uint8_t a2dp_stream_locate_the_connected_dev_id(a2dp_stream_t *Stream);
       
      +void btif_a2dp_get_info(uint8_t devIndex, btif_avdtp_codec_type_t* pCodec,
      +    uint8_t* pSampleRate, uint8_t* pSampleBit);
       
       #ifdef __cplusplus
       }
  • services/bt_if_enhanced/inc/avctp_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/avctp_api.h bes/services/bt_if_enhanced/inc/avctp_api.h
      index 444c48cc997..2ee52139765 100644
      --- a/services/bt_if_enhanced/inc/avctp_api.h
      +++ b/services/bt_if_enhanced/inc/avctp_api.h
      @@ -33,7 +33,7 @@ typedef uint8_t btif_avctp_event_t;
       
       #define BTIF_AVCTP_OPERANDS_EVENT            9
       
      -#define BTIF_AVCTP_LAST_EVENT               30
      +#define BTIF_AVCTP_LAST_EVENT                9
       
       #define BTIF_AVCTP_CTYPE_CONTROL               0x00
       #define BTIF_AVCTP_CTYPE_STATUS                0x01
  • services/bt_if_enhanced/inc/avrcp_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/avrcp_api.h bes/services/bt_if_enhanced/inc/avrcp_api.h
      index 20e60b191c1..5849dbfaf43 100644
      --- a/services/bt_if_enhanced/inc/avrcp_api.h
      +++ b/services/bt_if_enhanced/inc/avrcp_api.h
      @@ -27,7 +27,8 @@
       #define BTIF_AVRCP_RX_FRAG_BUFF_SIZE             672 //L2CAP_DEFAULT_MTU
       
       typedef btif_avctp_event_t btif_avrcp_event_t;
      -typedef struct { /* empty */ } avrcp_channel_t; /* used to hold the pointer to struct avrcp_control_t */
      +typedef void *btif_avrcp_chnl_handle_t;
      +typedef void *btif_app_bt_device_t;
       
       
       /** The transport layer is connected and commands/responses can now
      @@ -763,6 +764,7 @@ typedef uint8_t avrcp_folder_type_t;
       
       typedef uint8_t avrcp_is_playable_t;
       typedef uint16_t avrcp_capabilityId_t;
      +typedef void avrcp_advanced_pdu_t;
       
       #define BTIF_AVRCP_IS_NOT_PLAYABLE  0x00
       #define BTIF_AVRCP_IS_PLAYABLE      0x01
      @@ -1464,9 +1466,9 @@ enum {
           BTIF_AVRCP_STATE_DISCONNECTED,
           BTIF_AVRCP_STATE_CONNECTED
       };
      -typedef struct { /* empty */ } avrcp_callback_parms_t; /* used to hold the pointer to btif_avrcp_callback_parms_t */
      +typedef void avrcp_callback_parms_t;
       
      -typedef void (*btif_avrcp_callback)(uint8_t device_id, btif_avrcp_channel_t *btif_avrcp, const avrcp_callback_parms_t *parms);
      +typedef void (*btif_avrcp_callback)(btif_avrcp_chnl_handle_t chnl, const avrcp_callback_parms_t *parms);
       
       static POSSIBLY_UNUSED inline btif_avctp_event_t btif_convert_avrcp_event(btif_avrcp_event_t event)
       {
      @@ -1476,11 +1478,50 @@ static POSSIBLY_UNUSED inline btif_avctp_event_t btif_convert_avrcp_event(btif_a
       #define BTIF_AVRCP_EVENT(stack_avrcp_event)   btif_convert_avrcp_event(stack_avrcp_event)
       #define BTIF_AVRCP_ERROR_CODE(statck_error_code)  statck_error_code
       
      +typedef struct
      +{
      +    list_entry_t node;
      +    U8 op;
      +    U16 parm_len;
      +    U8 *parms;
      +    U8  trans_id;
      +
      +    BOOL more;
      +    U16  cur_len;
      +    U16  bytes_to_send;
      +    U8   cont_op;
      +    BOOL abort;
       
      +    BOOL  internal;
      +    U8  response;
      +    U8 error;
      +
      +    BOOL is_cmd;
      +    U8  ctype;          /* 4 bits */
      +} btif_avrcp_advanced_cmd_pdu_t ;
      +
      +typedef struct
      +{
      +    bool free;
      +    uint8_t state;
      +    list_entry_t tx_cmd_list;
      +    CQueue tx_op_queue;
      +    uint8_t tx_op_queue_buff[BTIF_AVRCP_SUBUNIT_OP_QUEUE_MAX*3]; // 3 bytes per operation
      +    avctp_cmd_frame_t rx_cmd_frame;
      +    uint8_t rx_frag_buff[BTIF_AVRCP_RX_FRAG_BUFF_SIZE];
      +    uint32_t rx_frag_buff_offset;
      +    struct
      +    {
      +        avrcp_event_mask_t rem_eventMask;
      +        btif_avrcp_advanced_cmd_pdu_t *tx_cmd;
      +    } adv;
      +    btif_avrcp_callback cb;
      +    btif_avrcp_chnl_handle_t avrcp_channel_handle;
      +} btif_avrcp_channel_t;
       
       typedef struct
       {
      -    struct avrcp_advanced_cmd_pdu *tx_cmd;
      +    btif_avrcp_advanced_cmd_pdu_t *tx_cmd;
           avrcp_adv_rsp_parms_t rsp;
           avrcp_adv_notify_parms_t notify;
       } btif_avrcp_rsp_adv;
      @@ -1505,13 +1546,13 @@ typedef struct
       extern "C" {
       #endif
       
      -    void btif_avrcp_init(void);
      +    void btif_avrcp_init(btif_app_bt_device_t btif_app_bt_device);
       
           bt_status_t btif_avrcp_register(btif_avrcp_channel_t *channel, btif_avrcp_callback cb, avrcp_features_t feat);
       
      -    btif_avrcp_channel_t *btif_alloc_avrcp_ct_channel(void);
      +    btif_avrcp_channel_t *btif_alloc_avrcp_channel(void);
       
      -    btif_avrcp_channel_t *btif_get_avrcp_channel(avrcp_channel_t* handle);
      +    btif_avrcp_channel_t *btif_get_avrcp_channel(btif_avrcp_chnl_handle_t handle);
       
           btif_avctp_event_t btif_avrcp_get_callback_event(const avrcp_callback_parms_t * parms);
       
      @@ -1519,20 +1560,23 @@ extern "C" {
       
           void btif_avrcp_set_volume_cmd(void *cmd, uint8_t transid, int8_t volume);
       
      +    void btif_avrcp_register_read_remote_sdp_callback(void (*cb)(btif_avrcp_chnl_handle_t chnl, uint16_t version, uint16_t features));
       
           void btif_avrcp_send_custom_cmd_generic(btif_avrcp_channel_t * chnl, uint8_t * ptrData,
                                                   uint32_t len);
      -    bt_status_t btif_avrcp_ct_accept_custom_cmd(btif_avrcp_channel_t * chnl, uint8_t isAccept, uint8_t trans_id);
      -    bt_status_t btif_avrcp_connect(bt_bdaddr_t *addr);
      +    bt_status_t btif_avrcp_ct_accept_custom_cmd_rsp(btif_avrcp_channel_t * chnl, void *cmd_res, uint8_t isAccept);
      +    bt_status_t btif_avrcp_connect(btif_avrcp_channel_t * channel, bt_bdaddr_t * addr);
       
           bt_status_t btif_avrcp_connect_rsp(btif_avrcp_channel_t * chnl, BOOL accept);
       
      -    bt_status_t btif_avrcp_disconnect(btif_avrcp_channel_t* channel);
      +    bt_status_t btif_avrcp_disconnect(btif_avrcp_chnl_handle_t channel);
       
      -    bt_status_t btif_avrcp_ct_get_play_status(btif_avrcp_channel_t * channel);
      +    bt_status_t btif_avrcp_ct_get_play_status(btif_avrcp_channel_t * channel,
      +                                              avrcp_advanced_pdu_t * cmd);
           avrcp_version_t btif_get_avrcp_version(btif_avrcp_channel_t * channel);
       
           bt_status_t btif_avrcp_ct_get_capabilities(btif_avrcp_channel_t * channel,
      +                                               avrcp_advanced_pdu_t * pdu,
                                                      btif_avrcp_capabilityId capabilityId);
       
           void btif_set_avrcp_state(btif_avrcp_channel_t * channel, uint8_t avrcp_state);
      @@ -1541,16 +1585,17 @@ extern "C" {
       
           bool btif_avrcp_is_control_channel_connected(btif_avrcp_channel_t * channel);
       
      -    btif_remote_device_t *btif_avrcp_get_remote_device(btif_avrcp_channel_t* handle);
      +    btif_remote_device_t *btif_avrcp_get_remote_device(btif_avrcp_chnl_handle_t handle);
       
      +    uint8_t btif_avrcp_get_channel_panel_int_state(btif_avrcp_chnl_handle_t handle);
       
      +    uint8_t btif_avrcp_get_channel_avrcp_state(btif_avrcp_chnl_handle_t handle);
       
           void btif_avrcp_set_register_notify_check_callback(bool (*cb)(uint8_t event), void (*resp_cb)(uint8_t event));
       
      -    bt_status_t btif_avrcp_ct_register_volume_change_notification(btif_avrcp_channel_t * channel, uint32_t interval);
      -    bt_status_t btif_avrcp_ct_register_media_status_notification(btif_avrcp_channel_t * channel, uint32_t interval);
      -    bt_status_t btif_avrcp_ct_register_play_pos_notification(btif_avrcp_channel_t * channel, uint32_t interval);
      -    bt_status_t btif_avrcp_ct_register_track_change_notification(btif_avrcp_channel_t * channel, uint32_t interval);
      +    bt_status_t btif_avrcp_ct_register_notification(btif_avrcp_channel_t * channel,
      +                                                    avrcp_advanced_pdu_t * pdu,
      +                                                    btif_avrcp_event_t eventId, uint32_t interval);
           void btif_avrcp_ct_register_notify_response_check(btif_avrcp_channel_t * channel, uint8_t event);
           bt_status_t btif_get_avrcp_cb_channel_state(const avrcp_callback_parms_t * parms);
       
      @@ -1582,20 +1627,45 @@ extern "C" {
       
           void btif_set_avrcp_adv_rem_event_mask(btif_avrcp_channel_t * channel, uint16_t mask);
       
      +    void btif_set_app_bt_device_avrcp_notify_rsp_ctype(avrcp_advanced_pdu_t * cmd, uint8_t type);
       
      +    uint8_t btif_get_app_bt_device_avrcp_notify_rsp_transid(avrcp_advanced_pdu_t * cmd);
       
      -    bt_status_t btif_avrcp_ct_get_media_Info(btif_avrcp_channel_t * channel, avrcp_media_attrId_mask_t mediaMask);
      +    bt_status_t btif_avrcp_ct_get_media_Info(btif_avrcp_channel_t * channel,
      +                                             avrcp_advanced_pdu_t * cmd,
      +                                             avrcp_media_attrId_mask_t mediaMask);
           avctp_cmd_frame_t *btif_get_avrcp_cmd_frame(const avrcp_callback_parms_t * parms);
       
      -    bt_status_t btif_avrcp_ct_send_capability_rsp(btif_avrcp_channel_t * channel, avrcp_capabilityId_t capid, uint16_t mask, uint8_t trans_id);
      +    void btif_avrcp_set_capabilities_rsp_cmd(avrcp_advanced_pdu_t * cmd_pdu, uint8_t transId,
      +                                             uint8_t type);
      +
      +    void btif_avrcp_set_control_rsp_cmd(avrcp_advanced_pdu_t * cmd_pdu, uint8_t transId,
      +                                        uint8_t type);
      +
      +    void btif_avrcp_set_control_rsp_cmd_witherror(avrcp_advanced_pdu_t * cmd_pdu, uint8_t transId, uint8_t type, uint8_t error);
      +
      +    bt_status_t btif_avrcp_ct_get_capabilities_rsp(btif_avrcp_channel_t * channel,
      +                                                   avrcp_advanced_pdu_t * cmd_pdu,
      +                                                   avrcp_capabilityId_t capid, uint16_t mask);
      +
      +    bt_status_t btif_avrcp_ct_get_capabilities_company_id_rsp(btif_avrcp_channel_t * channel, avrcp_advanced_pdu_t * cmd_pdu);
      +
      +    bt_status_t btif_avrcp_ct_accept_absolute_volume_rsp(btif_avrcp_channel_t * channel,
      +                                                         avrcp_advanced_pdu_t * cmd_pdu,
      +                                                         uint8_t volume);
      +
      +    void btif_avrcp_set_notify_rsp_cmd(avrcp_advanced_pdu_t * cmd_pdu, uint8_t transId,
      +                                       uint8_t type);
      +
      +    void btif_avrcp_set_notify_rsp_cmd_witherror(avrcp_advanced_pdu_t * cmd_pdu, uint8_t transId, uint8_t type, uint8_t error);
       
      -    bt_status_t btif_avrcp_ct_send_absolute_volume_rsp(btif_avrcp_channel_t * channel, uint8_t volume, uint8_t trans_id, uint8_t error_n);
      +    void btif_avrcp_recheck_vol_ctrl_flag(uint8_t * flag);
       
      -    bt_status_t btif_avrcp_ct_send_volume_change_interim_rsp(btif_avrcp_channel_t * channel, uint8_t volume, uint8_t trans_id);
      -    bt_status_t btif_avrcp_ct_send_volume_change_actual_rsp(btif_avrcp_channel_t * channel, int volume);
      +    bt_status_t btif_avrcp_ct_get_absolute_volume_rsp(btif_avrcp_channel_t * channel,
      +                                                      avrcp_advanced_pdu_t * cmd_pdu,
      +                                                      uint8_t volume);
       
      -    bt_status_t btif_avrcp_send_play_status_change_interim_rsp(btif_avrcp_channel_t * channel, uint8_t play_status, uint8_t trans_id);
      -    bt_status_t btif_avrcp_send_play_status_change_actual_rsp(btif_avrcp_channel_t * channel, uint8_t play_status);
      +    bt_status_t btif_avrcp_tg_absolute_volume_notify(btif_avrcp_channel_t * channel, avrcp_advanced_pdu_t * cmd_pdu, uint8_t volume);
       
           uint16_t btif_avrcp_get_cmgrhandler_remDev_hciHandle(btif_avrcp_channel_t * channel);
       
      @@ -1609,17 +1679,17 @@ extern "C" {
           uint8_t btif_avrcp_get_ctl_trans_id(btif_avrcp_channel_t * channel);
           void btif_avrcp_set_ctl_trans_id(btif_avrcp_channel_t * channel, uint8_t trans_id);
       
      -    bt_status_t btif_avrcp_ct_set_absolute_volume(btif_avrcp_channel_t *channel, uint8_t volume);
      +    bt_status_t btif_avrcp_ct_set_absolute_volume(btif_avrcp_channel_t *channel, avrcp_advanced_pdu_t *_pdu, uint8_t volume);
       
      -    void btif_avrcp_set_channel_adv_event_mask(btif_avrcp_channel_t* handle, uint16_t mask);
      +    void btif_avrcp_set_channel_adv_event_mask(btif_avrcp_chnl_handle_t handle, uint16_t mask);
       
      -    bt_status_t btif_avrcp_tg_send_general_rsp(btif_avrcp_channel_t * channel, uint8_t op, uint8_t error_code, uint8_t trans_id, uint8_t ctype);
      +    bt_status_t btif_avrcp_tg_send_general_rsp(btif_avrcp_channel_t * channel, avrcp_advanced_pdu_t * cmd_pdu, uint8_t op, uint8_t error_code);
       
      -    bt_status_t btif_avrcp_ct_send_invalid_volume_rsp(btif_avrcp_channel_t * channel, uint8_t trans_id);
      +    bt_status_t btif_avrcp_ct_invalid_volume_rsp(btif_avrcp_channel_t * channel, avrcp_advanced_pdu_t * cmd_pdu);
       
       #if defined(IBRT)
           uint32_t btif_avrcp_profile_save_ctxs(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      -    uint32_t btif_avrcp_profile_restore_ctxs(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len);
      +    uint32_t btif_avrcp_profile_restore_ctxs(uint8_t *buf, uint32_t buf_len);
       #endif
       
       #ifdef __cplusplus
  • services/bt_if_enhanced/inc/bluetooth.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/bluetooth.h bes/services/bt_if_enhanced/inc/bluetooth.h
      index 9ca02517952..86e606b0648 100644
      --- a/services/bt_if_enhanced/inc/bluetooth.h
      +++ b/services/bt_if_enhanced/inc/bluetooth.h
      @@ -360,6 +360,7 @@ void store_be16(U8 *buff, U16 be_value);
        */
       void store_be32(U8 *buff, U32 be_value);
       
      +#if defined(ENHANCED_STACK)
       /* Copy, compare bluetooth Address */
       static inline int ba_cmp(const bt_bdaddr_t *ba1, const bt_bdaddr_t *ba2)
       {
      @@ -433,6 +434,7 @@ struct btif_ctx_content {
           unsigned char *buff;
           unsigned int buff_len;
       };
      +#endif /* ENHANCED_STACK */
       
       #ifdef __cplusplus
       }
  • services/bt_if_enhanced/inc/btgatt_api.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/btgatt_api.h bes/services/bt_if_enhanced/inc/btgatt_api.h
      index 64ecd86d301..9b1f51e4f88 100644
      --- a/services/bt_if_enhanced/inc/btgatt_api.h
      +++ b/services/bt_if_enhanced/inc/btgatt_api.h
      @@ -12,6 +12,7 @@
        * See the License for the specific language governing permissions and
        * limitations under the License.
        */
      +#ifdef __GATT_OVER_BR_EDR__
       #ifndef __BTGATT_API_H__
       #define __BTGATT_API_H__
       
      @@ -26,14 +27,15 @@
       #define BTIF_BTGATT_EVENT_CONTROL_DATA_SENT            0x24
       #define BTIF_BTGATT_EVENT_CONTROL_SET_IDLE             0x30
       
      +#define L2CAP_HEADER_LEN    4
       #define BTGATT_DATA_BUF_SIZE (L2CAP_CFG_MTU)
       #define BD_ADDR_LEN 6
       
       typedef uint16_t btif_btgatt_event;
       
      -typedef void (*btif_btgatt_status_change_callback)(uint8_t device_id,btif_btgatt_event event);
      +typedef void (*btif_btgatt_status_change_callback)(btif_btgatt_event event);
       
      -typedef void (*btif_btgatt_data_received_callback)(uint8_t, uint8_t*, uint16_t);
      +typedef void (*btif_btgatt_data_received_callback)(uint8_t*, uint16_t);
       
       typedef struct
       {
      @@ -43,7 +45,7 @@ typedef struct
       #ifdef __cplusplus
       extern "C" {
       #endif
      -uint8_t btif_btgatt_is_connected(void);
      +uint8_t btif_btgatt_is_connected(void);;
       void btif_btgatt_client_create(btif_remote_device_t *dev);
       void btif_btgatt_server_create(btif_btgatt_status_change_callback callback);
       void btif_btgatt_data_received_register(btif_btgatt_data_received_callback callback);
      @@ -54,7 +56,7 @@ uint8_t btif_btgatt_get_connection_index(void);
       int32_t btif_btgatt_get_l2cap_buffer_size(void);
       void btif_btgatt_get_device_address(uint8_t *addr);
       
      -void btif_btgatt_callback(uint8_t device_id, BtgattChannel *Chan, BtgattCallbackParms *Info);
      +void btif_btgatt_callback(BtgattChannel *Chan, BtgattCallbackParms *Info);
       uint32_t btif_btgatt_get_l2cap_handle(void);
       uint16_t btif_btgatt_get_conn_handle(void);
       void btif_btgatt_addsdp(uint16_t pServiceUUID, uint16_t startHandle, uint16_t endHandle);
      @@ -65,3 +67,4 @@ void btif_btgatt_addsdp(uint16_t pServiceUUID, uint16_t startHandle, uint16_t en
       #endif
       
       #endif
      +#endif
  • services/bt_if_enhanced/inc/bt_if.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/bt_if.h bes/services/bt_if_enhanced/inc/bt_if.h
      index 8f7c5e44971..483fc5daa9b 100644
      --- a/services/bt_if_enhanced/inc/bt_if.h
      +++ b/services/bt_if_enhanced/inc/bt_if.h
      @@ -20,33 +20,45 @@
       #include "me_api.h"
       
       //Application ID,indentify profle app context
      -#define    BTIF_APP_INVALID_ID              ((uint64_t)(0x0000000000000000))
      -#define    BTIF_APP_HFP_PROFILE_ID          ((uint64_t)(0x0000000000000001))
      -#define    BTIF_APP_A2DP_PROFILE_ID         ((uint64_t)(0x0000000000000002))
      -#define    BTIF_APP_AVRCP_PROFILE_ID        ((uint64_t)(0x0000000000000004))
      -#define    BTIF_APP_MAP_PROFILE_ID          ((uint64_t)(0X0000000000000008))
      -#define    BTIF_APP_BTGATT_PROFILE_ID       ((uint64_t)(0x0000000000000010))
      -
      -#define    BTIF_APP_SPP_SERVER_START_ID     ((uint64_t)(0x0000000000000020))
      -#define    BTIF_APP_SPP_SERVER_END_ID       ((uint64_t)(BTIF_APP_SPP_SERVER_START_ID << (BTIF_APP_SPP_SERVER_NUM - 1)))
      -#define    BTIF_APP_SPP_SERVER_OFFSET       (5)
      -#define    BTIF_APP_SPP_SERVER_NUM          (30)
      -#define    BTIF_APP_SPP_SERVER_MASK         ((uint64_t)(0x000000003FFFFFFF<<BTIF_APP_SPP_SERVER_OFFSET))
      -
      -#define    BTIF_APP_SPP_CLIENT_START_ID     ((uint64_t)(BTIF_APP_SPP_SERVER_END_ID << 1))
      -#define    BTIF_APP_SPP_CLIENT_NUM          (10)
      -#define    BTIF_APP_SPP_CLIENT_END_ID       ((uint64_t)(BTIF_APP_SPP_CLIENT_START_ID << (BTIF_APP_SPP_CLIENT_NUM - 1)))
      -#define    BTIF_APP_SPP_OFFSET              (5)
      -#define    BTIF_APP_SPP_NUM                 (BTIF_APP_SPP_SERVER_NUM+BTIF_APP_SPP_CLIENT_NUM)
      -#define    BTIF_APP_SPP_MASK                ((uint64_t)(0x000000FFFFFFFFFF<<BTIF_APP_SPP_OFFSET))
      +#define    BTIF_APP_INVALID_ID              (0x00000000u)
      +#define    BTIF_APP_HFP_PROFILE_ID          (0x00000001u)
      +#define    BTIF_APP_A2DP_PROFILE_ID         (0x00000002u)
      +#define    BTIF_APP_AVRCP_PROFILE_ID        (0x00000004u)
      +#define    BTIF_APP_MAP_PROFILE_ID          (0X00000008u)
      +#define    BTIF_APP_HID_PROFILE_ID          (0X00000010u)
      +
      +#define    BTIF_APP_SPP_SERVER_START_ID     (0x00000020u)
      +#define    BTIF_APP_SPP_SERVER_ID_1         (BTIF_APP_SPP_SERVER_START_ID)
      +#define    BTIF_APP_SPP_SERVER_ID_2         (BTIF_APP_SPP_SERVER_START_ID << 1)
      +#define    BTIF_APP_SPP_SERVER_ID_3         (BTIF_APP_SPP_SERVER_START_ID << 2)
      +#define    BTIF_APP_SPP_SERVER_ID_4         (BTIF_APP_SPP_SERVER_START_ID << 3)
      +#define    BTIF_APP_SPP_SERVER_ID_5         (BTIF_APP_SPP_SERVER_START_ID << 4)
      +#define    BTIF_APP_SPP_SERVER_ID_6         (BTIF_APP_SPP_SERVER_START_ID << 5)
      +#define    BTIF_APP_SPP_SERVER_ID_7         (BTIF_APP_SPP_SERVER_START_ID << 6)
      +#define    BTIF_APP_SPP_SERVER_ID_8         (BTIF_APP_SPP_SERVER_START_ID << 7)
      +#define    BTIF_APP_SPP_SERVER_ID_9         (BTIF_APP_SPP_SERVER_START_ID << 8)
      +#define    BTIF_APP_SPP_SERVER_ID_10        (BTIF_APP_SPP_SERVER_START_ID << 9)
      +#define    BTIF_APP_SPP_SERVER_END_ID       (BTIF_APP_SPP_SERVER_ID_10)
      +#define    BTIF_APP_SPP_SERVER_OFFSET       (4)
      +#define    BTIF_APP_SPP_SERVER_NUM          (10)
      +#define    BTIF_APP_SPP_SERVER_MASK         (0x000003FF<<BTIF_APP_SPP_SERVER_OFFSET)
      +
      +#define    BTIF_APP_SPP_CLIENT_START_ID     (BTIF_APP_SPP_SERVER_END_ID)
      +#define    BTIF_APP_SPP_CLIENT_ID_1         (BTIF_APP_SPP_CLIENT_START_ID << 1)
      +#define    BTIF_APP_SPP_CLIENT_ID_2         (BTIF_APP_SPP_CLIENT_START_ID << 2)
      +#define    BTIF_APP_SPP_CLIENT_ID_3         (BTIF_APP_SPP_CLIENT_START_ID << 3)
      +#define    BTIF_APP_SPP_CLIENT_END_ID       (BTIF_APP_SPP_CLIENT_ID_3)
      +#define    BTIF_APP_SPP_OFFSET              (4)
      +#define    BTIF_APP_SPP_NUM                 (13)
      +#define    BTIF_APP_SPP_MASK                (0x00001FFF<<BTIF_APP_SPP_OFFSET)
       
       #define    BTIF_TWS_LINK_CONNECTED          (1 << 0)
       #define    BTIF_TWS_L2CAP_CONNECTED         (1 << 1)
       
       
       #if defined(IBRT)
      -uint64_t btif_app_get_app_id_from_spp_flag(uint8_t spp_flag);
      -uint8_t btif_app_get_spp_flag_from_app_id(uint64_t app_id);
      +uint32_t btif_app_get_app_id_from_spp_flag(uint8_t spp_flag);
      +uint8_t btif_app_get_spp_flag_from_app_id(uint32_t app_id);
       #endif
       
       #ifdef __cplusplus
      @@ -75,13 +87,14 @@ static inline int bt_authing_init(authing_callback_t auth_cb)
           return 0;
       }
       #endif
      +int a2dp_codec_init(void);
       int bt_stack_config(const unsigned char *dev_name, uint8_t len);
       void btif_update_bt_name(const unsigned char *dev_name, uint8_t len);
       int bt_set_local_dev_name(const unsigned char *dev_name, uint8_t len);
       void bt_process_stack_events(void);
       void bt_generate_ecdh_key_pair(void);
      -uint8_t bt_get_max_sco_number(void);
      -void bt_set_max_sco_number(uint8_t sco_num);
      +uint8_t bt_get_sco_number(void);
      +void bt_set_sco_number(uint8_t sco_num);
       void bt_fast_init(uint8_t* bt_addr, uint8_t* ble_addr);
       
       void btif_set_btstack_chip_config(void *config);
  • services/bt_if_enhanced/inc/btif_sys_config.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/btif_sys_config.h bes/services/bt_if_enhanced/inc/btif_sys_config.h
      index ea9f1c640ef..9f97d1aefd1 100644
      --- a/services/bt_if_enhanced/inc/btif_sys_config.h
      +++ b/services/bt_if_enhanced/inc/btif_sys_config.h
      @@ -22,12 +22,12 @@
       
       #define BTIF_AV_WORKER  BTIF_ENABLED
       
      -#define SYS_MAX_A2DP_STREAMS (BT_DEVICE_NUM+BT_SOURCE_DEVICE_NUM)
      +#define SYS_MAX_A2DP_STREAMS    14
       
       #define BTIF_SBC_ENCODER   BTIF_ENABLED
       #define BTIF_SBC_DECODER   BTIF_ENABLED
       
      -#define SYS_MAX_AVRCP_CHNS  (BT_DEVICE_NUM+BT_SOURCE_DEVICE_NUM)
      +#define SYS_MAX_AVRCP_CHNS  2
       
       #define BTIF_AVRCP_NUM_PLAYER_SETTINGS 4
       
      @@ -85,6 +85,9 @@
       #define BTIF_SECURITY
       #define BTIF_BLE_APP_DATAPATH_SERVER
       
      +#if defined (__AI_VOICE__) || defined (BISTO_ENABLED)
      +#define BTIF_DIP_DEVICE
      +#endif
       
       //#define HF_CUSTOM_FEATURE_RESERVED          (0x01 << 0)
       #define BTIF_HF_CUSTOM_FEATURE_BATTERY_REPORT    (0x03 << 0)
      @@ -113,6 +116,7 @@
       
       #define  __BTIF_EARPHONE__
       
      +#define  __BTIF_AUTOPOWEROFF__
       
       #if !defined(BLE_ONLY_ENABLED)
       #define  __BTIF_BT_RECONNECT__
  • services/bt_if_enhanced/inc/bt_status_conv.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/bt_status_conv.h bes/services/bt_if_enhanced/inc/bt_status_conv.h
      index 5e5a136df32..d757b54acd6 100644
      --- a/services/bt_if_enhanced/inc/bt_status_conv.h
      +++ b/services/bt_if_enhanced/inc/bt_status_conv.h
      @@ -31,7 +31,7 @@ char *btstatus2str(BtStatus status);
       
       //static inline bt_status_t bt_convert_status(BtStatus stack_status)
       //{
      -//    // TRACE(0, "%s:input=%d%s,output=%d%s", __func__, stack_status, btstatus2str(stack_status), status_table[stack_status], btifstatus2str(status_table[stack_status]));
      +//    // TRACE("%s:input=%d%s,output=%d%s", __func__, stack_status, btstatus2str(stack_status), status_table[stack_status], btifstatus2str(status_table[stack_status]));
       //
       //    if (stack_status <= BT_STATUS_LAST_CODE)
       //        return status_table[stack_status];
  • services/bt_if_enhanced/inc/bt_xtal_sync.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/bt_xtal_sync.h bes/services/bt_if_enhanced/inc/bt_xtal_sync.h
      index 0c2bcc39695..8d2482659ba 100644
      --- a/services/bt_if_enhanced/inc/bt_xtal_sync.h
      +++ b/services/bt_if_enhanced/inc/bt_xtal_sync.h
      @@ -33,6 +33,7 @@ typedef struct {
           float Kd;
       }pid_para_t;
       void bt_xtal_sync_new(int32_t rxbit, bool fix_rxbit_en, enum BT_XTAL_SYNC_MODE_T mode);
      +void bt_xtal_sync_new_new(int32_t rxbit, bool fix_rxbit_en, enum BT_XTAL_SYNC_MODE_T mode);
       
       #endif
       void bt_init_xtal_sync(enum BT_XTAL_SYNC_MODE_T mode, int range_min, int range_max, int fcap_range);
  • services/bt_if_enhanced/inc/conmgr_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/conmgr_api.h bes/services/bt_if_enhanced/inc/conmgr_api.h
      index 32396401ee2..ea4867b6b63 100644
      --- a/services/bt_if_enhanced/inc/conmgr_api.h
      +++ b/services/bt_if_enhanced/inc/conmgr_api.h
      @@ -36,15 +36,15 @@ typedef void btif_cmgr_handler_t;
       #ifdef BISTO_ENABLED
       #define BTIF_CMGR_SNIFF_MIN_INTERVAL 160
       #else
      -#define BTIF_CMGR_SNIFF_MIN_INTERVAL (796)
      +#define BTIF_CMGR_SNIFF_MIN_INTERVAL 800
       #endif
       #endif /*  */
       
       #ifndef BTIF_CMGR_SNIFF_MAX_INTERVAL
       #ifdef BISTO_ENABLED
      -#define BTIF_CMGR_SNIFF_MAX_INTERVAL (160)
      +#define BTIF_CMGR_SNIFF_MAX_INTERVAL 160
       #else
      -#define BTIF_CMGR_SNIFF_MAX_INTERVAL (796)
      +#define BTIF_CMGR_SNIFF_MAX_INTERVAL 800
       #endif
       #endif /*  */
       
      @@ -59,6 +59,7 @@ typedef void btif_cmgr_handler_t;
       #define BTIF_CMGR_SNIFF_DISABLED    (0xFF)
       #define BTIF_CMGR_SNIFF_DONT_CARE   (0)
       #define BTIF_CMGR_SNIFF_TIMER       (10000)
      +#define BTIF_CMGR_TWS_SNIFF_TIMER       (10000)
       #define BTIF_CMGR_MOBILE_SNIFF_TIMER     (20000)
       
       typedef U8 btif_cmgr_sniff_exit_policy_t;
      @@ -105,14 +106,17 @@ typedef uint8_t cmgr_event_t;
       extern "C" {
       #endif                          /*  */
       
      +    btif_cmgr_handler_t *btif_cmgr_get_first_handler(btif_remote_device_t * remDev);
       
      +    bt_status_t btif_cmgr_set_sniff_exit_policy(btif_cmgr_handler_t * cmgr_handler,
      +                                                btif_cmgr_sniff_exit_policy_t Policy);
       
           bt_status_t btif_cmgr_set_sniff_timer(btif_cmgr_handler_t * cmgr_handler,
                                                 btif_sniff_info_t * SniffInfo, TimeT Time);
       
           uint32_t btif_cmgr_get_cmgrhandler_sniff_timeout(btif_cmgr_handler_t * cmgr_handler);
       
      -    uint16_t  btif_cmgr_get_cmgrhandler_sniff_interval(btif_cmgr_handler_t * cmgr_handler);
      +    uint16_t  btif_cmgr_get_cmgrhandler_sniff_Interval(btif_cmgr_handler_t * cmgr_handler);
       
           btif_sniff_info_t*btif_cmgr_get_cmgrhandler_sniff_info(btif_cmgr_handler_t *cmgr_handler);
       
      @@ -122,7 +126,7 @@ extern "C" {
       
           btif_handler *btif_cmgr_get_cmgrhandler_remdev_bthandle(btif_cmgr_handler_t *cmgr_handler);
       
      -    bt_status_t btif_cmgr_set_sniff_info_by_remdev(btif_sniff_info_t * SniffInfo,
      +    bt_status_t btif_cmgr_set_sniff_info_to_all_handler_by_remdev(btif_sniff_info_t * SniffInfo,
                                                                         btif_remote_device_t * remDev);
       
           bt_status_t btif_cmgr_set_sniff_timeout_handler_ext(void (*ext_fn)(evm_timer_t * timer,
      @@ -154,9 +158,11 @@ extern "C" {
                                                                   btif_cmgr_handler_t *cmgr_handler,
                                                                   uint8_t window);
       
      +    bt_status_t btif_cmgr_remove_audio_link(btif_cmgr_handler_t * cmgr_handler);
       
           bool btif_cmgr_is_audio_up(btif_cmgr_handler_t *Handler);
       
      +    bt_status_t btif_cmgr_set_master_role(btif_cmgr_handler_t *cmgr_handler, BOOL flag);
       
           void btif_evm_start_timer(evm_timer_t *timer, TimeT ms);
       
      @@ -181,6 +187,12 @@ extern "C" {
           bool btif_cmgr_is_link_up(btif_cmgr_handler_t *cmgr_handler);
           btif_remote_device_t *btif_cmgr_pts_get_remDev(btif_cmgr_handler_t *cmgr_handler);
       
      +#if defined(IBRT)
      +    uint32_t btif_save_cmgr_cxt(uint8_t * ctx_buffer);
      +    uint32_t btif_set_cmgr_cxt(uint8_t * ctx_buffer, uint8_t bt_devices_idx,uint8_t rm_devtbl_idx);
      +    uint32_t btif_save_avrcp_ctx(uint8_t * ctx_buffer);
      +    uint32_t btif_set_avrcp_ctx(uint8_t * ctx_buffer, uint8_t bt_devices_idx,uint8_t rm_devtbl_idx, uint8_t avd_ctx_device_idx);
      +#endif
       
       #ifdef __cplusplus
       }
  • services/bt_if_enhanced/inc/dip_api.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/dip_api.h bes/services/bt_if_enhanced/inc/dip_api.h
      index 8ae8f7919e1..dae8d83f434 100644
      --- a/services/bt_if_enhanced/inc/dip_api.h
      +++ b/services/bt_if_enhanced/inc/dip_api.h
      @@ -30,15 +30,7 @@ extern "C" {
       #endif
       
       typedef void btif_dip_client_t;
      -typedef struct
      -{
      -    uint16_t spec_id;
      -    uint16_t vend_id;
      -    uint16_t prod_id;
      -    uint16_t prod_ver;
      -    uint8_t  prim_rec;
      -    uint16_t vend_id_source;
      -} btif_dip_pnp_info;
      +typedef void dip_pnp_info;
       
       typedef void (*DipApiCallBack)(bt_bdaddr_t *_addr, bool ios_flag);
       
      @@ -48,6 +40,7 @@ bt_status_t btif_dip_query_for_service(btif_dip_client_t *client_t,btif_remote_d
       bool btif_dip_check_is_ios_device(btif_remote_device_t *btDevice);
       void btif_dip_get_remote_info(btif_remote_device_t *btDevice);
       bool btif_dip_get_process_status(btif_remote_device_t *btDevice);
      +void btif_dip_get_record_vend_id_and_source(bt_bdaddr_t *bdAddr, uint16_t *vend_id, uint16_t *vend_id_source);
       bool btif_dip_check_is_ios_by_vend_id(uint16_t vend_id, uint16_t vend_id_source);
       
       #ifdef __cplusplus
  • services/bt_if_enhanced/inc/hci_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/hci_api.h bes/services/bt_if_enhanced/inc/hci_api.h
      index 3fc8b2e4ec6..5b541a85977 100644
      --- a/services/bt_if_enhanced/inc/hci_api.h
      +++ b/services/bt_if_enhanced/inc/hci_api.h
      @@ -264,7 +264,7 @@ typedef void (*btif_bt_addr_exchanged_callback_func) (uint8_t * newBtAddr);
       typedef void (*btif_hci_vendor_event_callback_func)(uint8_t* pbuf, uint32_t length);
       
       #if defined(IBRT)
      -typedef uint8_t (*btif_hci_sync_airmode_check_ind_func)(uint8_t status, bt_bdaddr_t *bdaddr);
      +typedef bool (*btif_hci_sync_airmode_check_ind_func)(uint8_t status);
       
       typedef void (*btif_ibrt_connect_ind_callback_func)(uint16_t conhdl,uint8_t ret);
       
      @@ -327,6 +327,11 @@ extern "C" {
       #if defined(IBRT)
           void btif_register_hci_sync_airmode_check_ind_callback(btif_hci_sync_airmode_check_ind_func func);
           uint8_t btif_hci_disconnect_connection_direct(uint16_t conn_handle, uint8_t reason);
      +    uint8_t btif_hci_tws_switch_direct(uint8_t op);
      +    uint32_t btif_save_hci_ctx(uint8_t * ctx_buffer, uint16_t dev_id);
      +    uint32_t btif_set_hci_ctx(uint8_t* ctx_buffer, uint16_t dev_id);
      +    uint16_t btif_hci_get_con_hci_handle(uint8_t con_idx);
      +    uint8_t btif_hci_get_con_conflags(uint8_t con_idx);
           void btif_hci_register_tx_buf_tss_process_callback(btif_callback_ext3 cb);
       
       #endif
  • services/bt_if_enhanced/inc/hfp_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/hfp_api.h bes/services/bt_if_enhanced/inc/hfp_api.h
      index 9f45be3898e..c87b31a5711 100644
      --- a/services/bt_if_enhanced/inc/hfp_api.h
      +++ b/services/bt_if_enhanced/inc/hfp_api.h
      @@ -19,9 +19,13 @@
       #include "conmgr_api.h"
       #include "hci_api.h"
       
      -#define HF_CHANNEL_NUM (BT_DEVICE_NUM+BT_SOURCE_DEVICE_NUM)
      +#ifdef __BT_ONE_BRING_TWO__
      +#define HF_CHANNEL_NUM     2
      +#else
      +#define HF_CHANNEL_NUM     1
      +#endif
       
      -typedef struct { /* empty */ } btif_hf_channel_t; /* used to hold the pointer to struct _hshf_channel */
      +typedef void *hf_chan_handle_t;
       /* start of btif_audio_state_t*/
       typedef enum {
           BTIF_HF_AUDIO_DISCON = 0,
      @@ -108,55 +112,55 @@ typedef uint16_t hf_gateway_version;
       /* End of hf_gateway_version */
       
       typedef enum {
      -    BTIF_HF_EVENT_SERVICE_CONNECT_REQ = 1,
      -    BTIF_HF_EVENT_SERVICE_CONNECTED = 2,
      -    BTIF_HF_EVENT_SERVICE_DISCONNECTED = 3,
      -    BTIF_HF_EVENT_AUDIO_CONNECTED = 4,
      -    BTIF_HF_EVENT_AUDIO_DISCONNECTED = 5,
      -    BTIF_HF_EVENT_AUDIO_DATA = 6,
      -    BTIF_HF_EVENT_AUDIO_DATA_SENT = 7,
      -    BTIF_HF_EVENT_GATEWAY_FEATURES = 8,
      -    BTIF_HF_EVENT_GW_HOLD_FEATURES = 9,
      -    BTIF_HF_EVENT_CALL_STATE = 10,
      -    BTIF_HF_EVENT_CALLER_ID = 11,
      -    BTIF_HF_EVENT_CALL_LISTING_ENABLED = 12,
      -    BTIF_HF_EVENT_RESPONSE_HOLD_APPL = 13,
      -    BTIF_HF_EVENT_CALL_IND = 14,
      -    BTIF_HF_EVENT_CALLSETUP_IND = 15,
      -    BTIF_HF_EVENT_CALLHELD_IND = 16,
      -    BTIF_HF_EVENT_RING_IND = 17,
      -    BTIF_HF_EVENT_WAIT_NOTIFY = 18,
      -    BTIF_HF_EVENT_CALLER_ID_NOTIFY = 19,
      -    BTIF_HF_EVENT_CURRENT_CALL_STATE = 20,
      -    BTIF_HF_EVENT_RESPONSE_HOLD = 21,
      -    BTIF_HF_EVENT_SERVICE_IND = 22,
      -    BTIF_HF_EVENT_BATTERY_IND = 23,
      -    BTIF_HF_EVENT_SIGNAL_IND = 24,
      -    BTIF_HF_EVENT_ROAM_IND = 25,
      -    BTIF_HF_EVENT_SMS_IND = 26,
      -    BTIF_HF_EVENT_VOICE_REC_STATE = 27,
      -    BTIF_HF_EVENT_VOICE_TAG_NUMBER = 28,
      -    BTIF_HF_EVENT_SPEAKER_VOLUME = 29,
      -    BTIF_HF_EVENT_MIC_VOLUME = 30,
      -    BTIF_HF_EVENT_IN_BAND_RING = 31,
      -    BTIF_HF_EVENT_NETWORK_OPERATOR = 32,
      -    BTIF_HF_EVENT_SUBSCRIBER_NUMBER = 33,
      -    BTIF_HF_EVENT_NO_CARRIER = 34,
      -    BTIF_HF_EVENT_BUSY = 35,
      -    BTIF_HF_EVENT_NO_ANSWER = 36,
      -    BTIF_HF_EVENT_DELAYED = 37,
      -    BTIF_HF_EVENT_BLACKLISTED = 38,
      -    BTIF_HF_EVENT_PHONEBOOK_STORAGE = 39,
      -    BTIF_HF_EVENT_PHONEBOOK_INFO = 40,
      -    BTIF_HF_EVENT_PHONEBOOK_SIZE = 41,
      -    BTIF_HF_EVENT_PHONEBOOK_ENTRY = 42,
      -    BTIF_HF_EVENT_AT_RESULT_DATA = 43,
      -    BTIF_HF_EVENT_COMMAND_COMPLETE = 44,
      -    BTIF_HF_EVENT_SIRI_STATUS = 45,
      -    BTIF_HF_EVENT_READ_AG_INDICATORS_STATUS = 46,
      -    BTIF_HF_EVENT_BES_TEST = 47,
      -    BTIF_HF_EVENT_SELECT_CHANNEL = 48,
      -    BTIF_HF_EVENT_RFCOMM_CONNECTED = 49,
      +    BTIF_HF_EVENT_SERVICE_CONNECT_REQ = 0,
      +    BTIF_HF_EVENT_SERVICE_CONNECTED = 1,
      +    BTIF_HF_EVENT_SERVICE_DISCONNECTED = 2,
      +    BTIF_HF_EVENT_AUDIO_CONNECTED = 3,
      +    BTIF_HF_EVENT_AUDIO_DISCONNECTED = 4,
      +    BTIF_HF_EVENT_AUDIO_DATA = 5,
      +    BTIF_HF_EVENT_AUDIO_DATA_SENT = 6,
      +    BTIF_HF_EVENT_GATEWAY_FEATURES = 7,
      +    BTIF_HF_EVENT_GW_HOLD_FEATURES = 8,
      +    BTIF_HF_EVENT_CALL_STATE = 9,
      +    BTIF_HF_EVENT_CALLER_ID = 10,
      +    BTIF_HF_EVENT_CALL_LISTING_ENABLED = 11,
      +    BTIF_HF_EVENT_RESPONSE_HOLD_APPL = 12,
      +    BTIF_HF_EVENT_CALL_IND = 13,
      +    BTIF_HF_EVENT_CALLSETUP_IND = 14,
      +    BTIF_HF_EVENT_CALLHELD_IND = 15,
      +    BTIF_HF_EVENT_RING_IND = 16,
      +    BTIF_HF_EVENT_WAIT_NOTIFY = 17,
      +    BTIF_HF_EVENT_CALLER_ID_NOTIFY = 18,
      +    BTIF_HF_EVENT_CURRENT_CALL_STATE = 19,
      +    BTIF_HF_EVENT_RESPONSE_HOLD = 20,
      +    BTIF_HF_EVENT_SERVICE_IND = 21,
      +    BTIF_HF_EVENT_BATTERY_IND = 22,
      +    BTIF_HF_EVENT_SIGNAL_IND = 23,
      +    BTIF_HF_EVENT_ROAM_IND = 24,
      +    BTIF_HF_EVENT_SMS_IND = 25,
      +    BTIF_HF_EVENT_VOICE_REC_STATE = 26,
      +    BTIF_HF_EVENT_VOICE_TAG_NUMBER = 27,
      +    BTIF_HF_EVENT_SPEAKER_VOLUME = 28,
      +    BTIF_HF_EVENT_MIC_VOLUME = 29,
      +    BTIF_HF_EVENT_IN_BAND_RING = 30,
      +    BTIF_HF_EVENT_NETWORK_OPERATOR = 31,
      +    BTIF_HF_EVENT_SUBSCRIBER_NUMBER = 32,
      +    BTIF_HF_EVENT_NO_CARRIER = 33,
      +    BTIF_HF_EVENT_BUSY = 34,
      +    BTIF_HF_EVENT_NO_ANSWER = 35,
      +    BTIF_HF_EVENT_DELAYED = 36,
      +    BTIF_HF_EVENT_BLACKLISTED = 37,
      +    BTIF_HF_EVENT_PHONEBOOK_STORAGE = 38,
      +    BTIF_HF_EVENT_PHONEBOOK_INFO = 39,
      +    BTIF_HF_EVENT_PHONEBOOK_SIZE = 40,
      +    BTIF_HF_EVENT_PHONEBOOK_ENTRY = 41,
      +    BTIF_HF_EVENT_AT_RESULT_DATA = 42,
      +    BTIF_HF_EVENT_COMMAND_COMPLETE = 43,
      +    BTIF_HF_EVENT_SIRI_STATUS = 44,
      +    BTIF_HF_EVENT_READ_AG_INDICATORS_STATUS = 45,
      +    BTIF_HF_EVENT_BES_TEST = 46,
      +    BTIF_HF_EVENT_SELECT_CHANNEL = 47,
      +    BTIF_HF_EVENT_RFCOMM_CONNECTED = 48,
       } hf_event_t;
       
       /* End of hf_event_t*/
      @@ -177,8 +181,8 @@ struct hfp_context {
           uint8_t error_code;
           uint8_t disc_reason;
           uint8_t disc_reason_saved;
      -    uint8_t speaker_volume;
      -    uint8_t voice_rec_state;
      +    uint32_t speaker_volume;
      +    uint32_t voice_rec_state;
           uint32_t **chan_sel_channel;
           btif_remote_device_t *chan_sel_remDev;
           char *ptr;
      @@ -191,7 +195,7 @@ struct hfp_vendor_info {
           uint16_t feature_id;  //default is 3, if you do not known, set it 0
       };
       
      -typedef void (*hf_event_cb_t) (uint8_t device_id, btif_hf_channel_t* chan, struct hfp_context * ctx);
      +typedef void (*hf_event_cb_t) (hf_chan_handle_t chan, struct hfp_context * ctx);
       
       #ifdef __cplusplus
       extern "C" {
      @@ -203,123 +207,129 @@ extern "C" {
            */
           void btif_hf_init_vendor_info(struct hfp_vendor_info *info_ptr);
       
      +    int hfp_hfcommand_mempool_init(void);
       
           int btif_hfp_initialize(void);
       
           int btif_hf_register_callback(hf_event_cb_t callback);
       
      -    hf_gateway_version btif_hf_get_version(btif_hf_channel_t* chan_h);
      +    hf_gateway_version btif_hf_get_version(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_update_indicators_batt_level(btif_hf_channel_t* chan_h, uint32_t level);
      +    bt_status_t btif_hf_update_indicators_batt_level(hf_chan_handle_t chan_h, uint8_t assigned_num, uint8_t level);
       
      -    bt_status_t btif_hf_batt_report(btif_hf_channel_t* chan_h, uint8_t level);
      +    bt_status_t btif_hf_batt_report(hf_chan_handle_t chan_h, uint8_t level);
       
      +    bt_status_t btif_hf_siri_report(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_enable_voice_recognition(btif_hf_channel_t* chan_h, bool en);
      +    bt_status_t btif_hf_enable_voice_recognition(hf_chan_handle_t chan_h, bool en);
       
      -    bt_status_t btif_hf_batt_report(btif_hf_channel_t* chan_h, uint8_t level);
      +    bt_status_t btif_hf_batt_report(hf_chan_handle_t chan_h, uint8_t level);
       
      -    bool btif_hf_is_voice_rec_active(btif_hf_channel_t* chan_h);
      +    bool btif_hf_is_voice_rec_active(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_disable_nrec(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_disable_nrec(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_report_speaker_volume(btif_hf_channel_t* chan_h, uint8_t gain);
      +    bt_status_t btif_hf_report_speaker_volume(hf_chan_handle_t chan_h, uint8_t gain);
       
      -    bt_status_t btif_hf_send_at_cmd(btif_hf_channel_t* chan_h, const char *at_str);
      +    bt_status_t btif_hf_send_at_cmd(hf_chan_handle_t chan_h, const char *at_str);
       
      -    bt_status_t btif_hf_list_current_calls(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_list_current_calls(hf_chan_handle_t chan_h);
       
      -    bool btif_hf_is_hf_indicators_support(btif_hf_channel_t* chan_h);
      +    bool btif_hf_is_hf_indicators_support(hf_chan_handle_t chan_h);
       
      -    bool btif_hf_is_batt_report_support(btif_hf_channel_t* chan_h);
      +    bool btif_hf_is_batt_report_support(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_force_disconnect_sco(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_force_disconnect_sco(hf_chan_handle_t chan_h);
       
      -    void btif_hf_set_negotiated_codec(btif_hf_channel_t* chan_h, hfp_sco_codec_t codec);
      +    void btif_hf_set_negotiated_codec(hf_chan_handle_t chan_h, hfp_sco_codec_t codec);
       
      -    hfp_sco_codec_t btif_hf_get_negotiated_codec(btif_hf_channel_t* chan_h);
      +    hfp_sco_codec_t btif_hf_get_negotiated_codec(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_answer_call(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_answer_call(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_hang_up_call(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_hang_up_call(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_redial_call(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_redial_call(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_dial_number(btif_hf_channel_t* chan_h, uint8_t *number, uint16_t len);
      +    bt_status_t btif_hf_dial_number(hf_chan_handle_t chan_h, uint8_t *number, uint16_t len);
       
      -    bt_status_t btif_hf_disc_audio_link(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_disc_audio_link(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_create_audio_link(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_create_audio_link(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_call_hold(btif_hf_channel_t* chan_h, btif_hf_hold_call_t action,
      +    bt_status_t btif_hf_call_hold(hf_chan_handle_t chan_h, btif_hf_hold_call_t action,
                                         uint8_t index);
      -    bt_status_t btif_hf_switch_calls(btif_hf_channel_t* hangup_chan_h,
      -                                     btif_hf_channel_t* answer_chan_h);
      +    bt_status_t btif_hf_switch_calls(hf_chan_handle_t hangup_chan_h,
      +                                     hf_chan_handle_t answer_chan_h);
       
      -    btif_hf_channel_t* btif_get_hf_chan_by_address(bt_bdaddr_t *bdaddr);
      +    hf_chan_handle_t btif_get_hf_chan_by_address(bt_bdaddr_t *bdaddr);
       
      -    uint8_t btif_get_hf_chan_audio_up_flag(btif_hf_channel_t* chan_h);
      +    uint8_t btif_get_hf_chan_audio_up_flag(hf_chan_handle_t chan_h);
       
      -    btif_hf_chan_state_t btif_get_hf_chan_state(btif_hf_channel_t* chan_h);
      +    btif_hf_chan_state_t btif_get_hf_chan_state(hf_chan_handle_t chan_h);
       
      -    bool btif_hf_check_AudioConnect_status(btif_hf_channel_t* chan_h);
      +    bool btif_hf_check_AudioConnect_status(hf_chan_handle_t chan_h);
       
      +    hf_chan_handle_t btif_hf_create_channel(void);
       
      -    int btif_hf_init_channel(btif_hf_channel_t* chan_h);
      +    int btif_hf_init_channel(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_disconnect_service_link(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_disconnect_service_link(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_create_service_link(bt_bdaddr_t * bt_addr);
      +    bt_status_t btif_hf_create_service_link(hf_chan_handle_t chan_h, bt_bdaddr_t * bt_addr);
       
      -    btif_cmgr_handler_t *btif_hf_get_chan_manager_handler(btif_hf_channel_t* chan_h);
      +    btif_cmgr_handler_t *btif_hf_get_chan_manager_handler(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hfp_switch_sco(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hfp_switch_sco(hf_chan_handle_t chan_h);
       
      -    bt_status_t btif_hf_set_master_role(btif_hf_channel_t* chan_h, bool role);
      +    bt_status_t btif_hf_set_master_role(hf_chan_handle_t chan_h, bool role);
       
      -    bt_status_t btif_hf_enable_sniff_mode(btif_hf_channel_t* chan_h, bool enable);
      +    bt_status_t btif_hf_enable_sniff_mode(hf_chan_handle_t chan_h, bool enable);
       
      -    bool btif_hf_get_remote_bdaddr(btif_hf_channel_t* chan_h, bt_bdaddr_t *bdaddr_p);
      +    bool btif_hf_get_remote_bdaddr(hf_chan_handle_t chan_h, bt_bdaddr_t *bdaddr_p);
       
      -    uint16_t btif_hf_get_sco_hcihandle(btif_hf_channel_t* chan_h);
      +    uint16_t btif_hf_get_sco_hcihandle(hf_chan_handle_t chan_h);
       
      -    btif_hci_handle_t btif_hf_get_remote_hci_handle(btif_hf_channel_t* chan_h);
      +    btif_hci_handle_t btif_hf_get_remote_hci_handle(hf_chan_handle_t chan_h);
       
      -    bool btif_hf_is_acl_connected(btif_hf_channel_t* chan_h);
      +    bool btif_hf_is_acl_connected(hf_chan_handle_t chan_h);
       
      -    btif_remote_device_t *btif_hf_cmgr_get_remote_device(btif_hf_channel_t* chan_h);
      +    btif_remote_device_t *btif_hf_cmgr_get_remote_device(hf_chan_handle_t chan_h);
       
           bool btif_hf_check_rfcomm_l2cap_channel_is_creating(bt_bdaddr_t *bdaddr);
       
      -    bt_status_t btif_hf_send_audio_data(btif_hf_channel_t* chan_h, btif_bt_packet_t *packet);
      +    bt_status_t btif_hf_send_audio_data(hf_chan_handle_t chan_h, btif_bt_packet_t *packet);
       
      -    bt_status_t btif_hf_is_inbandring_enabled(btif_hf_channel_t* chan_h);
      +    bt_status_t btif_hf_is_inbandring_enabled(hf_chan_handle_t chan_h);
       
           uint32_t btif_hfp_profile_save_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
       
      -    uint32_t btif_hfp_profile_restore_ctx(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len);
      +    uint32_t btif_hfp_profile_restore_ctx(uint8_t *buf, uint32_t buf_len);
       
       #if defined(IBRT)
           bt_status_t btif_hf_sync_conn_audio_connected(hfp_sco_codec_t codec,uint16_t conhdl);
           bt_status_t btif_hf_sync_conn_audio_disconnected(uint16_t conhdl);
      +    btif_hf_chan_state_t btif_hfp_profile_channel_state(uint8_t bt_device_id);
       #endif
       
      -    bt_status_t btif_hf_indicators_1(btif_hf_channel_t* chan_h);
      -    bt_status_t btif_hf_indicators_2(btif_hf_channel_t* chan_h);
      -    bt_status_t btif_hf_indicators_3(btif_hf_channel_t* chan_h);
      -
      -    bt_status_t btif_ag_create_service_link(btif_hf_channel_t* chan_h, bt_bdaddr_t * bt_addr);
      -    bt_status_t btif_ag_disconnect_service_link(btif_hf_channel_t* chan_h);
      -    bt_status_t btif_ag_create_audio_link(btif_hf_channel_t* chan_h);
      -    bt_status_t btif_ag_disc_audio_link(btif_hf_channel_t* chan_h);
      -    bt_status_t btif_ag_send_call_active_status(btif_hf_channel_t* chan_h, bool active);
      -    bt_status_t btif_ag_send_callsetup_status(btif_hf_channel_t* chan_h, uint8_t status);
      -    bt_status_t btif_ag_send_callheld_status(btif_hf_channel_t* chan_h, uint8_t status);
      -    bt_status_t btif_ag_send_calling_ring(btif_hf_channel_t* chan_h, const char* number);
      -    bt_status_t btif_ag_set_speaker_gain(btif_hf_channel_t* chan_h, uint8_t volume);
      -    bt_status_t btif_ag_set_microphone_gain(btif_hf_channel_t* chan_h, uint8_t volume);
      -    bt_status_t btif_ag_send_result_code(btif_hf_channel_t* chan_h, const char *data, int len);
      -    bt_status_t btif_ag_register_module_handler(btif_hf_channel_t* chan_h, struct btif_ag_module_handler* handler);
      +    bt_status_t btif_hf_indicators_1(hf_chan_handle_t chan_h);
      +    bt_status_t btif_hf_indicators_2(hf_chan_handle_t chan_h);
      +    bt_status_t btif_hf_indicators_3(hf_chan_handle_t chan_h);
      +
      +#if defined(HFP_MOBILE_AG_ROLE)
      +    bt_status_t btif_ag_create_service_link(hf_chan_handle_t chan_h, bt_bdaddr_t * bt_addr);
      +    bt_status_t btif_ag_disconnect_service_link(hf_chan_handle_t chan_h);
      +    bt_status_t btif_ag_create_audio_link(hf_chan_handle_t chan_h);
      +    bt_status_t btif_ag_disc_audio_link(hf_chan_handle_t chan_h);
      +    bt_status_t btif_ag_send_call_active_status(hf_chan_handle_t chan_h, bool active);
      +    bt_status_t btif_ag_send_callsetup_status(hf_chan_handle_t chan_h, uint8_t status);
      +    bt_status_t btif_ag_send_callheld_status(hf_chan_handle_t chan_h, uint8_t status);
      +    bt_status_t btif_ag_send_calling_ring(hf_chan_handle_t chan_h, const char* number);
      +    bt_status_t btif_ag_set_speaker_gain(hf_chan_handle_t chan_h, uint8_t volume);
      +    bt_status_t btif_ag_set_microphone_gain(hf_chan_handle_t chan_h, uint8_t volume);
      +    bt_status_t btif_ag_send_result_code(hf_chan_handle_t chan_h, const char *data, int len);
      +    bt_status_t btif_ag_register_mobile_module(hf_chan_handle_t chan_h, struct hfp_mobile_module_handler* handler);
      +#endif
       
       #ifdef __cplusplus
       }
  • services/bt_if_enhanced/inc/hid_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/hid_api.h bes/services/bt_if_enhanced/inc/hid_api.h
      index 57a885f2666..70ac908f81c 100644
      --- a/services/bt_if_enhanced/inc/hid_api.h
      +++ b/services/bt_if_enhanced/inc/hid_api.h
      @@ -40,7 +40,7 @@ typedef struct
           bt_bdaddr_t remote;
       } btif_hid_callback_param_t;
       
      -void btif_hid_init(void (*cb)(uint8_t device_id, struct hid_control_t *hid_ctl, const struct hid_callback_parms_t *info), hid_role_enum_t role);
      +void btif_hid_init(void (*cb)(struct hid_control_t *hid_ctl, const struct hid_callback_parms_t *info), hid_role_enum_t role);
       
       struct hid_control_t *btif_hid_channel_alloc(void);
       
      @@ -56,6 +56,12 @@ void btif_hid_keyboard_input_report(struct hid_control_t *hid_ctl, uint8_t modif
       
       void btif_hid_keyboard_send_ctrl_key(struct hid_control_t *hid_ctl, uint8_t ctrl_key);
       
      +#if defined(IBRT)
      +uint32_t hid_save_ctx(struct hid_control_t *hid_ctl, uint8_t *buf, uint32_t buf_len);
      +uint32_t hid_restore_ctx(struct hid_ctx_input *input);
      +uint32_t btif_hid_profile_save_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      +uint32_t btif_hid_profile_restore_ctx(uint8_t *buf, uint32_t buf_len);
      +#endif
       
       #ifdef __cplusplus
       }
  • services/bt_if_enhanced/inc/l2cap_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/l2cap_api.h bes/services/bt_if_enhanced/inc/l2cap_api.h
      index f0fb67518ca..b119c014a32 100644
      --- a/services/bt_if_enhanced/inc/l2cap_api.h
      +++ b/services/bt_if_enhanced/inc/l2cap_api.h
      @@ -90,11 +90,11 @@ extern "C" {
       #endif
       
       #if defined(IBRT)
      -    bool btif_l2cap_is_profile_channel_connected(btif_remote_device_t *p_dev, uint8_t psm_context_mask);
      +    bool btif_l2cap_is_profile_channel_connected(uint8_t psm_context_mask);
       #endif
      -    void btif_l2cap_register_sdp_disconnect_callback(void (*cb)(const void* addr));
      -    void btif_btm_register_get_ibrt_role_callback(uint8_t (*cb)(const void* addr));
      -    void btif_btm_register_get_tss_state_callback(uint8_t (*cb)(const void* addr));
      +    void btif_l2cap_register_sdp_disconnect_callback(btif_callback cb);
      +    void btif_btm_register_get_ibrt_role_callback(btif_callback_ext cb);
      +     void btif_btm_register_get_tss_state_callback(btif_callback_ext cb);
           btif_l2cap_channel_t *btif_l2cap_alloc_channel_instance(uint16_t index);
           btif_l2cap_channel_t *btif_l2cap_get_l2cap_channel_instance(uint16_t index);
           uint16_t btif_l2cap_cid_to_index(uint16_t index);
  • services/bt_if_enhanced/inc/map_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/map_api.h bes/services/bt_if_enhanced/inc/map_api.h
      index 043bf00c5ec..42124267220 100644
      --- a/services/bt_if_enhanced/inc/map_api.h
      +++ b/services/bt_if_enhanced/inc/map_api.h
      @@ -16,6 +16,7 @@
       #define __MAP_API_H__
       
       #include "bluetooth.h"
      +#include "obex_api.h"
       
       #ifdef __cplusplus
       extern "C" {
      @@ -103,12 +104,14 @@ bool btif_map_check_is_connected(btif_map_session_handle_t handle);
       void btif_map_callback_register(btif_map_callback_t callback);
       bool btif_map_check_is_idle(btif_map_session_handle_t handle);
       #if defined(IBRT)
      +#ifdef __BTMAP_ENABLE__
       uint32_t btif_map_get_server_chnl(void);
       uint32_t map_save_ctx(uint32_t server_chnl, uint32_t conn_id,uint8_t *buf, uint32_t buf_len);
       uint32_t map_restore_ctx(bt_bdaddr_t *remote,uint32_t connection_id,uint32_t server_chnl);
       uint32_t btif_map_get_rfcomm_handle(void);
       uint32_t btif_map_profile_save_ctx(uint8_t *buf, uint32_t buf_len);
      -uint32_t btif_map_profile_restore_ctx(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len);
      +uint32_t btif_map_profile_restore_ctx(uint8_t *buf, uint32_t buf_len);
      +#endif
       #endif
       
       #ifdef __cplusplus
  • services/bt_if_enhanced/inc/me_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/me_api.h bes/services/bt_if_enhanced/inc/me_api.h
      index cae6047794f..4053135443d 100644
      --- a/services/bt_if_enhanced/inc/me_api.h
      +++ b/services/bt_if_enhanced/inc/me_api.h
      @@ -37,7 +37,7 @@ typedef uint8_t btif_event_type_t;
       
       #define BTIF_BTEVENT_LINK_CONNECT_CNF     7
       
      -#define BTIF_BTEVENT_ROLE_DISCOVERED      8
      +#define BTIF_BTEVENT_LINK_CON_RESTRICT    8
       
       #define BTIF_BTEVENT_MODE_CHANGE          9
       
      @@ -241,7 +241,7 @@ typedef uint32_t btif_event_mask_t;
       #define BTIF_BEM_SCO_CONNECT_IND              0x00000010
       #define BTIF_BEM_LINK_DISCONNECT              0x00000020
       #define BTIF_BEM_LINK_CONNECT_CNF             0x00000040
      -#define BTIF_BEM_ROLE_DISCOVERED              0x00000080
      +#define BTIF_BEM_LINK_CON_RESTRICT            0x00000080
       #define BTIF_BEM_MODE_CHANGE                  0x00000100
       #define BTIF_BEM_ACCESSIBLE_CHANGE            0x00000200
       #define BTIF_BEM_AUTHENTICATED                0x00000400
      @@ -442,15 +442,16 @@ typedef enum {
       #define BTIF_BTSS_DEINITIALIZE    3
       
       /* End of BtStackState */
      -typedef struct { /* empty */ } btif_remote_device_t; /* used to hold the pointer to btm_conn_item_t */
      +typedef void btif_remote_device_t;
       
       
      +typedef void btif_BtDeviceContext;
       
       
       /* Forward declaration of the callback parameters */
      -typedef struct { /* empty */ } btif_event_t; /* used to hold the pointer to event */
      +typedef void btif_event_t;
       
      -typedef void (*btif_callback) (const btif_event_t *);
      +typedef void (*btif_callback) (const void *);
       typedef void (*ibrt_cmd_status_callback)(const uint8_t *para);
       typedef void (*ibrt_cmd_complete_callback)(const uint8_t *para);
       typedef uint8_t (*btif_callback_ext) (const void *);
      @@ -738,7 +739,7 @@ typedef struct {
       
       typedef struct {
           bt_bdaddr_t bdAddr;
      -    bool trusted;
      +    BOOL trusted;
           uint8_t linkKey[16];
           btif_link_key_type_t keyType;
       
      @@ -1115,7 +1116,7 @@ typedef struct
           btif_event_mask_t mask;
       } me_event_t;
       typedef bool (*ibrt_io_capbility_callback)(void *bdaddr);
      -typedef void (*ibrt_disconnect_callback)(const btif_event_t *event);
      +typedef void (*ibrt_disconnect_callback)(const void *event);
       typedef void (*btif_cmgr_callback) (void *handler, uint8_t event, bt_status_t status);
       typedef void (*btif_global_handle)(const btif_event_t *Event);
       
      @@ -1180,6 +1181,7 @@ extern "C" {
       
           btif_remote_device_t *btif_me_get_callback_event_rem_dev(const btif_event_t * event);
       
      +    btif_BtDeviceContext* btif_me_get_bt_device_context(const btif_event_t * event);
       
           uint16_t btif_me_get_scohdl_by_connhdl(uint16_t conn_handle);
           btif_remote_device_t *btif_me_get_callback_event_sco_connect_rem_dev(const btif_event_t *
      @@ -1264,6 +1266,7 @@ extern "C" {
                                                                 btif_remote_device_t * rdev,
                                                                 uint8_t reason, BOOL forceDisconnect);
       
      +    void btif_me_sec_set_io_cap_rsp_reject_ext(BOOL(*ext_fn) (void *));
           void btif_me_write_bt_sleep_enable(uint8_t sleep_en);
           void btif_me_write_bt_page_scan_type(uint8_t scan_type);
           void btif_me_write_bt_inquiry_scan_type(uint8_t scan_type);
      @@ -1280,7 +1283,7 @@ extern "C" {
           bt_status_t btif_bind_cmgr_handler(void *cmgr_handler, bt_bdaddr_t * bdAddr,btif_cmgr_callback Callback);
           bt_status_t btif_create_acl_to_slave(void *cmgr_handler, bt_bdaddr_t * bdAddr,btif_cmgr_callback Callback);
           bt_status_t btif_register_cmgr_handle(void *cmgr_handler,btif_cmgr_callback Callback);
      -    void btif_register_remote_is_mobile_func(bool (*cb)(void* remote));
      +    void btif_me_update_cmgr_info(void *cmgr_handler,btif_BtDeviceContext* bt_device_context,btif_remote_device_t * rdev);
           void btif_me_unregister_globa_handler(btif_handler * handler);
           void btif_me_set_inquiry_mode(uint8_t mode);
           void btif_me_inquiry_result_setup(uint8_t *inquiry_buff, bool rssi,
      @@ -1320,18 +1323,21 @@ extern "C" {
       
           bt_status_t btif_me_enable_fastack(uint16_t conhdl, uint8_t direction, uint8_t enable);
           bt_status_t btif_me_start_ibrt(U16 slaveConnHandle, U16 mobileConnHandle);
      -    bt_status_t btif_me_stop_ibrt(uint16_t mobile_conhdl,uint8_t reason);
      +    bt_status_t btif_me_stop_ibrt(uint8_t enable,uint8_t reason);
           bt_status_t btif_me_suspend_ibrt(void);
           bt_status_t btif_me_ibrt_mode_init(bool enable);
      -    bt_status_t btif_me_ibrt_role_switch(uint16_t mobile_conhdl);
      +    bt_status_t btif_me_ibrt_role_switch(uint8_t switch_op);
       
      +    void btif_me_set_ibrt_mobile_hci_handle(uint16_t hci_handle);
      +    uint16_t btif_me_get_ibrt_mobile_hci_handle(void);
       
      -    void btif_me_set_devctx_state(uint8_t acl_array_idx, uint16_t state);
      -    void btif_me_set_devctx_link(uint8_t acl_array_idx, btif_remote_device_t * rm_dev);
      -    bt_bdaddr_t*  btif_me_get_devctx_btaddr(uint8_t acl_array_idx);
      -    btif_remote_device_t* btif_me_get_remote_device(uint8_t acl_array_idx);
      +    void btif_me_set_devctx_state(uint8_t ctx_idx, uint16_t state);
      +    void btif_me_set_devctx_link(uint8_t ctx_idx, btif_remote_device_t * rm_dev);
      +    bt_bdaddr_t*  btif_me_get_devctx_btaddr(uint8_t ctx_idx);
      +    btif_remote_device_t* btif_me_get_remote_device(uint8_t dev_index);
           void btif_me_free_tws_outgoing_dev(uint8_t *peer_tws_addr);
      -    btif_remote_device_t*  btif_me_get_devctx_remote_device(uint8_t acl_array_idx);
      +    btif_remote_device_t*  btif_me_get_devctx_remote_device(uint8_t ctx_idx);
      +    btif_remote_device_t * btif_me_avdev_ctx_get_conn_remote_device(uint8_t dev_idx);
       
           uint32_t btif_me_save_record_ctx(uint8_t *ctx_buffer, uint8_t *addr);
           uint32_t btif_me_set_record_ctx(uint8_t *ctx_buffer,  uint8_t *addr);
      @@ -1350,8 +1356,9 @@ extern "C" {
           void btif_me_write_scan_activity_specific(uint16_t opcode, uint16_t scan_interval, uint16_t scan_window);
           void btif_me_write_dbg_sniffer(const uint8_t subcode, const uint16_t connhandle);
           void btif_me_ibrt_simu_hci_event_disallow(uint8_t opcode1, uint8_t opcode2);
      -    void btif_me_register_cmd_status_callback(void (*cb)(const void *para));
      -    void btif_me_register_cmd_complete_callback(HCI_CMD_COMPLETE_USER_E index, void (*cb)(const btif_event_t *para));
      +    void btif_me_register_conn_req_pre_treatment_callback(btif_callback cb);
      +    void btif_me_register_cmd_status_callback(btif_callback cb);
      +    void btif_me_register_cmd_complete_callback(HCI_CMD_COMPLETE_USER_E index,btif_callback cb);
           bt_status_t btif_me_ibrt_conn_connected(bt_bdaddr_t *bt_addr, uint16_t conhdl);
           bt_status_t btif_me_ibrt_conn_disconnected(bt_bdaddr_t *bt_addr, uint16_t conhdl, uint8_t status, uint8_t reason);
           void btif_me_register_ibrt_io_capbility_callback(ibrt_io_capbility_callback cb);
  • services/bt_if_enhanced/inc/rfcomm_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/rfcomm_api.h bes/services/bt_if_enhanced/inc/rfcomm_api.h
      index 6370b0636d0..389c8a3dfa0 100644
      --- a/services/bt_if_enhanced/inc/rfcomm_api.h
      +++ b/services/bt_if_enhanced/inc/rfcomm_api.h
      @@ -217,9 +217,9 @@ struct rf_service
       struct _rf_channel
       {
           rf_callback_func callback;
      -    uint8_t server_channel;
      +    int8_t server_channel;
           uint32_t rfcomm_handle;
      -    uint64_t app_id;
      +    uint32_t app_id;
           void *priv;
           list_entry_t tx_queue;
       };
      @@ -275,18 +275,31 @@ bool btif_rf_credit_flow_enabled(rf_channel_t chan_h);
       bt_status_t btif_rf_setup_channel(rf_channel_t chan_h, struct rf_chan_info *info);
       
       void *btif_rf_get_channel_priv(rf_channel_t chan);
      -uint64_t btif_rf_get_app_id(rf_channel_t chan_h);
      +uint32_t btif_rf_get_app_id(rf_channel_t chan_h);
       
       uint32_t btif_rf_get_rfcomm_handle(rf_channel_t chan_h);
       bt_status_t btif_rf_set_rfcomm_handle(rf_channel_t chan_h, uint32_t rfcomm_handle);
       uint8_t btif_rf_get_server_channel(rf_channel_t chan_h);
       
       uint16_t btif_rf_max_frame_size_configure(void);
      -void btif_rf_set_app_id(rf_channel_t chan_h,uint64_t app_id);
      +void btif_rf_set_app_id(rf_channel_t chan_h,uint32_t app_id);
       
       #if defined(IBRT)
      +#if defined(ENHANCED_STACK)
      +uint32_t btif_save_rfc_ctx(uint8_t *ctx_buffer, uint8_t MuxId);
      +uint32_t btif_set_rfc_ctx(uint8_t* ctx_buffer, uint16_t MuxId, uint8_t rm_devtbl_idx);
       uint32_t btif_rfc_get_session_l2c_handle(uint16_t hci_handle);
      -bool btif_rfc_is_dlci_channel_connected(uint32_t session_l2c_handle,uint64_t app_id);
      +bool btif_rfc_is_dlci_channel_connected(uint32_t session_l2c_handle,uint32_t app_id);
      +#else
      +uint32_t btif_save_rfc_ctx(uint8_t *ctx_buffer, uint8_t MuxId);
      +uint32_t btif_set_rfc_ctx(uint8_t* ctx_buffer, uint16_t MuxId, uint8_t rm_devtbl_idx);
      +uint32_t btif_save_rfcomm_channel_ctx(uint8_t *ctx_buffer, uint8_t MuxId, uint32_t app_id);
      +uint32_t btif_set_rfcomm_channel_ctx(uint8_t *ctx_buffer, uint8_t MuxId, uint32_t app_id);
      +#endif
      +bool btif_rf_is_rfcomm_channel_connected(uint8_t mux_id,uint32_t app_id);
      +btif_remote_device_t*  btif_rfc_get_mux_remote_device(uint8_t mux_idx);
      +uint8_t btif_rfc_get_mux_index(uint16_t hci_handle);
      +uint8_t btif_rfc_get_mux_state(uint8_t mux_idx);
       #endif
       
       #ifdef __cplusplus
  • services/bt_if_enhanced/inc/spp_api.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/spp_api.h bes/services/bt_if_enhanced/inc/spp_api.h
      index dd143725437..5eb8bf466d9 100644
      --- a/services/bt_if_enhanced/inc/spp_api.h
      +++ b/services/bt_if_enhanced/inc/spp_api.h
      @@ -20,8 +20,8 @@
       #include "cqueue.h"
       #include "rfcomm_api.h"
       
      -#define SPP_DEVICE_NUM      (SPP_SERVICE_NUM*BT_DEVICE_NUM)
      -#define SPP_SERVICE_NUM 5
      +#define SPP_DEVICE_NUM      6
      +#define SPP_SERVICE_NUM     6
       
       typedef uint16_t spp_event_t;
       #define BTIF_SPP_EVENT_REMDEV_CONNECTED         0
      @@ -70,10 +70,10 @@ struct spp_callback_parms {
           } p;
       };
       
      -typedef void (*spp_callback_t)(uint8_t device_id, struct spp_device *locDev,
      +typedef void (*spp_callback_t)(struct spp_device *locDev,
                                   struct spp_callback_parms *Info);
       
      -typedef int (*spp_handle_data_event_func_t)(uint8_t device_id, void *pDev, uint8_t process, uint8_t *pData, uint16_t dataLen);
      +typedef int (*spp_handle_data_event_func_t)(void *pDev, uint8_t process, uint8_t *pData, uint16_t dataLen);
       
       struct _spp_dev {
           union {
      @@ -84,7 +84,7 @@ struct _spp_dev {
       
       struct spp_device {
           spp_port_t      portType;
      -    uint64_t        app_id;
      +    uint32_t        app_id;
           osThreadId      reader_thread_id;
           osMutexId       mutex_id;
           CQueue          rx_queue;
      @@ -92,7 +92,7 @@ struct spp_device {
           uint32_t        rx_buffer_size;
           uint32_t        tx_packet_num;
           void            *priv;
      -    spp_callback_t  spp_app_callback;
      +    spp_callback_t  spp_callback;
           spp_handle_data_event_func_t spp_handle_data_event_func;
           uint8_t         serialNumber;
           uint8_t         spp_connected_flag;
      @@ -125,7 +125,7 @@ bt_status_t btif_spp_open_client(struct spp_device *dev,
                               spp_callback_t callback);
       bt_status_t btif_spp_open_server(struct spp_device *dev,
                               spp_callback_t callback);
      -bt_status_t btif_spp_disconnect(struct spp_device *dev,uint8_t reason);
      +bt_status_t btif_spp_disconnect(struct spp_device *dev);
       bt_status_t btif_spp_close(struct spp_device *dev);
       void btif_spp_close_device(struct spp_device *dev);
       bt_status_t btif_spp_read(struct spp_device *dev, char *buffer, uint16_t *nBytes);
      @@ -134,23 +134,23 @@ bt_status_t btif_spp_service_setup(struct spp_device *dev,
                                       struct spp_service *service,
                                       btif_sdp_record_t *record);
       bt_status_t btif_ccmp_open(struct spp_device *dev,
      -                        bt_bdaddr_t  *remote,
      +                        btif_remote_device_t  *btDevice,
                               spp_callback_t callback,
                               uint8_t port);
       struct spp_device *btif_create_spp_device(void);
       void btif_destroy_spp_device(struct spp_device *dev_t);
      -struct spp_device *btif_spp_get_device(uint64_t app_id);
      +struct spp_device *btif_spp_get_device(uint32_t app_id);
       struct spp_service *btif_create_spp_service(void);
       void btif_destroy_spp_service(struct spp_service *spp_service_p);
      -uint64_t btif_spp_get_app_id(struct spp_device *dev);
      +uint32_t btif_spp_get_app_id(struct spp_device *dev);
       uint32_t btif_spp_get_rfcomm_handle(struct spp_device *dev);
       uint8_t btif_spp_get_server_channel(struct spp_device *dev);
       const char *btif_spp_event2str(spp_event_t event);
       
      -typedef void (*btif_bt_spp_app_callback_func)(uint8_t device_id, void* spp_devi, void* spp_para);
      +typedef void (*btif_bt_spp_app_callback_func)(void* spp_devi, void* spp_para);
       void btif_register_bt_spp_callback_func(btif_bt_spp_app_callback_func func);
      -uint32_t btif_spp_profile_save_ctx(uint64_t app_id,btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      -uint32_t btif_spp_profile_restore_ctx(bt_bdaddr_t *bdaddr_p, uint8_t *buf, uint32_t buf_len);
      +uint32_t btif_spp_profile_save_ctx(uint32_t app_id,btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
      +uint32_t btif_spp_profile_restore_ctx(uint8_t *buf, uint32_t buf_len);
       
       /*---------------------------------------------------------------------------
        * rfcomm channel number
  • services/bt_if_enhanced/inc/tws_role_switch.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/bt_if_enhanced/inc/tws_role_switch.h bes/services/bt_if_enhanced/inc/tws_role_switch.h
      index 9388c15e123..4ab463c613f 100644
      --- a/services/bt_if_enhanced/inc/tws_role_switch.h
      +++ b/services/bt_if_enhanced/inc/tws_role_switch.h
      @@ -17,6 +17,21 @@
       
       #include "bluetooth.h"
       
      +enum TWS_DATA_STRUCTURE
      +{
      +    BT_ME = 0,
      +    BT_HCI,
      +    CMGR_CONTEXT,
      +
      +    BT_L2CAP,
      +    BT_RFC,
      +
      +    RFCOMM_CHANNEL,
      +    AVRCP_CONTEXT,
      +    APP_BT_DEVICE,
      +    AVDEV_CONTEXT,
      +    SLAVE_SAVE_DATA_OK,
      +};
       
       enum PSM_CONTEXT_TYPE
       {
      @@ -28,26 +43,42 @@ enum PSM_CONTEXT_TYPE
            PSM_CONTEXT_INVALID = 0x80,
       };
       
      -#define BT_RPOFILE_FINAL_FLAG   (0x5f)
      +#define BT_RPOFILE_FINAL_FLAG   (0x55)
       
       enum PROFILE_CONTEXT_FLAG
       {
      +#if defined(ENHANCED_STACK)
           BT_HFP_FLAG = 0x01,
           BT_A2DP_FLAG = 0x02,
           BT_AVRCP_FLAG = 0x04,
           BT_MAP_FLAG =0x08,
      -    BT_GATT_FLAG = 0x10,
      +    BT_HID_FLAG = 0x10,
       
           //add new profile flag here
       
           BT_SPP_FLAG = 0x80, //SPP has multiple app id(total BTIF_APP_SPP_NUM),BT_SPP_FLAG flag should be at high bit
      +#else
      +    BT_COMMON_FLAG = 0x01,
      +    BT_RFC_MUX_FLAG = 0x02,
      +    BT_HFP_FLAG = 0x04,
      +    BT_A2DP_FLAG = 0x08,
      +    BT_A2DP_CONTINUE_FLAG = 0x10,
      +    BT_AVRCP_FLAG = 0x20,
      +    BT_SPP_FLAG = 0x40,
      +
      +    DATA_COMPLETE_FLAG = 0x80,
      +#endif
       };
       
      -#define BT_ALL_CONTEXT_PSM    (PSM_CONTEXT_SDP | PSM_CONTEXT_RFC | PSM_CONTEXT_AVDTP | PSM_CONTEXT_AVCTP | PSM_CONTEXT_BTGATT)
      +#define BT_ALL_CONTEXT_PSM    (PSM_CONTEXT_SDP | PSM_CONTEXT_RFC | PSM_CONTEXT_AVDTP | PSM_CONTEXT_AVCTP)
       
      -#define BT_ALL_CONTEXT_FLAG   (BT_HFP_FLAG | BT_A2DP_FLAG  | BT_AVRCP_FLAG | BT_MAP_FLAG | BT_SPP_FLAG | BT_GATT_FLAG)
      +#if defined(ENHANCED_STACK)
      +#define BT_ALL_CONTEXT_FLAG   (BT_HFP_FLAG | BT_A2DP_FLAG  | BT_AVRCP_FLAG | BT_MAP_FLAG | BT_SPP_FLAG | BT_HID_FLAG)
      +#else
      +#define BT_ALL_CONTEXT_FLAG   (BT_COMMON_FLAG | BT_RFC_MUX_FLAG | BT_HFP_FLAG | BT_A2DP_FLAG | BT_A2DP_CONTINUE_FLAG | BT_AVRCP_FLAG | SPP_SERVER_INTERACTION_FLAG)
      +#endif
       
      -#define BT_ALL_RFC_APP_ID     BTIF_APP_HFP_PROFILE_ID
      +#define BT_ALL_RFC_APP_ID     (BTIF_APP_HFP_PROFILE_ID | BT_SPP_FLAG)
       
       #define BT_EARPHONE_BASIC_APP_ID       (BTIF_APP_HFP_PROFILE_ID | BTIF_APP_A2DP_PROFILE_ID | BTIF_APP_AVRCP_PROFILE_ID)
       
  • services/communication/comminication_knowles/communication_sysapi.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/communication/comminication_knowles/communication_sysapi.h bes/services/communication/comminication_knowles/communication_sysapi.h
      index 98459080989..166c72f1d4c 100644
      --- a/services/communication/comminication_knowles/communication_sysapi.h
      +++ b/services/communication/comminication_knowles/communication_sysapi.h
      @@ -25,7 +25,7 @@ extern "C" {
       #define TRACE(str, ...)                 do { printf("%s/" str "\n", __FUNCTION__, __VA_ARGS__); } while (0)
       #define ASSERT(cond, str, ...)          \
           do { if (!(cond)) { printf("[ASSERT]%s/" str, __FUNCTION__, __VA_ARGS__); while (1); } } while (0)
      -#define TRACE_TIME(str, ...)            TRACE(str, __VA_ARGS__)
      +#define TRACE_TIME(num,str, ...)        TRACE(num,str, __VA_ARGS__)
       
       int write_sig_data(const unsigned char *data, unsigned int len);
       int write_code_data(const unsigned char *data, unsigned int len);
      @@ -34,7 +34,7 @@ void programmer_main(void);
       #include "hal_trace.h"
       #include "hal_timer.h"
       
      -#define TRACE_TIME(str, ...)            TRACE("[%05u] " str, TICKS_TO_MS(hal_sys_timer_get()), ##__VA_ARGS__)
      +#define TRACE_TIME(num,str, ...)        TRACE(num+1,"[%05u] " str, TICKS_TO_MS(hal_sys_timer_get()), ##__VA_ARGS__)
       #endif
       
       #define UART_OUT_SIGNAL_ID 0x19
  • services/Makefile

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/Makefile bes/services/Makefile
      index 3b22217c4e2..27ea8262ceb 100644
      --- a/services/Makefile
      +++ b/services/Makefile
      @@ -10,7 +10,7 @@
       # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       # See the License for the specific language governing permissions and
       # limitations under the License.
      -obj-y += audio_dump/ \
      +obj-y := audio_dump/ \
                audioflinger/ \
                audio_process/ \
                hw_dsp/ \
      @@ -23,24 +23,27 @@ obj-y += audio_dump/ \
                osif/ \
                norflash_api/ \
       
      -ifeq ($(SPEECH_BONE_SENSOR),1)
      +ifeq ($(BONE_SENSOR_TDM),1)
       obj-y += bone_sensor/
       endif
       
      -ifneq ($(filter 1,$(INTERCONNECTION) $(INTERACTION) $(AI_VOICE)),)
      +ifneq ($(INTERCONNECTION)_$(AI_VOICE),0_0)
       obj-y += interconnection/
       endif
       
      -ifneq ($(BT_CLOSE),1)
      +ifeq ($(ENHANCED_STACK),1)
       obj-y += bt_profiles_enhanced/
       obj-y += bt_if_enhanced/
      +else
      +obj-y += bt_profiles/
      +obj-y += bt_if/
       endif
       
       ifeq ($(MBED),1)
       obj-y += fs/
       endif
       
      -ifneq ($(filter 1, $(MBED) $(AI_VOICE) $(TOTA_v2)),)
      +ifneq ($(MBED)_$(AI_VOICE),0_0)
       obj-y +=../utils/kfifo/
       endif
       
      @@ -49,7 +52,7 @@ obj-y += voicepath/
       obj-y += voicepath/$(VOICE_DATAPATH_TYPE)/
       endif
       
      -ifneq ($(filter 1, $(VOICE_DATAPATH_ENABLED) $(AI_VOICE)),)
      +ifneq ($(VOICE_DATAPATH_ENABLED)_$(AI_VOICE),0_0)
       obj-y += app_ai/
       endif
       
      @@ -83,14 +86,16 @@ ifeq ($(TEST_OVER_THE_AIR),1)
       obj-y += tota/
       endif
       
      -ifneq ($(filter 1, $(BES_OTA) $(AI_OTA) $(BES_OTA_BASIC)),)
      -ifeq ($(IBRT_OTA),1)
      +ifeq ($(OTA_ENABLE),1)
      +ifeq ($(IBRT),1)
       ifeq ($(FPGA_IBRT_OTA),1)
       obj-y += fpga_ibrt_ota/
       else
       obj-y += ibrt_ota/
       endif
       else
      +endif
      +ifeq ($(OTA_ENABLE), 1)
       obj-y += ota/
       endif
       endif
      @@ -104,7 +109,7 @@ obj-y += ai_voice/
       endif
       
       ifeq ($(CHIP_HAS_CP),1)
      -obj-y += cp_boot/
      +obj-y += cp_accel/
       endif
       
       ifeq ($(IBRT),1)
      @@ -114,7 +119,7 @@ obj-y += ibrt_ui/
       endif
       
       ifeq ($(TWS_SYSTEM_ENABLED),1)
      -obj-y += ibrt_middleware/
      +obj-y += app_tws/
       endif
       
       ifeq ($(RSA_SHA),1)
      @@ -131,6 +136,9 @@ ifeq ($(RPC_SUPPORT),1)
       obj-y += rpc/
       endif
       
      +ifeq ($(A2DP_LHDC_ON),1)
      +obj-y += lhdc_license/
      +endif
       
       ifeq ($(THROUGH_PUT),1)
       obj-y += through_put/
  • services/norflash_api/norflash_api.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/norflash_api/norflash_api.h bes/services/norflash_api/norflash_api.h
      index d7c540de5be..b25773885bb 100644
      --- a/services/norflash_api/norflash_api.h
      +++ b/services/norflash_api/norflash_api.h
      @@ -221,6 +221,8 @@ enum NORFLASH_API_STATE norflash_api_get_state(enum NORFLASH_API_MODULE_ID_T mod
       
       void norflash_flush_all_pending_op(void);
       
      +void app_flush_pending_flash_op(enum NORFLASH_API_MODULE_ID_T module,
      +                                enum NORFLASH_API_OPRATION_TYPE type);
       
       void app_flash_page_erase(enum NORFLASH_API_MODULE_ID_T module, uint32_t flashOffset);
       
  • services/nvrecord/nvrecord_ble.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nvrecord/nvrecord_ble.h bes/services/nvrecord/nvrecord_ble.h
      index 1ce6f6794a8..da5dfa4e8fb 100644
      --- a/services/nvrecord/nvrecord_ble.h
      +++ b/services/nvrecord/nvrecord_ble.h
      @@ -58,6 +58,7 @@ uint8_t nv_record_ble_fill_irk(uint8_t *ltkToFill);
       void nv_record_blerec_init(void);
       void nv_record_blerec_get_local_irk(uint8_t *pIrk);
       bool nv_record_blerec_get_bd_addr_from_irk(uint8_t *pBdAddr, uint8_t *pIrk);
      +void nv_record_tws_exchange_ble_info(void);
       
       #ifdef __cplusplus
       }
  • services/nvrecord/nvrecord.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nvrecord/nvrecord.h bes/services/nvrecord/nvrecord.h
      index bfc89bce087..a4f9cbeb6fa 100644
      --- a/services/nvrecord/nvrecord.h
      +++ b/services/nvrecord/nvrecord.h
      @@ -112,23 +112,15 @@ typedef  struct btdevice_profile{
           uint8_t a2dp_codectype;
       }btdevice_profile;
       
      -typedef struct
      -{
      -    uint16_t spec_id;
      -    uint16_t vend_id;
      -    uint16_t prod_id;
      -    uint16_t prod_ver;
      -    uint8_t  prim_rec;
      -    uint16_t vend_id_source;
      -} bt_dip_pnp_info_t;
      -
       typedef struct _nvrec_btdevicerecord
       {
           btif_device_record_t record;
           btdevice_volume device_vol;
           btdevice_profile device_plf;
       #ifdef BTIF_DIP_DEVICE
      -    bt_dip_pnp_info_t pnp_info;
      +    uint16_t vend_id;
      +    uint16_t vend_id_source;
      +    uint16_t reserve;
       #endif
       } nvrec_btdevicerecord;
       
      @@ -158,6 +150,7 @@ void nv_record_btdevicerecord_set_a2dp_vol(nvrec_btdevicerecord* pRecord, int8_t
       void nv_record_btdevicerecord_set_hfp_vol(nvrec_btdevicerecord* pRecord, int8_t vol);
       void nv_record_btdevicevolume_set_a2dp_vol(btdevice_volume* device_vol, int8_t vol);
       void nv_record_btdevicevolume_set_hfp_vol(btdevice_volume* device_vol, int8_t vol);
      +void nv_record_btdevicerecord_set_vend_id_and_source(nvrec_btdevicerecord* pRecord, int16_t vend_id, int16_t vend_id_source);
       void nv_record_btdevicerecord_set_a2dp_profile_active_state(btdevice_profile* device_plf, bool isActive);
       void nv_record_btdevicerecord_set_hfp_profile_active_state(btdevice_profile* device_plf, bool isActive);
       void nv_record_btdevicerecord_set_hsp_profile_active_state(btdevice_profile* device_plf, bool isActive);
  • services/nv_section/fpga_section/nvrecord_bt.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/fpga_section/nvrecord_bt.h bes/services/nv_section/fpga_section/nvrecord_bt.h
      index a12c77386ab..a55802a2b8d 100644
      --- a/services/nv_section/fpga_section/nvrecord_bt.h
      +++ b/services/nv_section/fpga_section/nvrecord_bt.h
      @@ -30,6 +30,7 @@ void nv_record_btdevicerecord_set_a2dp_vol(nvrec_btdevicerecord* pRecord, int8_t
       void nv_record_btdevicerecord_set_hfp_vol(nvrec_btdevicerecord* pRecord, int8_t vol);
       void nv_record_btdevicevolume_set_a2dp_vol(btdevice_volume* device_vol, int8_t vol);
       void nv_record_btdevicevolume_set_hfp_vol(btdevice_volume* device_vol, int8_t vol);
      +void nv_record_btdevicerecord_set_vend_id_and_source(nvrec_btdevicerecord* pRecord, int16_t vend_id, int16_t vend_id_source);
       void nv_record_btdevicerecord_set_a2dp_profile_active_state(btdevice_profile* device_plf, bool isActive);
       void nv_record_btdevicerecord_set_hfp_profile_active_state(btdevice_profile* device_plf, bool isActive);
       void nv_record_btdevicerecord_set_hsp_profile_active_state(btdevice_profile* device_plf, bool isActive);
  • services/nv_section/fpga_section/nvrecord_env.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/fpga_section/nvrecord_env.h bes/services/nv_section/fpga_section/nvrecord_env.h
      index 6dd3fffae1d..0e870ba0a28 100644
      --- a/services/nv_section/fpga_section/nvrecord_env.h
      +++ b/services/nv_section/fpga_section/nvrecord_env.h
      @@ -27,6 +27,7 @@ extern "C" {
       #define NVRAM_ENV_MEDIA_LANGUAGE_DEFAULT (0)
       #define NVRAM_ENV_TWS_MODE_DEFAULT (0xff)
       #define NVRAM_ENV_FACTORY_TESTER_STATUS_DEFAULT (0xaabbccdd)
      +#define NVRAM_ENV_FACTORY_TESTER_STATUS_TEST_PASS (0xffffaa55)
       
       int nv_record_env_init(void);
       int nv_record_env_get(struct nvrecord_env_t **nvrecord_env);
  • services/nv_section/fpga_section/nvrecord_externsion.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/fpga_section/nvrecord_externsion.h bes/services/nv_section/fpga_section/nvrecord_externsion.h
      index 10cfa5bfbe0..9ec64a3ba74 100644
      --- a/services/nv_section/fpga_section/nvrecord_externsion.h
      +++ b/services/nv_section/fpga_section/nvrecord_externsion.h
      @@ -18,6 +18,7 @@
       #define __NVRECORD_EXTENSION_H__
       #include "bluetooth.h"
       #include "me_api.h"
      +#include "btif_sys_config.h"
       
       // increase by 1 if the nvrecord's whole data structure is changed and the content needs to be rebuilt
       #define NV_EXTENSION_MAJOR_VERSION 2
      @@ -133,6 +134,11 @@ typedef struct {
           btif_device_record_t record;
           btdevice_volume device_vol;
           btdevice_profile device_plf;
      +#ifdef BTIF_DIP_DEVICE
      +    uint16_t vend_id;
      +    uint16_t vend_id_source;
      +    uint16_t reserve;
      +#endif
       } nvrec_btdevicerecord;
       
       typedef struct {
      @@ -145,12 +151,12 @@ typedef enum {
           section_none
       } SECTIONS_ADP_ENUM;
       
      -#if defined(GSOUND_OTA_ENABLED)&&defined(VOICE_DATAPATH)
      +#if defined(OTA_ENABLED)
       typedef enum {
      -    GSOUND_OTA_STATUS_NONE        = 0,
      -    GSOUND_OTA_STATUS_IN_PROGRESS = 1,
      -    GSOUND_OTA_STATUS_COMPLETE    = 2,
      -    GSOUND_OTA_STATUS_NUM,
      +    OTA_STATUS_NONE        = 0,
      +    OTA_STAGE_ONGOING = 1,
      +    OTA_STATUS_COMPLETE    = 2,
      +    OTA_STATUS_NUM,
       } GSOUND_OTA_STATUS_E;
       #endif
       
      @@ -210,7 +216,7 @@ typedef struct {
       } NV_TILE_INFO_CONFIG_T;
       #endif
       
      -#if defined(GSOUND_OTA_ENABLED) && defined(VOICE_DATAPATH)
      +#if defined(BISTO_ENABLED)
       typedef struct {
           uint8_t isGsoundEnabled;
           uint8_t gsoundOtaStatus;
      @@ -242,7 +248,7 @@ typedef struct {
           NV_TILE_INFO_CONFIG_T tileConfig;
       #endif
       
      -#if defined(GSOUND_OTA_ENABLED) && defined(VOICE_DATAPATH)
      +#if defined(BISTO_ENABLED)
           NV_GSOUND_INFO_T gsound_info;
       #endif
       
      @@ -256,6 +262,14 @@ typedef struct {
           //     Then the nv record will keep all the whole hisotry.
       } NV_EXTENSION_RECORD_T;
       
      +typedef union {
      +    NV_EXTENSION_RECORD_T nv_record;
      +    /*
      +     * dummy data, just make sure the mirror buffer's size is
      +     * "NV_EXTENSION_MIRROR_RAM_SIZE"
      +     */
      +    uint8_t dummy_data[NV_EXTENSION_MIRROR_RAM_SIZE];
      +} NV_MIRROR_BUF_T;
       
       #ifdef __cplusplus
       extern "C" {
      @@ -279,6 +293,7 @@ void nv_record_flash_flush(void);
       
       int nv_record_flash_flush_in_sleep(void);
       
      +void nv_record_execute_async_flush(void);
       
       void nv_record_update_runtime_userdata(void);
       
  • services/nv_section/log_section/crash_dump_section.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/log_section/crash_dump_section.h bes/services/nv_section/log_section/crash_dump_section.h
      index ecc8fddfd78..c9ca33852e1 100644
      --- a/services/nv_section/log_section/crash_dump_section.h
      +++ b/services/nv_section/log_section/crash_dump_section.h
      @@ -74,7 +74,7 @@ void crashdump_init_section_info(void);
       #include "hal_trace.h"
       
       #define CRASH_DUMP_PREFIX     "__CRASH_DUMP:"
      -#define CRASH_DUMP_TRACE(fmt, ...)       TRACE(fmt, ##__VA_ARGS__)
      +#define CRASH_DUMP_TRACE(num,fmt, ...)   TRACE(num,fmt, ##__VA_ARGS__)
       #define CRASH_LOG_ALIGN(x,a)  (uint32_t)(((x + a - 1)/a) * a)
       
       
  • services/nv_section/log_section/log_section.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/log_section/log_section.h bes/services/nv_section/log_section/log_section.h
      index d3af0e6ad80..aae5d6e3996 100644
      --- a/services/nv_section/log_section/log_section.h
      +++ b/services/nv_section/log_section/log_section.h
      @@ -65,11 +65,12 @@ typedef struct
       typedef struct{
           uint32_t state;
           uint32_t offset;
      -    uint8_t buffer[LOG_DUMP_BUFFER_LEN];
      +    uint8_t buffer[LOG_DUMP_SECTOR_SIZE];
       }DATA_BUFFER;
       
       void log_dump_init(void);
       int log_dump_flush(void);
      +int log_dump_flush_all(void);
       void log_dump_notify_handler(enum HAL_TRACE_STATE_T state);
       void log_dump_output_handler(const unsigned char *buf, unsigned int buf_len);
       void log_dump_callback(void* param);
  • services/nv_section/nv_section_dbg.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/nv_section_dbg.h bes/services/nv_section/nv_section_dbg.h
      index 4766a34f7ff..2945a7baa72 100644
      --- a/services/nv_section/nv_section_dbg.h
      +++ b/services/nv_section/nv_section_dbg.h
      @@ -25,11 +25,11 @@ extern "C"{
       #include "hal_trace.h"
       
       /******************************macro defination*****************************/
      -#define LOG_V(str, ...) TR_VERBOSE(TR_MOD(NV_SEC), str, ##__VA_ARGS__)
      -#define LOG_D(str, ...) TR_DEBUG(TR_MOD(NV_SEC), str, ##__VA_ARGS__)
      -#define LOG_I(str, ...) TR_INFO(TR_MOD(NV_SEC), str, ##__VA_ARGS__)
      -#define LOG_W(str, ...) TR_WARN(TR_MOD(NV_SEC), str, ##__VA_ARGS__)
      -#define LOG_E(str, ...) TR_ERROR(TR_MOD(NV_SEC), str, ##__VA_ARGS__)
      +#define LOG_V(str, ...) LOG_VERBOSE(LOG_MOD(NV_SEC), str, ##__VA_ARGS__)
      +#define LOG_D(str, ...) LOG_DEBUG(LOG_MOD(NV_SEC), str, ##__VA_ARGS__)
      +#define LOG_I(str, ...) LOG_INFO(LOG_MOD(NV_SEC), str, ##__VA_ARGS__)
      +#define LOG_W(str, ...) LOG_WARN(LOG_MOD(NV_SEC), str, ##__VA_ARGS__)
      +#define LOG_E(str, ...) LOG_ERROR(LOG_MOD(NV_SEC), str, ##__VA_ARGS__)
       
       /******************************type defination******************************/
       
  • services/nv_section/userdata_section/nvrecord_ble.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/userdata_section/nvrecord_ble.h bes/services/nv_section/userdata_section/nvrecord_ble.h
      index 87b9064cdc3..49083847eaa 100644
      --- a/services/nv_section/userdata_section/nvrecord_ble.h
      +++ b/services/nv_section/userdata_section/nvrecord_ble.h
      @@ -38,6 +38,7 @@ void nvrecord_rebuild_paired_ble_dev_info(NV_RECORD_PAIRED_BLE_DEV_INFO_T* pPair
       void nv_record_extension_update_tws_ble_info(NV_RECORD_PAIRED_BLE_DEV_INFO_T *info);
       void nv_record_tws_exchange_ble_info(void);
       uint8_t *nv_record_tws_get_self_ble_info(void);
      +uint8_t *nv_record_tws_get_peer_ble_addr(void);
       #endif
       
       #ifdef __cplusplus
  • services/nv_section/userdata_section/nvrecord_bt.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/userdata_section/nvrecord_bt.h bes/services/nv_section/userdata_section/nvrecord_bt.h
      index 04918959a8c..6b680757073 100644
      --- a/services/nv_section/userdata_section/nvrecord_bt.h
      +++ b/services/nv_section/userdata_section/nvrecord_bt.h
      @@ -30,6 +30,7 @@ void nv_record_btdevicerecord_set_a2dp_vol(nvrec_btdevicerecord* pRecord, int8_t
       void nv_record_btdevicerecord_set_hfp_vol(nvrec_btdevicerecord* pRecord, int8_t vol);
       void nv_record_btdevicevolume_set_a2dp_vol(btdevice_volume* device_vol, int8_t vol);
       void nv_record_btdevicevolume_set_hfp_vol(btdevice_volume* device_vol, int8_t vol);
      +void nv_record_btdevicerecord_set_vend_id_and_source(nvrec_btdevicerecord* pRecord, int16_t vend_id, int16_t vend_id_source);
       void nv_record_btdevicerecord_set_a2dp_profile_active_state(btdevice_profile* device_plf, bool isActive);
       void nv_record_btdevicerecord_set_hfp_profile_active_state(btdevice_profile* device_plf, bool isActive);
       void nv_record_btdevicerecord_set_hsp_profile_active_state(btdevice_profile* device_plf, bool isActive);
  • services/nv_section/userdata_section/nvrecord_extension.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/userdata_section/nvrecord_extension.h bes/services/nv_section/userdata_section/nvrecord_extension.h
      index 3a4d23dd392..75f73bad462 100644
      --- a/services/nv_section/userdata_section/nvrecord_extension.h
      +++ b/services/nv_section/userdata_section/nvrecord_extension.h
      @@ -21,9 +21,9 @@
       #include "btif_sys_config.h"
       
       // increase by 1 if the nvrecord's whole data structure is changed and the content needs to be rebuilt
      -#define NV_EXTENSION_MAJOR_VERSION 10
      +#define NV_EXTENSION_MAJOR_VERSION 3
       // increase by 1 if the new items are appended to the tail of the former nvrecord's data structure
      -#define NV_EXTENSION_MINOR_VERSION 3
      +#define NV_EXTENSION_MINOR_VERSION 1
       
       #define NV_EXTENSION_SIZE 4096                              // one flash page
       #define NV_EXTENSION_PAGE_SIZE 256
      @@ -55,7 +55,7 @@
       #define FP_MAX_NAME_LEN 64
       #endif
       
      -#ifdef AI_OTA
      +#ifdef OTA_ENABLED
       #define MAX_VERSION_STRING_LEN 16
       #define OTA_DEVICE_CNT 2 //!< should be equal to OTA_DEVICE_NUM in @see OTA_DEVICE_E
       #endif
      @@ -76,12 +76,12 @@
       // TODO: should be increased if NV_EXTENSION_MIRROR_RAM_SIZE exceeds this value
       
       #if defined(__AI_VOICE__ ) || (defined(BISTO_ENABLED)|| defined(GFPS_ENABLED))
      -#define NV_EXTENSION_MIRROR_RAM_SIZE 0xA00
      +#define NV_EXTENSION_MIRROR_RAM_SIZE 0x800
       #else
      -#define NV_EXTENSION_MIRROR_RAM_SIZE 0x600
      +#define NV_EXTENSION_MIRROR_RAM_SIZE 0x400
       #endif
       
      -#define TILE_INFO_SIZE 428
      +#define TILE_INFO_SIZE 400
       #define BT_FREQENCY_RANGE_NUM   3
       #define BT_IQ_INVALID_MAGIC_NUM 0xFFFFFFFF
       #define BT_IQ_VALID_MAGIC_NUM   0x5a5a5a5a
      @@ -107,7 +107,7 @@ typedef struct {
           int8_t language;
       } media_language_t;
       
      -#if defined(BT_SOURCE)
      +#if defined(APP_LINEIN_A2DP_SOURCE) || defined(APP_I2S_A2DP_SOURCE)
       typedef struct {
           int8_t src_snk_mode;
       } src_snk_t;
      @@ -133,7 +133,7 @@ typedef struct {
       
       struct nvrecord_env_t {
           media_language_t media_language;
      -#if defined(BT_SOURCE)
      +#if defined(APP_LINEIN_A2DP_SOURCE) || defined(APP_I2S_A2DP_SOURCE)
           src_snk_t src_snk_flag;
       #endif
           ibrt_mode_t ibrt_mode;
      @@ -144,33 +144,25 @@ struct nvrecord_env_t {
       };
       
       typedef struct btdevice_volume {
      -    uint8_t a2dp_vol;
      -    uint8_t hfp_vol;
      +    int8_t a2dp_vol;
      +    int8_t hfp_vol;
       } btdevice_volume;
       
       typedef struct btdevice_profile {
           bool hfp_act;
      -    uint8_t a2dp_abs_vol;
      +    bool hsp_act;
           bool a2dp_act;
           uint8_t a2dp_codectype;
       } btdevice_profile;
       
      -typedef struct
      -{
      -    uint16_t spec_id;
      -    uint16_t vend_id;
      -    uint16_t prod_id;
      -    uint16_t prod_ver;
      -    uint8_t  prim_rec;
      -    uint16_t vend_id_source;
      -} bt_dip_pnp_info_t;
      -
       typedef struct {
           btif_device_record_t record;
           btdevice_volume device_vol;
           btdevice_profile device_plf;
       #ifdef BTIF_DIP_DEVICE
      -    bt_dip_pnp_info_t pnp_info;
      +    uint16_t vend_id;
      +    uint16_t vend_id_source;
      +    uint16_t reserve;
       #endif
       } nvrec_btdevicerecord;
       
      @@ -189,29 +181,21 @@ typedef struct {
           uint8_t ble_irk[BLE_IRK_SIZE];
       } BLE_BASIC_INFO_T;
       
      -typedef struct
      -{
      -    /// BD Address of device
      -    uint8_t addr[BLE_ADDR_SIZE];
      -    /// Address type of the device 0=public/1=private random
      -    uint8_t addr_type;
      -} BLE_ADDR_INFO_T;
      -
       typedef struct {
      -    BLE_ADDR_INFO_T peer_addr;
      +    uint8_t peer_bleAddr[BLE_ADDR_SIZE];
           uint16_t EDIV;
           uint8_t RANDOM[BLE_ENC_RANDOM_SIZE];
           uint8_t LTK[BLE_LTK_SIZE];
           uint8_t IRK[BLE_IRK_SIZE];
           uint8_t bonded;
       
      -} __attribute__ ((packed)) BleDeviceinfo;
      +} BleDeviceinfo;
       
       typedef struct {
           uint32_t saved_list_num;
           BLE_BASIC_INFO_T self_info;
           BleDeviceinfo ble_nv[BLE_RECORD_NUM];
      -} __attribute__ ((packed)) NV_RECORD_PAIRED_BLE_DEV_INFO_T;
      +} NV_RECORD_PAIRED_BLE_DEV_INFO_T;
       
       #ifdef TWS_SYSTEM_ENABLED
       typedef struct {
      @@ -248,7 +232,7 @@ typedef struct {
       } NV_TILE_INFO_CONFIG_T;
       #endif
       
      -#if defined(AI_OTA)
      +#if defined(OTA_ENABLED)
       typedef struct {
           // hotword model ID, arry size should equal to GSOUND_HOTWORD_MODEL_ID_BYTES
           char modelId[5];
      @@ -307,7 +291,7 @@ typedef struct {
           NV_TILE_INFO_CONFIG_T tileConfig;
       #endif
       
      -#ifdef AI_OTA
      +#ifdef OTA_ENABLED
           NV_OTA_INFO_T ota_info[OTA_DEVICE_CNT];
       #endif
       
  • services/nv_section/userdata_section/nvrecord_gsound.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/nv_section/userdata_section/nvrecord_gsound.h bes/services/nv_section/userdata_section/nvrecord_gsound.h
      index 64435ad0753..273fe44ef08 100644
      --- a/services/nv_section/userdata_section/nvrecord_gsound.h
      +++ b/services/nv_section/userdata_section/nvrecord_gsound.h
      @@ -28,7 +28,7 @@ extern "C"{
       #define F_4K_ALIGN(val) (((val)+0xFFF)&~0xFFF)
       #define IS_F_4K_ALIGNED(val) (val==(val&~0xFFF))
       
      -#define INVALID_MODEL_NUM 0xFF          //!< used to distinguish from 0 when first time bootup
      +#define INVALID_MODEL_NUM 0xFF          //!< used to distinguish from default 0 after first time bootup
       #define DEFAULT_MODEL_NUM 1             //!< number of default supported hotword model
       #define DEFAULT_HOTWORD_MODEL_ID "200Q" //!< default model ID, provided by Google
       
  • services/ota/ota_dbg.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/ota/ota_dbg.h bes/services/ota/ota_dbg.h
      index a7be68098fe..aeb106c3008 100644
      --- a/services/ota/ota_dbg.h
      +++ b/services/ota/ota_dbg.h
      @@ -24,11 +24,11 @@ extern "C"{
       #include "hal_trace.h"
       
       /******************************macro defination*****************************/
      -#define LOG_V(str, ...) TR_VERBOSE(TR_MOD(OTA), str, ##__VA_ARGS__)
      -#define LOG_D(str, ...) TR_DEBUG(TR_MOD(OTA), str, ##__VA_ARGS__)
      -#define LOG_I(str, ...) TR_INFO(TR_MOD(OTA), str, ##__VA_ARGS__)
      -#define LOG_W(str, ...) TR_WARN(TR_MOD(OTA), str, ##__VA_ARGS__)
      -#define LOG_E(str, ...) TR_ERROR(TR_MOD(OTA), str, ##__VA_ARGS__)
      +#define LOG_V(str, ...) LOG_VERBOSE(LOG_MOD(OTA), str, ##__VA_ARGS__)
      +#define LOG_D(str, ...) LOG_DEBUG(LOG_MOD(OTA), str, ##__VA_ARGS__)
      +#define LOG_I(str, ...) LOG_INFO(LOG_MOD(OTA), str, ##__VA_ARGS__)
      +#define LOG_W(str, ...) LOG_WARN(LOG_MOD(OTA), str, ##__VA_ARGS__)
      +#define LOG_E(str, ...) LOG_ERROR(LOG_MOD(OTA), str, ##__VA_ARGS__)
       
       /******************************type defination******************************/
       
  • services/overlay/app_overlay.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/overlay/app_overlay.h bes/services/overlay/app_overlay.h
      index 913c0f01fbb..6908de9985b 100644
      --- a/services/overlay/app_overlay.h
      +++ b/services/overlay/app_overlay.h
      @@ -43,6 +43,8 @@ enum APP_OVERLAY_ID_T {
       #endif
       #ifdef OPUS_IN_OVERLAY
           APP_OVERLAY_OPUS = HAL_OVERLAY_ID_7,
      +#elif defined(A2DP_LDAC_ON)
      +    APP_OVERLAY_A2DP_LDAC = HAL_OVERLAY_ID_7,
       #endif
       
           APP_OVERLAY_ID_QTY = HAL_OVERLAY_ID_QTY,
  • services/resources/resources.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/resources/resources.h bes/services/resources/resources.h
      index f3e3cd50747..1c002cf6c1d 100644
      --- a/services/resources/resources.h
      +++ b/services/resources/resources.h
      @@ -51,11 +51,15 @@ typedef enum {
           AUD_ID_BT_DIS_CONNECT,
           AUD_ID_BT_WARNING,
           AUDIO_ID_BT_ALEXA_START,
      +    AUDIO_ID_FIND_MY_BUDS,
      +    AUDIO_ID_FIND_TILE,
           AUDIO_ID_BT_ALEXA_STOP,
           AUDIO_ID_BT_GSOUND_MIC_OPEN,
           AUDIO_ID_BT_GSOUND_MIC_CLOSE,
           AUDIO_ID_BT_GSOUND_NC,
           AUDIO_ID_BT_MUTE,
      +    AUDIO_ID_BT_DU,
      +    AUDIO_ID_BT_DUDU,
           AUD_ID_RING_WARNING,
       #ifdef __INTERACTION__
           AUD_ID_BT_FINDME,
  • services/through_put/app_through_put.h

    • No Declared License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/through_put/app_through_put.h bes/services/through_put/app_through_put.h
      index 17180de588c..334c2ff2f37 100644
      --- a/services/through_put/app_through_put.h
      +++ b/services/through_put/app_through_put.h
      @@ -107,7 +107,7 @@ typedef struct
        * @brief through put command definition data structure
        *
        */
      -typedef void (*app_through_cmd_handler_t)(APP_THROUGHPUT_CMD_CODE_E cmdCode, uint8_t* ptrParam, uint32_t paramLen, uint8_t ai_index);
      +typedef void (*app_through_cmd_handler_t)(APP_THROUGHPUT_CMD_CODE_E cmdCode, uint8_t* ptrParam, uint32_t paramLen);
       typedef struct
       {
           uint32_t                cmdCode;
      @@ -134,7 +134,7 @@ extern "C" {
        * Return:
        *    void
        */
      -uint32_t app_throughput_cmd_send_done(void *param1, uint32_t param2, uint8_t ai_index, uint8_t dest_id);
      +uint32_t app_throughput_cmd_send_done(void *param1, uint32_t param2);
       
       /*---------------------------------------------------------------------------
        *            app_throughput_receive_cmd
      @@ -150,7 +150,7 @@ uint32_t app_throughput_cmd_send_done(void *param1, uint32_t param2, uint8_t ai_
        * Return:
        *    void
        */
      -uint32_t app_throughput_receive_cmd(void *param1, uint32_t param2, uint8_t ai_index, uint8_t dest_id);
      +uint32_t app_throughput_receive_cmd(void *param1, uint32_t param2);
       
       /*---------------------------------------------------------------------------
        *            app_stop_throughput_test
  • services/tota/app_spp_tota.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/tota/app_spp_tota.h bes/services/tota/app_spp_tota.h
      index 5d5c8f1165b..f0f323bcb80 100644
      --- a/services/tota/app_spp_tota.h
      +++ b/services/tota/app_spp_tota.h
      @@ -14,9 +14,12 @@
        */
       #ifndef __APP_SPP_TOTA_H__
       #define __APP_SPP_TOTA_H__
      +#include <map>
      +#include <stdint.h>
      +using namespace std;
       
       #define TOTA_SPP_ID                  0
      -#define TOTA_SPP_MAX_PACKET_SIZE     666
      +#define TOTA_SPP_MAX_PACKET_SIZE     600
       #define TOTA_SPP_MAX_PACKET_NUM      5
       
       
      @@ -24,23 +27,49 @@
       
       #define APP_TOTA_DATA_CMD_TIME_OUT_IN_MS    5000
       
      +/**
      + * @brief Type of the tota module
      + *
      + */
      +typedef enum
      +{
      +    APP_TOTA_AUDIO_DUMP = 0,
      +    APP_TOTA_MIC,
      +    APP_TOTA_FLASH,
      +    APP_TOTA_ANC,
      +    APP_TOTA_GENERAL,
      +    APP_TOTA_CUSTOM,
      +
      +    APP_TOTA_MODULE_NONE = 0xFF
      +} APP_TOTA_MODULE_E;
       
       
      +typedef struct{
      +    void (*tota_spp_connected)(void);
      +    void (*tota_spp_disconnected)(void);
      +    void (*tota_spp_tx_done)(void);
      +    void (*tota_spp_data_receive_hanle)(uint8_t * buf, uint32_t len);
      +}tota_callback_func_t;
       
       
      +void tota_callback_module_register(APP_TOTA_MODULE_E module, tota_callback_func_t tota_callback_func);
      +void tota_callback_module_set(APP_TOTA_MODULE_E module);
      +APP_TOTA_MODULE_E tota_callback_module_get();
       
       
       
       typedef void(*app_spp_tota_tx_done_t)(void);
       void app_spp_tota_register_tx_done(app_spp_tota_tx_done_t callback);
       void app_spp_tota_init(void);
      -void app_tota_send_cmd_via_spp(uint8_t* ptrData, uint32_t length);
      -void app_tota_send_data_via_spp(uint8_t* ptrData, uint32_t length);
       
       
       uint16_t app_spp_tota_tx_buf_size(void);
       void app_spp_tota_init_tx_buf(uint8_t* ptr);
      +uint8_t* app_spp_tota_fill_data_into_tx_buf(uint8_t* ptrData, uint32_t dataLen);
       
      +bool app_spp_tota_send_data(uint8_t* ptrData, uint16_t length);
       
      +/* for sniff */
      +bool spp_tota_in_progress(void);
       
       #endif
  • services/tota/app_tota_cmd_code.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/tota/app_tota_cmd_code.h bes/services/tota/app_tota_cmd_code.h
      index 16dc3f7c2b1..b7ef2947ff3 100644
      --- a/services/tota/app_tota_cmd_code.h
      +++ b/services/tota/app_tota_cmd_code.h
      @@ -26,9 +26,9 @@ extern "C" {
       #define TOTA_CONTROL_DEBUG
       
       #ifdef TOTA_CONTROL_DEBUG
      -#define TOTA_LOG_DBG(num,str,...)   TRACE(num,LOG_TAG"" str, ##__VA_ARGS__)             // DEBUG OUTPUT
      -#define TOTA_LOG_MSG(num,str,...)   TRACE(num,LOG_TAG"" str, ##__VA_ARGS__)             // MESSAGE OUTPUT
      -#define TOTA_LOG_ERR(num,str,...)   TRACE(num,LOG_TAG"err:""" str, ##__VA_ARGS__)       // ERROR OUTPUT
      +#define TOTA_LOG_DBG(num,str,...)   TRACE(num,LOG_TAG""str, ##__VA_ARGS__)              // DEBUG OUTPUT
      +#define TOTA_LOG_MSG(num,str,...)   TRACE(num,LOG_TAG""str, ##__VA_ARGS__)              // MESSAGE OUTPUT
      +#define TOTA_LOG_ERR(num,str,...)   TRACE(num,LOG_TAG"err:"""str, ##__VA_ARGS__)        // ERROR OUTPUT
       
       #define TOTA_LOG_FUNC_LINE()        TRACE(2,LOG_TAG"%s:%d\n", __FUNCTION__, __LINE__)
       #define TOTA_LOG_FUNC_IN()          TRACE(1,LOG_TAG"%s ++++\n", __FUNCTION__)
      @@ -37,8 +37,8 @@ extern "C" {
       #define TOTA_LOG_DUMP               DUMP8
       #else
       #define TOTA_LOG_DBG(str,...)
      -#define TOTA_LOG_MSG(num,str,...)   TRACE(num,LOG_TAG"" str, ##__VA_ARGS__)
      -#define TOTA_LOG_ERR(num,str,...)   TRACE(num,LOG_TAG"err:""" str, ##__VA_ARGS__)
      +#define TOTA_LOG_MSG(num,str,...)   TRACE(num,LOG_TAG""str, ##__VA_ARGS__)
      +#define TOTA_LOG_ERR(num,str,...)   TRACE(num,LOG_TAG"err:"""str, ##__VA_ARGS__)
       
       #define TOTA_LOG_FUNC_LINE()
       #define TOTA_LOG_FUNC_IN()
      @@ -62,6 +62,7 @@ typedef enum
           APP_TOTA_VIA_SPP = 0,
           APP_TOTA_VIA_NOTIFICATION,
           APP_TOTA_VIA_INDICATION,
      +    APP_TOTA_GEN_VIA_SPP,
           APP_TOTA_TRANSMISSION_PATH_COUNT,
       
           APP_TOTA_PATH_IDLE = 0xff
      @@ -73,48 +74,57 @@ typedef enum
        */
       typedef enum
       {
      -    /* 0 */ OP_TOTA_RESPONSE_TO_CMD      = 0x8000, /**< the payload is: OP_TOTA_RESPONSE_TO_CMD + paramLen + BLE_TOTA_CMD_RSP_T */
      -    /* 1 */ OP_TOTA_START_DATA_XFER      = 0x8001,
      -    /* 2 */ OP_TOTA_VERIFY_DATA_SEGMENT  = 0x8002,
      -    /* 3 */ OP_TOTA_STOP_TOTA_DATA_XFER  = 0x8003,
      -    /* 4 */ OP_TOTA_SPP_DATA_ACK         = 0x8004,
      -
      -    /* 5 */ OP_TOTA_DEMO_CMD             = 0x8005,
      -    /* 6 */ OP_TOTA_GENERAL_CMD          = 0x8006,
      -
      -#if defined(TOTA_CRASH_DUMP_TOOL_ENABLE)
      -    OP_TOTA_CRASH_DUMP_REQ               = 0x8050,
      -    OP_TOTA_CRASH_DUMP_PARAM_REQ         = 0x8051,
      -    OP_TOTA_CRASH_DUMP_START_REQ         = 0x8052,
      -    OP_TOTA_CRASH_DUMP_RECEIVED_ACK      = 0x8053,
      -    OP_TOTA_CRASH_DUMP_END               = 0x8054,
      -    OP_TOTA_CRASH_DUMP_ERASE_FLASH       = 0x8055,
      -    OP_TOTA_CRASH_DUMP_HEART_BEAT        = 0x8056,
      -#endif
      -
      -    // TODO: add new command code here
      -    OP_TOTA_BATTERY_STATUS_CMD           = 0x9001,
      -    OP_TOTA_MERIDIAN_EFFECT_CMD          = 0x9002,
      -    OP_TOTA_EQ_SELECT_CMD                = 0x9003,
      -    OP_TOTA_VOLUME_PLUS_CMD              = 0x9004,
      -    OP_TOTA_VOLUME_DEC_CMD               = 0x9005,
      -    OP_TOTA_VOLUME_SET_CMD,
      -    OP_TOTA_VOLUME_GET_CMD,
      -    OP_TOTA_EQ_SET_CMD,
      -    OP_TOTA_EQ_GET_CMD,
      -    OP_TOTA_FWVERSION_GET_CMD,
      -    OP_TOTA_RSSI_GET_CMD,
      -    OP_TOTA_ANC_STATUS_SYNC_CMD          = 0x900C,
      -    OP_TOTA_ANC_ONOFF_WRITE_CMD          = 0x900D,
      -    OP_TOTA_ANC_LEVEL_WRITE_CMD          = 0x900E,
      -    OP_TOTA_ANC_STATUS_REPORT_CMD        = 0x900F,
      -    OP_TOTA_ANC_TOTAL_GAIN_WRITE_CMD     = 0x9020,
      -
      -    OP_TOTA_AUDIO_DUMP_CMD               = 0x9030,
      +    /* basic cmd */
      +    OP_TOTA_STRING                       = 0x1000,
      +    OP_TOTA_CONN_INITIATE                = 0x1001,
      +    OP_TOTA_CONN_RESPONSE                = 0x1002,
      +    OP_TOTA_CONN_CONFIRM                 = 0x1003,
      +
      +    /* response cmd */
      +    OP_TOTA_RESPONSE_TO_CMD              = 0x6000, /**< the payload is: OP_TOTA_RESPONSE_TO_CMD + paramLen + BLE_TOTA_CMD_RSP_T */
      +    OP_TOTA_SPP_DATA_ACK                 = 0x6001,
      +
      +    /* test cmd: test ok */
      +    OP_TOTA_TEST_CMD                     = 0x6100,
      +    OP_TOTA_ECHO_TEST_CMD                = 0x6101,
      +    OP_TOTA_DEMO_CMD                     = 0x6102,
      +
      +    /* flash cmd: test ok */
      +    OP_TOTA_WRITE_FLASH_CMD              = 0x6200,
      +    OP_TOTA_ERASE_FLASH_CMD              = 0x6201,
      +
      +    /* general info cmd: test ok */
      +    OP_TOTA_GENERAL_INFO_CMD             = 0x6300,
      +    OP_TOTA_MERIDIAN_EFFECT_CMD          = 0x6301,
      +    OP_TOTA_EQ_SELECT_CMD                = 0x6302,
      +    OP_TOTA_VOLUME_PLUS_CMD              = 0x6303,
      +    OP_TOTA_VOLUME_DEC_CMD               = 0x6304,
      +    OP_TOTA_VOLUME_SET_CMD               = 0x6305,
      +    OP_TOTA_VOLUME_GET_CMD               = 0x6306,
      +    OP_TOTA_EQ_SET_CMD                   = 0x6307,
      +    OP_TOTA_EQ_GET_CMD                   = 0x6308,
      +
      +    /* audio dump and mic cmd */
      +    OP_TOTA_AUDIO_DUMP_START             = 0x6400,
      +    OP_TOTA_AUDIO_DUMP_STOP              = 0x6401,
      +    OP_TOTA_AUDIO_DUMP_CONTROL           = 0x6402,
      +    OP_TOTA_MIC_TEST_ON                  = 0x6403,
      +    OP_TOTA_MIC_TEST_OFF                 = 0x6404,
      +    OP_TOTA_MIC_SWITCH                   = 0x6405,
      +    /* custom cmd */
      +    // TODO:
      +    OP_TOTA_FACTORY_RESET                = 0x8000,
      +    OP_TOTA_CLEAR_PAIRING_INFO           = 0x8001,
      +    OP_TOTA_SHUTDOWM                     = 0x8002,
      +    OP_TOTA_REBOOT                       = 0x8003,
      +
      +    // TODO:?
           OP_TOTA_RAW_DATA_SET_CMD             = 0x9100,
      -    OP_TOTA_COMMAND_COUNT,
       
      -    OP_TOTA_DATA_XFER                    = 0xFFFF, // to mark that it's a data packet
      +    /* commond count */
      +    OP_TOTA_COMMAND_COUNT,
      +    /* to mark that it's a data packet */
      +    OP_TOTA_STREAM_DATA                  = 0xFFFF,
       } APP_TOTA_CMD_CODE_E;
       
       /**
      @@ -136,6 +146,8 @@ typedef enum
           TOTA_DATA_SEGMENT_CRC_CHECK_FAILED = 10,
           TOTA_WHOLE_DATA_CRC_CHECK_FAILED = 11,
           TOTA_DATA_XFER_LEN_NOT_MATCHED = 12,
      +    TOTA_WRITE_FLASH_CRC_CHECK_FAILED = 13,
      +    TOTA_MIC_SWITCH_FAILED,
           // TO ADD: new return status
       } APP_TOTA_CMD_RET_STATUS_E;
       
  • services/tota/app_tota_cmd_handler.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/tota/app_tota_cmd_handler.h bes/services/tota/app_tota_cmd_handler.h
      index b0e5d28f297..a48131758c6 100644
      --- a/services/tota/app_tota_cmd_handler.h
      +++ b/services/tota/app_tota_cmd_handler.h
      @@ -27,7 +27,7 @@ extern "C" {
       
       
       /**< maximum payload size of one smart voice command */
      -#define TOTA_MAXIMUM_DATA_PACKET_LEN        672
      +#define TOTA_MAXIMUM_DATA_PACKET_LEN        660 //672
       #define APP_TOTA_CMD_MAXIMUM_PAYLOAD_SIZE   TOTA_MAXIMUM_DATA_PACKET_LEN
       
       /**
  • services/tota/app_tota_data_handler.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/tota/app_tota_data_handler.h bes/services/tota/app_tota_data_handler.h
      index 2ae838e4540..dc62028245b 100644
      --- a/services/tota/app_tota_data_handler.h
      +++ b/services/tota/app_tota_data_handler.h
      @@ -73,6 +73,7 @@ void app_tota_data_xfer_stopped(APP_TOTA_CMD_RET_STATUS_E retStatus);
       void app_tota_data_segment_verified(APP_TOTA_CMD_RET_STATUS_E retStatus);
       //void app_tota_data_received_callback(uint8_t* ptrData, uint32_t dataLength);
       void app_tota_send_data(APP_TOTA_TRANSMISSION_PATH_E path, uint8_t* ptrData, uint32_t dataLength);
      +void app_tota_send_data_stream(APP_TOTA_TRANSMISSION_PATH_E path, uint8_t* ptrData, uint32_t dataLength);
       void app_tota_start_data_xfer(APP_TOTA_TRANSMISSION_PATH_E path, APP_TOTA_START_DATA_XFER_T* req);
       void app_tota_stop_data_xfer(APP_TOTA_TRANSMISSION_PATH_E path, APP_TOTA_STOP_DATA_XFER_T* req);
       APP_TOTA_CMD_RET_STATUS_E app_tota_data_received(uint8_t* ptrData, uint32_t dataLength);
  • services/tota/app_tota.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/services/tota/app_tota.h bes/services/tota/app_tota.h
      index f082d0b2606..173511190f0 100644
      --- a/services/tota/app_tota.h
      +++ b/services/tota/app_tota.h
      @@ -24,6 +24,7 @@
       #define APP_TOTA_CONNECTED             (1 << 0)
       #define APP_TOTA_DISCONNECTED          (~(1 << 0))
       
      +#define TOTA_SHARE_TX_RX_BUF    1
       
       #ifdef __cplusplus
       extern "C" {
      @@ -36,6 +37,7 @@ extern "C" {
       #define TOTA_SERVICE_DATA_WRITE_LENGTH  4*32
       #define TOTA_SERVICE_DATA_READ_LENGTH   4*32
       #endif
      +#define FLASH_SECTOR_SIZE_IN_BYTES 4*1024
       #define TOTA_DATA_BUFFER_SIZE_FOR_BURNING FLASH_SECTOR_SIZE_IN_BYTES
       #define TOTA_SERVICE_SYNC_WORD  0x54534542
       #define TOTA_SERVICE_SYNC_DATA_1    0xbe
      @@ -77,6 +79,7 @@ typedef enum{
           TOTA_SERVICE_CMD_SHUTDOWM,
           TOTA_SERVICE_CMD_MIC_TEST_ON,
           TOTA_SERVICE_CMD_MIC_TEST_OFF,
      +    TOTA_SERVICE_CMD_MIC_SWITCH,
           TOTA_SERVICE_CMD_COUNT = 0xff,          /*valid payload                                                                     */
       }TOTA_GENERAL_CMD_E;
       
      @@ -208,16 +211,27 @@ typedef struct
       void app_tota_init(void);
       void app_tota_connected(uint8_t connType);
       void app_tota_disconnected(uint8_t disconnType);
      +void app_tota_general_connected(uint8_t connType);
       bool app_is_in_tota_mode(void);
       void app_tota_update_datapath(APP_TOTA_TRANSMISSION_PATH_E dataPath);
       APP_TOTA_TRANSMISSION_PATH_E app_tota_get_datapath(void);
       
       
      +/* interface */
      +void tota_connected_handle();
      +void tota_disconnected_handle();
      +bool is_tota_connected();
      +void tota_set_encrypt_key_from_hash_key(uint8_t * set_key);
       
       
      +uint8_t * tota_encrypt_packet(uint8_t * in, uint32_t inLen, uint32_t * poutLen);
      +uint8_t * tota_decrypt_packet(uint8_t * in, uint32_t inLen, uint32_t * poutLen);
       
      +void tota_printf(const char * format, ...);
       
       
      +/*todo: for test*/
      +void test_aes_encode_decode();
       
       
       
  • utils/boot_struct/tool_msg.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/utils/boot_struct/tool_msg.h bes/utils/boot_struct/tool_msg.h
      index 62a7e8cb8ee..cb963751d18 100644
      --- a/utils/boot_struct/tool_msg.h
      +++ b/utils/boot_struct/tool_msg.h
      @@ -119,6 +119,7 @@ enum SYS_CMD_TYPE {
           SYS_CMD_SET_BOOTMODE = 0xE1,
           SYS_CMD_CLR_BOOTMODE = 0xE2,
           SYS_CMD_GET_BOOTMODE = 0xE3,
      +    SYS_CMD_SET_DLD_RATE = 0xD1,
       };
       
       enum ERR_CODE {
  • utils/cqueue/cqueue.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/utils/cqueue/cqueue.h bes/utils/cqueue/cqueue.h
      index 5dbd293a74a..81c8293a92f 100644
      --- a/utils/cqueue/cqueue.h
      +++ b/utils/cqueue/cqueue.h
      @@ -36,8 +36,6 @@ typedef struct __CQueue
           CQItemType *base;
       } CQueue;
       
      -typedef uint16_t (*FRAME_LEN_GETTER_T)(CQueue* q);
      -
       /* Init Queue */
       int InitCQueue(CQueue *Q, unsigned int size, CQItemType *buf);
       /* Is Queue Empty */
      @@ -49,7 +47,7 @@ int AvailableOfCQueue(CQueue *Q);
       /* Push Data Into Queue (Tail) */
       int EnCQueue(CQueue *Q, CQItemType *e, unsigned int len);
       /* Push Data Into Queue (Tail) */
      -int EnCQueue_AI(CQueue *Q, CQItemType *e, unsigned int len, FRAME_LEN_GETTER_T getter);
      +int EnCQueue_AI(CQueue *Q, CQItemType *e, unsigned int len);
       /* Push Data Into Front Of Queue */
       int EnCQueueFront(CQueue *Q, CQItemType *e, unsigned int len);
       /* Pop Data Data From Queue (Front) */
  • utils/crc32/crc32.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/utils/crc32/crc32.h bes/utils/crc32/crc32.h
      index 6e72dd5c6ac..44fada01b2e 100644
      --- a/utils/crc32/crc32.h
      +++ b/utils/crc32/crc32.h
      @@ -19,7 +19,7 @@
       extern "C" {
       #endif
       
      -unsigned long crc32_c(unsigned long crc, const unsigned char *buf, unsigned int len);
      +unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len);
       
       #ifdef __cplusplus
       }
  • utils/intersyshci/intersyshci.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/utils/intersyshci/intersyshci.h bes/utils/intersyshci/intersyshci.h
      index 7b79b4d18be..5852878767d 100644
      --- a/utils/intersyshci/intersyshci.h
      +++ b/utils/intersyshci/intersyshci.h
      @@ -21,12 +21,18 @@
       extern "C" {
       #endif
       
      +void BESHCI_BufferAvai(void *packet);
       void BESHCI_Open(void);
       void BESHCI_Close(void);
      -void BESHCI_LOCK_TX(void);
      -void BESHCI_UNLOCK_TX(void);
      +void BESHCI_Poll(void);
      +void BESHCI_LockBuffer(void);
      +void BESHCI_UNLockBuffer(void);
      +void BESHCI_SCO_Data_Start(void);
      +void BESHCI_SCO_Data_Stop(void);
      +void uartrxtx(void const *argument);
       
       bool BESHCI_Controller_Log_Handler(const unsigned char *p_buff, uint32_t length);
      +void BESHCI_Dump_A2DP_Seq(const unsigned char *p_buff, uint32_t length);
       typedef bool (*intersys_hci_cmd_filter_handler_func)(uint8_t* pbuf, uint32_t length);
       void intersys_register_hci_cmd_filter_handler_callback(intersys_hci_cmd_filter_handler_func func);
       
  • utils/intersyshci/trans_adapt.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/utils/intersyshci/trans_adapt.h bes/utils/intersyshci/trans_adapt.h
      index 183342d4fc4..3557a871ff8 100644
      --- a/utils/intersyshci/trans_adapt.h
      +++ b/utils/intersyshci/trans_adapt.h
      @@ -19,7 +19,11 @@
       extern "C" {
       #endif
       
      +#if defined(ENHANCED_STACK)
       #include "trans_adapt_v2.h"
      +#else
      +#include "trans_adapt_v1.h"
      +#endif
       
       #if defined(__cplusplus)
       }
  • utils/intersyshci/trans_adapt_v2.h

    • Declared BES License in SDK version.

    • Relicense to Apache-2.0.

    • Diff of changes (click to view)
      diff --git reconstruction/utils/intersyshci/trans_adapt_v2.h bes/utils/intersyshci/trans_adapt_v2.h
      index 3653da2cca9..d44cacc70c9 100644
      --- a/utils/intersyshci/trans_adapt_v2.h
      +++ b/utils/intersyshci/trans_adapt_v2.h
      @@ -19,8 +19,8 @@
       extern "C" {
       #endif
       
      -void bes_pack_bt_hci_data(unsigned char type, unsigned short cmd_conn, unsigned short len, unsigned char *buffer);
      -int bes_pack_le_hci_data(unsigned char packet_type, unsigned char *packet, int size);
      +void BESHCI_SendData(unsigned char type, unsigned short cmd_conn, unsigned short len, unsigned char *buffer);
      +int BESHCI_SendBuffer(unsigned char packet_type, unsigned char *packet, int size);
       unsigned short hci_h4_receive_msg( const uint8_t *buf, uint32_t size);
       
       #if defined(__cplusplus)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant