Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor10102931010293 Controller Layer Development Guide Anchor10111961011196To fully take advantage of advanced peripherals (for example, NAND flash controllers), you might decide to provide your own implementation of the controller layer. The controller layer is one level above the BSP layer. Its interface is more flexible, but is also more complex to implement. If you choose that route, it is strongly recommended to use the provided implementations as an example. Listing 13-12 describes Listing - Controller API type definition describes the API that must be implemented for the controller layer.anchor

Code Block

...

typedef struct
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
rowspan6
Anchor
10112021011202
language

...

void
 {
    void               *(*Open)        (FS_NAND_PART_API  *p_part_api,
void

                                        void              *p_bsp_api,
void

                                        void              *p_ctrlr_cfg,
FS_ERR

                                        FS_ERR            *p_err);
  void

 
    void                (*Close)       (void              *p_ctrlr_data);
 

 
    FS_NAND_PART_DATA  *(*PartDataGet) (void              *p_ctrlr_data);
 

 
    FS_NAND_PG_SIZE     (*Setup)       (void              *p_ctrlr_data,

                                        FS_NAND_PG_SIZE    sec_size,
FS_ERR

                                        FS_ERR            *p_err);
  void

 
    void                (*SecRd)       (void              *p_ctrlr_data,
void *p_dest, void
 
                                        void              *p_dest,
                                        void              *p_dest_oos,

                                        FS_SEC_NBR         sec_ix_phy,
FS_ERR

                                        FS_ERR            *p_err);
  void

 
    void                (*OOSRdRaw)    (void              *p_ctrlr_data,
void

                                        void              *p_dest_oos,

                                        FS_SEC_NBR         sec_nbr_phy,

                                        FS_NAND_PG_SIZE
offset,
    offset,
                                        FS_NAND_PG_SIZE
length, FS_ERR
    length,
                                        FS_ERR            *p_err);
  void

 
    void                (*SpareRdRaw)  (void              *p_ctrlr_data,
void

                                        void              *p_dest_oos,

                                        FS_SEC_QTY         pg_nbr_phy,

                                        FS_NAND_PG_SIZE
offset,
    offset,
                                        FS_NAND_PG_SIZE
length, FS_ERR
    length,
                                        FS_ERR            *p_err);
  void

 
    void                (*SecWr)       (void              *p_ctrlr_data,
void *p_src, void

                                        void              *p_src,
                                        void              *p_src_spare,

                                        FS_SEC_NBR         sec_nbr_phy,
FS_ERR

                                        FS_ERR            *p_err);
  void

 
    void                (*BlkErase)    (void              *p_ctrlr_data,
CPU_INT32U

                                        CPU_INT32U         blk_nbr_phy,
FS_ERR

                                        FS_ERR            *p_err);
  void

 
    void                (*IO_Ctrl)     (void              *p_ctrlr_data,
CPU_INT08U cmd, void *p_buf, FS_ERR

                                        CPU_INT08U         cmd,
                                        void              *p_buf,
                                        FS_ERR            *p_err);
}

} FS_NAND_CTRLR_API;
cpp
titleListing - Controller API type definition
linenumberstrue
typedef  struct  fs_nand_ctrlr_api
{
Anchor
10112031011203
Anchor
10112041011204
Anchor
10112051011205
Anchor
10112061011206
Anchor
10112071011207
Anchor
10112081011208
Anchor
10112091011209
Anchor
10112101011210
Anchor
10112111011211
Anchor
10112121011212
Anchor
10112131011213
Anchor
10112141011214
Anchor
10112151011215
Anchor
10112161011216
Anchor
10112171011217
Anchor
10112181011218
Anchor
10112191011219
Anchor
10112201011220
Anchor
10112211011221
Anchor
10112221011222
Anchor
10112231011223
Anchor
10112241011224
Anchor
10112251011225
Anchor
10112261011226
Anchor
10112271011227
Anchor
10112281011228
Anchor
10112291011229
Anchor
10112301011230
Anchor
10112311011231
Anchor
10112321011232
Anchor
10112331011233
Anchor
10112341011234
Anchor
10112351011235
Anchor
10112361011236
Anchor
10112371011237
Anchor
10112381011238
Anchor
10112391011239
Anchor
10112401011240
Anchor
10112411011241
Anchor
10112421011242
Anchor
10112431011243
Anchor
10112441011244
Anchor
10112451011245
Anchor
10112461011246
Anchor
10112471011247
Anchor
10112481011248
Anchor
10112491011249
Anchor
10112501011250
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)

