From b4f2b0dfc6dae503494a30faf0080ca2e44924a3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 3 Mar 2018 15:20:21 -0600 Subject: [PATCH] Remove all usage of printf() from the OS. That is not an acceptable context for the use of an application-oriented interface that depends on a task-specific file descriptor and C buffered I/O. --- arch/arm/src/lc823450/lc823450_procfs_dvfs.c | 2 +- arch/arm/src/lc823450/lc823450_wdt.c | 5 +- arch/x86/src/qemu/qemu_keypad.c | 1 - configs/indium-f7/src/stm32_bbsram.c | 3 +- configs/nucleo-144/src/stm32_bbsram.c | 3 +- configs/stm32f334-disco/src/stm32_powerled.c | 42 +++++------ configs/stm32f334-disco/src/stm32_smps.c | 75 ++++++++++---------- configs/zkit-arm-1769/src/lpc17_appinit.c | 6 +- drivers/contactless/mfrc522.c | 9 +-- drivers/mtd/smart.c | 52 +++++++++----- fs/userfs/fs_userfs.c | 3 +- 11 files changed, 107 insertions(+), 94 deletions(-) diff --git a/arch/arm/src/lc823450/lc823450_procfs_dvfs.c b/arch/arm/src/lc823450/lc823450_procfs_dvfs.c index 3e085dcaea..b1e7cb6ab1 100644 --- a/arch/arm/src/lc823450/lc823450_procfs_dvfs.c +++ b/arch/arm/src/lc823450/lc823450_procfs_dvfs.c @@ -322,7 +322,7 @@ static ssize_t dvfs_write(FAR struct file *filep, FAR const char *buffer, } else { - printf("%s not supported.\n", cmd); + serr("ERROR: %s not supported.\n", cmd); } return buflen; diff --git a/arch/arm/src/lc823450/lc823450_wdt.c b/arch/arm/src/lc823450/lc823450_wdt.c index cdd351c095..e6722273f0 100644 --- a/arch/arm/src/lc823450/lc823450_wdt.c +++ b/arch/arm/src/lc823450/lc823450_wdt.c @@ -45,7 +45,6 @@ #include #include #include -#include #include @@ -550,7 +549,7 @@ int lc823450_wdt_initialize(void) #else if (getreg32(WDT_WT0RSTS) & (1 << WDT_WT0RSTS_RSTS)) { - printf("**** WATCHDOG RESET****\n"); + wdwarn("**** WATCHDOG RESET****\n"); } #endif @@ -578,7 +577,7 @@ void lc823450_wdt_work_enable(int en) if (getreg32(WDT_WT0RSTS) & (1 << WDT_WT0RSTS_RSTS)) { - printf("**** WATCHDOG RESET****\n"); + wdwarn("**** WATCHDOG RESET****\n"); } if (getreg32(LOCKUPR) & LOCKUPR_LOCKUPR0) diff --git a/arch/x86/src/qemu/qemu_keypad.c b/arch/x86/src/qemu/qemu_keypad.c index 5efd1f5b07..dc5286400a 100644 --- a/arch/x86/src/qemu/qemu_keypad.c +++ b/arch/x86/src/qemu/qemu_keypad.c @@ -296,7 +296,6 @@ static ssize_t keypad_read(struct file *filep, FAR char *buf, size_t buflen) if ((scancode & 0x80) == 0) { keycode = g_kdbus[scancode]; - //printf("%02x ",scancode); buf[0] = keycode; return 1; } diff --git a/configs/indium-f7/src/stm32_bbsram.c b/configs/indium-f7/src/stm32_bbsram.c index df2bafcc08..38809c6b87 100644 --- a/configs/indium-f7/src/stm32_bbsram.c +++ b/configs/indium-f7/src/stm32_bbsram.c @@ -42,7 +42,6 @@ #include -#include #include #include #include @@ -364,7 +363,7 @@ int stm32_bbsram_int(void) rv = hardfault_get_desc(&desc); if (rv >= OK) { - printf("There is a hard fault logged.\n"); + _err("ERROR: There is a hard fault logged.\n"); state = (desc.lastwrite.tv_sec || desc.lastwrite.tv_nsec) ? OK : 1; syslog(LOG_INFO, "Fault Log info File No %d Length %d flags:0x%02x " diff --git a/configs/nucleo-144/src/stm32_bbsram.c b/configs/nucleo-144/src/stm32_bbsram.c index 085ee18249..cb1608c773 100644 --- a/configs/nucleo-144/src/stm32_bbsram.c +++ b/configs/nucleo-144/src/stm32_bbsram.c @@ -41,7 +41,6 @@ #include -#include #include #include #include @@ -363,7 +362,7 @@ int stm32_bbsram_int(void) rv = hardfault_get_desc(&desc); if (rv >= OK) { - printf("There is a hard fault logged.\n"); + _err("There is a hard fault logged.\n"); state = (desc.lastwrite.tv_sec || desc.lastwrite.tv_nsec) ? OK : 1; syslog(LOG_INFO, "Fault Log info File No %d Length %d flags:0x%02x " diff --git a/configs/stm32f334-disco/src/stm32_powerled.c b/configs/stm32f334-disco/src/stm32_powerled.c index f342e71b0a..c199786308 100644 --- a/configs/stm32f334-disco/src/stm32_powerled.c +++ b/configs/stm32f334-disco/src/stm32_powerled.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32f334-disco/src/stm32_powerled.c * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2017, 2018 Gregory Nutt. All rights reserved. * Author: Mateusz Szafoni * * Redistribution and use in source and binary forms, with or without @@ -39,19 +39,18 @@ #include -#include +#include +#include +#include #include -#include +#include +#include +#include #include +#include #include #include -#include -#include -#include -#include -#include -#include #include #include @@ -258,19 +257,19 @@ static int powerled_setup(FAR struct powerled_dev_s *dev) hrtim = lower->hrtim; if (hrtim == NULL) { - printf("ERROR: failed to get hrtim "); + pwrerr("ERROR: failed to get hrtim "); } comp = lower->comp; if (comp == NULL) { - printf("ERROR: failed to get lower level interface"); + pwrerr("ERROR: failed to get lower level interface"); } dac = lower->dac; if (dac == NULL) { - printf("ERROR: failed to get lower level interface"); + pwrerr("ERROR: failed to get lower level interface"); } /* Do nothing */ @@ -465,7 +464,7 @@ static int powerled_mode_set(FAR struct powerled_dev_s *dev, uint8_t mode) default: { - printf("ERROR: unsupported POWERLED mode %d!\n", mode); + pwrerr("ERROR: unsupported POWERLED mode %d!\n", mode); ret = ERROR; goto errout; } @@ -485,7 +484,7 @@ static int powerled_limits_set(FAR struct powerled_dev_s *dev, if (limits->current <= 0) { - printf("Output current limit must be set!\n"); + pwrerr("ERROR: Output current limit must be set!\n"); ret = ERROR; goto errout; } @@ -493,9 +492,10 @@ static int powerled_limits_set(FAR struct powerled_dev_s *dev, if (limits->current * 1000 > LED_ABSOLUTE_CURRENT_LIMIT_mA) { limits->current = (float)LED_ABSOLUTE_CURRENT_LIMIT_mA/1000.0; - printf("LED current limiit > LED absoulute current limit." - " Set current limit to %d.\n", - limits->current); + pwrwarn("WARNING: " + "LED current limiit > LED absoulute current limit." + " Set current limit to %d.\n", + limits->current); } /* We need only output current */ @@ -584,7 +584,7 @@ int stm32_powerled_setup(void) hrtim = stm32_hrtiminitialize(); if (hrtim == NULL) { - printf("ERROR: Failed to get HRTIM1 interface\n"); + pwrerr("ERROR: Failed to get HRTIM1 interface\n"); return -ENODEV; } @@ -593,7 +593,7 @@ int stm32_powerled_setup(void) dac = stm32_dacinitialize(DAC_CURRENT_LIMIT); if (dac == NULL) { - printf("ERROR: Failed to get DAC %d interface\n", DAC_CURRENT_LIMIT); + pwrerr("ERROR: Failed to get DAC %d interface\n", DAC_CURRENT_LIMIT); return -ENODEV; } @@ -602,7 +602,7 @@ int stm32_powerled_setup(void) comp = stm32_compinitialize(COMP_CURRENT_LIMIT); if (comp == NULL) { - printf("ERROR: Failed to get COMP %d interface\n", + pwrerr("ERROR: Failed to get COMP %d interface\n", COMP_CURRENT_LIMIT); return -ENODEV; } @@ -623,7 +623,7 @@ int stm32_powerled_setup(void) (void *)lower); if (ret < 0) { - printf("ERROR: powerled_register failed: %d\n", ret); + pwrerr("ERROR: powerled_register failed: %d\n", ret); return ret; } diff --git a/configs/stm32f334-disco/src/stm32_smps.c b/configs/stm32f334-disco/src/stm32_smps.c index 12f85667b1..ebaf30cd11 100644 --- a/configs/stm32f334-disco/src/stm32_smps.c +++ b/configs/stm32f334-disco/src/stm32_smps.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32f334-disco/src/stm32_smps.c * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2017, 2018 Gregory Nutt. All rights reserved. * Author: Mateusz Szafoni * * Redistribution and use in source and binary forms, with or without @@ -39,16 +39,15 @@ #include -#include #include -#include -#include -#include - -#include -#include #include #include +#include +#include +#include +#include +#include + #include #include #include @@ -372,13 +371,13 @@ static int smps_setup(FAR struct smps_dev_s *dev) hrtim = lower->hrtim; if (hrtim == NULL) { - printf("ERROR: failed to get hrtim "); + pwrerr("ERROR: failed to get hrtim "); } adc = lower->adc; if (adc == NULL) { - printf("ERROR: failed to get ADC lower level interface"); + pwrerr("ERROR: failed to get ADC lower level interface"); } /* TODO: create current limit table */ @@ -413,7 +412,7 @@ static int smps_start(FAR struct smps_dev_s *dev) per = fclk/TIMA_PWM_FREQ; if (per > HRTIM_PER_MAX) { - printf("ERROR: can not achieve tima pwm freq=%u if fclk=%llu\n", + pwrerr("ERROR: can not achieve tima pwm freq=%u if fclk=%llu\n", (uint32_t)TIMA_PWM_FREQ, (uint64_t)fclk); ret = -EINVAL; goto errout; @@ -429,7 +428,7 @@ static int smps_start(FAR struct smps_dev_s *dev) per = fclk/TIMB_PWM_FREQ; if (per > HRTIM_PER_MAX) { - printf("ERROR: can not achieve timb pwm freq=%u if fclk=%llu\n", + pwrerr("ERROR: can not achieve timb pwm freq=%u if fclk=%llu\n", (uint32_t)TIMB_PWM_FREQ, (uint64_t)fclk); ret = -EINVAL; goto errout; @@ -516,12 +515,12 @@ static int smps_params_set(FAR struct smps_dev_s *dev, if (param->i_out > 0) { - printf("WARNING: Output current parameters not used in this demo\n"); + pwrwarn("WARNING: Output current parameters not used in this demo\n"); } if (param->p_out > 0) { - printf("WARNING: Output power parameters not used in this demo\n"); + pwrwarn("WARNING: Output power parameters not used in this demo\n"); } return ret; @@ -540,7 +539,7 @@ static int smps_mode_set(FAR struct smps_dev_s *dev, uint8_t mode) } else { - printf("ERROR: unsupported SMPS mode %d!\n", mode); + pwrerr("ERROR: unsupported SMPS mode %d!\n", mode); ret = ERROR; goto errout; } @@ -559,21 +558,21 @@ static int smps_limits_set(FAR struct smps_dev_s *dev, if (limits->v_out <= 0) { - printf("Output voltage limit must be set!\n"); + pwrerr("ERROR: Output voltage limit must be set!\n"); ret = ERROR; goto errout; } if (limits->v_in <= 0) { - printf("Input voltage limit must be set!\n"); + pwrerr("ERROR: Input voltage limit must be set!\n"); ret = ERROR; goto errout; } if (limits->i_out <= 0) { - printf("Output current limit must be set!\n"); + pwrerr("ERROR: Output current limit must be set!\n"); ret = ERROR; goto errout; } @@ -581,25 +580,28 @@ static int smps_limits_set(FAR struct smps_dev_s *dev, if (limits->v_out * 1000 > CONFIG_EXAMPLES_SMPS_OUT_VOLTAGE_LIMIT) { limits->v_out = (float)CONFIG_EXAMPLES_SMPS_OUT_VOLTAGE_LIMIT/1000.0; - printf("SMPS output voltage limiit > SMPS absoulute output voltage limit." - " Set output voltage limit to %.2f.\n", - limits->v_out); + pwrwarn("WARNING: " + "SMPS output voltage limiit > SMPS absoulute output voltage limit." + " Set output voltage limit to %.2f.\n", + limits->v_out); } if (limits->v_in * 1000 > CONFIG_EXAMPLES_SMPS_IN_VOLTAGE_LIMIT) { limits->v_in = (float)CONFIG_EXAMPLES_SMPS_IN_VOLTAGE_LIMIT/1000.0; - printf("SMPS input voltage limiit > SMPS absoulute input voltage limit." - " Set input voltage limit to %.2f.\n", - limits->v_in); + pwrwarn("WARNING: " + "SMPS input voltage limiit > SMPS absoulute input voltage limit." + " Set input voltage limit to %.2f.\n", + limits->v_in); } if (limits->i_out * 1000 > CONFIG_EXAMPLES_SMPS_OUT_CURRENT_LIMIT) { limits->i_out = (float)CONFIG_EXAMPLES_SMPS_OUT_CURRENT_LIMIT/1000.0; - printf("SMPS output current limiit > SMPS absoulute output current limit." - " Set output current limit to %.2f.\n", - limits->i_out); + pwrwarn("WARNING: " + "SMPS output current limiit > SMPS absoulute output current limit." + " Set output current limit to %.2f.\n", + limits->i_out); } /* Set output voltage limit */ @@ -790,7 +792,7 @@ static void smps_duty_set(struct smps_priv_s *priv, struct smps_lower_dev_s *low default: { - printf("ERROR: unknown converter mode %d!\n", mode); + pwrerr("ERROR: unknown converter mode %d!\n", mode); break; } } @@ -882,7 +884,7 @@ static void smps_conv_mode_set(struct smps_priv_s *priv, struct smps_lower_dev_s default: { - printf("ERROR: unknown converter mode %d!\n", mode); + pwrerr("ERROR: unknown converter mode %d!\n", mode); break; } } @@ -1017,7 +1019,7 @@ int stm32_smps_setup(void) hrtim = stm32_hrtiminitialize(); if (hrtim == NULL) { - printf("ERROR: Failed to get HRTIM1 interface\n"); + pwrerr("ERROR: Failed to get HRTIM1 interface\n"); return -ENODEV; } @@ -1033,7 +1035,7 @@ int stm32_smps_setup(void) adc = stm32_adcinitialize(1, g_adc1chan, ADC1_NCHANNELS); if (adc == NULL) { - printf("ERROR: Failed to get ADC %d interface\n", 1); + pwrerr("ERROR: Failed to get ADC %d interface\n", 1); return -ENODEV; } @@ -1050,8 +1052,8 @@ int stm32_smps_setup(void) ret = up_ramvec_attach(STM32_IRQ_ADC12, adc12_handler); if (ret < 0) { - fprintf(stderr, "highpri_main: ERROR: up_ramvec_attach failed: %d\n", - ret); + pwrerr("ERROR: highpri_main: ERROR: up_ramvec_attach failed: %d\n", + ret); ret = EXIT_FAILURE; goto errout; } @@ -1061,8 +1063,9 @@ int stm32_smps_setup(void) ret = up_prioritize_irq(STM32_IRQ_ADC12, NVIC_SYSH_HIGH_PRIORITY); if (ret < 0) { - fprintf(stderr, - "highpri_main: ERROR: up_prioritize_irq failed: %d\n", ret); + pwrerr("ERROR: "" + "highpri_main: ERROR: up_prioritize_irq failed: %d\n", + ret); ret = EXIT_FAILURE; goto errout; } @@ -1080,7 +1083,7 @@ int stm32_smps_setup(void) ret = smps_register(CONFIG_EXAMPLES_SMPS_DEVPATH, smps, (void *)lower); if (ret < 0) { - printf("ERROR: smps_register failed: %d\n", ret); + pwrerr("ERROR: smps_register failed: %d\n", ret); return ret; } diff --git a/configs/zkit-arm-1769/src/lpc17_appinit.c b/configs/zkit-arm-1769/src/lpc17_appinit.c index d6e80895fd..25fd062dfb 100644 --- a/configs/zkit-arm-1769/src/lpc17_appinit.c +++ b/configs/zkit-arm-1769/src/lpc17_appinit.c @@ -44,9 +44,9 @@ #include -#include #include #include +#include #include #include @@ -120,13 +120,13 @@ # ifdef CONFIG_DEBUG_INFO # define message(...) _info(__VA_ARGS__) # else -# define message(...) printf(__VA_ARGS__) +# define message(...) _err(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG_INFO # define message _info # else -# define message printf +# define message _err # endif #endif diff --git a/drivers/contactless/mfrc522.c b/drivers/contactless/mfrc522.c index ccd82ceab4..c415b239fc 100644 --- a/drivers/contactless/mfrc522.c +++ b/drivers/contactless/mfrc522.c @@ -42,12 +42,13 @@ ****************************************************************************/ #include -#include + #include -#include -#include -#include #include +#include +#include +#include +#include #include #include diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index c07edc4b28..b7cc6a40e7 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -51,12 +51,13 @@ #include #include #include -#include #include #include #include #include +#include + #include #include #include @@ -3476,10 +3477,11 @@ static int smart_findfreephyssector(FAR struct smart_struct_s *dev, uint8_t maxwearlevel; #endif uint16_t physicalsector; - uint16_t x, block; + uint16_t block; uint32_t readaddr; struct smart_sect_header_s header; int ret; + uint16_t i; /* Determine which erase block we should allocate the new * sector from. This is based on the number of free sectors @@ -3504,7 +3506,7 @@ retry: } block = dev->lastallocblock; - for (x = 0; x < dev->neraseblocks; x++) + for (i = 0; i < dev->neraseblocks; i++) { /* Test if this block has more free blocks than the * currently selected block @@ -3533,7 +3535,7 @@ retry: * free sectors left, then we will use it. */ - if (x < dev->neraseblocks - 1 || !wornfreecount) + if (i < dev->neraseblocks - 1 || !wornfreecount) { wornfreecount = count; wornblock = block; @@ -3548,7 +3550,7 @@ retry: { /* Assign this block to alloc from */ - if (x < dev->neraseblocks - 1 || !allocfreecount) + if (i < dev->neraseblocks - 1 || !allocfreecount) { allocblock = block; allocfreecount = count; @@ -3576,7 +3578,7 @@ retry: /* Relocate up to 8 unworn blocks */ block = 0; - for (x = 0; x < 8; ) + for (i = 0; i < 8; ) { if (smart_get_wear_level(dev, block) < SMART_WEAR_FORCE_REORG_THRESHOLD) { @@ -3586,13 +3588,13 @@ retry: return -1; } - x++; + i++; } block++; } - if (x > 0) + if (i > 0) { /* Disable relocate for retry */ @@ -3615,25 +3617,37 @@ retry: #endif { - 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 */ + char buffer[8 * 12 + 1]; + long remaining; + int j; + int k; - printf("%d ", dev->freecount[x]); + ferr("ERROR: Program bug! Expected a free sector, free=%d\n", + dev->freesectors); + + for (i = 0, remaining = dev->neraseblock; + remaining > 0; + i += 8, remaining -= 8) + { + for (j = 0, k = 0; j < 8 && j < remaining ; j++) + { + k += sprintf(&buffer[k], "%12d", dev->freecount[i + j]); + } + + ferr("%04x:%s\n", i, buffer); } /* No free sectors found! Bug? */ - return -1; + return -ENOSPC; } } /* Now find a free physical sector within this selected * erase block to allocate. */ - for (x = allocblock * dev->sectorsPerBlk; - x < allocblock * dev->sectorsPerBlk + dev->availSectPerBlk; x++) + for (i = allocblock * dev->sectorsPerBlk; + i < allocblock * dev->sectorsPerBlk + dev->availSectPerBlk; i++) { /* Check if this physical sector is available. */ @@ -3645,7 +3659,7 @@ retry: while (allocsect) { - if (allocsect->physical == x) + if (allocsect->physical == i) { break; } @@ -3666,7 +3680,7 @@ retry: /* Now check on the physical media */ - readaddr = x * dev->mtdBlksPerSector * dev->geo.blocksize; + readaddr = i * dev->mtdBlksPerSector * dev->geo.blocksize; ret = MTD_READ(dev->mtd, readaddr, sizeof(struct smart_sect_header_s), (FAR uint8_t *) &header); if (ret != sizeof(struct smart_sect_header_s)) @@ -3684,7 +3698,7 @@ retry: ((header.status & SMART_STATUS_COMMITTED) == (CONFIG_SMARTFS_ERASEDSTATE & SMART_STATUS_COMMITTED))) { - physicalsector = x; + physicalsector = i; dev->lastallocblock = allocblock; break; } diff --git a/fs/userfs/fs_userfs.c b/fs/userfs/fs_userfs.c index 3cb7a10b21..45ff7f663c 100644 --- a/fs/userfs/fs_userfs.c +++ b/fs/userfs/fs_userfs.c @@ -46,7 +46,6 @@ #include #include -#include #include #include #include @@ -1366,7 +1365,7 @@ static int userfs_bind(FAR struct inode *blkdriver, FAR const void *data, ret = psock_socket(PF_INET, SOCK_DGRAM, 0, &priv->psock); if (ret < 0) { - printf("client: ERROR socket failure %d\n", ret); + ferr("ERROR: socket() failed: %d\n", ret); goto errout_with_alloc; }