Added chvprintf() function to the chprintf module.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@6469 35acf78f-673a-0410-8e92-d51de3d6d3f4master
parent
05a9be0c14
commit
7a0e63b86e
|
@ -13,8 +13,10 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Concepts and parts of this file have been contributed by Fabio Utzig.
|
Concepts and parts of this file have been contributed by Fabio Utzig,
|
||||||
|
chvprintf() added by Brent Roman.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,8 +27,6 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
#include "chprintf.h"
|
#include "chprintf.h"
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ static char *ftoa(char *p, double num) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System formatted output function.
|
* @brief System formatted output function.
|
||||||
* @details This function implements a minimal @p printf() like functionality
|
* @details This function implements a minimal @p vprintf()-like functionality
|
||||||
* with output on a @p BaseSequentialStream.
|
* with output on a @p BaseSequentialStream.
|
||||||
* The general parameters format is: %[-][width|*][.precision|*][l|L]p.
|
* The general parameters format is: %[-][width|*][.precision|*][l|L]p.
|
||||||
* The following parameter types (p) are supported:
|
* The following parameter types (p) are supported:
|
||||||
|
@ -104,9 +104,11 @@ static char *ftoa(char *p, double num) {
|
||||||
*
|
*
|
||||||
* @param[in] chp pointer to a @p BaseSequentialStream implementing object
|
* @param[in] chp pointer to a @p BaseSequentialStream implementing object
|
||||||
* @param[in] fmt formatting string
|
* @param[in] fmt formatting string
|
||||||
|
* @param[in] ap list of parameters
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
void chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
|
void chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
|
||||||
va_list ap;
|
|
||||||
char *p, *s, c, filler;
|
char *p, *s, c, filler;
|
||||||
int i, precision, width;
|
int i, precision, width;
|
||||||
bool_t is_long, left_align;
|
bool_t is_long, left_align;
|
||||||
|
@ -118,13 +120,10 @@ void chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
|
||||||
char tmpbuf[MAX_FILLER + 1];
|
char tmpbuf[MAX_FILLER + 1];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
c = *fmt++;
|
c = *fmt++;
|
||||||
if (c == 0) {
|
if (c == 0)
|
||||||
va_end(ap);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (c != '%') {
|
if (c != '%') {
|
||||||
chSequentialStreamPut(chp, (uint8_t)c);
|
chSequentialStreamPut(chp, (uint8_t)c);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#ifndef _CHPRINTF_H_
|
#ifndef _CHPRINTF_H_
|
||||||
#define _CHPRINTF_H_
|
#define _CHPRINTF_H_
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Float type support.
|
* @brief Float type support.
|
||||||
*/
|
*/
|
||||||
|
@ -35,11 +37,42 @@
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
void chprintf(BaseSequentialStream *chp, const char *fmt, ...);
|
void chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#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:
|
||||||
|
* - <b>x</b> hexadecimal integer.
|
||||||
|
* - <b>X</b> hexadecimal long.
|
||||||
|
* - <b>o</b> octal integer.
|
||||||
|
* - <b>O</b> octal long.
|
||||||
|
* - <b>d</b> decimal signed integer.
|
||||||
|
* - <b>D</b> decimal signed long.
|
||||||
|
* - <b>u</b> decimal unsigned integer.
|
||||||
|
* - <b>U</b> decimal unsigned long.
|
||||||
|
* - <b>c</b> character.
|
||||||
|
* - <b>s</b> string.
|
||||||
|
* .
|
||||||
|
*
|
||||||
|
* @param[in] chp pointer to a @p BaseSequentialStream implementing object
|
||||||
|
* @param[in] fmt formatting string
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
static inline void chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
chvprintf(chp, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _CHPRINTF_H_ */
|
#endif /* _CHPRINTF_H_ */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -128,6 +128,7 @@
|
||||||
(backported to 2.6.0).
|
(backported to 2.6.0).
|
||||||
- FIX: Fixed MS2ST() and US2ST() macros error (bug #415)(backported to 2.6.0,
|
- FIX: Fixed MS2ST() and US2ST() macros error (bug #415)(backported to 2.6.0,
|
||||||
2.4.4, 2.2.10, NilRTOS).
|
2.4.4, 2.2.10, NilRTOS).
|
||||||
|
- NEW: Added chvprintf() function to the chprintf module.
|
||||||
- NEW: Improved time range check in the kernel, new API chTimeElapsedSince()
|
- NEW: Improved time range check in the kernel, new API chTimeElapsedSince()
|
||||||
introduced. The API chTimeIsWithin() is now a macro.
|
introduced. The API chTimeIsWithin() is now a macro.
|
||||||
- NEW: Added a new function shellExit() to the shell. It allows to exit the
|
- NEW: Added a new function shellExit() to the shell. It allows to exit the
|
||||||
|
|
Loading…
Reference in New Issue