mtd.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 OTA keys S.A.
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
73 #ifndef MTD_H
74 #define MTD_H
75 
76 #include <stdint.h>
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
88 };
89 
100 typedef struct mtd_desc mtd_desc_t;
101 
108 typedef struct {
110  uint32_t sector_count;
111  uint32_t pages_per_sector;
112  uint32_t page_size;
113  uint32_t write_size;
114 #if defined(MODULE_MTD_WRITE_PAGE) || DOXYGEN
115  void *work_area;
116 #endif
117 } mtd_dev_t;
118 
124 #define MTD_DRIVER_FLAG_DIRECT_WRITE (1 << 0)
125 
137 #define MTD_DRIVER_FLAG_CLEARING_OVERWRITE (1 << 1)
138 
149 struct mtd_desc {
158  int (*init)(mtd_dev_t *dev);
159 
173  int (*read)(mtd_dev_t *dev,
174  void *buff,
175  uint32_t addr,
176  uint32_t size);
177 
193  int (*read_page)(mtd_dev_t *dev,
194  void *buff,
195  uint32_t page,
196  uint32_t offset,
197  uint32_t size);
198 
213  int (*write)(mtd_dev_t *dev,
214  const void *buff,
215  uint32_t addr,
216  uint32_t size);
217 
233  int (*write_page)(mtd_dev_t *dev,
234  const void *buff,
235  uint32_t page,
236  uint32_t offset,
237  uint32_t size);
238 
251  int (*erase)(mtd_dev_t *dev,
252  uint32_t addr,
253  uint32_t size);
254 
266  int (*erase_sector)(mtd_dev_t *dev,
267  uint32_t sector,
268  uint32_t count);
269 
279  int (*power)(mtd_dev_t *dev, enum mtd_power_state power);
280 
284  uint8_t flags;
285 };
286 
294 int mtd_init(mtd_dev_t *mtd);
295 
313 int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count);
314 
334 int mtd_read_page(mtd_dev_t *mtd, void *dest, uint32_t page, uint32_t offset, uint32_t size);
335 
358 int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count);
359 
384 int mtd_write_page_raw(mtd_dev_t *mtd, const void *src, uint32_t page,
385  uint32_t offset, uint32_t size);
386 
414 int mtd_write_page(mtd_dev_t *mtd, const void *src, uint32_t page,
415  uint32_t offset, uint32_t size);
416 
433 int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count);
434 
449 int mtd_erase_sector(mtd_dev_t *mtd, uint32_t sector, uint32_t num);
450 
463 int mtd_power(mtd_dev_t *mtd, enum mtd_power_state power);
464 
465 #ifdef __cplusplus
466 }
467 #endif
468 
469 #endif /* MTD_H */
mtd_power_state
MTD power states.
Definition: mtd.h:85
int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count)
Write data to a MTD device.
int mtd_init(mtd_dev_t *mtd)
mtd_init Initialize a MTD device
int mtd_write_page_raw(mtd_dev_t *mtd, const void *src, uint32_t page, uint32_t offset, uint32_t size)
Write data to a MTD device with pagewise addressing.
int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count)
Read data from a MTD device.
int mtd_read_page(mtd_dev_t *mtd, void *dest, uint32_t page, uint32_t offset, uint32_t size)
Read data from a MTD device with pagewise addressing.
int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count)
Erase sectors of a MTD device.
int mtd_write_page(mtd_dev_t *mtd, const void *src, uint32_t page, uint32_t offset, uint32_t size)
Write data to a MTD device with pagewise addressing.
int mtd_power(mtd_dev_t *mtd, enum mtd_power_state power)
Set power mode on a MTD device.
int mtd_erase_sector(mtd_dev_t *mtd, uint32_t sector, uint32_t num)
Erase sectors of a MTD device.
@ MTD_POWER_DOWN
Power down.
Definition: mtd.h:87
@ MTD_POWER_UP
Power up.
Definition: mtd.h:86
MTD driver interface.
Definition: mtd.h:149
int(* read)(mtd_dev_t *dev, void *buff, uint32_t addr, uint32_t size)
Read from the Memory Technology Device (MTD)
Definition: mtd.h:173
int(* read_page)(mtd_dev_t *dev, void *buff, uint32_t page, uint32_t offset, uint32_t size)
Read from the Memory Technology Device (MTD) using pagewise addressing.
Definition: mtd.h:193
int(* erase)(mtd_dev_t *dev, uint32_t addr, uint32_t size)
Erase sector(s) over the Memory Technology Device (MTD)
Definition: mtd.h:251
int(* erase_sector)(mtd_dev_t *dev, uint32_t sector, uint32_t count)
Erase sector(s) of the Memory Technology Device (MTD)
Definition: mtd.h:266
int(* power)(mtd_dev_t *dev, enum mtd_power_state power)
Control power of Memory Technology Device (MTD)
Definition: mtd.h:279
int(* write_page)(mtd_dev_t *dev, const void *buff, uint32_t page, uint32_t offset, uint32_t size)
Write to the Memory Technology Device (MTD) using pagewise addressing.
Definition: mtd.h:233
uint8_t flags
Properties of the MTD driver.
Definition: mtd.h:284
int(* init)(mtd_dev_t *dev)
Initialize Memory Technology Device (MTD)
Definition: mtd.h:158
int(* write)(mtd_dev_t *dev, const void *buff, uint32_t addr, uint32_t size)
Write to the Memory Technology Device (MTD)
Definition: mtd.h:213
MTD device descriptor.
Definition: mtd.h:108
uint32_t write_size
Minimum size and alignment of writes to the device.
Definition: mtd.h:113
uint32_t pages_per_sector
Number of pages by sector in the MTD.
Definition: mtd.h:111
uint32_t sector_count
Number of sector in the MTD.
Definition: mtd.h:110
const mtd_desc_t * driver
MTD driver.
Definition: mtd.h:109
void * work_area
sector-sized buffer (only present when mtd_write_page is enabled)
Definition: mtd.h:115
uint32_t page_size
Size of the pages in the MTD.
Definition: mtd.h:112