/******************************************************************************/
//
// Name: 	NAND FLASH interface with ADSP-21161
//
/******************************************************************************

(C) Copyright 2005 - Analog Devices, Inc.  All rights reserved.

File Name:		delayfunc.asm

Date Modified:	20/06/05 - AV	-	Rev 1.0

Software:       VisualDSP++4.0

Purpose:		Demonstrate NAND FLASH Interface
				
*******************************************************************************/

.global CLE_delay_func;
.global ALE_delay_func;
.global POLL_delay_func;
.global POLL_delayErase_func;
.global AFTER_RD_WR_delay_func;
.global Delay_Before_Return_func;

.section/pm seg_pmco;
//===========================================================================
//DELAY FUCNTIONS
//===========================================================================

	//CLE_delay - This delay is needed since FLAGx is used to generate this signal
	
CLE_delay_func:
	lcntr = 100, do CLE_delay until lce;
	CLE_delay:  nop;
	RTS;
	
CLE_delay_func.end:

	//ALE_delay - This delay is needed since FLAGx is used to generate this signal
ALE_delay_func:	
	lcntr = 4000, do ALE_delay until lce;
	ALE_delay: nop;
	RTS;
ALE_delay_func.end:
	/*
	The (R/B#) signal - BUSY signal, is "LO" indicating busy for about 25uSec in case of READ
	250uSec in case of WRITE/PROGRAM and about 2mSec for block erase
	Since busy signal is NOT used in this code example, sufficient delay is 
	implemented using counters									*/

POLL_delay_func:	
	lcntr = 0xffff, do poll_delay until lce;
	poll_delay: nop;
	RTS;
POLL_delay_func.end:
	
POLL_delayErase_func:
	lcntr = 0x4fff, do poll_delay_erase until lce;
		lcntr = 0xffff, do poll_delay_erase_lp1 until lce;
		poll_delay_erase_lp1: nop;
	poll_delay_erase: nop;
	RTS;
POLL_delayErase_func.end:
	
//This delay is used after READ/WRITE operations are performed	
AFTER_RD_WR_delay_func:
	lcntr = 0xffff, do AFTER_RD_WR_delay until lce;
	AFTER_RD_WR_delay: nop;
	RTS;
AFTER_RD_WR_delay_func.end:
//This delay is used before returning from a function call
Delay_Before_Return_func:
	lcntr = 0x1fff, do Delay_Before_Return until lce;
	Delay_Before_Return: nop;
	RTS;Delay_Before_Return_func.end:
	
//==============End Of Delay Routines========================================
