Delay
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Delay
1) install a valid IDT
2) program the Programmable Interval Counter chip to have some useful frequency (default is 18.2Hz, 1Khz is usually better)
3) use the timer interrupt to count milliseconds
then
nb: this is to be checked by disasembly to see if the compiler doesn't optimized the while(!done); into some while(1); - but it shouldn't
if you have multithreaded support, replace the done variable by some threadResume mechanism (and use a linked list of delay requests, each with its own delay value).
2) program the Programmable Interval Counter chip to have some useful frequency (default is 18.2Hz, 1Khz is usually better)
3) use the timer interrupt to count milliseconds
then
Code: Select all
int delay;
volatile int done;
wait(int milli) {
done=false;
delay=milli;
while (!done);
}
timer_interrupt_handler() {
if (!done && delay) delay--;
if (delay==0) done=true;
}
if you have multithreaded support, replace the done variable by some threadResume mechanism (and use a linked list of delay requests, each with its own delay value).
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Delay
Mobius has two delay routines: one similar to Pype.Clicker's (which uses the clock interrupt) and one high-resolution routine which doesn't use interrupts.
Link to high-resolution timer:
http://cvs.sourceforge.net/cgi-bin/view ... cvs-markup (function: ArchMicroDelay)
Programmable Interval Timer init code:
Link to high-resolution timer:
http://cvs.sourceforge.net/cgi-bin/view ... cvs-markup (function: ArchMicroDelay)
Programmable Interval Timer init code:
Code: Select all
/*! \brief Sets up the PC's programmable timer to issue interrupts at HZ
* (100 Hz) instead of the default ~18.2 Hz.
* \param hz The required clock frequency, in hertz
*/
void i386PitInit(unsigned hz)
{
unsigned short foo = (3579545L / 3) / hz;
/* reprogram the 8253 timer chip to run at 'HZ', instead of 18 Hz */
out(0x43, 0x36); /* channel 0, LSB/MSB, mode 3, binary */
out(0x40, foo & 0xFF); /* LSB */
out(0x40, foo >> 8); /* MSB */
}
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Delay
hmmm ... if get this right, it launch a "one-shot" timer on an alternative channel of the PIT and polls for end-of-period, right ?
interresting technique ...
interresting technique ...
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Delay
come on! this is not *that* hard to translate those little function in ASM, especially Tim's one
out(x,y)
becomes
mov al,y
out x,al
only the division will require you a few more computations ...
once you get your 16-bits value in ax for the frequency (if your frequency is fixed, you can ask your HP48 to do the computation instead of programming it you don't even need to do the &0xff and >>8 stuff: just use al and ah !
out(x,y)
becomes
mov al,y
out x,al
only the division will require you a few more computations ...
once you get your 16-bits value in ax for the frequency (if your frequency is fixed, you can ask your HP48 to do the computation instead of programming it you don't even need to do the &0xff and >>8 stuff: just use al and ah !
Re:Delay
Ok, you guys talked me into it. I am going to learn C but only so I can translate the examples people have given me. I am writing my operating system soley in assembly language. So I won't be using any C code in my os.
What compiler do you suggest I use?
At my school they have C books but they are too old and so there is no Cd-rom to go with the book. I can check out the book, but since I dont have the program to run and compile the code, Im stuck. They have alot of C++ books though with the programs I need.
What do you suggest I do?
What compiler do you suggest I use?
At my school they have C books but they are too old and so there is no Cd-rom to go with the book. I can check out the book, but since I dont have the program to run and compile the code, Im stuck. They have alot of C++ books though with the programs I need.
What do you suggest I do?
Re:Delay
Try out cc386 for a compiler. It doesn't do all the fancy tricks of gcc, but it has a nice windows ide and (First time I've seen this anywhere) you can get it to produce a nasm syntax text file as an intermediate step. So you can see exactly how cc386 turns your C instructions into something the computer can understand. Very handy if you're more familiar with C than asm.
Homepage is http://members.tripod.com/~ladsoft
Homepage is http://members.tripod.com/~ladsoft