File speeds and interrupts

18 Mar 2010

I'm trying to log AD345 data via SPI on InterruptIn and write it to an open local file with fwrite() in binary directly from the interrupt routine.  I find that my ideal data rates are right on the margin for the flash memory.  It is almost OK at 192 bytes per 20mSec (800s/s)  but quite marginal at 192 bytes/10mSec. (the fifo on the AD345 gives a bit of leeway).  Average measured single buffer dump seems to be about 15mSec but some are a lot longer (in some areas of the flash, changing block, cell errors?). It's the long fwrites() that are the real problem - occasionally >50mSec or more.

What is the fwrite() buffer size? Can it be changed?

The fwrite() appears to mask  InteruptIn, does it?  Also does pc.printf() mask it?

When using InterruptIn I can't get wait() to flash my led - low interrupt priority?

Chould I expect faster write speeds with a SD card FAT file system, or do I need to go to a raw storeage?

- Given that fwrite() masks the interrupt, I don't gain by fwriting as a forground task because I loose control of the relative timing.  Any suggestions?

Thanks,

18 Mar 2010

Any long work in the interrupt handler, especially file I/O, is not a good idea. What you should do is just set some flag and do writing in the main routine. If you need timing, store the timestamp into a variable in the handler too.

18 Mar 2010

Thanks; I tried that first, but it doesn't alter much if the interrupts are masked by fwrite()  and the fwrite() takes longer than the latency of the data source.  An intermediate buffer doesn't help if there is an atomic fwrite() size/time set by the buffer size.  I probably just need a faster, more predictable storage system. Suggestions?

Is the interrupt priority info available anywhere?

Does the MBED implement raw unbuffered  read() and write() ?

Thanks,

Tim