Moved header transmission to txhead, about to switch to 16-bit length field.
[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 //! Transmit a header.
36 void txhead(unsigned char app,
37             unsigned char verb,
38             unsigned int len){
39   serial_tx(app);
40   serial_tx(verb);
41   serial_tx(len);
42 }
43
44 //! Transmit data.
45 void txdata(unsigned char app,
46             unsigned char verb,
47             unsigned int len){
48   unsigned int i=0;
49   if(silent)
50     return;
51   txhead(app,verb,len);
52   for(i=0;i<len;i++){
53     serial_tx(cmddata[i]);
54   }
55 }
56
57 //Be very careful changing delay().
58 //It was chosen poorly by trial and error.
59
60 //! Delay for a count.
61 void delay(unsigned int count){
62   volatile unsigned int i=count;
63   while(i--) asm("nop");
64 }
65 //! MSDelay
66 void msdelay(unsigned int ms){
67   volatile unsigned int i,j;
68   i=100;
69   while(i--){
70     j=ms;
71     while(j--) asm("nop");
72   }
73   //Using TimerA might be cleaner.
74 }