-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
picoRTOS.h
139 lines (114 loc) · 5 KB
/
picoRTOS.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef PICORTOS_H
#define PICORTOS_H
#include <stddef.h>
#include <stdbool.h>
#include "picoRTOS_types.h"
#include <generated/autoconf.h>
/* TASKS */
typedef void (*picoRTOS_task_fn)(void*);
struct picoRTOS_task {
/*@temp@*/ picoRTOS_task_fn fn;
/*@temp@*/ void *priv;
/*@temp@*/ picoRTOS_stack_t *stack;
size_t stack_count;
};
void picoRTOS_task_init(/*@out@*/ struct picoRTOS_task *task,
picoRTOS_task_fn fn, /*@null@*/ void *priv,
/*@reldef@*/ picoRTOS_stack_t *stack,
size_t stack_count);
/* Group: picoRTOS scheduler API */
/* Macro: PICORTOS_STACK_COUNT(x)
* Computes stack count from array
*
* Parameters:
* x - a picoRTOS_stack_t array
*/
#define PICORTOS_STACK_COUNT(x) (sizeof(x) / sizeof(picoRTOS_stack_t))
/* SCHEDULER */
void picoRTOS_init(void);
void picoRTOS_add_task(struct picoRTOS_task *task,
picoRTOS_priority_t prio); /* register task */
picoRTOS_priority_t picoRTOS_get_next_available_priority(void); /* get next free priority slot */
picoRTOS_priority_t picoRTOS_get_last_available_priority(void); /* get last free priority slot */
/*@maynotreturn@*/ void picoRTOS_start(void); /* starts picoRTOS */
void picoRTOS_suspend(void); /* suspends the scheduling */
void picoRTOS_resume(void); /* resumes the scheduling */
void picoRTOS_schedule(void); /* move to next task */
void picoRTOS_sleep(picoRTOS_tick_t delay); /* put current task to sleep */
void picoRTOS_sleep_until(picoRTOS_tick_t *ref, /* put current task to sleep until */
picoRTOS_tick_t period);
/*@noreturn@*/ void picoRTOS_kill(void); /* kills the current task */
picoRTOS_pid_t picoRTOS_self(void); /* gets the current thread priority */
/*@unused@*/ picoRTOS_tick_t picoRTOS_get_tick(void); /* get current tick */
/* TIME MANAGEMENT */
/* Macro: PICORTOS_DELAY_SEC(x)
* Converts seconds to picoRTOS_tick_t
*
* Parameters:
* x - a value in seconds
*/
#define PICORTOS_DELAY_SEC(x) (picoRTOS_tick_t)((x) * CONFIG_TICK_HZ)
/* Macro: PICORTOS_DELAY_MSEC(x)
* Converts milliseconds to picoRTOS_tick_t
*
* Parameters:
* x - a value in milliseconds
*/
#define PICORTOS_DELAY_MSEC(x) (picoRTOS_tick_t)(((x) * CONFIG_TICK_HZ) / 1000)
/* Macro: PICORTOS_DELAY_USEC(x)
* Converts microseconds in picoRTOS_tick_t
*
* Parameters:
* x - a value in microseconds
*/
#define PICORTOS_DELAY_USEC(x) (picoRTOS_tick_t)(((x) * CONFIG_TICK_HZ) / 1000000)
/* INTERRUPT MANAGEMENT */
typedef void (*picoRTOS_isr_fn)(/*@null@*/ void*);
void picoRTOS_register_interrupt(picoRTOS_irq_t irq,
picoRTOS_isr_fn fn,
/*@null@*/ void *priv);
void picoRTOS_enable_interrupt(picoRTOS_irq_t irq);
void picoRTOS_disable_interrupt(picoRTOS_irq_t irq);
/* CACHE MANAGEMENT */
void picoRTOS_invalidate_dcache(void *addr, size_t n);
void picoRTOS_flush_dcache(void *addr, size_t n);
/* Group: picoRTOS assert API */
#if !defined(NDEBUG)
/* Macro: picoRTOS_break()
* Throws a debug exception, ignored if -DNDEBUG */
# define picoRTOS_break() arch_break()
/* Macro: picoRTOS_assert(x, or_else)
* Returns x, throws a debug exception & executes or_else if x is false,
* unless -DNDEBUG */
# define picoRTOS_assert(x, or_else) \
if (!(x)) { \
picoRTOS_break(); /*@notreached@*/ \
{ or_else; } \
}
/* Macro: picoRTOS_assert_void(x)
* Throws a debug exception if x is false, unless -DNDEBUG */
# define picoRTOS_assert_void(x) if (!(x)) picoRTOS_break()
/* Macro: picoRTOS_assert_fatal(x, or_else)
* Returns x, throws a debug exception & executes or_else if x is false,
* stalls the system if -DNDEBUG */
# define picoRTOS_assert_fatal(x, or_else) picoRTOS_assert(x, or_else)
/* Macro: picoRTOS_assert_void_fatal(x)
* Throws a debug exception if x is false, stalls the system if -DNDEBUG */
# define picoRTOS_assert_void_fatal(x) picoRTOS_assert_void(x)
#else
# define picoRTOS_break() for (;;) {}
# define picoRTOS_assert(x, or_else) if (!(x)) { or_else; }
# define picoRTOS_assert_void(x) {}
# define picoRTOS_assert_fatal(x, or_else) \
if (!(x)) { \
picoRTOS_suspend(); \
picoRTOS_break(); /*@notreached@*/ \
{ or_else; } \
}
# define picoRTOS_assert_void_fatal(x) \
if (!(x)) { \
picoRTOS_suspend(); \
picoRTOS_break(); \
}
#endif
#endif