Fixed USB host bugs.
[goodfet] / firmware / include / command.h
1 /*! \file command.h
2   \author Travis Goodspeed
3   \brief Command codes and buffers.
4 */
5
6
7 #ifndef COMMAND_H
8 #define COMMAND_H
9
10 #include <stdint.h>
11
12 //Types
13 #define u8 unsigned char
14 #define u16 unsigned int
15 #define u32 unsigned long
16
17
18 #ifdef msp430f2274
19 //256 bytes, plus overhead
20 //For chips with very little RAM.
21 #define CMDDATALEN 0x104
22 //#warning Very little RAM.
23 #endif
24
25 #ifndef CMDDATALEN
26 //512 bytes
27 #define CMDDATALEN 0x204
28 //4k
29 //#define CMDDATALEN 0x1004
30 #endif
31
32 //! Global data buffer.
33 extern unsigned char cmddata[CMDDATALEN];
34 extern unsigned char silent;
35
36 #define cmddataword ((unsigned int*) cmddata)
37 #define cmddatalong ((unsigned long*) cmddata)
38 #define memorybyte ((char*)  0)
39 //#define memoryword ((unsigned int*)  0))
40
41 // Global Commands
42 #define READ  0x00
43 #define WRITE 0x01
44 #define PEEK  0x02
45 #define POKE  0x03
46 #define SETUP 0x10
47 #define START 0x20
48 #define STOP  0x21
49 #define CALL  0x30
50 #define EXEC  0x31
51 #define LIMIT 0x7B /* limit reached */
52 #define EXIST 0x7C /* already or doesnt exist */
53 #define NMEM  0x7D /* OOM */
54 #define NOK   0x7E
55 #define OK    0x7F
56
57 #define DEBUGSTR 0xFF
58
59
60
61 //SPI commands
62 #define SPI_JEDEC 0x80
63 #define SPI_ERASE 0x81
64 #define SPI_RW_EM260 0x82
65
66 //OCT commands
67 #define OCT_CMP 0x90
68 #define OCT_RES 0x91
69
70 #ifdef GCC
71 #define WEAKDEF __attribute__ ((weak))
72 #else
73 //Compiler doesn't support weak linking. :(
74 #define WEAKDEF
75 #endif
76
77 //! Handle a command.  Defined in goodfet.c
78 void handle(uint8_t const app,
79                         uint8_t const verb,
80                         uint32_t const len);
81 //! Transmit a header.
82 void txhead(unsigned char app,
83             unsigned char verb,
84             unsigned long len);
85 //! Transmit data.
86 void txdata(unsigned char app,
87             unsigned char verb,
88             unsigned long len);
89 //! Transmit a string.
90 void txstring(unsigned char app,
91               unsigned char verb,
92               const char *str);
93
94 //! Receive a long.
95 unsigned long rxlong();
96 //! Receive a word.
97 unsigned int rxword();
98
99 //! Transmit a long.
100 void txlong(unsigned long l);
101 //! Transmit a word.
102 void txword(unsigned int l);
103
104 //! Transmit a debug sequence of bytes
105 void debugbytes(const char *bytes, unsigned int len);
106 //! Transmit a debug string.
107 void debugstr(const char *str);
108 //! brief Debug a hex word string.
109 void debughex(u16 v);
110 //! brief Debug a hex long string.
111 void debughex32(u32 v);
112
113 //! Delay for a count.
114 void delay(unsigned int count);
115 //! MSDelay
116 void msdelay(unsigned int ms);
117
118
119 //! Prepare Timer B; call before using delay_ms or delay_us.
120 void prep_timer();
121
122 //! Delay for specified number of milliseconds (given 16 MHz clock)
123 void delay_ms( unsigned int ms );
124
125 //! Delay for specified number of microseconds (given 16 MHz clock)
126 void delay_us( unsigned int us );
127
128 //! Delay for specified number of clock ticks (16 MHz clock implies 62.5 ns per tick).
129 void delay_ticks( unsigned int num_ticks );
130
131 #endif // COMMAND_H