The friendly Operating System for the Internet of Things
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 
22 #ifndef MTD_H
23 #define MTD_H
24 
25 #include <stdint.h>
26 #if MODULE_VFS
27 #include "vfs.h"
28 #endif
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
40 };
41 
52 typedef struct mtd_desc mtd_desc_t;
53 
57 typedef struct {
58  const mtd_desc_t *driver;
59  uint32_t sector_count;
60  uint32_t pages_per_sector;
61  uint32_t page_size;
62 } mtd_dev_t;
63 
74 struct mtd_desc {
83  int (*init)(mtd_dev_t *dev);
84 
98  int (*read)(mtd_dev_t *dev,
99  void *buff,
100  uint32_t addr,
101  uint32_t size);
102 
117  int (*write)(mtd_dev_t *dev,
118  const void *buff,
119  uint32_t addr,
120  uint32_t size);
121 
134  int (*erase)(mtd_dev_t *dev,
135  uint32_t addr,
136  uint32_t size);
137 
147  int (*power)(mtd_dev_t *dev, enum mtd_power_state power);
148 };
149 
157 int mtd_init(mtd_dev_t *mtd);
158 
176 int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count);
177 
197 int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count);
198 
215 int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count);
216 
229 int mtd_power(mtd_dev_t *mtd, enum mtd_power_state power);
230 
231 #if defined(MODULE_VFS) || defined(DOXYGEN)
232 
235 extern const vfs_file_ops_t mtd_vfs_ops;
236 #endif
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 
243 #endif /* MTD_H */
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:59
int(* power)(mtd_dev_t *dev, enum mtd_power_state power)
Control power of Memory Technology Device (MTD)
Definition: mtd.h:147
int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count)
mtd_read write data to a MTD device
uint32_t pages_per_sector
Number of pages by sector in the MTD.
Definition: mtd.h:60
MTD driver interface.
Definition: mtd.h:74
VFS layer API declarations.
Power down.
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:117
int mtd_init(mtd_dev_t *mtd)
mtd_init Initialize a MTD device
int mtd_power(mtd_dev_t *mtd, enum mtd_power_state power)
mtd_power Set power mode on a MTD device
const mtd_desc_t * driver
MTD driver.
Definition: mtd.h:58
int(* init)(mtd_dev_t *dev)
Initialize Memory Technology Device (MTD)
Definition: mtd.h:83
mtd_power_state
MTD power states.
Definition: mtd.h:37
int(* erase)(mtd_dev_t *dev, uint32_t addr, uint32_t size)
Erase sector(s) over the Memory Technology Device (MTD)
Definition: mtd.h:134
uint32_t page_size
Size of the pages in the MTD.
Definition: mtd.h:61
MTD device descriptor.
Definition: mtd.h:57
Operations on open files.
Definition: vfs.h:234
int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count)
mtd_read Read data from a MTD device
int(* read)(mtd_dev_t *dev, void *buff, uint32_t addr, uint32_t size)
Read from the Memory Technology Device (MTD)
Definition: mtd.h:98
const vfs_file_ops_t mtd_vfs_ops
MTD driver for VFS.
Power up.
Definition: mtd.h:38