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

[BUG] IOC Timers can infinite loop. #32

Open
1 task done
RichardBrown384 opened this issue Jul 10, 2024 · 1 comment
Open
1 task done

[BUG] IOC Timers can infinite loop. #32

RichardBrown384 opened this issue Jul 10, 2024 · 1 comment
Labels
bug Something isn't working component:ioc

Comments

@RichardBrown384
Copy link
Owner

RichardBrown384 commented Jul 10, 2024

Checklist

  • The application is running with a good CMOS configuration.

Describe the bug
The IOC timers can infinite loop.

Problem code

if (scaledTicks >= scaledValue) {
  const auto scaledInputLatch = Scale * inputLatch;
  while (scaledTicks >= scaledValue) {
    scaledValue += scaledInputLatch;
   }
   expiryCallback();
}
scaledValue -= scaledTicks;

The code infinite loops when the inputLatch has been programmed to zero.

To Reproduce
Steps to reproduce the behaviour:

  1. Configure a timer
  2. While the timer is counting down program 0 to the input latch
  3. Expire the timer.

Expected behaviour
While this is a programming error, there's an additional dimension that wasn't thought about durning development. Namely what's supposed to happen when the timer latch is programmed to zero? Does the IOC continuously set the timer bits in IRQ A or does it only do that the first time the timer expires?

The VTI manual says:

If a counter is loaded with zero it continuously reloads and does not count.

I'm not entirely sure how to interpret that statement.

Please complete the following information

  • Version CURRENT HEAD

Additional context
The IOC timers (and timers in general) don't currently have any unit tests. Unit tests for the IOC should include this case.

See #5

@RichardBrown384 RichardBrown384 added bug Something isn't working component:ioc labels Jul 10, 2024
@RichardBrown384
Copy link
Owner Author

Possible fix

const auto scaledInputLatch = Scale * inputLatch;
if (scaledInputLatch) {
    if (scaledTicks >= scaledValue) {
        while (scaledTicks >= scaledValue) {
            scaledValue += scaledInputLatch;
        }
        expiryCallback();
    }
    scaledValue -= scaledTicks;
    return;
}
if (scaledTicks >= scaledValue) {
    if (scaledValue) {
        expiryCallback();
    }
    scaledValue = 0u;
    return;
}
scaledValue -= scaledTicks;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component:ioc
Projects
None yet
Development

No branches or pull requests

1 participant