This commit is contained in:
2025-03-31 14:34:55 +08:00
5 changed files with 38 additions and 194 deletions

View File

@@ -116,7 +116,7 @@ void ledc_timer_ctrl(LEDC_PORT port, uint8_t status);
void ledc_cnt_ena(LEDC_PORT port, uint8_t status);
/**
* @brief ledc_polarity_sel() - ledc输出极性选择
* @brief ledc_polarity_sel() - ledc输出极性选择
* @param port: ledc 通道
* @param polarity: OUT_POL_ORIGINAL 不反相
* OUT_POL_INVERT 反相
@@ -124,7 +124,8 @@ void ledc_cnt_ena(LEDC_PORT port, uint8_t status);
void ledc_polarity_sel(LEDC_PORT port, uint8_t polarity);
/**
* @brief ledc_idle_level_sel() - ledc空闲时电平状态选择
* @brief ledc_idle_level_sel() - ledc空闲时电平状态选择
* 空闲是指关闭占空比的情况
* @param port: ledc 通道
* @param level: IDLE_LEVEL_HIGH 空闲时为高电平
* IDLE_LEVEL_LOW 空闲时为低电平
@@ -168,7 +169,7 @@ void ledc_l2h_point_set(LEDC_PORT port, uint16_t point);
void ledc_duty_cnt_sel(LEDC_PORT port, uint8_t duty_cnt);
/**
* @brief ledc_thrs_set() - 计数器阈值设置
* @brief ledc_thrs_set() - 计数器阈值设置,计数器大于这个值之后会重新开始计数
* @param port: ledc 通道
* @param thrs: 阈值范围0-0xffff
*/
@@ -211,35 +212,36 @@ void ledc_phase1_mode_sel(LEDC_PORT port, uint8_t mode);
void ledc_phase2_mode_sel(LEDC_PORT port, uint8_t mode);
/**
* @brief ledc_phase1_scale_set() - phase1的渐变幅度设置
* @brief ledc_phase1_scale_set() - phase1的渐变幅度设置scale为一次计数器周期中变化的count数
* @param port: ledc 通道
* @param scale: 范围 0-0xff
*/
void ledc_phase1_scale_set(LEDC_PORT port, uint8_t scale);
/**
* @brief ledc_phase2_scale_set() - phase2的渐变幅度设置
* @brief ledc_phase2_scale_set() - phase2的渐变幅度设置scale为一次计数器周期中变化的count数
* @param port: ledc 通道
* @param scale: 范围 0-0xff
*/
void ledc_phase2_scale_set(LEDC_PORT port, uint8_t scale);
/**
* @brief ledc_cycle_times_set() - 设置一个loop里有多少个cycle
* @brief ledc_cycle_times_set() - 设置一个loop里有多少个cycle,
* phase1 blink加上phase2 blink所使用的时间为一个cycle
* @param port: ledc 通道
* @param times: 范围 0-0xff
*/
void ledc_cycle_times_set(LEDC_PORT port, uint8_t times);
/**
* @brief ledc_cycle_times_set() - 设置一共多少个loop
* @brief ledc_loop_times_set() - 设置一共多少个loop
* @param port: ledc 通道
* @param times: 范围 0-0xff
*/
void ledc_loop_times_set(LEDC_PORT port, uint8_t times);
/**
* @brief ledc_nop_num_set() - 设置一共多少个loop
* @brief ledc_nop_num_set() - 设置一个loop里有多少个nop计数器周期,这个时候处于空闲状态
* @param port: ledc 通道
* @param times: 范围 0-0xff
*/
@@ -253,7 +255,7 @@ void ledc_nop_num_set(LEDC_PORT port, uint16_t num);
void ledc_common_cnt_ena(uint8_t en);
/**
* @brief ledc_common_thrs_set() - 共用计数器阈值设置
* @brief ledc_common_thrs_set() - 共用计数器阈值设置,计数器大于这个值之后会重新开始计数
* @param thrs: 阈值范围0-0xffff
*/
void ledc_common_thrs_set(uint16_t thrs);

