implement LPT pin "reset" function

This commit is contained in:
Sergey Popov 2011-12-13 19:09:17 +04:00
parent 8f39695140
commit 75c7a1be71

25
yasnd.c
View File

@ -1,5 +1,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/io.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
@ -130,6 +131,30 @@ void check_host(int num,host_decl* host)
host->helper_pid=pid;
}
/*
Function, that turn on only one LPT port pin, defined by it argument, wait a second,
and turn off all pins. That is enough to reset specified host.
*/
void reset_pin(int pin_num)
{
if (pin_num<1 || pin_num>8)
{
log_event("Error: incorrent LPT pin number");
return;
}
#define LPTPORT 0x378
int pins = 2<<(pin_num-1);
if (ioperm (LPTPORT, 3, 1))
{
log_event("Error: LPT port access error");
exit(EXIT_FAILURE);
}
// Reset host
outb (pins, LPTPORT);
sleep(1);
outb (0, LPTPORT);
}
void loop_function()
{
for (int i=0;i<hosts_count;i++)