NIOS II 错误:整数常量的后缀无效

Posted

技术标签:

【中文标题】NIOS II 错误:整数常量的后缀无效【英文标题】:NIOS II error: invalid suffix on integer constant 【发布时间】:2014-12-05 17:35:57 【问题描述】:

所以我一直在 DE2-155 板上制作 SD 卡音乐播放器。我终于完成了硬件并开始使用 C 进行编码以完成它。但是,在构建项目之前,我不断收到错误消息:“整数常量上的后缀无效“0b00100000”。”

这是我的 C 代码:

#include <io.h>
#include <system.h>

#include "altera_up_avalon_audio_and_video_config.h"
#include "altera_up_avalon_audio.h"

#define SD_CARD_OFFSET_RXTX 0
#define SD_CARD_OFFSET_CMD  560
#define SD_CARD_OFFSET_CMD_ARG  556
#define SD_CARD_OFFSET_ASR  564

#define SD_CONNECTED        0x02
#define SD_COMPLETE     0x04
#define SD_BLOCK_SIZE       512
#define SD_CMD_READ     0x11

int main()

    int *sd_asr = (int *)(ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_BASE + SD_CARD_OFFSET_ASR);
    short int sd_status;
    int res;
    int sector_count, byte_count;
    unsigned int l_buff,r_buff;

alt_up_av_config_dev* cfg_dev;
alt_up_audio_dev* audio_dev;

/* Wait for SD-Card */

printf("Wait for SD-Card to be connected...\n");

do
    sd_status=(short int)IORD_16DIRECT(sd_asr,0);
while((sd_status & SD_CONNECTED) == 0);

printf("SD-Card connected.\n");

/* Initialize CFG/Audio Device */

cfg_dev=alt_up_av_config_open_dev("/dev/audio_and_video_config_0");

if(cfg_dev == NULL)
    printf("Config device not found.\n");
else
    printf("Config device opened for configuration.\n");


printf("Resetting config device and peripherals...\n");

res = alt_up_av_config_reset(cfg_dev);

alt_up_av_config_write_audio_cfg_register(cfg_dev,0x08,0b00100000);

if(res == 0)
    printf("Reset successful.\n");
else
    printf("Reset failed.\n");


/* Play Music */

audio_dev = alt_up_audio_open_dev("/dev/audio_0");

if(audio_dev == NULL)
    printf("Failed to open audio device.\n");
else
    printf("Audio device opened.\n");


printf("Starting playback!\n");

sector_count=0;
while(1)

    /* Read 512B sector from SD-Card */
    IOWR_32DIRECT(ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_BASE,SD_CARD_OFFSET_CMD_ARG,sector_count*512);
    IOWR_16DIRECT(ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_BASE,SD_CARD_OFFSET_CMD,SD_CMD_READ);
    do
        sd_status=(short int)IORD_16DIRECT(ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_BASE,SD_CARD_OFFSET_ASR);
    while((sd_status & SD_COMPLETE) != 0);

    byte_count=0;
    while(byte_count < 512)
        l_buff = (unsigned int)IORD_16DIRECT(ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_BASE,SD_CARD_OFFSET_RXTX+byte_count);
        r_buff = (unsigned int)IORD_16DIRECT(ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_BASE,SD_CARD_OFFSET_RXTX+(byte_count+2));
        byte_count+=4;
        while(alt_up_audio_write_fifo_space(audio_dev,ALT_UP_AUDIO_RIGHT) < 4) asm("NOP"); 
            alt_up_audio_write_fifo (audio_dev, &(r_buff), 1, ALT_UP_AUDIO_RIGHT);
            alt_up_audio_write_fifo (audio_dev, &(l_buff), 1, ALT_UP_AUDIO_LEFT);
        

        sector_count++;
    

    return 0;

【问题讨论】:

【参考方案1】:

错误在线

alt_up_av_config_write_audio_cfg_register(cfg_dev,0x08,0b00100000);

0b00100000 是一个整数值。如果整数值以 0 开头,则下一个字符必须是 x 以将整数声明为十六进制数,否则将被解释为 octal number。八进制数只能有 0 到 7 位。

0b00100000 是二进制,即十进制 32 或十六进制 0x20

另见Can I use a binary literal in C or C++?

0b00100000 这样的二进制表示法只有启用了 GCC 扩展的 GCC 才支持。

【讨论】:

我把它换成了32,错误就消失了。我认为可能是这种情况,但有人告诉我二进制文件对他们有用,所以我想我会问。感谢您的帮助!

以上是关于NIOS II 错误:整数常量的后缀无效的主要内容,如果未能解决你的问题,请参考以下文章

Java每日一题——>剑指 Offer II 036. 后缀表达式

Java每日一题——>剑指 Offer II 036. 后缀表达式

Java每日一题——>剑指 Offer II 036. 后缀表达式

Java每日一题——>剑指 Offer II 036. 后缀表达式

4.常量

c 语言常量