pico430prog/src/msp430/msp430dbg.h

177 lines
6.0 KiB
C

#ifndef MSP430DBG_H_
#define MSP430DBG_H_
#include <stdint.h>
#include <stdbool.h>
// also seen: 8D 91 95 99
#define MSP430_JTAG_TAP_ID 0x89
enum msp430_ir {
//!all these // EMEX == EEM
msp430_ir_emex_data_exchange = 0x09,
msp430_ir_emex_read_trigger = 0x0a, // unused? / unknown
msp430_ir_emex_read_control = 0x0b,
msp430_ir_emex_write_control = 0x0c,
msp430_ir_emex_data_exchange32 = 0x0d, // 430X/Xv2-only
// overlaps with EMEX!
msp430_ir_bp_cntl_16bit = 0x09, // unused? / unknown // == data_exchange
msp430_ir_bp_cntl_capture = 0x0a, // unused? / unknown
msp430_ir_bp1_16bit = 0x0b, // unused? / unknown
msp430_ir_bp1_capture = 0x0c, // unused? / unknown
msp430_ir_bp2_16bit = 0x0d, // unused? / unknown
msp430_ir_bp2_capture = 0x0e, // unused? / unknown
msp430_ir_ctrl_sig_high_byte = 0x11,
msp430_ir_ctrl_sig_low_byte = 0x12,
msp430_ir_ctrl_sig_16bit = 0x13,
msp430_ir_ctrl_sig_capture = 0x14,
msp430_ir_ctrl_sig_release = 0x15,
msp430_ir_coreip_id = 0x17, // pointer to more data on non-0x89 JTAG IDs?
msp430_ir_jstate_id = 0x18, // JState is Xv2 stuff so eh // NOTE: 64-bit DRshift!
msp430_ir_flash_16bit_update = 0x19, // "disable flash test mode"?
msp430_ir_flash_capture = 0x1a, // unused? / unknown
msp430_ir_flash_16bit_in = 0x1b, // unused? / unknown
msp430_ir_flash_update = 0x1c, // unused? / unknown
// sesel = 0x0080, tmr = 0x0800
msp430_ir_cntrl = 0x21, // unused? / unknown
msp430_ir_fuse_prepare_blow = 0x22,
msp430_ir_fuse_ex_blow = 0x24,
msp430_ir_config_fuses = 0x29, // get fuse state? uses 8-bit DRshift!
msp43_ir_test_reg = 0x2a, // Xv2-only
msp43_ir_test_v3_reg = 0x2f,
// TODO: what is LPM? something with power? related to LPMx.5
// "embedded signal processing cell" control
msp430_ir_dual_8bit = 0x31,
msp430_ir_dual_capture = 0x32,
msp430_ir_select_main = 0x33,
msp430_ir_select_esp = 0x34,
msp430_ir_tclk_toggle_inst = 0x39, // unused? / unknown
msp430_ir_tclk_0_inst = 0x3a, // unused? / unknown
msp430_ir_tclk_1_inst = 0x3b, // unused? / unknown
msp430_ir_data_16bit = 0x41,
msp430_ir_data_capture = 0x42,//! // reads from data bus?
msp430_ir_data_quick = 0x43,
msp430_ir_data_psa = 0x44,
msp430_ir_data_16bit_opt = 0x45, // unused? / unknown
msp430_ir_shift_out_psa = 0x46,
msp430_ir_dta = 0x47, // unused? / unknown
msp430_ir_accept_key = 0x59, // unused? / unknown
msp430_ir_jmb_exchange = 0x61,
msp430_ir_tdo_event = 0x64, // unused? / unknown
msp430_ir_tdo_event_ctl = 0x65, // unused? / unknown
msp430_ir_addr_high_byte = 0x81,
msp430_ir_addr_low_byte = 0x82,
msp430_ir_addr_16bit = 0x83,
msp430_ir_addr_capture = 0x84,
msp430_ir_data_to_addr = 0x85,
msp430_ir_capture_cpu_reg = 0x86, // unused? / unknown
msp430_ir_device_id = 0x87, // "device ip pointer" for non-0x89 JTAG IDs
msp430_ir_jmb_write_32bit_mode = 0x88,//!
msp430_ir_bypass = 0xff
};
enum msp430_ctrl {
msp430_ctrl_RnW = 1<< 0,
msp430_ctrl_cpu_halt = 1<< 1,
msp430_ctrl_intr_req = 1<< 2,
msp430_ctrl_halt_jtag = 1<< 3,
msp430_ctrl_byte = 1<< 4,
msp430_ctrl_cpu_off = 1<< 5,
msp430_ctrl_mclk_on = 1<< 6,
msp430_ctrl_instr_load = 1<< 7,
msp430_ctrl_tmode = 1<< 8,
msp430_ctrl_tce0 = 1<< 9,
msp430_ctrl_tce1 = 1<<10,
msp430_ctrl_por = 1<<11,
msp430_release_lbyte0 = 1<<12,
msp430_tagfuncsat = 1<<13,
msp430_switch = 1<<14,
msp430_ctrl_stop_sel = 1<<15,
};
bool msp430_check_fuse_blown(void);
bool msp430_insn_fetch(void);
void msp430_pc_set(uint16_t pc);
void msp430_cpu_halt(void);
void msp430_cpu_release(void);
bool msp430_cpu_reset(void); // POR
static inline bool msp430_device_control(void) { return msp430_check_fuse_blown(); }
void msp430_device_release(uint16_t addr);
uint16_t msp430_memory_read16(uint16_t addr);
uint8_t msp430_memory_read8 (uint16_t addr);
void msp430_memory_write16(uint16_t addr, uint16_t value);
void msp430_memory_write8 (uint16_t addr, uint8_t value);
void msp430_memory_read_block(uint16_t srcaddr, uint16_t numwords, uint16_t* dest);
void msp430_memory_write_block(uint16_t dstaddr, uint16_t numwords, const uint16_t* src);
bool msp430_memory_verify(uint16_t startaddr, uint16_t length, const uint16_t* copy);
#define msp430_memory_read(bits, addr) (msp430_memory_read##bits (addr))
#define msp430_memory_write(bit, a, v) (msp430_memory_write##bit (a, v))
void msp430_flash_write(uint16_t startaddr, uint16_t num, const uint16_t* src);//
// TODO: erase routine needs to be redone
void msp430_flash_erase_seg(uint16_t startaddr, bool is_infosegA);//
void msp430_flash_erase_mass(bool withinfomem); // false: only main flash
uint32_t msp430_device_get(float freq);
// TODO: from non-slau320aj src
uint16_t msp430_read_jmb(void);
void msp430_write_jmb(uint16_t v);
uint16_t msp430_cpureg_read(short regno);
void msp430_cpureg_write(short regno, uint16_t value);
// TODO:
// 430X and Xv2 versions of the above routines
//
// EnableLpmx5
// DisableLpmx5
// what do these do? it's something about power mode, it's disabled when
// starting JTAG, and reenabled when releasing JTAG
// only MSP430Xv2, though, so we're not going to care for now. (I don't
// have such chips, only an MSP430G2212 and a G2452)
// uses test_reg and test_reg_3V
//
// jstate_read
// what is this for? (Xv2-only -> let's not care for this either now)
// uses 64-bit DRshift!
// -> PollJStateReg, HilCommand, SingleStepJState
//
// eem_write_control
// used in save & restore context stuff / jtag start & release
// eem_read_control
// used where write_control is used, but also "wait for eem" and single-step
// eem_data_exchange
// used in a lot of places: write_control places, single-step, wait for storage, "eemdataexchange", execute funclet
//
// what is EEM? what is its sub-command stuff?
//
// wait for EEM
// JTAG release with context restore
// JTAG start with context save
// single-step
// wait for storage(?)
// execute funclet
// get dco frequency // annoying
#endif