/*---------------------------------------------------------------------------* Project: CTR - NAND driver File: nand.h Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #ifndef __NAND_H__ #define __NAND_H__ #include "nandif_ip.h" #ifdef __cplusplus extern "C" { #endif /*---------------------------------------------------------------------------* 定義 *---------------------------------------------------------------------------*/ #define NAND_GUARANTEED_BLOCKS (999) #define NAND_GUARANTEED_SECTORS (NAND_GUARANTEED_BLOCKS*256) //保証されたセクタ数(=使える容量) #define NAND_CACHE_PAGES (1) /* 1以外は設定禁止 */ #define NAND_ANTI_READDISTURB (1) /* TODO */ /*---------------------------------------------------------------------------* 構造体 *---------------------------------------------------------------------------*/ typedef struct NandPageCacheFormat { //ブロックキャッシュ u16 valid; /*有効 or 無効*/ u16 dirty; /*ダーティ or クリーン*/ u16 OnTheFlush; /*Flush進行中のNewPhysicalBlk番号*/ struct NandBlockStatInfo* TargetNandBlockStat; /*Flush進行中のNewPhysicalBlk情報へのポインタ*/ BOOL BlockDirty; /*ブロック・ダーティ or クリーン*/ // u16 logical_blk; /*論理ブロック番号*/ u32 logical_page; /*論理ページ番号*/ u8 page_flushed_count; /*Flush先の物理ページオフセット(0からカウントアップ)*/ int page_flushed[64]; /*Flushによって書き込まれた物理ページのオフセット*/ struct NandPageFormat NandPage[NAND_CACHE_PAGES]; /*1ページ分のキャッシュメモリ*/ u32 ecc[NAND_CACHE_PAGES][4]; /*読み出し時に自動生成されたECC*/ struct NandSpareFormat NandSpareWriteForward; /*newブロックにライトするスペア領域*/ struct NandSpareFormat NandSpareWriteBack; /*oldブロックにライトバックするスペア領域*/ struct NandSpareFormat NandSpareWriteMerge; /*mergeブロックにライトするスペア領域*/ } NandPageCacheFormat; typedef struct NandBlockStatInfo { //ブロック状態リンクリスト u16 physical_blk; u16 block_stat_bad; u32 erase_count; struct NandBlockStatInfo* next; } NandBlockStatInfo; typedef struct NandStatInfo { struct NandBlockStatInfo* busy; /*論理blk番号が割り当て済み*/ struct NandBlockStatInfo* free; /*論理blk番号が未割り当て*/ } NandStatInfo; /*RTFS用 FATパラメータ*/ typedef struct { u32 device_capacity; //デバイス全体のサイズ(512Byte単位) u32 adjusted_device_capacity; u32 memory_capacity; //data areaのサイズ(512Byte単位) u32 adjusted_memory_capacity; //memory_capacityをシリンダ(heads*secptrack)の倍数に調整したサイズ(cylinders*heads*secptrackになる) u16 volume_cylinders; u16 heads; u16 secptrack; u16 cylinders; u16 SC; //sectors per cluster u16 BU; u16 RDE; //number of root dir entries(512 fix) u32 SS; //sector size(512 fix) u32 RSC; //reserved sector count(1 fix) u16 FATBITS; //16 or 32 u16 SF; //sectors per FAT u32 SSA; //sectors in system area u32 NOM; //sectors in master boot record u32 begin_sect; } NandSpec; /*---------------------------------------------------------------------------* API *---------------------------------------------------------------------------*/ BOOL nandRtfsAttach( int driveno, int partition); void nandInit( void); void nandEnable( NandPageCacheFormat* NandPageCache); void nandFormat( void); void nandReadSector( u32* dest, u32 logical_sector, u32 sector_count); void nandWriteSector( u32* src, u32 logical_sector, u32 sector_count); BOOL nandFlush( void); BOOL nandCheckMedia( void); #ifdef __cplusplus } /* extern "C" */ #endif #endif /*__NAND_H__*/