From 80a5f298927169b92a378eb9efae2e4fe24eab7e Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 22 Sep 2022 14:55:22 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15800 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/hal/ports/STM32/LLD/MACv1/hal_mac_lld.h | 2 +- os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.c | 39 +++---- os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.h | 126 ++++++--------------- 3 files changed, 49 insertions(+), 118 deletions(-) diff --git a/os/hal/ports/STM32/LLD/MACv1/hal_mac_lld.h b/os/hal/ports/STM32/LLD/MACv1/hal_mac_lld.h index 6748cb60b..1fb1365bb 100644 --- a/os/hal/ports/STM32/LLD/MACv1/hal_mac_lld.h +++ b/os/hal/ports/STM32/LLD/MACv1/hal_mac_lld.h @@ -225,7 +225,7 @@ typedef struct { /* Link status flag.*/ \ bool link_up; \ /* PHY address (pre shifted).*/ \ - uint32_t phyaddr; \ + uint32_t phyaddr; \ /* Receive next frame pointer.*/ \ stm32_eth_rx_descriptor_t *rxptr; \ /* Transmit next frame pointer.*/ \ diff --git a/os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.c b/os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.c index 2ebe30ccc..f52868db2 100644 --- a/os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.c +++ b/os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.c @@ -237,35 +237,28 @@ static void mac_lld_set_address(const uint8_t *p) { /*===========================================================================*/ OSAL_IRQ_HANDLER(STM32_ETH_HANDLER) { - uint32_t dmasr; + MACDriver *macp = ÐD1; + uint32_t dmacsr; OSAL_IRQ_PROLOGUE(); - dmasr = ETH->DMACSR; + dmacsr = ETH->DMACSR; + ETH->DMACSR = dmacsr; /* Clear status bits.*/ - if (dmasr & ETH_DMACSR_RI) { - /* Data Received.*/ - ETH->DMACSR = ETH_DMACSR_RI; - ETH->DMACIER &= ~ETH_DMACIER_RIE; - osalSysLockFromISR(); - osalThreadDequeueAllI(ÐD1.rdqueue, MSG_RESET); -#if MAC_USE_EVENTS - osalEventBroadcastFlagsI(ÐD1.rdevent, 0); -#endif - osalSysUnlockFromISR(); + if ((dmacsr & (ETH_DMACSR_RI | ETH_DMACSR_TI)) != 0U) { + if ((dmacsr & ETH_DMACSR_TI) != 0U) { + /* Data Transmitted.*/ + __mac_tx_wakeup(macp); + } + + if ((dmacsr & ETH_DMACSR_RI) != 0U) { + /* Data Received.*/ + __mac_rx_wakeup(macp); + } + + __mac_callback(macp); } - if (dmasr & ETH_DMACSR_TI) { - /* Data Transmitted.*/ - ETH->DMACSR = ETH_DMACSR_TI; - osalSysLockFromISR(); - osalThreadDequeueAllI(ÐD1.tdqueue, MSG_RESET); - osalSysUnlockFromISR(); - } - - ETH->DMACSR |= ETH_DMACSR_NIS; - ETH->DMACIER = ETH_DMACIER_NIE | ETH_DMACIER_RIE | ETH_DMACIER_TIE; - OSAL_IRQ_EPILOGUE(); } diff --git a/os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.h b/os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.h index d756205d2..a88706fc9 100644 --- a/os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.h +++ b/os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.h @@ -230,104 +230,42 @@ typedef struct { volatile uint32_t tdes3; } stm32_eth_tx_descriptor_t; -/** - * @brief Driver configuration structure. - */ -typedef struct { - /** - * @brief MAC address. - */ - uint8_t *mac_address; - /* End of the mandatory fields.*/ -} MACConfig; - -/** - * @brief Structure representing a MAC driver. - */ -struct MACDriver { - /** - * @brief Driver state. - */ - macstate_t state; - /** - * @brief Current configuration data. - */ - const MACConfig *config; - /** - * @brief Transmit semaphore. - */ - threads_queue_t tdqueue; - /** - * @brief Receive semaphore. - */ - threads_queue_t rdqueue; -#if MAC_USE_EVENTS || defined(__DOXYGEN__) - /** - * @brief Receive event. - */ - event_source_t rdevent; -#endif - /* End of the mandatory fields.*/ - /** - * @brief Link status flag. - */ - bool link_up; - /** - * @brief PHY address (pre shifted). - */ - uint32_t phyaddr; - /** - * @brief Receive next frame index. - */ - uint16_t rdindex; - /** - * @brief Transmit next frame index. - */ - uint16_t tdindex; -}; - -/** - * @brief Structure representing a transmit descriptor. - */ -typedef struct { - /** - * @brief Current write offset. - */ - size_t offset; - /** - * @brief Available space size. - */ - size_t size; - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the physical descriptor. - */ - stm32_eth_tx_descriptor_t *physdesc; -} MACTransmitDescriptor; - -/** - * @brief Structure representing a receive descriptor. - */ -typedef struct { - /** - * @brief Current read offset. - */ - size_t offset; - /** - * @brief Available data size. - */ - size_t size; - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the physical descriptor. - */ - stm32_eth_rx_descriptor_t *physdesc; -} MACReceiveDescriptor; - /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ +/** + * @brief Low level fields of the MAC driver structure. + */ +#define mac_lld_driver_fields \ + /* Link status flag.*/ \ + bool link_up; \ + /* PHY address (pre shifted).*/ \ + uint32_t phyaddr; \ + /* Receive next frame index.*/ \ + uint32_t rdindex; \ + /* Transmit next frame index.*/ \ + uint32_t tdindex + +/** + * @brief Low level fields of the MAC configuration structure. + */ +#define mac_lld_config_fields + +/** + * @brief Low level fields of the MAC transmit descriptor structure. + */ +#define mac_lld_transmit_descriptor_fields \ + /* Pointer to the physical descriptor.*/ \ + stm32_eth_tx_descriptor_t *physdesc + +/** + * @brief Low level fields of the MAC receive descriptor structure. + */ +#define mac_lld_receive_descriptor_fields \ + /* Pointer to the physical descriptor.*/ \ + stm32_eth_rx_descriptor_t *physdesc + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/