X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Flibsigrok-internal.h;h=b614c93d0bdc039407a345cdc0db0d844103abcf;hb=56213aa0270fc8046dfcc380c137e766be41fd9c;hp=de338888582ccc316b3101bdea9454e545c322a7;hpb=47a102f9bb7973aecc2ef3dd93725286ac983c86;p=libsigrok.git diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index de338888..b614c93d 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -74,6 +74,16 @@ static inline uint8_t read_u8(const uint8_t *p) } #define R8(x) read_u8((const uint8_t *)(x)) +/** + * Read an 8 bits signed integer out of memory. + * @param x a pointer to the input memory + * @return the corresponding signed integer + */ +static inline int8_t read_i8(const uint8_t *p) +{ + return (int8_t)p[0]; +} + /** * Read a 16 bits big endian unsigned integer out of memory. * @param x a pointer to the input memory @@ -312,7 +322,7 @@ static inline int64_t read_i64le(const uint8_t *p) #define RL64S(x) read_i64le((const uint8_t *)(x)) /** - * Read a 32 bits big endian float out of memory. + * Read a 32 bits big endian float out of memory (single precision). * @param x a pointer to the input memory * @return the corresponding float */ @@ -335,7 +345,7 @@ static inline float read_fltbe(const uint8_t *p) #define RBFL(x) read_fltbe((const uint8_t *)(x)) /** - * Read a 32 bits little endian float out of memory. + * Read a 32 bits little endian float out of memory (single precision). * @param x a pointer to the input memory * @return the corresponding float */ @@ -357,6 +367,51 @@ static inline float read_fltle(const uint8_t *p) } #define RLFL(x) read_fltle((const uint8_t *)(x)) +/** + * Read a 64 bits big endian float out of memory (double precision). + * @param x a pointer to the input memory + * @return the corresponding floating point value + */ +static inline double read_dblbe(const uint8_t *p) +{ + /* + * Implementor's note: Strictly speaking the "union" trick + * is not portable. But this phrase was found to work on the + * project's supported platforms, and serve well until a more + * appropriate phrase is found. + */ + union { uint64_t u64; double flt; } u; + double f; + + u.u64 = read_u64be(p); + f = u.flt; + + return f; +} + +/** + * Read a 64 bits little endian float out of memory (double precision). + * @param x a pointer to the input memory + * @return the corresponding floating point value + */ +static inline double read_dblle(const uint8_t *p) +{ + /* + * Implementor's note: Strictly speaking the "union" trick + * is not portable. But this phrase was found to work on the + * project's supported platforms, and serve well until a more + * appropriate phrase is found. + */ + union { uint64_t u64; double flt; } u; + double f; + + u.u64 = read_u64le(p); + f = u.flt; + + return f; +} +#define RLDB(x) read_dblle((const uint8_t *)(x)) + /** * Write a 8 bits unsigned integer to memory. * @param p a pointer to the output memory @@ -420,6 +475,24 @@ static inline void write_u32le(uint8_t *p, uint32_t x) } #define WL32(p, x) write_u32le((uint8_t *)(p), (uint32_t)(x)) +/** + * Write a 64 bits unsigned integer to memory stored as little endian. + * @param p a pointer to the output memory + * @param x the input unsigned integer + */ +static inline void write_u64le(uint8_t *p, uint64_t x) +{ + p[0] = x & 0xff; x >>= 8; + p[1] = x & 0xff; x >>= 8; + p[2] = x & 0xff; x >>= 8; + p[3] = x & 0xff; x >>= 8; + p[4] = x & 0xff; x >>= 8; + p[5] = x & 0xff; x >>= 8; + p[6] = x & 0xff; x >>= 8; + p[7] = x & 0xff; x >>= 8; +} +#define WL64(p, x) write_u64le((uint8_t *)(p), (uint64_t)(x)) + /** * Write a 32 bits float to memory stored as big endian. * @param p a pointer to the output memory @@ -446,6 +519,19 @@ static inline void write_fltle(uint8_t *p, float x) } #define WLFL(p, x) write_fltle((uint8_t *)(p), float (x)) +/** + * Write a 64 bits float to memory stored as little endian. + * @param p a pointer to the output memory + * @param x the input floating point value + */ +static inline void write_dblle(uint8_t *p, double x) +{ + union { uint64_t u; double f; } u; + u.f = x; + write_u64le(p, u.u); +} +#define WLDB(p, x) write_dblle((uint8_t *)(p), float (x)) + /* Endianess conversion helpers with read/write position increment. */ /** @@ -465,6 +551,23 @@ static inline uint8_t read_u8_inc(const uint8_t **p) return v; } +/** + * Read signed 8bit integer from raw memory, increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved integer value, signed. + */ +static inline int8_t read_i8_inc(const uint8_t **p) +{ + int8_t v; + + if (!p || !*p) + return 0; + v = read_i8(*p); + *p += sizeof(v); + + return v; +} + /** * Read unsigned 16bit integer from raw memory (big endian format), increment read position. * @param[in, out] p Pointer into byte stream. @@ -500,17 +603,34 @@ static inline uint16_t read_u16le_inc(const uint8_t **p) } /** - * Read unsigned 32bit integer from raw memory (big endian format), increment read position. + * Read signed 16bit integer from raw memory (big endian format), increment read position. * @param[in, out] p Pointer into byte stream. - * @return Retrieved integer value, unsigned. + * @return Retrieved integer value, signed. */ -static inline uint32_t read_u32be_inc(const uint8_t **p) +static inline int16_t read_i16be_inc(const uint8_t **p) { - uint32_t v; + int16_t v; if (!p || !*p) return 0; - v = read_u32be(*p); + v = read_i16be(*p); + *p += sizeof(v); + + return v; +} + +/** + * Read signed 16bit integer from raw memory (little endian format), increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved integer value, signed. + */ +static inline int16_t read_i16le_inc(const uint8_t **p) +{ + int16_t v; + + if (!p || !*p) + return 0; + v = read_i16le(*p); *p += sizeof(v); return v; @@ -533,6 +653,23 @@ static inline uint32_t read_u24le_inc(const uint8_t **p) return v; } +/** + * Read unsigned 32bit integer from raw memory (big endian format), increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved integer value, unsigned. + */ +static inline uint32_t read_u32be_inc(const uint8_t **p) +{ + uint32_t v; + + if (!p || !*p) + return 0; + v = read_u32be(*p); + *p += sizeof(v); + + return v; +} + /** * Read unsigned 32bit integer from raw memory (little endian format), increment read position. * @param[in, out] p Pointer into byte stream. @@ -550,6 +687,40 @@ static inline uint32_t read_u32le_inc(const uint8_t **p) return v; } +/** + * Read signed 32bit integer from raw memory (big endian format), increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved integer value, signed. + */ +static inline int32_t read_i32be_inc(const uint8_t **p) +{ + int32_t v; + + if (!p || !*p) + return 0; + v = read_i32be(*p); + *p += sizeof(v); + + return v; +} + +/** + * Read signed 32bit integer from raw memory (little endian format), increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved integer value, signed. + */ +static inline int32_t read_i32le_inc(const uint8_t **p) +{ + int32_t v; + + if (!p || !*p) + return 0; + v = read_i32le(*p); + *p += sizeof(v); + + return v; +} + /** * Read unsigned 64bit integer from raw memory (big endian format), increment read position. * @param[in, out] p Pointer into byte stream. @@ -584,6 +755,74 @@ static inline uint64_t read_u64le_inc(const uint8_t **p) return v; } +/** + * Read 32bit float from raw memory (big endian format), increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved float value. + */ +static inline float read_fltbe_inc(const uint8_t **p) +{ + float v; + + if (!p || !*p) + return 0; + v = read_fltbe(*p); + *p += sizeof(v); + + return v; +} + +/** + * Read 32bit float from raw memory (little endian format), increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved float value. + */ +static inline float read_fltle_inc(const uint8_t **p) +{ + float v; + + if (!p || !*p) + return 0; + v = read_fltle(*p); + *p += sizeof(v); + + return v; +} + +/** + * Read 64bit float from raw memory (big endian format), increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved float value. + */ +static inline double read_dblbe_inc(const uint8_t **p) +{ + double v; + + if (!p || !*p) + return 0; + v = read_dblbe(*p); + *p += sizeof(v); + + return v; +} + +/** + * Read 64bit float from raw memory (little endian format), increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved float value. + */ +static inline double read_dblle_inc(const uint8_t **p) +{ + double v; + + if (!p || !*p) + return 0; + v = read_dblle(*p); + *p += sizeof(v); + + return v; +} + /** * Write unsigned 8bit integer to raw memory, increment write position. * @param[in, out] p Pointer into byte stream. @@ -649,6 +888,45 @@ static inline void write_u32le_inc(uint8_t **p, uint32_t x) *p += sizeof(x); } +/** + * Write unsigned 64bit little endian integer to raw memory, increment write position. + * @param[in, out] p Pointer into byte stream. + * @param[in] x Value to write. + */ +static inline void write_u64le_inc(uint8_t **p, uint64_t x) +{ + if (!p || !*p) + return; + write_u64le(*p, x); + *p += sizeof(x); +} + +/** + * Write single precision little endian float to raw memory, increment write position. + * @param[in, out] p Pointer into byte stream. + * @param[in] x Value to write. + */ +static inline void write_fltle_inc(uint8_t **p, float x) +{ + if (!p || !*p) + return; + write_fltle(*p, x); + *p += sizeof(x); +} + +/** + * Write double precision little endian float to raw memory, increment write position. + * @param[in, out] p Pointer into byte stream. + * @param[in] x Value to write. + */ +static inline void write_dblle_inc(uint8_t **p, double x) +{ + if (!p || !*p) + return; + write_dblle(*p, x); + *p += sizeof(x); +} + /* Portability fixes for FreeBSD. */ #ifdef __FreeBSD__ #define LIBUSB_CLASS_APPLICATION 0xfe @@ -1481,6 +1759,8 @@ SR_PRIV int std_cg_idx(const struct sr_channel_group *cg, struct sr_channel_grou SR_PRIV int std_dummy_set_params(struct sr_serial_dev_inst *serial, int baudrate, int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr); +SR_PRIV int std_dummy_set_handshake(struct sr_serial_dev_inst *serial, + int rts, int dtr); /*--- resource.c ------------------------------------------------------------*/ @@ -1565,6 +1845,8 @@ SR_PRIV int serial_set_read_chunk_cb(struct sr_serial_dev_inst *serial, serial_rx_chunk_callback cb, void *cb_data); SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate, int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr); +SR_PRIV int serial_set_handshake(struct sr_serial_dev_inst *serial, + int rts, int dtr); SR_PRIV int serial_set_paramstr(struct sr_serial_dev_inst *serial, const char *paramstr); SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf, @@ -1605,6 +1887,8 @@ struct ser_lib_functions { int (*set_params)(struct sr_serial_dev_inst *serial, int baudrate, int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr); + int (*set_handshake)(struct sr_serial_dev_inst *serial, + int rts, int dtr); int (*setup_source_add)(struct sr_session *session, struct sr_serial_dev_inst *serial, int events, int timeout, @@ -2048,6 +2332,20 @@ SR_PRIV gboolean sr_brymen_bm25x_packet_valid(const uint8_t *buf); SR_PRIV int sr_brymen_bm25x_parse(const uint8_t *buf, float *floatval, struct sr_datafeed_analog *analog, void *info); +/*--- dmm/bm52x.c -----------------------------------------------------------*/ + +#define BRYMEN_BM52X_PACKET_SIZE 24 +#define BRYMEN_BM52X_DISPLAY_COUNT 2 + +struct brymen_bm52x_info { size_t ch_idx; }; + +#ifdef HAVE_SERIAL_COMM +SR_PRIV int sr_brymen_bm52x_packet_request(struct sr_serial_dev_inst *serial); +#endif +SR_PRIV gboolean sr_brymen_bm52x_packet_valid(const uint8_t *buf); +SR_PRIV int sr_brymen_bm52x_parse(const uint8_t *buf, float *floatval, + struct sr_datafeed_analog *analog, void *info); + /*--- dmm/bm86x.c -----------------------------------------------------------*/ #define BRYMEN_BM86X_PACKET_SIZE 24 @@ -2265,7 +2563,7 @@ struct sr_sw_limits { uint64_t start_time; }; -SR_PRIV int sr_sw_limits_config_get(struct sr_sw_limits *limits, uint32_t key, +SR_PRIV int sr_sw_limits_config_get(const struct sr_sw_limits *limits, uint32_t key, GVariant **data); SR_PRIV int sr_sw_limits_config_set(struct sr_sw_limits *limits, uint32_t key, GVariant *data);