]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/rpp/eth.h
Temporary
[pes-rpp/rpp-lib.git] / rpp / include / rpp / eth.h
1 /**
2  * Ethernet Communication RPP API header file.
3  *
4  * @file eth.h
5  *
6  * @copyright Copyright (C) 2013 Czech Technical University in Prague
7  *
8  * @author Carlos Jenkins <carlos@jenkins.co.cr>
9  * @author Rostislav Lisový
10  * @author Jan Doležal <pm.jenik@gmail.com>
11  */
12
13 #ifndef __RPP_ETH_H
14 #define __RPP_ETH_H
15
16 #include "os/os.h"
17 #include "lwip/netif.h"
18
19 /* this MAC address is used when user doesn't put the address to postInit function */
20 #define RPP_MAC_ADDR {0x12,0x34,0x56,0x78,0x9a,0xbc}
21 #if STATIC_IP_ADDRESS
22 #define RPP_IP_ADDR        0xC0A8F701 /* 192.168.247.1   IP4_ADDR(rppip, 192,168,0,10);       */
23 #define RPP_NETMASK        0xFFFFFF00 /* 255.255.255.0   IP4_ADDR(rppnetmask, 255,255,255,0); */
24 #define RPP_GW             0xC0A8F7FE /* 192.168.247.254 IP4_ADDR(rppgw, 192,168,0,254);      */
25 #endif
26
27 #define NO_PHY_ALIVE       -1
28 #define DFLT_PHY_NOT_ALIVE -1
29 #define UNKN_DUPLEX_MODE   -2 /* this could mean that autonegotiation was not completed yet */
30 #define MACADDR_NOT_SET    -3
31 #define PHY_LINK_DOWN      -4
32
33 #define NETIF_ADD_ERR      -10 /* could be one of previous */
34 #define DHCP_MEM_ERR       -11
35 #define DHCP_BIND_TIMEOUT  -12
36
37 /**
38  * ETH module system startup initialization.
39  *
40  * Call this method before using this module.
41  * This method starts autonegotiation and doesn't check for end of autoneg.
42  * When eth module is about to be used, you have to run rpp_eth_init_postInit()
43  * first and you should check whether link is up.
44  *
45  * @return SUCCESS if initialization successful.\n
46  *         FAILURE if module already initialized.
47  */
48 int8_t rpp_eth_init();
49
50
51 /**
52  * ETH module application initialization.
53  *
54  * Call this method before using eth module.
55  * This method blocks on autonegotiation till it's complete and creates tasks
56  * for lwIP (including lwIP init) and for receiving. Sets IP address using
57  * predefined static IP or DHCP. Before calling this method you must call rpp_eth_init() first.
58  *
59  * @param instNum number of EMAC instance
60  * @param macArray address assigned to link layer - when NULL RPP_MAC_ADDR is used
61  * @param waitTicksForPHYAneg maximum amount of ticks it will wait for autonegotiation
62  *
63  * @return SUCCESS if init successful.
64  *         NETIF_ADD_ERR if lwip netif was not succesfully initialized or on low hw init error.
65  *         DHCP_MEM_ERR if DHCP unsuccesfull.
66  *         DHCP_BIND_TIMEOUT
67  */
68 int8_t rpp_eth_init_postInit(uint32_t instNum, uint8_t *macArray);
69
70 //Generic API
71
72 /**
73  * Handles too short packets, preserves the integrity of the transmission,
74  * calls rpp_et_send_raw()
75  *
76  * @param netif lwIP network interface describing struct
77  * @param p buffer for data to be sent
78  */
79 err_t rpp_eth_send(struct netif * netif, struct pbuf *p);
80
81 /**
82  * Handles transmission of data buffer p through EMAC to network.
83  *
84  * @param netif lwIP network interface describing struct
85  * @param p buffer for data to be sent
86  */
87 err_t rpp_eth_send_raw(struct netif *netif, struct pbuf *p);
88
89 /**
90  * Receives raw data and sends them upward to lwIP stack.
91  * Handles rx emac descriptors.
92  *
93  * @param arg netif
94  */
95 void rpp_eth_recv_raw(void *arg);
96
97 /**
98  * Handles receiving by running rpp_eth_recv_raw()
99  *
100  * @param instNum number of EMAC instance
101  */
102 void RxIntHandler(u32_t instNum);
103
104 /**
105  * Handles tx emac descriptors.
106  *
107  * @param instNum number of EMAC instance
108  */
109 void TxIntHandler(u32_t instNum);
110
111 #endif /* __RPP_ETH_H */