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