Skip to content

Commit 78b186e

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
Update code according to the reviews
* move emac driver to COMPONENT folder * use mbed rtos C++ API instead of CMSIS API
1 parent eea7245 commit 78b186e

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

features/netsocket/emac-drivers/TARGET_ARM_FM_EMAC/fvp_emac.cpp renamed to features/netsocket/emac-drivers/TARGET_ARM_FM/COMPONENT_LAN91C111/fvp_emac.cpp

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,9 @@
4343
#define PHY_TASK_PERIOD_MS 200
4444

4545

46-
fvp_EMAC::fvp_EMAC()
47-
{
48-
}
46+
fvp_EMAC::fvp_EMAC() : _thread(THREAD_PRIORITY,THREAD_STACKSIZE,NULL,"fvp_emac_thread")
4947

50-
/** \brief Create a new thread for TX/RX. */
51-
static osThreadId_t create_new_thread(const char *threadName, void (*thread)(void *arg), void *arg, int stacksize, osPriority_t priority, mbed_rtos_storage_thread_t *_thread_cb)
5248
{
53-
osThreadAttr_t attr = {0};
54-
attr.name = threadName;
55-
attr.stack_mem = malloc(stacksize);
56-
attr.cb_mem = _thread_cb;
57-
attr.stack_size = stacksize;
58-
attr.cb_size = sizeof(mbed_rtos_storage_thread_t);
59-
attr.priority = priority;
60-
return osThreadNew(thread, arg, &attr);
6149
}
6250

6351
void fvp_EMAC::ethernet_callback(lan91_event_t event, void *param)
@@ -79,15 +67,13 @@ void fvp_EMAC::ethernet_callback(lan91_event_t event, void *param)
7967
/** \brief Ethernet receive interrupt handler */
8068
void fvp_EMAC::rx_isr()
8169
{
82-
if (_thread) {
83-
osThreadFlagsSet(_thread, FLAG_RX);
84-
}
70+
_thread.flags_set(FLAG_RX);
8571
}
8672

8773
/** \brief Ethernet transmit interrupt handler */
8874
void fvp_EMAC::tx_isr()
8975
{
90-
osThreadFlagsSet(_thread, FLAG_TX);
76+
_thread.flags_set(FLAG_TX);
9177
}
9278

9379
/** \brief Low level init of the MAC and PHY. */
@@ -109,7 +95,7 @@ void fvp_EMAC::thread_function(void* pvParameters)
10995
struct fvp_EMAC *fvp_enet = static_cast<fvp_EMAC *>(pvParameters);
11096

11197
for (;;) {
112-
uint32_t flags = osThreadFlagsWait(FLAG_RX|FLAG_TX, osFlagsWaitAny, osWaitForever);
98+
uint32_t flags = ThisThread::flags_wait_any(FLAG_RX|FLAG_TX);
11399
if (flags & FLAG_RX) {
114100
fvp_enet->packet_rx();
115101
}
@@ -234,8 +220,8 @@ bool fvp_EMAC::power_up()
234220
return false;
235221
}
236222

237-
/* ethernet Worker thread */
238-
_thread = create_new_thread("FVP_EMAC_thread", &fvp_EMAC::thread_function, this, THREAD_STACKSIZE, THREAD_PRIORITY, &_thread_cb);
223+
/* Start ethernet Worker thread */
224+
_thread.start(callback(&fvp_EMAC::thread_function, this));
239225

240226
/* Trigger thread to deal with any RX packets that arrived before thread was started */
241227
rx_isr();
@@ -246,7 +232,7 @@ bool fvp_EMAC::power_up()
246232
mbed::mbed_event_queue()->call(mbed::callback(this, &fvp_EMAC::phy_task));
247233

248234
/* Allow the PHY task to detect the initial link state and set up the proper flags */
249-
osDelay(10);
235+
wait_ms(10);
250236

251237
_phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &fvp_EMAC::phy_task));
252238

features/netsocket/emac-drivers/TARGET_ARM_FM_EMAC/fvp_emac.h renamed to features/netsocket/emac-drivers/TARGET_ARM_FM/COMPONENT_LAN91C111/fvp_emac.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define FVP_EMAC_H_
1919

2020
#include "EMAC.h"
21-
#include "rtos/Semaphore.h"
21+
#include "mbed.h"
2222
#include "rtos/Mutex.h"
2323
#include "lan91c111.h"
2424

@@ -163,8 +163,7 @@ class fvp_EMAC : public EMAC {
163163
void phy_task();
164164
static void ethernet_callback(lan91_event_t event, void *param);
165165

166-
mbed_rtos_storage_thread_t _thread_cb;
167-
osThreadId_t _thread; /* Processing thread */
166+
Thread _thread; /* Processing thread */
168167
rtos::Mutex _TXLockMutex; /* TX critical section mutex */
169168

170169
emac_link_input_cb_t _emac_link_input_cb; /* Callback for incoming data */

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7134,7 +7134,7 @@
71347134
"USTICKER"
71357135
],
71367136
"release_versions": ["5"],
7137-
"extra_labels": ["ARM_FM_EMAC"],
7137+
"components": ["LAN91C111"],
71387138
"overrides": {
71397139
"network-default-interface-type": "ETHERNET"
71407140
}

0 commit comments

Comments
 (0)