From: Jim Thomas Subject: Relaxed Autobuffer Interrupt Latency (for ADI serial ports) Date: 21 Apr 1999 THIS WORK IS PLACED IN THE PUBLIC DOMAIN
Name: Relaxed Autobuffer Interrupt Latency (for ADI serial ports)
Category: DSP chip/microprocessor-specific instruction set tricks
Application: When you need more than a one-sample latency before processing an interrupt from one of ADI's autobuffered serial ports.
Advantages: You don't have to service the serial port interrupt before the next sample comes in.
Introduction: This trick actually came to me in a dream (I'm not making this up!) It might sound a bit wacky, but bear with me - I've thought it through during the daylight hours and it still makes sense. There is one caveat though - I've never had the opportunity to try it. If you decide to try it, I'd LOVE to hear about it.
skip this part if you don't care about the idea's origin...
The Dream: I dreamed I was working on a project in the lab and my boss came in for a status report. Things were not looking good, but I didn't have enough data to know whether we were experiencing a real problem or not. So I decided to baffle him with non-sensical technical terminology. I told him there was a slight problem with the "non-unity modulo[1] circular autobuffering." About this time, I began to wake up, and this phrase was circulating in my brain over and over.
Non-unity modulo circular autobuffering
Non-unity modulo circular autobuffering
Non-unity modulo circular autobuffering
Non-unity modulo circular autobuffering
Usually when I wake up from a dream and can remember some detail from it, it turns out to be highly illogical [2] to the point of absurdity. Thinking that this might be one of those times, I hung on to the phrase for conscious analysis so I could get a cheap laugh out of it.
Non-unity modulo circular autobuffering
Non-unity modulo circular autobuffering
Non-unity modulo circular autobuffering
Non-unity modulo circular autobuffering
Then I realized... that's genius!
The Trick: Set up an odd-length buffer for the serial port RX data. I think setting the L-register to 25 would be ideal, because 25 is such a nice odd number [3]. Set the M-register equal to 2 (which is where the "non-unity modulo" comes from). As the data comes in initially, the data will be written into even addresses in the autobuffer. When the buffer wraps around (after 13 samples) an interrupt is generated. Subsequent samples will be written into the odd addresses in the autobuffer, but the old samples will be safe for 12 more sample periods - thus, you have 12 sample periods during which you can service the autobuffer. When you do get around to servicing the autobuffer, you'll have to deleave the data first. If the I-register is odd, you'll need to pull out the samples stored in the even addresses. Note that you'll already have an M-register equal to 2 for this. If the autobuffer were at address 0, the data will be written to these addresses in this order:
0, 2, 4, 6, 8, A, C, E, 10, 12, 14, 16, 18 (IRQ! I+1 % 0x19=1) 1, 3, 5, 7, 9, B, D, F, 11, 13, 15, 17 (IRQ! I+1 % 0x19=0)
If the sample rate is 8000, you'll have 12/8000=1.5ms to service the IRQ which is quite generous compared to the 125us you'd have otherwise.
Alas! I only wish I had the opportunity to use this trick!
[1] Back when ADI first came out with the ADSP2100, the "M" registers were called "modulo" registers which is a misnomer. Maybe you could call the L registers "modulo" registers. I think they call them "modify" registers now.
[2] This is the obligatory Star Trek reference that guarantees its acceptance into the Tricks Compilation. In spite of the idea's origin[4].
[3] Of course other numbers are possible too so long as they are odd and greater than 3. I like 25 because after 8 IRQ's you'll have 100 samples.
[4] I understand that the guy [5] who invented the sewing machine solved his greatest techincal challenge in a dream too. He dreamed he was being attacked by savages whose spearheads had holes in them. He applied this detail from his dream to the sewing machine's needle, placing the hole in the needle near the tip instead of near the tail.
[5] Does anyone know his name? Can anyone confirm this anecdote?