Subject: RE: project with parallel port
To: Francois Briere <port-i386@netbsd.org>
From: Rishabh Kumar Goel <Rishabh@soc-soft.com>
List: port-i386
Date: 07/22/2003 12:40:48
try mallocing memory to ioperm Data structure. Currently ioperm has only =
a 4 byte memory allocated to it and no memory is allocated to the data =
structure instance it points to.

Rishabh


-----Original Message-----
From:	Francois Briere [mailto:francois@dopha.org]
Sent:	Tue 7/22/2003 11:37 AM
To:	port-i386@netbsd.org
Cc:=09
Subject:	project with parallel port
Hi folks,

Im trying to setup my 'little' project running on netbsd
but im having a little problem with i386_set_ioperm().
I probably need to learn more about this function on netbsd...

The project is really stupid, this is for control the speed of a serie =
of leds running
on the parallel port.

debug:

ginger# ./b 5 10=20
hertz 5, delay 100000
Segmentation fault (core dumped)

gdb:
Program received signal SIGSEGV, Segmentation fault.
0x1c000a03 in __outb ()

(gdb) bt
#0  0x1c000a03 in __outb ()
#1  0x1c000723 in flashsolid ()
#2  0x1c0009f0 in main ()
#3  0x1c000521 in ___start ()
#4  0x1c000497 in _start ()
#5  0xcfbf8734 in ?? ()

my code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <machine/sysarch.h>
#include <machine/pio.h>

#define ver 1
#define subver 0
#define base 0x378

void ioport(int port) {
u_long iomap[255];
struct i386_set_ioperm_args ioperm;

ioperm.iomap =3D iomap;
syscall(SYS_sysarch, I386_GET_IOPERM, (char *) &ioperm);
iomap[port >> 5] &=3D ~(1 << (port & 0x1f));
syscall(SYS_sysarch, I386_SET_IOPERM, (char *) &ioperm);
}

void top(char *prog)
{
 printf("\ndophas led-controller %d.%d\n",ver,subver);
 printf("\nusage: %s <pattern> <frequency> =
<session-duration>\n\n",prog);
 printf("pattern is one of the following: solid, flipflop, chase\n\n");
 printf("frequency is the blinking-frequency in hertz (int)\n\n");
 printf("session-duration is the time in seconds that the session\nis =
supposed to last\n\n");
 exit(1);
}

void flashsolid(int hertz)
{
    int delay;
    delay =3D 1000 / hertz * 500;
	outb(base, 255);
	sleep(delay);
	outb(base, 0);
	sleep(delay);
}

void flashflipflop(int hertz)
{
	int delay;
        delay =3D 1000 / hertz * 500;
	outb(base, 85);
	sleep(delay);
	outb(base, 0);
	sleep(delay);
	outb(base, 170);
	sleep(delay);
	outb(base, 0);
	sleep(1000/hertz*500);
}


void flashchase(int hertz)
{
	int delay;
        delay =3D 1000 / hertz * 500;
	outb(base, 17);
	sleep(delay);
	outb(base, 0);
	sleep(delay);
	outb(base, 40);
	sleep(delay);
	outb(base, 0);
	sleep(delay);
	outb(base, 68);
	sleep(delay);
	outb(base, 0);
	sleep(delay);
	outb(base, 130);
	sleep(delay);
	outb(base, 0);
	sleep(delay);
}

main(int argc, char **argv)
{
  int value;
  if (argc !=3D 3) top(argv[0]);
  value=3Datoi(argv[1]);
  printf("hertz %d, delay %d\n",value,1000/value/2*1000);
  while (1=3D=3D1) {
	flashsolid(value);
  }=20
}

Anyone can help me for debuging that on netbsd ?
or refer to a good doc..

Thanks and sorry for my _really_ good english.
--
Francois Briere, Canada, Qc




Scanned by SecureSynergy VirusScreen Service. 
For more information log on to : http://www.securesynergyonline.com or http://www.securesynergy.com