AVR-LibC  2.2.0
Standard C library for AVR-GCC
 

AVR-LibC Documentation

Logo

AVR-LibC Development Pages

Main Page

User Manual

Library Reference

FAQ

Example Projects

File List

Loading...
Searching...
No Matches
pgmspace.h
Go to the documentation of this file.
1/* Copyright (c) 2002-2007 Marek Michalkiewicz
2 Copyright (c) 2006, Carlos Lamas
3 Copyright (c) 2009-2010, Jan Waclawek
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the
14 distribution.
15 * Neither the name of the copyright holders nor the names of
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE. */
30
31/* $Id$ */
32
33/*
34 pgmspace.h
35
36 Contributors:
37 Created by Marek Michalkiewicz <marekm@linux.org.pl>
38 Eric B. Weddington <eric@ecentral.com>
39 Wolfgang Haidinger <wh@vmars.tuwien.ac.at> (pgm_read_dword())
40 Ivanov Anton <anton@arc.com.ru> (pgm_read_float())
41 */
42
43/** \file */
44/** \defgroup avr_pgmspace <avr/pgmspace.h>: Program Space Utilities
45 \code
46 #include <avr/io.h>
47 #include <avr/pgmspace.h>
48 \endcode
49
50 The functions in this module provide interfaces for a program to access
51 data stored in program space (flash memory) of the device.
52
53 \note These functions are an attempt to provide some compatibility with
54 header files that come with IAR C, to make porting applications between
55 different compilers easier. This is not 100% compatibility though (GCC
56 does not have full support for multiple address spaces yet).
57
58 \note If you are working with strings which are completely based in RAM,
59 use the standard string functions described in \ref avr_string.
60
61 \note If possible, put your constant tables in the lower 64 KB and use
62 pgm_read_byte_near() or pgm_read_word_near() instead of
63 pgm_read_byte_far() or pgm_read_word_far() since it is more efficient that
64 way, and you can still use the upper 64K for executable code.
65 All functions that are suffixed with a \c _P \e require their
66 arguments to be in the lower 64 KB of the flash ROM, as they do
67 not use ELPM instructions. This is normally not a big concern as
68 the linker setup arranges any program space constants declared
69 using the macros from this header file so they are placed right after
70 the interrupt vectors, and in front of any executable code. However,
71 it can become a problem if there are too many of these constants, or
72 for bootloaders on devices with more than 64 KB of ROM.
73 <em>All these functions will not work in that situation.</em>
74
75 \note For <b>Xmega</b> devices, make sure the NVM controller
76 command register (\c NVM.CMD or \c NVM_CMD) is set to 0x00 (NOP)
77 before using any of these functions.
78*/
79
80#ifndef __PGMSPACE_H_
81#define __PGMSPACE_H_ 1
82
83#ifndef __DOXYGEN__
84#define __need_size_t
85#endif
86#include <inttypes.h>
87#include <stddef.h>
88#include <avr/io.h>
89
90#ifndef __DOXYGEN__
91#ifndef __ATTR_CONST__
92#define __ATTR_CONST__ __attribute__((__const__))
93#endif
94
95#ifndef __ATTR_PROGMEM__
96#define __ATTR_PROGMEM__ __attribute__((__progmem__))
97#endif
98
99#ifndef __ATTR_PURE__
100#define __ATTR_PURE__ __attribute__((__pure__))
101#endif
102
103#ifndef __ATTR_ALWAYS_INLINE__
104#define __ATTR_ALWAYS_INLINE__ __inline__ __attribute__((__always_inline__))
105#endif
106
107#define PROGMEM __ATTR_PROGMEM__
108
109#endif /* !__DOXYGEN__ */
110
111/**
112 \ingroup avr_pgmspace
113 \def PROGMEM_FAR
114
115 Attribute to use in order to declare an object being located in
116 far flash ROM. This is similar to #PROGMEM, except that it puts
117 the static storage object in section
118 <tt>\ref sec_dot_progmemx ".progmemx.data"</tt>.
119 In order to access the object,
120 the <tt>pgm_read_*_far</tt> and \c _PF functions declare in this header
121 can be used. In order to get its address, see pgm_get_far_address().
122
123 It only makes sense to put read-only objects in this section,
124 though the compiler does not diagnose when this is not the case. */
125#define PROGMEM_FAR __attribute__((__section__(".progmemx.data")))
126
127#ifdef __DOXYGEN__
128
129/**
130 \ingroup avr_pgmspace
131 \def PROGMEM
132
133 Attribute to use in order to declare an object being located in
134 flash ROM. */
135#define PROGMEM __attribute__((__progmem__))
136
137/** \ingroup avr_pgmspace
138 \fn char pgm_read_char (const char *__addr)
139 Read a <tt>char</tt> from 16-bit (near) byte-address \p __addr.
140 The address is in the lower 64 KiB of program memory. */
141static inline char pgm_read_char (const char *__addr);
142
143/** \ingroup avr_pgmspace
144 \fn unsigned char pgm_read_unsigned_char (const unsigned char *__addr)
145 Read an <tt>unsigned char</tt> from 16-bit (near) byte-address \p __addr.
146 The address is in the lower 64 KiB of program memory. */
147static inline unsigned char pgm_read_unsigned_char (const unsigned char *__addr);
148
149/** \ingroup avr_pgmspace
150 \fn signed char pgm_read_signed_char (const signed char *__addr)
151 Read a <tt>signed char</tt> from 16-bit (near) byte-address \p __addr.
152 The address is in the lower 64 KiB of program memory. */
153static inline signed char pgm_read_signed_char (const signed char *__addr);
154
155/** \ingroup avr_pgmspace
156 \fn uint8_t pgm_read_u8 (const uint8_t *__addr)
157 Read an <tt>uint8_t</tt> from 16-bit (near) byte-address \p __addr.
158 The address is in the lower 64 KiB of program memory. */
159static inline uint8_t pgm_read_u8 (const uint8_t *__addr);
160
161/** \ingroup avr_pgmspace
162 \fn int8_t pgm_read_i8 (const int8_t *__addr)
163 Read an <tt>int8_t</tt> from 16-bit (near) byte-address \p __addr.
164 The address is in the lower 64 KiB of program memory. */
165static inline int8_t pgm_read_i8 (const int8_t *__addr);
166
167/** \ingroup avr_pgmspace
168 \fn short pgm_read_short (const short *__addr)
169 Read a <tt>short</tt> from 16-bit (near) byte-address \p __addr.
170 The address is in the lower 64 KiB of program memory. */
171static inline short pgm_read_short (const short *__addr);
172
173/** \ingroup avr_pgmspace
174 \fn unsigned short pgm_read_unsigned_short (const unsigned short *__addr)
175 Read an <tt>unsigned short</tt> from 16-bit (near) byte-address \p __addr.
176 The address is in the lower 64 KiB of program memory. */
177static inline unsigned short pgm_read_unsigned_short (const unsigned short *__addr);
178
179/** \ingroup avr_pgmspace
180 \fn uint16_t pgm_read_u16 (const uint16_t *__addr)
181 Read an <tt>uint16_t</tt> from 16-bit (near) byte-address \p __addr.
182 The address is in the lower 64 KiB of program memory. */
183static inline uint16_t pgm_read_u16 (const uint16_t *__addr);
184
185/** \ingroup avr_pgmspace
186 \fn int16_t pgm_read_i16 (const int16_t *__addr)
187 Read an <tt>int16_t</tt> from 16-bit (near) byte-address \p __addr.
188 The address is in the lower 64 KiB of program memory. */
189static inline int16_t pgm_read_i16 (const int16_t *__addr);
190
191/** \ingroup avr_pgmspace
192 \fn int pgm_read_int (const int *__addr)
193 Read an <tt>int</tt> from 16-bit (near) byte-address \p __addr.
194 The address is in the lower 64 KiB of program memory. */
195static inline int pgm_read_int (const int *__addr);
196
197/** \ingroup avr_pgmspace
198 \fn signed pgm_read_signed (const signed *__addr)
199 Read a <tt>signed</tt> from 16-bit (near) byte-address \p __addr.
200 The address is in the lower 64 KiB of program memory. */
201static inline signed pgm_read_signed (const signed *__addr);
202
203/** \ingroup avr_pgmspace
204 \fn unsigned pgm_read_unsigned (const unsigned *__addr)
205 Read an <tt>unsigned</tt> from 16-bit (near) byte-address \p __addr.
206 The address is in the lower 64 KiB of program memory. */
207static inline unsigned pgm_read_unsigned (const unsigned *__addr);
208
209/** \ingroup avr_pgmspace
210 \fn signed int pgm_read_signed_int (const signed int *__addr)
211 Read a <tt>signed int</tt> from 16-bit (near) byte-address \p __addr.
212 The address is in the lower 64 KiB of program memory. */
213static inline signed int pgm_read_signed_int (const signed int *__addr);
214
215/** \ingroup avr_pgmspace
216 \fn unsigned int pgm_read_unsigned_int (const unsigned int *__addr)
217 Read an <tt>unsigned int</tt> from 16-bit (near) byte-address \p __addr.
218 The address is in the lower 64 KiB of program memory. */
219static inline unsigned int pgm_read_unsigned_int (const unsigned int *__addr);
220
221/** \ingroup avr_pgmspace
222 \fn __int24 pgm_read_i24 (const __int24 *__addr)
223 Read an <tt>__int24</tt> from 16-bit (near) byte-address \p __addr.
224 The address is in the lower 64 KiB of program memory. */
225static inline __int24 pgm_read_i24 (const __int24 *__addr);
226
227/** \ingroup avr_pgmspace
228 \fn __uint24 pgm_read_u24 (const __uint24 *__addr)
229 Read an <tt>__uint24</tt> from 16-bit (near) byte-address \p __addr.
230 The address is in the lower 64 KiB of program memory. */
231static inline __uint24 pgm_read_u24 (const __uint24 *__addr);
232
233/** \ingroup avr_pgmspace
234 \fn uint32_t pgm_read_u32 (const uint32_t *__addr)
235 Read an <tt>uint32_t</tt> from 16-bit (near) byte-address \p __addr.
236 The address is in the lower 64 KiB of program memory. */
237static inline uint32_t pgm_read_u32 (const uint32_t *__addr);
238
239/** \ingroup avr_pgmspace
240 \fn int32_t pgm_read_i32 (const int32_t *__addr)
241 Read an <tt>int32_t</tt> from 16-bit (near) byte-address \p __addr.
242 The address is in the lower 64 KiB of program memory. */
243static inline int32_t pgm_read_i32 (const int32_t *__addr);
244
245/** \ingroup avr_pgmspace
246 \fn long pgm_read_long (const long *__addr)
247 Read a <tt>long</tt> from 16-bit (near) byte-address \p __addr.
248 The address is in the lower 64 KiB of program memory. */
249static inline long pgm_read_long (const long *__addr);
250
251/** \ingroup avr_pgmspace
252 \fn unsigned long pgm_read_unsigned_long (const unsigned long *__addr)
253 Read an <tt>unsigned long</tt> from 16-bit (near) byte-address \p __addr.
254 The address is in the lower 64 KiB of program memory. */
255static inline unsigned long pgm_read_unsigned_long (const unsigned long *__addr);
256
257/** \ingroup avr_pgmspace
258 \fn long long pgm_read_long_long (const long long *__addr)
259 Read a <tt>long long</tt> from 16-bit (near) byte-address \p __addr.
260 The address is in the lower 64 KiB of program memory. */
261static inline long long pgm_read_long_long (const long long *__addr);
262
263/** \ingroup avr_pgmspace
264 \fn unsigned long long pgm_read_unsigned_long_long (const unsigned long long *__addr)
265 Read an <tt>unsigned long long</tt> from 16-bit (near) byte-address
266 \p __addr.
267 The address is in the lower 64 KiB of program memory. */
268static inline unsigned long long pgm_read_unsigned_long_long (const unsigned long long *__addr);
269
270/** \ingroup avr_pgmspace
271 \fn uint64_t pgm_read_u64 (const uint64_t *__addr)
272 Read an <tt>uint64_t</tt> from 16-bit (near) byte-address \p __addr.
273 The address is in the lower 64 KiB of program memory. */
274static inline uint64_t pgm_read_u64 (const uint64_t *__addr);
275
276/** \ingroup avr_pgmspace
277 \fn int64_t pgm_read_i64 (const int64_t *__addr)
278 Read an <tt>int64_t</tt> from 16-bit (near) byte-address \p __addr.
279 The address is in the lower 64 KiB of program memory. */
280static inline int64_t pgm_read_i64 (const int64_t *__addr);
281
282/** \ingroup avr_pgmspace
283 \fn float pgm_read_float (const float *__addr)
284 Read a <tt>float</tt> from 16-bit (near) byte-address \p __addr.
285 The address is in the lower 64 KiB of program memory. */
286static inline float pgm_read_float (const float *__addr);
287
288/** \ingroup avr_pgmspace
289 \fn double pgm_read_double (const double *__addr)
290 Read a <tt>double</tt> from 16-bit (near) byte-address \p __addr.
291 The address is in the lower 64 KiB of program memory. */
292static inline double pgm_read_double (const double *__addr);
293
294/** \ingroup avr_pgmspace
295 \fn long double pgm_read_long_double (const long double *__addr)
296 Read a <tt>long double</tt> from 16-bit (near) byte-address \p __addr.
297 The address is in the lower 64 KiB of program memory. */
298static inline long double pgm_read_long_double (const long double *__addr);
299
300#else /* !DOXYGEN */
301#if defined(__AVR_TINY__)
302/* For Reduced Tiny devices, avr-gcc adds 0x4000 when it takes the address
303 of a PROGMEM object. This means we can use open coded C/C++ to read
304 from progmem. This assumes we have
305 - GCC PR71948 - Make progmem work on Reduced Tiny (GCC v7 / 2016-08) */
306#define __LPM__1(res, addr) res = *addr
307#define __LPM__2(res, addr) res = *addr
308#define __LPM__3(res, addr) res = *addr
309#define __LPM__4(res, addr) res = *addr
310#define __LPM__8(res, addr) res = *addr
311
312#elif defined(__AVR_HAVE_LPMX__)
313#define __LPM__1(res, addr) \
314 __asm __volatile__ ("lpm %0,%a1" \
315 : "=r" (res) : "z" (addr))
316
317#define __LPM__2(res, addr) \
318 __asm __volatile__ ("lpm %A0,%a1+" "\n\t" \
319 "lpm %B0,%a1+" \
320 : "=r" (res), "+z" (addr))
321
322#define __LPM__3(res, addr) \
323 __asm __volatile__ ("lpm %A0,%a1+" "\n\t" \
324 "lpm %B0,%a1+" "\n\t" \
325 "lpm %C0,%a1+" \
326 : "=r" (res), "+z" (addr))
327
328#define __LPM__4(res, addr) \
329 __asm __volatile__ ("lpm %A0,%a1+" "\n\t" \
330 "lpm %B0,%a1+" "\n\t" \
331 "lpm %C0,%a1+" "\n\t" \
332 "lpm %D0,%a1+" \
333 : "=r" (res), "+z" (addr))
334
335#define __LPM__8(res, addr) \
336 __asm __volatile__ ("lpm %r0+0,%a1+" "\n\t" \
337 "lpm %r0+1,%a1+" "\n\t" \
338 "lpm %r0+2,%a1+" "\n\t" \
339 "lpm %r0+3,%a1+" "\n\t" \
340 "lpm %r0+4,%a1+" "\n\t" \
341 "lpm %r0+5,%a1+" "\n\t" \
342 "lpm %r0+6,%a1+" "\n\t" \
343 "lpm %r0+7,%a1+" \
344 : "=r" (res), "+z" (addr))
345#else /* Has no LPMx and no Reduced Tiny => Has LPM. */
346#define __LPM__1(res, addr) \
347 __asm __volatile__ ("lpm $ mov %A0,r0" \
348 : "=r" (res) : "z" (addr) : "r0")
349
350#define __LPM__2(res, addr) \
351 __asm __volatile__ ("lpm $ mov %A0,r0 $ adiw %1,1" "\n\t" \
352 "lpm $ mov %B0,r0" \
353 : "=r" (res), "+z" (addr) :: "r0")
354
355#define __LPM__3(res, addr) \
356 __asm __volatile__ ("lpm $ mov %A0,r0 $ adiw %1,1" "\n\t" \
357 "lpm $ mov %B0,r0 $ adiw %1,1" "\n\t" \
358 "lpm $ mov %C0,r0" \
359 : "=r" (res), "+z" (addr) :: "r0")
360
361#define __LPM__4(res, addr) \
362 __asm __volatile__ ("lpm $ mov %A0,r0 $ adiw %1,1" "\n\t" \
363 "lpm $ mov %B0,r0 $ adiw %1,1" "\n\t" \
364 "lpm $ mov %C0,r0 $ adiw %1,1" "\n\t" \
365 "lpm $ mov %D0,r0" \
366 : "=r" (res), "+z" (addr) :: "r0")
367
368#define __LPM__8(res, addr) \
369 __asm __volatile__ ("lpm $ mov %r0+0,r0 $ adiw %1,1" "\n\t" \
370 "lpm $ mov %r0+1,r0 $ adiw %1,1" "\n\t" \
371 "lpm $ mov %r0+2,r0 $ adiw %1,1" "\n\t" \
372 "lpm $ mov %r0+3,r0 $ adiw %1,1" "\n\t" \
373 "lpm $ mov %r0+4,r0 $ adiw %1,1" "\n\t" \
374 "lpm $ mov %r0+5,r0 $ adiw %1,1" "\n\t" \
375 "lpm $ mov %r0+6,r0 $ adiw %1,1" "\n\t" \
376 "lpm $ mov %r0+7,r0" \
377 : "=r" (res), "+z" (addr) :: "r0")
378#endif /* LPM cases */
379
380#define _Avrlibc_Def_Pgm_1(Name, Typ) \
381 static __ATTR_ALWAYS_INLINE__ \
382 Typ pgm_read_##Name (const Typ *__addr) \
383 { \
384 Typ __res; \
385 __LPM__1 (__res, __addr); \
386 return __res; \
387 }
388
389#define _Avrlibc_Def_Pgm_2(Name, Typ) \
390 static __ATTR_ALWAYS_INLINE__ \
391 Typ pgm_read_##Name (const Typ *__addr) \
392 { \
393 Typ __res; \
394 __LPM__2 (__res, __addr); \
395 return __res; \
396 }
397
398#define _Avrlibc_Def_Pgm_3(Name, Typ) \
399 static __ATTR_ALWAYS_INLINE__ \
400 Typ pgm_read_##Name (const Typ *__addr) \
401 { \
402 Typ __res; \
403 __LPM__3 (__res, __addr); \
404 return __res; \
405 }
406
407#define _Avrlibc_Def_Pgm_4(Name, Typ) \
408 static __ATTR_ALWAYS_INLINE__ \
409 Typ pgm_read_##Name (const Typ *__addr) \
410 { \
411 Typ __res; \
412 __LPM__4 (__res, __addr); \
413 return __res; \
414 }
415
416#define _Avrlibc_Def_Pgm_8(Name, Typ) \
417 static __ATTR_ALWAYS_INLINE__ \
418 Typ pgm_read_##Name (const Typ *__addr) \
419 { \
420 Typ __res; \
421 __LPM__8 (__res, __addr); \
422 return __res; \
423 }
424
425_Avrlibc_Def_Pgm_1 (char, char)
426_Avrlibc_Def_Pgm_1 (unsigned_char, unsigned char)
427_Avrlibc_Def_Pgm_1 (signed_char, signed char)
428_Avrlibc_Def_Pgm_1 (u8, uint8_t)
429_Avrlibc_Def_Pgm_1 (i8, int8_t)
430#if __SIZEOF_INT__ == 1
431_Avrlibc_Def_Pgm_1 (int, int)
432_Avrlibc_Def_Pgm_1 (signed, signed)
433_Avrlibc_Def_Pgm_1 (unsigned, unsigned)
434_Avrlibc_Def_Pgm_1 (signed_int, signed int)
435_Avrlibc_Def_Pgm_1 (unsigned_int, unsigned int)
436#endif
437#if __SIZEOF_SHORT__ == 1
438_Avrlibc_Def_Pgm_1 (short, short)
439_Avrlibc_Def_Pgm_1 (unsigned_short, unsigned short)
440#endif
441
442_Avrlibc_Def_Pgm_2 (u16, uint16_t)
443_Avrlibc_Def_Pgm_2 (i16, int16_t)
444#if __SIZEOF_INT__ == 2
445_Avrlibc_Def_Pgm_2 (int, int)
446_Avrlibc_Def_Pgm_2 (signed, signed)
447_Avrlibc_Def_Pgm_2 (unsigned, unsigned)
448_Avrlibc_Def_Pgm_2 (signed_int, signed int)
449_Avrlibc_Def_Pgm_2 (unsigned_int, unsigned int)
450#endif
451#if __SIZEOF_SHORT__ == 2
452_Avrlibc_Def_Pgm_2 (short, short)
453_Avrlibc_Def_Pgm_2 (unsigned_short, unsigned short)
454#endif
455#if __SIZEOF_LONG__ == 2
456_Avrlibc_Def_Pgm_2 (long, long)
457_Avrlibc_Def_Pgm_2 (unsigned_long, unsigned long)
458#endif
459
460#if defined(__INT24_MAX__)
461_Avrlibc_Def_Pgm_3 (i24, __int24)
462_Avrlibc_Def_Pgm_3 (u24, __uint24)
463#endif /* Have __int24 */
464
465_Avrlibc_Def_Pgm_4 (u32, uint32_t)
466_Avrlibc_Def_Pgm_4 (i32, int32_t)
467_Avrlibc_Def_Pgm_4 (float, float)
468#if __SIZEOF_LONG__ == 4
469_Avrlibc_Def_Pgm_4 (long, long)
470_Avrlibc_Def_Pgm_4 (unsigned_long, unsigned long)
471#endif
472#if __SIZEOF_LONG_LONG__ == 4
473_Avrlibc_Def_Pgm_4 (long_long, long long)
474_Avrlibc_Def_Pgm_4 (unsigned_long_long, unsigned long long)
475#endif
476#if __SIZEOF_DOUBLE__ == 4
477_Avrlibc_Def_Pgm_4 (double, double)
478#endif
479#if __SIZEOF_LONG_DOUBLE__ == 4
480_Avrlibc_Def_Pgm_4 (long_double, long double)
481#endif
482
483#if __SIZEOF_LONG_LONG__ == 8
484_Avrlibc_Def_Pgm_8 (u64, uint64_t)
485_Avrlibc_Def_Pgm_8 (i64, int64_t)
486_Avrlibc_Def_Pgm_8 (long_long, long long)
487_Avrlibc_Def_Pgm_8 (unsigned_long_long, unsigned long long)
488#endif
489#if __SIZEOF_DOUBLE__ == 8
490_Avrlibc_Def_Pgm_8 (double, double)
491#endif
492#if __SIZEOF_LONG_DOUBLE__ == 8
493_Avrlibc_Def_Pgm_8 (long_double, long double)
494#endif
495
496#endif /* DOXYGEN */
497
498#ifdef __DOXYGEN__
499
500/** \ingroup avr_pgmspace
501 \fn char pgm_read_char_far (uint_farptr_t __addr)
502 Read a <tt>char</tt> from far byte-address \p __addr.
503 The address is in the program memory. */
504static inline char pgm_read_char_far (uint_farptr_t __addr);
505
506/** \ingroup avr_pgmspace
507 \fn unsigned char pgm_read_unsigned_char_far (uint_farptr_t __addr)
508 Read an <tt>unsigned char</tt> from far byte-address \p __addr.
509 The address is in the program memory. */
510static inline unsigned char pgm_read_unsigned_char_far (uint_farptr_t __addr);
511
512/** \ingroup avr_pgmspace
513 \fn signed char pgm_read_signed_char_far (uint_farptr_t __addr)
514 Read a <tt>signed char</tt> from far byte-address \p __addr.
515 The address is in the program memory. */
516static inline signed char pgm_read_signed_char_far (uint_farptr_t __addr);
517
518/** \ingroup avr_pgmspace
519 \fn uint8_t pgm_read_u8_far (uint_farptr_t __addr)
520 Read an <tt>uint8_t</tt> from far byte-address \p __addr.
521 The address is in the program memory. */
522static inline uint8_t pgm_read_u8_far (uint_farptr_t __addr);
523
524/** \ingroup avr_pgmspace
525 \fn int8_t pgm_read_i8_far (uint_farptr_t __addr)
526 Read an <tt>int8_t</tt> from far byte-address \p __addr.
527 The address is in the program memory. */
528static inline int8_t pgm_read_i8_far (uint_farptr_t __addr);
529
530/** \ingroup avr_pgmspace
531 \fn short pgm_read_short_far (uint_farptr_t __addr)
532 Read a <tt>short</tt> from far byte-address \p __addr.
533 The address is in the program memory. */
534static inline short pgm_read_short_far (uint_farptr_t __addr);
535
536/** \ingroup avr_pgmspace
537 \fn unsigned short pgm_read_unsigned_short_far (uint_farptr_t __addr)
538 Read an <tt>unsigned short</tt> from far byte-address \p __addr.
539 The address is in the program memory. */
540static inline unsigned short pgm_read_unsigned_short_far (uint_farptr_t __addr);
541
542/** \ingroup avr_pgmspace
543 \fn uint16_t pgm_read_u16_far (uint_farptr_t __addr)
544 Read an <tt>uint16_t</tt> from far byte-address \p __addr.
545 The address is in the program memory. */
547
548/** \ingroup avr_pgmspace
549 \fn int16_t pgm_read_i16_far (uint_farptr_t __addr)
550 Read an <tt>int16_t</tt> from far byte-address \p __addr.
551 The address is in the program memory. */
553
554/** \ingroup avr_pgmspace
555 \fn int pgm_read_int_far (uint_farptr_t __addr)
556 Read an <tt>int</tt> from far byte-address \p __addr.
557 The address is in the program memory. */
558static inline int pgm_read_int_far (uint_farptr_t __addr);
559
560/** \ingroup avr_pgmspace
561 \fn unsigned pgm_read_unsigned_far (uint_farptr_t __addr)
562 Read an <tt>unsigned</tt> from far byte-address \p __addr.
563 The address is in the program memory. */
564static inline unsigned pgm_read_unsigned_far (uint_farptr_t __addr);
565
566/** \ingroup avr_pgmspace
567 \fn unsigned int pgm_read_unsigned_int_far (uint_farptr_t __addr)
568 Read an <tt>unsigned int</tt> from far byte-address \p __addr.
569 The address is in the program memory. */
570static inline unsigned int pgm_read_unsigned_int_far (uint_farptr_t __addr);
571
572/** \ingroup avr_pgmspace
573 \fn signed pgm_read_signed_far (uint_farptr_t __addr)
574 Read a <tt>signed</tt> from far byte-address \p __addr.
575 The address is in the program memory. */
576static inline signed pgm_read_signed_far (uint_farptr_t __addr);
577
578/** \ingroup avr_pgmspace
579 \fn signed int pgm_read_signed_int_far (uint_farptr_t __addr)
580 Read a <tt>signed int</tt> from far byte-address \p __addr.
581 The address is in the program memory. */
582static inline signed int pgm_read_signed_int_far (uint_farptr_t __addr);
583
584/** \ingroup avr_pgmspace
585 \fn long pgm_read_long_far (uint_farptr_t __addr)
586 Read a <tt>long</tt> from far byte-address \p __addr.
587 The address is in the program memory. */
588static inline long pgm_read_long_far (uint_farptr_t __addr);
589
590/** \ingroup avr_pgmspace
591 \fn unsigned long pgm_read_unsigned_long_far (uint_farptr_t __addr)
592 Read an <tt>unsigned long</tt> from far byte-address \p __addr.
593 The address is in the program memory. */
594static inline unsigned long pgm_read_unsigned_long_far (uint_farptr_t __addr);
595
596/** \ingroup avr_pgmspace
597 \fn __int24 pgm_read_i24_far (uint_farptr_t __addr)
598 Read an <tt>__int24</tt> from far byte-address \p __addr.
599 The address is in the program memory. */
600static inline __int24 pgm_read_i24_far (uint_farptr_t __addr);
601
602/** \ingroup avr_pgmspace
603 \fn __uint24 pgm_read_u24_far (uint_farptr_t __addr)
604 Read an <tt>__uint24</tt> from far byte-address \p __addr.
605 The address is in the program memory. */
606static inline __uint24 pgm_read_u24_far (uint_farptr_t __addr);
607
608/** \ingroup avr_pgmspace
609 \fn uint32_t pgm_read_u32_far (uint_farptr_t __addr)
610 Read an <tt>uint32_t</tt> from far byte-address \p __addr.
611 The address is in the program memory. */
613
614/** \ingroup avr_pgmspace
615 \fn int32_t pgm_read_i32_far (uint_farptr_t __addr)
616 Read an <tt>int32_t</tt> from far byte-address \p __addr.
617 The address is in the program memory. */
619
620/** \ingroup avr_pgmspace
621 \fn long long pgm_read_long_long_far (uint_farptr_t __addr)
622 Read a <tt>long long</tt> from far byte-address \p __addr.
623 The address is in the program memory. */
624static inline long long pgm_read_long_long_far (uint_farptr_t __addr);
625
626/** \ingroup avr_pgmspace
627 \fn unsigned long long pgm_read_unsigned_long_long_far (uint_farptr_t __addr)
628 Read an <tt>unsigned long long</tt> from far byte-address \p __addr.
629 The address is in the program memory. */
630static inline unsigned long long pgm_read_unsigned_long_long_far (uint_farptr_t __addr);
631
632/** \ingroup avr_pgmspace
633 \fn uint64_t pgm_read_u64_far (uint_farptr_t __addr)
634 Read an <tt>uint64_t</tt> from far byte-address \p __addr.
635 The address is in the program memory. */
637
638/** \ingroup avr_pgmspace
639 \fn int64_t pgm_read_i64_far (uint_farptr_t __addr)
640 Read an <tt>int64_t</tt> from far byte-address \p __addr.
641 The address is in the program memory. */
643
644/** \ingroup avr_pgmspace
645 \fn float pgm_read_float_far (uint_farptr_t __addr)
646 Read a <tt>float</tt> from far byte-address \p __addr.
647 The address is in the program memory. */
648static inline float pgm_read_float_far (uint_farptr_t __addr);
649
650/** \ingroup avr_pgmspace
651 \fn double pgm_read_double_far (uint_farptr_t __addr)
652 Read a <tt>double</tt> from far byte-address \p __addr.
653 The address is in the program memory. */
654static inline double pgm_read_double_far (uint_farptr_t __addr);
655
656/** \ingroup avr_pgmspace
657 \fn long double pgm_read_long_double_far (uint_farptr_t __addr)
658 Read a <tt>long double</tt> from far byte-address \p __addr.
659 The address is in the program memory. */
660static inline long double pgm_read_long_double_far (uint_farptr_t __addr);
661
662#else /* !DOXYGEN */
663
664#if defined(__AVR_HAVE_ELPMX__)
665
666#ifdef __AVR_HAVE_RAMPD__
667/* For devices with EBI, reset RAMPZ to zero after. */
668#define __pgm_clr_RAMPZ_ "\n\t" "out %i2,__zero_reg__"
669#else
670/* Devices without EBI: no need to reset RAMPZ. */
671#define __pgm_clr_RAMPZ_ /* empty */
672#endif
673
674#define __ELPM__1(res, addr, T) \
675 __asm __volatile__ ("movw r30,%1" "\n\t" \
676 "out %i2,%C1" "\n\t" \
677 "elpm %A0,Z" \
678 __pgm_clr_RAMPZ_ \
679 : "=r" (res) \
680 : "r" (addr), "n" (& RAMPZ) \
681 : "r30", "r31")
682
683#define __ELPM__2(res, addr, T) \
684 __asm __volatile__ ("movw r30,%1" "\n\t" \
685 "out %i2,%C1" "\n\t" \
686 "elpm %A0,Z+" "\n\t" \
687 "elpm %B0,Z+" \
688 __pgm_clr_RAMPZ_ \
689 : "=r" (res) \
690 : "r" (addr), "n" (& RAMPZ) \
691 : "r30", "r31")
692
693#define __ELPM__3(res, addr, T) \
694 __asm __volatile__ ("movw r30,%1" "\n\t" \
695 "out %i2,%C1" "\n\t" \
696 "elpm %A0,Z+" "\n\t" \
697 "elpm %B0,Z+" "\n\t" \
698 "elpm %C0,Z+" \
699 __pgm_clr_RAMPZ_ \
700 : "=r" (res) \
701 : "r" (addr), "n" (& RAMPZ) \
702 : "r30", "r31")
703
704#define __ELPM__4(res, addr, T) \
705 __asm __volatile__ ("movw r30,%1" "\n\t" \
706 "out %i2,%C1" "\n\t" \
707 "elpm %A0,Z+" "\n\t" \
708 "elpm %B0,Z+" "\n\t" \
709 "elpm %C0,Z+" "\n\t" \
710 "elpm %D0,Z+" \
711 __pgm_clr_RAMPZ_ \
712 : "=r" (res) \
713 : "r" (addr), "n" (& RAMPZ) \
714 : "r30", "r31")
715
716#define __ELPM__8(res, addr, T) \
717 __asm __volatile__ ("movw r30,%1" "\n\t" \
718 "out %i2,%C1" "\n\t" \
719 "elpm %r0+0,Z+" "\n\t" \
720 "elpm %r0+1,Z+" "\n\t" \
721 "elpm %r0+2,Z+" "\n\t" \
722 "elpm %r0+3,Z+" "\n\t" \
723 "elpm %r0+4,Z+" "\n\t" \
724 "elpm %r0+5,Z+" "\n\t" \
725 "elpm %r0+6,Z+" "\n\t" \
726 "elpm %r0+7,Z+" \
727 __pgm_clr_RAMPZ_ \
728 : "=r" (res) \
729 : "r" (addr), "n" (& RAMPZ) \
730 : "r30", "r31")
731
732/* FIXME: AT43USB320 does not have RAMPZ but supports (external) program
733 memory of 64 KiW, at least that's what the comments in io43usb32x.h are
734 indicating. A solution would be to put the device in a different
735 multilib-set (see GCC PR78275), as io.h has "#define FLASHEND 0x0FFFF".
736 For now, just exclude AT43USB320 from code that uses RAMPZ. Also note
737 that the manual asserts that the entire program memory can be accessed
738 by LPM, implying only 64 KiB of program memory. */
739#elif defined(__AVR_HAVE_ELPM__) \
740 && !defined(__AVR_AT43USB320__)
741/* The poor devices without ELPMx: Do 24-bit addresses by hand... */
742#define __ELPM__1(res, addr, T) \
743 __asm __volatile__ ("mov r30,%A1" "\n\t" \
744 "mov r31,%B1" "\n\t" \
745 "out %i2,%C1 $ elpm $ mov %A0,r0" \
746 : "=r" (res) \
747 : "r" (addr), "n" (& RAMPZ) \
748 : "r30", "r31", "r0")
749
750#define __ELPM__2(res, addr, T) \
751 __asm __volatile__ \
752 ("mov r30,%A1" "\n\t" \
753 "mov r31,%B1" "\n\t" \
754 "mov %B0,%C1" "\n\t" \
755 "out %i2,%B0 $ elpm $ mov %A0,r0 $ adiw r30,1 $ adc %B0,r1" "\n\t" \
756 "out %i2,%B0 $ elpm $ mov %B0,r0" \
757 : "=r" (res) \
758 : "r" (addr), "n" (& RAMPZ) \
759 : "r30", "r31", "r0")
760
761#define __ELPM__3(res, addr, T) \
762 __asm __volatile__ \
763 ("mov r30,%A1" "\n\t" \
764 "mov r31,%B1" "\n\t" \
765 "mov %C0,%C1" "\n\t" \
766 "out %i2,%C0 $ elpm $ mov %A0,r0 $ adiw r30,1 $ adc %C0,r1" "\n\t" \
767 "out %i2,%C0 $ elpm $ mov %B0,r0 $ adiw r30,1 $ adc %C0,r1" "\n\t" \
768 "out %i2,%C0 $ elpm $ mov %C0,r0" \
769 : "=r" (res) \
770 : "r" (addr), "n" (& RAMPZ) \
771 : "r30", "r31", "r0")
772
773#define __ELPM__4(res, addr, T) \
774 __asm __volatile__ \
775 ("mov r30,%A1" "\n\t" \
776 "mov r31,%B1" "\n\t" \
777 "mov %D0,%C1" "\n\t" \
778 "out %i2,%D0 $ elpm $ mov %A0,r0 $ adiw r30,1 $ adc %D0,r1" "\n\t" \
779 "out %i2,%D0 $ elpm $ mov %B0,r0 $ adiw r30,1 $ adc %D0,r1" "\n\t" \
780 "out %i2,%D0 $ elpm $ mov %C0,r0 $ adiw r30,1 $ adc %D0,r1" "\n\t" \
781 "out %i2,%D0 $ elpm $ mov %D0,r0" \
782 : "=r" (res) \
783 : "r" (addr), "n" (& RAMPZ) \
784 : "r30", "r31", "r0")
785
786#define __ELPM__8(res, addr, T) \
787 __asm __volatile__ \
788 ("mov r30,%A1" "\n\t" \
789 "mov r31,%B1" "\n\t" \
790 "mov %r0+7,%C1" "\n\t" \
791 "out %i2,%r0+7 $ elpm $ mov %r0+0,r0 $ adiw r30,1 $ adc %r0+7,r1" "\n\t" \
792 "out %i2,%r0+7 $ elpm $ mov %r0+1,r0 $ adiw r30,1 $ adc %r0+7,r1" "\n\t" \
793 "out %i2,%r0+7 $ elpm $ mov %r0+2,r0 $ adiw r30,1 $ adc %r0+7,r1" "\n\t" \
794 "out %i2,%r0+7 $ elpm $ mov %r0+3,r0 $ adiw r30,1 $ adc %r0+7,r1" "\n\t" \
795 "out %i2,%r0+7 $ elpm $ mov %r0+4,r0 $ adiw r30,1 $ adc %r0+7,r1" "\n\t" \
796 "out %i2,%r0+7 $ elpm $ mov %r0+5,r0 $ adiw r30,1 $ adc %r0+7,r1" "\n\t" \
797 "out %i2,%r0+7 $ elpm $ mov %r0+6,r0 $ adiw r30,1 $ adc %r0+7,r1" "\n\t" \
798 "out %i2,%r0+7 $ elpm $ mov %r0+7,r0" \
799 : "=r" (res) \
800 : "r" (addr), "n" (& RAMPZ) \
801 : "r30", "r31", "r0")
802#else
803/* No ELPM: Fall back to __LPM__<N>. */
804#define __ELPM__1(r,a,T) const T *__a = (const T*)(uint16_t) a; __LPM__1(r,__a)
805#define __ELPM__2(r,a,T) const T *__a = (const T*)(uint16_t) a; __LPM__2(r,__a)
806#define __ELPM__3(r,a,T) const T *__a = (const T*)(uint16_t) a; __LPM__3(r,__a)
807#define __ELPM__4(r,a,T) const T *__a = (const T*)(uint16_t) a; __LPM__4(r,__a)
808#define __ELPM__8(r,a,T) const T *__a = (const T*)(uint16_t) a; __LPM__8(r,__a)
809#endif /* ELPM cases */
810
811#define _Avrlibc_Def_Pgm_Far_1(Name, Typ) \
812 static __ATTR_ALWAYS_INLINE__ \
813 Typ pgm_read_##Name##_far (uint_farptr_t __addr) \
814 { \
815 Typ __res; \
816 __ELPM__1 (__res, __addr, Typ); \
817 return __res; \
818 }
819
820#define _Avrlibc_Def_Pgm_Far_2(Name, Typ) \
821 static __ATTR_ALWAYS_INLINE__ \
822 Typ pgm_read_##Name##_far (uint_farptr_t __addr) \
823 { \
824 Typ __res; \
825 __ELPM__2 (__res, __addr, Typ); \
826 return __res; \
827 }
828
829#define _Avrlibc_Def_Pgm_Far_3(Name, Typ) \
830 static __ATTR_ALWAYS_INLINE__ \
831 Typ pgm_read_##Name##_far (uint_farptr_t __addr) \
832 { \
833 Typ __res; \
834 __ELPM__3 (__res, __addr, Typ); \
835 return __res; \
836 }
837
838#define _Avrlibc_Def_Pgm_Far_4(Name, Typ) \
839 static __ATTR_ALWAYS_INLINE__ \
840 Typ pgm_read_##Name##_far (uint_farptr_t __addr) \
841 { \
842 Typ __res; \
843 __ELPM__4 (__res, __addr, Typ); \
844 return __res; \
845 }
846
847#define _Avrlibc_Def_Pgm_Far_8(Name, Typ) \
848 static __ATTR_ALWAYS_INLINE__ \
849 Typ pgm_read_##Name##_far (uint_farptr_t __addr) \
850 { \
851 Typ __res; \
852 __ELPM__8 (__res, __addr, Typ); \
853 return __res; \
854 }
855
856_Avrlibc_Def_Pgm_Far_1 (char, char)
857_Avrlibc_Def_Pgm_Far_1 (unsigned_char, unsigned char)
858_Avrlibc_Def_Pgm_Far_1 (signed_char, signed char)
859_Avrlibc_Def_Pgm_Far_1 (u8, uint8_t)
860_Avrlibc_Def_Pgm_Far_1 (i8, int8_t)
861#if __SIZEOF_INT__ == 1
862_Avrlibc_Def_Pgm_Far_1 (int, int)
863_Avrlibc_Def_Pgm_Far_1 (unsigned, unsigned)
864_Avrlibc_Def_Pgm_Far_1 (unsigned_int, unsigned int)
865_Avrlibc_Def_Pgm_Far_1 (signed, signed)
866_Avrlibc_Def_Pgm_Far_1 (signed_int, signed int)
867#endif
868#if __SIZEOF_SHORT__ == 1
869_Avrlibc_Def_Pgm_Far_1 (short, short)
870_Avrlibc_Def_Pgm_Far_1 (unsigned_short, unsigned short)
871#endif
872
873_Avrlibc_Def_Pgm_Far_2 (u16, uint16_t)
874_Avrlibc_Def_Pgm_Far_2 (i16, int16_t)
875#if __SIZEOF_INT__ == 2
876_Avrlibc_Def_Pgm_Far_2 (int, int)
877_Avrlibc_Def_Pgm_Far_2 (unsigned, unsigned)
878_Avrlibc_Def_Pgm_Far_2 (unsigned_int, unsigned int)
879_Avrlibc_Def_Pgm_Far_2 (signed, signed)
880_Avrlibc_Def_Pgm_Far_2 (signed_int, signed int)
881#endif
882#if __SIZEOF_SHORT__ == 2
883_Avrlibc_Def_Pgm_Far_2 (short, short)
884_Avrlibc_Def_Pgm_Far_2 (unsigned_short, unsigned short)
885#endif
886#if __SIZEOF_LONG__ == 2
887_Avrlibc_Def_Pgm_Far_2 (long, long)
888_Avrlibc_Def_Pgm_Far_2 (unsigned_long, unsigned long)
889#endif
890
891#if defined(__INT24_MAX__)
892_Avrlibc_Def_Pgm_Far_3 (i24, __int24)
893_Avrlibc_Def_Pgm_Far_3 (u24, __uint24)
894#endif /* Have __int24 */
895
896_Avrlibc_Def_Pgm_Far_4 (u32, uint32_t)
897_Avrlibc_Def_Pgm_Far_4 (i32, int32_t)
898_Avrlibc_Def_Pgm_Far_4 (float, float)
899#if __SIZEOF_LONG__ == 4
900_Avrlibc_Def_Pgm_Far_4 (long, long)
901_Avrlibc_Def_Pgm_Far_4 (unsigned_long, unsigned long)
902#endif
903#if __SIZEOF_LONG_LONG__ == 4
904_Avrlibc_Def_Pgm_Far_4 (long_long, long long)
905_Avrlibc_Def_Pgm_Far_4 (unsigned_long_long, unsigned long long)
906#endif
907#if __SIZEOF_DOUBLE__ == 4
908_Avrlibc_Def_Pgm_Far_4 (double, double)
909#endif
910#if __SIZEOF_LONG_DOUBLE__ == 4
911_Avrlibc_Def_Pgm_Far_4 (long_double, long double)
912#endif
913
914#if __SIZEOF_LONG_LONG__ == 8
915_Avrlibc_Def_Pgm_Far_8 (u64, uint64_t)
916_Avrlibc_Def_Pgm_Far_8 (i64, int64_t)
917_Avrlibc_Def_Pgm_Far_8 (long_long, long long)
918_Avrlibc_Def_Pgm_Far_8 (unsigned_long_long, unsigned long long)
919#endif
920#if __SIZEOF_DOUBLE__ == 8
921_Avrlibc_Def_Pgm_Far_8 (double, double)
922#endif
923#if __SIZEOF_LONG_DOUBLE__ == 8
924_Avrlibc_Def_Pgm_Far_8 (long_double, long double)
925#endif
926
927#endif /* DOXYGEN */
928
929#ifdef __cplusplus
930extern "C" {
931#endif
932
933#if defined(__DOXYGEN__)
934/* No documentation for the deprecated stuff. */
935#elif defined(__PROG_TYPES_COMPAT__) /* !DOXYGEN */
936
937typedef void prog_void __attribute__((__progmem__,__deprecated__("prog_void type is deprecated.")));
938typedef char prog_char __attribute__((__progmem__,__deprecated__("prog_char type is deprecated.")));
939typedef unsigned char prog_uchar __attribute__((__progmem__,__deprecated__("prog_uchar type is deprecated.")));
940typedef int8_t prog_int8_t __attribute__((__progmem__,__deprecated__("prog_int8_t type is deprecated.")));
941typedef uint8_t prog_uint8_t __attribute__((__progmem__,__deprecated__("prog_uint8_t type is deprecated.")));
942typedef int16_t prog_int16_t __attribute__((__progmem__,__deprecated__("prog_int16_t type is deprecated.")));
943typedef uint16_t prog_uint16_t __attribute__((__progmem__,__deprecated__("prog_uint16_t type is deprecated.")));
944typedef int32_t prog_int32_t __attribute__((__progmem__,__deprecated__("prog_int32_t type is deprecated.")));
945typedef uint32_t prog_uint32_t __attribute__((__progmem__,__deprecated__("prog_uint32_t type is deprecated.")));
946#if !__USING_MINT8
947typedef int64_t prog_int64_t __attribute__((__progmem__,__deprecated__("prog_int64_t type is deprecated.")));
948typedef uint64_t prog_uint64_t __attribute__((__progmem__,__deprecated__("prog_uint64_t type is deprecated.")));
949#endif
950
951#ifndef PGM_P
952#define PGM_P const prog_char *
953#endif
954
955#ifndef PGM_VOID_P
956#define PGM_VOID_P const prog_void *
957#endif
958
959#else /* !defined(__DOXYGEN__), !defined(__PROG_TYPES_COMPAT__) */
960
961#ifndef PGM_P
962#define PGM_P const char *
963#endif
964
965#ifndef PGM_VOID_P
966#define PGM_VOID_P const void *
967#endif
968#endif /* defined(__DOXYGEN__), defined(__PROG_TYPES_COMPAT__) */
969
970/* Although in C, we can get away with just using __c, it does not work in
971 C++. We need to use &__c[0] to avoid the compiler puking. Dave Hylands
972 explaned it thusly,
973
974 Let's suppose that we use PSTR("Test"). In this case, the type returned
975 by __c is a prog_char[5] and not a prog_char *. While these are
976 compatible, they aren't the same thing (especially in C++). The type
977 returned by &__c[0] is a prog_char *, which explains why it works
978 fine. */
979
980#if defined(__DOXYGEN__)
981/*
982 * The #define below is just a dummy that serves documentation
983 * purposes only.
984 */
985/** \ingroup avr_pgmspace
986 \def PSTR(str)
987
988 Used to declare a static pointer to a string in program space. */
989# define PSTR(str) ({ static const PROGMEM char c[] = (str); &c[0]; })
990#else /* !DOXYGEN */
991/* The real thing. */
992# define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
993#endif /* DOXYGEN */
994
995#if defined(__DOXYGEN__)
996/** \ingroup avr_pgmspace
997 \def PSTR_FAR(str)
998
999 Used to define a string literal in far program space, and to return its
1000 address of type #uint_farptr_t. */
1001# define PSTR_FAR(str) ({ static const PROGMEM_FAR char c[] = (str); pgm_get_far_address(c[0]); })
1002#else /* !DOXYGEN */
1003/* The real thing. */
1004# define PSTR_FAR(s) (__extension__({static const char __c[] PROGMEM_FAR = (s); pgm_get_far_address(__c[0]);}))
1005#endif /* DOXYGEN */
1006
1007#ifndef __DOXYGEN__
1008
1009/* These are used down the line for pgm_read_byte[_near] etc. */
1010
1011#if defined (__AVR_TINY__)
1012/* Attribute __progmem__ on Reduced Tiny works different than for
1013 all the other devices: When taking the address of a symbol that's
1014 attributed as progmem, then the compiler adds an offset of 0x4000
1015 to the value of the symbol. This means that accessing data in
1016 progmem can be performed by vanilla C/C++ code. This requires
1017 - GCC PR71948 - Make progmem work on Reduced Tiny (GCC v7 / 2016-08) */
1018#define __LPM(addr) (* (const uint8_t*)(addr))
1019#define __LPM_word(addr) (* (const uint16_t*)(addr))
1020#define __LPM_dword(addr) (* (const uint32_t*)(addr))
1021# if __SIZEOF_LONG_LONG__ == 8
1022# define __LPM_qword(addr) (* (const uint64_t*)(addr))
1023# endif
1024#else
1025#define __LPM(addr) \
1026 (__extension__({ \
1027 uint16_t __addr16 = (uint16_t) (addr); \
1028 uint8_t __result; \
1029 __LPM__1 (__result, __addr16); \
1030 __result; \
1031}))
1032
1033#define __LPM_word(addr) \
1034 (__extension__({ \
1035 uint16_t __addr16 = (uint16_t) (addr); \
1036 uint16_t __result; \
1037 __LPM__2 (__result, __addr16); \
1038 __result; \
1039}))
1040
1041#define __LPM_dword(addr) \
1042 (__extension__({ \
1043 uint16_t __addr16 = (uint16_t) (addr); \
1044 uint32_t __result; \
1045 __LPM__4 (__result, __addr16); \
1046 __result; \
1047}))
1048
1049#if __SIZEOF_LONG_LONG__ == 8
1050#define __LPM_qword(addr) \
1051 (__extension__({ \
1052 uint16_t __addr16 = (uint16_t) (addr); \
1053 uint64_t __result; \
1054 __LPM__8 (__result, __addr16); \
1055 __result; \
1056}))
1057#endif
1058#endif /* AVR_TINY */
1059
1060
1061#define __ELPM(addr) \
1062 (__extension__({ \
1063 uint_farptr_t __addr32 = (addr); \
1064 uint8_t __result; \
1065 __ELPM__1 (__result, __addr32, uint8_t); \
1066 __result; \
1067}))
1068
1069#define __ELPM_word(addr) \
1070 (__extension__({ \
1071 uint_farptr_t __addr32 = (addr); \
1072 uint16_t __result; \
1073 __ELPM__2 (__result, __addr32, uint16_t); \
1074 __result; \
1075}))
1076
1077#define __ELPM_dword(addr) \
1078 (__extension__({ \
1079 uint_farptr_t __addr32 = (addr); \
1080 uint32_t __result; \
1081 __ELPM__4 (__result, __addr32, uint32_t); \
1082 __result; \
1083}))
1084
1085#if __SIZEOF_LONG_LONG__ == 8
1086#define __ELPM_qword(addr) \
1087 (__extension__({ \
1088 uint_farptr_t __addr32 = (addr); \
1089 uint64_t __result; \
1090 __ELPM__8 (__result, __addr32, uint64_t); \
1091 __result; \
1092}))
1093#endif
1094
1095#endif /* !__DOXYGEN__ */
1096
1097/** \ingroup avr_pgmspace
1098 \def pgm_read_byte_near(__addr)
1099 Read a byte from the program space with a 16-bit (near) byte-address. */
1100
1101#define pgm_read_byte_near(__addr) __LPM ((uint16_t)(__addr))
1102
1103/** \ingroup avr_pgmspace
1104 \def pgm_read_word_near(__addr)
1105 Read a word from the program space with a 16-bit (near) byte-address. */
1106
1107#define pgm_read_word_near(__addr) __LPM_word ((uint16_t)(__addr))
1108
1109/** \ingroup avr_pgmspace
1110 \def pgm_read_dword_near(__addr)
1111 Read a double word from the program space with a 16-bit (near)
1112 byte-address. */
1113
1114#define pgm_read_dword_near(__addr) \
1115 __LPM_dword ((uint16_t)(__addr))
1116
1117/** \ingroup avr_pgmspace
1118 \def pgm_read_qword_near(__addr)
1119 Read a quad-word from the program space with a 16-bit (near)
1120 byte-address. */
1121
1122#define pgm_read_qword_near(__addr) __LPM_qword ((uint16_t)(__addr))
1123
1124/** \ingroup avr_pgmspace
1125 \def pgm_read_float_near (const float *address)
1126 Read a \c float from the program space with a 16-bit (near) byte-address.*/
1127
1128#define pgm_read_float_near(addr) pgm_read_float (addr)
1129
1130/** \ingroup avr_pgmspace
1131 \def pgm_read_ptr_near(__addr)
1132 Read a pointer from the program space with a 16-bit (near) byte-address. */
1133
1134#define pgm_read_ptr_near(__addr) \
1135 ((void*) __LPM_word ((uint16_t)(__addr)))
1136
1137/** \ingroup avr_pgmspace
1138 \def pgm_read_byte_far(__addr)
1139 Read a byte from the program space with a 32-bit (far) byte-address. */
1140
1141#define pgm_read_byte_far(__addr) __ELPM (__addr)
1142
1143/** \ingroup avr_pgmspace
1144 \def pgm_read_word_far(__addr)
1145 Read a word from the program space with a 32-bit (far) byte-address. */
1146
1147#define pgm_read_word_far(__addr) __ELPM_word (__addr)
1148
1149/** \ingroup avr_pgmspace
1150 \def pgm_read_dword_far(__addr)
1151 Read a double word from the program space with a 32-bit (far)
1152 byte-address. */
1153
1154#define pgm_read_dword_far(__addr) __ELPM_dword (__addr)
1155
1156/** \ingroup avr_pgmspace
1157 \def pgm_read_qword_far(__addr)
1158 Read a quad-word from the program space with a 32-bit (far)
1159 byte-address. */
1160
1161#define pgm_read_qword_far(__addr) __ELPM_qword (__addr)
1162
1163/** \ingroup avr_pgmspace
1164 \def pgm_read_ptr_far(__addr)
1165 Read a pointer from the program space with a 32-bit (far) byte-address. */
1166
1167#define pgm_read_ptr_far(__addr) ((void*) __ELPM_word (__addr))
1168
1169/** \ingroup avr_pgmspace
1170 \def pgm_read_byte(__addr)
1171 Read a byte from the program space with a 16-bit (near) nyte-address. */
1172
1173#define pgm_read_byte(__addr) pgm_read_byte_near(__addr)
1174
1175/** \ingroup avr_pgmspace
1176 \def pgm_read_word(__addr)
1177 Read a word from the program space with a 16-bit (near) byte-address. */
1178
1179#define pgm_read_word(__addr) pgm_read_word_near(__addr)
1180
1181/** \ingroup avr_pgmspace
1182 \def pgm_read_dword(__addr)
1183 Read a double word from the program space with a 16-bit (near)
1184 byte-address. */
1185
1186#define pgm_read_dword(__addr) pgm_read_dword_near(__addr)
1187
1188/** \ingroup avr_pgmspace
1189 \def pgm_read_qword(__addr)
1190 Read a quad-word from the program space with a 16-bit (near)
1191 byte-address. */
1192
1193#define pgm_read_qword(__addr) pgm_read_qword_near(__addr)
1194
1195/** \ingroup avr_pgmspace
1196 \def pgm_read_ptr(__addr)
1197 Read a pointer from the program space with a 16-bit (near) byte-address. */
1198
1199#define pgm_read_ptr(__addr) pgm_read_ptr_near(__addr)
1200
1201/** \ingroup avr_pgmspace
1202 \def pgm_get_far_address(var)
1203
1204 This macro evaluates to a ::uint_farptr_t 32-bit "far" pointer (only
1205 24 bits used) to data even beyond the 64 KiB limit for the 16-bit ordinary
1206 pointer. It is similar to the '&' operator, with some limitations.
1207 Example:
1208 \code
1209 #include <avr/pgmspace.h>
1210
1211 // Section .progmemx.data is located after all the code sections.
1212 __attribute__((section(".progmemx.data")))
1213 const int data[] = { 2, 3, 5, 7, 9, 11 };
1214
1215 int get_data (uint8_t idx)
1216 {
1217 uint_farptr_t pdata = pgm_get_far_address (data[0]);
1218 return pgm_read_int_far (pdata + idx * sizeof(int));
1219 }
1220 \endcode
1221
1222 Comments:
1223
1224 - The overhead is minimal and it's mainly due to the 32-bit size operation.
1225
1226 - 24 bit sizes guarantees the code compatibility for use in future devices.
1227
1228 - \p var has to be resolved at link-time as an existing symbol,
1229 i.e. a simple variable name, an array name, or an array or structure
1230 element provided the offset is known at compile-time, and \p var is
1231 located in static storage, etc.
1232
1233 - The returned value is the symbol's \ref sec_vma "VMA"
1234 (virtual memory address)
1235 determined by the linker and falls in the corresponding memory region.
1236 The AVR Harvard architecture requires non-overlapping VMA areas for
1237 the multiple \ref sec_memory_regions "memory regions" in the processor:
1238 Flash ROM, RAM, and EEPROM. Typical offset for these are
1239 \c 0x0, \c 0x800xx0, and \c 0x810000 respectively, derived from the
1240 linker script used and linker options.
1241*/
1242
1243#define pgm_get_far_address(var) \
1244(__extension__({ \
1245 uint_farptr_t __tmp; \
1246 \
1247 __asm__ __volatile__ ( \
1248 "ldi %A0, lo8(%1)" "\n\t" \
1249 "ldi %B0, hi8(%1)" "\n\t" \
1250 "ldi %C0, hh8(%1)" "\n\t" \
1251 "clr %D0" \
1252 : "=d" (__tmp) \
1253 : "i" (&(var)) \
1254 ); \
1255 __tmp; \
1256}))
1257
1258
1259
1260/** \ingroup avr_pgmspace
1261 \fn const void * memchr_P(const void *s, int val, size_t len)
1262 \brief Scan flash memory for a character.
1263
1264 The memchr_P() function scans the first \p len bytes of the flash
1265 memory area pointed to by \p s for the character \p val. The first
1266 byte to match \p val (interpreted as an unsigned character) stops
1267 the operation.
1268
1269 \return The memchr_P() function returns a pointer to the matching
1270 byte or \c NULL if the character does not occur in the given memory
1271 area. */
1272extern const void * memchr_P(const void *, int __val, size_t __len) __ATTR_CONST__;
1273
1274/** \ingroup avr_pgmspace
1275 \fn int memcmp_P(const void *s1, const void *s2, size_t len)
1276 \brief Compare memory areas
1277
1278 The memcmp_P() function compares the first \p len bytes of the memory
1279 areas \p s1 and flash \p s2. The comparision is performed using unsigned
1280 char operations.
1281
1282 \returns The memcmp_P() function returns an integer less than, equal
1283 to, or greater than zero if the first \p len bytes of \p s1 is found,
1284 respectively, to be less than, to match, or be greater than the first
1285 \p len bytes of \p s2. */
1286extern int memcmp_P(const void *, const void *, size_t) __ATTR_PURE__;
1287
1288/** \ingroup avr_pgmspace
1289 \fn void *memccpy_P (void *dest, const void *src, int val, size_t len)
1290
1291 This function is similar to memccpy() except that \p src is pointer
1292 to a string in program space. */
1293extern void *memccpy_P(void *, const void *, int __val, size_t);
1294
1295/** \ingroup avr_pgmspace
1296 \fn void *memcpy_P(void *dest, const void *src, size_t n)
1297
1298 The memcpy_P() function is similar to memcpy(), except the src string
1299 resides in program space.
1300
1301 \returns The memcpy_P() function returns a pointer to dest. */
1302extern void *memcpy_P(void *, const void *, size_t);
1303
1304/** \ingroup avr_pgmspace
1305 \fn void *memmem_P(const void *s1, size_t len1, const void *s2, size_t len2)
1306
1307 The memmem_P() function is similar to memmem() except that \p s2 is
1308 pointer to a string in program space. */
1309extern void *memmem_P(const void *, size_t, const void *, size_t) __ATTR_PURE__;
1310
1311/** \ingroup avr_pgmspace
1312 \fn const void +memrchr_P(const void *src, int val, size_t len)
1313
1314 The memrchr_P() function is like the memchr_P() function, except
1315 that it searches backwards from the end of the \p len bytes pointed
1316 to by \p src instead of forwards from the front. (Glibc, GNU extension.)
1317
1318 \return The memrchr_P() function returns a pointer to the matching
1319 byte or \c NULL if the character does not occur in the given memory
1320 area. */
1321extern const void * memrchr_P(const void *, int __val, size_t __len) __ATTR_CONST__;
1322
1323/** \ingroup avr_pgmspace
1324 \fn char *strcat_P(char *dest, const char *src)
1325
1326 The strcat_P() function is similar to strcat() except that the \e src
1327 string must be located in program space (flash).
1328
1329 \returns The strcat() function returns a pointer to the resulting string
1330 \e dest. */
1331extern char *strcat_P(char *, const char *);
1332
1333/** \ingroup avr_pgmspace
1334 \fn const char *strchr_P(const char *s, int val)
1335 \brief Locate character in program space string.
1336
1337 The strchr_P() function locates the first occurrence of \p val
1338 (converted to a char) in the string pointed to by \p s in program
1339 space. The terminating null character is considered to be part of
1340 the string.
1341
1342 The strchr_P() function is similar to strchr() except that \p s is
1343 pointer to a string in program space.
1344
1345 \returns The strchr_P() function returns a pointer to the matched
1346 character or \c NULL if the character is not found. */
1347extern const char * strchr_P(const char *, int __val) __ATTR_CONST__;
1348
1349/** \ingroup avr_pgmspace
1350 \fn const char *strchrnul_P(const char *s, int c)
1351
1352 The strchrnul_P() function is like strchr_P() except that if \p c is
1353 not found in \p s, then it returns a pointer to the null byte at the
1354 end of \p s, rather than \c NULL. (Glibc, GNU extension.)
1355
1356 \return The strchrnul_P() function returns a pointer to the matched
1357 character, or a pointer to the null byte at the end of \p s (i.e.,
1358 \c s+strlen(s)) if the character is not found. */
1359extern const char * strchrnul_P(const char *, int __val) __ATTR_CONST__;
1360
1361/** \ingroup avr_pgmspace
1362 \fn int strcmp_P(const char *s1, const char *s2)
1363
1364 The strcmp_P() function is similar to strcmp() except that \p s2 is
1365 pointer to a string in program space.
1366
1367 \returns The strcmp_P() function returns an integer less than, equal
1368 to, or greater than zero if \p s1 is found, respectively, to be less
1369 than, to match, or be greater than \p s2. A consequence of the
1370 ordering used by strcmp_P() is that if \p s1 is an initial substring
1371 of \p s2, then \p s1 is considered to be "less than" \p s2. */
1372extern int strcmp_P(const char *, const char *) __ATTR_PURE__;
1373
1374/** \ingroup avr_pgmspace
1375 \fn char *strcpy_P(char *dest, const char *src)
1376
1377 The strcpy_P() function is similar to strcpy() except that src is a
1378 pointer to a string in program space.
1379
1380 \returns The strcpy_P() function returns a pointer to the destination
1381 string dest. */
1382extern char *strcpy_P(char *, const char *);
1383
1384/** \ingroup avr_pgmspace
1385 \fn int strcasecmp_P(const char *s1, const char *s2)
1386 \brief Compare two strings ignoring case.
1387
1388 The strcasecmp_P() function compares the two strings \p s1 and \p s2,
1389 ignoring the case of the characters.
1390
1391 \param s1 A pointer to a string in the devices SRAM.
1392 \param s2 A pointer to a string in the devices Flash.
1393
1394 \returns The strcasecmp_P() function returns an integer less than,
1395 equal to, or greater than zero if \p s1 is found, respectively, to
1396 be less than, to match, or be greater than \p s2. A consequence of
1397 the ordering used by strcasecmp_P() is that if \p s1 is an initial
1398 substring of \p s2, then \p s1 is considered to be "less than" \p s2. */
1399extern int strcasecmp_P(const char *, const char *) __ATTR_PURE__;
1400
1401/** \ingroup avr_pgmspace
1402 \fn char *strcasestr_P(const char *s1, const char *s2)
1403
1404 This funtion is similar to strcasestr() except that \p s2 is pointer
1405 to a string in program space. */
1406extern char *strcasestr_P(const char *, const char *) __ATTR_PURE__;
1407
1408/** \ingroup avr_pgmspace
1409 \fn size_t strcspn_P(const char *s, const char *reject)
1410
1411 The strcspn_P() function calculates the length of the initial segment
1412 of \p s which consists entirely of characters not in \p reject. This
1413 function is similar to strcspn() except that \p reject is a pointer
1414 to a string in program space.
1415
1416 \return The strcspn_P() function returns the number of characters in
1417 the initial segment of \p s which are not in the string \p reject.
1418 The terminating zero is not considered as a part of string. */
1419extern size_t strcspn_P(const char *__s, const char * __reject) __ATTR_PURE__;
1420
1421/** \ingroup avr_pgmspace
1422 \fn size_t strlcat_P(char *dst, const char *src, size_t siz)
1423 \brief Concatenate two strings.
1424
1425 The strlcat_P() function is similar to strlcat(), except that the \p src
1426 string must be located in program space (flash).
1427
1428 Appends \p src to string \p dst of size \p siz (unlike strncat(),
1429 \p siz is the full size of \p dst, not space left). At most \p siz-1
1430 characters will be copied. Always NULL terminates (unless \p siz <=
1431 \p strlen(dst)).
1432
1433 \returns The strlcat_P() function returns strlen(src) + MIN(siz,
1434 strlen(initial dst)). If retval >= siz, truncation occurred. */
1435extern size_t strlcat_P (char *, const char *, size_t );
1436
1437/** \ingroup avr_pgmspace
1438 \fn size_t strlcpy_P(char *dst, const char *src, size_t siz)
1439 \brief Copy a string from progmem to RAM.
1440
1441 Copy \p src to string \p dst of size \p siz. At most \p siz-1
1442 characters will be copied. Always NULL terminates (unless \p siz == 0).
1443 The strlcpy_P() function is similar to strlcpy() except that the
1444 \p src is pointer to a string in memory space.
1445
1446 \returns The strlcpy_P() function returns strlen(src). If
1447 retval >= siz, truncation occurred. */
1448extern size_t strlcpy_P (char *, const char *, size_t );
1449
1450/** \ingroup avr_pgmspace
1451 \fn size_t strnlen_P(const char *src, size_t len)
1452 \brief Determine the length of a fixed-size string.
1453
1454 The strnlen_P() function is similar to strnlen(), except that \c src is a
1455 pointer to a string in program space.
1456
1457 \returns The strnlen_P function returns strlen_P(src), if that is less than
1458 \c len, or \c len if there is no '\\0' character among the first \c len
1459 characters pointed to by \c src. */
1460extern size_t strnlen_P(const char *, size_t) __ATTR_CONST__; /* program memory can't change */
1461
1462/** \ingroup avr_pgmspace
1463 \fn int strncmp_P(const char *s1, const char *s2, size_t n)
1464
1465 The strncmp_P() function is similar to strcmp_P() except it only compares
1466 the first (at most) n characters of s1 and s2.
1467
1468 \returns The strncmp_P() function returns an integer less than, equal to,
1469 or greater than zero if s1 (or the first n bytes thereof) is found,
1470 respectively, to be less than, to match, or be greater than s2. */
1471extern int strncmp_P(const char *, const char *, size_t) __ATTR_PURE__;
1472
1473/** \ingroup avr_pgmspace
1474 \fn int strncasecmp_P(const char *s1, const char *s2, size_t n)
1475 \brief Compare two strings ignoring case.
1476
1477 The strncasecmp_P() function is similar to strcasecmp_P(), except it
1478 only compares the first \p n characters of \p s1.
1479
1480 \param s1 A pointer to a string in the devices SRAM.
1481 \param s2 A pointer to a string in the devices Flash.
1482 \param n The maximum number of bytes to compare.
1483
1484 \returns The strncasecmp_P() function returns an integer less than,
1485 equal to, or greater than zero if \p s1 (or the first \p n bytes
1486 thereof) is found, respectively, to be less than, to match, or be
1487 greater than \p s2. A consequence of the ordering used by
1488 strncasecmp_P() is that if \p s1 is an initial substring of \p s2,
1489 then \p s1 is considered to be "less than" \p s2. */
1490extern int strncasecmp_P(const char *, const char *, size_t) __ATTR_PURE__;
1491
1492/** \ingroup avr_pgmspace
1493 \fn char *strncat_P(char *dest, const char *src, size_t len)
1494 \brief Concatenate two strings.
1495
1496 The strncat_P() function is similar to strncat(), except that the \e src
1497 string must be located in program space (flash).
1498
1499 \returns The strncat_P() function returns a pointer to the resulting string
1500 dest. */
1501extern char *strncat_P(char *, const char *, size_t);
1502
1503/** \ingroup avr_pgmspace
1504 \fn char *strncpy_P(char *dest, const char *src, size_t n)
1505
1506 The strncpy_P() function is similar to strcpy_P() except that not more
1507 than n bytes of src are copied. Thus, if there is no null byte among the
1508 first n bytes of src, the result will not be null-terminated.
1509
1510 In the case where the length of src is less than that of n, the remainder
1511 of dest will be padded with nulls.
1512
1513 \returns The strncpy_P() function returns a pointer to the destination
1514 string dest. */
1515extern char *strncpy_P(char *, const char *, size_t);
1516
1517/** \ingroup avr_pgmspace
1518 \fn char *strpbrk_P(const char *s, const char *accept)
1519
1520 The strpbrk_P() function locates the first occurrence in the string
1521 \p s of any of the characters in the flash string \p accept. This
1522 function is similar to strpbrk() except that \p accept is a pointer
1523 to a string in program space.
1524
1525 \return The strpbrk_P() function returns a pointer to the character
1526 in \p s that matches one of the characters in \p accept, or \c NULL
1527 if no such character is found. The terminating zero is not considered
1528 as a part of string: if one or both args are empty, the result will
1529 \c NULL. */
1530extern char *strpbrk_P(const char *__s, const char * __accept) __ATTR_PURE__;
1531
1532/** \ingroup avr_pgmspace
1533 \fn const char *strrchr_P(const char *s, int val)
1534 \brief Locate character in string.
1535
1536 The strrchr_P() function returns a pointer to the last occurrence of
1537 the character \p val in the flash string \p s.
1538
1539 \return The strrchr_P() function returns a pointer to the matched
1540 character or \c NULL if the character is not found. */
1541extern const char * strrchr_P(const char *, int __val) __ATTR_CONST__;
1542
1543/** \ingroup avr_pgmspace
1544 \fn char *strsep_P(char **sp, const char *delim)
1545 \brief Parse a string into tokens.
1546
1547 The strsep_P() function locates, in the string referenced by \p *sp,
1548 the first occurrence of any character in the string \p delim (or the
1549 terminating '\\0' character) and replaces it with a '\\0'. The
1550 location of the next character after the delimiter character (or \c
1551 NULL, if the end of the string was reached) is stored in \p *sp. An
1552 ``empty'' field, i.e. one caused by two adjacent delimiter
1553 characters, can be detected by comparing the location referenced by
1554 the pointer returned in \p *sp to '\\0'. This function is similar to
1555 strsep() except that \p delim is a pointer to a string in program
1556 space.
1557
1558 \return The strsep_P() function returns a pointer to the original
1559 value of \p *sp. If \p *sp is initially \c NULL, strsep_P() returns
1560 \c NULL. */
1561extern char *strsep_P(char **__sp, const char * __delim);
1562
1563/** \ingroup avr_pgmspace
1564 \fn size_t strspn_P(const char *s, const char *accept)
1565
1566 The strspn_P() function calculates the length of the initial segment
1567 of \p s which consists entirely of characters in \p accept. This
1568 function is similar to strspn() except that \p accept is a pointer
1569 to a string in program space.
1570
1571 \return The strspn_P() function returns the number of characters in
1572 the initial segment of \p s which consist only of characters from \p
1573 accept. The terminating zero is not considered as a part of string. */
1574extern size_t strspn_P(const char *__s, const char * __accept) __ATTR_PURE__;
1575
1576/** \ingroup avr_pgmspace
1577 \fn char *strstr_P(const char *s1, const char *s2)
1578 \brief Locate a substring.
1579
1580 The strstr_P() function finds the first occurrence of the substring
1581 \p s2 in the string \p s1. The terminating '\\0' characters are not
1582 compared. The strstr_P() function is similar to strstr() except that
1583 \p s2 is pointer to a string in program space.
1584
1585 \returns The strstr_P() function returns a pointer to the beginning
1586 of the substring, or NULL if the substring is not found. If \p s2
1587 points to a string of zero length, the function returns \p s1. */
1588extern char *strstr_P(const char *, const char *) __ATTR_PURE__;
1589
1590/** \ingroup avr_pgmspace
1591 \fn char *strtok_P(char *s, const char * delim)
1592 \brief Parses the string into tokens.
1593
1594 strtok_P() parses the string \p s into tokens. The first call to
1595 strtok_P() should have \p s as its first argument. Subsequent calls
1596 should have the first argument set to NULL. If a token ends with a
1597 delimiter, this delimiting character is overwritten with a '\\0' and a
1598 pointer to the next character is saved for the next call to strtok_P().
1599 The delimiter string \p delim may be different for each call.
1600
1601 The strtok_P() function is similar to strtok() except that \p delim
1602 is pointer to a string in program space.
1603
1604 \returns The strtok_P() function returns a pointer to the next token or
1605 NULL when no more tokens are found.
1606
1607 \note strtok_P() is NOT reentrant. For a reentrant version of this
1608 function see strtok_rP().
1609 */
1610extern char *strtok_P(char *__s, const char * __delim);
1611
1612/** \ingroup avr_pgmspace
1613 \fn char *strtok_rP (char *string, const char *delim, char **last)
1614 \brief Parses string into tokens.
1615
1616 The strtok_rP() function parses \p string into tokens. The first call to
1617 strtok_rP() should have string as its first argument. Subsequent calls
1618 should have the first argument set to NULL. If a token ends with a
1619 delimiter, this delimiting character is overwritten with a '\\0' and a
1620 pointer to the next character is saved for the next call to strtok_rP().
1621 The delimiter string \p delim may be different for each call. \p last is
1622 a user allocated char* pointer. It must be the same while parsing the
1623 same string. strtok_rP() is a reentrant version of strtok_P().
1624
1625 The strtok_rP() function is similar to strtok_r() except that \p delim
1626 is pointer to a string in program space.
1627
1628 \returns The strtok_rP() function returns a pointer to the next token or
1629 NULL when no more tokens are found. */
1630extern char *strtok_rP(char *__s, const char * __delim, char **__last);
1631
1632/** \ingroup avr_pgmspace
1633 \fn size_t strlen_PF(uint_farptr_t s)
1634 \brief Obtain the length of a string
1635
1636 The strlen_PF() function is similar to strlen(), except that \e s is a
1637 far pointer to a string in program space.
1638
1639 \param s A far pointer to the string in flash
1640
1641 \returns The strlen_PF() function returns the number of characters in
1642 \e s. The contents of RAMPZ SFR are undefined when the function returns. */
1643extern size_t strlen_PF(uint_farptr_t src) __ATTR_CONST__; /* program memory can't change */
1644
1645/** \ingroup avr_pgmspace
1646 \fn size_t strnlen_PF(uint_farptr_t s, size_t len)
1647 \brief Determine the length of a fixed-size string
1648
1649 The strnlen_PF() function is similar to strnlen(), except that \e s is a
1650 far pointer to a string in program space.
1651
1652 \param s A far pointer to the string in Flash
1653 \param len The maximum number of length to return
1654
1655 \returns The strnlen_PF function returns strlen_P(\e s), if that is less
1656 than \e len, or \e len if there is no '\\0' character among the first \e
1657 len characters pointed to by \e s. The contents of RAMPZ SFR are
1658 undefined when the function returns. */
1659extern size_t strnlen_PF(uint_farptr_t src, size_t len) __ATTR_CONST__; /* program memory can't change */
1660
1661/** \ingroup avr_pgmspace
1662 \fn void *memcpy_PF(void *dest, uint_farptr_t src, size_t n)
1663 \brief Copy a memory block from flash to SRAM
1664
1665 The memcpy_PF() function is similar to memcpy(), except the data
1666 is copied from the program space and is addressed using a far pointer.
1667
1668 \param dest A pointer to the destination buffer
1669 \param src A far pointer to the origin of data in flash memory
1670 \param n The number of bytes to be copied
1671
1672 \returns The memcpy_PF() function returns a pointer to \e dst. The contents
1673 of RAMPZ SFR are undefined when the function returns. */
1674extern void *memcpy_PF(void *dest, uint_farptr_t src, size_t len);
1675
1676/** \ingroup avr_pgmspace
1677 \fn char *strcpy_PF(char *dst, uint_farptr_t src)
1678 \brief Duplicate a string
1679
1680 The strcpy_PF() function is similar to strcpy() except that \e src is a far
1681 pointer to a string in program space.
1682
1683 \param dst A pointer to the destination string in SRAM
1684 \param src A far pointer to the source string in Flash
1685
1686 \returns The strcpy_PF() function returns a pointer to the destination
1687 string \e dst. The contents of RAMPZ SFR are undefined when the funcion
1688 returns. */
1689extern char *strcpy_PF(char *dest, uint_farptr_t src);
1690
1691/** \ingroup avr_pgmspace
1692 \fn char *strncpy_PF(char *dst, uint_farptr_t src, size_t n)
1693 \brief Duplicate a string until a limited length
1694
1695 The strncpy_PF() function is similar to strcpy_PF() except that not more
1696 than \e n bytes of \e src are copied. Thus, if there is no null byte among
1697 the first \e n bytes of \e src, the result will not be null-terminated.
1698
1699 In the case where the length of \e src is less than that of \e n, the
1700 remainder of \e dst will be padded with nulls.
1701
1702 \param dst A pointer to the destination string in SRAM
1703 \param src A far pointer to the source string in Flash
1704 \param n The maximum number of bytes to copy
1705
1706 \returns The strncpy_PF() function returns a pointer to the destination
1707 string \e dst. The contents of RAMPZ SFR are undefined when the function
1708 returns. */
1709extern char *strncpy_PF(char *dest, uint_farptr_t src, size_t len);
1710
1711/** \ingroup avr_pgmspace
1712 \fn char *strcat_PF(char *dst, uint_farptr_t src)
1713 \brief Concatenates two strings
1714
1715 The strcat_PF() function is similar to strcat() except that the \e src
1716 string must be located in program space (flash) and is addressed using
1717 a far pointer
1718
1719 \param dst A pointer to the destination string in SRAM
1720 \param src A far pointer to the string to be appended in Flash
1721
1722 \returns The strcat_PF() function returns a pointer to the resulting
1723 string \e dst. The contents of RAMPZ SFR are undefined when the function
1724 returns */
1725extern char *strcat_PF(char *dest, uint_farptr_t src);
1726
1727/** \ingroup avr_pgmspace
1728 \fn size_t strlcat_PF(char *dst, uint_farptr_t src, size_t n)
1729 \brief Concatenate two strings
1730
1731 The strlcat_PF() function is similar to strlcat(), except that the \e src
1732 string must be located in program space (flash) and is addressed using
1733 a far pointer.
1734
1735 Appends src to string dst of size \e n (unlike strncat(), \e n is the
1736 full size of \e dst, not space left). At most \e n-1 characters
1737 will be copied. Always NULL terminates (unless \e n <= strlen(\e dst)).
1738
1739 \param dst A pointer to the destination string in SRAM
1740 \param src A far pointer to the source string in Flash
1741 \param n The total number of bytes allocated to the destination string
1742
1743 \returns The strlcat_PF() function returns strlen(\e src) + MIN(\e n,
1744 strlen(initial \e dst)). If retval >= \e n, truncation occurred. The
1745 contents of RAMPZ SFR are undefined when the funcion returns. */
1746extern size_t strlcat_PF(char *dst, uint_farptr_t src, size_t siz);
1747
1748/** \ingroup avr_pgmspace
1749 \fn char *strncat_PF(char *dst, uint_farptr_t src, size_t n)
1750 \brief Concatenate two strings
1751
1752 The strncat_PF() function is similar to strncat(), except that the \e src
1753 string must be located in program space (flash) and is addressed using a
1754 far pointer.
1755
1756 \param dst A pointer to the destination string in SRAM
1757 \param src A far pointer to the source string in Flash
1758 \param n The maximum number of bytes to append
1759
1760 \returns The strncat_PF() function returns a pointer to the resulting
1761 string \e dst. The contents of RAMPZ SFR are undefined when the function
1762 returns. */
1763extern char *strncat_PF(char *dest, uint_farptr_t src, size_t len);
1764
1765/** \ingroup avr_pgmspace
1766 \fn int strcmp_PF(const char *s1, uint_farptr_t s2)
1767 \brief Compares two strings
1768
1769 The strcmp_PF() function is similar to strcmp() except that \e s2 is a far
1770 pointer to a string in program space.
1771
1772 \param s1 A pointer to the first string in SRAM
1773 \param s2 A far pointer to the second string in Flash
1774
1775 \returns The strcmp_PF() function returns an integer less than, equal to,
1776 or greater than zero if \e s1 is found, respectively, to be less than, to
1777 match, or be greater than \e s2. The contents of RAMPZ SFR are undefined
1778 when the function returns. */
1779extern int strcmp_PF(const char *s1, uint_farptr_t s2) __ATTR_PURE__;
1780
1781/** \ingroup avr_pgmspace
1782 \fn int strncmp_PF(const char *s1, uint_farptr_t s2, size_t n)
1783 \brief Compare two strings with limited length
1784
1785 The strncmp_PF() function is similar to strcmp_PF() except it only
1786 compares the first (at most) \e n characters of \e s1 and \e s2.
1787
1788 \param s1 A pointer to the first string in SRAM
1789 \param s2 A far pointer to the second string in Flash
1790 \param n The maximum number of bytes to compare
1791
1792 \returns The strncmp_PF() function returns an integer less than, equal
1793 to, or greater than zero if \e s1 (or the first \e n bytes thereof) is found,
1794 respectively, to be less than, to match, or be greater than \e s2. The
1795 contents of RAMPZ SFR are undefined when the function returns. */
1796extern int strncmp_PF(const char *s1, uint_farptr_t s2, size_t n) __ATTR_PURE__;
1797
1798/** \ingroup avr_pgmspace
1799 \fn int strcasecmp_PF(const char *s1, uint_farptr_t s2)
1800 \brief Compare two strings ignoring case
1801
1802 The strcasecmp_PF() function compares the two strings \e s1 and \e s2, ignoring
1803 the case of the characters.
1804
1805 \param s1 A pointer to the first string in SRAM
1806 \param s2 A far pointer to the second string in Flash
1807
1808 \returns The strcasecmp_PF() function returns an integer less than, equal
1809 to, or greater than zero if \e s1 is found, respectively, to be less than, to
1810 match, or be greater than \e s2. The contents of RAMPZ SFR are undefined
1811 when the function returns. */
1812extern int strcasecmp_PF(const char *s1, uint_farptr_t s2) __ATTR_PURE__;
1813
1814/** \ingroup avr_pgmspace
1815 \fn int strncasecmp_PF(const char *s1, uint_farptr_t s2, size_t n)
1816 \brief Compare two strings ignoring case
1817
1818 The strncasecmp_PF() function is similar to strcasecmp_PF(), except it
1819 only compares the first \e n characters of \e s1 and the string in flash is
1820 addressed using a far pointer.
1821
1822 \param s1 A pointer to a string in SRAM
1823 \param s2 A far pointer to a string in Flash
1824 \param n The maximum number of bytes to compare
1825
1826 \returns The strncasecmp_PF() function returns an integer less than, equal
1827 to, or greater than zero if \e s1 (or the first \e n bytes thereof) is found,
1828 respectively, to be less than, to match, or be greater than \e s2. The
1829 contents of RAMPZ SFR are undefined when the function returns. */
1830extern int strncasecmp_PF(const char *s1, uint_farptr_t s2, size_t n) __ATTR_PURE__;
1831
1832/** \ingroup avr_pgmspace
1833 \fn uint_farptr_t strchr_PF(uint_farptr_t s, int val)
1834 \brief Locate character in far program space string.
1835
1836 The strchr_PF() function locates the first occurrence of \p val
1837 (converted to a char) in the string pointed to by \p s in far program
1838 space. The terminating null character is considered to be part of
1839 the string.
1840
1841 The strchr_PF() function is similar to strchr() except that \p s is
1842 a far pointer to a string in program space that's \e not \e required to be
1843 located in the lower 64 KiB block like it is the case for strchr_P().
1844
1845 \returns The strchr_PF() function returns a far pointer to the matched
1846 character or \c 0 if the character is not found. */
1847extern uint_farptr_t strchr_PF(uint_farptr_t, int __val) __ATTR_CONST__;
1848
1849/** \ingroup avr_pgmspace
1850 \fn char *strstr_PF(const char *s1, uint_farptr_t s2)
1851 \brief Locate a substring.
1852
1853 The strstr_PF() function finds the first occurrence of the substring \c s2
1854 in the string \c s1. The terminating '\\0' characters are not
1855 compared.
1856 The strstr_PF() function is similar to strstr() except that \c s2 is a
1857 far pointer to a string in program space.
1858
1859 \returns The strstr_PF() function returns a pointer to the beginning of the
1860 substring, or NULL if the substring is not found.
1861 If \c s2 points to a string of zero length, the function returns \c s1. The
1862 contents of RAMPZ SFR are undefined when the function returns. */
1863extern char *strstr_PF(const char *s1, uint_farptr_t s2);
1864
1865/** \ingroup avr_pgmspace
1866 \fn size_t strlcpy_PF(char *dst, uint_farptr_t src, size_t siz)
1867 \brief Copy a string from progmem to RAM.
1868
1869 Copy src to string dst of size siz. At most siz-1 characters will be
1870 copied. Always NULL terminates (unless siz == 0).
1871
1872 \returns The strlcpy_PF() function returns strlen(src). If retval >= siz,
1873 truncation occurred. The contents of RAMPZ SFR are undefined when the
1874 function returns. */
1875extern size_t strlcpy_PF(char *dst, uint_farptr_t src, size_t siz);
1876
1877/** \ingroup avr_pgmspace
1878 \fn int memcmp_PF(const void *s1, uint_farptr_t s2, size_t len)
1879 \brief Compare memory areas
1880
1881 The memcmp_PF() function compares the first \p len bytes of the memory
1882 areas \p s1 and flash \p s2. The comparision is performed using unsigned
1883 char operations. It is an equivalent of memcmp_P() function, except
1884 that it is capable working on all FLASH including the exteded area
1885 above 64kB.
1886
1887 \returns The memcmp_PF() function returns an integer less than, equal
1888 to, or greater than zero if the first \p len bytes of \p s1 is found,
1889 respectively, to be less than, to match, or be greater than the first
1890 \p len bytes of \p s2. */
1891extern int memcmp_PF(const void *, uint_farptr_t, size_t) __ATTR_PURE__;
1892
1893#ifdef __DOXYGEN__
1894/** \ingroup avr_pgmspace
1895 \fn size_t strlen_P(const char *src)
1896
1897 The strlen_P() function is similar to strlen(), except that src is a
1898 pointer to a string in program space.
1899
1900 \returns The strlen_P() function returns the number of characters in src.
1901
1902 \note strlen_P() is implemented as an inline function in the avr/pgmspace.h
1903 header file, which will check if the length of the string is a constant
1904 and known at compile time. If it is not known at compile time, the macro
1905 will issue a call to __strlen_P() which will then calculate the length
1906 of the string as normal.
1907*/
1908static inline size_t strlen_P(const char * s);
1909#else /* !DOXYGEN */
1910
1911#ifdef __AVR_TINY__
1912#define __strlen_P strlen
1913extern size_t strlen (const char*);
1914#else
1915extern size_t __strlen_P(const char *) __ATTR_CONST__; /* internal helper function */
1916#endif
1917
1918static __ATTR_ALWAYS_INLINE__ size_t strlen_P(const char * s);
1919size_t strlen_P(const char *s)
1920{
1921 return __builtin_constant_p(__builtin_strlen(s))
1922 ? __builtin_strlen(s) : __strlen_P(s);
1923}
1924#endif /* DOXYGEN */
1925
1926#ifdef __cplusplus
1927} // extern "C"
1928#endif
1929
1930#if defined(__cplusplus) && defined(__pgm_read_template__)
1931
1932/* Caveat: When this file is found via -isystem <path>, then some older
1933 avr-g++ versions come up with
1934
1935 error: template with C linkage
1936
1937 because the target description did not define NO_IMPLICIT_EXTERN_C. */
1938
1939template<typename __T, size_t>
1940struct __pgm_read_impl
1941{
1942 // A default implementaton for T's with a size not in { 1, 2, 3, 4, 8 }.
1943 // While this works, the performance is absolute scrap because GCC does
1944 // not handle objects well that don't fit in a register (i.e. avr-gcc
1945 // has no respective machine_mode).
1946 __T operator() (const __T *__addr) const
1947 {
1948 __T __res;
1949 memcpy_P (&__res, __addr, sizeof(__T));
1950 return __res;
1951 }
1952};
1953
1954template<typename __T>
1955struct __pgm_read_impl<__T, 1>
1956{
1957 __T operator() (const __T *__addr) const
1958 {
1959 __T __res; __LPM__1 (__res, __addr); return __res;
1960 }
1961};
1962
1963template<typename __T>
1964struct __pgm_read_impl<__T, 2>
1965{
1966 __T operator() (const __T *__addr) const
1967 {
1968 __T __res; __LPM__2 (__res, __addr); return __res;
1969 }
1970};
1971
1972template<typename __T>
1973struct __pgm_read_impl<__T, 3>
1974{
1975 __T operator() (const __T *__addr) const
1976 {
1977 __T __res; __LPM__3 (__res, __addr); return __res;
1978 }
1979};
1980
1981template<typename __T>
1982struct __pgm_read_impl<__T, 4>
1983{
1984 __T operator() (const __T *__addr) const
1985 {
1986 __T __res; __LPM__4 (__res, __addr); return __res;
1987 }
1988};
1989
1990template<typename __T>
1991struct __pgm_read_impl<__T, 8>
1992{
1993 __T operator() (const __T *__addr) const
1994 {
1995 __T __res; __LPM__8 (__res, __addr); return __res;
1996 }
1997};
1998
1999template<typename __T>
2000__T pgm_read (const __T *__addr)
2001{
2002 return __pgm_read_impl<__T, sizeof(__T)>() (__addr);
2003}
2004
2005//////////////////////////////////////////////////////////
2006
2007template<typename __T, size_t>
2008struct __pgm_read_far_impl
2009{
2010 // A default implementaton for T's with a size not in { 1, 2, 3, 4, 8 }.
2011 // While this works, the performance is absolute scrap because GCC does
2012 // not handle objects well that don't fit in a register (i.e. avr-gcc
2013 // has no respective machine_mode).
2014 __T operator() (const __T *__addr) const
2015 {
2016 __T __res;
2017 memcpy_PF (&__res, __addr, sizeof(__T));
2018 return __res;
2019 }
2020};
2021
2022template<typename __T>
2023struct __pgm_read_far_impl<__T, 1>
2024{
2025 __T operator() (uint_farptr_t __addr) const
2026 {
2027 __T __res; __ELPM__1 (__res, __addr, __T); return __res;
2028 }
2029};
2030
2031template<typename __T>
2032struct __pgm_read_far_impl<__T, 2>
2033{
2034 __T operator() (uint_farptr_t __addr) const
2035 {
2036 __T __res; __ELPM__2 (__res, __addr, __T); return __res;
2037 }
2038};
2039
2040template<typename __T>
2041struct __pgm_read_far_impl<__T, 3>
2042{
2043 __T operator() (uint_farptr_t __addr) const
2044 {
2045 __T __res; __ELPM__3 (__res, __addr, __T); return __res;
2046 }
2047};
2048
2049template<typename __T>
2050struct __pgm_read_far_impl<__T, 4>
2051{
2052 __T operator() (uint_farptr_t __addr) const
2053 {
2054 __T __res; __ELPM__4 (__res, __addr, __T); return __res;
2055 }
2056};
2057
2058template<typename __T>
2059struct __pgm_read_far_impl<__T, 8>
2060{
2061 __T operator() (uint_farptr_t __addr) const
2062 {
2063 __T __res; __ELPM__8 (__res, __addr, __T); return __res;
2064 }
2065};
2066
2067template<typename __T>
2068__T pgm_read_far (uint_farptr_t __addr)
2069{
2070 return __pgm_read_far_impl<__T, sizeof(__T)>() (__addr);
2071}
2072
2073#endif /* C++ */
2074
2075#ifdef __DOXYGEN__
2076/** \ingroup avr_pgmspace
2077 \fn T pgm_read<T> (const T *addr)
2078
2079 Read an object of type \c T from program memory address \p addr and
2080 return it.
2081 This template is only available when macro \c __pgm_read_template__
2082 is defined. */
2083template<typename T>
2084T pgm_read<T> (const T *addr);
2085
2086/** \ingroup avr_pgmspace
2087 \fn T pgm_read_far<T> (uint_farptr_t addr)
2088
2089 Read an object of type \c T from program memory address \p addr and
2090 return it.
2091 This template is only available when macro \c __pgm_read_template__
2092 is defined. */
2093template<typename T>
2095#endif /* DOXYGEN */
2096
2097#endif /* __PGMSPACE_H_ */
uint32_t uint_farptr_t
Definition: inttypes.h:83
static long double pgm_read_long_double(const long double *__addr)
static uint16_t pgm_read_u16(const uint16_t *__addr)
static unsigned pgm_read_unsigned_far(uint_farptr_t __addr)
char * strstr_PF(const char *s1, uint_farptr_t s2)
Locate a substring.
static uint16_t pgm_read_u16_far(uint_farptr_t __addr)
const char * strchrnul_P(const char *, int __val)
static signed int pgm_read_signed_int_far(uint_farptr_t __addr)
static signed pgm_read_signed_far(uint_farptr_t __addr)
const char * strchr_P(const char *, int __val)
Locate character in program space string.
int strcmp_PF(const char *s1, uint_farptr_t s2)
Compares two strings.
void * memcpy_PF(void *dest, uint_farptr_t src, size_t len)
Copy a memory block from flash to SRAM.
char * strsep_P(char **__sp, const char *__delim)
Parse a string into tokens.
static uint32_t pgm_read_u32_far(uint_farptr_t __addr)
int strcmp_P(const char *, const char *)
char * strcasestr_P(const char *, const char *)
static unsigned char pgm_read_unsigned_char_far(uint_farptr_t __addr)
static int32_t pgm_read_i32(const int32_t *__addr)
char * strncpy_P(char *, const char *, size_t)
static int64_t pgm_read_i64(const int64_t *__addr)
static __int24 pgm_read_i24(const __int24 *__addr)
static signed int pgm_read_signed_int(const signed int *__addr)
static signed char pgm_read_signed_char(const signed char *__addr)
static int8_t pgm_read_i8_far(uint_farptr_t __addr)
static long long pgm_read_long_long_far(uint_farptr_t __addr)
static __uint24 pgm_read_u24_far(uint_farptr_t __addr)
int strcasecmp_P(const char *, const char *)
Compare two strings ignoring case.
size_t strcspn_P(const char *__s, const char *__reject)
static int pgm_read_int(const int *__addr)
static unsigned short pgm_read_unsigned_short(const unsigned short *__addr)
char * strpbrk_P(const char *__s, const char *__accept)
static float pgm_read_float_far(uint_farptr_t __addr)
static unsigned long long pgm_read_unsigned_long_long(const unsigned long long *__addr)
const void * memchr_P(const void *, int __val, size_t __len)
Scan flash memory for a character.
void * memccpy_P(void *, const void *, int __val, size_t)
static uint8_t pgm_read_u8(const uint8_t *__addr)
char * strtok_rP(char *__s, const char *__delim, char **__last)
Parses string into tokens.
char * strncpy_PF(char *dest, uint_farptr_t src, size_t len)
Duplicate a string until a limited length.
T pgm_read< T >(const T *addr)
void * memmem_P(const void *, size_t, const void *, size_t)
size_t strlen_PF(uint_farptr_t src)
Obtain the length of a string.
static int16_t pgm_read_i16(const int16_t *__addr)
static float pgm_read_float(const float *__addr)
size_t strnlen_P(const char *, size_t)
Determine the length of a fixed-size string.
char * strcpy_P(char *, const char *)
static uint8_t pgm_read_u8_far(uint_farptr_t __addr)
static char pgm_read_char(const char *__addr)
char * strcat_P(char *, const char *)
int strncasecmp_P(const char *, const char *, size_t)
Compare two strings ignoring case.
size_t strspn_P(const char *__s, const char *__accept)
size_t strlcpy_PF(char *dst, uint_farptr_t src, size_t siz)
Copy a string from progmem to RAM.
static uint64_t pgm_read_u64_far(uint_farptr_t __addr)
int memcmp_PF(const void *, uint_farptr_t, size_t)
Compare memory areas.
const char * strrchr_P(const char *, int __val)
Locate character in string.
static double pgm_read_double_far(uint_farptr_t __addr)
static uint64_t pgm_read_u64(const uint64_t *__addr)
static double pgm_read_double(const double *__addr)
static char pgm_read_char_far(uint_farptr_t __addr)
int strcasecmp_PF(const char *s1, uint_farptr_t s2)
Compare two strings ignoring case.
size_t strnlen_PF(uint_farptr_t src, size_t len)
Determine the length of a fixed-size string.
static unsigned long pgm_read_unsigned_long_far(uint_farptr_t __addr)
static long pgm_read_long(const long *__addr)
static int32_t pgm_read_i32_far(uint_farptr_t __addr)
size_t strlcat_P(char *, const char *, size_t)
Concatenate two strings.
static unsigned short pgm_read_unsigned_short_far(uint_farptr_t __addr)
char * strncat_P(char *, const char *, size_t)
Concatenate two strings.
static int8_t pgm_read_i8(const int8_t *__addr)
const void * memrchr_P(const void *, int __val, size_t __len)
static int pgm_read_int_far(uint_farptr_t __addr)
char * strncat_PF(char *dest, uint_farptr_t src, size_t len)
Concatenate two strings.
char * strcat_PF(char *dest, uint_farptr_t src)
Concatenates two strings.
T pgm_read_far< T >(uint_farptr_t addr)
static short pgm_read_short(const short *__addr)
static int64_t pgm_read_i64_far(uint_farptr_t __addr)
char * strtok_P(char *__s, const char *__delim)
Parses the string into tokens.
static int16_t pgm_read_i16_far(uint_farptr_t __addr)
static unsigned long long pgm_read_unsigned_long_long_far(uint_farptr_t __addr)
int strncmp_P(const char *, const char *, size_t)
static unsigned pgm_read_unsigned(const unsigned *__addr)
static long long pgm_read_long_long(const long long *__addr)
char * strstr_P(const char *, const char *)
Locate a substring.
int memcmp_P(const void *, const void *, size_t)
Compare memory areas.
static signed char pgm_read_signed_char_far(uint_farptr_t __addr)
static unsigned long pgm_read_unsigned_long(const unsigned long *__addr)
size_t strlcpy_P(char *, const char *, size_t)
Copy a string from progmem to RAM.
int strncasecmp_PF(const char *s1, uint_farptr_t s2, size_t n)
Compare two strings ignoring case.
char * strcpy_PF(char *dest, uint_farptr_t src)
Duplicate a string.
int strncmp_PF(const char *s1, uint_farptr_t s2, size_t n)
Compare two strings with limited length.
static short pgm_read_short_far(uint_farptr_t __addr)
void * memcpy_P(void *, const void *, size_t)
static unsigned int pgm_read_unsigned_int_far(uint_farptr_t __addr)
static unsigned char pgm_read_unsigned_char(const unsigned char *__addr)
static size_t strlen_P(const char *s)
static long pgm_read_long_far(uint_farptr_t __addr)
static __int24 pgm_read_i24_far(uint_farptr_t __addr)
uint_farptr_t strchr_PF(uint_farptr_t, int __val)
Locate character in far program space string.
static signed pgm_read_signed(const signed *__addr)
static uint32_t pgm_read_u32(const uint32_t *__addr)
static __uint24 pgm_read_u24(const __uint24 *__addr)
static long double pgm_read_long_double_far(uint_farptr_t __addr)
size_t strlcat_PF(char *dst, uint_farptr_t src, size_t siz)
Concatenate two strings.
static unsigned int pgm_read_unsigned_int(const unsigned int *__addr)
unsigned int uint16_t
Definition: stdint.h:93
unsigned long int uint32_t
Definition: stdint.h:103
signed long long int int64_t
Definition: stdint.h:110
signed int int16_t
Definition: stdint.h:88
unsigned char uint8_t
Definition: stdint.h:83
unsigned long long int uint64_t
Definition: stdint.h:117
signed long int int32_t
Definition: stdint.h:98
signed char int8_t
Definition: stdint.h:78
size_t strlen(const char *)
Calculate the length of a string.