-- ------------------------------------------------------------------- | Bernhard Kuhn (kuhn[at]lpr.ei.tum.de) O|||OO||OO| | | Laboratory for Process Control and Real-Time Systems O|||O|O|O|O | | Technische Universität München Tel.+49-89-289-23732 O|||OO||OO| | | 80290 München, Germany Room 3944 Fax -23555 OOO|O|||O|O | --------------------------------------------------------------------
Kay-Ulrich Scholl wrote: > I created a periodic task but the period-time changes > from time to time. > The tak decides on his own when he wants to be recalled again. > At the moment I do this in the following way: > > RTIME wait=last_send+wait_time-rt_get_time()-CAN_SEND_PERIOD; > // should I wait longer than CAN_SEND_PERIOD ? > if (wait>0) > { > long flags; > r_save_flags(flags); > r_cli(); > // wait a litle bit longer next time: > can_send_task.resume_time=rt_get_time()+wait; > r_restore_flags(flags); > } > rt_task_wait(); > > Is there a better way ? you may use int rt_task_make_periodic(RT_TASK *task, RTIME start_time, RTIME period) since that code is similar to yours (/usr/src/linux/kernel/rt_prio_sched.c): int rt_task_make_periodic(RT_TASK *task, RTIME start_time, RTIME period) { long flags; if (task->magic != RT_TASK_MAGIC) { return -EINVAL; } r_save_flags(flags); r_cli(); task->resume_time = start_time; task->period = period; task->state = RT_TASK_DELAYED; r_restore_flags(flags); rt_schedule(); return 0; } But you may also write write can_send_task.resume_time=rt_get_time()+wait; rt_task_wait(); since rt_task_wait() will reschedule anyway (/usr/src/linux/kernel/rt_prio_sched.c): int rt_task_wait(void) { long flags; r_save_flags(flags); r_cli(); rt_current->state = RT_TASK_DELAYED; rt_current->resume_time += rt_current->period; rt_schedule(); r_restore_flags(flags); return 0; } -- ------------------------------------------------------------------- | Bernhard Kuhn (kuhn[at]lpr.ei.tum.de) O|||OO||OO| | | Laboratory for Process Control and Real-Time Systems O|||O|O|O|O | | Technische Universität München Tel.+49-89-289-23732 O|||OO||OO| | | 80290 München, Germany Room 3944 Fax -23555 OOO|O|||O|O | --------------------------------------------------------------------