отладил алгоритм с ZD24C02A

This commit is contained in:
Eugene 2023-11-23 15:03:37 +03:00
parent 105cad443b
commit e76e971c3a
6 changed files with 102 additions and 77 deletions

View File

@ -50,7 +50,7 @@ uint16_t Bl25cm1a_ReadStatus(void)
return empty;
}
void Bl25cm1a_read_8_bytes(uint32_t Addr, uint16_t * read_data, uint16_t num_byte)
void Bl25cm1a_read_8_bytes(uint32_t Addr, uint16_t * read_data, uint16_t num_byte)//num_byte <=8
{
volatile uint16_t empty, i, j;
uint16_t Stat = 1;
@ -80,7 +80,7 @@ void Bl25cm1a_read_8_bytes(uint32_t Addr, uint16_t * read_data, uint16_t num_byt
}
}
void Bl25cm1a_write_8_bytes(uint32_t Addr, uint16_t * write_data, uint16_t num_byte)
void Bl25cm1a_write_8_bytes(uint32_t Addr, uint16_t * write_data, uint16_t num_byte)//num_byte <=8
{
volatile uint16_t empty, i, j;
uint16_t Stat = 1;
@ -112,7 +112,7 @@ void Bl25cm1a_write_8_bytes(uint32_t Addr, uint16_t * write_data, uint16_t num_b
}
}
uint16_t Bl25cm1a_verify_8_bytes(uint32_t Addr, uint16_t * verify_data, uint16_t num_byte)
uint16_t Bl25cm1a_verify_8_bytes(uint32_t Addr, uint16_t * verify_data, uint16_t num_byte)//num_byte <=8
{
volatile uint16_t empty, i, j;
uint16_t Stat = 1;

View File

@ -7,6 +7,7 @@
#include "f28x_project.h"
#include "i2c_init.h"
#include "ZD24C02A.h"
#include "Arr.h"
volatile uint16_t SlaveAdr = I2C_SLAVE_ADDRESS;
uint16_t BufferZD24C02A[17];
@ -35,51 +36,78 @@ uint16_t ZD24C02A_verify_16(uint16_t Addr, uint16_t * Array, uint16_t quant)
return VerifyErr;
}
uint16_t ZD24C02A_write(uint32_t Addr, uint16_t byteCount, uint16_t * Array)
uint16_t ZD24C02A_write(uint32_t Addr, uint16_t quant, uint16_t * write_data)
{
return 0;
}
uint16_t ZD24C02A_read(uint32_t Addr, uint16_t quant, uint16_t * read_data)
{
uint16_t Err_read = 0;
uint32_t i=0;
uint16_t * addr_read_data = read_data;
uint16_t addr_write_data[16];
uint32_t Addressfull8bit;
if(quant > 16)
if(quant > 8)
{
for(i = 0; i < (quant-16); i += 16)
for(i = 0; i < (quant-8); i += 8)
{
Err_read = ZD24C02A_read_16(Addr+i, addr_read_data, 16);
if(Err_read) return 1;
addr_read_data += 16;
}
}
if(i < quant) Err_read = ZD24C02A_read_16(Addr+i, addr_read_data, quant - i);
if(Err_read) return 1;
else return 0;
}
uint16_t ZD24C02A_verify(uint32_t Addr, uint16_t quant, uint16_t * verify_data)
{
uint16_t Err_read = 0;
uint32_t i=0;
uint16_t * addr_read_data = verify_data;
if(quant > 16)
{
for(i = 0; i < (quant-16); i += 16)
{
Err_read = ZD24C02A_verify_16(Addr+i, addr_read_data, 16);
if(Err_read) return Err_read;
addr_read_data += 16;
copy16_to_8(write_data, addr_write_data, 8);
Addressfull8bit = Addr+2*i;
if( ZD24C02A_write_16(Addressfull8bit, addr_write_data, 16)) return 1;
write_data += 8;
}
}
if(i < quant)
{
Err_read = ZD24C02A_verify_16(Addr+i, addr_read_data, quant - i);
copy16_to_8(write_data, addr_write_data, (quant - i));
Addressfull8bit = Addr+2*i;
if( ZD24C02A_write_16(Addressfull8bit, addr_write_data, 2*(quant - i))) return 1;
}
return 0;
}
uint16_t ZD24C02A_read(uint32_t Addr, uint16_t quant16, uint16_t * read_data)
{
uint32_t i=0;
uint32_t Addressfull8bit;
uint16_t addr_read_data[8];
if(quant16 > 8)
{
for(i = 0; i < (quant16-8); i += 8)
{
Addressfull8bit = Addr+2*i;
if( ZD24C02A_read_16(Addr+i, addr_read_data, 16)) return 1;
copy8_to_16(addr_read_data, read_data, 8);
read_data+=8;
}
}
if(i < quant16)
{
Addressfull8bit = Addr+2*i;
if( ZD24C02A_read_16(Addressfull8bit, addr_read_data, 2*(quant16 - i))) return 1;
copy8_to_16(addr_read_data, read_data, (quant16 - i));
}
else return 0;
}
uint16_t ZD24C02A_verify(uint32_t Addr, uint16_t quant16, uint16_t * verify_data)
{
uint32_t i=0;
uint16_t addr_vfy_data[8];
uint16_t Err_read = 0;
if(quant16 > 8)
{
for(i = 0; i < (quant16-4); i += 8)
{
copy16_to_8(verify_data, addr_vfy_data, 8);
Err_read = ZD24C02A_verify_16(Addr+2*i, addr_vfy_data, 16);
if(Err_read) return Err_read;
verify_data+=8;
}
}
if(i < quant16)
{
copy16_to_8(verify_data, addr_vfy_data, (quant16 - i));
Err_read = ZD24C02A_verify_16(Addr+2*i, addr_vfy_data, 2*(quant16 - i));
if(Err_read) return Err_read;
}
return 0;

View File

@ -14,7 +14,7 @@
#define ZD24C02A_SIZE 0x80
uint16_t ZD24C02A_write(uint32_t Addr, uint16_t byteCount, uint16_t * Array);
uint16_t ZD24C02A_write(uint32_t Addr, uint16_t quant, uint16_t * write_data);
uint16_t ZD24C02A_read(uint32_t Addr, uint16_t quant, uint16_t * read_data);
void ZD24C02A_test(uint16_t * Array);
void ZD24C02A_read_all(uint16_t byteCount, uint16_t * Array);

View File

@ -18,7 +18,7 @@
#define TIME_OVER 1000
uint16_t TimerTimeouts = 0, ErrI2c = 0, ErrI2c1 = 0, ErrI2c2 = 0, ErrI2c3 = 0, Addr1[255];
uint16_t TimerTimeouts = 0, ErrI2c = 0, ErrI2c1 = 0, ErrI2c2 = 0, ErrI2c3 = 0, ErrI2c4 = 0, Addr1[255];
uint16_t RXdata, addrCount=0;
void TimerBaseTimeoutInc(void)
@ -171,7 +171,7 @@ uint16_t I2CWrite(uint16_t slaveAddr, uint16_t MemAdr, uint16_t byteCount, bool
while((I2caRegs.I2CSTR.bit.BYTESENT != 0x1)&&(TimerTimeouts < TIME_OVER));
I2caRegs.I2CSTR.bit.BYTESENT = 0x1;
if(TimerTimeouts >= TIME_OVER) {ErrI2c++; return 1;}
if(TimerTimeouts >= TIME_OVER) {ErrI2c1++; return 1;}
}
//
@ -183,7 +183,7 @@ uint16_t I2CWrite(uint16_t slaveAddr, uint16_t MemAdr, uint16_t byteCount, bool
TimerTimeouts = 0;
while((I2caRegs.I2CMDR.bit.STP != 0x0)&&(TimerTimeouts < TIME_OVER));
I2caRegs.I2CSTR.bit.BYTESENT = 0x1;
if(TimerTimeouts >= TIME_OVER) {ErrI2c1++; return 1;}
if(TimerTimeouts >= TIME_OVER) {ErrI2c2++; return 1;}
}
return 0;
}
@ -220,14 +220,14 @@ uint16_t I2CRead(uint16_t slaveAddr, uint16_t byteCount, bool sendStopCondition,
TimerTimeouts = 0;
while((count < (byteCount))&&(TimerTimeouts < TIME_OVER))
{
// if(count == (byteCount-1)) {I2caRegs.I2CMDR.bit.NACKMOD = 0x1; I2caRegs.I2CMDR.bit.STP = 0x1;}
if(count == (byteCount-1)) {I2caRegs.I2CMDR.bit.NACKMOD = 0x1; }//I2caRegs.I2CMDR.bit.STP = 0x1;}
if(I2caRegs.I2CSTR.bit.RRDY ==0x1)
{
RXdata = I2C_RXdata[count] = I2caRegs.I2CDRR.all;
count++;
}
}
if(TimerTimeouts >= TIME_OVER) {ErrI2c2 += (byteCount - count); return 1;}
if(TimerTimeouts >= TIME_OVER) {ErrI2c3 += (byteCount - count); return 1;}
//
// Send STOP condition
@ -238,7 +238,7 @@ uint16_t I2CRead(uint16_t slaveAddr, uint16_t byteCount, bool sendStopCondition,
TimerTimeouts = 0;
while((I2caRegs.I2CMDR.bit.STP != 0x0)&&(TimerTimeouts < TIME_OVER));
I2caRegs.I2CSTR.bit.BYTESENT = 0x1;
if(TimerTimeouts >= TIME_OVER) {ErrI2c3++; return 1;}
if(TimerTimeouts >= TIME_OVER) {ErrI2c4++; return 1;}
}
return 0;
}

