1.1 --- a/src/sh4/timer.c Wed Jan 30 09:38:24 2008 +0000
1.2 +++ b/src/sh4/timer.c Sat Aug 09 07:39:47 2008 +0000
1.6 case FRQCR: /* Frequency control */
1.7 - div = ifc_divider[(val >> 6) & 0x07];
1.8 - sh4_cpu_freq = sh4_input_freq / div;
1.9 - sh4_cpu_period = sh4_cpu_multiplier * div / sh4_input_freq;
1.10 - div = ifc_divider[(val >> 3) & 0x07];
1.11 - sh4_bus_freq = sh4_input_freq / div;
1.12 - sh4_bus_period = 1000 * div / sh4_input_freq;
1.13 - div = pfc_divider[val & 0x07];
1.14 - sh4_peripheral_freq = sh4_input_freq / div;
1.15 - sh4_peripheral_period = 1000 * div / sh4_input_freq;
1.16 + div = ifc_divider[(val >> 6) & 0x07];
1.17 + sh4_cpu_freq = sh4_input_freq / div;
1.18 + sh4_cpu_period = sh4_cpu_multiplier * div / sh4_input_freq;
1.19 + div = ifc_divider[(val >> 3) & 0x07];
1.20 + sh4_bus_freq = sh4_input_freq / div;
1.21 + sh4_bus_period = 1000 * div / sh4_input_freq;
1.22 + div = pfc_divider[val & 0x07];
1.23 + sh4_peripheral_freq = sh4_input_freq / div;
1.24 + sh4_peripheral_period = 1000 * div / sh4_input_freq;
1.26 - /* Update everything that depends on the peripheral frequency */
1.27 - SCIF_update_line_speed();
1.29 + /* Update everything that depends on the peripheral frequency */
1.30 + SCIF_update_line_speed();
1.32 case WTCSR: /* Watchdog timer */
1.38 MMIO_WRITE( CPG, reg, val );
1.41 @@ -136,14 +136,14 @@
1.45 - TMU_count( 0, sh4r.slice_cycle );
1.47 + TMU_count( 0, sh4r.slice_cycle );
1.50 - TMU_count( 1, sh4r.slice_cycle );
1.52 + TMU_count( 1, sh4r.slice_cycle );
1.55 - TMU_count( 2, sh4r.slice_cycle );
1.57 + TMU_count( 2, sh4r.slice_cycle );
1.60 return MMIO_READ( TMU, reg );
1.62 @@ -154,45 +154,45 @@
1.63 uint32_t oldtcr = MMIO_READ( TMU, TCR0 + (12*timer) );
1.65 if( (oldtcr & TCR_UNF) == 0 ) {
1.66 - tcr = tcr & (~TCR_UNF);
1.67 + tcr = tcr & (~TCR_UNF);
1.69 - if( ((oldtcr & TCR_UNIE) == 0) &&
1.70 - (tcr & TCR_IRQ_ACTIVE) == TCR_IRQ_ACTIVE ) {
1.71 - intc_raise_interrupt( INT_TMU_TUNI0 + timer );
1.72 - } else if( (oldtcr & TCR_UNIE) != 0 &&
1.73 - (tcr & TCR_IRQ_ACTIVE) != TCR_IRQ_ACTIVE ) {
1.74 - intc_clear_interrupt( INT_TMU_TUNI0 + timer );
1.76 + if( ((oldtcr & TCR_UNIE) == 0) &&
1.77 + (tcr & TCR_IRQ_ACTIVE) == TCR_IRQ_ACTIVE ) {
1.78 + intc_raise_interrupt( INT_TMU_TUNI0 + timer );
1.79 + } else if( (oldtcr & TCR_UNIE) != 0 &&
1.80 + (tcr & TCR_IRQ_ACTIVE) != TCR_IRQ_ACTIVE ) {
1.81 + intc_clear_interrupt( INT_TMU_TUNI0 + timer );
1.85 switch( tcr & 0x07 ) {
1.87 - period = sh4_peripheral_period << 2 ;
1.89 + period = sh4_peripheral_period << 2 ;
1.92 - period = sh4_peripheral_period << 4;
1.94 + period = sh4_peripheral_period << 4;
1.97 - period = sh4_peripheral_period << 6;
1.99 + period = sh4_peripheral_period << 6;
1.102 - period = sh4_peripheral_period << 8;
1.104 + period = sh4_peripheral_period << 8;
1.107 - period = sh4_peripheral_period << 10;
1.109 + period = sh4_peripheral_period << 10;
1.112 - /* Illegal value. */
1.113 - ERROR( "TMU %d period set to illegal value (5)", timer );
1.114 - period = sh4_peripheral_period << 12; /* for something to do */
1.116 + /* Illegal value. */
1.117 + ERROR( "TMU %d period set to illegal value (5)", timer );
1.118 + period = sh4_peripheral_period << 12; /* for something to do */
1.121 - period = rtc_output_period;
1.123 + period = rtc_output_period;
1.126 - /* External clock... Hrm? */
1.127 - period = sh4_peripheral_period; /* I dunno... */
1.129 + /* External clock... Hrm? */
1.130 + period = sh4_peripheral_period; /* I dunno... */
1.133 TMU_timers[timer].timer_period = period;
1.135 @@ -202,9 +202,9 @@
1.136 void TMU_schedule_timer( int timer )
1.138 uint64_t duration = (uint64_t)((uint32_t)(MMIO_READ( TMU, TCNT0 + 12*timer )+1)) *
1.139 - (uint64_t)TMU_timers[timer].timer_period - TMU_timers[timer].timer_remainder;
1.140 + (uint64_t)TMU_timers[timer].timer_period - TMU_timers[timer].timer_remainder;
1.141 event_schedule_long( EVENT_TMU0+timer, (uint32_t)(duration / 1000000000),
1.142 - (uint32_t)(duration % 1000000000) );
1.143 + (uint32_t)(duration % 1000000000) );
1.146 void TMU_start( int timer )
1.147 @@ -229,26 +229,26 @@
1.148 uint32_t TMU_count( int timer, uint32_t nanosecs )
1.150 uint32_t run_ns = nanosecs + TMU_timers[timer].timer_remainder -
1.151 - TMU_timers[timer].timer_run;
1.152 + TMU_timers[timer].timer_run;
1.153 TMU_timers[timer].timer_remainder =
1.154 - run_ns % TMU_timers[timer].timer_period;
1.155 + run_ns % TMU_timers[timer].timer_period;
1.156 TMU_timers[timer].timer_run = nanosecs;
1.157 uint32_t count = run_ns / TMU_timers[timer].timer_period;
1.158 uint32_t value = MMIO_READ( TMU, TCNT0 + 12*timer );
1.159 uint32_t reset = MMIO_READ( TMU, TCOR0 + 12*timer );
1.160 if( count > value ) {
1.161 - uint32_t tcr = MMIO_READ( TMU, TCR0 + 12*timer );
1.164 + uint32_t tcr = MMIO_READ( TMU, TCR0 + 12*timer );
1.167 value = reset - (count % reset) + 1;
1.168 - MMIO_WRITE( TMU, TCR0 + 12*timer, tcr );
1.169 - if( tcr & TCR_UNIE )
1.170 - intc_raise_interrupt( INT_TMU_TUNI0 + timer );
1.171 - MMIO_WRITE( TMU, TCNT0 + 12*timer, value );
1.172 - TMU_schedule_timer(timer);
1.173 + MMIO_WRITE( TMU, TCR0 + 12*timer, tcr );
1.174 + if( tcr & TCR_UNIE )
1.175 + intc_raise_interrupt( INT_TMU_TUNI0 + timer );
1.176 + MMIO_WRITE( TMU, TCNT0 + 12*timer, value );
1.177 + TMU_schedule_timer(timer);
1.180 - MMIO_WRITE( TMU, TCNT0 + 12*timer, value );
1.182 + MMIO_WRITE( TMU, TCNT0 + 12*timer, value );
1.186 @@ -259,45 +259,45 @@
1.190 - oldval = MMIO_READ( TMU, TSTR );
1.191 - for( i=0; i<3; i++ ) {
1.192 - uint32_t tmp = 1<<i;
1.193 - if( (oldval & tmp) != 0 && (val&tmp) == 0 )
1.195 - else if( (oldval&tmp) == 0 && (val&tmp) != 0 )
1.199 + oldval = MMIO_READ( TMU, TSTR );
1.200 + for( i=0; i<3; i++ ) {
1.201 + uint32_t tmp = 1<<i;
1.202 + if( (oldval & tmp) != 0 && (val&tmp) == 0 )
1.204 + else if( (oldval&tmp) == 0 && (val&tmp) != 0 )
1.209 - TMU_set_timer_control( 0, val );
1.211 + TMU_set_timer_control( 0, val );
1.214 - TMU_set_timer_control( 1, val );
1.216 + TMU_set_timer_control( 1, val );
1.219 - TMU_set_timer_control( 2, val );
1.221 + TMU_set_timer_control( 2, val );
1.224 - MMIO_WRITE( TMU, reg, val );
1.225 - if( TMU_IS_RUNNING(0) ) { // reschedule
1.226 - TMU_timers[0].timer_run = sh4r.slice_cycle;
1.227 - TMU_schedule_timer( 0 );
1.230 + MMIO_WRITE( TMU, reg, val );
1.231 + if( TMU_IS_RUNNING(0) ) { // reschedule
1.232 + TMU_timers[0].timer_run = sh4r.slice_cycle;
1.233 + TMU_schedule_timer( 0 );
1.237 - MMIO_WRITE( TMU, reg, val );
1.238 - if( TMU_IS_RUNNING(1) ) { // reschedule
1.239 - TMU_timers[1].timer_run = sh4r.slice_cycle;
1.240 - TMU_schedule_timer( 1 );
1.243 + MMIO_WRITE( TMU, reg, val );
1.244 + if( TMU_IS_RUNNING(1) ) { // reschedule
1.245 + TMU_timers[1].timer_run = sh4r.slice_cycle;
1.246 + TMU_schedule_timer( 1 );
1.250 - MMIO_WRITE( TMU, reg, val );
1.251 - if( TMU_IS_RUNNING(2) ) { // reschedule
1.252 - TMU_timers[2].timer_run = sh4r.slice_cycle;
1.253 - TMU_schedule_timer( 2 );
1.256 + MMIO_WRITE( TMU, reg, val );
1.257 + if( TMU_IS_RUNNING(2) ) { // reschedule
1.258 + TMU_timers[2].timer_run = sh4r.slice_cycle;
1.259 + TMU_schedule_timer( 2 );
1.263 MMIO_WRITE( TMU, reg, val );
1.265 @@ -306,13 +306,13 @@
1.267 int tcr = MMIO_READ( TMU, TSTR );
1.269 - TMU_count( 0, nanosecs );
1.270 + TMU_count( 0, nanosecs );
1.273 - TMU_count( 1, nanosecs );
1.274 + TMU_count( 1, nanosecs );
1.277 - TMU_count( 2, nanosecs );
1.278 + TMU_count( 2, nanosecs );