IntrOS
Loading...
Searching...
No Matches
osbase.h
1/******************************************************************************
2
3 @file IntrOS: osbase.h
4 @author Rajmund Szymanski
5 @date 18.11.2025
6 @brief This file contains basic definitions for IntrOS.
7
8 ******************************************************************************
9
10 Copyright (c) 2018-2022 Rajmund Szymanski. All rights reserved.
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to
14 deal in the Software without restriction, including without limitation the
15 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 sell copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included
20 in all copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 IN THE SOFTWARE.
29
30 ******************************************************************************/
31
32#ifndef __INTROSBASE_H
33#define __INTROSBASE_H
34
35#ifndef DEBUG
36#ifndef NDEBUG
37#define NDEBUG
38#endif // NDEBUG
39#endif // DEBUG
40
41#include <stdint.h>
42#include <limits.h>
43#include <stdbool.h>
44#include <assert.h>
45#include <setjmp.h>
46#include "osport.h"
47
48/* -------------------------------------------------------------------------- */
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54/* -------------------------------------------------------------------------- *
55 * FOR INTERNAL USE *
56 * -------------------------------------------------------------------------- */
57
58#ifndef OS_ATOMICS
59#define OS_ATOMICS 0
60#endif
61
62/* -------------------------------------------------------------------------- */
63
64#ifndef OS_TASK_EXIT
65#define OS_TASK_EXIT 0
66#endif
67
68/* -------------------------------------------------------------------------- */
69
70#ifndef OS_GUARD_SIZE
71#define OS_GUARD_SIZE 0
72#endif
73
74#ifndef __FPU_USED
75#define __FPU_USED 0
76#endif
77
78#ifndef __MPU_USED
79#define __MPU_USED 0
80#endif
81
82#if __MPU_USED
83#define __STKALIGN __ALIGNED(OS_GUARD_SIZE)
84#else
85#define __STKALIGN
86#endif
87
88#ifndef __ALIGNED
89#define __ALIGNED(x)
90#endif
91
92/* -------------------------------------------------------------------------- */
93
94#ifndef OS_TIMER_SIZE
95#define OS_TIMER_SIZE 32
96#endif
97
98/* -------------------------------------------------------------------------- */
99
100#if HW_TIMER_SIZE == 16
101typedef uint16_t hwt_t;
102#elif HW_TIMER_SIZE == 32
103typedef uint32_t hwt_t;
104#elif HW_TIMER_SIZE == 64
105typedef uint64_t hwt_t;
106#elif HW_TIMER_SIZE
107#error Invalid HW_TIMER_SIZE value!
108#endif
109
115
116#if OS_TIMER_SIZE == 16
117typedef uint16_t cnt_t;
118#define CNT_MAX 0xFFFFU
119#elif OS_TIMER_SIZE == 32
120typedef uint32_t cnt_t;
121#define CNT_MAX 0xFFFFFFFFUL
122#elif OS_TIMER_SIZE == 64
123typedef uint64_t cnt_t;
124#define CNT_MAX 0xFFFFFFFFFFFFFFFFULL
125#else
126#error Invalid OS_TIMER_SIZE value!
127#endif
128
129#define CNT_LIMIT ((CNT_MAX)-((CNT_MAX)>>((OS_TIMER_SIZE)/4)))
130
132
133/* -------------------------------------------------------------------------- */
134
135typedef struct __mtx mtx_t; // mutex
136typedef struct __tmr tmr_t; // timer
137typedef struct __tsk tsk_t; // task
141
142typedef void fun_t(void);
143typedef void fun_a(void*);
144
145/* -------------------------------------------------------------------------- */
146
148enum
149{
154};
155
157
158/* -------------------------------------------------------------------------- */
159
160// object id
161
162typedef enum __tid
163{
164 ID_STOPPED = 0, // inactive object
165 ID_READY, // active task
166 ID_TIMER, // active timer
167
168} tid_t;
169
170/* -------------------------------------------------------------------------- */
171
172// object header
173
174typedef struct __obj
175{
176 tsk_t * queue; // next process in the BLOCKED queue
177
178} obj_t;
179
180#define _OBJ_INIT() { NULL }
181
182/* -------------------------------------------------------------------------- */
183
184// timer / task header
185
186typedef struct __hdr
187{
188 void * prev; // previous object (timer / task) in the READY queue
189 void * next; // next object (timer / task) in the READY queue
190 tid_t id; // timer / task id
191
192} hdr_t;
193
194#define _HDR_INIT() { NULL, NULL, ID_STOPPED }
195
196/* -------------------------------------------------------------------------- */
197
198__STATIC_INLINE
199void core_hdr_init( hdr_t *hdr )
200{
201 hdr->id = ID_STOPPED;
202}
203
204/* -------------------------------------------------------------------------- */
205
206// system data
207
208typedef struct __sys
209{
210 tsk_t * cur; // pointer to the current task control block
211 tsk_t * tsk; // task executed in system suspend mode
212#if HW_TIMER_SIZE < OS_TIMER_SIZE
213 volatile
214 cnt_t cnt; // system timer counter
215#endif
216
217} sys_t;
218
219/* -------------------------------------------------------------------------- */
220
224
225#if (OS_FREQUENCY)/1000000 > 0 && (OS_FREQUENCY)/1000000 < (CNT_MAX)
226#define USEC (cnt_t)((OS_FREQUENCY)/1000000)
227#endif
228#if (OS_FREQUENCY)/1000 > 0 && (OS_FREQUENCY)/1000 < (CNT_MAX)
229#define MSEC (cnt_t)((OS_FREQUENCY)/1000)
230#endif
231#if (OS_FREQUENCY) < (CNT_MAX)
232#define SEC ((cnt_t)(OS_FREQUENCY))
233#endif
234#if (OS_FREQUENCY) < (CNT_MAX)/60
235#define MIN ((cnt_t)(OS_FREQUENCY)*60)
236#endif
237#if (OS_FREQUENCY) < (CNT_MAX)/3600
238#define HOUR ((cnt_t)(OS_FREQUENCY)*3600)
239#endif
240#if (OS_FREQUENCY) < (CNT_MAX)/86400
241#define DAY ((cnt_t)(OS_FREQUENCY)*86400)
242#endif
243
244/* -------------------------------------------------------------------------- */
245
246#ifndef IMMEDIATE
247#define IMMEDIATE 0
248#endif
249#ifndef INFINITE
250#define INFINITE CNT_MAX
251#endif
252
254
255/* -------------------------------------------------------------------------- */
256
257#ifdef __cplusplus
258}
259#endif
260
261#endif//__INTROSBASE_H
void fun_a(void *)
timer/task procedure with argument
Definition osbase.h:143
void fun_t(void)
timer/task procedure
Definition osbase.h:142
@ E_TIMEOUT
process was released as a result of the end of the timer countdown
Definition osbase.h:153
@ E_FAILURE
process was released as a result of any failure
Definition osbase.h:151
@ E_SUCCESS
process was released as a result of taking the supervising object
Definition osbase.h:150
@ E_STOPPED
process was released as a result of reset the supervising object
Definition osbase.h:152