Chipcon peek and poke for iram, include SFRs.
[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 //! Fetch a byte of IRAM.
43 u8 cc_peekirambyte(u8 adr);
44 //! Write a byte of IRAM.
45 u8 cc_pokeirambyte(u8 adr, u8 val);
46 //! Set a byte of data memory.
47 unsigned char cc_pokedatabyte(unsigned int adr,
48                               unsigned char val);
49 //! Debug an instruction, for local use.
50 unsigned char cc_debug(unsigned char len,
51                        unsigned char a,
52                        unsigned char b,
53                        unsigned char c);
54
55 //! Populates flash buffer in xdata.
56 void cc_write_flash_buffer(u8 *data, u16 len);
57 //! Populates flash buffer in xdata.
58 void cc_write_xdata(u16 adr, u8 *data, u16 len);
59 //! Copies flash buffer to flash.
60 void cc_write_flash_page(u32 adr);
61 //! Set the Chipcon's Program Counter
62 void cc_set_pc(u32 adr);
63
64 //! Halt the CPU.
65 void cc_halt();
66 //! Resume the CPU.
67 void cc_resume();
68 //! Step an instruction
69 void cc_step_instr();
70 //! Locks the chip.
71 void cc_lockchip();
72
73 #define CC_STATUS_ERASED 0x80
74 #define CC_STATUS_PCONIDLE 0x40
75 #define CC_STATUS_CPUHALTED 0x20
76 #define CC_STATUS_PM0 0x10
77 #define CC_STATUS_HALTSTATUS 0x08
78 #define CC_STATUS_LOCKED 0x04
79 #define CC_STATUS_OSCSTABLE 0x02
80 #define CC_STATUS_OVERFLOW 0x01
81
82 //CHIPCON commands
83 #define CC_CHIP_ERASE 0x80
84 #define CC_WR_CONFIG 0x81
85 #define CC_RD_CONFIG 0x82
86 #define CC_GET_PC 0x83
87 #define CC_READ_STATUS 0x84
88 #define CC_SET_HW_BRKPNT 0x85
89 #define CC_HALT 0x86
90 #define CC_RESUME 0x87
91 #define CC_DEBUG_INSTR 0x88
92 #define CC_STEP_INSTR 0x89
93 #define CC_STEP_REPLACE 0x8a
94 #define CC_GET_CHIP_ID 0x8b
95 //CHIPCON macros
96 #define CC_READ_CODE_MEMORY 0x90
97 #define CC_READ_XDATA_MEMORY 0x91
98 #define CC_WRITE_XDATA_MEMORY 0x92
99 #define CC_SET_PC 0x93
100 #define CC_CLOCK_INIT 0x94
101 #define CC_WRITE_FLASH_PAGE 0x95
102 #define CC_READ_FLASH_PAGE 0x96
103 #define CC_MASS_ERASE_FLASH 0x97
104 #define CC_PROGRAM_FLASH 0x98
105 #define CC_WIPEFLASHBUFFER 0x99
106 #define CC_LOCKCHIP 0x9A