source: rtems-libbsd/rtemsbsd/src/rtems-bsd-callout.c @ cbffdb7f

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since cbffdb7f was cbffdb7f, checked in by Joel Sherrill <joel.sherrill@…>, on 03/07/12 at 22:14:13

Separate RTEMS Specific Files from Those Direct from FreeBSD

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bsd_rtems
5 *
6 * @brief TODO.
7 */
8
9/*
10 * Copyright (c) 2009, 2010 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 */
22
23#include <rtems/freebsd/machine/rtems-bsd-config.h>
24
25#include <rtems/freebsd/sys/param.h>
26#include <rtems/freebsd/sys/types.h>
27#include <rtems/freebsd/sys/systm.h>
28#include <rtems/freebsd/sys/callout.h>
29#include <rtems/freebsd/sys/lock.h>
30#include <rtems/freebsd/sys/mutex.h>
31
32RTEMS_CHAIN_DEFINE_EMPTY(rtems_bsd_callout_chain);
33
34static void
35rtems_bsd_callout_dispatch(rtems_id id, void *arg)
36{
37        rtems_status_code sc = RTEMS_SUCCESSFUL;
38        struct callout *c = arg;
39
40        if (c->c_lock != NULL) {
41                sc = rtems_semaphore_obtain(c->c_lock->lo_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
42                BSD_ASSERT_SC(sc);
43        }
44
45        if (c->c_func != NULL) {
46                (*c->c_func)(c->c_arg);
47        }
48
49        if (c->c_lock != NULL && (c->c_flags & CALLOUT_RETURNUNLOCKED) == 0) {
50                sc = rtems_semaphore_release(c->c_lock->lo_id);
51                BSD_ASSERT_SC(sc);
52        }
53}
54
55void
56callout_init(struct callout *c, int mpsafe)
57{
58        _callout_init_lock(c, mpsafe ? NULL : &Giant.lock_object, mpsafe ? CALLOUT_RETURNUNLOCKED : 0);
59}
60
61void
62_callout_init_lock(struct callout *c, struct lock_object *lock, int flags)
63{
64        rtems_status_code sc = RTEMS_SUCCESSFUL;
65        rtems_id id = RTEMS_ID_NONE;
66
67        sc = rtems_timer_create(rtems_build_name('_', 'T', 'M', 'R'), &id);
68        BSD_ASSERT_SC(sc);
69
70        c->c_id = id;
71        c->c_lock = lock;
72        c->c_flags = flags;
73        c->c_func = NULL;
74        c->c_arg = NULL;
75
76        rtems_chain_append(&rtems_bsd_callout_chain, &c->c_node);
77}
78
79int
80callout_reset(struct callout *c, int to_ticks, void (*ftn)(void *), void *arg)
81{
82        /* FIXME: Integer conversions */
83
84        rtems_status_code sc = RTEMS_SUCCESSFUL;
85
86        if (to_ticks <= 0) {
87                to_ticks = 1;
88        }
89
90        c->c_func = ftn;
91        c->c_arg = arg;
92
93        sc = rtems_timer_server_fire_after(c->c_id, (rtems_interval) to_ticks, rtems_bsd_callout_dispatch, c);
94        BSD_ASSERT_SC(sc);
95
96        return 0;
97}
98
99int
100callout_schedule(struct callout *c, int to_ticks)
101{
102        return callout_reset(c, to_ticks, c->c_func, c->c_arg);
103}
104
105int
106_callout_stop_safe(struct callout *c, int safe)
107{
108        rtems_status_code sc = RTEMS_SUCCESSFUL;
109
110        if (!safe) {
111                sc = rtems_timer_cancel(c->c_id);
112                BSD_ASSERT_SC(sc);
113        } else {
114                sc = rtems_timer_delete(c->c_id);
115                BSD_ASSERT_SC(sc);
116
117                c->c_id = RTEMS_ID_NONE;
118                rtems_chain_extract(&c->c_node);
119        }
120
121        return 0;
122}
Note: See TracBrowser for help on using the repository browser.