OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4209|回复: 1

PROGMEM_*****宏定义如何理解?

[复制链接]

3

主题

95

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
2452
金钱
2452
注册时间
2015-11-1
在线时间
301 小时
发表于 2016-4-26 12:57:33 | 显示全部楼层 |阅读模式
1金钱
一堆宏定义无法理解,还请赐教:如下:

#if defined(__GNUC__) || defined(__DOXYGEN__)
# include <avr/pgmspace.h>
# define PROGMEM_LOCATION(type, name, loc) \
                type name __attribute__((section (#loc)))
# define PROGMEM_DECLARE(type, name) const type name __attribute__((__progmem__))
# define PROGMEM_STRING(x) PSTR(x)
# define PROGMEM_STRING_T  PGM_P
# define PROGMEM_T const
# define PROGMEM_PTR_T const *
# define PROGMEM_BYTE_ARRAY_T uint8_t*
# define PROGMEM_WORD_ARRAY_T uint16_t*
# define PROGMEM_READ_BYTE(x) pgm_read_byte(x)
# define PROGMEM_READ_WORD(x) pgm_read_word(x)

#elif defined(__ICCAVR__)
# include <pgmspace.h>
# ifndef __HAS_ELPM__
#  define _MEMATTR_ASF  __flash
# else /* __HAS_ELPM__ */
#  define _MEMATTR_ASF  __hugeflash
# endif /* __HAS_ELPM__ */
# define PROGMEM_LOCATION(type, name, loc) const _MEMATTR_ASF type name @ loc
# define PROGMEM_DECLARE(type, name) _MEMATTR_ASF type name
# define PROGMEM_STRING(x) ((_MEMATTR_ASF const char *)(x))
# define PROGMEM_STRING_T  char const _MEMATTR_ASF *
# define PROGMEM_T const _MEMATTR_ASF
# define PROGMEM_PTR_T const _MEMATTR_ASF *
# define PROGMEM_BYTE_ARRAY_T uint8_t const _MEMATTR_ASF *
# define PROGMEM_WORD_ARRAY_T uint16_t const _MEMATTR_ASF *
# define PROGMEM_READ_BYTE(x) *(x)
# define PROGMEM_READ_WORD(x) *(x)
#endif

在C内直接就这样定认数据:
PROGMEM_DECLARE(char const, header[]) = "Temperature";
PROGMEM_DECLARE(char const, cdc_help[]) =
        "\r\n"
        "Welcome to the XMEGA-A3BU Xplained Demo CDC interface!\r\n"
        "\r\n"
        "Key bindings for LCD menu control:\r\n"
        "  Enter      : Enter\r\n"
        "  Backspace  : Back\r\n"
        "  Arrow Up   : Up\r\n"
        "  Arrow Down : Down\r\n";
PROGMEM_DECLARE(char const, tz_00[]) =  "UTC: UK (GMT)";
PROGMEM_DECLARE(char const, tz_01[]) =  " +1: Oslo, Berlin";
PROGMEM_DECLARE(char const, tz_02[]) =  " +2: Istanbul";
PROGMEM_DECLARE(char const, tz_03[]) =  " +3: Nairobi";
PROGMEM_DECLARE(char const, tz_04[]) =  " +4: Moscow";
PROGMEM_DECLARE(char const, tz_05[]) =  " +5: Pakistan";
PROGMEM_DECLARE(char const, tz_06[]) =  " +6: Bangladesh";
PROGMEM_DECLARE(char const, tz_07[]) =  " +7: Thailand";
PROGMEM_DECLARE(char const, tz_08[]) =  " +8: Hong Kong";
PROGMEM_DECLARE(char const, tz_09[]) =  " +9: Tokyo";
PROGMEM_DECLARE(char const, tz_10[]) =  "+10: AEST";
PROGMEM_DECLARE(char const, tz_11[]) =  "+11: Solomon Island";
PROGMEM_DECLARE(char const, tz_12[]) =  "+12: Fiji";

就这样执行了:
        while ((val = PROGMEM_READ_BYTE(help))) {
                udi_cdc_putc(val);
                help++;
        }


这几句,真心不懂。
# define PROGMEM_LOCATION(type, name, loc) \
                type name __attribute__((section (#loc)))
# define PROGMEM_DECLARE(type, name) const type name __attribute__((__progmem__))

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2016-5-1 12:52:14 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-17 04:12

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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