From 50998fcfb916ae251309bd4b464f2c122e8cb30d Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 9 Apr 2021 18:38:02 +0200 Subject: Repo re-org --- reset-controller/fw/src/mspdebug_wrapper.c | 261 +++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 reset-controller/fw/src/mspdebug_wrapper.c (limited to 'reset-controller/fw/src/mspdebug_wrapper.c') diff --git a/reset-controller/fw/src/mspdebug_wrapper.c b/reset-controller/fw/src/mspdebug_wrapper.c new file mode 100644 index 0000000..c30864c --- /dev/null +++ b/reset-controller/fw/src/mspdebug_wrapper.c @@ -0,0 +1,261 @@ + +#include +#include +#include + +#include "output.h" +#include "jtaglib.h" + +#include "sr_global.h" +#include "gpio_helpers.h" +#include "mspdebug_wrapper.h" +#include "con_usart.h" + +#include + +#define BLOCK_SIZE 512 /* bytes */ + + +static void sr_delay_inst(void); + +static struct jtdev sr_jtdev; +static struct jtdev sr_jtdev_default; + +enum sr_gpio_types { + SR_GPIO_TCK, + SR_GPIO_TMS, + SR_GPIO_TDI, + SR_GPIO_RST, + SR_GPIO_TST, + SR_GPIO_TDO, + SR_NUM_GPIOS +}; + +struct { + GPIO_TypeDef *gpio; + int pin; + int mode; +} gpios[SR_NUM_GPIOS] = { + [SR_GPIO_TCK] = {GPIOE, 10, 1}, + [SR_GPIO_TMS] = {GPIOE, 11, 1}, + [SR_GPIO_TDI] = {GPIOE, 12, 1}, + [SR_GPIO_RST] = {GPIOE, 9, 1}, + [SR_GPIO_TST] = {GPIOE, 14, 1}, + [SR_GPIO_TDO] = {GPIOE, 13, 0}, +}; + +void sr_delay_inst() { + for (int i=0; i<10; i++) + asm volatile("nop"); +} + +void mspd_jtag_init() { + for (int i=0; iBSRR = 1<BSRR = 1< 0 && fmt[i-1] == '\n') + usart_putc_nonblocking(&con_usart, '\r'); + return rc; +} + + +static void sr_jtdev_power_on(struct jtdev *p) { + UNUSED(p); + /* ignore */ +} + +static void sr_jtdev_connect(struct jtdev *p) { + UNUSED(p); + /* ignore */ +} + +static void sr_jtdev_tck(struct jtdev *p, int out) { + UNUSED(p); + sr_gpio_write(SR_GPIO_TCK, out); +} + +static void sr_jtdev_tms(struct jtdev *p, int out) { + UNUSED(p); + sr_gpio_write(SR_GPIO_TMS, out); +} + +static void sr_jtdev_tdi(struct jtdev *p, int out) { + UNUSED(p); + sr_gpio_write(SR_GPIO_TDI, out); +} + +static void sr_jtdev_tst(struct jtdev *p, int out) { + UNUSED(p); + sr_gpio_write(SR_GPIO_TST, out); +} + +static int sr_jtdev_tdo_get(struct jtdev *p) { + UNUSED(p); + return !!(gpios[SR_GPIO_TDO].gpio->IDR & (1<ODR & (1<BSRR = 1<BSRR = 1<