⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lan.c

📁 基于psos操作系统的ns8390驱动源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*              This data buffer should come from a area of memory     */
/*              that can be seen by the processor and the lan chip.    */
/*              The lan chip should beable to DMA to or from this      */
/*              data buffer.                                           */
/*                                                                     */
/***********************************************************************/
static UCHAR *ni_getpkb(void)
{

/*---------------------------------------------------------------------*/
/*  Additional Code Here to get the data buffer and return a pointer   */
/*  to it.                                                             */
/*---------------------------------------------------------------------*/

}

/***********************************************************************/
/* ni_retpkb: Return a previously allocated data buffer to memory      */
/*                                                                     */
/*      INPUTS: address of data buffer                                 */
/*                                                                     */
/*     RETURNS: always returns 0                                       */
/*     OUTPUTS: NONE                                                   */
/*     NOTE(S): This function returns a data buffer from the protocol  */
/*              layer after it is done with it. This function should   */
/*              do whatever is necessary to free the memory for reuse. */
/*                                                                     */
/***********************************************************************/
static ULONG ni_retpkb(char *data)
{

/*---------------------------------------------------------------------*/
/*  Additional Code Here to free the data buffer.                      */
/*---------------------------------------------------------------------*/

}

/***********************************************************************/
/* ni_send: Send a buffer filled with data                             */
/*                                                                     */
/*      INPUTS: hwa_ptr: pointer to hardware destination address       */
/*              buff_addr: address of buffer                           */
/*              count: length of buffer in bytes                       */
/*              type: type of packet                                   */
/*     RETURNS: Always returns 0                                       */
/*     OUTPUTS: NONE                                                   */
/*     NOTE(S): This function should send the packet accross the       */
/*              network.                                               */
/*                                                                     */
/***********************************************************************/
static ULONG ni_send(char *hwa_ptr, char *buff_addr, long type)
{

/*---------------------------------------------------------------------*/
/* Get the pointer to the first message block.                         */
/*---------------------------------------------------------------------*/
mblk_t *mblkPtr = (mblk_t *)buff_addr;

/*---------------------------------------------------------------------*/
/* Each message block contains a write pointer "b_wptr" and a read     */
/* pointer "b_rptr". If these are equal it means there is no more      */
/* data in the message block. When there is no more data in the        */
/* message block the code should check to see if there are any         */
/* continuation blocks "b_cont" and if there are send the date in      */
/* those also                                                          */
/*---------------------------------------------------------------------*/
while (mblkPtr != 0)
    {
    if (mblkPtr->b_wptr == mblkPtr->b_rptr)
        {
        mblkPtr = mblkPtr->b_cont;
        continue;
        }

    /*-----------------------------------------------------------------*/
    /*  Additional Code Here to send data.                             */
    /*-----------------------------------------------------------------*/
    }
}

/***********************************************************************/
/* ni_broadcast: Broadcast a packet filled with data                   */
/*                                                                     */
/*      INPUTS: buff_addr: pointer to data buffer                      */
/*              count: length of buffer in bytes                       */
/*              type: type of packet                                   */
/*     RETURNS: Always returns 0                                       */
/*     OUTPUTS: NONE                                                   */
/*     NOTE(S): This function should set up a hardware broadcast       */
/*              address and call ni_send to send the packet.           */
/*                                                                     */
/***********************************************************************/
static ULONG ni_broadcast(char *buff_addr, long type)
{
char hwa_ptr[7] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0};
 
return ni_send(hwa_ptr, buff_addr, type);
}

/***********************************************************************/
/* ni_poll: Polling function                                           */
/*                                                                     */
/*      INPUTS: NONE                                                   */
/*                                                                     */
/*     RETURNS: Always returns 0                                       */
/*     OUTPUTS: NONE                                                   */
/*     NOTE(S): Checks if interrupt is pending.  If so, the ISR thread */
/*              is executed                                            */
/*              BD_LAN_INT_PENDING is a board  dependent #define that  */
/*              should be in board.h. It is a test for a interrupt.    */
/*                                                                     */
/***********************************************************************/
static ULONG ni_poll(void)
{
IMASK imask;
 
/*---------------------------------------------------------------------*/
/* Disable interrupts                                                  */
/*---------------------------------------------------------------------*/
imask = splx(MAX_ILEV);
 
/*---------------------------------------------------------------------*/
/* If an 82596CA interrupt is pending, service the interrupt.          */
/*---------------------------------------------------------------------*/
if(BD_LAN_INT_PENDING)
    lan_isr();
 
/*---------------------------------------------------------------------*/
/* Restore Interrupts and Return                                       */
/*---------------------------------------------------------------------*/
splx(imask);
return 0;
}

/***********************************************************************/
/* LanStop: Disable the LAN chip's DMA to memory.                      */
/*                                                                     */
/*      INPUTS: NONE                                                   */
/*                                                                     */
/*     RETURNS: NONE                                                   */
/*     OUTPUTS: NONE                                                   */
/*     NOTE(S): This function is called from InitBoard() to disable    */
/*              LAN DMA.  If  the LAN driver was used before           */
/*              InitBoard() is run (for example, to tftp download a    */
/*              system), the DMA will continue, in response to         */
/*              broadcast packets, unless explicitly stopped.          */
/*                                                                     */
/***********************************************************************/
void LanStop(void)
{

/*---------------------------------------------------------------------*/
/* Additional Code Here to to stop chip.                               */
/*---------------------------------------------------------------------*/

}

/***********************************************************************/
/* lan_isr: Interrupt handler for the lan chip.                        */
/*                                                                     */
/*      INPUTS: NONE                                                   */
/*                                                                     */
/*     RETURNS: psos_up_flag gotten from call to announce packet       */
/*              This return value is checked in the NI_WRAPPER to see  */
/*              if the ISR should use I_RETURN (return through psos)   */
/*              or not.                                                */
/*     OUTPUTS: NONE                                                   */
/*       NOTES: This is invoked every time the lan chip interrupts the */
/*              CPU.  It is also invoked with every call to ni_poll(), */
/*              if the chip has something pending.                     */
/*                                                                     */
/***********************************************************************/
static ULONG lan_isr(void)
{
UCHAR *frame;                        /* pointer to the frame received  */
ULONG count;                         /* number of bytes in the fram    */ 
ULONG src_addr;                      /* source address of the frame    */ 
ULONG dist_addr;                     /* distention address of the frame*/ 

frame = (UCHAR *)0;

/*---------------------------------------------------------------------*/
/* Add code here to find out what driver wa interrupted for            */
/* If the driver was interrupted because of a received frame then      */
/* set the variable frame to point to it. Take care of all other       */
/* interrupts here.                                                    */
/*---------------------------------------------------------------------*/

if(frame)
    {
    imask = splx(MAX_ILEV);

    /*-----------------------------------------------------------------*/
    /* Collect the total octets received for MIB                       */
    /*-----------------------------------------------------------------*/
    
    MG_stat.inoctets += count&0x3fff;
     
    /*-----------------------------------------------------------------*/
    /* Collect stats for MIB on broadcast or unicast packets.          */
    /* NOTE: packets are broadcast backets if first 6 bytes are FF     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -