YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
block_io_interface.h
1// ---------------------------------------------
2// This file is part of
3// _ _ __ _ _ __ __
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
7//
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
11//
12// ---------------------------------------------
13//
14// This file defines a generic and abstract C++
15// interface for all kinds low-level mass storages.
16// Single blocks of 512 bytes can be read and written.
17
18#ifndef _BLOCK_IO_INTERFACE_H_
19#define _BLOCK_IO_INTERFACE_H_
20
21#include <cstdint>
22
23typedef uint8_t blockio_status_t;
24
25namespace BLOCKIO {
26 // Enum for return value of blockio operations
27 enum result_t {
28 OK = 0, // 0: Successful
29 ERROR = 1, // 1: R/W Error
30 WRPRT = 2, // 2: Write Protected
31 NOTRDY = 3, // 3: Not Ready
32 PARERR = 4 // 4: Invalid Parameter
33 };
34 // Bit masks for device status
35 const blockio_status_t NOINIT = 0x01;
36 const blockio_status_t NODISK = 0x02;
37 const blockio_status_t PROTECT = 0x04;
38}
39
41public:
42 // Initialize device and return status
43 virtual blockio_status_t initialize() = 0;
44
45 // Get current device status
46 virtual blockio_status_t status() = 0;
47
48 // Read in 'count' 512-byte blocks. Start reading at 'start_block'.
49 // Store the data in buff, which has to point to a memory buffer
50 // with at least 512 * count bytes size.
51 virtual BLOCKIO::result_t readBlock(uint8_t* buff, uint32_t start_block,
52 uint16_t count) = 0;
53
54 // Write 'count' 512-byte blocks. Start storing at 'start_block'.
55 // Read the data from buff, which has to point to a memory buffer
56 // with at least 512 * count bytes size.
57 virtual BLOCKIO::result_t writeBlock(const uint8_t* buff, uint32_t start_block,
58 uint16_t count) = 0;
59
60 // Get the block count (total size of device is 512 * count bytes)
61 virtual uint32_t getBlockCount() = 0;
62
63 // Sync the IO device (dirty buffers are written)
64 virtual BLOCKIO::result_t sync() = 0;
65
66protected:
67 virtual ~block_io_interface() = default;
68};
69
70#endif // _BLOCK_IO_INTERFACE_H_
71