From 692be72ffcc48c293b3a3f63ac9d63d5b362d611 Mon Sep 17 00:00:00 2001 From: algin Date: Fri, 22 Sep 2023 10:59:11 +0300 Subject: [PATCH] =?UTF-8?q?fix(UML-1780):=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=83=D0=BF=D1=80=D0=B5=D0=B6=D0=B4?= =?UTF-8?q?=D0=B0=D1=8E=D1=89=D0=B0=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B7?= =?UTF-8?q?=D0=B0=D1=80=D1=8F=D0=B4=D0=BA=D0=B0=20DMA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/free_rtos/ethernet/eth.cpp | 4 +- components/free_rtos/ethernet/eth.hpp | 4 + components/free_rtos/ethernet/eth_rx_flow.cpp | 77 ++++++++++--------- components/free_rtos/ethernet/eth_rx_flow.hpp | 8 +- .../free_rtos/ethernet/eth_task_settings.hpp | 5 +- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/components/free_rtos/ethernet/eth.cpp b/components/free_rtos/ethernet/eth.cpp index a73b66b..aaa7720 100644 --- a/components/free_rtos/ethernet/eth.cpp +++ b/components/free_rtos/ethernet/eth.cpp @@ -67,6 +67,8 @@ bool free_rtos::Eth::Init(Settings& sett) for (int i = 0; i < macPortNum_; ++i) { linkUp_[i] = false; macPort_[i] = sett.macPort[i]; + rxTaskPriority_[i] = sett.rxTaskPriority[i]; + rxTaskStackSize_[i] = sett.rxTaskStackSize[i]; } core_id_ = EnetSoc_getCoreId(); @@ -223,7 +225,7 @@ void free_rtos::Eth::link_task() continue; } - if (!rx_flow_[i].open(i, ENET_DMA_RX_CH0 + i)) + if (!rx_flow_[i].open(i, ENET_DMA_RX_CH0 + i, rxTaskPriority_[i], rxTaskStackSize_[i])) { EnetAppUtils_print("link_task: %s: Failed to open rx flow: %u\n", name_.c_str(), i); continue; diff --git a/components/free_rtos/ethernet/eth.hpp b/components/free_rtos/ethernet/eth.hpp index 092d2bd..644f972 100644 --- a/components/free_rtos/ethernet/eth.hpp +++ b/components/free_rtos/ethernet/eth.hpp @@ -47,6 +47,8 @@ public: /* Peripheral's MAC ports to use */ Enet_MacPort macPort[e_ethMacTotal]; + UBaseType_t rxTaskPriority[e_ethMacTotal]; + UBaseType_t rxTaskStackSize[e_ethMacTotal]; /* Number of MAC ports in macPorts array */ uint32_t macPortNum; @@ -106,6 +108,8 @@ private: /// �������������� mac ������ Enet_MacPort macPort_[e_ethMacTotal]; + UBaseType_t rxTaskPriority_[e_ethMacTotal]; + UBaseType_t rxTaskStackSize_[e_ethMacTotal]; /// ���������� MAC ������ uint32_t macPortNum_; diff --git a/components/free_rtos/ethernet/eth_rx_flow.cpp b/components/free_rtos/ethernet/eth_rx_flow.cpp index 2716ffc..47a7d21 100644 --- a/components/free_rtos/ethernet/eth_rx_flow.cpp +++ b/components/free_rtos/ethernet/eth_rx_flow.cpp @@ -7,7 +7,6 @@ #include "free_rtos/ethernet/eth_rx_flow.hpp" #include -#include #include #include #include @@ -42,17 +41,22 @@ void free_rtos::rxTaskHandler(void *appData) } } -static void eth_initRxReadyPktQ(EnetDma_RxChHandle hRxCh, void * appPriv) +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_); +} + +void free_rtos::EthRxFlow::initRxFreePktQ(uint32_t qCount, void * appPriv) { EnetDma_PktQ rxReadyQ; - EnetDma_PktQ rxFreeQ; EnetDma_Pkt *pPktInfo; uint32_t i; int32_t status; - EnetQueue_initQ(&rxFreeQ); - - for (i = 0U; i < (ENET_SYSCFG_TOTAL_NUM_RX_PKT/2); ++i) + for (i = 0U; i < qCount; ++i) { pPktInfo = EnetMem_allocEthPkt(appPriv, ENET_MEM_LARGE_POOL_PKT_SIZE, @@ -61,40 +65,47 @@ static void eth_initRxReadyPktQ(EnetDma_RxChHandle hRxCh, void * appPriv) ENET_UTILS_SET_PKT_APP_STATE(&pPktInfo->pktState, ENET_PKTSTATE_APP_WITH_FREEQ); - EnetQueue_enq(&rxFreeQ, &pPktInfo->node); + EnetQueue_enq(&rx_free_pktq_, &pPktInfo->node); } /* Retrieve any packets which are ready */ EnetQueue_initQ(&rxReadyQ); - status = EnetDma_retrieveRxPktQ(hRxCh, &rxReadyQ); + status = EnetDma_retrieveRxPktQ(dma_handle_, &rxReadyQ); EnetAppUtils_assert(status == ENET_SOK); /* There should not be any packet with DMA during init */ EnetAppUtils_assert(EnetQueue_getQCount(&rxReadyQ) == 0U); +} - EnetAppUtils_validatePacketState(&rxFreeQ, +void free_rtos::EthRxFlow::reloadDmaRxPktQ(uint32_t qCount) +{ + EnetDma_PktQ rxSubmitQ; + EnetDma_Pkt* rxPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&rx_free_pktq_); + + EnetQueue_initQ(&rxSubmitQ); + + while((rxPktInfo != nullptr) && (qCount > 0)) + { + EnetQueue_enq(&rxSubmitQ, &rxPktInfo->node); + + rxPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&rx_free_pktq_); + qCount--; + } + + EnetAppUtils_validatePacketState(&rxSubmitQ, ENET_PKTSTATE_APP_WITH_FREEQ, ENET_PKTSTATE_APP_WITH_DRIVER); - EnetDma_submitRxPktQ(hRxCh, &rxFreeQ); + EnetDma_submitRxPktQ(dma_handle_, &rxSubmitQ); /* Assert here, as during init, the number of DMA descriptors should be equal to * the number of free Ethernet buffers available with app */ - EnetAppUtils_assert(EnetQueue_getQCount(&rxFreeQ) == 0U); -} - -free_rtos::EthRxFlow::EthRxFlow(TEthFrameMacAddr& mac_addr, EthStackIface& eth_stack) : - mac_addr_{mac_addr}, - eth_stack_{eth_stack}, - passive_mode_{false} -{ - + EnetAppUtils_assert(EnetQueue_getQCount(&rxSubmitQ) == 0U); } void free_rtos::EthRxFlow::rxProcessPktTask() { EnetDma_PktQ rxReadyQ; /// ������� ������� ������� (������ � �������) - EnetDma_PktQ rxFreeQ; /// ������� ��������� ������� EnetDma_Pkt* rxPktInfo; /// ����� � ������� int32_t status; @@ -105,13 +116,14 @@ void free_rtos::EthRxFlow::rxProcessPktTask() /// �������������� ������� (�������� ���� ��������) EnetQueue_initQ(&rxReadyQ); - EnetQueue_initQ(&rxFreeQ); /// ��������� ������� � � �������� � rxReadyQ status = EnetDma_retrieveRxPktQ(dma_handle_, &rxReadyQ); EnetAppUtils_assert(status == ENET_SOK); - // ��������� ����� �� ������� + // Reload DMA with a new rx free queue as fast as possible + reloadDmaRxPktQ(EnetQueue_getQCount(&rxReadyQ)); + rxPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&rxReadyQ); while(rxPktInfo != nullptr) @@ -133,7 +145,7 @@ void free_rtos::EthRxFlow::rxProcessPktTask() ENET_PKTSTATE_APP_WITH_FREEQ); /// ������ ����� � ������� ��������� ������� - EnetQueue_enq(&rxFreeQ, &rxPktInfo->node); + EnetQueue_enq(&rx_free_pktq_, &rxPktInfo->node); /// ��������� ��������� ���� �� ������� rxPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&rxReadyQ); @@ -141,22 +153,10 @@ void free_rtos::EthRxFlow::rxProcessPktTask() /// ����������� ������� �������� ������� ++rx_pkt_counter_; } - - /** - * ��������� ��������� ���� ������� � �������(������ ���� ENET_PKTSTATE_APP_WITH_FREEQ) - * � �������� ��� �� ENET_PKTSTATE_APP_WITH_DRIVER. �������� ����� �� ������ ��� ���� - * ���� ������� ����� ������� EnetDma_checkPktState. - */ - EnetAppUtils_validatePacketState(&rxFreeQ, - ENET_PKTSTATE_APP_WITH_FREEQ, - ENET_PKTSTATE_APP_WITH_DRIVER); - - /// ���������� ������� � ������� - EnetDma_submitRxPktQ(dma_handle_, &rxFreeQ); } } -bool free_rtos::EthRxFlow::open(uint32_t id, int32_t enetDmaRxChId) +bool free_rtos::EthRxFlow::open(uint32_t id, int32_t enetDmaRxChId, UBaseType_t task_priority, UBaseType_t task_stack_size) { EnetApp_GetDmaHandleInArgs rxInArgs; EnetApp_GetRxDmaHandleOutArgs rxChInfo; @@ -170,7 +170,7 @@ bool free_rtos::EthRxFlow::open(uint32_t id, int32_t enetDmaRxChId) return true; } - if (!rx_task.Create("rx_task", RX_TASK_PRIORITY, rxTaskHandler, this, RX_TASK_STACK_SIZE)) + if (!rx_task.Create("rx_task", task_priority, rxTaskHandler, this, task_stack_size)) { EnetAppUtils_print("rx_flow %u: failed to create rx task.\r\n", id_); return false; @@ -212,7 +212,8 @@ bool free_rtos::EthRxFlow::open(uint32_t id, int32_t enetDmaRxChId) } /// ������������� ������� ������� - eth_initRxReadyPktQ(dma_handle_, this); + initRxFreePktQ(ENET_SYSCFG_TOTAL_NUM_RX_PKT/2, this); + reloadDmaRxPktQ(ENET_SYSCFG_TOTAL_NUM_RX_PKT/4); open_ = true; diff --git a/components/free_rtos/ethernet/eth_rx_flow.hpp b/components/free_rtos/ethernet/eth_rx_flow.hpp index e3095f5..6663a55 100644 --- a/components/free_rtos/ethernet/eth_rx_flow.hpp +++ b/components/free_rtos/ethernet/eth_rx_flow.hpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include "free_rtos/handler_store/handler_store.hpp" #include "free_rtos/semaphore/semaphore.hpp" @@ -25,7 +27,7 @@ class EthRxFlow { public: EthRxFlow(TEthFrameMacAddr& mac_addr, EthStackIface& eth_stack); - bool open(uint32_t id, int32_t enetDmaRxChId); + bool open(uint32_t id, int32_t enetDmaRxChId, UBaseType_t task_priority, UBaseType_t task_stack_size); bool is_open() {return open_;} @@ -37,6 +39,9 @@ private: friend void rxTaskHandler(void *appData); ///������ ��������� �������� ������� + void initRxFreePktQ(uint32_t qCount, void * appPriv); + void reloadDmaRxPktQ(uint32_t qCount); + void rxProcessPktTask(); ///������� ��������� �������� ������� private: @@ -62,6 +67,7 @@ private: uint32_t rx_start_flow_idx_; uint32_t rx_flow_idx_; EnetDma_RxChHandle dma_handle_; + EnetDma_PktQ rx_free_pktq_; bool passive_mode_; /// ��������� �����, ������ �����������, �� �� ���������� � ���� ��������� }; diff --git a/components/free_rtos/ethernet/eth_task_settings.hpp b/components/free_rtos/ethernet/eth_task_settings.hpp index eb6fe7a..6a9b0b2 100644 --- a/components/free_rtos/ethernet/eth_task_settings.hpp +++ b/components/free_rtos/ethernet/eth_task_settings.hpp @@ -13,10 +13,7 @@ #include "free_rtos/task/task.hpp" namespace free_rtos { - static constexpr uint32_t RX_TASK_PRIORITY = Task::TaskPriorityHiest - 2; - static constexpr uint32_t RX_TASK_STACK_SIZE = (10U * 1024U); - - static constexpr uint32_t LINK_TASK_PRIORITY = 2; + static constexpr uint32_t LINK_TASK_PRIORITY = tskIDLE_PRIORITY + 2; static constexpr uint32_t LINK_TASK_STACK_SIZE = (10U * 1024U); }