/************************************************************************/ /* CIRCBUF.C Written by: Jerry Lenaz, 1/12/92 */ /************************************************************************/ /* This is an echo program written entirely in C to be used */ /* with the ADSP-21020 EZ-LAB board. */ /* */ /* The echo program takes the talkthru program and adds a */ /* circular buffering scheme. The circular buffer is defined */ /* by the functions CIRCULAR_BUFFER, BASE, and LENGTH. The */ /* echo is performed by adding the current input to the oldest */ /* input. The amount of delay in the echo can be modified by */ /* changing the value of BUFF_LENGTH. */ /************************************************************************/ #include <21020.h> /* For the idle() command */ #include /* For the interrupt command */ #include /* For the CIRCULAR_BUFFER and segment functions */ #define BUFF_LENGTH 4000 CIRCULAR_BUFFER(float,1,echo); /* Define echo as 21k DAG1 reg i1 */ /* a DM pointer to a circular buffer */ volatile int in_port segment(hip_reg0); /* hip_reg0 and hip_reg2 are */ volatile int out_port segment(hip_reg2);/* used in architecture file */ void process_input(int); void main(void) { /* make this a variable length array. If emulator is stopped at main */ /* and _BUFF_LENGTH in dm window is modified, the delay of the echo */ /* is modified. Do not make BUFF_LENGTH greater than stack size! */ float data_buff[BUFF_LENGTH]; interrupt(SIG_IRQ3, process_input); BASE(echo) = data_buff; /* Loads b1 and i1 with buff start adr */ LENGTH(echo) = BUFF_LENGTH; /* Loads L1 with the length of buffer */ /* As the array is filled, the nth location contains the newest value, */ /* while the nth+1 location contains the oldest value. */ while (1) { /* The echo sends the sum of the most */ float oldest,newest; /* recent value and the oldest value */ idle(); /* echo is pointing to the nth location after the interrupt routine. */ /* place the new value in variable 'newest'. After the access, update */ /* the pointer by one to point at location n+1. */ CIRC_READ(echo,1,newest,dm); /* Now echo is pointing to n+1. Read the location and place value in */ /* variable 'oldest'. Do not update the pointer, since it is now */ /* pointing to the new location for the interrupt handler */ CIRC_READ(echo,0,oldest,dm); /* add the oldest and most recent and send out on port */ out_port=oldest+newest; } } void process_input(int int_number) { /* The newest input value is written over the oldest value in the nth */ /* location and the pointer is not updated. */ /* A cast to float is necessary before writing in_port to *echo. */ CIRC_WRITE(echo, 0, (float)in_port, dm); }