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 1 commit
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
Next Next commit
Changing the logic of ethernet driver to avoid busy waiting
  • Loading branch information
andreagilardoni committed Oct 6, 2023
commit 57d878a6c35443e84e2b7ccbc69ef4e0d2968090
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
4 changes: 2 additions & 2 deletions libraries/Ethernet/src/EthernetDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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 +34,4 @@ void eth_set_lan_wake_up_cbk(EtherCallback_f fn);
void eth_set_magic_packet_cbk(EtherCallback_f fn);



#endif
#endif