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
112
113
114
// Copyright (C) 2018 Adam Gausmann
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Memory access utilities.
use OpenOptions;
use io;
use ;
/// A view into a memory map that splits it into "registers."
///
/// All reads and writes are 32-bit, as they are currently the only size
/// required by BCM283x peripherals. This data structure is a convenience
/// for 32-bit memory operations at any offset within the mapped data.
///
/// Internally, the specified location in memory is mapped using the
/// `/dev/mem` file. Unfortunately, this method requires root privileges,
/// but this may not be such a problem in the majority of use cases for this
/// library.
///
/// Registers may only be accessed via getters and setters. There is no
/// option to request a (mutable) reference because it would be unsafe
/// to do so. Registers may change at any time regardless of the mutability
/// of the reference that is held (since they are controlled by the system),
/// so it is only valid to receive its current state and set it via another
/// separate call once the new data is ready.
///
/// # Safety
///
/// In general, the ability to access arbitrary memory is a _very_ dangerous
/// privilege to have. For convenience, the only unsafe operation is the
/// constructur which is when the memory is mapped. Once that has happened,
/// it is assumed that the user has accepted the risks.