summaryrefslogtreecommitdiff
path: root/tests/qemu/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qemu/main.c')
-rw-r--r--tests/qemu/main.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/qemu/main.c b/tests/qemu/main.c
new file mode 100644
index 0000000..863ce9e
--- /dev/null
+++ b/tests/qemu/main.c
@@ -0,0 +1,58 @@
+#include <libopencm3/cm3/nvic.h>
+#include <libopencm3/cm3/systick.h>
+
+
+/* LM3S Specifics, usart and RCC */
+#include <libopencm3/lm3s/rcc.h>
+#include <libopencm3/lm3s/usart.h>
+
+static volatile uint32_t jiffies = 0u;
+
+static void printbanner(void)
+{
+ char msg[] = "One second elapsed!\r\n";
+ char *c = msg;
+ while (*c != 0) {
+ usart_send(USART0_BASE, (uint16_t )*c);
+ c++;
+ }
+}
+
+void sys_tick_handler(void)
+{
+ jiffies++;
+}
+
+static inline uint32_t systick_app_config(uint32_t n_ticks)
+{
+ /* constant from systick_set_reload -- as this returns something that's
+ * * not void, this is the only possible error condition */
+ if (n_ticks & ~0x00FFFFFF) {
+ return 1;
+ }
+
+ systick_set_reload(n_ticks);
+ systick_set_clocksource(1);
+ systick_interrupt_enable();
+ systick_counter_enable();
+
+ return 0;
+}
+
+#define HZ 1000
+
+int main(void)
+{
+ uint32_t last_time = 0;
+ rcc_clock_setup_in_xtal_8mhz_out_50mhz();
+ systick_app_config(HZ);
+
+ nvic_set_priority(NVIC_SYSTICK_IRQ, 0);
+ jiffies = 0;
+ while(1) {
+ if (jiffies > HZ) {
+ printbanner();
+ jiffies = 0;
+ }
+ }
+}