--- /dev/null
+/*
+ * Milkymist SoC (Software)
+ * Copyright (C) 2012 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <hw/timer.h>
+
+#include "timer.h"
+
+unsigned int get_system_frequency(void)
+{
+ return 83333333; /* TODO */
+}
+
+void timer_enable(int en)
+{
+ CSR_TIMER0_EN = en;
+}
+
+unsigned int timer_get(void)
+{
+ return (CSR_TIMER0_COUNT3 << 24)
+ |(CSR_TIMER0_COUNT2 << 16)
+ |(CSR_TIMER0_COUNT1 << 8)
+ |CSR_TIMER0_COUNT0;
+}
+
+void timer_set_counter(unsigned int value)
+{
+ CSR_TIMER0_COUNT3 = (value & 0xff000000) >> 24;
+ CSR_TIMER0_COUNT2 = (value & 0x00ff0000) >> 16;
+ CSR_TIMER0_COUNT1 = (value & 0x0000ff00) >> 8;
+ CSR_TIMER0_COUNT0 = value & 0x000000ff;
+}
+
+void timer_set_reload(unsigned int value)
+{
+ CSR_TIMER0_RELOAD3 = (value & 0xff000000) >> 24;
+ CSR_TIMER0_RELOAD2 = (value & 0x00ff0000) >> 16;
+ CSR_TIMER0_RELOAD1 = (value & 0x0000ff00) >> 8;
+ CSR_TIMER0_RELOAD0 = value & 0x000000ff;
+}
+
+void busy_wait(unsigned int ds)
+{
+ timer_enable(0);
+ timer_set_reload(0);
+ timer_set_counter(get_system_frequency()/10*ds);
+ timer_enable(1);
+ while(timer_get());
+}
--- /dev/null
+/*
+ * Milkymist SoC (Software)
+ * Copyright (C) 2012 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __TIMER_H
+#define __TIMER_H
+
+unsigned int get_system_frequency(void);
+void timer_enable(int en);
+unsigned int timer_get(void);
+void timer_set_counter(unsigned int value);
+void timer_set_reload(unsigned int value);
+void busy_wait(unsigned int ms);
+
+#endif /* __TIMER_H */
--- /dev/null
+/*
+ * Milkymist SoC (Software)
+ * Copyright (C) 2007, 2008, 2009, 2010, 2012 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HW_TIMER_H
+#define __HW_TIMER_H
+
+#include <hw/common.h>
+#include <csrbase.h>
+
+#define TIMER0_CSR(x) MMPTR(TIMER0_BASE+(x))
+
+#define CSR_TIMER0_EN TIMER0_CSR(0x00)
+
+#define CSR_TIMER0_COUNT3 TIMER0_CSR(0x04)
+#define CSR_TIMER0_COUNT2 TIMER0_CSR(0x08)
+#define CSR_TIMER0_COUNT1 TIMER0_CSR(0x0C)
+#define CSR_TIMER0_COUNT0 TIMER0_CSR(0x10)
+
+#define CSR_TIMER0_RELOAD3 TIMER0_CSR(0x14)
+#define CSR_TIMER0_RELOAD2 TIMER0_CSR(0x18)
+#define CSR_TIMER0_RELOAD1 TIMER0_CSR(0x1C)
+#define CSR_TIMER0_RELOAD0 TIMER0_CSR(0x20)
+
+#define CSR_TIMER0_EV_STAT TIMER0_CSR(0x24)
+#define CSR_TIMER0_EV_PENDING TIMER0_CSR(0x28)
+#define CSR_TIMER0_EV_ENABLE TIMER0_CSR(0x2C)
+
+#define TIMER0_EV 0x1
+
+#endif /* __HW_TIMER_H */