#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: timer_hb.c,v 1.21 2024/01/15 20:21:50 thorpej Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/intr.h>
#include <uvm/uvm_extern.h>
#include <machine/cpu.h>
#include <machine/bus.h>
#include <machine/vectors.h>
#include <dev/clock_subr.h>
#include <news68k/news68k/isr.h>
#include <news68k/news68k/clockvar.h>
#include <news68k/dev/hbvar.h>
#include "ioconf.h"
#define TIMER_LEVEL 6
#define TIMER_SIZE 8
static int timer_hb_match(device_t, cfdata_t, void *);
static void timer_hb_attach(device_t, device_t, void *);
static void timer_hb_initclocks(int, int);
void clock_intr(struct clockframe);
static inline void leds_intr(void);
extern void _isr_clock(void);
CFATTACH_DECL_NEW(timer_hb, 0,
timer_hb_match, timer_hb_attach, NULL, NULL);
static volatile uint8_t *ctrl_timer;
extern volatile u_char *ctrl_led;
static int
timer_hb_match(device_t parent, cfdata_t cf, void *aux)
{
struct hb_attach_args *ha = aux;
static int timer_hb_matched;
if (timer_hb_matched)
return 0;
if (strcmp(ha->ha_name, timer_cd.cd_name))
return 0;
if (ha->ha_ipl == -1)
ha->ha_ipl = TIMER_LEVEL;
ha->ha_size = TIMER_SIZE;
timer_hb_matched = 1;
return 1;
}
static void
timer_hb_attach(device_t parent, device_t self, void *aux)
{
struct hb_attach_args *ha = aux;
if (ha->ha_ipl != TIMER_LEVEL)
panic("clock_hb_attach: wrong interrupt level");
ctrl_timer = (uint8_t *)(ha->ha_address);
printf("\n");
timer_config(timer_hb_initclocks);
#if 0
vec_set_entry(VECI_INTRAV0 + ha->ha_ipl, _isr_clock);
#endif
}
static void
timer_hb_initclocks(int prof, int stat)
{
int s;
s = splhigh();
vec_set_entry(VECI_INTRAV0 + TIMER_LEVEL, _isr_clock);
*ctrl_timer = 1;
splx(s);
}
void
clock_intr(struct clockframe cf)
{
#ifdef LED_IDLE_CHECK
extern char _Idle[];
#endif
*ctrl_timer = 0;
*ctrl_timer = 1;
m68k_count_intr(TIMER_LEVEL);
#ifdef LED_IDLE_CHECK
if (cf.cf_pc == (long)_Idle)
#endif
leds_intr();
hardclock(&cf);
}
#define LED0 0x01
#define LED1 0x02
static inline void
leds_intr(void)
{
static u_char led_countdown, led_stat;
u_char i;
if (led_countdown) {
led_countdown--;
return;
}
i = led_stat ^ LED0;
*ctrl_led = i;
led_stat = i;
led_countdown = hz;
}