comparison gsm-fw/riviera/rvt/rvt_api.c @ 143:afceeeb2cba1

Our nuc-fw is destined to become gsm-fw, so I went ahead and did the big hg mv
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 12 Nov 2013 05:35:48 +0000
parents nuc-fw/riviera/rvt/rvt_api.c@28f967578233
children
comparison
equal deleted inserted replaced
142:15d5977390c2 143:afceeeb2cba1
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_gen.h"
26 #include "rvt_def_i.h"
27 #include "rvt_env.h"
28 #include "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 T_RVT_TRACE_RQST * req ;
148
149 /* Check is Trace Module is running */
150 if (rvt_module_state != RVT_STARTED)
151 {
152 (rvt_lost_msg_cpt.bit_mask).count++;
153 (rvt_lost_msg_cpt.bit_mask).not_started = 1;
154 return RVT_NOT_READY;
155 }
156
157 /* Allocate memory (msg_length + necessary room for the header) */
158 if ((rvf_get_buf (rvt_mb_id, (UINT32) msg_length + RVT_HEADER_SIZE, (T_RVF_BUFFER**) &req)) == RVF_RED)
159 {
160 (rvt_lost_msg_cpt.bit_mask).count++;
161 (rvt_lost_msg_cpt.bit_mask).insufficient_resources = 1;
162 return RVT_MEMORY_ERR;
163 }
164
165 /* Add the id, size and format of the msg at the beginning */
166 req->header.msg_id = RVT_TRACE_RQST_ID;
167 req->format = msg_format;
168 req->user_id = user_id;
169 req->msg_length = msg_length;
170
171 /* Copy the message */
172 memcpy( (UINT8*)req + RVT_HEADER_SIZE, msg, msg_length);
173
174 /*
175 ** Send it as a message to Trace Task
176 */
177 if (rvf_send_msg(rvt_addr_id, (void *) req) != RVF_OK)
178 {
179 (rvt_lost_msg_cpt.bit_mask).count++;
180 (rvt_lost_msg_cpt.bit_mask).message_not_sent = 1;
181 rvf_free_buf (req);
182 return RVT_INTERNAL_ERR;
183 }
184 return RVT_OK;
185 }
186
187
188
189 /********************************************************************************/
190 /* */
191 /* Function Name: rvt_register_id */
192 /* */
193 /* Purpose: function rvt_register id */
194 /* returns 0 if string not found, else the number */
195 /* stocked in the array */
196 /* */
197 /* Note: */
198 /* uses two arrays, one that stockes the messages,and another for the */
199 /* correspondent values. */
200 /* */
201 /********************************************************************************/
202
203 T_RVT_RET rvt_register_id(T_RVT_NAME name[], T_RVT_USER_ID *rvt_id, RVT_CALLBACK_FUNC callback)
204 {
205 UINT8 i;
206
207 /*looks in the array if the message is stocked */
208 for (i=0;rvt_user_db[i].user_id!=RVT_INVALID_HEADER;i++)
209 {
210 if (rvt_name_cmp(rvt_user_db[i].user_name,name))
211 {
212 *rvt_id = rvt_user_db[i].user_id;
213 rvt_user_db[i].rx_callback_func = callback;
214 return(RVT_OK);
215 }
216 }
217
218 /*else returns zero */
219 return (RVT_INVALID_PARAMETER);
220
221 }
222
223
224
225
226 /********************************************************************************/
227 /* */
228 /* Function Name: rvt_mem_alloc */
229 /* */
230 /* Purpose: this function allocates a buffer for tracing. */
231 /* */
232 /* Note: */
233 /* None. */
234 /* */
235 /********************************************************************************/
236 T_RVT_RET rvt_mem_alloc(T_RVT_USER_ID user_id, T_RVT_MSG_LG buffer_length, T_RVT_BUFFER * buff)
237 {
238 if (rvt_module_state != RVT_STARTED)
239 {
240 *buff = NULL;
241 (rvt_lost_msg_cpt.bit_mask).count++;
242 (rvt_lost_msg_cpt.bit_mask).not_started = 1;
243 return RVT_NOT_READY;
244 }
245
246 if (rvf_get_buf (rvt_mb_id, (UINT32) buffer_length + RVT_HEADER_SIZE, (T_RVF_BUFFER**) buff) == RVF_RED)
247 {
248 *buff = NULL;
249 (rvt_lost_msg_cpt.bit_mask).count++;
250 (rvt_lost_msg_cpt.bit_mask).insufficient_resources = 1;
251 return RVT_MEMORY_ERR;
252 }
253 *buff = *buff + RVT_HEADER_SIZE;
254 return RVT_OK;
255 }
256
257
258 /********************************************************************************/
259 /* */
260 /* Function Name: rvt_mem_free */
261 /* */
262 /* Purpose: this function frees an allocated buffer for the trace task */
263 /* */
264 /* Note: */
265 /* None. */
266 /* */
267 /********************************************************************************/
268 T_RVT_RET rvt_mem_free(T_RVT_BUFFER msg)
269 {
270
271 /*
272 ** Shift the pointer back to write control values
273 */
274 char *buff = (char*) msg - RVT_HEADER_SIZE;
275
276 // Deallocates the buffer
277 if (rvf_free_buf((T_RVF_BUFFER*) buff) == RVF_MEMORY_ERR)
278 {
279 return RVT_MEMORY_ERR;
280 }
281 return RVT_OK;
282 }
283
284
285 /*
286 ** User function used to compare name
287 */
288 BOOLEAN rvt_name_cmp( char * str1, char * str2)
289 {
290 UINT8 i;
291
292 for ( i = 0; (str1[i] == str2[i]) && (str1[i] != 0) && (str2[i] != 0) && (i < RVT_NAME_MAX_LEN); i++ );
293 if ( i == RVT_NAME_MAX_LEN)
294 { return TRUE;
295 }
296 if ( (str1[i] == 0) && (str2[i] == 0) )
297 { return TRUE;
298 }
299 return FALSE;
300 }