2010-04-30 04:01:03 +00:00
|
|
|
/* MSPDebug - debugging tool for MSP430 MCUs
|
2010-01-08 08:17:24 +00:00
|
|
|
* Copyright (C) 2009, 2010 Daniel Beer
|
2010-01-06 03:17:55 +00:00
|
|
|
*
|
|
|
|
* 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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DEVICE_H_
|
|
|
|
#define DEVICE_H_
|
|
|
|
|
2010-05-13 00:57:21 +00:00
|
|
|
#include <stdint.h>
|
2010-08-05 02:43:07 +00:00
|
|
|
#include "util.h"
|
2012-10-03 03:28:51 +00:00
|
|
|
#include "powerbuf.h"
|
2015-10-21 06:20:15 +00:00
|
|
|
#include "chipinfo.h"
|
2015-10-24 13:48:21 +00:00
|
|
|
#include "bytes.h"
|
2010-01-06 03:17:55 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
struct device;
|
|
|
|
typedef struct device *device_t;
|
2010-01-06 03:17:55 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
DEVICE_CTL_RESET,
|
|
|
|
DEVICE_CTL_RUN,
|
|
|
|
DEVICE_CTL_HALT,
|
2013-12-02 18:27:13 +00:00
|
|
|
DEVICE_CTL_STEP,
|
|
|
|
DEVICE_CTL_SECURE
|
2010-01-06 03:17:55 +00:00
|
|
|
} device_ctl_t;
|
|
|
|
|
2010-03-23 01:37:53 +00:00
|
|
|
typedef enum {
|
|
|
|
DEVICE_STATUS_HALTED,
|
|
|
|
DEVICE_STATUS_RUNNING,
|
|
|
|
DEVICE_STATUS_INTR,
|
|
|
|
DEVICE_STATUS_ERROR
|
|
|
|
} device_status_t;
|
|
|
|
|
2010-09-23 03:45:06 +00:00
|
|
|
typedef enum {
|
|
|
|
DEVICE_ERASE_ALL,
|
|
|
|
DEVICE_ERASE_MAIN,
|
|
|
|
DEVICE_ERASE_SEGMENT
|
|
|
|
} device_erase_type_t;
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
#define DEVICE_NUM_REGS 16
|
2010-07-27 01:08:21 +00:00
|
|
|
#define DEVICE_MAX_BREAKPOINTS 32
|
|
|
|
|
|
|
|
#define DEVICE_BP_ENABLED 0x01
|
|
|
|
#define DEVICE_BP_DIRTY 0x02
|
|
|
|
|
2012-04-25 00:43:14 +00:00
|
|
|
typedef enum {
|
|
|
|
DEVICE_BPTYPE_BREAK,
|
2012-04-25 02:10:26 +00:00
|
|
|
DEVICE_BPTYPE_WATCH,
|
|
|
|
DEVICE_BPTYPE_READ,
|
|
|
|
DEVICE_BPTYPE_WRITE
|
2012-04-25 00:43:14 +00:00
|
|
|
} device_bptype_t;
|
|
|
|
|
2010-07-27 01:08:21 +00:00
|
|
|
struct device_breakpoint {
|
2012-04-25 00:43:14 +00:00
|
|
|
device_bptype_t type;
|
|
|
|
address_t addr;
|
|
|
|
int flags;
|
2010-07-27 01:08:21 +00:00
|
|
|
};
|
2010-04-30 04:01:03 +00:00
|
|
|
|
2011-03-15 01:20:06 +00:00
|
|
|
#define DEVICE_FLAG_JTAG 0x01 /* default is SBW */
|
|
|
|
#define DEVICE_FLAG_LONG_PW 0x02
|
|
|
|
#define DEVICE_FLAG_TTY 0x04 /* default is USB */
|
2011-03-23 15:13:03 +00:00
|
|
|
#define DEVICE_FLAG_FORCE_RESET 0x08
|
2011-10-13 23:49:04 +00:00
|
|
|
#define DEVICE_FLAG_DO_FWUPDATE 0x10
|
2013-05-21 03:59:17 +00:00
|
|
|
#define DEVICE_FLAG_SKIP_CLOSE 0x20
|
2019-03-11 23:16:35 +00:00
|
|
|
#define DEVICE_FLAG_BSL_NME 0x40 /* BSL no-mass-erase */
|
2011-03-15 01:20:06 +00:00
|
|
|
|
|
|
|
struct device_args {
|
|
|
|
int flags;
|
|
|
|
int vcc_mv;
|
|
|
|
const char *path;
|
|
|
|
const char *forced_chip_id;
|
2011-07-18 02:56:29 +00:00
|
|
|
const char *requested_serial;
|
2011-12-14 00:11:29 +00:00
|
|
|
const char *require_fwupdate;
|
2014-04-01 23:37:43 +00:00
|
|
|
const char *bsl_entry_seq;
|
2014-12-14 20:06:30 +00:00
|
|
|
int bsl_gpio_used;
|
|
|
|
int bsl_gpio_rts;
|
|
|
|
int bsl_gpio_dtr;
|
2019-03-07 19:46:16 +00:00
|
|
|
uint8_t bsl_entry_password[32];
|
2011-03-15 01:20:06 +00:00
|
|
|
};
|
|
|
|
|
2011-03-15 01:56:07 +00:00
|
|
|
struct device_class {
|
|
|
|
const char *name;
|
|
|
|
const char *help;
|
|
|
|
|
|
|
|
/* Create a new device */
|
|
|
|
device_t (*open)(const struct device_args *args);
|
2010-07-02 02:22:52 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
/* Close the connection to the device and destroy the driver object */
|
|
|
|
void (*destroy)(device_t dev);
|
2010-01-06 03:17:55 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
/* Read/write memory */
|
2010-08-05 02:43:07 +00:00
|
|
|
int (*readmem)(device_t dev, address_t addr,
|
|
|
|
uint8_t *mem, address_t len);
|
|
|
|
int (*writemem)(device_t dev, address_t addr,
|
|
|
|
const uint8_t *mem, address_t len);
|
2010-01-06 03:17:55 +00:00
|
|
|
|
2010-09-23 03:45:06 +00:00
|
|
|
/* Erase memory */
|
|
|
|
int (*erase)(device_t dev, device_erase_type_t type,
|
|
|
|
address_t address);
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
/* Read/write registers */
|
2010-08-05 02:43:07 +00:00
|
|
|
int (*getregs)(device_t dev, address_t *regs);
|
|
|
|
int (*setregs)(device_t dev, const address_t *regs);
|
2010-01-06 03:17:55 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
/* CPU control */
|
|
|
|
int (*ctl)(device_t dev, device_ctl_t op);
|
2010-01-09 03:14:30 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
/* Wait a little while for the CPU to change state */
|
|
|
|
device_status_t (*poll)(device_t dev);
|
2017-06-14 19:28:07 +00:00
|
|
|
|
|
|
|
/* Get the configuration fuse values */
|
|
|
|
int (*getconfigfuses)(device_t dev);
|
2010-04-30 04:01:03 +00:00
|
|
|
};
|
2010-04-10 02:35:36 +00:00
|
|
|
|
2011-03-15 01:56:07 +00:00
|
|
|
struct device {
|
|
|
|
const struct device_class *type;
|
|
|
|
|
2012-08-09 03:33:56 +00:00
|
|
|
uint8_t dev_id[3];
|
|
|
|
|
2011-03-15 01:56:07 +00:00
|
|
|
/* Breakpoint table. This should not be modified directly.
|
|
|
|
* Instead, you should use the device_setbrk() helper function. This
|
|
|
|
* will set the appropriate flags and ensure that the breakpoint is
|
|
|
|
* reloaded before the next run.
|
|
|
|
*/
|
|
|
|
int max_breakpoints;
|
|
|
|
struct device_breakpoint breakpoints[DEVICE_MAX_BREAKPOINTS];
|
2012-10-03 03:28:51 +00:00
|
|
|
|
|
|
|
/* Power sample buffer, if power profiling is supported by this
|
|
|
|
* device.
|
|
|
|
*/
|
|
|
|
powerbuf_t power_buf;
|
2015-10-21 06:20:15 +00:00
|
|
|
|
|
|
|
/* Chip information data.
|
|
|
|
*/
|
|
|
|
const struct chipinfo *chip;
|
|
|
|
int need_probe;
|
2011-03-15 01:56:07 +00:00
|
|
|
};
|
|
|
|
|
2012-08-09 03:33:56 +00:00
|
|
|
/* Probe the device memory and extract ID bytes. This should be called
|
|
|
|
* after the device structure is ready.
|
|
|
|
*/
|
2015-10-21 06:20:15 +00:00
|
|
|
int device_probe_id(device_t dev, const char *force_id);
|
2012-08-09 03:33:56 +00:00
|
|
|
|
|
|
|
/* Determine, from the device ID bytes, whether this chip is an FRAM or
|
|
|
|
* flash-based device.
|
|
|
|
*/
|
|
|
|
int device_is_fram(device_t dev);
|
|
|
|
|
2010-07-27 01:08:21 +00:00
|
|
|
/* Set or clear a breakpoint. The index of the modified entry is
|
|
|
|
* returned, or -1 if no free entries were available. The modified
|
|
|
|
* entry is flagged so that it will be reloaded on the next run.
|
|
|
|
*
|
|
|
|
* If which is specified, a particular breakpoint slot is
|
|
|
|
* modified. Otherwise, if which < 0, breakpoint slots are selected
|
|
|
|
* automatically.
|
|
|
|
*/
|
2012-04-25 00:43:14 +00:00
|
|
|
int device_setbrk(device_t dev, int which, int enabled, address_t address,
|
|
|
|
device_bptype_t type);
|
2010-07-27 01:08:21 +00:00
|
|
|
|
2011-03-15 00:12:48 +00:00
|
|
|
extern device_t device_default;
|
|
|
|
|
|
|
|
/* Helper macros for operating on the default device */
|
2011-03-15 01:56:07 +00:00
|
|
|
#define device_destroy() device_default->type->destroy(device_default)
|
2011-03-15 00:12:48 +00:00
|
|
|
#define device_readmem(addr, mem, len) \
|
2011-03-15 01:56:07 +00:00
|
|
|
device_default->type->readmem(device_default, addr, mem, len)
|
2011-03-15 00:12:48 +00:00
|
|
|
#define device_writemem(addr, mem, len) \
|
2011-03-15 01:56:07 +00:00
|
|
|
device_default->type->writemem(device_default, addr, mem, len)
|
2011-03-15 00:12:48 +00:00
|
|
|
#define device_getregs(regs) \
|
2011-03-15 01:56:07 +00:00
|
|
|
device_default->type->getregs(device_default, regs)
|
2011-03-15 00:12:48 +00:00
|
|
|
#define device_setregs(regs) \
|
2011-03-15 01:56:07 +00:00
|
|
|
device_default->type->setregs(device_default, regs)
|
2011-03-15 00:12:48 +00:00
|
|
|
#define device_ctl(op) \
|
2011-03-15 01:56:07 +00:00
|
|
|
device_default->type->ctl(device_default, op)
|
2011-03-15 00:12:48 +00:00
|
|
|
#define device_poll() \
|
2011-03-15 01:56:07 +00:00
|
|
|
device_default->type->poll(device_default)
|
2011-03-15 00:12:48 +00:00
|
|
|
|
2012-08-09 03:30:05 +00:00
|
|
|
int device_erase(device_erase_type_t et, address_t addr);
|
|
|
|
|
2015-10-24 13:48:21 +00:00
|
|
|
address_t check_range(const struct chipinfo *chip,
|
|
|
|
address_t addr, address_t size,
|
|
|
|
const struct chipinfo_memory **m_ret);
|
|
|
|
|
|
|
|
int readmem(device_t dev, address_t addr,
|
|
|
|
uint8_t *mem, address_t len,
|
|
|
|
int (*read_words)(device_t dev,
|
|
|
|
const struct chipinfo_memory *m,
|
|
|
|
address_t addr, address_t len,
|
|
|
|
uint8_t *data)
|
|
|
|
);
|
|
|
|
|
|
|
|
int writemem(device_t dev, address_t addr,
|
|
|
|
const uint8_t *mem, address_t len,
|
|
|
|
int (*write_words)(device_t dev,
|
|
|
|
const struct chipinfo_memory *m,
|
|
|
|
address_t addr, address_t len,
|
|
|
|
const uint8_t *data),
|
|
|
|
int (*read_words)(device_t dev,
|
|
|
|
const struct chipinfo_memory *m,
|
|
|
|
address_t addr, address_t len,
|
|
|
|
uint8_t *data)
|
|
|
|
);
|
|
|
|
|
2010-01-06 03:17:55 +00:00
|
|
|
#endif
|