fsrw write
mctrivia
Posts: 3,772
I am playing with writing to the sd card. I can get it to create the file but it does not write anything to the file. I know I am probably missing something obvious.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ rr : "RealRandom" sd : "fsrw" VAR byte rand0[noparse][[/noparse]128] 'holds 32 random longs byte rand1[noparse][[/noparse]128] 'holds 32 random longs byte bank 'which is being used long stack[noparse][[/noparse]1000] PUB start | temp, x, y bank:=-1 'start RealRandom rr.start 'start sd card recorder cognew(writeData,@stack) 'start generating numbers repeat 'write to buffer 0 bank:=0 repeat x from 0 to 31 temp := rr.random repeat y from 0 to 3 rand0[noparse][[/noparse]x*4+y]:=temp & $FF temp := temp >> 8 'write to buffer 1 bank:=1 repeat x from 0 to 31 temp := rr.random repeat y from 0 to 3 rand1[noparse][[/noparse]x*4+y]:=temp & $FF temp := temp >> 8 PUB writeData | r 'Mount SD Drive sd.mount(0) ' Create or overwrite file r := sd.popen(string("otp00002.bin"), "w") 'write 1 cluster worth of data to a file repeat 'wait for the random number generator to be writing to 1 repeat until bank==1 'write rand0 to the file sd.pwrite(rand0, 128) 'wait for the random number generator to be writing to 0 repeat until bank==0 'write rand1 to the file sd.pwrite(rand1, 128) sd.pclose
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
Comments
You also need to synchronize the random number generator to the write routine in case the write routine is slower than the generator. The random number generator will keep on filling the buffers, one at a time, without waiting for the write routine to finish writing the buffer. If there's enough write delay, the generator will overwrite the buffer before the write routines finishes. This could happen if the SD card is waiting for an erase cycle or needs to do wear levelling which can take 100ms or more sometimes.
Post Edited (Mike Green) : 4/18/2009 3:33:14 AM GMT
Note: I have modified rr.random to wait $A000 instead of $4000 because i want a 0.5ms delay instead.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
now to get it to fill 1 cluster, pause rand generation if sd is not keeping up.....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
cogs will cause things to fail. (Of course you are not doing this, but I'm just
saying, in case other people try to use it multi-threaded).
On flushing, or prohibiting remounts---fsrw explicitly and intentionally does neither;
it depends on the programmer to use it correctly. In particular, flushing automatically
is exactly the wrong thing to do if the user switches cards and then initiates a mount.
You might want to just open the file with "w+" (append mode). Alternatively, put a
pflush in there every once in a while.
repeat x from 0 to 63
this way it generates a 16k file(1 cluster) and stops. now to see if someone has writen a byte to string conversion or write one myself and make the code step to the next file name after each cluster.
Attached file is 16k resulting file.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
It doesn't really matter because you have enough space here since you only need 2 bytes,
but the var byte filename[noparse][[/noparse]15] should be var word filename or var long filename.
Can't help you with Tom's file methods.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.