-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCoreAVR.h
More file actions
70 lines (58 loc) · 1.87 KB
/
CoreAVR.h
File metadata and controls
70 lines (58 loc) · 1.87 KB
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
// import header files or add definitions here that you want to be visible
// within Swift via the clang importer
// note that many gcc constructs will not work, if you are having trouble
// getting something to compile, add a normal .c file (and optionally header)
// with wrapper functions, then declare the wrapper function here instead
#define cpuFrequency F_CPU
#include <stdint.h>
/**
* @brief Read a 32-bit value from a volatile pointer.
* @param ptr The pointer to read from.
* @return The value read.
*/
static inline uint8_t _volatileRegisterReadUInt8(uintptr_t address) {
volatile uint8_t *ptr = (volatile uint8_t *)address;
return *ptr;
}
/**
* @brief Write a 32-bit value to a volatile pointer.
* @param ptr The pointer to write to.
* @param value The value to write.
*/
static inline void _volatileRegisterWriteUInt8(uintptr_t address, uint8_t value) {
volatile uint8_t *ptr = (volatile uint8_t *)address;
*ptr = value;
}
/**
* @brief Read a 32-bit value from a volatile pointer.
* @param ptr The pointer to read from.
* @return The value read.
*/
static inline uint16_t _volatileRegisterReadUInt16(uintptr_t address) {
volatile uint16_t *ptr = (volatile uint16_t *)address;
return *ptr;
}
/**
* @brief Write a 32-bit value to a volatile pointer.
* @param ptr The pointer to write to.
* @param value The value to write.
*/
static inline void _volatileRegisterWriteUInt16(uintptr_t address, uint16_t value) {
volatile uint16_t *ptr = (volatile uint16_t *)address;
*ptr = value;
}
static inline void _noOpperation() {
asm volatile("nop");
}
/**
* @brief Inserts a "Global Interrupt Enable" (`sei`) instruction at the current location.
*/
static inline void _sei() {
asm volatile("sei");
}
/**
* @brief Inserts a "Global Interrupt Disable" (`cli`) instruction at the current location.
*/
static inline void _cli() {
asm volatile("cli");
}