Silence support and beginnings of proper buffer management.
[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 unsigned char silent=0;
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   if(silent)
42     return;
43   serial_tx(app);
44   serial_tx(verb);
45   serial_tx(len);
46   for(i=0;i<len;i++){
47     serial_tx(cmddata[i]);
48   }
49 }
50
51 //Be very careful changing delay().
52 //It was chosen poorly by trial and error.
53
54 //! Delay for a count.
55 void delay(unsigned int count){
56   volatile unsigned int i=count;
57   while(i--) asm("nop");
58 }
59 //! MSDelay
60 void msdelay(unsigned int ms){
61   volatile unsigned int i,j;
62   i=100;
63   while(i--){
64     j=ms;
65     while(j--) asm("nop");
66   }
67   //Using TimerA might be cleaner.
68 }