diff options
author | Keith Packard <keithp@keithp.com> | 2008-12-19 11:04:16 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2008-12-19 11:04:16 -0800 |
commit | 55995515b9d4fc1e193039eab697c5d03db417c2 (patch) | |
tree | 26fe03c8e599a60cdaf2b4d1ebc3b17549584320 /ccdbg-command.c | |
parent | 0bc52385b8f86f9ca1c450ad106e6d8afe3bc153 (diff) |
Add flash writing code.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ccdbg-command.c')
-rw-r--r-- | ccdbg-command.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/ccdbg-command.c b/ccdbg-command.c index 50dd1fd4..38c006cb 100644 --- a/ccdbg-command.c +++ b/ccdbg-command.c @@ -65,7 +65,7 @@ ccdbg_rd_config(struct ccdbg *dbg) return ccdbg_cmd_write_read8(dbg, CC_RD_CONFIG, NULL, 0); } -uint8_t +uint16_t ccdbg_get_pc(struct ccdbg *dbg) { return ccdbg_cmd_write_read16(dbg, CC_GET_PC, NULL, 0); @@ -146,3 +146,37 @@ ccdbg_execute(struct ccdbg *dbg, uint8_t *inst) return status; } +static uint8_t jump_mem[] = { + 3, LJMP, 0xf0, 0x00, +#define PC_HIGH 2 +#define PC_LOW 3 + 0 +}; + +uint8_t +ccdbg_set_pc(struct ccdbg *dbg, uint16_t pc) +{ + jump_mem[PC_HIGH] = pc >> 8; + jump_mem[PC_LOW] = pc & 0xff; + return ccdbg_execute(dbg, jump_mem); +} + +uint8_t +ccdbg_execute_hex_image(struct ccdbg *dbg, struct hex_image *image) +{ + uint16_t pc; + uint8_t status; + + if (image->address < 0xf000) { + fprintf(stderr, "Cannot execute program starting at 0x%04x\n", image->address); + return -1; + } + ccdbg_write_hex_image(dbg, image, 0); + ccdbg_set_pc(dbg, image->address); + pc = ccdbg_get_pc(dbg); + printf ("pc starts at 0x%04x\n", pc); + status = ccdbg_resume(dbg); + printf ("resume status: 0x%02x\n", status); + return 0; +} + |