Git Product home page Git Product logo

Comments (4)

kentindell avatar kentindell commented on August 11, 2024

That's me being sloppy: there's an implicit assumption integers are 32 bits. Bad boy!

Needs to be cast to a 32-bit integer first before shifting.

You can't change the shifts: it will all explode. Basically this is assembling a 32-bit number byte-by-byte. The compiler is normally smart enough to work out what's going on. Let me fix it.

from min.

kentindell avatar kentindell commented on August 11, 2024

0a20297

from min.

Resonanz avatar Resonanz commented on August 11, 2024

I would rewrite this as follows using almost identical code for each additional byte (is there a better way?)

        case RECEIVING_CHECKSUM_3:
            self->rx_frame_checksum = byte;
            self->rx_frame_checksum << 8;
            self->rx_frame_state = RECEIVING_CHECKSUM_2;
            break;
        case RECEIVING_CHECKSUM_2:
            self->rx_frame_checksum |= byte;
            self->rx_frame_checksum << 8;
            self->rx_frame_state = RECEIVING_CHECKSUM_1;
            break;
        case RECEIVING_CHECKSUM_1:
            self->rx_frame_checksum |= byte;
            self->rx_frame_checksum << 8;
             self->rx_frame_state = RECEIVING_CHECKSUM_0;
            break;
        case RECEIVING_CHECKSUM_0:
            self->rx_frame_checksum |= byte;

from min.

kentindell avatar kentindell commented on August 11, 2024

You could do that but on an 8-bit device it means shifting a 32-bit word, which is fairly costly (it might even try and do something like four individual rotates in a loop executed 8 times). Good compiler optimizers are generally coded to see things like "<< 16" and "<< 24" and see that it's really just writing a byte to the nth byte of a word and then optimize the code to do that directly.

Need to have a look at the assembly language to see what the Arduino compiler makes of it. GCC on the ARM is very slick at this kind of thing.

from min.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.