Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

pgmspace.h 5.5KB

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