Would it be practical to facilitate assembly code within the IDE ? In the past, I have used languages which somply have reserved strings something like just "asm" to tell the compiler to include some assembly code. I think that was when I was writing for an 8051 family.
Would it be practical to facilitate assembly code within the IDE ? In the past, I have used languages which somply have reserved strings something like just "asm" to tell the compiler to include some assembly code. I think that was when I was writing for an 8051 family.
The IDE will currently support .S assembly files, as well as inline-assembler in C/C++ modules.
But the slowness of digitalWrite() isn't at all due to it being written in a HLL. The compiler will happily produce a single machine instruction for something like "PORTB |= 8;" But digitalWrite() actually does quite a lot:
- Translate the Arduino "Pin" into an internal "Port" and "bit." Since "Pin" can be a run-time variable, this has to happen at run time.
- The port and bit are thus also runtime variables, making the AVR's single-instruction IO instructions useless. A longer read/modify/write sequence is needed.
- Also, the code "needs" to check whether the pin is currently outputing PWM, which is controlled by a timer. In that case, it has to switch the pin back to GPIO.
The various "fast" implementations don't improve on the code, so much as they remove the flexibility. Most of the digitalWriteFast implementations ignore the PWM issue, and will ONLY write pins and values that are compile-time constants.
westfw:
The various "fast" implementations don't improve on the code, so much as they remove the flexibility. Most of the digitalWriteFast implementations ignore the PWM issue, and will ONLY write pins and values that are compile-time constants.
The digital i/o code in the Teensy 2.x core is an improvement without changing anything in the API to the application.
i.e. the same code when compiled with Teensy core will be much faster than with the stock AVR core.
It is simply a better implementation that offers faster code for all cases, and single instructions when both arguments are compile time constants. But you still get much faster results even when both are not constants.
Paul offered the code to the Arduino.cc team for the standard AVR core and they rejected it.
--- bill
Split from an old unrelated topic
Paul offered the code to the Arduino.cc team for the standard AVR core and they rejected it.
I... Wow! That is some ugly code that looks like a big job to maintain, or port to new chips/pinouts.
I have a lot of respect for Paul, but I don't blame the Arduino team for rejecting that code...