...


Anchor10129151012915Open/Close functionsBefore implementing the following functions, it is important to understand the difference between out-of-sector (OOS) data and the spare area. In a NAND device, each page has a spare area, typically used to store metadata and error correction codes (ECC). The spare area also contains a factory defect mark and, optionally, reserved sections. In the implementation of the µC/FS NAND driver, the OOS data is metadata sent to the controller layer by the translation layer. It must be stored in the spare area, wit.hout overwriting the bad block mark and without writing to the reserved section. It must also be protected by ECC. The OOS data is only a part of what is inside the spare area. It doesn’t include the factory defect marks, the reserved sections and the ECC data. Also, if the sector size is not equal to the page size, the OOS data will be associated to a single sector, while the spare area will be associated to a single page. In that case, multiple OOS sections would be fit in a single spare area. Anchor10129231012923 Open/Close functionsanchor

10129161012916The Open() and Close() function will be called respectively by FSDev_Open() and FSDev_Close(). Typically, FSDev_Open() is called during initialization and FSDev_Close() is never called. When implementing the Open() function of the controller layer, you should typically add all necessary code for the bus/controller initialization (or call the Open() function of the BSP layer). You should also allocate the necessary memory and perform all the operations that need to be done a single time only, when opening the device. The Close() function is typically left empty. Anchor10113021011302

Part data get function

...

1011332The PartDataGet() function should return an instance of the type FS_NAND_PART_DATA associated to a particular device.anchor10113381011338

Setup function

Anchor10113571011357The Setup() function is called a single time, after the Open() function. It must perform the proper calculation to make sure that the out-of-sector data (OOS) and the error correction codes (ECC) can fit in the spare area.anchor10113631011363

Sector read function

...

1047880The SectorRd() function must copy the data found at the physical sector sec_ix_phy into the p_dest buffer. It must also copy the out-of-sector data (OOS - the section of the spare area, excluding ECC, bad block marks and unused sections) into the p_dest_oos buffer. Before returning successfully, the function should check for errors and correct them, if needed (with ECC). Anchor10478811047881

Out-Of-sector (OOS) raw read function

...

The OOSRdRaw() function must copy len octets from the offset octet in the OOS of the sector sec_ix_phy into the p_dest_oos buffer. This function should not perform error correction. Anchor10114481011448

Spare area raw read function

Anchor10114961011496The SpareRdRaw() function must copy len octets from the offset octet in the spare area of the page pg_ix_phy into the p_dest_spare buffer. This function should not perform error correction. Anchor10115021011502

Sector write function

...

The SectorWr() function must write the data found in the p_src buffer into the physical sector sec_ix_phy of the NAND device. It must also write the out-of-sector data (OOS - the section of the spare area, excluding ECC, bad block marks and unused sections) found in the p_src_oos buffer into the spare area. It should also store error correction codes (ECC) in the spare area. Anchor10115311011531

Block erase function

Anchor10115531011553The BlkErase() function should erase the block blk_ix_phy of the device. Anchor10115591011559

IO control function

...

1011581The IO_Ctrl() function body can be left empty. It was created to perform device or controller specific commands without the need of a custom API. It can simply return the FS_ERR_DEV_INVALID_IO_CTRL error code. Anchor10274441027444

Note that the ONFI part layer implementation makes use of the FS_DEV_IO_CTRL_NAND_PARAM_PG_RD I/O control operation. In order to retain compatibility with the ONFI part layer implementation, your controller implementation must support that operation.