58 #define USE_BLOCK_TRANSACTION 0 59 #define FOUND_SIZE 0x79 100 Serial.print(F(
"Read Alert: fail.\n"));
102 return (address >> 1);
110 while (timeout-- > 0)
124 for (address = 0x10; address < 0x7F; address++)
150 for (address = 0x10; address < 0x7F; address++)
190 Serial.print(F(
"Write Byte With Pec: fail.\n"));
195 Serial.print(F(
"Write Byte: fail.\n"));
200 uint8_t *
data, uint8_t no_addresses)
207 while (index < no_addresses)
209 buffer[0] = data[
index];
211 pecAdd(addresses[index] << 1);
217 Serial.print(F(
"Write Bytes With Pec: fail.\n"));
225 while (index < no_addresses)
228 Serial.print(F(
"Write Bytes: fail.\n"));
245 pecAdd((address << 1) | 0x01);
247 Serial.print(F(
"Read Byte With Pec: fail.\n"));
251 Serial.print(F(
"Read Byte With Pec: fail pec\n"));
260 Serial.print(F(
"Read Byte: fail.\n"));
270 buffer[0] = (uint8_t) (data & 0xff);
271 buffer[1] = (uint8_t) (data >> 8);
280 Serial.print(F(
"Write Word With Pec: fail.\n"));
285 #if USE_BLOCK_TRANSACTION 287 buffer[0] = (uint8_t) (data & 0xff);
288 buffer[1] = (uint8_t) (data >> 8);
291 Serial.print(F(
"Write Word: fail.\n"));
294 rdata = (data << 8) | (data >> 8);
296 Serial.print(F(
"Write Word: fail.\n"));
313 pecAdd((address << 1) | 0x01);
316 Serial.print(F(
"Read Word With Pec: fail.\n"));
321 Serial.print(F(
"Read Word With Pec: fail pec\n"));
323 return input[1] << 8 | input[0];
328 #if USE_BLOCK_TRANSACTION 334 Serial.print(F(
"Read Word: fail.\n"));
335 return input[1] << 8 | input[0];
339 Serial.print(F(
"Read Word: fail.\n"));
340 return (rdata << 8) | (rdata >> 8);
346 uint8_t *block, uint16_t block_size)
357 while (pos < block_size)
361 uint8_t *data_with_pec = (uint8_t *) malloc(block_size + 2);
362 data_with_pec[0] = block_size;
363 memcpy(data_with_pec + 1, block, block_size);
364 data_with_pec[block_size + 1] =
pec;
367 Serial.print(F(
"Write Block With Pec: fail.\n"));
372 uint8_t *buffer = (uint8_t *)malloc(block_size + 1);
373 buffer[0] = block_size;
374 memcpy(buffer + 1, block, block_size);
376 Serial.print(F(
"Write Block: fail.\n"));
382 uint8_t *block_out, uint16_t block_out_size, uint8_t *block_in, uint16_t block_in_size)
387 uint8_t actual_block_size;
393 while (pos < block_out_size)
397 uint8_t *buffer = (uint8_t *)malloc(block_out_size + 1);
398 buffer[0] = block_out_size;
399 memcpy(buffer + 1, block_out, block_out_size);
403 Serial.print(F(
"Write/Read Block w/PEC: write fail\n"));
408 pecAdd((address << 1) | 0x01);
411 buffer = (uint8_t *)malloc(block_in_size + 2);
413 Serial.print(F(
"Write/Read Block w/PEC: read fail.\n"));
414 if (buffer[0] > block_in_size)
416 Serial.print(F(
"Write/Read Block w/PEC: fail read size too big.\n"));
418 memcpy(block_in, buffer + 1, block_in_size);
420 for (pos = 0; pos<buffer[0] + 1u; pos++)
422 if (
pecGet() != buffer[buffer[0]+1])
423 Serial.print(F(
"Write/Read Block w/Pec: fail pec\n"));
425 actual_block_size = buffer[0];
427 return actual_block_size;
431 uint8_t *buffer = (uint8_t *)malloc(block_out_size + 1);
432 uint8_t actual_block_size;
434 buffer[0] = block_out_size;
435 memcpy(buffer + 1, block_out, block_out_size);
439 Serial.print(F(
"Write/Read Block write fail\n"));
443 buffer = (uint8_t *)malloc(block_in_size + 1);
445 Serial.print(F(
"Write/Read Block: read fail.\n"));
446 if (buffer[0] > block_in_size)
448 Serial.print(F(
"Write/Read Block: fail size too big.\n"));
450 memcpy(block_in, buffer + 1, block_in_size);
452 actual_block_size = buffer[0];
454 return actual_block_size;
460 uint8_t *block, uint16_t block_size)
465 uint8_t *buffer = (uint8_t *)malloc(block_size + 2);
466 uint8_t actual_block_size;
471 pecAdd((address << 1) | 0x01);
475 if (buffer[0] > block_size)
476 Serial.print(F(
"Read Block with PEC: fail size too big.\n"));
478 memcpy(block, buffer + 1, block_size);
480 for (pos = 0; pos<buffer[0] + 1u; pos++)
482 if (
pecGet() != buffer[buffer[0]+1])
483 Serial.print(F(
"Read Block With Pec: fail pec\n"));
485 actual_block_size = buffer[0];
487 return actual_block_size;
491 uint8_t *buffer = (uint8_t *)malloc(block_size + 1);
492 uint8_t actual_block_size;
495 Serial.print(F(
"Read Block: fail.\n"));
496 if (buffer[0] > block_size)
498 Serial.print(F(
"Read Block: fail size too big.\n"));
500 memcpy(block, buffer + 1, block_size);
502 actual_block_size = buffer[0];
504 return actual_block_size;
520 Serial.print(F(
"Send Byte With Pec: fail.\n"));
525 Serial.print(F(
"Send Byte: fail.\n"));
void sendByte(uint8_t address, uint8_t command)
SMBus send byte command.
void endGroupProtocol(void)
ends group protocol so I2CBus knows to send STOPs again.
void quikevalI2CInit(void)
Initializes Linduino I2C port.
int8_t writeWordData(uint8_t address, uint8_t command, uint16_t value)
Write a 16-bit word of data to register specified by "command".
static uint8_t found_address_[]
int8_t readByteData(uint8_t address, uint8_t command, uint8_t *value)
Read a byte of data at register specified by "command", store in "value".
void writeWord(uint8_t address, uint8_t command, uint16_t data)
SMBus write word command.
uint8_t * probe(uint8_t command)
SMBus bus probe.
int8_t readBlockData(uint8_t address, uint8_t command, uint16_t length, uint8_t *values)
Read a block of data, starting at register specified by "command" and ending at (command + length - 1...
int8_t writeBlockData(uint8_t address, uint8_t command, uint16_t length, uint8_t *values)
Write a block of data, starting at register specified by "command" and ending at (command + length - ...
void writeByte(uint8_t address, uint8_t command, uint8_t data)
SMBus write byte command.
void startGroupProtocol(void)
starts group protocol so I2CBus knows to repeat START instead of STOP.
uint8_t * probeUnique(uint8_t command)
SMBus bus probe.
uint8_t readAlert(void)
Perform ARA.
union LT_union_int32_4bytes data
uint8_t pecGet(void)
Get the current pec result.
static bool open_
Used to ensure initialisation of i2c once.
void writeBytes(uint8_t *addresses, uint8_t *commands, uint8_t *data, uint8_t no_addresses)
SMBus write byte command for a list of addresses.
int8_t readWordData(uint8_t address, uint8_t command, uint16_t *value)
Read a 16-bit word of data from register specified by "command".
uint8_t readByte(uint8_t address, uint8_t command)
SMBus read byte command.
#define input(pin)
Return the state of pin "pin".
void quikevalI2CConnect(void)
Switch MUX to connect I2C pins to QuikEval connector.
uint8_t readBlock(uint8_t address, uint8_t command, uint8_t *block, uint16_t block_size)
SMBus read block command.
int8_t writeByte(uint8_t address, uint8_t value)
Write "value" byte to device at "address".
void pecClear(void)
Clear the pec value so it can start a new calculation.
void writeBlock(uint8_t address, uint8_t command, uint8_t *block, uint16_t block_size)
SMBus write block command.
int8_t writeByteData(uint8_t address, uint8_t command, uint8_t value)
Write a byte of data to register specified by "command".
void pecAdd(uint8_t byte_value)
Add a byte to the pec calculation.
int8_t readByte(uint8_t address, uint8_t *value)
Read a byte, store in "value".
LTC SMBus Support: Implementation for a shared SMBus layer.
uint16_t readWord(uint8_t address, uint8_t command)
SMBus read word command.
uint8_t waitForAck(uint8_t address, uint8_t command)
Read with the address and command in loop until ack, then issue stop.
uint8_t writeReadBlock(uint8_t address, uint8_t command, uint8_t *block_out, uint16_t block_out_size, uint8_t *block_in, uint16_t block_in_size)
SMBus write then read block command.