39 #ifndef OS_FOSI_INTERNAL_HPP 40 #define OS_FOSI_INTERNAL_HPP 41 #define OROBLD_OS_LXRT_INTERNAL 47 #include "../fosi_internal_interface.hpp" 50 #include <sys/types.h> 51 #include "../../rtt-config.h" 56 #include "../../Logger.hpp" 64 if ( geteuid() != 0 ) {
65 std::cerr <<
"You are not root. This program requires that you are root." <<
std::endl;
69 #ifdef OROSEM_OS_LOCK_MEMORY 70 int locktype = MCL_CURRENT;
71 #ifdef OROSEM_OS_LOCK_MEMORY_FUTURE 72 locktype |= MCL_FUTURE;
75 int rv = mlockall(locktype);
77 perror(
"rtos_task_create_main: Could not lock memory using mlockall" );
89 unsigned long name = nam2num(
"main");
90 while ( rt_get_adr( name ) != 0 )
94 const char* tname =
"main";
95 main_task->
name = strcpy( (
char*)malloc( (strlen(tname) + 1) *
sizeof(
char)), tname);
97 if( !(main_task->
rtaitask = rt_task_init(name, 10,0,0)) )
99 std::cerr <<
"Cannot rt_task_init() MainThread." <<
std::endl;
103 struct sched_param param;
105 param.sched_priority = sched_get_priority_max(SCHED_OTHER);
106 if (param.sched_priority != -1 )
107 sched_setscheduler( 0, SCHED_OTHER, ¶m);
110 rt_task_use_fpu(main_task->
rtaitask, 1);
112 #ifdef OROSEM_OS_LXRT_PERIODIC 113 rt_set_periodic_mode();
114 start_rt_timer( nano2count(
NANO_TIME(ORODAT_OS_LXRT_PERIODIC_TICK*1000*1000*1000) ) );
118 rt_set_oneshot_mode();
120 #if defined(CONFIG_RTAI_VERSION_MINOR) && defined(CONFIG_RTAI_VERSION_MAJOR) 121 # if CONFIG_RTAI_VERSION_MAJOR == 3 && CONFIG_RTAI_VERSION_MINOR == 0 122 rt_preempt_always(1);
125 rt_preempt_always(1);
138 rt_task_delete(main_task->
rtaitask);
139 free(main_task->
name);
140 main_task->
name = NULL;
147 void *(*wrapper)(
void*);
160 void*(*wrapper)(
void*) = d->
wrapper;
163 if (!(task->
rtaitask = rt_task_init(tnum, priority, 0, 0))) {
164 std::cerr <<
"CANNOT INIT LXRT Thread " << task->
name <<
std::endl;
165 std::cerr <<
"Exiting this thread." <<
std::endl;
170 struct sched_param param;
171 param.sched_priority = sched_get_priority_max(SCHED_OTHER);
172 if (param.sched_priority != -1 )
173 sched_setscheduler( 0, SCHED_OTHER, ¶m);
179 rt_make_hard_real_time();
184 rt_make_soft_real_time();
194 unsigned cpu_affinity,
198 void * (*start_routine)(
void *),
202 if ( strlen(name) == 0 )
204 strncpy(taskName, name, 7);
205 unsigned long task_num = nam2num( taskName );
206 if ( rt_get_adr(nam2num( taskName )) != 0 ) {
207 unsigned long nname = nam2num( taskName );
208 while ( rt_get_adr( nname ) != 0 )
210 num2nam( nname, taskName);
216 task->
name = strcpy( (
char*)malloc( (strlen(name)+1)*
sizeof(
char) ), name);
231 int retv = pthread_create(&(task->
thread), 0,
235 while ( task->
rtaitask == 0 && ++timeout < 20)
237 return timeout < 20 ? retv : -1;
248 RT_TASK*
self = rt_buddy();
278 rt_make_hard_real_time();
280 rt_make_soft_real_time();
285 if ( rt_is_hard_real_time( t->
rtaitask ) )
294 if (rt_buddy() == mytask->
rtaitask) {
304 rt_task_suspend( mytask->
rtaitask );
309 rt_task_suspend( mytask->
rtaitask );
310 rt_task_make_periodic_relative_ns(mytask->
rtaitask, 0, nanosecs);
319 rt_set_period(mytask->
rtaitask, 0 );
321 rt_set_period(mytask->
rtaitask, nano2count( nanosecs ));
335 rt_task_wait_period();
340 if ( pthread_join((mytask->
thread),0) != 0 )
343 free( mytask->
name );
357 log(
Warning) <<
"Forcing priority ("<<*priority<<
") of thread to 0." <<
endlog();
361 if (*priority > 255){
362 log(
Warning) <<
"Forcing priority ("<<*priority<<
") of thread to 255." <<
endlog();
377 rv = rt_change_prio( mytask->
rtaitask, priority);
387 return t->
name ? t->
name :
"(destroyed)";
int rtos_task_is_self(const RTOS_TASK *task)
int rtos_task_get_priority(const RTOS_TASK *task)
INTERNAL_QUAL void rtos_task_make_periodic(RTOS_TASK *mytask, NANO_TIME nanosecs)
INTERNAL_QUAL void * rtai_thread_wrapper(void *arg)
unsigned int rtos_task_get_pid(const RTOS_TASK *task)
INTERNAL_QUAL int rtos_task_delete_main(RTOS_TASK *main_task)
int rtos_task_set_scheduler(RTOS_TASK *t, int sched_type)
int usleep(unsigned int us)
int rtos_task_set_cpu_affinity(RTOS_TASK *task, unsigned cpu_affinity)
unsigned rtos_task_get_cpu_affinity(const RTOS_TASK *task)
INTERNAL_QUAL int rtos_task_check_priority(int *scheduler, int *priority)
void *(* wrapper)(void *)
void rtos_task_set_wait_period_policy(RTOS_TASK *task, int policy)
void rtos_task_delete(RTOS_TASK *mytask)
INTERNAL_QUAL void rtos_task_yield(RTOS_TASK *)
int rtos_task_set_priority(RTOS_TASK *task, int priority)
static std::ostream & endl(std::ostream &__os)
const char * rtos_task_get_name(const RTOS_TASK *task)
int rtos_task_check_scheduler(int *sched_type)
basic_ostreams & endl(basic_ostreams &s)
int rtos_task_wait_period(RTOS_TASK *task)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
INTERNAL_QUAL int rtos_task_create_main(RTOS_TASK *main_task)
void rtos_task_set_period(RTOS_TASK *mytask, NANO_TIME nanosecs)
RTOS_RTAI_TASK * rtaitask
static Logger::LogFunction endlog()
INTERNAL_QUAL int rtos_task_create(RTOS_TASK *task, int priority, unsigned cpu_affinity, const char *name, int sched_type, size_t stack_size, void *(*start_routine)(void *), ThreadInterface *obj)
int rtos_task_get_scheduler(const RTOS_TASK *t)