X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Flib%2Fcommand.c;h=d984fca791feb33f357e38223acde6d73d0bd090;hp=c9c1b1cbbbc7a523906598fe0e72b089a062dc74;hb=f4a6b415e762bcdc560f3ea655851d16f483ea5a;hpb=6a87a627534bd71abda0c446269dd03c5cad4a42 diff --git a/firmware/lib/command.c b/firmware/lib/command.c index c9c1b1c..d984fca 100644 --- a/firmware/lib/command.c +++ b/firmware/lib/command.c @@ -1,16 +1,108 @@ -//! Different command handling functions. +/*! \file command.c + \author Travis Goodspeed + \brief These functions manage command interpretation. +*/ -unsigned char cmddata[256]; +#include "command.h" +#include "platform.h" +#include -//!Transmit data. -void txdata(unsigned char app, +unsigned char cmddata[CMDDATALEN]; +unsigned char silent=0; + +//! Transmit a string. +void txstring(unsigned char app, + unsigned char verb, + const char *str){ + unsigned long len=strlen(str); + txhead(app,verb,len); + while(len--) + serial_tx(*(str++)); +} + +/*! \brief Transmit a debug string. + + Transmits a debugging string that is to be printed + out of line by the client. This is just for record-keeping; + it is not considered a proper reply to a query. + */ +void debugstr(const char *str){ + txstring(0xFF,0xFF,str); +} + +//! Transmit a header. +void txhead(unsigned char app, unsigned char verb, - unsigned char len){ - unsigned int i=0; + unsigned long len){ serial_tx(app); serial_tx(verb); - serial_tx(len); + //serial_tx(len); + txword(len); +} + +//! Transmit data. +void txdata(unsigned char app, + unsigned char verb, + unsigned long len){ + unsigned int i=0; + if(silent) + return; + txhead(app,verb,len); for(i=0;i>=8; + serial_tx(l&0xFF); + l>>=8; + serial_tx(l&0xFF); + l>>=8; + serial_tx(l&0xFF); + l>>=8; +} +//! Transmit a word. +void txword(unsigned int l){ + serial_tx(l&0xFF); + l>>=8; + serial_tx(l&0xFF); + l>>=8; +} + +//Be very careful changing delay(). +//It was chosen poorly by trial and error. + +//! Delay for a count. +void delay(unsigned int count){ + volatile unsigned int i=count; + while(i--) asm("nop"); +} +//! MSDelay +void msdelay(unsigned int ms){ + volatile unsigned int i,j; + i=100; + while(i--){ + j=ms; + while(j--) asm("nop"); + } + //Using TimerA might be cleaner. +}