X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fopenbench-logic-sniffer%2Fprotocol.c;h=dddc37e43dcb1c043aecd44146f986973779459a;hb=72cd99b876eb2185358bc108b488585c956f3dc7;hp=813c5083167d764b714b8b051b2704cb5ef3c812;hpb=0aba65da9f4031ca6eb7d0c268e4d06b0d0bfa06;p=libsigrok.git diff --git a/hardware/openbench-logic-sniffer/protocol.c b/hardware/openbench-logic-sniffer/protocol.c index 813c5083..dddc37e4 100644 --- a/hardware/openbench-logic-sniffer/protocol.c +++ b/hardware/openbench-logic-sniffer/protocol.c @@ -1,7 +1,7 @@ /* * This file is part of the sigrok project. * - * Copyright (C) 2010-2012 Bert Vermeulen + * Copyright (C) 2013 Bert Vermeulen * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ #include "protocol.h" -SR_PRIV struct sr_dev_driver ols_driver_info; +extern SR_PRIV struct sr_dev_driver ols_driver_info; static struct sr_dev_driver *di = &ols_driver_info; SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial, @@ -133,14 +133,20 @@ SR_PRIV struct dev_context *ols_dev_new(void) { struct dev_context *devc; - if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { + if (!(devc = g_try_malloc(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); return NULL; } + /* Device-specific settings */ + devc->max_samples = devc->max_samplerate = devc->protocol_version = 0; + + /* Acquisition settings */ + devc->limit_samples = devc->capture_ratio = 0; devc->trigger_at = -1; devc->probe_mask = 0xffffffff; - devc->cur_samplerate = SR_KHZ(200); + devc->flag_reg = 0; + devc->serial = NULL; return devc; @@ -284,16 +290,12 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) } SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi, - uint64_t samplerate, - const struct sr_samplerates *samplerates) + const uint64_t samplerate) { struct dev_context *devc; devc = sdi->priv; - if (devc->max_samplerate) { - if (samplerate > devc->max_samplerate) - return SR_ERR_SAMPLERATE; - } else if (samplerate < samplerates->low || samplerate > samplerates->high) + if (devc->max_samplerate && samplerate > devc->max_samplerate) return SR_ERR_SAMPLERATE; if (samplerate > CLOCK_RATE) { @@ -311,7 +313,7 @@ SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi, if (devc->flag_reg & FLAG_DEMUX) devc->cur_samplerate *= 2; if (devc->cur_samplerate != samplerate) - sr_err("Can't match samplerate %" PRIu64 ", using %" + sr_info("Can't match samplerate %" PRIu64 ", using %" PRIu64 ".", samplerate, devc->cur_samplerate); return SR_OK; @@ -338,6 +340,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) struct drv_context *drvc; struct dev_context *devc; GSList *l; + uint32_t sample; int num_channels, offset, i, j; unsigned char byte; @@ -392,8 +395,9 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) sr_dbg("Received byte 0x%.2x.", byte); if (devc->num_bytes == num_channels) { /* Got a full sample. */ - sr_dbg("Received sample 0x%.*x.", - devc->num_bytes * 2, *(int *)devc->sample); + sample = devc->sample[0] | (devc->sample[1] << 8) \ + | (devc->sample[2] << 16) | (devc->sample[3] << 24); + sr_dbg("Received sample 0x%.*x.", devc->num_bytes * 2, sample); if (devc->flag_reg & FLAG_RLE) { /* * In RLE mode -1 should never come in as a @@ -405,7 +409,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) * FIXME: This will only work on * little-endian systems. */ - devc->rle_count = *(int *)(devc->sample); + devc->rle_count = sample; sr_dbg("RLE count: %d.", devc->rle_count); devc->num_bytes = 0; return TRUE; @@ -441,7 +445,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) } } memcpy(devc->sample, devc->tmp_sample, 4); - sr_dbg("Full sample: 0x%.8x.", *(int *)devc->sample); + sr_dbg("Full sample: 0x%.8x.", sample); } /* the OLS sends its sample buffer backwards.