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