po_hi_driver_leon_eth.c 3.35 KB
Newer Older
jdelange's avatar
jdelange committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * This is a part of PolyORB-HI-C distribution, a minimal
 * middleware written for generated code from AADL models.
 * You should use it with the Ocarina toolsuite.
 *
 * For more informations, please visit http://ocarina.enst.fr
 *
 * Copyright (C) 2011, European Space Agency (ESA).
 */

#include <deployment.h>

#if defined (__PO_HI_NEED_DRIVER_ETH_LEON) || \
    defined (__PO_HI_NEED_DRIVER_ETH_LEON_SENDER) || \
    defined (__PO_HI_NEED_DRIVER_ETH_LEON_RECEIVER)

#include <po_hi_debug.h>
#include <po_hi_utils.h>
#include <po_hi_messages.h>
#include <po_hi_transport.h>
#include <po_hi_gqueue.h>
#include <drivers/configuration/ip.h>
/* po-hi-c related files */

#include <activity.h>
#include <marshallers.h>
#include <deployment.h>
/* generated files */

#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int po_hi_c_driver_leon_eth_fd_read;
int po_hi_c_driver_leon_eth_fd_write;

#if defined (__PO_HI_NEED_DRIVER_ETH_LEON) || \
    defined (__PO_HI_NEED_DRIVER_ETH_LEON_RECEIVER)

void __po_hi_c_driver_eth_leon_poller (const __po_hi_device_id dev_id)
{
   int n;
   int ts;
   int tr;

   (void) dev_id;

   __po_hi_msg_t msg;
   __po_hi_request_t request;

   __PO_HI_DEBUG_DEBUG ("[LEON ETH] Hello, i'm the eth poller , must read %d bytes on %d !\n", __PO_HI_MESSAGES_MAX_SIZE, po_hi_c_driver_leon_eth_fd_read);

   __po_hi_msg_reallocate (&msg);

   tr = 0;
   while (tr < __PO_HI_MESSAGES_MAX_SIZE)
   {
      if (read (po_hi_c_driver_leon_eth_fd_read, &(msg.content[tr]), 1) == 1)
      {
         tr++;
      }
   }

   msg.length = __PO_HI_MESSAGES_MAX_SIZE;
  __PO_HI_DEBUG_DEBUG ("[LEON ETH] read() syscall returns in total %d, received: ", tr);
#ifdef __PO_HI_DEBUG_DEBUG
   __PO_HI_DEBUG_DEBUG("[LEON ETH] Message received: 0x");
   for (ts = 0 ; ts < msg.length ; ts++)
   {
        __PO_HI_DEBUG_DEBUG ("%x", msg.content[ts]);
   }
   __PO_HI_DEBUG_DEBUG ("\n");
#endif

   __po_hi_unmarshall_request (&request, &msg);

   if (request.port > __PO_HI_NB_PORTS)
   {
      __PO_HI_DEBUG_WARNING ("[LEON ETH] Invalid port number !\n");
      return;
   }

   __PO_HI_DEBUG_INFO ("[LEON ETH] Destination port: %d\n", request.port);
   __po_hi_main_deliver (&request);
}
#endif

#if (defined (__PO_HI_NEED_DRIVER_ETH_LEON) || \
     defined (__PO_HI_NEED_DRIVER_ETH_LEON_SENDER))

void __po_hi_c_driver_eth_leon_init (__po_hi_device_id id)
{
}
#endif


#if defined (__PO_HI_NEED_DRIVER_ETH_LEON) 

int  __po_hi_c_driver_eth_leon_sender (__po_hi_task_id task, __po_hi_port_t port)
{
   int n;
   int ts;
   __po_hi_local_port_t local_port;
   __po_hi_request_t* request;
   __po_hi_msg_t msg;
   __po_hi_port_t destination_port;

   local_port = __po_hi_get_local_port_from_global_port (port);

   request = __po_hi_gqueue_get_most_recent_value (task, local_port);

   destination_port     = __po_hi_gqueue_get_destination (task, local_port, 0);

   __po_hi_msg_reallocate (&msg);

   request->port = destination_port;

   __po_hi_marshall_request (request, &msg);

   n = write (po_hi_c_driver_leon_eth_fd_write, &(msg.content[0]), __PO_HI_MESSAGES_MAX_SIZE);

#ifdef __PO_HI_DEBUG_INFO
   __PO_HI_DEBUG_INFO  ("[LEON ETH] Message sent: 0x");

   for (ts = 0 ; ts < __PO_HI_MESSAGES_MAX_SIZE ; ts++)
   {
      __PO_HI_DEBUG_INFO ("%x", msg.content[ts]);
   }
   __PO_HI_DEBUG_INFO ("\n");
#endif

   return 1;
}
#endif

#endif