Skip to content

Commit 4034e09

Browse files
authored
Merge pull request #151 from andreagilardoni/ethernet-fixes
[WIRE-98] Ethernet driver and LWIP wrapper fixes
2 parents 0be64ae + 23eccce commit 4034e09

File tree

6 files changed

+165
-156
lines changed

6 files changed

+165
-156
lines changed

extras/net/lwipopts.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
* a lot of data that needs to be copied, this should be set high.
138138
*/
139139
#ifndef MEM_SIZE
140-
#define MEM_SIZE (1522*4)
140+
#define MEM_SIZE (15*1024)
141141
#endif
142142

143143

@@ -596,7 +596,7 @@
596596
* Define to 0 if your device is low on memory.
597597
*/
598598
#ifndef TCP_QUEUE_OOSEQ
599-
#define TCP_QUEUE_OOSEQ (LWIP_TCP)
599+
#define TCP_QUEUE_OOSEQ 0
600600
#endif
601601

602602
/**

libraries/Ethernet/src/EthernetDriver.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class EthernetDriver {
6464
#define ETHER_FRAME_TRANSFER_COMPLETED (1UL << 21)
6565
#define ETHER_MAGIC_PACKET_DETECTED_MASK (1UL << 1)
6666

67-
static volatile bool frame_transmitted_flag = false;
67+
static volatile bool frame_being_transmitted = false;
6868
static EthernetDriver eth_driver;
6969

7070
static uint8_t eth_tx_buffer[ETH_BUFF_DIM];
@@ -230,7 +230,7 @@ void EthernetDriver::irq_callback(ether_callback_args_t * p_args) {
230230
if (ETHER_FRAME_TRANSFER_COMPLETED == (reg_eesr & ETHER_FRAME_TRANSFER_COMPLETED)) {
231231

232232

233-
frame_transmitted_flag = true;
233+
frame_being_transmitted = false;
234234
/* FRAME TRANSMISSION COMPLETED */
235235
if(frame_transmitted != nullptr) {
236236
frame_transmitted();
@@ -341,18 +341,23 @@ void eth_release_rx_buffer() {
341341

342342

343343
bool eth_output(uint8_t *buf, uint16_t dim) {
344-
frame_transmitted_flag = false;
345-
fsp_err_t err = R_ETHER_Write ( eth_driver.get_ctrl(), buf, dim);
346-
if(err == FSP_SUCCESS) {
347-
348-
while(!frame_transmitted_flag) {
344+
bool retval = true;
349345

350-
}
351-
return true;
346+
fsp_err_t err = R_ETHER_Write(eth_driver.get_ctrl(), buf, dim);
347+
if(err == FSP_SUCCESS) {
348+
frame_being_transmitted = true;
349+
retval = true;
352350
}
353351
else {
354-
return false;
352+
retval = false;
355353
}
354+
355+
return retval;
356+
}
357+
358+
// this function return true if the tx buffer is not being used for the transmission of another frame
359+
bool eth_output_can_transimit() {
360+
return !frame_being_transmitted;
356361
}
357362

358363
uint8_t *eth_input(volatile uint32_t *dim) {

libraries/Ethernet/src/EthernetDriver.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#include "r_ether_phy.h"
66
#include "r_ether_api.h"
77
#include "r_ether.h"
8+
#include <functional>
89

9-
using EtherCallback_f = void (*)(void);
10+
using EtherCallback_f = std::function<void(void)>;
1011

1112
#define ETHERNET_IRQ_PRIORITY 10
1213

@@ -23,6 +24,7 @@ bool eth_init();
2324
void eth_execute_link_process();
2425
uint8_t *eth_input(volatile uint32_t *dim);
2526
bool eth_output(uint8_t *buf, uint16_t dim);
27+
bool eth_output_can_transimit();
2628
void eth_release_rx_buffer();
2729
uint8_t *eth_get_tx_buffer(uint16_t *size);
2830
void eth_set_rx_frame_cbk(EtherCallback_f fn);
@@ -33,5 +35,4 @@ void eth_set_lan_wake_up_cbk(EtherCallback_f fn);
3335
void eth_set_magic_packet_cbk(EtherCallback_f fn);
3436

3537

36-
37-
#endif
38+
#endif

0 commit comments

Comments
 (0)