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