/************************************************************************/ /* CIRCBUF1.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 an older */ /* input. The amount of delay in the echo can be modified by */ /* changing the value of ECHOSIZE. */ /* This program displays the use of the CIRC_MODIFY macro. */ /* CIRC_MODIFY can be used to modify circular buffer pointers */ /* by more than 0x3f (6 bits). */ /************************************************************************/ #include <21020.h> /* For the idle() command */ #include /* For the interrupt command */ #include /* For the CIRCULAR_BUFFER and segment functions */ #define BUFF_LENGTH 4000 float data_buff[BUFF_LENGTH]; #ifndef ECHOSIZE #define ECHOSIZE 2000 #endif 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) { 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 older,newest; /* recent value and an older value */ idle(); /* echo is pointing to the nth location after the interrupt routine. */ /* place the new value in variable 'newest'. After the access, do not */ /* modify the pointer. */ CIRC_READ(echo,0,newest,dm); /* Use the CIRC_MODIFY macro to modify the echo pointer by ECHOSIZE. */ /* Now echo will point to n-ECHOSIZE position in the circular buffer. */ CIRC_MODIFY(echo, -ECHOSIZE); /* Now echo is pointing to n-ECHOSIZE. Read the location and place in */ /* variable 'older'. Do not update the pointer. */ CIRC_READ(echo,0,older,dm); /* Use CIRC_MODIFY to modify echo to point to n+1. Upon the next */ /* interrupt, the pointer will be pointing to the new location to */ /* be updated. */ CIRC_MODIFY(echo, ECHOSIZE+1); /* add the older and most recent and send out on port */ out_port=older+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); }