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