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
+1 -1
View File
@@ -322,7 +322,7 @@ static ssize_t dvfs_write(FAR struct file *filep, FAR const char *buffer,
} }
else else
{ {
printf("%s not supported.\n", cmd); serr("ERROR: %s not supported.\n", cmd);
} }
return buflen; return buflen;
+2 -3
View File
@@ -45,7 +45,6 @@
#include <stdint.h> #include <stdint.h>
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
#include <stdio.h>
#include <nuttx/timers/watchdog.h> #include <nuttx/timers/watchdog.h>
@@ -550,7 +549,7 @@ int lc823450_wdt_initialize(void)
#else #else
if (getreg32(WDT_WT0RSTS) & (1 << WDT_WT0RSTS_RSTS)) if (getreg32(WDT_WT0RSTS) & (1 << WDT_WT0RSTS_RSTS))
{ {
printf("**** WATCHDOG RESET****\n"); wdwarn("**** WATCHDOG RESET****\n");
} }
#endif #endif
@@ -578,7 +577,7 @@ void lc823450_wdt_work_enable(int en)
if (getreg32(WDT_WT0RSTS) & (1 << WDT_WT0RSTS_RSTS)) if (getreg32(WDT_WT0RSTS) & (1 << WDT_WT0RSTS_RSTS))
{ {
printf("**** WATCHDOG RESET****\n"); wdwarn("**** WATCHDOG RESET****\n");
} }
if (getreg32(LOCKUPR) & LOCKUPR_LOCKUPR0) if (getreg32(LOCKUPR) & LOCKUPR_LOCKUPR0)
-1
View File
@@ -296,7 +296,6 @@ static ssize_t keypad_read(struct file *filep, FAR char *buf, size_t buflen)
if ((scancode & 0x80) == 0) if ((scancode & 0x80) == 0)
{ {
keycode = g_kdbus[scancode]; keycode = g_kdbus[scancode];
//printf("%02x ",scancode);
buf[0] = keycode; buf[0] = keycode;
return 1; return 1;
} }
+1 -2
View File
@@ -42,7 +42,6 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@@ -364,7 +363,7 @@ int stm32_bbsram_int(void)
rv = hardfault_get_desc(&desc); rv = hardfault_get_desc(&desc);
if (rv >= OK) 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; 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 " syslog(LOG_INFO, "Fault Log info File No %d Length %d flags:0x%02x "
+1 -2
View File
@@ -41,7 +41,6 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@@ -363,7 +362,7 @@ int stm32_bbsram_int(void)
rv = hardfault_get_desc(&desc); rv = hardfault_get_desc(&desc);
if (rv >= OK) 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; 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 " syslog(LOG_INFO, "Fault Log info File No %d Length %d flags:0x%02x "
+21 -21
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/stm32f334-disco/src/stm32_powerled.c * 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> * Author: Mateusz Szafoni <raiden00@railab.me>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -39,19 +39,18 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <fcntl.h> #include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/boardctl.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <debug.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/board.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
@@ -258,19 +257,19 @@ static int powerled_setup(FAR struct powerled_dev_s *dev)
hrtim = lower->hrtim; hrtim = lower->hrtim;
if (hrtim == NULL) if (hrtim == NULL)
{ {
printf("ERROR: failed to get hrtim "); pwrerr("ERROR: failed to get hrtim ");
} }
comp = lower->comp; comp = lower->comp;
if (comp == NULL) if (comp == NULL)
{ {
printf("ERROR: failed to get lower level interface"); pwrerr("ERROR: failed to get lower level interface");
} }
dac = lower->dac; dac = lower->dac;
if (dac == NULL) if (dac == NULL)
{ {
printf("ERROR: failed to get lower level interface"); pwrerr("ERROR: failed to get lower level interface");
} }
/* Do nothing */ /* Do nothing */
@@ -465,7 +464,7 @@ static int powerled_mode_set(FAR struct powerled_dev_s *dev, uint8_t mode)
default: default:
{ {
printf("ERROR: unsupported POWERLED mode %d!\n", mode); pwrerr("ERROR: unsupported POWERLED mode %d!\n", mode);
ret = ERROR; ret = ERROR;
goto errout; goto errout;
} }
@@ -485,7 +484,7 @@ static int powerled_limits_set(FAR struct powerled_dev_s *dev,
if (limits->current <= 0) if (limits->current <= 0)
{ {
printf("Output current limit must be set!\n"); pwrerr("ERROR: Output current limit must be set!\n");
ret = ERROR; ret = ERROR;
goto errout; 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) if (limits->current * 1000 > LED_ABSOLUTE_CURRENT_LIMIT_mA)
{ {
limits->current = (float)LED_ABSOLUTE_CURRENT_LIMIT_mA/1000.0; limits->current = (float)LED_ABSOLUTE_CURRENT_LIMIT_mA/1000.0;
printf("LED current limiit > LED absoulute current limit." pwrwarn("WARNING: "
" Set current limit to %d.\n", "LED current limiit > LED absoulute current limit."
limits->current); " Set current limit to %d.\n",
limits->current);
} }
/* We need only output current */ /* We need only output current */
@@ -584,7 +584,7 @@ int stm32_powerled_setup(void)
hrtim = stm32_hrtiminitialize(); hrtim = stm32_hrtiminitialize();
if (hrtim == NULL) if (hrtim == NULL)
{ {
printf("ERROR: Failed to get HRTIM1 interface\n"); pwrerr("ERROR: Failed to get HRTIM1 interface\n");
return -ENODEV; return -ENODEV;
} }
@@ -593,7 +593,7 @@ int stm32_powerled_setup(void)
dac = stm32_dacinitialize(DAC_CURRENT_LIMIT); dac = stm32_dacinitialize(DAC_CURRENT_LIMIT);
if (dac == NULL) 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; return -ENODEV;
} }
@@ -602,7 +602,7 @@ int stm32_powerled_setup(void)
comp = stm32_compinitialize(COMP_CURRENT_LIMIT); comp = stm32_compinitialize(COMP_CURRENT_LIMIT);
if (comp == NULL) if (comp == NULL)
{ {
printf("ERROR: Failed to get COMP %d interface\n", pwrerr("ERROR: Failed to get COMP %d interface\n",
COMP_CURRENT_LIMIT); COMP_CURRENT_LIMIT);
return -ENODEV; return -ENODEV;
} }
@@ -623,7 +623,7 @@ int stm32_powerled_setup(void)
(void *)lower); (void *)lower);
if (ret < 0) if (ret < 0)
{ {
printf("ERROR: powerled_register failed: %d\n", ret); pwrerr("ERROR: powerled_register failed: %d\n", ret);
return ret; return ret;
} }
+39 -36
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/stm32f334-disco/src/stm32_smps.c * 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> * Author: Mateusz Szafoni <raiden00@railab.me>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -39,16 +39,15 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <fcntl.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <debug.h>
#include <errno.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.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/boardctl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/types.h> #include <sys/types.h>
@@ -372,13 +371,13 @@ static int smps_setup(FAR struct smps_dev_s *dev)
hrtim = lower->hrtim; hrtim = lower->hrtim;
if (hrtim == NULL) if (hrtim == NULL)
{ {
printf("ERROR: failed to get hrtim "); pwrerr("ERROR: failed to get hrtim ");
} }
adc = lower->adc; adc = lower->adc;
if (adc == NULL) 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 */ /* TODO: create current limit table */
@@ -413,7 +412,7 @@ static int smps_start(FAR struct smps_dev_s *dev)
per = fclk/TIMA_PWM_FREQ; per = fclk/TIMA_PWM_FREQ;
if (per > HRTIM_PER_MAX) 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); (uint32_t)TIMA_PWM_FREQ, (uint64_t)fclk);
ret = -EINVAL; ret = -EINVAL;
goto errout; goto errout;
@@ -429,7 +428,7 @@ static int smps_start(FAR struct smps_dev_s *dev)
per = fclk/TIMB_PWM_FREQ; per = fclk/TIMB_PWM_FREQ;
if (per > HRTIM_PER_MAX) 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); (uint32_t)TIMB_PWM_FREQ, (uint64_t)fclk);
ret = -EINVAL; ret = -EINVAL;
goto errout; goto errout;
@@ -516,12 +515,12 @@ static int smps_params_set(FAR struct smps_dev_s *dev,
if (param->i_out > 0) 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) 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; return ret;
@@ -540,7 +539,7 @@ static int smps_mode_set(FAR struct smps_dev_s *dev, uint8_t mode)
} }
else else
{ {
printf("ERROR: unsupported SMPS mode %d!\n", mode); pwrerr("ERROR: unsupported SMPS mode %d!\n", mode);
ret = ERROR; ret = ERROR;
goto errout; goto errout;
} }
@@ -559,21 +558,21 @@ static int smps_limits_set(FAR struct smps_dev_s *dev,
if (limits->v_out <= 0) if (limits->v_out <= 0)
{ {
printf("Output voltage limit must be set!\n"); pwrerr("ERROR: Output voltage limit must be set!\n");
ret = ERROR; ret = ERROR;
goto errout; goto errout;
} }
if (limits->v_in <= 0) if (limits->v_in <= 0)
{ {
printf("Input voltage limit must be set!\n"); pwrerr("ERROR: Input voltage limit must be set!\n");
ret = ERROR; ret = ERROR;
goto errout; goto errout;
} }
if (limits->i_out <= 0) if (limits->i_out <= 0)
{ {
printf("Output current limit must be set!\n"); pwrerr("ERROR: Output current limit must be set!\n");
ret = ERROR; ret = ERROR;
goto errout; 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) if (limits->v_out * 1000 > CONFIG_EXAMPLES_SMPS_OUT_VOLTAGE_LIMIT)
{ {
limits->v_out = (float)CONFIG_EXAMPLES_SMPS_OUT_VOLTAGE_LIMIT/1000.0; limits->v_out = (float)CONFIG_EXAMPLES_SMPS_OUT_VOLTAGE_LIMIT/1000.0;
printf("SMPS output voltage limiit > SMPS absoulute output voltage limit." pwrwarn("WARNING: "
" Set output voltage limit to %.2f.\n", "SMPS output voltage limiit > SMPS absoulute output voltage limit."
limits->v_out); " Set output voltage limit to %.2f.\n",
limits->v_out);
} }
if (limits->v_in * 1000 > CONFIG_EXAMPLES_SMPS_IN_VOLTAGE_LIMIT) if (limits->v_in * 1000 > CONFIG_EXAMPLES_SMPS_IN_VOLTAGE_LIMIT)
{ {
limits->v_in = (float)CONFIG_EXAMPLES_SMPS_IN_VOLTAGE_LIMIT/1000.0; limits->v_in = (float)CONFIG_EXAMPLES_SMPS_IN_VOLTAGE_LIMIT/1000.0;
printf("SMPS input voltage limiit > SMPS absoulute input voltage limit." pwrwarn("WARNING: "
" Set input voltage limit to %.2f.\n", "SMPS input voltage limiit > SMPS absoulute input voltage limit."
limits->v_in); " Set input voltage limit to %.2f.\n",
limits->v_in);
} }
if (limits->i_out * 1000 > CONFIG_EXAMPLES_SMPS_OUT_CURRENT_LIMIT) if (limits->i_out * 1000 > CONFIG_EXAMPLES_SMPS_OUT_CURRENT_LIMIT)
{ {
limits->i_out = (float)CONFIG_EXAMPLES_SMPS_OUT_CURRENT_LIMIT/1000.0; limits->i_out = (float)CONFIG_EXAMPLES_SMPS_OUT_CURRENT_LIMIT/1000.0;
printf("SMPS output current limiit > SMPS absoulute output current limit." pwrwarn("WARNING: "
" Set output current limit to %.2f.\n", "SMPS output current limiit > SMPS absoulute output current limit."
limits->i_out); " Set output current limit to %.2f.\n",
limits->i_out);
} }
/* Set output voltage limit */ /* 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: default:
{ {
printf("ERROR: unknown converter mode %d!\n", mode); pwrerr("ERROR: unknown converter mode %d!\n", mode);
break; break;
} }
} }
@@ -882,7 +884,7 @@ static void smps_conv_mode_set(struct smps_priv_s *priv, struct smps_lower_dev_s
default: default:
{ {
printf("ERROR: unknown converter mode %d!\n", mode); pwrerr("ERROR: unknown converter mode %d!\n", mode);
break; break;
} }
} }
@@ -1017,7 +1019,7 @@ int stm32_smps_setup(void)
hrtim = stm32_hrtiminitialize(); hrtim = stm32_hrtiminitialize();
if (hrtim == NULL) if (hrtim == NULL)
{ {
printf("ERROR: Failed to get HRTIM1 interface\n"); pwrerr("ERROR: Failed to get HRTIM1 interface\n");
return -ENODEV; return -ENODEV;
} }
@@ -1033,7 +1035,7 @@ int stm32_smps_setup(void)
adc = stm32_adcinitialize(1, g_adc1chan, ADC1_NCHANNELS); adc = stm32_adcinitialize(1, g_adc1chan, ADC1_NCHANNELS);
if (adc == NULL) 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; return -ENODEV;
} }
@@ -1050,8 +1052,8 @@ int stm32_smps_setup(void)
ret = up_ramvec_attach(STM32_IRQ_ADC12, adc12_handler); ret = up_ramvec_attach(STM32_IRQ_ADC12, adc12_handler);
if (ret < 0) if (ret < 0)
{ {
fprintf(stderr, "highpri_main: ERROR: up_ramvec_attach failed: %d\n", pwrerr("ERROR: highpri_main: ERROR: up_ramvec_attach failed: %d\n",
ret); ret);
ret = EXIT_FAILURE; ret = EXIT_FAILURE;
goto errout; goto errout;
} }
@@ -1061,8 +1063,9 @@ int stm32_smps_setup(void)
ret = up_prioritize_irq(STM32_IRQ_ADC12, NVIC_SYSH_HIGH_PRIORITY); ret = up_prioritize_irq(STM32_IRQ_ADC12, NVIC_SYSH_HIGH_PRIORITY);
if (ret < 0) if (ret < 0)
{ {
fprintf(stderr, pwrerr("ERROR: ""
"highpri_main: ERROR: up_prioritize_irq failed: %d\n", ret); "highpri_main: ERROR: up_prioritize_irq failed: %d\n",
ret);
ret = EXIT_FAILURE; ret = EXIT_FAILURE;
goto errout; goto errout;
} }
@@ -1080,7 +1083,7 @@ int stm32_smps_setup(void)
ret = smps_register(CONFIG_EXAMPLES_SMPS_DEVPATH, smps, (void *)lower); ret = smps_register(CONFIG_EXAMPLES_SMPS_DEVPATH, smps, (void *)lower);
if (ret < 0) if (ret < 0)
{ {
printf("ERROR: smps_register failed: %d\n", ret); pwrerr("ERROR: smps_register failed: %d\n", ret);
return ret; return ret;
} }
+3 -3
View File
@@ -44,9 +44,9 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdio.h>
#include <syslog.h> #include <syslog.h>
#include <errno.h> #include <errno.h>
#include <debug.h>
#include <nuttx/board.h> #include <nuttx/board.h>
#include <nuttx/spi/spi.h> #include <nuttx/spi/spi.h>
@@ -120,13 +120,13 @@
# ifdef CONFIG_DEBUG_INFO # ifdef CONFIG_DEBUG_INFO
# define message(...) _info(__VA_ARGS__) # define message(...) _info(__VA_ARGS__)
# else # else
# define message(...) printf(__VA_ARGS__) # define message(...) _err(__VA_ARGS__)
# endif # endif
#else #else
# ifdef CONFIG_DEBUG_INFO # ifdef CONFIG_DEBUG_INFO
# define message _info # define message _info
# else # else
# define message printf # define message _err
# endif # endif
#endif #endif
+5 -4
View File
@@ -42,12 +42,13 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/signal.h> #include <nuttx/signal.h>
+33 -19
View File
@@ -51,12 +51,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <debug.h>
#include <errno.h> #include <errno.h>
#include <crc8.h> #include <crc8.h>
#include <crc16.h> #include <crc16.h>
#include <crc32.h> #include <crc32.h>
#include <debug.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h> #include <nuttx/fs/ioctl.h>
@@ -3476,10 +3477,11 @@ static int smart_findfreephyssector(FAR struct smart_struct_s *dev,
uint8_t maxwearlevel; uint8_t maxwearlevel;
#endif #endif
uint16_t physicalsector; uint16_t physicalsector;
uint16_t x, block; uint16_t block;
uint32_t readaddr; uint32_t readaddr;
struct smart_sect_header_s header; struct smart_sect_header_s header;
int ret; int ret;
uint16_t i;
/* Determine which erase block we should allocate the new /* Determine which erase block we should allocate the new
* sector from. This is based on the number of free sectors * sector from. This is based on the number of free sectors
@@ -3504,7 +3506,7 @@ retry:
} }
block = dev->lastallocblock; 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 /* Test if this block has more free blocks than the
* currently selected block * currently selected block
@@ -3533,7 +3535,7 @@ retry:
* free sectors left, then we will use it. * free sectors left, then we will use it.
*/ */
if (x < dev->neraseblocks - 1 || !wornfreecount) if (i < dev->neraseblocks - 1 || !wornfreecount)
{ {
wornfreecount = count; wornfreecount = count;
wornblock = block; wornblock = block;
@@ -3548,7 +3550,7 @@ retry:
{ {
/* Assign this block to alloc from */ /* Assign this block to alloc from */
if (x < dev->neraseblocks - 1 || !allocfreecount) if (i < dev->neraseblocks - 1 || !allocfreecount)
{ {
allocblock = block; allocblock = block;
allocfreecount = count; allocfreecount = count;
@@ -3576,7 +3578,7 @@ retry:
/* Relocate up to 8 unworn blocks */ /* Relocate up to 8 unworn blocks */
block = 0; block = 0;
for (x = 0; x < 8; ) for (i = 0; i < 8; )
{ {
if (smart_get_wear_level(dev, block) < SMART_WEAR_FORCE_REORG_THRESHOLD) if (smart_get_wear_level(dev, block) < SMART_WEAR_FORCE_REORG_THRESHOLD)
{ {
@@ -3586,13 +3588,13 @@ retry:
return -1; return -1;
} }
x++; i++;
} }
block++; block++;
} }
if (x > 0) if (i > 0)
{ {
/* Disable relocate for retry */ /* Disable relocate for retry */
@@ -3615,25 +3617,37 @@ retry:
#endif #endif
{ {
ferr("ERROR: Program bug! Expected a free sector, free=%d\n", dev->freesectors); char buffer[8 * 12 + 1];
for (x = 0; x < dev->neraseblocks; x++) long remaining;
{ int j;
/* REVISIT: Use of printf is not permitted within the OS */ 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? */ /* No free sectors found! Bug? */
return -1; return -ENOSPC;
} }
} }
/* Now find a free physical sector within this selected /* Now find a free physical sector within this selected
* erase block to allocate. */ * erase block to allocate. */
for (x = allocblock * dev->sectorsPerBlk; for (i = allocblock * dev->sectorsPerBlk;
x < allocblock * dev->sectorsPerBlk + dev->availSectPerBlk; x++) i < allocblock * dev->sectorsPerBlk + dev->availSectPerBlk; i++)
{ {
/* Check if this physical sector is available. */ /* Check if this physical sector is available. */
@@ -3645,7 +3659,7 @@ retry:
while (allocsect) while (allocsect)
{ {
if (allocsect->physical == x) if (allocsect->physical == i)
{ {
break; break;
} }
@@ -3666,7 +3680,7 @@ retry:
/* Now check on the physical media */ /* 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), ret = MTD_READ(dev->mtd, readaddr, sizeof(struct smart_sect_header_s),
(FAR uint8_t *) &header); (FAR uint8_t *) &header);
if (ret != sizeof(struct smart_sect_header_s)) if (ret != sizeof(struct smart_sect_header_s))
@@ -3684,7 +3698,7 @@ retry:
((header.status & SMART_STATUS_COMMITTED) == ((header.status & SMART_STATUS_COMMITTED) ==
(CONFIG_SMARTFS_ERASEDSTATE & SMART_STATUS_COMMITTED))) (CONFIG_SMARTFS_ERASEDSTATE & SMART_STATUS_COMMITTED)))
{ {
physicalsector = x; physicalsector = i;
dev->lastallocblock = allocblock; dev->lastallocblock = allocblock;
break; break;
} }
+1 -2
View File
@@ -46,7 +46,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <semaphore.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); ret = psock_socket(PF_INET, SOCK_DGRAM, 0, &priv->psock);
if (ret < 0) if (ret < 0)
{ {
printf("client: ERROR socket failure %d\n", ret); ferr("ERROR: socket() failed: %d\n", ret);
goto errout_with_alloc; goto errout_with_alloc;
} }