mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
update
This commit is contained in:
92
software/bootloader/SYSTEM/delay.c
Normal file
92
software/bootloader/SYSTEM/delay.c
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "delay.h"
|
||||
#include "sys.h"
|
||||
|
||||
/*
|
||||
//roughly delay
|
||||
void delay_us(u32 nus)
|
||||
{
|
||||
u32 i;
|
||||
u16 temp;
|
||||
temp = nus*SYS_CLK/15;
|
||||
for(i=0;i<temp;i++);
|
||||
}
|
||||
|
||||
//延时nms
|
||||
//nms:要延时的ms数
|
||||
void delay_ms(u16 nms)
|
||||
{
|
||||
u32 i;
|
||||
for(i=0;i<nms;i++) delay_us(1000);
|
||||
}
|
||||
*/
|
||||
|
||||
void delay_init(void)
|
||||
{
|
||||
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
||||
/* Configure the SysTick to have interrupt in 1ms time basis*/
|
||||
HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq));
|
||||
}
|
||||
|
||||
#if OS_SUPPORT
|
||||
void delay_us(u32 nus)
|
||||
{
|
||||
u32 ticks;
|
||||
u32 told,tnow,tcnt=0;
|
||||
u32 reload=SysTick->LOAD;
|
||||
ticks=nus*SYS_CLK;
|
||||
delay_osschedlock();
|
||||
told=SysTick->VAL;
|
||||
while(1)
|
||||
{
|
||||
tnow=SysTick->VAL;
|
||||
if(tnow!=told)
|
||||
{
|
||||
if(tnow<told)tcnt+=told-tnow;//这里注意一下SYSTICK是一个递减的计数器就可以了.
|
||||
else tcnt+=reload-tnow+told;
|
||||
told=tnow;
|
||||
if(tcnt>=ticks)break;
|
||||
}
|
||||
};
|
||||
delay_osschedunlock();
|
||||
}
|
||||
|
||||
void delay_ms(u16 nms)
|
||||
{
|
||||
if(delay_osrunning&&delay_osintnesting==0)
|
||||
{
|
||||
if(nms>=fac_ms)
|
||||
{
|
||||
delay_ostimedly(nms/fac_ms);
|
||||
}
|
||||
nms%=fac_ms;
|
||||
}
|
||||
delay_us((u32)(nms*1000));
|
||||
}
|
||||
#else
|
||||
|
||||
void delay_us(u32 nus)
|
||||
{
|
||||
u32 ticks;
|
||||
u32 told,tnow,tcnt=0;
|
||||
u32 reload=SysTick->LOAD;
|
||||
ticks=nus*SYS_CLK;
|
||||
told=SysTick->VAL;
|
||||
while(1)
|
||||
{
|
||||
tnow=SysTick->VAL;
|
||||
if(tnow!=told)
|
||||
{
|
||||
if(tnow<told)tcnt+=told-tnow;
|
||||
else tcnt+=reload-tnow+told;
|
||||
told=tnow;
|
||||
if(tcnt>=ticks)break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void delay_ms(u16 nms)
|
||||
{
|
||||
u32 i;
|
||||
for(i=0;i<nms;i++) delay_us(1000);
|
||||
}
|
||||
#endif
|
||||
9
software/bootloader/SYSTEM/delay.h
Normal file
9
software/bootloader/SYSTEM/delay.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _DELAY_H
|
||||
#define _DELAY_H
|
||||
#include "sys.h"
|
||||
|
||||
void delay_init(void);
|
||||
void delay_ms(u16 nms);
|
||||
void delay_us(u32 nus);
|
||||
#endif
|
||||
|
||||
42
software/bootloader/SYSTEM/sys.h
Normal file
42
software/bootloader/SYSTEM/sys.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef __SYS_H__
|
||||
#define __SYS_H__
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
#define OS_SUPPORT 0
|
||||
#define SYS_CLK 96
|
||||
|
||||
typedef int32_t s32;
|
||||
typedef int16_t s16;
|
||||
typedef int8_t s8;
|
||||
|
||||
typedef const int32_t sc32;
|
||||
typedef const int16_t sc16;
|
||||
typedef const int8_t sc8;
|
||||
|
||||
typedef __IO int32_t vs32;
|
||||
typedef __IO int16_t vs16;
|
||||
typedef __IO int8_t vs8;
|
||||
|
||||
typedef __I int32_t vsc32;
|
||||
typedef __I int16_t vsc16;
|
||||
typedef __I int8_t vsc8;
|
||||
|
||||
typedef uint32_t u32;
|
||||
typedef uint16_t u16;
|
||||
typedef uint8_t u8;
|
||||
|
||||
typedef const uint32_t uc32;
|
||||
typedef const uint16_t uc16;
|
||||
typedef const uint8_t uc8;
|
||||
|
||||
typedef __IO uint32_t vu32;
|
||||
typedef __IO uint16_t vu16;
|
||||
typedef __IO uint8_t vu8;
|
||||
|
||||
typedef __I uint32_t vuc32;
|
||||
typedef __I uint16_t vuc16;
|
||||
typedef __I uint8_t vuc8;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user