FreeCalypso > hg > freecalypso-citrine
comparison g23m-aci/uart/uart_dtxp.c @ 0:75a11d740a02
initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 09 Jun 2016 00:02:41 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:75a11d740a02 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : | |
4 | Modul : | |
5 +----------------------------------------------------------------------------- | |
6 | Copyright 2002 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 is part of the entity UART and implements all | |
18 | functions to handles the incoming primitives as described in | |
19 | the SDL-documentation (DTX-statemachine) | |
20 +----------------------------------------------------------------------------- | |
21 */ | |
22 | |
23 #ifndef UART_DTXP_C | |
24 #define UART_DTXP_C | |
25 #endif /* !UART_DTXP_C */ | |
26 | |
27 #include "config.h" | |
28 #include "fixedconf.h" | |
29 #include "condat-features.h" | |
30 | |
31 #define ENTITY_UART | |
32 | |
33 /*==== INCLUDES =============================================================*/ | |
34 | |
35 #ifdef WIN32 | |
36 #include "nucleus.h" | |
37 #endif /* WIN32 */ | |
38 #include "typedefs.h" /* to get Condat data types */ | |
39 #include "vsi.h" /* to get a lot of macros */ | |
40 #include "macdef.h" /* to get a lot of macros */ | |
41 #include "custom.h" | |
42 #include "gsm.h" /* to get a lot of macros */ | |
43 #include "cnf_uart.h" /* to get cnf-definitions */ | |
44 #include "mon_uart.h" /* to get mon-definitions */ | |
45 #include "prim.h" /* to get the definitions of used SAP and directions */ | |
46 #ifdef DTILIB | |
47 #include "dti.h" /* to get dti lib */ | |
48 #endif /* DTILIB */ | |
49 #include "pei.h" /* to get PEI interface */ | |
50 #ifdef FF_MULTI_PORT | |
51 #include "gsi.h" /* to get definitions of serial driver */ | |
52 #else /* FF_MULTI_PORT */ | |
53 #ifdef _TARGET_ | |
54 #include "../../serial/serialswitch.h" | |
55 #include "../../serial/traceswitch.h" | |
56 #else /* _TARGET_ */ | |
57 #include "serial_dat.h" /* to get definitions of serial driver */ | |
58 #endif /* _TARGET_ */ | |
59 #endif /* FF_MULTI_PORT */ | |
60 #include "uart.h" /* to get the global entity definitions */ | |
61 | |
62 #include "uart_dtxf.h" /* to get DTX function definitions */ | |
63 #include "uart_dtxp.h" /* to get DTX primitive definitions */ | |
64 #include "uart_kers.h" /* to get signal definitions of service KER */ | |
65 #ifdef FF_MULTI_PORT | |
66 #include "uart_prxs.h" /* to get signal definitions for service TX */ | |
67 #else /* FF_MULTI_PORT */ | |
68 #include "uart_rxs.h" /* to get signal definitions of service RX */ | |
69 #endif /* FF_MULTI_PORT */ | |
70 | |
71 #ifdef _SIMULATION_ | |
72 #include <stdio.h> /* to get sprintf */ | |
73 #endif /* _SIMULATION_ */ | |
74 #include <string.h> /* JK, delete warnings: to get memcpy */ | |
75 | |
76 /*==== CONST ================================================================*/ | |
77 | |
78 /*==== LOCAL VARS ===========================================================*/ | |
79 | |
80 /*==== PRIVATE FUNCTIONS ====================================================*/ | |
81 | |
82 /*==== PUBLIC FUNCTIONS =====================================================*/ | |
83 | |
84 | |
85 #ifdef DTILIB | |
86 | |
87 /* | |
88 +------------------------------------------------------------------------------ | |
89 | Function : sig_dti_dtx_tx_buffer_ready_ind | |
90 +------------------------------------------------------------------------------ | |
91 | Description : Handles the DTILIB callback call DTI_REASON_TX_BUFFER_READY | |
92 | | |
93 | This signal means that data may be sent over a dti connection. | |
94 | | |
95 | Parameters : - | |
96 | | |
97 +------------------------------------------------------------------------------ | |
98 * | |
99 * when not using DTILIB, the functionality of sig_dti_dtx_tx_buffer_ready_ind() | |
100 * is to be found in dtx_dti_getdata_req(). When debugging, please have a look at | |
101 * both versions!! | |
102 */ | |
103 | |
104 GLOBAL void sig_dti_dtx_tx_buffer_ready_ind() | |
105 { | |
106 USHORT old_write_pos; | |
107 T_DATA_FLOW_STATE old_data_flow; | |
108 T_desc2* temp_desc; | |
109 | |
110 TRACE_FUNCTION( "sig_dti_dtx_tx_buffer_ready_ind" ); | |
111 | |
112 #ifdef FLOW_TRACE | |
113 sndcp_trace_flow_control(FLOW_TRACE_UART, FLOW_TRACE_UP, FLOW_TRACE_TOP, TRUE); | |
114 #endif /* FLOW_TRACE */ | |
115 switch( GET_STATE( UART_SERVICE_DTX ) ) | |
116 { | |
117 case DTX_NOT_READY: | |
118 old_data_flow = uart_data->dtx->data_flow; | |
119 old_write_pos = uart_data->dtx->write_pos; | |
120 /* | |
121 * enable data flow if necessary | |
122 */ | |
123 if(uart_data->dtx->data_flow NEQ UART_FLOW_ENABLED) | |
124 { | |
125 uart_data->dtx->data_flow = UART_FLOW_ENABLED; | |
126 sig_dtx_ker_enable_ind(uart_data->dtx->dlc_instance); | |
127 } | |
128 | |
129 if(uart_data->dtx->receiving_state EQ UART_DTX_NOT_RECEIVING) | |
130 { | |
131 /* | |
132 * if data to send available or | |
133 * line states changed | |
134 */ | |
135 if((uart_data->dtx->to_send_data->len) || | |
136 (uart_data->dtx->lines_changed)) | |
137 { | |
138 PALLOC_DESC2 (dti_data_ind, DTI2_DATA_IND); | |
139 SET_STATE( UART_SERVICE_DTX, DTX_NOT_READY ); | |
140 | |
141 if(uart_data->dtx->to_send_data->len) | |
142 { | |
143 /* | |
144 * mark entity descriptor as invalid, since data will be forwarded | |
145 */ | |
146 temp_desc = uart_data->dtx->to_send_data; | |
147 uart_data->dtx->to_send_data = NULL; | |
148 | |
149 dti_data_ind->desc_list2.first = (ULONG)temp_desc; | |
150 dti_data_ind->desc_list2.list_len = temp_desc->len; | |
151 | |
152 /* | |
153 * calculate new size multiplier according to fillrate of buffer | |
154 */ | |
155 dtx_calculate_size_multiplier (temp_desc, old_data_flow); | |
156 /* | |
157 * allocate a new descriptor with size according to new size_multiplier | |
158 */ | |
159 dtx_allocate_resources(); | |
160 /* | |
161 * Check for data which has not yet been validated, i.e. because | |
162 * the frame containing the data has not yet been received completely. | |
163 * In this case, the not yet validated data is copied to the newly | |
164 * allocated descriptor. | |
165 */ | |
166 if(old_write_pos > temp_desc->len) | |
167 { | |
168 memcpy(uart_data->dtx->to_send_data->buffer, | |
169 &temp_desc->buffer[temp_desc->len], | |
170 old_write_pos - temp_desc->len); | |
171 uart_data->dtx->write_pos = old_write_pos - temp_desc->len; | |
172 } | |
173 uart_data->dtx->esd_pos-= temp_desc->len; | |
174 } | |
175 else | |
176 { | |
177 /* | |
178 * just line states has been changed | |
179 */ | |
180 dti_data_ind->desc_list2.first = (ULONG)NULL; | |
181 dti_data_ind->desc_list2.list_len = 0; | |
182 } | |
183 | |
184 /* | |
185 * set line states and | |
186 * mark line states as unchanged; | |
187 */ | |
188 #ifdef DTI2 | |
189 dti_data_ind->parameters.st_lines.st_flow = uart_data->dtx->st_flow; | |
190 dti_data_ind->parameters.st_lines.st_line_sa = uart_data->dtx->st_line_sa; | |
191 dti_data_ind->parameters.st_lines.st_line_sb = uart_data->dtx->st_line_sb; | |
192 dti_data_ind->parameters.st_lines.st_line_sb = uart_data->dtx->st_line_sb; | |
193 dti_data_ind->parameters.st_lines.st_break_len = uart_data->dtx->st_break_len; | |
194 #else /* DTI2 */ | |
195 dti_data_ind->st_flow = uart_data->dtx->st_flow; | |
196 dti_data_ind->st_line_sa = uart_data->dtx->st_line_sa; | |
197 dti_data_ind->st_line_sb = uart_data->dtx->st_line_sb; | |
198 dti_data_ind->st_line_sb = uart_data->dtx->st_line_sb; | |
199 dti_data_ind->st_escape = uart_data->dtx->st_escape; | |
200 dti_data_ind->tui = uart_data->tui_uart; | |
201 #endif /* DTI2 */ | |
202 uart_data->dtx->lines_changed = FALSE; | |
203 uart_data->dtx->st_break_len = DTI_BREAK_OFF; | |
204 | |
205 #ifdef _SIMULATION_ | |
206 #ifndef DTI2 | |
207 dti_data_ind->op_ack = OP_UNACK; | |
208 #endif /* !DTI2 */ | |
209 #else /* _SIMULATION_ */ | |
210 #ifdef FLOW_TRACE | |
211 sndcp_trace_flow_control(FLOW_TRACE_UART, FLOW_TRACE_UP, FLOW_TRACE_TOP, FALSE); | |
212 #endif /* FLOW_TRACE */ | |
213 #endif /* _SIMULATION_ */ | |
214 dti_send_data( | |
215 uart_hDTI, | |
216 uart_data->device, | |
217 UART_DTI_UP_INTERFACE, | |
218 uart_data->dtx->dlc_instance, | |
219 dti_data_ind | |
220 ); | |
221 } | |
222 else | |
223 { | |
224 /* | |
225 * no data to send | |
226 */ | |
227 SET_STATE( UART_SERVICE_DTX, DTX_READY ); | |
228 } | |
229 sig_dtx_rx_ready_to_receive_req( uart_data->dtx->dlc_instance, | |
230 uart_data->dtx->to_send_data, | |
231 uart_data->dtx->write_pos, | |
232 uart_data->dtx->cur_desc_size ); | |
233 } | |
234 else | |
235 { | |
236 /* | |
237 * DTX service is currently receiving, | |
238 * data will be forwarded to upper layer when | |
239 * sig_rx_dtx_data_received_ind() is called | |
240 */ | |
241 SET_STATE( UART_SERVICE_DTX, DTX_READY ); | |
242 } | |
243 break; | |
244 | |
245 default: | |
246 TRACE_FUNCTION( "DTI_GETDATA_REQ unexpected" ); | |
247 break; | |
248 } | |
249 } /* sig_dti_dtx_tx_buffer_ready_ind() */ | |
250 | |
251 | |
252 /* | |
253 +------------------------------------------------------------------------------ | |
254 | Function : sig_dti_dtx_tx_buffer_full_ind | |
255 +------------------------------------------------------------------------------ | |
256 | Description : Handles the DTILIB callback call DTI_REASON_TX_BUFFER_FULL | |
257 | Since no send queue is used, this function does not have | |
258 | any functionality by now | |
259 | | |
260 | This signal means that data may not be sent over a dti connection. | |
261 | | |
262 | Parameters : - | |
263 | | |
264 +------------------------------------------------------------------------------ | |
265 */ | |
266 | |
267 GLOBAL void sig_dti_dtx_tx_buffer_full_ind() | |
268 { | |
269 TRACE_FUNCTION( "sig_dti_dtx_tx_buffer_full_ind" ); | |
270 } /* sig_dti_dtx_tx_buffer_full_ind() */ | |
271 | |
272 #else /* DTILIB */ | |
273 /* | |
274 +------------------------------------------------------------------------------ | |
275 | Function : dtx_dti_getdata_req | |
276 +------------------------------------------------------------------------------ | |
277 | Description : Handles the primitive DTI_GETDATA_REQ | |
278 | | |
279 | Parameters : *dti_getdata_req - Ptr to primitive payload | |
280 | | |
281 +------------------------------------------------------------------------------ | |
282 * | |
283 * when using DTILIB, the functionality of dtx_dti_getdata_req() is to be found | |
284 * in sig_dti_dtx_tx_buffer_ready_ind(). When debugging, please have a look at | |
285 * both versions!! | |
286 */ | |
287 GLOBAL void dtx_dti_getdata_req ( T_DTI_GETDATA_REQ *dti_getdata_req ) | |
288 { | |
289 USHORT old_write_pos; | |
290 T_DATA_FLOW_STATE old_data_flow; | |
291 T_desc2* temp_desc; | |
292 | |
293 TRACE_FUNCTION( "dtx_dti_getdata_req" ); | |
294 | |
295 #ifdef FLOW_TRACE | |
296 sndcp_trace_flow_control(FLOW_TRACE_UART, FLOW_TRACE_UP, FLOW_TRACE_TOP, TRUE); | |
297 #endif /* FLOW_TRACE */ | |
298 | |
299 #ifdef UART_RANGE_CHECK | |
300 if(dti_getdata_req EQ NULL) | |
301 { | |
302 TRACE_EVENT("ERROR: dti_getdata_req is NULL"); | |
303 } | |
304 else if((*((ULONG*)((UBYTE*)dti_getdata_req - sizeof(T_PRIM_HEADER) - 8))) NEQ 0) | |
305 { | |
306 TRACE_EVENT_P1("ERROR: dti_getdata_req=%08x is not allocated", | |
307 dti_getdata_req); | |
308 } | |
309 #endif /* UART_RANGE_CHECK */ | |
310 | |
311 if( pei_select_instances( dti_getdata_req->c_id ) EQ TRUE ) | |
312 { | |
313 switch( GET_STATE( UART_SERVICE_DTX ) ) | |
314 { | |
315 case DTX_NOT_READY: | |
316 old_data_flow = uart_data->dtx->data_flow; | |
317 old_write_pos = uart_data->dtx->write_pos; | |
318 /* | |
319 * enable data flow if necessary | |
320 */ | |
321 if(uart_data->dtx->data_flow NEQ UART_FLOW_ENABLED) | |
322 { | |
323 uart_data->dtx->data_flow = UART_FLOW_ENABLED; | |
324 sig_dtx_ker_enable_ind(uart_data->dtx->dlc_instance); | |
325 } | |
326 | |
327 if(uart_data->dtx->receiving_state EQ UART_DTX_NOT_RECEIVING) | |
328 { | |
329 /* | |
330 * if data to send available or | |
331 * line states changed | |
332 */ | |
333 if((uart_data->dtx->to_send_data->len) || | |
334 (uart_data->dtx->lines_changed)) | |
335 { | |
336 PALLOC_DESC2 (dti_data_ind, DTI_DATA_IND); | |
337 SET_STATE( UART_SERVICE_DTX, DTX_NOT_READY ); | |
338 | |
339 if(uart_data->dtx->to_send_data->len) | |
340 { | |
341 /* | |
342 * mark entity descriptor as invalid, since data will be forwarded | |
343 */ | |
344 temp_desc = uart_data->dtx->to_send_data; | |
345 uart_data->dtx->to_send_data = NULL; | |
346 | |
347 dti_data_ind->desc_list2.first = (ULONG)temp_desc; | |
348 dti_data_ind->desc_list2.list_len = temp_desc->len; | |
349 | |
350 /* | |
351 * calculate new size multiplier according to fillrate of buffer | |
352 */ | |
353 dtx_calculate_size_multiplier (temp_desc, old_data_flow); | |
354 /* | |
355 * allocate a new descriptor with size according to new size_multiplier | |
356 */ | |
357 dtx_allocate_resources(); | |
358 /* | |
359 * Check for data which has not yet been validated, i.e. because | |
360 * the frame containing the data has not yet been received completely. | |
361 * In this case, the not yet validated data is copied to the newly | |
362 * allocated descriptor. | |
363 */ | |
364 if(old_write_pos > temp_desc->len) | |
365 { | |
366 memcpy(uart_data->dtx->to_send_data->buffer, | |
367 &temp_desc->buffer[temp_desc->len], | |
368 old_write_pos - temp_desc->len); | |
369 uart_data->dtx->write_pos = old_write_pos - temp_desc->len; | |
370 } | |
371 uart_data->dtx->esd_pos-= temp_desc->len; | |
372 } | |
373 else | |
374 { | |
375 /* | |
376 * just line states has been changed | |
377 */ | |
378 dti_data_ind->desc_list2.first = (ULONG)NULL; | |
379 dti_data_ind->desc_list2.list_len = 0; | |
380 } | |
381 | |
382 /* | |
383 * set line states and | |
384 * mark line states as unchanged; | |
385 */ | |
386 dti_data_ind->st_flow = uart_data->dtx->st_flow; | |
387 dti_data_ind->st_line_sa = uart_data->dtx->st_line_sa; | |
388 dti_data_ind->st_line_sb = uart_data->dtx->st_line_sb; | |
389 dti_data_ind->st_line_sb = uart_data->dtx->st_line_sb; | |
390 dti_data_ind->st_escape = uart_data->dtx->st_escape; | |
391 uart_data->dtx->lines_changed = FALSE; | |
392 uart_data->dtx->st_escape = DTI_ESC_OFF; | |
393 | |
394 dti_data_ind->tui = uart_data->tui_uart; | |
395 dti_data_ind->c_id = dtx_get_channel_id(); | |
396 #ifdef _SIMULATION_ | |
397 dti_data_ind->op_ack = OP_UNACK; | |
398 | |
399 dtx_psend_dti_data_test_ind(dti_data_ind); | |
400 #else /* _SIMULATION_ */ | |
401 #ifdef FLOW_TRACE | |
402 sndcp_trace_flow_control(FLOW_TRACE_UART, FLOW_TRACE_UP, FLOW_TRACE_TOP, FALSE); | |
403 #endif /* FLOW_TRACE */ | |
404 PSEND (uart_data->dtx->hComm_DTX_UPLINK, dti_data_ind); | |
405 #endif /* _SIMULATION_ */ | |
406 } | |
407 else | |
408 { | |
409 /* | |
410 * no data to send | |
411 */ | |
412 SET_STATE( UART_SERVICE_DTX, DTX_READY ); | |
413 } | |
414 sig_dtx_rx_ready_to_receive_req( uart_data->dtx->dlc_instance, | |
415 uart_data->dtx->to_send_data, | |
416 uart_data->dtx->write_pos, | |
417 uart_data->dtx->cur_desc_size ); | |
418 } | |
419 else | |
420 { | |
421 /* | |
422 * DTX service is currently receiving, | |
423 * data will be forwarded to upper layer when | |
424 * sig_rx_dtx_data_received_ind() is called | |
425 */ | |
426 SET_STATE( UART_SERVICE_DTX, DTX_READY ); | |
427 } | |
428 break; | |
429 | |
430 default: | |
431 TRACE_FUNCTION( "DTI_GETDATA_REQ unexpected" ); | |
432 break; | |
433 } | |
434 } | |
435 PFREE( dti_getdata_req ); | |
436 } /* dtx_dti_getdata_req() */ | |
437 #endif /* DTILIB */ | |
438 | |
439 | |
440 #if defined ( _SIMULATION_ ) | |
441 #ifndef DTILIB | |
442 /* | |
443 +------------------------------------------------------------------------------ | |
444 | Function : dtx_psend_dti_data_test_ind | |
445 +------------------------------------------------------------------------------ | |
446 | Description : Copies the content of the given DTI DATA IND primitive to a new | |
447 | DTI_DATA_TEST_IND primitive, sends the primitive | |
448 | DTI_DATA_TEST_IND to hCommUPLINK and frees the original | |
449 | DTI_DATA_IND primitive. | |
450 | Note: function is only needed in case of simulation target | |
451 | | |
452 | Parameters : *dti_data_ind - Ptr to primitive payload | |
453 | | |
454 +------------------------------------------------------------------------------ | |
455 */ | |
456 GLOBAL void dtx_psend_dti_data_test_ind ( T_DTI_DATA_IND *dti_data_ind ) | |
457 { | |
458 T_desc2* temp_desc; | |
459 USHORT packet_len; | |
460 USHORT pos; | |
461 char buf[100]; | |
462 USHORT i; | |
463 | |
464 TRACE_FUNCTION( "dtx_psend_dti_data_test_ind" ); | |
465 | |
466 /* | |
467 * create new primitive and copy all parameters into new primitive | |
468 */ | |
469 packet_len = dti_data_ind->desc_list2.list_len; | |
470 { | |
471 PALLOC_SDU (dti_data_test_ind, | |
472 DTI_DATA_TEST_IND, | |
473 (USHORT)(packet_len << 3)); | |
474 dti_data_test_ind->tui = dti_data_ind->tui; | |
475 dti_data_test_ind->c_id = dti_data_ind->c_id; | |
476 dti_data_test_ind->p_id = dti_data_ind->p_id; | |
477 dti_data_test_ind->op_ack = dti_data_ind->op_ack; | |
478 dti_data_test_ind->st_flow = dti_data_ind->st_flow; | |
479 dti_data_test_ind->st_line_sa = dti_data_ind->st_line_sa; | |
480 dti_data_test_ind->st_line_sb = dti_data_ind->st_line_sb; | |
481 dti_data_test_ind->st_escape = dti_data_ind->st_escape; | |
482 /* | |
483 * copy generic data descriptor in sdu | |
484 */ | |
485 temp_desc = (T_desc2*)dti_data_ind->desc_list2.first; | |
486 dti_data_test_ind->sdu.o_buf = 0; | |
487 dti_data_test_ind->sdu.l_buf = (packet_len << 3); | |
488 pos = 0; | |
489 while(temp_desc) | |
490 { | |
491 memcpy(&dti_data_test_ind->sdu.buf[pos], | |
492 temp_desc->buffer, | |
493 temp_desc->len); | |
494 pos += temp_desc->len; | |
495 temp_desc = (T_desc2*)temp_desc->next; | |
496 } | |
497 /* | |
498 * trace output | |
499 */ | |
500 i = 0; | |
501 pos = 0; | |
502 while(pos < packet_len) | |
503 { | |
504 i+= sprintf(&buf[i], "0x%02x, ", dti_data_test_ind->sdu.buf[pos]); | |
505 pos++; | |
506 if(i > 80) | |
507 { | |
508 TRACE_FUNCTION( buf ); | |
509 i = 0; | |
510 } | |
511 else if(pos >= packet_len) | |
512 { | |
513 TRACE_FUNCTION( buf ); | |
514 } | |
515 } | |
516 /* | |
517 * send primitive | |
518 */ | |
519 PSEND (uart_data->dtx->hComm_DTX_UPLINK, dti_data_test_ind); | |
520 } | |
521 /* | |
522 * free the primitive | |
523 */ | |
524 PFREE_DESC(dti_data_ind); | |
525 } /* dtx_psend_dti_data_test_ind() */ | |
526 #endif /* !DTILIB */ | |
527 #endif /* _SIMULATION_ */ | |
528 |