FreeCalypso > hg > freecalypso-sw
comparison gsm-fw/g23m-aci/bat/bat_app.c @ 775:eedbf248bac0
gsm-fw/g23m-aci subtree: initial import from LoCosto source
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 12 Oct 2014 01:45:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
774:40a721fd9854 | 775:eedbf248bac0 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : | |
4 | Modul : BAT | |
5 +----------------------------------------------------------------------------- | |
6 | Copyright 2005 Texas Instruments Berlin, AG | |
7 | All rights reserved. | |
8 | | |
9 | This file is confidential and a trade secret of Texas | |
10 | Instruments Berlin, AG | |
11 | The receipt of or possession of this file does not convey | |
12 | any rights to reproduce or disclose its contents or to | |
13 | manufacture, use, or sell anything it may describe, in | |
14 | whole, or in part, without the specific written consent of | |
15 | Texas Instruments Berlin, AG. | |
16 +----------------------------------------------------------------------------- | |
17 | Purpose : This Modul holds the functions | |
18 | for the binary AT command library at APPlication side | |
19 +----------------------------------------------------------------------------- | |
20 */ | |
21 #ifndef _BAT_APP_C_ | |
22 #define _BAT_APP_C_ | |
23 | |
24 /*==== INCLUDES =============================================================*/ | |
25 #include <string.h> | |
26 #include <math.h> | |
27 | |
28 #include "typedefs.h" | |
29 #include "gdd.h" | |
30 #include "gdd_sys.h" | |
31 #include "l2p_types.h" | |
32 #include "l2p.h" | |
33 #include "bat.h" | |
34 #include "bat_ctrl.h" | |
35 #include "bat_intern.h" | |
36 | |
37 /*==== DEFINES==== ==========================================================*/ | |
38 #define BAT_NOT_INITIALIZED FALSE | |
39 #define BAT_INITIALIZED TRUE | |
40 | |
41 | |
42 /*==== GLOBAL VARS ==========================================================*/ | |
43 | |
44 | |
45 /*==== EXTERN VARS ==========================================================*/ | |
46 | |
47 LOCAL void cvt_to_str (unsigned char input_num, char *num_str) | |
48 { | |
49 int i; | |
50 memset(num_str, 0, 3); | |
51 | |
52 for (i = 0; i < 3; i++) | |
53 { | |
54 if(input_num/pow(10,i) >0) | |
55 { | |
56 *(num_str+(2-i)) = (char)(input_num/pow(10,i))+'0'; | |
57 } | |
58 } | |
59 return; | |
60 } | |
61 | |
62 /* create dummy functions to make the interface alligned with BT */ | |
63 GLOBAL T_BAT_return bat_init (void *mem, unsigned char num) | |
64 { | |
65 BAT_TRACE_FUNCTION ("bat_init()"); | |
66 return (BAT_OK); | |
67 } | |
68 | |
69 GLOBAL T_BAT_return bat_deinit (void) | |
70 { | |
71 BAT_TRACE_FUNCTION ("bat_deinit()"); | |
72 return (BAT_OK); | |
73 } | |
74 | |
75 /* | |
76 +----------------------------------------------------------------------------+ | |
77 | PROJECT : MODULE : BINARY AT COMMAND LIBRARY | | |
78 | STATE : code ROUTINE : bat_new | | |
79 +----------------------------------------------------------------------------+ | |
80 PURPOSE : | |
81 This function is used to create a new instance of BAT Lib. It provides BAT Lib | |
82 the following information: an output parameter to pass back the instance handle | |
83 to the application; a pointer to the memory, which is allocated by the application | |
84 framework, for internal maintenance; the number of clients to maintain; the | |
85 appropriate configuration, a signal call back function pointer | |
86 and an unsolicited result code call back function pointer. | |
87 */ | |
88 | |
89 GLOBAL T_BAT_return bat_new (T_BAT_instance *inst_hndl, | |
90 void *mem, | |
91 unsigned char num, | |
92 T_BAT_config *config, | |
93 void (*instance_signal_cb)(T_BAT_signal signal)) | |
94 { | |
95 int i; | |
96 T_BAT_client_maintain *clnt_mt = NULL; | |
97 T_BAT_instance_maintain *inst_mt = NULL; | |
98 CHAR sem_str[] = "SEM_BAT000"; /* long enough to hold "SEM_BATxxx" */ | |
99 | |
100 U32 mem_l2p; | |
101 | |
102 BAT_TRACE_FUNCTION ("bat_new()"); | |
103 | |
104 /* check if the parameters are correct */ | |
105 if ((mem EQ NULL) OR (num > BAT_CONTROL_CHANNEL) OR | |
106 (config EQ NULL) OR (instance_signal_cb EQ NULL)) | |
107 { | |
108 BAT_TRACE_ERROR ("bat_new(): input parameter incorrect!"); | |
109 return (BAT_ERROR); | |
110 } | |
111 /* init allocated memory */ | |
112 memset(mem, 0, num * BAT_CLIENT_SIZE + BAT_INSTANCE_SIZE); | |
113 | |
114 /* init global params */ | |
115 if (bat_init_global_params()) | |
116 { | |
117 return (BAT_ERROR); | |
118 } | |
119 | |
120 /* get the free slot to store the instance pointer */ | |
121 if (bat_get_new_instance(inst_hndl) NEQ BAT_OK) | |
122 { | |
123 return (BAT_ERROR); | |
124 } | |
125 | |
126 /* init the instance maintainance data */ | |
127 inst_mt = (T_BAT_instance_maintain *)mem; | |
128 | |
129 /* init semaphore */ | |
130 cvt_to_str(*inst_hndl, &sem_str[7]); | |
131 inst_mt->sem_BAT = gdd_sys_sem_open(sem_str, 1); | |
132 | |
133 if (inst_mt->sem_BAT EQ (-1)) | |
134 { | |
135 BAT_TRACE_ERROR("canīt open semaphore \"SEM_BAT\""); | |
136 return (BAT_ERROR); | |
137 } | |
138 | |
139 /* init the pointer in the pointer list */ | |
140 bat_init_instance_pointer (*inst_hndl, inst_mt); | |
141 | |
142 inst_mt->instance_signal_cb = instance_signal_cb; | |
143 inst_mt->unsolicited_result_cb = NULL; | |
144 inst_mt->max_client_num = num; | |
145 inst_mt->config = config; | |
146 bat_change_instance_state(inst_mt,BAT_INSTANCE_IDLE); | |
147 bat_change_buffer_state(inst_mt, BAT_BUF_EMPTY); | |
148 | |
149 BAT_TRACE_EVENT_P1 ("bat_new(): BAT INST add is: %04X", mem); | |
150 | |
151 /* init the clients */ | |
152 for (i = 0; i < num; i ++) | |
153 { | |
154 clnt_mt = (T_BAT_client_maintain *)((U32)sizeof(T_BAT_client_maintain)*i + (U32)inst_mt + | |
155 (U32)sizeof (T_BAT_instance_maintain)); | |
156 BAT_TRACE_EVENT_P2 ("bat_new(): BAT CLNT %d ' add is: %04X", i, clnt_mt); | |
157 | |
158 bat_change_client_state(clnt_mt, BAT_CLIENT_IDLE); | |
159 } | |
160 | |
161 /* configure the L2P */ | |
162 mem_l2p = (U32)inst_mt+sizeof(T_BAT_instance_maintain) + num*sizeof(T_BAT_client_maintain); | |
163 BAT_TRACE_EVENT_P1("bat_new(): The address passed to L2P is 0x%4x", mem_l2p); | |
164 L2P_Configure(*inst_hndl, (void*)((U32)inst_mt+sizeof(T_BAT_instance_maintain)+num*sizeof(T_BAT_client_maintain)), | |
165 config->l2p.protocol_id, (U16)(config->adapter.cap.dio_cap.mtu_size), bat_l2p_get_tx_buffer, | |
166 bat_l2p_get_rx_buffer, bat_l2p_get_next_buf_seg, bat_l2p_send_frame, bat_l2p_message_rxd); | |
167 | |
168 /* call GDD to create the connection, if ERROR is returned the app should call bat_new later*/ | |
169 if ((config->adapter.gdd_if.gdd_connect(GDD_INST_BAT, (T_GDD_CON_HANDLE*)&(inst_mt->con_handle), | |
170 &(config->adapter.cap), bat_gdd_receive_data_cb, | |
171 bat_gdd_signal_cb))NEQ GDD_OK) | |
172 { | |
173 BAT_TRACE_ERROR ("bat_new(): Error returned from gdd_connect()."); | |
174 bat_deinit_instance_pointer(*inst_hndl); | |
175 L2P_Remove (*inst_hndl); | |
176 return (BAT_ERROR); | |
177 } | |
178 | |
179 /* BAT Lib is awaiting 2 confirmations. One from GDD and one from ACI, the confirmations will be handled in the cbs */ | |
180 | |
181 return (BAT_OK); | |
182 } | |
183 | |
184 /* | |
185 +----------------------------------------------------------------------------+ | |
186 | PROJECT : MODULE : BINARY AT COMMAND LIBRARY | | |
187 | STATE : code ROUTINE : bat_delete | | |
188 +----------------------------------------------------------------------------+ | |
189 PURPOSE : | |
190 This function is used to delete the BAT Lib instance created by function | |
191 bat_new().The provided callback function is used to inform the application of | |
192 the finial result. If the application receives an indication of successfully | |
193 deleting of the BAT Lib instance, the memory allocated to this instance can | |
194 be freed by the application. Please note that the application should call | |
195 bat_close() to close all the clients before deleting the BAT Lib instance. | |
196 */ | |
197 | |
198 GLOBAL T_BAT_return bat_delete (T_BAT_instance inst_hndl) | |
199 { | |
200 T_BAT_instance_maintain *inst_mt = NULL; | |
201 | |
202 BAT_TRACE_FUNCTION ("bat_delete()"); | |
203 | |
204 /* check if inst_hndl is valid */ | |
205 if (inst_hndl EQ BAT_INVALID_INSTANCE_HANDLE) | |
206 { | |
207 return (BAT_ERROR); | |
208 } | |
209 | |
210 /* the instance can not be deleted before all clients are closed */ | |
211 if (bat_check_if_all_clients_are_closed(inst_hndl) EQ FALSE) | |
212 { | |
213 return (BAT_ERROR); | |
214 } | |
215 | |
216 /* get instance from instance handle */ | |
217 if (bat_get_instance_from_instance_handle (inst_hndl, &inst_mt) EQ BAT_ERROR) | |
218 { | |
219 return (BAT_ERROR); | |
220 } | |
221 | |
222 /* call GDD to inform the close of an instance */ | |
223 if (inst_mt->config->adapter.gdd_if.gdd_disconnect((T_GDD_CON_HANDLE)(inst_mt->con_handle)) NEQ GDD_OK) | |
224 { | |
225 BAT_TRACE_ERROR ("bat_delete(): Error returned from gdd_connect(), instance cannot be deleted."); | |
226 return (BAT_ERROR); | |
227 } | |
228 bat_change_instance_state(inst_mt,BAT_INSTANCE_IDLE); | |
229 | |
230 /* remove the l2p maintainance data */ | |
231 L2P_Remove (inst_hndl); | |
232 /*BAT deinit the instance*/ | |
233 bat_deinit_instance_pointer (inst_hndl); | |
234 | |
235 if (inst_mt->sem_BAT NEQ (-1)) | |
236 { | |
237 gdd_sys_sem_close(inst_mt->sem_BAT); | |
238 } | |
239 | |
240 /* deinit the BAT Lib if the last instance has been deleted */ | |
241 bat_deinit_global_params(); | |
242 | |
243 return (BAT_OK); | |
244 } | |
245 | |
246 /* | |
247 +----------------------------------------------------------------------------+ | |
248 | PROJECT : MODULE : BINARY AT COMMAND LIBRARY | | |
249 | STATE : code ROUTINE : bat_open | | |
250 +----------------------------------------------------------------------------+ | |
251 PURPOSE : | |
252 This function is used to open a new binary AT command client path. This | |
253 function passes a unique client handle to the application by the output | |
254 parameter clnt_hndl. This client handle is used by bat_send(), bat_close() | |
255 and bat_cntrl().The bat_open() function is re-entrant and can be | |
256 called in serial within one instance. | |
257 */ | |
258 | |
259 GLOBAL T_BAT_return bat_open( T_BAT_instance instance, | |
260 T_BAT_client *clnt_hndl, | |
261 int(*response_cb)( T_BAT_client,T_BAT_cmd_response*), | |
262 void (*signal_cb)( T_BAT_client, T_BAT_signal)) | |
263 { | |
264 T_BAT_client_maintain *clnt_mt = NULL; | |
265 T_BAT_instance_maintain *inst_mt = NULL; | |
266 T_BAT_return ret = BAT_ERROR; | |
267 T_BATC_signal ctrl_sig; | |
268 T_BATC_open_client param; | |
269 | |
270 BAT_TRACE_FUNCTION ("bat_open()"); | |
271 | |
272 /* find the correct instance */ | |
273 if (bat_get_instance_from_instance_handle (instance, &inst_mt) EQ BAT_ERROR) | |
274 { | |
275 return (BAT_ERROR); | |
276 } | |
277 | |
278 /* bat_open should be called after bat instance is created */ | |
279 if (inst_mt->instance_state < BAT_INSTANCE_READY) | |
280 { | |
281 BAT_TRACE_EVENT_P1 ("ERROR: the instance state is %d", inst_mt->instance_state); | |
282 return (BAT_ERROR); | |
283 } | |
284 | |
285 /* check if one more client can be created */ | |
286 if (bat_get_new_client(instance, clnt_hndl) EQ BAT_ERROR) | |
287 { | |
288 return (BAT_ERROR); | |
289 } | |
290 | |
291 /* set the necessary states before sending the data to BAT ACI, this is bec it can | |
292 happen that the callback is used before function bat_send_ctrl_data() returns */ | |
293 if (bat_init_new_client (*clnt_hndl, response_cb, signal_cb) EQ BAT_ERROR) | |
294 { | |
295 return (BAT_ERROR); | |
296 } | |
297 | |
298 if (bat_get_client_from_client_handle(*clnt_hndl, &clnt_mt) EQ BAT_ERROR) | |
299 { | |
300 return (BAT_ERROR); | |
301 } | |
302 | |
303 bat_change_client_state(clnt_mt, BAT_CLIENT_ACTIVATING); | |
304 | |
305 param.client_id = (U32)(GET_CLNT_ID_FROM_CLNT_HANDLE(*clnt_hndl)); | |
306 ctrl_sig.ctrl_params = BATC_OPEN_CLIENT; | |
307 ctrl_sig.params.ptr_open_client = ¶m; | |
308 | |
309 /* send control data to BAT ACI */ | |
310 ret = bat_send_ctrl_data(instance, &ctrl_sig); | |
311 | |
312 switch (ret) | |
313 { | |
314 case (BAT_BUSY_RESOURCE): | |
315 { | |
316 /* instance state shows that the bat_open() call receives Busy */ | |
317 bat_change_instance_state(inst_mt, BAT_INSTANCE_BUSY); | |
318 clnt_mt->client_state = BAT_CLIENT_IDLE; | |
319 clnt_mt->signal_cb = NULL; | |
320 clnt_mt->response_cb = NULL; | |
321 break; | |
322 } | |
323 case (BAT_ERROR): | |
324 { | |
325 /* change back the necessary states if error happens */ | |
326 bat_change_client_state(clnt_mt, BAT_CLIENT_IDLE); | |
327 clnt_mt->signal_cb = NULL; | |
328 clnt_mt->response_cb = NULL; | |
329 break; | |
330 } | |
331 case (BAT_OK): | |
332 default: | |
333 { | |
334 break; | |
335 } | |
336 } | |
337 return (ret); | |
338 } | |
339 | |
340 /* | |
341 +----------------------------------------------------------------------------+ | |
342 | PROJECT : MODULE : BINARY AT COMMAND LIBRARY | | |
343 | STATE : code ROUTINE : bat_uns_open | | |
344 +----------------------------------------------------------------------------+ | |
345 PURPOSE : | |
346 This function is used to open a path to receive unsolicited result code. | |
347 This function passes a unique client handle to the application by the output | |
348 parameter client. This client handle is used by bat_close()and bat_cntrl(). | |
349 */ | |
350 | |
351 GLOBAL T_BAT_return bat_uns_open (T_BAT_instance instance, | |
352 T_BAT_client *client, | |
353 int(*unsolicited_result_cb)( T_BAT_client client, T_BAT_cmd_response *response)) | |
354 { | |
355 T_BAT_instance_maintain *inst_mt = NULL; | |
356 | |
357 BAT_TRACE_FUNCTION ("bat_uns_open()"); | |
358 | |
359 /* find the correct instance */ | |
360 if (bat_get_instance_from_instance_handle (instance, &inst_mt) EQ BAT_ERROR) | |
361 { | |
362 return (BAT_ERROR); | |
363 } | |
364 | |
365 /* this func should be called after bat instance is created */ | |
366 if (inst_mt->instance_state < BAT_INSTANCE_READY) | |
367 { | |
368 BAT_TRACE_EVENT_P1 ("ERROR: the instance is not yet initialized! It's state is", | |
369 inst_mt->instance_state); | |
370 return (BAT_ERROR); | |
371 } | |
372 | |
373 inst_mt->unsolicited_result_cb = unsolicited_result_cb; | |
374 *client = MAKE_UNS_CLNT_HNDL(instance); | |
375 | |
376 return (BAT_OK); | |
377 } | |
378 | |
379 | |
380 /* | |
381 +----------------------------------------------------------------------------+ | |
382 | PROJECT : MODULE : BINARY AT COMMAND LIBRARY | | |
383 | STATE : code ROUTINE : bat_close | | |
384 +----------------------------------------------------------------------------+ | |
385 PURPOSE : | |
386 This function is used to close a binary AT command channel. This closing | |
387 process includes closing of the connection to the modem. If the close process | |
388 has been successfully performed, BAT Lib will call the signal callback | |
389 function provided by bat_open() on the application side to indicate. The | |
390 application can delete the BAT Lib instance only after successfully closing | |
391 all the clients by calling bat_close(). | |
392 */ | |
393 | |
394 GLOBAL T_BAT_return bat_close (T_BAT_client clnt_hndl) | |
395 { | |
396 T_BAT_instance_maintain *inst_mt = NULL; | |
397 T_BAT_client_maintain *clnt_mt = NULL; | |
398 T_BATC_signal ctrl_sig; | |
399 T_BATC_close_client param; | |
400 T_BAT_return reslt = BAT_ERROR; | |
401 | |
402 BAT_TRACE_FUNCTION ("bat_close()"); | |
403 | |
404 if (bat_get_instance_from_instance_handle(GET_INST_HNDL_FROM_CLNT_HANDLE(clnt_hndl), &inst_mt)) | |
405 { | |
406 return (BAT_ERROR); | |
407 } | |
408 | |
409 /* if the channel to close is unsolicited code channel */ | |
410 if ((GET_CLNT_ID_FROM_CLNT_HANDLE(clnt_hndl) EQ BAT_BROADCAST_CHANNEL)) | |
411 { | |
412 inst_mt->unsolicited_result_cb = NULL; | |
413 /* if there is still data in the buffer for this channel, just ignore the data and empty the buffer */ | |
414 if ((inst_mt->buffer.buf_st EQ BAT_BUF_FILLED) AND (inst_mt->buffer.dest EQ clnt_hndl)) | |
415 { | |
416 bat_change_buffer_state(inst_mt, BAT_BUF_EMPTY); | |
417 inst_mt->config->adapter.gdd_if.gdd_signal_ready_rcv ((T_GDD_CON_HANDLE)(inst_mt->con_handle)); | |
418 } | |
419 return (BAT_OK); | |
420 } | |
421 | |
422 /* If the channel to close is a normal client channel */ | |
423 if (bat_get_client_from_client_handle(clnt_hndl, &clnt_mt) OR | |
424 clnt_mt->client_state < BAT_CLIENT_ACTIVATING) | |
425 { | |
426 BAT_TRACE_ERROR ("ERROR: parameter wrong or BAT client is not yet open."); | |
427 return (BAT_ERROR); | |
428 } | |
429 | |
430 param.client_id = GET_CLNT_ID_FROM_CLNT_HANDLE(clnt_hndl); | |
431 | |
432 ctrl_sig.ctrl_params = BATC_CLOSE_CLIENT; | |
433 ctrl_sig.params.ptr_close_client = ¶m; | |
434 | |
435 /* send control data to BAT ACI */ | |
436 reslt = bat_send_ctrl_data(GET_INST_HNDL_FROM_CLNT_HANDLE(clnt_hndl), &ctrl_sig); | |
437 | |
438 /* change back the necessary states if GDD busy */ | |
439 switch (reslt) | |
440 { | |
441 case (BAT_BUSY_RESOURCE): | |
442 { | |
443 bat_change_client_state(clnt_mt, BAT_CLIENT_BUSY); | |
444 return (BAT_BUSY_RESOURCE); | |
445 } | |
446 case (BAT_ERROR): | |
447 { | |
448 return (BAT_ERROR); | |
449 } | |
450 case (BAT_OK): | |
451 { | |
452 break; | |
453 } | |
454 } | |
455 | |
456 /* client state is now changed to Idle, the close function always performs, no asynchronized signal */ | |
457 bat_change_client_state(clnt_mt, BAT_CLIENT_IDLE); | |
458 | |
459 /* if the buffer is filled with data for this client, free it and send a ready signal to GDD */ | |
460 if ((inst_mt->buffer.buf_st EQ BAT_BUF_FILLED) AND (inst_mt->buffer.dest EQ clnt_hndl)) | |
461 { | |
462 bat_change_buffer_state(inst_mt, BAT_BUF_EMPTY); | |
463 inst_mt->config->adapter.gdd_if.gdd_signal_ready_rcv ((T_GDD_CON_HANDLE)(inst_mt->con_handle)); | |
464 } | |
465 | |
466 return (BAT_OK); | |
467 } | |
468 | |
469 /* | |
470 +----------------------------------------------------------------------------+ | |
471 | PROJECT : MODULE : BINARY AT COMMAND LIBRARY | | |
472 | STATE : code ROUTINE : bat_close | | |
473 +----------------------------------------------------------------------------+ | |
474 PURPOSE : | |
475 This function is used to send a BAT command. The final result is received | |
476 asynchronously by response_cb(). | |
477 */ | |
478 | |
479 GLOBAL T_BAT_return bat_send (T_BAT_client clnt_hndl, T_BAT_cmd_send *cmd) | |
480 { | |
481 T_BAT_client_maintain *clnt_mt = NULL; | |
482 T_BAT_return ret = BAT_ERROR; | |
483 | |
484 BAT_TRACE_FUNCTION ("bat_send()"); | |
485 | |
486 /* find the client */ | |
487 if (bat_get_client_from_client_handle(clnt_hndl, &clnt_mt) NEQ BAT_OK) | |
488 { | |
489 BAT_TRACE_EVENT_P1("bat_send(): unknown client handle %d", clnt_hndl); | |
490 return (BAT_ERROR); | |
491 } | |
492 | |
493 if (clnt_mt->client_state NEQ BAT_CLIENT_READY) | |
494 { | |
495 TRACE_EVENT_P1("bat_send(): client is not in state READY, but in %d", clnt_mt->client_state); | |
496 return (BAT_ERROR); | |
497 } | |
498 | |
499 if (cmd EQ NULL) | |
500 { | |
501 TRACE_EVENT("bat_send(): cmd EQ NULL"); | |
502 return (BAT_ERROR); | |
503 } | |
504 | |
505 bat_change_client_state(clnt_mt, BAT_CLIENT_SENDING); | |
506 /* send the data (get buffer, fill buffer and send) */ | |
507 ret = bat_send_cmd_data(clnt_hndl, cmd); | |
508 | |
509 switch (ret) | |
510 { | |
511 case (BAT_BUSY_RESOURCE): | |
512 { | |
513 bat_change_client_state(clnt_mt, BAT_CLIENT_BUSY); | |
514 break; | |
515 } | |
516 case (BAT_ERROR): | |
517 { | |
518 bat_change_client_state(clnt_mt, BAT_CLIENT_READY); | |
519 break; | |
520 } | |
521 default: | |
522 { | |
523 break; | |
524 } | |
525 } | |
526 return (ret); | |
527 } | |
528 | |
529 /* | |
530 +----------------------------------------------------------------------------+ | |
531 | PROJECT : MODULE : BINARY AT COMMAND LIBRARY | | |
532 | STATE : code ROUTINE : bat_close | | |
533 +----------------------------------------------------------------------------+ | |
534 PURPOSE : | |
535 This function is used to send control information, which is not directly | |
536 related to a binary command request or response, to the BAT library. E.g. | |
537 telling the BAT Lib to stop the currently running BAT command or to inform | |
538 the BAT Lib that the application is no longer at BAT_BUSY_RESOURCE state, | |
539 but is able to receive more data. | |
540 */ | |
541 | |
542 GLOBAL T_BAT_return bat_ctrl (T_BAT_client clnt_hndl, T_BAT_ctrl *ctrl) | |
543 { | |
544 T_BAT_instance_maintain *inst_mt = NULL; | |
545 T_BAT_client_maintain *clnt_mt = NULL; | |
546 T_BATC_signal ctrl_sig; | |
547 T_BATC_abort_cmd param; | |
548 T_BAT_return ret = BAT_ERROR; | |
549 | |
550 BAT_TRACE_FUNCTION ("bat_ctrl()"); | |
551 | |
552 /* check the ctrl param */ | |
553 if (ctrl EQ NULL) | |
554 { | |
555 return (BAT_ERROR); | |
556 } | |
557 | |
558 /* get the correct instance */ | |
559 if (bat_get_instance_from_instance_handle (GET_INST_HNDL_FROM_CLNT_HANDLE(clnt_hndl), &inst_mt)) | |
560 { | |
561 return (BAT_ERROR); | |
562 } | |
563 | |
564 /* abort the running cmd */ | |
565 if (ctrl->event EQ BAT_ABORT) | |
566 { | |
567 /* get the correct client */ | |
568 if (bat_get_client_from_client_handle (clnt_hndl, &clnt_mt)) | |
569 { | |
570 return (BAT_ERROR); | |
571 } | |
572 | |
573 if (clnt_mt->client_state < BAT_CLIENT_SENDING) | |
574 { | |
575 BAT_TRACE_ERROR ("bat_ctrl(): No running cmd to abort."); | |
576 return (BAT_ERROR); | |
577 } | |
578 | |
579 /* set the abort cmd */ | |
580 param.client_id = GET_CLNT_ID_FROM_CLNT_HANDLE(clnt_hndl); | |
581 ctrl_sig.ctrl_params = BATC_ABORT_CMD; | |
582 ctrl_sig.params.ptr_abort_cmd = ¶m; | |
583 | |
584 ret = bat_send_ctrl_data(GET_INST_HNDL_FROM_CLNT_HANDLE(clnt_hndl), &ctrl_sig); | |
585 | |
586 switch (ret) | |
587 { | |
588 case (BAT_BUSY_RESOURCE): | |
589 { | |
590 /* change back the client state if the command can not be aborted */ | |
591 bat_change_client_state(clnt_mt, BAT_CLIENT_SENDING_AND_BUSY); | |
592 break; | |
593 } | |
594 case (BAT_ERROR): | |
595 { | |
596 BAT_TRACE_ERROR ("bat_ctrl(): sending of ctrl data FAILED!"); | |
597 break; | |
598 } | |
599 default: | |
600 { | |
601 break; | |
602 } | |
603 } | |
604 return (ret); | |
605 } | |
606 | |
607 /* this is a ready signal */ | |
608 if (ctrl->event EQ BAT_APP_READY_RESOURCE) | |
609 { | |
610 if ((inst_mt->buffer.buf_st EQ BAT_BUF_FILLED) AND (inst_mt->buffer.dest EQ clnt_hndl)) | |
611 { | |
612 BAT_TRACE_EVENT("bat_ctrl(): Ready signal received, buffered data will be sent!"); | |
613 | |
614 /* handle the case when the buffer is filled with unsolicited code */ | |
615 if ((clnt_hndl EQ MAKE_UNS_CLNT_HNDL(GET_INST_HNDL_FROM_CLNT_HANDLE(clnt_hndl)))) | |
616 { | |
617 if (inst_mt->unsolicited_result_cb (clnt_hndl, &(inst_mt->buffer.rsp)) NEQ BAT_BUSY_RESOURCE) | |
618 { | |
619 bat_change_buffer_state(inst_mt, BAT_BUF_EMPTY); | |
620 | |
621 inst_mt->config->adapter.gdd_if.gdd_signal_ready_rcv ((T_GDD_CON_HANDLE)(inst_mt->con_handle)); | |
622 BAT_TRACE_EVENT("bat_ctrl(): Buffer sent to APP and the ready signal sent to GDD!"); | |
623 } | |
624 return (BAT_OK); | |
625 } | |
626 else /* signal the GDD that the BAT Lib is able to receive more data */ | |
627 { | |
628 /* get the correct client */ | |
629 if (bat_get_client_from_client_handle (clnt_hndl, &clnt_mt)) | |
630 { | |
631 return (BAT_ERROR); | |
632 } | |
633 if (clnt_mt->response_cb(clnt_hndl, &(inst_mt->buffer.rsp)) NEQ BAT_BUSY_RESOURCE) | |
634 { | |
635 bat_change_buffer_state(inst_mt, BAT_BUF_EMPTY); | |
636 bat_change_client_state(clnt_mt, BAT_CLIENT_READY); | |
637 | |
638 inst_mt->config->adapter.gdd_if.gdd_signal_ready_rcv ((T_GDD_CON_HANDLE)(inst_mt->con_handle)); | |
639 BAT_TRACE_EVENT("bat_ctrl(): Buffer sent to APP and the ready signal sent to GDD!"); | |
640 } | |
641 return (BAT_OK); | |
642 } | |
643 } | |
644 } | |
645 return (BAT_ERROR); | |
646 } | |
647 | |
648 | |
649 #endif | |
650 | |
651 | |
652 |