#include "project.h" volatile uint32_t ticks; static uint32_t scale = 7; unsigned led2 = 1000; void delay_us (uint32_t d) { d *= scale; while (d--) __asm__ ("nop"); } void sys_tick_handler (void) { ticks++; cdcacm_tick(); hands_tick(); motor_tick(); if (led2) led2--; if (led2) CLEAR (LED2); else SET (LED2); } void ticker_init (void) { uint32_t v, w; /*Start periodic timer */ systick_set_clocksource (STK_CSR_CLKSOURCE_AHB_DIV8); /* 72MHz / 8 = > 9Mhz */ systick_set_reload (9000); /* 9MHz / 9000 => 1kHz */ systick_interrupt_enable(); systick_counter_enable(); /*Calibrate the delay loop */ do { scale--; v = ticks; while (v == ticks) ; delay_us (1000); w = ticks; v++; w -= v; } while (w); } void delay_ms (uint32_t d) { uint32_t v = ticks; while ((ticks - v) < d); }