?? net_nic.c
字號:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2006; 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
*
* STR91x MAC/DMA Controller
*
* Filename : net_nic.c
* Version : V1.00
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define NET_NIC_MODULE
#include "includes.h"
#include "net_nic.h"
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
static ENET_MACConfig NIC_Config;
/*
*********************************************************************************************************
* Local Function Prototypes
*********************************************************************************************************
*/
static void NetNIC_TxPktDiscard (NET_ERR *perr);
static void MAC_Init (void);
/*
*********************************************************************************************************
* NetNIC_Init()
*
* Description : (1) Initialize Network Interface Card :
*
* (a) Perform NIC Layer OS initialization
* (b) Initialize NIC status
* (c) Initialize NIC statistics & error counters
* (d) Initialize STR91x MAC
*
* Argument(s) : perr Pointer to variable that will hold the return error code from this function :
*
* NET_NIC_ERR_NONE Network interface card successfully initialized.
*
* -------- RETURNED BY NetOS_NIC_Init() : --------
* NET_OS_ERR_INIT_NIC_TX_RDY NIC transmit ready signal NOT successfully
* initialized.
* NET_OS_ERR_INIT_NIC_TX_RDY_NAME NIC transmit ready name NOT successfully
* configured.
*
* Return(s) : none.
*
* Caller(s) : Net_Init().
*
* Note(s) : none.
*********************************************************************************************************
*/
void NetNIC_Init (NET_ERR *perr)
{
NetOS_NIC_Init(perr); /* Create NIC OS Objects */
if (*perr != NET_OS_ERR_NONE) {
return;
}
NetNIC_ConnStatus = DEF_OFF; /* Initialize the NIC status */
#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED) /* Initialize NIC statistics counters */
NetNIC_StatRxPktCtr = 0;
NetNIC_StatTxPktCtr = 0;
#endif
#if (NET_CTR_CFG_ERR_EN == DEF_ENABLED) /* Initialize NIC error counters */
NetNIC_ErrRxPktDiscardedCtr = 0;
NetNIC_ErrTxPktDiscardedCtr = 0;
#endif
MAC_Init(); /* Initialize the NIC hardware */
NetNIC_ConnStatus = DEF_ON;
*perr = NET_NIC_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetNIC_IntEn()
*
* Description : Enable NIC interrupts.
*
* Argument(s) : perr Pointer to variable that will hold the return error code from this function :
*
* NET_NIC_ERR_NONE NIC interrupts successfully enabled.
*
* Return(s) : none.
*
* Caller(s) : Net_Init().
*
* Note(s) : none.
*********************************************************************************************************
*/
void NetNIC_IntEn (NET_ERR *perr)
{
/* Abort any transfers currently in progress */
ENET_DMA->RXSTR &=~DMA_RX_START_DMA_EN;
ENET_DMA->TXSTR &=~DMA_TX_START_DMA_EN;
/* Clear any pending interrupts */
ENET_DMA->ISR = 0xFFFFFFFF;
/* Enable Rx and Tx interrupts */
ENET_DMA->IER = 0x80008000;
/* Enable Rx and Tx on the MAC */
ENET_MAC->MCR |= (MAC_MCR_TE | MAC_MCR_RE);
/* Initiate Rx DMA transfer */
ENET_DMA->RXSTR = DMA_RX_START_RUNT | DMA_RX_START_FFAIL | DMA_RX_START_FETCH;
*perr = NET_NIC_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetNIC_ConnStatusChk()
*
* Description : Check the NIC's network connection status. This function always indicates that the
* connection is up.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : ####
*********************************************************************************************************
*/
void NetNIC_ConnStatusChk (void)
{
NetNIC_ConnStatus = DEF_ON;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetNIC_ConnStatusGet()
*
* Description : Get NIC's network connection status.
*
* (1) Obtaining the NIC's network connection status is encapsulated in this function for the
* possibility that obtaining a NIC's connection status requires a non-trivial procedure.
*
*
* Argument(s) : none.
*
* Return(s) : NIC network connection status :
*
* DEF_OFF Network connection DOWN.
* DEF_ON Network connection UP.
*
* Caller(s) : NetIF_Pkt_Tx()
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN NetNIC_ConnStatusGet (void)
{
return (NetNIC_ConnStatus);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetNIC_RxPktGetSize()
*
* Description : Get network packet size from NIC.
*
* Argument(s) : none.
*
* Return(s) : Size, in octets, of NIC's next network packet.
*
* Caller(s) : NetIF_RxTaskHandler().
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_INT16U NetNIC_RxPktGetSize (void)
{
CPU_INT16U size;
size = (CPU_INT16U)ENET_RxPacketGetSize();
return (size);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetNIC_RxPkt()
*
* Description : Read network packet from NIC into buffer.
*
* Argument(s) : ppkt Pointer to memory buffer to receive NIC packet.
* ---- Argument validated in NetIF_RxTaskHandler().
*
* size Number of packet frame octets to read into buffer.
* ---- Argument checked in NetIF_RxTaskHandler().
*
* perr Pointer to variable that will hold the return error code from this function :
*
* NET_NIC_ERR_NONE Packet successfully read.
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
*
* Return(s) : none.
*
* Caller(s) : NetIF_RxTaskHandler().
*********************************************************************************************************
*/
void NetNIC_RxPkt (void *ppkt,
CPU_INT16U size,
NET_ERR *perr)
{
#if ((NET_CTR_CFG_STAT_EN == DEF_ENABLED) && \
(CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
CPU_SR cpu_sr = 0;
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -