static void timer_test_constants(void) { kprintf("TIMER_HW_HPTICKS_PER_SEC=%lu\n", (unsigned long)TIMER_HW_HPTICKS_PER_SEC); #ifdef TIMER_PRESCALER kprintf("TIMER_PRESCALER = %lu\n", (unsigned long)TIMER_PRESCALER); #endif #ifdef TIMER1_OVF_COUNT kprintf("TIMER1_OVF_COUNT = %lu\n", (unsigned long)TIMER1_OVF_COUNT); #endif kprintf("TIMER_TICKS_PER_SEC= %lu\n", (unsigned long)TIMER_TICKS_PER_SEC); kprintf("\n"); kprintf("ms_to_ticks(100) = %lu\n", (unsigned long)ms_to_ticks(100)); kprintf("ms_to_ticks(10000) = %lu\n", (unsigned long)ms_to_ticks(10000)); kprintf("us_to_ticks(100) = %lu\n", (unsigned long)us_to_ticks(100)); kprintf("us_to_ticks(10000) = %lu\n", (unsigned long)us_to_ticks(10000)); kprintf("\n"); kprintf("ticks_to_ms(100) = %lu\n", (unsigned long)ticks_to_ms(100)); kprintf("ticks_to_ms(10000) = %lu\n", (unsigned long)ticks_to_ms(10000)); kprintf("ticks_to_us(100) = %lu\n", (unsigned long)ticks_to_us(100)); kprintf("ticks_to_us(10000) = %lu\n", (unsigned long)ticks_to_us(10000)); kprintf("\n"); kprintf("hptime_to_us(100) = %lu\n", (unsigned long)hptime_to_us(100)); #if (SIZEOF_HPTIME_T > 1) kprintf("hptime_to_us(10000)= %lu\n", (unsigned long)hptime_to_us(10000)); #endif kprintf("us_to_hptime(100) = %lu\n", (unsigned long)us_to_hptime(100)); kprintf("us_to_hptime(10000)= %lu\n", (unsigned long)us_to_hptime(10000)); }
uint32 cdp_cmd(UNIT * uptr, uint16 cmd, uint16 dev) { int chan = UNIT_G_CHAN(uptr->flags); int u = (uptr - cdp_unit); extern uint16 IC; if ((uptr->flags & UNIT_ATT) != 0 && cmd == IO_WRS) { /* Start device */ if (!(uptr->u5 & CDPSTA_CMD)) { dev_pulse[chan] &= ~PUNCH_M; uptr->u5 &= ~CDPSTA_PUNCH; if ((uptr->u5 & CDPSTA_ON) == 0) { uptr->wait = 330; /* Startup delay */ } else if (uptr->u5 & CDPSTA_IDLE && uptr->wait <= 30) { uptr->wait += 85; /* Wait for next latch point */ } uptr->u5 |= (CDPSTA_WRITE | CDPSTA_CMD); uptr->u5 &= ~CDPSTA_POSMASK; chan_set_sel(chan, 1); chan_clear_status(chan); sim_activate(uptr, us_to_ticks(1000)); /* activate */ sim_debug(DEBUG_CMD, &cdp_dev, "%05o WRS unit=%d\n", IC, u); return SCPE_OK; } } chan_set_attn(chan); return SCPE_IOERR; }
/* generate an interrupt after the specified time (in microseconds) */ void clock_generate_interrupt(uint64_t time) { uint64_t clock = clock_read(); while(timer_timeout(timer_device.ti, us_to_ticks(timer_device.frequency, clock + time))) time *= 2; }
/* delay x useconds */ void __udelay(unsigned long usec) { unsigned long start = readl(&timer_base->tcrr); unsigned long ticks = us_to_ticks(usec); if (usec == 0) return; if (ticks == 0) ticks++; while (readl(&timer_base->tcrr) - start < ticks) /* NOP */ ; }
/* Wait for the specified time (in microseconds) */ void clock_wait(uint64_t time) { int error; uint64_t clock = clock_read(); uint64_t timeout = clock + time; error = okn_syscall_interrupt_register(CLOCK_IRQ); assert(!error); if (timer_timeout(timer_device.ti, us_to_ticks(timer_device.frequency, timeout))) { error = okn_syscall_interrupt_deregister(CLOCK_IRQ); assert(!error); return; /* Already expired */ } /* wait for the interrupt */ while(!device_interrupt(timer_device.di, okn_syscall_interrupt_wait())); error = okn_syscall_interrupt_deregister(CLOCK_IRQ); assert(!error); }
t_stat cdp_srv(UNIT * uptr) { int chan = UNIT_G_CHAN(uptr->flags); int u = (uptr - cdp_unit); int pos; t_uint64 wd; int bit; t_uint64 mask; int b; int col; struct _card_data *data; /* Channel has disconnected, abort current card. */ if (uptr->u5 & CDPSTA_CMD && chan_stat(chan, DEV_DISCO)) { if ((uptr->u5 & CDPSTA_POSMASK) != 0) { sim_debug(DEBUG_DETAIL, &cdp_dev, "punch card\n"); sim_punch_card(uptr, NULL); uptr->u5 &= ~CDPSTA_PUNCH; } uptr->u5 &= ~(CDPSTA_WRITE | CDPSTA_CMD | CDPSTA_POSMASK); chan_clear(chan, DEV_WEOR | DEV_SEL); sim_debug(DEBUG_CHAN, &cdp_dev, "unit=%d disconnect\n", u); } /* Check to see if we have timed out */ if (uptr->wait != 0) { uptr->wait--; /* If at end of record and channel is still active, do another read */ if ( ((uptr->u5 & (CDPSTA_CMD | CDPSTA_IDLE | CDPSTA_WRITE | CDPSTA_ON)) == (CDPSTA_CMD | CDPSTA_IDLE | CDPSTA_ON)) && uptr->wait > 30 && chan_test(chan, STA_ACTIVE)) { uptr->u5 |= CDPSTA_WRITE; uptr->u5 &= ~CDPSTA_IDLE; chan_set(chan, DEV_WRITE); chan_clear(chan, DEV_WEOR); sim_debug(DEBUG_CHAN, &cdp_dev, "unit=%d restarting\n", u); } sim_activate(uptr, us_to_ticks(1000)); /* activate */ return SCPE_OK; } /* If no write request, go to idle mode */ if ((uptr->u5 & CDPSTA_WRITE) == 0) { if ((uptr->u5 & (CDPSTA_IDLE | CDPSTA_ON)) == (CDPSTA_IDLE | CDPSTA_ON)) { uptr->wait = 85; /* Delay 85ms */ uptr->u5 &= ~CDPSTA_IDLE; /* Not running */ sim_activate(uptr, us_to_ticks(1000)); } else { uptr->u5 &= ~CDPSTA_ON; /* Turn motor off */ } return SCPE_OK; } /* Motor is up to speed now */ uptr->u5 |= CDPSTA_ON; uptr->u5 &= ~CDPSTA_IDLE; /* Not running */ if (dev_pulse[chan] & PUNCH_M) uptr->u5 |= CDPSTA_PUNCH; pos = (uptr->u5 & CDPSTA_POSMASK) >> CDPSTA_POSSHIFT; if (pos == 24) { if (chan_test(chan, STA_ACTIVE)) { sim_debug(DEBUG_CHAN, &cdp_dev, "unit=%d set EOR\n", u); chan_set(chan, DEV_REOR); } else { chan_clear(chan, DEV_WEOR | DEV_SEL); sim_debug(DEBUG_CHAN, &cdp_dev, "unit=%d disconnect\n", u); } sim_debug(DEBUG_DETAIL, &cdp_dev, "punch card\n"); sim_punch_card(uptr, NULL); uptr->u5 |= CDPSTA_IDLE; uptr->u5 &= ~(CDPSTA_WRITE | CDPSTA_POSMASK | CDPSTA_PUNCH); uptr->wait = 85; sim_activate(uptr, us_to_ticks(1000)); return SCPE_OK; } sim_debug(DEBUG_DATA, &cdp_dev, "unit=%d write column %d ", u, pos); wd = 0; data = (struct _card_data *)uptr->up7; switch (chan_read(chan, &wd, 0)) { case DATA_OK: sim_debug(DEBUG_DATA, &cdp_dev, " %012llo\n", wd); /* Bit flip into temp buffer */ bit = 1 << (pos / 2); mask = 1; b = (pos & 1)?36:0; for (col = 35; col >= 0; mask <<= 1, col--) { if (wd & mask) data->image[col + b] |= bit; } pos++; uptr->wait = 0; uptr->u5 &= ~CDPSTA_POSMASK; uptr->u5 |= (pos << CDPSTA_POSSHIFT) & CDPSTA_POSMASK; sim_activate(uptr, (pos & 1) ? us_to_ticks(300) : us_to_ticks(8000)); return SCPE_OK; case END_RECORD: sim_debug(DEBUG_DATA, &cdp_dev, "eor\n"); uptr->wait = 8 * (12 - (pos / 2)) /*+ 85*/; uptr->u5 &= ~(CDPSTA_POSMASK); uptr->u5 |= (24 << CDPSTA_POSSHIFT) & CDPSTA_POSMASK; break; case TIME_ERROR: sim_debug(DEBUG_DATA, &cdp_dev, "no data\n"); uptr->wait = 8 * (12 - (pos / 2)) /*+ 85*/; uptr->u5 &= ~(CDPSTA_POSMASK); uptr->u5 |= (24 << CDPSTA_POSSHIFT) & CDPSTA_POSMASK; break; } sim_activate(uptr, us_to_ticks(1000)); return SCPE_OK; }
/* This is usually in libogc; we can't use that on wiiu */ int usleep(useconds_t microseconds) { OSSleepTicks(us_to_ticks(microseconds)); return 0; }