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

Fix events and timer compare #1581

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ void Time_SetCompare ( uint64_t compareValueTicks )
// compareValueTicks is in CMSIS ticks (which equals to ms), so we use TIME_MS2I only to round
compareValueTicks -= HAL_Time_CurrentSysTicks();
uint64_t delay = TIME_MS2I(compareValueTicks);
// make sure that chVTSet does not get called with zero delay
if (delay == 0)

// make sure that chVTSet does not get called with zero delay
if (delay == 0)
{
delay = 1;
// compare value is 0 so dequeue and execute immediately
// no need to call the timer
HAL_COMPLETION::DequeueAndExec();
return;
}

// no need to stop the timer if it's running because the API does it anyway
Expand Down
7 changes: 5 additions & 2 deletions targets/FreeRTOS/common/nanoCLR/targetPAL_Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents,
Events_WaitForEvents_Calls++;
#endif

uint64_t expireTimeInTicks = HAL_Time_CurrentTime() + countsRemaining;
uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining;
bool runContinuations = true;

while(true)
Expand All @@ -135,7 +135,7 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents,
return events;
}

if(expireTimeInTicks <= HAL_Time_CurrentTime())
if(expireTimeInTicks <= HAL_Time_CurrentSysTicks())
{
break;
}
Expand Down Expand Up @@ -163,6 +163,9 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents,
{
break;
}

// feed the watchdog...
Watchdog_Reset();
}

return 0;
Expand Down
6 changes: 4 additions & 2 deletions targets/FreeRTOS/common/nanoCLR/targetPAL_Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ void Time_SetCompare ( uint64_t compareValueTicks )
// need to subtract the current system time to set when the timer will fire
compareValueTicks -= HAL_Time_CurrentTime();

if (compareValueTicks == 0) {
// compare value is 0 so dequeue and schedule immediately
if (compareValueTicks == 0)
{
// compare value is 0 so dequeue and execute immediately
// no need to call the timer
HAL_COMPLETION::DequeueAndExec();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents,
Events_WaitForEvents_Calls++;
#endif

uint64_t expireTimeInTicks = HAL_Time_CurrentTime() + countsRemaining;
uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining;
bool runContinuations = true;

while(true)
Expand All @@ -134,7 +134,7 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents,
return events;
}

if(expireTimeInTicks <= HAL_Time_CurrentTime())
if(expireTimeInTicks <= HAL_Time_CurrentSysTicks())
{
break;
}
Expand Down
12 changes: 10 additions & 2 deletions targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void Time_SetCompare ( uint64_t compareValueTicks )
}
else
{
if (HAL_Time_CurrentTime() >= compareValueTicks)
if (HAL_Time_CurrentSysTicks() >= compareValueTicks)
{
// already missed the event, dequeue and execute immediately
HAL_COMPLETION::DequeueAndExec();
Expand All @@ -56,7 +56,15 @@ void Time_SetCompare ( uint64_t compareValueTicks )

// compareValueTicks is the time (in sys ticks) that is being requested to fire an HAL_COMPLETION::DequeueAndExec()
// need to subtract the current system time to set when the timer will fire
compareValueTicks -= HAL_Time_CurrentTime();
compareValueTicks -= HAL_Time_CurrentSysTicks();

if (compareValueTicks == 0)
{
// compare value is 0 so dequeue and execute immediately
// no need to call the timer
HAL_COMPLETION::DequeueAndExec();
return;
}

// no need to stop the timer even if it's running because the API does it anyway
// need to convert from nF ticks to milliseconds and then to FreeRTOS sys ticks to load the timer
Expand Down
4 changes: 2 additions & 2 deletions targets/TI-SimpleLink/nanoCLR/targetPAL_Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents,
Events_WaitForEvents_Calls++;
#endif

uint64_t expireTimeInTicks = HAL_Time_CurrentTime() + countsRemaining;
uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining;
bool runContinuations = true;

while(true)
Expand All @@ -164,7 +164,7 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents,
return events;
}

if(expireTimeInTicks <= HAL_Time_CurrentTime())
if(expireTimeInTicks <= HAL_Time_CurrentSysTicks())
{
break;
}
Expand Down
10 changes: 7 additions & 3 deletions targets/TI-SimpleLink/nanoCLR/targetPAL_Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@ void Time_SetCompare ( uint64_t compareValueTicks )
// need to subtract the current system time to set when the timer will fire
compareValueTicks -= HAL_Time_CurrentTime();

// // no need to stop the timer even if it's running because the API does it anyway
// // need to convert from nF ticks to milliseconds and then to FreeRTOS sys ticks to load the timer
// xTimerChangePeriod(nextEventTimer, compareValueTicks, 0);
if (compareValueTicks == 0)
{
// compare value is 0 so dequeue and execute immediately
// no need to call the timer
HAL_COMPLETION::DequeueAndExec();
return;
}

Clock_setPeriod(nextEventTimer, compareValueTicks);
Clock_start(nextEventTimer);
Expand Down