Provide SWI(9) and TIMEOUT(9)

This commit is contained in:
Christian Mauderer
2012-05-10 15:06:10 +02:00
committed by Sebastian Huber
parent a4d8e191b9
commit ee6b343cba
21 changed files with 1994 additions and 322 deletions

View File

@@ -1,140 +0,0 @@
/**
* @file
*
* @ingroup rtems_bsd_rtems
*
* @brief TODO.
*/
/*
* Copyright (c) 2009, 2010 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 <freebsd/machine/rtems-bsd-config.h>
#include <freebsd/sys/param.h>
#include <freebsd/sys/types.h>
#include <freebsd/sys/systm.h>
#include <freebsd/sys/callout.h>
#include <freebsd/sys/lock.h>
#include <freebsd/sys/mutex.h>
RTEMS_CHAIN_DEFINE_EMPTY(rtems_bsd_callout_chain);
static void
rtems_bsd_callout_dispatch(rtems_id id, void *arg)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
struct callout *c = arg;
if (c->c_lock != NULL) {
sc = rtems_semaphore_obtain(c->c_lock->lo_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
BSD_ASSERT_SC(sc);
}
if (c->c_func != NULL) {
(*c->c_func)(c->c_arg);
}
if (c->c_lock != NULL && (c->c_flags & CALLOUT_RETURNUNLOCKED) == 0) {
sc = rtems_semaphore_release(c->c_lock->lo_id);
BSD_ASSERT_SC(sc);
}
}
void
callout_init(struct callout *c, int mpsafe)
{
_callout_init_lock(c, mpsafe ? NULL : &Giant.lock_object, mpsafe ? CALLOUT_RETURNUNLOCKED : 0);
}
void
_callout_init_lock(struct callout *c, struct lock_object *lock, int flags)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
rtems_id id = RTEMS_ID_NONE;
sc = rtems_timer_create(rtems_build_name('_', 'T', 'M', 'R'), &id);
BSD_ASSERT_SC(sc);
c->c_id = id;
c->c_lock = lock;
c->c_flags = flags;
c->c_func = NULL;
c->c_arg = NULL;
rtems_chain_append(&rtems_bsd_callout_chain, &c->c_node);
}
int
callout_reset(struct callout *c, int to_ticks, void (*ftn)(void *), void *arg)
{
/* FIXME: Integer conversions */
rtems_status_code sc = RTEMS_SUCCESSFUL;
if (to_ticks <= 0) {
to_ticks = 1;
}
c->c_func = ftn;
c->c_arg = arg;
sc = rtems_timer_server_fire_after(c->c_id, (rtems_interval) to_ticks, rtems_bsd_callout_dispatch, c);
BSD_ASSERT_SC(sc);
return 0;
}
int
callout_schedule(struct callout *c, int to_ticks)
{
return callout_reset(c, to_ticks, c->c_func, c->c_arg);
}
int
_callout_stop_safe(struct callout *c, int safe)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
if (!safe) {
sc = rtems_timer_cancel(c->c_id);
BSD_ASSERT_SC(sc);
} else {
sc = rtems_timer_delete(c->c_id);
BSD_ASSERT_SC(sc);
c->c_id = RTEMS_ID_NONE;
rtems_chain_extract(&c->c_node);
}
return 0;
}

View File

@@ -51,23 +51,6 @@
#include <freebsd/bsd.h>
#include <rtems/shell.h>
static void
rtems_bsd_dump_callout(void)
{
rtems_chain_control *chain = &rtems_bsd_callout_chain;
rtems_chain_node *node = rtems_chain_first(chain);
printf("callout dump:\n");
while (!rtems_chain_is_tail(chain, node)) {
struct callout *c = (struct callout *) node;
printf("\t%08x\n", c->c_id);
node = rtems_chain_next(node);
}
}
static void
rtems_bsd_dump_mtx(void)
{
@@ -169,10 +152,6 @@ rtems_bsd_info(int argc, char **argv)
rtems_bsd_dump_thread();
usage = false;
}
if (CMP("callout")) {
rtems_bsd_dump_callout();
usage = false;
}
}
if (usage) {

View File

@@ -1,129 +0,0 @@
/**
* @file
*
* @ingroup rtems_bsd_rtems
*
* @brief TODO.
*/
/*
* COPYRIGHT (c) 2012.
* On-Line Applications Research Corporation (OAR).
* All rights reserved.
*
* 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 <freebsd/machine/rtems-bsd-config.h>
#include <freebsd/sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <freebsd/sys/param.h>
#include <freebsd/sys/systm.h>
#include <freebsd/sys/bus.h>
#include <freebsd/sys/callout.h>
#include <freebsd/sys/condvar.h>
#include <freebsd/sys/interrupt.h>
#include <freebsd/sys/kernel.h>
#include <freebsd/sys/ktr.h>
#include <freebsd/sys/lock.h>
#include <freebsd/sys/malloc.h>
#include <freebsd/sys/mutex.h>
#include <freebsd/sys/proc.h>
#include <freebsd/sys/sdt.h>
static int timeout_cpu;
/*
* There is one struct callout_cpu per cpu, holding all relevant
* state for the callout processing thread on the individual CPU.
* In particular:
* cc_ticks is incremented once per tick in callout_cpu().
* It tracks the global 'ticks' but in a way that the individual
* threads should not worry about races in the order in which
* hardclock() and hardclock_cpu() run on the various CPUs.
* cc_softclock is advanced in callout_cpu() to point to the
* first entry in cc_callwheel that may need handling. In turn,
* a softclock() is scheduled so it can serve the various entries i
* such that cc_softclock <= i <= cc_ticks .
* XXX maybe cc_softclock and cc_ticks should be volatile ?
*
* cc_ticks is also used in callout_reset_cpu() to determine
* when the callout should be served.
*/
struct callout_cpu {
struct mtx cc_lock;
struct callout *cc_callout;
struct callout_tailq *cc_callwheel;
struct callout_list cc_callfree;
struct callout *cc_next;
struct callout *cc_curr;
void *cc_cookie;
int cc_ticks;
int cc_softticks;
int cc_cancel;
int cc_waiting;
};
/*
* timeout --
* Execute a function after a specified length of time.
*
* untimeout --
* Cancel previous timeout function call.
*
* callout_handle_init --
* Initialize a handle so that using it with untimeout is benign.
*
* See AT&T BCI Driver Reference Manual for specification. This
* implementation differs from that one in that although an
* identification value is returned from timeout, the original
* arguments to timeout as well as the identifier are used to
* identify entries for untimeout.
*/
struct callout_handle
timeout(ftn, arg, to_ticks)
timeout_t *ftn;
void *arg;
int to_ticks;
{
struct callout_cpu *cc;
struct callout *new;
struct callout_handle handle;
#if 0
cc = CC_CPU(timeout_cpu);
CC_LOCK(cc);
/* Fill in the next free callout structure. */
new = SLIST_FIRST(&cc->cc_callfree);
if (new == NULL)
/* XXX Attempt to malloc first */
panic("timeout table full");
SLIST_REMOVE_HEAD(&cc->cc_callfree, c_links.sle);
callout_reset(new, to_ticks, ftn, arg);
handle.callout = new;
CC_UNLOCK(cc);
#endif
return (handle);
}