diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-10-26 13:59:06 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-10-28 13:33:55 +0200 |
commit | 7bec7f2715f0f3495f59513e61c319fe65a3fd40 (patch) | |
tree | ebd8253ec8fe2169ef6fcd2becd5cf7550f66796 /cpukit | |
parent | tests: Move rtems_test_printer definition (diff) | |
download | rtems-7bec7f2715f0f3495f59513e61c319fe65a3fd40.tar.bz2 |
rtems: Add rtems_print_printer_fprintf_putc()
Update #3170.
Update #3199.
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/include/rtems/printer.h | 25 | ||||
-rw-r--r-- | cpukit/libcsupport/Makefile.am | 1 | ||||
-rw-r--r-- | cpukit/libcsupport/src/printerfprintfputc.c | 67 |
3 files changed, 82 insertions, 11 deletions
diff --git a/cpukit/include/rtems/printer.h b/cpukit/include/rtems/printer.h index c18600bbe3..fccd9bcf5f 100644 --- a/cpukit/include/rtems/printer.h +++ b/cpukit/include/rtems/printer.h @@ -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. + * @brief Initializes the printer to print via fprintf() using the specified + * file stream. * - * The printer will output to the libc fprintf file provided. + * @param[in] printer Pointer to the printer structure. + */ +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. */ -extern void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file); +void rtems_print_printer_fprintf_putc(rtems_printer *printer); typedef struct { rtems_id task; diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index 66a8aa06da..8645ba1914 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -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) \ diff --git a/cpukit/libcsupport/src/printerfprintfputc.c b/cpukit/libcsupport/src/printerfprintfputc.c new file mode 100644 index 0000000000..8b502fa489 --- /dev/null +++ b/cpukit/libcsupport/src/printerfprintfputc.c @@ -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; +} |