22
22
23
23
#include "esp_log.h"
24
24
25
- #if ESP_UDP
25
+ #if ESP_UDP && LWIP_NETIF_TX_SINGLE_PBUF
26
26
27
27
#define UDP_SYNC_MAX MEMP_NUM_NETCONN
28
28
#define UDP_SYNC_RETRY_MAX CONFIG_ESP_UDP_SYNC_RETRY_MAX
40
40
typedef struct udp_sync {
41
41
struct api_msg * msg ;
42
42
43
- int ret ;
43
+ struct netif * netif ;
44
44
45
- int retry ;
45
+ int8_t ret ;
46
+
47
+ uint8_t retry ;
46
48
} udp_sync_t ;
47
49
48
50
static const char * TAG = "udp_sync" ;
49
51
static size_t s_udp_sync_num ;
50
52
static udp_sync_t s_udp_sync [UDP_SYNC_MAX ];
51
- static bool s_register_locked ;
52
53
static struct api_msg * s_cur_msg ;
53
54
54
55
/*
@@ -57,7 +58,6 @@ static struct api_msg *s_cur_msg;
57
58
void udp_sync_init (void )
58
59
{
59
60
memset (s_udp_sync , 0 , sizeof (s_udp_sync ));
60
- s_register_locked = false;
61
61
s_udp_sync_num = 0 ;
62
62
}
63
63
@@ -68,18 +68,13 @@ void udp_sync_regitser(void *in_msg)
68
68
{
69
69
s_cur_msg = in_msg ;
70
70
71
- if (s_register_locked == true)
72
- return ;
73
-
74
71
struct api_msg * msg = (struct api_msg * )in_msg ;
75
72
int s = msg -> conn -> socket ;
76
73
77
74
if (s < 0 || s >= UDP_SYNC_MAX ) {
78
75
ESP_LOGE (TAG , "UDP sync register error, socket is %d" , s );
79
- return ;
80
76
} else if (s_udp_sync [s ].msg ) {
81
77
ESP_LOGE (TAG , "UDP sync register error, msg is %p" , s_udp_sync [s ].msg );
82
- return ;
83
78
}
84
79
85
80
s_udp_sync_num ++ ;
@@ -88,6 +83,25 @@ void udp_sync_regitser(void *in_msg)
88
83
s_udp_sync [s ].msg = msg ;
89
84
}
90
85
86
+ static void _udp_sync_ack_ret (int s , struct api_msg * msg )
87
+ {
88
+ /* Only cache when low-level has no buffer to send packet */
89
+ if (s_udp_sync [s ].ret != ERR_MEM || s_udp_sync [s ].retry >= UDP_SYNC_RETRY_MAX ) {
90
+
91
+ ESP_LOGD (TAG , "UDP sync ret %d retry %d" , s_udp_sync [s ].ret , s_udp_sync [s ].retry );
92
+
93
+ s_udp_sync [s ].msg = NULL ;
94
+ s_udp_sync [s ].retry = 0 ;
95
+ s_udp_sync [s ].ret = ERR_OK ;
96
+ s_udp_sync_num -- ;
97
+
98
+ TCPIP_APIMSG_ACK (msg );
99
+ } else {
100
+ s_udp_sync [s ].retry ++ ;
101
+ ESP_LOGD (TAG , "UDP sync ack error, errno %d" , s_udp_sync [s ].ret );
102
+ }
103
+ }
104
+
91
105
/*
92
106
* @brief ack the message
93
107
*/
@@ -98,34 +112,19 @@ void udp_sync_ack(void *in_msg)
98
112
99
113
if (s < 0 || s >= UDP_SYNC_MAX ) {
100
114
ESP_LOGE (TAG , "UDP sync ack error, socket is %d" , s );
101
- return ;
102
115
} else if (!s_udp_sync [s ].msg ) {
103
116
ESP_LOGE (TAG , "UDP sync ack error, msg is NULL" );
104
- return ;
105
117
}
106
118
107
- /* Only cache when low-level has no buffer to send packet */
108
- if (s_udp_sync [s ].ret != ERR_MEM || s_udp_sync [s ].retry >= UDP_SYNC_RETRY_MAX ) {
109
- s_udp_sync [s ].msg = NULL ;
110
- s_udp_sync [s ].retry = 0 ;
111
- s_udp_sync [s ].ret = ERR_OK ;
112
- s_udp_sync_num -- ;
113
-
114
- ESP_LOGD (TAG , "UDP sync ret %d" , s_udp_sync [s ].ret );
115
-
116
- TCPIP_APIMSG_ACK (msg );
117
- } else {
118
- s_udp_sync [s ].retry ++ ;
119
- ESP_LOGD (TAG , "UDP sync ack error, errno %d" , s_udp_sync [s ].ret );
120
- }
119
+ _udp_sync_ack_ret (s , msg );
121
120
122
121
s_cur_msg = NULL ;
123
122
}
124
123
125
124
/*
126
125
* @brief set the current message send result
127
126
*/
128
- void udp_sync_set_ret (int ret )
127
+ void udp_sync_set_ret (void * netif , int ret )
129
128
{
130
129
/* Only poll and regitser can set current message */
131
130
if (!s_cur_msg ) {
@@ -139,15 +138,28 @@ void udp_sync_set_ret(int ret)
139
138
140
139
if (s < 0 || s >= UDP_SYNC_MAX ) {
141
140
ESP_LOGE (TAG , "UDP sync ack error, socket is %d" , s );
142
- return ;
143
141
} else if (!s_udp_sync [s ].msg ) {
144
142
ESP_LOGE (TAG , "UDP sync ack error, msg is NULL" );
145
- return ;
146
143
}
147
144
145
+ s_udp_sync [s ].netif = netif ;
148
146
s_udp_sync [s ].ret = ret ;
149
147
}
150
148
149
+ static void udp_sync_send (struct api_msg * msg )
150
+ {
151
+ struct pbuf * p = msg -> msg .b -> p ;
152
+ int s = msg -> conn -> socket ;
153
+ struct netif * netif = s_udp_sync [s ].netif ;
154
+
155
+ s_cur_msg = msg ;
156
+
157
+ netif -> linkoutput (netif , p );
158
+ _udp_sync_ack_ret (s , msg );
159
+
160
+ s_cur_msg = NULL ;
161
+ }
162
+
151
163
/*
152
164
* @brief process the sync
153
165
*/
@@ -156,19 +168,17 @@ void udp_sync_proc(void)
156
168
if (!s_udp_sync_num )
157
169
return ;
158
170
159
- s_register_locked = true;
160
171
for (int i = 0 ; i < UDP_SYNC_MAX ; i ++ ) {
161
172
if (!s_udp_sync [i ].msg )
162
173
continue ;
163
174
164
- lwip_netconn_do_send (s_udp_sync [i ].msg );
175
+ udp_sync_send (s_udp_sync [i ].msg );
165
176
#if 0
166
177
//Todo: Add this later
167
178
if (s_udp_sync [i ].ret != ERR_OK )
168
179
break ;
169
180
#endif
170
181
}
171
- s_register_locked = false;
172
182
}
173
183
174
184
#endif /* ESP_UDP */
0 commit comments