zoukankan      html  css  js  c++  java
  • BCM_I2C函数更改

    版本:sdk-xgs-robo-6.3.8
    平台:BCM53344
    应用:控制POE芯片
    
    描述:POE控制芯片使用PD69200,使用i2c与其通信,每次需要发送15字节数据,并接受15字节的返回数据。

    1.更改函数
    打开文件sdk
    -xgs-robo-6.3.8/src/soc/i2c/smbus.c 更改如下: int soc_i2c_block_read(int unit, i2c_saddr_t saddr, uint8 com, uint8* count, uint8* data) { //... 省略 ... I2C_LOCK(unit); // 53344芯片在定义了BCM_CMICM_SUPPORT,所以会运行下面的代码。 #ifdef BCM_CMICM_SUPPORT if(soc_feature(unit, soc_feature_cmicm) && !SOC_IS_SAND(unit)) { retry:
      //这个函数是smbus协议的命令格式。与I2C有些区别。注释掉发送地址和com的地方。
      //直接读取数据
    // rval = SOC_I2C_TX_ADDR(saddr); // WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); // rval = com; // WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); rval = SOC_I2C_RX_ADDR(saddr); soc_reg_field_set(unit, CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr, &rval, MASTER_WR_STATUSf, 1); /* Last Byte */ WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval);     //更改要接受的数据个数。默认是0,因此会读取0个数据。
        //查看芯片手册,需要将CMIC_I2CM_SMBus_Master_Command寄存器的最低8位(RD_BYTE_COUNT),设置为要读取的字节个数。
    // rval = 0; rval = *count; soc_reg_field_set(unit, CMIC_I2CM_SMBUS_MASTER_COMMANDr, &rval, SMBUS_PROTOCOLf, SMBUS_BLOCK_READ); WRITE_CMIC_I2CM_SMBUS_MASTER_COMMANDr(unit,rval); rv = smbus_start_wait(unit); if (rv == SOC_E_NONE) {
        //直接读取即可,这一部分也不需要,smbus协议才需要
    // READ_CMIC_I2CM_SMBUS_MASTER_DATA_READr(unit, &rval); // *count = (uint8) (rval & 0xff); ptr = data; for( i = 0; i < *count; i++, ptr++) { READ_CMIC_I2CM_SMBUS_MASTER_DATA_READr(unit, &rval); *ptr = (uint8) (rval & 0xff); } } else if (rt-- > 0) { goto retry; } else { rv = SOC_E_TIMEOUT; } } else  //后面的不运行 #endif   // ... 省略 ...
    }
    //同理,write函数也进行注释 int soc_i2c_block_write(int unit, i2c_saddr_t saddr, uint8 com, uint8 count, uint8* data) { int i,rv = SOC_E_NONE; uint8* ptr = NULL; #ifdef BCM_CMICM_SUPPORT uint32 rval; int rt = 5; #endif soc_cm_debug(DK_I2C, "i2c%d: soc_i2c_block_write %02x bytes @ %02x - %02x ", unit, count, saddr, com); #ifdef BCM_CALADAN3_SVK if (unit == -1) { return cpu_i2c_block_write(unit, saddr, com, data, count); } #endif I2C_LOCK(unit); #ifdef BCM_CMICM_SUPPORT if(soc_feature(unit, soc_feature_cmicm) && !SOC_IS_SAND(unit)) { retry: rval = SOC_I2C_TX_ADDR(saddr); WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); // rval = com; // WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); // rval = count; // WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); ptr = data; for( i = 0; i < (int) (count - 1); i++, ptr++) { rval = (uint32) *ptr; WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); } rval = (uint32) *ptr; soc_reg_field_set(unit, CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr, &rval, MASTER_WR_STATUSf, 1); /* Last Byte */ WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); rval = 0; soc_reg_field_set(unit, CMIC_I2CM_SMBUS_MASTER_COMMANDr, &rval, SMBUS_PROTOCOLf, SMBUS_BLOCK_WRITE); WRITE_CMIC_I2CM_SMBUS_MASTER_COMMANDr(unit,rval); rv = smbus_start_wait(unit); if (rv != SOC_E_NONE && rt-- > 0) { goto retry; } else if (rt < 0) { rv = SOC_E_TIMEOUT; } } else #endif

    2.导出全局符号
    打开文件 sdk/systems/linux/kernel/modules/include/bcmx_export.h
    最后添加:
      #include <soc/i2c.h>
      EXPORT_SYMBOL(soc_i2c_is_attached);
      EXPORT_SYMBOL(soc_i2c_attach);
      EXPORT_SYMBOL(soc_i2c_block_read);
      EXPORT_SYMBOL(soc_i2c_block_write);

    之后从新编译SDK即可。

  • 相关阅读:
    bzoj 2120 数颜色 带修改莫队
    luogu 2709 小B的询问 莫队
    bzoj 2002 [Hnoi2010]Bounce 弹飞绵羊 分块
    bzoj 4765 普通计算姬 dfs序 + 分块
    loj 数列分块入门 6 9(区间众数)
    loj 数列分块入门 5 7 8
    AtCoder Grand Contest 021 D
    Codeforces Round #466
    office 威胁检测
    修改macos的启动LOGO
  • 原文地址:https://www.cnblogs.com/helloworldtoyou/p/5319907.html
Copyright © 2011-2022 走看看