SimpleLink CC3120/CC3220 Host Driver  Version 2.0.1.15
Simplifies the implementation of Internet connectivity
trace.h
1 /*
2  * Copyright (C) 2016 Texas Instruments Incorporated
3  *
4  * All rights reserved. Property of Texas Instruments Incorporated.
5  * Restricted rights to use, duplicate or disclose this code are
6  * granted through contract.
7  *
8  * The program may not be used without the written permission of
9  * Texas Instruments Incorporated or against the terms and conditions
10  * stipulated in the agreement under which this program has been supplied,
11  * and under no circumstances can it be used with non-TI connectivity device.
12  *
13  */
14 
15 
16 
17 #include <ti/drivers/net/wifi/simplelink.h>
18 
19 #ifndef __SIMPLELINK_TRACE_H__
20 #define __SIMPLELINK_TRACE_H__
21 
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /*****************************************************************************/
28 /* Macro declarations */
29 /*****************************************************************************/
30 
31 #define SL_SYNC_SCAN_THRESHOLD (( _u32 )2000)
32 
33 #ifdef SL_TINY
34 #define _SlDrvAssert(line ) { while(1); }
35 #else
36 #define _SlDrvAssert() _SlDrvHandleFatalError(SL_DEVICE_EVENT_FATAL_DRIVER_ABORT, 0, 0)
37 #endif
38 
39 #define _SL_ASSERT(expr) { if(!(expr)){ \
40  _SlDrvAssert(); } \
41 }
42 #define _SL_ERROR(expr, error) { if(!(expr)){return (error); } }
43 
44 #define SL_HANDLING_ASSERT 2
45 #define SL_HANDLING_ERROR 1
46 #define SL_HANDLING_NONE 0
47 
48 #ifndef SL_TINY
49 #define SL_SELF_COND_HANDLING SL_HANDLING_ASSERT
50 #define SL_PROTOCOL_HANDLING SL_HANDLING_ASSERT
51 #define SL_DRV_RET_CODE_HANDLING SL_HANDLING_ERROR
52 #define SL_NWP_IF_HANDLING SL_HANDLING_ASSERT
53 #define SL_OSI_RET_OK_HANDLING SL_HANDLING_ERROR
54 #define SL_MALLOC_OK_HANDLING SL_HANDLING_ASSERT
55 #define SL_USER_ARGS_HANDLING SL_HANDLING_ASSERT
56 #define SL_ERR_IN_PROGRESS_HANDLING SL_HANDLING_ERROR
57 #define SL_ERR_IN_API_ALLOWED SL_HANDLING_ERROR
58 #else
59 #define SL_SELF_COND_HANDLING SL_HANDLING_NONE
60 #define SL_PROTOCOL_HANDLING SL_HANDLING_NONE
61 #define SL_DRV_RET_CODE_HANDLING SL_HANDLING_NONE
62 #define SL_NWP_IF_HANDLING SL_HANDLING_NONE
63 #define SL_OSI_RET_OK_HANDLING SL_HANDLING_NONE
64 #define SL_MALLOC_OK_HANDLING SL_HANDLING_NONE
65 #define SL_USER_ARGS_HANDLING SL_HANDLING_NONE
66 #define SL_ERR_IN_PROGRESS_HANDLING SL_HANDLING_NONE
67 #define SL_ERR_IN_API_ALLOWED SL_HANDLING_NONE
68 #endif
69 
70 
71 #if (SL_ERR_IN_PROGRESS_HANDLING == SL_HANDLING_ERROR)
72 #define VERIFY_NO_ERROR_HANDLING_IN_PROGRESS() { \
73  if (SL_IS_RESTART_REQUIRED) return SL_API_ABORTED; }
74 #else
75 #define VERIFY_NO_ERROR_HANDLING_IN_PROGRESS()
76 #endif
77 
78 #if (SL_ERR_IN_API_ALLOWED == SL_HANDLING_ERROR)
79 #define VERIFY_API_ALLOWED(Silo) { \
80  _SlReturnVal_t status = _SlDrvDriverIsApiAllowed(Silo); \
81  if ( status ) return status; }
82 #else
83 #define VERIFY_API_ALLOWED(Silo)
84 #endif
85 
86 #if (SL_DRV_RET_CODE_HANDLING == SL_HANDLING_ASSERT)
87 #define VERIFY_RET_OK(Func) {_SlReturnVal_t _RetVal = (Func); _SL_ASSERT((_SlReturnVal_t)SL_OS_RET_CODE_OK == _RetVal)}
88 #elif (SL_DRV_RET_CODE_HANDLING == SL_HANDLING_ERROR)
89 #define VERIFY_RET_OK(Func) {_SlReturnVal_t _RetVal = (Func); if (SL_OS_RET_CODE_OK != _RetVal) return (_SlReturnVal_t)_RetVal;}
90 #else
91 #define VERIFY_RET_OK(Func) (Func);
92 #endif
93 
94 #if (SL_PROTOCOL_HANDLING == SL_HANDLING_ASSERT)
95 #define VERIFY_PROTOCOL(expr) _SL_ASSERT(expr)
96 #elif (SL_PROTOCOL_HANDLING == SL_HANDLING_ERROR)
97 #define VERIFY_PROTOCOL(expr) _SL_ERROR(expr, SL_RET_CODE_PROTOCOL_ERROR)
98 #else
99 #define VERIFY_PROTOCOL(expr)
100 #endif
101 
102 #if (defined(PROTECT_SOCKET_ASYNC_RESP) && (SL_SELF_COND_HANDLING == SL_HANDLING_ASSERT))
103 #define VERIFY_SOCKET_CB(expr) _SL_ASSERT(expr)
104 #elif (defined(PROTECT_SOCKET_ASYNC_RESP) && (SL_SELF_COND_HANDLING == SL_HANDLING_ERROR))
105 #define VERIFY_SOCKET_CB(expr) _SL_ERROR(expr, SL_RET_CODE_SELF_ERROR)
106 #else
107 #define VERIFY_SOCKET_CB(expr)
108 #endif
109 
110 #if (SL_NWP_IF_HANDLING == SL_HANDLING_ASSERT)
111 #define NWP_IF_WRITE_CHECK(fd,pBuff,len) { _i16 RetSize, ExpSize = (_i16)(len); RetSize = sl_IfWrite((fd),(pBuff),ExpSize); _SL_ASSERT(ExpSize == RetSize)}
112 #define NWP_IF_READ_CHECK(fd,pBuff,len) { _i16 RetSize, ExpSize = (_i16)(len); RetSize = sl_IfRead((fd),(pBuff),ExpSize); _SL_ASSERT(ExpSize == RetSize)}
113 #elif (SL_NWP_IF_HANDLING == SL_HANDLING_ERROR)
114 #define NWP_IF_WRITE_CHECK(fd,pBuff,len) { _SL_ERROR((len == sl_IfWrite((fd),(pBuff),(len))), SL_RET_CODE_NWP_IF_ERROR);}
115 #define NWP_IF_READ_CHECK(fd,pBuff,len) { _SL_ERROR((len == sl_IfRead((fd),(pBuff),(len))), SL_RET_CODE_NWP_IF_ERROR);}
116 #else
117 #define NWP_IF_WRITE_CHECK(fd,pBuff,len) { sl_IfWrite((fd),(pBuff),(len));}
118 #define NWP_IF_READ_CHECK(fd,pBuff,len) { sl_IfRead((fd),(pBuff),(len));}
119 #endif
120 
121 #if (SL_OSI_RET_OK_HANDLING == SL_HANDLING_ASSERT)
122 #define OSI_RET_OK_CHECK(Func) {_SlReturnVal_t _RetVal = (Func); _SL_ASSERT((_SlReturnVal_t)SL_OS_RET_CODE_OK == _RetVal)}
123 #elif (SL_OSI_RET_OK_HANDLING == SL_HANDLING_ERROR)
124 #define OSI_RET_OK_CHECK(Func) {_SlReturnVal_t _RetVal = (Func); if (SL_OS_RET_CODE_OK != _RetVal) return _RetVal;}
125 #else
126 #define OSI_RET_OK_CHECK(Func) (Func);
127 #endif
128 
129 #if (SL_MALLOC_OK_HANDLING == SL_HANDLING_ASSERT)
130 #define MALLOC_OK_CHECK(Ptr) _SL_ASSERT(NULL != Ptr)
131 #elif (SL_MALLOC_OK_HANDLING == SL_HANDLING_ERROR)
132 #define MALLOC_OK_CHECK(Ptr) _SL_ERROR((NULL != Ptr), SL_RET_CODE_MALLOC_ERROR)
133 #else
134 #define MALLOC_OK_CHECK(Ptr)
135 #endif
136 
137 #ifdef SL_INC_ARG_CHECK
138 
139 #if (SL_USER_ARGS_HANDLING == SL_HANDLING_ASSERT)
140 #define ARG_CHECK_PTR(Ptr) _SL_ASSERT(NULL != Ptr)
141 #elif (SL_USER_ARGS_HANDLING == SL_HANDLING_ERROR)
142 #define ARG_CHECK_PTR(Ptr) _SL_ERROR((NULL != Ptr), SL_RET_CODE_INVALID_INPUT)
143 #else
144 #define ARG_CHECK_PTR(Ptr)
145 #endif
146 
147 #else
148 #define ARG_CHECK_PTR(Ptr)
149 #endif
150 
151 /*#define SL_DBG_TRACE_ENABLE*/
152 #ifdef SL_DBG_TRACE_ENABLE
153 #define SL_TRACE0(level,msg_id,str) printf(str)
154 #define SL_TRACE1(level,msg_id,str,p1) printf(str,(p1))
155 #define SL_TRACE2(level,msg_id,str,p1,p2) printf(str,(p1),(p2))
156 #define SL_TRACE3(level,msg_id,str,p1,p2,p3) printf(str,(p1),(p2),(p3))
157 #define SL_TRACE4(level,msg_id,str,p1,p2,p3,p4) printf(str,(p1),(p2),(p3),(p4))
158 #define SL_ERROR_TRACE(msg_id,str) printf(str)
159 #define SL_ERROR_TRACE1(msg_id,str,p1) printf(str,(p1))
160 #define SL_ERROR_TRACE2(msg_id,str,p1,p2) printf(str,(p1),(p2))
161 #define SL_ERROR_TRACE3(msg_id,str,p1,p2,p3) printf(str,(p1),(p2),(p3))
162 #define SL_ERROR_TRACE4(msg_id,str,p1,p2,p3,p4) printf(str,(p1),(p2),(p3),(p4))
163 #define SL_TRACE_FLUSH()
164 #else
165 #define SL_TRACE0(level,msg_id,str)
166 #define SL_TRACE1(level,msg_id,str,p1)
167 #define SL_TRACE2(level,msg_id,str,p1,p2)
168 #define SL_TRACE3(level,msg_id,str,p1,p2,p3)
169 #define SL_TRACE4(level,msg_id,str,p1,p2,p3,p4)
170 #define SL_ERROR_TRACE(msg_id,str)
171 #define SL_ERROR_TRACE1(msg_id,str,p1)
172 #define SL_ERROR_TRACE2(msg_id,str,p1,p2)
173 #define SL_ERROR_TRACE3(msg_id,str,p1,p2,p3)
174 #define SL_ERROR_TRACE4(msg_id,str,p1,p2,p3,p4)
175 #define SL_TRACE_FLUSH()
176 #endif
177 
178 /* #define SL_DBG_CNT_ENABLE */
179 #ifdef SL_DBG_CNT_ENABLE
180 #define _SL_DBG_CNT_INC(Cnt) g_DbgCnt. ## Cnt++
181 #define _SL_DBG_SYNC_LOG(index,value) {if(index < SL_DBG_SYNC_LOG_SIZE){*(_u32 *)&g_DbgCnt.SyncLog[index] = *(_u32 *)(value);}}
182 
183 #else
184 #define _SL_DBG_CNT_INC(Cnt)
185 #define _SL_DBG_SYNC_LOG(index,value)
186 #endif
187 
188 #define SL_DBG_LEVEL_1 1
189 #define SL_DBG_LEVEL_2 2
190 #define SL_DBG_LEVEL_3 4
191 #define SL_DBG_LEVEL_MASK (SL_DBG_LEVEL_2|SL_DBG_LEVEL_3)
192 
193 #define SL_INCLUDE_DBG_FUNC(Name) ((Name ## _DBG_LEVEL) & SL_DBG_LEVEL_MASK)
194 
195 #define _SlDrvPrintStat_DBG_LEVEL SL_DBG_LEVEL_3
196 #define _SlDrvOtherFunc_DBG_LEVEL SL_DBG_LEVEL_1
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 
203 #endif /*__SIMPLELINK_TRACE_H__*/
204