#include <signal.h>
#include "applicfg.h"
-#include "can_driver.h"
#include "timer.h"
pthread_mutex_t CanFestival_mutex = PTHREAD_MUTEX_INITIALIZER;
timer_t timer;
+void TimerCleanup(void)
+{
+ /* only used in realtime apps */
+}
+
void EnterMutex(void)
{
pthread_mutex_lock(&CanFestival_mutex);
pthread_mutex_unlock(&CanFestival_mutex);
}
-void timer_notify(int val)
+void timer_notify(sigval_t val)
{
gettimeofday(&last_sig,NULL);
EnterMutex();
// printf("getCurrentTime() return=%u\n", p.tv_usec);
}
-void initTimer(void)
+void TimerInit(void)
{
struct sigevent sigev;
timer_create (CLOCK_REALTIME, &sigev, &timer);
}
-void StopTimerLoop(void)
+void StopTimerLoop(TimerCallback_t exitfunction)
{
+ EnterMutex();
timer_delete (timer);
+ exitfunction(NULL,0);
+ LeaveMutex();
}
void StartTimerLoop(TimerCallback_t init_callback)
{
- initTimer();
+ EnterMutex();
// At first, TimeDispatch will call init_callback.
SetAlarm(NULL, 0, init_callback, 0, 0);
+ LeaveMutex();
}
-void ReceiveLoop(void* arg)
+void canReceiveLoop_signal(int sig)
+{
+}
+/* We assume that ReceiveLoop_task_proc is always the same */
+static void (*unixtimer_ReceiveLoop_task_proc)(CAN_PORT) = NULL;
+
+/**
+ * Enter in realtime and start the CAN receiver loop
+ * @param port
+ */
+void unixtimer_canReceiveLoop(CAN_PORT port)
{
- canReceiveLoop((CAN_HANDLE)arg);
+
+ /*get signal*/
+ signal(SIGTERM, canReceiveLoop_signal);
+ unixtimer_ReceiveLoop_task_proc(port);
}
-void CreateReceiveTask(CAN_HANDLE fd0, TASK_HANDLE* Thread)
+void CreateReceiveTask(CAN_PORT port, TASK_HANDLE* Thread, void* ReceiveLoopPtr)
{
- pthread_create(Thread, NULL, (void *)&ReceiveLoop, (void*)fd0);
+ unixtimer_ReceiveLoop_task_proc = ReceiveLoopPtr;
+ pthread_create(Thread, NULL, unixtimer_canReceiveLoop, (void*)port);
}
void WaitReceiveTaskEnd(TASK_HANDLE *Thread)
pthread_join(*Thread, NULL);
}
-#define maxval(a,b) a>b?a:b
+#define maxval(a,b) ((a>b)?a:b)
void setTimer(TIMEVAL value)
{
// printf("setTimer(TIMEVAL value=%d)\n", value);