Urgent client fix, related to block offsets.
[goodfet] / firmware / lib / command.c
1 /*! \file command.c
2   \author Travis Goodspeed
3   \brief These functions manage command interpretation.
4 */
5
6 #include "command.h"
7 #include "platform.h"
8 #include <string.h>
9
10 unsigned char cmddata[256];
11
12
13 //! Transmit a string.
14 void txstring(unsigned char app,
15               unsigned char verb,
16               const char *str){
17   unsigned char len=strlen(str);
18   serial_tx(app);
19   serial_tx(verb);
20   serial_tx(len);
21   while(len--)
22     serial_tx(*(str++));
23 }
24
25 /*! \brief Transmit a debug string.
26   
27   Transmits a debugging string that is to be printed
28   out of line by the client.  This is just for record-keeping;
29   it is not considered a proper reply to a query.
30  */
31 void debugstr(const char *str){
32   txstring(0xFF,0xFF,str);
33 }
34
35
36 //! Transmit data.
37 void txdata(unsigned char app,
38             unsigned char verb,
39             unsigned char len){
40   unsigned int i=0;
41   serial_tx(app);
42   serial_tx(verb);
43   serial_tx(len);
44   for(i=0;i<len;i++){
45     serial_tx(cmddata[i]);
46   }
47 }
48
49 //Be very careful changing delay().
50 //It was chosen poorly by trial and error.
51
52 //! Delay for a count.
53 void delay(unsigned int count){
54   volatile unsigned int i=count;
55   while(i--) asm("nop");
56 }
57 //! MSDelay
58 void msdelay(unsigned int ms){
59   volatile unsigned int i,j;
60   i=100;
61   while(i--){
62     j=ms;
63     while(j--) asm("nop");
64   }
65   //Using TimerA might be cleaner.
66 }