]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | #include "libsigrok.h" | |
24 | #include <stdint.h> | |
25 | #include <libusb.h> | |
26 | #include <glib.h> | |
27 | ||
28 | struct sr_usb_dev_inst; | |
29 | ||
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. */ | |
42 | #define LWLA_WORD(val) GUINT16_TO_LE(val) | |
43 | ||
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) | |
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 | ||
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 ??? */ | |
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 | ||
104 | SR_PRIV int lwla_send_bitstream(const struct sr_usb_dev_inst *usb, | |
105 | const char *basename); | |
106 | ||
107 | SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb, | |
108 | const uint16_t *command, int cmd_len); | |
109 | ||
110 | SR_PRIV int lwla_receive_reply(const struct sr_usb_dev_inst *usb, | |
111 | uint32_t *reply, int reply_len, int expect_len); | |
112 | ||
113 | SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb, | |
114 | uint16_t reg, uint32_t *value); | |
115 | ||
116 | SR_PRIV int lwla_write_reg(const struct sr_usb_dev_inst *usb, | |
117 | uint16_t reg, uint32_t value); | |
118 | ||
119 | SR_PRIV int lwla_write_regs(const struct sr_usb_dev_inst *usb, | |
120 | const struct regval_pair *regvals, int count); | |
121 | ||
122 | #endif /* !LIBSIGROK_HARDWARE_SYSCLK_LWLA_LWLA_H */ |