#ifndef _BSP_SYSTICK_H
#define _BSP_SYSTICK_H
#include "stm32f10x.h"
#include "core_cm3.h"
void SysTick_Dalay_us(uint32_t us);
void SysTick_Dalay_ms(uint32_t ms);
#endif /* _BSP_SYSTICK_H */
#include "bsp_systick.h"
static __INLINE uint32_t _SysTick_Config(uint32_t ticks)
{
if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
SysTick->VAL = 0; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0); /* Function successful */
}
void SysTick_Dalay_us(uint32_t us)
{
int i;
_SysTick_Config(72);
for(i=0;i<us;i++){
while(!(SysTick->CTRL & (1<<16)));
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
void SysTick_Dalay_ms(uint32_t ms)
{
int i;
_SysTick_Config(72000);
for(i=0;i<ms;i++){
while(!(SysTick->CTRL & (1<<16)));
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
|