po_hi_driver_rtems_ne2000.c 2.11 KB
Newer Older
jhugues's avatar
jhugues committed
1
2
3
4
5
/*
 * 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.
 *
yoogx's avatar
yoogx committed
6
 * For more informations, please visit http://taste.tuxfamily.org/wiki
jhugues's avatar
jhugues committed
7
 *
yoogx's avatar
yoogx committed
8
 * Copyright (C) 2012-2014 ESA & ISAE.
jhugues's avatar
jhugues committed
9
10
 */

julien.delange's avatar
julien.delange committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <deployment.h>

#ifdef __PO_HI_NEED_DRIVER_RTEMS_NE2000_SOCKETS

#include <bsp.h>
#include <rtems/rtems_bsdnet.h>

#include <po_hi_transport.h>
#include <po_hi_debug.h>

#include <drivers/po_hi_driver_sockets.h>

extern __po_hi_device_id socket_device_id;

extern struct rtems_bsdnet_ifconfig netdriver_config;
26
char __po_hi_rtems_ethernet_address[6] = { 0x52, 0x54, 0x00, 0x12, 0x34, 0x57}; 
julien.delange's avatar
julien.delange committed
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

extern __po_hi_inetnode_t nodes[__PO_HI_NB_DEVICES];
extern __po_hi_inetnode_t rnodes[__PO_HI_NB_DEVICES];

void __po_hi_driver_rtems_ne2000_init (__po_hi_device_id id)
{
   char* dev_conf;
   char dev_addr[16];
   int  dev_port;
   int node;

   memset (dev_addr, '\0', 16);

   for (node = 0 ; node < __PO_HI_NB_DEVICES ; node++)
   {
      nodes[node].socket = -1;
   }


   dev_conf = __po_hi_get_device_naming (id);
   dev_port = 0;

   if (sscanf (dev_conf, "ip %s %d", dev_addr, &dev_port) == 0)
   {
      __DEBUGMSG ("[DRIVER SOCKETS] Unable to parse device configuration (id=%d)\n", id);
   }

   __DEBUGMSG ("My configuration, addr=%s, port=%d\n", dev_addr, dev_port);

   memset (netdriver_config.ip_address, '\0', 15);
   memcpy (netdriver_config.ip_address, dev_addr, strlen (dev_addr));
   memcpy (netdriver_config.ip_netmask, "255.255.255.0", 13);

   __DEBUGMSG ("Set configuration addr for RTEMS=%s\n", netdriver_config.ip_address);

   __po_hi_rtems_ethernet_address[5] = (dev_port + 23) % 254;

   netdriver_config.hardware_address = __po_hi_rtems_ethernet_address;

   __DEBUGMSG ("Init RTEMS\n");

   if (rtems_bsdnet_initialize_network () != RTEMS_SUCCESSFUL)
   {
      __DEBUGMSG ("Error when initializing RTEMS network\n");
      return;
   }
   __DEBUGMSG ("RTEMS network init done\n");

#ifdef __PO_HI_DEBUG
   rtems_bsdnet_show_if_stats ();
#endif

   __po_hi_driver_sockets_common_generic_init (id, __po_hi_sockets_poller);
}

#endif