summaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
authorlefranc2007-07-04 13:11:04 +0000
committerlefranc2007-07-04 13:11:04 +0000
commit5d4f887e342adb7bf578533772a7817ea2fc7913 (patch)
tree8f9fb8e07556f0a03b831b6cb95d6b2b3f887367 /host
parent1ef1f3bbd6caf7a0acb38b660760d214834aa578 (diff)
- added pointer to get netclock msg id into netclock_schedule() prototype
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@439 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'host')
-rw-r--r--host/netclock.h4
-rw-r--r--host/src/netclock.c9
-rw-r--r--host/src/station.c4
-rw-r--r--host/test/src/test_netclock.c26
4 files changed, 32 insertions, 11 deletions
diff --git a/host/netclock.h b/host/netclock.h
index b82e6e36f2..55a4c57ddb 100644
--- a/host/netclock.h
+++ b/host/netclock.h
@@ -89,6 +89,7 @@ int netclock_init(netclock_ctx_t *netclock, sci_ctx_t *sci);
* \param tick next tick to start the event
* \param function pointer to the callback function to process the received message
* \param data user data to be included into callback function as 'data' parameter
+ * \param id pointer filled with id used to create the netclock msg
* \return 0 if ok, -1 if failed with errno:
* - EINVAL if netclock or msg is null, or if tick < current_tick
* - ENOSPC if there is no more place to register a callback function
@@ -99,7 +100,8 @@ int netclock_schedule(
netclock_type_t type,
tick_t schedule_tick,
void (*callback_function)(void *data),
- void *callback_data);
+ void *callback_data,
+ netclock_id_t *id);
/**
* remove a scheduled netclock event
diff --git a/host/src/netclock.c b/host/src/netclock.c
index 7b0ae452e8..6b8fa13910 100644
--- a/host/src/netclock.c
+++ b/host/src/netclock.c
@@ -82,6 +82,7 @@ int netclock_init(netclock_ctx_t *netclock, sci_ctx_t *sci)
* \param tick next tick to start the event
* \param function pointer to the callback function to process the received message
* \param data user data to be included into callback function as 'data' parameter
+ * \param id pointer filled with id used to create the netclock msg
* \return 0 if ok, -1 if failed with errno:
* - EINVAL if netclock or msg is null, or if tick < current_tick
* - ENOSPC if there is no more place to register a callback function
@@ -92,7 +93,9 @@ int netclock_schedule(
netclock_type_t type,
tick_t schedule_tick,
void (*callback_function)(void *data),
- void *callback_data)
+ void *callback_data,
+ netclock_id_t *id
+ )
{
sci_msg_t msg;
unsigned char buffer[256];
@@ -102,7 +105,8 @@ int netclock_schedule(
|| (type >= NETWORK_CLOCK_TYPE_NB)
|| (schedule_tick < netclock->sci->station->current_tick_tck)
|| (callback_function == NULL)
- || (callback_data == NULL))
+ || (callback_data == NULL)
+ || (id == NULL))
{
errno = EINVAL;
return -1;
@@ -122,6 +126,7 @@ int netclock_schedule(
netclock->callback_nb++;
/* fill the netclock message part */
+ *id = netclock->current_id;
netclock_fill_hdr(netclock, &msg, type, 0, schedule_tick);
/* fill the sci message part */
diff --git a/host/src/station.c b/host/src/station.c
index 23760a8c50..7a3f12f279 100644
--- a/host/src/station.c
+++ b/host/src/station.c
@@ -282,6 +282,7 @@ static void _ecos_set_itimer_cb(void *data)
*/
int station_ecos_set_itimer(station_ctx_t *station, tick_t tick)
{
+ netclock_id_t id;
if((station == NULL)
|| (station->status == STATION_STATUS_INIT))
{
@@ -294,7 +295,8 @@ int station_ecos_set_itimer(station_ctx_t *station, tick_t tick)
NETWORK_CLOCK_TYPE_STATION,
tick,
_ecos_set_itimer_cb,
- (void *)&maximus_pending_isrs);
+ (void *)&maximus_pending_isrs,
+ &id);
}
/**
diff --git a/host/test/src/test_netclock.c b/host/test/src/test_netclock.c
index c9f2d2cba2..1971edee25 100644
--- a/host/test/src/test_netclock.c
+++ b/host/test/src/test_netclock.c
@@ -193,6 +193,7 @@ void netclock_schedule_test_case(test_t t)
station_ctx_t station;
sci_ctx_t sci;
char data[32];
+ netclock_id_t id;
sci_msg_hdr_t *hdr;
netclock_msg_hdr_t *nclock_hdr;
int fd_in, len;
@@ -207,7 +208,7 @@ void netclock_schedule_test_case(test_t t)
test_begin(t, "netclock = NULL")
{
test_fail_unless(
- (netclock_schedule(NULL, &callback, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data) < 0)
+ (netclock_schedule(NULL, &callback, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data, &id) < 0)
&& (errno == EINVAL)
);
} test_end
@@ -215,7 +216,7 @@ void netclock_schedule_test_case(test_t t)
test_begin(t, "callback = NULL")
{
test_fail_unless(
- (netclock_schedule(&netclock, NULL, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data) < 0)
+ (netclock_schedule(&netclock, NULL, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data, &id) < 0)
&& (errno == EINVAL)
);
} test_end
@@ -223,7 +224,7 @@ void netclock_schedule_test_case(test_t t)
test_begin(t, "type < 0")
{
test_fail_unless(
- (netclock_schedule(&netclock, &callback, -1, 0x1234567890abcdefULL, _test_schedule, data) < 0)
+ (netclock_schedule(&netclock, &callback, -1, 0x1234567890abcdefULL, _test_schedule, data, &id) < 0)
&& (errno == EINVAL)
);
} test_end;
@@ -231,7 +232,7 @@ void netclock_schedule_test_case(test_t t)
test_begin(t, "type >= max value")
{
test_fail_unless(
- (netclock_schedule(&netclock, &callback, NETWORK_CLOCK_TYPE_NB, 0x1234567890abcdefULL, _test_schedule, data) < 0)
+ (netclock_schedule(&netclock, &callback, NETWORK_CLOCK_TYPE_NB, 0x1234567890abcdefULL, _test_schedule, data, &id) < 0)
&& (errno == EINVAL)
);
} test_end
@@ -240,26 +241,36 @@ void netclock_schedule_test_case(test_t t)
{
station.current_tick_tck = 0x2234567890abcdefULL;
test_fail_unless(
- (netclock_schedule(&netclock, &callback, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data) < 0)
+ (netclock_schedule(&netclock, &callback, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data, &id) < 0)
&& (errno == EINVAL)
);
} test_end
+ test_begin(t, "id = NULL")
+ {
+ test_fail_unless(
+ (netclock_schedule(&netclock, &callback, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data, &id) < 0)
+ && (errno == EINVAL)
+ );
+ } test_end
+
fd_in = open(station.pipe_out_name, O_RDONLY);
test_begin(t, "recv netclock msg")
{
station.current_tick_tck = 0x0ULL;
+ id = 0;
set_node_init(&cb_reference.node);
cb_reference.id = callback.id;
test_fail_unless(
- (netclock_schedule(&netclock, &callback, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data) >= 0)
+ (netclock_schedule(&netclock, &callback, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data, &id) >= 0)
&& (set_begin(&netclock.callback_set) == set_find(&netclock.callback_set, &cb_reference.node))
&& (set_begin(&netclock.callback_set) == &callback.node)
&& (callback.function == _test_schedule)
&& (callback.data == data)
&& (callback.id == netclock.current_id - 1)
&& (callback.tick == 0x1234567890abcdefULL)
+ && (id == netclock.current_id - 1)
&& (netclock.callback_nb == 1)
);
@@ -409,6 +420,7 @@ void netclock_recv_test_case(test_t t)
sci_ctx_t sci;
sci_msg_t msg;
sci_msg_hdr_t hdr;
+ netclock_id_t id;
unsigned char buffer[256];
char data_buffer[32];
int fd_in, fd_out;
@@ -443,7 +455,7 @@ void netclock_recv_test_case(test_t t)
test_begin(t, "recv")
{
test_fail_unless(
- (netclock_schedule(&netclock, &callback, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_callback, data_buffer) >= 0)
+ (netclock_schedule(&netclock, &callback, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_callback, data_buffer, &id) >= 0)
);
test_fail_unless(