Skip to content

Ethernet driver and LWIP wrapper fixes #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extras/net/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
* a lot of data that needs to be copied, this should be set high.
*/
#ifndef MEM_SIZE
#define MEM_SIZE (1522*4)
#define MEM_SIZE (15*1024)
#endif


Expand Down Expand Up @@ -596,7 +596,7 @@
* Define to 0 if your device is low on memory.
*/
#ifndef TCP_QUEUE_OOSEQ
#define TCP_QUEUE_OOSEQ (LWIP_TCP)
#define TCP_QUEUE_OOSEQ 0
#endif

/**
Expand Down
25 changes: 15 additions & 10 deletions libraries/Ethernet/src/EthernetDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class EthernetDriver {
#define ETHER_FRAME_TRANSFER_COMPLETED (1UL << 21)
#define ETHER_MAGIC_PACKET_DETECTED_MASK (1UL << 1)

static volatile bool frame_transmitted_flag = false;
static volatile bool frame_being_transmitted = false;
static EthernetDriver eth_driver;

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


frame_transmitted_flag = true;
frame_being_transmitted = false;
/* FRAME TRANSMISSION COMPLETED */
if(frame_transmitted != nullptr) {
frame_transmitted();
Expand Down Expand Up @@ -341,18 +341,23 @@ void eth_release_rx_buffer() {


bool eth_output(uint8_t *buf, uint16_t dim) {
frame_transmitted_flag = false;
fsp_err_t err = R_ETHER_Write ( eth_driver.get_ctrl(), buf, dim);
if(err == FSP_SUCCESS) {

while(!frame_transmitted_flag) {
bool retval = true;

}
return true;
fsp_err_t err = R_ETHER_Write(eth_driver.get_ctrl(), buf, dim);
if(err == FSP_SUCCESS) {
frame_being_transmitted = true;
retval = true;
}
else {
return false;
retval = false;
}

return retval;
}

// this function return true if the tx buffer is not being used for the transmission of another frame
bool eth_output_can_transimit() {
return !frame_being_transmitted;
}

uint8_t *eth_input(volatile uint32_t *dim) {
Expand Down
7 changes: 4 additions & 3 deletions libraries/Ethernet/src/EthernetDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include "r_ether_phy.h"
#include "r_ether_api.h"
#include "r_ether.h"
#include <functional>

using EtherCallback_f = void (*)(void);
using EtherCallback_f = std::function<void(void)>;

#define ETHERNET_IRQ_PRIORITY 10

Expand All @@ -23,6 +24,7 @@ bool eth_init();
void eth_execute_link_process();
uint8_t *eth_input(volatile uint32_t *dim);
bool eth_output(uint8_t *buf, uint16_t dim);
bool eth_output_can_transimit();
void eth_release_rx_buffer();
uint8_t *eth_get_tx_buffer(uint16_t *size);
void eth_set_rx_frame_cbk(EtherCallback_f fn);
Expand All @@ -33,5 +35,4 @@ void eth_set_lan_wake_up_cbk(EtherCallback_f fn);
void eth_set_magic_packet_cbk(EtherCallback_f fn);



#endif
#endif
Loading