From a9bc033bdd5bad5dcba73c55ee337bade1540d6a Mon Sep 17 00:00:00 2001 From: bushing Date: Fri, 1 Jan 2010 23:36:17 +0000 Subject: [PATCH 1/1] create Dbprintf convenience function --- armsrc/appmain.c | 18 ++++++++++++++++++ armsrc/apps.h | 2 ++ armsrc/lfops.c | 24 ++++++------------------ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 11047b1c..8d6c1812 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -14,6 +14,12 @@ #include "LCD.h" #endif +#define va_list __builtin_va_list +#define va_start __builtin_va_start +#define va_arg __builtin_va_arg +#define va_end __builtin_va_end +int kvsprintf(char const *fmt, void *arg, int radix, va_list ap); + //============================================================================= // A buffer where we can queue things up to be sent through the FPGA, for // any purpose (fake tag, as reader, whatever). We go MSB first, since that @@ -94,6 +100,18 @@ void DbpIntegers(int x1, int x2, int x3) SpinDelay(50); } +void Dbprintf(const char *fmt, ...) { +// should probably limit size here; oh well, let's just use a big buffer + char output_string[128]; + va_list ap; + + va_start(ap, fmt); + kvsprintf(fmt, output_string, 10, ap); + va_end(ap); + + DbpString(output_string); +} + //----------------------------------------------------------------------------- // Read an ADC channel and block till it completes, then return the result // in ADC units (0 to 1023). Also a routine to average 32 samples and diff --git a/armsrc/apps.h b/armsrc/apps.h index fba62365..b15ae6ad 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -21,6 +21,8 @@ void __attribute__((noreturn)) AppMain(void); void SamyRun(void); void DbpIntegers(int a, int b, int c); void DbpString(char *str); +void Dbprintf(const char *fmt, ...); + void ToSendStuffBit(int b); void ToSendReset(void); void ListenReaderField(int limit); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index eeaa5782..7ba0ad13 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -39,7 +39,6 @@ void DoAcquisition125k(void) BYTE *dest = (BYTE *)BigBuf; int n = sizeof(BigBuf); int i; - char output_string[64]; memset(dest, 0, n); i = 0; @@ -55,9 +54,7 @@ void DoAcquisition125k(void) if (i >= n) break; } } - sprintf(output_string, "read samples, dest[0]=%x dest[1]=%x", - dest[0], dest[1]); - DbpString(output_string); + Dbprintf("read samples, dest[0]=%x dest[1]=%x", dest[0], dest[1]); } void ModThenAcquireRawAdcSamples125k(int delay_off, int period_0, int period_1, BYTE *command) @@ -251,13 +248,10 @@ void ReadTItag(void) crc = update_crc16(crc, (shift1>>16)&0xff); crc = update_crc16(crc, (shift1>>24)&0xff); - char output_string[64]; - sprintf(output_string, "Info: Tag data_hi=%x, data_lo=%x, crc=%x", + Dbprintf("Info: Tag data_hi=%x, data_lo=%x, crc=%x", (unsigned int)shift1, (unsigned int)shift0, (unsigned int)shift2 & 0xFFFF); - DbpString(output_string); if (crc != (shift2&0xffff)) { - sprintf(output_string, "Error: CRC mismatch, expected %x", (unsigned int)crc); - DbpString(output_string); + Dbprintf("Error: CRC mismatch, expected %x", (unsigned int)crc); } else { DbpString("Info: CRC is good"); } @@ -380,10 +374,8 @@ void WriteTItag(DWORD idhi, DWORD idlo, WORD crc) crc = update_crc16(crc, (idhi>>16)&0xff); crc = update_crc16(crc, (idhi>>24)&0xff); } - char output_string[64]; - sprintf(output_string, "Writing the following data to tag: %x, %x, %x", + Dbprintf("Writing the following data to tag: %x, %x, %x", (unsigned int) idhi, (unsigned int) idlo, crc); - DbpString(output_string); // TI tags charge at 134.2Khz FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz @@ -927,10 +919,8 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol) found=1; idx+=6; if (found && (hi|lo)) { - char output_string[64]; - sprintf(output_string, "TAG ID: %x %x %x", + Dbprintf("TAG ID: %x %x %x", (unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF); - DbpString(output_string); /* if we're only looking for one tag */ if (findone) { @@ -962,10 +952,8 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol) found=1; idx+=6; if (found && (hi|lo)) { - char output_string[64]; - sprintf(output_string, "TAG ID: %x %x %x", + Dbprintf("TAG ID: %x %x %x", (unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF); - DbpString(output_string); /* if we're only looking for one tag */ if (findone) { -- 2.39.5