2 * Ethernet Communication RPP API header file.
6 * @copyright Copyright (C) 2013 Czech Technical University in Prague
8 * @author Carlos Jenkins <carlos@jenkins.co.cr>
9 * @author Rostislav Lisový
10 * @author Jan Doležal <pm.jenik@gmail.com>
19 #include "lwip/netif.h"
21 /* this MAC address is used when user put NULL on the right place when calling postInit function */
23 * Default MAC address for interface.
25 #define RPP_MAC_ADDR { 0x12 /* Unicast, Locally administered */, 0x34, 0x56, 0x78, 0x9A, 0xBC }
28 * When static IP is configured in lwipopts.h, this IP address is used for interface.
29 * Static IP address is working only at Ciirc. Also mask and GW havo to be changet to work in different network.
31 #define RPP_IP_ADDR 0x0A235F19 /* 10.35.95.25 IP4_ADDR(rppip, 10,35,95,25); */
33 * When static IP is configured in lwipopts.h, this NETMASK address is used for interface.
35 #define RPP_NETMASK 0xFFFFFF00 /* 255.255.255.0 IP4_ADDR(rppnetmask, 255,255,255,0); */
37 * When static IP is configured in lwipopts.h, this Gateway address is used for interface.
39 #define RPP_GW 0x0A235F01 /* 10.35.95.1 IP4_ADDR(rppgw, 10,35,95,1); */
43 * While scanning phy addresses no alive phy was found.
44 * Return value of rpp_eth_hw_init() function.
46 #define NO_PHY_ALIVE -1
48 * Scanning default phy address, it was found it's not alive.
49 * Return value of rpp_eth_hw_init() function.
51 #define DFLT_PHY_NOT_ALIVE -1
53 * When setting autonegotiation parameters to EMAC module, there was found impossible mode (usually on timeout of autonegotiation).
54 * Return value of rpp_eth_hw_init_postInit() function.
56 #define UNKN_DUPLEX_MODE -2 /* this could mean that autonegotiation was not completed yet */
59 * Return value of rpp_eth_init_postInit() function.
61 #define PHY_LINK_DOWN -3
64 * LwIP netif couldn't be added, it is likely that there was an error during initialization of the hardware.
66 #define NETIF_ADD_ERR -10 /* could be one of previous, except PHY_LINK_DOWN - currently */
68 * Memory requirements couldn't be satisfied.
70 #define DHCP_MEM_ERR -11
73 * Configure which function will be used for debugging prints
76 #define rpp_debug_printf rpp_sci_printf
78 #define rpp_debug_printf(...)
82 * configures whether rpp_eth_get_macAddrStr() creates string with big or small latin letters
84 #define MAC_BIG_LETTERS 1
87 * This function allows application to check whether eth was already initialized
88 * (it's post OS starup part)
90 * @return TRUE if initialized
91 * FALSE if not initialized
93 boolean_t isPostInitialized();
96 * ETH module system startup initialization.
98 * Call this method before using this module.
99 * This method starts autonegotiation and doesn't check for end of autoneg.
100 * When eth module is about to be used, you have to run rpp_eth_init_postInit()
101 * first and you should check whether link is up.
103 * @return SUCCESS if initialization successful.\n
104 * FAILURE if module already initialized.
106 int8_t rpp_eth_init();
109 * ETH module application initialization.
111 * Call this method before using eth module.
112 * This method waits for a while on autonegotiation till it's complete, if not completed
113 * in predefined time it continues with creating tasks for lwIP (including lwIP init),
114 * for receiving and for handling transmission buffer descriptors. Sets IP address using
115 * predefined static IP or DHCP. Before calling this method you must call rpp_eth_init() first.
117 * @param instNum number of EMAC instance
118 * @param macArray address assigned to link layer - when NULL RPP_MAC_ADDR is used
120 * @return SUCCESS if init successful.
121 * FAILURE if module was already initialized
122 * NETIF_ADD_ERR if lwip netif was not succesfully initialized or on low hw init error.
123 * DHCP_MEM_ERR if DHCP unsuccesfull.
125 int8_t rpp_eth_init_postInit(uint32_t instNum, uint8_t *macArray);
127 // Helper routines/functions for command processor and other applications
130 * Uses MDIO module to read link status of PHY attached to instNum network interface
132 * @param instNum Number of network interface
134 * @return TRUE if link is UP
135 * FALSE if link is DOWN
137 uint32_t rpp_eth_phylinkstat(uint32_t instNum);
140 * Fills macStr field with MAC address of given network interface instance as 'string'
142 * @note 18 bytes will be filled {2 chars per 6 mac bytes + 5 semicolons + 1 null termination}
144 * @param instNum Number of network interface
145 * @param *macStr field where null terminated string will be inserted
147 void rpp_eth_get_macAddrStr(uint32_t instNum, uint8_t *macStr);
150 * Fills ipStr field with IP address in ip_addr_t as 'string';
151 * prepares an IP address to ipStr in form of null terminated string;
152 * each byte of ip is converted to one of 4 field in IPv4 IP address format 0xAABBCCDD -> "aaa.bbb.ccc.ddd"
154 * @note up to 16 bytes will be filled {1-3 * 4 IP fields + 3 dots + 1 null termination}
157 * @param ip ip address to be converted
158 * @param ipStr pointer to string where ip will be filled as text
160 inline void rpp_eth_getIPDecimalStr(ip_addr_t ip, uint8_t *ipStr)
162 snprintf((char *)ipStr, 16, "%d.%d.%d.%d",(ip.addr >> 24),((ip.addr >> 16) & 0xff),((ip.addr >> 8) & 0xff),(ip.addr & 0xff));
166 * Fills ip.addr with converted ipstr. Checks for correct format of IP string
167 * x.x.x.x where x = [0..9]. When FAILURE is returned struct ip was not modified.
169 * @param ip struct to be filled
170 * @param ipstr string to be converted
172 * @return SUCCESS when succesfully converted
173 * FAILURE when wrong format of IP string
175 err_t rpp_eth_stringToIP(ip_addr_t *ip, uint8_t *ipstr);
178 * Converts given null terminated string containing number to number in
181 * @param string to be converted
183 * port number otherwise
185 uint16_t rpp_eth_portStrToInt(uint8_t *string);
188 * Returns struct describing network interface
190 * @param instNum instance number of network interface
192 * @return pointer to struct netif
194 struct netif *rpp_eth_get_netif(uint32_t instNum);
197 * Adjusts packet (pbuf) length and send it within critical section
198 * using rpp_eth_send_raw()
200 * @param netif lwIP network interface describing struct
201 * @param p buffer for data to be sent
203 err_t rpp_eth_send(struct netif *netif, struct pbuf *p);
206 * Handles transmission of data buffer p through EMAC to network.
208 * @param netif lwIP network interface describing struct
209 * @param p buffer for data to be sent
211 static err_t rpp_eth_send_raw(struct netif *netif, struct pbuf *p);
214 * Receives raw data and sends them upward to lwIP stack.
215 * Handles rx emac descriptors.
217 * @note when using OS tasks (!NO_SYS) this function is used as
218 * task, otherwise (NO_SYS) this is called from RX ISR.
222 void rpp_eth_recv_raw_thr(void *arg);
224 void rpp_eth_send_raw_thr(void *arg);
227 * Handles freeing of buffer descriptors and other structures in memory
228 * after transmission of bd was completed.
232 void rpp_eth_send_bd_handler(void *arg);
235 * Handles receiving by running rpp_eth_recv_raw_thr()
237 * @param instNum number of EMAC instance
239 void RxIntHandler(u32_t instNum);
242 * Handles tx emac descriptors.
244 * @param instNum number of EMAC instance
246 void TxIntHandler(u32_t instNum);
248 #endif /* __RPP_ETH_H */