BCM_I2C函数更改
生活随笔
收集整理的這篇文章主要介紹了
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_SUPPORTif(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_SUPPORTuint32 rval;int rt = 5; #endifsoc_cm_debug(DK_I2C, "i2c%d: soc_i2c_block_write %02x bytes @ %02x - %02x\n", unit, count, saddr, com);#ifdef BCM_CALADAN3_SVKif (unit == -1) {return cpu_i2c_block_write(unit, saddr, com, data, count);} #endifI2C_LOCK(unit); #ifdef BCM_CMICM_SUPPORTif(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即可。
描述: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_SUPPORTif(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_SUPPORTuint32 rval;int rt = 5; #endifsoc_cm_debug(DK_I2C, "i2c%d: soc_i2c_block_write %02x bytes @ %02x - %02x\n", unit, count, saddr, com);#ifdef BCM_CALADAN3_SVKif (unit == -1) {return cpu_i2c_block_write(unit, saddr, com, data, count);} #endifI2C_LOCK(unit); #ifdef BCM_CMICM_SUPPORTif(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即可。
?
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的BCM_I2C函数更改的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用unison+inotify 实现数
- 下一篇: 《从零开始学Swift》学习笔记(Day