-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathmcal_memory_progmem.h
72 lines (54 loc) · 2.22 KB
/
mcal_memory_progmem.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
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2019 - 2020.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MCAL_MEMORY_PROGMEM_2019_08_17_H_
#define MCAL_MEMORY_PROGMEM_2019_08_17_H_
#include <stdint.h>
#define MY_PROGMEM
#if defined(__cplusplus)
extern "C"
{
#endif
typedef uintptr_t mcal_progmem_uintptr_t;
typedef ptrdiff_t mcal_progmem_ptrdiff_t;
#define MCAL_PROGMEM_ADDRESSOF(x) ((mcal_progmem_uintptr_t) (&(x)))
static inline uint8_t mcal_memory_progmem_read_byte(const mcal_progmem_uintptr_t src_addr)
{
return *(const uint8_t*) src_addr;
}
static inline uint16_t mcal_memory_progmem_read_word(const mcal_progmem_uintptr_t src_addr)
{
uint16_t dest;
*(((uint8_t*) &dest) + 0U) = *((const uint8_t*) (src_addr + 0U));
*(((uint8_t*) &dest) + 1U) = *((const uint8_t*) (src_addr + 1U));
return dest;
}
static inline uint32_t mcal_memory_progmem_read_dword(const mcal_progmem_uintptr_t src_addr)
{
uint32_t dest;
*(((uint8_t*) &dest) + 0U) = *((const uint8_t*) (src_addr + 0U));
*(((uint8_t*) &dest) + 1U) = *((const uint8_t*) (src_addr + 1U));
*(((uint8_t*) &dest) + 2U) = *((const uint8_t*) (src_addr + 2U));
*(((uint8_t*) &dest) + 3U) = *((const uint8_t*) (src_addr + 3U));
return dest;
}
static inline uint64_t mcal_memory_progmem_read_qword(const mcal_progmem_uintptr_t src_addr)
{
uint64_t dest;
*(((uint8_t*) &dest) + 0U) = *((const uint8_t*) (src_addr + 0U));
*(((uint8_t*) &dest) + 1U) = *((const uint8_t*) (src_addr + 1U));
*(((uint8_t*) &dest) + 2U) = *((const uint8_t*) (src_addr + 2U));
*(((uint8_t*) &dest) + 3U) = *((const uint8_t*) (src_addr + 3U));
*(((uint8_t*) &dest) + 4U) = *((const uint8_t*) (src_addr + 4U));
*(((uint8_t*) &dest) + 5U) = *((const uint8_t*) (src_addr + 5U));
*(((uint8_t*) &dest) + 6U) = *((const uint8_t*) (src_addr + 6U));
*(((uint8_t*) &dest) + 7U) = *((const uint8_t*) (src_addr + 7U));
return dest;
}
#if defined(__cplusplus)
}
#endif
#endif // MCAL_MEMORY_PROGMEM_2019_08_17_H_