So I've been making an SD card music player on a DE2-155 board for a while. I've finally finished the hardware and have moved into coding in C to finish it up. However, before I can build the project I keep getting the error: "Invalid suffix "0b00100000" on integer constant."
Here is my C code:
#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;
}
The error is on line
0b00100000 is an integer value. If an integer value starts with a 0, the next character must be either an x to declare the integer number as hexadecimal number, or it will be interpreted as octal number. An octal number can have only the digits 0 to 7.
0b00100000 is binary which is decimal 32 or hexadecimal 0x20.
See also Can I use a binary literal in C or C++?
A binary notation like 0b00100000 is supported only by GCC with enabled GCC extensions.