#include #include void __am_timer_init(); void __am_timer_rtc(AM_TIMER_RTC_T *); void __am_timer_uptime(AM_TIMER_UPTIME_T *); static void __am_timer_config(AM_TIMER_CONFIG_T *cfg) { cfg->present = true; cfg->has_rtc = true; } typedef void (*handler_t)(void *buf); static void *lut[128] = { [AM_TIMER_CONFIG] = __am_timer_config, [AM_TIMER_RTC ] = __am_timer_rtc, [AM_TIMER_UPTIME] = __am_timer_uptime, }; static void fail(void *buf) { panic("access nonexist register"); } bool ioe_init() { for (int i = 0; i < LENGTH(lut); i++) if (!lut[i]) lut[i] = fail; __am_timer_init(); return true; } void ioe_read (int reg, void *buf) { ((handler_t)lut[reg])(buf); } void ioe_write(int reg, void *buf) { ((handler_t)lut[reg])(buf); }