summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/cl/data_rate.h11
-rw-r--r--cesar/cl/src/data_rate.c46
-rw-r--r--cesar/cl/test/data_rate/override/mac/common/ntb.h21
-rw-r--r--cesar/cl/test/data_rate/src/data_rate_test.c132
-rw-r--r--[-rwxr-xr-x]cesar/cl/test/data_rate/test_1_ref.csv0
-rw-r--r--[-rwxr-xr-x]cesar/cl/test/data_rate/test_2_ref.csv5
-rw-r--r--[-rwxr-xr-x]cesar/cl/test/data_rate/test_3_ref.csv0
-rw-r--r--[-rwxr-xr-x]cesar/cl/test/data_rate/test_4_ref.csv0
-rw-r--r--cesar/mac/common/src/sta.c17
-rw-r--r--cesar/mac/common/sta.h3
10 files changed, 110 insertions, 125 deletions
diff --git a/cesar/cl/data_rate.h b/cesar/cl/data_rate.h
index bc7f30d74e..eff3ecc0dd 100644
--- a/cesar/cl/data_rate.h
+++ b/cesar/cl/data_rate.h
@@ -15,6 +15,11 @@
* This data rate info are shared between CP and CL.
*/
+/* This value in the data_rate field of the cl_data_rate_t
+ * structure indicate that the whole structure needs to be initialized.
+ */
+#define CL_DATA_RATE_REQ_INIT 0xFFFFFFFF
+
/**
* Structure used to store data rate informations.
* It stores the data rate value the moment when
@@ -23,11 +28,11 @@
struct cl_data_rate_t
{
/** data rate value expressed in octets/sec. */
- u64 data_rate;
+ u32 data_rate;
/** time (in ecos clock ticks 10ms) when the value was calculated. */
- u64 ecos_time;
+ u64 time_rtc;
/** time (in phy clock ticks 40ns) when the value was calculated. */
- u32 phy_time;
+ u32 time_tck;
};
typedef struct cl_data_rate_t cl_data_rate_t;
diff --git a/cesar/cl/src/data_rate.c b/cesar/cl/src/data_rate.c
index 7a20064a91..ca4aaf2ece 100644
--- a/cesar/cl/src/data_rate.c
+++ b/cesar/cl/src/data_rate.c
@@ -22,55 +22,57 @@
void
data_rate_update_info (cl_data_rate_t *p_dr, uint data_size)
{
- static u32 phy_period = 0;
- static u64 ecos_period = 0;
- u64 new_ecos_time; /* in ecos tick (10ms so far) */
- u32 new_phy_time; /* in phy ticks (40ns so far) */
- u32 interval; /* delay between last time and now (in phy ticks) */
+ static u32 period_tck = 0;
+ static u64 period_rtc = 0;
+ u64 new_time_rtc; /* in ecos tick (10ms so far) */
+ u32 new_time_tck; /* in phy ticks (40ns so far) */
+ u32 interval_tck; /* delay between last time and now (in phy ticks) */
u64 new_rate; /* in octets per phy ticks */
/* This is the period (in ns) over which the data rate is evaluated */
- u64 data_rate_period = 1000000000LL;
+ u32 period_ns = 1000000000;
- if (!phy_period)
+ if (!period_tck)
{
/* evaluate the periods phy tick counts only once for all */
cyg_resolution_t res =
cyg_clock_get_resolution (cyg_real_time_clock ());
- ecos_period = div(res.divisor*data_rate_period, res.dividend);
- phy_period = div(data_rate_period, 40);
+ period_rtc = div(res.divisor * period_ns, res.dividend);
+ period_tck = div(period_ns, 40);
}
/* Get delay between last time data rate was evaluated and now */
- new_ecos_time = cyg_current_time();
- new_phy_time = mac_date ();
+ new_time_rtc = cyg_current_time ();
+ new_time_tck = mac_date ();
- if ((new_ecos_time - p_dr->ecos_time) > ecos_period)
+ if (((new_time_rtc - p_dr->time_rtc) > period_rtc)
+ || (p_dr->data_rate == CL_DATA_RATE_REQ_INIT))
{
- /* maximise the delay */
- interval = phy_period;
+ /* maximise the delay when the interval is larger than the period
+ * and when it's the first data for this data rate. */
+ interval_tck = period_tck;
}
else
{
/* mesure delay with phy time */
- interval = new_phy_time - p_dr->phy_time;
+ interval_tck = new_time_tck - p_dr->time_tck;
}
- if (interval >= phy_period)
+ if (interval_tck >= period_tck)
{
/* mesure the new rate over one period */
- new_rate = div(data_size , phy_period);
+ new_rate = data_size;
}
else
{
/* fine mesure of the delay with phy clock */
- new_rate = div(p_dr->data_rate * (phy_period - interval), phy_period)
- + data_size;
+ new_rate = (u64)(p_dr->data_rate) * (period_tck - interval_tck);
+ new_rate = div(new_rate, period_tck) + data_size;
}
/* update the data_rate structure */
- p_dr->data_rate = new_rate;
- p_dr->phy_time = new_phy_time;
- p_dr->ecos_time = new_ecos_time;
+ p_dr->data_rate = (u32)new_rate;
+ p_dr->time_tck = new_time_tck;
+ p_dr->time_rtc = new_time_rtc;
}
diff --git a/cesar/cl/test/data_rate/override/mac/common/ntb.h b/cesar/cl/test/data_rate/override/mac/common/ntb.h
deleted file mode 100644
index 509a7641dc..0000000000
--- a/cesar/cl/test/data_rate/override/mac/common/ntb.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef override_hal_phy_phy_h
-#define override_hal_phy_phy_h
-/* Cesar project {{{
- *
- * Copyright (C) 2009 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file cl/test/data_rate/override/hal/phy/phy.h
- * \brief override some hal api from "hal/phy/phy.h".
- * \ingroup cl
- *
- *
- */
-
-u32
-mac_date (void);
-
-#endif
diff --git a/cesar/cl/test/data_rate/src/data_rate_test.c b/cesar/cl/test/data_rate/src/data_rate_test.c
index 3b379713b2..5cc92b5a15 100644
--- a/cesar/cl/test/data_rate/src/data_rate_test.c
+++ b/cesar/cl/test/data_rate/src/data_rate_test.c
@@ -1,8 +1,14 @@
-/*
- * data_rate_test.c
+/* Cesar project {{{
+ *
+ * Copyright (C) 2009 Spidcom
*
- * Created on: 28 août 2009
- * Author: mercadie
+ * <<<Licence>>>
+ *
+ * }}} */
+ /**
+ * \file cl/src/data_rate.c
+ * \brief Data rate tests.
+ * \ingroup cl
*
* This test simulate data rate calculation
* the calculation is made using data contained in an array "sample"
@@ -10,7 +16,7 @@
* - the data quantity received/sent on interruption
* - the delay since last reception/emission
*
- * This test simulate a data rate requested every 10 ms independtly of
+ * This test simulate a data rate requested every 10 ms independently of
* the data reception/emission
* The main loop cycles with data rate requests.
* Between each request many rec/send interruptions may have occured.
@@ -31,18 +37,18 @@
#include <cyg/kernel/kapi.h>
#include "hal/phy/phy.h"
-#define SEQ_PERIOD (10000000LL/40) /* 10 ms expressed in phy ticks */
-#define AVERAGE_PERIOD (1000000000LL/40) /* 1 sec expressed in phy tics */
+#define SEQ_PERIOD_TCK (10000000LL/40) /* 10 ms expressed in phy ticks */
+#define AVERAGE_PERIOD_TCK (1000000000LL/40) /* 1 sec expressed in phy tics */
/*
* artificial phy date
*/
-u32 tick_time;
+u32 time_tck;
typedef struct
{
u32 data_size; /* in octets */
- u32 delta_time; /* in usec */
+ u32 delta_time_tck; /* in ticks */
}
sample_t;
@@ -72,11 +78,9 @@ cyg_current_time (void)
u32
mac_date (void)
{
- return tick_time;
+ return time_tck;
}
-/*
- * local functions
- */
+
#define div(a, b) ((a+((b)/2))/(b))
int
@@ -132,7 +136,7 @@ compare_files (char* file_in, char* file_ref)
* \param sample sample array
* \param max_samples max index for the array
* \param index index in the array where to start the burst
- * \param duration duration of the burst in msec
+ * \param duration duration of the burst in samples of 60 ticks
*/
int
make_burst (sample_t *sample, int max_samples, int index, int duration)
@@ -142,7 +146,7 @@ make_burst (sample_t *sample, int max_samples, int index, int duration)
for (i = index; (i < index+duration) && (i < max_samples); i++)
{
sample[i].data_size = 1580;
- sample[i].delta_time = 60;
+ sample[i].delta_time_tck = 60;
}
return i;
@@ -161,7 +165,7 @@ make_blank (sample_t *sample, int max_samples, int index, int duration)
if (index < max_samples)
{
sample[index].data_size = 0;
- sample[index].delta_time = time;
+ sample[index].delta_time_tck = time;
index++;
}
@@ -177,36 +181,38 @@ void
make_average_from_sample (sample_t *sample, FILE *chart)
{
/* data rate updated every time data is received */
- cl_data_rate_t cl_dr = {0, 0, 0};
+ cl_data_rate_t cl_dr;
/* data rate updated when data rate is requested */
- cl_data_rate_t req_dr = {0, 0, 0};
+ cl_data_rate_t req_dr;
int period_index;
int sample_index = 0;
- u32 seq_time = 0;
- u32 period_time;
+ u32 seq_time_tck = 0;
+ u32 period_time_tck;
- u64 total_data = 0;
- u64 seq_data;
- u64 period_data;
+ u32 seq_data;
+ u32 period_data;
- fprintf(chart,
- "time(ms),new data size(Mb),data rate(Mb/s),real rate(Mb/s)\n");
+ fprintf(chart,
+ "time(ms),new data size(Mb),data rate(Mb/s),real rate(Mb/s)\n");
- tick_time = seq_time;
+ time_tck = seq_time_tck;
+ cl_dr.data_rate = CL_DATA_RATE_REQ_INIT;
+ data_rate_update_info (&cl_dr, 0);
/* This loop simulate a DR request every 10ms */
do
{
- seq_time += SEQ_PERIOD;
+ seq_time_tck += SEQ_PERIOD_TCK;
seq_data = 0;
/* This loop simulate what happended since last data rate request */
- while (sample[sample_index].delta_time &&
- (cl_dr.phy_time + sample[sample_index].delta_time <= seq_time))
+ while (sample[sample_index].delta_time_tck &&
+ (cl_dr.time_tck + sample[sample_index].delta_time_tck
+ <= seq_time_tck))
{
- tick_time = cl_dr.phy_time + sample[sample_index].delta_time;
+ time_tck = cl_dr.time_tck + sample[sample_index].delta_time_tck;
data_rate_update_info(&cl_dr, sample[sample_index].data_size);
/* sum data size since last request */
@@ -215,35 +221,34 @@ make_average_from_sample (sample_t *sample, FILE *chart)
sample_index++;
}
- total_data += seq_data;
-
/* Update data rate with delay between last data and request */
req_dr = cl_dr;
- tick_time = seq_time;
+ time_tck = seq_time_tck;
data_rate_update_info (&req_dr, 0);
/* calculate real data quantity on last average period */
- period_time = seq_time - cl_dr.phy_time;
+ period_time_tck = seq_time_tck - cl_dr.time_tck;
period_data = 0;
if (sample_index) period_index = sample_index-1; else period_index = 0;
for (period_index = sample_index-1;
(period_index >= 0) &&
- (period_time + sample[period_index].delta_time) <= (AVERAGE_PERIOD);
+ (period_time_tck + sample[period_index].delta_time_tck)
+ <= (AVERAGE_PERIOD_TCK);
period_index--)
{
- period_time += sample [period_index].delta_time;
+ period_time_tck += sample [period_index].delta_time_tck;
period_data += sample [period_index].data_size;
}
/* Print the results to a file */
fprintf(chart, "%u,%u,%u,%u\n",
- (u32)div(seq_time*40, 1000000LL), /* timeline in ms */
- (u32)div(8*seq_data, 1000000LL), /* data since last req in Mb */
- (u32)div(8*req_dr.data_rate, 1000000LL), /* req dr in Mb/sec */
- (u32)div(8*period_data, 1000000LL)); /* exact data in last sec */
+ div(seq_time_tck*40, 1000000), /* timeline in ms */
+ div(8*seq_data, 1000000), /* data since last req in Mb */
+ div(8*req_dr.data_rate, 1000000), /* req dr in Mb/sec */
+ div(8*period_data, 1000000)); /* exact data in last sec */
}
- while(sample [sample_index].delta_time);
+ while(sample [sample_index].delta_time_tck);
}
int
@@ -251,6 +256,7 @@ main (int argc, char **argv)
{
FILE *f_in;
int i;
+ int result;
int nb_samples;
sample_t *sample_test;
test_t test;
@@ -269,26 +275,27 @@ main (int argc, char **argv)
test_case_begin (test, "Check max data");
test_begin (test, "Continuus data rate of 200Mb/s with max data")
{
- nb_samples = div (5*1000000000LL, 1518*40);
+ nb_samples = 5 * (div (1000000000, 1518*40));
sample_test = malloc(sizeof(sample_t) * (nb_samples+2));
for (i = 0; i < nb_samples; i++)
{
sample_test[i].data_size = 1518;
- sample_test[i].delta_time = 1518;
+ sample_test[i].delta_time_tck = 1518;
}
sample_test[nb_samples].data_size = 0;
- sample_test[nb_samples].delta_time = 5*1000000000LL/40;
+ sample_test[nb_samples].delta_time_tck = 5*1000000000LL/40;
sample_test[nb_samples+1].data_size = 0;
- sample_test[nb_samples+1].delta_time = 0;
+ sample_test[nb_samples+1].delta_time_tck = 0;
- f_in = fopen ("test_1.csv", "wr");
+ f_in = fopen ("obj/test_1.csv", "wr");
make_average_from_sample (sample_test, f_in);
fclose (f_in);
- test_fail_if (compare_files("test_1.csv", "test_1_ref.csv") != 0);
+ result = compare_files("obj/test_1.csv", "test_1_ref.csv");
+ test_fail_if (result != 0);
free(sample_test);
}
@@ -300,28 +307,29 @@ main (int argc, char **argv)
* (1 sec/40ns) / 416 666 = 60 ticks
*/
test_case_begin (test, "Check max rate");
- test_begin (test, "Continuus data rate of 200Mb/s with max data")
+ test_begin (test, "Continuus data rate of 200Mb/s with max freq")
{
- nb_samples = div (5*1000000000LL, 60*40); // 5 sec
+ nb_samples = 5 * (div (1000000000, 60*40)); // 5 sec
sample_test = malloc(sizeof(sample_t) * (nb_samples+2));
for (i = 0; i < nb_samples; i++)
{
sample_test[i].data_size = 60;
- sample_test[i].delta_time = 60;
+ sample_test[i].delta_time_tck = 60;
}
sample_test[nb_samples].data_size = 0;
- sample_test[nb_samples].delta_time = 5*1000000000LL/40; // 5 sec
+ sample_test[nb_samples].delta_time_tck = 5*1000000000LL/40; // 5 sec
sample_test[nb_samples+1].data_size = 0;
- sample_test[nb_samples+1].delta_time = 0;
+ sample_test[nb_samples+1].delta_time_tck = 0;
- f_in = fopen ("test_2.csv", "wr");
+ f_in = fopen ("obj/test_2.csv", "wr");
make_average_from_sample (sample_test, f_in);
fclose (f_in);
- test_fail_if (compare_files("test_2.csv", "test_2_ref.csv") != 0);
+ result = compare_files("obj/test_2.csv", "test_2_ref.csv");
+ test_fail_if (result != 0);
free(sample_test);
}
@@ -344,12 +352,13 @@ main (int argc, char **argv)
}
sample_test[i].data_size = 0;
- sample_test[i].delta_time = 0;
+ sample_test[i].delta_time_tck = 0;
- f_in = fopen ("test_3.csv", "wr");
+ f_in = fopen ("obj/test_3.csv", "wr");
make_average_from_sample (sample_test, f_in);
fclose (f_in);
- test_fail_if (compare_files("test_3.csv", "test_3_ref.csv") != 0);
+ result = compare_files("obj/test_3.csv", "test_3_ref.csv");
+ test_fail_if (result != 0);
free(sample_test);
}
@@ -403,22 +412,23 @@ main (int argc, char **argv)
if (i < nb_samples)
{
sample_test[i].data_size = 0;
- sample_test[i].delta_time = 0;
+ sample_test[i].delta_time_tck = 0;
}
else
{
nb_samples = 0;
sample_test[0].data_size = 0;
- sample_test[0].delta_time = 0;
+ sample_test[0].delta_time_tck = 0;
}
- f_in = fopen ("test_4.csv", "wr");
+ f_in = fopen ("obj/test_4.csv", "wr");
make_average_from_sample (sample_test, f_in);
fclose (f_in);
free(sample_test);
- test_fail_if (compare_files("test_4.csv", "test_4_ref.csv") != 0);
+ result = compare_files("obj/test_4.csv", "test_4_ref.csv");
+ test_fail_if (result != 0);
}
test_end;
diff --git a/cesar/cl/test/data_rate/test_1_ref.csv b/cesar/cl/test/data_rate/test_1_ref.csv
index bc64a11159..bc64a11159 100755..100644
--- a/cesar/cl/test/data_rate/test_1_ref.csv
+++ b/cesar/cl/test/data_rate/test_1_ref.csv
diff --git a/cesar/cl/test/data_rate/test_2_ref.csv b/cesar/cl/test/data_rate/test_2_ref.csv
index fbaf1b2394..b7eced57de 100755..100644
--- a/cesar/cl/test/data_rate/test_2_ref.csv
+++ b/cesar/cl/test/data_rate/test_2_ref.csv
@@ -508,7 +508,7 @@ time(ms),new data size(Mb),data rate(Mb/s),real rate(Mb/s)
775,0,184,186
785,0,182,184
795,0,180,182
-805,0,178,180
+805,0,179,180
815,0,177,178
825,0,175,176
835,0,173,174
@@ -568,7 +568,7 @@ time(ms),new data size(Mb),data rate(Mb/s),real rate(Mb/s)
1375,0,65,66
1385,0,63,64
1395,0,61,62
-1405,0,59,60
+1405,0,60,60
1415,0,58,58
1425,0,56,56
1435,0,54,54
@@ -999,3 +999,4 @@ time(ms),new data size(Mb),data rate(Mb/s),real rate(Mb/s)
1390,0,0,0
1400,0,0,0
1410,0,0,0
+1420,0,0,0
diff --git a/cesar/cl/test/data_rate/test_3_ref.csv b/cesar/cl/test/data_rate/test_3_ref.csv
index a641819b04..a641819b04 100755..100644
--- a/cesar/cl/test/data_rate/test_3_ref.csv
+++ b/cesar/cl/test/data_rate/test_3_ref.csv
diff --git a/cesar/cl/test/data_rate/test_4_ref.csv b/cesar/cl/test/data_rate/test_4_ref.csv
index 13853ea381..13853ea381 100755..100644
--- a/cesar/cl/test/data_rate/test_4_ref.csv
+++ b/cesar/cl/test/data_rate/test_4_ref.csv
diff --git a/cesar/mac/common/src/sta.c b/cesar/mac/common/src/sta.c
index 5ae07b1881..8eb4deb0df 100644
--- a/cesar/mac/common/src/sta.c
+++ b/cesar/mac/common/src/sta.c
@@ -19,19 +19,6 @@
#include <cyg/kernel/kapi.h>
#include "mac/common/ntb.h"
-/**
- * Initialize the data rate informations
- * \param p_dr pointer to the data rate structure.
- */
-void
-sta_data_rate_init (cl_data_rate_t* p_dr)
-{
- p_dr->data_rate = 0;
- p_dr->ecos_time = cyg_current_time ();
- p_dr->phy_time = mac_date ();
-}
-
-
void
sta_init (sta_t *sta, uint tei)
{
@@ -46,8 +33,8 @@ sta_init (sta_t *sta, uint tei)
sta->tx_tonemaps = tonemaps_alloc ();
sta->multi_unicast_receiver = true;
ce_rx_bitloading_init (&sta->ce_rx_bt);
- sta_data_rate_init (&sta->tx_data_rate);
- sta_data_rate_init (&sta->rx_data_rate);
+ sta->tx_data_rate->data_rate = CL_DATA_RATE_REQ_INIT;
+ sta->rx_data_rate->data_rate = CL_DATA_RATE_REQ_INIT;
}
diff --git a/cesar/mac/common/sta.h b/cesar/mac/common/sta.h
index 9aa321c674..b620bd6409 100644
--- a/cesar/mac/common/sta.h
+++ b/cesar/mac/common/sta.h
@@ -35,8 +35,9 @@ struct sta_t
bool multi_unicast_receiver;
/** Bit-loading state & data (CE/RX). */
ce_rx_bitloading_t ce_rx_bt;
- /** data rate */
+ /** Data rate for transmit from the local station to this one. */
cl_data_rate_t tx_data_rate;
+ /** Data rate for receive from this station to the local one. */
cl_data_rate_t rx_data_rate;
};
typedef struct sta_t sta_t;