[]NA and callback functions

No need to worry about going "off topic" here
Forum rules
This forum is for general chit-chat, not necessarily APL-related. However, it's not for spam or for offensive or illegal comments.

[]NA and callback functions

Postby ray on Mon Jan 16, 2017 2:51 pm

I am trying to use a shared object library (the PIGPIO "C" interface) that access the GPIO pins on my Raspberry Pi. http://abyz.co.uk/rpi/pigpio/cif.html

To this end, I am writing APL cover functions that allow direct access to these functions from APL without the need of writing any C code. I already have the I2C interface working well.

This library contains a function (called gpioSetAlertFunc) that triggers a call-back function when a GPIO pin changes "level" (switches form 0 to 1 or 1 to 0).

From Dyalog HELP on Name Association:
Callbacks (∇)
Currently, support for a ⎕NA function to call an APL function is limited to the use of the NAG (National Algorithms Group) library of functions. This library is a FORTRAN library and FORTRAN passes arguments by reference (address) rather than by value. The expression:
∇f8←(P P P P)
declares a callback function that returns a double and takes 4 pointer arguments. The result can be any of the normal results. It is not possible to return a pointer. The arguments can be from 0 to 16 P values.

The argument when passed can be the name of an APL function or the ⎕OR of a function.


This appears to be saying that I can't ⎕NA call gpioSetAlertFunc with a callback to an APL function, because it (gpioSetAlertFunc) is not in the NAG library.

Use of callback functions is desirable when accurate timings are required, (such as when timing ultrasound "sonar" echos to measure distances to sub-centimeter accuracy).

Can anyone suggest a work around?

Thanks
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: []NA and callback functions

Postby Geoff|Dyalog on Tue Jan 17, 2017 9:27 am

What is the specification for the callback arguments? Whilst we put in enough support for NAG it is more general than just that. We can cope with register sized arguments. Pointers are register sized. So are integers. Structures are, generally, not. What we did when supporting NAG is to receive the arguments as pointers - because that is what FORTRAN does - and dereference them using MEMCPY in the APL code. Full support for callbacks is a big project but a lot can be done with the support that is already there.

If the C version of the callback is too complicated to code you might look for a FORTRAN version of the library.

Or you might be forced to write a C cover function to manipulate the arguments into something more friendly.
Geoff|Dyalog
 
Posts: 43
Joined: Wed May 13, 2009 12:36 pm

Re: []NA and callback functions

Postby ray on Tue Jan 17, 2017 7:01 pm

Hi Geoff

I may be in luck than, the 3 arguments being passed from the library are an all unsigned integers:
1)the Broadcom GPIO pin number (0-53),
2)the "level" (low=0 or high=1)
3)the internal clock tick (an unsigned 32-bit value).

I will have a play and see if I can get anything working.

Thanks

Ray
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: []NA and callback functions

Postby ray on Tue Jan 17, 2017 7:54 pm

For clarification, an example "C" call-back function might be:

Code: Select all
void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}


where uint32_t is defined as a 32-bit unsigned value.
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK


Return to Chat

Who is online

Users browsing this forum: No registered users and 1 guest