加入大疆C板例程bsp
This commit is contained in:
76
bsp/boards/bsp_delay.c
Normal file
76
bsp/boards/bsp_delay.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "bsp_delay.h"
|
||||
#include "main.h"
|
||||
|
||||
static uint8_t fac_us = 0;
|
||||
static uint32_t fac_ms = 0;
|
||||
|
||||
void delay_init(void)
|
||||
{
|
||||
fac_us = SystemCoreClock / 1000000;
|
||||
fac_ms = SystemCoreClock / 1000;
|
||||
|
||||
}
|
||||
|
||||
void delay_us(uint16_t nus)
|
||||
{
|
||||
uint32_t ticks = 0;
|
||||
uint32_t told = 0;
|
||||
uint32_t tnow = 0;
|
||||
uint32_t tcnt = 0;
|
||||
uint32_t reload = 0;
|
||||
reload = SysTick->LOAD;
|
||||
ticks = nus * fac_us;
|
||||
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(uint16_t nms)
|
||||
{
|
||||
uint32_t ticks = 0;
|
||||
uint32_t told = 0;
|
||||
uint32_t tnow = 0;
|
||||
uint32_t tcnt = 0;
|
||||
uint32_t reload = 0;
|
||||
reload = SysTick->LOAD;
|
||||
ticks = nms * fac_ms;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user