}
uint8_t
-ccdbg_read_status(struct ccdbg *dbg)
+ccdbg_chip_erase(struct ccdbg *dbg)
{
- return ccdbg_cmd_write_read8(dbg, CC_READ_STATUS, NULL, 0);
+ return ccdbg_cmd_write_read8(dbg, CC_CHIP_ERASE, NULL, 0);
+}
+
+uint8_t
+ccdbg_wr_config(struct ccdbg *dbg, uint8_t config)
+{
+ return ccdbg_cmd_write_read8(dbg, CC_WR_CONFIG, &config, 1);
}
uint8_t
return ccdbg_cmd_write_read8(dbg, CC_RD_CONFIG, NULL, 0);
}
+uint8_t
+ccdbg_get_pc(struct ccdbg *dbg)
+{
+ return ccdbg_cmd_write_read16(dbg, CC_GET_PC, NULL, 0);
+}
+
+uint8_t
+ccdbg_read_status(struct ccdbg *dbg)
+{
+ return ccdbg_cmd_write_read8(dbg, CC_READ_STATUS, NULL, 0);
+}
+
+uint8_t
+ccdbg_set_hw_brkpnt(struct ccdbg *dbg, uint8_t number, uint8_t enable, uint16_t addr)
+{
+ uint8_t data[3];
+
+ data[0] = (number << 3) | (enable << 2);
+ data[1] = (addr >> 8);
+ data[2] = addr;
+ return ccdbg_cmd_write_read8(dbg, CC_SET_HW_BRKPNT, data, 3);
+}
+
+uint8_t
+ccdbg_halt(struct ccdbg *dbg)
+{
+ return ccdbg_cmd_write_read8(dbg, CC_HALT, NULL, 0);
+}
+
+uint8_t
+ccdbg_resume(struct ccdbg *dbg)
+{
+ return ccdbg_cmd_write_read8(dbg, CC_RESUME, NULL, 0);
+}
+
+uint8_t
+ccdbg_debug_instr(struct ccdbg *dbg, uint8_t *instr, int nbytes)
+{
+ return ccdbg_cmd_write_read8(dbg, CC_DEBUG_INSTR(nbytes), instr, nbytes);
+}
+
+uint8_t
+ccdbg_step_instr(struct ccdbg *dbg)
+{
+ return ccdbg_cmd_write_read8(dbg, CC_STEP_INSTR, NULL, 0);
+}
+
+uint8_t
+ccdbg_step_replace(struct ccdbg *dbg, uint8_t *instr, int nbytes)
+{
+ return ccdbg_cmd_write_read8(dbg, CC_STEP_REPLACE(nbytes), instr, nbytes);
+}
+
uint16_t
ccdbg_get_chip_id(struct ccdbg *dbg)
{
return ccdbg_cmd_write_read16(dbg, CC_GET_CHIP_ID, NULL, 0);
}
-
#include "ccdbg.h"
+#define MOV 0x75
+
+static uint8_t instructions[] = {
+ 3, MOV, 0xfe, 0x02,
+ 3, MOV, 0x90, 0xff,
+ 0
+};
+
+static void
+ccdbg_instructions(struct ccdbg *dbg, uint8_t *inst)
+{
+ while(inst[0] != 0) {
+ uint8_t len = inst[0];
+ uint8_t status;
+ status = ccdbg_debug_instr(dbg, inst+1, len);
+ printf ("inst status 0x%02x\n", status);
+ inst += len + 1;
+ }
+}
+
int
main (int argc, char **argv)
{
printf("Status: 0x%02x\n", status);
chip_id = ccdbg_get_chip_id(dbg);
printf("Chip id: 0x%04x\n", chip_id);
- ccdbg_reset(dbg);
+ status = ccdbg_halt(dbg);
+ printf ("halt status: 0x%02x\n", status);
+ ccdbg_instructions(dbg, instructions);
#endif
ccdbg_close(dbg);
exit (0);
#define CC_RESUME 0x4c
#define CC_DEBUG_INSTR(n) (0x54|(n))
#define CC_STEP_INSTR 0x5c
-#define CC_STEP_REPLACE (0x64|(n))
+#define CC_STEP_REPLACE(n) (0x64|(n))
#define CC_GET_CHIP_ID 0x68
#define CC_DEBUG_BITBANG 0x00000001
ccdbg_reset(struct ccdbg *dbg);
uint8_t
-ccdbg_read_status(struct ccdbg *dbg);
+ccdbg_chip_erase(struct ccdbg *dbg);
+
+uint8_t
+ccdbg_wr_config(struct ccdbg *dbg, uint8_t config);
uint8_t
ccdbg_rd_config(struct ccdbg *dbg);
+uint8_t
+ccdbg_get_pc(struct ccdbg *dbg);
+
+uint8_t
+ccdbg_read_status(struct ccdbg *dbg);
+
+uint8_t
+ccdbg_set_hw_brkpnt(struct ccdbg *dbg, uint8_t number, uint8_t enable, uint16_t addr);
+
+uint8_t
+ccdbg_halt(struct ccdbg *dbg);
+
+uint8_t
+ccdbg_resume(struct ccdbg *dbg);
+
+uint8_t
+ccdbg_debug_instr(struct ccdbg *dbg, uint8_t *instr, int nbytes);
+
+uint8_t
+ccdbg_step_instr(struct ccdbg *dbg);
+
+uint8_t
+ccdbg_step_replace(struct ccdbg *dbg, uint8_t *instr, int nbytes);
+
uint16_t
ccdbg_get_chip_id(struct ccdbg *dbg);
+
+
/* ccdbg-debug.c */
void
ccdbg_debug(int level, char *format, ...);