2023-05-03 14:01:32 +03:00
|
|
|
|
/*
|
|
|
|
|
|
* eth_rx_flow.cpp
|
|
|
|
|
|
*
|
|
|
|
|
|
* Created on: 7 <EFBFBD><EFBFBD><EFBFBD>. 2023 <EFBFBD>.
|
|
|
|
|
|
* Author: sychev
|
|
|
|
|
|
*/
|
2023-06-26 18:22:30 +03:00
|
|
|
|
#include "free_rtos/ethernet/eth_rx_flow.hpp"
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
#include <networking/enet/core/include/core/enet_soc.h>
|
2023-09-27 15:37:10 +03:00
|
|
|
|
#include <networking/enet/core/src/dma/udma/enet_udma_priv.h> // Yes, it is forbidden !
|
2023-05-03 14:01:32 +03:00
|
|
|
|
#include <networking/enet/utils/include/enet_board.h>
|
|
|
|
|
|
#include <networking/enet/utils/include/enet_appmemutils.h>
|
|
|
|
|
|
#include <networking/enet/utils/include/enet_appmemutils_cfg.h>
|
|
|
|
|
|
#include <networking/enet/utils/include/enet_apputils.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
|
|
/**
|
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sysconfig.
|
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <build_name>/syscfg
|
|
|
|
|
|
*/
|
|
|
|
|
|
#include "ti_enet_config.h"
|
|
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
using namespace free_rtos;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
*/
|
|
|
|
|
|
void free_rtos::rxIsrHandler(void *appData)
|
|
|
|
|
|
{
|
|
|
|
|
|
EthRxFlow * rx_flow = (EthRxFlow *)appData;
|
2023-09-26 10:09:59 +03:00
|
|
|
|
|
2023-09-26 16:29:18 +03:00
|
|
|
|
if(rx_flow == nullptr) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-09-26 10:09:59 +03:00
|
|
|
|
|
2023-09-28 14:13:26 +03:00
|
|
|
|
rx_flow->sem_[EthRxFlow::e_signalRxPkt].post();
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void free_rtos::rxTaskHandler(void *appData)
|
|
|
|
|
|
{
|
|
|
|
|
|
EthRxFlow * rx_flow = (EthRxFlow *)appData;
|
|
|
|
|
|
if (rx_flow != nullptr) {
|
|
|
|
|
|
rx_flow->rxProcessPktTask();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-22 10:59:11 +03:00
|
|
|
|
free_rtos::EthRxFlow::EthRxFlow(TEthFrameMacAddr& mac_addr, EthStackIface& eth_stack) :
|
|
|
|
|
|
mac_addr_{mac_addr},
|
|
|
|
|
|
eth_stack_{eth_stack},
|
|
|
|
|
|
passive_mode_{false}
|
|
|
|
|
|
{
|
|
|
|
|
|
EnetQueue_initQ(&rx_free_pktq_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-27 13:20:33 +03:00
|
|
|
|
void free_rtos::EthRxFlow::initRxFreePktQ(void * appPriv, EnetDma_PktQ * p_packet_queue, uint32_t qCount)
|
2023-05-03 14:01:32 +03:00
|
|
|
|
{
|
|
|
|
|
|
EnetDma_PktQ rxReadyQ;
|
|
|
|
|
|
EnetDma_Pkt *pPktInfo;
|
|
|
|
|
|
uint32_t i;
|
|
|
|
|
|
int32_t status;
|
|
|
|
|
|
|
2023-09-22 10:59:11 +03:00
|
|
|
|
for (i = 0U; i < qCount; ++i)
|
2023-05-03 14:01:32 +03:00
|
|
|
|
{
|
|
|
|
|
|
pPktInfo = EnetMem_allocEthPkt(appPriv,
|
|
|
|
|
|
ENET_MEM_LARGE_POOL_PKT_SIZE,
|
|
|
|
|
|
ENETDMA_CACHELINE_ALIGNMENT);
|
|
|
|
|
|
EnetAppUtils_assert(pPktInfo != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
ENET_UTILS_SET_PKT_APP_STATE(&pPktInfo->pktState, ENET_PKTSTATE_APP_WITH_FREEQ);
|
|
|
|
|
|
|
2023-10-27 13:20:33 +03:00
|
|
|
|
EnetQueue_enq(p_packet_queue, &pPktInfo->node);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Retrieve any packets which are ready */
|
|
|
|
|
|
EnetQueue_initQ(&rxReadyQ);
|
2023-10-27 13:20:33 +03:00
|
|
|
|
|
2023-09-22 10:59:11 +03:00
|
|
|
|
status = EnetDma_retrieveRxPktQ(dma_handle_, &rxReadyQ);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
EnetAppUtils_assert(status == ENET_SOK);
|
|
|
|
|
|
|
|
|
|
|
|
/* There should not be any packet with DMA during init */
|
|
|
|
|
|
EnetAppUtils_assert(EnetQueue_getQCount(&rxReadyQ) == 0U);
|
2023-09-22 10:59:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-26 16:29:18 +03:00
|
|
|
|
void free_rtos::EthRxFlow::submitFreeRxPkts(uint32_t qCount)
|
2023-09-22 10:59:11 +03:00
|
|
|
|
{
|
|
|
|
|
|
EnetDma_PktQ rxSubmitQ;
|
|
|
|
|
|
EnetDma_Pkt* rxPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&rx_free_pktq_);
|
2023-09-25 14:58:34 +03:00
|
|
|
|
int32_t status;
|
2023-09-22 10:59:11 +03:00
|
|
|
|
|
|
|
|
|
|
EnetQueue_initQ(&rxSubmitQ);
|
|
|
|
|
|
|
2023-10-27 13:20:33 +03:00
|
|
|
|
while((qCount > 0) && (rxPktInfo != nullptr))
|
2023-09-22 10:59:11 +03:00
|
|
|
|
{
|
|
|
|
|
|
EnetQueue_enq(&rxSubmitQ, &rxPktInfo->node);
|
|
|
|
|
|
|
|
|
|
|
|
rxPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&rx_free_pktq_);
|
|
|
|
|
|
qCount--;
|
|
|
|
|
|
}
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-09-22 10:59:11 +03:00
|
|
|
|
EnetAppUtils_validatePacketState(&rxSubmitQ,
|
2023-05-03 14:01:32 +03:00
|
|
|
|
ENET_PKTSTATE_APP_WITH_FREEQ,
|
|
|
|
|
|
ENET_PKTSTATE_APP_WITH_DRIVER);
|
|
|
|
|
|
|
2023-09-25 14:58:34 +03:00
|
|
|
|
status = EnetDma_submitRxPktQ(dma_handle_, &rxSubmitQ);
|
2023-10-27 13:20:33 +03:00
|
|
|
|
EnetAppUtils_assert(status == ENET_SOK);
|
2023-09-25 14:58:34 +03:00
|
|
|
|
|
|
|
|
|
|
qCount = EnetQueue_getQCount(&rxSubmitQ);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
/* Assert here, as during init, the number of DMA descriptors should be equal to
|
2023-10-27 13:20:33 +03:00
|
|
|
|
* the number of free Ethernet buffers available with app */
|
|
|
|
|
|
EnetAppUtils_assert(qCount == 0U);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void free_rtos::EthRxFlow::rxProcessPktTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
EnetDma_Pkt* rxPktInfo; /// <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2023-09-26 16:29:18 +03:00
|
|
|
|
EnetDma_PktQ rxReadyQ;
|
|
|
|
|
|
uint32_t readyQCount;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
int32_t status;
|
|
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
|
{
|
2023-11-01 11:48:36 +03:00
|
|
|
|
if(enetDmaRxChId_ != ENET_DMA_RX_CH0) {
|
|
|
|
|
|
status = sem_[e_signalRxPkt].pend();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
status = sem_[e_signalRxPkt].pend(semaphore_timeout_ticks_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(status != SystemP_SUCCESS) {
|
|
|
|
|
|
EnetAppUtils_print("RX Timeout ");
|
|
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2023-09-25 14:58:34 +03:00
|
|
|
|
|
2023-10-18 15:29:31 +03:00
|
|
|
|
do {
|
2023-10-27 13:20:33 +03:00
|
|
|
|
EnetDma_PktQ rxFreeQ;
|
|
|
|
|
|
|
|
|
|
|
|
EnetQueue_initQ(&rxFreeQ);
|
|
|
|
|
|
|
2023-10-18 15:29:31 +03:00
|
|
|
|
status = EnetDma_retrieveRxPktQ(dma_handle_, &rxReadyQ);
|
|
|
|
|
|
EnetAppUtils_assert(status == ENET_SOK);
|
2023-09-26 16:29:18 +03:00
|
|
|
|
|
2023-10-18 15:29:31 +03:00
|
|
|
|
readyQCount = EnetQueue_getQCount(&rxReadyQ);
|
2023-10-27 14:34:26 +03:00
|
|
|
|
|
|
|
|
|
|
if(readyQCount == 0) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-10-18 15:29:31 +03:00
|
|
|
|
// Reload DMA with a new rx free queue as fast as possible
|
|
|
|
|
|
submitFreeRxPkts(readyQCount);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-10-18 15:29:31 +03:00
|
|
|
|
rxPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&rxReadyQ);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-10-18 15:29:31 +03:00
|
|
|
|
while(rxPktInfo != nullptr) {
|
|
|
|
|
|
//if (!passive_mode_) {
|
|
|
|
|
|
for (int j = 0 ; j < rxPktInfo->sgList.numScatterSegments; ++j)
|
|
|
|
|
|
{
|
|
|
|
|
|
eth_stack_.rx_handler(rxPktInfo->sgList.list[j].bufPtr, rxPktInfo->sgList.list[j].segmentFilledLen);
|
|
|
|
|
|
}
|
|
|
|
|
|
//}
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-10-27 13:20:33 +03:00
|
|
|
|
EnetQueue_enq(&rxFreeQ, &rxPktInfo->node);
|
2023-10-18 15:29:31 +03:00
|
|
|
|
|
|
|
|
|
|
rxPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&rxReadyQ);
|
|
|
|
|
|
}
|
2023-10-27 13:20:33 +03:00
|
|
|
|
|
|
|
|
|
|
EnetAppUtils_validatePacketState(&rxFreeQ,
|
|
|
|
|
|
ENET_PKTSTATE_APP_WITH_DRIVER,
|
|
|
|
|
|
ENET_PKTSTATE_APP_WITH_FREEQ);
|
|
|
|
|
|
|
|
|
|
|
|
EnetQueue_append(&rx_free_pktq_, &rxFreeQ);
|
2023-10-18 15:29:31 +03:00
|
|
|
|
} while(readyQCount > 0);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-22 10:59:11 +03:00
|
|
|
|
bool free_rtos::EthRxFlow::open(uint32_t id, int32_t enetDmaRxChId, UBaseType_t task_priority, UBaseType_t task_stack_size)
|
2023-05-03 14:01:32 +03:00
|
|
|
|
{
|
|
|
|
|
|
EnetApp_GetDmaHandleInArgs rxInArgs;
|
|
|
|
|
|
EnetApp_GetRxDmaHandleOutArgs rxChInfo;
|
|
|
|
|
|
|
2024-01-19 14:57:14 +03:00
|
|
|
|
constexpr uint32_t numPkts[2] = {ENET_DMA_RX_CH0_NUM_PKTS, ENET_DMA_RX_CH1_NUM_PKTS};
|
|
|
|
|
|
|
2023-05-03 14:01:32 +03:00
|
|
|
|
EnetAppUtils_print("rx_flow %u: opening flow...\r\n", id);
|
|
|
|
|
|
|
|
|
|
|
|
if (open_) {
|
|
|
|
|
|
EnetAppUtils_print("rx_flow %u: rx flow is already open. Do nothing.\r\n", id_);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-22 10:59:11 +03:00
|
|
|
|
if (!rx_task.Create("rx_task", task_priority, rxTaskHandler, this, task_stack_size))
|
2023-05-03 14:01:32 +03:00
|
|
|
|
{
|
|
|
|
|
|
EnetAppUtils_print("rx_flow %u: failed to create rx task.\r\n", id_);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
id_ = id;
|
2023-11-01 11:48:36 +03:00
|
|
|
|
enetDmaRxChId_ = enetDmaRxChId;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
rxInArgs.notifyCb = rxIsrHandler; /// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
rxInArgs.cbArg = this; /// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
EnetApp_getRxDmaHandle(enetDmaRxChId, &rxInArgs, &rxChInfo);
|
|
|
|
|
|
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
rx_start_flow_idx_ = rxChInfo.rxFlowStartIdx;
|
|
|
|
|
|
rx_flow_idx_ = rxChInfo.rxFlowIdx;
|
|
|
|
|
|
dma_handle_ = rxChInfo.hRxCh;
|
|
|
|
|
|
|
|
|
|
|
|
if (rxChInfo.macAddressValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
EnetUtils_copyMacAddr(mac_addr_.bytes, rxChInfo.macAddr);
|
|
|
|
|
|
mac_addr_.addr&= ETH_FRAME_MAC_ADDR_MASK;
|
|
|
|
|
|
|
|
|
|
|
|
eth_stack_.set_mac_address(mac_addr_.addr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
EnetAppUtils_assert(rxChInfo.useGlobalEvt == true);
|
|
|
|
|
|
EnetAppUtils_assert(rxChInfo.sizeThreshEn == 0U);
|
2024-01-19 14:57:14 +03:00
|
|
|
|
EnetAppUtils_assert(rxChInfo.maxNumRxPkts >= numPkts[enetDmaRxChId]);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
EnetAppUtils_assert(rxChInfo.chIdx == id_);
|
|
|
|
|
|
EnetAppUtils_assert(rxChInfo.useDefaultFlow == true);
|
|
|
|
|
|
|
|
|
|
|
|
if (dma_handle_ == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
EnetAppUtils_print("rx_flow %u: failed to open rx dma flow\r\n", id_);
|
|
|
|
|
|
EnetAppUtils_assert(dma_handle_ != nullptr);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-01-19 14:57:14 +03:00
|
|
|
|
initRxFreePktQ(this, &rx_free_pktq_, numPkts[enetDmaRxChId]);
|
|
|
|
|
|
submitFreeRxPkts(numPkts[enetDmaRxChId]/2);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
open_ = true;
|
|
|
|
|
|
|
|
|
|
|
|
EnetAppUtils_print("rx_flow %u: rx flow open successfully\r\n", id);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|