|
@@ -26,7 +26,7 @@
|
|
|
*************************************************************************/
|
|
|
#include "i2c_master.h"
|
|
|
#include "gd32f30x_dma.h"
|
|
|
-
|
|
|
+#include "api.h"
|
|
|
/*************************************************************************
|
|
|
Exported Functions (N/A)
|
|
|
*************************************************************************/
|
|
@@ -562,7 +562,7 @@ static void i2c_voBufferWrite2EE(const UBYTE *pBuffer, UBYTE SlaveAddr, UBYTE Wr
|
|
|
UBYTE ubNPages = 0, ubNSingleBytes = 0, ubAddr = 0, ubCnt = 0, ubTemp = 0;
|
|
|
|
|
|
ubAddr = WriteAddr % I2C_EE_PAGESIZE_NBYTES;
|
|
|
- ubCnt = I2C_EE_PAGESIZE_NBYTES - 1 - ubAddr; // Cnt datas away from page alignment
|
|
|
+ ubCnt = I2C_EE_PAGESIZE_NBYTES - ubAddr; // Cnt datas away from page alignment
|
|
|
ubNPages = NBytesToWrite / I2C_EE_PAGESIZE_NBYTES;
|
|
|
ubNSingleBytes = NBytesToWrite % I2C_EE_PAGESIZE_NBYTES;
|
|
|
|
|
@@ -678,7 +678,8 @@ void i2c_voInfoWrite2EE(const I2C_TX_COF *coef, I2C_TX_OUT *out)
|
|
|
{
|
|
|
ubSlaveAddr = I2C_SLAVEADDR_BLOCK1;
|
|
|
}
|
|
|
- i2c_voBufferWrite2EE(I2C_pWriteBuffer, ubSlaveAddr, ubWriteAddr, ubNBytes);
|
|
|
+ //i2c_voBufferWrite2EE(I2C_pWriteBuffer, ubSlaveAddr, ubWriteAddr, ubNBytes);
|
|
|
+ iI2C_Write(0, ubSlaveAddr, ubWriteAddr, 8, I2C_pWriteBuffer, ubNBytes);
|
|
|
}
|
|
|
|
|
|
if ((ubReTX1 == 0) && (I2C_EE_ComuFltFlg != TRUE))
|
|
@@ -727,7 +728,9 @@ void i2c_voHistoryWrite2EE(const I2C_TX_COF *coef, I2C_TX_OUT *out)
|
|
|
{
|
|
|
ubSlaveAddr = I2C_SLAVEADDR_BLOCK3;
|
|
|
}
|
|
|
- i2c_voBufferWrite2EE(I2C_pHistoryWriteBuffer, ubSlaveAddr, ubWriteAddr, ubNBytes);
|
|
|
+
|
|
|
+ //i2c_voBufferWrite2EE(I2C_pHistoryWriteBuffer, ubSlaveAddr, ubWriteAddr, ubNBytes);
|
|
|
+ iI2C_Write(0, ubSlaveAddr, ubWriteAddr, 8, I2C_pHistoryWriteBuffer, ubNBytes);
|
|
|
}
|
|
|
if ((ubReTX2 == 0) && (I2C_EE_ComuFltFlg != TRUE))
|
|
|
{
|
|
@@ -796,263 +799,302 @@ void i2c_bus_reset(void)
|
|
|
Subroutine Call:
|
|
|
Reference:
|
|
|
*************************************************************************/
|
|
|
-void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
|
|
|
-{
|
|
|
+// void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
|
|
|
+// {
|
|
|
|
|
|
- UWORD timeout = 0;
|
|
|
- UBYTE ubRdNBytes = 0, ubRdSlaveAddr = 0, ubRdAddr = 0;
|
|
|
- UBYTE state = (UBYTE)I2C_START;
|
|
|
- UBYTE read_cycle = 0;
|
|
|
- UBYTE ubRdCnt = 2;
|
|
|
+// UWORD timeout = 0;
|
|
|
+// UBYTE ubRdNBytes = 0, ubRdSlaveAddr = 0, ubRdAddr = 0;
|
|
|
+// UBYTE state = (UBYTE)I2C_START;
|
|
|
+// UBYTE read_cycle = 0;
|
|
|
+// UBYTE ubRdCnt = 2;
|
|
|
|
|
|
- UBYTE i2c_timeout_flag = 0;
|
|
|
- UBYTE *p_buffer;
|
|
|
+// UBYTE i2c_timeout_flag = 0;
|
|
|
+// UBYTE *p_buffer;
|
|
|
|
|
|
- while(ubRdCnt != 0)
|
|
|
- {
|
|
|
- ubRdCnt--;
|
|
|
+// while(ubRdCnt != 0)
|
|
|
+// {
|
|
|
+// ubRdCnt--;
|
|
|
|
|
|
- if (ubRdCnt == 1)
|
|
|
- {
|
|
|
- ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK1;
|
|
|
- ubRdAddr = 0x00;
|
|
|
- ubRdNBytes = I2C_RX1_NBYTES;
|
|
|
- p_buffer = I2C_ubReadBuffer[0];
|
|
|
- i2c_timeout_flag = 0;
|
|
|
- }
|
|
|
- else if (ubRdCnt == 0)
|
|
|
- {
|
|
|
- ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK3;
|
|
|
- ubRdAddr = 0x00;
|
|
|
- ubRdNBytes = I2C_RX2_NBYTES;
|
|
|
- p_buffer = I2C_ubReadBuffer[1];
|
|
|
- i2c_timeout_flag = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //do nothing
|
|
|
- }
|
|
|
+// if (ubRdCnt == 1)
|
|
|
+// {
|
|
|
+// ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK1;
|
|
|
+// ubRdAddr = 0x00;
|
|
|
+// ubRdNBytes = I2C_RX1_NBYTES;
|
|
|
+// p_buffer = I2C_ubReadBuffer[0];
|
|
|
+// i2c_timeout_flag = 0;
|
|
|
+// }
|
|
|
+// else if (ubRdCnt == 0)
|
|
|
+// {
|
|
|
+// ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK3;
|
|
|
+// ubRdAddr = 0x00;
|
|
|
+// ubRdNBytes = I2C_RX2_NBYTES;
|
|
|
+// p_buffer = I2C_ubReadBuffer[1];
|
|
|
+// i2c_timeout_flag = 0;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// //do nothing
|
|
|
+// }
|
|
|
|
|
|
- /* enable acknowledge */
|
|
|
- i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
|
|
+// /* enable acknowledge */
|
|
|
+// i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
|
|
|
|
|
- while(i2c_timeout_flag ==0)
|
|
|
- {
|
|
|
- switch(state)
|
|
|
- {
|
|
|
- case I2C_START:
|
|
|
- if(RESET == read_cycle)
|
|
|
- {
|
|
|
- /* disable I2C0 */
|
|
|
- i2c_disable(I2C0);
|
|
|
- /* enable I2C0 */
|
|
|
- i2c_enable(I2C0);
|
|
|
- /* enable acknowledge */
|
|
|
- i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
|
|
- /* i2c master sends start signal only when the bus is idle */
|
|
|
- while((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) != 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
- {
|
|
|
- timeout++;
|
|
|
- }
|
|
|
+// while(i2c_timeout_flag ==0)
|
|
|
+// {
|
|
|
+// switch(state)
|
|
|
+// {
|
|
|
+// case I2C_START:
|
|
|
+// if(RESET == read_cycle)
|
|
|
+// {
|
|
|
+// /* disable I2C0 */
|
|
|
+// i2c_disable(I2C0);
|
|
|
+// /* enable I2C0 */
|
|
|
+// i2c_enable(I2C0);
|
|
|
+// /* enable acknowledge */
|
|
|
+// i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
|
|
+// /* i2c master sends start signal only when the bus is idle */
|
|
|
+// while((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) != 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
+// {
|
|
|
+// timeout++;
|
|
|
+// }
|
|
|
|
|
|
- if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
- {
|
|
|
- /* send the start signal */
|
|
|
- i2c_start_on_bus(I2C0);
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_SEND_ADDRESS;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- i2c_bus_reset();
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_START;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- i2c_start_on_bus(I2C0);
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_SEND_ADDRESS;
|
|
|
- }
|
|
|
- break;
|
|
|
- case I2C_SEND_ADDRESS:
|
|
|
- /* i2c master sends START signal successfully */
|
|
|
- while((i2c_flag_get(I2C0, I2C_FLAG_SBSEND) == 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
- {
|
|
|
- timeout++;
|
|
|
- }
|
|
|
- if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
- {
|
|
|
- if(RESET == read_cycle)
|
|
|
- {
|
|
|
- i2c_master_addressing(I2C0, ubRdSlaveAddr, I2C_TRANSMITTER);
|
|
|
- state = (UBYTE)I2C_CLEAR_ADDRESS_FLAG;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- i2c_master_addressing(I2C0, ubRdSlaveAddr, I2C_RECEIVER);
|
|
|
- state = (UBYTE)I2C_CLEAR_ADDRESS_FLAG;
|
|
|
- }
|
|
|
- timeout = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_START;
|
|
|
- read_cycle = 0;
|
|
|
- }
|
|
|
- break;
|
|
|
- case I2C_CLEAR_ADDRESS_FLAG:
|
|
|
- /* address flag set means i2c slave sends ACK */
|
|
|
- while((i2c_flag_get(I2C0, I2C_FLAG_ADDSEND) == 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
- {
|
|
|
- timeout++;
|
|
|
- }
|
|
|
- if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
- {
|
|
|
- i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_TRANSMIT_DATA;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_START;
|
|
|
- read_cycle = 0;
|
|
|
- }
|
|
|
- break;
|
|
|
- case I2C_TRANSMIT_DATA:
|
|
|
- if(RESET == read_cycle)
|
|
|
- {
|
|
|
- /* wait until the transmit data buffer is empty */
|
|
|
- while((i2c_flag_get(I2C0, I2C_FLAG_TBE) == 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
- {
|
|
|
- timeout++;
|
|
|
- }
|
|
|
- if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
- {
|
|
|
- /* send the EEPROM's internal address to write to : only one byte address */
|
|
|
- i2c_data_transmit(I2C0, ubRdAddr);
|
|
|
- timeout = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_START;
|
|
|
- read_cycle = 0;
|
|
|
- }
|
|
|
- /* wait until BTC bit is set */
|
|
|
- while((i2c_flag_get(I2C0, I2C_FLAG_BTC) == 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
- {
|
|
|
- timeout++;
|
|
|
- }
|
|
|
- if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
- {
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_START;
|
|
|
- read_cycle++;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_START;
|
|
|
- read_cycle = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- /* one byte master reception procedure (polling) */
|
|
|
- if(ubRdNBytes < 2)
|
|
|
- {
|
|
|
- /* disable acknowledge */
|
|
|
- i2c_ack_config(I2C0, I2C_ACK_DISABLE);
|
|
|
- /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register (I2C_STAT0 has already been read) */
|
|
|
- i2c_flag_get(I2C0, I2C_FLAG_ADDSEND);
|
|
|
- /* send a stop condition to I2C bus*/
|
|
|
- i2c_stop_on_bus(I2C0);
|
|
|
- /* wait for the byte to be received */
|
|
|
- while(i2c_flag_get(I2C0, I2C_FLAG_RBNE) == 0)
|
|
|
- {
|
|
|
- // do nothing
|
|
|
- }
|
|
|
- /* read the byte received from the EEPROM */
|
|
|
- *p_buffer = i2c_data_receive(I2C0);
|
|
|
- /* decrement the read bytes counter */
|
|
|
- ubRdNBytes--;
|
|
|
- timeout = 0;
|
|
|
- state = (UBYTE)I2C_STOP;
|
|
|
- }
|
|
|
- else
|
|
|
- { /* more than one byte master reception procedure (DMA) */
|
|
|
+// if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
+// {
|
|
|
+// /* send the start signal */
|
|
|
+// i2c_start_on_bus(I2C0);
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_SEND_ADDRESS;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// i2c_bus_reset();
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_START;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// i2c_start_on_bus(I2C0);
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_SEND_ADDRESS;
|
|
|
+// }
|
|
|
+// break;
|
|
|
+// case I2C_SEND_ADDRESS:
|
|
|
+// /* i2c master sends START signal successfully */
|
|
|
+// while((i2c_flag_get(I2C0, I2C_FLAG_SBSEND) == 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
+// {
|
|
|
+// timeout++;
|
|
|
+// }
|
|
|
+// if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
+// {
|
|
|
+// if(RESET == read_cycle)
|
|
|
+// {
|
|
|
+// i2c_master_addressing(I2C0, ubRdSlaveAddr, I2C_TRANSMITTER);
|
|
|
+// state = (UBYTE)I2C_CLEAR_ADDRESS_FLAG;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// i2c_master_addressing(I2C0, ubRdSlaveAddr, I2C_RECEIVER);
|
|
|
+// state = (UBYTE)I2C_CLEAR_ADDRESS_FLAG;
|
|
|
+// }
|
|
|
+// timeout = 0;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_START;
|
|
|
+// read_cycle = 0;
|
|
|
+// }
|
|
|
+// break;
|
|
|
+// case I2C_CLEAR_ADDRESS_FLAG:
|
|
|
+// /* address flag set means i2c slave sends ACK */
|
|
|
+// while((i2c_flag_get(I2C0, I2C_FLAG_ADDSEND) == 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
+// {
|
|
|
+// timeout++;
|
|
|
+// }
|
|
|
+// if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
+// {
|
|
|
+// i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_TRANSMIT_DATA;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_START;
|
|
|
+// read_cycle = 0;
|
|
|
+// }
|
|
|
+// break;
|
|
|
+// case I2C_TRANSMIT_DATA:
|
|
|
+// if(RESET == read_cycle)
|
|
|
+// {
|
|
|
+// /* wait until the transmit data buffer is empty */
|
|
|
+// while((i2c_flag_get(I2C0, I2C_FLAG_TBE) == 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
+// {
|
|
|
+// timeout++;
|
|
|
+// }
|
|
|
+// if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
+// {
|
|
|
+// /* send the EEPROM's internal address to write to : only one byte address */
|
|
|
+// i2c_data_transmit(I2C0, ubRdAddr);
|
|
|
+// timeout = 0;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_START;
|
|
|
+// read_cycle = 0;
|
|
|
+// }
|
|
|
+// /* wait until BTC bit is set */
|
|
|
+// while((i2c_flag_get(I2C0, I2C_FLAG_BTC) == 0) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
+// {
|
|
|
+// timeout++;
|
|
|
+// }
|
|
|
+// if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
+// {
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_START;
|
|
|
+// read_cycle++;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_START;
|
|
|
+// read_cycle = 0;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// /* one byte master reception procedure (polling) */
|
|
|
+// if(ubRdNBytes < 2)
|
|
|
+// {
|
|
|
+// /* disable acknowledge */
|
|
|
+// i2c_ack_config(I2C0, I2C_ACK_DISABLE);
|
|
|
+// /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register (I2C_STAT0 has already been read) */
|
|
|
+// i2c_flag_get(I2C0, I2C_FLAG_ADDSEND);
|
|
|
+// /* send a stop condition to I2C bus*/
|
|
|
+// i2c_stop_on_bus(I2C0);
|
|
|
+// /* wait for the byte to be received */
|
|
|
+// while(i2c_flag_get(I2C0, I2C_FLAG_RBNE) == 0)
|
|
|
+// {
|
|
|
+// // do nothing
|
|
|
+// }
|
|
|
+// /* read the byte received from the EEPROM */
|
|
|
+// *p_buffer = i2c_data_receive(I2C0);
|
|
|
+// /* decrement the read bytes counter */
|
|
|
+// ubRdNBytes--;
|
|
|
+// timeout = 0;
|
|
|
+// state = (UBYTE)I2C_STOP;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// { /* more than one byte master reception procedure (DMA) */
|
|
|
|
|
|
- dma_transfer_number_config(DMA0, DMA_CH6, ubRdNBytes);
|
|
|
- DMA_CH6MADDR(DMA0) = (ULONG)p_buffer;
|
|
|
+// dma_transfer_number_config(DMA0, DMA_CH6, ubRdNBytes);
|
|
|
+// DMA_CH6MADDR(DMA0) = (ULONG)p_buffer;
|
|
|
|
|
|
- i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON);
|
|
|
- /* enable I2C0 DMA */
|
|
|
- i2c_dma_config(I2C0, I2C_DMA_ON);
|
|
|
- /* enable DMA0 channel5 */
|
|
|
- dma_channel_enable(DMA0, DMA_CH6);
|
|
|
- /* wait until BTC bit is set */
|
|
|
- while(dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF) == 0)
|
|
|
- {
|
|
|
- // do nothing
|
|
|
- }
|
|
|
-
|
|
|
- state = (UBYTE)I2C_STOP;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case I2C_STOP:
|
|
|
- /* send a stop condition to I2C bus */
|
|
|
- i2c_stop_on_bus(I2C0);
|
|
|
- /* i2c master sends STOP signal successfully */
|
|
|
- while((I2C_CTL0(I2C0) & I2C_CTL0_STOP) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
- {
|
|
|
- timeout++;
|
|
|
- }
|
|
|
-
|
|
|
- if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
- {
|
|
|
- timeout = 0;
|
|
|
- i2c_timeout_flag = 1;
|
|
|
- state = (UBYTE)I2C_START;
|
|
|
- read_cycle = 0;
|
|
|
+// i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON);
|
|
|
+// /* enable I2C0 DMA */
|
|
|
+// i2c_dma_config(I2C0, I2C_DMA_ON);
|
|
|
+// /* enable DMA0 channel5 */
|
|
|
+// dma_channel_enable(DMA0, DMA_CH6);
|
|
|
+// /* wait until BTC bit is set */
|
|
|
+// while(dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF) == 0)
|
|
|
+// {
|
|
|
+// // do nothing
|
|
|
+// }
|
|
|
+
|
|
|
+// state = (UBYTE)I2C_STOP;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// break;
|
|
|
+// case I2C_STOP:
|
|
|
+// /* send a stop condition to I2C bus */
|
|
|
+// i2c_stop_on_bus(I2C0);
|
|
|
+// /* i2c master sends STOP signal successfully */
|
|
|
+// while((I2C_CTL0(I2C0) & I2C_CTL0_STOP) && (timeout < I2C_SHORT_TIMEOUT))
|
|
|
+// {
|
|
|
+// timeout++;
|
|
|
+// }
|
|
|
+
|
|
|
+// if(timeout < I2C_SHORT_TIMEOUT)
|
|
|
+// {
|
|
|
+// timeout = 0;
|
|
|
+// i2c_timeout_flag = 1;
|
|
|
+// state = (UBYTE)I2C_START;
|
|
|
+// read_cycle = 0;
|
|
|
|
|
|
- /* disable DMA0 CH6 */
|
|
|
- dma_channel_disable(DMA0, DMA_CH6);
|
|
|
- /* disable I2C0 DMA */
|
|
|
- i2c_dma_config(I2C0, I2C_DMA_OFF);
|
|
|
- i2c_dma_last_transfer_config(I2C0, I2C_DMALST_OFF);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- timeout = 0;
|
|
|
- //state = I2C_START;
|
|
|
- state = (UBYTE)I2C_STOP;
|
|
|
- read_cycle = 0;
|
|
|
- }
|
|
|
+// /* disable DMA0 CH6 */
|
|
|
+// dma_channel_disable(DMA0, DMA_CH6);
|
|
|
+// /* disable I2C0 DMA */
|
|
|
+// i2c_dma_config(I2C0, I2C_DMA_OFF);
|
|
|
+// i2c_dma_last_transfer_config(I2C0, I2C_DMALST_OFF);
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// timeout = 0;
|
|
|
+// //state = I2C_START;
|
|
|
+// state = (UBYTE)I2C_STOP;
|
|
|
+// read_cycle = 0;
|
|
|
+// }
|
|
|
|
|
|
- break;
|
|
|
- default:
|
|
|
- state = (UBYTE)I2C_START;
|
|
|
- read_cycle = 0;
|
|
|
- i2c_timeout_flag = 1;
|
|
|
- timeout = 0;
|
|
|
+// break;
|
|
|
+// default:
|
|
|
+// state = (UBYTE)I2C_START;
|
|
|
+// read_cycle = 0;
|
|
|
+// i2c_timeout_flag = 1;
|
|
|
+// timeout = 0;
|
|
|
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
- }
|
|
|
+// }
|
|
|
|
|
|
+// i2c_voReadBufferCRC(out);
|
|
|
+
|
|
|
+// i2c_voGetValueFrmBuffer(out);
|
|
|
+
|
|
|
+// out->ReadFinishFlg = TRUE;
|
|
|
+
|
|
|
+// }
|
|
|
+
|
|
|
+void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
|
|
|
+{
|
|
|
+ UBYTE ubRdNBytes = 0, ubRdSlaveAddr = 0, ubRdAddr = 0;
|
|
|
+ UBYTE ubRdCnt = 2;
|
|
|
+ UBYTE *p_buffer;
|
|
|
+
|
|
|
+ while(ubRdCnt != 0)
|
|
|
+ {
|
|
|
+ ubRdCnt--;
|
|
|
+
|
|
|
+ if (ubRdCnt == 1)
|
|
|
+ {
|
|
|
+ ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK1;
|
|
|
+ ubRdAddr = 0x00;
|
|
|
+ ubRdNBytes = I2C_RX1_NBYTES;
|
|
|
+ p_buffer = I2C_ubReadBuffer[0];
|
|
|
+ }
|
|
|
+ else if (ubRdCnt == 0)
|
|
|
+ {
|
|
|
+ ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK3;
|
|
|
+ ubRdAddr = 0x00;
|
|
|
+ ubRdNBytes = I2C_RX2_NBYTES;
|
|
|
+ p_buffer = I2C_ubReadBuffer[1];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //do nothing
|
|
|
+ }
|
|
|
+
|
|
|
+ iI2C_Read(0, ubRdSlaveAddr, ubRdAddr, 8, p_buffer, ubRdNBytes);
|
|
|
+ }
|
|
|
+
|
|
|
i2c_voReadBufferCRC(out);
|
|
|
|
|
|
i2c_voGetValueFrmBuffer(out);
|
|
|
|
|
|
out->ReadFinishFlg = TRUE;
|
|
|
-
|
|
|
}
|
|
|
/*************************************************************************
|
|
|
Function:
|