diff options
author | Karl Palsson <karlp@tweak.net.au> | 2016-04-10 13:22:17 +0000 |
---|---|---|
committer | Karl Palsson <karlp@tweak.net.au> | 2016-09-09 22:16:45 +0000 |
commit | 02064576e8dc31509dc91a0681ba80f2c9615d2f (patch) | |
tree | 9cfc720d4e2138443cba2bf9ae7930c29dcf9672 /tests/qemu/main.c | |
parent | c5c33a46003ba66008774e1ddf9557906df76462 (diff) | |
download | olsndot-02064576e8dc31509dc91a0681ba80f2c9615d2f.tar.gz olsndot-02064576e8dc31509dc91a0681ba80f2c9615d2f.tar.bz2 olsndot-02064576e8dc31509dc91a0681ba80f2c9615d2f.zip |
qemu test sample from daniellinux:
soruced originally from: https://github.com/libopencm3/libopencm3/pull/613
edited to drop the use of bin files, and switch to devices.data
Diffstat (limited to 'tests/qemu/main.c')
-rw-r--r-- | tests/qemu/main.c | 58 |
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;
+ }
+ }
+}
|