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 /** 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 *basename);
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 uint32_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);