diff --git a/system/clkhandler.c b/system/clkhandler.c index 3759d2b..21dc18d 100644 --- a/system/clkhandler.c +++ b/system/clkhandler.c @@ -4,42 +4,62 @@ #include +#include +#include + +volatile unsigned int avr_ticks=0; + /*----------------------------------------------------------------------- * clkhandler - high level clock interrupt handler *----------------------------------------------------------------------- */ -void clkhandler() + +/* void clkhandler() */ + +ISR(TIMER0_COMPA_vect) { - struct timer_csreg *tptr; - /* Increment 1000ms counter */ + /* Every ms: What TO DO */ - count1000++; + /* every second */ + /* if avr_ticks == 1000 then 1 second */ - /* After 1 sec, increment clktime */ + avr_ticks ++; + if (avr_ticks > 100) { + avr_ticks=0; - if(count1000 >= 1000) { - clktime++; - count1000 = 0; - } - /* check if sleep queue is empty */ + /* Increment 1000ms counter */ - if(!isempty(sleepq)) { - /* sleepq nonempty, decrement the key of */ - /* topmost process on sleepq */ + count1000++; - if((--queuetab[firstid(sleepq)].qkey) == 0) { + /* After 1 sec, increment clktime */ - wakeup(); + if(count1000 >= 1000) { + clktime++; + count1000 = 0; } - } - /* Decrement the preemption counter */ - /* Reschedule if necessary */ + /* check if sleep queue is empty */ + + if(!isempty(sleepq)) { + /* sleepq nonempty, decrement the key of */ + /* topmost process on sleepq */ - if((--preempt) == 0) { - preempt = QUANTUM; - resched(); + if((--queuetab[firstid(sleepq)].qkey) == 0) { + + wakeup(); + } + } + + /* Decrement the preemption counter */ + /* Reschedule if necessary */ + + if((--preempt) == 0) { + preempt = QUANTUM; + resched(); + } } + } + diff --git a/system/clkinit.c b/system/clkinit.c index eadd0ac..8862ad3 100644 --- a/system/clkinit.c +++ b/system/clkinit.c @@ -8,9 +8,11 @@ #include uint32 clktime; /* Seconds since boot */ -uint32 count1000; /* ms since last clock tick */ +// RAFA uint32 count1000; /* ms since last clock tick */ +unsigned long count1000; /* ms since last clock tick */ qid16 sleepq; /* Queue of sleeping processes */ -uint32 preempt; /* Preemption counter */ +// RAFA uint32 preempt; /* Preemption counter */ +unsigned long preempt; /* Preemption counter */ /*------------------------------------------------------------------------ * clkinit - Initialize the clock and sleep queue at startup @@ -30,39 +32,16 @@ void clkinit(void) clktime = 0; /* Start counting seconds */ count1000 = 0; - /* AVR atmega328p timer/clock init: interrupt every 1ms */ + /* + * AVR atmega328p timer/clock init: interrupt every 1ms + * The AVR TIMER interrupt rutine is in clkhandler.c + */ TCCR0B |= (1< 100) { - avr_ticks=0; - resched(); - } - - /* every second */ - /* if avr_ticks == 1000 then 1 second */ - - sei(); -} - diff --git a/system/intr.c b/system/intr.c index fa1d611..f939d10 100644 --- a/system/intr.c +++ b/system/intr.c @@ -1,45 +1,34 @@ -/* Xinu for AVR - * - * Original license applies - * Modifications for STM32 by Robin Krens - * Please see LICENSE and AUTHORS - * - * $LOG$ - * 2019/11/11 - ROBIN KRENS - * Initial version - * - * $DESCRIPTION$ - * - * */ - /* intr.S - enable, disable, restore, halt, pause, (ARM) */ +/* avr specific */ + #include #include - -/* RAFA: the arguments and returns do not have any meaning. It were there - * for STM32. - * - * For AVR: remove them some day +/* + * This code is based on AVR-Xinu by Michael Minor */ +#include + /*------------------------------------------------------------------------ * disable - Disable interrupts and return the previous state *------------------------------------------------------------------------ */ -intmask disable() { - cli(); - return 0; +intmask disable(void) +{ + int x = SREG; + asm("cli"); /*and disable interrupts*/ + return x; } /*------------------------------------------------------------------------ * restore - Restore interrupts to value given by mask argument - Cortex M3 hardware handles a lot, rewrite *------------------------------------------------------------------------ */ -inline void restore(intmask c) { - sei(); +void restore(uint8 x) +{ + SREG = x; /*restore the status register, possibly reenabling interrupts*/ } /*------------------------------------------------------------------------