-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccessors.h
81 lines (75 loc) · 2.46 KB
/
accessors.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
#ifndef _ACCESSORS_H_
#define _ACCESSORS_H_
// Copyright (c) 2020 Jan Brittenson
// See LICENSE for details.
// This file contains accessor names. The reason for this file
// is that we collect control registers into uniform namespaces
// in the form of classes.
// For example,
// template <volatile uint8_t& _CTL0>
// class UCA {
// ...
// };
// The idea here is that UCA.CTL0 is used instead of the actual
// control register, but the template parameter (_CTL0) isn't public
// and doesn't exist outside the declaration and function definitions,
// so it's not possible to access it directly. With a type we could
// use a C++11 type alias that's public. With an scalar we could use
// an enum. But with references, functions, and some other types this
// isn't possible.
// We could use:
// volatile uint8_t& CTL0;
// UCA() : CTL0(_CTL0) { }
// This works, but adds memory footprint wherever we want to derive
// something from this namespace.
// So we use an accessor of the form:
// typeof _CTL0 CTL0() { return _CTL0; }
// However, it's kind of awkward and not particularly pleasant to
// use:
// UCA.CTL0() = 0xff;
// The code using CTL0 shouldn't have to know it's a function. So
// what we actually do is:
// typeof _CTL0 getCTL0() { return _CTL0; }
// #define CTL0 getCTL0()
// But, since #define's are global in scope they can only be added
// once, in a global scope. Hence they are collected in this file.
#define force_inline inline __attribute__((always_inline))
#define ACCESSOR(TYPE, FUNC, TPARM) \
static force_inline TYPE FUNC() { return TPARM; }
#define ABCTL getABCTL()
#define BR0 getBR0()
#define BR1 getBR1()
#define CTL getCTL()
#define CTL0 getCTL0()
#define CTL1 getCTL1()
#define I2CIE getI2CIE()
#define I2COA getI2COA()
#define I2CSA getI2CSA()
#define CPU_IE2 getIE2()
#define CPU_IFG getIFG()
#define CPU_IFG2 getIFG2()
#define P_DIR getPDIR()
#define P_IN getPIN()
#define P_OUT getPOUT()
#define P_SEL getPSEL()
#define P_SEL2 getPSEL2()
#define P_REN getPREN()
#define P_DS getPDS()
#define P_IFG getPIFG()
#define P_IES getPIES()
#define P_IE getPIE()
#define IRRCTL getIRRCTL()
#define IRTCTL getIRTCTL()
#define MCTL getMCTL()
#define RXBUF getRXBUF()
#define STAT getSTAT()
#define TA_CCTL0 getCCTL0()
#define TA_CCR0 getCCR0()
#define TA_CCTL1 getCCTL1()
#define TA_CCR1 getCCR1()
#define TA_CCTL2 getCCTL2()
#define TA_CCR2 getCCR2()
#define TA_IV getIV()
#define TA_R getR()
#define TXBUF getTXBUF()
#endif // _ACCESSORS_H_