12
Programming Model
12 – 11
SPORT0 is set up to generate the serial clock internally at 1.536 MHz,
based on a processor clock rate of 12.288 MHz. The RFS and TFS signals
are both required and the RFS signal is generated internally at 8 kHz,
while the TFS signal comes from the external device communicating with
the processor.
Finally, SPORT0 is enabled and the interrupts are enabled. Now the IDLE
instruction causes the processor to wait for interrupts. After the return
from interrupt instruction, execution resumes at the instruction following
the IDLE instruction. Once these setup instructions have been executed,
all further activity takes place in the interrupt service routine, shown in
Listing 12.2.
.MODULE/ROM fir_routine;
{relocatable FIR interrupt module}
.INCLUDE
<const.h>;
{include constant declarations}
.ENTRY
fir_start;
{make label visible outside module}
.EXTERNAL data_buffer, coefficient;
{make globals accessible in module}
{interrupt service routine code}
FIR_START:
CNTR = taps_less_one;
{N-1 passes within DO UNTIL}
SI = RX0;
{read from SPORT0}
DM(I0,M0) = SI;
{transfer data to buffer}
MR=0, MY0=PM(I4,M4), MX0=DM(I0,M0);
{set up multiplier for loop}
DO convolution UNTIL CE;
{CE = counter expired}
convolution: MR=MR+MX0*MY0(SS), MY0=PM(I4,M4), MX0=DM(I0,M0);
{MAC these, fetch next}
MR=MR+MX0*MY0(RND);
{Nth pass with rounding}
TX0 = MR1;
{write to sport}
RTI;
{return from interrupt}
.ENDMOD;
Listing 12.2 Interrupt Routine
12.2.2
Example Program: Interrupt Routine Discussion
This subroutine transfers the received data to the next location in the
circular buffer (overwriting the oldest sample). All samples and
coefficients are then multiplied and the products are accumulated to
produce the next output value. The subroutine checks for overflow and
saturates the output value to the appropriate full scale, then writes the
result to the transmit section of SPORT0 and returns.
The first four lines of the listing declare the code module (which is
relocatable rather than placed at an absolute address), include the same
file of constants, and make the entry point visible to the main routine with
the .ENTRY directive. Likewise, the .EXTERNAL directive makes the
main routine labels visible in the interrupt routine.