数码之家

 找回密码
 立即注册
搜索
查看: 150|回复: 3

[Arduino] 求大神给我一份avr/pgmspace.h库文件,深表感谢。

[复制链接]
发表于 2024-3-4 17:11:54 来自手机浏览器 | 显示全部楼层 |阅读模式

爱科技、爱创意、爱折腾、爱极致,我们都是技术控

您需要 登录 才可以下载或查看,没有账号?立即注册

x
小白想玩玩ws2812点阵。需要avr/pgmspace.h这个库文件,找好久没找到。那位大神有帮个忙给我发一份,感谢感谢。
发表于 2024-3-5 16:36:20 | 显示全部楼层
怎么会缺这个文件呢?这个应该是安装了库会正常自带的,附件给你发了一个。希望你就缺这一个文件,别的都齐啊。

pgmspace.rar

10.67 KB, 下载次数: 0, 下载积分: 家元 -55

回复 支持 反对

使用道具 举报

发表于 2024-3-5 17:18:29 | 显示全部楼层
  1. /* Copyright (c) 2002 - 2007  Marek Michalkiewicz
  2.    All rights reserved.

  3.    Redistribution and use in source and binary forms, with or without
  4.    modification, are permitted provided that the following conditions are met:

  5.    * Redistributions of source code must retain the above copyright
  6.      notice, this list of conditions and the following disclaimer.
  7.    * Redistributions in binary form must reproduce the above copyright
  8.      notice, this list of conditions and the following disclaimer in
  9.      the documentation and/or other materials provided with the
  10.      distribution.
  11.    * Neither the name of the copyright holders nor the names of
  12.      contributors may be used to endorse or promote products derived
  13.      from this software without specific prior written permission.

  14.   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15.   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16.   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17.   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18.   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19.   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20.   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21.   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22.   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23.   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24.   POSSIBILITY OF SUCH DAMAGE. */

  25. /* $Id: pgmspace.h,v 1.40.2.5 2009/11/15 06:42:40 dmix Exp $ */

  26. /*
  27.    pgmspace.h

  28.    Contributors:
  29.      Created by Marek Michalkiewicz <marekm@linux.org.pl>
  30.      Eric B. Weddington <eric@ecentral.com>
  31.      Wolfgang Haidinger <wh@vmars.tuwien.ac.at> (pgm_read_dword())
  32.      Ivanov Anton <anton@arc.com.ru> (pgm_read_float())
  33. */

  34. /** \file */
  35. /** \defgroup avr_pgmspace <avr/pgmspace.h>: Program Space Utilities
  36.     \code
  37.     #include <avr/io.h>
  38.     #include <avr/pgmspace.h>
  39.     \endcode

  40.     The functions in this module provide interfaces for a program to access
  41.     data stored in program space (flash memory) of the device.  In order to
  42.     use these functions, the target device must support either the \c LPM or
  43.     \c ELPM instructions.

  44.     \note These functions are an attempt to provide some compatibility with
  45.     header files that come with IAR C, to make porting applications between
  46.     different compilers easier.  This is not 100% compatibility though (GCC
  47.     does not have full support for multiple address spaces yet).

  48.     \note If you are working with strings which are completely based in ram,
  49.     use the standard string functions described in \ref avr_string.

  50.     \note If possible, put your constant tables in the lower 64 KB and use
  51.     pgm_read_byte_near() or pgm_read_word_near() instead of
  52.     pgm_read_byte_far() or pgm_read_word_far() since it is more efficient that
  53.     way, and you can still use the upper 64K for executable code.
  54.     All functions that are suffixed with a \c _P \e require their
  55.     arguments to be in the lower 64 KB of the flash ROM, as they do
  56.     not use ELPM instructions.  This is normally not a big concern as
  57.     the linker setup arranges any program space constants declared
  58.     using the macros from this header file so they are placed right after
  59.     the interrupt vectors, and in front of any executable code.  However,
  60.     it can become a problem if there are too many of these constants, or
  61.     for bootloaders on devices with more than 64 KB of ROM.
  62.     <em>All these functions will not work in that situation.</em>
  63. */

  64. #ifndef __PGMSPACE_H_
  65. #define __PGMSPACE_H_ 1

  66. #define __need_size_t
  67. #include <inttypes.h>
  68. #include <stddef.h>
  69. #include <avr/io.h>

  70. #ifndef __ATTR_CONST__
  71. #define __ATTR_CONST__ __attribute__((__const__))
  72. #endif

  73. #ifndef __ATTR_PROGMEM__
  74. #define __ATTR_PROGMEM__ __attribute__((__progmem__))
  75. #endif

  76. #ifndef __ATTR_PURE__
  77. #define __ATTR_PURE__ __attribute__((__pure__))
  78. #endif

  79. /**
  80.    \ingroup avr_pgmspace
  81.    \def PROGMEM

  82.    Attribute to use in order to declare an object being located in
  83.    flash ROM.
  84. */
  85. #define PROGMEM __ATTR_PROGMEM__

  86. #ifdef __cplusplus
  87. extern "C" {
  88. #endif

  89. #if defined(__DOXYGEN__)
  90. /*
  91. * Doxygen doesn't grok the appended attribute syntax of
  92. * GCC, and confuses the typedefs with function decls, so
  93. * supply a doxygen-friendly view.
  94. */
  95. /**
  96.    \ingroup avr_pgmspace
  97.    \typedef prog_void

  98.    Type of a "void" object located in flash ROM.  Does not make much
  99.    sense by itself, but can be used to declare a "void *" object in
  100.    flash ROM.
  101. */
  102. typedef void PROGMEM prog_void;
  103. /**
  104.    \ingroup avr_pgmspace
  105.    \typedef prog_char

  106.    Type of a "char" object located in flash ROM.
  107. */
  108. typedef char PROGMEM prog_char;

  109. /**
  110.    \ingroup avr_pgmspace
  111.    \typedef prog_uchar

  112.    Type of an "unsigned char" object located in flash ROM.
  113. */
  114. typedef unsigned char PROGMEM prog_uchar;


  115. /**
  116.    \ingroup avr_pgmspace
  117.    \typedef prog_int8_t

  118.    Type of an "int8_t" object located in flash ROM.
  119. */
  120. typedef int8_t PROGMEM prog_int8_t;

  121. /**
  122.    \ingroup avr_pgmspace
  123.    \typedef prog_uint8_t

  124.    Type of an "uint8_t" object located in flash ROM.
  125. */
  126. typedef uint8_t PROGMEM prog_uint8_t;

  127. /**
  128.    \ingroup avr_pgmspace
  129.    \typedef prog_int16_t

  130.    Type of an "int16_t" object located in flash ROM.
  131. */
  132. typedef int16_t PROGMEM prog_int16_t;

  133. /**
  134.    \ingroup avr_pgmspace
  135.    \typedef prog_uint16_t

  136.    Type of an "uint16_t" object located in flash ROM.
  137. */
  138. typedef uint16_t PROGMEM prog_uint16_t;

  139. /**
  140.    \ingroup avr_pgmspace
  141.    \typedef prog_int32_t

  142.    Type of an "int32_t" object located in flash ROM.
  143. */
  144. typedef int32_t PROGMEM prog_int32_t;

  145. /**
  146.    \ingroup avr_pgmspace
  147.    \typedef prog_uint32_t

  148.    Type of an "uint32_t" object located in flash ROM.
  149. */
  150. typedef uint32_t PROGMEM prog_uint32_t;

  151. /**
  152.    \ingroup avr_pgmspace
  153.    \typedef prog_int64_t

  154.    Type of an "int64_t" object located in flash ROM.

  155.    \note This type is not available when the compiler
  156.    option -mint8 is in effect.
  157. */
  158. typedef int64_t PROGMEM prog_int64_t;

  159. /**
  160.    \ingroup avr_pgmspace
  161.    \typedef prog_uint64_t

  162.    Type of an "uint64_t" object located in flash ROM.

  163.    \note This type is not available when the compiler
  164.    option -mint8 is in effect.
  165. */
  166. typedef uint64_t PROGMEM prog_uint64_t;
  167. #else  /* !DOXYGEN */
  168. typedef void prog_void PROGMEM;
  169. typedef char prog_char PROGMEM;
  170. typedef unsigned char prog_uchar PROGMEM;

  171. typedef int8_t    prog_int8_t   PROGMEM;
  172. typedef uint8_t   prog_uint8_t  PROGMEM;
  173. typedef int16_t   prog_int16_t  PROGMEM;
  174. typedef uint16_t  prog_uint16_t PROGMEM;
  175. typedef int32_t   prog_int32_t  PROGMEM;
  176. typedef uint32_t  prog_uint32_t PROGMEM;
  177. #if !__USING_MINT8
  178. typedef int64_t   prog_int64_t  PROGMEM;
  179. typedef uint64_t  prog_uint64_t PROGMEM;
  180. #endif
  181. #endif /* defined(__DOXYGEN__) */

  182. /* Although in C, we can get away with just using __c, it does not work in
  183.    C++. We need to use &__c[0] to avoid the compiler puking. Dave Hylands
  184.    explaned it thusly,

  185.      Let's suppose that we use PSTR("Test"). In this case, the type returned
  186.      by __c is a prog_char[5] and not a prog_char *. While these are
  187.      compatible, they aren't the same thing (especially in C++). The type
  188.      returned by &__c[0] is a prog_char *, which explains why it works
  189.      fine. */

  190. #if defined(__DOXYGEN__)
  191. /*
  192. * The #define below is just a dummy that serves documentation
  193. * purposes only.
  194. */
  195. /** \ingroup avr_pgmspace
  196.     \def PSTR(s)

  197.     Used to declare a static pointer to a string in program space. */
  198. # define PSTR(s) ((const PROGMEM char *)(s))
  199. #else  /* !DOXYGEN */
  200. /* The real thing. */
  201. # define PSTR(s) (__extension__({static char __c[] PROGMEM = (s); &__c[0];}))
  202. #endif /* DOXYGEN */

  203. #define __LPM_classic__(addr)   \
  204. (__extension__({                \
  205.     uint16_t __addr16 = (uint16_t)(addr); \
  206.     uint8_t __result;           \
  207.     __asm__                     \
  208.     (                           \
  209.         "lpm" "\n\t"            \
  210.         "mov %0, r0" "\n\t"     \
  211.         : "=r" (__result)       \
  212.         : "z" (__addr16)        \
  213.         : "r0"                  \
  214.     );                          \
  215.     __result;                   \
  216. }))

  217. #define __LPM_enhanced__(addr)  \
  218. (__extension__({                \
  219.     uint16_t __addr16 = (uint16_t)(addr); \
  220.     uint8_t __result;           \
  221.     __asm__                     \
  222.     (                           \
  223.         "lpm %0, Z" "\n\t"      \
  224.         : "=r" (__result)       \
  225.         : "z" (__addr16)        \
  226.     );                          \
  227.     __result;                   \
  228. }))

  229. #define __LPM_word_classic__(addr)          \
  230. (__extension__({                            \
  231.     uint16_t __addr16 = (uint16_t)(addr);   \
  232.     uint16_t __result;                      \
  233.     __asm__                                 \
  234.     (                                       \
  235.         "lpm"           "\n\t"              \
  236.         "mov %A0, r0"   "\n\t"              \
  237.         "adiw r30, 1"   "\n\t"              \
  238.         "lpm"           "\n\t"              \
  239.         "mov %B0, r0"   "\n\t"              \
  240.         : "=r" (__result), "=z" (__addr16)  \
  241.         : "1" (__addr16)                    \
  242.         : "r0"                              \
  243.     );                                      \
  244.     __result;                               \
  245. }))

  246. #define __LPM_word_enhanced__(addr)         \
  247. (__extension__({                            \
  248.     uint16_t __addr16 = (uint16_t)(addr);   \
  249.     uint16_t __result;                      \
  250.     __asm__                                 \
  251.     (                                       \
  252.         "lpm %A0, Z+"   "\n\t"              \
  253.         "lpm %B0, Z"    "\n\t"              \
  254.         : "=r" (__result), "=z" (__addr16)  \
  255.         : "1" (__addr16)                    \
  256.     );                                      \
  257.     __result;                               \
  258. }))

  259. #define __LPM_dword_classic__(addr)         \
  260. (__extension__({                            \
  261.     uint16_t __addr16 = (uint16_t)(addr);   \
  262.     uint32_t __result;                      \
  263.     __asm__                                 \
  264.     (                                       \
  265.         "lpm"           "\n\t"              \
  266.         "mov %A0, r0"   "\n\t"              \
  267.         "adiw r30, 1"   "\n\t"              \
  268.         "lpm"           "\n\t"              \
  269.         "mov %B0, r0"   "\n\t"              \
  270.         "adiw r30, 1"   "\n\t"              \
  271.         "lpm"           "\n\t"              \
  272.         "mov %C0, r0"   "\n\t"              \
  273.         "adiw r30, 1"   "\n\t"              \
  274.         "lpm"           "\n\t"              \
  275.         "mov %D0, r0"   "\n\t"              \
  276.         : "=r" (__result), "=z" (__addr16)  \
  277.         : "1" (__addr16)                    \
  278.         : "r0"                              \
  279.     );                                      \
  280.     __result;                               \
  281. }))

  282. #define __LPM_dword_enhanced__(addr)        \
  283. (__extension__({                            \
  284.     uint16_t __addr16 = (uint16_t)(addr);   \
  285.     uint32_t __result;                      \
  286.     __asm__                                 \
  287.     (                                       \
  288.         "lpm %A0, Z+"   "\n\t"              \
  289.         "lpm %B0, Z+"   "\n\t"              \
  290.         "lpm %C0, Z+"   "\n\t"              \
  291.         "lpm %D0, Z"    "\n\t"              \
  292.         : "=r" (__result), "=z" (__addr16)  \
  293.         : "1" (__addr16)                    \
  294.     );                                      \
  295.     __result;                               \
  296. }))

  297. #define __LPM_float_classic__(addr)         \
  298. (__extension__({                            \
  299.     uint16_t __addr16 = (uint16_t)(addr);   \
  300.     float __result;                         \
  301.     __asm__                                 \
  302.     (                                       \
  303.         "lpm"           "\n\t"              \
  304.         "mov %A0, r0"   "\n\t"              \
  305.         "adiw r30, 1"   "\n\t"              \
  306.         "lpm"           "\n\t"              \
  307.         "mov %B0, r0"   "\n\t"              \
  308.         "adiw r30, 1"   "\n\t"              \
  309.         "lpm"           "\n\t"              \
  310.         "mov %C0, r0"   "\n\t"              \
  311.         "adiw r30, 1"   "\n\t"              \
  312.         "lpm"           "\n\t"              \
  313.         "mov %D0, r0"   "\n\t"              \
  314.         : "=r" (__result), "=z" (__addr16)  \
  315.         : "1" (__addr16)                    \
  316.         : "r0"                              \
  317.     );                                      \
  318.     __result;                               \
  319. }))

  320. #define __LPM_float_enhanced__(addr)        \
  321. (__extension__({                            \
  322.     uint16_t __addr16 = (uint16_t)(addr);   \
  323.     float __result;                         \
  324.     __asm__                                 \
  325.     (                                       \
  326.         "lpm %A0, Z+"   "\n\t"              \
  327.         "lpm %B0, Z+"   "\n\t"              \
  328.         "lpm %C0, Z+"   "\n\t"              \
  329.         "lpm %D0, Z"    "\n\t"              \
  330.         : "=r" (__result), "=z" (__addr16)  \
  331.         : "1" (__addr16)                    \
  332.     );                                      \
  333.     __result;                               \
  334. }))

  335. #if defined (__AVR_HAVE_LPMX__)
  336. #define __LPM(addr)         __LPM_enhanced__(addr)
  337. #define __LPM_word(addr)    __LPM_word_enhanced__(addr)
  338. #define __LPM_dword(addr)   __LPM_dword_enhanced__(addr)
  339. #define __LPM_float(addr)   __LPM_float_enhanced__(addr)
  340. #else
  341. #define __LPM(addr)         __LPM_classic__(addr)
  342. #define __LPM_word(addr)    __LPM_word_classic__(addr)
  343. #define __LPM_dword(addr)   __LPM_dword_classic__(addr)
  344. #define __LPM_float(addr)   __LPM_float_classic__(addr)
  345. #endif

  346. /** \ingroup avr_pgmspace
  347.     \def pgm_read_byte_near(address_short)
  348.     Read a byte from the program space with a 16-bit (near) address.
  349.     \note The address is a byte address.
  350.     The address is in the program space. */

  351. #define pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short))

  352. /** \ingroup avr_pgmspace
  353.     \def pgm_read_word_near(address_short)
  354.     Read a word from the program space with a 16-bit (near) address.
  355.     \note The address is a byte address.
  356.     The address is in the program space. */

  357. #define pgm_read_word_near(address_short) __LPM_word((uint16_t)(address_short))

  358. /** \ingroup avr_pgmspace
  359.     \def pgm_read_dword_near(address_short)
  360.     Read a double word from the program space with a 16-bit (near) address.
  361.     \note The address is a byte address.
  362.     The address is in the program space. */

  363. #define pgm_read_dword_near(address_short) \
  364.     __LPM_dword((uint16_t)(address_short))

  365. /** \ingroup avr_pgmspace
  366.     \def pgm_read_float_near(address_short)
  367.     Read a float from the program space with a 16-bit (near) address.
  368.     \note The address is a byte address.
  369.     The address is in the program space. */

  370. #define pgm_read_float_near(address_short) \
  371.     __LPM_float((uint16_t)(address_short))

  372. #if defined(RAMPZ) || defined(__DOXYGEN__)

  373. /* Only for devices with more than 64K of program memory.
  374.    RAMPZ must be defined (see iom103.h, iom128.h).
  375. */

  376. /* The classic functions are needed for ATmega103. */

  377. #define __ELPM_classic__(addr)      \
  378. (__extension__({                    \
  379.     uint32_t __addr32 = (uint32_t)(addr); \
  380.     uint8_t __result;               \
  381.     __asm__                         \
  382.     (                               \
  383.         "out %2, %C1" "\n\t"        \
  384.         "mov r31, %B1" "\n\t"       \
  385.         "mov r30, %A1" "\n\t"       \
  386.         "elpm" "\n\t"               \
  387.         "mov %0, r0" "\n\t"         \
  388.         : "=r" (__result)           \
  389.         : "r" (__addr32),           \
  390.           "I" (_SFR_IO_ADDR(RAMPZ)) \
  391.         : "r0", "r30", "r31"        \
  392.     );                              \
  393.     __result;                       \
  394. }))

  395. #define __ELPM_enhanced__(addr)     \
  396. (__extension__({                    \
  397.     uint32_t __addr32 = (uint32_t)(addr); \
  398.     uint8_t __result;               \
  399.     __asm__                         \
  400.     (                               \
  401.         "out %2, %C1" "\n\t"        \
  402.         "movw r30, %1" "\n\t"       \
  403.         "elpm %0, Z+" "\n\t"        \
  404.         : "=r" (__result)           \
  405.         : "r" (__addr32),           \
  406.           "I" (_SFR_IO_ADDR(RAMPZ)) \
  407.         : "r30", "r31"              \
  408.     );                              \
  409.     __result;                       \
  410. }))

  411. #define __ELPM_xmega__(addr)        \
  412. (__extension__({                    \
  413.     uint32_t __addr32 = (uint32_t)(addr); \
  414.     uint8_t __result;               \
  415.     __asm__                         \
  416.     (                               \
  417.         "in __tmp_reg__, %2" "\n\t" \
  418.         "out %2, %C1" "\n\t"        \
  419.         "movw r30, %1" "\n\t"       \
  420.         "elpm %0, Z+" "\n\t"        \
  421.         "out %2, __tmp_reg__"       \
  422.         : "=r" (__result)           \
  423.         : "r" (__addr32),           \
  424.           "I" (_SFR_IO_ADDR(RAMPZ)) \
  425.         : "r30", "r31"              \
  426.     );                              \
  427.     __result;                       \
  428. }))

  429. #define __ELPM_word_classic__(addr)     \
  430. (__extension__({                        \
  431.     uint32_t __addr32 = (uint32_t)(addr); \
  432.     uint16_t __result;                  \
  433.     __asm__                             \
  434.     (                                   \
  435.         "out %2, %C1"   "\n\t"          \
  436.         "mov r31, %B1"  "\n\t"          \
  437.         "mov r30, %A1"  "\n\t"          \
  438.         "elpm"          "\n\t"          \
  439.         "mov %A0, r0"   "\n\t"          \
  440.         "in r0, %2"     "\n\t"          \
  441.         "adiw r30, 1"   "\n\t"          \
  442.         "adc r0, __zero_reg__" "\n\t"   \
  443.         "out %2, r0"    "\n\t"          \
  444.         "elpm"          "\n\t"          \
  445.         "mov %B0, r0"   "\n\t"          \
  446.         : "=r" (__result)               \
  447.         : "r" (__addr32),               \
  448.           "I" (_SFR_IO_ADDR(RAMPZ))     \
  449.         : "r0", "r30", "r31"            \
  450.     );                                  \
  451.     __result;                           \
  452. }))

  453. #define __ELPM_word_enhanced__(addr)    \
  454. (__extension__({                        \
  455.     uint32_t __addr32 = (uint32_t)(addr); \
  456.     uint16_t __result;                  \
  457.     __asm__                             \
  458.     (                                   \
  459.         "out %2, %C1"   "\n\t"          \
  460.         "movw r30, %1"  "\n\t"          \
  461.         "elpm %A0, Z+"  "\n\t"          \
  462.         "elpm %B0, Z"   "\n\t"          \
  463.         : "=r" (__result)               \
  464.         : "r" (__addr32),               \
  465.           "I" (_SFR_IO_ADDR(RAMPZ))     \
  466.         : "r30", "r31"                  \
  467.     );                                  \
  468.     __result;                           \
  469. }))

  470. #define __ELPM_word_xmega__(addr)       \
  471. (__extension__({                        \
  472.     uint32_t __addr32 = (uint32_t)(addr); \
  473.     uint16_t __result;                  \
  474.     __asm__                             \
  475.     (                                   \
  476.         "in __tmp_reg__, %2" "\n\t"     \
  477.         "out %2, %C1"   "\n\t"          \
  478.         "movw r30, %1"  "\n\t"          \
  479.         "elpm %A0, Z+"  "\n\t"          \
  480.         "elpm %B0, Z"   "\n\t"          \
  481.         "out %2, __tmp_reg__"           \
  482.         : "=r" (__result)               \
  483.         : "r" (__addr32),               \
  484.           "I" (_SFR_IO_ADDR(RAMPZ))     \
  485.         : "r30", "r31"                  \
  486.     );                                  \
  487.     __result;                           \
  488. }))

  489. #define __ELPM_dword_classic__(addr)      \
  490. (__extension__({                          \
  491.     uint32_t __addr32 = (uint32_t)(addr); \
  492.     uint32_t __result;                    \
  493.     __asm__                               \
  494.     (                                     \
  495.         "out %2, %C1"          "\n\t"     \
  496.         "mov r31, %B1"         "\n\t"     \
  497.         "mov r30, %A1"         "\n\t"     \
  498.         "elpm"                 "\n\t"     \
  499.         "mov %A0, r0"          "\n\t"     \
  500.         "in r0, %2"            "\n\t"     \
  501.         "adiw r30, 1"          "\n\t"     \
  502.         "adc r0, __zero_reg__" "\n\t"     \
  503.         "out %2, r0"           "\n\t"     \
  504.         "elpm"                 "\n\t"     \
  505.         "mov %B0, r0"          "\n\t"     \
  506.         "in r0, %2"            "\n\t"     \
  507.         "adiw r30, 1"          "\n\t"     \
  508.         "adc r0, __zero_reg__" "\n\t"     \
  509.         "out %2, r0"           "\n\t"     \
  510.         "elpm"                 "\n\t"     \
  511.         "mov %C0, r0"          "\n\t"     \
  512.         "in r0, %2"            "\n\t"     \
  513.         "adiw r30, 1"          "\n\t"     \
  514.         "adc r0, __zero_reg__" "\n\t"     \
  515.         "out %2, r0"           "\n\t"     \
  516.         "elpm"                 "\n\t"     \
  517.         "mov %D0, r0"          "\n\t"     \
  518.         : "=r" (__result)                 \
  519.         : "r" (__addr32),                 \
  520.           "I" (_SFR_IO_ADDR(RAMPZ))       \
  521.         : "r0", "r30", "r31"              \
  522.     );                                    \
  523.     __result;                             \
  524. }))

  525. #define __ELPM_dword_enhanced__(addr)     \
  526. (__extension__({                          \
  527.     uint32_t __addr32 = (uint32_t)(addr); \
  528.     uint32_t __result;                    \
  529.     __asm__                               \
  530.     (                                     \
  531.         "out %2, %C1"   "\n\t"            \
  532.         "movw r30, %1"  "\n\t"            \
  533.         "elpm %A0, Z+"  "\n\t"            \
  534.         "elpm %B0, Z+"  "\n\t"            \
  535.         "elpm %C0, Z+"  "\n\t"            \
  536.         "elpm %D0, Z"   "\n\t"            \
  537.         : "=r" (__result)                 \
  538.         : "r" (__addr32),                 \
  539.           "I" (_SFR_IO_ADDR(RAMPZ))       \
  540.         : "r30", "r31"                    \
  541.     );                                    \
  542.     __result;                             \
  543. }))

  544. #define __ELPM_dword_xmega__(addr)        \
  545. (__extension__({                          \
  546.     uint32_t __addr32 = (uint32_t)(addr); \
  547.     uint32_t __result;                    \
  548.     __asm__                               \
  549.     (                                     \
  550.         "in __tmp_reg__, %2" "\n\t"       \
  551.         "out %2, %C1"   "\n\t"            \
  552.         "movw r30, %1"  "\n\t"            \
  553.         "elpm %A0, Z+"  "\n\t"            \
  554.         "elpm %B0, Z+"  "\n\t"            \
  555.         "elpm %C0, Z+"  "\n\t"            \
  556.         "elpm %D0, Z"   "\n\t"            \
  557.         "out %2, __tmp_reg__"             \
  558.         : "=r" (__result)                 \
  559.         : "r" (__addr32),                 \
  560.           "I" (_SFR_IO_ADDR(RAMPZ))       \
  561.         : "r30", "r31"                    \
  562.     );                                    \
  563.     __result;                             \
  564. }))

  565. #define __ELPM_float_classic__(addr)      \
  566. (__extension__({                          \
  567.     uint32_t __addr32 = (uint32_t)(addr); \
  568.     float __result;                       \
  569.     __asm__                               \
  570.     (                                     \
  571.         "out %2, %C1"          "\n\t"     \
  572.         "mov r31, %B1"         "\n\t"     \
  573.         "mov r30, %A1"         "\n\t"     \
  574.         "elpm"                 "\n\t"     \
  575.         "mov %A0, r0"          "\n\t"     \
  576.         "in r0, %2"            "\n\t"     \
  577.         "adiw r30, 1"          "\n\t"     \
  578.         "adc r0, __zero_reg__" "\n\t"     \
  579.         "out %2, r0"           "\n\t"     \
  580.         "elpm"                 "\n\t"     \
  581.         "mov %B0, r0"          "\n\t"     \
  582.         "in r0, %2"            "\n\t"     \
  583.         "adiw r30, 1"          "\n\t"     \
  584.         "adc r0, __zero_reg__" "\n\t"     \
  585.         "out %2, r0"           "\n\t"     \
  586.         "elpm"                 "\n\t"     \
  587.         "mov %C0, r0"          "\n\t"     \
  588.         "in r0, %2"            "\n\t"     \
  589.         "adiw r30, 1"          "\n\t"     \
  590.         "adc r0, __zero_reg__" "\n\t"     \
  591.         "out %2, r0"           "\n\t"     \
  592.         "elpm"                 "\n\t"     \
  593.         "mov %D0, r0"          "\n\t"     \
  594.         : "=r" (__result)                 \
  595.         : "r" (__addr32),                 \
  596.           "I" (_SFR_IO_ADDR(RAMPZ))       \
  597.         : "r0", "r30", "r31"              \
  598.     );                                    \
  599.     __result;                             \
  600. }))

  601. #define __ELPM_float_enhanced__(addr)     \
  602. (__extension__({                          \
  603.     uint32_t __addr32 = (uint32_t)(addr); \
  604.     float __result;                       \
  605.     __asm__                               \
  606.     (                                     \
  607.         "out %2, %C1"   "\n\t"            \
  608.         "movw r30, %1"  "\n\t"            \
  609.         "elpm %A0, Z+"  "\n\t"            \
  610.         "elpm %B0, Z+"  "\n\t"            \
  611.         "elpm %C0, Z+"  "\n\t"            \
  612.         "elpm %D0, Z"   "\n\t"            \
  613.         : "=r" (__result)                 \
  614.         : "r" (__addr32),                 \
  615.           "I" (_SFR_IO_ADDR(RAMPZ))       \
  616.         : "r30", "r31"                    \
  617.     );                                    \
  618.     __result;                             \
  619. }))

  620. #define __ELPM_float_xmega__(addr)        \
  621. (__extension__({                          \
  622.     uint32_t __addr32 = (uint32_t)(addr); \
  623.     float __result;                       \
  624.     __asm__                               \
  625.     (                                     \
  626.         "in __tmp_reg__, %2" "\n\t"       \
  627.         "out %2, %C1"   "\n\t"            \
  628.         "movw r30, %1"  "\n\t"            \
  629.         "elpm %A0, Z+"  "\n\t"            \
  630.         "elpm %B0, Z+"  "\n\t"            \
  631.         "elpm %C0, Z+"  "\n\t"            \
  632.         "elpm %D0, Z"   "\n\t"            \
  633.         "out %2, __tmp_reg__"             \
  634.         : "=r" (__result)                 \
  635.         : "r" (__addr32),                 \
  636.           "I" (_SFR_IO_ADDR(RAMPZ))       \
  637.         : "r30", "r31"                    \
  638.     );                                    \
  639.     __result;                             \
  640. }))

  641. /*
  642. Check for architectures that implement RAMPD (avrxmega3, avrxmega5,
  643. avrxmega7) as they need to save/restore RAMPZ for ELPM macros so it does
  644. not interfere with data accesses.
  645. */
  646. #if defined (__AVR_HAVE_RAMPD__)

  647. #define __ELPM(addr)        __ELPM_xmega__(addr)
  648. #define __ELPM_word(addr)   __ELPM_word_xmega__(addr)
  649. #define __ELPM_dword(addr)  __ELPM_dword_xmega__(addr)
  650. #define __ELPM_float(addr)  __ELPM_float_xmega__(addr)

  651. #else

  652. #if defined (__AVR_HAVE_LPMX__)

  653. #define __ELPM(addr)        __ELPM_enhanced__(addr)
  654. #define __ELPM_word(addr)   __ELPM_word_enhanced__(addr)
  655. #define __ELPM_dword(addr)  __ELPM_dword_enhanced__(addr)
  656. #define __ELPM_float(addr)  __ELPM_float_enhanced__(addr)

  657. #else

  658. #define __ELPM(addr)        __ELPM_classic__(addr)
  659. #define __ELPM_word(addr)   __ELPM_word_classic__(addr)
  660. #define __ELPM_dword(addr)  __ELPM_dword_classic__(addr)
  661. #define __ELPM_float(addr)  __ELPM_float_classic__(addr)

  662. #endif  /* __AVR_HAVE_LPMX__ */

  663. #endif  /* __AVR_HAVE_RAMPD__ */


  664. /** \ingroup avr_pgmspace
  665.     \def pgm_read_byte_far(address_long)
  666.     Read a byte from the program space with a 32-bit (far) address.

  667.     \note The address is a byte address.
  668.     The address is in the program space. */

  669. #define pgm_read_byte_far(address_long)  __ELPM((uint32_t)(address_long))

  670. /** \ingroup avr_pgmspace
  671.     \def pgm_read_word_far(address_long)
  672.     Read a word from the program space with a 32-bit (far) address.

  673.     \note The address is a byte address.
  674.     The address is in the program space. */

  675. #define pgm_read_word_far(address_long)  __ELPM_word((uint32_t)(address_long))

  676. /** \ingroup avr_pgmspace
  677.     \def pgm_read_dword_far(address_long)
  678.     Read a double word from the program space with a 32-bit (far) address.

  679.     \note The address is a byte address.
  680.     The address is in the program space. */

  681. #define pgm_read_dword_far(address_long) __ELPM_dword((uint32_t)(address_long))

  682. /** \ingroup avr_pgmspace
  683.     \def pgm_read_float_far(address_long)
  684.     Read a float from the program space with a 32-bit (far) address.

  685.     \note The address is a byte address.
  686.     The address is in the program space. */

  687. #define pgm_read_float_far(address_long) __ELPM_float((uint32_t)(address_long))

  688. #endif /* RAMPZ or __DOXYGEN__ */

  689. /** \ingroup avr_pgmspace
  690.     \def pgm_read_byte(address_short)
  691.     Read a byte from the program space with a 16-bit (near) address.

  692.     \note The address is a byte address.
  693.     The address is in the program space. */

  694. #define pgm_read_byte(address_short)    pgm_read_byte_near(address_short)

  695. /** \ingroup avr_pgmspace
  696.     \def pgm_read_word(address_short)
  697.     Read a word from the program space with a 16-bit (near) address.

  698.     \note The address is a byte address.
  699.     The address is in the program space. */

  700. #define pgm_read_word(address_short)    pgm_read_word_near(address_short)

  701. /** \ingroup avr_pgmspace
  702.     \def pgm_read_dword(address_short)
  703.     Read a double word from the program space with a 16-bit (near) address.

  704.     \note The address is a byte address.
  705.     The address is in the program space. */

  706. #define pgm_read_dword(address_short)   pgm_read_dword_near(address_short)

  707. /** \ingroup avr_pgmspace
  708.     \def pgm_read_float(address_short)
  709.     Read a float from the program space with a 16-bit (near) address.

  710.     \note The address is a byte address.
  711.     The address is in the program space. */

  712. #define pgm_read_float(address_short)   pgm_read_float_near(address_short)

  713. /** \ingroup avr_pgmspace
  714.     \def PGM_P

  715.     Used to declare a variable that is a pointer to a string in program
  716.     space. */

  717. #ifndef PGM_P
  718. #define PGM_P const prog_char *
  719. #endif

  720. /** \ingroup avr_pgmspace
  721.     \def PGM_VOID_P

  722.     Used to declare a generic pointer to an object in program space. */

  723. #ifndef PGM_VOID_P
  724. #define PGM_VOID_P const prog_void *
  725. #endif

  726. extern PGM_VOID_P memchr_P(PGM_VOID_P, int __val, size_t __len) __ATTR_CONST__;
  727. extern int memcmp_P(const void *, PGM_VOID_P, size_t) __ATTR_PURE__;
  728. extern void *memccpy_P(void *, PGM_VOID_P, int __val, size_t);
  729. extern void *memcpy_P(void *, PGM_VOID_P, size_t);
  730. extern void *memmem_P(const void *, size_t, PGM_VOID_P, size_t) __ATTR_PURE__;
  731. extern PGM_VOID_P memrchr_P(PGM_VOID_P, int __val, size_t __len) __ATTR_CONST__;
  732. extern char *strcat_P(char *, PGM_P);
  733. extern PGM_P strchr_P(PGM_P, int __val) __ATTR_CONST__;
  734. extern PGM_P strchrnul_P(PGM_P, int __val) __ATTR_CONST__;
  735. extern int strcmp_P(const char *, PGM_P) __ATTR_PURE__;
  736. extern char *strcpy_P(char *, PGM_P);
  737. extern int strcasecmp_P(const char *, PGM_P) __ATTR_PURE__;
  738. extern char *strcasestr_P(const char *, PGM_P) __ATTR_PURE__;
  739. extern size_t strcspn_P(const char *__s, PGM_P __reject) __ATTR_PURE__;
  740. extern size_t strlcat_P (char *, PGM_P, size_t );
  741. extern size_t strlcpy_P (char *, PGM_P, size_t );
  742. extern size_t strlen_P(PGM_P) __ATTR_CONST__; /* program memory can't change */
  743. extern size_t strnlen_P(PGM_P, size_t) __ATTR_CONST__; /* program memory can't change */
  744. extern int strncmp_P(const char *, PGM_P, size_t) __ATTR_PURE__;
  745. extern int strncasecmp_P(const char *, PGM_P, size_t) __ATTR_PURE__;
  746. extern char *strncat_P(char *, PGM_P, size_t);
  747. extern char *strncpy_P(char *, PGM_P, size_t);
  748. extern char *strpbrk_P(const char *__s, PGM_P __accept) __ATTR_PURE__;
  749. extern PGM_P strrchr_P(PGM_P, int __val) __ATTR_CONST__;
  750. extern char *strsep_P(char **__sp, PGM_P __delim);
  751. extern size_t strspn_P(const char *__s, PGM_P __accept) __ATTR_PURE__;
  752. extern char *strstr_P(const char *, PGM_P) __ATTR_PURE__;
  753. extern char *strtok_P(char *__s, PGM_P __delim);
  754. extern char *strtok_rP(char *__s, PGM_P __delim, char **__last);

  755. #ifdef __cplusplus
  756. }
  757. #endif

  758. #endif /* __PGMSPACE_H_ */
复制代码


回复 支持 反对

使用道具 举报

发表于 2024-3-6 00:45:00 | 显示全部楼层
用什么IDE玩?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2024-5-3 02:19 , Processed in 0.093600 second(s), 12 queries , Redis On.

Powered by Discuz!

© 2006-2023 smzj.net

快速回复 返回顶部 返回列表