A major refactor of the GoodFET firmware build system and apps to give better
[goodfet] / firmware / include / command.h
index fe3beb1..dfa4003 100644 (file)
@@ -3,12 +3,33 @@
   \brief Command codes and buffers.
 */
 
-//! Global data buffer.
+
+#ifndef COMMAND_H
+#define COMMAND_H
+
+#include <stdint.h>
+
+//Types
+#define u8 unsigned char
+#define u16 unsigned int
+#define u32 unsigned long
+
+
+#ifdef msp430x2274
+//256 bytes, plus overhead
+//For chips with very little RAM.
+#define CMDDATALEN 0x104
+//#warning Very little RAM.
+#endif
 
 #ifndef CMDDATALEN
-#define CMDDATALEN 0x200
+//512 bytes
+#define CMDDATALEN 0x204
+//4k
+//#define CMDDATALEN 0x1004
 #endif
 
+//! Global data buffer.
 extern unsigned char cmddata[CMDDATALEN];
 extern unsigned char silent;
 
@@ -25,84 +46,35 @@ extern unsigned char silent;
 #define SETUP 0x10
 #define START 0x20
 #define STOP  0x21
+#define CALL  0x30
+#define EXEC  0x31
 #define NOK   0x7E
 #define OK    0x7F
 
 #define DEBUGSTR 0xFF
 
-// Monitor Commands
-#define MONITOR_CHANGE_BAUD 0x80
-#define MONITOR_RAM_PATTERN 0x90
-#define MONITOR_RAM_DEPTH 0x91
-
-#define MONITOR_DIR 0xA0
-#define MONITOR_OUT 0xA1
-#define MONITOR_IN  0xA2
-
-#define MONITOR_SILENT 0xB0
-
-#define MONITOR_READBUF 0xC0
-#define MONITOR_WRITEBUF 0xC1
-#define MONITOR_SIZEBUF 0xC2
-
-
-//CHIPCON commands
-#define CC_CHIP_ERASE 0x80
-#define CC_WR_CONFIG 0x81
-#define CC_RD_CONFIG 0x82
-#define CC_GET_PC 0x83
-#define CC_READ_STATUS 0x84
-#define CC_SET_HW_BRKPNT 0x85
-#define CC_HALT 0x86
-#define CC_RESUME 0x87
-#define CC_DEBUG_INSTR 0x88
-#define CC_STEP_INSTR 0x89
-#define CC_STEP_REPLACE 0x8a
-#define CC_GET_CHIP_ID 0x8b
-//CHIPCON macros
-#define CC_READ_CODE_MEMORY 0x90
-#define CC_READ_XDATA_MEMORY 0x91
-#define CC_WRITE_XDATA_MEMORY 0x92
-#define CC_SET_PC 0x93
-#define CC_CLOCK_INIT 0x94
-#define CC_WRITE_FLASH_PAGE 0x95
-#define CC_READ_FLASH_PAGE 0x96
-#define CC_MASS_ERASE_FLASH 0x97
-#define CC_PROGRAM_FLASH 0x98
-
-//JTAG commands
-#define JTAG_IR_SHIFT 0x80
-#define JTAG_DR_SHIFT 0x81
-#define JTAG_DR_SHIFT20 0x91
+
 
 //SPI commands
 #define SPI_JEDEC 0x80
 #define SPI_ERASE 0x81
+#define SPI_RW_EM260 0x82
 
 //OCT commands
 #define OCT_CMP 0x90
 #define OCT_RES 0x91
 
-//JTAG430 commands
-#define JTAG430_HALTCPU 0xA0
-#define JTAG430_RELEASECPU 0xA1
-#define JTAG430_SETINSTRFETCH 0xC1
-#define JTAG430_SETPC 0xC2
-#define JTAG430_WRITEMEM 0xE0
-#define JTAG430_WRITEFLASH 0xE1
-#define JTAG430_READMEM 0xE2
-#define JTAG430_ERASEFLASH 0xE3
-#define JTAG430_ERASECHECK 0xE4
-#define JTAG430_VERIFYMEM 0xE5
-#define JTAG430_BLOWFUSE 0xE6
-#define JTAG430_ISFUSEBLOWN 0xE7
-#define JTAG430_COREIP_ID 0xF0
-#define JTAG430_DEVICE_ID 0xF1
+#ifdef GCC
+#define WEAKDEF __attribute__ ((weak))
+#else
+//Compiler doesn't support weak linking. :(
+#define WEAKDEF
+#endif
 
 //! Handle a command.  Defined in goodfet.c
-void handle(unsigned char app,
-           unsigned char verb,
-           unsigned long len);
+void handle(uint8_t const app,
+                       uint8_t const verb,
+                       uint32_t const len);
 //! Transmit a header.
 void txhead(unsigned char app,
            unsigned char verb,
@@ -126,8 +98,14 @@ void txlong(unsigned long l);
 //! Transmit a word.
 void txword(unsigned int l);
 
+//! Transmit a debug sequence of bytes
+void debugbytes(const char *bytes, unsigned int len);
 //! Transmit a debug string.
 void debugstr(const char *str);
+//! brief Debug a hex word string.
+void debughex(u16 v);
+//! brief Debug a hex long string.
+void debughex32(u32 v);
 
 //! Delay for a count.
 void delay(unsigned int count);
@@ -135,12 +113,16 @@ void delay(unsigned int count);
 void msdelay(unsigned int ms);
 
 
-void monitorhandle(unsigned char, unsigned char, unsigned long);
-void spihandle(unsigned char, unsigned char, unsigned long);
-void i2chandle(unsigned char, unsigned char, unsigned long);
-void cchandle(unsigned char, unsigned char, unsigned long);
-void jtaghandle(unsigned char, unsigned char, unsigned long);
-void jtag430handle(unsigned char, unsigned char, unsigned long);
-void jtag430x2handle(unsigned char app, unsigned char verb,
-                    unsigned long len);
-  
+//! Prepare Timer B; call before using delay_ms or delay_us.
+void prep_timer();
+
+//! Delay for specified number of milliseconds (given 16 MHz clock)
+void delay_ms( unsigned int ms );
+
+//! Delay for specified number of microseconds (given 16 MHz clock)
+void delay_us( unsigned int us );
+
+//! Delay for specified number of clock ticks (16 MHz clock implies 62.5 ns per tick).
+void delay_ticks( unsigned int num_ticks );
+
+#endif // COMMAND_H