aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/stm32
diff options
context:
space:
mode:
authorGareth McMullin2015-03-02 21:59:04 -0800
committerGareth McMullin2015-03-02 21:59:04 -0800
commit3e466f2d23401df610cb0f94a226317c2dc38751 (patch)
tree7225d3f7929044ced05872d0d11dfd3501605603 /src/platforms/stm32
parentb07ffffcee53e18051b324eb59a2794044ce6f95 (diff)
Factor out timing routines common to all STM32 targets.
Diffstat (limited to 'src/platforms/stm32')
-rw-r--r--src/platforms/stm32/gdb_if.c4
-rw-r--r--src/platforms/stm32/timing.c65
-rw-r--r--src/platforms/stm32/timing.h27
3 files changed, 94 insertions, 2 deletions
diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c
index 286c66b..52922e7 100644
--- a/src/platforms/stm32/gdb_if.c
+++ b/src/platforms/stm32/gdb_if.c
@@ -113,7 +113,7 @@ unsigned char gdb_if_getchar(void)
unsigned char gdb_if_getchar_to(int timeout)
{
- timeout_counter = timeout/100;
+ platform_timeout_set(timeout);
if (!(out_ptr < count_out)) do {
/* Detach if port closed */
@@ -121,7 +121,7 @@ unsigned char gdb_if_getchar_to(int timeout)
return 0x04;
gdb_if_update_buf();
- } while(timeout_counter && !(out_ptr < count_out));
+ } while (!platform_timeout_is_expired() && !(out_ptr < count_out));
if(out_ptr < count_out)
return gdb_if_getchar();
diff --git a/src/platforms/stm32/timing.c b/src/platforms/stm32/timing.c
new file mode 100644
index 0000000..cac22ca
--- /dev/null
+++ b/src/platforms/stm32/timing.c
@@ -0,0 +1,65 @@
+/*
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2015 Gareth McMullin <gareth@blacksphere.co.nz>
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 "general.h"
+
+#include <libopencm3/cm3/systick.h>
+#include <libopencm3/cm3/scb.h>
+
+uint8_t running_status;
+
+static volatile uint32_t timeout_counter;
+
+void platform_timing_init(void)
+{
+ /* Setup heartbeat timer */
+ systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
+ systick_set_reload(900000); /* Interrupt us at 10 Hz */
+ SCB_SHPR(11) &= ~((15 << 4) & 0xff);
+ SCB_SHPR(11) |= ((14 << 4) & 0xff);
+ systick_interrupt_enable();
+ systick_counter_enable();
+}
+
+void platform_timeout_set(uint32_t ms)
+{
+ timeout_counter = ms / 100;
+}
+
+bool platform_timeout_is_expired(void)
+{
+ return timeout_counter == 0;
+}
+
+void platform_delay(uint32_t delay)
+{
+ platform_timeout_set(delay);
+ while (platform_timeout_is_expired());
+}
+
+void sys_tick_handler(void)
+{
+ if(running_status)
+ gpio_toggle(LED_PORT, LED_IDLE_RUN);
+
+ if(timeout_counter)
+ timeout_counter--;
+
+ SET_ERROR_STATE(morse_update());
+}
+
diff --git a/src/platforms/stm32/timing.h b/src/platforms/stm32/timing.h
new file mode 100644
index 0000000..0178ff5
--- /dev/null
+++ b/src/platforms/stm32/timing.h
@@ -0,0 +1,27 @@
+/*
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2015 Gareth McMullin <gareth@blacksphere.co.nz>
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 __TIMING_H
+#define __TIMING_H
+
+extern uint8_t running_status;
+
+void platform_timing_init(void);
+
+#endif
+