1 |
2 |
dsmv |
|
2 |
|
|
#include <stdio.h>
|
3 |
|
|
#include <unistd.h>
|
4 |
|
|
#include <stdlib.h>
|
5 |
|
|
#include <string.h>
|
6 |
|
|
#include <ctype.h>
|
7 |
|
|
#include <time.h>
|
8 |
|
|
#include <errno.h>
|
9 |
|
|
#include <limits.h>
|
10 |
|
|
#include <stdarg.h>
|
11 |
|
|
#include <stdint.h>
|
12 |
|
|
#include <sys/types.h>
|
13 |
|
|
#include <sys/stat.h>
|
14 |
|
|
#include <sys/ioctl.h>
|
15 |
|
|
#include <sys/mman.h>
|
16 |
|
|
#include <fcntl.h>
|
17 |
|
|
|
18 |
6 |
v.karak |
#include "utypes_linux.h"
|
19 |
|
|
#include "brd_info.h"
|
20 |
2 |
dsmv |
#include "pexioctl.h"
|
21 |
|
|
#include "ambpexregs.h"
|
22 |
|
|
|
23 |
|
|
#define INSYS_VENDOR_ID 0x4953
|
24 |
|
|
#define AMBPEX8_DEVID 0x5503
|
25 |
|
|
#define ADP201X1AMB_DEVID 0x5504
|
26 |
|
|
#define ADP201X1DSP_DEVID 0x5505
|
27 |
|
|
#define AMBPEX5_DEVID 0x5507
|
28 |
|
|
|
29 |
|
|
//-----------------------------------------------------------------------------
|
30 |
|
|
|
31 |
|
|
void board_info(const struct board_info *bi);
|
32 |
|
|
void pld_info( uint32_t *base );
|
33 |
|
|
int board_init(uint32_t *base);
|
34 |
|
|
void ToPause(int ms);
|
35 |
|
|
|
36 |
|
|
//-----------------------------------------------------------------------------
|
37 |
|
|
uint32_t *bar0 = NULL;
|
38 |
|
|
uint32_t *bar1 = NULL;
|
39 |
|
|
//-----------------------------------------------------------------------------
|
40 |
|
|
|
41 |
|
|
int main(int argc, char *argv[])
|
42 |
|
|
{
|
43 |
|
|
int error = 0;
|
44 |
|
|
struct board_info bi;
|
45 |
|
|
struct memory_descriptor md;
|
46 |
|
|
struct memory_block *mb = NULL;
|
47 |
|
|
int fd = -1;
|
48 |
|
|
int N = 2;
|
49 |
|
|
|
50 |
|
|
if(argc == 1) {
|
51 |
|
|
fprintf(stderr, "usage: %s <device name>\n", argv[0]);
|
52 |
|
|
goto do_out;
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
fprintf(stderr, "Start testing device %s\n", argv[1]);
|
56 |
|
|
|
57 |
|
|
fd = open(argv[1], S_IROTH | S_IWOTH );
|
58 |
|
|
if(fd < 0) {
|
59 |
|
|
fprintf(stderr, "%s\n", strerror(errno));
|
60 |
|
|
goto do_out;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
error = ioctl(fd, IOCTL_PEX_BOARD_INFO, &bi);
|
64 |
|
|
if(error < 0) {
|
65 |
|
|
fprintf(stderr, "%s\n", strerror(errno));
|
66 |
|
|
goto do_close;
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
board_info(&bi);
|
70 |
|
|
|
71 |
|
|
mb = (struct memory_block*)malloc(N*sizeof(struct memory_block));
|
72 |
|
|
if(!mb) {
|
73 |
|
|
fprintf(stderr, "%s\n", strerror(errno));
|
74 |
|
|
goto do_close;
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
memset(mb, 0, N*sizeof(struct memory_block));
|
78 |
|
|
|
79 |
|
|
for(int i=0; i<N; i++) {
|
80 |
|
|
mb[i].size = 0x100000;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
md.blocks = mb;
|
84 |
|
|
md.total_blocks = N;
|
85 |
|
|
|
86 |
|
|
error = ioctl(fd, IOCTL_PEX_MEM_ALLOC, &md);
|
87 |
|
|
if(error < 0) {
|
88 |
|
|
fprintf(stderr, "%s\n", strerror(errno));
|
89 |
|
|
goto do_free_mem;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
for(int i=0; i<N; i++) {
|
93 |
|
|
fprintf(stderr, "%d: PA = 0x%zx\n", i, mb[i].phys);
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
fprintf(stderr, "Press Enter to free memory...\n");
|
97 |
|
|
getchar();
|
98 |
|
|
|
99 |
|
|
error = ioctl(fd, IOCTL_PEX_MEM_FREE, &md);
|
100 |
|
|
if(error < 0) {
|
101 |
|
|
fprintf(stderr, "%s\n", strerror(errno));
|
102 |
|
|
goto do_free_mem;
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
goto do_free_mem;
|
106 |
|
|
|
107 |
|
|
bar0 = (uint32_t*)mmap(NULL, bi.Size[0], PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)bi.PhysAddress[0]);
|
108 |
|
|
if( bar0 == MAP_FAILED ) {
|
109 |
|
|
fprintf(stderr, "%s\n", strerror(errno));
|
110 |
|
|
error = -EINVAL;
|
111 |
|
|
goto do_close;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
bar1 = (uint32_t*)mmap(NULL, bi.Size[1], PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)bi.PhysAddress[1]);
|
115 |
|
|
if( bar1== MAP_FAILED ) {
|
116 |
|
|
fprintf(stderr, "%s\n", strerror(errno));
|
117 |
|
|
error = -EINVAL;
|
118 |
|
|
goto do_unmap_bar0;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
fprintf(stderr, "Map BAR0 0x%zx -> %p\n", bi.PhysAddress[0], bar0);
|
122 |
|
|
fprintf(stderr, "Map BAR1 0x%zx -> %p\n", bi.PhysAddress[1], bar1);
|
123 |
|
|
|
124 |
|
|
for(int i=0; i<16; i++) {
|
125 |
|
|
fprintf(stderr, "%d: 0x%x\n", i, bar0[i]);
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
board_init(bar0);
|
129 |
|
|
|
130 |
|
|
//pld_info(bar1);
|
131 |
|
|
|
132 |
|
|
error = 0;
|
133 |
|
|
|
134 |
|
|
//do_unmap_bar1:
|
135 |
|
|
munmap(bar1, bi.Size[1]);
|
136 |
|
|
|
137 |
|
|
do_unmap_bar0:
|
138 |
|
|
munmap(bar0, bi.Size[0]);
|
139 |
|
|
|
140 |
|
|
do_free_mem:
|
141 |
|
|
free(mb);
|
142 |
|
|
|
143 |
|
|
do_close:
|
144 |
|
|
close(fd);
|
145 |
|
|
|
146 |
|
|
do_out:
|
147 |
|
|
return error;
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
//-----------------------------------------------------------------------------
|
151 |
|
|
|
152 |
|
|
void board_info(const struct board_info *bi)
|
153 |
|
|
{
|
154 |
|
|
if(!bi) return;
|
155 |
|
|
|
156 |
|
|
fprintf(stderr, "VENDOR ID: 0x%X\n", bi->vendor_id);
|
157 |
|
|
fprintf(stderr, "DEVICE ID: 0x%X\n", bi->device_id);
|
158 |
|
|
fprintf(stderr, "BAR0: 0x%zX\n", bi->PhysAddress[0]);
|
159 |
|
|
fprintf(stderr, "SIZE: 0x%zX\n", bi->Size[0]);
|
160 |
|
|
fprintf(stderr, "BAR1 0x%zX\n", bi->PhysAddress[1]);
|
161 |
|
|
fprintf(stderr, "SIZE: 0x%zX\n", bi->Size[1]);
|
162 |
|
|
fprintf(stderr, "IRQ: 0x%zX\n", bi->InterruptVector);
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
//-----------------------------------------------------------------------------
|
166 |
|
|
|
167 |
|
|
void memory_info(const struct memory_descriptor *md)
|
168 |
|
|
{
|
169 |
|
|
if(!md) return;
|
170 |
|
|
if(!md->blocks) return;
|
171 |
|
|
|
172 |
|
|
for(unsigned i=0; i<md->total_blocks; i++) {
|
173 |
|
|
|
174 |
|
|
struct memory_block *b = &md->blocks[i];
|
175 |
|
|
fprintf(stderr, "%d - kernel virtual: %p, kernel physical: %p \n", i, b->virt, (void*)b->phys);
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
//-----------------------------------------------------------------------------
|
180 |
|
|
|
181 |
|
|
uint16_t ReadOperationWordReg(uint32_t *base, uint32_t port)
|
182 |
|
|
{
|
183 |
|
|
return *((uint16_t*)((uint8_t*)base + port));
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
//-----------------------------------------------------------------------------
|
187 |
|
|
|
188 |
|
|
void WriteOperationWordReg(uint32_t *base, uint32_t port, uint16_t value)
|
189 |
|
|
{
|
190 |
|
|
*((uint16_t*)((uint8_t*)base + port)) = value;
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
//-----------------------------------------------------------------------------
|
194 |
|
|
|
195 |
|
|
uint32_t ReadAmbReg(uint32_t *base, uint32_t AdmNumber, uint32_t RelativePort)
|
196 |
|
|
{
|
197 |
|
|
uint8_t* pBaseAddress = (uint8_t*)base + AdmNumber * ADM_SIZE;
|
198 |
|
|
return *((uint32_t*)(pBaseAddress + RelativePort));
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
//-----------------------------------------------------------------------------
|
202 |
|
|
|
203 |
|
|
uint32_t ReadAmbMainReg(uint32_t *base, uint32_t RelativePort)
|
204 |
|
|
{
|
205 |
|
|
return *((uint32_t*)((uint8_t*)base + RelativePort));
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
//-----------------------------------------------------------------------------
|
209 |
|
|
|
210 |
|
|
void WriteAmbReg(uint32_t *base, uint32_t AdmNumber, uint32_t RelativePort, uint32_t value)
|
211 |
|
|
{
|
212 |
|
|
uint8_t* pBaseAddress = (uint8_t*)base + AdmNumber * ADM_SIZE;
|
213 |
|
|
*((uint32_t*)(pBaseAddress + RelativePort)) = value;
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
//-----------------------------------------------------------------------------
|
217 |
|
|
|
218 |
|
|
void WriteAmbMainReg(uint32_t *base, uint32_t RelativePort, uint32_t value)
|
219 |
|
|
{
|
220 |
|
|
*((uint32_t*)((uint8_t*)base + RelativePort)) = value;
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
//-----------------------------------------------------------------------------
|
224 |
|
|
|
225 |
|
|
int WaitCmdReady(uint32_t *base, uint32_t AdmNumber, uint32_t StatusAddress)
|
226 |
|
|
{
|
227 |
|
|
int pass_count = 0;
|
228 |
|
|
uint32_t cmd_rdy;
|
229 |
|
|
|
230 |
|
|
//fprintf(stderr,"%s()\n", __FUNCTION__);
|
231 |
|
|
|
232 |
|
|
do {
|
233 |
|
|
|
234 |
|
|
cmd_rdy = ReadAmbReg(base, AdmNumber, StatusAddress);
|
235 |
|
|
cmd_rdy &= AMB_statCMDRDY; //HOST_statCMDRDY;
|
236 |
|
|
|
237 |
|
|
if(pass_count < 10) {
|
238 |
|
|
|
239 |
|
|
pass_count++;
|
240 |
|
|
ToPause(1);
|
241 |
|
|
|
242 |
|
|
} else {
|
243 |
|
|
return -1;
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
} while(!cmd_rdy);
|
247 |
|
|
|
248 |
|
|
return 0;
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
//-----------------------------------------------------------------------------
|
252 |
|
|
|
253 |
|
|
int WriteRegData(uint32_t *base, uint32_t AdmNumber, uint32_t TetrNumber, uint32_t RegNumber, uint32_t value)
|
254 |
|
|
{
|
255 |
|
|
int Status = 0;
|
256 |
|
|
uint32_t Address = TetrNumber * TETRAD_SIZE;
|
257 |
|
|
uint32_t CmdAddress = Address + TRDadr_CMD_ADR * REG_SIZE;
|
258 |
|
|
uint32_t DataAddress = Address + TRDadr_CMD_DATA * REG_SIZE;
|
259 |
|
|
uint32_t StatusAddress = Address + TRDadr_STATUS * REG_SIZE;
|
260 |
|
|
|
261 |
|
|
WriteAmbReg(base, AdmNumber, CmdAddress, RegNumber);
|
262 |
|
|
|
263 |
|
|
Status = WaitCmdReady(base, AdmNumber, StatusAddress); // wait CMD_RDY
|
264 |
|
|
if(Status != 0) {
|
265 |
|
|
fprintf(stderr,"%s(): ERROR wait cmd ready.\n", __FUNCTION__);
|
266 |
|
|
return Status;
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
WriteAmbReg(base, AdmNumber, DataAddress, value);
|
270 |
|
|
|
271 |
|
|
//fprintf(stderr,"%s(): Adm = %d, Tetr = %d, Reg = %d\n", __FUNCTION__,
|
272 |
|
|
// AdmNumber, TetrNumber, RegNumber);
|
273 |
|
|
|
274 |
|
|
return Status;
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
//-----------------------------------------------------------------------------
|
278 |
|
|
|
279 |
|
|
int ReadRegData(uint32_t *base, uint32_t AdmNumber, uint32_t TetrNumber, uint32_t RegNumber, uint32_t *Value)
|
280 |
|
|
{
|
281 |
|
|
int Status = 0;
|
282 |
|
|
uint32_t Address = TetrNumber * TETRAD_SIZE;
|
283 |
|
|
uint32_t CmdAddress = Address + TRDadr_CMD_ADR * REG_SIZE;
|
284 |
|
|
uint32_t StatusAddress = Address + TRDadr_STATUS * REG_SIZE;
|
285 |
|
|
uint32_t DataAddress = Address + TRDadr_CMD_DATA * REG_SIZE;
|
286 |
|
|
|
287 |
|
|
WriteAmbReg(base, AdmNumber, CmdAddress, RegNumber);
|
288 |
|
|
|
289 |
|
|
Status = WaitCmdReady(base, AdmNumber, StatusAddress); // wait CMD_RDY
|
290 |
|
|
if(Status != 0) {
|
291 |
|
|
fprintf(stderr,"%s(): ERROR wait cmd ready.\n", __FUNCTION__);
|
292 |
|
|
return Status;
|
293 |
|
|
}
|
294 |
|
|
|
295 |
|
|
*Value = ReadAmbReg(base, AdmNumber, DataAddress);
|
296 |
|
|
|
297 |
|
|
//fprintf(stderr,"%s(): Adm = %d, Tetr = %d, Reg = %d, Val = %x\n", __FUNCTION__,
|
298 |
|
|
// AdmNumber, TetrNumber, RegNumber, (int)*Value);
|
299 |
|
|
|
300 |
|
|
return Status;
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
//-----------------------------------------------------------------------------
|
304 |
|
|
|
305 |
|
|
uint32_t RegPeekInd(uint32_t *base, uint32_t trdNo, uint32_t rgnum)
|
306 |
|
|
{
|
307 |
|
|
uint32_t Value = 0;
|
308 |
|
|
|
309 |
|
|
ReadRegData(base, 0, trdNo, rgnum, &Value);
|
310 |
|
|
|
311 |
|
|
return Value;
|
312 |
|
|
}
|
313 |
|
|
|
314 |
|
|
//-----------------------------------------------------------------------------
|
315 |
|
|
|
316 |
|
|
int RegPokeDir( uint32_t *base, uint32_t TetrNumber, uint32_t RegNumber, uint32_t Value )
|
317 |
|
|
{
|
318 |
|
|
uint32_t Address;
|
319 |
|
|
|
320 |
|
|
Address = TetrNumber * TETRAD_SIZE;
|
321 |
|
|
RegNumber = RegNumber & 0x3;
|
322 |
|
|
|
323 |
|
|
Address += RegNumber * REG_SIZE;
|
324 |
|
|
|
325 |
|
|
WriteAmbReg(base, 0, Address, Value);
|
326 |
|
|
|
327 |
|
|
return 0;
|
328 |
|
|
}
|
329 |
|
|
|
330 |
|
|
//-----------------------------------------------------------------------------
|
331 |
|
|
|
332 |
|
|
void ToPause(int ms)
|
333 |
|
|
{
|
334 |
|
|
struct timeval tv = {0, 0};
|
335 |
|
|
tv.tv_usec = 1000*ms;
|
336 |
|
|
|
337 |
|
|
select(0,NULL,NULL,NULL,&tv);
|
338 |
|
|
}
|
339 |
|
|
|
340 |
|
|
//-----------------------------------------------------------------------------
|
341 |
|
|
|
342 |
|
|
int board_init(uint32_t *base)
|
343 |
|
|
{
|
344 |
|
|
u16 temp = 0;
|
345 |
|
|
u16 blockId = 0;
|
346 |
|
|
u16 blockVer = 0;
|
347 |
|
|
u16 deviceID = 0;
|
348 |
|
|
u16 deviceRev = 0;
|
349 |
|
|
int i = 0;
|
350 |
|
|
|
351 |
|
|
blockId = ReadOperationWordReg(base, PEMAINadr_BLOCK_ID);
|
352 |
|
|
blockVer = ReadOperationWordReg(base, PEMAINadr_BLOCK_VER);
|
353 |
|
|
|
354 |
|
|
fprintf(stderr,"%s(): BlockID = 0x%X, BlockVER = 0x%X.\n", __FUNCTION__, blockId, blockVer);
|
355 |
|
|
|
356 |
|
|
deviceID = ReadOperationWordReg(base, PEMAINadr_DEVICE_ID);
|
357 |
|
|
deviceRev = ReadOperationWordReg(base, PEMAINadr_DEVICE_REV);
|
358 |
|
|
|
359 |
|
|
fprintf(stderr,"%s(): DeviceID = 0x%X, DeviceRev = 0x%X.\n", __FUNCTION__, deviceID, deviceRev);
|
360 |
|
|
|
361 |
|
|
if((AMBPEX8_DEVID != deviceID) &&
|
362 |
|
|
(ADP201X1AMB_DEVID != deviceID) &&
|
363 |
|
|
(AMBPEX5_DEVID != deviceID))
|
364 |
|
|
return -ENODEV;
|
365 |
|
|
|
366 |
|
|
temp = ReadOperationWordReg(base, PEMAINadr_PLD_VER);
|
367 |
|
|
int m_BlockCnt = ReadOperationWordReg(base, PEMAINadr_BLOCK_CNT);
|
368 |
|
|
|
369 |
|
|
fprintf(stderr,"%s(): PldVER = 0x%X.\n", __FUNCTION__, temp);
|
370 |
|
|
fprintf(stderr,"%s(): Block count = %d.\n", __FUNCTION__, m_BlockCnt);
|
371 |
|
|
|
372 |
|
|
// определим какие каналы ПДП присутствуют и их характеристики:
|
373 |
|
|
// направление передачи данных, размер FIFO, максимальный размер блока ПДП
|
374 |
|
|
|
375 |
|
|
FIFO_ID FifoId;
|
376 |
|
|
int m_DmaFifoSize[4] = {0};
|
377 |
|
|
int m_MaxDmaSize[4] = {0};
|
378 |
|
|
//int m_FifoAddr[4] = {0};
|
379 |
|
|
//int m_BlockFifoId[4] = {0};
|
380 |
|
|
int m_DmaDir[4] = {0};
|
381 |
|
|
int m_DmaChanMask = 0;
|
382 |
|
|
|
383 |
|
|
for(int iBlock = 0; iBlock < m_BlockCnt; iBlock++)
|
384 |
|
|
{
|
385 |
|
|
uint32_t FifoAddr = 0;
|
386 |
|
|
u16 block_id = 0;
|
387 |
|
|
FifoAddr = (iBlock + 1) * PE_FIFO_ADDR;
|
388 |
|
|
temp = ReadOperationWordReg(base, PEFIFOadr_BLOCK_ID + FifoAddr);
|
389 |
|
|
block_id = (temp & 0x0FFF);
|
390 |
|
|
if(block_id == PE_FIFO_ID)
|
391 |
|
|
{
|
392 |
|
|
u64 one = 0;
|
393 |
|
|
u64 maxdmasize = 0;
|
394 |
|
|
u16 iChan = ReadOperationWordReg(base, PEFIFOadr_FIFO_NUM + FifoAddr);
|
395 |
|
|
//m_FifoAddr[iChan] = FifoAddr;
|
396 |
|
|
//m_BlockFifoId[iChan] = block_id;
|
397 |
|
|
m_DmaChanMask |= (1 << iChan);
|
398 |
|
|
FifoId.AsWhole = ReadOperationWordReg(base, PEFIFOadr_FIFO_ID + FifoAddr);
|
399 |
|
|
m_DmaFifoSize[iChan] = FifoId.ByBits.Size;
|
400 |
|
|
m_DmaDir[iChan] = FifoId.ByBits.Dir;
|
401 |
|
|
temp = ReadOperationWordReg(base, PEFIFOadr_DMA_SIZE + FifoAddr);
|
402 |
|
|
|
403 |
|
|
one = 1;
|
404 |
|
|
maxdmasize = one << temp;
|
405 |
|
|
// если макс. размер ПДП может быть больше или равен 4 Гбайт, то снижаем его до 1 Гбайта
|
406 |
|
|
if(temp >= 32)
|
407 |
|
|
m_MaxDmaSize[iChan] = 0x40000000;
|
408 |
|
|
else
|
409 |
|
|
m_MaxDmaSize[iChan] = (uint32_t)maxdmasize;
|
410 |
|
|
|
411 |
|
|
fprintf(stderr,"%s(): Channel(ID) = %d(0x%x), FIFO size = %d Bytes, DMA Dir = %d,\n", __FUNCTION__,
|
412 |
|
|
iChan, block_id, m_DmaFifoSize[iChan] * 4, m_DmaDir[iChan]);
|
413 |
|
|
fprintf(stderr,"%s(): Max DMA size (hard) = %d MBytes, Max DMA size (soft) = %d MBytes.\n", __FUNCTION__,
|
414 |
|
|
(uint32_t)(maxdmasize / 1024 / 1024), m_MaxDmaSize[iChan] / 1024 / 1024);
|
415 |
|
|
}
|
416 |
|
|
if(block_id == PE_EXT_FIFO_ID)
|
417 |
|
|
{
|
418 |
|
|
uint32_t resource_id = 0;
|
419 |
|
|
u16 iChan = ReadOperationWordReg(base, PEFIFOadr_FIFO_NUM + FifoAddr);
|
420 |
|
|
//m_FifoAddr[iChan] = FifoAddr;
|
421 |
|
|
//m_BlockFifoId[iChan] = block_id;
|
422 |
|
|
m_DmaChanMask |= (1 << iChan);
|
423 |
|
|
FifoId.AsWhole = ReadOperationWordReg(base, PEFIFOadr_FIFO_ID + FifoAddr);
|
424 |
|
|
m_DmaFifoSize[iChan] = FifoId.ByBits.Size;
|
425 |
|
|
m_DmaDir[iChan] = FifoId.ByBits.Dir;
|
426 |
|
|
m_MaxDmaSize[iChan] = 0x40000000; // макс. размер ПДП пусть будет 1 Гбайт
|
427 |
|
|
resource_id = ReadOperationWordReg(base, PEFIFOadr_DMA_SIZE + FifoAddr); // RESOURCE
|
428 |
|
|
fprintf(stderr,"%s(): Channel(ID) = %d(0x%x), FIFO size = %d Bytes, DMA Dir = %d, Max DMA size = %d MBytes, resource = 0x%x.\n", __FUNCTION__,
|
429 |
|
|
iChan, block_id, m_DmaFifoSize[iChan] * 4, m_DmaDir[iChan], m_MaxDmaSize[iChan] / 1024 / 1024, resource_id);
|
430 |
|
|
}
|
431 |
|
|
}
|
432 |
|
|
|
433 |
|
|
// подготовим к работе ПЛИС ADM
|
434 |
|
|
fprintf(stderr,"%s(): Prepare ADM PLD.\n", __FUNCTION__);
|
435 |
|
|
WriteOperationWordReg(base,PEMAINadr_BRD_MODE, 0);
|
436 |
|
|
ToPause(100); // pause ~ 100 msec
|
437 |
|
|
for(i = 0; i < 10; i++)
|
438 |
|
|
{
|
439 |
|
|
WriteOperationWordReg(base, PEMAINadr_BRD_MODE, 1);
|
440 |
|
|
ToPause(100); // pause ~ 100 msec
|
441 |
|
|
WriteOperationWordReg(base, PEMAINadr_BRD_MODE, 3);
|
442 |
|
|
ToPause(100); // pause ~ 100 msec
|
443 |
|
|
WriteOperationWordReg(base, PEMAINadr_BRD_MODE, 7);
|
444 |
|
|
ToPause(100); // pause ~ 100 msec
|
445 |
|
|
temp = ReadOperationWordReg(base, PEMAINadr_BRD_STATUS) & 0x01;
|
446 |
|
|
if(temp)
|
447 |
|
|
break;
|
448 |
|
|
}
|
449 |
|
|
WriteOperationWordReg(base, PEMAINadr_BRD_MODE, 0x0F);
|
450 |
|
|
ToPause(100); // pause ~ 100 msec
|
451 |
|
|
|
452 |
|
|
if(temp)
|
453 |
|
|
{
|
454 |
|
|
uint32_t idx = 0;
|
455 |
|
|
BRD_STATUS brd_status;
|
456 |
|
|
fprintf(stderr,"%s(): ADM PLD is captured.\n", __FUNCTION__);
|
457 |
|
|
brd_status.AsWhole = ReadOperationWordReg(base, PEMAINadr_BRD_STATUS);
|
458 |
|
|
brd_status.ByBits.InFlags &= 0x80; // 1 - ADM PLD in test mode
|
459 |
|
|
if(brd_status.ByBits.InFlags)
|
460 |
|
|
{
|
461 |
|
|
BRD_MODE brd_mode;
|
462 |
|
|
fprintf(stderr,"%s(): ADM PLD in test mode.\n", __FUNCTION__);
|
463 |
|
|
|
464 |
|
|
// проверка линий передачи флагов
|
465 |
|
|
brd_mode.AsWhole = ReadOperationWordReg(base, PEMAINadr_BRD_MODE);
|
466 |
|
|
for(idx = 0; idx < 4; idx++)
|
467 |
|
|
{
|
468 |
|
|
brd_mode.ByBits.OutFlags = idx;
|
469 |
|
|
WriteOperationWordReg(base, PEMAINadr_BRD_MODE, brd_mode.AsWhole);
|
470 |
|
|
ToPause(10);
|
471 |
|
|
brd_status.AsWhole = ReadOperationWordReg(base, PEMAINadr_BRD_STATUS);
|
472 |
|
|
brd_status.ByBits.InFlags &= 0x03;
|
473 |
|
|
if(brd_mode.ByBits.OutFlags != brd_status.ByBits.InFlags)
|
474 |
|
|
{
|
475 |
|
|
temp = 0;
|
476 |
|
|
fprintf(stderr,"%s(): FLG_IN (%d) NOT equ FLG_OUT (%d).\n", __FUNCTION__,
|
477 |
|
|
brd_status.ByBits.InFlags, brd_mode.ByBits.OutFlags);
|
478 |
|
|
break;
|
479 |
|
|
}
|
480 |
|
|
}
|
481 |
|
|
if(temp)
|
482 |
|
|
fprintf(stderr,"%s(): FLG_IN equ FLG_OUT.\n", __FUNCTION__);
|
483 |
|
|
}
|
484 |
|
|
else
|
485 |
|
|
temp = 0;
|
486 |
|
|
}
|
487 |
|
|
|
488 |
|
|
if(!temp)
|
489 |
|
|
{
|
490 |
|
|
WriteOperationWordReg(base, PEMAINadr_BRD_MODE, 0);
|
491 |
|
|
ToPause(100); // pause ~ 100 msec
|
492 |
|
|
}
|
493 |
|
|
|
494 |
|
|
|
495 |
|
|
// состояние ПЛИС ADM: 0 - не готова
|
496 |
|
|
fprintf(stderr,"%s(): ADM PLD[%d] status = 0x%X.\n", __FUNCTION__, i, temp);
|
497 |
|
|
|
498 |
|
|
{
|
499 |
|
|
BRD_MODE brd_mode;
|
500 |
|
|
brd_mode.AsWhole = ReadOperationWordReg(base, PEMAINadr_BRD_MODE);
|
501 |
|
|
brd_mode.ByBits.OutFlags = 0;
|
502 |
|
|
WriteOperationWordReg(base, PEMAINadr_BRD_MODE, brd_mode.AsWhole);
|
503 |
|
|
fprintf(stderr,"%s(): BRD_MODE = 0x%X.\n", __FUNCTION__, brd_mode.AsWhole);
|
504 |
|
|
}
|
505 |
|
|
|
506 |
|
|
WriteOperationWordReg(base, PEMAINadr_IRQ_MASK, 0x4000);
|
507 |
|
|
|
508 |
|
|
//WriteAmbMainReg(base, 0x0, 0x1);
|
509 |
|
|
//WriteAmbMainReg(base, 0x0, 0x1);
|
510 |
|
|
|
511 |
|
|
return 0;
|
512 |
|
|
}
|
513 |
|
|
|
514 |
|
|
//-----------------------------------------------------------------------------
|
515 |
|
|
|
516 |
|
|
void pld_info( uint32_t *base )
|
517 |
|
|
{
|
518 |
|
|
uint32_t d = 0;
|
519 |
|
|
uint32_t d1 = 0;
|
520 |
|
|
uint32_t d2 = 0;
|
521 |
|
|
uint32_t d3 = 0;
|
522 |
|
|
uint32_t d4 = 0;
|
523 |
|
|
uint32_t d5 = 0;
|
524 |
|
|
int ii = 0;
|
525 |
|
|
|
526 |
|
|
if(!base) return;
|
527 |
|
|
|
528 |
|
|
fprintf(stderr,"Прошивка ПЛИС ADM\n" );
|
529 |
|
|
|
530 |
|
|
RegPokeDir( base, 0, 1, 1 );
|
531 |
|
|
|
532 |
|
|
d=RegPeekInd( base, 0, 0x108 );
|
533 |
|
|
if( d==0x4953 ) {
|
534 |
|
|
fprintf(stderr, " SIG= 0x%.4X - Ok \n", d );
|
535 |
|
|
} else {
|
536 |
|
|
fprintf(stderr, " SIG= 0x%.4X - Ошибка, ожидается 0x4953 \n", d );
|
537 |
|
|
return;
|
538 |
|
|
}
|
539 |
|
|
|
540 |
|
|
d=RegPeekInd( base, 0, 0x109 ); fprintf(stderr, " Версия интерфейса ADM: %d.%d\n", d>>8, d&0xFF );
|
541 |
|
|
d=RegPeekInd( base, 0, 0x110 ); d1=RegPeekInd( base, 0, 0x111 );
|
542 |
|
|
fprintf(stderr, " Базовый модуль: 0x%.4X v%d.%d\n", d, d1>>8, d1&0xFF );
|
543 |
|
|
|
544 |
|
|
d=RegPeekInd( base, 0, 0x112 ); d1=RegPeekInd( base, 0, 0x113 );
|
545 |
|
|
fprintf(stderr, " Субмодуль: 0x%.4X v%d.%d\n", d, d1>>8, d1&0xFF );
|
546 |
|
|
|
547 |
|
|
d=RegPeekInd( base, 0, 0x10B ); fprintf(stderr, " Модификация прошивки ПЛИС: %d \n", d );
|
548 |
|
|
d=RegPeekInd( base, 0, 0x10A ); fprintf(stderr, " Версия прошивки ПЛИС: %d.%d\n", d>>8, d&0xFF );
|
549 |
|
|
d=RegPeekInd( base, 0, 0x114 ); fprintf(stderr, " Номер сборки прошивки ПЛИС: 0x%.4X\n", d );
|
550 |
|
|
|
551 |
|
|
fprintf(stderr, "\nИнформация о тетрадах:\n\n" );
|
552 |
|
|
for( ii=0; ii<8; ii++ ) {
|
553 |
|
|
|
554 |
|
|
const char *str;
|
555 |
|
|
|
556 |
|
|
d=RegPeekInd( base, ii, 0x100 );
|
557 |
|
|
d1=RegPeekInd( base, ii, 0x101 );
|
558 |
|
|
d2=RegPeekInd( base, ii, 0x102 );
|
559 |
|
|
d3=RegPeekInd( base, ii, 0x103 );
|
560 |
|
|
d4=RegPeekInd( base, ii, 0x104 );
|
561 |
|
|
d5=RegPeekInd( base, ii, 0x105 );
|
562 |
|
|
|
563 |
|
|
switch( d ) {
|
564 |
|
|
case 1: str="TRD_MAIN "; break;
|
565 |
|
|
case 2: str="TRD_BASE_DAC "; break;
|
566 |
|
|
case 3: str="TRD_PIO_STD "; break;
|
567 |
|
|
case 0: str=" - "; break;
|
568 |
|
|
case 0x47: str="SBSRAM_IN "; break;
|
569 |
|
|
case 0x48: str="SBSRAM_OUT "; break;
|
570 |
|
|
case 0x12: str="DIO64_OUT "; break;
|
571 |
|
|
case 0x13: str="DIO64_IN "; break;
|
572 |
|
|
case 0x14: str="ADM212x200M "; break;
|
573 |
|
|
case 0x5D: str="ADM212x500M "; break;
|
574 |
|
|
case 0x41: str="DDS9956 "; break;
|
575 |
|
|
case 0x4F: str="TEST_CTRL "; break;
|
576 |
|
|
case 0x3F: str="ADM214x200M "; break;
|
577 |
|
|
case 0x40: str="ADM216x100 "; break;
|
578 |
|
|
case 0x2F: str="ADM28x1G "; break;
|
579 |
|
|
case 0x2D: str="TRD128_OUT "; break;
|
580 |
|
|
case 0x4C: str="TRD128_IN "; break;
|
581 |
|
|
case 0x30: str="ADMDDC5016 "; break;
|
582 |
|
|
case 0x2E: str="ADMFOTR2G "; break;
|
583 |
|
|
case 0x49: str="ADMFOTR3G "; break;
|
584 |
|
|
case 0x67: str="DDS9912 "; break;
|
585 |
|
|
case 0x70: str="AMBPEX5_SDRAM "; break;
|
586 |
|
|
case 0x71: str="TRD_MSG "; break;
|
587 |
|
|
case 0x72: str="TRD_TS201 "; break;
|
588 |
|
|
case 0x73: str="TRD_STREAM_IN "; break;
|
589 |
|
|
case 0x74: str="TRD_STREAM_OUT"; break;
|
590 |
|
|
|
591 |
|
|
|
592 |
|
|
default: str="UNKNOW "; break;
|
593 |
|
|
}
|
594 |
|
|
fprintf(stderr, " %d 0x%.4X %s ", ii, d, str );
|
595 |
|
|
if( d>0 ) {
|
596 |
|
|
fprintf(stderr, " MOD: %-2d VER: %d.%d ", d1, d2>>8, d2&0xFF );
|
597 |
|
|
if( d3 & 0x10 ) {
|
598 |
|
|
fprintf(stderr, "FIFO IN %dx%d\n", d4, d5 );
|
599 |
|
|
} else if( d3 & 0x20 ) {
|
600 |
|
|
fprintf(stderr, "FIFO OUT %dx%d\n", d4, d5 );
|
601 |
|
|
} else {
|
602 |
|
|
fprintf(stderr, "\n" );
|
603 |
|
|
}
|
604 |
|
|
} else {
|
605 |
|
|
fprintf(stderr, "\n" );
|
606 |
|
|
}
|
607 |
|
|
|
608 |
|
|
}
|
609 |
|
|
}
|
610 |
|
|
|
611 |
|
|
//-----------------------------------------------------------------------------
|