diff --git a/src/Makefile b/src/Makefile index 1b31a9ca2..a839f1d13 100755 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ 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 FLAGS = -mcpu=cortex-m4 -mthumb -mcpu=cortex-m4 -mthumb -mthumb-interwork -mlittle-endian -mfloat-abi=hard -mfpu=fpv4-sp-d16 AFLAGS = $(FLAGS) diff --git a/src/systick.c b/src/systick.c new file mode 100644 index 000000000..63090b44b --- /dev/null +++ b/src/systick.c @@ -0,0 +1,29 @@ +#include +#include +#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; +} diff --git a/src/systick.h b/src/systick.h new file mode 100644 index 000000000..f1ba8cb81 --- /dev/null +++ b/src/systick.h @@ -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__ */