Please enable JavaScript to view this site.

Waijung 2 User Guide

Design overview

SD card block appearance in a Simulink model,

zynq_7000_sd_card_block_1

SD card block mask overview,

Block Name

Mask

SD SETUP

zynq_7000_sd_card_block_2

SD WRITE

zynq_7000_sd_card_block_3

SD READ

zynq_7000_sd_card_block_4

SD FILE CONFIG

zynq_7000_sd_card_block_5

SD DRIVE INFO

zynq_7000_sd_card_block_6

SD Card Block input interfaces

SD SETUP

Name

Type

Range

Description

N/A

 

 

 

SD WRITE, SD READ

Name

Type

Range

Description

Data

uint8 | Vector

 

The buffer size for the input data is dynamically allocated.

Line #

uint16 | Scalar

 

This port is only visible when Read: mask parameter is configured as Specific line.

 

It can be used to specify the line number to be read from the SD card.

SD FILE CONFIG

Name

Type

Range

Description

N/A

 

 

 

SD DRIVE INFO

Name

Type

Range

Description

N/A

 

 

 

SD Card Block output interfaces

SD SETUP

Name

Type

Range

Description

N/A

 

 

 

SD WRITE, SD READ

Name

Type

Range

Description

Data

uint8 | Vector

 

The buffer size for the output data is specified with the Output data buffer size mask parameter.

Status

uint8 | Scalar

0 - 19

This port is only available when Status mask parameter is set to Enable.

 

The output of this port can be used to determine the success of a read/write transaction. If the data is successfully read/write, the output will be 0, else it will output an integer which correspond to a specific return code of API functions in the FatFs library.

# char

int32 | Scalar

 

This port is only available when Output number of characters read/written mask parameters are set to Enable.

 

It returns the number of characters written to the file if the function execution is successful. When the function fails due to disk full or any error, -1 value will be returned.

SD FILE CONFIG

Name

Type

Range

Description

N/A

 

 

 

SD DRIVE INFO

Name

Type

Range

Description

Total (KB)

uint32 | Scalar

 

The total memory size of the selected logical drive in KB

Free (KB)

uint32 | Scalar

 

The remaining free memory size of the selected logical drive in KB

Status

uint8 | Scalar

0 - 19

The output of this port can be used to determine the success of this transaction. If the data is successfully acquired, the output will be 0, else it will output an integer which correspond to a specific return code of API functions in the FatFs library.

SD Card Block behavior

The following list of blocks complete the SD card driver blocks:

Block Name

Functionality

SD SETUP

Initialize the library and library configuration parameters.

SD READ

Read data from a SD card.

SD WRITE

Write data to a SD card.

SD FILE CONFIG

This block is used to configure multiple files simultaneously. There can be more than one SD FILE CONFIG block in a single model file.

SD DRIVE INFO

This block is used to retrieve information of the logical drives in SD card such as:

Total memory size in the drive in Kilobytes

Free memory size in the drive in Kilobytes

Waijung2 SD card blocks were implemented using the XILFFS library provided by Xilinx, Inc. Details related to the XILFFS library:

The LibXil fat file system (FFS) library consists of a file system and a glue layer. This FAT file system can be used with an interface supported in the glue layer.

The file system code is open source and is used as it is. Glue layer implementation supports SD/eMMC interface presently.

Application should make use of APIs provided in ff.h. These file system APIs access the driver functions through the glue layer.

This library treats Windows and Unix line endings same for reading operations. When a complete file is read, the string will be read without a carriage return (CR) and only newline (LF) character. Following is an example of the read all function output for a file with three lines. The output string will be as shown.

     Line1                

             Line2

                      Line3

The SDPS driver used by the XILFFS library consist of two SD controllers that have the same feature set and can be operated independently. However, the glue layer can currently be used only with one SD controller enabled.

SD Card Block configuration

Only a few of the FatFS library configuration parameters are available for configuration when using the XILFFS library. Default XILFFS Library configurations were maintained except the following:

Library Configuration Parameter

Description

use_lfn

Enables Long File Name (LFN) support. The user has been given the option to configure this using the Support Long File Names (LFN) and Manage memory for LFN using: parameters in the SD SETUP block.

The following parameters can be configured through block mask of SD SETUP.

Configuration Parameter

Selectable Option/Value

Description

Format the SD card

true

false

If true, the SD card will be formatted during initialization and vise-versa.

Support Long File Names (LFN)

On

Off

