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

Casting error on vPortDelay function #126

Closed
Oscar-Wohlfarhrt opened this issue Dec 11, 2023 · 0 comments
Closed

Casting error on vPortDelay function #126

Oscar-Wohlfarhrt opened this issue Dec 11, 2023 · 0 comments

Comments

@Oscar-Wohlfarhrt
Copy link

I was developing a home project, and need to make a 5 minutes delay. Of course, I use delay(300000);, but when I compile and upload the code, the delay was approximately of 1 minute.
Since I have experience with c++ and arduino, I dig in the repository code and found that the delay() function was defined as vPortDelay(), so i search it's definition.
When I found it, discover that in line 651 "vTaskDelay( (TickType_t) (ms) / portTICK_PERIOD_MS );" is casting an unsigned long to a TickType_t (which is defined as uint16_t) before doing the operation. That results in an overflow of the TickType_t, which lost all the unsigned long data (almost all data, until 65535 is all ok) before operating it to convert it to TickType_t and use it on vTaskDelay() function.
My thoughs was the brackets of (ms) should be over the entire operation, like this (TickType_t) (ms / portTICK_PERIOD_MS) for it to work properly. I do the operation on my code, and use vTaskDelay() instead of delay(), and it worked as expected, for 300000 ms I had a 5 minutes delay.
So I raise this issue to inform, what I supose is a typo error, this library error.
I don't belive that someone else are going to use a 5 minutes delay, but I used and found this error.

I don't speak English natively, so I used Google Translate to help me write.

@feilipu feilipu closed this as completed in 9be0651 Jan 2, 2024
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

No branches or pull requests

1 participant