AVR-LibC  2.3.0
Standard C library for AVR-GCC
 

AVR-LibC Manual

AVR-LibC Sources

Main Page

User Manual

Lib­rary Refe­rence

FAQ

Exam­ple Pro­jects

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