2 ******************************************************************************
4 * @author Tau Labs, http://taulabs.org, Copyright (C) 2014
5 * @addtogroup PIOS PIOS Core hardware abstraction layer
7 * @addtogroup PIOS_Thread Thread Abstraction
9 * @brief Abstracts the concept of a thread to hide different implementations
10 *****************************************************************************/
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.
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
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifndef PIOS_THREAD_H_
28 #define PIOS_THREAD_H_
30 #define PIOS_THREAD_TIMEOUT_MAX 0xffffffff
35 #if defined(PIOS_INCLUDE_FREERTOS)
37 #include "FreeRTOSConfig.h"
39 enum pios_thread_prio_e
{
40 PIOS_THREAD_PRIO_LOW
= 1,
41 PIOS_THREAD_PRIO_NORMAL
= 2,
42 PIOS_THREAD_PRIO_HIGH
= 3,
43 PIOS_THREAD_PRIO_HIGHEST
= 4, /* @note: this has to match (configMAX_PRIORITIES - 1) */
46 #define PIOS_THREAD_STACK_SIZE_MIN (configMINIMAL_STACK_SIZE * 4)
49 uintptr_t task_handle
;
52 #elif defined(PIOS_INCLUDE_CHIBIOS)
56 enum pios_thread_prio_e
{
57 PIOS_THREAD_PRIO_LOW
= LOWPRIO
,
58 PIOS_THREAD_PRIO_NORMAL
= NORMALPRIO
,
59 PIOS_THREAD_PRIO_HIGH
= NORMALPRIO
+ 32,
60 PIOS_THREAD_PRIO_HIGHEST
= HIGHPRIO
,
63 #define PIOS_THREAD_STACK_SIZE_MIN THD_WA_SIZE(4096 + PORT_INT_REQUIRED_STACK)
69 #endif /* defined(PIOS_INCLUDE_CHIBIOS) */
72 * The following functions implement the concept of a thread usable
73 * with PIOS_INCLUDE_FREERTOS.
75 * see FreeRTOS documentation for details: http://www.freertos.org/a00019.html
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
);
79 void PIOS_Thread_Delete(struct pios_thread
*threadp
);
80 uint32_t PIOS_Thread_Systime(void);
81 void PIOS_Thread_Sleep(uint32_t time_ms
);
82 void PIOS_Thread_Sleep_Until(uint32_t *previous_ms
, uint32_t increment_ms
);
83 uint32_t PIOS_Thread_Get_Stack_Usage(struct pios_thread
*threadp
);
84 uint32_t PIOS_Thread_Get_Runtime(struct pios_thread
*threadp
);
85 void PIOS_Thread_Scheduler_Suspend(void);
86 void PIOS_Thread_Scheduler_Resume(void);
88 #endif /* PIOS_THREAD_H_ */