OK, found the solution to this!
ftp://ftp.altera.com/up/pub/university_program_ip_cores/90/altera_up_avalon_sd_card_interface.zip The altera_up_sd_card_interface folder should go in the sopc builder default library component directory (/altera/11.0/ip/sopc_builder_ip/)
The way our university has set it up, these files require root permissions to change on the local machines, so I will have a chat to the admins to see if I can get them to put it in this directory for me.
The work around I found was to put an ip folder in the quartus project folder and then extract the zip file there:
(~/Altera_Systems_Labs/De0_Counter/ip/altera_up_sd_card_interface/)
De0_Counter being the project folder.
I ran ip-make-ipx from De0_Counter to generate components.ipx which sopc_builder uses to find components. Now there's no need to specify the IP search path in sopc builder.
Launching quartus and sopc builder the component is now available in the Project Library on the left hand side. Added the components and gave the instance the name: "Altera_UP_SD_Card" case sensitive.
This step is important, since all of the macros in the header files are looking for that name.
Generate in sopc builder, compile in quartus, clean project in nios2-ide.
At this point, the alt_sys_init.c is generated. In my nios2 project (FreeRTOS) it is located:
~/Altera_Systems_Labs/New_FreeRTOS/FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo_syslib/Debug/system_description/alt_sys_init.c
I haven't managed to get the macros from the header file included automatically, hopefully that will be sorted by putting it in the default library path. But the lines that I added to this file were from the bottom of altera_up_sd_card_avalon_interface.h:
@72:# include "altera_up_sd_card_avalon_interface.h"
@85: ALTERA_UP_SD_CARD_AVALON_INTERFACE_INSTANCE( ALTERA_UP_SD_CARD, altera_up_sd_card );
@114: ALTERA_UP_SD_CARD_AVALON_INTERFACE_INIT( ALTERA_UP_SD_CARD, altera_up_sd_card );
Using FreeRTOS so added a Task that calls the demo code available in the PDFs
ftp://ftp.altera.com/up/pub/altera_material/11.0/university_program_ip_cores/memory/sd_card_interface_for_sopc_builder.pdf Have a look in the header files for the functions available. So some functions I wrote:
int sd_card_read_names(void)
{
int number_of_files = 0;
char buffer_name[25];
short int handler;
handler = alt_up_sd_card_find_first("/.", buffer_name);
printf("%d, %s \n", handler, buffer_name);
while ((handler = alt_up_sd_card_find_next(buffer_name)) != -1)
{
number_of_files++;
printf("%d, %s \n", handler, buffer_name);
}
printf("Number of files: %d\n",number_of_files);
alt_up_sd_card_fclose(handler);
return number_of_files;
}
/*-----------------------------------*/
int sd_card_read_file(char *file_name)
{
int number_of_chars = 0;
short handler;
short read;
char cFileLine[100] = {0};
if ((handler = alt_up_sd_card_fopen(file_name, false)) != -1)
{
printf("looking for the file %s\n",file_name);
while ((read = alt_up_sd_card_read(handler)) != -1){
printf("%c", read);
cFileLine[number_of_chars] = (char)read;
number_of_chars++;
}
printf("'EOF'\nnumber_of_chars = %d\n",number_of_chars);
alt_up_sd_card_fclose(handler);
handler = 0;
}
if (handler == -1)
{
printf("File not found\n");
}
return number_of_chars;
}
Hope that helps all those who are struggling with the SD card too.
I found that the files it writes don't have the proper attributes and appear to have been created in 1601 (from windows). Windows created .txt files are 36 bytes min, whereas files created with the altera ip seem to be as long as the characters written to it. Linux can read the files fine with cat. Haven't got friendly with the get and set attributes yet. I'll leave that up to you to figure out ;)
Peace