Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up OutputPort::write() #34

Open
WestfW opened this issue Oct 26, 2022 · 0 comments
Open

Speed up OutputPort::write() #34

WestfW opened this issue Oct 26, 2022 · 0 comments

Comments

@WestfW
Copy link

WestfW commented Oct 26, 2022

Current OutputPort::write() code:

        void write(port_data_t value) {
            atomic {
                // read-modify-write cycle
                port_data_t v = port::port_output_read();
                port_data_t shifted = value << start_bit;
                v |= shifted & mask;
                v &= (shifted | ~mask);
                port::port_output_write(v);
            }
        }

On chips that have an output toggle feature, this can probably be sped up significantly using the clever XOR-based trick that I first saw in the RPi Pico SDK (https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_gpio/include/hardware/gpio.h#L719 )

the new code would not need "atomic", and would look something like:

        void write(port_data_t value) {
              port_data_t v = port::port_output_read();
              port_data_t shifted = value << start_bit;
              v ^= shifted;
              port::port_output_toggle(v & mask);
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant