summaryrefslogtreecommitdiff
path: root/time.h
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-09-04 02:12:45 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-09-04 02:12:45 +0200
commitbb2955ea4bb5c0f9431653351a47b373a2391389 (patch)
tree29e325c8ab76b089cbbd57505f7adc9b3117a440 /time.h
parente9f8369ce8b464f178c778ff8bcc3f54fe70b30c (diff)
Added systick based sleep().
Diffstat (limited to 'time.h')
-rw-r--r--time.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/time.h b/time.h
new file mode 100644
index 0000000..66d8e63
--- /dev/null
+++ b/time.h
@@ -0,0 +1,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