Sensor Watch 0.0.2
A board replacement for the classic Casio F-91W wristwatch, powered by a Microchip SAM L22 microcontroller.
|
This section covers functions related to the SAM L22's 8 kilobyte EEPROM emulation area. More...
Functions | |
bool | watch_storage_read (uint32_t row, uint32_t offset, uint8_t *buffer, uint32_t size) |
Reads a range of bytes from the storage area. | |
bool | watch_storage_write (uint32_t row, uint32_t offset, const uint8_t *buffer, uint32_t size) |
Writes bytes to a page in the storage area. Note that the row should already be erased before writing. | |
bool | watch_storage_erase (uint32_t row) |
Erases a row in the storage area, setting all its bytes to 0xFF. | |
bool | watch_storage_sync (void) |
Waits for any pending writes to complete. | |
This section covers functions related to the SAM L22's 8 kilobyte EEPROM emulation area.
The SAM L22 inside Sensor Watch has a 256 kilobyte Flash memory array that can be programmed with whatever data we want. We use most of it to store the bootloader and the application code that runs on your wrist. The bootloader region is read-only, and the main application area is only writable by the bootloader (when you drag new code onto the WATCHBOOT drive). However! there's also a special 8 kilobyte region at the end of the Flash memory called the EEPROM Emulation Area. This EEPROM emulation area can be written or erased while the main Flash array is being read. This makes it super easy to work with, and useful for storing a small amount of non-volatile data that persists across reboots, even when power is lost. The functions in this section are very basic, and only cover reading and writing data in this area. The region is laid out as 32 rows consisting of 4 pages of 64 bytes. 32*4*64 = 8192 bytes. The area can be written one page at a time, but it can only be erased one row at a time. You can read at arbitrary word-aligned offsets within a row.
┌──────────────┬──────────────┬──────────────┬──────────────┐
Row 0 │ 64 bytes │ 64 bytes │ 64 bytes │ 64 bytes │ ├──────────────┼──────────────┼──────────────┼──────────────┤ Row 1 │ 64 bytes │ 64 bytes │ 64 bytes │ 64 bytes │ ├──────────────┼──────────────┼──────────────┼──────────────┤ ... │ │ │ │ │ ├──────────────┼──────────────┼──────────────┼──────────────┤ Row 31 │ 64 bytes │ 64 bytes │ 64 bytes │ 64 bytes │ └──────────────┴──────────────┴──────────────┴──────────────┘
bool watch_storage_erase | ( | uint32_t | row | ) |
Erases a row in the storage area, setting all its bytes to 0xFF.
row | The row you want to erase. |
bool watch_storage_read | ( | uint32_t | row, |
uint32_t | offset, | ||
uint8_t * | buffer, | ||
uint32_t | size | ||
) |
Reads a range of bytes from the storage area.
row | The row you want to read. |
offset | The offset from the beginning of the row. |
buffer | A buffer of at least size bytes. |
size | The number of bytes you wish to read. |
bool watch_storage_write | ( | uint32_t | row, |
uint32_t | offset, | ||
const uint8_t * | buffer, | ||
uint32_t | size | ||
) |
Writes bytes to a page in the storage area. Note that the row should already be erased before writing.
row | The row containing the page you want to write. |
offset | The offset from the beginning of the row. Must be a multiple of 64. |
buffer | The buffer containing the bytes you wish to set. |
size | The number of bytes you wish to write. |