2 \author Travis Goodspeed
3 \brief These functions manage command interpretation.
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) {
39 a[2]+=(a[2]>9)?('a'-10):'0';
42 a[3]+=(a[3]>9)?('a'-10):'0';
45 a[4]+=(a[4]>9)?('a'-10):'0';
48 a[5]+=(a[5]>9)?('a'-10):'0';
52 txstring(0xFF,0xFF,a);
55 /*! \brief Transmit debug bytes.
57 Transmits bytes for debugging.
59 void debugbytes(const char *bytes, unsigned int len){
61 txhead(0xFF,0xFE,len);
67 //! Transmit a header.
68 void txhead(unsigned char app,
73 //serial_tx(len); //old protocol
78 void txdata(unsigned char app,
86 serial_tx(cmddata[i]);
91 unsigned long rxlong(){
92 unsigned long toret=0;
94 toret|=(((long)serial_rx())<<8);
95 toret|=(((long)serial_rx())<<16);
96 toret|=(((long)serial_rx())<<24);
100 unsigned int rxword(){
101 unsigned long toret=0;
103 toret|=(((long)serial_rx())<<8);
107 void txlong(unsigned long l){
118 void txword(unsigned int l){
125 //Be very careful changing delay().
126 //It was chosen poorly by trial and error.
128 //! Delay for a count.
129 void delay(unsigned int count){
130 volatile unsigned int i=count;
131 while(i--) asm("nop");
134 void msdelay(unsigned int ms){
135 volatile unsigned int i,j;
139 while(j--) asm("nop");
141 //Using TimerA might be cleaner.
145 /* To better satisfy the somewhat odd timing requirements for
146 dsPIC33F/PIC24H ICSP programming, and for better control of GoodFET
147 timing more generally, here are a few delay routines that use Timer A.
149 Note that I wrote these referring only to the MSP430x2xx family
150 manual. Beware on MSP430x1xx chips. Further note that, assuming
151 some minor errors will be made, I try to err on the side of
152 delaying slightly longer than requested. */
155 BCSCTL2 = 0x00; /* In particular, use DCOCLK as SMCLK source with
156 divider 1. Hence, Timer A ticks with system
159 TACTL = 0x0204; /* Driven by SMCLK; disable Timer A interrupts;
160 reset timer in case it was previously in use */
163 //! Delay for specified number of milliseconds (given 16 MHz clock)
164 void delay_ms( unsigned int ms )
166 // 16000 ticks = 1 ms
167 TACTL |= 0x20; // Start timer!
173 TACTL = 0x0204; // Reset Timer A, till next time
176 //! Delay for specified number of microseconds (given 16 MHz clock)
177 void delay_us( unsigned int us )
180 TACTL |= 0x20; // Start timer!
186 TACTL = 0x0204; // Reset Timer A, till next time
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 )
192 TACTL |= 0x20; // Start timer
193 while (TAR < num_ticks)
195 TACTL = 0x0204; // Reset Timer A, till next time