📄 net_nic.c
字号:
*
* 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;
CPU_INT16U phy_reg_link_mask;
phy_reg_val = LAN91C111_PhyRegRd(LAN91C111_PHY_REG_STATUS);
phy_reg_link_mask = LAN91C111_PHY_REG_STATUS_NEG_ACK | LAN91C111_PHY_REG_STATUS_LINK_OK;
if (phy_reg_val & phy_reg_link_mask) {
NetNIC_ConnStatus = DEF_ON;
} else {
NetNIC_ConnStatus = DEF_OFF;
}
}
/*$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_ISR_Handler()
*
* Description : (1) Decode ISR & call appropriate ISR handler :
*
* (a) LAN91C111 Receive ISR NetNIC_RxISR_Handler()
* (b) LAN91C111 Transmit ISR NetNIC_TxISR_Handler()
*
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_ISR() [see Note #2].
*
* Note(s) : (2) LAN91C111 ISR MUST call NetNIC_ISR_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 suorce(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_ISR_Handler (void)
{
CPU_INT16U int_reg;
CPU_INT08U int_en;
CPU_INT08U int_act;
/* ------------ DETERMINE NIC INT SRC ------------- */
int_reg = LAN91C111_RegRd(LAN91C111_REG_INT_BANK,
LAN91C111_REG_INT_OFFSET);
int_en = (int_reg & LAN91C111_REG_INT_MASK_EN ) >> 8; /* Get en'd ints. */
int_act = (int_reg & LAN91C111_REG_INT_MASK_STATUS) & int_en; /* Determine which en'd ints active. */
/* ------------- HANDLE ENABLED INTS -------------- */
if (int_act & LAN91C111_REG_INT_RX) {
NetNIC_RxISR_Handler();
}
if (int_act & LAN91C111_REG_INT_TX) {
NetNIC_TxISR_Handler();
}
#if (NET_NIC_CFG_INT_CTRL_EN == DEF_ENABLED)
NetNIC_IntClr(); /* Clr int ctrl'r LAN91C111 int (see Note #3). */
#endif
}
/*$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 = LAN91C111_RxPktGetSize();
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().
*
* Note(s) : (1) NetNIC_RxPkt() blocked until network initialization completes; perform NO action.
*
* (2) After packet read is complete or on any error, receive interrupts MUST be re-ENABLED
* (see also 'NetNIC_RxISR_Handler() Note #2').
*********************************************************************************************************
*/
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;
#endif
if (Net_InitDone != DEF_YES) { /* If init NOT complete, exit rx (see Note #1). */
*perr = NET_ERR_INIT_INCOMPLETE;
return;
}
LAN91C111_RxPkt(ppkt, size); /* Rd rx pkt from NIC. */
LAN91C111_RxIntEn(); /* See Note #2. */
NET_CTR_STAT_INC(NetNIC_StatRxPktCtr);
*perr = NET_NIC_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* 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 ((NET_CTR_CFG_ERR_EN == DEF_ENABLED)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -