Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/ad9361/sw/util.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file util.h
3 * @brief Header file of Util driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2013(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *******************************************************************************/
39 #ifndef __NO_OS_PORT_H__
40 #define __NO_OS_PORT_H__
41
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 #include <limits.h>
46 #include <stdint.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include "ad9361.h"
50 #include "common.h"
51 #include "config.h"
52
53
54 /******************************************************************************/
55 /********************** Macros and Constants Definitions **********************/
56 /******************************************************************************/
57 #define SUCCESS 0
58 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
59 #define min(x, y) (((x) < (y)) ? (x) : (y))
60 #define min_t(type, x, y) (type)min((type)(x), (type)(y))
61 #define max(x, y) (((x) > (y)) ? (x) : (y))
62 #define max_t(type, x, y) (type)max((type)(x), (type)(y))
63 #define clamp(val, min_val, max_val) (max(min((val), (max_val)), (min_val)))
64 #define clamp_t(type, val, min_val, max_val) (type)clamp((type)(val), (type)(min_val), (type)(max_val))
65 #define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y))
66 #define DIV_ROUND_CLOSEST(x, divisor) (((x) + (divisor) / 2) / (divisor))
67 #define BIT(x) (1 << (x))
68 #define CLK_IGNORE_UNUSED BIT(3)
69 #define CLK_GET_RATE_NOCACHE BIT(6)
70
71 #if defined(HAVE_VERBOSE_MESSAGES)
72 #define dev_err(dev, format, ...) ({printf(format, ## __VA_ARGS__);printf("\n"); })
73 #define dev_warn(dev, format, ...) ({printf(format, ## __VA_ARGS__);printf("\n"); })
74 #if defined(HAVE_DEBUG_MESSAGES)
75 #define dev_dbg(dev, format, ...) ({printf(format, ## __VA_ARGS__);printf("\n"); })
76 #else
77 #define dev_dbg(dev, format, ...) ({ if (0) printf(format, ## __VA_ARGS__); })
78 #endif
79 #define printk(format, ...) printf(format, ## __VA_ARGS__)
80 #else
81 #define dev_err(dev, format, ...) ({ if (0) printf(format, ## __VA_ARGS__); })
82 #define dev_warn(dev, format, ...) ({ if (0) printf(format, ## __VA_ARGS__); })
83 #define dev_dbg(dev, format, ...) ({ if (0) printf(format, ## __VA_ARGS__); })
84 #define printk(format, ...) ({ if (0) printf(format, ## __VA_ARGS__); })
85 #endif
86
87 struct device {
88 };
89
90 struct spi_device {
91 struct device dev;
92 uint8_t id_no;
93 };
94
95 struct axiadc_state {
96 struct ad9361_rf_phy *phy;
97 uint32_t pcore_version;
98 };
99
100 struct axiadc_chip_info {
101 char *name;
102 int32_t num_channels;
103 };
104
105 struct axiadc_converter {
106 struct axiadc_chip_info *chip_info;
107 uint32_t scratch_reg[16];
108 };
109
110 #ifdef WIN32
111 #include "basetsd.h"
112 typedef SSIZE_T ssize_t;
113 #define strsep(s, ct) 0
114 #define snprintf(s, n, format, ...) 0
115 #define __func__ __FUNCTION__
116 #endif
117
118 /******************************************************************************/
119 /************************ Functions Declarations ******************************/
120 /******************************************************************************/
121 int32_t clk_prepare_enable(struct clk *clk);
122 uint32_t clk_get_rate(struct ad9361_rf_phy *phy,
123 struct refclk_scale *clk_priv);
124 int32_t clk_set_rate(struct ad9361_rf_phy *phy,
125 struct refclk_scale *clk_priv,
126 uint32_t rate);
127 uint32_t int_sqrt(uint32_t x);
128 int32_t ilog2(int32_t x);
129 uint64_t do_div(uint64_t* n,
130 uint64_t base);
131 uint32_t find_first_bit(uint32_t word);
132 void * ERR_PTR(long error);
133 void *zmalloc(size_t size);
134
135 #endif