blob: 3a64a471484a4df82ba03791db8dcfa7cb7bf229 [file] [log] [blame]
Jacob Erlbeck3bed5d12015-03-19 11:22:38 +01001/*
2 * Copyright (C) 2015 by Sysmocom s.f.m.c. GmbH
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19inline int msecs_to_frames(int msecs) {
20 return (msecs * (1024 * 1000 / 4615)) / 1024;
21}
Jacob Erlbeck0c1c8772015-03-20 12:02:42 +010022
Max9dabfa22017-05-16 16:10:45 +020023inline uint32_t next_fn(uint32_t fn, uint32_t offset)
24{
25 return (fn + offset) % GSM_MAX_FN;
26}
27
Jacob Erlbeck0c1c8772015-03-20 12:02:42 +010028inline void csecs_to_timeval(unsigned csecs, struct timeval *tv) {
29 tv->tv_sec = csecs / 100;
30 tv->tv_usec = (csecs % 100) * 10000;
31}
Jacob Erlbeck8cba7e92016-01-19 15:48:03 +010032
33template <typename T>
34inline unsigned int pcu_bitcount(T x)
35{
36 unsigned int count = 0;
37 for (count = 0; x; count += 1)
38 x &= x - 1;
39
40 return count;
41}
42
43template <typename T>
44inline T pcu_lsb(T x)
45{
46 return x & -x;
47}