comparison src/g23m-aci/gdd_dio/gdd_dio_drv.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 2004 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 : DIOv4 GDD functional interfaces
18 +-----------------------------------------------------------------------------
19 */
20
21 #define GDD_DIO_DRV_C
22
23 /*==== INCLUDES =============================================================*/
24
25 #include <string.h>
26 #include "typedefs.h" /* to get Condat data types */
27 #include "vsi.h" /* to get a lot of macros */
28
29 /* DIO stuff */
30 #include "dio.h"
31 #include "dio_il/dio_drv.h"
32
33 /* GDD_DIO stuff */
34
35 /* We must define P_DIO_H, in order to avoid inclusion of p_dio.h.
36 This is necessary due to the special fact, that "dio.h", which is included
37 in the header "dio_io/dio_drv.h", mirrors the header "p_dio.h". */
38 #define P_DIO_H
39
40 #include "gdd_dio.h"
41 #include "gdd_dio_rxf.h"
42 #include "gdd_dio_txf.h"
43 #include "gdd_dio_queue.h"
44 #include "gdd_dio_con_mgr.h" /* for gdd_dio_con_mgr_mark_dead() */
45
46
47
48
49 /*==== CONSTANTS ============================================================*/
50
51 /*
52 * SEE_TRACE_DURING_SYS_INIT, if defined, allows the showing of traces during
53 * system initialization. The definition should be removed for normal
54 * operation.
55 * SEE_DIO_READ_WRITE_DATA, if defined, displays the data content of DIO_READ and
56 * DIO_WRITE. The definition should be removed for normal operation.
57 */
58 /* #define SEE_TRACE_DURING_SYS_INIT */
59 /* #define SEE_DIO_READ_WRITE_DATA */
60
61 /*==== DEFINITIONS ==========================================================*/
62
63 #ifdef SEE_TRACE_DURING_SYS_INIT
64
65 #ifdef TRACE_FUNCTION
66 #undef TRACE_FUNCTION
67 #define TRACE_FUNCTION TRACE_ERROR
68 #endif /* #ifdef TRACE_FUNCTION */
69
70 #ifdef TRACE_EVENT
71 #undef TRACE_EVENT
72 #define TRACE_EVENT TRACE_ERROR
73 #endif /* #ifdef TRACE_EVENT */
74
75 #endif /* #ifdef SEE_TRACE_DURING_SYS_INIT */
76
77
78 #define IS_DRV_NUM_BAT(n) (((n&DIO_DRV_MASK)==DIO_DRV_BAT)?TRUE:FALSE)
79 #define IS_DRV_NUM_APP(n) (((n&DIO_DRV_MASK)==DIO_DRV_APP)?TRUE:FALSE)
80 #define IS_DIO_TYPE_PKT(n) (((n&DIO_TYPE_MASK)==DIO_TYPE_PKT)?TRUE:FALSE)
81
82
83 /* The following driver definitions should be removed as soon as the DIO IL
84 contains these definitiones */
85 #ifndef DIO_DRV_TCP
86 #define DIO_DRV_TCP 0x0A000000 /* driver number - TCP/IP adapter */
87 #endif /* DIO_DRV_TCP */
88 #ifndef DIO_DRV_SOCK
89 #define DIO_DRV_SOCK 0x0B000000 /* driver number - Socket adapter */
90 #endif /* DIO_DRV_SOCK */
91 #ifndef DIO_DRV_SOCKCFG
92 #define DIO_DRV_SOCKCFG 0x0C000000 /* driver number - Socket conf. adapter */
93 #endif /* DIO_DRV_SOCKCFG */
94
95
96
97 /*==== TYPES ================================================================*/
98
99
100 /*==== PROTOTYPES GDD DIO INTERFACE FUNCTIONS ================================*/
101
102 void dio_user_ready_gdd(U32 device_range_start, U32 device_range_end,
103 U16 drv_handle, T_DRV_CB_FUNC signal_callback);
104 U16 dio_user_not_ready_gdd(U32 device_range_start, U32 device_range_end);
105 void dio_exit_gdd(void);
106 U16 dio_set_rx_buffer_gdd(U32 device, T_dio_buffer * buffer);
107 U16 dio_read_gdd(U32 device, T_DIO_CTRL * control_info, T_dio_buffer **buffer);
108 U16 dio_write_gdd(U32 device, T_DIO_CTRL * control_info, T_dio_buffer *buffer);
109 U16 dio_get_tx_buffer_gdd(U32 device, T_dio_buffer ** buffer);
110 U16 dio_clear_gdd(U32 device);
111 U16 dio_flush_gdd(U32 device);
112 U16 dio_get_capabilities_gdd(U32 device, T_DIO_CAP ** capabilities);
113 U16 dio_set_config_gdd(U32 device, T_DIO_DCB * dcb);
114 U16 dio_get_config_gdd(U32 device, T_DIO_DCB * dcb);
115 U16 dio_close_device_gdd(U32 device);
116
117
118 /*==== GLOBAL VARS ==========================================================*/
119
120 /*==== LOCAL VARS ===========================================================*/
121
122
123 static T_DIO_FUNC dio_func_bat =
124 {
125 dio_user_ready_gdd,
126 dio_user_not_ready_gdd,
127 dio_exit_gdd,
128 dio_set_rx_buffer_gdd,
129 dio_read_gdd,
130 dio_write_gdd,
131 dio_get_tx_buffer_gdd,
132 dio_clear_gdd,
133 dio_flush_gdd,
134 dio_get_capabilities_gdd,
135 dio_set_config_gdd,
136 dio_get_config_gdd,
137 dio_close_device_gdd
138 };
139
140
141
142 /*==== LOCAL FUNCS ==========================================================*/
143
144
145 /*
146 +------------------------------------------------------------------------------
147 | Function : inst_num_from_dev_id
148 +------------------------------------------------------------------------------
149 | Description : get instance number from device id
150 |
151 | Parameters : con_data - connection data
152 |
153 | Return : >= 0 - Success, instance ID
154 < 0 - Error (invalid device)
155 +------------------------------------------------------------------------------
156 */
157 int inst_num_from_dev_id(U32 device)
158 {
159 U32 drv_num = device & DIO_DRV_MASK;
160
161 switch (drv_num)
162 {
163 case DIO_DRV_BAT:
164 return GDD_INST_BAT;
165 case DIO_DRV_APP:
166 return GDD_INST_APP;
167 case DIO_DRV_TCP:
168 return GDD_INST_TCP;
169 case DIO_DRV_SOCK:
170 return GDD_INST_SOCK;
171 case DIO_DRV_SOCKCFG:
172 return GDD_INST_SOCKCFG;
173 default:
174 return -1;
175 }
176 }
177
178
179 /*
180 +------------------------------------------------------------------------------
181 | Function : get_instance_data
182 +------------------------------------------------------------------------------
183 | Description : Local helper function to get the instance data of a device
184 |
185 | Parameters : gdd_dio_data - pointer to pointer to gdd_dio_data instance
186 | (output parameter)
187 | device - DIO device ID
188 |
189 | Return : FALSE - Success (gdd_dio_data has been set)
190 | TRUE - Failed (invalid device)
191 +------------------------------------------------------------------------------
192 */
193 U16 get_instance_data(T_GDD_DIO_DATA ** /*out*/ gdd_dio_data, U32 device)
194 {
195 int inst = inst_num_from_dev_id(device);
196 if(inst >= 0)
197 {
198 *gdd_dio_data = &(gdd_dio_data_base[inst]);
199 return FALSE;
200 }
201 else
202 {
203 return TRUE;
204 }
205 }
206
207
208 /*
209 +------------------------------------------------------------------------------
210 | Function : get_connection_data
211 +------------------------------------------------------------------------------
212 | Description : Local helper function to map from DIO device ID to the
213 | connection data pointer.
214 |
215 | Parameters : device - DIO device ID
216 | gdd_dio_data - pointer to pointer to gdd_dio_data instance
217 | con_data - pointer to connection data (output parameter)
218 |
219 | Return : FALSE - Success
220 | TRUE - Failed
221 +------------------------------------------------------------------------------
222 */
223 U16 get_connection_data(U32 device, T_GDD_DIO_CON_DATA ** /*out*/ con_data)
224 {
225 int i;
226 T_GDD_DIO_DATA *gdd_dio_data = 0;
227
228 if(get_instance_data(&gdd_dio_data, device))
229 {
230 TRACE_ERROR("[GDD] Bad DIO device number");
231 return DRV_INTERNAL_ERROR;
232 }
233
234 if (gdd_dio_data->ker.state NEQ GDD_DIO_KER_READY)
235 {
236 TRACE_ERROR("[GDD] State error: instance not ready");
237 return DRV_INTERNAL_ERROR;
238 }
239
240 for(i=0; i < gdd_dio_data->max_con; ++i)
241 {
242 if(gdd_dio_data->con_arr[i].dio_device EQ device)
243 {
244 *con_data = &(gdd_dio_data->con_arr[i]);
245 return DRV_OK;
246 }
247 }
248
249 TRACE_ERROR("[GDD] Cannot get connection info for this device");
250 return DRV_INTERNAL_ERROR;
251 }
252
253
254 /*
255 +------------------------------------------------------------------------------
256 | Function : send_gdd_signal
257 +------------------------------------------------------------------------------
258 | Description : Local helper function to send a GDD signal to a GDD client.
259 |
260 | Parameters : con_data - connection data
261 | sig_type - type of signal to send
262 +------------------------------------------------------------------------------
263 */
264
265 LOCAL void send_gdd_signal(T_GDD_DIO_CON_DATA * con_data, T_GDD_SIGTYPE sig_type)
266 {
267 T_GDD_SIGNAL sig;
268 char * sig_type_str;
269
270 switch (sig_type)
271 {
272 case GDD_SIGTYPE_CONNECTION_OPENED: sig_type_str = "GDD_SIGTYPE_CONNECTION_OPENED"; break;
273 case GDD_SIGTYPE_SEND_BUF_AVAILABLE: sig_type_str = "GDD_SIGTYPE_SEND_BUF_AVAILABLE"; break;
274 case GDD_SIGTYPE_CONNECTION_FAILED: sig_type_str = "GDD_SIGTYPE_CONNECTION_FAILED"; break;
275 case GDD_SIGTYPE_BUF_SENT: sig_type_str = "GDD_SIGTYPE_BUF_SENT"; break;
276 default: sig_type_str = "ununsed signal type"; break;
277 }
278
279 TRACE_USER_CLASS_P2(TC_SIGNALS, "[GDD] Sending signal %s to GDD client (con_handle=0x%4x)",
280 sig_type_str, con_data->dio_device);
281
282 sig.sig = sig_type;
283 con_data->sig_cb(con_data->dio_device, sig);
284 }
285
286
287 /*
288 +------------------------------------------------------------------------------
289 | Function : init_dio_driver_instance
290 +------------------------------------------------------------------------------
291 | Description : Local helper initialize a dio driver instance
292 +------------------------------------------------------------------------------
293 */
294 LOCAL void init_dio_driver_instance(T_GDD_DIO_DATA * gdd_dio_data, U16 max_devices)
295 {
296 gdd_dio_data->max_con = (U8) max_devices;
297 gdd_dio_data->ker.state = GDD_DIO_KER_INIT;
298 }
299
300
301
302 /*==== FUNCTIONS EXPORTED VIA dio_export() ==================================*/
303
304 /*
305 +------------------------------------------------------------------------------
306 | Function : dio_user_ready_gdd
307 +------------------------------------------------------------------------------
308 | Description : The function allows the driver to open the channels that have
309 | channel numbers of the given range. Each driver has its ready
310 | function. The function is not called directly by the user of
311 | the DIO interface. The DIO interface layer calls the ready
312 | functions of the DIO driver when dio_user_init() is called.
313 | The driver uses the given signal_callback function for channel
314 | of the given channel number range. The driver stores the
315 | drv_handle and passes it in the T_DRV_SIGNAL structure of the
316 | Signal parameter to the calling process every time the callback
317 | function is called. This function needs to be provided by each
318 | DIO driver in order to enable more than one user using the DIO
319 | interface.
320 |
321 | Parameters : device_range_start - First channel number of a range of
322 | channels which can be handled by a DIO
323 | user now
324 | device_range_end - Last channel number of a range of
325 | channels which can be handled by a
326 | DIO user now
327 | drv_handle - Unique handle of the DIO user.
328 | signal_callback - This parameter points to the function
329 | that is called at the time an event
330 | occurs that is to be signaled.
331 |
332 | Return : none
333 |
334 +------------------------------------------------------------------------------
335 */
336 void dio_user_ready_gdd
337 (
338 U32 device_range_start,
339 U32 device_range_end,
340 U16 drv_handle,
341 T_DRV_CB_FUNC signal_callback
342 )
343 {
344 T_GDD_DIO_DATA *gdd_dio_data = 0;
345
346 TRACE_FUNCTION("[GDD] dio_user_ready_gdd()");
347
348 /* Only packet data is currently supported - this might change later */
349 if(IS_DIO_TYPE_PKT(device_range_start) EQ FALSE)
350 {
351 TRACE_ERROR("[GDD] Non-packet device not supported");
352 return;
353 }
354
355 if(get_instance_data(&gdd_dio_data, device_range_start))
356 {
357 TRACE_ERROR("[GDD] Bad DIO device number");
358 return;
359 }
360
361 if (gdd_dio_data->ker.state NEQ GDD_DIO_KER_INIT)
362 {
363 TRACE_ERROR("[GDD] DIO driver not initialized");
364 return;
365 }
366
367 gdd_dio_data->inst_id = (T_GDD_INST_ID)inst_num_from_dev_id(device_range_start);
368 gdd_dio_data->drv_num = device_range_start & DIO_DRV_MASK;
369 gdd_dio_data->device_range_start = device_range_start;
370 gdd_dio_data->device_range_end = device_range_end;
371 gdd_dio_data->drv_handle = drv_handle;
372 gdd_dio_data->signal_callback = signal_callback;
373
374 gdd_dio_data->ker.state = GDD_DIO_KER_READY;
375
376 } /* dio_user_ready_gdd */
377
378 /*
379 +------------------------------------------------------------------------------
380 | Function : dio_user_not_ready_gdd
381 +------------------------------------------------------------------------------
382 | Description : The function is used to clear the signal_callback/channel
383 | association which was previously set with dio_user_ready_gdd().
384 | That means the signal_callback function of channels of the
385 | given channel number range must not be call any more. All
386 | channels of the given channel number range need to be closed
387 | before the function can be called. The function returns DRV_OK
388 | if it was able to clear the signal_callback/channel
389 | associations successfully. In case there is no channel in the
390 | given channel number range the function also returns DRV_OK.
391 | If there is still an open channel in the given channel number
392 | range then the function returns DRV_INVALID_PARAMS. In this
393 | case the signal_callback function can still be used by the
394 | driver.
395 |
396 | Parameters : device_range_start - First channel number of a range of
397 | channels which can no longer be handled
398 | by a DIO user now
399 | device_range_end - Last channel number of a range of
400 | channels which can no longer be handled
401 | by a DIO user now
402 |
403 | Return : DRV_OK - Initialization successful
404 | DRV_INVALID_PARAMS - User operation can not be terminated yet
405 | DRV_INTERNAL_ERROR - Internal driver error
406 |
407 +------------------------------------------------------------------------------
408 */
409 U16 dio_user_not_ready_gdd
410 (
411 U32 device_range_start,
412 U32 device_range_end
413 )
414 {
415 T_GDD_DIO_DATA *gdd_dio_data = 0;
416
417 TRACE_FUNCTION("[GDD] dio_user_not_ready_gdd()");
418
419 if(get_instance_data(&gdd_dio_data, device_range_start))
420 {
421 TRACE_ERROR("Bad DIO device number");
422 return DRV_INTERNAL_ERROR;
423 }
424
425 if (gdd_dio_data->ker.state NEQ GDD_DIO_KER_READY)
426 {
427 TRACE_ERROR("[GDD] State error: instance not ready");
428 }
429
430 gdd_dio_data->ker.state = GDD_DIO_KER_INIT;
431
432 return DRV_OK;
433 } /* dio_user_not_ready_gdd */
434
435 /*
436 +------------------------------------------------------------------------------
437 | Function : dio_exit_gdd
438 +------------------------------------------------------------------------------
439 | Description : This function is called when this device driver is no longer
440 | longer required. DIO_IL calls this function after both send/
441 | receive buffers in the driver are flushed and all BAT devies
442 | are closed.
443 |
444 | Parameters : none
445 |
446 | Return : none
447 |
448 +------------------------------------------------------------------------------
449 */
450 void dio_exit_gdd(void)
451 {
452 int inst;
453
454 TRACE_FUNCTION("[GDD] dio_exit_gdd()");
455
456 /* Shutdown all instances */
457 for(inst=0; inst<GDD_NUM_INSTS; ++inst)
458 {
459 gdd_dio_data_base[inst].ker.state = GDD_DIO_KER_DEAD;
460 }
461
462 } /* dio_exit_gdd */
463
464 /*
465 +------------------------------------------------------------------------------
466 | Function : dio_set_rx_buffer_gdd
467 +------------------------------------------------------------------------------
468 | Description : This function provides a receive buffer to the driver. The
469 | driver uses this buffer to store the received data of the
470 | specified device. The function should always return immediately
471 | after overtaking the buffer, without waiting for data. To
472 | avoid reception gaps more than one receive buffer should be
473 | provided to the driver via several calls of this function.
474 | The provided buffers should be used in the order they were
475 | provided. If the driver is not able to take over the provided
476 | buffer (e.g. because its internal data buffer queue is full)
477 | the function returns DRV_BUFFER_FULL. The driver uses the
478 | DRV_SIGTYPE_READ signal when data is received.
479 |
480 | Parameters : device - Data device number or DLC number
481 | buffer - Data buffer description
482 |
483 | Return : DRV_OK - Initialization successful
484 | DRV_BUFFER_FULL - Buffer queue is full
485 | DRV_INVALID_PARAMS - User operation can not be terminated yet
486 | DRV_INTERNAL_ERROR - Internal driver error
487 | DRV_NOTCONFIGURED - The device is not yet configured
488 |
489 +------------------------------------------------------------------------------
490 */
491 U16 dio_set_rx_buffer_gdd
492 (
493 U32 device,
494 T_dio_buffer * buffer
495 )
496 {
497 T_GDD_DIO_CON_DATA *con_data = 0;
498 U16 pos = 0;
499
500 TRACE_USER_CLASS(TC_FUNC_DATA_FLOW, "[GDD] dio_set_rx_buffer_gdd()");
501
502 if(get_connection_data(device, &con_data) NEQ DRV_OK)
503 {
504 return DRV_INTERNAL_ERROR;
505 }
506
507 if(gdd_dio_enqueue(buffer, &con_data->rx_queue, &pos) EQ FALSE)
508 {
509 return DRV_BUFFER_FULL;
510 }
511 else
512 {
513 if(con_data->con_state == GDD_DIO_CON_CONNECT)
514 {
515 con_data->con_state = GDD_DIO_CON_READY;
516
517 send_gdd_signal(con_data, GDD_SIGTYPE_CONNECTION_OPENED);
518 }
519 if(con_data->wait_send_buf)
520 {
521 send_gdd_signal(con_data, GDD_SIGTYPE_SEND_BUF_AVAILABLE);
522
523 con_data->wait_send_buf = FALSE;
524 }
525
526 return DRV_OK;
527 }
528 } /* dio_set_rx_buffer_gdd */
529
530 /*
531 +------------------------------------------------------------------------------
532 | Function : dio_read_gdd
533 +------------------------------------------------------------------------------
534 | Description : This function returns a receive buffer and control information.
535 | It should always return immediately after changing internal
536 | states, without waiting for any more data. The receive buffers
537 | should be returned in the same order as provided with the
538 | dio_set_rx_buffer() calls (First-In-First-Out). The returned
539 | buffer is not in control of the driver any more. The buffer
540 | should be returned even if it is empty. If there is no receive
541 | buffer in control of the driver any more then buffer is set to
542 | NULL. In this case only control information is delivered.
543 |
544 | Parameters : device - Data device number or DLC number
545 | control_info - The driver copies control information
546 | into the provided control buffer
547 | buffer - Data buffer description
548 |
549 | Return : DRV_OK - Initialization successful
550 | DRV_INVALID_PARAMS - User operation can not be terminated yet
551 | DRV_INTERNAL_ERROR - Internal driver error
552 | DRV_NOTCONFIGURED - The device is not yet configured
553 |
554 +------------------------------------------------------------------------------
555 */
556 U16 dio_read_gdd
557 (
558 U32 device,
559 T_DIO_CTRL * control_info,
560 T_dio_buffer ** buffer
561 )
562 {
563 T_GDD_DIO_CON_DATA *con_data = 0;
564
565 TRACE_USER_CLASS(TC_FUNC_DATA_FLOW, "[GDD] dio_read_gdd()");
566
567 if(get_connection_data(device, &con_data) NEQ DRV_OK)
568 {
569 return DRV_INTERNAL_ERROR;
570 }
571
572 /* Set control info : do nothing for now! */
573
574 if(gdd_dio_dequeue(&(con_data->rx_queue), buffer) EQ FALSE)
575 {
576 TRACE_ERROR("[GDD] RX queue is empty");
577
578 con_data->con_state = GDD_DIO_CON_READY;
579 return DRV_INTERNAL_ERROR;
580 }
581 else
582 {
583 send_gdd_signal(con_data, GDD_SIGTYPE_BUF_SENT);
584 }
585
586 if(con_data->con_state NEQ GDD_DIO_CON_CLOSE)
587 {
588 con_data->con_state = GDD_DIO_CON_READY;
589 }
590
591 return DRV_OK;
592 } /* dio_read_gdd */
593
594 /*
595 +------------------------------------------------------------------------------
596 | Function : dio_write_gdd
597 +------------------------------------------------------------------------------
598 | Description : This function provides a send buffer to the driver which
599 | contains data to send. This function should return immediately
600 | after overtaking the buffer. To avoid transmission gaps more
601 | than one send buffer should be provided to the driver via
602 | several calls of this function. The provided send buffers
603 | should be sent in the order they were provided. If the driver
604 | is not able to take over the provided buffer (e.g. because its
605 | internal buffer queue is full) the function returns
606 | DRV_BUFFER_FULL. If buffer is set to NULL then the driver only
607 | copies the provided control information. The driver uses the
608 | DRV_SIGTYPE_WRITE signal when the data of the buffer is sent.
609 |
610 | Parameters : device - Data device number or DLC number
611 | control_info - The driver copies control information
612 | into the provided control buffer
613 | buffer - Data buffer description
614 |
615 | Return : DRV_OK - Initialization successful
616 | DRV_BUFFER_FULL - Buffer queue is full
617 | DRV_INVALID_PARAMS - User operation can not be terminated yet
618 | DRV_INTERNAL_ERROR - Internal driver error
619 | DRV_NOTCONFIGURED - The device is not yet configured
620 |
621 +------------------------------------------------------------------------------
622 */
623 U16 dio_write_gdd
624 (
625 U32 device,
626 T_DIO_CTRL * control_info,
627 T_dio_buffer * buf
628 )
629 {
630 T_GDD_DIO_CON_DATA *con_data = 0;
631 U16 pos = 0;
632
633 TRACE_USER_CLASS(TC_FUNC_DATA_FLOW, "[GDD] dio_write_gdd()");
634
635 if(get_connection_data(device, &con_data) NEQ DRV_OK)
636 {
637 return DRV_INTERNAL_ERROR;
638 }
639
640 /* Ignore control information for now */
641
642 if(gdd_dio_enqueue(buf, &con_data->tx_queue, &pos) EQ FALSE)
643 {
644 TRACE_ERROR("[GDD] TX buffer queue full");
645 return DRV_BUFFER_FULL;
646 }
647
648 gdd_dio_tx_receive_buf(con_data->dio_device, buf);
649
650 return DRV_OK;
651 } /* dio_write_gdd */
652
653 /*
654 +------------------------------------------------------------------------------
655 | Function : dio_get_tx_buffer_gdd
656 +------------------------------------------------------------------------------
657 | Description : This function returns a send buffer provided via dio_write().
658 | It should always return immediately after changing internal
659 | states, without waiting for any outstanding events. The send
660 | buffers should be re-turned in the same order as provided with
661 | the dio_write() calls (First-In-First-Out). The returned send
662 | buffer is not in control of the driver any more. If there is
663 | no send buffer in control of the driver any more then buffer is
664 | set to NULL.
665 |
666 | Parameters : device - Data device number or DLC number
667 | buffer - Data buffer description
668 |
669 | Return : DRV_OK - Initialization successful
670 | DRV_INVALID_PARAMS - User operation can not be terminated yet
671 | DRV_INTERNAL_ERROR - Internal driver error
672 | DRV_NOTCONFIGURED - The device is not yet configured
673 |
674 +------------------------------------------------------------------------------
675 */
676 U16 dio_get_tx_buffer_gdd
677 (
678 U32 device,
679 T_dio_buffer ** buffer
680 )
681 {
682 T_GDD_DIO_CON_DATA *con_data = 0;
683
684 TRACE_USER_CLASS(TC_FUNC_DATA_FLOW, "[GDD] dio_get_tx_buffer_gdd()");
685
686 if(get_connection_data(device, &con_data) NEQ DRV_OK)
687 {
688 return DRV_INTERNAL_ERROR;
689 }
690
691 if(gdd_dio_dequeue(&con_data->tx_queue, buffer) EQ FALSE)
692 {
693 TRACE_ERROR("[GDD] TX buffer queue empty");
694 return DRV_INTERNAL_ERROR;
695 }
696
697 return DRV_OK;
698 } /* dio_get_tx_buffer_gdd */
699
700 /*
701 +------------------------------------------------------------------------------
702 | Function : dio_clear_gdd
703 +------------------------------------------------------------------------------
704 | Description : Clear the hardware send buffer of the device.
705 | - currently not needed for GDD_DIO (BAT adapter).
706 |
707 | Parameters : device - Data device number or DLC number
708 |
709 | Return : DRV_OK - Initialization successful
710 | DRV_INVALID_PARAMS - User operation can not be terminated yet
711 | DRV_INTERNAL_ERROR - Internal driver error
712 | DRV_NOTCONFIGURED - The device is not yet configured
713 | DRV_INPROCESS - The driver is busy clearing the buffer
714 |
715 +------------------------------------------------------------------------------
716 */
717 U16 dio_clear_gdd
718 (
719 U32 device
720 )
721 {
722
723 TRACE_FUNCTION("[GDD] dio_clear_gdd()");
724
725 /* Do nothing ! */
726
727 return DRV_OK;
728 } /* dio_clear_gdd */
729
730 /*
731 +------------------------------------------------------------------------------
732 | Function : dio_flush_gdd
733 +------------------------------------------------------------------------------
734 | Description : Flush the hardware send buffer of the device.
735 | - currently not needed for GDD_DIO (BAT adapter).
736 |
737 | Parameters : device - Data device number or DLC number.
738 |
739 | Return : DRV_OK - Initialization successful
740 | DRV_INVALID_PARAMS - User operation can not be terminated yet
741 | DRV_INTERNAL_ERROR - Internal driver error
742 | DRV_NOTCONFIGURED - The device is not yet configured
743 | DRV_INPROCESS - The driver is busy clearing the buffer
744 |
745 +------------------------------------------------------------------------------
746 */
747 U16 dio_flush_gdd
748 (
749 U32 device
750 )
751 {
752
753 TRACE_FUNCTION("[GDD] dio_flush_gdd()");
754
755 /* Do nothing ! */
756
757 return DRV_OK;
758 } /* dio_flush_gdd */
759
760 /*
761 +------------------------------------------------------------------------------
762 | Function : dio_get_capabilities_gdd
763 +------------------------------------------------------------------------------
764 | Description : This function is used to retrieve the capabilities of a device.
765 | It is not allowed to change these values neither by the
766 | driver nor by the protocol stack.
767 |
768 | Parameters : device - Data device number or DLC number.
769 | capabilities - Pointer to the device capabilities.
770 |
771 | Return : DRV_OK - Initialization successful
772 | DRV_INVALID_PARAMS - User operation can not be terminated yet
773 | DRV_INTERNAL_ERROR - Internal driver error
774 |
775 +------------------------------------------------------------------------------
776 */
777 U16 dio_get_capabilities_gdd
778 (
779 U32 device,
780 T_DIO_CAP ** capabilities
781 )
782 {
783 T_GDD_DIO_CON_DATA * con_data;
784
785 TRACE_FUNCTION("[GDD] dio_get_capabilities_gdd()");
786
787 if(get_connection_data(device, &con_data) NEQ DRV_OK)
788 {
789 return DRV_INTERNAL_ERROR;
790 }
791
792 if(inst_num_from_dev_id(device) < 0)
793 {
794 TRACE_ERROR("[GDD] Bad device");
795 send_gdd_signal(con_data, GDD_SIGTYPE_CONNECTION_FAILED);
796 return DRV_INTERNAL_ERROR;
797 }
798
799 /* Only packet data is supported */
800 if(IS_DIO_TYPE_PKT(device))
801 {
802 *capabilities = (T_DIO_CAP *) & con_data->dio_cap;
803 return DRV_OK;
804 }
805 else
806 {
807 *capabilities = NULL;
808 send_gdd_signal(con_data, GDD_SIGTYPE_CONNECTION_FAILED);
809 return DRV_INVALID_PARAMS;
810 }
811 } /* dio_get_capability_gdd */
812
813 /*
814 +------------------------------------------------------------------------------
815 | Function : dio_set_config_gdd
816 +------------------------------------------------------------------------------
817 | Description : This function is used to configure a device (transmission rate,
818 | flow control, etc). A device can be configured at any time.
819 | dcb points to a Device Control Block. The parameters that can
820 | be configured are included in the Device Control Block. If any
821 | value of the configuration is out of range, not supported or
822 | invalid in combination with any other value of the
823 | configuration, the function returns DRV_INVALID_PARAMS. Each
824 | device needs to be configured after the reception of a
825 | DRV_SIGTYPE_CONNECT signal. Only dio_get_capabilities(),
826 | dio_set_config() and dio_close_device() can be called while the
827 | device is not configured. All other device-specific functions
828 | return DRV_NOTCONFIGURED.
829 |
830 | Parameters : device - Data device number or DLC number
831 | dcb - Pointer to a Device Control Block
832 |
833 | Return : DRV_OK - Initialization successful
834 | DRV_INVALID_PARAMS - User operation can not be terminated yet
835 | DRV_INTERNAL_ERROR - Internal driver error
836 |
837 +------------------------------------------------------------------------------
838 */
839 U16 dio_set_config_gdd
840 (
841 U32 device,
842 T_DIO_DCB * dcb
843 )
844 {
845 T_GDD_DIO_CON_DATA * con_data;
846
847 TRACE_FUNCTION("[GDD] dio_set_config_gdd()");
848
849 if(get_connection_data(device, &con_data) NEQ DRV_OK)
850 {
851 return DRV_INTERNAL_ERROR;
852 }
853
854 if (dcb EQ NULL)
855 {
856 TRACE_ERROR("[GDD] dcb is NULL");
857 send_gdd_signal(con_data, GDD_SIGTYPE_CONNECTION_FAILED);
858 return DRV_INTERNAL_ERROR;
859 }
860
861 if (DIO_TYPE_PKT != dcb->device_type)
862 {
863 TRACE_ERROR("[GDD] bad dcb->device_type");
864 send_gdd_signal(con_data, GDD_SIGTYPE_CONNECTION_FAILED);
865 return DRV_INVALID_PARAMS;
866 }
867
868 /* Ignore dbc->sleep_mode. */
869
870 return DRV_OK;
871 } /* dio_set_config_gdd */
872
873 /*
874 +------------------------------------------------------------------------------
875 | Function : dio_get_config_gdd
876 +------------------------------------------------------------------------------
877 | Description : This function is used to retrieve the configuration of a
878 | device. The driver copies the configuration into the Device
879 | Control Block provided with dcb.
880 |
881 | Parameters : device - Data device number or DLC number
882 | dcb - Pointer to a Device Control Block
883 |
884 | Return : DRV_OK - Initialization successful
885 | DRV_INVALID_PARAMS - User operation can not be terminated yet
886 | DRV_INTERNAL_ERROR - Internal driver error
887 | DRV_NOTCONFIGURED - The device is not yet configured
888 |
889 +------------------------------------------------------------------------------
890 */
891 U16 dio_get_config_gdd
892 (
893 U32 device,
894 T_DIO_DCB * dcb
895 )
896 {
897 T_GDD_DIO_DATA * gdd_dio_data;
898
899 TRACE_FUNCTION("[GDD] dio_get_config_gdd()");
900
901 if(get_instance_data(&gdd_dio_data, device))
902 {
903 TRACE_ERROR("[GDD] Bad DIO device number");
904 return DRV_INTERNAL_ERROR;
905 }
906
907 if (gdd_dio_data->ker.state NEQ GDD_DIO_KER_READY)
908 {
909 TRACE_ERROR("[GDD] State error: instance not ready");
910 return GDD_DIO_NOT_READY;
911 }
912
913 dcb->device_type = DIO_TYPE_PKT;
914 dcb->sleep_mode = DIO_SLEEP_DISABLE;
915
916 return DRV_OK;
917 } /* dio_get_config_gdd */
918
919 /*
920 +------------------------------------------------------------------------------
921 | Function : dio_close_device_gdd
922 +------------------------------------------------------------------------------
923 | Description : This function is used to close a device. The driver returns
924 | DRV_OK if it was able to close the device successfully. In case
925 | the specified device does not exist the driver also returns
926 | DRV_OK. If the driver still controls a protocol stack buffer
927 | for this device then it returns DRV_INVALID_PARAMS. In this
928 | case the device is not closed. In order to get the remaining
929 | buffers the protocol stack needs to call the functions
930 | dio_read() and dio_get_tx_buffer().
931 |
932 | Parameters : device - Data device number or DLC number
933 |
934 | Return : DRV_OK - Initialization successful
935 | DRV_INVALID_PARAMS - User operation can not be terminated yet
936 | DRV_INTERNAL_ERROR - Internal driver error
937 |
938 +------------------------------------------------------------------------------
939 */
940 U16 dio_close_device_gdd
941 (
942 U32 device
943 )
944 {
945 T_GDD_DIO_CON_DATA * con_data;
946
947 TRACE_FUNCTION("[GDD] dio_close_device_gdd()");
948
949 if(get_connection_data(device, &con_data) NEQ DRV_OK)
950 {
951 return DRV_INTERNAL_ERROR;
952 }
953
954 /* Inform client: in case the connection was closing,
955 we mark the connection as dead. If not, it means that the
956 connection (which was not yet established) has failed. */
957 if(con_data->con_state EQ GDD_DIO_CON_CLOSE)
958 {
959 gdd_dio_con_mgr_mark_dead(con_data->dio_device);
960 }
961 else
962 {
963 send_gdd_signal(con_data, GDD_SIGTYPE_CONNECTION_FAILED);
964 }
965
966 return DRV_OK;
967 } /* dio_close_device_bat */
968
969
970
971 /*==== EXPORTED FUNCTIONS ===================================================*/
972
973 /*
974 +------------------------------------------------------------------------------
975 | Function : dio_init_bat
976 +------------------------------------------------------------------------------
977 | Description : The function initializes the BAT driver. The
978 | function returns DRV_INITIALIZED if the driver has already been
979 | initialized and is ready to be used or is already in use. In
980 | case of initialization failure (e.g. the configuration given
981 | with drv_init can not be used) the function returns
982 | DRV_INITFAILURE. In this case the driver can not be used.
983 |
984 | Parameters : none
985 |
986 | Return : DRV_OK - Initialization successful
987 | DRV_INITIALIZED - Interface already initialized
988 | DRV_INITFAILURE - Initialization failed
989 |
990 +------------------------------------------------------------------------------
991 */
992 U16 dio_init_bat
993 (
994 T_DIO_DRV * drv_init
995 )
996 {
997 T_GDD_DIO_DATA * gdd_dio_data = &gdd_dio_data_base[GDD_INST_BAT];
998
999 TRACE_FUNCTION("[GDD] dio_init_bat()");
1000
1001 if (gdd_dio_data->ker.state NEQ GDD_DIO_KER_DEAD)
1002 {
1003 TRACE_FUNCTION("Instance 'BAT' already initialized");
1004 return DRV_INITIALIZED;
1005 }
1006
1007 init_dio_driver_instance(gdd_dio_data, drv_init->max_devices);
1008
1009 return DRV_OK;
1010 } /* dio_init_bat */
1011
1012 /*
1013 +------------------------------------------------------------------------------
1014 | Function : dio_export_bat
1015 +------------------------------------------------------------------------------
1016 | Description : The function returns, through dio_func, a list of functions
1017 | that are exported by the BAT driver. DIO_IL calls this
1018 | function after dio_init_bat call return DRV_OK.
1019 |
1020 | Parameters : dio_func - Return as a pointer to the list of functions
1021 | exported by the driver.
1022 |
1023 | Return : none
1024 |
1025 +------------------------------------------------------------------------------
1026 */
1027 void dio_export_bat
1028 (
1029 T_DIO_FUNC ** dio_func
1030 )
1031 {
1032 TRACE_FUNCTION("[GDD] dio_export_bat");
1033
1034 *dio_func = (T_DIO_FUNC*) &dio_func_bat;
1035
1036 } /* dio_export_bat */
1037
1038
1039 /*
1040 +------------------------------------------------------------------------------
1041 | Function : dio_init_app
1042 +------------------------------------------------------------------------------
1043 | Description : The function initializes the APP driver. The
1044 | function returns DRV_INITIALIZED if the driver has already been
1045 | initialized and is ready to be used or is already in use. In
1046 | case of initialization failure (e.g. the configuration given
1047 | with drv_init can not be used) the function returns
1048 | DRV_INITFAILURE. In this case the driver can not be used.
1049 |
1050 | Parameters : none
1051 |
1052 | Return : DRV_OK - Initialization successful
1053 | DRV_INITIALIZED - Interface already initialized
1054 | DRV_INITFAILURE - Initialization failed
1055 |
1056 +------------------------------------------------------------------------------
1057 */
1058 U16 dio_init_app
1059 (
1060 T_DIO_DRV * drv_init
1061 )
1062 {
1063 T_GDD_DIO_DATA * gdd_dio_data = &gdd_dio_data_base[GDD_INST_APP];
1064
1065 TRACE_FUNCTION("[GDD] dio_init_app()");
1066
1067 if (gdd_dio_data->ker.state NEQ GDD_DIO_KER_DEAD)
1068 {
1069 TRACE_FUNCTION("[GDD] Instance 'APP' already initialized");
1070 return DRV_INITIALIZED;
1071 }
1072
1073 init_dio_driver_instance(gdd_dio_data, drv_init->max_devices);
1074
1075 return DRV_OK;
1076 } /* dio_init_app */
1077
1078
1079 /*
1080 +------------------------------------------------------------------------------
1081 | Function : dio_export_app
1082 +------------------------------------------------------------------------------
1083 | Description : The function returns, through dio_func, a list of functions
1084 | that are exported by the APP driver. DIO_IL calls this
1085 | function after dio_init_bat call return DRV_OK.
1086 |
1087 | Parameters : dio_func - Return as a pointer to the list of functions
1088 | exported by the driver.
1089 |
1090 | Return : none
1091 |
1092 +------------------------------------------------------------------------------
1093 */
1094 void dio_export_app
1095 (
1096 T_DIO_FUNC ** dio_func
1097 )
1098 {
1099 TRACE_FUNCTION("[GDD] dio_export_app()");
1100
1101 *dio_func = (T_DIO_FUNC*) &dio_func_bat;
1102
1103 } /* dio_export_app */
1104
1105
1106 /*
1107 +------------------------------------------------------------------------------
1108 | Function : dio_init_sock
1109 +------------------------------------------------------------------------------
1110 | Description : The function initializes the TCP driver. The
1111 | function returns DRV_INITIALIZED if the driver has already been
1112 | initialized and is ready to be used or is already in use. In
1113 | case of initialization failure (e.g. the configuration given
1114 | with drv_init can not be used) the function returns
1115 | DRV_INITFAILURE. In this case the driver can not be used.
1116 |
1117 | Parameters : none
1118 |
1119 | Return : DRV_OK - Initialization successful
1120 | DRV_INITIALIZED - Interface already initialized
1121 | DRV_INITFAILURE - Initialization failed
1122 |
1123 +------------------------------------------------------------------------------
1124 */
1125 U16 dio_init_tcp
1126 (
1127 T_DIO_DRV * drv_init
1128 )
1129 {
1130 T_GDD_DIO_DATA * gdd_dio_data = &gdd_dio_data_base[GDD_INST_TCP];
1131
1132 TRACE_FUNCTION("[GDD] dio_init_tcp()");
1133
1134 if (gdd_dio_data->ker.state NEQ GDD_DIO_KER_DEAD)
1135 {
1136 TRACE_FUNCTION("[GDD] Instance 'TCP' already initialized");
1137 return DRV_INITIALIZED;
1138 }
1139
1140 init_dio_driver_instance(gdd_dio_data, drv_init->max_devices);
1141
1142 return DRV_OK;
1143 } /* dio_init_tcp */
1144
1145
1146 /*
1147 +------------------------------------------------------------------------------
1148 | Function : dio_export_tcp
1149 +------------------------------------------------------------------------------
1150 | Description : The function returns, through dio_func, a list of functions
1151 | that are exported by the TCP driver. DIO_IL calls this
1152 | function after dio_init_bat call return DRV_OK.
1153 |
1154 | Parameters : dio_func - Return as a pointer to the list of functions
1155 | exported by the driver.
1156 |
1157 | Return : none
1158 |
1159 +------------------------------------------------------------------------------
1160 */
1161 void dio_export_tcp
1162 (
1163 T_DIO_FUNC ** dio_func
1164 )
1165 {
1166 TRACE_FUNCTION("[GDD] dio_export_tcp()");
1167
1168 *dio_func = (T_DIO_FUNC*) &dio_func_bat;
1169
1170 } /* dio_export_tcp */
1171
1172
1173 /*
1174 +------------------------------------------------------------------------------
1175 | Function : dio_init_sock
1176 +------------------------------------------------------------------------------
1177 | Description : The function initializes the SOCK driver. The
1178 | function returns DRV_INITIALIZED if the driver has already been
1179 | initialized and is ready to be used or is already in use. In
1180 | case of initialization failure (e.g. the configuration given
1181 | with drv_init can not be used) the function returns
1182 | DRV_INITFAILURE. In this case the driver can not be used.
1183 |
1184 | Parameters : none
1185 |
1186 | Return : DRV_OK - Initialization successful
1187 | DRV_INITIALIZED - Interface already initialized
1188 | DRV_INITFAILURE - Initialization failed
1189 |
1190 +------------------------------------------------------------------------------
1191 */
1192 U16 dio_init_sock
1193 (
1194 T_DIO_DRV * drv_init
1195 )
1196 {
1197 T_GDD_DIO_DATA * gdd_dio_data = &gdd_dio_data_base[GDD_INST_SOCK];
1198
1199 TRACE_FUNCTION("[GDD] dio_init_sock()");
1200
1201 if (gdd_dio_data->ker.state NEQ GDD_DIO_KER_DEAD)
1202 {
1203 TRACE_FUNCTION("[GDD] Instance 'SOCK' already initialized");
1204 return DRV_INITIALIZED;
1205 }
1206
1207 init_dio_driver_instance(gdd_dio_data, drv_init->max_devices);
1208
1209 return DRV_OK;
1210 } /* dio_init_sock */
1211
1212
1213 /*
1214 +------------------------------------------------------------------------------
1215 | Function : dio_export_sock
1216 +------------------------------------------------------------------------------
1217 | Description : The function returns, through dio_func, a list of functions
1218 | that are exported by the SOCK driver. DIO_IL calls this
1219 | function after dio_init_bat call return DRV_OK.
1220 |
1221 | Parameters : dio_func - Return as a pointer to the list of functions
1222 | exported by the driver.
1223 |
1224 | Return : none
1225 |
1226 +------------------------------------------------------------------------------
1227 */
1228 void dio_export_sock
1229 (
1230 T_DIO_FUNC ** dio_func
1231 )
1232 {
1233 TRACE_FUNCTION("[GDD] dio_export_sock()");
1234
1235 *dio_func = (T_DIO_FUNC*) &dio_func_bat;
1236
1237 } /* dio_export_sock */
1238
1239
1240 /*
1241 +------------------------------------------------------------------------------
1242 | Function : dio_init_sockcfg
1243 +------------------------------------------------------------------------------
1244 | Description : The function initializes the SOCKCFG driver. The
1245 | function returns DRV_INITIALIZED if the driver has already been
1246 | initialized and is ready to be used or is already in use. In
1247 | case of initialization failure (e.g. the configuration given
1248 | with drv_init can not be used) the function returns
1249 | DRV_INITFAILURE. In this case the driver can not be used.
1250 |
1251 | Parameters : none
1252 |
1253 | Return : DRV_OK - Initialization successful
1254 | DRV_INITIALIZED - Interface already initialized
1255 | DRV_INITFAILURE - Initialization failed
1256 |
1257 +------------------------------------------------------------------------------
1258 */
1259 U16 dio_init_sockcfg
1260 (
1261 T_DIO_DRV * drv_init
1262 )
1263 {
1264 T_GDD_DIO_DATA * gdd_dio_data = &gdd_dio_data_base[GDD_INST_SOCKCFG];
1265
1266 TRACE_FUNCTION("[GDD] dio_init_sockcfg()");
1267
1268 if (gdd_dio_data->ker.state NEQ GDD_DIO_KER_DEAD)
1269 {
1270 TRACE_FUNCTION("[GDD] Instance 'SOCKCFG' already initialized");
1271 return DRV_INITIALIZED;
1272 }
1273
1274 init_dio_driver_instance(gdd_dio_data, drv_init->max_devices);
1275
1276 return DRV_OK;
1277 } /* dio_init_sockcfg */
1278
1279
1280 /*
1281 +------------------------------------------------------------------------------
1282 | Function : dio_export_sockcfg
1283 +------------------------------------------------------------------------------
1284 | Description : The function returns, through dio_func, a list of functions
1285 | that are exported by the SOCKCFG driver. DIO_IL calls this
1286 | function after dio_init_bat call return DRV_OK.
1287 |
1288 | Parameters : dio_func - Return as a pointer to the list of functions
1289 | exported by the driver.
1290 |
1291 | Return : none
1292 |
1293 +------------------------------------------------------------------------------
1294 */
1295 void dio_export_sockcfg
1296 (
1297 T_DIO_FUNC ** dio_func
1298 )
1299 {
1300 TRACE_FUNCTION("[GDD] dio_export_sockcfg()");
1301
1302 *dio_func = (T_DIO_FUNC*) &dio_func_bat;
1303
1304 } /* dio_export_sockcfg */
1305
1306
1307
1308 #ifdef _SIMULATION_
1309
1310 /* Set the signal callback for all GDD drivers - for simulation only !!! */
1311 GLOBAL void set_bat_driver_callback_for_simulation(T_DRV_CB_FUNC signal_callback)
1312 {
1313 gdd_dio_data_base[GDD_INST_BAT].signal_callback = signal_callback;
1314 gdd_dio_data_base[GDD_INST_APP].signal_callback = signal_callback;
1315 gdd_dio_data_base[GDD_INST_TCP].signal_callback = signal_callback;
1316 gdd_dio_data_base[GDD_INST_SOCK].signal_callback = signal_callback;
1317 gdd_dio_data_base[GDD_INST_SOCKCFG].signal_callback = signal_callback;
1318 }
1319
1320 #endif /* _SIMULATION_ */