]>
Commit | Line | Data |
---|---|---|
5874e88d DE |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2014 Daniel Elstner <daniel.kitta@gmail.com> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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/>. | |
18 | */ | |
19 | ||
20 | #ifndef LIBSIGROK_HARDWARE_SYSCLK_LWLA_LWLA_H | |
21 | #define LIBSIGROK_HARDWARE_SYSCLK_LWLA_LWLA_H | |
22 | ||
5874e88d DE |
23 | #include <stdint.h> |
24 | #include <libusb.h> | |
25 | #include <glib.h> | |
c1aae900 | 26 | #include <libsigrok/libsigrok.h> |
5874e88d DE |
27 | |
28 | struct sr_usb_dev_inst; | |
29 | ||
e0df15d4 DE |
30 | /* Rotate argument n bits to the left. |
31 | * This construct is an idiom recognized by GCC as bit rotation. | |
32 | */ | |
33 | #define LROTATE(a, n) (((a) << (n)) | ((a) >> (CHAR_BIT * sizeof(a) - (n)))) | |
34 | ||
35 | /* Convert 16-bit little endian LWLA protocol word to machine word order. */ | |
36 | #define LWLA_TO_UINT16(val) GUINT16_FROM_LE(val) | |
37 | ||
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) | |
40 | ||
41 | /* Convert 16-bit argument to LWLA protocol word. */ | |
5874e88d DE |
42 | #define LWLA_WORD(val) GUINT16_TO_LE(val) |
43 | ||
e0df15d4 DE |
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) | |
5874e88d DE |
49 | |
50 | /** USB device end points. | |
51 | */ | |
52 | enum { | |
53 | EP_COMMAND = 2, | |
54 | EP_BITSTREAM = 4, | |
55 | EP_REPLY = 6 | LIBUSB_ENDPOINT_IN | |
56 | }; | |
57 | ||
58 | /** LWLA protocol command ID codes. | |
59 | */ | |
60 | enum { | |
61 | CMD_READ_REG = 1, | |
62 | CMD_WRITE_REG = 2, | |
63 | CMD_READ_MEM = 6, | |
64 | CMD_CAP_SETUP = 7, | |
65 | CMD_CAP_STATUS = 8, | |
66 | }; | |
67 | ||
68 | /** LWLA capture state flags. | |
69 | */ | |
70 | enum { | |
71 | STATUS_CAPTURING = 1 << 1, | |
72 | STATUS_TRIGGERED = 1 << 4, | |
73 | STATUS_MEM_AVAIL = 1 << 5, | |
74 | STATUS_FLAG_MASK = 0x3F | |
75 | }; | |
76 | ||
77 | /** LWLA register addresses. | |
78 | */ | |
79 | enum { | |
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 ??? */ | |
83 | ||
84 | REG_DIV_BYPASS = 0x1094, /* bypass clock divider flag */ | |
85 | ||
3a322bbc DE |
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 */ | |
5874e88d DE |
90 | |
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 */ | |
95 | }; | |
96 | ||
97 | /** Register/value pair. | |
98 | */ | |
99 | struct regval_pair { | |
100 | unsigned int reg; | |
101 | unsigned int val; | |
102 | }; | |
103 | ||
8e2d6c9d DE |
104 | SR_PRIV int lwla_send_bitstream(struct sr_context *ctx, |
105 | const struct sr_usb_dev_inst *usb, | |
106 | const char *name); | |
5874e88d DE |
107 | |
108 | SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb, | |
109 | const uint16_t *command, int cmd_len); | |
110 | ||
111 | SR_PRIV int lwla_receive_reply(const struct sr_usb_dev_inst *usb, | |
e0df15d4 | 112 | uint32_t *reply, int reply_len, int expect_len); |
5874e88d DE |
113 | |
114 | SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb, | |
115 | uint16_t reg, uint32_t *value); | |
116 | ||
117 | SR_PRIV int lwla_write_reg(const struct sr_usb_dev_inst *usb, | |
118 | uint16_t reg, uint32_t value); | |
119 | ||
120 | SR_PRIV int lwla_write_regs(const struct sr_usb_dev_inst *usb, | |
121 | const struct regval_pair *regvals, int count); | |
122 | ||
db24496a | 123 | #endif |