You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

560 lines
23 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_eth_ex.c
  4. * @author MCD Application Team
  5. * @brief ETH HAL Extended module driver.
  6. *
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32h7xx_hal.h"
  22. /** @addtogroup STM32H7xx_HAL_Driver
  23. * @{
  24. */
  25. #ifdef HAL_ETH_MODULE_ENABLED
  26. #if defined(ETH)
  27. /** @defgroup ETHEx ETHEx
  28. * @brief ETH HAL Extended module driver
  29. * @{
  30. */
  31. /* Private typedef -----------------------------------------------------------*/
  32. /* Private define ------------------------------------------------------------*/
  33. /** @defgroup ETHEx_Private_Constants ETHEx Private Constants
  34. * @{
  35. */
  36. #define ETH_MACL4CR_MASK (ETH_MACL3L4CR_L4PEN | ETH_MACL3L4CR_L4SPM | \
  37. ETH_MACL3L4CR_L4SPIM | ETH_MACL3L4CR_L4DPM | \
  38. ETH_MACL3L4CR_L4DPIM)
  39. #define ETH_MACL3CR_MASK (ETH_MACL3L4CR_L3PEN | ETH_MACL3L4CR_L3SAM | \
  40. ETH_MACL3L4CR_L3SAIM | ETH_MACL3L4CR_L3DAM | \
  41. ETH_MACL3L4CR_L3DAIM | ETH_MACL3L4CR_L3HSBM | \
  42. ETH_MACL3L4CR_L3HDBM)
  43. #define ETH_MACRXVLAN_MASK (ETH_MACVTR_EIVLRXS | ETH_MACVTR_EIVLS | \
  44. ETH_MACVTR_ERIVLT | ETH_MACVTR_EDVLP | \
  45. ETH_MACVTR_VTHM | ETH_MACVTR_EVLRXS | \
  46. ETH_MACVTR_EVLS | ETH_MACVTR_DOVLTC | \
  47. ETH_MACVTR_ERSVLM | ETH_MACVTR_ESVL | \
  48. ETH_MACVTR_VTIM | ETH_MACVTR_ETV)
  49. #define ETH_MACTXVLAN_MASK (ETH_MACVIR_VLTI | ETH_MACVIR_CSVL | \
  50. ETH_MACVIR_VLP | ETH_MACVIR_VLC)
  51. /**
  52. * @}
  53. */
  54. /* Private macros ------------------------------------------------------------*/
  55. /* Private function prototypes -----------------------------------------------*/
  56. /* Exported functions ---------------------------------------------------------*/
  57. /** @defgroup ETHEx_Exported_Functions ETH Extended Exported Functions
  58. * @{
  59. */
  60. /** @defgroup ETHEx_Exported_Functions_Group1 Extended features functions
  61. * @brief Extended features functions
  62. *
  63. @verbatim
  64. ===============================================================================
  65. ##### Extended features functions #####
  66. ===============================================================================
  67. [..] This section provides functions allowing to:
  68. (+) Configure ARP offload module
  69. (+) Configure L3 and L4 filters
  70. (+) Configure Extended VLAN features
  71. (+) Configure Energy Efficient Ethernet module
  72. @endverbatim
  73. * @{
  74. */
  75. /**
  76. * @brief Enables ARP Offload.
  77. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  78. * the configuration information for ETHERNET module
  79. * @retval None
  80. */
  81. void HAL_ETHEx_EnableARPOffload(ETH_HandleTypeDef *heth)
  82. {
  83. SET_BIT(heth->Instance->MACCR, ETH_MACCR_ARP);
  84. }
  85. /**
  86. * @brief Disables ARP Offload.
  87. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  88. * the configuration information for ETHERNET module
  89. * @retval None
  90. */
  91. void HAL_ETHEx_DisableARPOffload(ETH_HandleTypeDef *heth)
  92. {
  93. CLEAR_BIT(heth->Instance->MACCR, ETH_MACCR_ARP);
  94. }
  95. /**
  96. * @brief Set the ARP Match IP address
  97. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  98. * the configuration information for ETHERNET module
  99. * @param IpAddress: IP Address to be matched for incoming ARP requests
  100. * @retval None
  101. */
  102. void HAL_ETHEx_SetARPAddressMatch(ETH_HandleTypeDef *heth, uint32_t IpAddress)
  103. {
  104. WRITE_REG(heth->Instance->MACARPAR, IpAddress);
  105. }
  106. /**
  107. * @brief Configures the L4 Filter, this function allow to:
  108. * set the layer 4 protocol to be matched (TCP or UDP)
  109. * enable/disable L4 source/destination port perfect/inverse match.
  110. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  111. * the configuration information for ETHERNET module
  112. * @param Filter: L4 filter to configured, this parameter must be one of the following
  113. * ETH_L4_FILTER_0
  114. * ETH_L4_FILTER_1
  115. * @param pL4FilterConfig: pointer to a ETH_L4FilterConfigTypeDef structure
  116. * that contains L4 filter configuration.
  117. * @retval HAL status
  118. */
  119. HAL_StatusTypeDef HAL_ETHEx_SetL4FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter , ETH_L4FilterConfigTypeDef *pL4FilterConfig)
  120. {
  121. __IO uint32_t *configreg = ((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter));
  122. if(pL4FilterConfig == NULL)
  123. {
  124. return HAL_ERROR;
  125. }
  126. /* Write configuration to (MACL3L4C0R + filter )register */
  127. MODIFY_REG(*configreg, ETH_MACL4CR_MASK ,(pL4FilterConfig->Protocol |
  128. pL4FilterConfig->SrcPortFilterMatch |
  129. pL4FilterConfig->DestPortFilterMatch));
  130. configreg = ((__IO uint32_t *)(&(heth->Instance->MACL4A0R) + Filter));
  131. /* Write configuration to (MACL4A0R + filter )register */
  132. MODIFY_REG(*configreg, (ETH_MACL4AR_L4DP | ETH_MACL4AR_L4SP) , (pL4FilterConfig->SourcePort |
  133. (pL4FilterConfig->DestinationPort << 16)));
  134. /* Enable L4 filter */
  135. SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
  136. return HAL_OK;
  137. }
  138. /**
  139. * @brief Configures the L4 Filter, this function allow to:
  140. * set the layer 4 protocol to be matched (TCP or UDP)
  141. * enable/disable L4 source/destination port perfect/inverse match.
  142. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  143. * the configuration information for ETHERNET module
  144. * @param Filter: L4 filter to configured, this parameter must be one of the following
  145. * ETH_L4_FILTER_0
  146. * ETH_L4_FILTER_1
  147. * @param pL4FilterConfig: pointer to a ETH_L4FilterConfigTypeDef structure
  148. * that contains L4 filter configuration.
  149. * @retval HAL status
  150. */
  151. HAL_StatusTypeDef HAL_ETHEx_GetL4FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter, ETH_L4FilterConfigTypeDef *pL4FilterConfig)
  152. {
  153. if(pL4FilterConfig == NULL)
  154. {
  155. return HAL_ERROR;
  156. }
  157. /* Get configuration to (MACL3L4C0R + filter )register */
  158. pL4FilterConfig->Protocol = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), ETH_MACL3L4CR_L4PEN);
  159. pL4FilterConfig->DestPortFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), (ETH_MACL3L4CR_L4DPM | ETH_MACL3L4CR_L4DPIM));
  160. pL4FilterConfig->SrcPortFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), (ETH_MACL3L4CR_L4SPM | ETH_MACL3L4CR_L4SPIM));
  161. /* Get configuration to (MACL3L4C0R + filter )register */
  162. pL4FilterConfig->DestinationPort = (READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL4A0R) + Filter)), ETH_MACL4AR_L4DP) >> 16);
  163. pL4FilterConfig->SourcePort = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL4A0R) + Filter)), ETH_MACL4AR_L4SP);
  164. return HAL_OK;
  165. }
  166. /**
  167. * @brief Configures the L3 Filter, this function allow to:
  168. * set the layer 3 protocol to be matched (IPv4 or IPv6)
  169. * enable/disable L3 source/destination port perfect/inverse match.
  170. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  171. * the configuration information for ETHERNET module
  172. * @param Filter: L3 filter to configured, this parameter must be one of the following
  173. * ETH_L3_FILTER_0
  174. * ETH_L3_FILTER_1
  175. * @param pL3FilterConfig: pointer to a ETH_L3FilterConfigTypeDef structure
  176. * that contains L3 filter configuration.
  177. * @retval HAL status
  178. */
  179. HAL_StatusTypeDef HAL_ETHEx_SetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter, ETH_L3FilterConfigTypeDef *pL3FilterConfig)
  180. {
  181. __IO uint32_t *configreg = ((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter));
  182. if(pL3FilterConfig == NULL)
  183. {
  184. return HAL_ERROR;
  185. }
  186. /* Write configuration to (MACL3L4C0R + filter )register */
  187. MODIFY_REG(*configreg, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
  188. pL3FilterConfig->SrcAddrFilterMatch |
  189. pL3FilterConfig->DestAddrFilterMatch |
  190. (pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
  191. (pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
  192. /* Check if IPv6 protocol is selected */
  193. if(pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
  194. {
  195. /* Set the IPv6 address match */
  196. /* Set Bits[31:0] of 128-bit IP addr */
  197. *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter)) = pL3FilterConfig->Ip6Addr[0];
  198. /* Set Bits[63:32] of 128-bit IP addr */
  199. *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter)) = pL3FilterConfig->Ip6Addr[1];
  200. /* update Bits[95:64] of 128-bit IP addr */
  201. *((__IO uint32_t *)(&(heth->Instance->MACL3A2R0R) + Filter)) = pL3FilterConfig->Ip6Addr[2];
  202. /* update Bits[127:96] of 128-bit IP addr */
  203. *((__IO uint32_t *)(&(heth->Instance->MACL3A3R0R) + Filter)) = pL3FilterConfig->Ip6Addr[3];
  204. }
  205. else /* IPv4 protocol is selected */
  206. {
  207. /* Set the IPv4 source address match */
  208. *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter)) = pL3FilterConfig->Ip4SrcAddr;
  209. /* Set the IPv4 destination address match */
  210. *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter)) = pL3FilterConfig->Ip4DestAddr;
  211. }
  212. return HAL_OK;
  213. }
  214. /**
  215. * @brief Configures the L3 Filter, this function allow to:
  216. * set the layer 3 protocol to be matched (IPv4 or IPv6)
  217. * enable/disable L3 source/destination port perfect/inverse match.
  218. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  219. * the configuration information for ETHERNET module
  220. * @param Filter: L3 filter to configured, this parameter must be one of the following
  221. * ETH_L3_FILTER_0
  222. * ETH_L3_FILTER_1
  223. * @param pL3FilterConfig: pointer to a ETH_L3FilterConfigTypeDef structure
  224. * that will contain the L3 filter configuration.
  225. * @retval HAL status
  226. */
  227. HAL_StatusTypeDef HAL_ETHEx_GetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter, ETH_L3FilterConfigTypeDef *pL3FilterConfig)
  228. {
  229. if(pL3FilterConfig == NULL)
  230. {
  231. return HAL_ERROR;
  232. }
  233. pL3FilterConfig->Protocol = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), ETH_MACL3L4CR_L3PEN);
  234. pL3FilterConfig->SrcAddrFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), (ETH_MACL3L4CR_L3SAM | ETH_MACL3L4CR_L3SAIM));
  235. pL3FilterConfig->DestAddrFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), (ETH_MACL3L4CR_L3DAM | ETH_MACL3L4CR_L3DAIM));
  236. pL3FilterConfig->SrcAddrHigherBitsMatch = (READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), ETH_MACL3L4CR_L3HSBM) >> 6);
  237. pL3FilterConfig->DestAddrHigherBitsMatch = (READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), ETH_MACL3L4CR_L3HDBM) >> 11);
  238. if(pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
  239. {
  240. pL3FilterConfig->Ip6Addr[0] = *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter));
  241. pL3FilterConfig->Ip6Addr[1] = *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter));
  242. pL3FilterConfig->Ip6Addr[2] = *((__IO uint32_t *)(&(heth->Instance->MACL3A2R0R) + Filter));
  243. pL3FilterConfig->Ip6Addr[3] = *((__IO uint32_t *)(&(heth->Instance->MACL3A3R0R) + Filter));
  244. }
  245. else
  246. {
  247. pL3FilterConfig->Ip4SrcAddr = *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter));
  248. pL3FilterConfig->Ip4DestAddr = *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter));
  249. }
  250. return HAL_OK;
  251. }
  252. /**
  253. * @brief Enables L3 and L4 filtering process.
  254. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  255. * the configuration information for ETHERNET module
  256. * @retval None.
  257. */
  258. void HAL_ETHEx_EnableL3L4Filtering(ETH_HandleTypeDef *heth)
  259. {
  260. /* Enable L3/L4 filter */
  261. SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
  262. }
  263. /**
  264. * @brief Disables L3 and L4 filtering process.
  265. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  266. * the configuration information for ETHERNET module
  267. * @retval None.
  268. */
  269. void HAL_ETHEx_DisableL3L4Filtering(ETH_HandleTypeDef *heth)
  270. {
  271. /* Disable L3/L4 filter */
  272. CLEAR_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
  273. }
  274. /**
  275. * @brief Get the VLAN Configuration for Receive Packets.
  276. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  277. * the configuration information for ETHERNET module
  278. * @param pVlanConfig: pointer to a ETH_RxVLANConfigTypeDef structure
  279. * that will contain the VLAN filter configuration.
  280. * @retval HAL status
  281. */
  282. HAL_StatusTypeDef HAL_ETHEx_GetRxVLANConfig(ETH_HandleTypeDef *heth, ETH_RxVLANConfigTypeDef *pVlanConfig)
  283. {
  284. if(pVlanConfig == NULL)
  285. {
  286. return HAL_ERROR;
  287. }
  288. pVlanConfig->InnerVLANTagInStatus = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EIVLRXS) >> 31) == 0U) ? DISABLE : ENABLE;
  289. pVlanConfig->StripInnerVLANTag = READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EIVLS);
  290. pVlanConfig->InnerVLANTag = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_ERIVLT) >> 27) == 0U) ? DISABLE : ENABLE;
  291. pVlanConfig->DoubleVLANProcessing = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EDVLP) >> 26) == 0U) ? DISABLE : ENABLE;
  292. pVlanConfig->VLANTagHashTableMatch = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_VTHM) >> 25) == 0U) ? DISABLE : ENABLE;
  293. pVlanConfig->VLANTagInStatus = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EVLRXS) >> 24) == 0U) ? DISABLE : ENABLE;
  294. pVlanConfig->StripVLANTag = READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EVLS);
  295. pVlanConfig->VLANTypeCheck = READ_BIT(heth->Instance->MACVTR, (ETH_MACVTR_DOVLTC | ETH_MACVTR_ERSVLM | ETH_MACVTR_ESVL));
  296. pVlanConfig->VLANTagInverceMatch = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_VTIM) >> 17) == 0U) ? DISABLE : ENABLE;
  297. return HAL_OK;
  298. }
  299. /**
  300. * @brief Set the VLAN Configuration for Receive Packets.
  301. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  302. * the configuration information for ETHERNET module
  303. * @param pVlanConfig: pointer to a ETH_RxVLANConfigTypeDef structure
  304. * that contains VLAN filter configuration.
  305. * @retval HAL status
  306. */
  307. HAL_StatusTypeDef HAL_ETHEx_SetRxVLANConfig(ETH_HandleTypeDef *heth, ETH_RxVLANConfigTypeDef *pVlanConfig)
  308. {
  309. if(pVlanConfig == NULL)
  310. {
  311. return HAL_ERROR;
  312. }
  313. /* Write config to MACVTR */
  314. MODIFY_REG(heth->Instance->MACVTR, ETH_MACRXVLAN_MASK, (((uint32_t)pVlanConfig->InnerVLANTagInStatus << 31) |
  315. pVlanConfig->StripInnerVLANTag |
  316. ((uint32_t)pVlanConfig->InnerVLANTag << 27) |
  317. ((uint32_t)pVlanConfig->DoubleVLANProcessing << 26) |
  318. ((uint32_t)pVlanConfig->VLANTagHashTableMatch << 25) |
  319. ((uint32_t)pVlanConfig->VLANTagInStatus << 24) |
  320. pVlanConfig->StripVLANTag |
  321. pVlanConfig->VLANTypeCheck |
  322. ((uint32_t)pVlanConfig->VLANTagInverceMatch << 17)));
  323. return HAL_OK;
  324. }
  325. /**
  326. * @brief Set the VLAN Hash Table
  327. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  328. * the configuration information for ETHERNET module
  329. * @param VLANHashTable: VLAN hash table 16 bit value
  330. * @retval None
  331. */
  332. void HAL_ETHEx_SetVLANHashTable(ETH_HandleTypeDef *heth, uint32_t VLANHashTable)
  333. {
  334. MODIFY_REG(heth->Instance->MACVHTR, ETH_MACVHTR_VLHT, VLANHashTable);
  335. }
  336. /**
  337. * @brief Get the VLAN Configuration for Transmit Packets.
  338. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  339. * the configuration information for ETHERNET module
  340. * @param VLANTag: Selects the vlan tag, this parameter must be one of the following
  341. * ETH_OUTER_TX_VLANTAG
  342. * ETH_INNER_TX_VLANTAG
  343. * @param pVlanConfig: pointer to a ETH_TxVLANConfigTypeDef structure
  344. * that will contain the Tx VLAN filter configuration.
  345. * @retval HAL Status.
  346. */
  347. HAL_StatusTypeDef HAL_ETHEx_GetTxVLANConfig(ETH_HandleTypeDef *heth, uint32_t VLANTag ,ETH_TxVLANConfigTypeDef *pVlanConfig)
  348. {
  349. if (pVlanConfig == NULL)
  350. {
  351. return HAL_ERROR;
  352. }
  353. if(VLANTag == ETH_INNER_TX_VLANTAG)
  354. {
  355. pVlanConfig->SourceTxDesc = ((READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_VLTI) >> 20) == 0U) ? DISABLE : ENABLE;
  356. pVlanConfig->SVLANType = ((READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_CSVL) >> 19) == 0U) ? DISABLE : ENABLE;
  357. pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACIVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC));
  358. }
  359. else
  360. {
  361. pVlanConfig->SourceTxDesc = ((READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_VLTI) >> 20) == 0U) ? DISABLE : ENABLE;
  362. pVlanConfig->SVLANType = ((READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_CSVL) >> 19) == 0U) ? DISABLE : ENABLE;
  363. pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC));
  364. }
  365. return HAL_OK;;
  366. }
  367. /**
  368. * @brief Set the VLAN Configuration for Transmit Packets.
  369. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  370. * the configuration information for ETHERNET module
  371. * @param VLANTag: Selects the vlan tag, this parameter must be one of the following
  372. * ETH_OUTER_TX_VLANTAG
  373. * ETH_INNER_TX_VLANTAG
  374. * @param pVlanConfig: pointer to a ETH_TxVLANConfigTypeDef structure
  375. * that contains Tx VLAN filter configuration.
  376. * @retval HAL Status
  377. */
  378. HAL_StatusTypeDef HAL_ETHEx_SetTxVLANConfig(ETH_HandleTypeDef *heth, uint32_t VLANTag ,ETH_TxVLANConfigTypeDef *pVlanConfig)
  379. {
  380. if(VLANTag == ETH_INNER_TX_VLANTAG)
  381. {
  382. MODIFY_REG(heth->Instance->MACIVIR, ETH_MACTXVLAN_MASK, (((uint32_t)pVlanConfig->SourceTxDesc << 20) |
  383. ((uint32_t)pVlanConfig->SVLANType << 19) |
  384. pVlanConfig->VLANTagControl));
  385. /* Enable Double VLAN processing */
  386. SET_BIT(heth->Instance->MACVTR, ETH_MACVTR_EDVLP);
  387. }
  388. else
  389. {
  390. MODIFY_REG(heth->Instance->MACVIR, ETH_MACTXVLAN_MASK, (((uint32_t)pVlanConfig->SourceTxDesc << 20) |
  391. ((uint32_t)pVlanConfig->SVLANType << 19) |
  392. pVlanConfig->VLANTagControl));
  393. }
  394. return HAL_OK;
  395. }
  396. /**
  397. * @brief Set the VLAN Tag Identifier for Transmit Packets.
  398. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  399. * the configuration information for ETHERNET module
  400. * @param VLANTag: Selects the vlan tag, this parameter must be one of the following
  401. * ETH_OUTER_TX_VLANTAG
  402. * ETH_INNER_TX_VLANTAG
  403. * @param VLANIdentifier: VLAN Identifier 16 bit value
  404. * @retval None
  405. */
  406. void HAL_ETHEx_SetTxVLANIdentifier(ETH_HandleTypeDef *heth, uint32_t VLANTag ,uint32_t VLANIdentifier)
  407. {
  408. if(VLANTag == ETH_INNER_TX_VLANTAG)
  409. {
  410. MODIFY_REG(heth->Instance->MACIVIR, ETH_MACVIR_VLT, VLANIdentifier);
  411. }
  412. else
  413. {
  414. MODIFY_REG(heth->Instance->MACVIR, ETH_MACVIR_VLT, VLANIdentifier);
  415. }
  416. }
  417. /**
  418. * @brief Enables the VLAN Tag Filtering process.
  419. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  420. * the configuration information for ETHERNET module
  421. * @retval None.
  422. */
  423. void HAL_ETHEx_EnableVLANProcessing(ETH_HandleTypeDef *heth)
  424. {
  425. /* Enable VLAN processing */
  426. SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_VTFE);
  427. }
  428. /**
  429. * @brief Disables the VLAN Tag Filtering process.
  430. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  431. * the configuration information for ETHERNET module
  432. * @retval None.
  433. */
  434. void HAL_ETHEx_DisableVLANProcessing(ETH_HandleTypeDef *heth)
  435. {
  436. /* Disable VLAN processing */
  437. CLEAR_BIT(heth->Instance->MACPFR, ETH_MACPFR_VTFE);
  438. }
  439. /**
  440. * @brief Enters the Low Power Idle (LPI) mode
  441. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  442. * the configuration information for ETHERNET module
  443. * @param TxAutomate: Enable/Disbale automate enter/exit LPI mode.
  444. * @param TxClockStop: Enable/Disbale Tx clock stop in LPI mode.
  445. * @retval None
  446. */
  447. void HAL_ETHEx_EnterLPIMode(ETH_HandleTypeDef *heth, FunctionalState TxAutomate, FunctionalState TxClockStop)
  448. {
  449. /* Enable LPI Interrupts */
  450. __HAL_ETH_MAC_ENABLE_IT(heth, ETH_MACIER_LPIIE);
  451. /* Write to LPI Control register: Enter low power mode */
  452. MODIFY_REG(heth->Instance->MACLCSR, (ETH_MACLCSR_LPIEN | ETH_MACLCSR_LPITXA | ETH_MACLCSR_LPITCSE), (((uint32_t)TxAutomate << 19) |
  453. ((uint32_t)TxClockStop << 21) |
  454. ETH_MACLCSR_LPIEN));
  455. }
  456. /**
  457. * @brief Exits the Low Power Idle (LPI) mode.
  458. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  459. * the configuration information for ETHERNET module
  460. * @retval None
  461. */
  462. void HAL_ETHEx_ExitLPIMode(ETH_HandleTypeDef *heth)
  463. {
  464. /* Clear the LPI Config and exit low power mode */
  465. CLEAR_BIT(heth->Instance->MACLCSR, (ETH_MACLCSR_LPIEN | ETH_MACLCSR_LPITXA | ETH_MACLCSR_LPITCSE));
  466. /* Enable LPI Interrupts */
  467. __HAL_ETH_MAC_DISABLE_IT(heth, ETH_MACIER_LPIIE);
  468. }
  469. /**
  470. * @brief Returns the ETH MAC LPI event
  471. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  472. * the configuration information for ETHERNET module
  473. * @retval ETH MAC WakeUp event
  474. */
  475. uint32_t HAL_ETHEx_GetMACLPIEvent(ETH_HandleTypeDef *heth)
  476. {
  477. return heth->MACLPIEvent;
  478. }
  479. /**
  480. * @}
  481. */
  482. /**
  483. * @}
  484. */
  485. /**
  486. * @}
  487. */
  488. #endif /* ETH */
  489. #endif /* HAL_ETH_MODULE_ENABLED */
  490. /**
  491. * @}
  492. */
  493. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/