blob: cfabd0cc6f5d6ef36980f195288c0a05e32cc6f5 [file] [log] [blame]
Ivan Kluchnikov65785622012-04-12 14:49:02 +04001/* gsm_timer.h
2 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20/*! \defgroup timer GSM timers
21 * @{
22 */
23
24/*! \file gsm_timer.h
25 * \brief GSM timer handling routines
26 */
27#ifndef GSM_TIMER_H
28#define GSM_TIMER_H
29
30extern "C" {
31#include <osmocom/core/linuxlist.h>
32#include <osmocom/core/linuxrbtree.h>
33}
34/**
35 * Timer management:
36 * - Create a struct osmo_gsm_timer_list
37 * - Fill out timeout and use add_gsm_timer or
38 * use schedule_gsm_timer to schedule a timer in
39 * x frames from now...
40 * - Use del_gsm_timer to remove the timer
41 *
42 * Internally:
43 * - We hook into select.c to give a frame number of the
44 * nearest timer. On already passed timers we give
45 * it a 0 to immediately fire after the select.
46 * - update_gsm_timers will call the callbacks and remove
47 * the timers.
48 *
49 */
50/*! \brief A structure representing a single instance of a gsm timer */
51struct osmo_gsm_timer_list {
52 struct rb_node node; /*!< \brief rb-tree node header */
53 struct llist_head list; /*!< \brief internal list header */
54 int fn; /*!< \brief expiration frame number */
55 unsigned int active : 1; /*!< \brief is it active? */
56
57 void (*cb)(void*); /*!< \brief call-back called at timeout */
58 void *data; /*!< \brief user data for callback */
59};
60
61/**
62 * timer management
63 */
64
65void osmo_gsm_timer_add(struct osmo_gsm_timer_list *timer);
66
67void osmo_gsm_timer_schedule(struct osmo_gsm_timer_list *timer, int fn);
68
69void osmo_gsm_timer_del(struct osmo_gsm_timer_list *timer);
70
71int osmo_gsm_timer_pending(struct osmo_gsm_timer_list *timer);
72
73
74/*
75 * internal timer list management
76 */
77int *osmo_gsm_timers_nearest(void);
78void osmo_gsm_timers_prepare(void);
79int osmo_gsm_timers_update(void);
80int osmo_gsm_timers_check(void);
81
Philipp Maier7e8e3972018-04-10 13:31:45 +020082
83/*
84 * Get Current Frame Number
85 */
86int get_current_fn();
87
Ivan Kluchnikov65785622012-04-12 14:49:02 +040088/*! }@ */
89
90#endif // GSM_TIMER_H