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.

This commit is contained in:
Gregory Nutt 2018-03-03 15:20:21 -06:00
parent d1b31d536a
commit b4f2b0dfc6
11 changed files with 107 additions and 94 deletions

View File

@ -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;

View File

@ -45,7 +45,6 @@
#include <stdint.h>
#include <errno.h>
#include <debug.h>
#include <stdio.h>
#include <nuttx/timers/watchdog.h>
@ -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)

View File

@ -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;
}

View File

@ -42,7 +42,6 @@
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
@ -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 "

View File

@ -41,7 +41,6 @@
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
@ -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 "

View File

@ -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 <raiden00@railab.me>
*
* Redistribution and use in source and binary forms, with or without
@ -39,19 +39,18 @@
#include <nuttx/config.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/boardctl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <debug.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/boardctl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <nuttx/board.h>
#include <nuttx/fs/fs.h>
@ -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;
}

View File

@ -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 <raiden00@railab.me>
*
* Redistribution and use in source and binary forms, with or without
@ -39,16 +39,15 @@
#include <nuttx/config.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <debug.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <debug.h>
#include <sys/boardctl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
@ -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;
}

View File

@ -44,9 +44,9 @@
#include <nuttx/config.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
@ -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

View File

@ -42,12 +42,13 @@
****************************************************************************/
#include <nuttx/config.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/kmalloc.h>
#include <nuttx/signal.h>

View File

@ -51,12 +51,13 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
#include <crc8.h>
#include <crc16.h>
#include <crc32.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
@ -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;
}

View File

@ -46,7 +46,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <semaphore.h>
@ -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;
}