Skip to content

Commit 15b7fe4

Browse files
authored
Merge pull request #13142 from rajkan01/fix_emac_chrono_warning
EMAC: Fix Chrono compliation warnings
2 parents 6646e8e + 31bc95a commit 15b7fe4

File tree

7 files changed

+142
-119
lines changed

7 files changed

+142
-119
lines changed

features/netsocket/emac-drivers/TARGET_ARM_FM/COMPONENT_LAN91C111/fvp_emac.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "netsocket/nsapi_types.h"
2727
#include "mbed_shared_queues.h"
2828

29+
using namespace std::chrono;
2930

3031
/********************************************************************************
3132
* Internal data
@@ -40,7 +41,7 @@
4041
/** \brief Driver thread priority */
4142
#define THREAD_PRIORITY (osPriorityNormal)
4243

43-
#define PHY_TASK_PERIOD_MS 200
44+
#define PHY_TASK_PERIOD 200ms
4445

4546

4647
fvp_EMAC::fvp_EMAC() : _thread(THREAD_PRIORITY, THREAD_STACKSIZE, NULL, "fvp_emac_thread")
@@ -229,7 +230,7 @@ bool fvp_EMAC::power_up()
229230
/* Allow the PHY task to detect the initial link state and set up the proper flags */
230231
ThisThread::sleep_for(10);
231232

232-
_phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &fvp_EMAC::phy_task));
233+
_phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD, mbed::callback(this, &fvp_EMAC::phy_task));
233234

234235
return true;
235236
}

features/netsocket/emac-drivers/TARGET_Freescale_EMAC/kinetis_emac.cpp

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "kinetis_emac.h"
4949
#include "mbed_power_mgmt.h"
5050

51+
using namespace std::chrono;
52+
5153
enet_handle_t g_handle;
5254
// TX Buffer descriptors
5355
uint8_t *tx_desc_start_addr;
@@ -75,7 +77,7 @@ extern "C" void kinetis_init_eth_hardware(void);
7577
/** \brief Driver thread priority */
7678
#define THREAD_PRIORITY (osPriorityNormal)
7779

78-
#define PHY_TASK_PERIOD_MS 200
80+
#define PHY_TASK_PERIOD 200ms
7981

