📄 sp_serialflashv1.asm
字号:
//////////////////////////////////////////////////////////////////
// File: sflash.asm
// Function: SERIAL Flash Interface with Serial Flash V1.1
// Writen by: Honda
// Modified by: Arthur Shieh
// Modify list:
// 2001/08/23 : first version
// 2002/05/26 : Modified to use with DVR by Arthur Shieh
// 2002/06/06 : API wrapping
// Note:
// 1. Modify the C_SIOCLOCK to speed up the serial IO bus
// 2. Modified the delay to shorten the waiting time for flash writing
//////////////////////////////////////////////////////////////////
.include hardware.inc;
.DEFINE C_SIOCLOCK 0x0010; // CPUCLOCK/8
.CODE
//////////////////////////////////////////////////////////////////
// Function: Send A Byte to Serial Flash
// Syntax: SP_SIOSendAByte(AddressLow,AddressHigh, data)
// c level public
// Used register: r1,r2,r3
//////////////////////////////////////////////////////////////////
.public _SP_SIOSendAByte;
_SP_SIOSendAByte: .PROC
F_SIOSendAByte:
PUSH BP,BP TO [SP];
BP = SP + 1;
r1=0x00C3+C_SIOCLOCK;
[P_SIO_Ctrl]=r1; // clk=CPUclk/8, 24 bit address ;write
R1 = [BP+3];
[P_SIO_Addr_Low]=r1; // input SFLASH low address
r1=r1 lsr 4; // right shift 8
r1=r1 lsr 4;
[P_SIO_Addr_Mid]=r1; // input SFLASH mid address
R1 = [BP+4]; // Port direction
r1=r1&0x0007; // input SFLASH hi address
[P_SIO_Addr_High]=r1;
[P_SIO_Start]=r1; // enable write mode
R1 = [BP+5];
[P_SIO_Data]=r1; // state to transmit data
L_WaitSIOSendReady:
r1=[P_SIO_Start];
test r1,0x0080
jne L_WaitSIOSendReady
call F_DelayPT // Delay necessary for the writing
call F_DelayPT
call F_DelayPT
call F_DelayPT
[P_SIO_Stop]=r1; //disable write mode
POP BP,BP FROM [SP];
retf;
.ENDP;
//////////////////////////////////////////////////////////////////
// Function: Read A Byte to Serial Flash
// Syntax: SP_SIOReadAByte(AddressLow, AddressHigh)
// c level public
// Used register: r1,r2,r3
// Return register: r1
//////////////////////////////////////////////////////////////////
.public _SP_SIOReadAByte;
_SP_SIOReadAByte: .PROC
F_SIOReadAByte:
PUSH BP,BP TO [SP];
[P_SIO_Stop]=r1; // disable read mode add at 0229
BP = SP + 1;
r1=0x0083;
[P_SIO_Ctrl]=r1; // clk=CPUclk/16, 24 bit address ;read
R1 = [BP+3];
[P_SIO_Addr_Low]=r1; // input SFLASH low address
r1=r1 lsr 4;
r1=r1 lsr 4;
[P_SIO_Addr_Mid]=r1; // input SFLASH mid address
R1 = [BP+4]; // Port direction
r1=r1&0x0007; // input SFLASH hi address
[P_SIO_Addr_High]=r1;
[P_SIO_Start]=r1; // enable read mode
r2=[P_SIO_Data]; // Clear SFLASH buffer
L_WaitSIOReadReady1:
r1=[P_SIO_Start];
test r1,0x0080
jne L_WaitSIOReadReady1
r1=[P_SIO_Data]; // Read exact Data
L_WaitSIOReadReady2: // Wait read stop
r2=[P_SIO_Start];
test r2,0x0080
jne L_WaitSIOReadReady2
[P_SIO_Stop]=r2; // disable read mode
POP BP,BP FROM [SP];
retf;
.ENDP;
//////////////////////////////////////////////////////////////////
// Function: Send A Word to Serial Flash
// Syntax: SP_SIOSendAData(AddressLow,AddressHigh, data) Address must be even
// c level public
// Used register: r1,r2,r3
//////////////////////////////////////////////////////////////////
.public _SP_SIOSendAWord;
_SP_SIOSendAWord: .PROC
F_SIOSendAWord:
PUSH BP,BP TO [SP];
BP = SP + 1;
// PUSH r1,r3 TO [SP];
r1=0x00C3+C_SIOCLOCK;
[P_SIO_Ctrl]=r1; // clk=CPUclk/8, 24 bit address ;write
R1 = [BP+3];
[P_SIO_Addr_Low]=r1; // input Sflash low address
r1=r1 lsr 4; // right shift 8
r1=r1 lsr 4;
[P_SIO_Addr_Mid]=r1; // input SFLASH mid address
R1 = [BP+4]; // Port direction
r1=r1&0x0007; // input SFLASH hi address
[P_SIO_Addr_High]=r1;
[P_SIO_Start]=r1; // enable write mode
R1 = [BP+5];
[P_SIO_Data]=r1; //start to transmit low byte
L_WaitSIOSendReadyLB:
r1=[P_SIO_Start];
test r1,0x0080
jne L_WaitSIOSendReadyLB
call F_DelayPT // Delay necessary for the writing
call F_DelayPT
call F_DelayPT
call F_DelayPT //
[P_SIO_Stop]=r1; // disable write mode
R1 = [BP+3];
r1+=1;
[P_SIO_Addr_Low]=r1; // input SFLASH low address
[P_SIO_Start]=r1; //enable write mode
r1=[BP+5];
r1=r1 lsr 4; // right shift 8
r1=r1 lsr 4;
[P_SIO_Data]=r1; //start to transmit high byte
L_WaitSIOSendReadyHB:
r1=[P_SIO_Start];
test r1,0x0080
jne L_WaitSIOSendReadyHB
call F_DelayPT //
call F_DelayPT //
call F_DelayPT
call F_DelayPT
[P_SIO_Stop]=r1; //disable write mode
// POP r1,r3 FROM [SP];
POP BP,BP FROM [SP];
retf;
.ENDP;
//////////////////////////////////////////////////////////////////
// Function: Read A Word from Serial Flash
// Syntax: SP_SIOReadAWord(AddressLow, AddressHigh)
// c level public
// Used register: r1,r2,r3,r4
// Return register: r1
//////////////////////////////////////////////////////////////////
.public _SP_SIOReadAWord;
_SP_SIOReadAWord: .PROC
F_SIOReadAWord:
PUSH BP,BP TO [SP];
BP = SP + 1;
// PUSH r2,r4 TO [SP]; modify by
r4=0x00FF;
R1 = [BP+3];
[P_SIO_Addr_Low]=r1; // input SFLASH low address
r1=r1 lsr 4;
r1=r1 lsr 4;
[P_SIO_Addr_Mid]=r1; // input SFLASH mid address
R1 = [BP+4]; // Port direction
r1=r1&0x0007; // input SFLASH hi address
[P_SIO_Addr_High]=r1;
// r1=0x0083+C_SIOCLOCK; // C_SIOCLOCK 0x0010
r1=0x0083; // C_SIOCLOCK 0x0010
[P_SIO_Ctrl]=r1; // clk=CPUclk/16, 24 bit address ;read
[P_SIO_Start]=r1; // enable read mode
////////
r2=[P_SIO_Data]; // Clear SFLASH buffer
////////
L_WaitSIOReadReady1LB:
r1=[P_SIO_Start];
test r1,0x0080
jne L_WaitSIOReadReady1LB
r2=r4&[P_SIO_Data]; // Read exact Low Byte
L_WaitSIOReadReady2LB: // Wait read stop
r1=[P_SIO_Start];
test r1,0x0080
jne L_WaitSIOReadReady2LB
r3=r4&[P_SIO_Data]; // Read exact High Byte
L_WaitSIOReadReady2HB: // Wait read stop
r1=[P_SIO_Start];
test r1,0x0080
jne L_WaitSIOReadReady2HB
[P_SIO_Stop]=r1; // disable read mode
r3=r3 lsl 4; //shift left 8
r1=r3 lsl 4;
r1|=r2; //return data
// POP r2,r4 FROM [SP];
POP BP,BP FROM [SP];
retf;
.ENDP;
///////////////////////////////////////////////////////////////
//Function : Page Erase for S_Flash (Page Size 1K)
// Syntax: SP_SIOPageErase(Page)
// Used register: r1,r2
///////////////////////////////////////////////////////////////
.public _SP_SIOPageErase;
_SP_SIOPageErase: .PROC
F_SIOPageErase:
PUSH BP,BP TO [SP];
BP = SP + 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -