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