FreeCalypso > hg > fc-selenite
comparison src/cs/riviera/rvt/rvt_api.c @ 0:b6a5e36de839
src/cs: initial import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Jul 2018 04:39:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b6a5e36de839 |
---|---|
1 /************************************************************************** | |
2 * | |
3 * rvt_api.c | |
4 * | |
5 * This module defines the interface of Trace Module | |
6 * | |
7 * (C) Texas Instruments, all rights reserved | |
8 * | |
9 * Version number : 0.1 | |
10 * | |
11 * History : 0.1 (7/5/2000) - Created | |
12 * | |
13 * Date : 7/5/2000 | |
14 * | |
15 * Author : Guido Pagana g-pagana@ti.com * | |
16 ***************************************************************************/ | |
17 | |
18 | |
19 | |
20 #include "rv/general.h" | |
21 #include "rv/rv_general.h" | |
22 #include "rvf/rvf_api.h" | |
23 #include "rvm/rvm_use_id_list.h" | |
24 | |
25 #include "rvt/rvt_gen.h" | |
26 #include "rvt/rvt_def_i.h" | |
27 #include "rvt/rvt_env.h" | |
28 #include "rvt/rvt_env_i.h" | |
29 | |
30 #include <string.h> | |
31 | |
32 | |
33 /* | |
34 ** Trace User data base global variable | |
35 */ | |
36 T_RVT_USER_DB rvt_user_db [] = RVT_USER_ID_MAPPING; | |
37 | |
38 /* | |
39 ** Number of messages lost | |
40 */ | |
41 T_RVT_LOST_MSG rvt_lost_msg_cpt = {0}; | |
42 | |
43 extern UINT8 rvf_trace_level; | |
44 | |
45 extern UINT32 rvf_layer_mask; | |
46 | |
47 | |
48 /********************************************************************************/ | |
49 /* */ | |
50 /* Function Name: rvt_set_trace_level */ | |
51 /* */ | |
52 /* Purpose: Updating the level of filtering, as well as the 32-bit */ | |
53 /* mask related to the software entities to be monitored, */ | |
54 /* according to the PC. */ | |
55 /* */ | |
56 /* Note: None. */ | |
57 /* */ | |
58 /********************************************************************************/ | |
59 void rvt_set_trace_level (T_RVT_BUFFER p_msg, UINT16 msg_length) | |
60 { | |
61 | |
62 /* Checking for an invalid PDU. */ | |
63 if ((p_msg == NULL) || \ | |
64 (msg_length != (sizeof (UINT8) + sizeof (UINT32)))) | |
65 { | |
66 return; | |
67 } | |
68 | |
69 /* Update the level of filtering. */ | |
70 if (*p_msg <= RV_TRACE_LEVEL_DEBUG_LOW) | |
71 { | |
72 rvf_trace_level = *p_msg; | |
73 } | |
74 | |
75 /* Update the 32-bit mask related to the software entities to be monitored. | |
76 Note that the 32-bit mask is transmitted LSB first. */ | |
77 rvf_layer_mask = *(++p_msg); | |
78 rvf_layer_mask |= *(++p_msg) << 8; | |
79 rvf_layer_mask |= *(++p_msg) << 16; | |
80 rvf_layer_mask |= *(++p_msg) << 24; | |
81 } | |
82 | |
83 | |
84 /********************************************************************************/ | |
85 /* */ | |
86 /* Function Name: rvt_send_trace_no_copy */ | |
87 /* */ | |
88 /* Purpose: This function is used send trace messages without */ | |
89 /* copying. */ | |
90 /* */ | |
91 /* Note: */ | |
92 /* WARNING!!!! The buffer containing the message has been allocated */ | |
93 /* by the trace module!!! */ | |
94 /* */ | |
95 /********************************************************************************/ | |
96 | |
97 T_RVT_RET | |
98 rvt_send_trace_no_cpy( T_RVT_BUFFER msg, | |
99 T_RVT_USER_ID user_id, | |
100 T_RVT_MSG_LG msg_length, | |
101 T_RVT_FORMAT msg_format) | |
102 { | |
103 /* Shift the pointer back to write control values */ | |
104 T_RVT_TRACE_RQST * req_msg = (T_RVT_TRACE_RQST * )((UINT8*)msg - RVT_HEADER_SIZE); | |
105 | |
106 /* Check is Trace Module is running */ | |
107 if (rvt_module_state != RVT_STARTED) | |
108 { | |
109 (rvt_lost_msg_cpt.bit_mask).count++; | |
110 (rvt_lost_msg_cpt.bit_mask).not_started = 1; | |
111 return RVT_NOT_READY; | |
112 } | |
113 | |
114 | |
115 /* Add the id, size and format of the msg at the beginning */ | |
116 | |
117 req_msg->header.msg_id = RVT_TRACE_RQST_ID; | |
118 req_msg->format = msg_format; | |
119 req_msg->user_id = user_id; | |
120 req_msg->msg_length = msg_length; | |
121 | |
122 if (rvf_send_msg(rvt_addr_id, (void *) req_msg) != RVF_OK) | |
123 { | |
124 (rvt_lost_msg_cpt.bit_mask).count++; | |
125 (rvt_lost_msg_cpt.bit_mask).message_not_sent = 1; | |
126 return RVT_INTERNAL_ERR; | |
127 } | |
128 return RVT_OK; | |
129 } | |
130 | |
131 | |
132 /********************************************************************************/ | |
133 /* */ | |
134 /* Function Name: send trace copy */ | |
135 /* */ | |
136 /* Purpose: this function sends traces with copy */ | |
137 /* */ | |
138 /* Note: */ | |
139 /* No check on id parameter !!!! Must be done in PC. */ | |
140 /* */ | |
141 /********************************************************************************/ | |
142 T_RVT_RET rvt_send_trace_cpy (T_RVT_BUFFER msg, | |
143 T_RVT_USER_ID user_id, | |
144 T_RVT_MSG_LG msg_length, | |
145 T_RVT_FORMAT msg_format) | |
146 | |
147 | |
148 | |
149 { | |
150 T_RVT_TRACE_RQST * req ; | |
151 | |
152 /* Check is Trace Module is running */ | |
153 if (rvt_module_state != RVT_STARTED) | |
154 { | |
155 (rvt_lost_msg_cpt.bit_mask).count++; | |
156 (rvt_lost_msg_cpt.bit_mask).not_started = 1; | |
157 return RVT_NOT_READY; | |
158 } | |
159 | |
160 /* Allocate memory (msg_length + necessary room for the header) */ | |
161 if ((rvf_get_buf (rvt_mb_id, (UINT32) msg_length + RVT_HEADER_SIZE, (T_RVF_BUFFER**) &req)) == RVF_RED) | |
162 { | |
163 (rvt_lost_msg_cpt.bit_mask).count++; | |
164 (rvt_lost_msg_cpt.bit_mask).insufficient_resources = 1; | |
165 return RVT_MEMORY_ERR; | |
166 } | |
167 | |
168 /* Add the id, size and format of the msg at the beginning */ | |
169 req->header.msg_id = RVT_TRACE_RQST_ID; | |
170 req->format = msg_format; | |
171 req->user_id = user_id; | |
172 req->msg_length = msg_length; | |
173 | |
174 /* Copy the message */ | |
175 memcpy( (UINT8*)req + RVT_HEADER_SIZE, msg, msg_length); | |
176 | |
177 /* | |
178 ** Send it as a message to Trace Task | |
179 */ | |
180 if (rvf_send_msg(rvt_addr_id, (void *) req) != RVF_OK) | |
181 { | |
182 (rvt_lost_msg_cpt.bit_mask).count++; | |
183 (rvt_lost_msg_cpt.bit_mask).message_not_sent = 1; | |
184 rvf_free_buf (req); | |
185 return RVT_INTERNAL_ERR; | |
186 } | |
187 return RVT_OK; | |
188 } | |
189 | |
190 | |
191 | |
192 /********************************************************************************/ | |
193 /* */ | |
194 /* Function Name: rvt_register_id */ | |
195 /* */ | |
196 /* Purpose: function rvt_register id */ | |
197 /* returns 0 if string not found, else the number */ | |
198 /* stocked in the array */ | |
199 /* */ | |
200 /* Note: */ | |
201 /* uses two arrays, one that stockes the messages,and another for the */ | |
202 /* correspondent values. */ | |
203 /* */ | |
204 /********************************************************************************/ | |
205 | |
206 T_RVT_RET rvt_register_id(T_RVT_NAME name[], T_RVT_USER_ID *rvt_id, RVT_CALLBACK_FUNC callback) | |
207 { | |
208 UINT8 i; | |
209 | |
210 /*looks in the array if the message is stocked */ | |
211 for (i=0;rvt_user_db[i].user_id!=RVT_INVALID_HEADER;i++) | |
212 { | |
213 if (rvt_name_cmp(rvt_user_db[i].user_name,name)) | |
214 { | |
215 *rvt_id = rvt_user_db[i].user_id; | |
216 rvt_user_db[i].rx_callback_func = callback; | |
217 return(RVT_OK); | |
218 } | |
219 } | |
220 | |
221 /*else returns zero */ | |
222 return (RVT_INVALID_PARAMETER); | |
223 | |
224 } | |
225 | |
226 | |
227 | |
228 | |
229 /********************************************************************************/ | |
230 /* */ | |
231 /* Function Name: rvt_mem_alloc */ | |
232 /* */ | |
233 /* Purpose: this function allocates a buffer for tracing. */ | |
234 /* */ | |
235 /* Note: */ | |
236 /* None. */ | |
237 /* */ | |
238 /********************************************************************************/ | |
239 T_RVT_RET rvt_mem_alloc(T_RVT_USER_ID user_id, T_RVT_MSG_LG buffer_length, T_RVT_BUFFER * buff) | |
240 { | |
241 if (rvt_module_state != RVT_STARTED) | |
242 { | |
243 *buff = NULL; | |
244 (rvt_lost_msg_cpt.bit_mask).count++; | |
245 (rvt_lost_msg_cpt.bit_mask).not_started = 1; | |
246 return RVT_NOT_READY; | |
247 } | |
248 | |
249 if (rvf_get_buf (rvt_mb_id, (UINT32) buffer_length + RVT_HEADER_SIZE, (T_RVF_BUFFER**) buff) == RVF_RED) | |
250 { | |
251 *buff = NULL; | |
252 (rvt_lost_msg_cpt.bit_mask).count++; | |
253 (rvt_lost_msg_cpt.bit_mask).insufficient_resources = 1; | |
254 return RVT_MEMORY_ERR; | |
255 } | |
256 *buff = *buff + RVT_HEADER_SIZE; | |
257 return RVT_OK; | |
258 } | |
259 | |
260 | |
261 /********************************************************************************/ | |
262 /* */ | |
263 /* Function Name: rvt_mem_free */ | |
264 /* */ | |
265 /* Purpose: this function frees an allocated buffer for the trace task */ | |
266 /* */ | |
267 /* Note: */ | |
268 /* None. */ | |
269 /* */ | |
270 /********************************************************************************/ | |
271 T_RVT_RET rvt_mem_free(T_RVT_BUFFER msg) | |
272 { | |
273 | |
274 /* | |
275 ** Shift the pointer back to write control values | |
276 */ | |
277 char *buff = (char*) msg - RVT_HEADER_SIZE; | |
278 | |
279 // Deallocates the buffer | |
280 if (rvf_free_buf((T_RVF_BUFFER*) buff) == RVF_MEMORY_ERR) | |
281 { | |
282 return RVT_MEMORY_ERR; | |
283 } | |
284 return RVT_OK; | |
285 } | |
286 | |
287 | |
288 /* | |
289 ** User function used to compare name | |
290 */ | |
291 BOOLEAN rvt_name_cmp( char * str1, char * str2) | |
292 { | |
293 UINT8 i; | |
294 | |
295 for ( i = 0; (str1[i] == str2[i]) && (str1[i] != 0) && (str2[i] != 0) && (i < RVT_NAME_MAX_LEN); i++ ); | |
296 if ( i == RVT_NAME_MAX_LEN) | |
297 { return TRUE; | |
298 } | |
299 if ( (str1[i] == 0) && (str2[i] == 0) ) | |
300 { return TRUE; | |
301 } | |
302 return FALSE; | |
303 } |