• Raspi OS wiringPi - How to attach an Interrupt to a Word?

    From Christof Eberspaecher@21:1/5 to All on Tue Jul 26 08:07:06 2022
    Hi,
    with Raspi OS using GForth and wiringPi with this GForth interface: https://github.com/kristopherjohnson/wiringPi_gforth

    there is a line:
    c-function wiringPiISR wiringPiISR n n func -- n

    In C this would be used like:
    wiringPiISR(INT_PIN, INT_FALLING_EDGE, MyInterrupt)
    void myInterrupt(void) { .... }

    Is there a way to attach a GForth word to the interrupt?
    I don't know enough about the internal organisation of GForth.

    Thanks, in advance!
    Christof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to Christof Eberspaecher on Wed Jul 27 07:01:52 2022
    Christof Eberspaecher <chwebersp@gmail.com> writes:
    Hi,
    with Raspi OS using GForth and wiringPi with this GForth interface: >https://github.com/kristopherjohnson/wiringPi_gforth

    there is a line:
    c-function wiringPiISR wiringPiISR n n func -- n

    In C this would be used like:
    wiringPiISR(INT_PIN, INT_FALLING_EDGE, MyInterrupt)
    void myInterrupt(void) { .... }

    Is there a way to attach a GForth word to the interrupt?

    Gforth's C interface supports callbacks, which should be of use for
    this application:

    https://gforth.org/manual/Callbacks.html

    - anton
    --
    M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
    comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
    New standard: https://forth-standard.org/
    EuroForth 2022: http://www.euroforth.org/ef22/cfp.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jos Ven@21:1/5 to All on Wed Jul 27 04:42:52 2022
    On 26 juli 2022 om 17:07:07 UTC+2 Christof Eberspaecher wrote:
    Hi,
    with Raspi OS using GForth and wiringPi with this GForth interface: https://github.com/kristopherjohnson/wiringPi_gforth

    there is a line:
    c-function wiringPiISR wiringPiISR n n func -- n

    In C this would be used like:
    wiringPiISR(INT_PIN, INT_FALLING_EDGE, MyInterrupt)
    void myInterrupt(void) { .... }

    Is there a way to attach a GForth word to the interrupt?
    I don't know enough about the internal organisation of GForth.

    Thanks, in advance!
    Christof

    Marker wiringPiInt.fs \ Testet on a Raspberry zero under the Bullseye

    c-library MywiringPi
    s" wiringPi" add-lib
    \ **** wiringPi wrapper ****

    \c #include <wiringPi.h>
    c-function pinMode pinMode n n -- void ( pin mode - ) c-function digitalWrite digitalWrite n n -- void ( pin value - ) c-function digitalRead digitalRead n -- n ( pin - value ) c-function wiringPiSetupGpio wiringPiSetupGpio void -- n ( - res )
    c-function pullUpDnControl pullUpDnControl n n -- void ( pin pud - void ) c-function wiringPiISR wiringPiISR n n a -- n ( pin mode funct - res )
    c-function piBoardRev piBoardRev void -- n ( - piBoardRev ) c-callback ISR_Gpio1 a -- n ( xt -- n ) c-callback ISR_Gpio2 a -- n ( xt -- n ) c-callback ISR_Gpio3 a -- n ( xt -- n )

    end-c-library

    \ Pin modes
    0 constant INPUT
    1 constant OUTPUT
    2 constant PWM_OUTPUT
    3 constant GPIO_CLOCK
    4 constant SOFT_PWM_OUTPUT
    5 constant SOFT_TONE_OUTPUT
    6 constant PWM_TONE_OUTPUT
    0 constant LOW
    1 constant HIGH

    \ Interrupt levels
    0 constant INT_EDGE_SETUP
    1 constant INT_EDGE_FALLING
    2 constant INT_EDGE_RISING
    3 constant INT_EDGE_BOTH

    \ Pull up/down/none
    0 constant PUD_OFF \ no pull up/down
    1 constant PUD_DOWN \ pull to ground
    2 constant PUD_UP \ pull to 3.3v

    \ PWM
    0 constant PWM_MODE_MS
    1 constant PWM_MODE_BAL

    : InitWiringPi ( - ) wiringPiSetupGpio abort" wiringPiSetupGpio failed" ;

    \ Test

    InitWiringPi \ 1 time only

    22 value pin

    : testOutput ( pin - )
    to pin
    pin OUTPUT pinMode
    pin HIGH digitalWrite
    pin digitalRead cr .
    2000 ms
    pin LOW digitalWrite ;

    : IntDetected1 ( - ) cr 1 . ." interrupt detected" ;
    : IntDetected2 ( - ) cr 2 . ." interrupt detected" ;
    : IntDetected3 ( - ) cr 3 . ." interrupt detected" ;

    : testInput1 ( pin - )
    to pin
    pin INPUT pinMode
    pin INT_EDGE_BOTH ['] IntDetected1 ISR_Gpio1 wiringPiISR drop ;

    : testInput2 ( pin - )
    to pin
    pin INPUT pinMode
    pin INT_EDGE_BOTH ['] IntDetected2 ISR_Gpio2 wiringPiISR drop ;

    : testInput3 ( pin - )
    to pin
    pin INPUT pinMode
    pin INT_EDGE_BOTH ['] IntDetected3 ISR_Gpio3 wiringPiISR drop ;


    cr .s .( Start 1: ) 22 testInput1 .s
    cr .s .( Start 2: ) 22 testInput2 .s
    cr .s .( Start 3: ) 25 testInput3 .s

    \ 25 testOutput \ to test

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christof Eberspaecher@21:1/5 to Jos Ven on Wed Jul 27 07:24:45 2022
    Jos Ven schrieb am Mittwoch, 27. Juli 2022 um 13:42:53 UTC+2:
    On 26 juli 2022 om 17:07:07 UTC+2 Christof Eberspaecher wrote:
    Hi,
    with Raspi OS using GForth and wiringPi with this GForth interface: https://github.com/kristopherjohnson/wiringPi_gforth

    there is a line:
    c-function wiringPiISR wiringPiISR n n func -- n

    In C this would be used like:
    wiringPiISR(INT_PIN, INT_FALLING_EDGE, MyInterrupt)
    void myInterrupt(void) { .... }

    Is there a way to attach a GForth word to the interrupt?
    I don't know enough about the internal organisation of GForth.

    Thanks, in advance!
    Christof
    Marker wiringPiInt.fs \ Testet on a Raspberry zero under the Bullseye

    c-library MywiringPi
    s" wiringPi" add-lib
    \ **** wiringPi wrapper ****

    \c #include <wiringPi.h>
    c-function pinMode pinMode n n -- void ( pin mode - )
    c-function digitalWrite digitalWrite n n -- void ( pin value - )
    c-function digitalRead digitalRead n -- n ( pin - value )
    c-function wiringPiSetupGpio wiringPiSetupGpio void -- n ( - res )
    c-function pullUpDnControl pullUpDnControl n n -- void ( pin pud - void ) c-function wiringPiISR wiringPiISR n n a -- n ( pin mode funct - res ) c-function piBoardRev piBoardRev void -- n ( - piBoardRev )
    c-callback ISR_Gpio1 a -- n ( xt -- n )
    c-callback ISR_Gpio2 a -- n ( xt -- n )
    c-callback ISR_Gpio3 a -- n ( xt -- n )

    end-c-library

    \ Pin modes
    0 constant INPUT
    1 constant OUTPUT
    2 constant PWM_OUTPUT
    3 constant GPIO_CLOCK
    4 constant SOFT_PWM_OUTPUT
    5 constant SOFT_TONE_OUTPUT
    6 constant PWM_TONE_OUTPUT
    0 constant LOW
    1 constant HIGH

    \ Interrupt levels
    0 constant INT_EDGE_SETUP
    1 constant INT_EDGE_FALLING
    2 constant INT_EDGE_RISING
    3 constant INT_EDGE_BOTH

    \ Pull up/down/none
    0 constant PUD_OFF \ no pull up/down
    1 constant PUD_DOWN \ pull to ground
    2 constant PUD_UP \ pull to 3.3v

    \ PWM
    0 constant PWM_MODE_MS
    1 constant PWM_MODE_BAL

    : InitWiringPi ( - ) wiringPiSetupGpio abort" wiringPiSetupGpio failed" ;

    \ Test

    InitWiringPi \ 1 time only

    22 value pin

    : testOutput ( pin - )
    to pin
    pin OUTPUT pinMode
    pin HIGH digitalWrite
    pin digitalRead cr .
    2000 ms
    pin LOW digitalWrite ;

    : IntDetected1 ( - ) cr 1 . ." interrupt detected" ;
    : IntDetected2 ( - ) cr 2 . ." interrupt detected" ;
    : IntDetected3 ( - ) cr 3 . ." interrupt detected" ;

    : testInput1 ( pin - )
    to pin
    pin INPUT pinMode
    pin INT_EDGE_BOTH ['] IntDetected1 ISR_Gpio1 wiringPiISR drop ;

    : testInput2 ( pin - )
    to pin
    pin INPUT pinMode
    pin INT_EDGE_BOTH ['] IntDetected2 ISR_Gpio2 wiringPiISR drop ;

    : testInput3 ( pin - )
    to pin
    pin INPUT pinMode
    pin INT_EDGE_BOTH ['] IntDetected3 ISR_Gpio3 wiringPiISR drop ;


    cr .s .( Start 1: ) 22 testInput1 .s
    cr .s .( Start 2: ) 22 testInput2 .s
    cr .s .( Start 3: ) 25 testInput3 .s

    \ 25 testOutput \ to test

    Thank you both very much, Anton and Jos!
    I must say, that the docu of Gforth is not easy to understand for me sometimes. So I appreciate the example code very much!
    The goal ist to read a quadrature encoder.
    Christof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)