* Makefile.in (SIM_OBJS): Add dsp.o.
[deliverable/binutils-gdb.git] / sim / mips / dv-tx3904tmr.c
index b1014218a5e131ffb361d19771ddfdaac8d4bcaa..c1c7b8ce601f8d77ac4330f378ec5ea9c9c1c378 100644 (file)
@@ -151,6 +151,7 @@ struct tx3904tmr {
   signed_8 last_ticks; /* time at last deliver_*_tick call */
   signed_8 roundoff_ticks; /* sim ticks unprocessed during last tick call */
   int ff; /* pulse generator flip-flop value: 1/0 */
+  struct hw_event* event; /* last scheduled event */
 
   unsigned_4 tcr;
 #define GET_TCR_TCE(c)      (((c)->tcr & 0x80) >> 7)
@@ -265,6 +266,8 @@ tx3904tmr_finish (struct hw *me)
     controller->trr = 0;
   controller->cpra = controller->cprb = 0x00FFFFFF;
   controller->ff = 0;
+  controller->last_ticks = controller->roundoff_ticks = 0;
+  controller->event = NULL;
 }
 
 
@@ -297,6 +300,10 @@ tx3904tmr_port_event (struct hw *me,
          controller->tisr = 
          controller->trr = 0;
        controller->cpra = controller->cprb = 0x00FFFFFF;
+       controller->last_ticks = controller->roundoff_ticks = 0;
+       if(controller->event != NULL)
+         hw_event_queue_deschedule(me, controller->event);
+       controller->event = NULL;
        break;
       }
 
