Skip to content

Commit f4a12ef

Browse files
victor-Lopez25jorgesg82
authored andcommitted
revert merge from development
1 parent fb1b7c2 commit f4a12ef

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Inc/HALAL/Services/Time/Scheduler.hpp

Lines changed: 3 additions & 1 deletion
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>
@@ -113,4 +115,4 @@ struct Scheduler {
113115

114116
static inline void global_timer_disable();
115117
static inline void global_timer_enable();
116-
};
118+
};

Src/HALAL/Services/Time/Scheduler.cpp

Lines changed: 9 additions & 4 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);
@@ -401,4 +406,4 @@ bool Scheduler::cancel_timeout(uint16_t id) {
401406
schedule_next_interval();
402407
SchedUnlock();
403408
return true;
404-
}
409+
}

Tests/Time/scheduler_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,4 @@ TEST_F(SchedulerTests, SameTaskMultipleTimes) {
289289
NUM_TICKS / 1 - 1 + NUM_TICKS / 2 - 1 + NUM_TICKS / 3 - 1 + NUM_TICKS / 4 - 1 +
290290
NUM_TICKS / 5 - 1 + NUM_TICKS / 6 - 1
291291
);
292-
}
292+
}

0 commit comments

Comments
 (0)