1 /*
2  *  Routines to access hardware
3  *
4  *  Copyright (c) 2013 Realtek Semiconductor Corp.
5  *
6  *  This module is a confidential and proprietary property of RealTek and
7  *  possession or use of this module requires written permission of RealTek.
8  */
9 
10 #ifndef _DIAG_H_
11 #define _DIAG_H_
12 
13 #include "platform_autoconf.h"
14 #include "basic_types.h"
15 #include "rtl_trace.h"
16 
17 u32 DiagPrintf(const char *fmt, ...);
18 u32 DiagPrintfD(const char *fmt, ...);
19 int DiagVSprintf(char *buf, const char *fmt, const int *dp);
20 
21 
22 /** @addtogroup Ameba_Platform
23   * @{
24   */
25 
26 /** @defgroup Platform_Debug Debug
27   * @brief Platform_Debug modules
28   * @{
29   */
30 
31 /** @defgroup Platform_Debug_Log_Trace_Exported_Types Log Trace Types
32   * @{
33   */
34 /** @brief Log Module Definition */
35 typedef enum {
36 	MODULE_OS			= 0,  /**< FreeRTOS */
37 	MODULE_BOOT		= 1,  /**< bootloader */
38 	MODULE_GDMA		= 2,  /**< gdma */
39 	MODULE_GPIO		= 3,  /**< gpio */
40 	MODULE_TIMER		= 4,  /**< timer */
41 	MODULE_I2C			= 5,  /**< i2c */
42 	MODULE_I2S			= 6,  /**< i2s */
43 	MODULE_PWM		= 7,  /**< pwm */
44 	MODULE_SDIO		= 8,  /**< sdio */
45 	MODULE_SPI			= 9,  /**< spi */
46 	MODULE_FLASH		= 10, /**< flash */
47 	MODULE_UART		= 11, /**< uart */
48 	MODULE_USB_OTG	= 12, /**< usb otg */
49 	MODULE_IPSEC		= 13, /**< ipsec */
50 	MODULE_ADC		= 14, /**< adc */
51 	MODULE_EFUSE		= 15, /**< efuse */
52 	MODULE_MONIT		= 16, /**< monitor */
53 	MODULE_MISC		= 17, /**< misc */
54 	MODULE_IR			= 18,
55 	MODULE_QDECODE	= 19,
56 	MODULE_KEYSCAN	= 20,
57 	MODULE_SGPIO		= 21,
58 	MODULE_AUDIO		= 22,
59 	MODULE_LCD		= 23,
60 	MODULE_WIFIFW	= 24,
61 	MODULE_BT			= 25,
62 	MODULE_IPC			= 26,
63 	MODULE_KM4		= 27,
64 
65 	MODULE_NUMs		= 32 /**< Module Number */
66 } MODULE_DEFINE;
67 
68 /** @brief Log Level Definition */
69 typedef enum {
70 	LEVEL_ERROR	= 0, /**< Error */
71 	LEVEL_WARN	= 1, /**< Warning */
72 	LEVEL_INFO		= 2, /**< Information */
73 	LEVEL_TRACE	= 3, /**< Trace Data */
74 	LEVEL_NUMs		= 4  /**< Level Number */
75 } LEVEL_DEFINE;
76 /** End of Platform_Debug_Log_Trace_Exported_Types
77   * @}
78   */
79 
80 /** @defgroup Platform_Debug_Log_Trace_Functions_And_Macro Function & Macro
81   * @{
82   */
83 
84 /** @cond private */
85 /** @brief  Debug Log mask */
86 extern u32 ConfigDebug[];
87 /** @endcond */
88 
89 /**
90   * @brief  Debug Log Mask Set.
91   * @param  config[4] --  Print log if bit MODULE_DEFINE of config[LEVEL_DEFINE] is 1;
92   * @return void.
93   * @note   Here is a MODULE_BOOT module sample to demostrate the using of LOG_MASK().
94   *         We want to print log under ERROR level and INFO level.
95   * @code{.c}
96   * u32 debug[4];
97   * debug[LEVEL_ERROR] = BIT(MODULE_BOOT);
98   * debug[LEVEL_WARN]  = 0x0;
99   * debug[LEVEL_INFO]  = BIT(MODULE_BOOT);
100   * debug[LEVEL_TRACE] = 0x0;
101   *
102   * LOG_MASK(LEVEL_ERROR, debug[LEVEL_ERROR]);
103   * LOG_MASK(LEVEL_WARN, debug[LEVEL_WARN]);
104   * LOG_MASK(LEVEL_INFO, debug[LEVEL_INFO]);
105   * LOG_MASK(LEVEL_TRACE, debug[LEVEL_TRACE]);
106   *
107   * DBG_PRINTF(MODULE_BOOT, LEVEL_INFO, "MODULE_BOOT Info.\n");
108   * DBG_PRINTF(MODULE_BOOT, LEVEL_ERROR, "MODULE_BOOT Error!\n");
109   * @endcode
110   */
111 #define LOG_MASK(level, config) do {\
112 		ConfigDebug[level] = config;\
113 } while (0)
114 
115 #define LOG_MASK_MODULE(module, level, new_status) do {\
116 	if (new_status == ENABLE) { \
117 		ConfigDebug[level] |= BIT(module); \
118 	} else { \
119 		ConfigDebug[level] &= ~BIT(module); \
120 	} \
121 } while (0)
122 
123 /**
124   * @brief  DBG_PRINTF is used to print log
125   */
126 //#define RELEASE_VERSION
127 #ifdef RELEASE_VERSION
128 #define DBG_PRINTF(MODULE, LEVEL, pFormat, ...)     do {\
129 		if ((LEVEL < LEVEL_NUMs) && (MODULE < MODULE_NUMs) && (ConfigDebug[LEVEL] & BIT(MODULE))) {\
130 		}\
131 	}while(0)
132 #else
133 #define DBG_PRINTF(MODULE, LEVEL, pFormat, ...)     do {\
134    if ((LEVEL < LEVEL_NUMs) && (MODULE < MODULE_NUMs) && (ConfigDebug[LEVEL] & BIT(MODULE)))\
135         DiagPrintf("["#MODULE"-"#LEVEL"]:"pFormat, ##__VA_ARGS__);\
136 }while(0)
137 #endif
138 
139 #define DBG_ERR_MSG_ON(x)       (ConfigDebug[LEVEL_ERROR] |= BIT(x))
140 #define DBG_WARN_MSG_ON(x)      (ConfigDebug[LEVEL_WARN] |= BIT(x))
141 #define DBG_INFO_MSG_ON(x)      (ConfigDebug[LEVEL_INFO] |= BIT(x))
142 
143 #define DBG_ERR_MSG_OFF(x)      (ConfigDebug[LEVEL_ERROR] &= ~BIT(x))
144 #define DBG_WARN_MSG_OFF(x)     (ConfigDebug[LEVEL_WARN] &= ~BIT(x))
145 #define DBG_INFO_MSG_OFF(x)     (ConfigDebug[LEVEL_INFO] &= ~BIT(x))
146 #define DRIVER_PREFIX	"RTL8721D[Driver]: "
147 
148 #ifdef CONFIG_DEBUG_LOG
149 #define DBG_8195A(...)     do {\
150     if (unlikely(ConfigDebug[LEVEL_ERROR] & BIT(MODULE_MISC))) \
151         DiagPrintf("\r" __VA_ARGS__);\
152 }while(0)
153 
154 #define MONITOR_LOG(...)     do {\
155      if (unlikely(ConfigDebug[LEVEL_ERROR] & BIT(MODULE_MONIT))) \
156         DiagPrintf( __VA_ARGS__);\
157 }while(0)
158 
159 #else   // else of "#if CONFIG_DEBUG_LOG"
160 #define DBG_8195A(...)
161 #define MONITOR_LOG(...)
162 #endif
163 
164 /** End of Platform_Debug_Log_Trace_Functions_And_Macro
165   * @}
166   */
167 
168 /** End of Platform_Debug
169   * @}
170   */
171 
172 /** End of AmebaZ_Platform
173   * @}
174   */
175 
176 extern u32 ConfigDebugBuffer;
177 extern u32 ConfigDebugClose;
178 extern u32 ConfigDebug[];
179 
180 
181 #endif //_DIAG_H_
182