comparison services/etm/etm_api.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /********************************************************************************
2 * Enhanced TestMode (ETM)
3 * @file etm_api.c
4 *
5 * API for ETM SWE.
6 *
7 * @author Kim T. Peteren (ktp@ti.com)
8 * @version 0.1
9 *
10
11 *
12 * History:
13 *
14 * Date Modification
15 * ------------------------------------
16 * 11/06/2003 Creation
17 *
18 * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
19 *********************************************************************************/
20
21
22 #include "etm.h"
23 #include "etm_env.h"
24 #include "etm_messages_i.h"
25 #include "etm_trace.h"
26
27 #include "etm_misc.h"
28
29 #include "../../riviera/rvf/rvf_api.h"
30
31 #include <string.h>
32
33 extern T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk;
34
35
36 /********************************************************************************
37 * Registers the SWE to the ETM instance.
38 *
39 * This is a bridge function. It sends the T_ETM_REGISTRATION_REQ
40 * message to the ETM SWE.
41 * It is the first function that should be called.
42 *
43 * @return ETM_NOMEM in case of a memory error,
44 * the return value of rvf_send_msg otherwise.
45 *********************************************************************************/
46
47 int etm_register(char name[], int mid, int task_id, T_RVF_ADDR_ID addr_id,
48 ETM_CALLBACK_FUNC callback)
49 {
50 /* Type for a registration event. */
51 T_ETM_REGISTER_REQ *etm_registration_p;
52
53 tr_etm(TgTrEtmLow, "ETM API: _register bridge function(%s)", name);
54
55 /* Allocate the memory for the message to send */
56 if ((etm_registration_p = (T_ETM_REGISTER_REQ*)
57 etm_malloc(sizeof(T_ETM_REGISTER_REQ))) == NULL)
58 return ETM_NOMEM;
59
60 /* Fill the message id */
61 etm_registration_p->header.msg_id = ETM_REGISTER_REQ;
62
63 /* Fill the address source id */
64 etm_registration_p->header.src_addr_id = rvf_get_taskid();
65 etm_registration_p->header.dest_addr_id = etm_env_ctrl_blk->addr_id;
66 etm_registration_p->header.callback_func = NULL;
67
68 /* Fill the message parameters */
69 memcpy(etm_registration_p->name, name, strlen(name));
70 etm_registration_p->mid = mid;
71 etm_registration_p->task_id = task_id;
72 etm_registration_p->addr_id = addr_id;
73 etm_registration_p->rx_callback_func = callback;
74
75 /* Send the message using mailbox. */
76 return rvf_send_msg(etm_env_ctrl_blk->addr_id, (void*) etm_registration_p);
77 }
78
79
80 /********************************************************************************
81 * Cleans ETM register tables, i.e. set/clean the variable at their
82 * initialization state for a specific entity.
83 * This function can be used to reinitialize ETM register database without
84 * having to start/stop it.
85 *
86 * This is a bridge function. It sends ETM_UNREGISTER message to ETM.
87 *
88 * @return ETM_NOMEM in case of a memory error,
89 * the return value of rvf_send_msg otherwise.
90 *********************************************************************************/
91
92 int etm_unregister(char name[], int mid, int task_id, T_RVF_ADDR_ID addr_id, ETM_CALLBACK_FUNC callback)
93 {
94 /* Type for a start input event. */
95 T_ETM_UNREGISTER *etm_unregister_p;
96
97 tr_etm(TgTrEtmLow, "ETM API: _unregister bridge function");
98
99 /* Allocate the memory for the message to send */
100 if ((etm_unregister_p = (T_ETM_UNREGISTER*)
101 etm_malloc(sizeof(T_ETM_UNREGISTER))) == NULL)
102 return ETM_NOMEM;
103
104 /* Fill the message id */
105 etm_unregister_p->header.msg_id = ETM_UNREGISTER;
106
107 /* Fill the address source id */
108 etm_unregister_p->header.src_addr_id = rvf_get_taskid();
109 etm_unregister_p->header.dest_addr_id = etm_env_ctrl_blk->addr_id;
110 etm_unregister_p->header.callback_func = NULL;
111
112 /* Fill the message parameters */
113 memcpy(etm_unregister_p->name, name, strlen(name));
114 etm_unregister_p->mid = mid;
115 etm_unregister_p->task_id = task_id;
116 etm_unregister_p->addr_id = addr_id;
117 etm_unregister_p->rx_callback_func = callback;
118
119 /* Send the message using mailbox. */
120 return rvf_send_msg(etm_env_ctrl_blk->addr_id, (void*) etm_unregister_p);
121 }
122
123
124 /********************************************************************************
125 * Get data from a ETM packet structur. Get either 8, 16 or 32 value
126 * Used to unpack data
127 *
128 * This is helpers
129 *
130 * @return the return value of the point of the ETM packet.
131 *********************************************************************************/
132
133 int etm_get8(void *buf)
134 {
135 unsigned char *p = buf;
136
137 int value = *p;
138
139 tr_etm(TgTrEtmLow, "ETM API: _get8(%d)", value);
140
141 return value;
142 }
143
144 int etm_get16(void *buf)
145 {
146 unsigned char *p = buf;
147
148 int value = (p[0] | (p[1] << 8));
149
150 tr_etm(TgTrEtmLow, "ETM API: _get16(%d)", value);
151
152 return value;
153 }
154
155 int etm_get32(void *buf)
156 {
157 unsigned char *p = buf;
158 int value = 0;
159
160 value = *p;
161 p++;
162 value |= (*p << 8);
163 p++;
164 value |= (*p << 16);
165 p++;
166 value |= (*p << 24);
167
168 tr_etm(TgTrEtmLow, "ETM API: _get32(%d)", value);
169
170 return value;
171 }
172
173
174 /********************************************************************************
175 * Put data into a ETM packet structur. Put either 8, 16 or 32 value
176 * Used to pack data
177 *
178 * This is helpers
179 *
180 * @return Return ETM_PACKET of ETM_OK.
181 *********************************************************************************/
182
183 #define max_ul_data_size 240
184
185 int etm_pkt_put8(T_ETM_PKT *pkt, int value)
186 {
187 tr_etm(TgTrEtmLow, "ETM API: _pkt_put8(*, %d)", value);
188
189 if (pkt->index + 1 > max_ul_data_size)
190 return ETM_PACKET;
191
192 pkt->data[pkt->index] = value;
193 pkt->index += 1;
194
195 pkt->size += 1;
196
197 return ETM_OK;
198 }
199
200 int etm_pkt_put16(T_ETM_PKT *pkt, int value)
201 {
202 tr_etm(TgTrEtmLow, "ETM API: _pkt_put16(*, %d)", value);
203
204 if (pkt->index + 2 > max_ul_data_size)
205 return ETM_PACKET;
206
207 memcpy(&pkt->data[pkt->index], &value, 2);
208 pkt->index += 2;
209
210 pkt->size += 2;
211
212 return ETM_OK;
213 }
214
215 int etm_pkt_put32(T_ETM_PKT *pkt, int value)
216 {
217 tr_etm(TgTrEtmLow, "ETM API: _pkt_put32(*, %d)", value);
218
219 if (pkt->index + 4 > max_ul_data_size)
220 return ETM_PACKET;
221
222 memcpy(&pkt->data[pkt->index], &value, 4);
223 pkt->index += 4;
224
225 pkt->size += 4;
226
227 return ETM_OK;
228 }
229
230 int etm_pkt_putdata(T_ETM_PKT *pkt, const void *buf, int size)
231 {
232 tr_etm(TgTrEtmLow, "ETM API: _pkt_putdata(*, %d)", size);
233
234 if (pkt->index + size > max_ul_data_size)
235 return ETM_PACKET;
236 memcpy(&pkt->data[pkt->index], buf, size);
237 pkt->index += size;
238
239 pkt->size += size;
240
241 return ETM_OK;
242 }
243
244
245 /********************************************************************************
246 * This function is used to send an ETM Packet to the PC
247 *
248 * This is helpers
249 *
250 * @return Return value of rvf_send_trace_cpy.
251 *********************************************************************************/
252
253 int etm_pkt_send(T_ETM_PKT *pkt)
254 {
255 extern unsigned char etm_trace_user_id;
256 uint8 *buf, cksum = 0;
257 uint16 sendsize, size;
258 int error = ETM_OK;
259
260 buf = (uint8 *) &pkt->mid;
261 sendsize = size = pkt->size + 2; //one for mid, one for status
262
263 tr_etm(TgTrEtmLow, "ETM API: _pkt_send: size(%d)", sendsize);
264
265 while (size-- ) {
266 cksum ^= *buf++;
267 }
268 *buf = cksum;
269
270 sendsize += 1; // one for checksum
271
272 tr_etm_hexdump(TgTrEtmLow, &pkt->mid, sendsize);
273
274 error = rvt_send_trace_cpy((uint8 *) &pkt->mid, etm_trace_user_id,
275 sendsize, RVT_BINARY_FORMAT);
276 if(error < 0)
277 tr_etm(TgTrFatal, "ETM API: _pkt_send: ERROR(%d)", error);
278
279 return error;
280 }