CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

CCS fat.c does it work or not?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Sep 16, 2013 5:04 pm     Reply with quote

They often say a project is a journey not a destination
The issue with the CCS fat.c is the failure to type cast.
There are a number of smaller errors I'll post them soon after I fully test the features.
Below is patched working code that still could use more mathematical consistency
Code:
 
// figure out the size of a cluster
   Bytes_Per_Cluster = Sectors_Per_Cluster * Bytes_Per_Sector;

   // figure out how long one FAT is
   FAT_Length = Sectors_Per_FAT * (int32)Bytes_Per_Sector;

   // figure out where the FAT starts
   FAT_Start = g_mmcsdPartitionOffset+(int32)Reserved_Sectors * (int32)Bytes_Per_Sector;

   // figure out where the root directory starts
   Root_Dir = FAT_Start + ((signed int32)FATs * FAT_Length);


The main issue was the absence of the int32 type casts... any calculation of offsets with Fat32 and a good sized card in my case 2gb will wrap with 16 bit values.
Next there is no reason I can see for signed integers I'll tidy that up later
Once the offsets go haywire due to multiplications without strict type casting the code is almost destined to crash and burn.
Anyway dir is now working.
I'll relax the condition that the partition be active if there is only one partition. Clean up the math etc.
I'll try to add some documentation to show why the offsets have the values they have.
The math needs to be put on a consistent notational basis .. since this FAT32 math only involves positive displacements there is a chance to get 4gb with a 32 bit binary notation of positive integers ( yes there were some 4gb SD cards made ..I have some) .
In the past with limited ram there perhaps was a reason to mix notation between 8 16 and 32 bit.. with modern PIC chips unless it is an array the extra bytes used to ensure a consistent notation for the few variables used in critical arithmetic is often worth it.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Thu Sep 19, 2013 11:08 am     Reply with quote

As a retired mathematician I once oversaw hundreds of coders so I have some awareness of coders
Many know coders love to use pointers but pointers often have issues and often don't form what mathematicians would call an algebra. Fat32 is a labeling of the storage space it doesn't impose a metric. Labels are mbr, partition record, fat table, cluster number, file name tile etc. There is no metric just labels and relationships. Something like mbr is (a) partition record is (b). a<b is true in this algebra without having to apply any metric ( bits bytes words blocks etc.) It is true distance relative to storage memory may be quantized into bytes, words, double words or 512 byte blocks but the algebra shouldn't care. Labels have relations to each other in the algebra (the mbr is before the partition record ) but the physical distance is imposed by the card geometry; the algebra is independent.
The algebra t is like drawing points on a line but not placing a grid. The points are just labels that have relations with each other. When a label needs a metric a transform table should be used based on the cards physical geometry. This places the math notationally above the card geometry. Like as if SD cards are a rubber strip with labels (mbr etc)...they differ by the way the strip is stretched between the labels and the maximum stretch possible ( capacity). The relationship between the labels is conserved no matter how the strip is stretched.

Pointers impose a specific metric 8 bit jump for a byte 16 bit jump 2 etc. In places the pointer is even cast down ....I'm living with them for now in this CCS code.


The weakness of pointers is that they can point to unlabeled points that are meaningless in the algebra (Ex. like some meaningless location within in the mbr... the CCS code doesn't do this but it is a good example of the risk pointers impose) and it is the source of the bugs.
CCS did a good job of isolating (abstracting) the low level SPI card driver. Coders often do well with hardware abstraction.
Now luckily object programming is imposing an algebra on coders. Objects have relations with each other and the compiler decides the physical location of the object in the metric of the memory space.

Anyway with several patches I can read the contents of my files from my SD card which is all I need and keeps me on firm ground w.r.t. Microsoft patents ( my file creation ,writing etc. is done only with Microsoft licensed products). I know non lawyers have offered broader opinions on this issue. This CCS code maybe useable for others but it is non only for me partially useable. I would advise not to use this CCS code if an alternative is available.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group