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

📄 cs8900_enet_eeprom_driver.c

📁 sharp的arm920t 7A400的评估板附带光盘Sharp KEVLH7A400 v0.3b Welcome to the SHARP KEV7A400 Evaluation board
💻 C
字号:
/**********************************************************************
 *  $Workfile:   CS8900_enet_eeprom_driver.c  $
 *  $Revision:   1.1  $
 *  $Author:   MaysR  $
 *  $Date:   Aug 29 2002 08:55:44  $
 *
 *  Project: 
 *
 *  Description: Functions for programming the CS8900A ethernet 
 *               controller EEPROM.
 *
 *	References: CS8900A chip user's guide
 *
 *	Revision History:
 *  $Log:   //smaicnt2/pvcs/VM/CHIPS/archives/LH7A400/Ethernet/Drivers/CS8900_enet_eeprom_driver.c-arc  $
 * 
 *    Rev 1.1   Aug 29 2002 08:55:44   MaysR
 * Corrected parameter types for set IRQ and set DMA functions.
 * 
 *    Rev 1.0   Aug 27 2002 11:41:04   MaysR
 * Initial revision.
 * 
 * 
 * SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
 * OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
 * AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES, 
 * SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
 *
 * SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY 
 * FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A 
 * SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
 * FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
 *
 *	COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *		CAMAS, WA
 *
 *********************************************************************/

#include <stdio.h>

#include "CS8900_enet_if_driver.h"
#include "CS8900_enet_eeprom_driver.h"

#define ENET_EEP_BLK1_HDR       0x2020
#define ENET_EEP_BLK2_HDR       0x502C
#define ENET_EEP_BLK3_HDR       0x2158

struct
{
    const   UNS_16  blk_header;
    const   UNS_16  gp1_header;
            UNS_16  io_base;
            UNS_16  irq_num;
            UNS_16  dma_num;
    const   UNS_16  gp2_header;
            UNS_16  mem_base_low;
            UNS_16  mem_base_hi;
            UNS_16  prom_base_low;
            UNS_16  prom_base_hi;
            UNS_16  prom_add_mask_low;
            UNS_16  prom_add_mask_hi;
    const   UNS_16  gp3_header;
            UNS_16  mac_octet_01;
            UNS_16  mac_octet_23;
            UNS_16  mac_octet_45;
            UNS_16  checksum;
}enet_eeprom[] = 
    { 
        (UNS_16) ENET_EEP_HDR, 
        (UNS_16) ENET_EEP_BLK1_HDR,
        0x300,
        0x3,
        0x1,
        (UNS_16)ENET_EEP_BLK2_HDR,
        0x0,
        0x0,
        0x0,
        0x0,
        0x0,
        0x0,
        (UNS_16)ENET_EEP_BLK3_HDR,
        0x0,
        0x0,
        0x0
    };

/*********************************************************************
*
* Function: enet_wait_for_eeprom
*
* Purpose:  ethernet controller wait for eeprom to be ready
*  
* Parameters:
*
* Returns: 
*
* Notes:
**********************************************************************/
void enet_wait_for_eeprom(void)
{
   UNS_16 volatile temp;

   enet_set_pp_addr (&enet_pp_data->stco_regs.reg16_selfst, 0);
   temp = SIBUSY;
   while ((temp & SIBUSY) == SIBUSY)
   {
      temp = enet_read_data();
   }
}

/*********************************************************************
*
* Function: enet_e2_calc_cksum
*
* Purpose:  Compute the 2's complement checksum of the EEPROM structure.
*  
* Parameters:  None
*
* Returns:  None.
*
* Notes:  The checksum is stored in the EEPROM data structure.
 * 
**********************************************************************/
void enet_e2_calc_cksum(void)
{
    UNS_32 temp, idx;
    UNS_8 *enet_vals;
     
    enet_vals = (UNS_8 *)enet_eeprom;
    temp = 0;
    for (idx = 0; idx < (sizeof(enet_eeprom) - 1); idx++)
    {
        temp += enet_vals[idx];
    }
// Checksum is computed as 2's-complement of data
    enet_eeprom->checksum = (0xFF - (temp & 0xFF) + 1) << 8;
}

/**********************************************************************
 *
 * Function: enet_8900e2_set_mac
 *
 * Purpose:  Set the MAC address in the EEPROM data structure
 *  
 * Processing:  Set up the ethernet controller EEPROM data structure 
 *              with the ethernet controller MAC address.
 *
 * Parameters:  mac_addr: Pointer to the ethernet address array.
 *
 * Outputs:  None
 *
 * Returns:  Nothing
 *
 * Notes:  Converts ethernet address to 3 16bit values
 *
 *********************************************************************/
void enet_8900e2_set_mac(UNS_8 *mac_addr)
{
    enet_eeprom->mac_octet_01 = (mac_addr[1] << 8) + mac_addr[0];
    enet_eeprom->mac_octet_23 = (mac_addr[3] << 8) + mac_addr[2];
    enet_eeprom->mac_octet_45 = (mac_addr[5] << 8) + mac_addr[4];
}

