summaryrefslogtreecommitdiff
path: root/time.h
blob: 66d8e63259b0bdbcd92fc7ea2c55f17751d4319c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef TIME_H
#define TIME_H

#include "stm32.h"
#include "interrupt.h"
#include "thread.h"

class Time {
	friend void interrupt<Interrupt::SysTick>();
	
	private:
		static volatile uint32_t systime;
	
	public:
		static void init() {
			STK.LOAD = 72000000 / 8 / 1000; // 1000 Hz.
			STK.CTRL = 0x03;
		}
		
		static void sleep(uint32_t ms) {
			ms += systime;
			while(systime < ms) {
				Thread::yield();
			}
		}
};

#endif