View File

@ -303,36 +303,9 @@ void getMessage_from_Cm_ZD24C02A(void)
__interrupt void IPC_ISR0()
{
IPC_readCommand(IPC_CPU1_L_CM_R, 0, 0, &InCommand, &InAddr, &InData );
switch(InCommand & 0xFFFF)
{
case INT_FLASH:
getMessage_from_Cm_Flash();
break;
#ifdef CPU1
case EMIF:
getMessage_from_Cm_EMIF();
break;
case BL25CM1A_1M_bit_SPI:
getMessage_from_Cm_BL25CM1A();
break;
case GD25Q16E_16M_bit_SPI:
getMessage_from_Cm_GD25Q16E();
break;
case ZD24C02A_2K_I2C:
getMessage_from_Cm_ZD24C02A();
break;
#endif
default:
IPC_sendCommand(IPC_CPU1_L_CM_R, WRONG_ID, 0, 0, 0);
break;
}
IPC_ackFlagRtoL(IPC_CPU1_L_CM_R, (1<<0));
PieCtrlRegs.PIEACK.all = PIEACK_GROUP11;
IPC_setFlagLtoR(IPC_CPU1_L_CM_R,(1<<0));
if(ReadFromCm == 0) ReadFromCm = 1;
}
@ -381,15 +354,40 @@ void ipc_init(void)
GD25Q16ETIGR_clean_SectorWasErraised();
clear_BlockWasErased();
}
void ipc_run(void)
{
if(ReadFromCm == 1)
{
ReadFromCm = 0;
ReadFromCm = 2;
IPC_readCommand(IPC_CPU1_L_CM_R, 0, 0, &InCommand, &InAddr, &InData );
switch(InCommand & 0xFFFF)
{
case INT_FLASH:
getMessage_from_Cm_Flash();
break;
#ifdef CPU1
case EMIF:
getMessage_from_Cm_EMIF();
break;
case BL25CM1A_1M_bit_SPI:
getMessage_from_Cm_BL25CM1A();
break;
case GD25Q16E_16M_bit_SPI:
getMessage_from_Cm_GD25Q16E();
break;
case ZD24C02A_2K_I2C:
getMessage_from_Cm_ZD24C02A();
break;
#endif
default:
IPC_sendCommand(IPC_CPU1_L_CM_R, WRONG_ID, 0, 0, 0);
break;
}
IPC_setFlagLtoR(IPC_CPU1_L_CM_R,(1<<0));
ReadFromCm = 0;
}
}

View File

@ -65,11 +65,10 @@ void InitPerif(void)
GpioInit();
SpiInit();
I2CMasterInit(I2C_OWN_ADDRESS,I2C_SLAVE_ADDRESS);
#endif
//
// Enable global Interrupts and higher priority real-time debug events:
//
#endif
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
#ifdef CPU1