STM32f407探索者 ThreadX NetXDuo
本文带来的是正点原子的开发板STM32F407探索者使用ThreadX和NetX的教程,工程文件是通过CubeMX创建的,导出为MDK在进行编辑。
一.创建工程
打开CubeMX选择stm32f407zgt6 144引脚版本,由于板子带的是lan8720的网口,我试过用lan8742的PHY也可以正常驱动,这点还是很方便的。
打开SoftWare Packs
然后我们设置时钟
然后开启ETH,一定要选中断!!!正点原子的板子引脚和CubeMX默认的不同,所以要修改一下
一定要选中断!!!一定要选中断!!!一定要选中断!!!一定要选中断!!!一定要选中断!!!
我开了一个串口,方便自己看调试信息什么的
然后设置GPIO,PD3是ETH的复位引脚,这个和别的板子也不同,如果这里不设置,则上电后无法初始化ETH,网口的灯是不会亮起的。
点击Project Manager,修改工程的Firmware Package。
生成工程,然后打开。
二.设置NetX静态IP实现ping
在工程栏里,这三个文件和NetX是最相关的,8720和8742都可以用同一套,但是如果换了别的网口,则需要修改里面的文件。一个是对应网口的驱动,比如上面的lan8742.c,一个是PHY层的NetX驱动,对应的是nx_stm32_phy_driver.c。正常情况下默认的nx_stm32_eth_driver.c不用修改。适配不同的网卡只需要改lan8742.c和nx_stm32_phy_driver.c
打开main.c 因为正点原子的板子需要给PD3引脚复位才可以正常启动MX_ETH_INIT,在上面添加对应代码。
打开app_netxduo.c和app_netxduo.h
?app_netxduo.c
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file app_netxduo.c
* @author MCD Application Team
* @brief NetXDuo applicative file
******************************************************************************
* @attention
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "app_netxduo.h"
#include "nx_stm32_eth_config.h"
#include "usart.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/**
* @brief Application NetXDuo Initialization.
* @param memory_ptr: memory pointer
* @retval int
*/
#define NX_PACKET_RXPOOL_SIZE ((1536 + sizeof(NX_PACKET)) * 8)
ULONG packet_rxpool_area[NX_PACKET_RXPOOL_SIZE/4 + 4] __attribute__((section(".RxArraySection"))); // Ethernet rx Buffer
#define NX_PACKET_TXPOOL_SIZE ((1536 + sizeof(NX_PACKET)) * 10)
ULONG packet_txpool_area[NX_PACKET_TXPOOL_SIZE/4 + 4] __attribute__((section(".TxArraySection"))); // Ethernet tx Buffer and data buff
ULONG arp_space_area[512 / sizeof(ULONG)];
NX_PACKET_POOL rx_pool, tx_pool;
NX_IP ip_0;
ULONG ip_thread_stack[2 * 1024 / sizeof(ULONG)];
UINT MX_NetXDuo_Init(VOID *memory_ptr)
{
UINT status;
/* Initialize the NetX system. */
nx_system_initialize();
/* Create a packet pool. */
status = nx_packet_pool_create(&tx_pool,
"NetX Main txPacket Pool",
1536,
(ULONG*)(((int)packet_txpool_area + 15) & ~15) ,
NX_PACKET_TXPOOL_SIZE);
if(status){
HAL_UART_Transmit(&huart1,(uint8_t *)&"error1",sizeof("error1"),1000);
}
else{
HAL_UART_Transmit(&huart1,(uint8_t *)&"work1",sizeof("work1"),1000);
}
/* Create a packet rxpool. */
status = nx_packet_pool_create(&rx_pool,
"NetX Main rxPacket Pool",
1536,
(ULONG*)(((int)packet_rxpool_area + 15) & ~15) ,
NX_PACKET_RXPOOL_SIZE);
if(status){
HAL_UART_Transmit(&huart1,(uint8_t *)&"error2",sizeof("error2"),1000);
}
else{
HAL_UART_Transmit(&huart1,(uint8_t *)&"work2",sizeof("work2"),1000);
}
/* Create an IP instance. */
status = nx_ip_create(&ip_0,"NetX IP Instance 0",IP_ADDRESS(192, 168,4, 36),0xFFFFFF00UL,&tx_pool, nx_stm32_eth_driver,(UCHAR*)ip_thread_stack,sizeof(ip_thread_stack),1);
if(status){
HAL_UART_Transmit(&huart1,(uint8_t *)&"error3",sizeof("error3"),1000);
}
else{
HAL_UART_Transmit(&huart1,(uint8_t *)&"work3",sizeof("work3"),1000);
}
/* Enable ARP and supply ARP cache memory for IP Instance 0. */
status = nx_arp_enable(&ip_0, (void *)arp_space_area, sizeof(arp_space_area));
if(status){
HAL_UART_Transmit(&huart1,(uint8_t *)&"error4",sizeof("error4"),1000);
}
else{
HAL_UART_Transmit(&huart1,(uint8_t *)&"work4",sizeof("work4"),1000);
}
/* Enable TCP traffic. */
status = nx_tcp_enable(&ip_0);
if(status){
HAL_UART_Transmit(&huart1,(uint8_t *)&"error5",sizeof("error5"),1000);
}
else{
HAL_UART_Transmit(&huart1,(uint8_t *)&"work5",sizeof("work5"),1000);
}
/* Enable UDP traffic. */
status = nx_udp_enable(&ip_0);
if(status){
HAL_UART_Transmit(&huart1,(uint8_t *)&"error6",sizeof("error6"),1000);
}
else{
HAL_UART_Transmit(&huart1,(uint8_t *)&"work6",sizeof("work6"),1000);
}
/* Enable ICMP. */
status = nx_icmp_enable(&ip_0);
if(status){
HAL_UART_Transmit(&huart1,(uint8_t *)&"error7",sizeof("error7"),1000);
}
else{
HAL_UART_Transmit(&huart1,(uint8_t *)&"work7",sizeof("work7"),1000);
}
UINT ret = NX_SUCCESS;
TX_BYTE_POOL *byte_pool = (TX_BYTE_POOL*)memory_ptr;
/* USER CODE BEGIN MX_NetXDuo_MEM_POOL */
(void)byte_pool;
/* USER CODE END MX_NetXDuo_MEM_POOL */
/* USER CODE BEGIN MX_NetXDuo_Init */
/* USER CODE END MX_NetXDuo_Init */
return ret;
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
?app_netx_duo.h
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file app_netxduo.h
* @author MCD Application Team
* @brief NetXDuo applicative header file
******************************************************************************
* @attention
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __APP_NETXDUO_H__
#define __APP_NETXDUO_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "nx_api.h"
#include "nx_stm32_eth_driver.h"
#include "main.h"
#include "stm32f407xx.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
UINT MX_NetXDuo_Init(VOID *memory_ptr);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
#ifdef __cplusplus
}
#endif
#endif /* __APP_NETXDUO_H__ */
编译工程,然后下装。我用的是DAP
三.测试?
下装以后可以看到ETH网口的灯亮起来了,这说明物理层已经正常启动了。?
修改电脑的IP地址,工程用的是192.168.4.36这个IP。电脑要在同一个域里,改成192.168.4.100?
可以看到正常ping通了。
我后面看了一下论坛老哥里的8720的驱动包,其实代码内容和8742是一样的。。。也贴上来好了。
/**
******************************************************************************
* @file lan8720.c
* @author MCD Application Team
* @brief This file provides a set of functions needed to manage the LAN742
* PHY devices.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "lan8720.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup LAN8720 LAN8720
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/** @defgroup LAN8720_Private_Defines LAN8720 Private Defines
* @{
*/
#define LAN8720_SW_RESET_TO ((uint32_t)500U)
#define LAN8720_INIT_TO ((uint32_t)2000U)
#define LAN8720_MAX_DEV_ADDR ((uint32_t)31U)
/**
* @}
*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @defgroup LAN8720_Private_Functions LAN8720 Private Functions
* @{
*/
/**
* @brief Register IO functions to component object
* @param pObj: device object of LAN8720_Object_t.
* @param ioctx: holds device IO functions.
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_ERROR if missing mandatory function
*/
int32_t LAN8720_RegisterBusIO(lan8720_Object_t *pObj, lan8720_IOCtx_t *ioctx)
{
if(!pObj || !ioctx->ReadReg || !ioctx->WriteReg || !ioctx->GetTick)
{
return LAN8720_STATUS_ERROR;
}
pObj->IO.Init = ioctx->Init;
pObj->IO.DeInit = ioctx->DeInit;
pObj->IO.ReadReg = ioctx->ReadReg;
pObj->IO.WriteReg = ioctx->WriteReg;
pObj->IO.GetTick = ioctx->GetTick;
return LAN8720_STATUS_OK;
}
/**
* @brief Initialize the lan8720 and configure the needed hardware resources
* @param pObj: device object LAN8720_Object_t.
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_ADDRESS_ERROR if cannot find device address
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
* LAN8720_STATUS_RESET_TIMEOUT if cannot perform a software reset
*/
int32_t LAN8720_Init(lan8720_Object_t *pObj)
{
uint32_t tickstart = 0, regvalue = 0, addr = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->Is_Initialized == 0)
{
if(pObj->IO.Init != 0)
{
/* GPIO and Clocks initialization */
pObj->IO.Init();
}
/* for later check */
pObj->DevAddr = LAN8720_MAX_DEV_ADDR + 1;
/* Get the device address from special mode register */
for(addr = 0; addr <= LAN8720_MAX_DEV_ADDR; addr ++)
{
if(pObj->IO.ReadReg(addr, LAN8720_SMR, ®value) < 0)
{
status = LAN8720_STATUS_READ_ERROR;
/* Can't read from this device address
continue with next address */
continue;
}
if((regvalue & LAN8720_SMR_PHY_ADDR) == addr)
{
pObj->DevAddr = addr;
status = LAN8720_STATUS_OK;
break;
}
}
if(pObj->DevAddr > LAN8720_MAX_DEV_ADDR)
{
status = LAN8720_STATUS_ADDRESS_ERROR;
}
/* if device address is matched */
if(status == LAN8720_STATUS_OK)
{
/* set a software reset */
if(pObj->IO.WriteReg(pObj->DevAddr, LAN8720_BCR, LAN8720_BCR_SOFT_RESET) >= 0)
{
/* get software reset status */
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BCR, ®value) >= 0)
{
tickstart = pObj->IO.GetTick();
/* wait until software reset is done or timeout occured */
while(regvalue & LAN8720_BCR_SOFT_RESET)
{
if((pObj->IO.GetTick() - tickstart) <= LAN8720_SW_RESET_TO)
{
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BCR, ®value) < 0)
{
status = LAN8720_STATUS_READ_ERROR;
break;
}
}
else
{
status = LAN8720_STATUS_RESET_TIMEOUT;
break;
}
}
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
}
else
{
status = LAN8720_STATUS_WRITE_ERROR;
}
}
}
if(status == LAN8720_STATUS_OK)
{
tickstart = pObj->IO.GetTick();
/* Wait for 2s to perform initialization */
while((pObj->IO.GetTick() - tickstart) <= LAN8720_INIT_TO)
{
}
pObj->Is_Initialized = 1;
}
return status;
}
/**
* @brief De-Initialize the lan8720 and it's hardware resources
* @param pObj: device object LAN8720_Object_t.
* @retval None
*/
int32_t LAN8720_DeInit(lan8720_Object_t *pObj)
{
if(pObj->Is_Initialized)
{
if(pObj->IO.DeInit != 0)
{
if(pObj->IO.DeInit() < 0)
{
return LAN8720_STATUS_ERROR;
}
}
pObj->Is_Initialized = 0;
}
return LAN8720_STATUS_OK;
}
/**
* @brief Disable the LAN8720 power down mode.
* @param pObj: device object LAN8720_Object_t.
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
*/
int32_t LAN8720_DisablePowerDownMode(lan8720_Object_t *pObj)
{
uint32_t readval = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BCR, &readval) >= 0)
{
readval &= ~LAN8720_BCR_POWER_DOWN;
/* Apply configuration */
if(pObj->IO.WriteReg(pObj->DevAddr, LAN8720_BCR, readval) < 0)
{
status = LAN8720_STATUS_WRITE_ERROR;
}
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
return status;
}
/**
* @brief Enable the LAN8720 power down mode.
* @param pObj: device object LAN8720_Object_t.
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
*/
int32_t LAN8720_EnablePowerDownMode(lan8720_Object_t *pObj)
{
uint32_t readval = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BCR, &readval) >= 0)
{
readval |= LAN8720_BCR_POWER_DOWN;
/* Apply configuration */
if(pObj->IO.WriteReg(pObj->DevAddr, LAN8720_BCR, readval) < 0)
{
status = LAN8720_STATUS_WRITE_ERROR;
}
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
return status;
}
/**
* @brief Start the auto negotiation process.
* @param pObj: device object LAN8720_Object_t.
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
*/
int32_t LAN8720_StartAutoNego(lan8720_Object_t *pObj)
{
uint32_t readval = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BCR, &readval) >= 0)
{
readval |= LAN8720_BCR_AUTONEGO_EN;
/* Apply configuration */
if(pObj->IO.WriteReg(pObj->DevAddr, LAN8720_BCR, readval) < 0)
{
status = LAN8720_STATUS_WRITE_ERROR;
}
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
return status;
}
/**
* @brief Get the link state of LAN8720 device.
* @param pObj: Pointer to device object.
* @param pLinkState: Pointer to link state
* @retval LAN8720_STATUS_LINK_DOWN if link is down
* LAN8720_STATUS_AUTONEGO_NOTDONE if Auto nego not completed
* LAN8720_STATUS_100MBITS_FULLDUPLEX if 100Mb/s FD
* LAN8720_STATUS_100MBITS_HALFDUPLEX if 100Mb/s HD
* LAN8720_STATUS_10MBITS_FULLDUPLEX if 10Mb/s FD
* LAN8720_STATUS_10MBITS_HALFDUPLEX if 10Mb/s HD
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
*/
int32_t LAN8720_GetLinkState(lan8720_Object_t *pObj)
{
uint32_t readval = 0;
/* Read Status register */
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BSR, &readval) < 0)
{
return LAN8720_STATUS_READ_ERROR;
}
/* Read Status register again */
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BSR, &readval) < 0)
{
return LAN8720_STATUS_READ_ERROR;
}
if((readval & LAN8720_BSR_LINK_STATUS) == 0)
{
/* Return Link Down status */
return LAN8720_STATUS_LINK_DOWN;
}
/* Check Auto negotiaition */
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BCR, &readval) < 0)
{
return LAN8720_STATUS_READ_ERROR;
}
if((readval & LAN8720_BCR_AUTONEGO_EN) != LAN8720_BCR_AUTONEGO_EN)
{
if(((readval & LAN8720_BCR_SPEED_SELECT) == LAN8720_BCR_SPEED_SELECT) && ((readval & LAN8720_BCR_DUPLEX_MODE) == LAN8720_BCR_DUPLEX_MODE))
{
return LAN8720_STATUS_100MBITS_FULLDUPLEX;
}
else if ((readval & LAN8720_BCR_SPEED_SELECT) == LAN8720_BCR_SPEED_SELECT)
{
return LAN8720_STATUS_100MBITS_HALFDUPLEX;
}
else if ((readval & LAN8720_BCR_DUPLEX_MODE) == LAN8720_BCR_DUPLEX_MODE)
{
return LAN8720_STATUS_10MBITS_FULLDUPLEX;
}
else
{
return LAN8720_STATUS_10MBITS_HALFDUPLEX;
}
}
else /* Auto Nego enabled */
{
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_PHYSCSR, &readval) < 0)
{
return LAN8720_STATUS_READ_ERROR;
}
/* Check if auto nego not done */
if((readval & LAN8720_PHYSCSR_AUTONEGO_DONE) == 0)
{
return LAN8720_STATUS_AUTONEGO_NOTDONE;
}
if((readval & LAN8720_PHYSCSR_HCDSPEEDMASK) == LAN8720_PHYSCSR_100BTX_FD)
{
return LAN8720_STATUS_100MBITS_FULLDUPLEX;
}
else if ((readval & LAN8720_PHYSCSR_HCDSPEEDMASK) == LAN8720_PHYSCSR_100BTX_HD)
{
return LAN8720_STATUS_100MBITS_HALFDUPLEX;
}
else if ((readval & LAN8720_PHYSCSR_HCDSPEEDMASK) == LAN8720_PHYSCSR_10BT_FD)
{
return LAN8720_STATUS_10MBITS_FULLDUPLEX;
}
else
{
return LAN8720_STATUS_10MBITS_HALFDUPLEX;
}
}
}
/**
* @brief Set the link state of LAN8720 device.
* @param pObj: Pointer to device object.
* @param pLinkState: link state can be one of the following
* LAN8720_STATUS_100MBITS_FULLDUPLEX if 100Mb/s FD
* LAN8720_STATUS_100MBITS_HALFDUPLEX if 100Mb/s HD
* LAN8720_STATUS_10MBITS_FULLDUPLEX if 10Mb/s FD
* LAN8720_STATUS_10MBITS_HALFDUPLEX if 10Mb/s HD
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_ERROR if parameter error
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
*/
int32_t LAN8720_SetLinkState(lan8720_Object_t *pObj, uint32_t LinkState)
{
uint32_t bcrvalue = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BCR, &bcrvalue) >= 0)
{
/* Disable link config (Auto nego, speed and duplex) */
bcrvalue &= ~(LAN8720_BCR_AUTONEGO_EN | LAN8720_BCR_SPEED_SELECT | LAN8720_BCR_DUPLEX_MODE);
if(LinkState == LAN8720_STATUS_100MBITS_FULLDUPLEX)
{
bcrvalue |= (LAN8720_BCR_SPEED_SELECT | LAN8720_BCR_DUPLEX_MODE);
}
else if (LinkState == LAN8720_STATUS_100MBITS_HALFDUPLEX)
{
bcrvalue |= LAN8720_BCR_SPEED_SELECT;
}
else if (LinkState == LAN8720_STATUS_10MBITS_FULLDUPLEX)
{
bcrvalue |= LAN8720_BCR_DUPLEX_MODE;
}
else
{
/* Wrong link status parameter */
status = LAN8720_STATUS_ERROR;
}
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
if(status == LAN8720_STATUS_OK)
{
/* Apply configuration */
if(pObj->IO.WriteReg(pObj->DevAddr, LAN8720_BCR, bcrvalue) < 0)
{
status = LAN8720_STATUS_WRITE_ERROR;
}
}
return status;
}
/**
* @brief Enable loopback mode.
* @param pObj: Pointer to device object.
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
*/
int32_t LAN8720_EnableLoopbackMode(lan8720_Object_t *pObj)
{
uint32_t readval = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BCR, &readval) >= 0)
{
readval |= LAN8720_BCR_LOOPBACK;
/* Apply configuration */
if(pObj->IO.WriteReg(pObj->DevAddr, LAN8720_BCR, readval) < 0)
{
status = LAN8720_STATUS_WRITE_ERROR;
}
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
return status;
}
/**
* @brief Disable loopback mode.
* @param pObj: Pointer to device object.
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
*/
int32_t LAN8720_DisableLoopbackMode(lan8720_Object_t *pObj)
{
uint32_t readval = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_BCR, &readval) >= 0)
{
readval &= ~LAN8720_BCR_LOOPBACK;
/* Apply configuration */
if(pObj->IO.WriteReg(pObj->DevAddr, LAN8720_BCR, readval) < 0)
{
status = LAN8720_STATUS_WRITE_ERROR;
}
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
return status;
}
/**
* @brief Enable IT source.
* @param pObj: Pointer to device object.
* @param Interrupt: IT source to be enabled
* should be a value or a combination of the following:
* LAN8720_WOL_IT
* LAN8720_ENERGYON_IT
* LAN8720_AUTONEGO_COMPLETE_IT
* LAN8720_REMOTE_FAULT_IT
* LAN8720_LINK_DOWN_IT
* LAN8720_AUTONEGO_LP_ACK_IT
* LAN8720_PARALLEL_DETECTION_FAULT_IT
* LAN8720_AUTONEGO_PAGE_RECEIVED_IT
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
*/
int32_t LAN8720_EnableIT(lan8720_Object_t *pObj, uint32_t Interrupt)
{
uint32_t readval = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_IMR, &readval) >= 0)
{
readval |= Interrupt;
/* Apply configuration */
if(pObj->IO.WriteReg(pObj->DevAddr, LAN8720_IMR, readval) < 0)
{
status = LAN8720_STATUS_WRITE_ERROR;
}
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
return status;
}
/**
* @brief Disable IT source.
* @param pObj: Pointer to device object.
* @param Interrupt: IT source to be disabled
* should be a value or a combination of the following:
* LAN8720_WOL_IT
* LAN8720_ENERGYON_IT
* LAN8720_AUTONEGO_COMPLETE_IT
* LAN8720_REMOTE_FAULT_IT
* LAN8720_LINK_DOWN_IT
* LAN8720_AUTONEGO_LP_ACK_IT
* LAN8720_PARALLEL_DETECTION_FAULT_IT
* LAN8720_AUTONEGO_PAGE_RECEIVED_IT
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_READ_ERROR if connot read register
* LAN8720_STATUS_WRITE_ERROR if connot write to register
*/
int32_t LAN8720_DisableIT(lan8720_Object_t *pObj, uint32_t Interrupt)
{
uint32_t readval = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_IMR, &readval) >= 0)
{
readval &= ~Interrupt;
/* Apply configuration */
if(pObj->IO.WriteReg(pObj->DevAddr, LAN8720_IMR, readval) < 0)
{
status = LAN8720_STATUS_WRITE_ERROR;
}
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
return status;
}
/**
* @brief Clear IT flag.
* @param pObj: Pointer to device object.
* @param Interrupt: IT flag to be cleared
* should be a value or a combination of the following:
* LAN8720_WOL_IT
* LAN8720_ENERGYON_IT
* LAN8720_AUTONEGO_COMPLETE_IT
* LAN8720_REMOTE_FAULT_IT
* LAN8720_LINK_DOWN_IT
* LAN8720_AUTONEGO_LP_ACK_IT
* LAN8720_PARALLEL_DETECTION_FAULT_IT
* LAN8720_AUTONEGO_PAGE_RECEIVED_IT
* @retval LAN8720_STATUS_OK if OK
* LAN8720_STATUS_READ_ERROR if connot read register
*/
int32_t LAN8720_ClearIT(lan8720_Object_t *pObj, uint32_t Interrupt)
{
uint32_t readval = 0;
int32_t status = LAN8720_STATUS_OK;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_ISFR, &readval) < 0)
{
status = LAN8720_STATUS_READ_ERROR;
}
return status;
}
/**
* @brief Get IT Flag status.
* @param pObj: Pointer to device object.
* @param Interrupt: IT Flag to be checked,
* should be a value or a combination of the following:
* LAN8720_WOL_IT
* LAN8720_ENERGYON_IT
* LAN8720_AUTONEGO_COMPLETE_IT
* LAN8720_REMOTE_FAULT_IT
* LAN8720_LINK_DOWN_IT
* LAN8720_AUTONEGO_LP_ACK_IT
* LAN8720_PARALLEL_DETECTION_FAULT_IT
* LAN8720_AUTONEGO_PAGE_RECEIVED_IT
* @retval 1 IT flag is SET
* 0 IT flag is RESET
* LAN8720_STATUS_READ_ERROR if connot read register
*/
int32_t LAN8720_GetITStatus(lan8720_Object_t *pObj, uint32_t Interrupt)
{
uint32_t readval = 0;
int32_t status = 0;
if(pObj->IO.ReadReg(pObj->DevAddr, LAN8720_ISFR, &readval) >= 0)
{
status = ((readval & Interrupt) == Interrupt);
}
else
{
status = LAN8720_STATUS_READ_ERROR;
}
return status;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* @file lan8720.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the
* lan8720.c PHY driver.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef LAN8720_H
#define LAN8720_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup LAN8720
* @{
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup LAN8720_Exported_Constants LAN8720 Exported Constants
* @{
*/
/** @defgroup LAN8720_Registers_Mapping LAN8720 Registers Mapping
* @{
*/
#define LAN8720_BCR ((uint16_t)0x0000U)
#define LAN8720_BSR ((uint16_t)0x0001U)
#define LAN8720_PHYI1R ((uint16_t)0x0002U)
#define LAN8720_PHYI2R ((uint16_t)0x0003U)
#define LAN8720_ANAR ((uint16_t)0x0004U)
#define LAN8720_ANLPAR ((uint16_t)0x0005U)
#define LAN8720_ANER ((uint16_t)0x0006U)
#define LAN8720_ANNPTR ((uint16_t)0x0007U)
#define LAN8720_ANNPRR ((uint16_t)0x0008U)
#define LAN8720_MMDACR ((uint16_t)0x000DU)
#define LAN8720_MMDAADR ((uint16_t)0x000EU)
#define LAN8720_ENCTR ((uint16_t)0x0010U)
#define LAN8720_MCSR ((uint16_t)0x0011U)
#define LAN8720_SMR ((uint16_t)0x0012U)
#define LAN8720_TPDCR ((uint16_t)0x0018U)
#define LAN8720_TCSR ((uint16_t)0x0019U)
#define LAN8720_SECR ((uint16_t)0x001AU)
#define LAN8720_SCSIR ((uint16_t)0x001BU)
#define LAN8720_CLR ((uint16_t)0x001CU)
#define LAN8720_ISFR ((uint16_t)0x001DU)
#define LAN8720_IMR ((uint16_t)0x001EU)
#define LAN8720_PHYSCSR ((uint16_t)0x001FU)
/**
* @}
*/
/** @defgroup LAN8720_BCR_Bit_Definition LAN8720 BCR Bit Definition
* @{
*/
#define LAN8720_BCR_SOFT_RESET ((uint16_t)0x8000U)
#define LAN8720_BCR_LOOPBACK ((uint16_t)0x4000U)
#define LAN8720_BCR_SPEED_SELECT ((uint16_t)0x2000U)
#define LAN8720_BCR_AUTONEGO_EN ((uint16_t)0x1000U)
#define LAN8720_BCR_POWER_DOWN ((uint16_t)0x0800U)
#define LAN8720_BCR_ISOLATE ((uint16_t)0x0400U)
#define LAN8720_BCR_RESTART_AUTONEGO ((uint16_t)0x0200U)
#define LAN8720_BCR_DUPLEX_MODE ((uint16_t)0x0100U)
/**
* @}
*/
/** @defgroup LAN8720_BSR_Bit_Definition LAN8720 BSR Bit Definition
* @{
*/
#define LAN8720_BSR_100BASE_T4 ((uint16_t)0x8000U)
#define LAN8720_BSR_100BASE_TX_FD ((uint16_t)0x4000U)
#define LAN8720_BSR_100BASE_TX_HD ((uint16_t)0x2000U)
#define LAN8720_BSR_10BASE_T_FD ((uint16_t)0x1000U)
#define LAN8720_BSR_10BASE_T_HD ((uint16_t)0x0800U)
#define LAN8720_BSR_100BASE_T2_FD ((uint16_t)0x0400U)
#define LAN8720_BSR_100BASE_T2_HD ((uint16_t)0x0200U)
#define LAN8720_BSR_EXTENDED_STATUS ((uint16_t)0x0100U)
#define LAN8720_BSR_AUTONEGO_CPLT ((uint16_t)0x0020U)
#define LAN8720_BSR_REMOTE_FAULT ((uint16_t)0x0010U)
#define LAN8720_BSR_AUTONEGO_ABILITY ((uint16_t)0x0008U)
#define LAN8720_BSR_LINK_STATUS ((uint16_t)0x0004U)
#define LAN8720_BSR_JABBER_DETECT ((uint16_t)0x0002U)
#define LAN8720_BSR_EXTENDED_CAP ((uint16_t)0x0001U)
/**
* @}
*/
/** @defgroup LAN8720_PHYI1R_Bit_Definition LAN8720 PHYI1R Bit Definition
* @{
*/
#define LAN8720_PHYI1R_OUI_3_18 ((uint16_t)0xFFFFU)
/**
* @}
*/
/** @defgroup LAN8720_PHYI2R_Bit_Definition LAN8720 PHYI2R Bit Definition
* @{
*/
#define LAN8720_PHYI2R_OUI_19_24 ((uint16_t)0xFC00U)
#define LAN8720_PHYI2R_MODEL_NBR ((uint16_t)0x03F0U)
#define LAN8720_PHYI2R_REVISION_NBR ((uint16_t)0x000FU)
/**
* @}
*/
/** @defgroup LAN8720_ANAR_Bit_Definition LAN8720 ANAR Bit Definition
* @{
*/
#define LAN8720_ANAR_NEXT_PAGE ((uint16_t)0x8000U)
#define LAN8720_ANAR_REMOTE_FAULT ((uint16_t)0x2000U)
#define LAN8720_ANAR_PAUSE_OPERATION ((uint16_t)0x0C00U)
#define LAN8720_ANAR_PO_NOPAUSE ((uint16_t)0x0000U)
#define LAN8720_ANAR_PO_SYMMETRIC_PAUSE ((uint16_t)0x0400U)
#define LAN8720_ANAR_PO_ASYMMETRIC_PAUSE ((uint16_t)0x0800U)
#define LAN8720_ANAR_PO_ADVERTISE_SUPPORT ((uint16_t)0x0C00U)
#define LAN8720_ANAR_100BASE_TX_FD ((uint16_t)0x0100U)
#define LAN8720_ANAR_100BASE_TX ((uint16_t)0x0080U)
#define LAN8720_ANAR_10BASE_T_FD ((uint16_t)0x0040U)
#define LAN8720_ANAR_10BASE_T ((uint16_t)0x0020U)
#define LAN8720_ANAR_SELECTOR_FIELD ((uint16_t)0x000FU)
/**
* @}
*/
/** @defgroup LAN8720_ANLPAR_Bit_Definition LAN8720 ANLPAR Bit Definition
* @{
*/
#define LAN8720_ANLPAR_NEXT_PAGE ((uint16_t)0x8000U)
#define LAN8720_ANLPAR_REMOTE_FAULT ((uint16_t)0x2000U)
#define LAN8720_ANLPAR_PAUSE_OPERATION ((uint16_t)0x0C00U)
#define LAN8720_ANLPAR_PO_NOPAUSE ((uint16_t)0x0000U)
#define LAN8720_ANLPAR_PO_SYMMETRIC_PAUSE ((uint16_t)0x0400U)
#define LAN8720_ANLPAR_PO_ASYMMETRIC_PAUSE ((uint16_t)0x0800U)
#define LAN8720_ANLPAR_PO_ADVERTISE_SUPPORT ((uint16_t)0x0C00U)
#define LAN8720_ANLPAR_100BASE_TX_FD ((uint16_t)0x0100U)
#define LAN8720_ANLPAR_100BASE_TX ((uint16_t)0x0080U)
#define LAN8720_ANLPAR_10BASE_T_FD ((uint16_t)0x0040U)
#define LAN8720_ANLPAR_10BASE_T ((uint16_t)0x0020U)
#define LAN8720_ANLPAR_SELECTOR_FIELD ((uint16_t)0x000FU)
/**
* @}
*/
/** @defgroup LAN8720_ANER_Bit_Definition LAN8720 ANER Bit Definition
* @{
*/
#define LAN8720_ANER_RX_NP_LOCATION_ABLE ((uint16_t)0x0040U)
#define LAN8720_ANER_RX_NP_STORAGE_LOCATION ((uint16_t)0x0020U)
#define LAN8720_ANER_PARALLEL_DETECT_FAULT ((uint16_t)0x0010U)
#define LAN8720_ANER_LP_NP_ABLE ((uint16_t)0x0008U)
#define LAN8720_ANER_NP_ABLE ((uint16_t)0x0004U)
#define LAN8720_ANER_PAGE_RECEIVED ((uint16_t)0x0002U)
#define LAN8720_ANER_LP_AUTONEG_ABLE ((uint16_t)0x0001U)
/**
* @}
*/
/** @defgroup LAN8720_ANNPTR_Bit_Definition LAN8720 ANNPTR Bit Definition
* @{
*/
#define LAN8720_ANNPTR_NEXT_PAGE ((uint16_t)0x8000U)
#define LAN8720_ANNPTR_MESSAGE_PAGE ((uint16_t)0x2000U)
#define LAN8720_ANNPTR_ACK2 ((uint16_t)0x1000U)
#define LAN8720_ANNPTR_TOGGLE ((uint16_t)0x0800U)
#define LAN8720_ANNPTR_MESSAGGE_CODE ((uint16_t)0x07FFU)
/**
* @}
*/
/** @defgroup LAN8720_ANNPRR_Bit_Definition LAN8720 ANNPRR Bit Definition
* @{
*/
#define LAN8720_ANNPTR_NEXT_PAGE ((uint16_t)0x8000U)
#define LAN8720_ANNPRR_ACK ((uint16_t)0x4000U)
#define LAN8720_ANNPRR_MESSAGE_PAGE ((uint16_t)0x2000U)
#define LAN8720_ANNPRR_ACK2 ((uint16_t)0x1000U)
#define LAN8720_ANNPRR_TOGGLE ((uint16_t)0x0800U)
#define LAN8720_ANNPRR_MESSAGGE_CODE ((uint16_t)0x07FFU)
/**
* @}
*/
/** @defgroup LAN8720_MMDACR_Bit_Definition LAN8720 MMDACR Bit Definition
* @{
*/
#define LAN8720_MMDACR_MMD_FUNCTION ((uint16_t)0xC000U)
#define LAN8720_MMDACR_MMD_FUNCTION_ADDR ((uint16_t)0x0000U)
#define LAN8720_MMDACR_MMD_FUNCTION_DATA ((uint16_t)0x4000U)
#define LAN8720_MMDACR_MMD_DEV_ADDR ((uint16_t)0x001FU)
/**
* @}
*/
/** @defgroup LAN8720_ENCTR_Bit_Definition LAN8720 ENCTR Bit Definition
* @{
*/
#define LAN8720_ENCTR_TX_ENABLE ((uint16_t)0x8000U)
#define LAN8720_ENCTR_TX_TIMER ((uint16_t)0x6000U)
#define LAN8720_ENCTR_TX_TIMER_1S ((uint16_t)0x0000U)
#define LAN8720_ENCTR_TX_TIMER_768MS ((uint16_t)0x2000U)
#define LAN8720_ENCTR_TX_TIMER_512MS ((uint16_t)0x4000U)
#define LAN8720_ENCTR_TX_TIMER_265MS ((uint16_t)0x6000U)
#define LAN8720_ENCTR_RX_ENABLE ((uint16_t)0x1000U)
#define LAN8720_ENCTR_RX_MAX_INTERVAL ((uint16_t)0x0C00U)
#define LAN8720_ENCTR_RX_MAX_INTERVAL_64MS ((uint16_t)0x0000U)
#define LAN8720_ENCTR_RX_MAX_INTERVAL_256MS ((uint16_t)0x0400U)
#define LAN8720_ENCTR_RX_MAX_INTERVAL_512MS ((uint16_t)0x0800U)
#define LAN8720_ENCTR_RX_MAX_INTERVAL_1S ((uint16_t)0x0C00U)
#define LAN8720_ENCTR_EX_CROSS_OVER ((uint16_t)0x0002U)
#define LAN8720_ENCTR_EX_MANUAL_CROSS_OVER ((uint16_t)0x0001U)
/**
* @}
*/
/** @defgroup LAN8720_MCSR_Bit_Definition LAN8720 MCSR Bit Definition
* @{
*/
#define LAN8720_MCSR_EDPWRDOWN ((uint16_t)0x2000U)
#define LAN8720_MCSR_FARLOOPBACK ((uint16_t)0x0200U)
#define LAN8720_MCSR_ALTINT ((uint16_t)0x0040U)
#define LAN8720_MCSR_ENERGYON ((uint16_t)0x0002U)
/**
* @}
*/
/** @defgroup LAN8720_SMR_Bit_Definition LAN8720 SMR Bit Definition
* @{
*/
#define LAN8720_SMR_MODE ((uint16_t)0x00E0U)
#define LAN8720_SMR_PHY_ADDR ((uint16_t)0x001FU)
/**
* @}
*/
/** @defgroup LAN8720_TPDCR_Bit_Definition LAN8720 TPDCR Bit Definition
* @{
*/
#define LAN8720_TPDCR_DELAY_IN ((uint16_t)0x8000U)
#define LAN8720_TPDCR_LINE_BREAK_COUNTER ((uint16_t)0x7000U)
#define LAN8720_TPDCR_PATTERN_HIGH ((uint16_t)0x0FC0U)
#define LAN8720_TPDCR_PATTERN_LOW ((uint16_t)0x003FU)
/**
* @}
*/
/** @defgroup LAN8720_TCSR_Bit_Definition LAN8720 TCSR Bit Definition
* @{
*/
#define LAN8720_TCSR_TDR_ENABLE ((uint16_t)0x8000U)
#define LAN8720_TCSR_TDR_AD_FILTER_ENABLE ((uint16_t)0x4000U)
#define LAN8720_TCSR_TDR_CH_CABLE_TYPE ((uint16_t)0x0600U)
#define LAN8720_TCSR_TDR_CH_CABLE_DEFAULT ((uint16_t)0x0000U)
#define LAN8720_TCSR_TDR_CH_CABLE_SHORTED ((uint16_t)0x0200U)
#define LAN8720_TCSR_TDR_CH_CABLE_OPEN ((uint16_t)0x0400U)
#define LAN8720_TCSR_TDR_CH_CABLE_MATCH ((uint16_t)0x0600U)
#define LAN8720_TCSR_TDR_CH_STATUS ((uint16_t)0x0100U)
#define LAN8720_TCSR_TDR_CH_LENGTH ((uint16_t)0x00FFU)
/**
* @}
*/
/** @defgroup LAN8720_SCSIR_Bit_Definition LAN8720 SCSIR Bit Definition
* @{
*/
#define LAN8720_SCSIR_AUTO_MDIX_ENABLE ((uint16_t)0x8000U)
#define LAN8720_SCSIR_CHANNEL_SELECT ((uint16_t)0x2000U)
#define LAN8720_SCSIR_SQE_DISABLE ((uint16_t)0x0800U)
#define LAN8720_SCSIR_XPOLALITY ((uint16_t)0x0010U)
/**
* @}
*/
/** @defgroup LAN8720_CLR_Bit_Definition LAN8720 CLR Bit Definition
* @{
*/
#define LAN8720_CLR_CABLE_LENGTH ((uint16_t)0xF000U)
/**
* @}
*/
/** @defgroup LAN8720_IMR_ISFR_Bit_Definition LAN8720 IMR ISFR Bit Definition
* @{
*/
#define LAN8720_INT_8 ((uint16_t)0x0100U)
#define LAN8720_INT_7 ((uint16_t)0x0080U)
#define LAN8720_INT_6 ((uint16_t)0x0040U)
#define LAN8720_INT_5 ((uint16_t)0x0020U)
#define LAN8720_INT_4 ((uint16_t)0x0010U)
#define LAN8720_INT_3 ((uint16_t)0x0008U)
#define LAN8720_INT_2 ((uint16_t)0x0004U)
#define LAN8720_INT_1 ((uint16_t)0x0002U)
/**
* @}
*/
/** @defgroup LAN8720_PHYSCSR_Bit_Definition LAN8720 PHYSCSR Bit Definition
* @{
*/
#define LAN8720_PHYSCSR_AUTONEGO_DONE ((uint16_t)0x1000U)
#define LAN8720_PHYSCSR_HCDSPEEDMASK ((uint16_t)0x001CU)
#define LAN8720_PHYSCSR_10BT_HD ((uint16_t)0x0004U)
#define LAN8720_PHYSCSR_10BT_FD ((uint16_t)0x0014U)
#define LAN8720_PHYSCSR_100BTX_HD ((uint16_t)0x0008U)
#define LAN8720_PHYSCSR_100BTX_FD ((uint16_t)0x0018U)
/**
* @}
*/
/** @defgroup LAN8720_Status LAN8720 Status
* @{
*/
#define LAN8720_STATUS_READ_ERROR ((int32_t)-5)
#define LAN8720_STATUS_WRITE_ERROR ((int32_t)-4)
#define LAN8720_STATUS_ADDRESS_ERROR ((int32_t)-3)
#define LAN8720_STATUS_RESET_TIMEOUT ((int32_t)-2)
#define LAN8720_STATUS_ERROR ((int32_t)-1)
#define LAN8720_STATUS_OK ((int32_t) 0)
#define LAN8720_STATUS_LINK_DOWN ((int32_t) 1)
#define LAN8720_STATUS_100MBITS_FULLDUPLEX ((int32_t) 2)
#define LAN8720_STATUS_100MBITS_HALFDUPLEX ((int32_t) 3)
#define LAN8720_STATUS_10MBITS_FULLDUPLEX ((int32_t) 4)
#define LAN8720_STATUS_10MBITS_HALFDUPLEX ((int32_t) 5)
#define LAN8720_STATUS_AUTONEGO_NOTDONE ((int32_t) 6)
/**
* @}
*/
/** @defgroup LAN8720_IT_Flags LAN8720 IT Flags
* @{
*/
#define LAN8720_WOL_IT LAN8720_INT_8
#define LAN8720_ENERGYON_IT LAN8720_INT_7
#define LAN8720_AUTONEGO_COMPLETE_IT LAN8720_INT_6
#define LAN8720_REMOTE_FAULT_IT LAN8720_INT_5
#define LAN8720_LINK_DOWN_IT LAN8720_INT_4
#define LAN8720_AUTONEGO_LP_ACK_IT LAN8720_INT_3
#define LAN8720_PARALLEL_DETECTION_FAULT_IT LAN8720_INT_2
#define LAN8720_AUTONEGO_PAGE_RECEIVED_IT LAN8720_INT_1
/**
* @}
*/
/**
* @}
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup LAN8720_Exported_Types LAN8720 Exported Types
* @{
*/
typedef int32_t (*lan8720_Init_Func) (void);
typedef int32_t (*lan8720_DeInit_Func) (void);
typedef int32_t (*lan8720_ReadReg_Func) (uint32_t, uint32_t, uint32_t *);
typedef int32_t (*lan8720_WriteReg_Func) (uint32_t, uint32_t, uint32_t);
typedef int32_t (*lan8720_GetTick_Func) (void);
typedef struct
{
lan8720_Init_Func Init;
lan8720_DeInit_Func DeInit;
lan8720_WriteReg_Func WriteReg;
lan8720_ReadReg_Func ReadReg;
lan8720_GetTick_Func GetTick;
} lan8720_IOCtx_t;
typedef struct
{
uint32_t DevAddr;
uint32_t Is_Initialized;
lan8720_IOCtx_t IO;
void *pData;
}lan8720_Object_t;
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup LAN8720_Exported_Functions LAN8720 Exported Functions
* @{
*/
int32_t LAN8720_RegisterBusIO(lan8720_Object_t *pObj, lan8720_IOCtx_t *ioctx);
int32_t LAN8720_Init(lan8720_Object_t *pObj);
int32_t LAN8720_DeInit(lan8720_Object_t *pObj);
int32_t LAN8720_DisablePowerDownMode(lan8720_Object_t *pObj);
int32_t LAN8720_EnablePowerDownMode(lan8720_Object_t *pObj);
int32_t LAN8720_StartAutoNego(lan8720_Object_t *pObj);
int32_t LAN8720_GetLinkState(lan8720_Object_t *pObj);
int32_t LAN8720_SetLinkState(lan8720_Object_t *pObj, uint32_t LinkState);
int32_t LAN8720_EnableLoopbackMode(lan8720_Object_t *pObj);
int32_t LAN8720_DisableLoopbackMode(lan8720_Object_t *pObj);
int32_t LAN8720_EnableIT(lan8720_Object_t *pObj, uint32_t Interrupt);
int32_t LAN8720_DisableIT(lan8720_Object_t *pObj, uint32_t Interrupt);
int32_t LAN8720_ClearIT(lan8720_Object_t *pObj, uint32_t Interrupt);
int32_t LAN8720_GetITStatus(lan8720_Object_t *pObj, uint32_t Interrupt);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* LAN8720_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
?
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!