88
99#include <types.h>
1010
11+ /* Forward declaration */
12+ struct tcb ;
13+
1114void ktimer_handler (void );
1215
1316/* Returns 0 if successfully handled
@@ -22,14 +25,50 @@ typedef struct ktimer_event {
2225
2326 uint32_t delta ;
2427 void * data ;
28+
29+ /* Notification mode: if notify_thread is non-NULL, timer uses
30+ * async event notification instead of calling handler directly.
31+ * This integrates with Event-Chaining + ASYNC_SOFTIRQ subsystem.
32+ */
33+ struct tcb * notify_thread ; /* Target thread for notification */
34+ uint32_t notify_bits ; /* Notification bit mask to signal */
35+
36+ /* Deadline tracking for periodic timers (prevents drift accumulation).
37+ * For periodic timers, deadline tracks absolute target time.
38+ * Reschedule based on: next_ticks = max(1, deadline - now)
39+ * This maintains phase-lock to original schedule even if softirq delayed.
40+ */
41+ uint64_t deadline ; /* Absolute deadline (in ticks since boot) */
2542} ktimer_event_t ;
2643
2744void ktimer_event_init (void );
2845
2946int ktimer_event_schedule (uint32_t ticks , ktimer_event_t * kte );
47+
48+ /* Callback-based timer (traditional API) */
3049ktimer_event_t * ktimer_event_create (uint32_t ticks ,
3150 ktimer_event_handler_t handler ,
3251 void * data );
52+
53+ /* Notification-based timer (Event-Chaining + ASYNC_SOFTIRQ integration).
54+ * When timer expires, posts async event to notify_thread with notify_bits.
55+ * Thread receives notification via Event-Chaining callback.
56+ *
57+ * @param ticks Timer period in ticks
58+ * @param notify_thread Target thread to notify (must be valid TCB)
59+ * @param notify_bits Notification bit mask to signal
60+ * @param periodic If 0, one-shot timer. If non-zero, reschedule with same
61+ * period.
62+ * @return Allocated timer event, or NULL if pool exhausted
63+ *
64+ * NOTE: For one-shot timers, event is freed automatically after firing.
65+ * For periodic timers, event remains allocated until explicitly freed.
66+ */
67+ ktimer_event_t * ktimer_event_create_notify (uint32_t ticks ,
68+ struct tcb * notify_thread ,
69+ uint32_t notify_bits ,
70+ int periodic );
71+
3372void ktimer_event_handler (void );
3473
3574#ifdef CONFIG_KTIMER_TICKLESS
0 commit comments