32 #define TM_ETHERNET_H 110
188 #include "stm32f4xx.h"
189 #include "stm32f4xx_rcc.h"
190 #include "stm32f4xx_gpio.h"
192 #include "attributes.h"
193 #include "tm_stm32f4_delay.h"
194 #include "tm_stm32f4_gpio.h"
197 #include "stm32f4x7_eth.h"
198 #include "stm32f4x7_eth_bsp.h"
200 #include "tcp_echoclient.h"
201 #include "lwip/ip_addr.h"
202 #include "lwip/dns.h"
203 #include "lwip/tcp.h"
220 #define ETHERNET_PHY 0
226 #ifndef LINK_TIMER_INTERVAL
227 #define LINK_TIMER_INTERVAL 1000
233 #ifndef ETHERNET_SERVER_PORT
234 #define ETHERNET_SERVER_PORT 80
248 #define MAC_ADDR0 0x06
249 #define MAC_ADDR1 0x05
250 #define MAC_ADDR2 0x04
251 #define MAC_ADDR3 0x03
252 #define MAC_ADDR4 0x02
253 #define MAC_ADDR5 0x01
275 #ifndef NETMASK_ADDR0
276 #define NETMASK_ADDR0 255
277 #define NETMASK_ADDR1 255
278 #define NETMASK_ADDR2 255
279 #define NETMASK_ADDR3 0
296 #ifndef ETHERNET_HOSTNAME_DHCP
297 #define ETHERNET_HOSTNAME_DHCP "TM-ETH-Device"
301 #if !defined(ETHERNET_MII_MODE) && !defined(ETHERNET_RMII_MODE)
302 #define ETHERNET_RMII_MODE
313 #ifndef ETHERNET_MAX_HEADER_SIZE
314 #define ETHERNET_MAX_HEADER_SIZE 1024
321 #ifndef ETHERNET_MAX_CONNECTION_NAME
322 #define ETHERNET_MAX_CONNECTION_NAME 100
328 #ifndef ETHERNET_MAX_OPEN_FILES
329 #define ETHERNET_MAX_OPEN_FILES 10
335 #ifndef ETHERNET_SSI_MAX_TAG_LEN
336 #define ETHERNET_SSI_MAX_TAG_LEN 32
343 #ifndef ETHERNET_SSI_MAX_TAG_INSERT_LEN
344 #define ETHERNET_SSI_MAX_TAG_INSERT_LEN 512
375 uint32_t ClientSuccessfullConnections, ClientConnections;
376 uint64_t Client_TX_Bytes, Client_RX_Bytes;
377 uint32_t Server_Connections;
378 uint64_t Server_TX_Bytes, Server_RX_Bytes;
379 uint8_t server_active;
380 uint16_t server_port;
383 uint8_t timeout_detected;
392 CLIENT_NOT_CONNECTED = 0,
540 #define TM_ETHERNET_IsIPStatic() (TM_ETHERNET.staticip)
549 #define TM_ETHERNET_Is100M() (TM_ETHERNET.speed_100m)
558 #define TM_ETHERNET_IsFullDuplex() (TM_ETHERNET.full_duplex)
565 #define TM_ETHERNET_GetLocalIP(x) (((x) >= 0 && (x) < 4) ? TM_ETHERNET.ip_addr[(x)] : 0)
572 #define TM_ETHERNET_GetMACAddr(x) (((x) >= 0 && (x) < 6) ? TM_ETHERNET.mac_addr[(x)] : 0)
579 #define TM_ETHERNET_GetGateway(x) (((x) >= 0 && (x) < 4) ? TM_ETHERNET.gateway[(x)] : 0)
586 #define TM_ETHERNET_GetNetmask(x) (((x) >= 0 && (x) < 4) ? TM_ETHERNET.netmask[(x)] : 0)
596 #define TM_ETHERNET_SetTimeoutDetected() (TM_ETHERNET.timeout_detected = 1)
632 #define TM_ETHERNETSERVER_Enabled() (TM_ETHERNET.server_active)
639 #define TM_ETHERNETSERVER_GetPortNumber() (TM_ETHERNET.server_port)
646 #define TM_ETHERNETSERVER_GetTXBytes() (TM_ETHERNET.Server_TX_Bytes)
653 #define TM_ETHERNETSERVER_GetRXBytes() (TM_ETHERNET.Server_RX_Bytes)
660 #define TM_ETHERNETSERVER_GetConnectionsCount() (TM_ETHERNET.Server_Connections)
724 #define TM_ETHERNETCLIENT_GetTXBytes() (TM_ETHERNET.Client_TX_Bytes)
731 #define TM_ETHERNETCLIENT_GetRXBytes() (TM_ETHERNET.Client_RX_Bytes)
738 #define TM_ETHERNETCLIENT_GetConnectionsCount() (TM_ETHERNET.ClientConnections)
745 #define TM_ETHERNETCLIENT_GetSuccessfullConnectionsCount() (TM_ETHERNET.ClientSuccessfullConnections)
1139 void TM_ETHERNET_INT_CustomOptions(uint32_t PHYAddress);
1140 void TM_ETHERNET_INT_SetIPAddress(uint8_t ip_addr1, uint8_t ip_addr2, uint8_t ip_addr3, uint8_t ip_addr4, uint8_t dhcp);
1141 void TM_ETHERNET_INT_LinkIsDownCallback(
void);
1142 void TM_ETHERNET_INT_LinkIsUpCallback(
void);
TM_ETHERNET_Result_t TM_ETHERNETDNS_GetHostByName(char *host_name)
Definition: tm_stm32f4_ethernet.h:444
int content_len
Definition: tm_stm32f4_ethernet.h:435
char * response_uri
Definition: tm_stm32f4_ethernet.h:436
Definition: tm_stm32f4_ethernet.h:446
void TM_ETHERNETDNS_ErrorCallback(char *host_name)
DNS error callback.
const char * http_request
Definition: tm_stm32f4_ethernet.h:433
Client structure, passed as first parameter in all client based callback functions.
Definition: tm_stm32f4_ethernet.h:405
void TM_ETHERNET_LinkIsDownCallback(void)
Link is down callback.
const char * TM_ETHERNET_SSI_t
User friendly typedef for SSI tags.
Definition: tm_stm32f4_ethernet.h:455
POST request structure.
Definition: tm_stm32f4_ethernet.h:430
uint16_t http_request_len
Definition: tm_stm32f4_ethernet.h:434
TM_ETHERNET_Result_t TM_ETHERNETSERVER_Disable(void)
Disables and stops LwIP stack from server functionality.
client_states state
Definition: tm_stm32f4_ethernet.h:421
struct pbuf * p_tx
Definition: tm_stm32f4_ethernet.h:422
TM_ETHERNET_Result_t
Result enumeration used in ethernet library.
Definition: tm_stm32f4_ethernet.h:443
uint16_t response_uri_len
Definition: tm_stm32f4_ethernet.h:437
int TM_ETHERNETSERVER_OpenFileCallback(struct fs_file *file, const char *name)
Open file callback.
void TM_ETHERNET_DHCPStartCallback(void)
DHCP started callback.
struct tcp_pcb * pcb
Definition: tm_stm32f4_ethernet.h:420
void * connection
Definition: tm_stm32f4_ethernet.h:431
uint8_t TM_ETHERNETSERVER_PostRequestBeginCallback(TM_ETHERNETPOST_t *params)
Post request begin callback.
void TM_ETHERNETCLIENT_ConnectionClosedCallback(TM_TCPCLIENT_t *connection, uint8_t success)
Client Connection closed callback.
TM_ETHERNET_Result_t TM_ETHERNETSERVER_SetSSITags(TM_ETHERNET_SSI_t *tags, uint16_t number_of_tags)
Set SSI tags, which will be used in your HTML files for displaying variables on website.
TM_ETHERNET_Result_t TM_ETHERNET_Init(uint8_t *mac_addr, uint8_t *ip_addr, uint8_t *gateway, uint8_t *netmask)
Initializes ethernet device and prepare device to work.
void TM_ETHERNETCLIENT_ConnectedCallback(TM_TCPCLIENT_t *connection)
Connected callback.
uint8_t TM_ETHERNETSERVER_ClientConnectedCallback(struct tcp_pcb *pcb)
Client connected callback Called when new client is connected to server.
TM_ETHERNET_Result_t TM_ETHERNET_TimeUpdate(uint16_t millis)
This function should be called in specific time period for LwIP stack using interrupts.
uint8_t active
Definition: tm_stm32f4_ethernet.h:407
void * user_parameters
Definition: tm_stm32f4_ethernet.h:416
void TM_ETHERNETSERVER_ClientDisconnectedCallback(void)
Client disconnected from server.
uint16_t TM_ETHERNETSERVER_SSICallback(int iIndex, char *pcInsert, int iInsertLen)
SSI callback for ethernet server.
uint8_t headers_done
Definition: tm_stm32f4_ethernet.h:410
uint8_t * active_connections_count
Definition: tm_stm32f4_ethernet.h:415
#define ETHERNET_MAX_CONNECTION_NAME
Max connection string name when connection as client.
Definition: tm_stm32f4_ethernet.h:322
void TM_ETHERNETCLIENT_ReceiveDataCallback(TM_TCPCLIENT_t *connection, uint8_t *buffer, uint16_t buffer_length, uint16_t total_length)
Receive data callback.
void TM_ETHERNET_LinkIsUpCallback(void)
Link is up callback.
TM_ETHERNET_Result_t TM_ETHERNETCLIENT_Connect(char *conn_name, uint8_t ip1, uint8_t ip2, uint8_t ip3, uint8_t ip4, uint16_t port, void *user_parameters)
Makes TCP CLIENT Connection to external server.
void TM_ETHERNETSERVER_CloseFileCallback(struct fs_file *file)
Close file callback.
void TM_ETHERNETSERVER_PostRequestEndCallback(void *connection, char *response_uri, u16_t response_uri_len)
Post request end callback.
void TM_ETHERNET_SystemResetCallback(void)
System reset callback.
Definition: tm_stm32f4_ethernet.h:448
uint8_t TM_ETHERNETSERVER_PostRequestReceiveDataCallback(TM_ETHERNETPOST_t *params, struct pbuf *p)
Post request receive data available callback.
void TM_ETHERNETCLIENT_ErrorCallback(TM_TCPCLIENT_t *connection)
Client Error callback.
const char * uri
Definition: tm_stm32f4_ethernet.h:432
void TM_ETHERNET_IPIsSetCallback(uint8_t ip_addr1, uint8_t ip_addr2, uint8_t ip_addr3, uint8_t ip_addr4, uint8_t dhcp)
IP is set callback. This function is called when IP is assigned to device.
client_states
Client protocol states.
Definition: tm_stm32f4_ethernet.h:391
Definition: tm_stm32f4_ethernet.h:445
void TM_ETHERNETCLIENT_ConnectionStartedCallback(TM_TCPCLIENT_t *connection)
Connection started callback.
int TM_ETHERNETSERVER_ReadFileCallback(struct fs_file *file, char *buffer, int count)
Read file callback.
TM_ETHERNET_Result_t TM_ETHERNET_TestReady(void)
Tests if ethernet library is prepared to work as client or server.
TM_ETHERNET_Result_t TM_ETHERNETSERVER_SetCGIHandlers(const TM_ETHERNET_CGI_t *cgis, uint16_t number_of_handlers)
Set GCI handlers which will be used when you want to control something over ethernet configured as se...
tCGI TM_ETHERNET_CGI_t
Structure for CGI tags.
Definition: tm_stm32f4_ethernet.h:466
TM_ETHERNET_Result_t TM_ETHERNETSERVER_Enable(uint16_t server_port)
Enables and prepares LwIP stack for server functionality.
Definition: tm_stm32f4_ethernet.h:367
void TM_ETHERNETDNS_FoundCallback(char *host_name, uint8_t ip_addr1, uint8_t ip_addr2, uint8_t ip_addr3, uint8_t ip_addr4)
DNS Found callback.
TM_ETHERNET_Result_t TM_ETHERNET_Update(void)
Updates ethernet LwIP stack.
Definition: tm_stm32f4_ethernet.h:447
uint8_t TM_ETHERNET_InitPinsCallback(void)
Called on ethernet GPIO initialization In this function, user can initialize custom pins...
uint16_t TM_ETHERNETCLIENT_CreateHeadersCallback(TM_TCPCLIENT_t *connection, char *buffer, uint16_t buffer_length)
Create headers callback.
uint16_t port
Definition: tm_stm32f4_ethernet.h:409
void TM_ETHERNETPHY_CustomOptions(uint32_t PHYAddress)
PHY low layer custom options callback.
Definition: tm_stm32f4_ethernet.h:449