Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 #ifndef _IIO_UTILS_H_
0003 #define _IIO_UTILS_H_
0004 
0005 /* IIO - useful set of util functionality
0006  *
0007  * Copyright (c) 2008 Jonathan Cameron
0008  */
0009 
0010 #include <stdint.h>
0011 
0012 /* Made up value to limit allocation sizes */
0013 #define IIO_MAX_NAME_LENGTH 64
0014 
0015 #define FORMAT_SCAN_ELEMENTS_DIR "%s/buffer%d"
0016 #define FORMAT_EVENTS_DIR "%s/events"
0017 #define FORMAT_TYPE_FILE "%s_type"
0018 
0019 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
0020 
0021 extern const char *iio_dir;
0022 
0023 /**
0024  * struct iio_channel_info - information about a given channel
0025  * @name: channel name
0026  * @generic_name: general name for channel type
0027  * @scale: scale factor to be applied for conversion to si units
0028  * @offset: offset to be applied for conversion to si units
0029  * @index: the channel index in the buffer output
0030  * @bytes: number of bytes occupied in buffer output
0031  * @bits_used: number of valid bits of data
0032  * @shift: amount of bits to shift right data before applying bit mask
0033  * @mask: a bit mask for the raw output
0034  * @be: flag if data is big endian
0035  * @is_signed: is the raw value stored signed
0036  * @location: data offset for this channel inside the buffer (in bytes)
0037  **/
0038 struct iio_channel_info {
0039     char *name;
0040     char *generic_name;
0041     float scale;
0042     float offset;
0043     unsigned index;
0044     unsigned bytes;
0045     unsigned bits_used;
0046     unsigned shift;
0047     uint64_t mask;
0048     unsigned be;
0049     unsigned is_signed;
0050     unsigned location;
0051 };
0052 
0053 static inline int iioutils_check_suffix(const char *str, const char *suffix)
0054 {
0055     return strlen(str) >= strlen(suffix) &&
0056         strncmp(str+strlen(str)-strlen(suffix),
0057             suffix, strlen(suffix)) == 0;
0058 }
0059 
0060 int iioutils_break_up_name(const char *full_name, char **generic_name);
0061 int iioutils_get_param_float(float *output, const char *param_name,
0062                  const char *device_dir, const char *name,
0063                  const char *generic_name);
0064 void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt);
0065 int build_channel_array(const char *device_dir, int buffer_idx,
0066             struct iio_channel_info **ci_array, int *counter);
0067 int find_type_by_name(const char *name, const char *type);
0068 int write_sysfs_int(const char *filename, const char *basedir, int val);
0069 int write_sysfs_int_and_verify(const char *filename, const char *basedir,
0070                    int val);
0071 int write_sysfs_string_and_verify(const char *filename, const char *basedir,
0072                   const char *val);
0073 int write_sysfs_string(const char *filename, const char *basedir,
0074                const char *val);
0075 int read_sysfs_posint(const char *filename, const char *basedir);
0076 int read_sysfs_float(const char *filename, const char *basedir, float *val);
0077 int read_sysfs_string(const char *filename, const char *basedir, char *str);
0078 
0079 #endif /* _IIO_UTILS_H_ */