-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathflash-mtd.h
86 lines (70 loc) · 2.05 KB
/
flash-mtd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @file flash-mtd.h
* @brief FLASH25 main include file
* @author Vladimir Ermakov Copyright (C) 2014.
*/
/*
* chibios-flash
* Copyright (c) 2014, Vlidimir Ermakov, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
#ifndef FLASH_MTD_H
#define FLASH_MTD_H
/* ChibiOS block */
#include "hal.h"
#include "mtd_config.h"
/* -*- debugging print -*- */
#ifndef MTD_DEBUG
#define MTD_DEBUG(fmt, arg...)
#endif
#ifndef MTD_INFO
#define MTD_INFO(fmt, arg...)
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
#endif
/** Base MTD driver methods
*/
#define _base_mtd_driver_methods \
_base_block_device_methods \
bool (*erase)(void *instance, uint32_t startblk, \
uint32_t n);
/** Base MTD driver data
*/
#define _base_mtd_driver_data \
_base_block_device_data \
const char *name; \
void *parent; \
uint16_t page_size; \
uint16_t erase_size; \
uint32_t nr_pages; \
uint32_t start_page;
struct BaseMTDDriverVMT {
_base_mtd_driver_methods
};
struct mtd_partition {
const char *name;
uint32_t start_page;
uint32_t nr_pages;
};
/* -*- methods -*- */
#define mtdGetEraseSize(flp) ((flp)->erase_size)
#define mtdGetPageSize(flp) ((flp)->page_size)
#define mtdGetSize(flp) ((flp)->page_size * (flp)->nr_pages)
#define mtdGetName(flp) ((flp)->name)
#define mtdErase(flp, sect, n) ((flp)->vmt->erase(flp, sect, n))
#include <inttypes.h>
#include "sst25.h"
#endif /* FLASH25_H */