-
Notifications
You must be signed in to change notification settings - Fork 0
/
force32.h
49 lines (38 loc) · 957 Bytes
/
force32.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
//
// Created by andyh on 2/6/21.
//
#pragma once
#include "bitbanger.h"
/** some peripherals have a requirement of aligned 32 bit write.
* gcc will optimize a write or field insert to only manipulate the bytes changing, which for these memory spaces leads to bad things.
*
* This "unsigned workalike" class alows you to manipulate the pattern for such a beast, and writes it on exit of scope.
* */
class Force32 {
unsigned &wordwide;
public:
unsigned cache;
public:
Force32(unsigned &wordwide):wordwide(wordwide),cache(wordwide){}
void flush() {
wordwide = cache;
}
~Force32() {
flush();
}
operator unsigned () {
return cache;
}
Force32& operator |=(unsigned rhs) {
cache |=rhs;
return *this;
}
Force32& operator &=(unsigned rhs) {
cache &=rhs;
return *this;
}
Force32& set(unsigned msb,unsigned lsb,unsigned pattern) {
mergeField(cache,pattern,msb,lsb);
return *this;
}
};