YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
dma_msp432.h
1#ifndef _DMA_MSP432_H_
2#define _DMA_MSP432_H_
3
4#include <stdint.h>
5
6#define __RO const volatile
7#define __WO volatile
8#define __RW volatile
9
11// Helper templates and macros
13template<typename T, int Offset, int Bits>
15{
16private:
17 T value; // This is the value which is 'mirrored' by the union
18 static const T max = (T(1) << Bits) - T(1);
19
20public:
21 inline operator T() const
22 {
23 return (value >> Offset) & max;
24 }
25};
26
27template<typename T, int Offset, int Bits>
29{
30private:
31 T value; // This is the value which is 'mirrored' by the union
32 static const T max = (T(1) << Bits) - T(1);
33 static const T mask = max << Offset;
34
35public:
36 inline BitFieldMember_WO & operator=(T v)
37 {
38 value = (value & ~mask) | ((v & max) << Offset);
39 return *this;
40 }
41};
42
43template<typename T, int Offset, int Bits>
45{
46private:
47 T value; // This is the value which is 'mirrored' by the union
48 static const T max = (T(1) << Bits) - T(1);
49 static const T mask = max << Offset;
50
51public:
52 inline operator T() const
53 {
54 return (value >> Offset) & max;
55 }
56 inline BitFieldMember_RW & operator=(T v)
57 {
58 value = (value & ~mask) | ((v & max) << Offset);
59 return *this;
60 }
61};
62
63#define BEGIN_BITFIELD_TYPE(typeName, T) \
64 union typeName \
65 { \
66 T value{0}; \
67 typeName& operator=(T v) { value = v; return *this; } \
68 operator T&() { return value; } \
69 operator T() const { return value; } \
70 typedef T StorageType;
71
72#define ADD_BITFIELD_MEMBER_RO(memberName, offset, bits) \
73 BitFieldMember_RO<StorageType, offset, bits> memberName;
74
75#define ADD_BITFIELD_MEMBER_WO(memberName, offset, bits) \
76 BitFieldMember_WO<StorageType, offset, bits> memberName;
77
78#define ADD_BITFIELD_MEMBER_RW(memberName, offset, bits) \
79 BitFieldMember_RW<StorageType, offset, bits> memberName;
80
81#define END_BITFIELD_TYPE() \
82 };
83
85// Control Data Configuration //
87
88namespace DMA
89{
90 BEGIN_BITFIELD_TYPE(ctrl_data_conf_t, uint32_t)
91 ADD_BITFIELD_MEMBER_RW(CYCLE_CTRL, 0, 3)
92 ADD_BITFIELD_MEMBER_RW(NEXT_USEBURST, 3, 1)
93 ADD_BITFIELD_MEMBER_RW(N_MINUS_1, 4, 10)
94 ADD_BITFIELD_MEMBER_RW(R_POWER, 14, 4)
95 ADD_BITFIELD_MEMBER_RW(SRC_PROT_CTRL, 18, 3)
96 ADD_BITFIELD_MEMBER_RW(DST_PROT_CTRL, 21, 3)
97 ADD_BITFIELD_MEMBER_RW(SRC_SIZE, 24, 2)
98 ADD_BITFIELD_MEMBER_RW(SRC_INC, 26, 2)
99 ADD_BITFIELD_MEMBER_RW(DST_SIZE, 28, 2)
100 ADD_BITFIELD_MEMBER_RW(DST_INC, 30, 2)
101 END_BITFIELD_TYPE()
102
103 // values for CYCLE_CTRL bitfield
104 const uint8_t CYCLE_STOP = 0;
105 const uint8_t CYCLE_BASIC = 1;
106 const uint8_t CYCLE_AUTO_REQUEST = 2;
107 const uint8_t CYCLE_PING_PONG = 3;
108 const uint8_t CYCLE_MEM_SCATTER_GATHER_PRI = 4;
109 const uint8_t CYCLE_MEM_SCATTER_GATHER_ALT = 5;
110 const uint8_t CYCLE_PERI_SCATTER_GATHER_PRI = 6;
111 const uint8_t CYCLE_PERI_SCATTER_GATHER_ALT = 7;
112
113 // values for R_POWER bitfield
114 const uint8_t ARB_AFTER_1 = 0;
115 const uint8_t ARB_AFTER_2 = 1;
116 const uint8_t ARB_AFTER_4 = 2;
117 const uint8_t ARB_AFTER_8 = 3;
118 const uint8_t ARB_AFTER_16 = 4;
119 const uint8_t ARB_AFTER_32 = 5;
120 const uint8_t ARB_AFTER_64 = 6;
121 const uint8_t ARB_AFTER_128 = 7;
122 const uint8_t ARB_AFTER_256 = 8;
123 const uint8_t ARB_AFTER_512 = 9;
124 const uint8_t ARB_AFTER_1024 = 10;
125
126 // values for SIZE and INC bitfields
127 const uint8_t BYTE = 0;
128 const uint8_t HALFWORD = 1;
129 const uint8_t WORD = 2;
130 const uint8_t NO_INCREMENT = 3;
131
133 {
134 __RW void * SRC_DATA_END_PTR;
135 __RW void * DST_DATA_END_PTR;
136 ctrl_data_conf_t CTRL;
137 __RW uint32_t unused = 0;
138 };
139}
140
142public:
143 // DMA is a singleton...
144 static dma_msp432 & inst();
145
146 // public structure for 8 primary
147 // and 8 alternate channels
148 __attribute__ ((aligned (256)))
149 DMA::CH_CTRL_DATA ctrl_data[16];
150
151private:
152 static dma_msp432 _inst;
153 dma_msp432();
154};
155
156#endif // _DMA_MSP432_H_
void __attribute__((noreturn))(*rom_reset_usb_boot_fn)(uint32_t
Reboot the device into BOOTSEL mode.
Definition bootrom.h:66