/**********************************************************************
 *
 * Function:  enet_8900e2_set_io
 *
 * Purpose:  Set the IO base address
 *  
 * Processing:  Set the ethernet controller EEPROM data structure 
 *              with the ethernet controller I/O base address.
 *
 * Parameters:  : Value to set the I/O base address to
 *
 * Outputs:  None
 *
 * Returns:  Nothing
 *
 * Notes:  None
 *
 *********************************************************************/
void enet_8900e2_set_io(UNS_16 io_base_addr)
{
    enet_eeprom->io_base = io_base_addr;
}

/**********************************************************************
 *
 * Function:  enet_8900e2_set_irq
 *
 * Purpose:  Set the IRQ number that the CS8900 will use
 *  
 * Processing:  Set the ethernet controller EEPROM data structure 
 *              with the ethernet controller IRQ number.
 *
 * Parameters:  irq_value: Value to set the IRQ number to
 *
 * Outputs:  None
 *
 * Returns:  Nothing
 *
 * Notes:  None
 *
 *********************************************************************/
void enet_8900e2_set_irq(enet_int_t irq_value)
{
    enet_eeprom->irq_num = irq_value;
}

/**********************************************************************
 *
 * Function:  enet_8900e2_set_dma
 *
 * Purpose:  Set the DMA channel that the CS8900 will use
 *  
 * Processing:  Set the ethernet controller EEPROM data structure 
 *              with the ethernet controller DMA channel.
 *
 * Parameters:  dma_num: Value to set the DMA channel to
 *
 * Outputs:  None
 *
 * Returns:  Nothing
 *
 * Notes:  None
 *
 *********************************************************************/
void enet_8900e2_set_dma(enet_dma_t dma_num)
{
    enet_eeprom->dma_num = dma_num;
}

/**********************************************************************
 *
 * Function: enet_8900e2_erase_all
 *
 * Purpose:  Erase the 8900A EEPROM.
 *  
 * Processing:  This function erases the ethernet controller EEPROM 
 *
 * Parameters:  None.
 *
 * Outputs:  None
 *
 * Returns:  Nothing
 *
 * Notes:  Should not need to call enet_set_pp_addr, but if the driver
 *         is used by an RTOS, pre-empting may occur.  Testing for the 
 *         BUSY bit should be used, and a methode of locking out EEPROM
 *         accesses should be implemented as well.
 *
 **********************************************************************/
void enet_8900e2_erase_all(void)
{
    enet_8900e2_ew_enable();
    enet_set_pp_addr(&enet_pp_data->bus_regs.eeprom_cmd, 0);
    enet_write_data(EEPROM_ERASE_ALL);
    enet_wait_for_eeprom();
    enet_8900e2_ew_enable();
}

/**********************************************************************
 *
 * Function: enet_8900e2_ew_enable
 *
 * Purpose:   the 8900A EEPROM.
 *  
 * Processing:  
 *
 * Parameters:  None.
 *
 * Outputs:  None
 *
 * Returns:  Nothing
 *
 * Notes:  
 *
 **********************************************************************/
void enet_8900e2_ew_enable(void)
{
    enet_wait_for_eeprom();
    enet_set_pp_addr(&enet_pp_data->bus_regs.eeprom_cmd, 0);
    enet_write_data(EEPROM_EW_ENABLE);
    enet_wait_for_eeprom();
}

/**********************************************************************
 *
 * Function: enet_8900e2_ew_disable
 *
 * Purpose:   the 8900A EEPROM.
 *  
 * Processing:  
 *
 * Parameters:  None.
 *
 * Outputs:  None
 *
 * Returns:  Nothing
 *
 * Notes:  
 *
 **********************************************************************/
void enet_8900e2_ew_disable(void)
{
    enet_wait_for_eeprom();
    enet_set_pp_addr(&enet_pp_data->bus_regs.eeprom_cmd, 0);
    enet_write_data(EEPROM_EW_DISABLE);
    enet_wait_for_eeprom();
}

/**********************************************************************
 *
 * Function: enet_8900e2_update
 *
 * Purpose:  Write the EEPROM data structure to the 8900A EEPROM.
 *  
 * Processing:  
 *
 * Parameters:  None.
 *
 * Outputs:  None
 *
 * Returns:  Nothing
 *
 * Notes:  There is no error checking for this function.  It expects 
 *         the data structure to be complete and ready to write. 
 *         It re-calculates the checksum before writing.
 *
 **********************************************************************/
void enet_8900e2_update(void)
{
    UNS_16 idx;
    UNS_16 *enet_vals;

    enet_e2_calc_cksum();
    enet_vals = (UNS_16 *)enet_eeprom;
    enet_8900e2_erase_all();
    enet_8900e2_ew_enable();
    for (idx = 0; idx < (sizeof(enet_eeprom) / 2); idx++)
    {
      // Write data to be written to EEPROM into data holding register
        enet_set_pp_addr(&enet_pp_data->bus_regs.eeprom_data, 0);
        enet_write_data(enet_vals[idx]);
      
      // Send out data at correct EEPROM address
        enet_set_pp_addr(&enet_pp_data->bus_regs.eeprom_cmd, 0);
        enet_write_data(EEPROM_WRITE | idx);
        enet_wait_for_eeprom();
    }
    enet_8900e2_ew_disable();
}

⌨️ 快捷键说明

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