Skip to content

Commit 1499d3a

Browse files
committed
added get_target_default_instance and lock
1 parent 534aa21 commit 1499d3a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/W5500EMAC.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
12
#include "W5500EMAC.h"
23
#include <Arduino.h>
34
#include <SPI.h>
45

6+
#include <EthernetInterface.h>
7+
#include <mbed_events.h>
8+
59
#ifndef W5500_CS
610
#ifdef ARDUINO_ARCH_MBED_PORTENTA
711
#define W5500_CS D5 // MKR ETH shield CS
@@ -162,33 +166,39 @@ bool W5500EMAC::link_out(emac_mem_buf_t *buf) {
162166

163167
uint16_t len = memoryManager->get_len(buf);
164168
uint8_t *data = (uint8_t*) (memoryManager->get_ptr(buf));
169+
ethLockMutex.lock();
165170
spi.beginTransaction(SPI_ETHERNET_SETTINGS);
166171
bool ret = driver.sendFrame(data, len) == len;
167172
spi.endTransaction();
168173
memoryManager->free(buf);
174+
ethLockMutex.unlock();
169175

170176
return ret;
171177
}
172178

173179
void W5500EMAC::linkStatusTask() {
180+
ethLockMutex.lock();
174181
spi.beginTransaction(SPI_ETHERNET_SETTINGS);
175-
static bool linked = false;
182+
static bool linked = !driver.isLinked();
176183
if (linked != driver.isLinked()) {
177184
linked = driver.isLinked();
178185
emac_link_state_cb(linked);
179186
}
180187
spi.endTransaction();
188+
ethLockMutex.unlock();
181189
}
182190

183191
void W5500EMAC::receiveTask() {
184192
if (!emac_link_input_cb)
185193
return;
194+
ethLockMutex.lock();
186195
spi.beginTransaction(SPI_ETHERNET_SETTINGS);
187196
emac_mem_buf_t *buf = driver.readFrame(memoryManager);
188197
spi.endTransaction();
189198
if (buf != NULL) {
190199
emac_link_input_cb(buf);
191200
}
201+
ethLockMutex.unlock();
192202
}
193203

194204
/**
@@ -247,3 +257,9 @@ void W5500EMAC::set_memory_manager(EMACMemoryManager &mem_mngr) {
247257
EMAC& EMAC::get_default_instance() {
248258
return W5500EMAC::get_instance();
249259
}
260+
261+
EthInterface *EthInterface::get_target_default_instance()
262+
{
263+
static EthernetInterface ethernet;
264+
return &ethernet;
265+
}

src/W5500EMAC.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class W5500EMAC : public EMAC {
156156
int linkStatusTaskHandle = 0;
157157

158158
EMACMemoryManager* memoryManager = nullptr;
159-
rtos::Mutex wifiLockMutex;
159+
rtos::Mutex ethLockMutex;
160160

161161
emac_link_input_cb_t emac_link_input_cb;
162162
emac_link_state_change_cb_t emac_link_state_cb;

0 commit comments

Comments
 (0)