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

📄 lan_saa9730.c

📁 MIPS YAMON, a famous monitor inc. source, make file and PDF manuals.
💻 C
📖 第 1 页 / 共 5 页
字号:
 *  'OK'(=0) * * * ************************************************************************/staticINT32 LAN_SAA9730_open(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          t_LAN_OPEN_desc *p_param ) ; /* IN: receive handler reference *//************************************************************************ * *                          LAN_SAA9730_read *  Description : *  ------------- *  This service polls the specified LAN interface for any received frame. *  If any frame has been received, it will be read into the user allocated *  variable, *p_param; if none present, completion = 'ERROR_LAN_NO_FRAME' *  will be returned. *   * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    minor device number for multi device drivers *  'p_param',   INOUT, LAN variable of type, t_LAN_IO_desc. * * *  Return values : *  --------------- * *  'OK'(=0) *  'ERROR_LAN_NO_FRAME':     no frame present on this LAN interface *  'ERROR_LAN_COMM_ERROR':   communication error detected * * ************************************************************************/staticINT32 LAN_SAA9730_read(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          t_LAN_IO_desc *p_param ) ; /* INOUT: LAN frame           *//************************************************************************ * *                          LAN_SAA9730_write *  Description : *  ------------- *  This service requests transmission of a frame on the LAN interface. *   * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    minor device number for multi device drivers *  'p_param',   INOUT, LAN variable of type, t_LAN_IO_desc. * * *  Return values : *  --------------- * *  'OK'(=0) *  'ERROR_LAN_COMM_ERROR':   communication error detected * * ************************************************************************/staticINT32 LAN_SAA9730_write(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          t_LAN_IO_desc *p_param ) ; /* OUT: frame to transmit     *//************************************************************************ * *                          LAN_SAA9730_ctrl *  Description : *  ------------- *  This service requests special service via 'ctrl' *   * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    minor device number for multi device drivers *  'p_param',   INOUT, LAN variable of type, t_LAN_IO_desc. * * *  Return values : *  --------------- * *  'OK'(=0) * * ************************************************************************/staticINT32 LAN_SAA9730_ctrl(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          t_LAN_CTRL_desc *p_param ) ; /* IN-OUT:                       *//************************************************************************ *      Implementation : Public functions ************************************************************************//************************************************************************ * *                          LAN_SAA9730_install *  Description : *  ------------- * *  Installs the SAA9730 LAN device drivers services in  *  the IO system at the reserved device slot, found in the *  'sysdev.h' file, which defines all major device numbers. * *  Note: *  This service is the only public declared interface function; all *  provided device driver services are static declared, but this *  function installs the function pointers in the io-system to *  enable the provided public driver services. * *  Parameters : *  ------------ * *  - * * *  Return values : *  --------------- * *  'OK'(=0) *  'ERROR_IO_ILLEGAL_MAJOR':  Illegal major device number *  'ERROR_IO_NO_SPACE':       Device slot already allocated * ************************************************************************/INT32 LAN_SAA9730_install( void ){    /* pre-initialize local variables and install device services */    memset( minor_device, sizeof(minor_device), 0) ;    IO_install(   SYS_MAJOR_LAN_SAA9730, /* major device number */           (t_io_service) LAN_SAA9730_init,      /* 'init'  service     */           (t_io_service) LAN_SAA9730_open,      /* 'open'  service     */                          NULL,                  /* 'close' service  na */           (t_io_service) LAN_SAA9730_read,      /* 'read'  service     */           (t_io_service) LAN_SAA9730_write,     /* 'write' service     */           (t_io_service) LAN_SAA9730_ctrl ) ;   /* 'ctrl'  service     */    /* Initialize SAA9730 LAN device driver */    if( IO_init( SYS_MAJOR_LAN_SAA9730, 0, NULL ) != OK )    {        /* Should not happen unless board is defect */        IO_deinstall( SYS_MAJOR_LAN_SAA9730 );    }    return OK;}/************************************************************************ *      Implementation : Static functions ************************************************************************//************************************************************************ *      Implementation : Local helper functions ************************************************************************//************************************************************************ * *                         LAN_SAA9730_enable_buffer *  Description : *  ------------- *  *  Enable next receive buffer. *  * *  Parameters : *  ------------ * *  buffer_index                  Index for next buffer to be enabled * *  Return values : *  --------------- * *  - * ************************************************************************/staticvoid LAN_SAA9730_enable_buffer( t_LAN_SAA9730_device *pdevice,                                UINT32               buffer_index ){    UINT32  *pPacket;    int     j ;    /* Enable RX buffer */    for ( j= 0; j < LAN_SAA9730_RCV_Q_SIZE; j++ )    {        pPacket     = (UINT32* )pdevice->RcvBuffer[buffer_index][j];        REG( pPacket, RXPACKET_STATUS ) = cpu_to_le32(( RX_READY << RXPACKET_STATUS_FLAG_SHF )) ;    }    REG( pdevice->p9730Regs, LAN_OK2USE ) |= (buffer_index == 0)                                              ? LAN_OK2USE_RXA_MSK                                              : LAN_OK2USE_RXB_MSK ;}/************************************************************************ * *                          LAN_SAA9730_allocate_buffers *  Description : *  ------------- *     This routine allocates memory for: * *     - Receive buffers *     - Transmit buffer *   * *  Parameters : *  ------------ * *  'pdevice',     IN,    reference for this device  context * * *  Return values : *  --------------- * *  'OK'(=0) * * * ************************************************************************/staticINT32 LAN_SAA9730_allocate_buffers( t_LAN_SAA9730_device *pdevice )  {    INT32                rcode ;    t_sys_malloc         mem ;    UINT32               Pa;    UINT32               i, j ;    if (lan_dma_buffers == 0)    {        /* first time initialization */        /* allocate all RX and TX packets in one chunk on a 2K boundary */        mem.size     = (LAN_SAA9730_RCV_Q_SIZE  + LAN_SAA9730_TXM_Q_SIZE) *                        LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_BUFFERS ;        mem.boundary = LAN_SAA9730_PACKET_SIZE ;        mem.memory   = (void*)&Pa ;        /* request RX and TX memory in one chunk */        rcode = SYSCON_read( SYSCON_BOARD_MALLOC_ID,                             &mem,                             sizeof(t_sys_malloc) ) ;        if (rcode != OK)        {            return( rcode ) ;        }            /* cache this reference */        lan_dma_buffers = Pa ;    }    else    {        /* not first time initialization */        Pa = lan_dma_buffers ;    }    /* Initialize buffer space */    mem.size     = (LAN_SAA9730_RCV_Q_SIZE  + LAN_SAA9730_TXM_Q_SIZE) *                    LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_BUFFERS ;    Pa = KSEG1(Pa) ;    memset( (void *)Pa, 0, mem.size ) ;    /* Init RX buffers */    for ( i=0; i < 2; i++ )    {        for ( j= 0; j < LAN_SAA9730_RCV_Q_SIZE; j++ )        {            REG( Pa, RXPACKET_STATUS ) = 0 ;            pdevice->RcvBuffer[i][j]   = Pa;            Pa += LAN_SAA9730_PACKET_SIZE ;        }    }    /* Init TX buffers */    for ( i=0; i < 2; i++ )    {        for ( j= 0; j < LAN_SAA9730_TXM_Q_SIZE; j++ )        {            REG( Pa, TXPACKET_STATUS ) = cpu_to_le32(( TX_EMPTY << TXPACKET_STATUS_FLAG_SHF )) ;            pdevice->TxmBuffer[i][j]   = Pa;            Pa += LAN_SAA9730_PACKET_SIZE ;        }    }    /* Initialize Buffer Index */    pdevice->NextRcvPacketIndex = 0;    pdevice->NextRcvToUseIsA    = TRUE;    /* Set current buffer index & next availble packet index */    pdevice->NextTxmPacketIndex = 0;    pdevice->NextTxmBufferIndex = 0;    return( OK );}/************************************************************************ * *                          LAN_SAA9730_stop *  Description : *  ------------- *   This routine stops the SAA9730 LAN controller *   by stoping  DMA transfer and resetting the chip. *   * *  Parameters : *  ------------ * *  'pdevice',     IN,    reference for this device  context * * *  Return values : *  --------------- * *  'OK'(=0) * * * ************************************************************************/staticINT32 LAN_SAA9730_stop( t_LAN_SAA9730_device *pdevice )              {    /* Stop DMA first */    REG( pdevice->p9730Regs, LAN_DMACTL ) &= ~LAN_DMACTL_ENTX_SET ;    REG( pdevice->p9730Regs, LAN_DMACTL ) &= ~LAN_DMACTL_ENRX_SET ;    /* Stop any transmit or receive activity */    REG( pdevice->p9730Regs, LAN_TXCTL )  &= ~LAN_TXCTL_ENTX_SET ;    REG( pdevice->p9730Regs, LAN_RXCTL )  &= ~LAN_RXCTL_RXEN_SET ;    /* Set the SW Reset bits in DMA and MAC control registers */    REG( pdevice->p9730Regs, LAN_DMATST ) |= LAN_DMATST_RESET_SET ;    REG( pdevice->p9730Regs, LAN_MACCTL ) |= LAN_MACCTL_RESET_SET ;    LAN_SAA9730_state = LAN_SAA9730_DRIVER_IS_STOPPED ;    return( OK );}/************************************************************************ * *                          LAN_SAA9730_CAM_init *  Description : *  ------------- *    Initialize the SAA9730 LAN CAM *   * *  Parameters : *  ------------ * *  'pdevice',     IN,    reference for this device  context * * *  Return values : *  --------------- * *  'OK'(=0) * * * ************************************************************************/staticINT32 LAN_SAA9730_CAM_init( t_LAN_SAA9730_device *pdevice )          {    UINT32     rcode ;    UINT32     i;    t_mac_addr mac_addr ;    /* get MAC address from board */    IF_ERROR( (rcode),              (SYSCON_read( SYSCON_COM_EN0_MAC_ADDR_ID,      

⌨️ 快捷键说明

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