GPIO’s using in acquire.c

Applications, development tools, FPGA, C, WEB
Post Reply
pietroo
Posts: 3
Joined: Wed Dec 03, 2014 6:18 pm

GPIO’s using in acquire.c

Post by pietroo » Thu Dec 18, 2014 11:27 am

GPIO’s using in acquire.c

I would like to control the GPIO’s in the “acquire.c”.
For example:
If I measuring 5V on the CH 1,
than I would like to set DIO_P output to high (0x40000018 0x02).

I know I have to use the mmap() in monitor.c.
I know I have to use the list of control FPGA-registers.
I don’t know how implementation that in acquire.c.
Who can help me.
Maybe with a sample code.

Thank you very much

edgo
Posts: 34
Joined: Wed Jun 25, 2014 11:38 pm

Re: GPIO’s using in acquire.c

Post by edgo » Thu Dec 18, 2014 6:11 pm

I hacked this out of "monitor" once upon a time:

int _monitor(unsigned long the_addr, int write, unsigned long the_value) {
int fd = -1;
int retval = EXIT_SUCCESS;

if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;

{
unsigned long addr;
unsigned long *val = NULL;
unsigned long incoming_value;
int access_type = 'w';
ssize_t val_count = 0;
//parse_from_argv(argc, argv, &addr, &access_type, &val, &val_count);

addr = the_addr;
if (write == 1)
{
val_count = 1;
incoming_value = the_value;
val = &incoming_value;
}
/* Map one page */
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, addr & ~MAP_MASK);
if(map_base == (void *) -1) FATAL;

if (addr != 0) {
if (val_count == 0) {
printf(" read_value addr=0x%x\n", (unsigned int)addr);
retval = read_value(addr);//pass back the value read
}
else {
printf(" write_values addr=0x%x the_value=0x%x\n", (unsigned int)addr, (unsigned int)the_value);
write_values(addr, access_type, val, val_count);
}
}
if (map_base != (void*)(-1)) {
if(munmap(map_base, MAP_SIZE) == -1) FATAL;
map_base = (void*)(-1);
}
#if DEBUG_MONITOR
printf("addr/type: %lu/%c\n", addr, access_type);

printf("val (%ld):", val_count);
for (ssize_t i = 0; i < val_count; ++i) {
printf("%lu ", val);
}

if (val != NULL) {
free(val);
val = NULL;
}
printf("\n");
#endif
}

if (map_base != (void*)(-1)) {
if(munmap(map_base, MAP_SIZE) == -1) FATAL;
}
if (fd != -1) {
close(fd);
}

return retval;
}

==================================================================
Then it would be called in the following manner to write as you desire:

_monitor(0x40000018, 1, 0x02);

:-( Sorry it gets flattened, I can put in GitHub if this is not clear enough...

pietroo
Posts: 3
Joined: Wed Dec 03, 2014 6:18 pm

Re: GPIO’s using in acquire.c

Post by pietroo » Fri Dec 19, 2014 5:08 pm

ok
Last edited by pietroo on Mon Dec 22, 2014 9:48 pm, edited 1 time in total.

pietroo
Posts: 3
Joined: Wed Dec 03, 2014 6:18 pm

Re: GPIO’s using in acquire.c

Post by pietroo » Mon Dec 22, 2014 9:47 pm

Thank you very much for your fast answer.

It works.

I can use the GPIO´s in acquire.c

with best regards

pietro

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 41 guests