|
| 1 | +#pragma once |
1 | 2 |
|
| 3 | +#include <pico/stdlib.h> |
| 4 | + |
| 5 | +// Initialises the SPI interface bridge to the microcontroller. |
| 6 | +void avr_spi_init(); |
| 7 | + |
| 8 | +// Causes the microcontroller to perform a reset sequence by pulsing the RESET pin. |
| 9 | +void avr_reset(); |
| 10 | + |
| 11 | +// Sends a Programming Enable command to enter memory programming mode. |
| 12 | +// Returns a boolean indicating the microcontrollers acknowledgement through a satisfactory echo. |
| 13 | +// "If the 0x53 did not echo back, give RESET a positive pulse and issue a new Programming Enable command" |
| 14 | +bool avr_enter_programming_mode(); |
| 15 | + |
| 16 | +// Erases the program memory as well as the EEPROM. |
| 17 | +// This operation must be performed before programming of new data. |
| 18 | +// This operation is destructive to the underlying flash storage and can only be done a limited amount of times (usually ~10,000 times). |
| 19 | +void avr_erase_memory(); |
| 20 | + |
| 21 | +// Performs a write to the AVR program memory temporary buffer. |
| 22 | +// Addresses are per-word, 0 = first 2 bytes, 1 = 3rd and 4th byte (little endian). |
| 23 | +// Combined 16-bit uint version. |
| 24 | +void avr_write_temporary_buffer_16(uint16_t word_address, uint16_t data); |
| 25 | + |
| 26 | +// Performs a write to the AVR program memory temporary buffer. |
| 27 | +// Addresses are per-word, 0 = first 2 bytes, 1 = 3rd and 4th byte (little endian). |
| 28 | +// Separate data byte version. |
| 29 | +void avr_write_temporary_buffer(uint16_t word_address, uint8_t low_byte, uint8_t high_byte); |
| 30 | + |
| 31 | +// Flashes the data from the temporary buffer to the program memory at the specified address. |
| 32 | +// Addresses are per-word, 0 = first 2 bytes, 1 = 3rd and 4th byte (little endian). |
| 33 | +void avr_flash_program_memory(uint16_t word_address); |
| 34 | + |
| 35 | +// Performs a read on the AVR program memory at the specified address. |
| 36 | +// Addresses are per-word, 0 = first 2 bytes, 1 = 3rd and 4th byte (little endian). |
| 37 | +// Low byte only version. |
| 38 | +uint8_t avr_read_program_memory_low_byte(uint16_t word_address); |
| 39 | + |
| 40 | +// Performs a read on the AVR program memory at the specified address. |
| 41 | +// Addresses are per-word, 0 = first 2 bytes, 1 = 3rd and 4th byte (little endian). |
| 42 | +// High byte only version. |
| 43 | +uint8_t avr_read_program_memory_high_byte(uint16_t word_address); |
| 44 | + |
| 45 | +// Performs a read on the AVR program memory at the specified address. |
| 46 | +// Addresses are per-word, 0 = first 2 bytes, 1 = 3rd and 4th byte (little endian). |
| 47 | +uint16_t avr_read_program_memory(uint16_t word_address); |
| 48 | + |
| 49 | +// Writes a specified amount of words directly from a buffer onto the AVR controllers temporary buffer. |
| 50 | +// The maximum supported words depends on the specific AVR controller/page size used, for the ATTiny84A it is 32 words (64 bytes). |
| 51 | +// https://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny24A-44A-84A-DataSheet-DS40002269A.pdf |
| 52 | +void avr_write_temporary_buffer_page(uint16_t* data, size_t data_len); |
| 53 | + |
| 54 | +// Verifies and compares the values on the program memory to the expected_data buffer and returns a boolean indicating result (true = matches). |
| 55 | +// This should be done after each page is flashed onto the controller as writes can be often unreliable and fail, so that the operation can be retried. |
| 56 | +bool avr_verify_program_memory_page(uint16_t page_address_start, uint16_t* expected_data, size_t data_len); |
0 commit comments