Subj : Re: Library built but Not working To : borland.public.cpp.borlandcpp From : Ed Mulroy [TeamB] Date : Wed Oct 13 2004 06:37 pm A library is only a collection of object files. The only difference in the end result, in the executable which is created, between if it were built with a library or built by explicitly linking in all the object files that are in the library is that the linker will only include those object files from the library which have things which are called or used by the object files you supply (mostly those created from your source code). I did not go through the source that you posted in detail. A quick look shows 'float' being used in many places. Look at the compiler documentation and the DOS documentation. Floating point should not be used inside an interrupt service routine. .. Ed > D Kat wrote in message > news:416d669c$1@newsgroups.borland.com... > > Well I managed to put a library together that links into a program > and the program happily compiles and runs. > > Problem is that the program no longer works with the ISR and > associated programs in the library. I should be getting displays on > an LCD board which I'm not and rather than speech I'm getting just > garbage played out. In addition the program will not escape as it > should. I have not a clue how I would debug a ISR or a Library..... > I suspect that it has something to do with the file opening and > reading being done in the main program. Any suggestions? > > This is using Borland C 3.1F and running on DOS. > > > > //*************************Library Routines for Daq802 board plus > others > > #include //disable getvect setvect enable > #include > #include > #include "daq.h" > > void __interrupt far(*ibmvec)(...); > void __interrupt i_service(...); > /***********************************************************************/ > //======================================================================= > // INIT DAQ801 > //======================================================================= > void daq_init(unsigned short rate) // Daq801 > initialize/interrupt set routine > { > int old_index; // temp index register storage > > inp(B_EN); // disable DAQ801 & reset all registers! > outp(B_EN,0); // enable board by writing to 'B_EN' > //============================= > old_index=inp(INDEX_REG)&7; // save current contents of index > reg. > outp(INDEX_REG,INT_SEL); // setup interrupt level > outp(INDEX_DAT,IRQ3); // > outp(INDEX_REG,old_index); // restore original contents > > old_index=inp(INDEX_REG)&7; // temporarily disable all > interrupts > > outp(INDEX_REG,INT_CTL); > outp(INDEX_DAT,0); > outp(INDEX_REG,old_index); > //============================= > outp (INDEX_REG,TCP); // load Daq801 index reg. with addr. > // of the 8254 control port > outp (INDEX_DAT,T0_MODE); // load 8254 CP with timer#0 mode > outp (INDEX_REG,T0); // point to timer#0 > outp (INDEX_DAT,RATE_LB[rate]); > outp (INDEX_DAT,RATE_UB_HR); > outp (INDEX_DAT,0); > //============================== > old_index=inp(INDEX_REG)&7; > outp(INDEX_REG,INT_CTL); // point to interrupt control > register > outp(INDEX_DAT,GLOBAL_ENABLE_T0); // enable board,timer#0 > interrupts > outp(INDEX_REG,old_index); > } > //========================================================================== > // INTERRUPT INITIALIZATION > //========================================================================== > void interrupt_init(void) > { > disable(); > ibmvec=getvect(DAQ_IRQ3); // get original IRQ3 vector and save > it > setvect(DAQ_IRQ3,i_service); // set vector to new service routine > > int temp; > temp=inp(0x21); // enable irq7 on 8259 by writing // > old mask w/bit#7 anded w/zero > outp(0x21,(temp & IRQ3_MASK)); // 0x7f for irq#7 > outp(0x20,EOI_IRQ3); // clear any pending 8259 > interrupts > outp (CP,CW); // write control word to 8255 control > port > enable(); // re-enable interrupts > } > //========================================================================== > // check if interupt is still running > //========================================================================== > void check_interupts(void) //check the interrupts > { > timer[0]=1; > while(timer[0]) > { > delay(1); //gives the timer a count of 1ms (10) before error and > reset > if(timer[0]) > { daq_reset(); } //error! reset DAQ board! > } > } > //========================================================================== > // DAQ RESET IF DAQ TIMER HAS STOPPED > //=========================================================================== > void daq_reset(void) // Daq801 interrupt reset routine > { > int old_index; // temp index register storage > > old_index=inp(INDEX_REG)&7; // temporarily disable all > interrupts > outp(INDEX_REG,INT_CTL); > outp(INDEX_DAT,0); > outp(INDEX_REG,old_index); > //%%%%%%%%%%%%%% > old_index=inp(INDEX_REG)&7; > outp(INDEX_REG,INT_CTL); // point to interrupt control > register > outp(INDEX_DAT,GLOBAL_ENABLE_T0); // enable board,timer#0 > interrupts > outp(INDEX_REG,old_index);//============================== > } > //========================================================================== > // restore original IRQ3 vector routine > //========================================================================== > void restor_vec(void) > { > disable(); // temporarily disable interrupts > > int temp; > temp=inp(0x21); // set bit#7 in 8259 mask=1 to disable > > outp(0x21,(temp | IRQ3_OR)); > outp(0x20,EOI_IRQ3); // clear any pending interrupt > > setvect(DAQ_IRQ3,ibmvec); // restore original vector > enable(); // re-enable interrupts > } > //========================================================================== > //interrupt routine with play and button catch > //======================================================================= > > void __interrupt i_service(...)// Daq801 interrupt service routine > { > disable(); // disable the interrupts > > int button,i; // button iterator > unsigned char PA_buttons,PC_buttons; // temp holding register for > current buttons > > inp(I_STATUS); // read the interrupt status register and clear > interrupt > > for (i=0;i for (i=0;i > if (counter[0] == file_length)PLAYFLAG=0; > if (PLAYFLAG) > { > outpw(DA_0,*da_point); > outpw(DA_1,*da_point++); > if (counter[1] == (readlength[playndx])) > {//if at end of buffer point to next buffer > ++playndx; > if(playndx==NUMBUF)playndx=0;//next buffer at 0 if beyond last > buffer > if(readlength[playndx]<2) PLAYFLAG=0;//if buffer empty - stop > play > else{ //else setup to play next buffer and read next buffer > da_point = &wavebuffer[playndx][0]; //point to next buffer to > play > counter[1]=0;//counter for this buffer set to beginning > READ = 1; > }// read flag: buffer is empty -> fill buffer > } > } > if (BUTTONFLAG) > { > PA_buttons=(inp(PA)); // freeze data > if (PA_buttons != MASK)// process following path only if one or > more > { // buttons were pressed! > for (button=0;button { > if ((PA_buttons &(1< { > ++press_count; // increment press counter > counter_time[button]=counter[0]; // record response time > } > } > } > PC_buttons=(inp(PC)&UPPER_MASK); // freeze data & mask off upper > buttons > if ((PC_buttons) != UPPER_MASK)// process following path only if > one or more > { // buttons were pressed! > for (button=4;button { > if ((PC_buttons &(1< { > ++press_count; // increment press counter > counter_time[button+4]=counter[0]; // record response time > } > } > } > } > outp(0x20,EOI_IRQ3); // clear the 8259 interrupt > enable(); // re-enable the interrupts > } // end of interrupt service routine > > void ms_delay(unsigned long time_wait,unsigned short rate)//waits > til time_wait reaches 0 > { > timer[1] = time_wait*rate; > while (timer[1]) { } > } > /***************************************************************************/ > /* CATCHES WHAT BOARD EACH SUBJECT IS AT */ > /***************************************************************************/ > int button_catch(void) > { > int button; // button iterator > > PA_buttons=(inp(PA)); // freeze data > if (PA_buttons != MASK)// process following path only if one or more > buttons were pressed! > > for (button=0;button if ((PA_buttons &(1< { > button=(button/4)+1; > return(button); > } > PC_buttons=(inp(PC)); > PC_buttons= PC_buttons&UPPER_MASK; // freeze data & mask off upper > buttons > > if ((PC_buttons) != UPPER_MASK)// process following path only if one > or more buttons were pressed! > > for (button=4;button if ((PC_buttons &(1< return(0); > } > /***********************************************************************///CONSTANT > SUBROUTINES! > int randndx(int *ndx,int num)//randomize an array from 0 - num for > indexing > { > int x,temp,y; > float f; > for (x=0; x < num;x++) > ndx[x] = x; > for (x=0; x < num;x++) > { > f=rand(); > f = f/32767; > y = f * num; > if (y < 0 || y > num) > { > cout << "y index " << y << " func stimn"; > return(0); > } > temp = ndx[y]; > ndx[y] = ndx[x]; > ndx[x] = temp; > } > return(1); > } > /***********************************************************************/ > int r01()//randomly return 0/1 > { > float ftemp,fr; > ftemp = rand(); > fr = ftemp/32767; > return(fr > .5 ? 0:1); > } > int stop() > { > char answer[2]; > cout << "\nTERMINATE? "; > cin >> answer; > if (answer[0] == 'y' || answer[0] == 'Y') > return 1; > return 0; > } > .