Skip to content

Commit dfd47d2

Browse files
Temporary changes to debug scheduler
1 parent e49afea commit dfd47d2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Inc/HALAL/Services/Time/Scheduler.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#endif
1818

1919
#include "stm32h7xx_ll_tim_wrapper.h"
20+
#include "HALAL/Models/Packets/Packet.hpp"
21+
#include "HALAL/Services/Communication/Ethernet/LWIP/UDP/DatagramSocket.hpp"
2022

2123
#include <array>
2224
#include <cstdint>

Src/HALAL/Services/Time/Scheduler.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void Scheduler::update() {
143143
uint32_t bit_index = static_cast<uint32_t>(__builtin_ctz(ready_bitmap_));
144144

145145
Task& task = tasks_[bit_index];
146+
146147
task.callback();
147148

148149
SchedLock();
@@ -280,9 +281,9 @@ void Scheduler::schedule_next_interval() {
280281

281282
Scheduler_global_timer->ARR = current_interval_us_ - 1u;
282283
if (Scheduler_global_timer->CNT > Scheduler_global_timer->ARR) [[unlikely]] {
283-
uint32_t offset = Scheduler_global_timer->CNT - Scheduler_global_timer->ARR;
284+
uint32_t cnt_temp = Scheduler_global_timer->CNT;
284285
Scheduler_global_timer->CNT = 0;
285-
global_tick_us_ += offset;
286+
global_tick_us_ += cnt_temp;
286287
}
287288
}
288289
Scheduler::global_timer_enable();
@@ -298,11 +299,15 @@ inline void Scheduler::on_timer_update() {
298299
if (diff > 0) [[likely]] {
299300
break; // Task is in the future, stop processing
300301
}
302+
uint32_t task_bit = 1u << candidate_id;
301303

302304
SchedLock();
303305
pop_front();
304306
// mark task as ready
305-
SET_BIT(ready_bitmap_, 1u << candidate_id);
307+
if ((ready_bitmap_ & task_bit) != 0) [[unlikely]] {
308+
ErrorHandler("Too slow, could not execute task %u in time", candidate_id);
309+
}
310+
SET_BIT(ready_bitmap_, task_bit);
306311
if (task.repeating) [[likely]] {
307312
task.next_fire_us = static_cast<uint32_t>(global_tick_us_ + task.period_us);
308313
insert_sorted(candidate_id);

0 commit comments

Comments
 (0)