1
+ /*
2
+ pgmspace.cpp - PROGMEM stubs for host-side tests
3
+ Copyright © 2016 Ivan Grokhotkov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+ */
1
15
#ifndef __PGMSPACE_H_
2
16
#define __PGMSPACE_H_
3
17
7
21
#define PROGMEM
8
22
#define PGM_P const char *
9
23
#define PGM_VOID_P const void *
10
- #define PSTR (s ) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}) )
24
+ #define PSTR (s ) (s )
11
25
12
26
13
27
#define _SFR_BYTE (n ) (n)
@@ -22,47 +36,35 @@ typedef uint16_t prog_uint16_t;
22
36
typedef int32_t prog_int32_t ;
23
37
typedef uint32_t prog_uint32_t ;
24
38
25
- #define SIZE_IRRELEVANT 0x7fffffff
39
+ #define memcmp_P memcmp
40
+ #define memccpy_P memccpy
41
+ #define memmem_P memmem
42
+ #define memcpy_P memcpy
26
43
44
+ #define strncpy_P strncpy
45
+ #define strcpy_P strcpy
27
46
28
- int memcmp_P (const void * buf1 , PGM_VOID_P buf2P , size_t size );
29
- // memccpy_P is only valid when used with pointers to 8bit data, due to size aligned pointers
30
- // and endianess of the values greater than 8bit, matching c may return invalid aligned pointers
31
- void * memccpy_P (void * dest , PGM_VOID_P src , int c , size_t count );
32
- void * memmem_P (const void * buf , size_t bufSize , PGM_VOID_P findP , size_t findPSize );
33
- void * memcpy_P (void * dest , PGM_VOID_P src , size_t count );
47
+ #define strncat_P strncat
48
+ #define strcat_P strcat
34
49
35
- #define strncpy_P ( dest , src , size ) strncpy(dest, src, size)
36
- #define strcpy_P ( dest , src ) strncpy_P((dest), (src), SIZE_IRRELEVANT)
50
+ #define strncmp_P strncmp
51
+ #define strcmp_P strcmp
37
52
38
- #define strncat_P ( dest , src , size ) strncat(dest, src, size)
39
- #define strcat_P ( dest , src ) strncat_P((dest), (src), SIZE_IRRELEVANT)
53
+ #define strncasecmp_P strncasecmp
54
+ #define strcasecmp_P strcasecmp
40
55
41
- #define strncmp_P ( str1 , str2P , size ) strncmp(str1, str2P, size)
42
- #define strcmp_P ( str1 , str2P ) strncmp_P((str1), (str2P), SIZE_IRRELEVANT)
56
+ #define strnlen_P strnlen
57
+ #define strlen_P strlen
43
58
44
- #define strncasecmp_P (str1 , str2P , size ) strncasecmp(str1, str2P, size)
45
- #define strcasecmp_P (str1 , str2P ) strncasecmp_P((str1), (str2P), SIZE_IRRELEVANT)
59
+ #define printf_P printf
60
+ #define sprintf_P sprintf
61
+ #define snprintf_P snprintf
62
+ #define vsnprintf_P vsnprintf
46
63
47
- #define strnlen_P (s , size ) strnlen(s, size)
48
- #define strlen_P (strP ) strnlen_P((strP), SIZE_IRRELEVANT)
49
-
50
- #define printf_P (formatP , ...) printf(formatP, __VA_ARGS__)
51
- #define sprintf_P (str , formatP , ...) sprintf(str, formatP, __VA_ARGS__)
52
- #define snprintf_P (str , strSize , formatP , ...) snprintf(str, strSize, formatP, __VA_ARGS__)
53
- #define vsnprintf_P (str , strSize , formatP , ap ) vsnprintf(str, strSize, formatP, ap)
54
-
55
- // flash memory must be read using 32 bit aligned addresses else a processor
56
- // exception will be triggered
57
- // order within the 32 bit values are
58
- // --------------
59
- // b3, b2, b1, b0
60
- // w1, w0
61
-
62
- #define pgm_read_byte (x ) (*reinterpret_cast<const uint8_t*>(x))
63
- #define pgm_read_word (x ) (*reinterpret_cast<const uint16_t*>(x))
64
- #define pgm_read_float (x ) (*reinterpret_cast<const float*>(x))
65
- #define pgm_read_dword (x ) (*reinterpret_cast<const uint32_t*>(x))
64
+ #define pgm_read_byte (addr ) (*reinterpret_cast<const uint8_t*>(addr))
65
+ #define pgm_read_word (addr ) (*reinterpret_cast<const uint16_t*>(addr))
66
+ #define pgm_read_float (addr ) (*reinterpret_cast<const float*>(addr))
67
+ #define pgm_read_dword (addr ) (*reinterpret_cast<const uint32_t*>(addr))
66
68
67
69
#define pgm_read_byte_near (addr ) pgm_read_byte(addr)
68
70
#define pgm_read_word_near (addr ) pgm_read_word(addr)
0 commit comments