mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #13142 from rajkan01/fix_emac_chrono_warning
EMAC: Fix Chrono compliation warningspull/13172/head
commit
15b7fe404e
|
@ -26,6 +26,7 @@
|
|||
#include "netsocket/nsapi_types.h"
|
||||
#include "mbed_shared_queues.h"
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
/********************************************************************************
|
||||
* Internal data
|
||||
|
@ -40,7 +41,7 @@
|
|||
/** \brief Driver thread priority */
|
||||
#define THREAD_PRIORITY (osPriorityNormal)
|
||||
|
||||
#define PHY_TASK_PERIOD_MS 200
|
||||
#define PHY_TASK_PERIOD 200ms
|
||||
|
||||
|
||||
fvp_EMAC::fvp_EMAC() : _thread(THREAD_PRIORITY, THREAD_STACKSIZE, NULL, "fvp_emac_thread")
|
||||
|
@ -229,7 +230,7 @@ bool fvp_EMAC::power_up()
|
|||
/* Allow the PHY task to detect the initial link state and set up the proper flags */
|
||||
ThisThread::sleep_for(10);
|
||||
|
||||
_phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &fvp_EMAC::phy_task));
|
||||
_phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD, mbed::callback(this, &fvp_EMAC::phy_task));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@
|
|||
#include "kinetis_emac.h"
|
||||
#include "mbed_power_mgmt.h"
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
enet_handle_t g_handle;
|
||||
// TX Buffer descriptors
|
||||
uint8_t *tx_desc_start_addr;
|
||||
|
@ -75,7 +77,7 @@ extern "C" void kinetis_init_eth_hardware(void);
|
|||
/** \brief Driver thread priority */
|
||||
#define THREAD_PRIORITY (osPriorityNormal)
|
||||
|
||||
#define PHY_TASK_PERIOD_MS 200
|
||||
#define PHY_TASK_PERIOD 200ms
|
||||
|
||||
Kinetis_EMAC::Kinetis_EMAC() : xTXDCountSem(ENET_TX_RING_LEN, ENET_TX_RING_LEN), hwaddr()
|
||||
{
|
||||
|
@ -125,24 +127,25 @@ static void update_read_buffer(uint8_t *buf)
|
|||
*/
|
||||
void Kinetis_EMAC::tx_reclaim()
|
||||
{
|
||||
/* Get exclusive access */
|
||||
TXLockMutex.lock();
|
||||
/* Get exclusive access */
|
||||
TXLockMutex.lock();
|
||||
|
||||
// Traverse all descriptors, looking for the ones modified by the uDMA
|
||||
while((tx_consume_index != tx_produce_index) &&
|
||||
(!(g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
|
||||
memory_manager->free(tx_buff[tx_consume_index % ENET_TX_RING_LEN]);
|
||||
if (g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK)
|
||||
g_handle.txBdDirty = g_handle.txBdBase;
|
||||
else
|
||||
g_handle.txBdDirty++;
|
||||
// Traverse all descriptors, looking for the ones modified by the uDMA
|
||||
while ((tx_consume_index != tx_produce_index) &&
|
||||
(!(g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
|
||||
memory_manager->free(tx_buff[tx_consume_index % ENET_TX_RING_LEN]);
|
||||
if (g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK) {
|
||||
g_handle.txBdDirty = g_handle.txBdBase;
|
||||
} else {
|
||||
g_handle.txBdDirty++;
|
||||
}
|
||||
|
||||
tx_consume_index += 1;
|
||||
xTXDCountSem.release();
|
||||
}
|
||||
tx_consume_index += 1;
|
||||
xTXDCountSem.release();
|
||||
}
|
||||
|
||||
/* Restore access */
|
||||
TXLockMutex.unlock();
|
||||
/* Restore access */
|
||||
TXLockMutex.unlock();
|
||||
}
|
||||
|
||||
/** \brief Ethernet receive interrupt handler
|
||||
|
@ -164,16 +167,15 @@ void Kinetis_EMAC::tx_isr()
|
|||
void Kinetis_EMAC::ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *param)
|
||||
{
|
||||
Kinetis_EMAC *enet = static_cast<Kinetis_EMAC *>(param);
|
||||
switch (event)
|
||||
{
|
||||
case kENET_RxEvent:
|
||||
enet->rx_isr();
|
||||
break;
|
||||
case kENET_TxEvent:
|
||||
enet->tx_isr();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (event) {
|
||||
case kENET_RxEvent:
|
||||
enet->rx_isr();
|
||||
break;
|
||||
case kENET_TxEvent:
|
||||
enet->tx_isr();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,13 +193,15 @@ bool Kinetis_EMAC::low_level_init_successful()
|
|||
|
||||
// Allocate RX descriptors
|
||||
rx_desc_start_addr = (uint8_t *)calloc(1, sizeof(enet_rx_bd_struct_t) * ENET_RX_RING_LEN + ENET_BUFF_ALIGNMENT);
|
||||
if(!rx_desc_start_addr)
|
||||
if (!rx_desc_start_addr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allocate TX descriptors
|
||||
tx_desc_start_addr = (uint8_t *)calloc(1, sizeof(enet_tx_bd_struct_t) * ENET_TX_RING_LEN + ENET_BUFF_ALIGNMENT);
|
||||
if(!tx_desc_start_addr)
|
||||
if (!tx_desc_start_addr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rx_desc_start_addr = (uint8_t *)ENET_ALIGN(rx_desc_start_addr, ENET_BUFF_ALIGNMENT);
|
||||
tx_desc_start_addr = (uint8_t *)ENET_ALIGN(tx_desc_start_addr, ENET_BUFF_ALIGNMENT);
|
||||
|
@ -205,10 +209,11 @@ bool Kinetis_EMAC::low_level_init_successful()
|
|||
/* Create buffers for each receive BD */
|
||||
for (i = 0; i < ENET_RX_RING_LEN; i++) {
|
||||
rx_buff[i] = memory_manager->alloc_heap(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT);
|
||||
if (NULL == rx_buff[i])
|
||||
if (NULL == rx_buff[i]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rx_ptr[i] = (uint32_t*)memory_manager->get_ptr(rx_buff[i]);
|
||||
rx_ptr[i] = (uint32_t *)memory_manager->get_ptr(rx_buff[i]);
|
||||
}
|
||||
|
||||
tx_consume_index = tx_produce_index = 0;
|
||||
|
@ -221,7 +226,7 @@ bool Kinetis_EMAC::low_level_init_successful()
|
|||
0,
|
||||
(volatile enet_rx_bd_struct_t *)rx_desc_start_addr,
|
||||
(volatile enet_tx_bd_struct_t *)tx_desc_start_addr,
|
||||
(uint8_t *)&rx_ptr,
|
||||
(uint8_t *) &rx_ptr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
@ -291,16 +296,16 @@ emac_mem_buf_t *Kinetis_EMAC::low_level_input(int idx)
|
|||
update_read_buffer(NULL);
|
||||
|
||||
#ifdef LOCK_RX_THREAD
|
||||
TXLockMutex.unlock();
|
||||
TXLockMutex.unlock();
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rx_buff[idx] = temp_rxbuf;
|
||||
rx_ptr[idx] = (uint32_t*)memory_manager->get_ptr(rx_buff[idx]);
|
||||
rx_ptr[idx] = (uint32_t *)memory_manager->get_ptr(rx_buff[idx]);
|
||||
|
||||
update_read_buffer((uint8_t*)rx_ptr[idx]);
|
||||
update_read_buffer((uint8_t *)rx_ptr[idx]);
|
||||
}
|
||||
|
||||
#ifdef LOCK_RX_THREAD
|
||||
|
@ -333,12 +338,12 @@ void Kinetis_EMAC::input(int idx)
|
|||
*
|
||||
* \param[in] pvParameters pointer to the interface data
|
||||
*/
|
||||
void Kinetis_EMAC::thread_function(void* pvParameters)
|
||||
void Kinetis_EMAC::thread_function(void *pvParameters)
|
||||
{
|
||||
struct Kinetis_EMAC *kinetis_enet = static_cast<Kinetis_EMAC *>(pvParameters);
|
||||
|
||||
for (;;) {
|
||||
uint32_t flags = osThreadFlagsWait(FLAG_RX|FLAG_TX, osFlagsWaitAny, osWaitForever);
|
||||
uint32_t flags = osThreadFlagsWait(FLAG_RX | FLAG_TX, osFlagsWaitAny, osWaitForever);
|
||||
|
||||
MBED_ASSERT(!(flags & osFlagsError));
|
||||
|
||||
|
@ -389,7 +394,7 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
|
|||
{
|
||||
// If buffer is chained or not aligned then make a contiguous aligned copy of it
|
||||
if (memory_manager->get_next(buf) ||
|
||||
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
|
||||
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
|
||||
emac_mem_buf_t *copy_buf;
|
||||
copy_buf = memory_manager->alloc_heap(memory_manager->get_total_len(buf), ENET_BUFF_ALIGNMENT);
|
||||
if (NULL == copy_buf) {
|
||||
|
@ -507,7 +512,7 @@ bool Kinetis_EMAC::power_up()
|
|||
/* Allow the PHY task to detect the initial link state and set up the proper flags */
|
||||
osDelay(10);
|
||||
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &Kinetis_EMAC::phy_task));
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD, mbed::callback(this, &Kinetis_EMAC::phy_task));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -540,7 +545,7 @@ bool Kinetis_EMAC::get_hwaddr(uint8_t *addr) const
|
|||
void Kinetis_EMAC::set_hwaddr(const uint8_t *addr)
|
||||
{
|
||||
memcpy(hwaddr, addr, sizeof hwaddr);
|
||||
ENET_SetMacAddr(ENET, const_cast<uint8_t*>(addr));
|
||||
ENET_SetMacAddr(ENET, const_cast<uint8_t *>(addr));
|
||||
}
|
||||
|
||||
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)
|
|||
}
|
||||
|
||||
|
||||
Kinetis_EMAC &Kinetis_EMAC::get_instance() {
|
||||
Kinetis_EMAC &Kinetis_EMAC::get_instance()
|
||||
{
|
||||
static Kinetis_EMAC emac;
|
||||
return emac;
|
||||
}
|
||||
|
||||
// Weak so a module can override
|
||||
MBED_WEAK EMAC &EMAC::get_default_instance() {
|
||||
MBED_WEAK EMAC &EMAC::get_default_instance()
|
||||
{
|
||||
return Kinetis_EMAC::get_instance();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include "gd32xx_emac.h"
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
/* \brief Flags for worker thread */
|
||||
#define _ENET_FLAG_RX (1)
|
||||
|
||||
|
@ -34,7 +36,7 @@
|
|||
#define _THREAD_STACKSIZE (512)
|
||||
#define _THREAD_PRIORITY (osPriorityHigh)
|
||||
|
||||
#define _PHY_TASK_PERIOD_MS (200)
|
||||
#define _PHY_TASK_PERIOD (200ms)
|
||||
|
||||
#define _ENET_HW_ADDR_SIZE (6)
|
||||
#define _ENET_MTU_SIZE (1500)
|
||||
|
@ -345,7 +347,7 @@ bool GD32_EMAC::power_up()
|
|||
/* Worker thread */
|
||||
rx_thread = create_new_thread("gd32_emac_thread", &GD32_EMAC::thread_function, this, _THREAD_STACKSIZE, _THREAD_PRIORITY, &rx_thread_cb);
|
||||
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(_PHY_TASK_PERIOD_MS, mbed::callback(this, &GD32_EMAC::phy_task));
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(_PHY_TASK_PERIOD, mbed::callback(this, &GD32_EMAC::phy_task));
|
||||
|
||||
/* Allow the PHY task to detect the initial link state and set up the proper flags */
|
||||
osDelay(10);
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include "numaker_emac.h"
|
||||
#include "numaker_eth_hal.h"
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
********************************************************************************/
|
||||
|
@ -53,7 +55,7 @@ extern "C" void numaker_eth_rx_next(void);
|
|||
/** \brief Driver thread priority */
|
||||
#define THREAD_PRIORITY (osPriorityNormal)
|
||||
|
||||
#define PHY_TASK_PERIOD_MS 200
|
||||
#define PHY_TASK_PERIOD 200ms
|
||||
|
||||
NUMAKER_EMAC::NUMAKER_EMAC() : thread(0), hwaddr()
|
||||
{
|
||||
|
@ -331,7 +333,7 @@ bool NUMAKER_EMAC::power_up()
|
|||
/* PHY monitoring task */
|
||||
phy_state = PHY_UNLINKED_STATE;
|
||||
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &NUMAKER_EMAC::phy_task));
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD, mbed::callback(this, &NUMAKER_EMAC::phy_task));
|
||||
|
||||
/* Allow the PHY task to detect the initial link state and set up the proper flags */
|
||||
osDelay(10);
|
||||
|
|
|
@ -48,6 +48,8 @@
|
|||
#include "imx_emac.h"
|
||||
#include "mbed_power_mgmt.h"
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
enet_handle_t g_handle;
|
||||
// RX packet buffer pointers
|
||||
emac_mem_buf_t *rx_buff[ENET_RX_RING_LEN];
|
||||
|
@ -71,7 +73,7 @@ extern "C" void kinetis_init_eth_hardware(void);
|
|||
/** \brief Driver thread priority */
|
||||
#define THREAD_PRIORITY (osPriorityNormal)
|
||||
|
||||
#define PHY_TASK_PERIOD_MS 200
|
||||
#define PHY_TASK_PERIOD 200ms
|
||||
|
||||
Kinetis_EMAC::Kinetis_EMAC() : xTXDCountSem(ENET_TX_RING_LEN, ENET_TX_RING_LEN), hwaddr()
|
||||
{
|
||||
|
@ -127,24 +129,25 @@ static void update_read_buffer(uint8_t *buf)
|
|||
*/
|
||||
void Kinetis_EMAC::tx_reclaim()
|
||||
{
|
||||
/* Get exclusive access */
|
||||
TXLockMutex.lock();
|
||||
/* Get exclusive access */
|
||||
TXLockMutex.lock();
|
||||
|
||||
// Traverse all descriptors, looking for the ones modified by the uDMA
|
||||
while((tx_consume_index != tx_produce_index) &&
|
||||
(!(g_handle.txBdDirty[0]->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
|
||||
memory_manager->free(tx_buff[tx_consume_index % ENET_TX_RING_LEN]);
|
||||
if (g_handle.txBdDirty[0]->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK)
|
||||
g_handle.txBdDirty[0] = g_handle.txBdBase[0];
|
||||
else
|
||||
g_handle.txBdDirty[0]++;
|
||||
// Traverse all descriptors, looking for the ones modified by the uDMA
|
||||
while ((tx_consume_index != tx_produce_index) &&
|
||||
(!(g_handle.txBdDirty[0]->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
|
||||
memory_manager->free(tx_buff[tx_consume_index % ENET_TX_RING_LEN]);
|
||||
if (g_handle.txBdDirty[0]->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK) {
|
||||
g_handle.txBdDirty[0] = g_handle.txBdBase[0];
|
||||
} else {
|
||||
g_handle.txBdDirty[0]++;
|
||||
}
|
||||
|
||||
tx_consume_index += 1;
|
||||
xTXDCountSem.release();
|
||||
}
|
||||
tx_consume_index += 1;
|
||||
xTXDCountSem.release();
|
||||
}
|
||||
|
||||
/* Restore access */
|
||||
TXLockMutex.unlock();
|
||||
/* Restore access */
|
||||
TXLockMutex.unlock();
|
||||
}
|
||||
|
||||
/** \brief Ethernet receive interrupt handler
|
||||
|
@ -166,16 +169,15 @@ void Kinetis_EMAC::tx_isr()
|
|||
void Kinetis_EMAC::ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *param)
|
||||
{
|
||||
Kinetis_EMAC *enet = static_cast<Kinetis_EMAC *>(param);
|
||||
switch (event)
|
||||
{
|
||||
case kENET_RxEvent:
|
||||
enet->rx_isr();
|
||||
break;
|
||||
case kENET_TxEvent:
|
||||
enet->tx_isr();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (event) {
|
||||
case kENET_RxEvent:
|
||||
enet->rx_isr();
|
||||
break;
|
||||
case kENET_TxEvent:
|
||||
enet->tx_isr();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,10 +200,11 @@ bool Kinetis_EMAC::low_level_init_successful()
|
|||
for (i = 0; i < ENET_RX_RING_LEN; i++) {
|
||||
rx_buff[i] = memory_manager->alloc_heap(ENET_ALIGN(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT),
|
||||
ENET_BUFF_ALIGNMENT);
|
||||
if (NULL == rx_buff[i])
|
||||
if (NULL == rx_buff[i]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rx_ptr[i] = (uint32_t*)memory_manager->get_ptr(rx_buff[i]);
|
||||
rx_ptr[i] = (uint32_t *)memory_manager->get_ptr(rx_buff[i]);
|
||||
SCB_InvalidateDCache_by_Addr(rx_ptr[i], ENET_ALIGN(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT));
|
||||
}
|
||||
|
||||
|
@ -215,7 +218,7 @@ bool Kinetis_EMAC::low_level_init_successful()
|
|||
0,
|
||||
(volatile enet_rx_bd_struct_t *)rx_desc_start_addr,
|
||||
(volatile enet_tx_bd_struct_t *)tx_desc_start_addr,
|
||||
(uint8_t *)&rx_ptr,
|
||||
(uint8_t *) &rx_ptr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
@ -287,17 +290,17 @@ emac_mem_buf_t *Kinetis_EMAC::low_level_input(int idx)
|
|||
update_read_buffer(NULL);
|
||||
|
||||
#ifdef LOCK_RX_THREAD
|
||||
TXLockMutex.unlock();
|
||||
TXLockMutex.unlock();
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rx_buff[idx] = temp_rxbuf;
|
||||
rx_ptr[idx] = (uint32_t*)memory_manager->get_ptr(rx_buff[idx]);
|
||||
rx_ptr[idx] = (uint32_t *)memory_manager->get_ptr(rx_buff[idx]);
|
||||
SCB_InvalidateDCache_by_Addr(rx_ptr[idx], ENET_ALIGN(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT));
|
||||
|
||||
update_read_buffer((uint8_t*)rx_ptr[idx]);
|
||||
update_read_buffer((uint8_t *)rx_ptr[idx]);
|
||||
}
|
||||
|
||||
#ifdef LOCK_RX_THREAD
|
||||
|
@ -330,12 +333,12 @@ void Kinetis_EMAC::input(int idx)
|
|||
*
|
||||
* \param[in] pvParameters pointer to the interface data
|
||||
*/
|
||||
void Kinetis_EMAC::thread_function(void* pvParameters)
|
||||
void Kinetis_EMAC::thread_function(void *pvParameters)
|
||||
{
|
||||
struct Kinetis_EMAC *kinetis_enet = static_cast<Kinetis_EMAC *>(pvParameters);
|
||||
|
||||
for (;;) {
|
||||
uint32_t flags = osThreadFlagsWait(FLAG_RX|FLAG_TX, osFlagsWaitAny, osWaitForever);
|
||||
uint32_t flags = osThreadFlagsWait(FLAG_RX | FLAG_TX, osFlagsWaitAny, osWaitForever);
|
||||
|
||||
MBED_ASSERT(!(flags & osFlagsError));
|
||||
|
||||
|
@ -386,7 +389,7 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
|
|||
{
|
||||
// If buffer is chained or not aligned then make a contiguous aligned copy of it
|
||||
if (memory_manager->get_next(buf) ||
|
||||
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
|
||||
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
|
||||
emac_mem_buf_t *copy_buf;
|
||||
copy_buf = memory_manager->alloc_heap(memory_manager->get_total_len(buf), ENET_BUFF_ALIGNMENT);
|
||||
if (NULL == copy_buf) {
|
||||
|
@ -511,7 +514,7 @@ bool Kinetis_EMAC::power_up()
|
|||
/* Allow the PHY task to detect the initial link state and set up the proper flags */
|
||||
osDelay(10);
|
||||
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &Kinetis_EMAC::phy_task));
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD, mbed::callback(this, &Kinetis_EMAC::phy_task));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -544,7 +547,7 @@ bool Kinetis_EMAC::get_hwaddr(uint8_t *addr) const
|
|||
void Kinetis_EMAC::set_hwaddr(const uint8_t *addr)
|
||||
{
|
||||
memcpy(hwaddr, addr, sizeof hwaddr);
|
||||
ENET_SetMacAddr(ENET, const_cast<uint8_t*>(addr));
|
||||
ENET_SetMacAddr(ENET, const_cast<uint8_t *>(addr));
|
||||
}
|
||||
|
||||
void Kinetis_EMAC::set_link_input_cb(emac_link_input_cb_t input_cb)
|
||||
|
@ -589,13 +592,15 @@ void Kinetis_EMAC::set_memory_manager(EMACMemoryManager &mem_mngr)
|
|||
}
|
||||
|
||||
|
||||
Kinetis_EMAC &Kinetis_EMAC::get_instance() {
|
||||
Kinetis_EMAC &Kinetis_EMAC::get_instance()
|
||||
{
|
||||
static Kinetis_EMAC emac;
|
||||
return emac;
|
||||
}
|
||||
|
||||
// Weak so a module can override
|
||||
MBED_WEAK EMAC &EMAC::get_default_instance() {
|
||||
MBED_WEAK EMAC &EMAC::get_default_instance()
|
||||
{
|
||||
return Kinetis_EMAC::get_instance();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include "lpc546xx_emac_config.h"
|
||||
#include "lpc546xx_emac.h"
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
enet_handle_t g_handle;
|
||||
// RX packet buffer pointers
|
||||
emac_mem_buf_t *rx_buff[ENET_RX_RING_LEN];
|
||||
|
@ -54,7 +56,7 @@ extern "C" void lpc546xx_init_eth_hardware(void);
|
|||
/** \brief Driver thread priority */
|
||||
#define THREAD_PRIORITY (osPriorityNormal)
|
||||
|
||||
#define PHY_TASK_PERIOD_MS 200
|
||||
#define PHY_TASK_PERIOD 200ms
|
||||
|
||||
LPC546XX_EMAC::LPC546XX_EMAC() : xTXDCountSem(ENET_TX_RING_LEN, ENET_TX_RING_LEN), hwaddr()
|
||||
{
|
||||
|
@ -143,8 +145,7 @@ void LPC546XX_EMAC::ethernet_callback(ENET_Type *base, enet_handle_t *handle, en
|
|||
{
|
||||
LPC546XX_EMAC *enet = static_cast<LPC546XX_EMAC *>(param);
|
||||
|
||||
switch (event)
|
||||
{
|
||||
switch (event) {
|
||||
case kENET_RxIntEvent:
|
||||
enet->rx_isr();
|
||||
break;
|
||||
|
@ -203,22 +204,23 @@ bool LPC546XX_EMAC::low_level_init_successful()
|
|||
AT_NONCACHEABLE_SECTION_ALIGN(static enet_tx_bd_struct_t tx_desc_start_addr[ENET_TX_RING_LEN], ENET_BUFF_ALIGNMENT);
|
||||
|
||||
/* prepare the buffer configuration. */
|
||||
enet_buffer_config_t buffCfg = {
|
||||
ENET_RX_RING_LEN,
|
||||
ENET_TX_RING_LEN,
|
||||
&tx_desc_start_addr[0],
|
||||
&tx_desc_start_addr[0],
|
||||
&rx_desc_start_addr[0],
|
||||
&rx_desc_start_addr[ENET_RX_RING_LEN],
|
||||
rx_ptr,
|
||||
ENET_BuffSizeAlign(ENET_ETH_MAX_FLEN),
|
||||
};
|
||||
enet_buffer_config_t buffCfg = {
|
||||
ENET_RX_RING_LEN,
|
||||
ENET_TX_RING_LEN,
|
||||
&tx_desc_start_addr[0],
|
||||
&tx_desc_start_addr[0],
|
||||
&rx_desc_start_addr[0],
|
||||
&rx_desc_start_addr[ENET_RX_RING_LEN],
|
||||
rx_ptr,
|
||||
ENET_BuffSizeAlign(ENET_ETH_MAX_FLEN),
|
||||
};
|
||||
|
||||
/* Create buffers for each receive BD */
|
||||
for (i = 0; i < ENET_RX_RING_LEN; i++) {
|
||||
rx_buff[i] = memory_manager->alloc_heap(buffCfg.rxBuffSizeAlign, ENET_BUFF_ALIGNMENT);
|
||||
if (NULL == rx_buff[i])
|
||||
if (NULL == rx_buff[i]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rx_ptr[i] = (uint32_t)memory_manager->get_ptr(rx_buff[i]);
|
||||
}
|
||||
|
@ -291,7 +293,7 @@ emac_mem_buf_t *LPC546XX_EMAC::low_level_input()
|
|||
rx_buff[rxBdRing->rxGenIdx] = temp_rxbuf;
|
||||
rx_ptr[rxBdRing->rxGenIdx] = (uint32_t)memory_manager->get_ptr(rx_buff[rxBdRing->rxGenIdx]);
|
||||
|
||||
update_read_buffer(bdPtr, (uint8_t*)rx_ptr[rxBdRing->rxGenIdx]);
|
||||
update_read_buffer(bdPtr, (uint8_t *)rx_ptr[rxBdRing->rxGenIdx]);
|
||||
}
|
||||
|
||||
#ifdef LOCK_RX_THREAD
|
||||
|
@ -322,7 +324,7 @@ void LPC546XX_EMAC::input()
|
|||
*
|
||||
* \param[in] pvParameters pointer to the interface data
|
||||
*/
|
||||
void LPC546XX_EMAC::thread_function(void* pvParameters)
|
||||
void LPC546XX_EMAC::thread_function(void *pvParameters)
|
||||
{
|
||||
struct LPC546XX_EMAC *lpc_enet = static_cast<LPC546XX_EMAC *>(pvParameters);
|
||||
|
||||
|
@ -364,8 +366,7 @@ void LPC546XX_EMAC::packet_rx()
|
|||
}
|
||||
|
||||
/* Set command for rx when it is suspend. */
|
||||
if (suspend)
|
||||
{
|
||||
if (suspend) {
|
||||
ENET->DMA_CH[0].DMA_CHX_RXDESC_TAIL_PTR = ENET->DMA_CH[0].DMA_CHX_RXDESC_TAIL_PTR;
|
||||
}
|
||||
}
|
||||
|
@ -394,7 +395,7 @@ bool LPC546XX_EMAC::link_out(emac_mem_buf_t *buf)
|
|||
|
||||
// If buffer is chained or not aligned then make a contiguous aligned copy of it
|
||||
if (memory_manager->get_next(buf) ||
|
||||
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
|
||||
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
|
||||
emac_mem_buf_t *copy_buf;
|
||||
copy_buf = memory_manager->alloc_heap(memory_manager->get_total_len(buf), ENET_BUFF_ALIGNMENT);
|
||||
if (NULL == copy_buf) {
|
||||
|
@ -438,7 +439,8 @@ bool LPC546XX_EMAC::link_out(emac_mem_buf_t *buf)
|
|||
|
||||
#define STATE_UNKNOWN (-1)
|
||||
|
||||
int phy_link_status(void) {
|
||||
int phy_link_status(void)
|
||||
{
|
||||
bool connection_status;
|
||||
uint32_t phyAddr = 0;
|
||||
|
||||
|
@ -497,7 +499,7 @@ bool LPC546XX_EMAC::power_up()
|
|||
prev_state.speed = (phy_speed_t)STATE_UNKNOWN;
|
||||
prev_state.duplex = (phy_duplex_t)STATE_UNKNOWN;
|
||||
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &LPC546XX_EMAC::phy_task));
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD, mbed::callback(this, &LPC546XX_EMAC::phy_task));
|
||||
|
||||
/* Allow the PHY task to detect the initial link state and set up the proper flags */
|
||||
osDelay(10);
|
||||
|
@ -536,7 +538,7 @@ bool LPC546XX_EMAC::get_hwaddr(uint8_t *addr) const
|
|||
void LPC546XX_EMAC::set_hwaddr(const uint8_t *addr)
|
||||
{
|
||||
memcpy(hwaddr, addr, sizeof hwaddr);
|
||||
ENET_SetMacAddr(ENET, const_cast<uint8_t*>(addr));
|
||||
ENET_SetMacAddr(ENET, const_cast<uint8_t *>(addr));
|
||||
}
|
||||
|
||||
void LPC546XX_EMAC::set_link_input_cb(emac_link_input_cb_t input_cb)
|
||||
|
@ -583,13 +585,15 @@ void LPC546XX_EMAC::set_memory_manager(EMACMemoryManager &mem_mngr)
|
|||
}
|
||||
|
||||
|
||||
LPC546XX_EMAC &LPC546XX_EMAC::get_instance() {
|
||||
LPC546XX_EMAC &LPC546XX_EMAC::get_instance()
|
||||
{
|
||||
static LPC546XX_EMAC emac;
|
||||
return emac;
|
||||
}
|
||||
|
||||
// Weak so a module can override
|
||||
MBED_WEAK EMAC &EMAC::get_default_instance() {
|
||||
MBED_WEAK EMAC &EMAC::get_default_instance()
|
||||
{
|
||||
return LPC546XX_EMAC::get_instance();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,13 +52,15 @@
|
|||
#include "lwip/api.h"
|
||||
#endif
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
/* \brief Flags for worker thread */
|
||||
#define FLAG_RX 1
|
||||
|
||||
/** \brief Driver thread priority */
|
||||
#define THREAD_PRIORITY (osPriorityHigh)
|
||||
|
||||
#define PHY_TASK_PERIOD_MS 200
|
||||
#define PHY_TASK_PERIOD 200ms
|
||||
|
||||
#define STM_HWADDR_SIZE (6)
|
||||
#define STM_ETH_MTU_SIZE 1500
|
||||
|
@ -884,13 +886,13 @@ bool STM32_EMAC::power_up()
|
|||
|
||||
/* Worker thread */
|
||||
#if MBED_CONF_MBED_TRACE_ENABLE
|
||||
thread = create_new_thread("stm32_emac_thread", &STM32_EMAC::thread_function, this, MBED_CONF_STM32_EMAC_THREAD_STACKSIZE*2, THREAD_PRIORITY, &thread_cb);
|
||||
thread = create_new_thread("stm32_emac_thread", &STM32_EMAC::thread_function, this, MBED_CONF_STM32_EMAC_THREAD_STACKSIZE * 2, THREAD_PRIORITY, &thread_cb);
|
||||
#else
|
||||
thread = create_new_thread("stm32_emac_thread", &STM32_EMAC::thread_function, this, MBED_CONF_STM32_EMAC_THREAD_STACKSIZE, THREAD_PRIORITY, &thread_cb);
|
||||
#endif
|
||||
|
||||
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD_MS, mbed::callback(this, &STM32_EMAC::phy_task));
|
||||
phy_task_handle = mbed::mbed_event_queue()->call_every(PHY_TASK_PERIOD, mbed::callback(this, &STM32_EMAC::phy_task));
|
||||
|
||||
#if defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx)\
|
||||
|| defined (STM32F779xx)
|
||||
|
|
Loading…
Reference in New Issue