AVR ISP adapter (avr109/910 compatible, using ATmega16)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.0 KiB

  1. #ifndef TWI_MASTER_H_
  2. #define TWI_MASTER_H_
  3. #include <stdint.h>
  4. /* *********************************************************************** */
  5. /* SLA+R */
  6. #define CMD_WAIT 0x00
  7. #define CMD_READ_VERSION 0x01
  8. #define CMD_READ_MEMORY 0x02
  9. /* SLA+W */
  10. #define CMD_SWITCH_APPLICATION CMD_READ_VERSION
  11. #define CMD_WRITE_MEMORY CMD_READ_MEMORY
  12. /* CMD_SWITCH_APPLICATION parameter */
  13. #define BOOTTYPE_BOOTLOADER 0x00
  14. #define BOOTTYPE_APPLICATION 0x80
  15. /* CMD_{READ|WRITE}_* parameter */
  16. #define MEMTYPE_CHIPINFO 0x00
  17. #define MEMTYPE_FLASH 0x01
  18. #define MEMTYPE_EEPROM 0x02
  19. #define TWI_SUCCESS 0x00
  20. #define TWI_ERROR 0x01
  21. #define TWI_NACK_ADDR 0x02
  22. #define TWI_NACK_DATA 0x03
  23. typedef struct twi_chipinfo_s
  24. {
  25. uint8_t sig[3];
  26. uint8_t page_size;
  27. uint16_t flash_size;
  28. uint16_t eeprom_size;
  29. } twi_chipinfo_t;
  30. /* *********************************************************************** */
  31. uint8_t twi_generic (uint8_t twi_addr,
  32. const uint8_t * p_wr_data, uint16_t write_size,
  33. uint8_t * p_rd_data, uint16_t read_size);
  34. uint8_t twi_switch_application (uint8_t addr, uint8_t app);
  35. uint8_t twi_read_version (uint8_t addr, char * p_version,
  36. uint8_t version_length);
  37. uint8_t twi_read_chipinfo (uint8_t addr, twi_chipinfo_t * p_chipinfo);
  38. uint8_t twi_read_memory (uint8_t twi_addr, uint8_t memory_type,
  39. uint16_t memory_addr,
  40. uint8_t * p_data, uint16_t data_length);
  41. uint8_t twi_write_memory (uint8_t twi_addr, uint8_t memory_type,
  42. uint16_t memory_addr,
  43. const uint8_t * p_data, uint16_t data_length);
  44. void twi_init (uint8_t enable);
  45. /* *********************************************************************** */
  46. #endif /* TWI_MASTER_H_ */