Commit 012b8d05 authored by 陈家乐's avatar 陈家乐

🐞 fix:优化串口初始化速度(中微厂家更改)

parent 344db24e
...@@ -103,7 +103,96 @@ void sci_error_log_internal(int8_t err, const char *file, int32_t line) ...@@ -103,7 +103,96 @@ void sci_error_log_internal(int8_t err, const char *file, int32_t line)
/* Do nothing. */ /* Do nothing. */
} }
} }
#if 1
/**
* @brief Calculate the register setting options for baud rate to UART peripheral.
* @param fclk_freq: System clock value on chip.
* @param baud: The target baud rate which want to setting.
* @param pValue: UART baud rate setting option data structure.
* @param cur_sps: current SPS register value, clock sharing it with other channels, Try not to modify it as much as possible.
* if 'cur_sps = 0x00' or 'cur_sps = FORCE_RECONF', Ignore the original register value and force reconfiguration. laidi
* @retval None
*/
float SCIPeriphal_ClockUpdate(SCIAFSelect_TypeDef func, uint32_t fclk, uint32_t ftclk, uint8_t cur_sps, SCIPeriph_Clock_TypeDef *clock)
{
#define CALCULATE_MAX_SPS 0x0F
#define CALCULATE_MAX_SDR 0x7F
#define FORCE_RECONF 0xFF
uint8_t i;
uint8_t min_sdr, max_sps;
uint32_t cal_fmck = 0;
int16_t idea_sdr;
uint8_t sdr_int;
uint16_t max_err = 0xFFFF, temp_err = 0xFFFF;
float ret_err = 100.0;
if(ftclk == 0)
{
return ret_err;
}
if (func & SCI_UART_MASK)
{
min_sdr = 2;
}
else if (func & SCI_I2C_MASK)
{
min_sdr = 1;
}
else
{
min_sdr = 0;
}
if ((cur_sps == 0x00) || (cur_sps == FORCE_RECONF))
{
max_sps = CALCULATE_MAX_SPS + 1;
}
else
{
clock->sps = cur_sps;
max_sps = 1; /* for (i..) loop once */
}
for (i = 0; i < max_sps; i++)
{
/* cac fMCK, SPS reg*/
if ((cur_sps == 0x00) || (cur_sps == FORCE_RECONF))
{
cal_fmck = fclk / sps_tab[i];
}
else
{
i = cur_sps;
cal_fmck = fclk / sps_tab[cur_sps];
}
/* cal_ftclk = cal_fmck /2 /(SDR[15:9]+1), data scaled up 100 times for calculations.*/
idea_sdr = ((cal_fmck >> 1) *100) / ftclk;
if((idea_sdr > (min_sdr*100 +50)) && (idea_sdr < (CALCULATE_MAX_SDR*100 +50)))
{
sdr_int = (idea_sdr + 50)/100;
temp_err = abs((sdr_int * 100) - idea_sdr) * 10000 / idea_sdr;
if(temp_err < max_err)
{
clock->sps = i;
clock->sdr = sdr_int - 1;
max_err = temp_err;
}
if(max_err == 0)
{
return (float)0.0;
}
}
}
ret_err = max_err /(float)100.0;
return ret_err;
}
#endif
#if 0
/** /**
* @brief Calculate the register setting options for baud rate to UART peripheral. * @brief Calculate the register setting options for baud rate to UART peripheral.
* @param fclk_freq: System clock value on chip. * @param fclk_freq: System clock value on chip.
...@@ -167,6 +256,7 @@ float SCIPeriphal_ClockUpdate(SCIAFSelect_TypeDef func, uint32_t fclk, uint32_t ...@@ -167,6 +256,7 @@ float SCIPeriphal_ClockUpdate(SCIAFSelect_TypeDef func, uint32_t fclk, uint32_t
return max_err; return max_err;
} }
#endif
/** /**
* @brief This function is aimed to check sci unit and its channel is used or not * @brief This function is aimed to check sci unit and its channel is used or not
* @param func: The AF function for SCI channel periphal. * @param func: The AF function for SCI channel periphal.
......
  • 62938 【天鹰TY200】【TCS外发】重新上大电,TCS外发前22帧发无效值,从第23帧开始发正确值

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment