C Microkernel Realtime eXecutive
Realtime Operating System for Cortex-M based microcontrollers
 
Loading...
Searching...
No Matches
timer.h
1
7#pragma once
8
9#include <stdint.h>
10#include <stdbool.h>
11#include "runtime.h"
12
13/* List of various timer types supported by this framework.
14 * For most part, the most important characteristic is if
15 * the timer is periodic or not.
16 *
17 * This is decided by if the timer type is *above* or *below*
18 * the TIMER_PERIODIC type.
19 */
23 TIMER_PERIODIC, // Marks the first periodic timer type
25};
26
27#define SLEEPER_KEY_TYPE_SHIFT 24
28
29#define SLEEPER_KEY(_type, _thread) (((_type) << SLEEPER_KEY_TYPE_SHIFT) | (_thread))
30
36 uint32_t key;
37 uint32_t sleep_from;
38 uint32_t interval;
39 uint8_t thread_id;
40 uint8_t timer_type;
41};
42
47 uint32_t resume_time;
48 uint8_t entry_id;
49};
50
51#define TIMER_INVALID_ID 0xFF
52
53_Static_assert(TIMER_INVALID_ID > SLEEPERS_MAX, "Timer invalid value must lie outside of timer ID range!");
54
55
59int os_usleep(unsigned microseconds);
60
64int os_setitimer(unsigned microseconds);
65
71void os_timer_init(void);
72
82int os_set_timed_event(unsigned microseconds, enum eSleepType type);
83
91int os_find_timer(Thread_t owner, enum eSleepType type);
92
101int os_cancel_timed_event(Thread_t owner, enum eSleepType type);
102
111int os_cancel_sleeper(unsigned sleeper_queue_id);
112
123bool os_schedule_timer(unsigned * delay);
124
131void os_run_timer(uint32_t start_microtime, uint32_t interval);
132
138uint32_t os_cpu_freq_get(void);
139
uint8_t Thread_t
Data type used for thread IDs.
Definition defines.h:72
#define SLEEPERS_MAX
How many sleeping threads can exist.
Definition kernel.h:41
int os_find_timer(Thread_t owner, enum eSleepType type)
Find a timer slot matching owner thread and timer type.
Definition timer.c:169
void os_run_timer(uint32_t start_microtime, uint32_t interval)
Fire scheduled events.
Definition timer.c:297
#define TIMER_INVALID_ID
Definition timer.h:51
void os_timer_init(void)
This routine initializes kernel scheduling subsystem.
Definition timer.c:252
int os_usleep(unsigned microseconds)
Kernel implementation of usleep() syscall.
Definition timer.c:230
uint32_t os_cpu_freq_get(void)
Get current CPU frequency.
Definition timer.c:372
int os_set_timed_event(unsigned microseconds, enum eSleepType type)
Find a slot for timed event and store it.
Definition timer.c:147
int os_cancel_sleeper(unsigned queue_id)
Cancel existing sleeper.
Definition timer.c:199
int os_cancel_timed_event(Thread_t owner, enum eSleepType type)
Cancels existing timed event.
Definition timer.c:175
bool os_schedule_timer(unsigned *delay)
Provide information on next scheduled event.
Definition timer.c:263
int os_setitimer(unsigned microseconds)
Kernel implementation of setitimer() syscall.
Definition timer.c:240
eSleepType
Definition timer.h:20
@ TIMER_PERIODIC
Definition timer.h:23
@ TIMER_SLEEP
Definition timer.h:21
@ TIMER_INTERVAL
Definition timer.h:24
@ TIMER_TIMEOUT
Definition timer.h:22
Description of one sleep request.
Definition timer.h:35
uint32_t interval
amount of time sleep shall take
Definition timer.h:38
uint32_t key
key created from timer_type and thread_id using SLEEPER_KEY
Definition timer.h:36
uint32_t sleep_from
time at which sleep has been requested
Definition timer.h:37
uint8_t timer_type
type of sleep performed
Definition timer.h:40
uint8_t thread_id
thread ID which requested the sleep
Definition timer.h:39
Entry for sorting sleep requests.
Definition timer.h:46
uint8_t entry_id
Definition timer.h:48
uint32_t resume_time
Definition timer.h:47