优化延时函数为中断延时,关闭总中断则为普通延时
        优化ips114屏幕的初始化时间,移除不必要的延时
        修复串口错误中断的串口号异常的问题
This commit is contained in:
SEEKFREE_BUDING
2023-11-29 10:13:09 +08:00
parent 68a58caf81
commit 0b61a0a0c6
112 changed files with 2221 additions and 1757 deletions

View File

@@ -31,31 +31,68 @@
* <20>޸ļ<DEB8>¼
* <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ע
* 2022-09-15 pudding first version
* 2023-11-28 pudding <20>޸<EFBFBD><DEB8><EFBFBD>ͨ<EFBFBD><CDA8>ʱ<EFBFBD>߼<EFBFBD>Ϊ<EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϹر<CFB9><D8B1><EFBFBD>ʹ<EFBFBD>üĴ<C3BC><C4B4><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ʱ
********************************************************************************************************************/
#include "IfxStm.h"
#include "IFXSTM_CFG.h"
#include "SysSe/Bsp/Bsp.h"
#include "zf_common_interrupt.h"
#include "zf_driver_delay.h"
#define IFX_INTPRIO_STM0_SR0 220
#define IFX_INTPRIO_STM1_SR0 221
static vuint8 stm0_isr_flag = 1;
static vuint8 stm1_isr_flag = 1;
IFX_INTERRUPT(stm0_isr, 0, IFX_INTPRIO_STM0_SR0)
{
interrupt_global_enable(0); // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>Ƕ<EFBFBD><C7B6>
IfxStm_clearCompareFlag(&MODULE_STM0, IfxStm_Comparator_0);
stm0_isr_flag = 0;
}
IFX_INTERRUPT(stm1_isr, 0, IFX_INTPRIO_STM1_SR0)
{
interrupt_global_enable(0); // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>Ƕ<EFBFBD><C7B6>
IfxStm_clearCompareFlag(&MODULE_STM1, IfxStm_Comparator_1);
stm1_isr_flag = 0;
}
//-------------------------------------------------------------------------------------------------------------------
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> system<65><6D>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> time <20><>ʱһ<CAB1>ֵ<EFBFBD>ʱ<EFBFBD><EFBFBD><E4A3A8>λΪ<CEBB><CEAA><EFBFBD><EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD>Χ0-20000000<30><30>
// <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> num <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD> void
// ʹ<><CAB9>ʾ<EFBFBD><CABE> <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ã<EFBFBD><C3A3>û<EFBFBD><C3BB><EFBFBD>ʹ<EFBFBD><CAB9>h<EFBFBD>ļ<EFBFBD><C4BC>еĺ궨<C4BA><EAB6A8>
// ʹ<><CAB9>ʾ<EFBFBD><CABE> <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ã<EFBFBD><C3A3>û<EFBFBD><C3BB><EFBFBD>ʹ<EFBFBD><CAB9>h<EFBFBD>ļ<EFBFBD><C4BC>еĺ궨<C4BA><EAB6A8> // 100Mʱ<4D><CAB1> <20><>С<EFBFBD><D0A1>λΪ 10ns
//-------------------------------------------------------------------------------------------------------------------
void system_delay (uint32 time, uint32 num)
void system_delay_10ns (uint32 time)
{
uint32 stm_clk;
uint32 delay_time;
stm_clk = IfxStm_getFrequency(IfxStm_getAddress((IfxStm_Index)(IfxCpu_getCoreId())));
delay_time = (uint32)(stm_clk/1000000*time/1000);
IfxStm_Index stm_index;
while(num--)
stm_index = (IfxStm_Index)IfxCpu_getCoreId();
if(areInterruptsEnabled() == 0)
{
IfxStm_waitTicks(IfxStm_getAddress((IfxStm_Index)(IfxCpu_getCoreId())), delay_time);
IfxStm_waitTicks(IfxStm_getAddress(stm_index), time);
}
else
{
if(stm_index == IfxStm_Index_0)
{
Ifx_STM *stm_sfr = &MODULE_STM0;
stm_sfr->CMP[0].U = stm_sfr->TIM0.U + time;
stm0_isr_flag = 1;
while(stm0_isr_flag);
}
else if(stm_index == IfxStm_Index_1)
{
Ifx_STM *stm_sfr = &MODULE_STM1;
stm_sfr->CMP[1].U = stm_sfr->TIM0.U + time;
stm1_isr_flag = 1;
while(stm1_isr_flag);
}
}
}
@@ -68,7 +105,19 @@ void system_delay (uint32 time, uint32 num)
//-------------------------------------------------------------------------------------------------------------------
void system_delay_us (uint32 time)
{
system_delay(time*1000, 1);
if(time > 40000000)
{
while(time > 40000000)
{
system_delay_10ns(4000000000);
time = time - 40000000;
}
system_delay_10ns(time * 100);
}
else
{
system_delay_10ns(time * 100);
}
}
//-------------------------------------------------------------------------------------------------------------------
@@ -79,6 +128,53 @@ void system_delay_us (uint32 time)
//-------------------------------------------------------------------------------------------------------------------
void system_delay_ms (uint32 time)
{
system_delay(1000000, time);
if(time > 40000)
{
while(time > 40000)
{
system_delay_10ns(4000000000);
time = time - 40000;
}
system_delay_10ns(time * 100000);
}
else
{
system_delay_10ns(time * 100000);
}
}
//-------------------------------------------------------------------------------------------------------------------
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> system <20>ӳٳ<D3B3>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD> void
// ʹ<><CAB9>ʾ<EFBFBD><CABE> system_delay_init();
//-------------------------------------------------------------------------------------------------------------------
void system_delay_init(void)
{
IfxStm_CompareConfig stmConfig;
boolean interrupt_state = disableInterrupts();
stmConfig.comparator = IfxStm_Comparator_0;
stmConfig.compareOffset = IfxStm_ComparatorOffset_0;
stmConfig.compareSize = IfxStm_ComparatorSize_32Bits;
stmConfig.comparatorInterrupt = IfxStm_ComparatorInterrupt_ir0;
stmConfig.ticks = 1;
stmConfig.triggerPriority = IFX_INTPRIO_STM0_SR0;
stmConfig.typeOfService = IfxSrc_Tos_cpu0;
IfxStm_initCompare(&MODULE_STM0, &stmConfig);
IfxStm_clearCompareFlag(&MODULE_STM0, IfxStm_Comparator_0);
stmConfig.comparator = IfxStm_Comparator_1;
stmConfig.compareOffset = IfxStm_ComparatorOffset_0;
stmConfig.compareSize = IfxStm_ComparatorSize_32Bits;
stmConfig.comparatorInterrupt = IfxStm_ComparatorInterrupt_ir1;
stmConfig.ticks = 1;
stmConfig.triggerPriority = IFX_INTPRIO_STM1_SR0;
stmConfig.typeOfService = IfxSrc_Tos_cpu1;
IfxStm_initCompare(&MODULE_STM1, &stmConfig);
IfxStm_clearCompareFlag(&MODULE_STM1, IfxStm_Comparator_0);
restoreInterrupts(interrupt_state);
}

View File

@@ -42,6 +42,7 @@
void system_delay (uint32 time, uint32 num);
void system_delay_us (uint32 time);
void system_delay_ms (uint32 time);
void system_delay_init (void);
//====================================================<3D><>ʱ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>====================================================