Date: Fri, 5 Jul 2002 00:40:05 +0200 From: "Cole" <cole@acenet.co.za> To: <freebsd-questions@freebsd.org> Subject: Watchdog timer with the winbond w83627HF chip Message-ID: <200207050040.AA3570663656@acenet.co.za>
next in thread | raw e-mail | index | archive | help
Hi, i have written a program to read and write values to the winbond w83627HF chip, that comes on some motherboards. What i would like to know, is if freebsd blocks direct hardware calls and stuff, and when i write to the chip, if what im trying to write to it is actually being written, or weather its just being handled by freebsd and making it appear as if it has. If it was writing to the chip, it should have started the hardware watchdog timer counting down from the value i passed it and when reaching 0 should have rebooted the computer. but not happening. I would just like to know if freebsd prohibits direct hardware writing by users or root? and what the work aroud is for this. Please find below the c code. and if you reply to this, could you please cc a copy to me as im not subscribed to the list. Code Begin: #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <machine/cpufunc.h> #define WDT_EFER 0x295 /* Extended Function Enable Registers */ #define WDT_EFIR 0x295 /* Extended Function Index Register (same as EFER) */ #define WDT_EFDR 0x296 #define TEMP 0x27 u_char get_data(int iodev, u_char command, int interface) { u_char return_val; return_val = 0; outb(WDT_EFER, command); return_val = inb(WDT_EFDR); return return_val; } void enter_ext_mode() { outb(WDT_EFER,0x87); //Write 0x87 to enter extended function mode, have to do it twice outb(WDT_EFER,0x87); } void exit_ext_mode() { outb(WDT_EFER,0xAA); //write 0xAA to exit extended function mode } void set_time(int time) { enter_ext_mode(); //enter extended function mode outb(WDT_EFER,0x07); //Point to logical device number register outb(WDT_EFDR,0x08); //select logic devive 8 outb(WDT_EFER,0xF6); //select CRF6 of device 8 outb(WDT_EFDR,0x05); //write time value to CRF6 printf("Time written to winbond chip\n"); exit_ext_mode(); //exit extended function mode } u_char read_time() { char time; enter_ext_mode(); //enter extended function mode outb(WDT_EFER,0x07); //Point to logical device number register outb(WDT_EFDR,0x08); //select logic device 8 outb(WDT_EFER,0xF6); //select CRF6 of device 8 time = inb(WDT_EFDR); //read value in CRF6 exit_ext_mode(); //exit extended function mode return time; } static void configure(char w83627_time) { char cr_data=0; enter_ext_mode(); outb(WDT_EFER,0x2B); /* Select CR2B (GPIO multiplexed pin selection register 2. VCC powered. Default 0XC0) */ cr_data = inb (WDT_EFDR); /* Read the data from CR2B */ printf("W83627 - Configure (%d), CR2B 0x%x -> ", w83627_time, cr_data); cr_data &= 0xEF; /* Set bit 4 in CR2B to 0 to select watch dog timer output */ cr_data &= 0xFF; printf("... 0x%x\n", cr_data); outb(WDT_EFDR,cr_data); /* Write back the new value */ outb(WDT_EFER,0x08); /* Select locical device 8 */ outb(WDT_EFER,0x0F5); /* Select config register F5 */ cr_data = inb(WDT_EFDR); /* Read CRF5 */ printf("W83627 - Configure (%d), CRF5 0x%x -> ", w83627_time, cr_data); cr_data |= 0x08; /* Set bit 3 to 1 to select the minute counter */ printf("... 0x%x\n", cr_data); outb(WDT_EFER,0x5F); /* Select CRF5 */ outb(WDT_EFDR,cr_data); /* Write new value to CRF5) */ outb(WDT_EFER,0x0F6); /* Select CRF6 */ outb(WDT_EFDR,w83627_time); /* Write Timeout counter to CRF6 */ exit_ext_mode(); printf("W83627 - Configure (%d)\n", w83627_time); } int main(int argc, char *argv[]) { char timeout; int iodev,temp,value; if ((iodev = open("/dev/io", O_RDWR)) == -1){ printf("could not open device /dev/io\n"); exit(0); } else{ temp = get_data(iodev,TEMP,0); printf("Temp: %i\n",temp); value = read_time(); printf("Time Value : %i\n",value); configure(2); //value = read_time(); //printf("Time Value : %i\n",value); //sleep(2); //value = read_time(); //printf("Time Value : %i\n",value); } close(iodev); } Code End: Thanx Cole To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200207050040.AA3570663656>