comparison chipsetsw/services/atp/atp_sw_ent.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*******************************************************************************
2 *
3 * File Name : atp_sw_ent.c
4 *
5 * Functions handling registered SW entities database of the ATP
6 *
7 * (C) Texas Instruments, all rights reserved
8 *
9 * Version number : 0.1 Date : 28-Feb-2000
10 *
11 * History : 0.1 - Created by E. Baissus
12 * : 0.9 (3-May-2000) : reviewed
13 *
14 * Author : Eric Baissus : e-baissus@ti.com
15 *
16 * (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved
17 ******************************************************************************/
18 #include "rv/rv_general.h"
19 #include "rvf/rvf_api.h"
20 #include "atp/atp_api.h"
21 #include "atp/atp_i.h"
22 #include "atp/atp_config.h"
23
24 #include <string.h>
25
26
27 /* Number of SW entity which has been registered into ATP excluding GSM */
28 T_ATP_SW_ENTITY_ID atp_nb_sw_entity;
29
30
31 /* Table gathering the pointers on the different SW entity data structure */
32 /* If NULL, field is free (initiated in atp_init)*/
33 /* Note that a static field is used for GSM in order to be able to register the GSM */
34 /* SW entity even if no memory bank has been allocated to ATP yet */
35
36 static T_ATP_SW_ENTITY_STRUCT gsm_sw_entity;
37 T_ATP_SW_ENTITY_STRUCT * atp_sw_entity_table_p[ATP_MAX_NB_SW_ENTITY+1] = { NULL } ; //First one is reserved for GSM and is NULL at beginning
38
39
40
41
42
43 /******************************************************************************
44 * Function name: atp_reg
45 *
46 * Description : This function is used to register a new SW entity to the ATP entity
47
48 * Parameters : - name = SW entity name
49 * - return_path => way to send event to the new registered entity,
50 * - mode => supported mode of the new registered entity
51 * - &sw_id_p => pointer on id to use later on to identify the SW entity
52 *
53 * Return : Standard error
54 * RV_OK or RV_MEMORY_ERR (no more entity can register, or prim MB not GREEN)
55 *
56 * History : 0.1 (29-Feb-2000)
57 * : 0.9 (3-May-2000) : reviewed
58 ******************************************************************************/
59
60 T_ATP_RET atp_reg(T_ATP_SW_ENTITY_NAME name, T_ATP_CALLBACK return_path, T_ATP_ENTITY_MODE mode ,
61 T_ATP_SW_ENTITY_ID * sw_id_p)
62 {
63 T_ATP_SW_ENTITY_STRUCT * sw_struct_p;
64 UINT8 i;
65
66 if (atp_get_sw(name,sw_id_p)== RV_OK)
67 {
68 /* SW entity is already registered */
69 atp_error_switch(ATP_ERROR_FAILED_TO_HANDLE_REGISTRATION,ATP_SAME_ACTION_ALREADY_DONE,NULL);
70 return RV_NOT_SUPPORTED;
71 }
72
73 if (strcmp((char *) name,ATP_GSM_NAME) !=0) // Not GSM registration
74 {
75 // Check if a new SW entity can register and if ATP has been started
76 if ( (atp_nb_sw_entity==ATP_MAX_NB_SW_ENTITY) || (atp_swe_state != ATP_STARTED))
77 {
78 atp_error_switch(ATP_ERROR_FAILED_TO_HANDLE_REGISTRATION,ATP_NO_MORE_RESSOURCE,NULL);
79 return RV_NOT_SUPPORTED;
80 }
81
82 // Get buffer for a new instance
83 switch (rvf_get_buf(atp_mb_prim,sizeof(T_ATP_SW_ENTITY_STRUCT),(void **) &sw_struct_p))
84 {
85 case RVF_GREEN:
86 {
87 break;
88 }
89 case RVF_YELLOW:
90 {
91 rvf_free_buf ((T_RVF_BUFFER *) sw_struct_p);
92 }
93 default:
94 {
95 atp_error_switch(ATP_ERROR_FAILED_TO_HANDLE_REGISTRATION,ATP_MEMORY_ERROR,NULL);
96 return RV_MEMORY_ERR; // not enough memory : refuse any new registration
97 }
98 }
99 }
100 else
101 {
102 if (atp_sw_entity_table_p[0]!=NULL)
103 {
104 atp_error_switch(ATP_ERROR_FAILED_TO_HANDLE_REGISTRATION,ATP_SAME_ACTION_ALREADY_DONE,NULL);
105 return RV_NOT_SUPPORTED; // GSM is already registered
106 }
107 sw_struct_p=(&gsm_sw_entity);
108 }
109
110 // Initialisation of the structure
111
112 // Copy SW entity name
113 strcpy((char *) sw_struct_p->sw_entity_name ,(char *) name);
114
115
116 // Copy return path information
117 sw_struct_p->return_path.callback_func = return_path.callback_func;
118 sw_struct_p->return_path.addr_id = return_path.addr_id;
119
120
121 // Copy mode information
122 sw_struct_p->mode= mode;
123
124 // Initialize number of open port with the SW entity
125 sw_struct_p->nb_open_port=0;
126
127
128 // START : THIS SECTION MUST BE PROTECTED BY A SEMAPHORE !!!!!!
129 // Initialise SW entity table: next field points on new structure
130 if (strcmp( (char *) name,ATP_GSM_NAME) !=0) // Not GSM registration
131 {
132 i=1;
133 while(atp_sw_entity_table_p[i]!=NULL)
134 {
135 i++;
136 if (i>ATP_MAX_NB_SW_ENTITY)
137 {
138 rvf_free_buf(sw_struct_p);
139 atp_error_switch(ATP_ERROR_FAILED_TO_HANDLE_REGISTRATION,ATP_MEMORY_ERROR,NULL);
140 return RV_MEMORY_ERR;
141 }
142 }
143 atp_nb_sw_entity++;
144 }
145 else
146 {
147 i=0; // GSM always got id = 0
148 }
149
150 *sw_id_p=i;
151 atp_sw_entity_table_p[i]=sw_struct_p;
152
153
154 // END : THIS SECTION MUST BE PROTECTTED BY A SEMAPHORE !!!!!!
155
156
157
158 return RV_OK;
159 }
160
161
162
163
164
165 /******************************************************************************
166 * Function name: atp_dereg
167 *
168 * Description : This function is used to remove a SW entity to the list of
169 * SW entities registered in ATP.
170 *
171 * Parameters : - sw_id => id of the SWE
172 *
173 * Return : Standard error
174 * RV_OK ,
175 * RV_NOT_READY if a port is still open involving the SW entity
176 * RV_NOT_SUPPORTED if sw_id is already de-registered -> ignore call
177 *
178 * History : 0.1 (29-Feb-2000)
179 * : 0.9 (3-May-2000) : reviewed
180 ******************************************************************************/
181
182 T_ATP_RET atp_dereg(T_ATP_SW_ENTITY_ID sw_id)
183 {
184
185 T_ATP_SW_ENTITY_STRUCT * sw_entity_p;
186
187 // Check for invalid parameters
188 if (sw_id > ATP_MAX_NB_SW_ENTITY)
189 {
190 return RV_INVALID_PARAMETER;
191 }
192
193 // START : THIS SECTION MUST BE PROTECTED BY A SEMAPHORE !!!!!!
194 sw_entity_p=atp_sw_entity_table_p[sw_id];
195
196 if (sw_entity_p==NULL)
197 {
198 // This entity is no longer registered
199 return RV_NOT_SUPPORTED;
200 }
201
202 if (sw_entity_p->nb_open_port>0)
203 {
204 // A port is still open involving this SW entity : refuse de-registration
205 atp_error_switch(ATP_ERROR_FAILED_TO_HANDLE_REGISTRATION,ATP_ISSUED_IN_A_WRONG_STATE_ERROR,NULL);
206 return RV_NOT_READY;
207 }
208
209 // Remove SW entity
210 atp_sw_entity_table_p[sw_id]=NULL; // free the field
211 if (sw_id != 0)
212 {
213 rvf_free_buf(sw_entity_p); // free the buffer
214 atp_nb_sw_entity--;
215 }
216
217 // END : THIS SECTION MUST BE PROTECTTED BY A SEMAPHORE !!!!!!
218
219 return RV_OK;
220 }
221
222
223
224
225
226
227
228 /******************************************************************************
229 * Function name: atp_get_sw
230 *
231 * Description : This function is used to get SWE ID from the SWE name
232 *
233 * Parameters : - name => name of the SWE to find
234 * - sw_id_p => & of the id of the SWE
235 *
236 * Return : Standard error
237 * RV_OK ,
238 * RV_NOT_SUPPORTED if name was not in the SWE ATP list
239 *
240 * History : 0.1 (29-Feb-2000)
241 * : 0.9 (3-May-2000) : reviewed
242 ******************************************************************************/
243 T_ATP_RET atp_get_sw(T_ATP_SW_ENTITY_NAME name,T_ATP_SW_ENTITY_ID * sw_id_p)
244 {
245 UINT8 i;
246 T_ATP_SW_ENTITY_STRUCT * sw_entity_p;
247
248 for(i=0;i<=ATP_MAX_NB_SW_ENTITY;i++)
249 {
250 sw_entity_p=atp_sw_entity_table_p[i];
251 if (sw_entity_p!=NULL)
252 {
253 if(strcmp((const char *) name,(const char *) sw_entity_p->sw_entity_name)==0)
254 { /* Found one SW entity with proper name */
255 *sw_id_p=i;
256 return RV_OK;
257 }
258 }
259 }
260 return RV_NOT_SUPPORTED; // No SW entity had this name
261 }
262
263
264
265
266 /******************************************************************************
267 * Function name: atp_reg_info
268 *
269 * Description : This function is used to get info on a SWE
270 *
271 * Parameters : - name => name of the SWE to get info on
272 * - return : id of the SWE
273 * - return : SWE mode information
274 *
275 * Return : Standard error
276 * RV_OK ,
277 * RV_NOT_SUPPORTED if name has not been found
278 *
279 * History : 0.1 (29-Feb-2000)
280 * : 0.9 (3-May-2000) : reviewed
281 ******************************************************************************/
282 T_ATP_RET atp_reg_info(T_ATP_SW_ENTITY_NAME name, T_ATP_SW_ENTITY_ID * sw_id_p,
283 T_ATP_ENTITY_MODE * mode_p )
284 {
285
286 T_ATP_SW_ENTITY_STRUCT * sw_entity_p;
287
288
289 // START : THIS SECTION MUST BE PROTECTED BY A SEMAPHORE !!!!!!
290 /* Search related sw entity instance */
291 if(atp_get_sw(name,sw_id_p)!=RV_OK)
292 {
293 return RV_NOT_SUPPORTED;
294 }
295
296 sw_entity_p=atp_sw_entity_table_p[*sw_id_p];
297 (*mode_p)=sw_entity_p->mode;
298
299
300 // END : THIS SECTION MUST BE PROTECTTED BY A SEMAPHORE !!!!!!
301
302 return RV_OK;
303 }
304
305
306
307 /******************************************************************************
308 * Function name: atp_dereg_all
309 *
310 * Description : De-register all the registered entity
311 *
312 * Parameters : None
313 *
314 * Return : Always RV_OK
315 *
316 *
317 * History
318 * : 0.9 (10-Aug-2000)
319 ******************************************************************************/
320 T_ATP_RET atp_dereg_all(void)
321 {
322
323 UINT8 i;
324
325 for(i=0;i<(ATP_MAX_NB_SW_ENTITY+1);i++)
326 {
327 if (atp_sw_entity_table_p[i] !=NULL)
328 {
329 /* A SWE is registered in this index */
330 if (atp_dereg(i) != RV_OK)
331 {
332 return RV_INTERNAL_ERR;
333 };
334 }
335 }
336
337 return RV_OK;
338 }
339
340
341
342
343