3 ms·
The interrupt routine would only be writing the next byte of audio to the DAC which would be at a fixed address, whats causing the corruption is that the CPU st
by axman6 13y ago
The interrupt routine would only be writing the next byte of audio to the DAC which would be at a fixed address, whats causing the corruption is that the CPU stores the state of the CPU when the interrupt occurs onto the stack; this isn't where the audio is being played from
void execute_interrupt(void * isr) {
// push the registers of the program running when
// the interrupt happens onto the stack that's currently
// in use. this is something the CPU looks after usually
// (I think).
// This meant in the article that the contents of the
// registers were being pushed to the buffer holding
// the current image, overwriting whatever data was
// above the stack pointer. The fix was to swap which
// register was the source and which the dest, so that
// the ISR would be pushing to the buffer that was about
// to be written to.
pushRegs();
// do whatever's needed to get the CPU into a consistant
// state for the ISR
zeroRegs();
// call the interrupt service routine for whatever interrupt
// has occured
isr();
// just decrements the system stack pointer, leaving
// whatever was above the point corrupted in the
// original version using the two stack regs
popRegs();
}