2 \author Travis Goodspeed
3 \brief These functions manage command interpretation and timing.
10 unsigned char cmddata[CMDDATALEN];
11 unsigned char silent=0;
13 //! Transmit a string.
14 void txstring(unsigned char app,
17 unsigned long len=strlen(str);
23 /*! \brief Transmit a debug string.
25 Transmits a debugging string that is to be printed
26 out of line by the client. This is just for record-keeping;
27 it is not considered a proper reply to a query.
29 void debugstr(const char *str){
30 txstring(0xFF,0xFF,str);
33 //! brief Debug a hex word string.
34 void debughex(u16 v) {
35 debugbytes((void *)&v, 2);
38 //! brief Debug a hex word string.
39 void debughex32(u32 v) {
40 debugbytes((void *)&v, 4);
43 /*! \brief Transmit debug bytes.
45 Transmits bytes for debugging.
47 void debugbytes(const char *bytes, unsigned int len){
49 txhead(0xFF,0xFE,len);
55 //! Transmit a header.
56 void txhead(unsigned char app,
61 //serial_tx(len); //old protocol
66 void txdata(unsigned char app,
74 serial_tx(cmddata[i]);
79 unsigned long rxlong(){
80 unsigned long toret=0;
82 toret|=(((long)serial_rx())<<8);
83 toret|=(((long)serial_rx())<<16);
84 toret|=(((long)serial_rx())<<24);
88 unsigned int rxword(){
89 unsigned long toret=0;
91 toret|=(((long)serial_rx())<<8);
95 void txlong(unsigned long l){
106 void txword(unsigned int l){
113 //Be very careful changing delay().
114 //It was chosen poorly by trial and error.
116 //! Delay for a count.
117 void delay(unsigned int count){
118 volatile unsigned int i=count;
119 while(i--) asm("nop");
122 void msdelay(unsigned int ms){
123 volatile unsigned int i,j;
127 while(j--) asm("nop");
129 //Using TimerA might be cleaner.
133 /* To better satisfy the somewhat odd timing requirements for
134 PIC33F/24H/24F ICSP programming, and for better control of GoodFET
135 timing more generally, here are a few delay routines that use Timer B.
137 Note that I wrote these referring only to the MSP430x2xx family
138 manual. Beware on MSP430x1xx chips. Further note that, assuming
139 some minor errors will be made, I try to err on the side of
140 delaying slightly longer than requested. */
144 BCSCTL2 = 0x00; /* In particular, use DCOCLK as SMCLK source with
145 divider 1. Hence, Timer B ticks with system
148 TBCTL = 0x0204; /* Driven by SMCLK; disable Timer B interrupts;
149 reset timer in case it was previously in use */
151 #warning "prep_timer() unimplemented for this platform."
154 #if (platform != tilaunchpad)
155 //! Delay for specified number of milliseconds (given 16 MHz clock)
156 void delay_ms( unsigned int ms )
159 // 16000 ticks = 1 ms
160 TBCTL |= 0x20; // Start timer!
166 TBCTL = 0x0204; // Reset Timer B, till next time
168 debugstr("delay_ms unimplemented");
172 //! Delay for specified number of microseconds (given 16 MHz clock)
173 void delay_us( unsigned int us )
177 TBCTL |= 0x20; // Start timer!
183 TBCTL = 0x0204; // Reset Timer B, till next time
185 debugstr("delay_us unimplemented");
189 //! Delay for specified number of clock ticks (16 MHz clock implies 62.5 ns per tick).
190 void delay_ticks( unsigned int num_ticks )
193 TBCTL |= 0x20; // Start timer
194 while (TBR < num_ticks)
196 TBCTL = 0x0204; // Reset Timer B, till next time
198 debugstr("delay_ticks unimplemented");