From ea6abe0731888c334b721970d37d3aef0a8ab220 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 6 Feb 2015 11:42:26 +0000 Subject: [PATCH] chprintf and streams are now part of the HAL library. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7665 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/KINETIS/RT-MCHCK-K20-GPT/Makefile | 3 +- demos/KINETIS/RT-MCHCK-K20-SPI/Makefile | 3 +- demos/SPC5/RT-SPC560B-EVB/Makefile | 3 +- demos/SPC5/RT-SPC560D-EVB/Makefile | 3 +- demos/SPC5/RT-SPC560P-EVB/Makefile | 3 +- demos/SPC5/RT-SPC563M-EVB/Makefile | 3 +- demos/SPC5/RT-SPC564A-EVB/Makefile | 3 +- demos/SPC5/RT-SPC56EC-EVB/Makefile | 3 +- demos/SPC5/RT-SPC56EL-EVB/Makefile | 3 +- .../STM32/CMSIS-STM32F407-DISCOVERY/.cproject | 4 +- demos/STM32/NIL-STM32F303-DISCOVERY/.cproject | 48 +-- demos/STM32/RT-STM32F072-DISCOVERY/Makefile | 3 +- demos/STM32/RT-STM32F103-MAPLEMINI/Makefile | 3 +- .../RT-STM32F103_INEMO_DISCOVERY/Makefile | 3 +- demos/STM32/RT-STM32F401RE-NUCLEO/.cproject | 4 +- .../STM32/RT-STM32F407-DISCOVERY-G++/Makefile | 3 +- .../RT-STM32F407-DISCOVERY-MEMS/Makefile | 3 +- .../Makefile | 3 +- demos/STM32/RT-STM32F429-DISCOVERY/Makefile | 3 +- demos/various/RT-Win32-Simulator/Makefile | 19 +- os/various/chprintf.c | 337 ------------------ os/various/chprintf.h | 82 ----- os/various/memstreams.c | 113 ------ os/various/memstreams.h | 95 ----- os/various/various.dox | 8 - testhal/AVR/GPT/Makefile | 4 +- testhal/AVR/ICU/Makefile | 4 +- testhal/STM32/STM32F0xx/USB_CDC/Makefile | 3 +- testhal/STM32/STM32F1xx/USB_CDC/Makefile | 3 +- testhal/STM32/STM32F1xx/USB_CDC_F107/Makefile | 3 +- testhal/STM32/STM32F30x/USB_CDC/Makefile | 3 +- testhal/STM32/STM32F30x/USB_CDC_IAD/Makefile | 3 +- testhal/STM32/STM32F37x/USB_CDC/Makefile | 3 +- testhal/STM32/STM32F4xx/RTC/Makefile | 3 +- testhal/STM32/STM32F4xx/SDC/Makefile | 3 +- testhal/STM32/STM32F4xx/USB_CDC/Makefile | 3 +- testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile | 3 +- 37 files changed, 70 insertions(+), 726 deletions(-) delete mode 100644 os/various/chprintf.c delete mode 100644 os/various/chprintf.h delete mode 100644 os/various/memstreams.c delete mode 100644 os/various/memstreams.h diff --git a/demos/KINETIS/RT-MCHCK-K20-GPT/Makefile b/demos/KINETIS/RT-MCHCK-K20-GPT/Makefile index a8370b0a3..d12b6a10f 100644 --- a/demos/KINETIS/RT-MCHCK-K20-GPT/Makefile +++ b/demos/KINETIS/RT-MCHCK-K20-GPT/Makefile @@ -95,7 +95,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/demos/KINETIS/RT-MCHCK-K20-SPI/Makefile b/demos/KINETIS/RT-MCHCK-K20-SPI/Makefile index 1e972097a..f9f459bd1 100644 --- a/demos/KINETIS/RT-MCHCK-K20-SPI/Makefile +++ b/demos/KINETIS/RT-MCHCK-K20-SPI/Makefile @@ -95,7 +95,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/demos/SPC5/RT-SPC560B-EVB/Makefile b/demos/SPC5/RT-SPC560B-EVB/Makefile index dc0de9bf8..f6c6b5108 100644 --- a/demos/SPC5/RT-SPC560B-EVB/Makefile +++ b/demos/SPC5/RT-SPC560B-EVB/Makefile @@ -95,7 +95,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ main.c diff --git a/demos/SPC5/RT-SPC560D-EVB/Makefile b/demos/SPC5/RT-SPC560D-EVB/Makefile index 210bcd1be..9a921552f 100644 --- a/demos/SPC5/RT-SPC560D-EVB/Makefile +++ b/demos/SPC5/RT-SPC560D-EVB/Makefile @@ -95,7 +95,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ main.c diff --git a/demos/SPC5/RT-SPC560P-EVB/Makefile b/demos/SPC5/RT-SPC560P-EVB/Makefile index c20e65a77..766196a2f 100644 --- a/demos/SPC5/RT-SPC560P-EVB/Makefile +++ b/demos/SPC5/RT-SPC560P-EVB/Makefile @@ -95,7 +95,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ main.c diff --git a/demos/SPC5/RT-SPC563M-EVB/Makefile b/demos/SPC5/RT-SPC563M-EVB/Makefile index 2e6f3734d..b5138e155 100644 --- a/demos/SPC5/RT-SPC563M-EVB/Makefile +++ b/demos/SPC5/RT-SPC563M-EVB/Makefile @@ -95,7 +95,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ main.c diff --git a/demos/SPC5/RT-SPC564A-EVB/Makefile b/demos/SPC5/RT-SPC564A-EVB/Makefile index e72a00878..474bc259a 100644 --- a/demos/SPC5/RT-SPC564A-EVB/Makefile +++ b/demos/SPC5/RT-SPC564A-EVB/Makefile @@ -95,7 +95,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ main.c diff --git a/demos/SPC5/RT-SPC56EC-EVB/Makefile b/demos/SPC5/RT-SPC56EC-EVB/Makefile index 9a18d1f05..55f1333a4 100644 --- a/demos/SPC5/RT-SPC56EC-EVB/Makefile +++ b/demos/SPC5/RT-SPC56EC-EVB/Makefile @@ -95,7 +95,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ main.c diff --git a/demos/SPC5/RT-SPC56EL-EVB/Makefile b/demos/SPC5/RT-SPC56EL-EVB/Makefile index db3ac54fd..6df79a954 100644 --- a/demos/SPC5/RT-SPC56EL-EVB/Makefile +++ b/demos/SPC5/RT-SPC56EL-EVB/Makefile @@ -95,7 +95,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ main.c diff --git a/demos/STM32/CMSIS-STM32F407-DISCOVERY/.cproject b/demos/STM32/CMSIS-STM32F407-DISCOVERY/.cproject index a1d0ba157..914646b39 100644 --- a/demos/STM32/CMSIS-STM32F407-DISCOVERY/.cproject +++ b/demos/STM32/CMSIS-STM32F407-DISCOVERY/.cproject @@ -1,7 +1,5 @@ - - - + diff --git a/demos/STM32/NIL-STM32F303-DISCOVERY/.cproject b/demos/STM32/NIL-STM32F303-DISCOVERY/.cproject index a32ef55e6..80e5e6c26 100644 --- a/demos/STM32/NIL-STM32F303-DISCOVERY/.cproject +++ b/demos/STM32/NIL-STM32F303-DISCOVERY/.cproject @@ -1,7 +1,5 @@ - - - + @@ -42,6 +40,8 @@ + + @@ -54,16 +54,6 @@ - - - - - - - - - - @@ -94,36 +84,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -208,6 +168,4 @@ - - diff --git a/demos/STM32/RT-STM32F072-DISCOVERY/Makefile b/demos/STM32/RT-STM32F072-DISCOVERY/Makefile index b0b36edb2..b720144f4 100644 --- a/demos/STM32/RT-STM32F072-DISCOVERY/Makefile +++ b/demos/STM32/RT-STM32F072-DISCOVERY/Makefile @@ -97,7 +97,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/demos/STM32/RT-STM32F103-MAPLEMINI/Makefile b/demos/STM32/RT-STM32F103-MAPLEMINI/Makefile index 43e141ff8..ffc408a30 100644 --- a/demos/STM32/RT-STM32F103-MAPLEMINI/Makefile +++ b/demos/STM32/RT-STM32F103-MAPLEMINI/Makefile @@ -109,7 +109,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/Makefile b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/Makefile index fac6c60c9..4f20569a9 100644 --- a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/Makefile +++ b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/Makefile @@ -102,7 +102,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/demos/STM32/RT-STM32F401RE-NUCLEO/.cproject b/demos/STM32/RT-STM32F401RE-NUCLEO/.cproject index 1dd60e086..ad4a2d0ab 100644 --- a/demos/STM32/RT-STM32F401RE-NUCLEO/.cproject +++ b/demos/STM32/RT-STM32F401RE-NUCLEO/.cproject @@ -1,7 +1,5 @@ - - - + diff --git a/demos/STM32/RT-STM32F407-DISCOVERY-G++/Makefile b/demos/STM32/RT-STM32F407-DISCOVERY-G++/Makefile index 8d16de8c1..9b0322826 100644 --- a/demos/STM32/RT-STM32F407-DISCOVERY-G++/Makefile +++ b/demos/STM32/RT-STM32F407-DISCOVERY-G++/Makefile @@ -104,7 +104,8 @@ CSRC = $(PORTSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/devices_lib/accel/lis302dl.c \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/syscalls.c \ # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/demos/STM32/RT-STM32F407-DISCOVERY-MEMS/Makefile b/demos/STM32/RT-STM32F407-DISCOVERY-MEMS/Makefile index c8fefbd85..8e87a7212 100644 --- a/demos/STM32/RT-STM32F407-DISCOVERY-MEMS/Makefile +++ b/demos/STM32/RT-STM32F407-DISCOVERY-MEMS/Makefile @@ -103,7 +103,8 @@ CSRC = $(PORTSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/devices_lib/accel/lis302dl.c \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/Makefile b/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/Makefile index e4cc74c07..d8f029d0e 100644 --- a/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/Makefile +++ b/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/Makefile @@ -106,7 +106,8 @@ CSRC = $(PORTSRC) \ $(LWSRC) \ $(FATFSSRC) \ $(CHIBIOS)/os/various/evtimer.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ web/web.c main.c diff --git a/demos/STM32/RT-STM32F429-DISCOVERY/Makefile b/demos/STM32/RT-STM32F429-DISCOVERY/Makefile index 453a2f150..b9f550e11 100644 --- a/demos/STM32/RT-STM32F429-DISCOVERY/Makefile +++ b/demos/STM32/RT-STM32F429-DISCOVERY/Makefile @@ -102,7 +102,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/demos/various/RT-Win32-Simulator/Makefile b/demos/various/RT-Win32-Simulator/Makefile index 7621091b1..5723fb09f 100644 --- a/demos/various/RT-Win32-Simulator/Makefile +++ b/demos/various/RT-Win32-Simulator/Makefile @@ -58,12 +58,12 @@ UADEFS = # Imported source files CHIBIOS = ../../.. include $(CHIBIOS)/os/hal/boards/simulator/board.mk -include ${CHIBIOS}/os/hal/hal.mk -include ${CHIBIOS}/os/hal/ports/simulator/win32/platform.mk +include $(CHIBIOS)/os/hal/hal.mk +include $(CHIBIOS)/os/hal/ports/simulator/win32/platform.mk include $(CHIBIOS)/os/hal/osal/rt/osal.mk -include ${CHIBIOS}/os/rt/ports/SIMIA32/compilers/GCC/port.mk -include ${CHIBIOS}/os/rt/rt.mk -include ${CHIBIOS}/test/rt/test.mk +include $(CHIBIOS)/os/rt/ports/SIMIA32/compilers/GCC/port.mk +include $(CHIBIOS)/os/rt/rt.mk +include $(CHIBIOS)/test/rt/test.mk # List C source files here SRC = $(PORTSRC) \ @@ -73,9 +73,9 @@ SRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - ${CHIBIOS}/os/various/shell.c \ - ${CHIBIOS}/os/various/memstreams.c \ - ${CHIBIOS}/os/various/chprintf.c \ + $(CHIBIOS)/os/various/shell.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # List ASM source files here @@ -84,7 +84,7 @@ ASRC = # List all user directories here UINCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ $(HALINC) $(OSALINC) $(PLATFORMINC) $(BOARDINC) \ - ${CHIBIOS}/os/various + $(CHIBIOS)/os/various # List the user directory to look for the libraries here ULIBDIR = @@ -99,7 +99,6 @@ OPT = -ggdb -O2 -fomit-frame-pointer # End of user defines ############################################################################################## - INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR)) LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR)) DEFS = $(DDEFS) $(UDEFS) diff --git a/os/various/chprintf.c b/os/various/chprintf.c deleted file mode 100644 index e44bd9d5b..000000000 --- a/os/various/chprintf.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/* - Concepts and parts of this file have been contributed by Fabio Utzig, - chvprintf() added by Brent Roman. - */ - -/** - * @file chprintf.c - * @brief Mini printf-like functionality. - * - * @addtogroup chprintf - * @{ - */ - -#include "ch.h" -#include "chprintf.h" -#include "memstreams.h" - -#define MAX_FILLER 11 -#define FLOAT_PRECISION 9 - -static char *long_to_string_with_divisor(char *p, - long num, - unsigned radix, - long divisor) { - int i; - char *q; - long l, ll; - - l = num; - if (divisor == 0) { - ll = num; - } else { - ll = divisor; - } - - q = p + MAX_FILLER; - do { - i = (int)(l % radix); - i += '0'; - if (i > '9') - i += 'A' - '0' - 10; - *--q = i; - l /= radix; - } while ((ll /= radix) != 0); - - i = (int)(p + MAX_FILLER - q); - do - *p++ = *q++; - while (--i); - - return p; -} - -static char *ltoa(char *p, long num, unsigned radix) { - - return long_to_string_with_divisor(p, num, radix, 0); -} - -#if CHPRINTF_USE_FLOAT -static const long pow10[FLOAT_PRECISION] = { - 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 -}; - -static char *ftoa(char *p, double num, unsigned long precision) { - long l; - - if ((precision == 0) || (precision > FLOAT_PRECISION)) - precision = FLOAT_PRECISION; - precision = pow10[precision - 1]; - - l = (long)num; - p = long_to_string_with_divisor(p, l, 10, 0); - *p++ = '.'; - l = (long)((num - l) * precision); - return long_to_string_with_divisor(p, l, 10, precision / 10); -} -#endif - -/** - * @brief System formatted output function. - * @details This function implements a minimal @p vprintf()-like functionality - * with output on a @p BaseSequentialStream. - * The general parameters format is: %[-][width|*][.precision|*][l|L]p. - * The following parameter types (p) are supported: - * - x hexadecimal integer. - * - X hexadecimal long. - * - o octal integer. - * - O octal long. - * - d decimal signed integer. - * - D decimal signed long. - * - u decimal unsigned integer. - * - U decimal unsigned long. - * - c character. - * - s string. - * . - * - * @param[in] chp pointer to a @p BaseSequentialStream implementing object - * @param[in] fmt formatting string - * @param[in] ap list of parameters - * @return The number of bytes that would have been - * written to @p chp if no stream error occurs - * - * @api - */ -int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { - char *p, *s, c, filler; - int i, precision, width; - int n = 0; - bool is_long, left_align; - long l; -#if CHPRINTF_USE_FLOAT - float f; - char tmpbuf[2*MAX_FILLER + 1]; -#else - char tmpbuf[MAX_FILLER + 1]; -#endif - - while (TRUE) { - c = *fmt++; - if (c == 0) - return n; - if (c != '%') { - chSequentialStreamPut(chp, (uint8_t)c); - n++; - continue; - } - p = tmpbuf; - s = tmpbuf; - left_align = FALSE; - if (*fmt == '-') { - fmt++; - left_align = TRUE; - } - filler = ' '; - if (*fmt == '0') { - fmt++; - filler = '0'; - } - width = 0; - while (TRUE) { - c = *fmt++; - if (c >= '0' && c <= '9') - c -= '0'; - else if (c == '*') - c = va_arg(ap, int); - else - break; - width = width * 10 + c; - } - precision = 0; - if (c == '.') { - while (TRUE) { - c = *fmt++; - if (c >= '0' && c <= '9') - c -= '0'; - else if (c == '*') - c = va_arg(ap, int); - else - break; - precision *= 10; - precision += c; - } - } - /* Long modifier.*/ - if (c == 'l' || c == 'L') { - is_long = TRUE; - if (*fmt) - c = *fmt++; - } - else - is_long = (c >= 'A') && (c <= 'Z'); - - /* Command decoding.*/ - switch (c) { - case 'c': - filler = ' '; - *p++ = va_arg(ap, int); - break; - case 's': - filler = ' '; - if ((s = va_arg(ap, char *)) == 0) - s = "(null)"; - if (precision == 0) - precision = 32767; - for (p = s; *p && (--precision >= 0); p++) - ; - break; - case 'D': - case 'd': - case 'I': - case 'i': - if (is_long) - l = va_arg(ap, long); - else - l = va_arg(ap, int); - if (l < 0) { - *p++ = '-'; - l = -l; - } - p = ltoa(p, l, 10); - break; -#if CHPRINTF_USE_FLOAT - case 'f': - f = (float) va_arg(ap, double); - if (f < 0) { - *p++ = '-'; - f = -f; - } - p = ftoa(p, f, precision); - break; -#endif - case 'X': - case 'x': - c = 16; - goto unsigned_common; - case 'U': - case 'u': - c = 10; - goto unsigned_common; - case 'O': - case 'o': - c = 8; -unsigned_common: - if (is_long) - l = va_arg(ap, unsigned long); - else - l = va_arg(ap, unsigned int); - p = ltoa(p, l, c); - break; - default: - *p++ = c; - break; - } - i = (int)(p - s); - if ((width -= i) < 0) - width = 0; - if (left_align == FALSE) - width = -width; - if (width < 0) { - if (*s == '-' && filler == '0') { - chSequentialStreamPut(chp, (uint8_t)*s++); - n++; - i--; - } - do { - chSequentialStreamPut(chp, (uint8_t)filler); - n++; - } while (++width != 0); - } - while (--i >= 0) { - chSequentialStreamPut(chp, (uint8_t)*s++); - n++; - } - - while (width) { - chSequentialStreamPut(chp, (uint8_t)filler); - n++; - width--; - } - } -} - -/** - * @brief System formatted output function. - * @details This function implements a minimal @p vprintf()-like functionality - * with output on a @p BaseSequentialStream. - * The general parameters format is: %[-][width|*][.precision|*][l|L]p. - * The following parameter types (p) are supported: - * - x hexadecimal integer. - * - X hexadecimal long. - * - o octal integer. - * - O octal long. - * - d decimal signed integer. - * - D decimal signed long. - * - u decimal unsigned integer. - * - U decimal unsigned long. - * - c character. - * - s string. - * . - * @post @p str is NUL-terminated, unless @p size is 0. - * - * @param[in] str pointer to a buffer - * @param[in] size maximum size of the buffer - * @param[in] fmt formatting string - * @return The number of characters (excluding the - * terminating NUL byte) that would have been - * stored in @p str if there was room. - * - * @api - */ -int chsnprintf(char *str, size_t size, const char *fmt, ...) { - va_list ap; - MemoryStream ms; - BaseSequentialStream *chp; - size_t size_wo_nul; - int retval; - - if (size > 0) - size_wo_nul = size - 1; - else - size_wo_nul = 0; - - /* Memory stream object to be used as a string writer, reserving one - byte for the final zero.*/ - msObjectInit(&ms, (uint8_t *)str, size_wo_nul, 0); - - /* Performing the print operation using the common code.*/ - chp = (BaseSequentialStream *)&ms; - va_start(ap, fmt); - retval = chvprintf(chp, fmt, ap); - va_end(ap); - - /* Terminate with a zero, unless size==0.*/ - if (ms.eos < size) - str[ms.eos] = 0; - - /* Return number of bytes that would have been written.*/ - return retval; -} - -/** @} */ diff --git a/os/various/chprintf.h b/os/various/chprintf.h deleted file mode 100644 index 030640aa5..000000000 --- a/os/various/chprintf.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/** - * @file chprintf.h - * @brief Mini printf-like functionality. - * - * @addtogroup chprintf - * @{ - */ - -#ifndef _CHPRINTF_H_ -#define _CHPRINTF_H_ - -#include - -/** - * @brief Float type support. - */ -#if !defined(CHPRINTF_USE_FLOAT) || defined(__DOXYGEN__) -#define CHPRINTF_USE_FLOAT FALSE -#endif - -#ifdef __cplusplus -extern "C" { -#endif - int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap); - int chsnprintf(char *str, size_t size, const char *fmt, ...); -#ifdef __cplusplus -} -#endif - -/** - * @brief System formatted output function. - * @details This function implements a minimal @p printf() like functionality - * with output on a @p BaseSequentialStream. - * The general parameters format is: %[-][width|*][.precision|*][l|L]p. - * The following parameter types (p) are supported: - * - x hexadecimal integer. - * - X hexadecimal long. - * - o octal integer. - * - O octal long. - * - d decimal signed integer. - * - D decimal signed long. - * - u decimal unsigned integer. - * - U decimal unsigned long. - * - c character. - * - s string. - * . - * - * @param[in] chp pointer to a @p BaseSequentialStream implementing object - * @param[in] fmt formatting string - * - * @api - */ -static inline int chprintf(BaseSequentialStream *chp, const char *fmt, ...) { - va_list ap; - int formatted_bytes; - - va_start(ap, fmt); - formatted_bytes = chvprintf(chp, fmt, ap); - va_end(ap); - - return formatted_bytes; -} - -#endif /* _CHPRINTF_H_ */ - -/** @} */ diff --git a/os/various/memstreams.c b/os/various/memstreams.c deleted file mode 100644 index 499ec53e7..000000000 --- a/os/various/memstreams.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/** - * @file memstreams.c - * @brief Memory streams code. - * - * @addtogroup memory_streams - * @{ - */ - -#include - -#include "ch.h" -#include "memstreams.h" - -/*===========================================================================*/ -/* Driver local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver local functions. */ -/*===========================================================================*/ - -static size_t writes(void *ip, const uint8_t *bp, size_t n) { - MemoryStream *msp = ip; - - if (msp->size - msp->eos < n) - n = msp->size - msp->eos; - memcpy(msp->buffer + msp->eos, bp, n); - msp->eos += n; - return n; -} - -static size_t reads(void *ip, uint8_t *bp, size_t n) { - MemoryStream *msp = ip; - - if (msp->eos - msp->offset < n) - n = msp->eos - msp->offset; - memcpy(bp, msp->buffer + msp->offset, n); - msp->offset += n; - return n; -} - -static msg_t put(void *ip, uint8_t b) { - MemoryStream *msp = ip; - - if (msp->size - msp->eos <= 0) - return MSG_RESET; - *(msp->buffer + msp->eos) = b; - msp->eos += 1; - return MSG_OK; -} - -static msg_t get(void *ip) { - uint8_t b; - MemoryStream *msp = ip; - - if (msp->eos - msp->offset <= 0) - return MSG_RESET; - b = *(msp->buffer + msp->offset); - msp->offset += 1; - return b; -} - -static const struct MemStreamVMT vmt = {writes, reads, put, get}; - -/*===========================================================================*/ -/* Driver exported functions. */ -/*===========================================================================*/ - -/** - * @brief Memory stream object initialization. - * - * @param[out] msp pointer to the @p MemoryStream object to be initialized - * @param[in] buffer pointer to the memory buffer for the memory stream - * @param[in] size total size of the memory stream buffer - * @param[in] eos initial End Of Stream offset. Normally you need to - * put this to zero for RAM buffers or equal to @p size - * for ROM streams. - */ -void msObjectInit(MemoryStream *msp, uint8_t *buffer, - size_t size, size_t eos) { - - msp->vmt = &vmt; - msp->buffer = buffer; - msp->size = size; - msp->eos = eos; - msp->offset = 0; -} - -/** @} */ diff --git a/os/various/memstreams.h b/os/various/memstreams.h deleted file mode 100644 index 5d0072e2e..000000000 --- a/os/various/memstreams.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/** - * @file memstreams.h - * @brief Memory streams structures and macros. - - * @addtogroup memory_streams - * @{ - */ - -#ifndef _MEMSTREAMS_H_ -#define _MEMSTREAMS_H_ - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -/** - * @brief @p MemStream specific data. - */ -#define _memory_stream_data \ - _base_sequential_stream_data \ - /* Pointer to the stream buffer.*/ \ - uint8_t *buffer; \ - /* Size of the stream.*/ \ - size_t size; \ - /* Current end of stream.*/ \ - size_t eos; \ - /* Current read offset.*/ \ - size_t offset; - -/** - * @brief @p MemStream virtual methods table. - */ -struct MemStreamVMT { - _base_sequential_stream_methods -}; - -/** - * @extends BaseSequentialStream - * - * @brief Memory stream object. - */ -typedef struct { - /** @brief Virtual Methods Table.*/ - const struct MemStreamVMT *vmt; - _memory_stream_data -} MemoryStream; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - void msObjectInit(MemoryStream *msp, uint8_t *buffer, - size_t size, size_t eos); -#ifdef __cplusplus -} -#endif - -#endif /* _MEMSTREAMS_H_ */ - -/** @} */ diff --git a/os/various/various.dox b/os/various/various.dox index 976728585..a12b0da1b 100644 --- a/os/various/various.dox +++ b/os/various/various.dox @@ -70,14 +70,6 @@ * @ingroup various */ -/** - * @defgroup chrtclib RTC time conversion utilities - * - * @brief RTC time conversion utilities. - * - * @ingroup various - */ - /** * @defgroup chprintf System formatted print * diff --git a/testhal/AVR/GPT/Makefile b/testhal/AVR/GPT/Makefile index 1b67f0d30..8bdb365c1 100644 --- a/testhal/AVR/GPT/Makefile +++ b/testhal/AVR/GPT/Makefile @@ -75,8 +75,8 @@ SRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/evtimer.c \ - $(CHIBIOS)/os/various/memstreams.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # List C++ source files here. (C dependencies are automatically generated.) diff --git a/testhal/AVR/ICU/Makefile b/testhal/AVR/ICU/Makefile index 1b67f0d30..8bdb365c1 100644 --- a/testhal/AVR/ICU/Makefile +++ b/testhal/AVR/ICU/Makefile @@ -75,8 +75,8 @@ SRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/evtimer.c \ - $(CHIBIOS)/os/various/memstreams.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # List C++ source files here. (C dependencies are automatically generated.) diff --git a/testhal/STM32/STM32F0xx/USB_CDC/Makefile b/testhal/STM32/STM32F0xx/USB_CDC/Makefile index 09f14985b..0bca6f985 100644 --- a/testhal/STM32/STM32F0xx/USB_CDC/Makefile +++ b/testhal/STM32/STM32F0xx/USB_CDC/Makefile @@ -97,7 +97,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/testhal/STM32/STM32F1xx/USB_CDC/Makefile b/testhal/STM32/STM32F1xx/USB_CDC/Makefile index 3d277c20b..2d6594793 100644 --- a/testhal/STM32/STM32F1xx/USB_CDC/Makefile +++ b/testhal/STM32/STM32F1xx/USB_CDC/Makefile @@ -102,7 +102,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/testhal/STM32/STM32F1xx/USB_CDC_F107/Makefile b/testhal/STM32/STM32F1xx/USB_CDC_F107/Makefile index b660588d3..88b8e950b 100644 --- a/testhal/STM32/STM32F1xx/USB_CDC_F107/Makefile +++ b/testhal/STM32/STM32F1xx/USB_CDC_F107/Makefile @@ -78,7 +78,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/testhal/STM32/STM32F30x/USB_CDC/Makefile b/testhal/STM32/STM32F30x/USB_CDC/Makefile index 4028a4949..b54a31026 100644 --- a/testhal/STM32/STM32F30x/USB_CDC/Makefile +++ b/testhal/STM32/STM32F30x/USB_CDC/Makefile @@ -102,7 +102,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/testhal/STM32/STM32F30x/USB_CDC_IAD/Makefile b/testhal/STM32/STM32F30x/USB_CDC_IAD/Makefile index 4b3d40da0..b5e2e4d22 100644 --- a/testhal/STM32/STM32F30x/USB_CDC_IAD/Makefile +++ b/testhal/STM32/STM32F30x/USB_CDC_IAD/Makefile @@ -102,7 +102,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/testhal/STM32/STM32F37x/USB_CDC/Makefile b/testhal/STM32/STM32F37x/USB_CDC/Makefile index 537b6fa59..53ea39d43 100644 --- a/testhal/STM32/STM32F37x/USB_CDC/Makefile +++ b/testhal/STM32/STM32F37x/USB_CDC/Makefile @@ -101,7 +101,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ main.c diff --git a/testhal/STM32/STM32F4xx/RTC/Makefile b/testhal/STM32/STM32F4xx/RTC/Makefile index 8690e1f32..14b700a8c 100644 --- a/testhal/STM32/STM32F4xx/RTC/Makefile +++ b/testhal/STM32/STM32F4xx/RTC/Makefile @@ -104,7 +104,8 @@ CSRC = $(PORTSRC) \ $(CHIBIOS)/os/various/evtimer.c \ $(CHIBIOS)/os/various/syscalls.c \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/testhal/STM32/STM32F4xx/SDC/Makefile b/testhal/STM32/STM32F4xx/SDC/Makefile index 6ea143f6a..9860c138f 100644 --- a/testhal/STM32/STM32F4xx/SDC/Makefile +++ b/testhal/STM32/STM32F4xx/SDC/Makefile @@ -101,7 +101,8 @@ CSRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/shell.c \ main.c diff --git a/testhal/STM32/STM32F4xx/USB_CDC/Makefile b/testhal/STM32/STM32F4xx/USB_CDC/Makefile index c964f5d86..0db62b01f 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC/Makefile +++ b/testhal/STM32/STM32F4xx/USB_CDC/Makefile @@ -102,7 +102,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile b/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile index 486617f6e..abd79278e 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile @@ -102,7 +102,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/various/chprintf.c \ + $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global