source: S-port/trunk/LWIP/App/lwip.c

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 5.9 KB
RevLine 
[1]1/**
2 ******************************************************************************
3 * File Name : LWIP.c
4 * Description : This file provides initialization code for LWIP
5 * middleWare.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
10 * All rights reserved.</center></h2>
11 *
12 * This software component is licensed by ST under Ultimate Liberty license
13 * SLA0044, the "License"; You may not use this file except in compliance with
14 * the License. You may obtain a copy of the License at:
15 * www.st.com/SLA0044
16 *
17 ******************************************************************************
18 */
19
20/* Includes ------------------------------------------------------------------*/
21#include "lwip.h"
22#include "lwip/init.h"
23#include "lwip/netif.h"
24#if defined ( __CC_ARM ) /* MDK ARM Compiler */
25#include "lwip/sio.h"
26#endif /* MDK ARM Compiler */
27
28/* USER CODE BEGIN 0 */
29
30/* USER CODE END 0 */
31/* Private function prototypes -----------------------------------------------*/
32/* ETH Variables initialization ----------------------------------------------*/
33void Error_Handler(void);
34
35#include "string.h"
36extern struct eth_addr MACAddr;
37ip_addr_t ip;
38ip_addr_t nm;
39ip_addr_t gw;
40
41void LWIP_SetIP(network_settings *net, char *NewIP)
42{
43 ip4addr_aton(NewIP, &ip);
44 netif_set_ipaddr(&net->netif, &ip);
45 memcpy(net->ipv4_addr, NewIP, strlen(NewIP));
46}
47
48void LWIP_SetNetMask(network_settings *net, char *NewNetMask)
49{
50 ip4addr_aton(NewNetMask, &nm);
51 netif_set_netmask(&net->netif, &nm);
52 memcpy(net->ipv4_nm, NewNetMask, strlen(NewNetMask));
53}
54
55void LWIP_Set_Gateway(network_settings *net, char *NewGateway)
56{
57 ip4addr_aton(NewGateway, &gw);
58 netif_set_gw(&net->netif, &gw);
59 memcpy(net->ipv4_gw, NewGateway, strlen(NewGateway));
60}
61
62void LWIP_NetApply(network_settings *net){
63 ip4addr_aton(net->ipv4_addr, &ip);
64 ip4addr_aton(net->ipv4_nm, &nm);
65 ip4addr_aton(net->ipv4_gw, &gw);
66
67 netif_set_addr(&net->netif, &ip, &nm, &gw);
68}
69
70void LWIP_SetNetSettings(network_settings *net, char *NewIP, char *NewNetMask, char *NewGateway)
71{
72 memset(net->ipv4_addr, 0x00, sizeof(net->ipv4_addr));
73 memcpy(net->ipv4_addr, NewIP, strlen(NewIP));
74 memset(net->ipv4_nm, 0x00, sizeof(net->ipv4_nm));
75 memcpy(net->ipv4_nm, NewNetMask, strlen(NewNetMask));
76 memset(net->ipv4_gw, 0x00, sizeof(net->ipv4_gw));
77 memcpy(net->ipv4_gw, NewGateway, strlen(NewGateway));
78
79 ip4addr_aton(net->ipv4_addr, &ip);
80 ip4addr_aton(net->ipv4_nm, &nm);
81 ip4addr_aton(net->ipv4_gw, &gw);
82
83 netif_set_addr(&net->netif, &ip, &nm, &gw);
84}
85
86void LWIP_resetIP(network_settings *net){
87 ip4addr_aton("192.168.0.254", &ip);
88 ip4addr_aton("255.255.255.0", &nm);
89 ip4addr_aton("192.168.0.1", &gw);
90
91 netif_set_addr(&net->netif, &ip, &nm, &gw);
92}
93
94/* USER CODE END 2 */
95
96/**
97 * LwIP initialization function
98 */
99void MX_LWIP_Init(network_settings *net)
100{
101
102 ip4addr_aton(net->ipv4_addr, &ip);
103 ip4addr_aton(net->ipv4_nm, &nm);
104 ip4addr_aton(net->ipv4_gw, &gw);
105
106 netif_add(&net->netif, &ip, &nm, &gw, NULL, &ethernetif_init, &tcpip_input);
107
108 net->netif.flags |= NETIF_FLAG_LINK_UP;
109
110 net->netif.hwaddr_len = ETH_HWADDR_LEN;
111
112 net->netif.hwaddr[0] = MACAddr.addr[0];
113 net->netif.hwaddr[1] = MACAddr.addr[1];
114 net->netif.hwaddr[2] = MACAddr.addr[2];
115 net->netif.hwaddr[3] = MACAddr.addr[3];
116 net->netif.hwaddr[4] = MACAddr.addr[4];
117 net->netif.hwaddr[5] = MACAddr.addr[5];
118
119 /* maximum transfer unit */
120 net->netif.mtu = 1500;
121 net->netif.flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;// | NETIF_FLAG_LINK_UP;
122
123// if (netif_is_link_up(&net->netif))netif_set_up(&net->netif);
124// else netif_set_down(&net->netif);
125}
126
127#ifdef USE_OBSOLETE_USER_CODE_SECTION_4
128/* Kept to help code migration. (See new 4_1, 4_2... sections) */
129/* Avoid to use this user section which will become obsolete. */
130/* USER CODE BEGIN 4 */
131/* USER CODE END 4 */
132#endif
133
134#if defined ( __CC_ARM ) /* MDK ARM Compiler */
135/**
136 * Opens a serial device for communication.
137 *
138 * @param devnum device number
139 * @return handle to serial device if successful, NULL otherwise
140 */
141sio_fd_t sio_open(u8_t devnum)
142{
143 sio_fd_t sd;
144
145/* USER CODE BEGIN 7 */
146 sd = 0; // dummy code
147/* USER CODE END 7 */
148
149 return sd;
150}
151
152/**
153 * Sends a single character to the serial device.
154 *
155 * @param c character to send
156 * @param fd serial device handle
157 *
158 * @note This function will block until the character can be sent.
159 */
160void sio_send(u8_t c, sio_fd_t fd)
161{
162/* USER CODE BEGIN 8 */
163/* USER CODE END 8 */
164}
165
166/**
167 * Reads from the serial device.
168 *
169 * @param fd serial device handle
170 * @param data pointer to data buffer for receiving
171 * @param len maximum length (in bytes) of data to receive
172 * @return number of bytes actually received - may be 0 if aborted by sio_read_abort
173 *
174 * @note This function will block until data can be received. The blocking
175 * can be cancelled by calling sio_read_abort().
176 */
177u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)
178{
179 u32_t recved_bytes;
180
181/* USER CODE BEGIN 9 */
182 recved_bytes = 0; // dummy code
183/* USER CODE END 9 */
184 return recved_bytes;
185}
186
187/**
188 * Tries to read from the serial device. Same as sio_read but returns
189 * immediately if no data is available and never blocks.
190 *
191 * @param fd serial device handle
192 * @param data pointer to data buffer for receiving
193 * @param len maximum length (in bytes) of data to receive
194 * @return number of bytes actually received
195 */
196u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)
197{
198 u32_t recved_bytes;
199
200/* USER CODE BEGIN 10 */
201 recved_bytes = 0; // dummy code
202/* USER CODE END 10 */
203 return recved_bytes;
204}
205#endif /* MDK ARM Compiler */
206
207/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.