Specifications

This function is the interrupt service routine that is called when the DREQ line of the
VLSI goes high. This pin goes high whenever the buffer in the decoder is getting low.
The pin that this DREQ line is connected to is an interrupt on edge pin on the Atmel
that is configured to interrupt of the rising signal edge. To operate interrupts in the Nut
OS, the code must register the interrupt, first by identifying what the interrupt is, and
then when the Interrupt Service Routine (ISR) is called. When an interrupt happens the
OS actually has its own ISR that in turn calls the ISR that was registered. When this ISR
finishes, control is given back to the operating system ISR that clears the flags and
returns.
The ISR for the DREQ function starts by checking whether output to the decoder is
allowed at that moment. This allows the data transfer to be disabled when needed and is
a global variable that can be modified anywhere. It then sets the CS line to select the
data register and goes into a loop that keeps sending data to the decoder until the buffer
becomes empty or the decoder becomes full (when the DREQ line goes low again). To
send each byte it needs to set the BSYNC line before sending the byte and then clear it
after sending the byte. The data that is sent is the data at the current transmit pointer of
the ring buffer. After that byte is sent, the pointer is incremented to the next point. Just
like the receive pointer, if it exceeds the memory space allocated to the buffer it wraps
back to the beginning of the buffer. If the buffer becomes empty when the transmit
pointer equals the receive pointer, the function sets a global variable indicating that the
buffer is empty. If the decoder buffer is full when it lowers the DREQ line, the function
exits this loop and goes into another loop to input 32 more bytes of data. This is because
when the decoder indicates it is full it actually still has 32 more bytes of space available.
The first program to test if the buffer data can be used to produce music works as shown
in figure 18.
36