Alchemy
Loading...
Searching...
No Matches

flash.h

Go to the documentation of this file.
1#ifndef ALCHEMY_FLASH_H
2#define ALCHEMY_FLASH_H
3
4/// @file
5/// Flash memory: erasing, programming and reading sectors.
6
7#include "types.h"
8
10u16 ProgramFlashByte(u8 *source, u8 *destination);
12u16 ProgramFlashSector(u16 sector, u8 *source);
13void StopFlashTimer(void);
14u8 ReadFlashByte(u8 *source);
15void CopyFlashReadRoutineToRam(void *destination);
16s32 ReadFlashId(void);
17s32 IdentifyFlash(void);
19u16 WaitForFlashWrite(u8 timingIndex, volatile u8 *address, u8 expected);
23u16 ProgramAtmelFlashSector(u32 sector, const u8 *source);
24u16 ProgramAtmelFlashBlock(u16 block, u8 *source);
25void FlashTimerIntr(void);
26s32 SetFlashTimerIntr(u8 timer_index, void (**callback)(void));
27void ReadFlashCore(const u8 *source, u8 *destination, u32 size);
28void ReadFlash(u16 sector, u32 offset, u8 *destination, s32 size);
29u8 *VerifyFlashCore(u8 *left, u8 *right, u16 size);
30s32 Flash_VerifySector(u16 sector, s32 source);
31
32extern u8 (*gFlashReadRoutine)(u8 *source);
33
34#endif
u16 ProgramAtmelFlashSector(u32 sector, const u8 *source)
Programs a small Atmel sector with interrupts disabled, then polls its last byte.
Definition atmel.c:105
u16 EraseAtmelFlashSector(u16 sector)
Erases one small Atmel sector by programming every byte to 0xff.
Definition atmel.c:35
u16 EraseAtmelFlashBlock(u16 sector)
Erases thirty-two small sectors, trying each sector at most twice.
Definition atmel.c:64
u16 EraseAtmelFlashChip(void)
Erases the Atmel chip and waits for completion with its configured timing.
Definition atmel.c:8
u16 ProgramAtmelFlashBlock(u16 sector, u8 *source)
Programs an Atmel block in small sectors, trying each sector at most twice.
Definition atmel.c:139
void StopFlashTimer(void)
Stops the flash timer and restores the saved interrupt-enable state.
Definition flash.c:140
u16 WaitForFlashWrite(u8 timingIndex, volatile u8 *address, u8 expected)
Polls for the expected byte until success or timeout, returning an operation error.
Definition flash.c:181
u8 * VerifyFlashCore(u8 *left, u8 *right, u16 size)
Returns the first differing byte in the right buffer, or NULL when all bytes match.
Definition flash.c:238
s32 ReadFlashId(void)
Enters flash ID mode, waits for the chip and reads its device and manufacturer IDs.
Definition flash.c:10
s32 SetFlashTimerIntr(u8 timerIndex, void(**callback)(void))
Selects a hardware timer and returns its timeout interrupt callback.
Definition flash.c:106
void FlashTimerIntr(void)
Counts down the active flash timeout and marks its expiration.
Definition flash.c:93
void ReadFlash(u16 sector, u32 offset, u8 *destination, s32 size)
Copies the RAM reader and reads a range using the standard sector geometry.
Definition flash.c:214
void CopyFlashReadRoutineToRam(void *destination)
Copies the byte reader to RAM and installs its Thumb entry point.
Definition flash.c:161
s32 Flash_VerifySector(u16 sector, s32 source)
Copies the verifier to RAM and compares a standard flash sector with source data.
Definition flash.c:259
void ReadFlashCore(const u8 *source, u8 *destination, u32 size)
Copies flash bytes into RAM; this routine executes from a RAM copy.
Definition flash.c:201
u8 ReadFlashByte(u8 *source)
Reads one byte; copied into RAM so the cartridge can be polled during a write.
Definition flash.c:158
s32 IdentifyFlash(void)
Selects matching chip handlers, falling back to the final table entry when unknown.
Definition flash.c:61
u8(*) gFlashReadRoutine(u8 *source)
u16 ProgramFlashSector(u16 sector, u8 *source)
Erases a standard sector and programs bytes until completion or an error.
u16 ProgramFlashSectorWithEraseRetry(u16 sector, u8 *source)
Erases and verifies a sector with retries, then programs its bytes.
Definition sst.c:95
u16 EraseFlashSector(u16 sector)
Erases one of sixteen sectors, restoring the cartridge wait setting afterward.
Definition sst.c:39
u16 ProgramFlashByte(u8 *source, u8 *destination)
Issues a byte-program command and waits for its destination to match.
Definition sst.c:81
u16 EraseFlashChip(void)
Issues the chip-erase command and waits for an erased byte.
Definition sst.c:13
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11