@@ -324,7 +331,7 @@ tx3904tmr_io_read_buffer (struct hw *me,
     {
       address_word address = base + byte;
       int reg_number = (address - controller->base_address) / 4;
-      int reg_offset = (address - controller->base_address) % 4;
+      int reg_offset = 3 - (address - controller->base_address) % 4;
       unsigned_4 register_value; /* in target byte order */
 
       /* fill in entire register_value word */
@@ -365,11 +372,9 @@ tx3904tmr_io_write_buffer (struct hw *me,
   for (byte = 0; byte < nr_bytes; byte++)
     {
       address_word address = base + byte;
-      unsigned_1 write_byte = ((char*) source)[byte];
+      unsigned_1 write_byte = ((const char*) source)[byte];
       int reg_number = (address - controller->base_address) / 4;
-      int reg_offset = (address - controller->base_address) % 4;
-      unsigned_4* register_ptr;
-      unsigned_4 register_value;
+      int reg_offset = 3 - (address - controller->base_address) % 4;
 
       /* fill in entire register_value word */
       switch (reg_number)
@@ -384,9 +389,8 @@ tx3904tmr_io_write_buffer (struct hw *me,
              if(GET_TCR_TCE(controller) == 0 &&
                 GET_TCR_CRE(controller) == 1)
                controller->trr = 0;
-
            }
-         HW_TRACE ((me, "tcr: %08lx", (long) controller->tcr));
+         /* HW_TRACE ((me, "tcr: %08lx", (long) controller->tcr)); */
          break;
 
        case ITMR_REG:
@@ -398,7 +402,7 @@ tx3904tmr_io_write_buffer (struct hw *me,
            {
              SET_ITMR_TZCE(controller, write_byte & 0x01);
            }
-         HW_TRACE ((me, "itmr: %08lx", (long) controller->itmr));
+         /* HW_TRACE ((me, "itmr: %08lx", (long) controller->itmr)); */
          break;
 
        case CCDR_REG:
@@ -406,7 +410,7 @@ tx3904tmr_io_write_buffer (struct hw *me,
            {
              controller->ccdr = write_byte & 0x07;
            }
-         HW_TRACE ((me, "ccdr: %08lx", (long) controller->ccdr));
+         /* HW_TRACE ((me, "ccdr: %08lx", (long) controller->ccdr)); */
          break;
 
        case PMGR_REG:
@@ -419,7 +423,7 @@ tx3904tmr_io_write_buffer (struct hw *me,
            {
              SET_PMGR_FFI(controller, write_byte & 0x01);
            }
-         HW_TRACE ((me, "pmgr: %08lx", (long) controller->pmgr));
+         /* HW_TRACE ((me, "pmgr: %08lx", (long) controller->pmgr)); */
          break;
 
        case WTMR_REG:
@@ -432,7 +436,7 @@ tx3904tmr_io_write_buffer (struct hw *me,
              SET_WTMR_WDIS(controller, write_byte & 0x80);
              SET_WTMR_TWC(controller, write_byte & 0x01);
            }
-         HW_TRACE ((me, "wtmr: %08lx", (long) controller->wtmr));
+         /* HW_TRACE ((me, "wtmr: %08lx", (long) controller->wtmr)); */
          break;
 
        case TISR_REG:
@@ -450,23 +454,23 @@ tx3904tmr_io_write_buffer (struct hw *me,
              /* clear interrupt status register */
              controller->tisr = 0;
            }
-         HW_TRACE ((me, "tisr: %08lx", (long) controller->tisr));
+         /* HW_TRACE ((me, "tisr: %08lx", (long) controller->tisr)); */
          break;
 
        case CPRA_REG:
          if(reg_offset < 3) /* first, second, or third byte */
            {
-             MBLIT32(controller->cpra, (reg_offset*8), (reg_offset*8+7), write_byte);
+             MBLIT32(controller->cpra, (reg_offset*8)+7, (reg_offset*8), write_byte);
            }
-         HW_TRACE ((me, "cpra: %08lx", (long) controller->cpra));
+         /* HW_TRACE ((me, "cpra: %08lx", (long) controller->cpra)); */
          break;
 
        case CPRB_REG:
          if(reg_offset < 3) /* first, second, or third byte */
            {
-             MBLIT32(controller->cprb, (reg_offset*8), (reg_offset*8+7), write_byte);
+             MBLIT32(controller->cprb, (reg_offset*8)+7, (reg_offset*8), write_byte);
            }
-         HW_TRACE ((me, "cprb: %08lx", (long) controller->cprb));
+         /* HW_TRACE ((me, "cprb: %08lx", (long) controller->cprb)); */
          break;
 
        default: 
@@ -492,15 +496,27 @@ deliver_tx3904tmr_tick (struct hw *me,
   SIM_DESC sd = hw_system (me);
   signed_8 this_ticks = sim_events_time(sd);
 
-  /* compute simulation ticks between last tick and this tick */
-  signed_8 warp = this_ticks - controller->last_ticks + controller->roundoff_ticks;
+  signed_8 warp;
   signed_8 divisor;
-  signed_8 quotient, reminder;
+  signed_8 quotient, remainder;
+
+  /* compute simulation ticks between last tick and this tick */
+  if(controller->last_ticks != 0)
+    warp = this_ticks - controller->last_ticks + controller->roundoff_ticks;
+  else
+    {
+      controller->last_ticks = this_ticks; /* initialize */
+      warp = controller->roundoff_ticks;
+    }
+
+  if(controller->event != NULL)
+    hw_event_queue_deschedule(me, controller->event);
+  controller->event = NULL;
 
   /* Check whether the timer ticking is enabled at this moment.  This
      largely a function of the TCE bit, but is also slightly
      mode-dependent. */
-  switch(GET_TCR_TMODE(controller))
+  switch((int) GET_TCR_TMODE(controller))
     {
     case 0: /* interval */
       /* do not advance counter if TCE = 0 or if holding at count = CPRA */
@@ -538,27 +554,27 @@ deliver_tx3904tmr_tick (struct hw *me,
     {
       /* apply internal clock divider */
       if(GET_TCR_CCDE(controller)) /* divisor circuit enabled? */
-       divisor = controller->ext_ticks * (1 << (1 + GET_CCDR_CDR(controller)));
+       divisor = controller->clock_ticks * (1 << (1 + GET_CCDR_CDR(controller)));
       else
-       divisor = controller->ext_ticks;
+       divisor = controller->clock_ticks;
     }
   else
     {
-      divisor = controller->clock_ticks;
+      divisor = controller->ext_ticks;
     }
 
   /* how many times to increase counter? */
   quotient = warp / divisor;
-  reminder = warp % divisor;
+  remainder = warp % divisor;
 
   /* NOTE: If the event rescheduling code works properly, the quotient
      should never be larger than 1.  That is, we should receive events
      here at least as frequently as the simulated counter is supposed
-     to decrement.  So the reminder (-> roundoff_ticks) will slowly
+     to decrement.  So the remainder (-> roundoff_ticks) will slowly
      accumulate, with the quotient == 0.  Once in a while, quotient
      will equal 1. */
 
-  controller->roundoff_ticks = reminder;
+  controller->roundoff_ticks = remainder;
   controller->last_ticks = this_ticks;
   while(quotient > 0) /* Is it time to increment counter? */
     {
@@ -566,7 +582,7 @@ deliver_tx3904tmr_tick (struct hw *me,
       unsigned_4 next_trr = (controller->trr + 1) % (1 << 24);
       quotient --;
       
-      switch(GET_TCR_TMODE(controller))
+      switch((int) GET_TCR_TMODE(controller))
        {
        case 0: /* interval timer mode */
          {
@@ -663,13 +679,14 @@ deliver_tx3904tmr_tick (struct hw *me,
 
       /* update counter and report */
       controller->trr = next_trr;
-      HW_TRACE ((me, "counter trr %d tisr %x", controller->trr, controller->tisr));
+      /* HW_TRACE ((me, "counter trr %ld tisr %lx",
+        (long) controller->trr, (long) controller->tisr)); */
     } /* end quotient loop */
 
   /* Reschedule a timer event in near future, so we can increment the
-     counter again.  Set the event about 50% of divisor time away, so
-     we will experience roughly two events per counter increment. */
-  hw_event_queue_schedule(me, divisor/2, deliver_tx3904tmr_tick, NULL);
+     counter again.  Set the event about 75% of divisor time away, so
+     we will experience roughly 1.3 events per counter increment. */
+  controller->event = hw_event_queue_schedule(me, divisor*3/4, deliver_tx3904tmr_tick, NULL);
 }
 
 
This page took 0.025869 seconds and 4 git commands to generate.