AVR-LibC  2.3.0git
Standard C library for AVR-GCC
 

AVR-LibC Documen­tation

AVR-LibC Development Pages

Main Page

User Manual

Library Refe­rence

FAQ

Example Projects

File List

Index

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