diff target-utils/buzplayer/timer.c @ 77:0f11da299b7d

buzplayer: beginning of timer implementation
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 27 Oct 2016 04:01:16 +0000
parents
children e3d40f49d8c4
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/buzplayer/timer.c	Thu Oct 27 04:01:16 2016 +0000
@@ -0,0 +1,19 @@
+/*
+ * FreeCalypso buzzer "melodies" have times measured in TDMA frames,
+ * as that is the time unit in the main firmware which will ultimately
+ * play them.  In this standalone buzzer player we simulate TDMA frame
+ * timing by programming Calypso TIMER1 with the period of 1875, and
+ * we detect timer overflow (one virtual TDMA frame time having passed)
+ * by polling the read register to avoid the need for interrupt handling
+ * infrastructure.
+ */
+
+#include "types.h"
+#include "timer.h"
+
+timer_init()
+{
+	TIMER1_REGS.cntl = CNTL_CLOCK_ENABLE;
+	TIMER1_REGS.load = 1875;
+	TIMER1_REGS.cntl = CNTL_CLOCK_ENABLE | CNTL_AUTO_RELOAD | CNTL_START;
+}