From d1b31d536a8fcb6e5ed556398a9bdbc62c291a3f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 3 Mar 2018 12:59:48 -0600 Subject: [PATCH] Eliminate a couple more uses of printf() within the OS. There are several more. --- drivers/contactless/mfrc522.c | 18 +++++--- drivers/mtd/smart.c | 2 + drivers/wireless/cc1101.c | 43 +++++++++++-------- .../wireless/ieee802154/at86rf23x/at86rf23x.c | 14 +++--- 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/drivers/contactless/mfrc522.c b/drivers/contactless/mfrc522.c index 849f759b67..ccd82ceab4 100644 --- a/drivers/contactless/mfrc522.c +++ b/drivers/contactless/mfrc522.c @@ -1285,13 +1285,16 @@ void mfrc522_init(FAR struct mfrc522_dev_s *dev) int mfrc522_selftest(FAR struct mfrc522_dev_s *dev) { - uint8_t i; - uint8_t result[64]; uint8_t zeros[25] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + char outbuf[3 * 8 + 1] + uint8_t result[64]; + int i; + int j; + int k; /* Execute a software reset */ @@ -1347,14 +1350,15 @@ int mfrc522_selftest(FAR struct mfrc522_dev_s *dev) mfrc522_writeu8(dev, MFRC522_AUTOTEST_REG, 0x00); mfrc522info("Self Test Result:\n"); - for (i = 1; i <= 64; i++) - { - printf("0x%02X ", result[i - 1]); - if ((i % 8) == 0) + for (i = 0; i < 64; i += 8) + { + for (j = 0; k = 0; j < 8; j++, k += 3) { - printf("\n"); + (void)sprintf(&outbuf[k], " %02x", result[i + j]); } + + mfrc522info(" %02x:%s\n", i, outbuf); } mfrc522info("Done!\n"); diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index 02bae30d6f..c07edc4b28 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -3618,6 +3618,8 @@ retry: ferr("ERROR: Program bug! Expected a free sector, free=%d\n", dev->freesectors); for (x = 0; x < dev->neraseblocks; x++) { + /* REVISIT: Use of printf is not permitted within the OS */ + printf("%d ", dev->freecount[x]); } diff --git a/drivers/wireless/cc1101.c b/drivers/wireless/cc1101.c index e481470b32..7ed3d777cb 100644 --- a/drivers/wireless/cc1101.c +++ b/drivers/wireless/cc1101.c @@ -900,33 +900,42 @@ int cc1101_checkpart(struct cc1101_dev_s *dev) * Description: * Dump the specified range of registers to the syslog. * - * WARNING: Uses around 200 bytes of stack! + * WARNING: Uses around 75 bytes of stack! * ****************************************************************************/ void cc1101_dumpregs(struct cc1101_dev_s *dev, uint8_t addr, uint8_t length) { - char outbuf[3 * 48]; - uint8_t regbuf[48]; + char outbuf[3 * 16 + 1]; + uint8_t regbuf[16]; + int readsize; + int remaining; int i; int j; - DEBUGASSERT(length < 48); - - /* Read the registers into a buffer */ - - cc1101_access(dev, addr, (FAR uint8_t *)regbuf, length); - - /* Format the output data */ - - for (i = 0, j = 0; i < length; i++, j += 3) + for (remaining = length; remaining > 0; remaining -= 16, addr += 16) { - (void)sprintf(&outbuf[j], "%02x ", regbuf[i]); + /* Read up to 16 registers into a buffer */ + + readsize = remaining; + if (readsize > 16) + { + readsize = 16; + } + + cc1101_access(dev, addr, (FAR uint8_t *)regbuf, readsize); + + /* Format the output data */ + + for (i = 0, j = 0; i < readsize; i++, j += 3) + { + (void)sprintf(&outbuf[j], " %02x", regbuf[i]); + } + + /* Dump the formatted data to the syslog output */ + + wlinfo("CC1101[%2x]:%s\n", addr, outbuf); } - - /* Dump the formatted data to the syslog output */ - - wlinfo("CC1101[%2x]: %s\n", addr, outbuf); } /**************************************************************************** diff --git a/drivers/wireless/ieee802154/at86rf23x/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x/at86rf23x.c index ba6486d8b4..cfd5dd0488 100644 --- a/drivers/wireless/ieee802154/at86rf23x/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x/at86rf23x.c @@ -1288,18 +1288,18 @@ static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg) static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev) { uint32_t i; - char buf[4+16*3+2+1]; + char buf[4 + 16 * 3 + 2 + 1]; int len=0; - printf("RF23X regs:\n"); + wlinfo("RF23X regs:\n"); - for (i=0;i<0x30;i++) + for (i = 0; i < 0x30; i++) { /* First row and every 15 regs */ if ((i & 0x0f) == 0) { - len = sprintf(buf, "%02x: ",i&0xFF); + len = sprintf(buf, "%02x: ", i & 0xFF); } /* Print the register value */ @@ -1310,10 +1310,10 @@ static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev) * debug message. */ - if ((i&15) == 15 || i == 0x2f) + if ((i & 15) == 15 || i == 0x2f) { - sprintf(buf+len, "\n"); - printf("%s",buf); + sprintf(buf + len, "\n"); + wlinfo("%s" ,buf);q } }