Skip to content

opto_ac5: still in use here, ported to uspace and tested on hardware #4880

Closed

Description

@Josbleuet

opto_ac5 was removed in #4513 because nobody was known to use it or to be able to test it. I have been running an Opto22 PCI-AC5 on my milling machine since 2012 (step/dir on port 0, spindle speed and I/O on port 1), so I ported the driver to uspace instead of staying on RTAI.

  • The change is limited to the PCI part: pci_get_device()/ioremap_nocache() become a rtapi_pci driver (probe/remove, rtapi_pci_ioremap_bar), and readl()/writel() go through two small helpers. Pins, params, functions and the read/write logic are untouched.
  • The uspace rtapi_pci matches subvendor/subdevice exactly, PCI_ANY_ID is not a wildcard there, so the id table has to list 148a:ac05.
  • The version that was removed would not have built on master anyway: hal_export_functf() lost an argument and the driver was never compiled for uspace, so nobody saw it. Fixed in the branch.
  • Tested on Debian 13, 6.12 PREEMPT_RT kernel, i7-2600, base thread at 90 us, with my full machine config: first on 2.9.10 out of tree with halcompile, then on master with the driver back in tree. Jogging, spindle speed and inputs behave like they did under RTAI. On master the base thread max is around 15 us, digital-read around 5 us.

Branch: https://github.com/Josbleuet/linuxcnc/tree/opto_ac5-uspace

I can keep testing it on real hardware when needed. Would you take it as a PR on master, or would you rather handle it differently?

Activity

  1. grandixximo commented on Nov 22, 2026

    @grandixximo
    Contributor

    If the board are still in production, and you stick around to test it trough the review process, send in the PR and we will handle it trough there.
    About the driver being removed, as you mentioned it was just cause no one showed up to tell us if it was still working, we will mark you down as our new tester for this hardware ;-)

  2. BsAtHome commented on Nov 22, 2026

    @BsAtHome
    Contributor

    To prevent multiple read/write to/from the HAL pins, you may want to change this: https://github.com/Josbleuet/linuxcnc/blob/a4c80f85662e5e0ff2521344ab02273b82205567/src/hal/drivers/opto_ac5.c#L414-L420 into:

    if ((pboard->port[portnum].mask & mask) == 0) { // is it an input bit ?
        rtapi_bool b = (pins & mask) == 0;
        hal_set_bool(pDigital->pValue, b);
        hal_set_bool(pDigital->pValueNot, !b);
    }

    and https://github.com/Josbleuet/linuxcnc/blob/a4c80f85662e5e0ff2521344ab02273b82205567/src/hal/drivers/opto_ac5.c#L457-L464 into:

    if ((pboard->port[portnum].mask & mask) != 0) { //is it an output?
        // add mask to pins if HAL pin + invert =true.
        rtapi_bool val = hal_get_bool(pDigital->pValue);
        rtapi_bool inv = hal_get_bool(pDigital->invert);
        if( (!val && !inv ) || (val && inv) {
            pins |= mask;
        }
    }

    And, when you do want to add it again, the files need a bit of a indent cleanup (please use only spaces). Better do that at the same time.

  3. BsAtHome commented on Nov 23, 2026

    @BsAtHome
    Contributor

    Merged in #4883

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions