dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_thread.h
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
25 
26 #ifndef PIOS_THREAD_H_
27 #define PIOS_THREAD_H_
28 
29 #define PIOS_THREAD_TIMEOUT_MAX 0xffffffff
30 
31 #include <stdint.h>
32 #include <stdbool.h>
33 
34 struct pios_thread;
35 
36 #include <taskmonitor.h>
37 
38 #if defined(PIOS_INCLUDE_CHIBIOS)
39 
40 #include "ch.h"
41 
43 {
44  PIOS_THREAD_PRIO_LOW = LOWPRIO,
45  PIOS_THREAD_PRIO_NORMAL = NORMALPRIO,
46  PIOS_THREAD_PRIO_HIGH = NORMALPRIO + 8,
47  PIOS_THREAD_PRIO_HIGHEST = NORMALPRIO + 16,
48 };
49 
50 #define PIOS_THREAD_STACK_SIZE_MIN THD_WA_SIZE(256 + PORT_INT_REQUIRED_STACK)
51 
52 #else
53 
54 /* Posix or targets without threading or default for extensions */
55 #define PIOS_THREAD_STACK_SIZE_MIN (4096)
56 
58 {
63 };
64 #endif
65 
66 /*
67  * The following functions implement the concept of a thread usable
68  * with either FreeRTOS or ChibiOS
69  */
70 
71 struct pios_thread *PIOS_Thread_Create(void (*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio);
72 void PIOS_Thread_Delete(struct pios_thread *threadp);
73 uint32_t PIOS_Thread_Systime(void);
74 void PIOS_Thread_Sleep(uint32_t time_ms);
75 void PIOS_Thread_Sleep_Until(uint32_t *previous_ms, uint32_t increment_ms);
76 uint32_t PIOS_Thread_Get_Stack_Usage(struct pios_thread *threadp);
77 uint32_t PIOS_Thread_Get_Runtime(struct pios_thread *threadp);
80 
81 /*
82  * The following functions are provided to assist with common thread timing uses
83  */
90 bool PIOS_Thread_Period_Elapsed(const uint32_t prev_systime, const uint32_t increment_ms);
91 struct pios_thread *PIOS_Thread_WrapCurrentThread(const char *namep);
93 
94 #ifdef FLIGHT_POSIX
95 void PIOS_Thread_FakeClock_Tick(void);
97 void PIOS_Thread_FakeClock_UpdateBarrier(uint32_t increment);
98 #endif
99 
100 #endif /* PIOS_THREAD_H_ */
101 
uint32_t PIOS_Thread_Systime(void)
Definition: pios_thread.c:212
void PIOS_Thread_Scheduler_Suspend(void)
Task monitoring library.
void PIOS_Thread_ChangePriority(enum pios_thread_prio_e prio)
Definition: pios_thread.c:78
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
Definition: pios_thread.c:89
bool PIOS_Thread_Period_Elapsed(const uint32_t prev_systime, const uint32_t increment_ms)
Determine if a period has elapsed since a datum.
Definition: pios_thread.c:281
void PIOS_Thread_Sleep_Until(uint32_t *previous_ms, uint32_t increment_ms)
Definition: pios_thread.c:255
void PIOS_Thread_Sleep(uint32_t time_ms)
Definition: pios_thread.c:229
uint32_t PIOS_Thread_Get_Stack_Usage(struct pios_thread *threadp)
Definition: pios_thread.c:271
pios_thread_prio_e
Definition: pios_thread.h:57
uint32_t PIOS_Thread_Get_Runtime(struct pios_thread *threadp)
Definition: pios_thread.c:276
void PIOS_Thread_Scheduler_Resume(void)
void PIOS_Thread_Delete(struct pios_thread *threadp)
Definition: pios_thread.c:132
struct pios_thread * PIOS_Thread_WrapCurrentThread(const char *namep)
Creates a handle for the current thread.
Definition: pios_thread.c:51
bool PIOS_Thread_FakeClock_IsActive(void)
Definition: pios_thread.c:207