View File

@@ -137,6 +137,7 @@ void ledc_gpio_config(LEDC_PORT port, uint8_t gpio)
gpio_module_sig_select(&info, GPIO_MTX_MODE_MATRIX);
}
// 定时器复位
void ledc_timer_rst(LEDC_PORT port)
{
uint32_t tmp;
@@ -152,6 +153,7 @@ void ledc_timer_rst(LEDC_PORT port)
timer_hw_write_reg(port, CFG_LEDC_TIMER0_CONF_ADDR, tmp);
}
// 定时器初始化 div是分频实际分频为div+1
void ledc_timer_init(LEDC_PORT port, uint16_t div)
{
uint32_t tmp;
@@ -165,6 +167,7 @@ void ledc_timer_init(LEDC_PORT port, uint16_t div)
timer_hw_write_reg(port, CFG_LEDC_TIMER0_CONF_ADDR, tmp);
}
// 定时器启动或暂停 1启动 0暂停
void ledc_timer_ctrl(LEDC_PORT port, uint8_t status)
{
uint32_t tmp;
@@ -185,6 +188,7 @@ void ledc_timer_ctrl(LEDC_PORT port, uint8_t status)
timer_hw_write_reg(port, CFG_LEDC_TIMER0_CONF_ADDR, tmp);
}
// 输出极性 1反向 0不反向
void ledc_polarity_sel(LEDC_PORT port, uint8_t polarity)
{
uint32_t tmp;
@@ -198,6 +202,7 @@ void ledc_polarity_sel(LEDC_PORT port, uint8_t polarity)
ledc_hw_write_reg(port, CFG_LEDC0_CONF_ADDR, tmp);
}
// 空闲时状态 1空闲时高 0 空闲时低
void ledc_idle_level_sel(LEDC_PORT port, uint8_t level)
{
uint32_t tmp;
@@ -211,6 +216,7 @@ void ledc_idle_level_sel(LEDC_PORT port, uint8_t level)
ledc_hw_write_reg(port, CFG_LEDC0_CONF_ADDR, tmp);
}
// 相位1闪烁次数
void ledc_phase1_blink_times_set(LEDC_PORT port, uint16_t times)
{
uint32_t tmp;
@@ -225,6 +231,7 @@ void ledc_phase1_blink_times_set(LEDC_PORT port, uint16_t times)
}
// 相位2闪烁次数
void ledc_phase2_blink_times_set(LEDC_PORT port, uint16_t times)
{
uint32_t tmp;
@@ -239,6 +246,7 @@ void ledc_phase2_blink_times_set(LEDC_PORT port, uint16_t times)
}
// 控制脉冲输出由高到低的时钟刻度
void ledc_h2l_point_set(LEDC_PORT port, uint16_t point)
{
uint32_t tmp;
@@ -252,6 +260,7 @@ void ledc_h2l_point_set(LEDC_PORT port, uint16_t point)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF0_ADDR, tmp);
}
// 控制脉冲由低到高的时钟刻度
void ledc_l2h_point_set(LEDC_PORT port, uint16_t point)
{
uint32_t tmp;
@@ -265,6 +274,7 @@ void ledc_l2h_point_set(LEDC_PORT port, uint16_t point)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF0_ADDR, tmp);
}
// 选择计数器 0使用自身参考时钟 1使用通用时钟
void ledc_duty_cnt_sel(LEDC_PORT port, uint8_t duty_cnt)
{
uint32_t tmp;
@@ -278,6 +288,7 @@ void ledc_duty_cnt_sel(LEDC_PORT port, uint8_t duty_cnt)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF1_ADDR, tmp);
}
// 打开占空比计数
void ledc_cnt_ena(LEDC_PORT port, uint8_t en)
{
uint32_t tmp;
@@ -291,6 +302,7 @@ void ledc_cnt_ena(LEDC_PORT port, uint8_t en)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF1_ADDR, tmp);
}
// 设置占空比阈值
void ledc_thrs_set(LEDC_PORT port, uint16_t thrs)
{
uint32_t tmp;
@@ -304,6 +316,7 @@ void ledc_thrs_set(LEDC_PORT port, uint16_t thrs)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF1_ADDR, tmp);
}
// 相位模式选择 0普通模式 1相位模式
void ledc_phase_opt_sel(LEDC_PORT port, uint8_t opt)
{
uint32_t tmp;
@@ -317,6 +330,7 @@ void ledc_phase_opt_sel(LEDC_PORT port, uint8_t opt)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF5_ADDR, tmp);
}
// 相位数量 0单相位 1双相位
void ledc_phase_num_sel(LEDC_PORT port, uint8_t num)
{
uint32_t tmp;
@@ -330,6 +344,7 @@ void ledc_phase_num_sel(LEDC_PORT port, uint8_t num)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF5_ADDR, tmp);
}
// 相位1的相位模式 0占空比模式 1保持关闭 2递增模式 3递减模式
void ledc_phase1_mode_sel(LEDC_PORT port, uint8_t mode)
{
uint32_t tmp;
@@ -344,6 +359,7 @@ void ledc_phase1_mode_sel(LEDC_PORT port, uint8_t mode)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF5_ADDR, tmp);
}
// 相位2的相位模式 0占空比模式 1保持关闭 2递增模式 3递减模式
void ledc_phase2_mode_sel(LEDC_PORT port, uint8_t mode)
{
uint32_t tmp;
@@ -359,6 +375,7 @@ void ledc_phase2_mode_sel(LEDC_PORT port, uint8_t mode)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF5_ADDR, tmp);
}
// 相位1阴影模式下的信号周期变化程度
void ledc_phase1_scale_set(LEDC_PORT port, uint8_t scale)
{
uint32_t tmp;
@@ -372,6 +389,7 @@ void ledc_phase1_scale_set(LEDC_PORT port, uint8_t scale)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF1_ADDR, tmp);
}
// 相位2阴影模式下的信号周期变化幅度
void ledc_phase2_scale_set(LEDC_PORT port, uint8_t scale)
{
uint32_t tmp;
@@ -385,6 +403,7 @@ void ledc_phase2_scale_set(LEDC_PORT port, uint8_t scale)
ledc_hw_write_reg(port, CFG_LEDC0_DUTY_CONF5_ADDR, tmp);
}
// 无nop状态的循环数
void ledc_cycle_times_set(LEDC_PORT port, uint8_t times)
{
uint32_t tmp;

View File

@@ -27,7 +27,7 @@
#define LEDC0_OUT_INV_MASK 0x00000200
#define LEDC0_IDLE_LV_OFFSET 8
#define LEDC0_IDLE_LV_MASK 0x00000100
#define LEDC0_TIMER_SEL_OFFSET 0
#define LEDC0_TIMER_SEL_OFFSET 0 // 每个通道使用公共定时器的时候可以选择定时器?
#define LEDC0_TIMER_SEL_MASK 0x000000FF
//-----------------------------------

View File

@@ -1065,186 +1065,6 @@ static int ramCalDumpAfterBurn(void)
return 0;
}
static int ramMatchEnctypeAndPattern(uint8_t enctype, uint8_t pattern)
{
/*
*ret 0: The match is successful
*ret not 0: The match is failure
*/
int ret = 0;
/*
* enctype 0 : FW not encrypted.
* enctype 3 : FW encrypted with xor.
* pattern : value for encrypting.
* HTZD FW : enctype = 0, pattern = 0x55.(default)
* JSMT FW : enctype = 3, pattern = 0xaa.
* FLX FW : enctype = 3, pattern = 0x99.
* QJ FW : enctype = 3, pattern = 0x66.
* SPE FW : enctype = 3, pattern = 0xcc.
* GX FW : enctype = 3, pattern = 0x33.
* DT FW : enctype = 3, pattern = 0xdd.
* YP FW : enctype = 3, pattern = 0xa9.
* WTZ FW : enctype = 3, pattern = 0xc6.
* TCE FW : enctype = 3, pattern = 0x93.
*/
switch (enctype) {
case 0:
switch (pattern) {
case 0x55:
/* plain image */
if (
/* HT */
(g_chip_subid != CHIP_ID_HZ3201_V1A) &&
(g_chip_subid != CHIP_ID_HZ3211_V1A) &&
(g_chip_subid != CHIP_ID_HZ3201_RF_V1A) &&
(g_chip_subid != CHIP_ID_HZ3211_RF_V1A) &&
(g_chip_subid != CHIP_ID_HZ5202_V1A) &&
(g_chip_subid != CHIP_ID_HZ_K48V1A) &&
(g_chip_subid != CHIP_ID_HZ_K48V2A) &&
(g_chip_subid != CHIP_ID_HZ_K48V3A) &&
(g_chip_subid != CHIP_ID_HZ_K68V1A) &&
(g_chip_subid != CHIP_ID_HZ_K68V2A) &&
(g_chip_subid != CHIP_ID_HZ_K68V3A) &&
/* WQ */
(g_chip_subid != CHIP_ID_WQ3021_REVA) &&
(g_chip_subid != CHIP_ID_WQ3021_REVB) &&
(g_chip_subid != CHIP_ID_WQ3021_REVC) &&
(g_chip_subid != CHIP_ID_WQ3021_REVD) &&
(g_chip_subid != CHIP_ID_WQ3031_V1A) &&
(g_chip_subid != CHIP_ID_WQ5007_REVA) &&
(g_chip_subid != CHIP_ID_WQ5007_REVB) &&
(g_chip_subid != CHIP_ID_WQ5106_REVB) &&
(g_chip_subid != CHIP_ID_WQ_K48V2A) &&
(g_chip_subid != CHIP_ID_WQ_K48V2A2) &&
(g_chip_subid != CHIP_ID_WQ_K48V3A) &&
(g_chip_subid != CHIP_ID_WQ_K48V3A2) &&
(g_chip_subid != CHIP_ID_WQ_K48V3A3) &&
(g_chip_subid != CHIP_ID_WQ_K68V3A) &&
(g_chip_subid != CHIP_ID_WQ_K68V3A2) &&
/* FLX */
(g_chip_subid != CHIP_ID_FLX_K48) &&
(g_chip_subid != CHIP_ID_FLX_K68)) {
/*
* HTZD FW (no xor) can be burn on FLX6610/FLX6611.
*/
ret = 3;
}
break;
default:
ret = 2;
break;
}
break;
case 3:
switch (pattern) {
case 0xaa:
/* scramble image */
if ((g_chip_subid != CHIP_ID_MT_K68V1B) &&
(g_chip_subid != CHIP_ID_MT_K68V1BB) &&
(g_chip_subid != CHIP_ID_MT_K68V2B) &&
(g_chip_subid != CHIP_ID_MT_K68V2BB) &&
(g_chip_subid != CHIP_ID_MT_K68V3B) &&
(g_chip_subid != CHIP_ID_MT_K68V3BB) &&
(g_chip_subid != CHIP_ID_MT_K68V3A)) {
ret = 3;
}
break;
case 0x99:
/* scramble image */
if ((g_chip_subid != CHIP_ID_FLX_K68) &&
(g_chip_subid != CHIP_ID_FLX_K48) &&
(g_chip_subid != CHIP_ID_FLX6710_V1A) &&
(g_chip_subid != CHIP_ID_FLX6711_V1A)) {
/*
* FLX FW (xor) can be burn on FLX chip
*/
ret = 3;
}
break;
case 0x66:
/* scramble image */
if ((g_chip_subid != CHIP_ID_QJ5580D_V1A) &&
(g_chip_subid != CHIP_ID_QJ5582D_V1A)) {
/*
* QJ FW (xor) can only be burn on QJ5580D/QJ5582D.
*/
ret = 3;
}
break;
case 0xcc:
/* scramble image */
if ((g_chip_subid != CHIP_ID_SPE7303_V1A) &&
(g_chip_subid != CHIP_ID_SPE7301_V1A)) {
/*
* SPE FW (xor) can only be burn on SPE7303/SPE7301.
*/
ret = 3;
}
break;
case 0x33:
/* scramble image */
if ((g_chip_subid != CHIP_ID_GX2001_V1A) &&
(g_chip_subid != CHIP_ID_GX2011_V1A)) {
/*
* GX FW (xor) can only be burn on GX2001/GX2011.
*/
ret = 3;
}
break;
case 0xdd:
/* scramble image */
if ((g_chip_subid != CHIP_ID_DT0530_V1A) &&
(g_chip_subid != CHIP_ID_DT0531_V1A)) {
/*
* DT FW (xor) can only be burn on DT0530/DT0531.
*/
ret = 3;
}
break;
case 0xa9:
/* scramble image */
if ((g_chip_subid != CHIP_ID_YP8801_V1A) &&
(g_chip_subid != CHIP_ID_YP8811_V1A)) {
/*
* YP FW (xor) can only be burn on YP8801/YP8811.
*/
ret = 3;
}
break;
case 0xc6:
/* scramble image */
if ((g_chip_subid != CHIP_ID_WTZ31C_V1A) &&
(g_chip_subid != CHIP_ID_WTZ31S_V1A)) {
/*
* WTZ FW (xor) can only be burn on WTZ31C/WTZ31S.
*/
ret = 3;
}
break;
case 0x93:
/* scramble image */
if ((g_chip_subid != CHIP_ID_TCE3202_V1A) &&
(g_chip_subid != CHIP_ID_TCE3201_V1A)) {
/*
* TCE FW (xor) can only be burn on TCE3202/TCE3201.
*/
ret = 3;
}
break;
default:
ret = 2;
break;
}
break;
default:
ret = 1;
break;
}
return ret;
}
static int ramDownloadPackage(void)
{
rbuf xbuf;
@@ -1443,10 +1263,6 @@ static int ramDownloadPackage(void)
pkg_hdr_ver_micro = (pkg_hdr_version >> 16) & 0x0F;
pkg_hdr_ver_build = (pkg_hdr_version >> 0) & 0xFFFF;
if (ramMatchEnctypeAndPattern(pkg_hdr->enctype, pkg_hdr->pattern) != 0) {
ram_error_no |= RAM_IMAGE_MISMATCH_ERR;
goto ERROR_OUT;
}
// 接收了3个imgheader长度,是pkgheader
} else if (toltalRecieved == 3 * IMAGE_ALIGNED_SIZE) {
pkg_hdr_fw_type = pkg_hdr->img_type;

View File

@@ -218,9 +218,12 @@ interrupt:
.global entry_mip
.global entry_mcause
// cpu
trap_entry:
/* Interrupt trap */
// t0
csrw mscratch, t0
/* 保存mcause && mip 到pmpaddr中 */
csrr t0, mcause
@@ -228,11 +231,15 @@ trap_entry:
csrr t0, mip
csrw pmpaddr15, t0
// 线
andi t0, t0, -1912 // -1912 = 0x888
// bnez jal x1 ra
bnez t0, interrupt
/* System call and other traps */
// mscratcht0 spmscratch
csrrw t0, mscratch, sp
//
la sp, _trap_sp
#ifndef __riscv_float_abi_soft
addi sp, sp, -REGBYTES*64