os_port_sys_bios.h
Go to the documentation of this file.
1 /**
2  * @file os_port_sys_bios.h
3  * @brief RTOS abstraction layer (SYS/BIOS)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 2.4.4
27  **/
28 
29 #ifndef _OS_PORT_SYS_BIOS_H
30 #define _OS_PORT_SYS_BIOS_H
31 
32 //Dependencies
33 #include <xdc/std.h>
34 #include <xdc/runtime/error.h>
35 #include <xdc/runtime/system.h>
36 #include <xdc/runtime/memory.h>
37 #include <ti/sysbios/bios.h>
38 #include <ti/sysbios/knl/task.h>
39 #include <ti/sysbios/knl/event.h>
40 #include <ti/sysbios/knl/semaphore.h>
41 #include <ti/sysbios/knl/clock.h>
42 #include <ti/sysbios/hal/hwi.h>
43 
44 //Invalid task identifier
45 #define OS_INVALID_TASK_ID NULL
46 //Self task identifier
47 #define OS_SELF_TASK_ID NULL
48 
49 //Task priority (normal)
50 #ifndef OS_TASK_PRIORITY_NORMAL
51  #define OS_TASK_PRIORITY_NORMAL 1
52 #endif
53 
54 //Task priority (high)
55 #ifndef OS_TASK_PRIORITY_HIGH
56  #define OS_TASK_PRIORITY_HIGH 2
57 #endif
58 
59 //Milliseconds to system ticks
60 #ifndef OS_MS_TO_SYSTICKS
61  #define OS_MS_TO_SYSTICKS(n) (n)
62 #endif
63 
64 //System ticks to milliseconds
65 #ifndef OS_SYSTICKS_TO_MS
66  #define OS_SYSTICKS_TO_MS(n) (n)
67 #endif
68 
69 //Retrieve 64-bit system time (not implemented)
70 #ifndef osGetSystemTime64
71  #define osGetSystemTime64() osGetSystemTime()
72 #endif
73 
74 //Task prologue
75 #define osEnterTask()
76 //Task epilogue
77 #define osExitTask()
78 //Interrupt service routine prologue
79 #define osEnterIsr()
80 //Interrupt service routine epilogue
81 #define osExitIsr(flag)
82 
83 //C++ guard
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87 
88 
89 /**
90  * @brief System time
91  **/
92 
93 typedef uint32_t systime_t;
94 
95 
96 /**
97  * @brief Task identifier
98  **/
99 
100 typedef Task_Handle OsTaskId;
101 
102 
103 /**
104  * @brief Task parameters
105  **/
106 
107 typedef struct
108 {
109  size_t stackSize;
112 
113 
114 /**
115  * @brief Event object
116  **/
117 
118 typedef struct
119 {
120  Event_Handle handle;
121 } OsEvent;
122 
123 
124 /**
125  * @brief Semaphore object
126  **/
127 
128 typedef struct
129 {
130  Semaphore_Handle handle;
131 } OsSemaphore;
132 
133 
134 /**
135  * @brief Mutex object
136  **/
137 
138 typedef struct
139 {
140  Semaphore_Handle handle;
141 } OsMutex;
142 
143 
144 /**
145  * @brief Task routine
146  **/
147 
148 typedef void (*OsTaskCode)(void *arg);
149 
150 
151 //Default task parameters
153 
154 //Kernel management
155 void osInitKernel(void);
156 void osStartKernel(void);
157 
158 //Task management
159 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
160  const OsTaskParameters *params);
161 
162 void osDeleteTask(OsTaskId taskId);
163 void osDelayTask(systime_t delay);
164 void osSwitchTask(void);
165 void osSuspendAllTasks(void);
166 void osResumeAllTasks(void);
167 
168 //Event management
170 void osDeleteEvent(OsEvent *event);
171 void osSetEvent(OsEvent *event);
172 void osResetEvent(OsEvent *event);
173 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
175 
176 //Semaphore management
177 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
178 void osDeleteSemaphore(OsSemaphore *semaphore);
179 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
180 void osReleaseSemaphore(OsSemaphore *semaphore);
181 
182 //Mutex management
184 void osDeleteMutex(OsMutex *mutex);
185 void osAcquireMutex(OsMutex *mutex);
186 void osReleaseMutex(OsMutex *mutex);
187 
188 //System time
190 
191 //Memory management
192 void *osAllocMem(size_t size);
193 void osFreeMem(void *p);
194 
195 //C++ guard
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #endif
int bool_t
Definition: compiler_port.h:53
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
void osDelayTask(systime_t delay)
Delay routine.
uint8_t p
Definition: ndp.h:300
Semaphore_Handle handle
Event object.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
char_t name[]
uint32_t systime_t
System time.
void osDeleteTask(OsTaskId taskId)
Delete a task.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void osSwitchTask(void)
Yield control to the next task.
Semaphore object.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
Semaphore_Handle handle
Task_Handle OsTaskId
Task identifier.
mutex_t OsMutex
Mutex object.
binary_semaphore_t OsEvent
Event object.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
Task parameters.
void(* OsTaskCode)(void *arg)
Task routine.
void osInitKernel(void)
Kernel initialization.
void * osAllocMem(size_t size)
Allocate a memory block.
void osSuspendAllTasks(void)
Suspend scheduler activity.
void osStartKernel(void)
Start kernel.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
Mutex object.
uint32_t systime_t
System time.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
char char_t
Definition: compiler_port.h:48
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
void osResumeAllTasks(void)
Resume scheduler activity.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
systime_t osGetSystemTime(void)
Retrieve system time.
void osDeleteEvent(OsEvent *event)
Delete an event object.
void osFreeMem(void *p)
Release a previously allocated memory block.
thread_t * OsTaskId
Task identifier.
unsigned int uint_t
Definition: compiler_port.h:50
uint16_t priority
Definition: dns_common.h:265
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
Event_Handle handle
semaphore_t OsSemaphore
Semaphore object.