More help with sd card, fsrwfemto and file systems.
Ravenkallen
Posts: 1,057
Hey, You guys have been so helpful. Alas, i call upon your help once again. I have successfully interfaced the SD card using a demo program called "SD_trainer". Everything has worked out fine, but this demo just covers the basics of SD protocol. The actual object that powers the demo is called "fsrwfemto" and the object that powers that one is called "sdspifemto". I am very new to SD(propeller to·for that matter), And as such i have no clue about some of the stuff in those objects. Like what is the sector size constant in fsrwfemto. Are sectors the number of files you can have on the disk?
Or does that represent how many bytes can fit on a file? Also, i was wondering, How big a given can file be? I have read some places where is says like 8 KB's to 32 KB's. I hope you can make them larger than that. And what the heck are clusters? they keep mentioning them in the objects. I guess SD cards are kinda like a sector erasable/ programmable flash chip. Where you can only manipulate certain sections at a time, instead of having total access, like i2c. If all seems so hard when you don't know what you are doing, but so easy when you do.·If you guys know any·info about these things, please tell me all about it. Thanks again for everything.
Or does that represent how many bytes can fit on a file? Also, i was wondering, How big a given can file be? I have read some places where is says like 8 KB's to 32 KB's. I hope you can make them larger than that. And what the heck are clusters? they keep mentioning them in the objects. I guess SD cards are kinda like a sector erasable/ programmable flash chip. Where you can only manipulate certain sections at a time, instead of having total access, like i2c. If all seems so hard when you don't know what you are doing, but so easy when you do.·If you guys know any·info about these things, please tell me all about it. Thanks again for everything.
Comments
Building on sectors you have the file-system. It's called FAT (file allocation table). You don't have to know much about that because this part is already implemented by fsrwfemto. A FAT is build on 2 basic parts, the cluster-table and the directories.
One cluster combines a number of sectors. This way a list of used parts of the SD card/HD... can be smaller. The cluster table marks the used clusters and builds a chain of clusters that belong together (because these are used by one file).
The directory holds the name of the files and the number of the start cluster and the filesize in bytes.
When building a cluster-table you have to decide how big a cluster number can be ( how much bits you want to waste ;o). The possible cluster size (how many sectors belong to 1 cluster) depends on the size of the storage device and the max. cluster number.
Theoretically this system allows to use all sectors which are not needed for cluster table and directory can be used for one file.
The 8kB or 32kB you mention are not file-sizes, but cluster sizes. A 2GB or 4GB SD card usually is formatted with 32kB clusters. So, even if you have a file with only one byte, this will occupy 32kB.
We use file sizes of 8MB and 32MB for ZiCog and it's derivatives. These files are used to simulate each disk drive under CPM.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
I have a pcb that has 512KB of SRAM and a microSD called the RamBlade (see my signature). However, because I am after speed, there are only 2 prop pins spare for I/O. These can be for a serial pc connection or to another processor running as a terminal or to a PS2 Kyeboard and TV B&W using my 2-pin drivers (1 for TV, 1 for keyboard). The RamBlade runs ZiCog and CPM as well as a mini operating system of PropDos, PropCmd and Sphinx.
There are other pcbs with SRAM such as my TriBlade, the DracBlade, and Bill's Morpheus products. It really depends on your precise requirements.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
As clusoe already mentioned, it depends on your application whether it's a good idea to use SD or not. For high frequency write it's not a good idea, as the SD will very soon malfunction then.
Have a look at this thread: http://forums.parallax.com/showthread.php?p=856170
Please read the comments in the driver and the demo very carefully!
If you really need random access the speed will of course go down as you read/write 512 bytes just for picking/updating 1 byte. Maybe something in logic/datastructure can be changed.
Post Edited (MagIO2) : 4/25/2010 5:17:04 PM GMT
You need the file you wanna read from as the first file on the SD card. Simply format the SD card, copy that file to it (per default it has to be names SWAP.SYS, but that can be changed in your program if you need). After that you can copy whatever you want. The file can have any size up to the maximum free bytes of the SD card.
For real random access you'd use the vPeek vPoke functions for longs or vbPeek and vbPoke for bytes. Please note that addresses for longs are automatically alligned to long-addresses. This means that address 0, 1, 2 and 3 will access the same long.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
Yep ... as stated before ... and you'll find an additional description in vMem object (which is only an addon to FSRW). Please read!
Any file that is big enough to store your data. If you only want to do random reads I suppose you already have a file containing some data, don't you? Take it.
See answer above ... it depends on what you want to do. If you already have a file containing the data that you need you can take that file. If you are happy with an empty file you can create an empty file. vMem will open a file called SWAP.SYS per default. If you want to use another file you can call vOpenSwap with another filename. Important thing is that you never write to an address which will not fit into the file! Which means, if the file has a size of·32768·bytes you should only write to byte 0 - 32767. Any address above that will overwrite whatever is stored in the next sector/cluster of the SD card.
Yep ... but as discussed before, if you really do random read/write an SD card is only good in a write sometimes/read many application. According to clusos MTBF of ~100000 write cycles to the same sector, if you do 1000 writes per day per sector, you'd wear out the SD card in 100 days. If you only have 10 writes per sector a day, you have 10000 days.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Leon Heller
Amateur radio callsign: G1HSM
If you want to use EEPROMs, remember that they come in sizes up to 128K bytes and you can have four of those on a pair of I/O pins for a total of 512K bytes. I have part of a compiler that reads a file from an SD card into a 32K block of EEPROM. This is the source program. The 2nd 32K block is the dictionary. The 3rd 32K block is the object file which gets written to the SD card if the compilation is successful. The main advantage of this scheme is that it's really easy to make small "random" changes in the dictionary and object file as the compilation progresses. If the files had to be on the SD card, there would be a lot of 512 byte blocks read and written for a series of 1 or 2 byte changes and/or accesses scattered over the whole 32K area.
Let's say your file is 1MB in size = 1024kB. As one sector exactly has 0.5kB you need 2048 sectors to store this file. If you give each byte in this file an address, the address range is from 0 - 1048575. If you want to access a random byte inside of this file you have to find out in which sector it is. This is an easy operation, as 512 is 2^9 which means that it perfectly fits to bit-representations. Addresses of the first sector ( 0 - 511 ) have a bit representation of %...000_000000000 - %...000_111111111. The next address will be located in the second sector and have the address %...001_000000000. So, on the right side of the underscore you find the relative address inside of a sector and the left side gives you the number of the sector to load.
Now let's assume you want to access byte 128, 196, 246 and 1033 in this sequence. vbPeek( ... 128 ) will load the first sector and gives you the content of the byte with address 128. vbPeek( ... 196 ) will not load, because it's in the same sector which is already loaded into a local buffer. It simply returns the value of byte 196. Same for byte 246. When you now do vbPeek( .. 1033 ) vMem recognizes that another sector is now needed. First it checks whether something has been written in the old sector and writes it back if so, then it loads the sector needed to find byte 1033.
So, if you do really jump from one end of the file to the other with each access the only thing that can happen is, that vMem has to read a sector with each access. But you don't have to take care of that!