The more and more I play with this I find that I’m limited with visibility. Its tough to debug when you constantly have to deal with this overhanging problem :
The data arrives at my hardware, and to the PC bitshifted. The data is not evenly byte-aligned, and so before you can do anything with the data, even look at it, you have do a couple things:
1. Find how much the particular sector is shifted by finding the sync.
2. Anytime you need to read a byte, shift all future reads by the same amount
You can’t simply access an array, because you need to massage the data for read.
This I find to be a royal pain in the butt, and a lot of extra bitshifting code on the PC.
I was reading some 68000 assembly on the amiga yesterday, and most of the code is so simple because the hardware sync’s on the sync string, and the data arrives to the higher software layers properly shifted.
Which made me think next, why can’t my hardware just deliver properly aligned data?
So at least for the next couple days, I’m going to look into ways of doing this.
This isn’t particularly easy, because right now, I’m handling everything at the bit level since everything done is serially. One bit received, one bit stored into the FRAM. The segment of code that handles the USB transfers is mostly one bit at a time as well.
I suppose I could setup a 4-byte shift register, checked after each bit to see if the contents of the four bytes are 0x44 0x89 0x44 0x89. Hrrmm.. I wonder if just 0x44 0x89 would suffice. But then I guess I’d have to determine if that’s the first one or the second…. but I guess either way, aligning the next data on a new byte would work. BUT, that’s assuming I keep track of the which bit position I’m currently in, and then “hurry up” and shift a bunch of 0’s or something into memory. I say hurry up because if I’m doing this when I’m storing, time is of the essence.
The other alternative, I guess, is to handle this at transfer time, but time is crucial there too because I’m dealing with an ASYNC uart on the USB side, where time between bits is very important. However, I can control the exact time between bits by changing the baud rate. Which is currently at 9600. If memory serves me 9600 gives me something like 104 microseconds between bits. I guess that’s tons of 20ns clock cycles.
I’m just thinking out loud………