GoodFET for Chipcon can erase chip and read/write info flash.
[goodfet] / firmware / include / chipcon.h
1 /*! \file chipcon.h
2   \author Travis Goodspeed
3   \brief Chipcon application functions.
4 */
5
6 #include "command.h"
7
8 //Chipcon command definitions.
9 #define CCCMD_CHIP_ERASE 0x14
10
11 //1D or 19?
12 #define CCCMD_WR_CONFIG 0x1D
13 #define CCCMD_RD_CONFIG 0x24
14 #define CCCMD_READ_STATUS 0x34
15 #define CCCMD_GET_CHIP_ID 0x68
16 #define CCCMD_GET_PC 0x28
17 #define CCCMD_HALT 0x44
18 #define CCCMD_RESUME 0x4C
19 #define CCCMD_STEP_INSTR 0x5C
20 #define CCCMD_DEBUG_INSTR 0x54
21
22 //! Erase a chipcon chip.
23 void cc_chip_erase();
24 //! Write the configuration byte.
25 void cc_wr_config(unsigned char config);
26 //! Read the configuration byte.
27 unsigned char cc_rd_config();
28 //! Read the status register.
29 unsigned char cc_read_status();
30 //! Read the CHIP ID bytes.
31 unsigned short cc_get_chip_id();
32 //! Get the PC
33 unsigned short cc_get_pc();
34 //! Set a hardware breakpoint.
35 void cc_set_hw_brkpnt(unsigned short);
36 //! Debug an instruction, for remote use.
37 void cc_debug_instr(unsigned char);
38 //!Read a byte of code memory.
39 unsigned char cc_peekcodebyte(unsigned long adr);
40 //!Read a byte of data memory.
41 unsigned char cc_peekdatabyte(unsigned int adr);
42 //! Set a byte of data memory.
43 unsigned char cc_pokedatabyte(unsigned int adr,
44                               unsigned char val);
45 //! Debug an instruction, for local use.
46 unsigned char cc_debug(unsigned char len,
47                        unsigned char a,
48                        unsigned char b,
49                        unsigned char c);
50
51 //! Populates flash buffer in xdata.
52 void cc_write_flash_buffer(u8 *data, u16 len);
53 //! Populates flash buffer in xdata.
54 void cc_write_xdata(u16 adr, u8 *data, u16 len);
55 //! Copies flash buffer to flash.
56 void cc_write_flash_page(u32 adr);
57 //! Set the Chipcon's Program Counter
58 void cc_set_pc(u32 adr);
59
60 //! Halt the CPU.
61 void cc_halt();
62 //! Resume the CPU.
63 void cc_resume();
64 //! Step an instruction
65 void cc_step_instr();
66 //! Locks the chip.
67 void cc_lockchip();
68
69 #define CC_STATUS_ERASED 0x80
70 #define CC_STATUS_PCONIDLE 0x40
71 #define CC_STATUS_CPUHALTED 0x20
72 #define CC_STATUS_PM0 0x10
73 #define CC_STATUS_HALTSTATUS 0x08
74 #define CC_STATUS_LOCKED 0x04
75 #define CC_STATUS_OSCSTABLE 0x02
76 #define CC_STATUS_OVERFLOW 0x01
77
78 //CHIPCON commands
79 #define CC_CHIP_ERASE 0x80
80 #define CC_WR_CONFIG 0x81
81 #define CC_RD_CONFIG 0x82
82 #define CC_GET_PC 0x83
83 #define CC_READ_STATUS 0x84
84 #define CC_SET_HW_BRKPNT 0x85
85 #define CC_HALT 0x86
86 #define CC_RESUME 0x87
87 #define CC_DEBUG_INSTR 0x88
88 #define CC_STEP_INSTR 0x89
89 #define CC_STEP_REPLACE 0x8a
90 #define CC_GET_CHIP_ID 0x8b
91 //CHIPCON macros
92 #define CC_READ_CODE_MEMORY 0x90
93 #define CC_READ_XDATA_MEMORY 0x91
94 #define CC_WRITE_XDATA_MEMORY 0x92
95 #define CC_SET_PC 0x93
96 #define CC_CLOCK_INIT 0x94
97 #define CC_WRITE_FLASH_PAGE 0x95
98 #define CC_READ_FLASH_PAGE 0x96
99 #define CC_MASS_ERASE_FLASH 0x97
100 #define CC_PROGRAM_FLASH 0x98
101 #define CC_WIPEFLASHBUFFER 0x99
102 #define CC_LOCKCHIP 0x9A