drivers/timers_xeno/timers_xeno.c
author edouard
Sat, 13 Nov 2010 00:03:24 +0100
changeset 631 08b6b903f84a
parent 468 787a54d068d6
child 797 12340b4ea907
permissions -rw-r--r--
Piotr Trojanek (ptroja) cleanup patche. Thanks.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
#include <stdlib.h>
47
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents: 35
diff changeset
     2
#include <unistd.h>
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents: 35
diff changeset
     3
#include <sys/mman.h>
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
#include <native/task.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
#include <native/timer.h>
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
     7
#include <native/sem.h>
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
#include <native/mutex.h>
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
     9
#include <native/cond.h>
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
#include <native/alarm.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
#include "applicfg.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
#include "can_driver.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
#include "timer.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
#define TIMERLOOP_TASK_CREATED        1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    18
TimerCallback_t exitall;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    19
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    20
RT_MUTEX condition_mutex;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    21
RT_SEM CanFestival_mutex;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    22
RT_SEM control_task; 
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    23
RT_COND timer_set;	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
RT_TASK timerloop_task;
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    25
 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
RTIME last_time_read;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
RTIME last_occured_alarm;
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    28
RTIME last_timeout_set;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    29
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    30
int stop_timer = 0;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    31
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    32
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    33
 * Init Mutex, Semaphores and Condition variable
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    34
 */
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    35
void TimerInit(void)
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    36
{
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    37
  	int ret = 0;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    38
  	char taskname[32];
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    39
459
ddd1a31b7960 - remove mlockall in timerloop
greg
parents: 457
diff changeset
    40
	// lock process in to RAM
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    41
  	mlockall(MCL_CURRENT | MCL_FUTURE);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    42
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    43
  	snprintf(taskname, sizeof(taskname), "S1-%d", getpid());
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    44
	rt_sem_create(&CanFestival_mutex, taskname, 1, S_FIFO);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    45
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    46
  	snprintf(taskname, sizeof(taskname), "S2-%d", getpid());
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    47
  	rt_sem_create(&control_task, taskname, 0, S_FIFO);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    48
  	  	
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    49
  	snprintf(taskname, sizeof(taskname), "M1-%d", getpid());
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    50
  	rt_mutex_create(&condition_mutex, taskname);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    51
  	
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    52
  	snprintf(taskname, sizeof(taskname), "C1-%d", getpid());
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    53
  	rt_cond_create(&timer_set, taskname);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    54
}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    55
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    56
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    57
 * Stop Timer Task
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    58
 * @param exitfunction
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    59
 */
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    60
void StopTimerLoop(TimerCallback_t exitfunction)
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    61
{
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    62
	exitall = exitfunction;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    63
	stop_timer = 1;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    64
	rt_cond_signal(&timer_set);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    65
}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
void cleanup_all(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
{
463
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
    69
	if (rt_task_join(&timerloop_task) != 0){
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
    70
		printf("Failed to join with Timerloop task\n");
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
    71
	}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
	rt_task_delete(&timerloop_task);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
}
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    74
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    75
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    76
 * Clean all Semaphores, mutex, condition variable and main task
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    77
 */
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    78
void TimerCleanup(void)
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    79
{
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    80
	rt_sem_delete(&CanFestival_mutex);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    81
	rt_mutex_delete(&condition_mutex);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    82
	rt_cond_delete(&timer_set);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    83
	rt_sem_delete(&control_task);
463
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
    84
	if (rt_task_join(&timerloop_task) != 0){
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
    85
		printf("Failed to join with Timerloop task\n");
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
    86
	}
459
ddd1a31b7960 - remove mlockall in timerloop
greg
parents: 457
diff changeset
    87
	rt_task_delete(&timerloop_task);
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    88
}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    89
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    90
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    91
 * Take a semaphore
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    92
 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
void EnterMutex(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
{
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    95
	rt_sem_p(&CanFestival_mutex, TM_INFINITE);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    96
}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    97
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    98
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
    99
 * Signaling a semaphore
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   100
 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
void LeaveMutex(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
{
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   103
	rt_sem_v(&CanFestival_mutex);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   104
}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   105
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   106
static TimerCallback_t init_callback;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   107
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   108
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   109
 * Timer Task
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   110
 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
void timerloop_task_proc(void *arg)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
{
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   113
	int ret = 0;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   114
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   115
	getElapsedTime();
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   116
	last_timeout_set = 0;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   117
	last_occured_alarm = last_time_read;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   118
	
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   119
	/* trigger first alarm */
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   120
	SetAlarm(NULL, 0, init_callback, 0, 0);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   121
	RTIME current_time;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   122
	RTIME real_alarm;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
	do{
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   124
		
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   125
		rt_mutex_acquire(&condition_mutex, TM_INFINITE);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   126
		if(last_timeout_set == TIMEVAL_MAX)
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   127
		{
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   128
			ret = rt_cond_wait(
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   129
				&timer_set,
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   130
				&condition_mutex,
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   131
				TM_INFINITE
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   132
				);		/* Then sleep until next message*/
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   133
			rt_mutex_release(&condition_mutex);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   134
		}else{
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   135
			current_time = rt_timer_read();
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   136
			real_alarm = last_time_read + last_timeout_set;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   137
			ret = rt_cond_wait( /* sleep until next deadline */
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   138
				&timer_set,
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   139
				&condition_mutex,
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   140
				(real_alarm - current_time)); /* else alarm consider expired */   
457
ee7f0092bcb1 fix typo line 135
greg
parents: 454
diff changeset
   141
			if(ret == -ETIMEDOUT){
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   142
				last_occured_alarm = real_alarm;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   143
				rt_mutex_release(&condition_mutex);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   144
				EnterMutex();
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   145
				TimeDispatch();
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   146
				LeaveMutex();
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   147
			}else{ 
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   148
				rt_mutex_release(&condition_mutex);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   149
			}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   150
		}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   151
	}while ((ret == 0 || ret == -EINTR || ret == -ETIMEDOUT) && !stop_timer);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   152
	
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   153
	if(exitall){
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   154
		EnterMutex();
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   155
		exitall(NULL,0);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   156
		LeaveMutex();
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   157
	}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   158
}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   159
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   160
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   161
 * Create the Timer Task
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   162
 * @param _init_callback
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   163
 */
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   164
void StartTimerLoop(TimerCallback_t _init_callback)
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   165
{
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   166
	int ret = 0;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   167
	stop_timer = 0;	
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   168
	init_callback = _init_callback;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   169
	
47
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents: 35
diff changeset
   170
	char taskname[32];
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents: 35
diff changeset
   171
	snprintf(taskname, sizeof(taskname), "timerloop-%d", getpid());
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   173
	/* create timerloop_task */
463
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
   174
	ret = rt_task_create(&timerloop_task, taskname, 0, 50, T_JOINABLE);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
	if (ret) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
		printf("Failed to create timerloop_task, code %d\n",errno);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
		return;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
 	
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   180
	/* start timerloop_task */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
	ret = rt_task_start(&timerloop_task,&timerloop_task_proc,NULL);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
	if (ret) {
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   183
		printf("Failed to start timerloop_task, code %u\n",errno);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
		goto error;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
	
33
c767eabbaaac Fixed some bugs with Xenomai and CAN/peak
etisserant
parents: 32
diff changeset
   187
	return;
c767eabbaaac Fixed some bugs with Xenomai and CAN/peak
etisserant
parents: 32
diff changeset
   188
	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
error:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
	cleanup_all();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   193
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   194
 * Create the CAN Receiver Task
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   195
 * @param fd0 CAN port
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   196
 * @param *ReceiveLoop_task CAN receiver task
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   197
 * @param *ReceiveLoop_task_proc CAN receiver function
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   198
 */
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 47
diff changeset
   199
void CreateReceiveTask(CAN_PORT fd0, TASK_HANDLE *ReceiveLoop_task, void* ReceiveLoop_task_proc)
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   200
{	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
	int ret;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
	static int id = 0;
47
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents: 35
diff changeset
   203
	char taskname[32];
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents: 35
diff changeset
   204
	snprintf(taskname, sizeof(taskname), "canloop%d-%d", id, getpid());
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
	id++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   207
	/* create ReceiveLoop_task */
463
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
   208
	ret = rt_task_create(ReceiveLoop_task,taskname,0,50,T_JOINABLE);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
	if (ret) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
		printf("Failed to create ReceiveLoop_task number %d, code %d\n", id, errno);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
		return;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
	}
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   213
	/* start ReceiveLoop_task */
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   214
	ret = rt_task_start(ReceiveLoop_task, ReceiveLoop_task_proc,(void*)fd0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
	if (ret) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
		printf("Failed to start ReceiveLoop_task number %d, code %d\n", id, errno);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
		return;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
	}
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   219
	rt_sem_v(&control_task);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   220
}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   221
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   222
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   223
 * Wait for the CAN Receiver Task end
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   224
 * @param *ReceiveLoop_task CAN receiver thread
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   225
 */
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   226
void WaitReceiveTaskEnd(TASK_HANDLE *ReceiveLoop_task)
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   227
{
463
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
   228
	if (rt_task_join(ReceiveLoop_task) != 0){
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
   229
		printf("Failed to join with Receive task\n");
f7455fef585f add rt_task_join for receive task and timerloop task
greg
parents: 459
diff changeset
   230
	}
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   231
	rt_task_delete(ReceiveLoop_task);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   232
}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   233
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   234
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   235
 * Set timer for the next wakeup
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   236
 * @param value
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   237
 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
void setTimer(TIMEVAL value)
47
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents: 35
diff changeset
   239
{
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   240
	rt_mutex_acquire(&condition_mutex, TM_INFINITE);
468
787a54d068d6 Fixed minor typos in timers_rtai.c and timers_xeno.c
etisserant
parents: 463
diff changeset
   241
	last_timeout_set = value;
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   242
	rt_mutex_release(&condition_mutex);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   243
	rt_cond_signal(&timer_set);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   244
}
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   245
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   246
/**
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   247
 * Get the elapsed time since the last alarm
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   248
 * @return a time in nanoseconds
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   249
 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
TIMEVAL getElapsedTime(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
{
454
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   252
	RTIME res;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   253
	rt_mutex_acquire(&condition_mutex, TM_INFINITE);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   254
	last_time_read = rt_timer_read();
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   255
	res = last_time_read - last_occured_alarm;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   256
	rt_mutex_release(&condition_mutex);
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   257
	return res;
bc000083297a - add RTAI support
greg
parents: 170
diff changeset
   258
}