Skip to content

Fix loops in the SAM banzai() reset function #1876

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

Closed

Conversation

matthijskooijman
Copy link
Collaborator

(Note: I have only compile-tested this code. I haven't got a Due to actually test this, nor the know-how to tell if the fixed code is really correct, but I am sure that the old code is wrong).

The code used to say:

while (EFC0->EEFC_FSR & EEFC_FSR_FRDY == 0);

This triggered a compiler warning, which is why I looked at this line
more closely:

warning: suggest parentheses around comparison in operand of '&'

As the warning indicates, because the == operator has higher precedence
than the & operator, the compiler is interpreting this line as:

while (EFC0->EEFC_FSR & (EEFC_FSR_FRDY == 0));

Since EEFC_FSR_FRDY is defined as 1, (EEFC_FSR_FRDY == 0) is always
false (== 0) and this reduces to:

while (EFC0->EEFC_FSR & 0);

Which reduces to:

while (0);

So effectively this line is a no-op.

This commit adds parenthesis to restore the intended behaviour.

The code used to say:

  while (EFC0->EEFC_FSR & EEFC_FSR_FRDY == 0);

This triggered a compiler warning, which is why I looked at this line
more closely:

	warning: suggest parentheses around comparison in operand of '&'

As the warning indicates, because the == operator has higher precedence
than the & operator, the compiler is interpreting this line as:

  while (EFC0->EEFC_FSR & (EEFC_FSR_FRDY == 0));

Since EEFC_FSR_FRDY is defined as 1, (EEFC_FSR_FRDY == 0) is always
false (== 0) and this reduces to:

  while (EFC0->EEFC_FSR & 0);

Which reduces to:

  while (0);

So effectively this line is a no-op.

This commit adds parenthesis to restore the intended behaviour.
@cmaglie
Copy link
Member

cmaglie commented Feb 18, 2014

Thanks, I've manually merged this patch.
This explains why the waiting loop wasn't working as expected.

Now we can also remove the "settling" delay:
9fcf005

@cmaglie cmaglie closed this Feb 18, 2014
@matthijskooijman
Copy link
Collaborator Author

Cool!

@matthijskooijman matthijskooijman deleted the ide-1.5.x-banzai branch April 14, 2014 14:05
ollie1400 pushed a commit to ollie1400/Arduino that referenced this pull request May 2, 2022
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.

2 participants