📄 net_nic.c
字号:
}
CS8900_RxPktDiscard(size);
NET_CTR_ERR_INC(NetNIC_ErrRxPktDiscardedCtr);
*perr = NET_NIC_ERR_NONE;
}
/*
*********************************************************************************************************
* NetNIC_TxPkt()
*
* Description : Transmit data packets from network driver layer to network interface card.
*
* Argument(s) : ppkt Pointer to memory buffer to transmit NIC packet.
*
* size Number of packet frame octets to write to frame.
*
* perr Pointer to variable that will hold the return error code from this function :
*
* NET_NIC_ERR_NONE Packet successfully transmitted.
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
*
* - RETURNED BY NetNIC_TxPktDiscard() : -
* NET_ERR_TX Transmit error; packet discarded.
*
* Return(s) : none.
*
* Caller(s) : NetIF_Pkt_Tx().
*
* Note(s) : (1) NetNIC_TxPkt() blocked until network initialization completes; perform NO action.
*********************************************************************************************************
*/
void NetNIC_TxPkt (void *ppkt,
CPU_INT16U size,
NET_ERR *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
if (Net_InitDone != DEF_YES) { /* If init NOT complete, exit tx (see Note #1). */
*perr = NET_ERR_INIT_INCOMPLETE;
return;
}
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
if (ppkt == (void *)0) { /* ------------------- VALIDATE PTR ------------------- */
NetNIC_TxPktDiscard(perr);
return;
}
#endif
CS8900_TxPkt(ppkt, size, perr); /* Tx pkt to CS8900. */
if (*perr != NET_NIC_ERR_NONE) {
NetNIC_TxPktDiscard(perr);
return;
}
NET_CTR_STAT_INC(NetNIC_StatTxPktCtr);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NetNIC_RxISR_Handler()
*
* Description : Signal Network Interface Receive Task that a receive packet is available.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_ISR_Handler().
*
* Note(s) : (1) NetNIC_ISR_Handler() decodes CS8900 Receive ISR & calls NetNIC_RxISR_Handler().
*********************************************************************************************************
*/
NET_LOCAL void NetNIC_RxISR_Handler (void)
{
NET_ERR err;
/* Interrupts are acknowledged when ISR read */
/* ISR are previously read in NetNIC_ISR_Handler(). */
NetOS_IF_RxTaskSignal(&err); /* Signal Net IF Rx Task of NIC rx pkt. */
switch (err) {
case NET_IF_ERR_NONE:
break;
case NET_IF_ERR_RX_Q_FULL:
case NET_IF_ERR_RX_Q_POST_FAIL:
default:
NetNIC_RxPktDiscard(0, &err); /* If any net drv signal err, discard rx pkt. */
break;
}
}
/*
*********************************************************************************************************
* NetNIC_TxISR_Handler()
*
* Description : (1) Clear transmit interrupt &/or transmit errors :
*
* (a) Acknowledge transmit interrupt
* (b) Post transmit FIFO empty signal
*
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_ISR_Handler().
*
* Note(s) : (2) NetNIC_ISR_Handler() decodes CS8900 Transmit ISR & calls NetNIC_TxISR_Handler().
*********************************************************************************************************
*/
NET_LOCAL void NetNIC_TxISR_Handler (void)
{
/* ISR are previously read in NetNIC_ISR_Handler(). */
/* --------------- POST TX EMPTY SIGNAL --------------- */
NetOS_NIC_TxRdySignal();
}
/*
*********************************************************************************************************
* NetNIC_TxPktDiscard()
*
* Description : On any Transmit errors, set error.
*
* Argument(s) : pbuf Pointer to network buffer.
*
* perr Pointer to variable that will hold the return error code from this function :
*
* NET_ERR_TX Transmit error; packet discarded.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_TxPkt().
*
* Note(s) : none.
*********************************************************************************************************
*/
NET_LOCAL void NetNIC_TxPktDiscard (NET_ERR *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
NET_CTR_ERR_INC(NetNIC_ErrTxPktDiscardedCtr);
*perr = NET_ERR_TX;
}
/*
*********************************************************************************************************
* CS8900_Init()
*
* Description : (1) Initialize & start CS8900 :
*
* (a) Initialize Interrupts
* (b) Initialize Registers
* (c) Initialize MAC Address
* (d) Initialize RX Buffer descriptors
* (e) Initialize Auto Negotiation
* (f) Enable Receiver/Transmitter
* (g) Initialize External Interrupt Controller See Note #4
*
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_Init().
*
* Note(s) : (2) See this 'net_nic.c CS8900 REGISTER BITS' for register bit summary.
*
* (3) (a) Assumes MAC address to set has previously been initialized by
*
* (1) CS8900's EEPROM for CS8900_MAC_ADDR_SEL_EEPROM
* (2) Application code for CS8900_MAC_ADDR_SEL_CFG
*
* (b) CS8900 NIC module allows of one MAC addresses that will be
* used to accept or reject an ethernet packet.
*
* (4) Interrupts MUST be enabled ONLY after ALL network initialization is complete (see also
* 'net.c Net_Init() Note #4c').
*
* (5) This function initializes an external interrupt controller (if present) &, if ENABLED,
* MUST be developer-implemented in
*
* \<Your Product Application>\net_isr.c
*
* where
* <Your Product Application> directory path for Your Product's Application
*********************************************************************************************************
*/
NET_LOCAL void CS8900_Init (void)
{
CPU_INT16U reg_val;
#if (EMAC_CFG_MAC_ADDR_SEL == EMAC_MAC_ADDR_SEL_EEPROM)
CPU_INT16U i;
#endif
frame_bff_head = 0;
frame_bff_tail = 0;
frame_bff_num = 0;
reg_val = CS8900_Reset(); /* Step 1: software reset the chip */
if (reg_val != 0 ) {
CS8900_DBG_PRINT("CS8900 Error: Reset Failed!\r\n");
return;
}
/* Step 2: Configure RxCTL to receive good frames for */
/* Indivual Addr, Broadcast, and Multicast */
CS8900_PPRegWr(PP_RxCTL,
PP_RxCTL_RxOK | PP_RxCTL_IA | PP_RxCTL_Broadcast | PP_RxCTL_Multicast);
#if 0
CS8900_PPRegWr(PP_RxCTL,
PP_RxCTL_Promiscuous | PP_RxCTL_RxOK); /* Step 3: OR set to Promiscuous mode to receive all traffic */
#endif
CS8900_PPRegWr(PP_TestCTL, 0); /* Step 4: Configure TestCTL (DuplexMode) */
/* default: 0:half duplex; 0x4000=Full duplex */
CS8900_PPRegWr(PP_LineCTL, /* Step 5: Set SerRxOn, SerTxOn in LineCTL */
PP_LineCTL_Rx | PP_LineCTL_Tx);
CS8900_PPRegWr(PP_IntReg, 0); /* Step 6: Set the IRQ number in the chip */
/* 0:IRQ10; 1:IRQ11 2:IRQ12 3:IRQ5 */
/* Step 7: Initialize RxCFG register for Rx Event Interrupt */
/* Accept good and bad Rx frames */
CS8900_PPRegWr(PP_RxCFG,
PP_RxCFG_RxOK | PP_RxCFG_CRC | PP_RxCFG_RUNT | PP_RxCFG_EXTRA);
#if 0
CS8900_PPRegWr(PP_RxCFG, PP_RxCFG_RxOK ); /* Or just accept good Rx frames and don't worry */
#endif /* about Rx statistics including details for bad ones. */
CS8900_PPRegWr(PP_TxCFG, PP_TxCFG_ALL_IE); /* Step 8: Initialize TxCFG register for Tx Event Interrupt */
/* Enable all Tx IEs. Please refer to cs8900.h for */
/* what Tx interrupts are available enabled. */
CS8900_PPRegWr(PP_BufCFG, PP_BufCFG_TxRDY); /* Step 9: Enable interrupt when ready for Tx */
#if (EMAC_CFG_MAC_ADDR_SEL == EMAC_MAC_ADDR_SEL_EEPROM) /* MAC address is fetched from EMAC EEPROM */
for (i = 0; i < sizeof(NetIF_MAC_Addr); i += sizeof(CPU_INT16U)) {
reg_val = CS8900_PPRegRd(PP_IA + i);
NetIF_MAC_Addr[i] = (CPU_INT08U) reg_val;
NetIF_MAC_Addr[i + 1] = (CPU_INT08U)(reg_val >> DEF_OCTET_NBR_BITS);
}
#else
reg_val = (NetIF_MAC_Addr[1] << DEF_OCTET_NBR_BITS) | NetIF_MAC_Addr[0];
CS8900_PPRegWr(PP_IA + 0, reg_val);
reg_val = (NetIF_MAC_Addr[3] << DEF_OCTET_NBR_BITS) | NetIF_MAC_Addr[2];
CS8900_PPRegWr(PP_IA + 2, reg_val);
reg_val = (NetIF_MAC_Addr[5] << DEF_OCTET_NBR_BITS) | NetIF_MAC_Addr[4];
CS8900_PPRegWr(PP_IA + 4, reg_val);
#endif
#if 0
CS8900_DBG_PRINT("MAC addr : %x %x %x %x %x %x\r\n",
NetIF_MAC_Addr[0],
NetIF_MAC_Addr[1],
NetIF_MAC_Addr[2],
NetIF_MAC_Addr[3],
NetIF_MAC_Addr[4],
NetIF_MAC_Addr[5]);
#endif
NetIF_MAC_AddrValid = DEF_YES;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -