/**********************************************************************
*
*   strong_symbol.c
*   定义库里面部分WEAK函数的Strong函数，动态关闭库代码
***********************************************************************/
#include "include.h"
#include "driver_uart.h"

uint8_t cfg_spiflash_speed_up_en = SPIFLASH_SPEED_UP_EN;

#if SYS_SLEEP_LEVEL == SLEEP_LEVEL_LV1
uint8_t cfg_bt_sniff_clk_sel = CLK_31K25;
#else
uint8_t cfg_bt_sniff_clk_sel = CLK_RCDIV;
#endif


#if FUNC_USBD_EN
u8 mem_heap[8*1024] AT(.mem_heap);

static const struct thread_cfg_cb thread_cfg =
{
   .bt_hw      =       {1, 11,  1024},
   .bt_stack   =       {1, 23, 1536},
   .aupcm      =       {1, 17, 1024},
   .dirver     =       {1, 6, 1024},
   .timer      =       {1, 16, 768},
   .main       =       {1, 25, 1024},
};

uint32_t mem_heap_size_get(void)
{
   return sizeof(mem_heap);
}

struct thread_cfg_cb* thread_cfg_get(void)
{
   return (struct thread_cfg_cb*)&thread_cfg;
}
#endif

uint8_t cfg_bt_rf_def_txpwr;

void ble_get_local_bd_addr(u8 *addr)
{
    memcpy(addr, xcfg_cb.le_addr, 6);
}

const uint8_t *bt_rf_get_param(void)
{
    cfg_bt_rf_def_txpwr = xcfg_cb.bt_rf_pwrdec;

    if(xcfg_cb.bt_rf_param_en) {
        cfg_bt_rf_def_txpwr = 0;
        return (const uint8_t *)&xcfg_cb.rf_pa_gain;
    } else {
        if (bt_get_ft_trim_value(&xcfg_cb.rf_pa_gain)) {
            return (const uint8_t *)&xcfg_cb.rf_pa_gain;
        }
    }
    return NULL;
}

u8 bt_rf_get_tx_pwr(void)
{
    return xcfg_cb.rf_tx_pwr;
}

void xosc_get_xcfg(u8 *osci_cap, u8 *osco_cap, u8 *both_cap)
{
    *osci_cap = xcfg_cb.osci_cap;
    *osco_cap = xcfg_cb.osco_cap;
    *both_cap = xcfg_cb.osc_both_cap;
}

void param_xosc_read(u8 *param)
{
    bsp_param_read(param, PARAM_BT_XOSC_CAP, PARAM_BT_XOSC_CAP_LEN);
}

void param_xosc_write(u8 *param)
{
    bsp_param_write(param, PARAM_BT_XOSC_CAP, PARAM_BT_XOSC_CAP_LEN);
    bsp_param_sync();
}

AT(.com_text.spiflash)
bool spiflash_data_protect_en(void)
{
    return false;
}

AT(.com_text.spiflash)
bool os_spiflash_addr_check(u32 addr, uint len)
{
    if ((addr >= CM_START) && ((addr + len) <= (CM_START + CM_SIZE))) {
        return true;
    }

#if AB_FOT_EN
    #if (AB_FOT_TYPE == AB_FOT_TYPE_PACK)
    if ((addr >= FOT_PACK_START) && ((addr + len) <= (FOT_PACK_START + FOT_PACK_SIZE))) {
        return true;
    }
    #endif
    #if (AB_FOT_TYPE == AB_FOT_TYPE_NORMAL)
    return true;
    #endif
#endif

    printf("-->os_spiflash_addr_err:0x%x\n", addr);

    return false;
}

#if (!LE_DUT_UART_EN)
void hci_fcc_init(void){}
#endif

AT(.com_text.timer)
void usr_tmr5ms_thread_callback(void)
{
    usr_tmr5ms_thread_do();
}

void sys_clk_change_callback(void)
{
#if BSP_UART_DEBUG_EN
    uart_baud_config(UART, UART_DEBUG_BAUD);
#endif // BSP_UART_DEBUG_EN
}

#if BSP_UART_DEBUG_EN
void uart_debug_init_callback(void)
{
    bsp_uart_debug_init();
}
#else
AT(.com_text.printf)
void uart_debug_putchar(char ch)
{

}

void uart_debug_init_callback(void)
{
    my_printf_init(uart_debug_putchar);
}
#endif // BSP_UART_DEBUG_EN

#if !AB_FOT_EN
u8 fot_checksum_cal(u8 *buf)
{
    return 0;
}
#endif

#if (SYS_SLEEP_LEVEL == SLEEP_LEVEL_LV1)
void rc_sleep_trim_init(void) {}
void rc_sleep_trim_clear(void) {}
u32 rc_sleep_get_freqcnt(void) {return 1;}
void rc_sleep_reset_sta(void) {}
u32 rc_sleep_get_trim_freqcnt(u32 *freqcnt) {return 0;}
void lowpwr_sleep_lv2_proc(void) {}
#else
void lowpwr_sleep_lv1_proc(void) {}
#endif

void ble_get_link_info(void *buf, u16 addr, u16 size)
{
    cm_read(buf, BLE_CM_PAGE(addr), size);
}

void ble_put_link_info(void *buf, u16 addr, u16 size)
{
    cm_write(buf, BLE_CM_PAGE(addr), size);
    cm_sync();
}

bool ble_mtu_exchange_enabled(void)
{
    return false;
}

bool ble_rx_exit_sleep(void)
{
    return false;
}

uint16_t ble_sm_send_security_req_time_get(void)
{
    return 500; //ms
}

bool ble_disconnected_restart_adv(void)
{
    return true;
}
