📄 net_phy.c
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Stack
*
* (c) Copyright 2003-2004; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may not be used to write a similar
* product. This file may only be used in accordance with a license
* and should not be redistributed in any way.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK INTERFACE CARD
*
* LXT971A
*
* Filename : net_phy.c
* Version : V1.05
* Programmer(S) : JDH
*********************************************************************************************************
* Note(s) : (1) Supports Intel LXT971A '3.3V Dual-Speed Fast Ethernet Transceiver' as described in
*
* Intel Corporation (INTEL; http://www.intel.com)
* (a) LXT971A (INTEL LXT971A; Revision 249414-002)
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <net.h>
#include <net_nic.h>
#include <net_phy.h>
/*
*********************************************************************************************************
* NetNIC_PhyInit()
*
* Description : Initialize phyter (ethernet link controller)
* This instance configure the Intel LXT971A Phyter
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : ???_Init.
*
* Note(s) : none.
*********************************************************************************************************
*/
void NetNIC_PhyInit (void)
{
/* LXT971A register 0x00: Control Register */
/* BIT 15: Reset */
/* BIT 09: Restart Auto-negotiation */
NetNIC_PhyRegWr(0, 0x00, DEF_BIT_15 | DEF_BIT_09);
LXT971A_DlyReset();
/* Clear pending interrupts */
NetNIC_PhyRegRd(0, 0x13);
/* LXT971A register 0x12: Interrupt Enable Register */
/* BIT 04: Link Status Interrupt */
/* BIT 01: Enable Interrupts */
NetNIC_PhyRegWr(0, 0x12, DEF_BIT_04 | DEF_BIT_01);
/* LXT971A register 0x14: LED Configuration Register */
/* LED 1: Display Speed Status (Continuous, Default) */
/* LED 2: Display Link and Activity Status combined (Stretched) */
/* LED 3: Display Collision Status */
/* Stretch LED events to 100 ms */
/* Enable pulse stretching of all LEDs */
NetNIC_PhyRegWr(0, 0x14, 0x0D3A);
NetNIC_PhyIntInit(); /* Initialize external interrupt controller */
NetNIC_PhyAutoNeg(); /* Do link auto-negotiation */
NetNIC_ConnStatus = NetNIC_PhyLinkState(); /* Set NetNIC_ConnStatus according to link state */
if (NetNIC_ConnStatus == DEF_ON) {
NetNIC_LinkUp();
} else {
NetNIC_LinkDown();
}
}
/*
*********************************************************************************************************
* NetNIC_PhyAutoNeg()
*
* Description : Do link auto-negotiation
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_PhyInit.
*
* Note(s) : none.
*********************************************************************************************************
*/
void NetNIC_PhyAutoNeg (void)
{
CPU_INT16U i;
CPU_BOOLEAN link;
i = LXT971A_INIT_AUTO_NEG_RETRIES;
link = NetNIC_PhyAutoNegState();
while ((link != DEF_ON) && (i > 0)) {
LXT971A_DlyAutoNegAck();
link = NetNIC_PhyAutoNegState();
i--;
}
}
/*
*********************************************************************************************************
* NetNIC_PhyAutoNegState()
*
* Description : Returns state of auto-negotiation
* This instance probe the Intel LXT971A '3.3V Dual-Speed Fast Ethernet Transceiver'
*
* Argument(s) : none.
*
* Return(s) : State of auto-negociation (DEF_OFF = not completed, DEF_ON = completed).
*
* Caller(s) : NetNIC_PhyInit.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN NetNIC_PhyAutoNegState (void)
{
CPU_INT32U reg_val;
/* LXT971A register 0x11: Status Register #2 */
/* BIT 07: Auto-negotiation complete */
reg_val = NetNIC_PhyRegRd(0, 0x11);
if ((reg_val & DEF_BIT_07) == DEF_BIT_07) {
return (DEF_ON);
} else {
return (DEF_OFF);
}
}
/*
*********************************************************************************************************
* NetNIC_PhyLinkState()
*
* Description : Returns state of ethernet link
* This instance probe the Intel LXT971A '3.3V Dual-Speed Fast Ethernet Transceiver'
*
* Argument(s) : none.
*
* Return(s) : State of ethernet link (DEF_OFF = link down, DEF_ON = link up).
*
* Caller(s) : NetNIC_PhyISR_Handler.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN NetNIC_PhyLinkState (void)
{
CPU_INT32U reg_val;
/* LXT971A register 0x11: Status Register #2 */
/* BIT 10: Link status */
reg_val = NetNIC_PhyRegRd(0, 0x11);
if ((reg_val & DEF_BIT_10) == DEF_BIT_10) {
return (DEF_ON);
} else {
return (DEF_OFF);
}
}
/*
*********************************************************************************************************
* NetNIC_ISR_Handler()
*
* Description : (1) Update NetNIC_ConnStatus according to link state
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_ISR() [see Note #2].
*
* Note(s) : (2) LXT971A ISR MUST call NetNIC_PhyISR_Handler() & MUST be developer-implemented in
*
* \<Your Product Application>\net_isr*.*
*
* where
* <Your Product Application> directory path for Your Product's Application
*
* (3) This function clears the interrupt source(s) on an external interrupt controller &, if
* ENABLED, MUST be developer-implemented in
*
* \<Your Product Application>\net_isr.c
*
* where
* <Your Product Application> directory path for Your Product's Application
*********************************************************************************************************
*/
void NetNIC_PhyISR_Handler (void)
{
NetNIC_ConnStatus = NetNIC_PhyLinkState(); /* Set NetNIC_ConnStatus according to link state */
if (NetNIC_ConnStatus == DEF_ON) {
NetNIC_LinkUp();
} else {
NetNIC_LinkDown();
}
NetNIC_PhyRegRd(0, 0x13);
NetNIC_PhyIntClr();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -