More cleanup. Communication with mso19 is working, but its not triggering. Need to check why.

This commit is contained in:
lelazary 2013-01-05 09:29:00 -08:00 committed by Uwe Hermann
parent 26ddb5baca
commit 4db2aaffe7
3 changed files with 125 additions and 122 deletions

View File

@ -19,9 +19,6 @@
#include "protocol.h"
#define SERIALCOMM "460800/8n1" //Default communication params
#define SERIALCONN "/dev/ttyUSB0" //Default communication params
static const int hwcaps[] = {
SR_HWCAP_LOGIC_ANALYZER,
SR_HWCAP_SAMPLERATE,
@ -43,25 +40,28 @@ SR_PRIV const char *mso19_probe_names[NUM_PROBES + 1] = {
/*supported samplerates */
static const struct sr_samplerates samplerates = {
SR_HZ(100),
SR_HZ(200),
SR_HZ(500),
SR_KHZ(1),
SR_KHZ(2),
SR_KHZ(5),
SR_KHZ(10),
SR_KHZ(20),
SR_KHZ(50),
SR_KHZ(100),
SR_KHZ(200),
SR_KHZ(500),
SR_MHZ(1),
SR_MHZ(2),
SR_MHZ(5),
SR_MHZ(10),
SR_MHZ(20),
SR_MHZ(50),
SR_MHZ(100),
SR_MHZ(200),
SR_HZ(1),
//SR_HZ(100),
//SR_HZ(200),
//SR_HZ(500),
//SR_KHZ(1),
//SR_KHZ(2),
//SR_KHZ(5),
//SR_KHZ(10),
//SR_KHZ(20),
//SR_KHZ(50),
//SR_KHZ(100),
//SR_KHZ(200),
//SR_KHZ(500),
//SR_MHZ(1),
//SR_MHZ(2),
//SR_MHZ(5),
//SR_MHZ(10),
//SR_MHZ(20),
//SR_MHZ(50),
//SR_MHZ(100),
//SR_MHZ(200),
NULL,
};
@ -165,7 +165,7 @@ static GSList *hw_scan(GSList *options)
}
strncpy(product, iProduct, s);
product[s] = 0;
strcpy(manufacturer, iProduct + s);
strcpy(manufacturer, iProduct + s + 1);
//Create the device context and set its params
struct dev_context *devc;
@ -206,13 +206,17 @@ static GSList *hw_scan(GSList *options)
return devices;
}
//sdi->index = 0;
sdi->driver = di;
sdi->priv = devc;
//sdi->model = "
//sdi->version = "Testing1234";
//struct sr_probe *probe;
//sdi->probes = g_slist_append(sdi->probes, probe);
for (i = 0; i < NUM_PROBES; i++) {
struct sr_probe *probe;
if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
mso19_probe_names[i])))
return 0;
sdi->probes = g_slist_append(sdi->probes, probe);
}
printf("Add the context\n");
//Add the driver
@ -357,12 +361,7 @@ static int hw_info_get(int info_id, const void **data,
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
const void *value)
{
struct dev_context *devc;
int ret;
const uint64_t *tmp_u64;
printf("Config set\n");
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR;
@ -395,12 +394,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
struct sr_datafeed_header *header;
struct sr_datafeed_meta_logic meta;
struct dev_context *devc;
uint32_t trigger_config[4];
uint32_t data;
uint16_t readcount, delaycount;
uint8_t changrp_mask;
int num_channels;
int i;
int ret = SR_ERR;
@ -438,19 +431,23 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
devc->ctlbase1 &= 0x7f;
// devc->ctlbase1 |= devc->acdcmode;
printf("Configure rate\n");
ret = mso_configure_rate(sdi, devc->cur_rate);
if (ret != SR_OK)
return ret;
/* set dac offset */
printf("Configure dac\n");
ret = mso_dac_out(sdi, devc->dac_offset);
if (ret != SR_OK)
return ret;
printf("Configure threshold level\n");
ret = mso_configure_threshold_level(sdi);
if (ret != SR_OK)
return ret;
printf("Configure trigger\n");
ret = mso_configure_trigger(sdi);
if (ret != SR_OK)
return ret;
@ -461,6 +458,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
/* END of config hardware part */
/* with trigger */
printf("arm\n");
ret = mso_arm(sdi);
if (ret != SR_OK)
return ret;
@ -471,13 +469,16 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
// return ret;
/* Start acquisition on the device. */
mso_check_trigger(sdi, &devc->trigger_state);
ret = mso_check_trigger(sdi, NULL);
printf("Check trigger\n");
mso_check_trigger(devc->serial, &devc->trigger_state);
ret = mso_check_trigger(devc->serial, NULL);
if (ret != SR_OK)
return ret;
printf("Source add\n");
sr_source_add(devc->serial->fd, G_IO_IN, -1, mso_receive_data, cb_data);
printf("Create packet\n");
if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
sr_err("Datafeed packet malloc failed.");
return SR_ERR_MALLOC;

View File

@ -18,10 +18,55 @@
*/
#include "protocol.h"
#include <arpa/inet.h>
extern SR_PRIV struct sr_dev_driver link_mso19_driver_info;
static struct sr_dev_driver *di = &link_mso19_driver_info;
SR_PRIV int mso_send_control_message(struct sr_serial_dev_inst *serial,
uint16_t payload[], int n)
{
int i, w, ret, s = n * 2 + sizeof(mso_head) + sizeof(mso_foot);
char *p, *buf;
ret = SR_ERR;
if (serial->fd < 0)
goto ret;
if (!(buf = g_try_malloc(s))) {
sr_err("Failed to malloc message buffer.");
ret = SR_ERR_MALLOC;
goto ret;
}
p = buf;
memcpy(p, mso_head, sizeof(mso_head));
p += sizeof(mso_head);
for (i = 0; i < n; i++) {
*(uint16_t *) p = htons(payload[i]);
p += 2;
}
memcpy(p, mso_foot, sizeof(mso_foot));
w = 0;
while (w < s) {
ret = serial_write(serial, buf + w, s - w);
if (ret < 0) {
ret = SR_ERR;
goto free;
}
w += ret;
}
ret = SR_OK;
free:
g_free(buf);
ret:
return ret;
}
SR_PRIV int mso_configure_trigger(struct sr_dev_inst *sdi)
{
struct dev_context *devc = sdi->priv;
@ -91,7 +136,7 @@ SR_PRIV int mso_configure_trigger(struct sr_dev_inst *sdi)
/* Select the default config bank */
ops[15] = mso_trans(REG_CTL2, devc->ctlbase2);
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops));
}
SR_PRIV int mso_configure_threshold_level(struct sr_dev_inst *sdi)
@ -176,7 +221,6 @@ SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct,
return SR_ERR;
devc->hwmodel = u4;
devc->hwrev = u5;
devc->serial = u6;
devc->vbit = u1 / 10000;
if (devc->vbit == 0)
devc->vbit = 4.19195;
@ -196,49 +240,6 @@ SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct,
return SR_OK;
}
SR_PRIV int mso_send_control_message(struct sr_serial_dev_inst *serial,
uint16_t payload[], int n)
{
int i, w, ret, s = n * 2 + sizeof(mso_head) + sizeof(mso_foot);
char *p, *buf;
ret = SR_ERR;
if (serial->fd < 0)
goto ret;
if (!(buf = g_try_malloc(s))) {
sr_err("Failed to malloc message buffer.");
ret = SR_ERR_MALLOC;
goto ret;
}
p = buf;
memcpy(p, mso_head, sizeof(mso_head));
p += sizeof(mso_head);
for (i = 0; i < n; i++) {
*(uint16_t *) p = htons(payload[i]);
p += 2;
}
memcpy(p, mso_foot, sizeof(mso_foot));
w = 0;
while (w < s) {
ret = serial_write(serial, buf + w, s - w);
if (ret < 0) {
ret = SR_ERR;
goto free;
}
w += ret;
}
ret = SR_OK;
free:
g_free(buf);
ret:
return ret;
}
SR_PRIV int mso_reset_adc(struct sr_dev_inst *sdi)
{
struct dev_context *devc = sdi->priv;
@ -252,6 +253,32 @@ SR_PRIV int mso_reset_adc(struct sr_dev_inst *sdi)
return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops));
}
SR_PRIV int mso_reset_fsm(struct sr_dev_inst *sdi)
{
struct dev_context *devc = sdi->priv;
uint16_t ops[1];
devc->ctlbase1 |= BIT_CTL1_RESETFSM;
ops[0] = mso_trans(REG_CTL1, devc->ctlbase1);
sr_dbg("Requesting ADC reset.");
return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops));
}
SR_PRIV int mso_toggle_led(struct sr_dev_inst *sdi, int state)
{
struct dev_context *devc = sdi->priv;
uint16_t ops[1];
devc->ctlbase1 &= ~BIT_CTL1_LED;
if (state)
devc->ctlbase1 |= BIT_CTL1_LED;
ops[0] = mso_trans(REG_CTL1, devc->ctlbase1);
sr_dbg("Requesting LED toggle.");
return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops));
}
SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi)
{
struct sr_datafeed_packet packet;
@ -291,6 +318,10 @@ SR_PRIV int mso_configure_rate(struct sr_dev_inst *sdi, uint32_t rate)
return ret;
}
}
if (ret != SR_OK)
sr_err("Unsupported rate.");
return ret;
}
@ -324,16 +355,13 @@ SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
struct sr_dev_inst *sdi;
struct drv_context *drvc;
struct dev_context *devc;
GSList *l;
int num_channels, offset, i, j;
unsigned char byte;
int i;
drvc = di->priv;
struct drv_context *drvc = di->priv;
/* Find this device's devc struct by its fd. */
devc = NULL;
struct dev_context *devc = NULL;
for (l = drvc->instances; l; l = l->next) {
sdi = l->data;
devc = sdi->priv;
@ -402,4 +430,5 @@ SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
packet.type = SR_DF_END;
sr_session_send(devc->session_dev_id, &packet);
return TRUE;
}

View File

@ -41,22 +41,11 @@
#define NUM_PROBES 8
#define NUM_TRIGGER_STAGES 4
#define TRIGGER_TYPES "01"
#define SERIAL_SPEED B115200
#define SERIALCOMM "460800/8n1/flow=2"
#define SERIALCONN "/dev/ttyUSB0"
#define CLOCK_RATE SR_MHZ(100)
#define MIN_NUM_SAMPLES 4
///* Bitmasks for CMD_FLAGS */
//#define FLAG_DEMUX 0x01
//#define FLAG_FILTER 0x02
//#define FLAG_CHANNELGROUP_1 0x04
//#define FLAG_CHANNELGROUP_2 0x08
//#define FLAG_CHANNELGROUP_3 0x10
//#define FLAG_CHANNELGROUP_4 0x20
//#define FLAG_CLOCK_EXTERNAL 0x40
//#define FLAG_CLOCK_INVERTED 0x80
//#define FLAG_RLE 0x0100
#define MSO_TRIGGER_UNKNOWN '!'
#define MSO_TRIGGER_UNKNOWN1 '1'
#define MSO_TRIGGER_UNKNOWN2 '2'
@ -140,8 +129,9 @@ SR_PRIV int mso_read_buffer(struct sr_dev_inst *sdi);
SR_PRIV int mso_arm(struct sr_dev_inst *sdi);
SR_PRIV int mso_force_capture(struct sr_dev_inst *sdi);
SR_PRIV int mso_dac_out(struct sr_dev_inst *sdi, uint16_t val);
SR_PRIV int mso_configure_rate(struct sr_dev_inst *sdi, uint32_t rate);
SR_PRIV inline uint16_t mso_calc_raw_from_mv(struct dev_context *devc);
SR_PRIV int mso_reset_fsm(struct sr_dev_inst *sdi);
SR_PRIV int mso_toggle_led(struct sr_dev_inst *sdi, int state);
SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi);
@ -224,21 +214,4 @@ static uint16_t la_threshold_map[] = {
0x8fff,
};
//SR_PRIV extern const char *ols_probe_names[NUM_PROBES + 1];
//
//SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial,
// uint8_t command);
//SR_PRIV int send_longcommand(struct sr_serial_dev_inst *serial,
// uint8_t command, uint32_t data);
//SR_PRIV int ols_configure_probes(const struct sr_dev_inst *sdi);
//SR_PRIV uint32_t reverse16(uint32_t in);
//SR_PRIV uint32_t reverse32(uint32_t in);
//SR_PRIV struct dev_context *ols_dev_new(void);
//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);
//SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data);
#endif