42 #define TIMER_INTERRUPT_FREQUENCY 82 43 #define TIMER_INTERRUPT_DELTA 12 45 static uint64_t currentKernelTimestamp;
49 static void __timerDestroy(
struct object *obj);
50 static void __timerShutdown(
struct object *obj,
UNUSED uint32_t
mode);
51 static int32_t __timerGetStatus(
struct object *obj,
UNUSED uint32_t
mode);
52 static struct linkedList *__timerWait(
struct object *obj,
UNUSED uint32_t
mode, uint32_t *result);
53 static void __timerSignal(
struct object *obj,
UNUSED uint32_t result);
54 static int32_t __timerWrite(
struct object *obj, uint8_t *buf, uint32_t length);
71 static inline void __timerDeactivate(
struct timer *t)
81 static inline void __timerActivate(
struct timer *t)
96 static inline void __timerUpdate(
struct timer *t)
120 __objectInit(&t->
obj, &timerFunctions);
135 static void __timerDestroy(
struct object *
obj)
140 __timerDeactivate(t);
141 queueWakeup(&t->
waiters,
true, -1);
158 static void __timerShutdown(
struct object *obj,
UNUSED uint32_t
mode)
163 __timerDeactivate(t);
164 queueWakeup(&t->
waiters,
true, -1);
178 static int32_t __timerGetStatus(
struct object *obj,
UNUSED uint32_t mode)
195 static struct linkedList *__timerWait(
struct object *obj,
UNUSED uint32_t mode, uint32_t *result)
201 if (t->
timeout > currentKernelTimestamp)
217 __timerDeactivate(t);
221 *result = eventCount;
235 static void __timerSignal(
struct object *obj,
UNUSED uint32_t result)
251 static int32_t __timerWrite(
struct object *obj, uint8_t *buf, uint32_t length)
255 if (length !=
sizeof(
struct timerInfo))
return -1;
274 static uint32_t timer_irq(
UNUSED uint32_t irq)
283 if (t->
timeout > currentKernelTimestamp)
break;
295 __timerDeactivate(t);
327 return currentKernelTimestamp;
const struct objectFunctions * functions
void * heapAlloc(uint32_t length)
Allocates a block of kernel memory.
struct linkedList timerList
struct linkedList waiters
void heapFree(void *addr)
Deallocates a block of kernel memory.
#define TIMER_INTERRUPT_DELTA
#define LL_INIT(list)
Initializes a linkedList.
#define LL_ENTRY(element, type, field)
bool picReserveIRQ(uint32_t irq, irq_callback callback)
Assign a callback function to an IRQ.
void pitSetFrequency(uint32_t channel, uint32_t frequency)
Set frequency of the programmable interval timer.
#define TIMER_INTERRUPT_FREQUENCY
#define objectContainer(p, type, functions)
struct timer * timerCreate(bool wakeupAll)
Creates a new kernel timer object.
void timerInit()
Initializes the system timer.
#define LL_FOR_EACH(element, list, type, field)
Allows to iterate a linkedList similar to a for-loop.
uint64_t timerGetTimestamp()
Returns the current kernel timestamp.