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

Waveform: int/uint8_t inconsistency and implied stop PWM #8008

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

dok-net
Copy link
Contributor

@dok-net dok-net commented Apr 29, 2021

@earlephilhower This is basically a cleanup, and I'm asking for you to review this, because it's your code.
I'm head scratching about the weak-ref magic you performed, it looks convoluted, but appears to be the only working variant - albeit I am worried that enablePhaseLockedWaveform(); does not remove the PWM bits from the final BSP like it was with the previous config menu?

@dok-net dok-net force-pushed the unifypwm branch 6 times, most recently from 36cab6f to 102091c Compare May 3, 2021 17:50
@dok-net dok-net force-pushed the unifypwm branch 5 times, most recently from e191c8f to 3108e68 Compare May 17, 2021 23:23
Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some logic changes I don't think are correct here.

Also, please try not to mix naming/indentation/style changes with logic changes. It makes reviewing the PR very difficult because multiple unrelated things are all changing at once. There are probably 30 real logic/type change lines in this PR, but it's a few hundred lines due to formatting and renaming changes (which GH diff struggles to match, making it a real pain to examine). Simple change 1-thing PRs are way faster/easier for 3rd parties to look at and review.

@@ -96,7 +96,7 @@ static WVFState wvfState;
static IRAM_ATTR void timer1Interrupt();
static bool timerRunning = false;

static __attribute__((noinline)) void initTimer() {
static void initTimer() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The noinline attribute was added here to save a few bytes of program space...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in a #pragma GCC optimize ("Os") code section anyway. Let the compiler decide?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-added the noinline attribute.

cores/esp8266/core_esp8266_waveform_phase.cpp Show resolved Hide resolved
pwmState.pwmUpdate = p;
MEMBARRIER();
forceTimerInterrupt();
// The ISR pulls updates on the next PWM interval
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be 10 milliseconds away. forceTimerInterrupt would make it happen in 10 microseconds. I think this needs to be undone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think: the ISR does NOT act on the request immediately when the ISR is triggered, but only as scheduled previously, anyway, because of !pwmState.cnt:

  } else if (!pwmState.cnt && pwmState.pwmUpdate) {
    // Start up the PWM generator by copying from the mailbox
    pwmState.cnt = 1;
    pwmState.idx = 1; // Ensure copy this cycle, cause it to start at t=0
    pwmState.nextServiceCycle = GetCycleCountIRQ(); // Do it this loop!
    // No need for mem barrier here.  Global must be written by IRQ exit
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it's a tradeoff, when it's the first PWM starting, you're right, if anything else is running already, it's wasting resources and may very badly affect PWM/waveform timings.

cores/esp8266/core_esp8266_waveform_pwm.cpp Outdated Show resolved Hide resolved
cores/esp8266/Tone.cpp Show resolved Hide resolved
cores/esp8266/core_esp8266_wiring_digital.cpp Show resolved Hide resolved
cores/esp8266/core_esp8266_wiring_pwm.cpp Show resolved Hide resolved
cores/esp8266/core_esp8266_wiring_pwm.cpp Show resolved Hide resolved
cores/esp8266/core_esp8266_wiring_pwm.cpp Outdated Show resolved Hide resolved
cores/esp8266/core_esp8266_wiring_pwm.cpp Show resolved Hide resolved
@dok-net
Copy link
Contributor Author

dok-net commented Jun 19, 2021

@s-hadinger I am curious if you would be willing to spend some time on giving an opinion with regard to this PR and/or #8011 performing with LED strips. Real-life use cases are the most interesting, after all :-)

@s-hadinger
Copy link
Contributor

s-hadinger commented Jun 20, 2021

Sorry I'm not familiar with this code. I'm afraid I can't help.

@dok-net
Copy link
Contributor Author

dok-net commented Jun 20, 2021

@s-hadinger I am sorry, too, I was just going by things like #7231 (comment) and #7057 and all your much appreciated feedback to #7022

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

Successfully merging this pull request may close these issues.

None yet

3 participants