88
Figure 6-16 Block diagram of the Micro SD demonstration
shows the software stack of this demonstration. The Nios PIO block provides basic IO
functions to access hardware directly. The functions are provided from Nios II system and the
function prototype is defined in the header file <io.h>. The SD Card block implements 4-bit mode
protocol for communication with SD Cards. The FAT File System block implements reading
function for FAT16 and FAT 32 file system. Long filename is supported. By calling the public FAT
functions, users can browse files under the root directory of the Micro SD Card. Furthermore, users
can open a specified file and read the contents of the file. The main block implements main control
of this demonstration. When the program is executed, it detects whether an Micro SD Card is
inserted. If an Micro SD Card is found, it will check whether the Micro SD Card is formatted as
FAT file system. If so, it searches all files in the root directory of the FAT file system and displays
their names in the nios2-terminal. If a text file named “test.txt” is found, it will dump the file
contents. If it successfully recognizes the FAT file system, it will turn on the green LED. On the
other hand, it will turn on the red LED if it fails to parse the FAT file system or if there is no SD
Card found in the SD Card socket of the C5G board. If users press KEY3 of the C5G board, the
program will perform above process again.