Jacob Erlbeck | 3bed5d1 | 2015-03-19 11:22:38 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Max | 20c7c46 | 2017-12-22 14:20:05 +0100 | [diff] [blame] | 19 | extern "C" { |
| 20 | #include <osmocom/gsm/gsm_utils.h> |
| 21 | } |
Pau Espin Pedrol | 1de6873 | 2020-03-11 14:04:52 +0100 | [diff] [blame] | 22 | #include <time.h> |
Max | 20c7c46 | 2017-12-22 14:20:05 +0100 | [diff] [blame] | 23 | |
Jacob Erlbeck | 3bed5d1 | 2015-03-19 11:22:38 +0100 | [diff] [blame] | 24 | inline int msecs_to_frames(int msecs) { |
| 25 | return (msecs * (1024 * 1000 / 4615)) / 1024; |
| 26 | } |
Jacob Erlbeck | 0c1c877 | 2015-03-20 12:02:42 +0100 | [diff] [blame] | 27 | |
Max | 9dabfa2 | 2017-05-16 16:10:45 +0200 | [diff] [blame] | 28 | inline uint32_t next_fn(uint32_t fn, uint32_t offset) |
| 29 | { |
| 30 | return (fn + offset) % GSM_MAX_FN; |
| 31 | } |
| 32 | |
Pau Espin Pedrol | 1de6873 | 2020-03-11 14:04:52 +0100 | [diff] [blame] | 33 | inline void csecs_to_timespec(unsigned csecs, struct timespec *ts) { |
| 34 | ts->tv_sec = csecs / 100; |
| 35 | ts->tv_nsec = (csecs % 100) * 10000000; |
Jacob Erlbeck | 0c1c877 | 2015-03-20 12:02:42 +0100 | [diff] [blame] | 36 | } |
Jacob Erlbeck | 8cba7e9 | 2016-01-19 15:48:03 +0100 | [diff] [blame] | 37 | |
| 38 | template <typename T> |
| 39 | inline unsigned int pcu_bitcount(T x) |
| 40 | { |
| 41 | unsigned int count = 0; |
| 42 | for (count = 0; x; count += 1) |
| 43 | x &= x - 1; |
| 44 | |
| 45 | return count; |
| 46 | } |
| 47 | |
Max | 735e435 | 2018-01-26 18:49:39 +0100 | [diff] [blame] | 48 | inline uint8_t pcu_lsb(uint8_t x) |
Jacob Erlbeck | 8cba7e9 | 2016-01-19 15:48:03 +0100 | [diff] [blame] | 49 | { |
| 50 | return x & -x; |
| 51 | } |