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
23 #include "libsigrok.h"
28 struct sr_usb_dev_inst;
30 /* Read mixed endian words from a buffer of 16-bit units. */
31 #define LWLA_READ16(buf) GUINT16_FROM_LE(*(buf))
32 #define LWLA_READ32(buf) \
33 (((uint32_t)GUINT16_FROM_LE((buf)[0]) << 16) | \
34 ((uint32_t)GUINT16_FROM_LE((buf)[1])))
35 #define LWLA_READ64(buf) \
36 (((uint64_t)LWLA_READ32((buf))) | \
37 ((uint64_t)LWLA_READ32((buf) + 2) << 32))
39 /* Convert 16-bit argument to little endian. */
40 #define LWLA_WORD(val) GUINT16_TO_LE(val)
42 /* Extract 16-bit units from 32/64-bit value in mixed endian order. */
43 #define LWLA_WORD_0(val) GUINT16_TO_LE(((val) & 0xFFFF0000u) >> 16)
44 #define LWLA_WORD_1(val) GUINT16_TO_LE(((val) & 0x0000FFFFu))
45 #define LWLA_WORD_2(val) \
46 GUINT16_TO_LE(((val) & G_GUINT64_CONSTANT(0xFFFF000000000000)) >> 48)
47 #define LWLA_WORD_3(val) \
48 GUINT16_TO_LE(((val) & G_GUINT64_CONSTANT(0x0000FFFF00000000)) >> 32)
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 /** LWLA register addresses.
80 REG_MEM_CTRL2 = 0x1074, /* capture buffer control ??? */
81 REG_MEM_FILL = 0x1078, /* capture buffer fill level */
82 REG_MEM_CTRL4 = 0x107C, /* capture buffer control ??? */
84 REG_DIV_BYPASS = 0x1094, /* bypass clock divider flag */
86 REG_CMD_CTRL1 = 0x10B0, /* command control ??? */
87 REG_CMD_CTRL2 = 0x10B4, /* command control ??? */
88 REG_CMD_CTRL3 = 0x10B8, /* command control ??? */
89 REG_CMD_CTRL4 = 0x10BC, /* command control ??? */
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 /** Register/value pair.
104 SR_PRIV int lwla_send_bitstream(const struct sr_usb_dev_inst *usb,
105 const char *filename);
107 SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb,
108 const uint16_t *command, int cmd_len);
110 SR_PRIV int lwla_receive_reply(const struct sr_usb_dev_inst *usb,
111 uint16_t *reply, int reply_len, int expect_len);
113 SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb,
114 uint16_t reg, uint32_t *value);
116 SR_PRIV int lwla_write_reg(const struct sr_usb_dev_inst *usb,
117 uint16_t reg, uint32_t value);
119 SR_PRIV int lwla_write_regs(const struct sr_usb_dev_inst *usb,
120 const struct regval_pair *regvals, int count);
122 #endif /* !LIBSIGROK_HARDWARE_SYSCLK_LWLA_LWLA_H */