C
static uint32_t Init_SysTick(uint32_t ticks) {
SysTick->LOAD = (ticks & SYSTICK_MAXCOUNT) - 1;
SysTick->VAL = 0;
SysTick->CTRL = 0x5; //允许计数但未开启中断使能
return (0);
}
C
static uint32_t Init_SysTick(uint32_t ticks) {
SysTick->LOAD = (ticks & SYSTICK_MAXCOUNT) - 1;
SysTick->VAL = 0;
SysTick->CTRL = 0x5;
return (0);
}
void wait_Timeout1(unsigned int timeout1) {
unsigned int temp = 0;
for(int cnt = 0; cnt < timeout1; cnt++) {
while(1) {
temp = SysTick->CTRL;
if(temp & (unsigned int)(1<<16)) {
break;
}
}
}
}
C
void wait_Timeout2(unsigned int timeout2) {
if(!(SysTick->CTRL & 0x02)) {
SysTick->CTRL |= 0x02;
}
system_int_cnt = 0;
while(system_int_cnt < timeout2) {};
}
void SysTick_Handler(void) {
system_int_cnt++;
}
C
void wait_Timeout3(unsigned int timeout3) {
if(!(SysTick->CTRL & 0x02)) {
SysTick->CTRL |= 0x02; //中断使能开启中断
}
system_int_cnt = timeout3;
while(system_int_cnt != 0) {};
}
void SysTick_Handler(void) {
system_int_cnt--;
}