diff --git a/Makefile b/Makefile index ce594e90..212ab62c 100644 --- a/Makefile +++ b/Makefile @@ -880,8 +880,6 @@ TEST_TIMEOUT01_O_FILES += testsuite/timeout01/init.o TEST_TIMEOUT01_D_FILES += testsuite/timeout01/init.d TEST_TIMEOUT01_O_FILES += testsuite/timeout01/timeout_test.o TEST_TIMEOUT01_D_FILES += testsuite/timeout01/timeout_test.d -TEST_TIMEOUT01_O_FILES += testsuite/timeout01/timeout_helper.o -TEST_TIMEOUT01_D_FILES += testsuite/timeout01/timeout_helper.d $(TEST_TIMEOUT01): $(TEST_TIMEOUT01_O_FILES) $(LIB) $(LINK.c) -Wl,-Map,testsuite/timeout01/timeout01.map $^ -lm -lz -o $@ TESTS += $(TEST_TIMEOUT01) diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py index 9ea97810..d4a88469 100755 --- a/freebsd-to-rtems.py +++ b/freebsd-to-rtems.py @@ -2355,7 +2355,7 @@ tests.addTest('usb01', ['init', 'test-file-system'], False) tests.addTest('loopback01', ['test_main']) tests.addTest('netshell01', ['test_main', 'shellconfig', 'ns_parser_vars'], False) tests.addTest('swi01', ['init', 'swi_test']) -tests.addTest('timeout01', ['init', 'timeout_test', 'timeout_helper']) +tests.addTest('timeout01', ['init', 'timeout_test']) tests.addTest('init01', ['test_main']) tests.addTest('thread01', ['test_main']) diff --git a/freebsd/sys/kern/kern_timeout.c b/freebsd/sys/kern/kern_timeout.c index 1d5dbadf..2fed3727 100644 --- a/freebsd/sys/kern/kern_timeout.c +++ b/freebsd/sys/kern/kern_timeout.c @@ -160,6 +160,19 @@ MALLOC_DEFINE(M_CALLOUT, "callout", "Callout datastructures"); #ifdef __rtems__ static void rtems_bsd_timeout_init(void *); +static void +rtems_bsd_callout_timer(rtems_id id, void *arg) +{ + rtems_status_code sc; + + (void) arg; + + sc = rtems_timer_reset(id); + BSD_ASSERT(sc == RTEMS_SUCCESSFUL); + + callout_tick(); +} + static void callout_cpu_init(struct callout_cpu *); SYSINIT(rtems_bsd_timeout, SI_SUB_VM, SI_ORDER_FIRST, rtems_bsd_timeout_init, @@ -174,6 +187,8 @@ kern_timeout_callwheel_alloc(caddr_t v) { struct callout_cpu *cc; #ifdef __rtems__ + rtems_status_code sc; + rtems_id id; caddr_t v; (void) unused; @@ -202,6 +217,12 @@ kern_timeout_callwheel_alloc(caddr_t v) return(v); #else /* __rtems__ */ callout_cpu_init(cc); + + sc = rtems_timer_create(rtems_build_name('_', 'C', 'L', 'O'), &id); + BSD_ASSERT(sc == RTEMS_SUCCESSFUL); + + sc = rtems_timer_server_fire_after(id, 1, rtems_bsd_callout_timer, NULL); + BSD_ASSERT(sc == RTEMS_SUCCESSFUL); #endif /* __rtems__ */ } diff --git a/libbsd.txt b/libbsd.txt index 1b2da2b2..890c5cbf 100644 --- a/libbsd.txt +++ b/libbsd.txt @@ -100,6 +100,9 @@ the current Git submodule commit is this * KQUEUE(2): Choose proper lock for global kqueue list. +* TIMEOUT(9): Maybe use special task instead of timer server to call + callout_tick(). + [listing] ---- /* sysinit section? */ diff --git a/testsuite/timeout01/init.c b/testsuite/timeout01/init.c index f74a1b80..11f95f3a 100644 --- a/testsuite/timeout01/init.c +++ b/testsuite/timeout01/init.c @@ -38,7 +38,6 @@ #include #include "timeout_test.h" -#include "timeout_helper.h" static void Init(rtems_task_argument arg) { @@ -49,8 +48,6 @@ static void Init(rtems_task_argument arg) sc = rtems_bsd_initialize(); assert(sc == RTEMS_SUCCESSFUL); - callout_tick_task_init(); - timeout_test(); puts("*** END OF TEST TIMOUT 1 ***"); diff --git a/testsuite/timeout01/timeout_helper.c b/testsuite/timeout01/timeout_helper.c deleted file mode 100644 index 343651df..00000000 --- a/testsuite/timeout01/timeout_helper.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2012 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include -#include - -#include -#include - -#include "timeout_helper.h" - -#define CALLOUT_TICK_TASK_PRIO (PRIORITY_DEFAULT_MAXIMUM - 1) -#define CALLOUT_TICK_TASK_STACK_SIZE (1024) -#define CALLOUT_TICK_TASK_NAME rtems_build_name('C', 'O', 'U', 'T') -#define CALLOUT_TICKS_PER_CALLOUT_TICK 1 - -static const rtems_event_set TRIGGER_EVENT = RTEMS_EVENT_13; - -static void callout_tick_task_trigger(rtems_id timer, void *arg) -{ - rtems_status_code status; - rtems_id *task_id = arg; - - status = rtems_event_send(*task_id, TRIGGER_EVENT); - assert(status == RTEMS_SUCCESSFUL); - - status = rtems_timer_reset(timer); - assert(status == RTEMS_SUCCESSFUL); -} - -rtems_task callout_tick_task(rtems_task_argument arg) -{ - rtems_name name; - rtems_id timer; - rtems_status_code status; - const rtems_interval ticks_per_ms = CALLOUT_TICKS_PER_CALLOUT_TICK; - rtems_id self_id = rtems_task_self(); - - name = CALLOUT_TICK_TASK_NAME; - - status = rtems_timer_create( name, &timer ); - assert(status == RTEMS_SUCCESSFUL); - - status = rtems_timer_fire_after( timer, ticks_per_ms, callout_tick_task_trigger, &self_id ); - assert(status == RTEMS_SUCCESSFUL); - - while ( 1 ) { - rtems_event_set event; - - status = rtems_event_receive( - TRIGGER_EVENT, - RTEMS_EVENT_ALL | RTEMS_WAIT, - RTEMS_NO_TIMEOUT, - &event - ); - assert(status == RTEMS_SUCCESSFUL); - assert(event == TRIGGER_EVENT); - - callout_tick(); - } -} - - -void callout_tick_task_init(void) -{ - static bool initialized = false; - rtems_status_code sc = RTEMS_SUCCESSFUL; - - if (!initialized) { - rtems_id id = RTEMS_ID_NONE; - - initialized = true; - - sc = rtems_task_create( - CALLOUT_TICK_TASK_NAME, - CALLOUT_TICK_TASK_PRIO, - CALLOUT_TICK_TASK_STACK_SIZE, - RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, - &id - ); - assert(sc == RTEMS_SUCCESSFUL); - - sc = rtems_task_start(id, callout_tick_task, 0); - assert(sc == RTEMS_SUCCESSFUL); - } -} - diff --git a/testsuite/timeout01/timeout_helper.h b/testsuite/timeout01/timeout_helper.h deleted file mode 100644 index 050c592e..00000000 --- a/testsuite/timeout01/timeout_helper.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef TIMEOUT_HELPER_H -#define TIMEOUT_HELPER_H - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -void callout_tick_task_init(void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* TIMEOUT_HELPER_H */