Thanks
Heres the closest Ive managed to get just after posting but its a bit of a remedial way lol
Code: Select all
void timer_wait(int ticks)
{
unsigned long eticks;
eticks = timer_ticks + ticks;
do{
if(towait == 1)
{
timer_ticks ++;
} else{
//ticks to wait is 54 which should be 3 secs
towait = 1;
}
}while(timer_ticks < eticks );
the reason for the towait flag is because the timer has already been incremented comming into the function and I dont want it incremented twice in one interrupt. not sure if my way is working properly , will try what you posted as well, Im doing this as much for understanding as anything else
actually brans initial way shouldnt be infinite looping , is it because he doesnt increment timer_ticks in timer_wait? what gets me is when interrupted timer_ticks should be incremented again in timer_handler but its like thats not happening, if its the case that when its in the while loop that is stopping any other timer_interups from happening then I think I can now see why It didnt work?
edit:
Nah that way isnt working, Im refering to my own code in this post and Im unsure why, its firing to fast , I will try taking that extra increment out the first if and if I cant get my head around whats causing the prob I will try your way, thanks for your reply
edit:
your code still isnt working for me in brans timer.c file could you tell me exactly where and how you initialise your timer_ticks variable, i.e is it in the same file as the code you gave me is it global to that file and initialised to zero? Is the int timer var thats passed to the delay function ddone so that the int ticks =18 would = 1 second.
I have no doubt your code works , I can see it should work for me but it doesnt , I still get the sameloop like some number is getting continually reset
Code: Select all
/* bkerndev - Bran's Kernel Development Tutorial
* By: Brandon F. ([email protected])
* Desc: Timer driver
*
* Notes: No warranty expressed or implied. Use at own risk. */
#include <system.h>
/* This will keep track of how many ticks that the system
* has been running for */
int timer_ticks=0;
int runonce = 0;
/* Handles the timer. In this case, it's very simple: We
* increment the 'timer_ticks' variable every time the
* timer fires. By default, the timer fires 18.222 times
* per second. Why 18.222Hz? Some engineer at IBM must've
* been smoking something funky */
void timer_handler(struct regs *r)
{
/* Increment our 'tick count' */
timer_ticks++;
/* Every 18 clocks (approximately 1 second), we will
* display a message on the screen */
if (timer_ticks % 18 == 0)
{
puts("One second has passed\n");
}
timer_wait(54); //should be 3 secs
}
/* This will continuously loop until the given time has
* been reached */
void timer_wait(int ticks)
{
int start_timer = timer_ticks;
//void delay(int ticks) {
//int start = timer_ticks;
//while(timer_ticks<start+ticks);
//}
while(timer_ticks < start_timer+ticks);
puts("waited the TIME \n");
}
/* Sets up the system clock by installing the timer handler
* into IRQ0 */
void timer_install()
{
/* Installs 'timer_handler' to IRQ0 */
irq_install_handler(0, timer_handler);
//clirq_install_handler(int irq, void (*handler)(struct regs *r))
}
edit:
Ahh crap its not because Im calling it from at the end of but inside the timer_handler function is it? , please tell me if Im wrong

because Im trying to understand this but what I think is because I put it in the timer handler function , i.e the timer_wait(int) call that every time the timer interrupts the values are being reset? (Although that doesnt make sense to me that the timer_counter should reset?, however I guess it would overflow if it didnt get set to 0 every x amount of seconds per interrupt?Is this correct>)
edit:
That timer code stillisnt working correctly even if I call it from main the message right after the while loop never fires and says alloted time waited
edit:
What the hell:( check this one out folks, why does this not work:
Code: Select all
void timer_wait(int ticks)
{
int start_timer = timer_ticks;
}while(timer_ticks < start_timer+ticks);
puts("alloted time PASSED!!!");
brans code doesnt work, (Not needing to submit that since its above ^^ or on his page.
and yet THIS does work:
Code: Select all
void timer_wait(int ticks)
{
int start_timer = timer_ticks;
do{
puts("waiting the time Im retarded and cant print past the while\n");
}while(timer_ticks < start_timer+ticks);
puts("waited the TIME \n");
[
Also this works
void timer_wait(int ticks)
{
int start_timer = timer_ticks;
puts("waiting the time Im retarded and cant print past the while\n");
}while(timer_ticks < start_timer+ticks);
puts("alloted time PASSED!!!");
Now actually Im kinda hoping its to do with the fact I have put int start_timer= timer_ticks outside the whileloop? If this is the case that means the other timer code wouldnt work either?
Is there a better way form to do this than how I have done? On looking at all my submissions and Im thinking of when I did java here if you did like an iff with only one line after it you didnt need bracers , wander if thats anything to do with it?