Skip to content

Commit af8520a

Browse files
committed
Move software timer defs to lib-superloop
Consolidate software-timer definitions into lib-superloop: remove lib-hal/include/softwaretimers.h, add kSoftwareTimersMax and kTimerIdNone to lib-superloop/include/superloop/softwaretimers.h, and update function declarations. Adjust lib-superloop/src/softwaretimers.cpp to use kSoftwareTimersMax (and drop the hal:: namespace) for the timer pool and bounds check. Also update common/make/gd32/Includes.mk to include the lib-superloop/superloop header path.
1 parent b52b763 commit af8520a

4 files changed

Lines changed: 12 additions & 79 deletions

File tree

common/make/gd32/Includes.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $(call set_if_present,CONFIG_USB_DEVICE_HID,USB_DEVICE_HID)
2727
ifdef FREE_RTOS
2828
INCLUDES+=-I../FreeRTOS/FreeRTOS-Kernel/include
2929
else
30-
INCLUDES+=-I../lib-superloop/include
30+
INCLUDES+=-I../lib-superloop/include/superloop
3131
endif
3232

3333
ifdef USB_HOST

lib-hal/include/softwaretimers.h

Lines changed: 0 additions & 76 deletions
This file was deleted.

lib-superloop/include/superloop/softwaretimers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@
2828

2929
#include <cstdint>
3030

31+
static constexpr uint32_t kSoftwareTimersMax =
32+
#if defined(CONFIG_HAL_TIMERS_COUNT)
33+
CONFIG_HAL_TIMERS_COUNT;
34+
#else
35+
12;
36+
#endif
37+
3138
typedef int32_t TimerHandle_t;
3239
typedef void (*TimerCallbackFunction_t)(TimerHandle_t);
3340

41+
inline constexpr TimerHandle_t kTimerIdNone = -1;
42+
3443
TimerHandle_t SoftwareTimerAdd(uint32_t interval_millis, const TimerCallbackFunction_t kCallback);
3544
bool SoftwareTimerDelete(TimerHandle_t& id);
3645
bool SoftwareTimerChange(TimerHandle_t id, uint32_t interval_millis);

lib-superloop/src/softwaretimers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct Timer {
5252
TimerCallbackFunction_t callback_function; ///< Callback invoked on expiry; must be non-null.
5353
};
5454

55-
static Timer s_timers[hal::kSoftwareTimersMax]; ///< Timer storage pool.
55+
static Timer s_timers[kSoftwareTimersMax]; ///< Timer storage pool.
5656
static uint32_t s_timers_count = 0; ///< Number of active timers (0..hal::SOFTWARE_TIMERS_MAX).
5757
static int32_t s_next_id = 0; ///< Monotonically increasing ID source (may wrap, see notes).
5858
static uint32_t s_timer_current = 0; ///< bRound-robin cursor for SoftwareTimerRun().
@@ -72,7 +72,7 @@ TimerHandle_t SoftwareTimerAdd(uint32_t interval_millis, const TimerCallbackFunc
7272
DEBUG_ENTRY();
7373
DEBUG_PRINTF("s_timers_count=%u", s_timers_count);
7474

75-
if (s_timers_count >= hal::kSoftwareTimersMax) {
75+
if (s_timers_count >= kSoftwareTimersMax) {
7676
Error(__func__, "Max timer limit reached");
7777
return -1;
7878
}

0 commit comments

Comments
 (0)