blob: 329245285af26d1830c935d334992142e4daba2d [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
Max20c7c462017-12-22 14:20:05 +010019extern "C" {
20#include <osmocom/gsm/gsm_utils.h>
21}
22
Jacob Erlbeck3bed5d12015-03-19 11:22:38 +010023inline int msecs_to_frames(int msecs) {
24 return (msecs * (1024 * 1000 / 4615)) / 1024;
25}
Jacob Erlbeck0c1c8772015-03-20 12:02:42 +010026
Max9dabfa22017-05-16 16:10:45 +020027inline uint32_t next_fn(uint32_t fn, uint32_t offset)
28{
29 return (fn + offset) % GSM_MAX_FN;
30}
31
Jacob Erlbeck0c1c8772015-03-20 12:02:42 +010032inline void csecs_to_timeval(unsigned csecs, struct timeval *tv) {
33 tv->tv_sec = csecs / 100;
34 tv->tv_usec = (csecs % 100) * 10000;
35}
Jacob Erlbeck8cba7e92016-01-19 15:48:03 +010036
37template <typename T>
38inline unsigned int pcu_bitcount(T x)
39{
40 unsigned int count = 0;
41 for (count = 0; x; count += 1)
42 x &= x - 1;
43
44 return count;
45}
46
Max735e4352018-01-26 18:49:39 +010047inline uint8_t pcu_lsb(uint8_t x)
Jacob Erlbeck8cba7e92016-01-19 15:48:03 +010048{
49 return x & -x;
50}