Hardware Libraries  20.1
Stratix 10 SoC Hardware Manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
alt_printf.h
1 /******************************************************************************
2 *
3 * Copyright 2013-2017 Altera Corporation. All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 ******************************************************************************/
32 
33 #if !defined(ALT_PRINTF_H)
34 #define ALT_PRINTF_H
35 #include <stdio.h>
36 #include <stddef.h>
37 #include <stdarg.h>
38 #include <inttypes.h>
39 
40 
41 typedef struct ALT_PRINTF_MEM_INFO_s
42 {
43  void (*putc_function)(char pchar,FILE * info);
44  int (*getc_function)(FILE * info);
45  char *toptr;
46  char *maxptr;
47 } ALT_PRINTF_MEM_INFO_t;
48 
49 #ifndef DEFAULT_TERM
50  #ifdef soc_a10
51  #define DEFAULT_TERM term1
52  #define DEFAULT_UART_INT ALT_INT_INTERRUPT_UART1
53  #define pdefault_term_info term1_info
54  #else
55  #define DEFAULT_TERM term0
56  #define DEFAULT_UART_INT ALT_INT_INTERRUPT_UART0
57  #define pdefault_term_info term0_info
58  #endif
59 #endif
60 
61 extern FILE *term0;
62 extern FILE *term1;
63 
64 static __inline int null_printf(const char *format, ...)
65  {(void)format;return 0;}
66 static __inline int null_vfprintf(FILE *stream, const char *format, va_list args)
67  {(void)stream;(void)format;(void)args;return 0;}
68 
69 #if defined (PRINTF_HOST)
70  #define ALT_PRINTF printf
71  #define alt_printf printf
72 #else
73  #define snprintf alt_snprintf
74  #define ALT_SNPRINTF alt_snprintf
75  #define sprintf alt_sprintf
76  #define ALT_SPRINTF alt_sprintf
77 
78  #if defined (PRINTF_UART)
79  #define ALT_PRINTF printf
80  #define alt_printf printf
81  #define alt_fprintf fprintf
82  #define alt_fputs fputs
83  #define alt_puts puts
84  #define alt_putc putc
85  #define alt_fputc fputc
86  #define alt_vfprintf vfprintf
87  #define alt_fwrite fwrite
88  #define alt_fgetc fgetc
89  #define alt_fgets fgets
90  #else
91  #define ALT_PRINTF null_printf
92  #define printf null_printf
93  #define vprintf null_vfprintf
94  #endif /* PRINTF_UART */
95 #endif /* PRINTF_HOST */
96 
97 char *alt_fgets(char * str, int num, FILE *stream);
98 int alt_fgetc(FILE *stream);
99 int alt_printf(const char *format, ...);
100 int alt_snprintf(char *to, size_t n, const char *format, ...);
101 int alt_sprintf(char *to, const char *format, ...);
102 int alt_fprintf(FILE *stream, const char *format, ...);
103 int alt_vfprintf(FILE *stream, const char *format, va_list args);
104 void alt_log_done(FILE *);
105 int alt_fputs(const char *str, FILE *stream);
106 int alt_puts(const char *str);
107 size_t alt_fwrite(const void *ptr, size_t size, size_t count, FILE *stream);
108 
109 
110 #endif /* ALT_PRINTF_H */