comparison src/g23m-aci/bat/bat_adp.c @ 1:d393cd9bb723

src/g23m-*: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
0:b6a5e36de839 1:d393cd9bb723
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 used by GDD
18 | for the binary AT command library
19 +-----------------------------------------------------------------------------
20 */
21
22 #define _BAT_ADP_C_
23
24 #include "typedefs.h"
25 #include "gdd.h"
26 #include "l2p_types.h"
27 #include "l2p.h"
28 #include "bat.h"
29 #include "bat_ctrl.h"
30 #include "bat_intern.h"
31
32
33 /*
34 +----------------------------------------------------------------------------+
35 | PROJECT : MODULE : BINARY AT COMMAND LIBRARY |
36 | STATE : code ROUTINE : bat_gdd_receive_data_cb |
37 +----------------------------------------------------------------------------+
38 PURPOSE :
39 This function is called by GDD when itself received new data from PSI.
40 It will pass a GDD buffer (linked list), which has the following speciality:
41 - the first list element is reserved and BAT Lib has to follow the next pointer
42 to see the "first" user data.
43 - such a user data element is passed by BAT Lib to L2P. L2P added at the sender
44 side its own header, which maintains possibly fragmentation. If the received
45 data have been fragmented by L2P at the sender side, then L2P itself iterates
46 over the GDD linked list by calling bat_l2p_get_next_buf_seg() here at receiver side.
47 When L2P has reassembled from several segments/list element the complete user data,
48 then it passes this complete data to BAT Lib.
49 - BUT THERE IS AN ADDITIONAL SCENARIO:
50 ACI was not able to send the data to PSI/GDD. Then ACI also builds up a linked list
51 until it is able to send to PSI/GDD.
52 Every list element represents one response/indication, which itself could be fragmented by L2P.
53 Assume the following scenario:
54 The connection between ACI and PSI was not available.
55 ACI received three indications from the protocol stack, where the second one is too large so that
56 L2P must split it into two segments. That means that ACI has built a linked list of four
57 elements, which represents three logical data unit. The first list element belongs to the
58 first indication, the second and third list element belongs to the second indication
59 and the fourth list element belongs to the third indication.
60 */
61
62 GDD_RESULT bat_gdd_receive_data_cb (T_GDD_CON_HANDLE con, T_GDD_BUF *buf)
63 {
64 T_BAT_instance inst_hndl = BAT_BROADCAST_CHANNEL;
65 T_BAT_instance_maintain *inst_mt = NULL;
66
67 BAT_TRACE_FUNCTION ("bat_gdd_receive_data_cb()");
68 BAT_TRACE_EVENT_P2 ("data received from GDD has length: %d, has c_segment %d", buf->length, buf->c_segment);
69
70 /* if the info is for an unknown instance, return OK, GDD can only handle ok and busy,
71 so in error cases, GDD_OK will be returned */
72 if (bat_get_instance_from_gdd_handle(con, &inst_hndl, &inst_mt))
73 {
74 /* if instance is unknown, BAT Lib ignores the data and returns OK to GDD */
75 BAT_TRACE_ERROR("bat_gdd_receive_data_cb(): Data from unknown instance received!");
76 return (GDD_OK);
77 }
78
79 /* if the instance is not initialized */
80 if (inst_mt->instance_state EQ BAT_INSTANCE_IDLE)
81 {
82 /* if instance is not initialized, BAT Lib ignores the data and returns OK to GDD */
83 BAT_TRACE_ERROR ("bat_gdd_receive_data_cb(): Data is received from GDD for an uninitialized instance.");
84 return (GDD_OK);
85 }
86
87 /* check if the receiver buffer is free, if not return a busy signal to GDD, BAT Lib will
88 send a ready signal to GDD when the buffer is freed (BAT Lib will receive ctrl info from)
89 app, see bat_ctrl() */
90 if (inst_mt->buffer.buf_st EQ BAT_BUF_FILLED)
91 {
92 BAT_TRACE_EVENT ("bat_gdd_receive_data_cb(): receive buffer is not yet freed!");
93 return (GDD_BUSY);
94 }
95
96 bat_l2p_receive(inst_hndl, buf);
97
98 return (GDD_OK);
99 }
100
101
102 LOCAL void bat_check_clients_for_busy (T_BAT_instance_maintain *instance, T_BAT_instance inst_hndl)
103 {
104 T_BAT_client_maintain *clnt_mt = NULL;
105 T_BAT_client clnt_hndl = BAT_INVALID_CLIENT_HANDLE;
106 int i;
107
108 for (i = 0; i < instance->max_client_num; i++)
109 {
110 clnt_hndl = MAKE_CLNT_HNDL(i, inst_hndl);
111 bat_get_client_from_client_handle(clnt_hndl, &clnt_mt);
112 switch (clnt_mt->client_state)
113 {
114 case (BAT_CLIENT_BUSY):
115 {
116 clnt_mt->signal_cb (clnt_hndl, BAT_READY_RESOURCE);
117 bat_change_client_state(clnt_mt, BAT_CLIENT_READY);
118 break;
119 }
120 case (BAT_CLIENT_SENDING_AND_BUSY):
121 {
122 clnt_mt->signal_cb (clnt_hndl, BAT_READY_RESOURCE);
123 bat_change_client_state(clnt_mt, BAT_CLIENT_SENDING);
124 break;
125 }
126 default:
127 break;
128 }
129 }
130 }
131
132 /*
133 +----------------------------------------------------------------------------+
134 | PROJECT : MODULE : BINARY AT COMMAND LIBRARY |
135 | STATE : code ROUTINE : bat_gdd_signal_cb |
136 +----------------------------------------------------------------------------+
137 PURPOSE :
138 This function is called by GDD for signalling of control information between
139 BAT Lib and GDD.
140
141 */
142 void bat_gdd_signal_cb(T_GDD_CON_HANDLE con, T_GDD_SIGNAL signal)
143 {
144 T_BAT_instance_maintain *instance = NULL;
145 T_BAT_instance inst_hndl = BAT_INVALID_INSTANCE_HANDLE;
146 T_BATC_signal ctrl_data;
147 T_BATC_max_clients max_clnt;
148
149 BAT_TRACE_FUNCTION ("bat_gdd_signal_cb()");
150 BAT_TRACE_EVENT_P1 ("bat_gdd_signal_cb(): con_hndl searched for is %x", con);
151
152 if (bat_get_instance_from_gdd_handle(con, &inst_hndl, &instance))
153 {
154 BAT_TRACE_ERROR ("bat_gdd_signal_cb(): gdd handle is not found, ignore signal");
155 return;
156 }
157
158 switch (signal.sig)
159 {
160 case (GDD_SIGTYPE_CONNECTION_OPENED):
161 case (GDD_SIGTYPE_SEND_BUF_AVAILABLE):
162 {
163 BAT_TRACE_EVENT ("bat_gdd_signal_cb(): GDD_SIGTYPE_SEND_BUF_AVAILABLE received from GDD");
164
165 switch (instance->instance_state)
166 {
167 case (BAT_INSTANCE_IDLE):
168 {
169 /* update the instance state */
170 bat_change_instance_state(instance, BAT_INSTANCE_ACTIVATING);
171
172 /* BAT sends out the control info to ACI*/
173 ctrl_data.ctrl_params = BATC_MAX_CLIENTS;
174 max_clnt.num_clients = instance->max_client_num;
175 ctrl_data.params.ptr_max_clients = &max_clnt;
176
177 if (bat_send_ctrl_data(inst_hndl, &ctrl_data) NEQ BAT_OK)
178 {
179 BAT_TRACE_ERROR ("bat_gdd_signal_cb(): BAT new fails to send ctrl info, connection can not be open");
180
181 if (instance->config->adapter.gdd_if.gdd_disconnect(con))
182 {
183 BAT_TRACE_ERROR ("bat_gdd_signal_cb(): GDD returns error when disconnecting.");
184 }
185 instance->instance_signal_cb(BAT_NEW_INSTANCE_FAIL);
186 bat_deinit_instance_pointer(inst_hndl);
187 }
188 break;
189 }
190 /* flow control for client channels, GDD state has be changed from BUSY to READY */
191 case (BAT_INSTANCE_READY):
192 {
193 bat_check_clients_for_busy(instance, inst_hndl);
194 break;
195 }
196 /* flow control for instance, bat_open() hasn't been succesful yet */
197 case (BAT_INSTANCE_BUSY):
198 {
199 instance->instance_signal_cb (BAT_READY_RESOURCE);
200 bat_change_instance_state(instance, BAT_INSTANCE_READY);
201 break;
202 }
203 default:
204 {
205 return;
206 }
207 }
208 break;
209 }
210 case (GDD_SIGTYPE_CONNECTION_FAILED):
211 {
212 BAT_TRACE_ERROR("bat_gdd_signal_cb(): GDD_SIGTYPE_CONNECTION_OPENED_FAILED received from GDD");
213 if (instance->config->adapter.gdd_if.gdd_disconnect(con))
214 {
215 BAT_TRACE_ERROR ("bat_gdd_signal_cb(): GDD returns error when disconnecting.");
216 }
217 instance->instance_signal_cb (BAT_NEW_INSTANCE_FAIL);
218 bat_deinit_instance_pointer(inst_hndl);
219 L2P_Remove (inst_hndl);
220 break;
221 }
222 /* ignore other signal types */
223 default:
224 {
225 break;
226 }
227 }
228 return;
229 }
230
231