SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
flash.h
Go to the documentation of this file.
1
28
29#ifndef __FLASH_H__
30#define __FLASH_H__
31
32// I usually include stdint.h, but SGDK defines some stdint types here:
33#include "types.h"
34
35// Maximum number of flash regions. CFI standard allows up to 4
36#define FLASH_REGION_MAX 4
37
43 uint32_t start_addr; //< Sector start address
44 uint16_t num_sectors; //< Number of sectors
45 uint16_t sector_len; //< Sector length in 256 byte units
46};
47
48
53struct flash_chip {
54 uint32_t len; //< Length of chip in bytes
55 uint16_t num_regions; //< Number of regions in chip
56 struct flash_region region[FLASH_REGION_MAX]; //< Region data array
57};
58
59
67int16_t flash_init(void);
68
72void flash_deinit(void);
73
79const struct flash_chip *flash_metadata_get(void);
80
95uint32_t flash_sector_erase(uint32_t addr);
96
115uint16_t flash_program(uint32_t addr, const uint8_t *data, uint16_t len);
116
130int16_t flash_read(uint32_t addr, uint8_t *data, uint16_t len);
131
148int16_t flash_copy(uint32_t dst, uint32_t src, uint16_t len);
149
162int16_t flash_sector_limits(uint32_t addr, uint32_t *start, uint32_t *next);
163
164#endif
uint16_t flash_program(uint32_t addr, const uint8_t *data, uint16_t len)
Programs (writes) a data buffer to the specified flash address.
int16_t flash_init(void)
Initialise flash chip. Call this function only once, before any other function in the module.
uint32_t flash_sector_erase(uint32_t addr)
Erases a flash sector. Erased sectors will be read as 0xFF.
const struct flash_chip * flash_metadata_get(void)
Get chip metadata.
void flash_deinit(void)
Deinitialise flash chip.
int16_t flash_sector_limits(uint32_t addr, uint32_t *start, uint32_t *next)
Obtains the sector limits (start of sector, start of next sector) corresponding to the specified addr...
int16_t flash_read(uint32_t addr, uint8_t *data, uint16_t len)
Reads data from the specified flash address.
int16_t flash_copy(uint32_t dst, uint32_t src, uint16_t len)
Copy data from a flash region to other region also in flash.
Metadata of a flash chip, describing memory layout.
Definition flash.h:53
Metadata of a flash region, consisting of several sectors. /.
Definition flash.h:42
Types definition.