|
Message
From: cvs at opencores.org<cvs@o...>
Date: Sat Jan 19 12:51:39 CET 2008
Subject: [cvs-checkins] MODIFIED: jop ...
Date: 00/08/01 19:12:51 Modified: jop/java/target/src/app/sdcard BootSec.java DirEntry.java FatTest.java FileInputStream.java FileOutputStream.java Log: new version of SD-card interface Revision Changes Path 1.2 jop/java/target/src/app/sdcard/BootSec.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/app/sdcard/BootSec.java.diff?r1=1.1&r2=1.2 (In the diff below, changes in quantity of whitespace are not shown.) Index: BootSec.java =================================================================== RCS file: /cvsroot/martin/jop/java/target/src/app/sdcard/BootSec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- BootSec.java 13 Jan 2008 22:05:43 -0000 1.1 +++ BootSec.java 19 Jan 2008 11:51:39 -0000 1.2 @@ -1,5 +1,7 @@ package sdcard; +// Boot Sector Struct + public class BootSec { public static int[] BS_jmpBoot = new int[3]; 1.2 jop/java/target/src/app/sdcard/DirEntry.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/app/sdcard/DirEntry.java.diff?r1=1.1&r2=1.2 (In the diff below, changes in quantity of whitespace are not shown.) Index: DirEntry.java =================================================================== RCS file: /cvsroot/martin/jop/java/target/src/app/sdcard/DirEntry.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- DirEntry.java 13 Jan 2008 22:05:43 -0000 1.1 +++ DirEntry.java 19 Jan 2008 11:51:39 -0000 1.2 @@ -1,5 +1,8 @@ package sdcard; + +// Directory Entry Struct + public class DirEntry { public static int[] DIR_Name = new int[11]; //8 chars filename 1.3 jop/java/target/src/app/sdcard/FatTest.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/app/sdcard/FatTest.java.diff?r1=1.2&r2=1.3 (In the diff below, changes in quantity of whitespace are not shown.) Index: FatTest.java =================================================================== RCS file: /cvsroot/martin/jop/java/target/src/app/sdcard/FatTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- FatTest.java 15 Jan 2008 13:13:50 -0000 1.2 +++ FatTest.java 19 Jan 2008 11:51:39 -0000 1.3 @@ -8,46 +8,14 @@ import com.jopdesign.sys.*; -// import dsp.*; -/** - * @author Martin Schoeberl (martin@j...) - * - */ public class FatTest { - // #################################################################################### - // AC97 DEF Section BEGIN - // #################################################################################### - - public static final int CSR = 0x0 / 4; // Main Configuration/Status - // Register - public static final int OCC0 = 0x4 / 4; // RO Output Channel Configuration - // Register 0 - public static final int OCC1 = 0x8 / 4; // Output Channel Configuration - // Register 1 - public static final int ICC = 0xc / 4; // Input Channel Configuration - // Register - public static final int CRAC = 0x10 / 4; // Codec Register Access Command - public static final int INTM = 0x14 / 4; // Interrupt Mask - public static final int INTS = 0x18 / 4; // Interrupt Status Register
- public static final int RES = 0x1c;
- public static final int OCH0 = 0x20 / 4; // Output Channel 0
- public static final int OCH1 = 0x24 / 4; // Output Channel 1
- public static final int OCH2 = 0x28 / 4; // Output Channel 2
- public static final int OCH3 = 0x2c / 4; // Output Channel 3
- public static final int OCH4 = 0x30 / 4; // Output Channel 4
- public static final int OCH5 = 0x34 / 4; // Output Channel 5
- public static final int ICH0 = 0x38 / 4; // Input Channel 0
- public static final int ICH1 = 0x3c / 4; // Input Channel 1
- public static final int ICH2 = 0x40 / 4; // Input Channel 2
- public static final int MSK_RD_DONE = 0x01;
- public static final int MSK_WR_DONE = 0x02;
// ####################################################################################
- // AC97 DEF Section END
+ // FileIn/OutputStream def Begin
// ####################################################################################
public static FatItS FatInterface = new FatItS();
@@ -56,93 +24,51 @@
public static FileInputStream FIS;
// ####################################################################################
- // AC97 Section Begin
+ // FileIn/OutputStream def End
// ####################################################################################
- public static int rd(int wb_reg) {
- return Native.rdMem(Const.WB_AC97 + wb_reg);
+ public static void read_test() {
+
+ byte[] k = new byte[400];
+ int y = 0;
+
+
+
+ // 1 Byte read
+ System.out.print((char) FIS.read());
+ System.out.print((char) FIS.read());
+ System.out.print((char) FIS.read());
+
+
+ // Read till array full or EOF
+ y = FIS.read(k);
+ int h = 0;
+
+ while (y != -1) {
+ for (int g = 0; g < y; g++) {
+
+ System.out.print((char) k[g]);
+ // FatInterface.printf(k[g],'s');
}
- public static void wr(int wb_reg, int val) {
+ h++;
- Native.wrMem(val, Const.WB_AC97 + wb_reg);
+ // Read 300 byte from actual offset
+ y = FIS.read(k, 0, 300);
}
- public static int codecRd(int reg) {
-
- wr(CRAC, 0x80000000 + (reg << 16));
- while ((rd(INTS) & MSK_RD_DONE) == 0) {
- ; // busy wait till value read
- }
- return rd(CRAC) & 0xffff;
- }
-
- public static void codecWr(int reg, int val) {
-
- wr(CRAC, (reg << 16) + val);
- while ((rd(INTS) & MSK_WR_DONE) == 0) {
- ; // busy wait till write done
- }
- }
-
- public static void init_ac97() {
-
- //
- // check status register and force a reset
- //
- System.out.println("CSR=" + rd(CSR));
- wr(CSR, 1); // cold reset the AC97
- System.out.println("CSR=" + rd(CSR));
- RtThread.sleepMs(10);
- System.out.println("CSR=" + rd(CSR));
- wr(CSR, 2); // resume the AC97
- RtThread.sleepMs(10);
- System.out.println("CSR=" + rd(CSR));
-
- //
- // enable stereo in and out in the AC97 interface
- //
- System.out.println("OCC0=" + rd(OCC0));
- wr(OCC0, 0x0101); // enable front left and right output
- // wr(OCC0, 0x0909); // enable front left and right output
- System.out.println("OCC0=" + rd(OCC0));
- // wr(ICC, 0x2121); // enable left and right input
- wr(ICC, 0x02323); // enable left and right input
- System.out.println("ICC=" + rd(ICC));
-
- //
- // read some vendor information
- //
- System.out.println("VENDOR ID=" + codecRd(0x7c));
- System.out.println("VENDOR version=" + codecRd(0x7e));
- System.out.println("Imput sampling rate=" + codecRd(0x32));
- //
- // do the initilization
- //
- System.out.println("MASTER VOLUME=" + codecRd(0x02));
- codecWr(0x02, 0x0000); // unmute master volume
- System.out.println("MASTER VOLUME=" + codecRd(0x02));
-
- // codecWr(0x10, 0x0808); // enable line input
- codecWr(0x18, 0x0808); // PCM-out volume
- codecWr(0x1a, 0x0404); // select line record
- codecWr(0x1c, 0x000); // record gain
- codecWr(0x2A, 0x0605);
-
- System.out.println("EXT Reg=" + codecRd(0x28));
- // codecWr(0x20, 0x0000); // local loopback
- // codecWr(0x64, 0x0000); // mixer adc, input gain
- codecWr(0x32, 0x5622); // imput samplig Rate
- System.out.println("Imput sampling rate=" + codecRd(0x32));
+ for (int g = 0; g < y; g++) {
+
+ System.out.print((char) k[g]);
+ // FatInterface.printf(k[g],'s');
+ }
}
- // ####################################################################################
- // AC97 Section END
- // ####################################################################################
- public static void test() {
+
+ public static void write_test() {
int fj = 0;
byte[] tes = new byte[518];
/*
@@ -153,86 +79,94 @@
*/
for (fj = 0; fj < 512; fj++) {
- tes[fj] = (byte) 'O';
+ tes[fj] = (byte) 'F';
}
tes[512] = 0x0d;
tes[513] = 0x0a;
tes[514] = 0x0;
+
+ // write till tes[x]==0
FOS.write(tes);
- for (fj = 0; fj < 512; fj++) {
- FOS.write((int) 'K');
- }
- FOS.write((int) 0x0D);
- FOS.write((int) 0x0A);
+/* 512* 1Byte write very very slow
for (fj = 0; fj < 512; fj++) {
- FOS.write((int) '-');
+
+ // 512* 1Byte write
+ FOS.write((int) 'A');
}
- FOS.write((int) 0x0D);
- FOS.write((int) 0x0A);
+ FOS.write((int) 0x0d);
+ FOS.write((int) 0x0a);
+*/
+
for (fj = 0; fj < 512; fj++) {
- FOS.write((int) '4');
+ tes[fj] = (byte) 'A';
}
- FOS.write((int) 0x0D);
- FOS.write((int) 0x0A);
+ // write 514 Bytes with offset 0
+ FOS.write(tes,0,512);
+
+
+ // 1 Byte write
+ FOS.write((int) 0x0d);
+ FOS.write((int) 0x0a);
+
+
for (fj = 0; fj < 512; fj++) {
- FOS.write((int) '7');
+ tes[fj] = (byte) 'T';
}
- FOS.write((int) 0x0D);
- FOS.write((int) 0x0A);
+ tes[512] = 0x0d;
+ tes[513] = 0x0a;
+
- byte[] tes1 = new byte[518];
+ // write 514 Bytes with offset 0
+ FOS.write(tes,0,514);
for (fj = 0; fj < 512; fj++) {
- tes1[fj] = (byte) 'F';
+ tes[fj] = (byte) '1';
}
- tes1[512] = 0x0D;
- tes1[513] = 0x0A;
+ tes[512] = 0x0d;
+ tes[513] = 0x0a;
- FOS.write(tes1, 3820, 513);
+ // write 514 Bytes with offset 0
+ FOS.write(tes,0,514);
+
+ for (fj = 0; fj < 512; fj++) {
+ tes[fj] = (byte) '6';
}
- public static void run() {
+ tes[512] = 0x0d;
+ tes[513] = 0x0a;
- int left, right, i, j, v1, v2, x = 1;
- int[] Buffer = new int[520];
- int[] name = new int[13];
- FatInterface.fat_cluster_data_store();
+ // write 514 Bytes with offset 0
+ FOS.write(tes,0,514);
- int CMD[] = new int[6];
+ FOS.write((int) 0x0d);
+ FOS.write((int) 0x0a);
+ FOS.write((int) 'E');
+ FOS.write((int) 'N');
+ FOS.write((int) 'D');
- // System.out.println("volume_boot_record_addr="+fat_addr(Buffer));
- name[0] = 'F';
- name[1] = 'I';
- name[2] = 'C';
- name[3] = 'H';
- name[4] = '2';
- name[5] = '2';
- name[6] = '2';
- name[7] = '2';
- name[8] = 'T';
- name[9] = 'X';
- name[10] = 'T';
- name[11] = 0;
- name[12] = 0;
- for (int a = 0; a < 515; a++) {
- Buffer[a] = 0;
}
+
+
+ public static void run() {
+
+ int i, j, x = 1;
+ int[] Buffer = new int[520];
int Clustervar;
int[] Dir_Attrib = new int[1];
Dir_Attrib[0] = 0;
@@ -240,58 +174,57 @@
long[] Size = new long[1];
Size[0] = 0;
- String namea = new String("TUCME.TXT");
-
- System.out.println(FOS.FileOutputStream(namea));
- namea = null;
- System.out.println("FOStream_offset_from_start[0]"
- + FOS.FOStream_offset_from_start[0]);
-
- test();
+ // needed for FatInterface.printf_fat(0);
+ //FatInterface.fat_cluster_data_store();
- byte[] k = new byte[400];
- int y = 0;
+/* "FAT-TEST.TXT" -> /FAT-TEST.TXT
+* "TEST/FAT-TEST.TXT" -> /TEST/FAT-TEST.TXT
+*
+* Do not start the filename string with "/" !
+*/
+
+ String namea = new String("FAT-TEST.TXT");
+ System.out.print("Open File ");
+ System.out.print(namea);
+ System.out.print(" for write = ");
+ System.out.println(FOS.FileOutputStream(namea));
namea = null;
- System.out.println("danach");
+ System.out.println();
+ System.out.println("Start write_test();");
+ write_test();
+ System.out.println("Finished write_test();");
+ System.out.println();
+ System.out.println();
+ //FatInterface.fat_load_reset();
- String nameb = new String("TUCME.TXT");
- FatInterface.fat_load_reset();
-
- System.out.println("danach");
+ System.out.println();
+ String nameb = new String("FAT-TEST.TXT");
+ System.out.print("Open File ");
+ System.out.print(nameb);
+ System.out.print(" for read = ");
System.out.println(FIS.FileInputStream(nameb));
nameb = null;
- y = 0;
- y = FIS.read(k, 0, 300);
- int h = 0;
-
- while ((y == 300)) {
- for (int g = 0; g < y; g++) {
- // FatInterface.printf(k[g],'s');
- }
-
- h++;
- y = FIS.read(k, 0, 300);
- }
-
- for (int g = 0; g < y; g++) {
-
- // FatInterface.printf(k[g],'s');
- }
-
- System.out.println("FIS.FIStream_startcluster[0]"
- + FIS.FIStream_startcluster[0]);
- System.out.println("FOS.FOStream_startcluster[0]"
- + FOS.FOStream_startcluster[0]);
-
- // FatInterface.printf_fat (FOStream_startcluster[0]);
-
- System.out.println("Directory");
- // for (int a = 1;a < 240;a++)
+ System.out.println();
+ System.out.println("Start read_test();");
+ System.out.println();
+ System.out.println();
+ read_test();
+ System.out.println();
+ System.out.println();
+ System.out.println("Finished read_test();");
+ System.out.println();
+
+
+ System.out.println();
+ System.out.println();
+ System.out.println(" print Directory-listing of write file dir");
+ System.out.println();
+ System.out.println();
int[] Buf2 = new int[513];
@@ -312,146 +245,39 @@
FatInterface.printf(Buf2, 's');
}
- System.out.println("Directory Ende");
+ System.out.println("Directory Print End");
- FatInterface.printf_fat(0);
- /*
- * int[] Clustervar2= new int[1];
- *
- *
- * FatInterface.fat_find_free_offset(0, Clustervar2, Buffer);
- * System.out.println("FatInterface.fat_find_free_offset
- * ="+Clustervar2[0]);
- *
- * //Lade Cluster für das index.htm File in den Speicher Clustervar =
- * 0;//suche im Root Verzeichnis Clustervar2[0] =Clustervar; if
- * (FatInterface.fat_search_file(name,Clustervar2,Size,Dir_Attrib,Buffer) ==
- * 1) { System.out.println("File Found!"); //usart_write("\nFile
- * Found!!\n\n"); //Lese File und gibt es auf der seriellen
- * Schnittstelle aus
- *
- * for (int a = 0;a<512;a=a+4) { Buffer[a]='O'; Buffer[a+1]='r';
- * Buffer[a+2]='g'; Buffer[a+3]='l'; }
- *
- * FatInterface.fat_write_file ( Clustervar2[0],//Angabe des
- * Startclusters vom File Buffer, //Workingbuffer 0) ;
- *
- *
- * int wieoft=0; long tempsize; int end; /* //
- * FatInterface.printf_fat(0); FatInterface.printf_fat(Clustervar2[0]);
- *
- * FatInterface.fat_add_cluster_to_end_of_chain(Clustervar2[0]);
- * // FatInterface.printf_fat(0);
- * FatInterface.printf_fat(Clustervar2[0]);
- *
- * FatInterface.fat_set_dir_ent(0,0, 1536,32, Buffer) ;
- *
- * Clustervar2[0] =Clustervar;
- * FatInterface.fat_search_file(name,Clustervar2,Size,Dir_Attrib,Buffer);
- * System.out.println("Size = "+Size[0]+"Cluster = "+Clustervar2[0]+"
- * DirA = "+Dir_Attrib[0]+" FileName = ");
- *
- *
- * for (int a = 0;a<500;a=a+4) { Buffer[a]='O'; Buffer[a+1]='r';
- * Buffer[a+2]='g'; Buffer[a+3]='l'; }
- *
- *
- * FatInterface.fat_write_file ( Clustervar2[0],//Angabe des
- * Startclusters vom File Buffer, //Workingbuffer 0) ;
- *
- * FatInterface.fat_write_file ( Clustervar2[0],//Angabe des
- * Startclusters vom File Buffer, //Workingbuffer 1) ;
- *
- * for (int a = 0;a<500;a=a+4) { Buffer[a]='F'; Buffer[a+1]='i';
- * Buffer[a+2]='C'; Buffer[a+3]='h'; }
- *
- * FatInterface.fat_write_file ( Clustervar2[0],//Angabe des
- * Startclusters vom File Buffer, //Workingbuffer 2) ;
- *
- *
- * FatInterface.fat_read_file (Clustervar2[0],Buffer,0);
- *
- *
- *
- * for (int a = 0;a<512;a++) { //FatInterface.printf(Buffer[a],'x'); //
- * System.out.println(); FatInterface.printf(Buffer[a],'s');
- * //System.out.println(); } FatInterface.fat_read_file
- * (Clustervar2[0],Buffer,1);
- *
- * System.out.println();
- *
- * for (int a = 0;a<512;a++) { //FatInterface.printf(Buffer[a],'x'); //
- * System.out.println(); FatInterface.printf(Buffer[a],'s'); //
- * System.out.println(); } // System.out.println('a'); // for (int a =
- * 0;a<500;a=a+4) // { // Buffer[a]='O'; // Buffer[a+1]='r'; //
- * Buffer[a+2]='g'; // Buffer[a+3]='l'; // } //System.out.println('a');
- * //for(;;) //{ //for (int u=1;u<2000;u++) // { //
- * FatInterface.fat_write_file ( Clustervar2[0],//Angabe des
- * Startclusters vom File // Buffer, //Workingbuffer // u) ; // } //}
- * // FatInterface.fat_load_cluster_st = -1; //
- * FatInterface.fat_load_cluster_tmp = -1; //
- * FatInterface.fat_load_a_tmp=0;
- */
- // }
- /*
- * else { System.out.println("File not found"); }
- */
- /*
- * Clustervar=Clustervar2[0];
- *
- *
- *
- *
- *
- *
- *
- * for (i=0; i<10; ++i) { // flush input FIFOs rd(ICH0); rd(ICH1);
- * rd(INTS); }
- *
- * i = 0; int u=0;
- *
- * System.out.println("Clustervar="+Clustervar);
- * System.out.println("cluster_size="+cluster_size);
- * System.out.println("cluster_offset="+cluster_offset);
- * System.out.println("volume_boot_record_addr="+volume_boot_record_addr);
- *
- * int status=0;
- *
- * for (u=2;u<35;u++) { int b; /* x=0; for (x=0;x<512;x=x+64) { //
- * busy wait for input samples for (;;) { //System.out.println(1);
- * status =Native.rdMem(Const.WB_AC97+INTS); if ((status&0x2d00000)!=0)
- * break; // Interupt 8 Samples anwesend & clr interupt }
- *
- *
- * for (int n=0;n<64;n=n+4) { left = Native.rdMem(Const.WB_AC97+ICH0);
- * right = Native.rdMem(Const.WB_AC97+ICH1); // if
- * ((Native.rdMem(Const.WB_AC97+INTS)&0x1200000)!=0) { //
- * System.out.println(2); // continue; // }
- *
- * Buffer[x+n+0]=left&0x000000FF; Buffer[x+n+1]=(left&0x0000FF00)>>8;
- * Buffer[x+n+2]=(left>>16)&0x00FF; Buffer[x+n+3]=(left>>24)&0x00FF; }
- *
- * //Native.wrMem(left, Const.WB_AC97+OCH0); //Native.wrMem(right,
- * Const.WB_AC97+OCH1); }
- */
- // FatInterface.fat_write_file ( Clustervar,//Angabe des Startclusters
- // vom File
- // Buffer, //Workingbuffer
- // u) ;
- // System.out.println("MMC write end");
- // }
+/*
+ System.out.println();
+ System.out.println();
+ System.out.println(" Print first 512 Bytes of FAT");
+ System.out.println();
+ System.out.println();
+ FatInterface.printf_fat(0);
+*/
+
}
+
public static void main(String[] args) {
- //for(;;)
- //{
- init_ac97();
- System.out.println("MmcInterface.mmc_init=" + MmcInterface.mmc_init());
- //}
+
+ System.out.println("MmcInterface.mmc_init start" );
+
+ if ( MmcInterface.mmc_init() != 0)
+ {
+ System.out.println("MmcInterface.mmc_init failed or no Card connected" );
+ }
+
+ else
+ {
+ System.out.println("MmcInterface.mmc_init done" );
+ System.out.println();
+ System.out.println();
run();
}
+ }
}
1.2 jop/java/target/src/app/sdcard/FileInputStream.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/app/sdcard/FileInputStream.java.diff?r1=1.1&r2=1.2
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FileInputStream.java
===================================================================
RCS file: /cvsroot/martin/jop/java/target/src/app/sdcard/FileInputStream.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- FileInputStream.java 13 Jan 2008 22:05:43 -0000 1.1
+++ FileInputStream.java 19 Jan 2008 11:51:39 -0000 1.2
@@ -13,12 +13,28 @@
public static FatMmc MmcInterface = new FatMmc();
+ public static int[] FIStream_Buffer = new int [512];
+ public static long[] FIStream_size = new long [1];
+ public static int[] FIStream_startcluster = new int [1];
+ public static long[] FIStream_offset_from_start = new long [1];
//####################################################################################
// FileInputStream Section Begin
//####################################################################################
+
+
+
+/*****************************************************************
+* public FileInputStream(String name)
+* Creates a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system.
+*
+* If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then ???????????????????????
+*
+* Parameters:
+* name Directories and files are seperated with "/". Do not write the leading "/" in the filename string.
+*****************************************************************/
public static boolean FileInputStream(String file)
{
int [] Clustervar = new int[1];
@@ -150,6 +166,18 @@
}
+
+
+/*****************************************************************
+* public int read(byte[] b)
+* Reads up to b.length bytes of data from this input stream into an array of bytes.
+* This method blocks until some input is available.
+*
+* Parameters:
+* b - the buffer into which the data is read.
+* Returns:
+* the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.
+*****************************************************************/
public static int read ()
{
int block;
@@ -157,7 +185,7 @@
if (FIStream_offset_from_start[0] >= FIStream_size[0])
{
- return (0xFFFFFFFF);
+ return (-1);
}
@@ -173,13 +201,32 @@
}
+
+
+/****************************************************************
+* public int read(byte[] b)
+* Reads up to b.length bytes of data from this input stream into an array of bytes.
+* This method blocks until some input is available.
+*
+* Parameters:
+* b - the buffer into which the data is read.
+* Returns:
+* the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.
+****************************************************************/
public static int read (byte b[])
{
int block=0xFFFFFFFF, block_alt;
int byte_count, i=0;
-while (! (FIStream_offset_from_start[0] >= FIStream_size[0]))
+
+if (FIStream_offset_from_start[0] >= FIStream_size[0])
+{
+ return (-1);
+}
+
+
+while (! (FIStream_offset_from_start[0] >= FIStream_size[0]) && (i<b.length))
{
@@ -204,11 +251,35 @@
}
+
+
+
+/****************************************************************
+* public int read(byte[] b,
+* int off,
+* int len)
+* Reads up to len bytes of data from this input stream into an array of bytes.
+* This method blocks until some input is available.
+*
+* Parameters:
+* b - the buffer into which the data is read.
+* off - the start offset of the data.
+* len - the maximum number of bytes read.
+* Returns:
+* the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.
+****************************************************************/
public static int read (byte b[], int off, int len)
{
-if ((FIStream_offset_from_start[0]+off) > FIStream_size[0])
+
+
+if (FIStream_offset_from_start[0] >= FIStream_size[0])
{
- return (0);
+ return (-1);
+}
+
+if ((FIStream_offset_from_start[0]+off) >= FIStream_size[0])
+{
+ return (-1);
}
FIStream_offset_from_start[0] =FIStream_offset_from_start[0]+off;
@@ -218,7 +289,7 @@
int byte_count, i=0;
-while ( (! (FIStream_offset_from_start[0] >= FIStream_size[0])) && (i<len))
+while ( (! (FIStream_offset_from_start[0] >= FIStream_size[0])) && (i<len) && (i<b.length))
{
@@ -244,33 +315,58 @@
}
+/*****************************************************************
+* public long skip(long n)
+* Skips over and discards n bytes of data from the input stream.
+* The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0.
+* The actual number of bytes skipped is returned.
+*
+*
+* Parameters:
+* n - the number of bytes to be skipped.
+* Returns:
+* the actual number of bytes skipped.
+***************************************************************/
+
public static long skip (long n)
{
+long k=0;
-if ((FIStream_offset_from_start[0]+n) > FIStream_size[0])
+if (FIStream_offset_from_start[0] >=FIStream_size[0])
{
return (0);
}
+
+if ((FIStream_offset_from_start[0]+n) > FIStream_size[0])
+{
+ k= FIStream_size[0] - FIStream_offset_from_start[0];
+ FIStream_offset_from_start[0]=FIStream_offset_from_start[0]+k;
+ return (k);
+}
+
FIStream_offset_from_start[0] =FIStream_offset_from_start[0]+n;
-return (FIStream_offset_from_start[0]);
+return (n);
}
+/**************************************************************
+* public void close()
+ * Closes this file input stream and releases any system resources associated with the stream.
+**************************************************************/
+
public static void close()
{
FIStream_Buffer =null;
FIStream_size =null;
FIStream_startcluster =null;
FIStream_offset_from_start =null;
+FatInterface =null;
+MmcInterface =null;
}
-public static int[] FIStream_Buffer = new int [512];
-public static long[] FIStream_size = new long [1];
-public static int[] FIStream_startcluster = new int [1];
-public static long[] FIStream_offset_from_start = new long [1];
//####################################################################################
// FileOutputStream Section End
//####################################################################################
1.2 jop/java/target/src/app/sdcard/FileOutputStream.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/app/sdcard/FileOutputStream.java.diff?r1=1.1&r2=1.2
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FileOutputStream.java
===================================================================
RCS file: /cvsroot/martin/jop/java/target/src/app/sdcard/FileOutputStream.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- FileOutputStream.java 13 Jan 2008 22:05:43 -0000 1.1
+++ FileOutputStream.java 19 Jan 2008 11:51:39 -0000 1.2
@@ -11,7 +11,13 @@
public static FatItS FatInterface = new FatItS();
public static FatMmc MmcInterface = new FatMmc();
-
+ public static int[] FOStream_Buffer = new int [512];
+ public static long[] FOStream_size = new long [1];
+ public static int[] FOStream_startcluster = new int [1];
+ public static long[] FOStream_offset_from_start = new long [1];
+ public static int[] FOStream_Filename = new int [13];
+ public static int FOStream_Dir_Attr;
+ public static int FOStream_Dir_cluster;
@@ -20,7 +26,19 @@
// FileOutputStream Section Begin
//####################################################################################
-public static boolean FileOutputStream(String file)
+
+
+/******************************************************************
+* public FileOutputStream(String file)
+* Creates an output file stream to write to the file with the specified name.
+*
+* If the file exists but is a directory rather than a regular file, does not exist but cannot be created,
+* or cannot be opened for any other reason then a ?????????????????????????????.
+*
+* Parameters:
+* file - Directories and files are seperated with "/". Do not write the leading "/" in the filename string.
+******************************************************************/
+public static boolean FileOutputStream(String file, boolean append)
{
int [] Clustervar = new int[1];
long [] Size = new long[1];
@@ -128,8 +146,8 @@
}
- FatInterface.printf( filename,'s');
- System.out.println();
+ //xxxxxxxFatInterface.printf( filename,'s');
+ //xxxxxxxSystem.out.println();
//System.out.println("Vor File Found!");
@@ -138,7 +156,7 @@
if (FatInterface.fat_search_file(filename,Clustervar,Size,Dir_Attrib,FOStream_Buffer) == 1)
{
- System.out.println("File Found!");
+ //xxxxxxxxxxxxxSystem.out.println("File Found!");
for (int h=0; h<13;h++)
{
@@ -159,7 +177,7 @@
else
{
- System.out.println("Try to Create File !"+tmp);
+ //xxxxxxxxSystem.out.println("Try to Create File !"+tmp);
Clustervar[0] = tmp;
//Clustervar[0] = 0;
@@ -167,7 +185,7 @@
if (FatInterface.fat_add_file_ent( Clustervar, filename, FOStream_Buffer) == 1)
{
- System.out.println("Create File !");
+ //xxxxxxxxxxxxSystem.out.println("Create File !");
for (int h=0; h<13;h++)
{
@@ -179,7 +197,7 @@
}
}
- FOStream_size[0] = 1;
+ FOStream_size[0] = 0;
FOStream_startcluster[0] = Clustervar[0];
FOStream_offset_from_start[0] =0;
FOStream_Dir_Attr = 0x20;
@@ -191,24 +209,43 @@
}
}
- return (true);
-}
-public static boolean FileOutputStream(String filename, boolean append)
+
+if (append == false)
{
- if (!append)
- {
- return( FileOutputStream( filename));
- }
+ int Cluster=0;
+ long [] tmp1 = new long [1];
+ int [] tmp2 = new int [1];
- else
+
+ for (int a = 0;a < 100;a++)
+{
+ //System.out.println("a in search = "+a);
+ Cluster = FatInterface.fat_read_dir_ent(FOStream_Dir_cluster,a,tmp1,tmp2,FOStream_Buffer);
+ if (Cluster == 0xffff)
{
- if (!FileOutputStream( filename))
+ //System.out.println("a in search aus = "+a);
+ tmp1 = null;
+ tmp2 = null;
+ return(false); //File not Found
+ }
+ if(FatInterface.strcasecmp(FOStream_Filename,FOStream_Buffer) == 0)
{
- return (false);
+ FatInterface.fat_set_dir_ent(FOStream_Dir_cluster,a, 0,FOStream_Dir_Attr, FOStream_Buffer) ;
+ FatInterface.fat_load_reset();
+ //System.out.println("a in search found = "+a);
+ FOStream_size[0] = 0;
+ break;
}
+}
+ tmp1 = null;
+ tmp2 = null;
+}
+
+if (append == true)
+ {
FOStream_offset_from_start[0] = FOStream_size[0];
}
@@ -216,9 +253,43 @@
}
+
+
+/******************************************************************
+* public FileOutputStream(String filename,
+* boolean append)
+* Creates an output file stream to write to the file with the specified name.
+* If the second argument is true, then bytes will be written to the end of the file rather than the beginning.
+*
+* If the file exists but is a directory rather than a regular file, does not exist but cannot be created,
+* or cannot be opened for any other reason then a ?????????????????????????????.
+*
+* Parameters:
+* file - Directories and files are seperated with "/". Do not write the leading "/" in the filename string.
+* append - if true, then bytes will be written to the end of the file rather than the beginning
+******************************************************************/
+public static boolean FileOutputStream(String filename)
+{
+ return( FileOutputStream( filename, false));
+}
+
+
+
+
+
+
+
+/******************************************************************
+* public void close()
+* Closes this file output stream and releases any system resources associated with this stream.
+* This file output stream may no longer be used for writing bytes.
+******************************************************************/
public static boolean close ()
{
+
+
+
FOStream_Buffer = null;
FOStream_size = null;
FOStream_startcluster = null;
@@ -228,11 +299,22 @@
}
+
+
+
+
+/******************************************************************
+* public void write(byte[] b)
+* Writes b.length or while (b[i++] != 0) bytes from the specified byte array to this file output stream.
+*
+* Parameters:
+* b - the data.
+******************************************************************/
public static boolean write (byte[] b)
{
int i=0;
-while (b[i] != 0)
+while ((b[i] != 0)&&(i<b.length))
{
i++;
}
@@ -245,6 +327,22 @@
+
+
+
+/******************************************************************
+* public void write(byte[] b,
+* int off,
+* int len)
+* Writes len bytes from the specified byte array starting at offset off to this file output stream.
+*
+* Overrides:
+* write in class OutputStream
+* Parameters:
+* b - the data.
+* off - the start offset in the data.
+* len - the number of bytes to write.
+******************************************************************/
public static boolean write (byte[] b, int off , int len)
{
@@ -256,19 +354,25 @@
+if (b.length < len)
+{
+ len = b.length;
+}
+
+
//System.out.println("FOStream_size[0] = "+FOStream_size[0]);
//System.out.println("off = "+off);
-if ((((long)(off+len)) )> (FOStream_size[0]+1 ))
+if ((( FOStream_offset_from_start[0]+(long)(off+len)) )> (FOStream_size[0]+1 ))
{
//System.out.println("in here ");
- if ((((long)(off+len))/FatInterface.BlockSize )!= (FOStream_size[0]/FatInterface.BlockSize ))
+ if ((( FOStream_offset_from_start[0]+(long)(off+len))/FatInterface.BlockSize )!= (FOStream_size[0]/FatInterface.BlockSize ))
{
- int diff = ((int)((long)(off+len))/FatInterface.BlockSize ) - (int)(FOStream_size[0]/FatInterface.BlockSize );
+ int diff = ((int)( FOStream_offset_from_start[0]+(long)(off+len))/FatInterface.BlockSize ) - (int)(FOStream_size[0]/FatInterface.BlockSize );
//System.out.println("in there diff="+diff);
@@ -294,10 +398,13 @@
if(FatInterface.strcasecmp(FOStream_Filename,FOStream_Buffer) == 0)
{
//System.out.println("in set");
-
+ //System.out.println("FOStream_size[0] = "+FOStream_size[0]);
//System.out.println("off = "+off);
- FOStream_size[0]=(long) (off+len-1);
- FatInterface.fat_set_dir_ent(FOStream_Dir_cluster,a,(long) (off+len-1),FOStream_Dir_Attr, FOStream_Buffer) ;
+ //System.out.println("FOStream_offset_from_start[0] = "+FOStream_offset_from_start[0]);
+
+
+ FOStream_size[0]= FOStream_offset_from_start[0]+(long) (off+len-1);
+ FatInterface.fat_set_dir_ent(FOStream_Dir_cluster,a,FOStream_size[0],FOStream_Dir_Attr, FOStream_Buffer) ;
FatInterface.fat_load_reset();
//System.out.println("a in search found = "+a);
break;
@@ -312,7 +419,7 @@
-FOStream_offset_from_start[0]=(long) off;
+FOStream_offset_from_start[0]= FOStream_offset_from_start[0] +(long)off;
//System.out.println("for for");
int k=0;
@@ -406,6 +513,15 @@
+
+
+/******************************************************************
+* public void write(int b)
+* Writes the specified byte to this file output stream. Implements the write method of OutputStream.
+*
+* Parameters:
+* b - the byte to be written.
+******************************************************************/
public static boolean write (int b)
{
@@ -457,6 +573,8 @@
if (Cluster == 0xffff)
{
//System.out.println("a in search aus = "+a);
+ tmp1 = null;
+ tmp2 = null;
return(false); //File not Found
}
if(FatInterface.strcasecmp(FOStream_Filename,FOStream_Buffer) == 0)
@@ -464,25 +582,24 @@
FatInterface.fat_set_dir_ent(FOStream_Dir_cluster,a, (FOStream_size[0]-1),FOStream_Dir_Attr, FOStream_Buffer) ;
FatInterface.fat_load_reset();
//System.out.println("a in search found = "+a);
+ tmp1 = null;
+ tmp2 = null;
break;
}
}
// System.out.println("we");
+
+
}
+
return (true);
}
-public static int[] FOStream_Buffer = new int [512];
-public static long[] FOStream_size = new long [1];
-public static int[] FOStream_startcluster = new int [1];
-public static long[] FOStream_offset_from_start = new long [1];
-public static int[] FOStream_Filename = new int [13];
-public static int FOStream_Dir_Attr;
-public static int FOStream_Dir_cluster;
+
//####################################################################################
// FileOutputStream Section End
//####################################################################################
|
 |