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 
118  int (*write)(mtd_dev_t *dev,
119  const void *buff,
120  uint32_t addr,
121  uint32_t size);
122 
135  int (*erase)(mtd_dev_t *dev,
136  uint32_t addr,
137  uint32_t size);
138 
148  int (*power)(mtd_dev_t *dev, enum mtd_power_state power);
149 };
150 
158 int mtd_init(mtd_dev_t *mtd);
159 
177 int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count);
178 
198 int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count);
199 
216 int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count);
217 
230 int mtd_power(mtd_dev_t *mtd, enum mtd_power_state power);
231 
232 #if defined(MODULE_VFS) || defined(DOXYGEN)
233 
236 extern const vfs_file_ops_t mtd_vfs_ops;
237 #endif
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #endif /* MTD_H */
244 
int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count)
mtd_erase Erase sectors of a MTD device
uint32_t sector_count
Number of sector in the MTD.
Definition: mtd.h:60
int(* power)(mtd_dev_t *dev, enum mtd_power_state power)
Control power of Memory Technology Device (MTD)
Definition: mtd.h:148
uint32_t pages_per_sector
Number of pages by sector in the MTD.
Definition: mtd.h:61
MTD driver interface.
Definition: mtd.h:75
VFS layer API declarations.
Power up.
Definition: mtd.h:39
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:118
int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count)
mtd_read write data to a MTD device
int mtd_init(mtd_dev_t *mtd)
mtd_init Initialize a MTD device
const mtd_desc_t * driver
MTD driver.
Definition: mtd.h:59
int(* init)(mtd_dev_t *dev)
Initialize Memory Technology Device (MTD)
Definition: mtd.h:84
int(* erase)(mtd_dev_t *dev, uint32_t addr, uint32_t size)
Erase sector(s) over the Memory Technology Device (MTD)
Definition: mtd.h:135
uint32_t page_size
Size of the pages in the MTD.
Definition: mtd.h:62
mtd_power_state
MTD power states.
Definition: mtd.h:38
MTD device descriptor.
Definition: mtd.h:58
Operations on open files.
Definition: vfs.h:234
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
int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count)
mtd_read Read data from a MTD device
int mtd_power(mtd_dev_t *mtd, enum mtd_power_state power)
mtd_power Set power mode on a MTD device
Power down.
Definition: mtd.h:40
const vfs_file_ops_t mtd_vfs_ops
MTD driver for VFS.