📄 net_nic.c
字号:
* 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)
{
CPU_INT16U val;
val = CS8900_PPRegRd(PP_BusCtl); /* Read value from BusCTL register */
val |= PP_BusCtl_EnableIRQ; /* Set the bit PP_BusCtl_EnableIRQ, for cs8900 global IntEn */
CS8900_PPRegWr(PP_BusCtl, val); /* Write back to BusCTL register */
*perr = NET_NIC_ERR_NONE;
}
/*
*********************************************************************************************************
* NetNIC_ConnStatusChk()
*
* Description : Check the NIC's network connection status. This function checks the PHY to see if the
* connection is still established and sets 'NetNIC_ConnStatus' accordingly.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : ####
*
* Note(s) : (1) Check NIC connection status :
*
* (a) By NIC transmit handler(s)
* (b) By NIC status state machine
* (c) May be configured with a network timer to execute periodically
*********************************************************************************************************
*/
void NetNIC_ConnStatusChk (void)
{
CPU_INT16U phy_reg_val;
phy_reg_val = CS8900_PPRegRd(PP_LineStat); /* Read value from LineStat register */
phy_reg_val &= CS8900_Phy_Reg_Link_Mask; /* Extract the LinkOK information from the register data */
if (phy_reg_val == CS8900_Phy_Reg_Link_Mask) { /* If Link is on... */
NetNIC_ConnStatus = DEF_ON;
} else {
NetNIC_ConnStatus = DEF_OFF;
}
}
/*
*********************************************************************************************************
* 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)
{
NetNIC_ConnStatusChk();
return (NetNIC_ConnStatus);
}
/*
*********************************************************************************************************
* NetNIC_ISR_Handler()
*
* Description : (1) Decode ISR & call appropriate ISR handler :
*
* (a) CS8900 Receive Buffer Not Available ISR NetNIC_RxPktDiscard()
* (b) CS8900 Receive ISR NetNIC_RxISR_Handler()
* (c) CS8900 Transmit ISR NetNIC_TxISR_Handler()
*
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : This function is an Interrupt Service Routine
*
* Note(s) : (1) This function clears the interrupt source(s) on an external interrupt controller
* if enabled.
*********************************************************************************************************
*/
void NetNIC_ISR_Handler (void)
{
CPU_INT16U int_stat;
CPU_INT32S size;
int_stat = CS8900_RegRd(CS8900_ISQ_OFFSET);
while (int_stat != 0) {
switch (int_stat&ISQ_EventMask) {
case ISQ_RxEvent:
size = CS8900_Int_Receive(&frame_bff[frame_bff_head], int_stat);
if (size > 40) {
if (++frame_bff_head >= (CS8900_NUM_ETH_FRAME_BUF - 1)) {
frame_bff_head = 0;
}
NetNIC_RxISR_Handler();
CS8900_DBG_PRINT("ISQ_RxEvent\r\n");
} else {
CS8900_DBG_PRINT("Something wrong\r\n");
}
break;
case ISQ_TxEvent:
CS8900_DBG_PRINT("ISQ_TxEvent\r\n");
NetNIC_TxISR_Handler();
break;
case ISQ_BufEvent:
CS8900_DBG_PRINT("ISQ_BufEvent\r\n");
break;
case ISQ_RxMissEvent:
CS8900_DBG_PRINT("ISQ_RxMissEvent\r\n");
break;
case ISQ_TxColEvent:
CS8900_DBG_PRINT("ISQ_TxColEvent\r\n"); /* counter-overflow report: TxCOL (register 12) */
break;
default:
break;
}
int_stat = CS8900_RegRd(CS8900_ISQ_OFFSET);
}
#if (NET_NIC_CFG_INT_CTRL_EN == DEF_ENABLED)
NetNIC_IntClr(); /* Clr int ctrl'r CS8900 int */
#endif
}
/*
*********************************************************************************************************
* 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 = frame_bff[frame_bff_tail].size;
return (size);
}
/*
*********************************************************************************************************
* NetNIC_RxPkt()
*
* Description : Read network packet from NIC into buffer.
*
* Argument(s) : ppkt Pointer to memory buffer to receive NIC packet.
*
* size Number of packet frame octets to read into buffer.
*
* 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.
* NET_NIC_ERR_NULL_PTR Argument 'ppkt' passed a NULL pointer.
* NET_NIC_ERR_INVALID_SIZE Invalid size.
*
* Return(s) : none.
*
* Caller(s) : NetIF_RxTaskHandler().
*
* Note(s) : (1) NetNIC_RxPkt() blocked until network initialization completes; perform NO action.
*********************************************************************************************************
*/
void NetNIC_RxPkt (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 rx (see Note #2). */
*perr = NET_ERR_INIT_INCOMPLETE;
return;
}
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
/* ------------------- VALIDATE PTR ------------------- */
if (ppkt == (void *)0) {
*perr = NET_NIC_ERR_NULL_PTR;
return;
}
/* ------------------- VALIDATE SIZE ------------------ */
if (size < NET_IF_FRAME_MIN_SIZE) {
*perr = NET_NIC_ERR_INVALID_SIZE;
return;
}
#endif
CS8900_RxPkt(ppkt, size, perr); /* Rd rx pkt from NIC. */
if (*perr != NET_NIC_ERR_NONE) {
return;
}
NET_CTR_STAT_INC(NetNIC_StatRxPktCtr);
*perr = NET_NIC_ERR_NONE;
}
/*
*********************************************************************************************************
* NetNIC_RxPktDiscard()
*
* Description : Discard network packet from NIC to free NIC packet frames for new receive packets.
*
* Argument(s) : size Number of packet frame octets.
*
* perr Pointer to variable that will hold the return error code from this function :
*
* NET_NIC_ERR_NONE Packet successfully discarded.
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
*
* Return(s) : none.
*
* Caller(s) : NetIF_RxTaskHandler().
*
* Note(s) : (1) NetNIC_RxPktDiscard() blocked until network initialization completes; perform NO action.
*
* (2) #### 'perr' may NOT be necessary (remove before product release if unnecessary).
*********************************************************************************************************
*/
void NetNIC_RxPktDiscard (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 discard (see Note #1). */
*perr = NET_ERR_INIT_INCOMPLETE;
return;
}
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() : -
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -