2 * This file is part of INAV.
4 * INAV is free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * INAV is distributed in the hope that it
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
25 #include "common/time.h"
29 typedef uint16_t flashSector_t
;
36 typedef struct flashGeometry_s
{
37 flashSector_t sectors
; // Count of the number of erasable blocks on the device
38 uint16_t pageSize
; // In bytes
39 uint32_t sectorSize
; // This is just pagesPerSector * pageSize
40 uint32_t totalSize
; // This is just sectorSize * sectors
41 uint16_t pagesPerSector
;
42 flashType_e flashType
;
47 bool (*init
)(int flashNumToUse
);
48 bool (*isReady
)(void);
49 bool (*waitForReady
)(timeMs_t timeoutMillis
);
50 void (*eraseSector
)(uint32_t address
);
51 void (*eraseCompletely
)(void);
52 uint32_t (*pageProgram
)(uint32_t address
, const uint8_t *data
, int length
);
53 int (*readBytes
)(uint32_t address
, uint8_t *buffer
, int length
);
55 const flashGeometry_t
*(*getGeometry
)(void);
60 bool flashIsReady(void);
61 bool flashWaitForReady(timeMs_t timeoutMillis
);
62 void flashEraseSector(uint32_t address
);
63 void flashEraseCompletely(void);
64 uint32_t flashPageProgram(uint32_t address
, const uint8_t *data
, int length
);
65 int flashReadBytes(uint32_t address
, uint8_t *buffer
, int length
);
66 void flashFlush(void);
67 const flashGeometry_t
*flashGetGeometry(void);
70 // flash partitioning api
73 typedef struct flashPartition_s
{
75 flashSector_t startSector
;
76 flashSector_t endSector
;
79 #define FLASH_PARTITION_SECTOR_COUNT(partition) (partition->endSector + 1 - partition->startSector) // + 1 for inclusive, start and end sector can be the same sector.
81 // Must be in sync with flashPartitionTypeNames[]
82 // Should not be deleted or reordered once the code is writing a table to a flash.
84 FLASH_PARTITION_TYPE_UNKNOWN
= 0,
85 FLASH_PARTITION_TYPE_PARTITION_TABLE
,
86 FLASH_PARTITION_TYPE_FLASHFS
,
87 FLASH_PARTITION_TYPE_BADBLOCK_MANAGEMENT
,
88 FLASH_PARTITION_TYPE_FIRMWARE
,
89 FLASH_PARTITION_TYPE_CONFIG
,
90 FLASH_PARTITION_TYPE_FULL_BACKUP
,
91 FLASH_PARTITION_TYPE_FIRMWARE_UPDATE_META
,
92 FLASH_PARTITION_TYPE_UPDATE_FIRMWARE
,
94 } flashPartitionType_e
;
96 typedef struct flashPartitionTable_s
{
97 flashPartition_t partitions
[FLASH_MAX_PARTITIONS
];
98 } flashPartitionTable_t
;
100 void flashPartitionSet(uint8_t index
, uint32_t startSector
, uint32_t endSector
);
101 flashPartition_t
*flashPartitionFindByType(flashPartitionType_e type
);
102 const flashPartition_t
*flashPartitionFindByIndex(uint8_t index
);
103 const char *flashPartitionGetTypeName(flashPartitionType_e type
);
104 int flashPartitionCount(void);
105 uint32_t flashPartitionSize(flashPartition_t
*partition
);
106 void flashPartitionErase(flashPartition_t
*partition
);
108 //#endif [> USE_FLASHFS <]