Skip to content

Commit 4e71d87

Browse files
committed
Improving the accuracy and comments around
1 parent bdc1372 commit 4e71d87

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

ee/kernel/src/timer.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,10 @@ __attribute__((weak)) s32 StopTimerSystemTime(void)
263263
#endif
264264

265265
#ifdef F_SetNextComp
266+
#define CLOCKS_GAP 0x200 // For assuring the timer interrupt is triggered
266267
void SetNextComp(u64 time_now)
267268
{
268-
u64 a0, a1;
269+
u64 current_schedule, next_schedule;
269270
counter_struct_t *timer_current;
270271

271272
if (g_Timer.current_handling_timer_id >= 0)
@@ -279,30 +280,32 @@ void SetNextComp(u64 time_now)
279280
SetT2_MODE((*T2_MODE) & (~(1 << 11)));
280281
return;
281282
}
282-
a0 = timer_current->timer_schedule + timer_current->timer_base_time - timer_current->timer_base_count;
283+
current_schedule = timer_current->timer_schedule + timer_current->timer_base_time - timer_current->timer_base_count;
283284
timer_current = timer_current->timer_next;
285+
286+
// Grouping the timers that are so close to each other, to reduce the number of interrupts
284287
while (timer_current != NULL)
285288
{
286-
a1 = timer_current->timer_schedule + timer_current->timer_base_time - timer_current->timer_base_count;
287-
if (a1 < (a0 + 0x733))
289+
next_schedule = timer_current->timer_schedule + timer_current->timer_base_time - timer_current->timer_base_count;
290+
if (next_schedule < (current_schedule + CLOCKS_GAP))
288291
{
289-
a0 = a1;
292+
current_schedule = next_schedule;
290293
}
291294
else
292295
{
293296
break;
294297
}
295298
timer_current = timer_current->timer_next;
296299
}
297-
if (a0 < (time_now + 0x733))
300+
if (current_schedule < (time_now + CLOCKS_GAP))
298301
{
299-
SetT2_COMP((*T2_COUNT) + (0x733 >> (((*T2_MODE) & 3) << 2)));
302+
SetT2_COMP((*T2_COUNT) + (CLOCKS_GAP >> (((*T2_MODE) & 3) << 2)));
300303
SetT2_MODE((*T2_MODE) & (~(1 << 11)));
301304
}
302305
else
303306
{
304307
SetT2_MODE((*T2_MODE) & (~(1 << 11)));
305-
SetT2_COMP(a0 >> (((*T2_MODE) & 3) << 2));
308+
SetT2_COMP(current_schedule >> (((*T2_MODE) & 3) << 2));
306309
}
307310
}
308311
#endif

0 commit comments

Comments
 (0)