1 /******************************************************************************
2 @file mt_msg_dbg_core.c
4 @brief TIMAC 2.0 mt msg - debug decoder.
6 Group: WCS LPC
7 $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350, CC1352$
9 ******************************************************************************
10 $License: BSD3 2016 $
12 Copyright (c) 2015, Texas Instruments Incorporated
13 All rights reserved.
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions
17 are met:
19 * Redistributions of source code must retain the above copyright
20 notice, this list of conditions and the following disclaimer.
22 * Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in the
24 documentation and/or other materials provided with the distribution.
26 * Neither the name of Texas Instruments Incorporated nor the names of
27 its contributors may be used to endorse or promote products derived
28 from this software without specific prior written permission.
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ******************************************************************************
42 $Release Name: TI-15.4Stack Linux x64 SDK$
43 $Release Date: Sept 27, 2017 (2.04.00.13)$
44 *****************************************************************************/
46 #include "compiler.h"
47 #include "mt_msg.h"
48 #include "mt_msg_dbg.h"
49 #include "log.h"
50 #include "mutex.h"
51 #include "threads.h"
52 #include "stream.h"
53 #include "stream_socket.h"
54 #include "stream_uart.h"
55 #include "timer.h"
56 #include "ti_semaphore.h"
57 #include "fatal.h"
59 #include <stdarg.h>
60 #include <string.h>
61 #include <stdlib.h>
63 struct mt_msg_dbg *ALL_MT_MSG_DBG;
65 static void print_field(struct mt_msg_dbg_info *pV)
66 {
67 uint32_t v, a, b, c, d;
68 int n, x;
70 /* handle ... array of bytes type */
71 n = -1;
72 if (IS_FIELDTYPE_BYTES_N(pV->m_pCurField->m_fieldtype))
73 {
74 n = pV->m_pCurField->m_fieldtype - FIELDTYPE_BYTES_N(0);
75 }
76 if (IS_FIELDTYPE_MAXBYTES(pV->m_pCurField->m_fieldtype))
77 {
78 n = pV->m_pCurField->m_fieldtype - FIELDTYPE_MAXBYTES(0);
79 x = (pV->m_idx_end - pV->m_idx_cursor);
80 if( n > x )
81 {
82 n = x;
83 }
84 }
86 if( n >= 0 )
87 {
88 LOG_printf(LOG_ALWAYS, "%s: DBG: %s Byte: %2d | %s = ",
89 pV->m_pIface->dbg_name,
90 pV->m_pDbg->m_pktName,
91 pV->m_idx_cursor,
92 pV->m_pCurField->m_name);
93 for (a = 0; ((int)a) < n; a++ )
94 {
95 LOG_printf(LOG_ALWAYS, "%02x ",
96 (unsigned)(pV->m_pMsg->iobuf[pV->m_idx_cursor + a]));
97 }
98 LOG_printf(LOG_ALWAYS, "\n");
99 return;
100 }
102 a = b = c = d = v = 0;
103 LOG_printf(LOG_ALWAYS, "%s: DBG: %s Byte: %2d | %s = ",
104 pV->m_pIface->dbg_name,
105 pV->m_pDbg->m_pktName,
106 pV->m_idx_cursor,
107 pV->m_pCurField->m_name);
109 switch( pV->m_pCurField->m_fieldtype ){
110 default:
111 BUG_HERE("unknown field type? %d\n", pV->m_pCurField->m_fieldtype);
112 break;
113 case FIELDTYPE_U8:
114 a = pV->m_pMsg->iobuf[pV->m_idx_cursor + 0];
115 LOG_printf(LOG_ALWAYS, "% 3d (0x%02x)\n", (int)(a), (unsigned)(a));
116 pV->m_idx_cursor += 1;
117 break;
118 case FIELDTYPE_U16:
119 a = pV->m_pMsg->iobuf[pV->m_idx_cursor + 0];
120 b = pV->m_pMsg->iobuf[pV->m_idx_cursor + 1];
121 a = a + (b << 8);
122 LOG_printf(LOG_ALWAYS, "0x%04x\n", (unsigned)(a));
123 pV->m_idx_cursor += 2;
124 break;
125 case FIELDTYPE_U32:
126 a = pV->m_pMsg->iobuf[pV->m_idx_cursor + 0];
127 b = pV->m_pMsg->iobuf[pV->m_idx_cursor + 1];
128 c = pV->m_pMsg->iobuf[pV->m_idx_cursor + 2];
129 d = pV->m_pMsg->iobuf[pV->m_idx_cursor + 3];
130 a = a + (b << 8) + (c << 16) + (d << 24);
131 LOG_printf(LOG_ALWAYS, "0x%08x\n",
132 (unsigned)(a));
133 pV->m_idx_cursor += 4;
134 break;
135 }
136 }
138 /*
139 Decode & log a message for debug purposes
141 Public function in mt_msg.h
142 */
143 void MT_MSG_dbg_decode(struct mt_msg *pMsg,
144 struct mt_msg_interface *pIface,
145 struct mt_msg_dbg *pDbg)
146 {
147 struct mt_msg_dbg_info v;
148 int m;
150 if( pDbg == NULL )
151 {
152 /* We have no dbg info... so leave */
153 return;
154 }
155 /* if not enabled leave */
156 if( !LOG_test(LOG_DBG_MT_MSG_decode) ){
157 return;
158 }
161 memset((void *)(&v), 0, sizeof(v));
162 v.m_pMsg = pMsg;
163 v.m_pIface = pIface;
165 /* where is the data portion? */
166 v.m_idx_start = 0;
167 /* go past header */
168 if (v.m_pIface->frame_sync)
169 {
170 v.m_idx_start += 1;
171 }
173 if (v.m_pIface->len_2bytes)
174 {
175 v.m_idx_start += 2;
176 }
177 else
178 {
179 v.m_idx_start += 1;
180 }
181 /* cmd0/cmd1 */
182 v.m_idx_start += 2;
183 v.m_idx_end = v.m_idx_start + v.m_pMsg->expected_len;
185 /* setup cur */
186 v.m_idx_cursor = v.m_idx_start;
188 v.m_pDbg= pDbg;
189 while(v.m_pDbg)
190 {
191 m = 1;
192 if ( v.m_pDbg->m_cmd0 == -1)
193 {
194 /* -1 = match all */
195 } else if( v.m_pMsg->cmd0 != v.m_pDbg->m_cmd0 )
196 {
197 m = 0;
198 }
200 if (v.m_pDbg->m_cmd1 == -1)
201 {
202 /* -1 = match all */
203 }
204 else if (v.m_pMsg->cmd1 != v.m_pDbg->m_cmd1)
205 {
206 m = 0;
207 }
209 if( m )
210 {
211 break;
212 }
213 v.m_pDbg = v.m_pDbg->m_pNext;
214 }
216 if (v.m_pDbg == NULL)
217 {
218 LOG_printf(LOG_ALWAYS,
219 "%s: DBG: Unknown msg: 0x%02x 0x%02x\n",
220 v.m_pIface->dbg_name,
221 v.m_pMsg->cmd0, v.m_pMsg->cmd1);
222 return;
223 }
225 if (v.m_pDbg->m_pktName)
226 {
227 LOG_printf(LOG_ALWAYS, "%s: DBG: %s\n",
228 v.m_pIface->dbg_name, v.m_pDbg->m_pktName);
229 }
231 /* could be this msg has fields */
232 v.m_pCurField = v.m_pDbg->m_pFields;
233 if (v.m_pCurField == NULL)
234 {
235 /* no fields, no data */
236 if (v.m_pMsg->expected_len)
237 {
238 LOG_printf(LOG_ALWAYS, "%s: msg-len: %d no detail availabe\n",
239 v.m_pIface->dbg_name, v.m_pMsg->expected_len);
240 }
241 return;
242 }
244 while (v.m_pCurField)
245 {
246 print_field(&v);
247 v.m_pCurField = v.m_pCurField->m_pNext;
248 }
249 LOG_printf(LOG_ALWAYS,"%s: DBG %s: end\n",
250 v.m_pIface->dbg_name, v.m_pDbg->m_pktName);
251 }
254 /*
255 * ========================================
256 * Texas Instruments Micro Controller Style
257 * ========================================
258 * Local Variables:
259 * mode: c
260 * c-file-style: "bsd"
261 * tab-width: 4
262 * c-basic-offset: 4
263 * indent-tabs-mode: nil
264 * End:
265 * vim:set filetype=c tabstop=4 shiftwidth=4 expandtab=true
266 */