libc/stream: Support lowsyslog.

This commit added support for lowsyslog.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
ouyangxiangzhen 2025-02-13 11:56:33 +08:00 committed by Xiang Xiao
parent 0c9a239b9e
commit 9f01e5c972
3 changed files with 42 additions and 3 deletions

View file

@ -29,6 +29,7 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <nuttx/streams.h>
#ifdef CONFIG_ARCH_DEBUG_H
# include <arch/debug.h>
@ -1318,6 +1319,26 @@
# define resetinfodumpbuffer(m,b,n)
#endif
/****************************************************************************
* Name: lowsyslog
*
* Description:
* lowsyslog() is used for output debug information at early boot-stage.
*
* The NuttX implementation does not support any special formatting
* characters beyond those supported by printf.
*
****************************************************************************/
#define lowsyslog(...) \
do \
{ \
struct lib_outstream_s stream; \
lib_lowoutstream(&stream); \
lib_sprintf(&stream, __VA_ARGS__); \
} \
while (0)
/****************************************************************************
* Public Function Prototypes
****************************************************************************/

View file

@ -2820,6 +2820,18 @@ int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg,
void up_putc(int ch);
/****************************************************************************
* Name: up_lowputc
*
* Description:
* Output one character in early boot-stages.
*
****************************************************************************/
#ifdef CONFIG_ARCH_LOWPUTC
void up_lowputc(int ch);
#endif
/****************************************************************************
* Name: up_puts
*

View file

@ -67,7 +67,7 @@ static void lowoutstream_putc(FAR struct lib_outstream_s *self, int ch)
{
DEBUGASSERT(self);
up_putc(ch);
up_lowputc(ch);
if (ch != EOF)
{
@ -82,10 +82,16 @@ static void lowoutstream_putc(FAR struct lib_outstream_s *self, int ch)
static ssize_t lowoutstream_puts(FAR struct lib_outstream_s *self,
FAR const void *buf, size_t len)
{
FAR const char *str = (FAR const char *)buf;
size_t idx = 0;
DEBUGASSERT(self);
self->nput += len;
up_nputs(buf, len);
while (str[idx] != 0 && idx < len)
{
lowoutstream_putc(self, str[idx]);
idx++;
}
return len;
}