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 
23 #ifndef MTD_H
24 #define MTD_H
25 
26 #include <stdint.h>
27 #if MODULE_VFS
28 #include "vfs.h"
29 #endif
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
41 };
42 
53 typedef struct mtd_desc mtd_desc_t;
54 
58 typedef struct {
59  const mtd_desc_t *driver;
60  uint32_t sector_count;
61  uint32_t pages_per_sector;
62  uint32_t page_size;
63 } mtd_dev_t;
64 
75 struct mtd_desc {
84  int (*init)(mtd_dev_t *dev);
85 
99  int (*read)(mtd_dev_t *dev,
100  void *buff,
101  uint32_t addr,
102  uint32_t size);
103 
119  int (*read_page)(mtd_dev_t *dev,
120  void *buff,
121  uint32_t page,
122  uint32_t offset,
123  uint32_t size);
124 
139  int (*write)(mtd_dev_t *dev,
140  const void *buff,
141  uint32_t addr,
142  uint32_t size);
143 
159  int (*write_page)(mtd_dev_t *dev,
160  const void *buff,
161  uint32_t page,
162  uint32_t offset,
163  uint32_t size);
164 
177  int (*erase)(mtd_dev_t *dev,
178  uint32_t addr,
179  uint32_t size);
180 
192  int (*erase_sector)(mtd_dev_t *dev,
193  uint32_t sector,
194  uint32_t count);
195 
205  int (*power)(mtd_dev_t *dev, enum mtd_power_state power);
206 };
207 
215 int mtd_init(mtd_dev_t *mtd);
216 
234 int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count);
235 
257 int mtd_read_page(mtd_dev_t *mtd, void *dest, uint32_t page, uint32_t offset, uint32_t size);
258 
280 int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count);
281 
305 int mtd_write_page(mtd_dev_t *mtd, const void *src, uint32_t page, uint32_t offset, uint32_t size);
306 
323 int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count);
324 
339 int mtd_erase_sector(mtd_dev_t *mtd, uint32_t sector, uint32_t num);
340 
353 int mtd_power(mtd_dev_t *mtd, enum mtd_power_state power);
354 
355 #if defined(MODULE_VFS) || defined(DOXYGEN)
356 
359 extern const vfs_file_ops_t mtd_vfs_ops;
360 #endif
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 
366 #endif /* MTD_H */
367 
mtd_desc::write
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:139
mtd_desc::read_page
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:119
mtd_desc::power
int(* power)(mtd_dev_t *dev, enum mtd_power_state power)
Control power of Memory Technology Device (MTD)
Definition: mtd.h:205
mtd_dev_t
MTD device descriptor.
Definition: mtd.h:58
mtd_dev_t::driver
const mtd_desc_t * driver
MTD driver.
Definition: mtd.h:59
mtd_write
int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count)
Write data to a MTD device.
mtd_power_state
mtd_power_state
MTD power states.
Definition: mtd.h:38
mtd_write_page
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.
MTD_POWER_DOWN
@ MTD_POWER_DOWN
Power down.
Definition: mtd.h:40
mtd_vfs_ops
const vfs_file_ops_t mtd_vfs_ops
MTD driver for VFS.
mtd_desc
MTD driver interface.
Definition: mtd.h:75
mtd_dev_t::page_size
uint32_t page_size
Size of the pages in the MTD.
Definition: mtd.h:62
mtd_read
int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count)
Read data from a MTD device.
mtd_desc::erase
int(* erase)(mtd_dev_t *dev, uint32_t addr, uint32_t size)
Erase sector(s) over the Memory Technology Device (MTD)
Definition: mtd.h:177
mtd_dev_t::sector_count
uint32_t sector_count
Number of sector in the MTD.
Definition: mtd.h:60
mtd_erase
int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count)
Erase sectors of a MTD device.
mtd_erase_sector
int mtd_erase_sector(mtd_dev_t *mtd, uint32_t sector, uint32_t num)
Erase sectors of a MTD device.
mtd_init
int mtd_init(mtd_dev_t *mtd)
mtd_init Initialize a MTD device
mtd_desc::write_page
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:159
mtd_desc::init
int(* init)(mtd_dev_t *dev)
Initialize Memory Technology Device (MTD)
Definition: mtd.h:84
mtd_dev_t::pages_per_sector
uint32_t pages_per_sector
Number of pages by sector in the MTD.
Definition: mtd.h:61
mtd_desc::erase_sector
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:192
mtd_read_page
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.
mtd_desc::read
int(* read)(mtd_dev_t *dev, void *buff, uint32_t addr, uint32_t size)
Read from the Memory Technology Device (MTD)
Definition: mtd.h:99
vfs_file_ops
Operations on open files.
Definition: vfs.h:328
mtd_power
int mtd_power(mtd_dev_t *mtd, enum mtd_power_state power)
Set power mode on a MTD device.
vfs.h
VFS layer API declarations.
MTD_POWER_UP
@ MTD_POWER_UP
Power up.
Definition: mtd.h:39