重构以下代码 void i2c_as_slave_xfer_enable(int bus) { u32 ctrl_bits; /* Disable Master function , Set buffer page selection = 0*/ ctrl_bits = i2c_as_read_reg(bus,I2C_FUNCTION_CONTROL_REG); ctrl_bits &= ~( ENABLE_MASTER_FUNC); ctrl_bits |= ENABLE_SLAVE_FUNC; #if defined(GROUP_AST2300_PLUS) ctrl_bits &= ~( BUFFER_SELECTION_PAGE_MASK); ctrl_bits |= BUFFER_SELECTION_PAGE_0; #endif i2c_as_write_reg( bus,ctrl_bits,I2C_FUNCTION_CONTROL_REG); udelay(100); /* clear interrups */ i2c_as_disable_all_interrupts(bus); i2c_as_write_reg (bus, CLR_ALL_INTS_VAL, I2C_INTR_STATUS_REG); as_data_ptr[bus].SlaveTX_Enable = 1; as_data_ptr[bus].TX_len = 0; as_data_ptr[bus].TX_index = 0; as_data_ptr[bus].MasterRX_len = 0; as_data_ptr[bus].MasterRX_index = 0; /* Default I2C_BYTE_MODE for GROUP_AST2300 and GROUP_AST2300_PLUS. For testing buffer transfer mode of SSIF, init ssif tx pool buffer. */ //as_data_ptr[bus].pool_buff_base = AST_I2C_POLLBUF_VA_BASE; /* Enable interrupts */ i2c_as_write_reg (bus, ENABLE_TX_DONE_WITH_ACK_INTR | \ ENABLE_TX_DONE_WITH_NACK_INTR | \ ENABLE_RX_DONE_INTR| ENABLE_STOP_CONDITION_RECVD_INTR| ENABLE_ABNORMAL_START_STOP_RECVD_INTR| ENABLE_SLAVE_ADDR_MATCH_INTR, I2C_INTR_CONTROL_REG); }
时间: 2023-02-11 20:24:56 浏览: 141
I2C-Driver.rar_i c2666.com_ucos i2c_ucos ii下i2c
重构代码:
```
void i2c_as_slave_xfer_enable(int bus) {
u32 ctrl_bits;
// 禁用主机功能,设置缓冲区页面选择为0
ctrl_bits = i2c_as_read_reg(bus, I2C_FUNCTION_CONTROL_REG);
//...
}
```
其中该代码禁用了I2C总线上的主机功能,并将缓冲区页面选择设置为0。
阅读全文