|
| 1 | + |
1 | 2 | #include "W5500EMAC.h"
|
2 | 3 | #include <Arduino.h>
|
3 | 4 | #include <SPI.h>
|
4 | 5 |
|
| 6 | +#include <EthernetInterface.h> |
| 7 | +#include <mbed_events.h> |
| 8 | + |
5 | 9 | #ifndef W5500_CS
|
6 | 10 | #ifdef ARDUINO_ARCH_MBED_PORTENTA
|
7 | 11 | #define W5500_CS D5 // MKR ETH shield CS
|
@@ -162,33 +166,39 @@ bool W5500EMAC::link_out(emac_mem_buf_t *buf) {
|
162 | 166 |
|
163 | 167 | uint16_t len = memoryManager->get_len(buf);
|
164 | 168 | uint8_t *data = (uint8_t*) (memoryManager->get_ptr(buf));
|
| 169 | + ethLockMutex.lock(); |
165 | 170 | spi.beginTransaction(SPI_ETHERNET_SETTINGS);
|
166 | 171 | bool ret = driver.sendFrame(data, len) == len;
|
167 | 172 | spi.endTransaction();
|
168 | 173 | memoryManager->free(buf);
|
| 174 | + ethLockMutex.unlock(); |
169 | 175 |
|
170 | 176 | return ret;
|
171 | 177 | }
|
172 | 178 |
|
173 | 179 | void W5500EMAC::linkStatusTask() {
|
| 180 | + ethLockMutex.lock(); |
174 | 181 | spi.beginTransaction(SPI_ETHERNET_SETTINGS);
|
175 |
| - static bool linked = false; |
| 182 | + static bool linked = !driver.isLinked(); |
176 | 183 | if (linked != driver.isLinked()) {
|
177 | 184 | linked = driver.isLinked();
|
178 | 185 | emac_link_state_cb(linked);
|
179 | 186 | }
|
180 | 187 | spi.endTransaction();
|
| 188 | + ethLockMutex.unlock(); |
181 | 189 | }
|
182 | 190 |
|
183 | 191 | void W5500EMAC::receiveTask() {
|
184 | 192 | if (!emac_link_input_cb)
|
185 | 193 | return;
|
| 194 | + ethLockMutex.lock(); |
186 | 195 | spi.beginTransaction(SPI_ETHERNET_SETTINGS);
|
187 | 196 | emac_mem_buf_t *buf = driver.readFrame(memoryManager);
|
188 | 197 | spi.endTransaction();
|
189 | 198 | if (buf != NULL) {
|
190 | 199 | emac_link_input_cb(buf);
|
191 | 200 | }
|
| 201 | + ethLockMutex.unlock(); |
192 | 202 | }
|
193 | 203 |
|
194 | 204 | /**
|
@@ -247,3 +257,9 @@ void W5500EMAC::set_memory_manager(EMACMemoryManager &mem_mngr) {
|
247 | 257 | EMAC& EMAC::get_default_instance() {
|
248 | 258 | return W5500EMAC::get_instance();
|
249 | 259 | }
|
| 260 | + |
| 261 | +EthInterface *EthInterface::get_target_default_instance() |
| 262 | +{ |
| 263 | + static EthernetInterface ethernet; |
| 264 | + return ðernet; |
| 265 | +} |
0 commit comments