summaryrefslogtreecommitdiffstats
path: root/carl9170fw/carlfw/include/printf.h
blob: dd4559e28ec5994562e9a978a62c554e087645a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * carl9170 firmware - used by the ar9170 wireless device
 *
 * printf and his friends...
 *
 * Copyright (c) 2000-2005 ZyDAS Technology Corporation
 * Copyright (c) 2007-2009 Atheros Communications, Inc.
 * Copyright	2009	Johannes Berg <johannes@sipsolutions.net>
 * Copyright 2009-2011	Christian Lamparter <chunkeey@googlemail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __CARL9170FW_PRINTF_H
#define __CARL9170FW_PRINTF_H

#include <stdarg.h>
#include <string.h>
#include "config.h"
#include "carl9170.h"
#include "uart.h"
#include "fwcmd.h"

#ifdef CONFIG_CARL9170FW_PRINTF
void __attribute__((format (printf, 1, 2))) tfp_printf(const char *fmt, ...);

#define printf tfp_printf

#else
void __attribute__((format (printf, 1, 2))) min_printf(const char *fmt, ...);

#define printf min_printf
#endif /* CONFIG_CARL9170FW_PRINTF */

#define PRINT(fmt, args...)						\
	do {								\
		printf(fmt, ## args);					\
	} while (0)

#define INFO(fmt, args...)	PRINT(fmt, ## args)

#define ERR(fmt, args...)	PRINT(CARL9170_ERR_MAGIC fmt, ## args)

#ifdef CONFIG_CARL9170FW_DEBUG
#define DBG(fmt, args...)	PRINT(fmt, ## args)
#else
#define DBG(...)		do { } while (0);
#endif

/*
 * NB: even though the MACRO is called "stall". It isn't supposed
 * to stall since this will render the device unresponsive, until
 * someone pulls the plug.
 */
#define STALL()

#define BUG(fmt, args...)						\
	do {								\
		PRINT(CARL9170_BUG_MAGIC" %s()@%d \"" fmt "\"" ,	\
		      __func__, __LINE__, ## args);			\
		STALL()							\
	} while (0);

#define BUG_ON(condition)						\
	({								\
		int __ret = !!(condition);				\
		if (unlikely(!!(__ret)))				\
			BUG(#condition);				\
		(__ret);						\
	})

static inline __inline void putcharacter(const char c __unused)
{
#ifdef CONFIG_CARL9170FW_DEBUG_USB
	usb_putc(c);
#endif /* CONFIG_CARL9170FW_DEBUG_USB */

#ifdef CONFIG_CARL9170FW_DEBUG_UART
	uart_putc(c);
#endif /* CONFIG_CARL9170FW_DEBUG_UART */
}

static inline __inline void print_hex_dump(const void *buf __unused, int len __unused)
{
#ifdef CONFIG_CARL9170FW_DEBUG_USB
	usb_print_hex_dump(buf, len);
#endif /* CONFIG_CARL9170FW_DEBUG_USB */

#ifdef CONFIG_CARL9170FW_DEBUG_UART
	uart_print_hex_dump(buf, len);
#endif /* CONFIG_CARL9170FW_DEBUG_UART */
}

#endif /* __CARL9170FW_PRINTF_H */