rtems: Add rtems_print_printer_fprintf_putc()

Update #3170.
Update #3199.
This commit is contained in:
Sebastian Huber
2017-10-26 13:59:06 +02:00
parent f703e7f5c7
commit 7bec7f2715
3 changed files with 83 additions and 12 deletions

View File

@@ -74,7 +74,7 @@ static inline bool rtems_print_printer_valid(const rtems_printer *printer)
}
/**
* @brief Initializes the rtems_printer struct to empty.
* @brief Initializes the printer to print nothing.
*
* An empty printer prints nothing. You can use this to implement an enable and
* disable type print implementation.
@@ -88,31 +88,34 @@ static inline void rtems_print_printer_empty(rtems_printer *printer)
}
/**
* @brief Initializes the rtems_printer struct to printk
*
* The printer will output to the kernel printk support.
* @brief Initializes the printer to print via printk().
*
* @param[in] printer Pointer to the printer structure.
*/
void rtems_print_printer_printk(rtems_printer *printer);
/**
* @brief Initializes the rtems_printer struct to printf
*
* The printer will output to the libc printf support.
* @brief Initializes the printer to print via printf().
*
* @param[in] printer Pointer to the printer structure.
*/
extern void rtems_print_printer_printf(rtems_printer *printer);
void rtems_print_printer_printf(rtems_printer *printer);
/**
* @brief Initializes the rtems_printer struct to a fprintf device.
*
* The printer will output to the libc fprintf file provided.
* @brief Initializes the printer to print via fprintf() using the specified
* file stream.
*
* @param[in] printer Pointer to the printer structure.
*/
extern void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file);
void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file);
/**
* @brief Initializes the printer to print via fprintf() using an unbuffered
* FILE stream with output through rtems_putc().
*
* @param[in] printer Pointer to the printer structure.
*/
void rtems_print_printer_fprintf_putc(rtems_printer *printer);
typedef struct {
rtems_id task;

View File

@@ -139,6 +139,7 @@ libcsupport_a_SOURCES = src/gxx_wrappers.c src/getchark.c src/printk.c \
$(BSD_LIBC_C_FILES) $(BASE_FS_C_FILES) $(MALLOC_C_FILES) \
$(ERROR_C_FILES) $(ASSOCIATION_C_FILES)
libcsupport_a_SOURCES += src/printertask.c
libcsupport_a_SOURCES += src/printerfprintfputc.c
libcsupport_a_SOURCES += $(LIBC_GLUE_C_FILES) $(PASSWORD_GROUP_C_FILES) \
$(TERMINAL_IDENTIFICATION_C_FILES) $(SYSTEM_CALL_C_FILES) \

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2017 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/printer.h>
#include <rtems/bspIo.h>
#include <pthread.h>
static pthread_once_t fprintf_putc_once = PTHREAD_ONCE_INIT;
static FILE fprintf_putc_file;
static _READ_WRITE_RETURN_TYPE fprintf_putc_write(
struct _reent *ptr,
void *cookie,
char const *buf,
_READ_WRITE_BUFSIZE_TYPE n
)
{
_READ_WRITE_RETURN_TYPE i;
_READ_WRITE_RETURN_TYPE m;
m = (_READ_WRITE_RETURN_TYPE) n;
for (i = 0; i < m; ++i) {
rtems_putc(buf[i]);
}
return m;
}
static void fprintf_putc_init(void)
{
FILE *f;
f = &fprintf_putc_file;
f->_flags = __SWR | __SNBF;
f->_cookie = f;
f->_write = fprintf_putc_write;
__lock_init_recursive(f->_lock);
}
static int fprintf_putc_printer(void *context, const char *fmt, va_list ap)
{
return vfprintf(context, fmt, ap);
}
void rtems_print_printer_fprintf_putc(rtems_printer *printer)
{
pthread_once(&fprintf_putc_once, fprintf_putc_init);
printer->context = &fprintf_putc_file;
printer->printer = fprintf_putc_printer;
}