8082
Kinetis_EMAC::Kinetis_EMAC() : xTXDCountSem(ENET_TX_RING_LEN, ENET_TX_RING_LEN), hwaddr()
8183
{
@@ -125,24 +127,25 @@ static void update_read_buffer(uint8_t *buf)
125127
*/
126128
void Kinetis_EMAC::tx_reclaim()
127129
{
128-
/* Get exclusive access */
129-
TXLockMutex.lock();
130-
131-
// Traverse all descriptors, looking for the ones modified by the uDMA
132-
while((tx_consume_index != tx_produce_index) &&
133-
(!(g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
134-
memory_manager->free(tx_buff[tx_consume_index % ENET_TX_RING_LEN]);
135-
if (g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK)
136-
g_handle.txBdDirty = g_handle.txBdBase;
137-
else
138-
g_handle.txBdDirty++;
139-
140-
tx_consume_index += 1;
141-
xTXDCountSem.release();
142-
}
143-
144-
/* Restore access */
145-
TXLockMutex.unlock();
130+
/* Get exclusive access */
131+
TXLockMutex.lock();
132+
133+
// Traverse all descriptors, looking for the ones modified by the uDMA
134+
while ((tx_consume_index != tx_produce_index) &&
135+
(!(g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
136+
memory_manager->free(tx_buff[tx_consume_index % ENET_TX_RING_LEN]);
137+
if (g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK) {
138+
g_handle.txBdDirty = g_handle.txBdBase;
139+
} else {
140+
g_handle.txBdDirty++;
141+
}
142+
143+
tx_consume_index += 1;
144+
xTXDCountSem.release();
145+
}
146+
147+
/* Restore access */
148+
TXLockMutex.unlock();
146149
}
147150

148151
/** \brief Ethernet receive interrupt handler
@@ -164,16 +167,15 @@ void Kinetis_EMAC::tx_isr()
164167
void Kinetis_EMAC::ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *param)
165168
{
166169
Kinetis_EMAC *enet = static_cast<Kinetis_EMAC *>(param);
167-
switch (event)
168-
{
169-
case kENET_RxEvent:
170-
enet->rx_isr();
171-
break;
172-
case kENET_TxEvent:
173-
enet->tx_isr();
174-
break;
175-
default:
176-
break;
170+
switch (event) {
171+
case kENET_RxEvent:
172+
enet->rx_isr();
173+
break;
174+
case kENET_TxEvent:
175+
enet->tx_isr();
176+
break;
177+
default:
178+
break;
177179
}
178180
}
179181

@@ -191,24 +193,27 @@ bool Kinetis_EMAC::low_level_init_successful()
191193

192194
// Allocate RX descriptors
193195
rx_desc_start_addr = (uint8_t *)calloc(1, sizeof(enet_rx_bd_struct_t) * ENET_RX_RING_LEN + ENET_BUFF_ALIGNMENT);
194-
if(!rx_desc_start_addr)
196+
if (!rx_desc_start_addr) {
195197
return false;
198+
}
196199

197200
// Allocate TX descriptors
198201
tx_desc_start_addr = (uint8_t *)calloc(1, sizeof(enet_tx_bd_struct_t) * ENET_TX_RING_LEN + ENET_BUFF_ALIGNMENT);
199-
if(!tx_desc_start_addr)
202+
if (!tx_desc_start_addr) {
200203
return false;
204+
}
201205

202206
rx_desc_start_addr = (uint8_t *)ENET_ALIGN(rx_desc_start_addr, ENET_BUFF_ALIGNMENT);
203207
tx_desc_start_addr = (uint8_t *)ENET_ALIGN(tx_desc_start_addr, ENET_BUFF_ALIGNMENT);
204208

205209
/* Create buffers for each receive BD */
206210
for (i = 0; i < ENET_RX_RING_LEN; i++) {
207211
rx_buff[i] = memory_manager->alloc_heap(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT);
208-
if (NULL == rx_buff[i])
212+
if (NULL == rx_buff[i]) {
209213
return false;
214+
}
210215

211-
rx_ptr[i] = (uint32_t*)memory_manager->get_ptr(rx_buff[i]);
216+
rx_ptr[i] = (uint32_t *)memory_manager->get_ptr(rx_buff[i]);
212217
}
213218

214219
tx_consume_index = tx_produce_index = 0;
@@ -221,7 +226,7 @@ bool Kinetis_EMAC::low_level_init_successful()
221226
0,
222227
(volatile enet_rx_bd_struct_t *)rx_desc_start_addr,
223228
(volatile enet_tx_bd_struct_t *)tx_desc_start_addr,
224-
(uint8_t *)&rx_ptr,
229+
(uint8_t *) &rx_ptr,
225230
NULL,
226231
};
227232

@@ -291,16 +296,16 @@ emac_mem_buf_t *Kinetis_EMAC::low_level_input(int idx)
291296
update_read_buffer(NULL);
292297

293298
#ifdef LOCK_RX_THREAD
294-
TXLockMutex.unlock();
299+
TXLockMutex.unlock();
295300
#endif
296301

297302
return NULL;
298303
}
299304

300305
rx_buff[idx] = temp_rxbuf;
301-
rx_ptr[idx] = (uint32_t*)memory_manager->get_ptr(rx_buff[idx]);
306+
rx_ptr[idx] = (uint32_t *)memory_manager->get_ptr(rx_buff[idx]);
302307

303-
update_read_buffer((uint8_t*)rx_ptr[idx]);
308+
update_read_buffer((uint8_t *)rx_ptr[idx]);
304309
}
305310

306311
#ifdef LOCK_RX_THREAD
@@ -333,12 +338,12 @@ void Kinetis_EMAC::input(int idx)
333338
*
334339
* \param[in] pvParameters pointer to the interface data
335340
*/
336-
void Kinetis_EMAC::thread_function(void* pvParameters)
341+
void Kinetis_EMAC::thread_function(void *pvParameters)
337342
{
338343
struct Kinetis_EMAC *kinetis_enet = static_cast<Kinetis_EMAC *>(pvParameters);
339344

340345
for (;;) {
341-
uint32_t flags = osThreadFlagsWait(FLAG_RX|FLAG_TX, osFlagsWaitAny, osWaitForever);
346+
uint32_t flags = osThreadFlagsWait(FLAG_RX | FLAG_TX, osFlagsWaitAny, osWaitForever);
342347

343348
MBED_ASSERT(!(flags & osFlagsError));
344349

@@ -389,7 +394,7 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
389394
{
390395
// If buffer is chained or not aligned then make a contiguous aligned copy of it
391396
if (memory_manager->get_next(buf) ||
392-
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
397+
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
393398
emac_mem_buf_t *copy_buf;
394399
copy_buf = memory_manager->alloc_heap(memory_manager->get_total_len(buf), ENET_BUFF_ALIGNMENT);
395400
if (NULL == copy_buf) {
@@ -507,7 +512,7 @@ bool Kinetis_EMAC::power_up()
507512
/* Allow the PHY task to detect the initial link state and set up the proper flags */
508513
osDelay(10);
509514

510-
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &Kinetis_EMAC::phy_task));
515+
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD, mbed::callback(this, &Kinetis_EMAC::phy_task));
511516

512517
return true;
513518
}
@@ -540,7 +545,7 @@ bool Kinetis_EMAC::get_hwaddr(uint8_t *addr) const
540545
void Kinetis_EMAC::set_hwaddr(const uint8_t *addr)
541546
{
542547
memcpy(hwaddr, addr, sizeof hwaddr);
543-
ENET_SetMacAddr(ENET, const_cast<uint8_t*>(addr));
548+
ENET_SetMacAddr(ENET, const_cast<uint8_t *>(addr));
544549
}
545550

546551
void Kinetis_EMAC::set_link_input_cb(emac_link_input_cb_t input_cb)
@@ -585,13 +590,15 @@ void Kinetis_EMAC::set_memory_manager(EMACMemoryManager &mem_mngr)
585590
}
586591

587592

588-
Kinetis_EMAC &Kinetis_EMAC::get_instance() {
593+
Kinetis_EMAC &Kinetis_EMAC::get_instance()
594+
{
589595
static Kinetis_EMAC emac;
590596
return emac;
591597
}
592598

593599
// Weak so a module can override
594-
MBED_WEAK EMAC &EMAC::get_default_instance() {
600+
MBED_WEAK EMAC &EMAC::get_default_instance()
601+
{
595602
return Kinetis_EMAC::get_instance();
596603
}
597604

features/netsocket/emac-drivers/TARGET_GD_EMAC/gd32xx_emac.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@
2727

2828
#include "gd32xx_emac.h"
2929

30+
using namespace std::chrono;
31+
3032
/* \brief Flags for worker thread */
3133
#define _ENET_FLAG_RX (1)
3234

3335
/** \brief Driver thread priority */
3436
#define _THREAD_STACKSIZE (512)
3537
#define _THREAD_PRIORITY (osPriorityHigh)
3638

37-
#define _PHY_TASK_PERIOD_MS (200)
39+
#define _PHY_TASK_PERIOD (200ms)
3840

3941
#define _ENET_HW_ADDR_SIZE (6)
4042
#define _ENET_MTU_SIZE (1500)
@@ -345,7 +347,7 @@ bool GD32_EMAC::power_up()
345347
/* Worker thread */
346348
rx_thread = create_new_thread("gd32_emac_thread", &GD32_EMAC::thread_function, this, _THREAD_STACKSIZE, _THREAD_PRIORITY, &rx_thread_cb);
347349

348-
phy_task_handle = mbed::mbed_event_queue()->call_every(_PHY_TASK_PERIOD_MS, mbed::callback(this, &GD32_EMAC::phy_task));
350+
phy_task_handle = mbed::mbed_event_queue()->call_every(_PHY_TASK_PERIOD, mbed::callback(this, &GD32_EMAC::phy_task));
349351

350352
/* Allow the PHY task to detect the initial link state and set up the proper flags */
351353
osDelay(10);

features/netsocket/emac-drivers/TARGET_NUVOTON_EMAC/numaker_emac.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "numaker_emac.h"
3737
#include "numaker_eth_hal.h"
3838

39+
using namespace std::chrono;
40+
3941
/********************************************************************************
4042
*
4143
********************************************************************************/
@@ -53,7 +55,7 @@ extern "C" void numaker_eth_rx_next(void);
5355
/** \brief Driver thread priority */
5456
#define THREAD_PRIORITY (osPriorityNormal)
5557

56-
#define PHY_TASK_PERIOD_MS 200
58+
#define PHY_TASK_PERIOD 200ms
5759

5860
NUMAKER_EMAC::NUMAKER_EMAC() : thread(0), hwaddr()
5961
{
@@ -331,7 +333,7 @@ bool NUMAKER_EMAC::power_up()
331333
/* PHY monitoring task */
332334
phy_state = PHY_UNLINKED_STATE;
333335

334-
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &NUMAKER_EMAC::phy_task));
336+
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD, mbed::callback(this, &NUMAKER_EMAC::phy_task));
335337

336338
/* Allow the PHY task to detect the initial link state and set up the proper flags */
337339
osDelay(10);

0 commit comments

Comments
 (0)