systick timer module

This commit is contained in:
iabdalkader 2013-11-19 04:34:41 +02:00
parent 8968c08392
commit c6f7ed40d1
3 changed files with 36 additions and 1 deletions

View File

@ -1,5 +1,5 @@
BIN = "openmv" BIN = "openmv"
OBJ = main.o ov9650.o sccb.o rgb_led.o usart.o imlib.o OBJ = main.o ov9650.o sccb.o rgb_led.o usart.o imlib.o systick.o
LIB = -lc -lcm4 LIB = -lc -lcm4
FLAGS = -mcpu=cortex-m4 -mthumb -mcpu=cortex-m4 -mthumb -mthumb-interwork -mlittle-endian -mfloat-abi=hard -mfpu=fpv4-sp-d16 FLAGS = -mcpu=cortex-m4 -mthumb -mcpu=cortex-m4 -mthumb -mthumb-interwork -mlittle-endian -mfloat-abi=hard -mfpu=fpv4-sp-d16
AFLAGS = $(FLAGS) AFLAGS = $(FLAGS)

29
src/systick.c Normal file
View File

@ -0,0 +1,29 @@
#include <stdint.h>
#include <stm32f4xx.h>
#include "systick.h"
static volatile uint32_t sys_ticks;
void SysTick_Handler(void)
{
++sys_ticks;
}
int systick_init()
{
/* configure systick to interrupt every 1ms */
if (SysTick_Config(SystemCoreClock / 1000)) {
return -1;
}
return 0;
}
void systick_sleep(uint32_t ms)
{
uint32_t curr_ticks = sys_ticks;
while ((sys_ticks - curr_ticks) < ms);
}
uint32_t systick_current_millis()
{
return sys_ticks;
}

6
src/systick.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __SYSTICK_H__
#define __SYSTICK_H__
int systick_init();
void systick_sleep(uint32_t ms);
uint32_t systick_current_millis();
#endif /* __SYSTICK_H__ */