Exemple #1
0
void iniz( u32 idt, u32 gdt )
{
  exIdt = idt;
  exGdt = gdt;

  inizVConsole();

  // Configuring PIT (programmable interval timer)
  // PIT Channel 0 - IRQ0 - scheduler
  INIT_PIT( PIT_CONFIG_CH0 | PIT_MODE3 | PIT_BIN | PIT_READ_LHB );
  SET_PIT( PIT_DIVIDER(20), PIT_CH0 );

  // Set 24-hour mode
  // Set binary data format
  wrcmos( rdcmos(CMOS_RTC_STATUSB) | 0x4 | 0x2, CMOS_RTC_STATUSB );

  // If battery is low...
  if( !(rdcmos(CMOS_RTC_STATUSD) & 0x80) )
    vsprint("warning: cmos battery is low\n");

  // Configuring PIC and interrupts
  setTrapGate( &onIRQ0, IRQ(0) );
  setTrapGate( &onIRQ1, IRQ(1) );
  SET_PIC_MASK( ~0x0300 );

  // Configuring scheduler
  inizTask( &xtask, TSS_ENTRY(0) );
  LTR( xtask.uid );
  currentTask = &xtask;
  currentTask->next = currentTask;
};
unsigned long
rtc_time_m48t37(paddr_t base, unsigned reg_shift, int mmap, int cent_reg) {
	struct tm	tm;
	int cent = 0;

	//Tell Neutrino what kind of chip for 'rtc' utility
	hwi_add_rtc("m48t37", base, reg_shift, 0x8000, mmap, cent_reg);

	chip_access(base, reg_shift, mmap, 0x8000);

	do {
		tm.tm_sec  = rdcmos(M48T37_TIME_REGS + 0x9);
		tm.tm_min  = rdcmos(M48T37_TIME_REGS + 0xa);
		tm.tm_hour = rdcmos(M48T37_TIME_REGS + 0xb);
		tm.tm_mday = rdcmos(M48T37_TIME_REGS + 0xd);
		tm.tm_mon  = rdcmos(M48T37_TIME_REGS + 0xe);
		tm.tm_year = rdcmos(M48T37_TIME_REGS + 0xf);
		if(cent_reg >= 0)
		    cent = rdcmos(M48T37_TIME_REGS + cent_reg);

		//Loop while time inconsistent
	} while(tm.tm_sec != rdcmos(M48T37_TIME_REGS + 0x9));

	chip_done();

	tm.tm_sec &= ~0x80;

	tm.tm_sec  = bcd2bin(tm.tm_sec);
	tm.tm_min  = bcd2bin(tm.tm_min);
	tm.tm_hour = bcd2bin(tm.tm_hour);
	tm.tm_mday = bcd2bin(tm.tm_mday);
	tm.tm_mon  = bcd2bin(tm.tm_mon);
	tm.tm_year = bcd2bin(tm.tm_year);

	tm.tm_mon -= 1;

	if(cent_reg >= 0) {
	    if(cent > 19) tm.tm_year += (bcd2bin(cent)-19) * 100;
	} else if(tm.tm_year < 70) {
	    tm.tm_year += 100; //21st century.
	}

	return(calc_time_t(&tm));
}
Exemple #3
0
unsigned long
rtc_time_mc146818(paddr_t base, unsigned reg_shift, int mmap, int cent_reg) {
	struct tm	tm;
	unsigned	save_hour;
	unsigned	reg_b;
	unsigned	cent;
	unsigned char	sra;

	//Tell Neutrino what kind of chip for 'rtc' utility
	hwi_add_rtc("mc146818", base, reg_shift, 2, mmap, cent_reg);

	chip_access(base, reg_shift, mmap, 2);

	// bail if the clock is not running.
	sra = rdcmos(MC146818_SRA);
	if ((sra & 0x60) != 0x20) {
		chip_write8 (1, (sra | 0x60));	//Check for ATI IXP200 RTC - these bits are reserved
		if ((rdcmos(MC146818_SRA) & 0x60) != 0) {
			chip_write8 (1, sra);	//restore old value
			return(0L);
			}
		}
	reg_b = rdcmos(MC146818_SRB);

	do {
		tm.tm_sec  = rdcmos(0);
		tm.tm_min  = rdcmos(2);
		tm.tm_hour = rdcmos(4);
		tm.tm_mday = rdcmos(7);
		tm.tm_mon  = rdcmos(8);
		tm.tm_year = rdcmos(9);

		//Loop while time inconsistent
	} while(tm.tm_sec != rdcmos(0));

	chip_done();

	save_hour = tm.tm_hour;
	tm.tm_hour &= ~0x80;

	if(!(reg_b & MC146818_SRB_DM)) {
		tm.tm_sec  = bcd2bin(tm.tm_sec);
		tm.tm_min  = bcd2bin(tm.tm_min);
		tm.tm_hour = bcd2bin(tm.tm_hour);
		tm.tm_mday = bcd2bin(tm.tm_mday);
		tm.tm_mon  = bcd2bin(tm.tm_mon);
		tm.tm_year = bcd2bin(tm.tm_year);
	}
	if(!(reg_b & MC146818_SRB_24_12) && (save_hour & 0x80)) {
		//12 hour format & past 12pm
		tm.tm_hour += 12;
	}
	tm.tm_mon -= 1;

	if(cent_reg >= 0) {
		cent = rdcmos(cent_reg);			//century
		if(!(reg_b & MC146818_SRB_DM)) {
			cent = bcd2bin(cent_reg);
		}
		if(cent == 20) tm.tm_year += 100;
	} else if(tm.tm_year < 70) {
		tm.tm_year += 100; //21st century.
	}

	return(calc_time_t(&tm));
}