1
- /*
2
- pgmspace.h - Definitions for compatibility with AVR pgmspace macros
3
-
4
- Copyright (c) 2015 Arduino LLC
5
-
6
- Based on work of Paul Stoffregen on Teensy 3 (http://pjrc.com)
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy
9
- of this software and associated documentation files (the "Software"), to deal
10
- in the Software without restriction, including without limitation the rights
11
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- copies of the Software, and to permit persons to whom the Software is
13
- furnished to do so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in
16
- all copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- THE SOFTWARE
25
- */
1
+ /* Simple compatibility headers for AVR code used with ARM chips
2
+ * Copyright (c) 2015 Paul Stoffregen <[email protected] >
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ * THE SOFTWARE.
21
+ */
26
22
27
23
#ifndef __PGMSPACE_H_
28
24
#define __PGMSPACE_H_ 1
@@ -44,27 +40,91 @@ typedef int16_t prog_int16_t;
44
40
typedef uint16_t prog_uint16_t ;
45
41
typedef int32_t prog_int32_t ;
46
42
typedef uint32_t prog_uint32_t ;
43
+ typedef int64_t prog_int64_t ;
44
+ typedef uint64_t prog_uint64_t ;
47
45
46
+ #define memchr_P (str , c , len ) memchr((str), (c), (len))
47
+ #define memcmp_P (a , b , n ) memcmp((a), (b), (n))
48
48
#define memcpy_P (dest , src , num ) memcpy((dest), (src), (num))
49
- #define strcpy_P (dest , src ) strcpy((dest), (src))
49
+ #define memmem_P (a , alen , b , blen ) memmem((a), (alen), (b), (blen))
50
+ #define memrchr_P (str , val , len ) memrchr((str), (val), (len))
50
51
#define strcat_P (dest , src ) strcat((dest), (src))
52
+ #define strchr_P (str , c ) strchr((str), (c))
53
+ #define strchrnul_P (str , c ) strchrnul((str), (c))
51
54
#define strcmp_P (a , b ) strcmp((a), (b))
55
+ #define strcpy_P (dest , src ) strcpy((dest), (src))
56
+ #define strcasecmp_P (a , b ) strcasecmp((a), (b))
57
+ #define strcasestr_P (a , b ) strcasestr((a), (b))
58
+ #define strlcat_P (dest , src , len ) strlcat((dest), (src), (len))
59
+ #define strlcpy_P (dest , src , len ) strlcpy((dest), (src), (len))
60
+ #define strlen_P (s ) strlen((const char *)(s))
61
+ #define strnlen_P (str , len ) strnlen((str), (len))
62
+ #define strncmp_P (a , b , n ) strncmp((a), (b), (n))
63
+ #define strncasecmp_P (a , b , n ) strncasecmp((a), (b), (n))
64
+ #define strncat_P (a , b , n ) strncat((a), (b), (n))
65
+ #define strncpy_P (a , b , n ) strncpy((a), (b), (n))
66
+ #define strpbrk_P (str , chrs ) strpbrk((str), (chrs))
67
+ #define strrchr_P (str , c ) strrchr((str), (c))
68
+ #define strsep_P (strp , delim ) strsep((strp), (delim))
69
+ #define strspn_P (str , chrs ) strspn((str), (chrs))
52
70
#define strstr_P (a , b ) strstr((a), (b))
53
- #define strlen_P (a ) strlen((a))
54
- #define sprintf_P (s , f , ...) sprintf((s), (f), __VA_ARGS__)
71
+ #define sprintf_P (s , ...) sprintf((s), __VA_ARGS__)
72
+ #define vfprintf_P (fp , s , ...) vfprintf((fp), (s), __VA_ARGS__)
73
+ #define printf_P (...) printf(__VA_ARGS__)
74
+ #define snprintf_P (s , n , ...) snprintf((s), (n), __VA_ARGS__)
75
+ #define vsprintf_P (s , ...) vsprintf((s), __VA_ARGS__)
76
+ #define vsnprintf_P (s , n , ...) vsnprintf((s), (n), __VA_ARGS__)
77
+ #define fprintf_P (fp , ...) fprintf((fp), __VA_ARGS__)
78
+ #define strlen_PF (a ) strlen((a))
79
+ #define strnlen_PF (src , len ) strnlen((src), (len))
80
+ #define memcpy_PF (dest , src , len ) memcpy((dest), (src), (len))
81
+ #define strcpy_PF (dest , src ) strcpy((dest), (src))
82
+ #define strncpy_PF (dest , src , len ) strncpy((dest), (src), (len))
83
+ #define strcat_PF (dest , src ) strcat((dest), (src))
84
+ #define strlcat_PF (dest , src , len ) strlcat((dest), (src), (len))
85
+ #define strncat_PF (dest , src , len ) strncat((dest), (src), (len))
86
+ #define strcmp_PF (s1 , s2 ) strcmp((s1), (s2))
87
+ #define strncmp_PF (s1 , s2 , n ) strncmp((s1), (s2), (n))
88
+ #define strcasecmp_PF (s1 , s2 ) strcasecmp((s1), (s2))
89
+ #define strncasecmp_PF (s1 , s2 , n ) strncasecmp((s1), (s2), (n))
90
+ #define strstr_PF (s1 , s2 ) strstr((s1), (s2))
91
+ #define strlcpy_PF (dest , src , n ) strlcpy((dest), (src), (n))
92
+ #define memcmp_PF (s1 , s2 , n ) memcmp((s1), (s2), (n))
93
+
55
94
56
95
#define pgm_read_byte (addr ) (*(const unsigned char *)(addr))
96
+ #if 0
57
97
#define pgm_read_word (addr ) (*(const unsigned short *)(addr))
58
98
#define pgm_read_dword (addr ) (*(const unsigned long *)(addr))
59
99
#define pgm_read_float (addr ) (*(const float *)(addr))
100
+ #else
101
+ #define pgm_read_word (addr ) ({ \
102
+ typeof(addr) _addr = (addr); \
103
+ *(const unsigned short *)(_addr); \
104
+ })
105
+ #define pgm_read_dword (addr ) ({ \
106
+ typeof(addr) _addr = (addr); \
107
+ *(const unsigned long *)(_addr); \
108
+ })
109
+ #define pgm_read_float (addr ) ({ \
110
+ typeof(addr) _addr = (addr); \
111
+ *(const float *)(_addr); \
112
+ })
113
+ #define pgm_read_ptr (addr ) ({ \
114
+ typeof(addr) _addr = (addr); \
115
+ *(void * const *)(_addr); \
116
+ })
117
+ #endif
60
118
61
119
#define pgm_read_byte_near (addr ) pgm_read_byte(addr)
62
120
#define pgm_read_word_near (addr ) pgm_read_word(addr)
63
121
#define pgm_read_dword_near (addr ) pgm_read_dword(addr)
64
122
#define pgm_read_float_near (addr ) pgm_read_float(addr)
123
+ #define pgm_read_ptr_near (addr ) pgm_read_ptr(addr)
65
124
#define pgm_read_byte_far (addr ) pgm_read_byte(addr)
66
125
#define pgm_read_word_far (addr ) pgm_read_word(addr)
67
126
#define pgm_read_dword_far (addr ) pgm_read_dword(addr)
68
127
#define pgm_read_float_far (addr ) pgm_read_float(addr)
128
+ #define pgm_read_ptr_far (addr ) pgm_read_ptr(addr)
69
129
70
130
#endif
0 commit comments