Merge pull request #51 from mehlis/vtimer

use out parameter for vtimer_now
dev/timer
Oleg 10 years ago
commit c70426b57b

@ -102,22 +102,26 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
// Calculate collisions per second
if (collision_state == COLLISION_STATE_INITIAL) {
timex_t now = vtimer_now();
timex_t now;
vtimer_now(&now);
collision_measurement_start = now.microseconds;
collision_count = 0;
collisions_per_sec = 0;
collision_state = COLLISION_STATE_MEASURE;
} else if (collision_state == COLLISION_STATE_MEASURE) {
timex_t now = vtimer_now();
timex_t now;
vtimer_now(&now);
uint64_t timespan = now.microseconds - collision_measurement_start;
if (timespan > 1000000) {
collisions_per_sec = (collision_count * 1000000) / (double) timespan;
if (collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) {
timex_t now = vtimer_now();
timex_t now;
vtimer_now(&now);
collision_measurement_start = now.microseconds;
collision_state = COLLISION_STATE_KEEP;
} else if (collisions_per_sec > 2.2) {
timex_t now = vtimer_now();
timex_t now;
vtimer_now(&now);
collision_measurement_start = now.microseconds;
collision_state = COLLISION_STATE_KEEP;
} else {
@ -125,7 +129,8 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
}
}
} else if (collision_state == COLLISION_STATE_KEEP) {
timex_t now = vtimer_now();
timex_t now;
vtimer_now(&now);
uint64_t timespan = now.microseconds - collision_measurement_start;
if (timespan > 5000000) {
collision_state = COLLISION_STATE_INITIAL;

@ -375,7 +375,8 @@ static bool contains_seq_entry(uint8_t src, uint8_t id)
{
int i;
uint32_t cmp;
timex_t now_timex = vtimer_now();
timex_t now_timex;
vtimer_now(&now_timex);
uint64_t now = now_timex.microseconds;
for (i = 0; i < MAX_SEQ_BUFFER_SIZE; i++)
@ -414,7 +415,8 @@ static void add_seq_entry(uint8_t src, uint8_t id)
// Add new entry
seq_buffer[seq_buffer_pos].source = src;
seq_buffer[seq_buffer_pos].identification = id;
timex_t now = vtimer_now();
timex_t now;
vtimer_now(&now);
seq_buffer[seq_buffer_pos].m_ticks = now.microseconds;
// Store 16 bit sequence number of layer 0 for speedup

@ -43,7 +43,7 @@ typedef struct vtimer_t {
* @brief Current system time
* @return Time as timex_t since system boot
*/
timex_t vtimer_now(void);
void vtimer_now(timex_t* out);
/**
* @brief Initializes the vtimer subsystem. To be called once at system initialization. Will be initialized by auto_init.

@ -27,7 +27,9 @@ void init_transport_layer(void)
set_udp_packet_handler_pid(udp_thread_pid);
// TCP
srand(vtimer_now().microseconds);
timex_t now;
vtimer_now(&now);
srand(now.microseconds);
#ifdef TCP_HC
printf("TCP_HC enabled!\n");
global_context_counter = rand();

@ -74,9 +74,11 @@ void print_tcp_flags (tcp_hdr_t *tcp_header)
void print_tcp_cb(tcp_cb_t *cb)
{
timex_t now;
vtimer_now(&now);
printf("Send_ISS: %lu\nSend_UNA: %lu\nSend_NXT: %lu\nSend_WND: %u\n", cb->send_iss, cb->send_una, cb->send_nxt, cb->send_wnd);
printf("Rcv_IRS: %lu\nRcv_NXT: %lu\nRcv_WND: %u\n", cb->rcv_irs, cb->rcv_nxt, cb->rcv_wnd);
printf("Time difference: %lu, No_of_retries: %u, State: %u\n\n", timex_sub(vtimer_now(), cb->last_packet_time).microseconds, cb->no_of_retries, cb->state);
printf("Time difference: %lu, No_of_retries: %u, State: %u\n\n", timex_sub(now, cb->last_packet_time).microseconds, cb->no_of_retries, cb->state);
}
void print_tcp_status(int in_or_out, ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socket_t *tcp_socket)
@ -497,7 +499,9 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
set_tcp_cb(&current_tcp_socket->tcp_control, 0, STATIC_WINDOW, current_tcp_socket->tcp_control.send_iss, current_tcp_socket->tcp_control.send_iss, 0);
// Remember current time
current_tcp_socket->tcp_control.last_packet_time = vtimer_now();
timex_t now;
vtimer_now(&now);
current_tcp_socket->tcp_control.last_packet_time = now;
current_tcp_socket->tcp_control.no_of_retries = 0;
msg_from_server.type = TCP_RETRY;
@ -554,7 +558,9 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
msg_from_server.type = UNDEFINED;
// Remember current time
current_tcp_socket->tcp_control.last_packet_time = vtimer_now();
timex_t now;
vtimer_now(&now)
current_tcp_socket->tcp_control.last_packet_time = now;
current_tcp_socket->tcp_control.no_of_retries = 0;
#ifdef TCP_HC
@ -1113,7 +1119,9 @@ int handle_new_tcp_connection(socket_internal_t *current_queued_int_socket, sock
&server_socket->socket_values.tcp_control.tcp_context.context_id, sizeof(server_socket->socket_values.tcp_control.tcp_context.context_id));
#endif
// Remember current time
current_queued_int_socket->socket_values.tcp_control.last_packet_time = vtimer_now();
timex_t now;
vtimer_now(&now);
current_queued_int_socket->socket_values.tcp_control.last_packet_time = now;
current_queued_int_socket->socket_values.tcp_control.no_of_retries = 0;

@ -23,8 +23,10 @@ void handle_synchro_timeout(socket_internal_t *current_socket)
msg_t send;
if (thread_getstatus(current_socket->recv_pid) == STATUS_RECEIVE_BLOCKED)
{
timex_t now;
vtimer_now(&now);
if ((current_socket->socket_values.tcp_control.no_of_retries == 0) &&
(timex_sub(vtimer_now(), current_socket->socket_values.tcp_control.last_packet_time).microseconds >
(timex_sub(now, current_socket->socket_values.tcp_control.last_packet_time).microseconds >
TCP_SYN_INITIAL_TIMEOUT))
{
current_socket->socket_values.tcp_control.no_of_retries++;
@ -32,7 +34,7 @@ void handle_synchro_timeout(socket_internal_t *current_socket)
// printf("FIRST RETRY!\n");
}
else if ((current_socket->socket_values.tcp_control.no_of_retries > 0) &&
(timex_sub(vtimer_now(), current_socket->socket_values.tcp_control.last_packet_time).microseconds >
(timex_sub(now, current_socket->socket_values.tcp_control.last_packet_time).microseconds >
(current_socket->socket_values.tcp_control.no_of_retries * TCP_SYN_TIMEOUT + TCP_SYN_INITIAL_TIMEOUT)))
{
current_socket->socket_values.tcp_control.no_of_retries++;
@ -66,20 +68,22 @@ void handle_established(socket_internal_t *current_socket)
{
current_timeout *= 2;
}
timex_t now;
vtimer_now(&now);
if (current_timeout > TCP_ACK_MAX_TIMEOUT)
{
net_msg_send(&send, current_socket->send_pid, 0, TCP_TIMEOUT);
// printf("GOT NO ACK: TIMEOUT!\n");
}
else if (timex_sub(vtimer_now(), current_socket->socket_values.tcp_control.last_packet_time).microseconds >
else if (timex_sub(now, current_socket->socket_values.tcp_control.last_packet_time).microseconds >
current_timeout)
{
// printReasBuffers();
current_socket->socket_values.tcp_control.no_of_retries++;
net_msg_send(&send, current_socket->send_pid, 0, TCP_RETRY);
// printf("GOT NO ACK YET, %i. RETRY! Now: %lu Before: %lu, Diff: %lu, Cur Timeout: %f\n", current_socket->socket_values.tcp_control.no_of_retries,
// vtimer_now().microseconds, current_socket->socket_values.tcp_control.last_packet_time.microseconds,
// vtimer_now().microseconds - current_socket->socket_values.tcp_control.last_packet_time.microseconds,
// now.microseconds, current_socket->socket_values.tcp_control.last_packet_time.microseconds,
// now.microseconds - current_socket->socket_values.tcp_control.last_packet_time.microseconds,
// current_timeout);
}
}

@ -211,7 +211,8 @@ void ipv6_iface_add_addr(ipv6_addr_t *addr, uint8_t state, uint32_t val_ltime, u
iface.addr_list[iface_addr_list_count].state = state;
timex_t valtime = {val_ltime, 0};
timex_t preftime = {pref_ltime, 0};
timex_t now = vtimer_now();
timex_t now;
vtimer_now(&now);
iface.addr_list[iface_addr_list_count].val_ltime = timex_add(now, valtime);
iface.addr_list[iface_addr_list_count].pref_ltime = timex_add(now, preftime);
iface.addr_list[iface_addr_list_count].type = type;
@ -451,7 +452,8 @@ uint8_t ipv6_next_hdr_unknown(uint8_t next_hdr) {
uint32_t get_remaining_time(timex_t *t){
timex_t now = vtimer_now();
timex_t now;
vtimer_now(&now);
return (timex_sub(*t, now).seconds);
}
@ -459,7 +461,9 @@ uint32_t get_remaining_time(timex_t *t){
void set_remaining_time(timex_t *t, uint32_t time){
timex_t tmp = {time, 0};
*t = timex_add(vtimer_now(), tmp);
timex_t now;
vtimer_now(&now)
*t = timex_add(now, tmp);
}
void ipv6_init_iface_as_router(void) {

@ -1154,7 +1154,8 @@ void def_rtr_lst_add(ipv6_addr_t *ipaddr, uint32_t rtr_ltime){
} else {
memcpy(&(def_rtr_lst[def_rtr_count].addr), ipaddr, 16);
timex_t rltime = {rtr_ltime, 0};
timex_t now = vtimer_now();
timex_t now;
vtimer_now(&now);
def_rtr_lst[def_rtr_count].inval_time = timex_add(now, rltime);

@ -298,7 +298,10 @@ lowpan_reas_buf_t *new_packet_buffer(uint16_t datagram_size, uint16_t datagram_t
new_buf->ident_no = datagram_tag;
new_buf->packet_size = datagram_size;
new_buf->timestamp = vtimer_now().microseconds;
timex_t now;
vtimer_now(&now)
new_buf->timestamp = now.microseconds;
if ((current_buf == NULL) && (temp_buf == NULL))
{
@ -334,7 +337,9 @@ lowpan_reas_buf_t *get_packet_frag_buf(uint16_t datagram_size, uint16_t datagram
current_buf->interval_list_head != NULL)
{
/* Found buffer for current packet fragment */
current_buf->timestamp = vtimer_now().microseconds;
timex_t now;
vtimer_now(&now);
current_buf->timestamp = now.microseconds;
return current_buf;
}
temp_buf = current_buf;
@ -526,7 +531,9 @@ void check_timeout(void)
long cur_time;
int count = 0;
cur_time = vtimer_now().microseconds;
timex_t now;
vtimer_now(&now)
cur_time = now.microseconds;
temp_buf = head;
while (temp_buf != NULL)

@ -49,7 +49,7 @@ void ping(radio_address_t addr, uint8_t channr){
cc1100_set_channel(channr);
cc1100_set_address(r_address);
while(1){
start = vtimer_now();
vtimer_now(&start);
int trans_ok = cc1100_send_csmaca(addr,
protocol_id,2,pipa->payload,sizeof(pipa->payload));
if(trans_ok < 0)
@ -59,7 +59,8 @@ void ping(radio_address_t addr, uint8_t channr){
}
void calc_rtt(void){
timex_t end = vtimer_now();
timex_t end;
vtimer_now(&end);
timex_t result = vtimer_sub(end, start);
rtt = result.seconds+(float)result.microseconds/100000;

@ -1,5 +1,6 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <irq.h>
#include <queue.h>
#include <timex.h>
@ -146,7 +147,9 @@ void normalize_to_tick(timex_t *time) {
static int vtimer_set(vtimer_t *timer) {
DEBUG("vtimer_set(): New timer. Offset: %lu %lu\n", timer->absolute.seconds, timer->absolute.microseconds);
timer->absolute = timex_add(vtimer_now(), timer->absolute);
timex_t now;
vtimer_now(&now);
timer->absolute = timex_add(now, timer->absolute);
normalize_to_tick(&(timer->absolute));
DEBUG("vtimer_set(): Absolute: %lu %lu\n", timer->absolute.seconds, timer->absolute.microseconds);
@ -184,10 +187,9 @@ static int vtimer_set(vtimer_t *timer) {
return result;
}
/* TODO: Do NOT return a struct! */
timex_t vtimer_now() {
void vtimer_now(timex_t* out) {
timex_t t = timex_set(seconds, hwtimer_now()-longterm_tick_start);
return t;
memcpy(out, &t, sizeof(timex_t));
}
int vtimer_init() {

Loading…
Cancel
Save