head	1.3;
access;
symbols
	bg2_23:1.3
	bg2_22:1.3
	bg2_21:1.3
	bg2_20:1.3
	bg2_16:1.3
	bg2_15:1.2
	bg2_12:1.2
	bg2_07:1.2
	isorc2008_submission:1.1
	handbook_alpha_edition:1.1
	jtres2007_submission:1.1
	bg1_07:1.1
	bg1_06:1.1
	bg1_05:1.1
	TAL_101:1.1
	TAL_100:1.1
	jtres_submission:1.1
	wises06_submission:1.1
	lctes2006_submission:1.1
	rtgc_isorc2006:1.1.0.4
	isorc2006:1.1.0.2
	rtgc_paper:1.1
	bg1_00:1.1
	nohandle:1.1;
locks; strict;
comment	@# @;


1.3
date	2008.06.26.18.43.42;	author martin;	state Exp;
branches;
next	1.2;
commitid	5b214863e3594567;

1.2
date	2008.02.24.18.36.06;	author martin;	state Exp;
branches;
next	1.1;
commitid	39b447c1b90f4567;

1.1
date	2005.05.11.16.31.15;	author martin;	state Exp;
branches;
next	;
commitid	a1a428233464567;


desc
@@


1.3
log
@BG V 2.16 and back to original single CPU scheduler
@
text
@/*
  This file is part of JOP, the Java Optimized Processor
    see <http://www.jopdesign.com/>

  Copyright (C) 2001-2008, Martin Schoeberl (martin@@jopdesign.com)

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package util;

import com.jopdesign.sys.Const;
import com.jopdesign.sys.Native;
/**
*	Flash programmer (for AMD Am29LV040).
*		read and write data to address 0x80000.
*
*	timing:
*		byte program: typ 9 us max. 300 us
*		sector erase: typ 0.7 s + 0.6 s max 15 s + 20 s
*
*	asumes Timer.java is initialized
*/


public class Amd {

	public static int read(int addr) {

		return Native.rdMem(addr+0x80000);
	}

	/** program and handle timeout (without wd handling!) */

	public static void program(int addr, int data) {

		int i;

		addr += 0x80000;

//		Native.wr(0, Const.IO_INT_ENA);
		
		Native.wrMem(0xaa, 0x80555);
		Native.wrMem(0x55, 0x802aa);
		Native.wrMem(0xa0, 0x80555);
		Native.wrMem(data, addr);

		int j = Native.rd(Const.IO_US_CNT);
		j += 350;						// maximum 350 us timeout
		data &= 0xff;

		for (;;) {
			if (Native.rdMem(addr) == data) break;
			if (j-Native.rd(Const.IO_US_CNT) < 0) break;
		}
		
//		Native.wr(1, Const.IO_INT_ENA);

	}

	/**
	*	erase one sector and handle wd.
	*/
	public static boolean erase(int addr) {

		int i;

		addr += 0x80000;

//		Native.wr(0, Const.IO_INT_ENA);
		
		Native.wrMem(0xaa, 0x80555);
		Native.wrMem(0x55, 0x802aa);
		Native.wrMem(0x80, 0x80555);
		Native.wrMem(0xaa, 0x80555);
		Native.wrMem(0x55, 0x802aa);
		Native.wrMem(0x30, addr);

//		Native.wr(1, Const.IO_INT_ENA);

		for (i=0; i<400; ++i) {					// maximum 40 s timeout
			joprt.RtThread.sleepMs(100);
Dbg.wr('.');
			Timer.wd();
			if (Native.rdMem(addr) == 0xff) return true;
		}
		return false;
	}
}
@


1.2
log
@JOP goes GPL
@
text
@d52 1
a52 1
		Native.wr(0, Const.IO_INT_ENA);
d68 1
a68 1
		Native.wr(1, Const.IO_INT_ENA);
d81 1
a81 1
		Native.wr(0, Const.IO_INT_ENA);
d90 1
a90 1
		Native.wr(1, Const.IO_INT_ENA);
@


1.1
log
@resync with current development
@
text
@d1 20
@

