Subj : Re: Library built but Not working To : borland.public.cpp.borlandcpp From : dkat Date : Thu Oct 14 2004 02:18 pm I will take anything I can get but the only place float is being used is in a little subroutine that randomizes an index of numbers. I just stuck this in the library because it never changes and is used in every program that uses the DAQ. I took a working program and pulled out all of the routines that had anything to do with the DAQ802 board and put them in a separate file. So except for how things are declared and the fact that the routines connected to the DAQ board are now precompiled there is really no change in the code. The program runs. I just get garbage played out and the LCD does not display. I know globals are frowned upon but they really are necessary for ISR and the buffers it uses. These must come from the main program. I believe that this is where things are failing when I load the routines as a separate file with the previous global variables now being treated as externals in the Main program.... My problem is grasping where the scope of the variables are and how I should be declaring them... I am pulling out all of my old books but nothing really addresses when you are compiling routines outside of your main code. I ended up declaring the buffer that holds the sound file as a double pointer in main and as a fixed array in the library. Perhaps this should be the other way around.... "Ed Mulroy [TeamB]" wrote in message news:416da02d@newsgroups.borland.com... > 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 All the variables in the ISR are either int, short or long //========================================================================== //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 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 > 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 > > } > > 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); > > } > > //** SUBROUTINES for randomizing index of numbers > > 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; > > } > > > > .