Files
Dr_Acula
Posts: 5,484
Sorry to be firing off lots of questions here.
Is there a demo for working with files?
I am assuming when you open a file it opens something on the sd card, not eeprom or anywhere else. In the code below, the file does not exist yet and it is being opened for writing. I'm getting an error back saying "can't open file". ... see below for more commentary
I found Dave Hein's code http://code.google.com/p/propgcc/source/browse/demos/c3files/src/filetest.c?r=5cbec3c195d78d733040ab6a814fb8f3953bfe23
but it says it can't fine dfs.h
Is this an essential part of file handling?
addit - found dfs.h and dosfs.h with a google search http://code.google.com/p/propgcc/source/browse/demos/c3files/src/dosfs.h?r=5cbec3c195d78d733040ab6a814fb8f3953bfe23
Getting an error now
Any simple file handling demos available - eg open a file, write a couple of bytes, close the file.
Is there a demo for working with files?
I am assuming when you open a file it opens something on the sd card, not eeprom or anywhere else. In the code below, the file does not exist yet and it is being opened for writing. I'm getting an error back saying "can't open file". ... see below for more commentary
#include <stdio.h> #include <propeller.h> #include <string.h> #include <stdarg.h> #include <stdlib.h> typedef unsigned char UCHAR; typedef unsigned long DWORD; typedef unsigned long UINT; static char a[2048]; static int z; static FILE *fp1; char* BCX_TmpStr(size_t); char* str (double); int main(int argc, char *argv[]) { strcpy(a,"Test"); if((fp1=fopen(a,"w"))==0) { fprintf(stderr,"Can't open file %s\n",a);exit(1); } }
I found Dave Hein's code http://code.google.com/p/propgcc/source/browse/demos/c3files/src/filetest.c?r=5cbec3c195d78d733040ab6a814fb8f3953bfe23
but it says it can't fine dfs.h
Is this an essential part of file handling?
addit - found dfs.h and dosfs.h with a google search http://code.google.com/p/propgcc/source/browse/demos/c3files/src/dosfs.h?r=5cbec3c195d78d733040ab6a814fb8f3953bfe23
Getting an error now
if (dfs_rmdir(argv[i]))saying this has not been declared, plus about 10 other errors.
Any simple file handling demos available - eg open a file, write a couple of bytes, close the file.
Comments
I haven't played with the SD and file I/O yet. There is a demo for the C3 using the SD and file I/O but there needs to be more for folks unfamiliar with C file I/O and/or Propeller SD support.
As I write this, I'm wondering what the minimum hardware configuration to support SD is and if we need another one of those matrices showing what memory models/hardware/features are compatible.
Sorry I can't help but hopefully the smart guys will be along soon.
Please keep trying things and asking, all these threads are valuable to the documentation/tutorial efforts!!
There have been some recent changes to the file I/O startup, but I don't think that's in the SimpleIDE yet.
So whatever setup people have - if you have an SD card then it ought to be possible just to change the pin numbers.
I am using XMM which is caching off the SD card so there is always the possibility of a conflict there but I'm sure that has been thought of.
There are #defines for other boards in c3files.
You can read pin from the .cfg files now with config variable patching, but I don't have an example ready yet.
There is also an improvement coming in sdcard variable patching that reduces the memory footprint.
We have thought of the conflicts in a few different ways. You can use a lock, or you can use HUBTEXT.
I know the SD card is working because downloading large programs to the SD card work.
I'm still not entirely sure of how these config files are working. It seems there is a starting file but then it creates other files the first time you do a XMM download. But it seems to edit the original file. So I am not really sure if this is downloading in XMM or LMM. I think it is LMM because it is a lot faster to download and less messages come up.
So this is the config file
and this is my C file. The file is being opened for "write" so it does not exist yet. Is the C code correct?
Your example is missing a mount which would not have worked ... until SimpleIDE v0-6-11 with PropellerGCC v0-3-1 that is.
David Betz recently added a feature that lets the file-system automatically mount using the .cfg file properties. That is, you no longer have to be concerned with calling dfs_mount, etc.... You only need to make sure you select the right .cfg file.
Download the SimpleIDE v0-6-11 package and retry your example. I produced a "tvkbfile" example that does something similar, but it is much more complicated (and it fits in HUB RAM with LMM mode). Your example should be relatively small.
SimpleIDE will only do XMM stuff if you select one of XMMC, XMM-SINGLE, or XMM-SPLIT memory models for your build.
--Steve
Here is another reason to get into C++ - a .jpg decoder
http://olickspulpit.blogspot.com.au/2010/04/simple-jpeg-encoder.html and click on the link in post #2 (too big to post on the forum).
Decoding .jpg files is a big part of the html viewer I want to get working on the touchscreen as not many sites use .bmp files.
The Prop is limited in the size of the image it can handle because of it's 32K RAM. You will need a buffer that is 16*3*W in size, where W is the image width. If you used the entire RAM for this buffer the maximum image width would be 672 pixels.
One thing you might consider is to just decode the DC portion of the image. This would give you an image that is one-eigth the size of the original image, and wouldn't require a DCT. A 1024x768 image would yield a 128x96 thumb-nail image. It might be suitable for small low-res displays.
I know the feeling - my propeller "to do" list is getting longer and starting to interfere with the honey do list.
Is it possible to split it up into smaller chunks? I don't know much about the jpg algorithm. With the fast transfers to and from external ram in the touchscreen driver it is pretty easy to move a chunk of data into and out of hub. Fill the hub in under 10ms. So then if a cog could be fired up and process that chunk, then move it back out to external ram.
But does every pixel depend on every other pixel? Or are they 8x8 blocks? Reading this at the moment... http://en.wikipedia.org/wiki/JPEG
Would the pasm version use a cordic algorithm to avoid the need for multiplies?
I'm a little confused by this thread and another where you said you have problems with files. But in another post you said everything was working. Follow up?
Thanks,
--Steve
However, I am still stuck writing a C program that can access the SD card.
I downloaded the latest 113Mb file from http://code.google.com/p/propgcc/downloads/list and copied all files over the existing files. However that package did not seem to include the latest SimpleIDE program. The one I have is 0.6.8. Do I need to update the SimpleIDE program as well in order to get the above program to open the SD card? If so, is there a link somewhere for the latest SimpleIDE program?
Many thanks in advance.
Ok, guess I missed the context. Sorry about that.
Looks like David pointed out the key requirement your code is missing for the file-system.
That code can be put into a separate file included in the project.
SimpleIDE 0-6-11 has the latest propeller-gcc compiler.
You can find it here: http://code.google.com/p/propside/downloads/list
I'll be updating the SimpleIDE packages again next week to version 0-7-0.
The DC coefficients of each 8x8 block are differentially coded based on the previous 8x8 block. So you need to decode all of the prior DC coefficients to be able to decode a particular DC value. The AC coefficients are self-contained in each 8x8 block.
The pasm version would be more efficient using hard-coded shifts and adds versus a multiplier or cordic algorithm.
I tried this code - the behaviour is now a little different as it hangs at "try opening a file" whereas before it was saying that it could not open the file. It doesn't get any further though - no message about either the file being open or not being open.
I'm running back in XMMC as the additional code pushed it back over the threshold for LMM. In an ideal world I'd like to debug using LMM as that will remove the variable of the cache driver interfering with file access. Not sure if this code can be shrunk much more though.
I'm sure this is just my lack of understanding of C. Many thanks for all the help here - I'm sure we will get there.
What board type do you have set?
You should consider adding a waitcnt(CLKFREQ+CNT); before output for terminal connect time.
Can you copy paste your load output here?
Right click Build Status window, Select All. Right click Build Status window again Copy.
Here's what I get for XMMC.
Here's what I get for LMM.
In both cases I get "File is open" on the terminal and no "Can't open file ...".
I'm not seeing some critical information in your dump. It should show a line like this:
Patching __cfg_sdspi_config2 ...
Seems that you don't have SimpleIDE 0-6-11. What's the version in the Menu->Help->About ?
Looks like 0-3-1 is current? I'm updating to this and will try again!
Actually, you might have propgcc version 0-3-1 already. It should be installed with 0-6-11.
Can you open a command window and type propeller-elf-gcc --version?
I get this:
I ?think? it has something to do with the board configuration. I made no changes other than the pin numbers for the DracTouch.cfg
I appreciate all the help!
Thank you for trying!
Can you do use your command line window to try the propeller-load separately from SimpleIDE?
That is:
- Start->Run->cmd (winXP) or Start->Search->cmd (win7)
- cd C:\Users\Joe\Documents\test
- dir - make sure you have a.out that should be 30260 bytes as you reported for LMM
- propeller-load -r -t a.out -b DracTouch
- copy/paste the output here.
My propeller-load command output looks like this:If you don't see "patching" messages, there is something wrong with your copy of the distribution.
If you do see the "patching" messages, then I have more IDE work to do and there is a board config issue.
Thanks,
--Steve
I have something wrong with distro apparently?
I'll recheck some things and post again later.
Thanks,
--Steve
Thanks,
--Steve
OK, I think I've figured something out. I don't get the patching, because my catching isn't "c3_cache_flash.dat", it's "eeprom_cache.dat"
I'm wondering about these stock dat files. What would need to be changed?
The cache thing is a red-herring for this particular issue. At some point another cache driver will be necessary, but for a 64KB eeprom, the eeprom_cache.dat is fine. If your eeprom is 32KB, that's a separate issue.
This issue is more than a loader problem, it is a windows package issue. I'm building a new package, but I need time. I'll post a new package later.
Thanks,
--Steve
Thanks again!
Here's the code for eeprom_cache.spin Click View raw file on that page to download. It is a write once (by loader) read many implementation for xmmc model.
Here's the code for dracblade_cache.spin Click View raw file on that page to download. This is a write/read implementation and can use xmmc or xmm-single models.