FreeCalypso > hg > freecalypso-sw
comparison gsm-fw/services/etm/etm_api.c @ 164:d78219c43fbf
gsm-fw/services/etm: initial import from the Leonardo semi-src
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 18 Nov 2013 06:39:44 +0000 |
parents | |
children | 9dbf3248a197 |
comparison
equal
deleted
inserted
replaced
163:5e0e41cd7c9f | 164:d78219c43fbf |
---|---|
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/etm.h" | |
23 #include "etm/etm_env.h" | |
24 #include "etm/etm_messages_i.h" | |
25 #include "etm/etm_trace.h" | |
26 | |
27 #include "etm/etm_misc.h" | |
28 | |
29 #include "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, ETM_CALLBACK_FUNC callback) | |
48 { | |
49 /* Type for a registration event. */ | |
50 T_ETM_REGISTER_REQ *etm_registration_p; | |
51 | |
52 tr_etm(TgTrEtmLow, "ETM API: _register bridge function(%s)", name); | |
53 | |
54 /* Allocate the memory for the message to send */ | |
55 if ((etm_registration_p = (T_ETM_REGISTER_REQ*) etm_malloc(sizeof(T_ETM_REGISTER_REQ))) == NULL) | |
56 return ETM_NOMEM; | |
57 | |
58 /* Fill the message id */ | |
59 etm_registration_p->header.msg_id = ETM_REGISTER_REQ; | |
60 | |
61 /* Fill the address source id */ | |
62 etm_registration_p->header.src_addr_id = rvf_get_taskid(); | |
63 etm_registration_p->header.dest_addr_id = etm_env_ctrl_blk->addr_id; | |
64 etm_registration_p->header.callback_func = NULL; | |
65 | |
66 /* Fill the message parameters */ | |
67 memcpy(etm_registration_p->name, name, strlen(name)); | |
68 etm_registration_p->mid = mid; | |
69 etm_registration_p->task_id = task_id; | |
70 etm_registration_p->addr_id = addr_id; | |
71 etm_registration_p->rx_callback_func = callback; | |
72 | |
73 /* Send the message using mailbox. */ | |
74 return rvf_send_msg(etm_env_ctrl_blk->addr_id, | |
75 (void*) etm_registration_p); | |
76 } | |
77 | |
78 | |
79 /******************************************************************************** | |
80 * Cleans ETM register tables, i.e. set/clean the variable at their initialization | |
81 * state for a specific entity. | |
82 * This function can be used to reinitialize ETM register database without having to | |
83 * start/stop it. | |
84 * | |
85 * This is a bridge function. It sends ETM_UNREGISTER message to ETM. | |
86 * | |
87 * @return ETM_NOMEM in case of a memory error, | |
88 * the return value of rvf_send_msg otherwise. | |
89 *********************************************************************************/ | |
90 | |
91 int etm_unregister(char name[], int mid, int task_id, T_RVF_ADDR_ID addr_id, ETM_CALLBACK_FUNC callback) | |
92 { | |
93 /* Type for a start input event. */ | |
94 T_ETM_UNREGISTER *etm_unregister_p; | |
95 | |
96 tr_etm(TgTrEtmLow, "ETM API: _unregister bridge function"); | |
97 | |
98 /* Allocate the memory for the message to send */ | |
99 if ((etm_unregister_p = (T_ETM_UNREGISTER*) etm_malloc(sizeof(T_ETM_UNREGISTER))) == NULL) | |
100 return ETM_NOMEM; | |
101 | |
102 /* Fill the message id */ | |
103 etm_unregister_p->header.msg_id = ETM_UNREGISTER; | |
104 | |
105 /* Fill the address source id */ | |
106 etm_unregister_p->header.src_addr_id = rvf_get_taskid(); | |
107 etm_unregister_p->header.dest_addr_id = etm_env_ctrl_blk->addr_id; | |
108 etm_unregister_p->header.callback_func = NULL; | |
109 | |
110 /* Fill the message parameters */ | |
111 memcpy(etm_unregister_p->name, name, strlen(name)); | |
112 etm_unregister_p->mid = mid; | |
113 etm_unregister_p->task_id = task_id; | |
114 etm_unregister_p->addr_id = addr_id; | |
115 etm_unregister_p->rx_callback_func = callback; | |
116 | |
117 /* Send the message using mailbox. */ | |
118 return rvf_send_msg(etm_env_ctrl_blk->addr_id, | |
119 (void*) etm_unregister_p); | |
120 } | |
121 | |
122 | |
123 /******************************************************************************** | |
124 * Get data from a ETM packet structur. Get either 8, 16 or 32 value | |
125 * Used to unpack data | |
126 * | |
127 * This is helpers | |
128 * | |
129 * @return the return value of the point of the ETM packet. | |
130 *********************************************************************************/ | |
131 | |
132 int etm_get8(void *buf) | |
133 { | |
134 unsigned char *p = buf; | |
135 | |
136 int value = *p; | |
137 | |
138 tr_etm(TgTrEtmLow, "ETM API: _get8(%d)", value); | |
139 | |
140 return value; | |
141 } | |
142 | |
143 int etm_get16(void *buf) | |
144 { | |
145 unsigned char *p = buf; | |
146 | |
147 int value = | |
148 (*p++ | (*p << 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, sendsize, size; | |
257 int error = ETM_OK; | |
258 | |
259 buf = (uint8 *) &pkt->mid; | |
260 sendsize = size = pkt->size + 2; //one for mid, one for status | |
261 | |
262 tr_etm(TgTrEtmLow, "ETM API: _pkt_send: size(%d)", sendsize); | |
263 | |
264 while (size-- ) { | |
265 cksum ^= *buf++; | |
266 } | |
267 *buf = cksum; | |
268 | |
269 sendsize += 1; // one for checksum | |
270 | |
271 tr_etm_hexdump(TgTrEtmLow, &pkt->mid, sendsize); | |
272 | |
273 error = rvt_send_trace_cpy((uint8 *) &pkt->mid, etm_trace_user_id, | |
274 sendsize, RVT_BINARY_FORMAT); | |
275 if(error < 0) | |
276 tr_etm(TgTrFatal, "ETM API: _pkt_send: ERROR(%d)", error); | |
277 | |
278 return error; | |
279 } | |
280 |