Nand Flash 以hynix_Hy27ss(08/16)121M為例
\ Ndf_Variable.f
---------------------------------------------------------------
\ System共用
\ true -1
\ false 0
defer pc! ' c! is pc! \ 當I/O 非 memory MAP or 模擬晶片動作時 修改
defer pc@ ' c@ is pc@ \ 當I/O 非 memory MAP or 模擬晶片動作時 修改
defer pw! ' w! is pw! \ 當I/O 非 memory MAP or 模擬晶片動作時 修改
defer pw@ ' w@ is pw@ \ 當I/O 非 memory MAP or 模擬晶片動作時 修改
0x01 constant bit0
\ Ndf共用變數
0 variable Ndf_Badr
0 variable Ndf_Buf
0 variable Ndf_Flag
0 variable Ndf_Len
0 variable Ndf_Adr0
0 variable Ndf_Adr1
0 variable Ndf_Adr2
0 variable Ndf_Adr3
\ Ndf_hynix_Hy27ss(08/16)121M.f
-----------------------------------------------------------
\ hynix Hy27ss(08/16)121M
\ Adr
0x00 constant Ndf_Data_Adr
0x01 constant Ndf_Command_Adr
0x02 constant Ndf_Address_Adr
\ code
0x00 constant Ndf_Area_A_Code
0x01 constant Ndf_Area_B_Code
0x50 constant Ndf_Area_C_Code
0x90 constant Ndf_Electronic_Signature_Code
0x70 constant Ndf_Status_Register_Code
0x80 constant Ndf_Page_Program0_Code
0x80 constant Ndf_Page_Program1_Code
0x00 constant Ndf_Copy_Back_Program0_Code
0x8A constant Ndf_Copy_Back_Program1_Code
0x10 constant Ndf_Copy_Back_Program2_Code
0x60 constant Ndf_Block_Erase0_Code
0xD0 constant Ndf_Block_Erase1_Code
0xFF constant Ndf_Reset_Code
\ time
0xFF constant Ndf_Wait_Time
0xFF constant Ndf_Page_Program_Wait_Time
0xFF constant Ndf_Block_Erase_Wait_Time
0xFF constant Ndf_Copy_Back_Program_Waite_Time
\ Ndf.f
------------------------------------------------------------------------
\ fload Ndf_Variable.f
\ folad Ndf_hynix_Hy27ss(08/16)121M.f
\ 程序定義
: Ndf_Wait( --- )
Ndf_Wait_Time 0 do loop
;
: Ndf_Page_Program_Wait
Ndf_Page_Program_Wait_Time 0 do loop
;
: Ndf_Block_Erase_Wait
Ndf_Block_Erase_Wait_Time 0 do loop
;
: Ndf_Copy_Back_Program_Waite
Ndf_Copy_Back_Program_Waite_Time 0 do loop
;
: Ndf_Adr_resolution ( Adr --- )
>r
r@ 0x7f and Ndf_Adr0 !
r@ 8 r-shift 0x7f and Ndf_Adr1 !
r@ 16 r-shift 0x7f and Ndf_Adr2 !
r> 24 r-shift 0x7f and Ndf_Adr3 !
;
: Ndf_Check ( Badr --- true|false )
Ndf_Badr !
Ndf_Status_Register_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Nand_Data_Adr Ndf_Badr @ + pw@ bit0 and 0=
if
-1
else
0
then
\ Ndf_SR ::=
\ Bit NAME Logic Level Definition
\ SR7 Write Protection
\ '1' Not Protected
\ '0' Protected
\ SR6 Program/Erase/Read Controller
\ '1' P/E/R C Inactive, device ready
\ '0' P/E/R C active, device busy
\ SR5 Program/ Erase/Read Controller
\ '1' P/E/R C inactive, device ready
\ '0' P/E/R C active, device busy
\ SR4, SR3, SR2 Reserved Don't Care
\ SR0 Generic Error
\ '1' Error - Operation failed
\ '0' No Error - Operation successful
;
: Ndf_Reset ( Badr --- )
Ndf_Badr !
Ndf_Reset_Code Ndf_Command_Adr Ndf_Badr @ + pc!
;
: Ndf_Block_Erase ( adr Badr --- true|false)
Ndf_Badr !
Ndf_Block_Erase0_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Adr_resolution
Ndf_Adr0 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr1 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr2 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr3 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Waite
Ndf_Block_Erase1_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Block_Erase_Wait
Ndf_Badr @ Ndf_Check
;
: Ndf_Copy_Back_Program ( Dadr Sadr Badr --- true|false)
Ndf_Badr !
Ndf_Copy_Back_Program0_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Adr_resolution
Ndf_Adr0 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr1 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr2 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr3 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Waite
Ndf_Copy_Back_Program1_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Adr_resolution
Ndf_Adr0 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr1 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr2 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr3 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Waite
Ndf_Copy_Back_Program2_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Copy_Back_Program_Waite
Ndf_Badr @ Ndf_Check
;
: Ndf_Page_Program ( dadr sadr len Badr --- true|false )
Ndf_Badr !
Ndf_len !
Ndf_Buf !
Ndf_Page_Program0_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Adr_resolution
Ndf_Adr0 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr1 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr2 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr3 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Waite
Ndf_Len @ 0 do
Ndf_Buf @ w@ Nand_Data_Adr Ndf_Badr @ + pc!
Ndf_Buf @ 1 + Ndf_Buf !
Ndf_Waite
loop
Ndf_Page_Program1_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Page_Program_Waite
Ndf_Badr @ Ndf_Check
;
: Ndf_Random_Read ( adr Badr --- data )
Ndf_Badr !
Ndf_Area_A_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Adr_resolution
Ndf_Adr0 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr1 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr2 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr3 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Waite
Nand_Data_Adr Ndf_Badr @ + pw@
Ndf_Waite
;
: Ndf_Read_Area_A ( sadr Dadr len Badr --- )
Ndf_Badr !
Ndf_len !
Ndf_Buf !
Ndf_Area_A_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Adr_resolution
Ndf_Adr0 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr1 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr2 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr3 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Waite
Ndf_len @ 0 do
Nand_Data_Adr Ndf_Badr @ + pw@ Ndf_Buf @ pw!
Ndf_Buf @ 1 + Ndf_Buf !
Ndf_Waite
loop
;
: Ndf_Read_Area_C ( sadr Dadr len Badr --- )
Ndf_Badr !
Ndf_len !
Ndf_Buf !
Ndf_Area_C_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Ndf_Adr_resolution
Ndf_Adr0 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr1 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr2 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Adr3 Nand_Address_Adr Ndf_Badr @ + pc!
Ndf_Waite
Ndf_len @ 0 do
Nand_Data_Adr Ndf_Badr @ + pw@ Ndf_Buf @ pw!
Ndf_Buf @ 1 + Ndf_Buf !
Ndf_Waite
loop
;
: Ndf_Read_Electronic_Signature ( Badr --- Manufacture_Code
Device_Code )
Ndf_Badr !
Ndf_Electronic_Signature_Code Ndf_Command_Adr Ndf_Badr @ + pc!
Nand_Data_Adr Ndf_Badr @ + pw@
Nand_Data_Adr Ndf_Badr @ + pw@
;