mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-07-24 02:22:03 +08:00
TIMEOUT(9): Use timer server for callout_tick()
This commit is contained in:
parent
0c9f27ba24
commit
a9e26f5d5b
2
Makefile
2
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)
|
||||
|
@ -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'])
|
||||
|
||||
|
@ -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__ */
|
||||
}
|
||||
|
||||
|
@ -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? */
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include <rtems/bsd/bsd.h>
|
||||
|
||||
#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 ***");
|
||||
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* 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 <machine/rtems-bsd-config.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* 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 */
|
Loading…
x
Reference in New Issue
Block a user