summaryrefslogtreecommitdiffstats
path: root/s3estarter/software/devel/timer.c
diff options
context:
space:
mode:
authorBert Lange <b.lange@fzd.de>2010-10-11 15:15:42 +0200
committerBert Lange <b.lange@fzd.de>2010-10-11 15:15:42 +0200
commit396f4a50c83dfb417e99d9c1a3e7f49d7f3f691c (patch)
tree549dc0395978ebe4eb82519577c91021eb3e54cf /s3estarter/software/devel/timer.c
parented06599311e10cb825c7e36d73037f01cac43663 (diff)
parent09f1be97f93fd588b1b5de76b06bbb9e163e61c5 (diff)
downloadzpu-396f4a50c83dfb417e99d9c1a3e7f49d7f3f691c.zip
zpu-396f4a50c83dfb417e99d9c1a3e7f49d7f3f691c.tar.gz
Merge
Diffstat (limited to 's3estarter/software/devel/timer.c')
-rw-r--r--s3estarter/software/devel/timer.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/s3estarter/software/devel/timer.c b/s3estarter/software/devel/timer.c
new file mode 100644
index 0000000..e28cafc
--- /dev/null
+++ b/s3estarter/software/devel/timer.c
@@ -0,0 +1,64 @@
+#include "peripherie.h"
+
+////////////////////////////////////////
+// timer functions
+
+void msleep(uint32_t msec)
+{
+ uint32_t tcr;
+
+ // 1 msec = 6250
+ // 167 msec = 2**20 (20 bit counter) 391 slices
+ // 2684 msec = 2**24 (24 bit counter) 450 slices
+ // = 2**32 (32 bit counter) 572 slices
+ timer0->e[0].reload = (F_CPU/TIMER_PRESCALER/1000)*msec;
+ timer0->e[0].ctrl = TIMER_ENABLE | TIMER_LOAD;
+
+ do
+ {
+ tcr = timer0->e[0].ctrl;
+ } while ( (tcr & TIMER_ENABLE));
+}
+
+void sleep(uint32_t sec)
+{
+ uint32_t timer;
+
+ for (timer=0; timer<sec; timer++)
+ {
+ msleep( 166);
+ msleep( 166);
+ msleep( 166);
+ msleep( 166);
+ msleep( 166);
+ msleep( 166);
+ }
+}
+
+void usleep(uint32_t nsec)
+{
+ uint32_t tcr;
+
+ // 1 nsec = 6
+ timer0->e[0].reload = (F_CPU/TIMER_PRESCALER/1000000)*nsec;
+ timer0->e[0].ctrl = TIMER_ENABLE | TIMER_LOAD;
+
+ do
+ {
+ tcr = timer0->e[0].ctrl;
+ } while ( (tcr & TIMER_ENABLE));
+}
+
+void wait( uint32_t value)
+{
+ uint32_t i;
+
+ for (i=0; i<value; i++) {}
+}
+
+void timer_init( void)
+{
+ timer0->scaler_reload = TIMER_PRESCALER-1; // set prescaler
+}
+
+
OpenPOWER on IntegriCloud