comparison src/g23m-aci/uart/uart_rxp.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 (RX-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef UART_RXP_C
24 #define UART_RXP_C
25 #endif /* !UART_RXP_C */
26
27 #define ENTITY_UART
28
29 #ifndef FF_MULTI_PORT
30 /*==== INCLUDES =============================================================*/
31
32 #ifdef WIN32
33 #include "nucleus.h"
34 #endif /* WIN32 */
35 #include "typedefs.h" /* to get Condat data types */
36 #include "vsi.h" /* to get a lot of macros */
37 #include "macdef.h" /* to get a lot of macros */
38 #include "custom.h"
39 #include "gsm.h" /* to get a lot of macros */
40 #include "cnf_uart.h" /* to get cnf-definitions */
41 #include "mon_uart.h" /* to get mon-definitions */
42 #include "prim.h" /* to get the definitions of used SAP and directions */
43 #include "dti.h" /* to get dti lib */
44 #include "pei.h" /* to get PEI interfac */
45 #ifdef _TARGET_
46 #include "uart/serialswitch.h"
47 #include "uart/traceswitch.h"
48 #else /* _TARGET_ */
49 #include "serial_dat.h" /* to get definitions of serial driver */
50 #endif /* _TARGET_ */
51 #include "uart.h" /* to get the global entity definitions */
52
53 #include "uart_rxf.h" /* to get rx functions */
54
55 #include "uart_kers.h" /* to get ker signals */
56 #include "uart_dtxs.h" /* to get dtx signals */
57
58 #ifdef _SIMULATION_
59 #include <stdio.h> /* to get sprintf */
60 #include "uart_rxp.h" /* to get rx_readdata */
61 #endif /* _SIMULATION_ */
62 /*==== CONST ================================================================*/
63
64 /*==== LOCAL VARS ===========================================================*/
65
66 /*==== PRIVATE FUNCTIONS ====================================================*/
67
68 /*==== PUBLIC FUNCTIONS =====================================================*/
69
70
71
72 /*
73 +------------------------------------------------------------------------------
74 | Function : rx_uart_driver_received_ind
75 +------------------------------------------------------------------------------
76 | Description : Handles the primitive UART_DRIVER_RECEIVED_IND
77 |
78 | Parameters : *uart_device - affected device database
79 |
80 +------------------------------------------------------------------------------
81 */
82 GLOBAL void rx_uart_driver_received_ind ( T_UART_DATA* uart_device )
83 {
84 USHORT i;
85 BOOL continuous;
86 T_DLC* dlc;
87 T_desc2* temp_desc = NULL;
88 ULONG line_states;
89
90 TRACE_EVENT( "rx_uart_driver_received_ind()" );
91
92 /*
93 * set affected instance
94 */
95 uart_data = uart_device;
96
97 /*
98 * inform about new line states
99 */
100 if(uart_data->rx.lines NEQ uart_data->rx.prev_lines)
101 {
102 /*
103 * convert line states and send it
104 */
105 line_states = 0;
106 if(uart_data->rx.lines & X_MASK)
107 {
108 line_states|= UART_X_RX_MASK;
109 if(!(uart_data->rx.prev_lines & X_MASK))
110 {
111 TRACE_EVENT("RX Flow Control: stop");
112 }
113 }
114 else if(uart_data->rx.prev_lines & X_MASK)
115 {
116 TRACE_EVENT("RX Flow Control: start");
117 }
118
119 if(uart_data->rx.lines & SA_MASK)
120 {
121 line_states|= UART_SA_RX_MASK;
122 if(!(uart_data->rx.prev_lines & SA_MASK))
123 {
124 TRACE_EVENT("DTR: drop");
125 }
126 }
127 else if(uart_data->rx.prev_lines & SA_MASK)
128 {
129 TRACE_EVENT("DTR: on");
130 }
131
132 if(uart_data->rx.lines & SB_MASK)
133 {
134 line_states|= UART_SB_RX_MASK;
135 if(!(uart_data->rx.prev_lines & SB_MASK))
136 {
137 TRACE_EVENT("RTS: off");
138 }
139 }
140 else if(uart_data->rx.prev_lines & SB_MASK)
141 {
142 TRACE_EVENT("RTS: on");
143 }
144
145 if(uart_data->rx.lines & ESC_MASK)
146 {
147 line_states|= UART_ESC_RX_MASK;
148 TRACE_EVENT("Escape Sequence detected");
149 }
150
151 if(uart_data->rx.lines & BRK_MASK)
152 {
153 line_states|= UART_BRK_RX_MASK;
154 line_states|= (((uart_data->rx.lines & BRK_LEN_MASK)
155 >> BRKLEN) << UART_BRKLEN_RX_POS);
156 TRACE_EVENT("Break detected");
157 }
158 /*
159 * store new line states
160 */
161 uart_data->rx.lines&= ~(ESC_MASK |
162 BRK_MASK |
163 BRK_LEN_MASK);
164 uart_data->rx.prev_lines = uart_data->rx.lines;
165 /*
166 * inform MMI
167 */
168 sig_rx_ker_line_states_ind(line_states);
169 }
170
171 switch( GET_STATE( UART_SERVICE_RX ) )
172 {
173 case RX_READY:
174 dlc = &uart_data->dlc_table[UART_CONTROL_INSTANCE];
175 if(uart_data->rx.dlc_instance NEQ UART_EMPTY_INSTANCE)
176 {
177 uart_data->rx.dlc_instance = UART_EMPTY_INSTANCE;
178 uart_data->rx.analyze_state = UART_RX_ERROR;
179 /*
180 * if ISR has read out some data
181 * inform all channels about data reception
182 */
183 if(uart_data->rx.read_permission)
184 {
185 for(i = 0; i <= UART_MAX_NUMBER_OF_CHANNELS; i++)
186 {
187 switch(uart_data->dlc_table[i].receive_process)
188 {
189 case UART_RX_PROCESS_READY:
190 case UART_RX_PROCESS_COMPLETE:
191 /*
192 * inform all channels about data reception
193 */
194 uart_data->dlc_table[i].receive_process = UART_RX_PROCESS_STOP;
195 temp_desc = uart_data->dlc_table[i].receive_data;
196 uart_data->dlc_table[i].receive_data = NULL;
197 if(i EQ UART_CONTROL_INSTANCE)
198 {
199 /*
200 * Control channel
201 */
202 sig_rx_ker_data_received_ind(
203 temp_desc,
204 uart_data->dlc_table[i].receive_pos);
205 }
206 else
207 {
208 /*
209 * Data channel
210 */
211 uart_data->dtx = uart_data->dlc_table[i].dtx;
212 sig_rx_dtx_data_received_ind(
213 temp_desc,
214 uart_data->dlc_table[i].receive_pos);
215 }
216 /* fall through */
217 case UART_RX_PROCESS_STOP:
218 /*
219 * add new channels which want to receive
220 */
221 if(uart_data->dlc_table[i].receive_data)
222 uart_data->dlc_table[i].receive_process = UART_RX_PROCESS_READY;
223 break;
224
225 default:
226 TRACE_EVENT_P2("Unexpected DLC process state: %d | uart_rxp.c(%d)",
227 dlc->receive_process, __LINE__);
228 break;
229 }
230 }
231 }
232 }
233 else
234 {
235 switch(dlc->receive_process)
236 {
237 case UART_RX_PROCESS_READY:
238 case UART_RX_PROCESS_COMPLETE:
239 /*
240 * if ISR has read out some data
241 * inform channel about data reception
242 */
243 if(uart_data->rx.read_permission)
244 {
245 /*
246 * inform channel about data reception
247 */
248 dlc->receive_process = UART_RX_PROCESS_STOP;
249 temp_desc = dlc->receive_data;
250 dlc->receive_data = NULL;
251 uart_data->dtx = dlc->dtx;
252 sig_rx_dtx_data_received_ind(temp_desc, dlc->receive_pos);
253 }
254 /* fall through */
255 case UART_RX_PROCESS_STOP:
256 /*
257 * add new channel which want to receive
258 */
259 if(dlc->receive_data)
260 dlc->receive_process = UART_RX_PROCESS_READY;
261 break;
262
263 default:
264 TRACE_EVENT_P2("Unexpected DLC process state: %d | uart_rxp.c(%d)",
265 dlc->receive_process, __LINE__);
266 break;
267 }
268 }
269 if(dlc->receive_process EQ UART_RX_PROCESS_STOP)
270 {
271 uart_data->rx.receive_state = UART_RX_NOT_RECEIVING;
272 break;
273 }
274
275 #ifdef _SIMULATION_
276 if(rx_inpavail(uart_data->device) > 0)
277 #else /* _SIMULATION_ */
278 if(UF_InpAvail (uart_data->device) > 0)
279 #endif /* _SIMULATION_ */
280 {
281 /*
282 * inform channel about reading
283 */
284 uart_data->rx.read_permission = TRUE;
285 uart_data->dtx = dlc->dtx;
286 sig_rx_dtx_receiving_ind();
287 }
288 else
289 uart_data->rx.read_permission = FALSE;
290
291 if(uart_data EQ (&(uart_data_base[0])))
292 {
293 TRACE_EVENT("UF_ReadData()");
294 #ifdef _SIMULATION_
295 rx_readdata(0);
296 #else /* _SIMULATION_ */
297 UF_ReadData (uart_data->device, sm_suspend, rx_readOutFunc_0);
298 #endif /* else _SIMULATION_ */
299 }
300 #ifdef FF_TWO_UART_PORTS
301 else if(uart_data EQ (&(uart_data_base[1])))
302 {
303 TRACE_EVENT("UF_ReadData()");
304 #ifdef _SIMULATION_
305 rx_readdata(1);
306 #else /* _SIMULATION_ */
307 UF_ReadData (uart_data->device, sm_suspend, rx_readOutFunc_1);
308 #endif /* else _SIMULATION_ */
309 }
310 #endif /* FF_TWO_UART_PORTS */
311 else
312 {
313 TRACE_ERROR("wrong value of uart_data");
314 }
315 break;
316
317 case RX_MUX:
318 if(uart_data->rx.dlc_instance EQ UART_EMPTY_INSTANCE)
319 {
320 uart_data->rx.dlc_instance = UART_CONTROL_INSTANCE;
321 uart_data->rx.analyze_state = UART_RX_ERROR;
322 }
323 continuous = FALSE;
324 for(i = 0; i <= UART_MAX_NUMBER_OF_CHANNELS; i++)
325 {
326 dlc = &uart_data->dlc_table[i];
327 switch(dlc->receive_process)
328 {
329 case UART_RX_PROCESS_READY:
330 case UART_RX_PROCESS_COMPLETE:
331 /*
332 * if ISR has read out some data
333 * inform all channels about data reception
334 */
335 if(uart_data->rx.read_permission)
336 {
337 dlc->receive_process = UART_RX_PROCESS_STOP;
338 temp_desc = dlc->receive_data;
339 dlc->receive_data = NULL;
340 if(i EQ UART_CONTROL_INSTANCE)
341 {
342 /*
343 * Control channel
344 */
345 sig_rx_ker_data_received_ind(temp_desc, dlc->receive_pos);
346 }
347 else
348 {
349 /*
350 * Data channel
351 */
352 uart_data->dtx = dlc->dtx;
353 sig_rx_dtx_data_received_ind(temp_desc, dlc->receive_pos);
354 }
355 }
356 /* fall through */
357 case UART_RX_PROCESS_STOP:
358 /*
359 * add new channels which want to receive
360 */
361 if(dlc->receive_data)
362 dlc->receive_process = UART_RX_PROCESS_READY;
363 break;
364
365 default:
366 TRACE_EVENT_P2("Unexpected DLC process state: %d, uart_rxp.c(%d)",
367 dlc->receive_process, __LINE__);
368 break;
369 }
370 if(dlc->receive_process NEQ UART_RX_PROCESS_STOP)
371 continuous = TRUE;
372 }
373 /*
374 * check whether there is a channel to receive
375 */
376 if(continuous NEQ TRUE)
377 {
378 uart_data->rx.receive_state = UART_RX_NOT_RECEIVING;
379 break;
380 }
381 #ifdef _SIMULATION_
382 if(rx_inpavail(uart_data->device) > 0)
383 #else /* _SIMULATION_ */
384 if(UF_InpAvail (uart_data->device) > 0)
385 #endif /* _SIMULATION_ */
386 {
387 /*
388 * inform each channel about reading
389 */
390 uart_data->rx.read_permission = TRUE;
391 for(i = 0; i <= UART_MAX_NUMBER_OF_CHANNELS; i++)
392 {
393 if(uart_data->dlc_table[i].receive_process EQ UART_RX_PROCESS_READY)
394 {
395 if(i EQ UART_CONTROL_INSTANCE)
396 {
397 /*
398 * Control channel
399 */
400 sig_rx_ker_receiving_ind();
401 }
402 else
403 {
404 /*
405 * Data channel
406 */
407 uart_data->dtx = uart_data->dlc_table[i].dtx;
408 sig_rx_dtx_receiving_ind();
409 }
410 }
411 }
412 }
413 else
414 uart_data->rx.read_permission = FALSE;
415
416 if(uart_data EQ (&(uart_data_base[0])))
417 {
418 TRACE_EVENT("UF_ReadData()");
419 #ifdef _SIMULATION_
420 rx_readdata(0);
421 #else /* _SIMULATION_ */
422 UF_ReadData (uart_data->device, sm_suspend, rx_readOutFunc_0);
423 #endif /* else _SIMULATION_ */
424 }
425 #ifdef FF_TWO_UART_PORTS
426 else if(uart_data EQ (&(uart_data_base[1])))
427 {
428 TRACE_EVENT("UF_ReadData()");
429 #ifdef _SIMULATION_
430 rx_readdata(1);
431 #else /* _SIMULATION_ */
432 UF_ReadData (uart_data->device, sm_suspend, rx_readOutFunc_1);
433 #endif /* else _SIMULATION_ */
434 }
435 #endif /* FF_TWO_UART_PORTS */
436 else
437 {
438 TRACE_ERROR("wrong value of uart_data");
439 }
440 break;
441
442 default:
443 TRACE_ERROR( "UART_DRIVER_RECEIVED_IND unexpected" );
444 break;
445 }
446 } /* rx_uart_driver_received_ind() */
447
448
449
450 #ifdef _SIMULATION_
451 /*
452 +------------------------------------------------------------------------------
453 | Function : rx_dti_data_test_ind
454 +------------------------------------------------------------------------------
455 | Description : Handles the primitive DTI_DATA_TEST_IND
456 |
457 | Parameters : *dti_data_test_ind - Ptr to primitive payload
458 |
459 +------------------------------------------------------------------------------
460 */
461 GLOBAL void rx_dti_data_test_ind ( T_DTI2_DATA_TEST_IND *dti_data_test_ind )
462 {
463 char buf[100];
464 T_reInstMode reInstall;
465 USHORT size[2];
466 USHORT pos;
467 USHORT i;
468 T_UART_DATA* uart_device;
469
470 TRACE_FUNCTION( "rx_dti_data_test_ind" );
471
472 /*
473 * set UART instance
474 */
475 uart_device = &(uart_data_base[UART_TEST_C_ID_1]);
476 /*
477 * copy data to simulation buffer
478 */
479 MFREE_DESC2(uart_device->rx.sim_buffer);
480 MALLOC(uart_device->rx.sim_buffer, (USHORT)(sizeof(T_desc2) - 1 +
481 (dti_data_test_ind->sdu.l_buf >> 3)));
482 memcpy(uart_device->rx.sim_buffer->buffer,
483 &dti_data_test_ind->sdu.buf[dti_data_test_ind->sdu.o_buf >> 3],
484 dti_data_test_ind->sdu.l_buf >> 3);
485 uart_device->rx.sim_buffer->len = dti_data_test_ind->sdu.l_buf >> 3;
486 uart_device->rx.sim_buffer->next = (ULONG)NULL;
487 uart_device->rx.sim_pos = 0;
488 /*
489 * trace output
490 */
491 sprintf(buf, "UART device %d:", dti_data_test_ind->link_id);
492 TRACE_FUNCTION( buf );
493 i = 0;
494 pos = uart_device->rx.sim_pos;
495 while(pos < uart_device->rx.sim_buffer->len)
496 {
497 i+= sprintf(&buf[i], "0x%02x, ", uart_device->rx.sim_buffer->buffer[pos]);
498 pos++;
499 if(i > 80)
500 {
501 TRACE_FUNCTION( buf );
502 i = 0;
503 }
504 else if(pos >= uart_device->rx.sim_buffer->len)
505 {
506 TRACE_FUNCTION( buf );
507 }
508 }
509 /*
510 * set values for ISR
511 */
512 uart_device->rx.source[0] = &uart_device->rx.sim_buffer->buffer[
513 uart_device->rx.sim_pos];
514 uart_device->rx.source[1] = NULL;
515 size[0] = uart_device->rx.sim_buffer->len -
516 uart_device->rx.sim_pos;
517 size[1] = 0;
518
519 /*
520 * call actual function
521 */
522 rx_readOutFunc_0 (FALSE, &reInstall, 1, uart_device->rx.source, size, 0);
523
524 /*
525 * store return values
526 */
527 if(size[0] EQ 0)
528 {
529 MFREE_DESC2(uart_device->rx.sim_buffer);
530 uart_device->rx.sim_buffer = NULL;
531 }
532 else
533 uart_device->rx.sim_pos = uart_device->rx.sim_buffer->len - size[0];
534
535 /*
536 * free the primitive
537 */
538 PFREE(dti_data_test_ind);
539 } /* rx_dti_data_test_ind() */
540
541
542
543 /*
544 +------------------------------------------------------------------------------
545 | Function : rx_readdata
546 +------------------------------------------------------------------------------
547 | Description : Simulates a UF_ReadData() call.
548 |
549 | Parameters : caller - calling UART instance
550 |
551 +------------------------------------------------------------------------------
552 */
553 GLOBAL void rx_readdata (UBYTE caller)
554 {
555 T_reInstMode reInstall;
556 USHORT size[2];
557 T_UART_DATA* uart_device;
558
559 TRACE_FUNCTION( "rx_readdata" );
560
561 /*
562 * set UART instance
563 */
564 uart_device = &(uart_data_base[caller]);
565
566 if(uart_device->rx.sim_buffer EQ NULL)
567 {
568 /*
569 * send DTI_GETDATA_REQ
570 */
571 PALLOC (dti_getdata_req, DTI2_GETDATA_REQ);
572 dti_getdata_req->link_id = LINK_READDATA_PORT_1; /* for usual read_data */
573 PSEND (hCommMMI, dti_getdata_req);
574 }
575 else
576 {
577 /*
578 * set values for ISR
579 */
580 uart_device->rx.source[0] = NULL;
581 uart_device->rx.source[1] = &uart_device->rx.sim_buffer->buffer[
582 uart_device->rx.sim_pos];
583 size[0] = 0;
584 size[1] = uart_device->rx.sim_buffer->len -
585 uart_device->rx.sim_pos;
586
587 /*
588 * call actual function
589 */
590 if(caller EQ 0)
591 {
592 rx_readOutFunc_0 (FALSE, &reInstall, 2, uart_device->rx.source, size, 0);
593 }
594 #ifdef FF_TWO_UART_PORTS
595 else if(caller EQ 1)
596 {
597 rx_readOutFunc_1 (FALSE, &reInstall, 2, uart_device->rx.source, size, 0);
598 }
599 #endif /* FF_TWO_UART_PORTS */
600 else
601 {
602 TRACE_ERROR("wrong caller value");
603 }
604
605 /*
606 * store return values
607 */
608 if(size[1] EQ 0)
609 {
610 MFREE_DESC2(uart_device->rx.sim_buffer);
611 uart_device->rx.sim_buffer = NULL;
612 }
613 else
614 uart_device->rx.sim_pos = uart_device->rx.sim_buffer->len - size[1];
615 }
616 } /* rx_readdata() */
617
618
619
620 /*
621 +------------------------------------------------------------------------------
622 | Function : rx_inpavail
623 +------------------------------------------------------------------------------
624 | Description : Simulates a UF_InpAvail() call.
625 |
626 | Parameters : caller - calling UART instance
627 |
628 | Return : number of octets in Input Queue
629 |
630 +------------------------------------------------------------------------------
631 */
632 GLOBAL USHORT rx_inpavail (UBYTE caller)
633 {
634 T_UART_DATA* uart_device;
635
636 TRACE_FUNCTION( "rx_inpavail" );
637
638 /*
639 * set UART instance
640 */
641 uart_device = &(uart_data_base[caller]);
642
643 if(uart_device->rx.sim_buffer)
644 return uart_device->rx.sim_buffer->len - uart_device->rx.sim_pos;
645 else
646 return 0;
647 } /* rx_inpavail() */
648 #endif /* _SIMULATION_ */
649 #endif /* !FF_MULTI_PORT */