SD Card Usage Survey
DavidZemon
Posts: 2,973
Does anyone write to and read from the same file in one program?
Specifically, does anyone write to and read from the same file repeatedly and in quick succession?
I'm considering going the C++/Java route for PropWare. That is: having separate classes for input and output. I think this will have positive effects for code size.
Thanks,
David
Specifically, does anyone write to and read from the same file repeatedly and in quick succession?
I'm considering going the C++/Java route for PropWare. That is: having separate classes for input and output. I think this will have positive effects for code size.
Thanks,
David
Comments
I've never done this (whether on or off of a Prop), but I can come up with cases where it would be useful, for example, if you need to transmit lots of packets over a lossy radio connection and have to be able to store them all on an SD card (they don't fit in RAM) and then mark them as acknowledged when you get acknowledges (by writing only one byte of a huge file). If the reception was any worse on a live telemetry system I made, I would have had to do this (or get longer range XBees, but that's much too simple a solution).
Could you make a read-only variant, a write-only variant, and a read-write variant, and only use the read-write variant if it's needed? The only problem with this is that, if the read-write variant is ever needed, you would probably want to replace all instances of the read-only and write-only variants with wrappers for the read-write variant. Obviously, it should automatically pick whether to use the read-write variant or to use the read-only and the write-only variants, but I can't see how you would do this with C++ without lots of preprocessor magic.
I agree with the breaking apart of the input and output. I worked on something similar here.
I was just looking at your Stream-related classes over the weekend and thinking "wow! this is just like my Printer/PrintCapable classes!". The only difference is, I had to make up my own dumb class names instead of going with standard stuff. I might rename them before an official 2.0 release :P
In another thread you asked for multiple SD card and the need to support this. So a while ago @MacTuxLin build me some 4 SD-card boards for the Quick-Start. They where (are?) for sale at propellerpowered.
The plan was a RAID system for and with the Propeller. Sadly in 2 years I sold none as far as I know. Around $3000 down the drain.
So my guess is that nobody is really interested in having multiple SD-cards on one Propeller.
Multiple files open at the same time is a must for most of my projects, Kyes Fat_Engine and FSWR both support this by including the objects multiple times. But the RAM cost of multiple File Control Blocks and Buffers is hard to the small HUB. Especially since support for FAT-16 and FAT-32 is implemented in both of them. So the objects are not small to begin with.
Both File System Objects support reading and writing of open files and seek() to go to a position in the file. But I did run into a lot of trouble while writing. Somehow writing somewhere inside the file would also change the file size to the end of the last written byte. I had to modify Kyes Fat_Engine to get around this problem. FSRW can just seek in one cluster, pretty useless on bigger files.
I did not followed your PropWare's file access closely, but for a SD block driver, nothing beats @LoneSock's PASM driver included in FSRW. I do not know if you are using it already - if not, take a serious look. It uses a internal 512byte buffer in the COG to support Read Ahead and Write Behind. Very cool PASM. So if writing a sector, the call returns after your HUB buffer is copied to the COG ram. Then written to SD. After reading a Sector from SD it gets copied to HUB and then the next sector gets pre-fetched into COG ram in case you need it next.
@LoneSocks PASM code is really cool. Somehow I also see @Kuroneko's handwriting in there, but have no proof of that.
I had some basic ISAM DataBase written for the Prop. Working nice, but hitting all them problems. Multiple files, random access, files larger then a cluster.
Then real work kicked in and I am not allowed to play with the propeller since a while. At the time I got self employed, I was not aware of what an A..hole my Boss would be. Constantly driving myself to overtime. No vacations, things like that.
TLDR
Yes, reading and writing the same open file is quite important. Fast seeking of position in a file also. Multiple files open at a time is also important, multiple SD cards not so.
Enjoy!
Mike
I'm sorry to hear that you didn't sell a single board for the RAID system .
The FSRW driver sounds slick. We'll have to see how PropWare's performance compares after I implement the array read/write functions in my SPI driver... hopefully it's able to come somewhat close to FSRW.
If it doesn't compare, I'm afraid it's probably not something I'll be fixing. What makes PropWare's SD classes special is that there are multiple levels of abstraction - something completely different from any other implementation on the Propeller. Because of that abstraction, it would be very difficult to make something like FSRW's driver work [well] with my classes. And what would be the point? We already have libpropeller's SD class if you decide you need FSRW in C++.
As for code size: no worries! That I have very well covered. An instance of FatFileReader takes up only 84 bytes! So, open lots of files, no problem! And I wrote the following snippet as a cool example of multii-file read:
`reader` uses the shared buffer which is statically allocated in the FatFS instance. This is great for tight memory requirements. On the other hand, `reader2` gets its own, dedicated buffer, as you can see by the third parameter to the constructor. This completely alleviates thrashing the SD card . Of course, if memory is more of a problem than speed, simply remove the third parameter from `reader2` and both file instances will share access to a single buffer - say hello to 512 more bytes of hub RAM!
tl;dr
I think you're gonna love SD card access with PropWare. I'm sure proud of what's done so far, and it's only going to get better. There's lots more to come!
-edit-
Oh yea - that's pretty silly about seeking causing problems. There won't be any issues with that here. The seek operation itself is nearly instant - just a single write to a variable. Reading in the new buffer and flushing out the old one doesn't happen until absolutely necessary. If you use seek() to a different part of the file, the read or write function will notice the buffer is incorrect and reload it. This was a necessary aspect of shared buffers, but also made implementing seek() really easy
On the other hand I see the value of C/C++ even on the Prop1. It just looks more like being at work then fun. I have barely time to follow the forum and no time for Propeller Fun. Sad.
But I follow PropWare with great interest.
Enjoy!
Mike