If unchecked use_lfn library configuration parameter is set to 0. Which indicates that the filenames can only exist in 8.3 format.

Manage Memory for LFN using:

Stack

Heap

This parameter is only visible when Support Long File Names (LFN) parameter is enabled. use_lfn library configuration parameter is set to 2 or 3 depending on the selection of Stack or Heap respectively.

The following parameters can be configured through block mask of SD FILE CONFIG.

Configuration Parameter

Selectable Option/Value

Description

Logical drive path

0:/

 

By default, the Logical drive path is set to 0:/. The logical drive path is fixed and read only.

Create directory

On

Off

If unchecked, the files configured by that specific SD SETUP block will be created in the root of the selected volume.

Directory name

 

Enter the directory name. This parameter is only visible when Create directory mask parameter is enabled.

File type

txt

csv

Select the file type.

File names

 

Specify the filenames. Multiple filenames can be specified by comma separation. Files specified in a particular SD SETUP block share the other configuration parameters such as Directory name.

The following parameters can be configured through block mask of SD DRIVE INFO.

Configuration Parameter

Selectable Option/Value

Description

Logical drive path

0:/

 

By default the Logical drive path is set to 0:/.

The following parameters can be configured through block masks of SD WRITE and SD READ blocks.

Configuration Parameter

Selectable Option/Value

Description

File name

 

Select file name. The drop-down menu will contain all file names specified in each an every SD FILE CONFIG block in the model.

File path

 

The file path will be automatically set depending on the configurations set at the SD FILE CONFIG block for the selected file.

Output number of characters read

Enable

Disable

If enabled, # char

Status

Enable

Disable

When enabled Status output port will appear. This port can be used to check the status* of every function execution. The block supports all the return codes that are supported by the FATFS file system library.

Read options

FA_READ

Specify the read option**

Output data buffer size

 

The SD READ block will only be able to read number of characters equivalent to the value specified for this parameter.

Read:

Last line

Select the read mode.

Last line – The last line of the specified file is read.

Specific line – When enabled Line # input port will appear. User can use this input port to specify the line to be read on-the-fly.

Read all lines in the specified file. However, the number of characters that can be read will be limited by the value specified for the Output data buffer size mask parameter.

Specific line

All

Write options

FA_CREATE_ALWAYS | FA_WRITE

Specify the write option**

FA_OPEN_APPEND | FA_WRITE

FA_CREATE_NEW | FA_WRITE

Sample time

-1 (inherited) or specify

Specify the sample time.

* The Status port output will return one of the following. These error codes are in-line with the return codes generated by the FATFS file system library.

enum STATUS {

FR_OK = 0,

FR_DISK_ERR,

FR_INT_ERR,

FR_NOT_READY,

FR_NO_FILE,

FR_NO_PATH,

FR_INVALID_NAME,

FR_DENIED,

FR_EXIST,

FR_INVALID_OBJECT,

FR_WRITE_PROTECTED,

FR_INVALID_DRIVE,

FR_NOT_ENABLED,

FR_NO_FILESYSTEM,

FR_MKFS_ABORTED,

FR_TIMEOUT,

FR_LOCKED,

FR_NOT_ENOUGH_CORE,

FR_TOO_MANY_OPEN_FILES,

FR_INVALID_PARAMETER

}

**Mode flags specifies the type of access and open method for the file. It is specified by a combination of following flags.

FA_READ - Specifies read access to the file. Data can be read from the file.

FA_WRITE - Specifies write access to the file. Data can be written to the file.

FA_CREATE_NEW - Creates a new file. The function fails with FR_EXIST if the file is existing.

FA_CREATE_ALWAYS - Creates a new file. If the file is existing, it will be truncated and overwritten.

FA_OPEN_APPEND - Same as FA_OPEN_ALWAYS except the read/write pointer is set end of the file.

SD Card Block limitations

The known limitations associated with the block are:

The XILFFS library used by this block can currently be used only with one SD controller (SDIO0, SDIO1) enabled.

The block does not support interrupt functionality.

The blocks are NOT thread-safe.

Troubleshooting

Typical application

Several demo files are provided at:

[<waijung2 installation directory>\waijung2\targets\zynq7000\demo\sd_demo]

To load the model file run the following commands in the Matlab Command Window:

Demo 1: waijung2.openDemoInCurrentFolder('zynq7000', 'sd_demo1')

Demo 2: waijung2.openDemoInCurrentFolder('zynq7000', 'sd_demo2')

 

Copyright 2024 Aimagin Co.,Ltd. Rev.1680