carl9170 toolchain: update to gcc 9.2.0
[carl9170fw.git] / carlfw / include / printf.h
1 /*
2  * carl9170 firmware - used by the ar9170 wireless device
3  *
4  * printf and his friends...
5  *
6  * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7  * Copyright (c) 2007-2009 Atheros Communications, Inc.
8  * Copyright    2009    Johannes Berg <johannes@sipsolutions.net>
9  * Copyright 2009-2011  Christian Lamparter <chunkeey@googlemail.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; If not, see <http://www.gnu.org/licenses/>.
23  */
24
25 #ifndef __CARL9170FW_PRINTF_H
26 #define __CARL9170FW_PRINTF_H
27
28 #include <stdarg.h>
29 #include <string.h>
30 #include "config.h"
31 #include "carl9170.h"
32 #include "uart.h"
33 #include "fwcmd.h"
34
35 #ifdef CONFIG_CARL9170FW_PRINTF
36 void __attribute__((format (printf, 1, 2))) tfp_printf(const char *fmt, ...);
37
38 #define printf tfp_printf
39
40 #else
41 void __attribute__((format (printf, 1, 2))) min_printf(const char *fmt, ...);
42
43 #define printf min_printf
44 #endif /* CONFIG_CARL9170FW_PRINTF */
45
46 #define PRINT(fmt, args...)                                             \
47         do {                                                            \
48                 printf(fmt, ## args);                                   \
49         } while (0)
50
51 #define INFO(fmt, args...)      PRINT(fmt, ## args)
52
53 #define ERR(fmt, args...)       PRINT(CARL9170_ERR_MAGIC fmt, ## args)
54
55 #ifdef CONFIG_CARL9170FW_DEBUG
56 #define DBG(fmt, args...)       PRINT(fmt, ## args)
57 #else
58 #define DBG(...)                do { } while (0);
59 #endif
60
61 /*
62  * NB: even though the MACRO is called "stall". It isn't supposed
63  * to stall since this will render the device unresponsive, until
64  * someone pulls the plug.
65  */
66 #define STALL()
67
68 #define BUG(fmt, args...)                                               \
69         do {                                                            \
70                 PRINT(CARL9170_BUG_MAGIC" %s()@%d \"" fmt "\"" ,        \
71                       __func__, __LINE__, ## args);                     \
72                 STALL()                                                 \
73         } while (0);
74
75 #define BUG_ON(condition)                                               \
76         ({                                                              \
77                 int __ret = !!(condition);                              \
78                 if (unlikely(!!(__ret)))                                \
79                         BUG(#condition);                                \
80                 (__ret);                                                \
81         })
82
83 static inline __inline void putcharacter(const char c __unused)
84 {
85 #ifdef CONFIG_CARL9170FW_DEBUG_USB
86         usb_putc(c);
87 #endif /* CONFIG_CARL9170FW_DEBUG_USB */
88
89 #ifdef CONFIG_CARL9170FW_DEBUG_UART
90         uart_putc(c);
91 #endif /* CONFIG_CARL9170FW_DEBUG_UART */
92 }
93
94 static inline __inline void print_hex_dump(const void *buf __unused, int len __unused)
95 {
96 #ifdef CONFIG_CARL9170FW_DEBUG_USB
97         usb_print_hex_dump(buf, len);
98 #endif /* CONFIG_CARL9170FW_DEBUG_USB */
99
100 #ifdef CONFIG_CARL9170FW_DEBUG_UART
101         uart_print_hex_dump(buf, len);
102 #endif /* CONFIG_CARL9170FW_DEBUG_UART */
103 }
104
105 #endif /* __CARL9170FW_PRINTF_H */
106