2 * This file is part of the libsigrok project.
4 * Copyright (C) 2014 Daniel Elstner <daniel.kitta@gmail.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef LIBSIGROK_HARDWARE_SYSCLK_LWLA_LWLA_H
21 #define LIBSIGROK_HARDWARE_SYSCLK_LWLA_LWLA_H
26 #include <libsigrok/libsigrok.h>
28 struct sr_usb_dev_inst;
30 /* Rotate argument n bits to the left.
31 * This construct is an idiom recognized by GCC as bit rotation.
33 #define LROTATE(a, n) (((a) << (n)) | ((a) >> (CHAR_BIT * sizeof(a) - (n))))
35 /* Convert 16-bit little endian LWLA protocol word to machine word order. */
36 #define LWLA_TO_UINT16(val) GUINT16_FROM_LE(val)
38 /* Convert 32-bit mixed endian LWLA protocol word to machine word order. */
39 #define LWLA_TO_UINT32(val) LROTATE(GUINT32_FROM_LE(val), 16)
41 /* Convert 16-bit argument to LWLA protocol word. */
42 #define LWLA_WORD(val) GUINT16_TO_LE(val)
44 /* Extract 16-bit units in mixed endian order from 32/64-bit value. */
45 #define LWLA_WORD_0(val) GUINT16_TO_LE(((val) >> 16) & 0xFFFF)
46 #define LWLA_WORD_1(val) GUINT16_TO_LE((val) & 0xFFFF)
47 #define LWLA_WORD_2(val) GUINT16_TO_LE(((val) >> 48) & 0xFFFF)
48 #define LWLA_WORD_3(val) GUINT16_TO_LE(((val) >> 32) & 0xFFFF)
50 /** USB device end points.
55 EP_REPLY = 6 | LIBUSB_ENDPOINT_IN
58 /** LWLA protocol command ID codes.
68 /** LWLA capture state flags.
71 STATUS_CAPTURING = 1 << 1,
72 STATUS_TRIGGERED = 1 << 4,
73 STATUS_MEM_AVAIL = 1 << 5,
74 STATUS_FLAG_MASK = 0x3F
77 /** LWLA1034 register addresses.
80 REG_MEM_CTRL = 0x1074, /* capture buffer control */
81 REG_MEM_FILL = 0x1078, /* capture buffer fill level */
82 REG_MEM_START = 0x107C, /* capture buffer start address */
84 REG_DIV_BYPASS = 0x1094, /* bypass clock divider flag */
86 REG_LONG_STROBE = 0x10B0, /* long register read/write strobe */
87 REG_LONG_ADDR = 0x10B4, /* long register address */
88 REG_LONG_LOW = 0x10B8, /* long register low word */
89 REG_LONG_HIGH = 0x10BC, /* long register high word */
91 REG_FREQ_CH1 = 0x10C0, /* channel 1 live frequency */
92 REG_FREQ_CH2 = 0x10C4, /* channel 2 live frequency */
93 REG_FREQ_CH3 = 0x10C8, /* channel 3 live frequency */
94 REG_FREQ_CH4 = 0x10CC, /* channel 4 live frequency */
97 /** Flag bits for REG_MEM_CTRL.
100 MEM_CTRL_WRITE = 1 << 0, /* "wr1rd0" bit */
101 MEM_CTRL_CLR_IDX = 1 << 1, /* "clr_idx" bit */
104 /* LWLA1034 long register addresses.
107 LREG_CAP_CTRL = 10, /* capture control bits */
108 LREG_TEST_ID = 100, /* constant test ID */
111 /** Flag bits for LREG_CAP_CTRL.
114 CAP_CTRL_TRG_EN = 1 << 0, /* "trg_en" bit */
115 CAP_CTRL_CLR_TIMEBASE = 1 << 2, /* "do_clr_timebase" bit */
116 CAP_CTRL_FLUSH_FIFO = 1 << 4, /* "flush_fifo" bit */
117 CAP_CTRL_CLR_FIFOFULL = 1 << 5, /* "clr_fifo32_ful" bit */
118 CAP_CTRL_CLR_COUNTER = 1 << 6, /* "clr_cntr0" bit */
121 /** Register/value pair.
128 SR_PRIV int lwla_send_bitstream(struct sr_context *ctx,
129 const struct sr_usb_dev_inst *usb,
132 SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb,
133 const uint16_t *command, int cmd_len);
135 SR_PRIV int lwla_receive_reply(const struct sr_usb_dev_inst *usb,
136 uint32_t *reply, int reply_len, int expect_len);
138 SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb,
139 uint16_t reg, uint32_t *value);
141 SR_PRIV int lwla_read_long_reg(const struct sr_usb_dev_inst *usb,
142 uint32_t addr, uint64_t *value);
144 SR_PRIV int lwla_write_reg(const struct sr_usb_dev_inst *usb,
145 uint16_t reg, uint32_t value);
147 SR_PRIV int lwla_write_regs(const struct sr_usb_dev_inst *usb,
148 const struct regval_pair *regvals, int count);