RTEMS
printer.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2016 Chris Johns <chrisj@rtems.org>
11  * All rights reserved.
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifndef _RTEMS_PRINTER_H
19 #define _RTEMS_PRINTER_H
20 
21 #include <rtems/print.h>
22 #include <rtems/chain.h>
23 #include <rtems/rtems/intr.h>
24 #include <rtems/rtems/tasks.h>
25 
26 #include <stdio.h>
27 #include <string.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
49 typedef int (*rtems_print_printer)(void *, const char *format, va_list ap);
50 
55 struct rtems_printer {
56  void *context;
57  rtems_print_printer printer;
58 };
59 
67 static inline bool rtems_print_printer_valid(const rtems_printer *printer)
68 {
69  return printer != NULL && printer->printer != NULL;
70 }
71 
80 static inline void rtems_print_printer_empty(rtems_printer *printer)
81 {
82  printer->context = NULL;
83  printer->printer = NULL;
84 }
85 
92 
99 
106 void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file);
107 
115 
116 typedef struct {
117  rtems_id task;
119  rtems_chain_control free_buffers;
120  rtems_chain_control todo_buffers;
121  size_t task_stack_size;
122  rtems_task_priority task_priority;
123  int fd;
124  void *buffer_table;
125  size_t buffer_count;
126  size_t buffer_size;
128 
129 static inline void rtems_printer_task_initialize(
131 )
132 {
133  /*
134  * Some C++ compiler think that the structure is complex enough to need a
135  * proper constructor. Cast to void * to silence a warning.
136  */
137  memset( (void *) context, 0, sizeof( *context ) );
138 }
139 
140 static inline void rtems_printer_task_set_stack_size(
142  size_t stack_size
143 )
144 {
145  context->task_stack_size = stack_size;
146 }
147 
148 static inline void rtems_printer_task_set_priority(
150  rtems_task_priority priority
151 )
152 {
153  context->task_priority = priority;
154 }
155 
156 static inline void rtems_printer_task_set_file_descriptor(
158  int fd
159 )
160 {
161  context->fd = fd;
162 }
163 
164 static inline void rtems_printer_task_set_buffer_table(
166  void *buffer_table
167 )
168 {
169  context->buffer_table = buffer_table;
170 }
171 
172 static inline void rtems_printer_task_set_buffer_count(
174  size_t buffer_count
175 )
176 {
177  context->buffer_count = buffer_count;
178 }
179 
180 static inline void rtems_printer_task_set_buffer_size(
182  size_t buffer_size
183 )
184 {
185  context->buffer_size = buffer_size;
186 }
187 
205  rtems_printer *printer,
207 );
208 
222 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif /* _RTEMS_PRINTER_H */
#define RTEMS_INTERRUPT_LOCK_MEMBER(_designator)
%
Definition: intr.h:378
int rtems_print_printer_task(rtems_printer *printer, rtems_printer_task_context *context)
Creates a printer task.
void rtems_print_printer_printf(rtems_printer *printer)
Initializes the printer to print via printf().
void rtems_printer_task_drain(rtems_printer_task_context *context)
Drains the work queue of the printer task.
uint32_t rtems_task_priority
%
Definition: tasks.h:94
static bool rtems_print_printer_valid(const rtems_printer *printer)
check if the printer is valid.
Definition: printer.h:67
int(* rtems_print_printer)(void *, const char *format, va_list ap)
Definition: printer.h:49
void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file)
Initializes the printer to print via fprintf() using the specified file stream.
void rtems_print_printer_printk(rtems_printer *printer)
Initializes the printer to print via printk().
Definition: printk_plugin.c:34
void rtems_print_printer_fprintf_putc(rtems_printer *printer)
Initializes the printer to print via fprintf() using an unbuffered FILE stream with output through rt...
This header file defines the main parts of the Tasks Manager API.
This header file defines the Interrupt Manager API.
Chain API.
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
static void rtems_print_printer_empty(rtems_printer *printer)
Initializes the printer to print nothing.
Definition: printer.h:80