//Loop_print.c Data acquisition. Loop with data printed to a file

#include <stdio.h>
#define BUFFER_SIZE 64                //buffer size
int i=0;
int j=0;
int buffer[BUFFER_SIZE];              //buffer for data 
FILE *fptr;					  //file pointer 

interrupt void c_int11()	        //interrupt service routine
{
 int sample_data;

 sample_data = input_sample(); 	  //new input data 
 buffer[i] = sample_data;  		  //store data in buffer
 i++;                      		  //increment buffer count
 if (i == BUFFER_SIZE - 1)    	  //if buffer full
  {
   fptr = fopen("loop.dat","w");      //create output data file
   for (j=0; j<BUFFER_SIZE; j++)
     fprintf(fptr,"%d\n", buffer[j]); //write buffer data to file
   fclose(fptr);                      //close file
   i = 0;                 		  //initialize buffer count
   puts("done");			        //finished storing to file
  }     
 output_sample(sample_data);		  //output data
 return;                       	  //return from ISR
}

void main()
{
 comm_intr();                  	  //init DSK, codec, McBSP
 puts("start\n");			   	  //print "start" indicator 
 while(1);                     	  //infinite loop
}