2
因此,我一直在DE2-155板上製作SD卡音樂播放器一段時間。我終於完成了這個硬件,並且已經在C編碼中完成了它。但是,在我可以構建項目之前,我一直收到錯誤:「整數常量上的後綴無效」0b00100000「。」NIOS II錯誤:整數常量上的無效後綴
這是我的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;
}
我用32替換了它,錯誤消失了。我認爲可能是這樣,但有人告訴我,二進制文件爲他們工作,所以我想我會問。謝謝您的幫助! – mightynifty 2014-12-05 18:05:15