-
Notifications
You must be signed in to change notification settings - Fork 123
/
block_device.hpp
111 lines (96 loc) · 3.06 KB
/
block_device.hpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// coding: utf-8
/*
* Copyright (c) 2018, Raphael Lehmann
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------
#ifndef MODM_INTERFACE_BLOCK_DEVICE_HPP
#define MODM_INTERFACE_BLOCK_DEVICE_HPP
#include <stdint.h>
#include <modm/processing/resumable.hpp>
namespace modm
{
/**
* Interface of a Block Device
*
* Access to storage devices like flash chips
*
* @author Raphael Lehmann
* @ingroup modm_architecture_block_device
*/
class BlockDevice
{
public:
BlockDevice() = default;
BlockDevice(const BlockDevice&) = delete;
BlockDevice& operator= (const BlockDevice&) = delete;
using bd_address_t = uint32_t;
using bd_size_t = uint32_t;
#ifdef __DOXYGEN__
public:
/// Initializes the storage hardware
modm::ResumableResult<bool>
initialize();
/// Deinitializes the storage hardware
modm::ResumableResult<bool>
deinitialize();
/** Read data from one or more blocks
*
* @param buffer Buffer to read data into
* @param address Address to begin reading from
* @param size Size to read in bytes (multiple of read block size)
* @return True on success
*/
modm::ResumableResult<bool>
read(uint8_t *buffer, bd_address_t address, bd_size_t size);
/** Program blocks with data
*
* Any block has to be erased prior to being programmed
*
* @param buffer Buffer of data to write to blocks
* @param address Address of first block to begin writing to
* @param size Size to write in bytes (multiple of read block size)
* @return True on success
*/
modm::ResumableResult<bool>
program(const uint8_t *buffer, bd_address_t address, bd_size_t size);
/** Erase blocks
*
* The state of an erased block is undefined until it has been programmed
*
* @param address Address of block to begin erasing
* @param size Size to erase in bytes (multiple of read block size)
* @return True on success
*/
modm::ResumableResult<bool>
erase(bd_address_t address, bd_size_t size);
/** Writes data to one or more blocks after erasing them
*
* The blocks are erased proir to being programmed
*
* @param buffer Buffer of data to write to blocks
* @param address Address of first block to begin writing to
* @param size Size to write in bytes (multiple of read block size)
* @return True on success
*/
modm::ResumableResult<bool>
write(const uint8_t *buffer, bd_address_t address, bd_size_t size);
public:
/** Minimum block sizes for block device operations
*
* Most persistent storage devices require `program()`, `erase()`
* and sometimes `read()` operations to be executed on fixed sized blocks.
*/
static constexpr bd_size_t BlockSizeRead = 1;
static constexpr bd_size_t BlockSizeWrite = 1;
static constexpr bd_size_t BlockSizeErase = 1;
static constexpr bd_size_t BlockDevice = 1'024;
#endif
};
} // namespace modm
#endif // MODM_INTERFACE_BLOCK_DEVICE_HPP