forked from LinuxCNC/mesaflash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lbp16.h
262 lines (227 loc) · 9.3 KB
/
lbp16.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
//
// Copyright (C) 2013-2014 Michael Geszkiewicz
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
#ifndef __LBP16_H
#define __LBP16_H
#include "types.h"
#include "common.h"
#define LBP16_SENDRECV_DEBUG 0
#define LBP16_UDP_PORT 27181
#define LBP16_HW_IP "192.168.1.121"
#define LBP16_MEM_SPACE_COUNT 8
#define LBP16_CMD_SIZE 2
#define LBP16_ADDR_SIZE 2
#define LBP16_CMDADDR_PACKET_SIZE (LBP16_CMD_SIZE + LBP16_ADDR_SIZE)
#define LBP16_CMDONLY_PACKET_SIZE (LBP16_CMD_SIZE)
#define LBP16_MAX_PACKET_DATA_SIZE 0x7F
#define FLASH_ADDR_REG 0x0000
#define FLASH_DATA_REG 0x0004
#define FLASH_ID_REG 0x0008
#define FLASH_SEC_ERASE_REG 0x000C
#define ETH_EEPROM_IP_REG 0x0020
#define COMM_CTRL_WRITE_ENA_REG 0x001A
#define LBP16_ADDR_AUTO_INC 0x0080
#define LBP16_ARGS_8BIT 0x0000
#define LBP16_ARGS_16BIT 0x0100
#define LBP16_ARGS_32BIT 0x0200
#define LBP16_ARGS_64BIT 0x0300
#define LBP16_SPACE_HM2 0x0000
#define LBP16_SPACE_ETH_CHIP 0x0400
#define LBP16_SPACE_ETH_EEPROM 0x0800
#define LBP16_SPACE_FPGA_FLASH 0x0C00
#define LBP16_SPACE_TIMER 0x1000
#define LBP16_SPACE_COMM_CTRL 0x1800
#define LBP16_SPACE_BOARD_INFO 0x1C00
#define LBP16_SPACE_ACC 0x0000
#define LBP16_INFO_ACC 0x2000
#define LBP16_READ 0x0000
#define LBP16_ADDR 0x4000
#define LBP16_NO_ADDR 0x0000
#define LBP16_WRITE 0x8000
#define CMD_READ_AREA_INFO_16 (LBP16_READ | LBP16_ADDR | LBP16_INFO_ACC | LBP16_ARGS_16BIT)
#define CMD_READ_ADDR_16 (LBP16_READ | LBP16_ADDR | LBP16_SPACE_ACC | LBP16_ARGS_16BIT)
#define CMD_READ_ADDR_32 (LBP16_READ | LBP16_ADDR | LBP16_SPACE_ACC | LBP16_ARGS_32BIT)
#define CMD_WRITE_ADDR_16 (LBP16_WRITE | LBP16_ADDR | LBP16_SPACE_ACC | LBP16_ARGS_16BIT)
#define CMD_WRITE_ADDR_16_INCR (LBP16_WRITE | LBP16_ADDR | LBP16_SPACE_ACC | LBP16_ADDR_AUTO_INC | LBP16_ARGS_16BIT)
#define CMD_WRITE_ADDR_32 (LBP16_WRITE | LBP16_ADDR | LBP16_SPACE_ACC | LBP16_ARGS_32BIT)
#define CMD_WRITE_ADDR_32_INCR (LBP16_WRITE | LBP16_ADDR | LBP16_SPACE_ACC | LBP16_ADDR_AUTO_INC | LBP16_ARGS_32BIT)
#define CMD_READ_AREA_INFO_ADDR16(space, size) (CMD_READ_AREA_INFO_16 | space | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_AREA_INFO_ADDR16_INCR(space, size) (CMD_READ_AREA_INFO_16 | LBP16_ADDR_AUTO_INC | space | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_HOSTMOT2_ADDR32(size) (CMD_READ_ADDR_32 | LBP16_SPACE_HM2 | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_HOSTMOT2_ADDR32_INCR(size) (CMD_READ_ADDR_32 | LBP16_SPACE_HM2 | LBP16_ADDR_AUTO_INC | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_ETH_CHIP_ADDR16(size) (CMD_READ_ADDR_16 | LBP16_SPACE_ETH_CHIP | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_ETH_CHIP_ADDR16_INCR(size) (CMD_READ_ADDR_16 | LBP16_SPACE_ETH_CHIP | LBP16_ADDR_AUTO_INC | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_ETH_EEPROM_ADDR16(size) (CMD_READ_ADDR_16 | LBP16_SPACE_ETH_EEPROM | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_ETH_EEPROM_ADDR16_INCR(size) (CMD_READ_ADDR_16 | LBP16_SPACE_ETH_EEPROM | LBP16_ADDR_AUTO_INC | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_FPGA_FLASH_ADDR32(size) (CMD_READ_ADDR_32 | LBP16_SPACE_FPGA_FLASH | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_TIMER_ADDR16(size) (CMD_READ_ADDR_16 | LBP16_SPACE_TIMER | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_TIMER_ADDR16_INCR(size) (CMD_READ_ADDR_16 | LBP16_SPACE_TIMER | LBP16_ADDR_AUTO_INC | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_COMM_CTRL_ADDR16(size) (CMD_READ_ADDR_16 | LBP16_SPACE_COMM_CTRL | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_COMM_CTRL_ADDR16_INCR(size) (CMD_READ_ADDR_16 | LBP16_SPACE_COMM_CTRL | LBP16_ADDR_AUTO_INC | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_BOARD_INFO_ADDR16(size) (CMD_READ_ADDR_16 | LBP16_SPACE_BOARD_INFO | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_READ_BOARD_INFO_ADDR16_INCR(size) (CMD_READ_ADDR_16 | LBP16_SPACE_BOARD_INFO | LBP16_ADDR_AUTO_INC | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_WRITE_HOSTMOT2_ADDR32(size) (CMD_WRITE_ADDR_32 | LBP16_SPACE_HM2 | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_WRITE_HOSTMOT2_ADDR32_INCR(size) (CMD_WRITE_ADDR_32 | LBP16_SPACE_HM2 | LBP16_ADDR_AUTO_INC | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_WRITE_FPGA_FLASH_ADDR32(size) (CMD_WRITE_ADDR_32 | LBP16_SPACE_FPGA_FLASH | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_WRITE_COMM_CTRL_ADDR16(size) (CMD_WRITE_ADDR_16 | LBP16_SPACE_COMM_CTRL | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_WRITE_ETH_EEPROM_ADDR16(size) (CMD_WRITE_ADDR_16 | LBP16_SPACE_ETH_EEPROM | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
#define CMD_WRITE_ETH_EEPROM_ADDR16_INCR(size) (CMD_WRITE_ADDR_16_INCR | LBP16_SPACE_ETH_EEPROM | ((size) & LBP16_MAX_PACKET_DATA_SIZE))
// common packets
#define CMD_READ_HM2_COOKIE (CMD_READ_HOSTMOT2_ADDR32(1))
#define CMD_READ_FLASH_IDROM (CMD_READ_FPGA_FLASH_ADDR32(1))
typedef struct {
u8 cmd_hi;
u8 cmd_lo;
} lbp16_cmd;
typedef struct {
u8 cmd_hi;
u8 cmd_lo;
u8 addr_hi;
u8 addr_lo;
} lbp16_cmd_addr;
typedef struct {
u8 cmd_hi;
u8 cmd_lo;
u8 addr_hi;
u8 addr_lo;
u8 data_hi;
u8 data_lo;
} lbp16_cmd_addr_data16;
typedef struct {
u8 cmd_hi;
u8 cmd_lo;
u8 addr_hi;
u8 addr_lo;
u8 data1;
u8 data2;
u8 data3;
u8 data4;
} lbp16_cmd_addr_data32;
typedef struct {
u8 cmd_hi;
u8 cmd_lo;
u8 addr_hi;
u8 addr_lo;
u8 page[256];
} lbp16_write_flash_page_packet;
typedef struct {
lbp16_cmd_addr_data16 write_ena_pck;
lbp16_cmd_addr_data32 fl_erase_pck;
} lbp16_erase_flash_sector_packets;
typedef struct {
lbp16_cmd_addr_data16 write_ena_pck;
lbp16_write_flash_page_packet fl_write_page_pck;
} lbp16_write_flash_page_packets;
typedef struct {
lbp16_cmd_addr_data16 write_ena_pck;
lbp16_cmd_addr_data32 eth_write_ip_pck;
} lbp16_write_ip_addr_packets;
#define LBP16_INIT_PACKET4(packet, cmd, addr) do { \
packet.cmd_hi = LO_BYTE(cmd); \
packet.cmd_lo = HI_BYTE(cmd); \
packet.addr_hi = LO_BYTE(addr); \
packet.addr_lo = HI_BYTE(addr); \
} while (0);
#define LBP16_INIT_PACKET4_SERIAL(packet, cmd, addr) do { \
packet.cmd_hi = HI_BYTE(cmd); \
packet.cmd_lo = LO_BYTE(cmd); \
packet.addr_hi = HI_BYTE(addr); \
packet.addr_lo = LO_BYTE(addr); \
} while (0);
#define LBP16_INIT_PACKET6(packet, cmd, addr, data) do { \
packet.cmd_hi = LO_BYTE(cmd); \
packet.cmd_lo = HI_BYTE(cmd); \
packet.addr_hi = LO_BYTE(addr); \
packet.addr_lo = HI_BYTE(addr); \
packet.data_hi = LO_BYTE(data); \
packet.data_lo = HI_BYTE(data); \
} while (0);
#define LBP16_INIT_PACKET8(packet, cmd, addr, data) do { \
packet.cmd_hi = LO_BYTE(cmd); \
packet.cmd_lo = HI_BYTE(cmd); \
packet.addr_hi = LO_BYTE(addr); \
packet.addr_lo = HI_BYTE(addr); \
packet.data1 = LO_BYTE(data); \
packet.data2 = HI_BYTE(data); \
packet.data3 = LO_BYTE((data >> 16) & 0xFFFF); \
packet.data4 = HI_BYTE((data >> 16) & 0xFFFF); \
} while (0);
typedef struct {
u16 cookie;
u16 size;
u16 range;
u16 addr;
u8 name[8];
} lbp_mem_info_area;
typedef struct {
u16 reserved1;
u16 mac_addr_lo;
u16 mac_addr_mid;
u16 mac_addr_hi;
u16 reserved2;
u16 reserved3;
u16 reserved4;
u16 reserved5;
u8 name[16];
u16 ip_addr_lo;
u16 ip_addr_hi;
u16 reserved6;
u16 reserved7;
u16 led_debug;
u16 reserved8;
u16 reserved9;
u16 reserved10;
} lbp_eth_eeprom_area;
typedef struct {
u16 uSTimeStampReg;
u16 WaituSReg;
u16 HM2Timeout;
} lbp_timers_area;
typedef struct {
u16 ErrorReg;
u16 LBPParseErrors;
u16 LBPMemErrors;
u16 LBPWriteErrors;
u16 RXPacketCount;
u16 RXGoodCount;
u16 RXBadCount;
u16 TXPacketCount;
u16 TXGoodCount;
u16 TXBadCount;
u16 led_mode;
u16 DebugLEDPtr;
u16 Scratch;
} lbp_status_area;
typedef struct {
u8 name[16];
u16 LBP16_version;
u16 firmware_version;
u16 jumpers;
} lbp_info_area;
typedef struct {
int (*send_packet)(void *packet, int size);
int (*recv_packet)(void *buffer, int size);
} lbp16_access_t;
void lbp16_init(int board_type);
void lbp16_cleanup(int board_type);
int lbp16_read(u16 cmd, u32 addr, void *buffer, int size);
int lbp16_write(u16 cmd, u32 addr, void *buffer, int size);
int lbp16_board_reset(llio_t *self);
int lbp16_board_reload(llio_t *self, int fallback_flag);
int lbp16_send_packet(void *packet, int size);
int lbp16_recv_packet(void *packet, int size);
#endif