-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperipheral.h
41 lines (32 loc) · 1.32 KB
/
peripheral.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
#ifndef __PERIPHERAL_H__
#define __PERIPHERAL_H__
template<typename T> struct peripheral
{
protected:
volatile T *const ptr;
public:
constexpr peripheral(const long addr) noexcept : ptr((volatile T *const)addr) { }
constexpr operator volatile T *() const noexcept { return ptr; }
constexpr volatile T *operator ->() const noexcept { return ptr; }
constexpr volatile T *addr() const noexcept { return ptr; }
peripheral() = delete;
peripheral(const peripheral<T> &) = delete;
peripheral(peripheral<T> &&) = delete;
peripheral<T> &operator =(peripheral<T> &) = delete;
peripheral<T> &operator =(peripheral<T> &&) = delete;
};
template<typename T, long address> struct constPeripheral
{
protected:
constexpr static volatile T *const ptr = (volatile T *const)address;
public:
constexpr constPeripheral() noexcept { }
constexpr operator volatile T *() const noexcept { return ptr; }
constexpr volatile T *operator ->() const noexcept { return ptr; }
constexpr volatile T *addr() const noexcept { return ptr; }
constPeripheral(const constPeripheral<T, address> &) = delete;
constPeripheral(constPeripheral<T, address> &&) = delete;
constPeripheral<T, address> &operator =(constPeripheral<T, address> &) = delete;
constPeripheral<T, address> &operator =(constPeripheral<T, address> &&) = delete;
};
#endif /*__PERIPHERAL_H__*/