Commit e3328f1f authored by Franksen, Benjamin's avatar Franksen, Benjamin
Browse files

vcan driver: better timestamp reporting

parent 2c91f2e0
......@@ -711,6 +711,7 @@ typedef struct
and ci_timestamp */
typedef enum
{
CI_TIMESTAMP_INVALID =-1, /* timestamp invalid (couldn't be read) */
CI_TIMESTAMP_EMPTY = 0, /* no timestamp (initial value) */
CI_TIMESTAMP_REQUEST = 1, /* timestamp set by request */
CI_TIMESTAMP_RESPONSE = 2 /* timestamp set by irq handler */
......@@ -1557,6 +1558,13 @@ static ci_errcodes check_timeout_val(int timeout)
static byte copy_time(unsigned long long *dest, byte *mode, ci_user_part *up);
static void msg_set_zero_timestamp(ci_message *msg)
{
msg->timestamp= 0;
msg->timestamp_mode= CI_TIMESTAMP_INVALID;
msg->timestamp_irq_cnt= 0;
}
static void msg_copy_timestamp(ci_message *msg, ci_user_part *up)
{
/* if use part pointer is NULL we cannot do anything: */
......@@ -2199,6 +2207,7 @@ BSTATIC void ci_readnow(int tid, ci_message *msg, void *gl)
/* initial settings of stat and errcode: */
msg->stat = CI_OK;
msg->errcode= CI_NO_ERROR;
msg_set_zero_timestamp(msg);
/* check tid, id and port : */
if (!mcheck_tid(tid, msg))
......@@ -2241,7 +2250,10 @@ BSTATIC void ci_readnow(int tid, ci_message *msg, void *gl)
/*@@@*/printf("[%d] S:%xh\n",__LINE__,stat);
#endif
if (!check_status(stat, TRUE, FALSE, FALSE, msg, __LINE__))
return;
{
msg_copy_timestamp(msg, up);
return;
}
/* big-endian conversion of the length of the CAN object: */
datalength= CAN_LEN_MASK & BE_GET_SHORT(&(data.length));
......@@ -2280,6 +2292,7 @@ BSTATIC void ci_read(int tid, ci_message *msg,void *gl)
/* initial settings of stat and errcode: */
msg->stat = CI_OK;
msg->errcode= CI_NO_ERROR;
msg_set_zero_timestamp(msg);
/* check tid, id and port : */
if (!mcheck_tid(tid, msg))
......@@ -2332,7 +2345,10 @@ BSTATIC void ci_read(int tid, ci_message *msg,void *gl)
/* check the status-field of the data */
if (!check_status(stat, was_handled, FALSE, FALSE, msg, __LINE__))
return;
{
msg_copy_timestamp(msg, up);
return;
}
/* the data is copied regardless wether there was a timeout or not */
/* return the message-index (this has been calculated before) */
......@@ -2369,6 +2385,7 @@ BSTATIC void ci_send_rtr(int tid, ci_message *msg, void *gl)
/* initial settings of stat and errcode: */
msg->stat = CI_OK;
msg->errcode= CI_NO_ERROR;
msg_set_zero_timestamp(msg);
/* check tid, id and port : */
if (!mcheck_tid(tid, msg))
......@@ -2527,9 +2544,10 @@ static void ci_iget_rtr(int tid, ci_message *msg, void *gl, boolean may_wait)
/* check the status-field of the data */
if (!check_status(stat, was_handled, FALSE, TRUE, msg, __LINE__))
{ /* reset the INUSE-Flag before returning: */
return;
};
{
msg_copy_timestamp(msg, up);
return;
}
/* return the message-index */
msg->counter= icnt;
......@@ -2588,6 +2606,7 @@ BSTATIC void ci_queue_readnow(int tid, ci_message *msg, void *gl)
/* initial settings of stat and errcode: */
msg->stat = CI_OK;
msg->errcode= CI_NO_ERROR;
msg_set_zero_timestamp(msg);
/* check tid: */
if (!mcheck_id(tid, msg))
......@@ -2651,6 +2670,7 @@ BSTATIC void ci_queue_read(int tid, ci_message *msg, void *gl)
/* initial settings of stat and errcode: */
msg->stat = CI_OK;
msg->errcode= CI_NO_ERROR;
msg_set_zero_timestamp(msg);
/* check tid: */
if (!mcheck_id(tid, msg))
......@@ -2720,6 +2740,7 @@ BSTATIC void ci_write(int tid, ci_message *msg, void *gl)
/* initial settings of stat and errcode: */
msg->stat = CI_OK;
msg->errcode= CI_NO_ERROR;
msg_set_zero_timestamp(msg);
/* check tid, id and port : */
if (!mcheck_tid(tid, msg))
......@@ -2848,6 +2869,7 @@ BSTATIC void ci_writelater(int tid, ci_message *msg, void *gl)
/* initial settings of stat and errcode: */
msg->stat = CI_OK;
msg->errcode= CI_NO_ERROR;
msg_set_zero_timestamp(msg);
/* check tid, id and port : */
if (!mcheck_tid(tid, msg))
......@@ -2891,6 +2913,7 @@ BSTATIC void ci_writelater(int tid, ci_message *msg, void *gl)
{
msg->stat |= CI_WAIT; /* return a CI_WAIT - status, timeval remains
unchanged */
msg_copy_timestamp(msg, up);
eieio;
return;
}
......@@ -2969,6 +2992,7 @@ BSTATIC void ci_writetimed(int tid, ci_message *msg, unsigned long *timeval,
/* initial settings of stat and errcode: */
msg->stat = CI_OK;
msg->errcode= CI_NO_ERROR;
msg_set_zero_timestamp(msg);
/* check tid, id and port : */
if (!mcheck_tid(tid, msg))
......@@ -3018,6 +3042,7 @@ BSTATIC void ci_writetimed(int tid, ci_message *msg, unsigned long *timeval,
{
msg->stat |= CI_WAIT; /* return a CI_WAIT - status, timeval remains
unchanged */
msg_copy_timestamp(msg, up);
eieio;
return;
}
......@@ -3049,6 +3074,7 @@ BSTATIC void ci_writetimed(int tid, ci_message *msg, unsigned long *timeval,
break;
case CI_TIMESTAMP_REQUEST:
msg->stat |= CI_WAIT;
msg_copy_timestamp(msg, up);
return;
case CI_TIMESTAMP_RESPONSE:
/* calc passed time since last CAN-write */
......@@ -3059,6 +3085,7 @@ BSTATIC void ci_writetimed(int tid, ci_message *msg, unsigned long *timeval,
msg->stat |= CI_WAIT; /* return a CI_WAIT - status,
timeval is now
the time that has to be wait */
msg_copy_timestamp(msg, up);
return;
};
break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment