aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGareth McMullin2015-02-28 22:05:10 -0800
committerGareth McMullin2015-02-28 22:05:10 -0800
commit75001a442126e3b42f6f95f1917a7cb33b92d063 (patch)
tree7f18e7d0623ef54afa3a94712d04abfe25e242db
parent5d136398e121168c41e1c3488454e02f11afd67b (diff)
Factor Morse code functions out of platform code.
-rw-r--r--src/Makefile1
-rw-r--r--src/adiv5_jtagdp.c1
-rw-r--r--src/adiv5_swdp.c1
-rw-r--r--src/command.c1
-rw-r--r--src/include/morse.h32
-rw-r--r--src/jtag_scan.c1
-rw-r--r--src/morse.c100
-rw-r--r--src/platforms/f4discovery/platform.c85
-rw-r--r--src/platforms/f4discovery/platform.h4
-rw-r--r--src/platforms/launchpad-icdi/platform.c8
-rw-r--r--src/platforms/launchpad-icdi/platform.h2
-rw-r--r--src/platforms/libftdi/platform.c8
-rw-r--r--src/platforms/libftdi/platform.h3
-rw-r--r--src/platforms/native/platform.c86
-rw-r--r--src/platforms/native/platform.h3
-rw-r--r--src/platforms/stlink/platform.c8
-rw-r--r--src/platforms/stlink/platform.h3
-rw-r--r--src/platforms/swlink/platform.c8
-rw-r--r--src/platforms/swlink/platform.h2
19 files changed, 146 insertions, 211 deletions
diff --git a/src/Makefile b/src/Makefile
index fcf5d1f..25cf715 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -29,6 +29,7 @@ SRC = \
lpc43xx.c \
kinetis.c \
main.c \
+ morse.c \
nrf51.c \
platform.c \
sam3x.c \
diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c
index 4306101..fd77a04 100644
--- a/src/adiv5_jtagdp.c
+++ b/src/adiv5_jtagdp.c
@@ -27,6 +27,7 @@
#include "adiv5.h"
#include "jtag_scan.h"
#include "jtagtap.h"
+#include "morse.h"
#include <stdlib.h>
diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c
index 7896d8b..6bafc91 100644
--- a/src/adiv5_swdp.c
+++ b/src/adiv5_swdp.c
@@ -30,6 +30,7 @@
#include "jtagtap.h"
#include "command.h"
+#include "morse.h"
#include <stdlib.h>
diff --git a/src/command.c b/src/command.c
index c13fa9f..7c17864 100644
--- a/src/command.c
+++ b/src/command.c
@@ -32,6 +32,7 @@
#include "jtag_scan.h"
#include "target.h"
+#include "morse.h"
#include "adiv5.h"
diff --git a/src/include/morse.h b/src/include/morse.h
new file mode 100644
index 0000000..ac53893
--- /dev/null
+++ b/src/include/morse.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2015 Black Sphere Technologies Ltd.
+ * Written by 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 __MORSE_H
+#define __MORSE_H
+
+#include <stdbool.h>
+
+extern const char *morse_msg;
+
+void morse(const char *msg, char repeat);
+bool morse_update(void);
+
+#endif
+
diff --git a/src/jtag_scan.c b/src/jtag_scan.c
index 6ca4603..257e6c4 100644
--- a/src/jtag_scan.c
+++ b/src/jtag_scan.c
@@ -30,6 +30,7 @@
#include "general.h"
#include "jtagtap.h"
+#include "morse.h"
#include "jtag_scan.h"
#include "gdb_packet.h"
diff --git a/src/morse.c b/src/morse.c
new file mode 100644
index 0000000..6b17c16
--- /dev/null
+++ b/src/morse.c
@@ -0,0 +1,100 @@
+/*
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2015 Black Sphere Technologies Ltd.
+ * Written by 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 "morse.h"
+
+/* Morse code patterns and lengths */
+static const struct {
+ uint16_t code;
+ uint8_t bits;
+} morse_letter[] = {
+ { 0b00011101, 8}, // 'A' .-
+ { 0b000101010111, 12}, // 'B' -...
+ { 0b00010111010111, 14}, // 'C' -.-.
+ { 0b0001010111, 10}, // 'D' -..
+ { 0b0001, 4}, // 'E' .
+ { 0b000101110101, 12}, // 'F' ..-.
+ { 0b000101110111, 12}, // 'G' --.
+ { 0b0001010101, 10}, // 'H' ....
+ { 0b000101, 6}, // 'I' ..
+ {0b0001110111011101, 16}, // 'J' .---
+ { 0b000111010111, 12}, // 'K' -.-
+ { 0b000101011101, 12}, // 'L' .-..
+ { 0b0001110111, 10}, // 'M' --
+ { 0b00010111, 8}, // 'N' -.
+ { 0b00011101110111, 14}, // 'O' ---
+ { 0b00010111011101, 14}, // 'P' .--.
+ {0b0001110101110111, 16}, // 'Q' --.-
+ { 0b0001011101, 10}, // 'R' .-.
+ { 0b00010101, 8}, // 'S' ...
+ { 0b000111, 6}, // 'T' -
+ { 0b0001110101, 10}, // 'U' ..-
+ { 0b000111010101, 12}, // 'V' ...-
+ { 0b000111011101, 12}, // 'W' .--
+ { 0b00011101010111, 14}, // 'X' -..-
+ {0b0001110111010111, 16}, // 'Y' -.--
+ { 0b00010101110111, 14}, // 'Z' --..
+};
+
+const char *morse_msg;
+static const char * volatile morse_ptr;
+static char morse_repeat;
+
+void morse(const char *msg, char repeat)
+{
+ morse_msg = morse_ptr = msg;
+ morse_repeat = repeat;
+}
+
+bool morse_update(void)
+{
+ static uint16_t code;
+ static uint8_t bits;
+
+ if (!morse_ptr)
+ return false;
+
+ if (!bits) {
+ char c = *morse_ptr++;
+ if (!c) {
+ if(morse_repeat) {
+ morse_ptr = morse_msg;
+ c = *morse_ptr++;
+ } else {
+ morse_ptr = 0;
+ return false;
+ }
+ }
+ if ((c >= 'A') && (c <= 'Z')) {
+ c -= 'A';
+ code = morse_letter[c].code;
+ bits = morse_letter[c].bits;
+ } else {
+ code = 0; bits = 4;
+ }
+ }
+
+ bool ret = code & 1;
+ code >>= 1;
+ bits--;
+
+ return ret;
+}
+
diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c
index efe8050..e051564 100644
--- a/src/platforms/f4discovery/platform.c
+++ b/src/platforms/f4discovery/platform.c
@@ -33,17 +33,14 @@
#include <libopencm3/usb/usbd.h>
#include "jtag_scan.h"
-#include <usbuart.h>
-
-#include <ctype.h>
+#include "usbuart.h"
+#include "morse.h"
uint8_t running_status;
volatile uint32_t timeout_counter;
jmp_buf fatal_error_jmpbuf;
-static void morse_update(void);
-
int platform_init(void)
{
/* Check the USER button*/
@@ -116,83 +113,7 @@ void sys_tick_handler(void)
if(timeout_counter)
timeout_counter--;
- morse_update();
-}
-
-
-/* Morse code patterns and lengths */
-static const struct {
- uint16_t code;
- uint8_t bits;
-} morse_letter[] = {
- { 0b00011101, 8}, // 'A' .-
- { 0b000101010111, 12}, // 'B' -...
- { 0b00010111010111, 14}, // 'C' -.-.
- { 0b0001010111, 10}, // 'D' -..
- { 0b0001, 4}, // 'E' .
- { 0b000101110101, 12}, // 'F' ..-.
- { 0b000101110111, 12}, // 'G' --.
- { 0b0001010101, 10}, // 'H' ....
- { 0b000101, 6}, // 'I' ..
- {0b0001110111011101, 16}, // 'J' .---
- { 0b000111010111, 12}, // 'K' -.-
- { 0b000101011101, 12}, // 'L' .-..
- { 0b0001110111, 10}, // 'M' --
- { 0b00010111, 8}, // 'N' -.
- { 0b00011101110111, 14}, // 'O' ---
- { 0b00010111011101, 14}, // 'P' .--.
- {0b0001110101110111, 16}, // 'Q' --.-
- { 0b0001011101, 10}, // 'R' .-.
- { 0b00010101, 8}, // 'S' ...
- { 0b000111, 6}, // 'T' -
- { 0b0001110101, 10}, // 'U' ..-
- { 0b000111010101, 12}, // 'V' ...-
- { 0b000111011101, 12}, // 'W' .--
- { 0b00011101010111, 14}, // 'X' -..-
- {0b0001110111010111, 16}, // 'Y' -.--
- { 0b00010101110111, 14}, // 'Z' --..
-};
-
-
-const char *morse_msg;
-static const char * volatile morse_ptr;
-static char morse_repeat;
-
-void morse(const char *msg, char repeat)
-{
- morse_msg = morse_ptr = msg;
- morse_repeat = repeat;
- SET_ERROR_STATE(0);
-}
-
-static void morse_update(void)
-{
- static uint16_t code;
- static uint8_t bits;
-
- if(!morse_ptr) return;
-
- if(!bits) {
- char c = *morse_ptr++;
- if(!c) {
- if(morse_repeat) {
- morse_ptr = morse_msg;
- c = *morse_ptr++;
- } else {
- morse_ptr = 0;
- return;
- }
- }
- if((c >= 'A') && (c <= 'Z')) {
- c -= 'A';
- code = morse_letter[c].code;
- bits = morse_letter[c].bits;
- } else {
- code = 0; bits = 4;
- }
- }
- SET_ERROR_STATE(code & 1);
- code >>= 1; bits--;
+ SET_ERROR_STATE(morse_update());
}
const char *platform_target_voltage(void)
diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h
index 7d6e92e..90b2a11 100644
--- a/src/platforms/f4discovery/platform.h
+++ b/src/platforms/f4discovery/platform.h
@@ -34,6 +34,7 @@
#include <alloca.h>
#include "gdb_packet.h"
+#include "morse.h"
#define INLINE_GPIO
#define CDCACM_PACKET_SIZE 64
@@ -156,8 +157,6 @@ extern volatile uint32_t timeout_counter;
extern jmp_buf fatal_error_jmpbuf;
-extern const char *morse_msg;
-
#define gpio_set_val(port, pin, val) do { \
if(val) \
gpio_set((port), (pin)); \
@@ -180,7 +179,6 @@ extern const char *morse_msg;
}
int platform_init(void);
-void morse(const char *msg, char repeat);
const char *platform_target_voltage(void);
void platform_delay(uint32_t delay);
static inline int platform_hwversion(void)
diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c
index 848271e..1e66e12 100644
--- a/src/platforms/launchpad-icdi/platform.c
+++ b/src/platforms/launchpad-icdi/platform.c
@@ -19,14 +19,6 @@ jmp_buf fatal_error_jmpbuf;
uint8_t running_status;
volatile uint32_t timeout_counter;
-const char *morse_msg;
-
-void morse(const char *msg, char repeat)
-{
- (void) msg;
- (void) repeat;
-}
-
void sys_tick_handler(void)
{
if(timeout_counter)
diff --git a/src/platforms/launchpad-icdi/platform.h b/src/platforms/launchpad-icdi/platform.h
index 7f5d55f..8c343a8 100644
--- a/src/platforms/launchpad-icdi/platform.h
+++ b/src/platforms/launchpad-icdi/platform.h
@@ -23,7 +23,6 @@ extern usbd_device *usbdev;
extern jmp_buf fatal_error_jmpbuf;
extern uint8_t running_status;
-extern const char *morse_msg;
extern volatile uint32_t timeout_counter;
#define TMS_PORT GPIOA_BASE
@@ -112,7 +111,6 @@ extern usbd_driver lm4f_usb_driver;
#define PLATFORM_HAS_TRACESWO
int platform_init(void);
-void morse(const char *msg, char repeat);
inline static void gpio_set_val(uint32_t port, uint8_t pin, uint8_t val) {
gpio_write(port, pin, val == 0 ? 0 : 0xff);
diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c
index dc57a45..723efa3 100644
--- a/src/platforms/libftdi/platform.c
+++ b/src/platforms/libftdi/platform.c
@@ -267,11 +267,3 @@ void platform_delay(uint32_t delay)
usleep(delay * 100000);
}
-void morse(const char *msg, char repeat)
-{
- (void)repeat;
-
- if (msg != NULL)
- fprintf(stderr,"%s\n", msg);
-}
-
diff --git a/src/platforms/libftdi/platform.h b/src/platforms/libftdi/platform.h
index 5ce45fd..a95a3f4 100644
--- a/src/platforms/libftdi/platform.h
+++ b/src/platforms/libftdi/platform.h
@@ -40,12 +40,9 @@
#define PLATFORM_FATAL_ERROR(error) abort()
#define PLATFORM_SET_FATAL_ERROR_RECOVERY()
-#define morse_msg 0
-
extern struct ftdi_context *ftdic;
int platform_init(int argc, char **argv);
-void morse(const char *msg, char repeat);
const char *platform_target_voltage(void);
void platform_delay(uint32_t delay);
diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c
index 5e5c78c..3e269d9 100644
--- a/src/platforms/native/platform.c
+++ b/src/platforms/native/platform.c
@@ -34,17 +34,14 @@
#include <libopencm3/stm32/f1/adc.h>
#include "jtag_scan.h"
-#include <usbuart.h>
-
-#include <ctype.h>
+#include "usbuart.h"
+#include "morse.h"
uint8_t running_status;
volatile uint32_t timeout_counter;
jmp_buf fatal_error_jmpbuf;
-static void morse_update(void);
-
static void adc_init(void);
/* Pins PB[7:5] are used to detect hardware revision.
@@ -187,83 +184,7 @@ void sys_tick_handler(void)
if(timeout_counter)
timeout_counter--;
- morse_update();
-}
-
-
-/* Morse code patterns and lengths */
-static const struct {
- uint16_t code;
- uint8_t bits;
-} morse_letter[] = {
- { 0b00011101, 8}, // 'A' .-
- { 0b000101010111, 12}, // 'B' -...
- { 0b00010111010111, 14}, // 'C' -.-.
- { 0b0001010111, 10}, // 'D' -..
- { 0b0001, 4}, // 'E' .
- { 0b000101110101, 12}, // 'F' ..-.
- { 0b000101110111, 12}, // 'G' --.
- { 0b0001010101, 10}, // 'H' ....
- { 0b000101, 6}, // 'I' ..
- {0b0001110111011101, 16}, // 'J' .---
- { 0b000111010111, 12}, // 'K' -.-
- { 0b000101011101, 12}, // 'L' .-..
- { 0b0001110111, 10}, // 'M' --
- { 0b00010111, 8}, // 'N' -.
- { 0b00011101110111, 14}, // 'O' ---
- { 0b00010111011101, 14}, // 'P' .--.
- {0b0001110101110111, 16}, // 'Q' --.-
- { 0b0001011101, 10}, // 'R' .-.
- { 0b00010101, 8}, // 'S' ...
- { 0b000111, 6}, // 'T' -
- { 0b0001110101, 10}, // 'U' ..-
- { 0b000111010101, 12}, // 'V' ...-
- { 0b000111011101, 12}, // 'W' .--
- { 0b00011101010111, 14}, // 'X' -..-
- {0b0001110111010111, 16}, // 'Y' -.--
- { 0b00010101110111, 14}, // 'Z' --..
-};
-
-
-const char *morse_msg;
-static const char * volatile morse_ptr;
-static char morse_repeat;
-
-void morse(const char *msg, char repeat)
-{
- morse_msg = morse_ptr = msg;
- morse_repeat = repeat;
- SET_ERROR_STATE(0);
-}
-
-static void morse_update(void)
-{
- static uint16_t code;
- static uint8_t bits;
-
- if(!morse_ptr) return;
-
- if(!bits) {
- char c = *morse_ptr++;
- if(!c) {
- if(morse_repeat) {
- morse_ptr = morse_msg;
- c = *morse_ptr++;
- } else {
- morse_ptr = 0;
- return;
- }
- }
- if((c >= 'A') && (c <= 'Z')) {
- c -= 'A';
- code = morse_letter[c].code;
- bits = morse_letter[c].bits;
- } else {
- code = 0; bits = 4;
- }
- }
- SET_ERROR_STATE(code & 1);
- code >>= 1; bits--;
+ SET_ERROR_STATE(morse_update());
}
static void adc_init(void)
@@ -351,3 +272,4 @@ void setup_vbus_irq(void)
exti15_10_isr();
}
+
diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h
index 81a2a4b..73b6c59 100644
--- a/src/platforms/native/platform.h
+++ b/src/platforms/native/platform.h
@@ -35,6 +35,7 @@
#include <alloca.h>
#include "gdb_packet.h"
+#include "morse.h"
#define INLINE_GPIO
#define CDCACM_PACKET_SIZE 64
@@ -163,7 +164,6 @@ extern volatile uint32_t timeout_counter;
extern jmp_buf fatal_error_jmpbuf;
-extern const char *morse_msg;
#define gpio_set_val(port, pin, val) do { \
if(val) \
@@ -187,7 +187,6 @@ extern const char *morse_msg;
} while (0)
int platform_init(void);
-void morse(const char *msg, char repeat);
const char *platform_target_voltage(void);
int platform_hwversion(void);
void platform_delay(uint32_t delay);
diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c
index 494499c..6ef8c77 100644
--- a/src/platforms/stlink/platform.c
+++ b/src/platforms/stlink/platform.c
@@ -156,14 +156,6 @@ void sys_tick_handler(void)
timeout_counter--;
}
-const char *morse_msg;
-
-void morse(const char *msg, char repeat)
-{
- (void)repeat;
- morse_msg = msg;
-}
-
const char *platform_target_voltage(void)
{
return "unknown";
diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h
index e56abd9..ee08875 100644
--- a/src/platforms/stlink/platform.h
+++ b/src/platforms/stlink/platform.h
@@ -143,8 +143,6 @@ extern volatile uint32_t timeout_counter;
extern jmp_buf fatal_error_jmpbuf;
-extern const char *morse_msg;
-
#define gpio_set_val(port, pin, val) do { \
if(val) \
gpio_set((port), (pin)); \
@@ -166,7 +164,6 @@ extern uint16_t led_idle_run;
} while (0)
int platform_init(void);
-void morse(const char *msg, char repeat);
const char *platform_target_voltage(void);
void platform_delay(uint32_t delay);
void platform_srst_set_val(bool assert);
diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c
index 7b7446a..853cbc9 100644
--- a/src/platforms/swlink/platform.c
+++ b/src/platforms/swlink/platform.c
@@ -124,14 +124,6 @@ void sys_tick_handler(void)
timeout_counter--;
}
-const char *morse_msg;
-
-void morse(const char *msg, char repeat)
-{
- (void)repeat;
- morse_msg = msg;
-}
-
const char *platform_target_voltage(void)
{
return "unknown";
diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h
index 6683421..99c8fa3 100644
--- a/src/platforms/swlink/platform.h
+++ b/src/platforms/swlink/platform.h
@@ -141,7 +141,6 @@ extern volatile uint32_t timeout_counter;
extern jmp_buf fatal_error_jmpbuf;
-extern const char *morse_msg;
#define gpio_set_val(port, pin, val) do { \
if(val) \
@@ -164,7 +163,6 @@ extern const char *morse_msg;
}
int platform_init(void);
-void morse(const char *msg, char repeat);
const char *platform_target_voltage(void);
void platform_delay(uint32_t delay);