// FREADER.CPP PC - TMS320C31 COMMUNICATION TO MULTIPLY TWO NUMBERS #include #include "dsklib.h" // contains several header files #include "tidsp.h" // contains memory address locations on DSP board // on DSP board for status flags and registers char DSK_APP[]="C31FILT.OUT"; char DSK_EXE[]="FREADER.EXE"; // default dsk communication routine // scans parallel port for dsk presence // if present, load dsk program // void config_dsk_for_comm() { //enumerated message for looking up messages // MSGS err; clrscr(); Scan_Command_line(DSK_EXE); Detect_Windows(); // Download the communications kernel // for(;;) { if(Init_Communication(10000) == NO_ERR) break; if(kbhit()) exit(0); } HALT_CPU(); if((err=Load_File(DSK_APP,LOAD))!=NO_ERR) { cout << DSK_APP << " " << Error_Strg(err) << endl; exit(0); } RUN_CPU(); //DSK is initialized & able to communicate clrscr(); } void main(int argc, char* argv[]) { // command line validation // if (argc < 3 || argc > 3) { cout << endl << "COMMAND LINE ERROR!!!" << endl; cout << "CORRECT USAGE IS: freader [input filename] "; cout << "[output filename]" << endl; exit(-1); } // declaration of file pointers // FILE *fp_1 = NULL, *fp_2 = NULL; // open and validate the input file for binary read operation // open the output file for binary write operation // fp_1 = fopen(argv[1], "rb"); fp_2 = fopen(argv[2], "wb"); if (fp_1 == NULL) { cout << endl << "INPUT FILE NOT FOUND!" << endl; fclose(fp_1); fclose(fp_2); exit(-1); } // variables declaration // short int ibuf[1], obuf[1]; // data buffer unsigned long ready, start, done, result, data; // comm variables unsigned long counter = 0; // configure and initialize the DSK board // config_dsk_for_comm(); cout << "FREADER.EXE PROGRAM" << endl << endl; // obtain the samples 1 at a time into the buffer // while(fread(ibuf, 2, 1, fp_1) > 0) { // send the start signal // start = 0; putmem((unsigned long)START, 1, &start); // the dsp sets ready to false in response to hearing start // do { getmem((unsigned long)DSP_READY, 1, &ready); } while (ready == 0); // send input data // data = ibuf[0]; putmem((unsigned long)IN, 1, &data); // pull the start flag high to tell the dsp to operate on the data // start = 1; putmem((unsigned long)START, 1, &start); // wait until the dsp signals it is done with the computation // do { getmem((unsigned long)DONE, 1, &done); } while (done == 0); // output the result and write to file // getmem((unsigned long)OUT, 1, &result); obuf[0] = (short int) result; fwrite(obuf, 2, 1, fp_2); // pull done low to signal dsp we are ready for the next iteration // done = 0; putmem((unsigned long)DONE, 1, &done); // display number of samples processed // counter++; if ((counter % 1000) == 0) { cout << "Samples processed = " << counter << endl; } // initialize and prepare for next iteration // ibuf[0] = 0; obuf[0] = 0; data = 0; result = 0; } // close the file pointers // fclose(fp_1); fclose(fp_2); // indicate completion of program and exit to prompt // cout << endl << endl; cout << "FREADER COMPLETED." << endl; cout << "TOTAL # OF SAMPLES PROCESSED IS " << counter << endl; return; }