36
36
******************************************************************************
37
37
*/
38
38
39
+ #include "Arduino.h"
39
40
#include "stm32_eth.h"
40
41
#include "lwip/init.h"
41
42
#include "lwip/netif.h"
46
47
#include "lwip/prot/dhcp.h"
47
48
#include "lwip/dns.h"
48
49
49
- //Keeps compatibilty with older version of the STM32 core
50
- #if __has_include ("core_callback.h" )
51
- #include "core_callback.h"
52
- #else
53
- void registerCoreCallback (void (* func )(void )) {
54
- UNUSED (func );
55
- }
56
- #endif
57
-
58
-
59
50
#ifdef __cplusplus
60
51
extern "C" {
61
52
#endif
@@ -69,6 +60,11 @@ void registerCoreCallback(void (*func)(void)) {
69
60
/* Maximum number of retries for DHCP request */
70
61
#define MAX_DHCP_TRIES 4
71
62
63
+ /* Timer used to call the scheduler */
64
+ #ifndef DEFAULT_ETHERNET_TIMER
65
+ #define DEFAULT_ETHERNET_TIMER TIM14
66
+ #endif
67
+
72
68
/* Ethernet configuration: user parameters */
73
69
struct stm32_eth_config {
74
70
ip_addr_t ipaddr ;
@@ -94,13 +90,16 @@ static uint8_t DHCP_Started_by_user = 0;
94
90
/* Ethernet link status periodic timer */
95
91
static uint32_t gEhtLinkTickStart = 0 ;
96
92
93
+ /* Handler for stimer */
94
+ static stimer_t TimHandle ;
95
+
97
96
/*************************** Function prototype *******************************/
98
97
static void Netif_Config (void );
99
- static void tcp_connection_close (struct tcp_pcb * tpcb , struct tcp_struct * tcp );
100
98
static err_t tcp_recv_callback (void * arg , struct tcp_pcb * tpcb , struct pbuf * p , err_t err );
101
99
static err_t tcp_sent_callback (void * arg , struct tcp_pcb * tpcb , u16_t len );
102
100
static void tcp_err_callback (void * arg , err_t err );
103
-
101
+ static void scheduler_callback (stimer_t * htim );
102
+ static void TIM_scheduler_Config (void );
104
103
105
104
/**
106
105
* @brief Configurates the network interface
@@ -132,6 +131,34 @@ static void Netif_Config(void)
132
131
#endif /* LWIP_NETIF_LINK_CALLBACK */
133
132
}
134
133
134
+ /**
135
+ * @brief Scheduler callback. Call by a timer interrupt.
136
+ * @param htim: pointer to stimer_t
137
+ * @retval None
138
+ */
139
+ static void scheduler_callback (stimer_t * htim )
140
+ {
141
+ UNUSED (htim );
142
+ stm32_eth_scheduler ();
143
+ }
144
+
145
+ /**
146
+ * @brief Enable the timer used to call ethernet scheduler function at regular
147
+ * interval.
148
+ * @param None
149
+ * @retval None
150
+ */
151
+ static void TIM_scheduler_Config (void )
152
+ {
153
+ /* Set TIMx instance. */
154
+ TimHandle .timer = DEFAULT_ETHERNET_TIMER ;
155
+
156
+ /* Timer set to 1ms */
157
+ TimerHandleInit (& TimHandle , (uint16_t )(1000 - 1 ), ((uint32_t )(getTimerClkFreq (DEFAULT_ETHERNET_TIMER ) / (1000000 )) - 1 ));
158
+
159
+ attachIntHandle (& TimHandle , scheduler_callback );
160
+ }
161
+
135
162
void stm32_eth_init (const uint8_t * mac , const uint8_t * ip , const uint8_t * gw , const uint8_t * netmask )
136
163
{
137
164
/* Initialize the LwIP stack */
@@ -178,8 +205,8 @@ void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, co
178
205
179
206
stm32_eth_scheduler ();
180
207
181
- // stm32_eth_scheduler() will be called directly inside the loop of the main() function .
182
- registerCoreCallback ( stm32_eth_scheduler );
208
+ // stm32_eth_scheduler() will be called every 1ms .
209
+ TIM_scheduler_Config ( );
183
210
}
184
211
185
212
/**
@@ -954,7 +981,7 @@ static void tcp_err_callback(void *arg, err_t err)
954
981
* @param es: pointer on echoclient structure
955
982
* @retval None
956
983
*/
957
- static void tcp_connection_close (struct tcp_pcb * tpcb , struct tcp_struct * tcp )
984
+ void tcp_connection_close (struct tcp_pcb * tpcb , struct tcp_struct * tcp )
958
985
{
959
986
/* remove callbacks */
960
987
tcp_recv (tpcb , NULL );
0 commit comments