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

📄 seeddm642_eeprom.c

📁 DSP DM642 eeprom检测程序
💻 C
字号:
/********************************************************************/
/*  Copyright 2004 by SEED Incorporated.							*/
/*  All rights reserved. Property of SEED Incorporated.				*/
/*  Restricted rights to use, duplicate or disclose this code are	*/
/*  granted through contract.									    */
/*  															    */
/********************************************************************/

/*
 *  ======== seeddm642_eeprom.c ========
 *  I2C EEPROM module implementation for SEED-DM642 
 */

#include <std.h>
#include <csl.h>
#include <csl_gpio.h>
#include <csl_i2c.h>
#include "seeddm642_eeprom.h"

I2C_Config eepromRcvCfg = {
    0x0000007f, /* I2COAR -    Not used if master */
    0x00000000, /* I2CIER -    Disable interrupts, use polling */
    0x0000001b, /* I2CCLKL -   Low period for 100KHz operation */
    0x0000001b, /* I2CCLKH -   High period for 100KHz operation */
    0x00000002, /* I2CCNT -    Data words per transmission */
    0x00000057, /* I2CSAR -    Slave address */
    0x000044a0, /* I2CMDR -    Mode */
    0x00000019  /* I2CPSC -    Prescale 300MHz to 12MHz */
};

I2C_Config eepromXmtCfg = {
    0x0000007f, /* I2COAR -    Not used if master */
    0x00000000, /* I2CIER -    Disable interrupts, use polling */
    0x0000001b, /* I2CCLKL -   Low period for 100KHz operation */
    0x0000001b, /* I2CCLKH -   High period for 100KHz operation */
    0x00000002, /* I2CCNT -    Data words per transmission */
    0x00000057, /* I2CSAR -    Slave address */
    0x000046a0, /* I2CMDR -    Mode */
    0x00000019  /* I2CPSC -    Prescale 300MHz to 12MHz */
};

/*
 *  ======== SEEDDM642_eeprom_read ========
 *  Read data from an I2C EEPROM
 */
void SEEDDM642_EEPROM_read(I2C_Handle hI2C,
						  Uint32 src, 
						  Uint32 dst, 
						  Uint32 length)
{
    Uint8 *pdst;
    Uint32 i;
    I2C_Config prevI2CCfg;
        
    /*将IIC总线切换到IIC1*/
    GPIO_RSET(GPGC,0x0);/*将GPIO0不做为GPINT使用*/
	GPIO_RSET(GPDIR,0x1);/*将GPIO0做为输出*/
	GPIO_RSET(GPVAL,0x1);/*GPIO0输出为高,选择IIC1总线1*/
	/*delay for a while*/
	SEEDDM642_waitusec(1);
    /* Establish destination pointer */
    pdst = (Uint8 *)dst;
    /* Wait until bus is free */
    while (I2C_bb(hI2C));

    /* Save old settings */
    I2C_getConfig(hI2C, &prevI2CCfg);
    
    /* Set address using dummy write */
    SEEDDM642_EEPROM_write(hI2C,0, src, 0);

    /* Configure for receive */
    I2C_config(hI2C, &eepromRcvCfg);
    SEEDDM642_waitusec(1);
  
    /* Generate start condition */
    I2C_start(hI2C);

    /* Receive the data */
    for (i = 0; i < length; i++)
    {
        while(!I2C_rrdy(hI2C));
        *pdst++ = I2C_readByte(hI2C);
    }

    /* Generate stop condition */
    I2C_sendStop(hI2C);
    
    /* Need to wait at least 10ms */
    SEEDDM642_waitusec(10000);

    /* Wait until bus is free */
    while (I2C_bb(hI2C));
        
    /* Reconfigure I2C with old settings */
    I2C_config(hI2C, &prevI2CCfg);
}

/*
 *  ======== SEEDDM642_eeprom_write ========
 *  Write data to an I2C EEPROM
 */
void SEEDDM642_EEPROM_write( I2C_Handle hI2C,
							 Uint32 src, 
							 Uint32 dst, 
							 Uint32 length)
{
    Uint8 *psrc;
    Uint32 i;
    I2C_Config prevI2CCfg;
    /*将IIC总线切换到IIC1*/
    GPIO_RSET(GPGC,0x0);/*将GPIO0不做为GPINT使用*/
	GPIO_RSET(GPDIR,0x1);/*将GPIO0做为输出*/
	GPIO_RSET(GPVAL,0x1);/*GPIO0输出为高,选择IIC1总线1*/    
    /* Establish source pointer */
    psrc = (Uint8 *)src;
    
    /* Wait until bus is free */
    while (I2C_bb(hI2C));
    
    /* Clear bus busy */
    I2C_FSETH(hI2C, I2CSTR, BB, 1);

    /* Save old settings */
    I2C_getConfig(hI2C, &prevI2CCfg);
    
    /* Configure for transmit */
    I2C_config(hI2C, &eepromXmtCfg);
    SEEDDM642_waitusec(1);
        
    /* Submit the high address byte */
    I2C_writeByte(hI2C, (dst & 0xff00) >> 8);
    
    /* Generate start condition */
    I2C_start(hI2C);
    
    while(!I2C_xrdy(hI2C));

    /* Submit the low address byte */ 
    I2C_writeByte(hI2C, dst & 0xff);

    while(!I2C_xrdy(hI2C));
    
    /* Transmit the data */
    for (i = 0; i < length; i++)
    {
        I2C_writeByte(hI2C, *psrc++);
        while(!I2C_xrdy(hI2C));
    }
    
    /* Generate stop condition */
    I2C_sendStop(hI2C);

    /* Need to wait at least 10ms */
    SEEDDM642_waitusec(10000);

    /* Wait until bus is free */
    while (I2C_bb(hI2C));
    
    /* Reconfigure I2C with old settings */
    I2C_config(hI2C, &prevI2CCfg);
}

⌨️ 快捷键说明

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