mcu_ab568x/userboot240328/app/platform/bsp/bsp_cm.c
2025-05-30 18:03:10 +08:00

77 lines
2.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "include.h"
#include "func.h"
#define TRACE_EN 0
#if TRACE_EN
#define TRACE(...) printf(__VA_ARGS__)
#else
#define TRACE(...)
#endif
///CM Init时判断该Page参数是否有效有效则加载
bool cm_loadparam(void *buff, uint page)
{
u8 *buf = buff;
uint key;
TRACE("cm_loadparam: %d\n", page);
if (page == SYS_CM_PAGE_NUM) {
sys_cb.vol = buf[PARAM_SYS_VOL];
// sys_cb.lang_id = LANG_SELECT;
#if MUSIC_BREAKPOINT_EN
if (f_msc.cur_dev == DEV_SDCARD) {
memcpy(&f_msc.brkpt, buf + PARAM_MSC_BRKPT_SD, 10);
} else if (f_msc.cur_dev == DEV_SDCARD1) {
memcpy(&f_msc.brkpt, buf + PARAM_MSC_BRKPT_SD1, 10);
} else {
memcpy(&f_msc.brkpt, buf + PARAM_MSC_BRKPT_USB, 10);
}
#endif // MUSIC_BREAKPOINT_EN
if(sys_cb.vol > VOL_MAX) {
TRACE("vol: %d error\n", sys_cb.vol);
return false; //音量值无效
}
key = GET_LE32(buf + PARAM_RANDOM_KEY);
if (key == 0 || key == UINT_MAX) {
TRACE("key: %d error\n", key);
return false;
}
}
return true;
}
///CM Init时如果找不到有效的参数则进行出厂值设置
void cm_factory(void *buff, uint page)
{
u8 *buf = buff;
memset(buf, 0, 250);
TRACE("cm_factory: %d\n", page);
if (page == SYS_CM_PAGE_NUM) {
//系统参数初始化
sys_cb.vol = SYS_INIT_VOLUME;
sys_cb.hfp_vol = SYS_INIT_VOLUME / sys_cb.hfp2sys_mul;
#if MUSIC_BREAKPOINT_EN
memset(&f_msc.brkpt, 0, 10);
#endif // MUSIC_BREAKPOINT_EN
// sys_cb.lang_id = LANG_SELECT;
#if FUNC_MUSIC_EN
f_msc.file_num = 1;
PUT_LE16(buf + PARAM_MSC_NUM_SD, f_msc.file_num);
PUT_LE16(buf + PARAM_MSC_NUM_USB, f_msc.file_num);
#endif
buf[PARAM_SYS_VOL] = sys_cb.vol;
//buf[PARAM_HSF_VOL] = sys_cb.hfp_vol;
// buf[PARAM_LANG_ID] = sys_cb.lang_id;
PUT_LE32(buf + PARAM_RANDOM_KEY, sys_get_rand_key());
}
}