Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/drivers/ad9371/mykonos_debug/mykonos_dbgjesd.c

raw symbols SCIP
1 /**
2 * \file mykonos_dbgjesd.c
3 *
4 * \brief Contains Mykonos APIs for Jesd debug facilities.
5 *
6 * Mykonos API version: 1.3.1.3534
7 */
8
9 #include <stdint.h>
10 #include <stddef.h>
11
12 #include "mykonos_dbgjesd.h"
13 #include "mykonos_macros.h"
14
15
16 /**
17 * \brief Helper function for return of character string based on 32-bit mykonosDbgErr_t enum value
18 *
19 * To save codespace, these error strings are ifdef'd out unless the user
20 * adds a define MYKONOS_VERBOSE to their workspace. This function can be
21 * useful for debug. Each function also returns unique error codes to
22 * make it easier to determine where the code broke.
23 *
24 * \param errorCode is enumerated error code value
25 *
26 * \return Returns character string based on enumerated value
27 */
28 const char* getDbgJesdMykonosErrorMessage(mykonosDbgErr_t errorCode)
29 {
30
31 #if MYKONOS_VERBOSE == 0
32 return "";
33 #else
34
35 switch (errorCode)
36 {
37 case MYKONOS_ERR_DBG_OK:
38 return "No error\n";
39
40 case MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER:
41 return "Pointer to passed parameter is NULL\n";
42
43 case MYKONOS_ERR_DBG_ILLEGAL_JESD_CORE:
44 return "Illegal JESD core passed, valid options for the JESD code are in mykonos_jesdcore_t\n";
45
46 case MYKONOS_ERR_DBG_ILLEGAL_ERROR_TYPE:
47 return "Illegal error type passed, valid error types are given in mykonosErrType_t\n";
48
49 case MYKONOS_ERR_DBG_ILLEGAL_ERROR_SELECTED:
50 return "Illegal errType passed, valid errType are BADDISP, NIT and UEKC\n";
51
52 case MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER:
53 return "Illegal lane number passed, valid lanes are given in mykonosLaneSel_t\n";
54
55 case MYKONOS_ERR_DBG_ERROR_THRESHOLD:
56 return "Illegal error threshold passed, valid error thresholds are in the range 0x00 to 0xFF\n";
57
58 case MYKONOS_ERR_DBG_ERROR_SYNC_MASK:
59 return "Illegal Sync Mask passed, valid Sync Masks are in the range 0x00 to 0x07\n";
60
61 case MYKONOS_ERR_DBG_ERROR_IRQ_MASK:
62 return "Illegal IRQ mask passed, valid IRQ Masks are in the range 0x00 to 0x1FF\n";
63
64 case MYKONOS_ERR_DBG_PATTERN_GEN_NULL_PATTERN:
65 return "Function parameter pattern is a NULL pointer\n";
66
67 case MYKONOS_ERR_DBG_PATTERN_GEN_NULL_ENABLE:
68 return "Function parameter enable is a NULL pointer\n";
69
70 case MYKONOS_ERR_DBG_PATTERN_GEN_NULL_TOGGLE:
71 return "Function parameter toggle is a NULL pointer\n";
72
73 case MYKONOS_ERR_DBG_ILLEGAL_TOGGLE:
74 return "Toggle is not valid, valid values are 0 and 1.\n";
75
76 case MYKONOS_ERR_DBG_ILLEGAL_FRAMER_PATTERN:
77 return "Pattern passed is outside the range valid range from 0x00000 to 0xFFFFF\n";
78
79 case MYKONOS_ERR_DBG_ILLEGAL_ENABLE:
80 return "Enable not valid, valid values are 0 and 1.\n";
81
82 case MYKONOS_ERR_DBG_ZERO_DATA_INV_LANE:
83 return "the lane selection is out of range, valid range is 0x00 to 0x0F in MYKONOS_framerSetZeroData().\n";
84
85 case MYKONOS_ERR_DBG_ZERO_DATA_LANE_NULL:
86 return "Function parameter lane is a NULL pointer passed to MYKONOS_framerGetZeroData().\n";
87
88 case MYKONOS_ERR_DBG_FRAMER_SEL_BASE_ADD_NULL:
89 return "base address is null in MYKONOS_framerCoreSel().\n";
90
91 case MYKONOS_ERR_DBG_FRAMER_ILLEGAL_JESD_CORE:
92 return "Only valid JESD cores are FRAMER and OBS_FRAMER in MYKONOS_framerCoreSel().\n";
93
94 default:
95 return "";
96 }
97
98 #endif
99 }
100
101 /**
102 * \brief Performs indirect write access to internal JESD register.
103 *
104 * <B>Dependencies</B>
105 * - device->spiSettings->chipSelectIndex
106 *
107 * \param device Pointer to Mykonos device data structure containing settings
108 * \param jesdCore JESD core selection
109 * \param intAddr Internal address to access in JESD core
110 * \param data Data to write into internal address
111 *
112 * \retval MYKONOS_ERR_OK Function completed successfully
113 * \retval MYKONOS_ERR_DBG_ILLEGAL_JESD_CORE An illegal JESD core passed, valid cores are given in mykonos_jesdcore_t
114 */
115 mykonosDbgErr_t MYKONOS_jesdIndWrReg(mykonosDevice_t *device, mykonos_jesdcore_t jesdCore, uint8_t intAddr, uint8_t data)
116 {
117 uint16_t baseAddr = 0;
118
119 #if (MYKONOS_VERBOSE == 1)
120 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdIndWrReg()\n");
121 #endif
122
123 /* Check for jesdCore and address assignment */
124 switch (jesdCore)
125 {
126 case MYK_FRAMER:
127 baseAddr = MYKONOS_ADDR_FRAMER_ADDR;
128 break;
129
130 case MYK_DEFRAMER:
131 baseAddr = MYKONOS_ADDR_DEFRAMER_ADDR;
132 break;
133
134 case MYK_OBS_FRAMER:
135 baseAddr = MYKONOS_ADDR_OBS_FRAMER_ADDR;
136 break;
137
138 default:
139 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_JESD_CORE,
140 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_JESD_CORE));
141 return MYKONOS_ERR_DBG_ILLEGAL_JESD_CORE;
142 break;
143 }
144
145 /* Perform indirect write */
146 CMB_SPIWriteByte(device->spiSettings, baseAddr, intAddr);
147 CMB_SPIWriteByte(device->spiSettings, baseAddr + 1, data);
148 CMB_SPIWriteByte(device->spiSettings, baseAddr + 2, 0x01);
149
150 return MYKONOS_ERR_DBG_OK;
151 }
152
153 /**
154 * \brief Performs indirect read access to internal JESD register.
155 *
156 * <B>Dependencies</B>
157 * - device->spiSettings->chipSelectIndex
158 *
159 * \param device Pointer to Mykonos device data structure containing settings
160 * \param jesdCore JESD core selection
161 * \param intAddr Internal address to access in JESD core
162 * \param data Pointer to store data
163 *
164 * \retval MYKONOS_ERR_OK Function completed successfully
165 * \retval MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER Data pointer passed is a NULL pointer
166 */
167 mykonosDbgErr_t MYKONOS_jesdIndRdReg(mykonosDevice_t *device, mykonos_jesdcore_t jesdCore, uint8_t intAddr, uint8_t *data)
168 {
169 uint16_t baseAddr = 0;
170
171 #if (MYKONOS_VERBOSE == 1)
172 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdIndRdReg()\n");
173 #endif
174
175 /* Check for valid data pointer */
176 if(data == NULL)
177 {
178 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER,
179 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER));
180 return MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER;
181 }
182
183 /* Check for jesdCore and address assignment */
184 switch (jesdCore)
185 {
186 case MYK_FRAMER:
187 baseAddr = MYKONOS_ADDR_FRAMER_ADDR;
188 break;
189
190 case MYK_DEFRAMER:
191 baseAddr = MYKONOS_ADDR_DEFRAMER_ADDR;
192 break;
193
194 case MYK_OBS_FRAMER:
195 baseAddr = MYKONOS_ADDR_OBS_FRAMER_ADDR;
196 break;
197
198 default:
199 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_JESD_CORE,
200 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_JESD_CORE));
201 return MYKONOS_ERR_DBG_ILLEGAL_JESD_CORE;
202 break;
203 }
204
205 /* Perform indirect read */
206 CMB_SPIWriteByte(device->spiSettings, baseAddr, intAddr);
207 CMB_SPIReadByte(device->spiSettings, baseAddr + 1, data);
208
209 return MYKONOS_ERR_DBG_OK;
210 }
211
212 /**
213 * \brief Performs reads to JESD Deframer secondary status register.
214 *
215 * <B>Dependencies</B>
216 * - device->spiSettings->chipSelectIndex
217 *
218 * \param device Pointer to Mykonos device data structure containing settings
219 * \param defStat2 Pointer to store the deframer secondary status
220 *
221 * Bit mask | Description of defStat2
222 * -----------|---------------
223 * 2 | DeframerSYSREF Phase Error, when set, this bit reports that an incoming SYSREF is not aligned to the current LMFC boundary.
224 * 1 | Deframer Det Lat FIFO RD, this bit is the status of rd_enable for deterministic sample FIFO. If set deterministic latency is achieved.
225 * 0 | Deframer Lane FIFO PTR Delta Changed. If set this bit reports that the offset between the read and write FIFO pointers has changed.
226 *
227 *
228 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
229 * \retval MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER Data pointer passed defStat2 is NULL
230 */
231 mykonosDbgErr_t MYKONOS_deframerRd2Stat(mykonosDevice_t *device, uint8_t *defStat2)
232 {
233 uint8_t regRd = 0x00;
234
235 const uint8_t SHIFT_MASK = 0x05;
236
237 #if (MYKONOS_VERBOSE == 1)
238 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdRdDefrmSndStat()\n");
239 #endif
240
241 /* Check for valid defStat2 pointer */
242 if (defStat2 == NULL)
243 {
244 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER,
245 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER));
246 return MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER;
247 }
248
249 /* Read deframer secondary status */
250 CMB_SPIReadByte(device->spiSettings, MYKONOS_ADDR_DEFRAMER_STATUS_2, &regRd);
251
252 *defStat2 = regRd >> SHIFT_MASK;
253
254 /* Refresh status registers */
255 CMB_SPIWriteByte(device->spiSettings, MYKONOS_ADDR_DEFRAMER_STAT_STRB, 0x01);
256 CMB_SPIWriteByte(device->spiSettings, MYKONOS_ADDR_DEFRAMER_STAT_STRB, 0x00);
257
258 return MYKONOS_ERR_OK;
259 }
260
261 /**
262 * \brief Performs read back lanes in error for the given errType of the JESD Deframer.
263 *
264 * <B>Dependencies</B>
265 * - device->spiSettings->chipSelectIndex
266 *
267 * \param device Pointer to Mykonos device data structure containing settings
268 * \param errType which error counter to read back
269 * \param lane Pointer to store which lane has reached the error threshold.
270 * Every bit shows per lane which error count has reached the threshold count.
271 * A value of 0x0F will represent that all the lanes has reached the error threshold.
272 *
273 * Value | Description of Lane
274 * --------------|-----------------------
275 * 8 | Lane 3 has reached the error threshold
276 * 4 | Lane 2 has reached the error threshold
277 * 2 | Lane 1 has reached the error threshold
278 * 1 | Lane 0 has reached the error threshold
279 * 0 | No errors in lanes
280 *
281 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
282 * \retval MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER Data pointer passed lane is NULL
283 * \retval MYKONOS_ERR_DBG_ILLEGAL_ERROR_SELECTED Illegal errType passed, valid errType are BADDISP, NIT and UEKC
284 */
285 mykonosDbgErr_t MYKONOS_deframerGetErrLane(mykonosDevice_t *device, mykonosErrType_t errType, uint8_t *lane)
286 {
287 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
288 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
289
290 #if (MYKONOS_VERBOSE == 1)
291 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdIndRdReg()\n");
292 #endif
293
294 /* Check for valid Lane pointer */
295 if(lane == NULL)
296 {
297 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER,
298 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER));
299 return MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER;
300 }
301
302 /* Check for valid error type */
303 switch (errType)
304 {
305 case MYK_BADDISP:
306 case MYK_NIT:
307 case MYK_UEKC:
308 break;
309
310 default:
311 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_ERROR_SELECTED,
312 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_ERROR_SELECTED));
313 return MYKONOS_ERR_DBG_ILLEGAL_ERROR_SELECTED;
314 }
315
316 /* Read error and store it in lane */
317 error = MYKONOS_jesdIndRdReg(device, jesdCore, errType, lane);
318
319 return error;
320 }
321
322 /**
323 * \brief Performs reset of the selected error type for the selected lane.
324 *
325 * <B>Dependencies</B>
326 * - device->spiSettings->chipSelectIndex
327 *
328 * \param device Pointer to Mykonos device data structure containing settings
329 * \param errType Which error counter to be reset
330 * \param lane Which lane error counter to be reset
331 *
332 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
333 * \retval MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER Illegal lane passed, valid lanes are given in mykonosLaneSel_t
334 * \retval MYKONOS_ERR_DBG_ILLEGAL_ERROR_SELECTED Illegal errType passed, valid errType are BADDISP, NIT and UEKC
335 */
336 mykonosDbgErr_t MYKONOS_deframerRstErrCntr(mykonosDevice_t *device, mykonosErrType_t errType, mykonosLaneSel_t lane)
337 {
338 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
339 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
340
341 const uint8_t rstCntBit = 0x20;
342
343 #if (MYKONOS_VERBOSE == 1)
344 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdIndRdReg()\n");
345 #endif
346
347 /* Check for valid Lane */
348 switch (lane)
349 {
350 case MYK_LANE_0:
351 case MYK_LANE_1:
352 case MYK_LANE_2:
353 case MYK_LANE_3:
354 break;
355
356 default:
357 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER,
358 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER));
359 return MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER;
360 }
361
362 /* Check for error type */
363 switch (errType)
364 {
365 case MYK_BADDISP:
366 case MYK_NIT:
367 case MYK_UEKC:
368 break;
369
370 default:
371 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_ERROR_SELECTED,
372 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_ERROR_SELECTED));
373 return MYKONOS_ERR_DBG_ILLEGAL_ERROR_SELECTED;
374 }
375
376 /* Perform reset counter */
377 error = MYKONOS_jesdIndWrReg(device, jesdCore, errType, (rstCntBit | ((uint8_t)lane)));
378
379 return error;
380 }
381
382 /**
383 * \brief Performs reset of the selected error type IRQ for the given lane.
384 *
385 *<B>Dependencies</B>
386 * - device->spiSettings->chipSelectIndex
387 *
388 * \param device Pointer to Mykonos device data structure containing settings
389 * \param errType Which error counter to be reset, for the full list
390 * \param lane Which lane error counter to be reset
391 *
392 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
393 * \retval MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER Illegal lane passed, valid lanes are given in mykonosLaneSel_t
394 * \retval MYKONOS_ERR_DBG_ILLEGAL_ERROR_TYPE Illegal errType passed, valid errType are given in mykonosErrType_t
395 */
396 mykonosDbgErr_t MYKONOS_deframerRstErrIrq(mykonosDevice_t *device, mykonosErrType_t errType, mykonosLaneSel_t lane)
397 {
398 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
399 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
400 uint8_t regRd = 0;
401 uint8_t rstIrqBit = 0x80;
402
403 #if (MYKONOS_VERBOSE == 1)
404 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdIndRdReg()\n");
405 #endif
406
407 /* Check for valid Lane */
408 switch (lane)
409 {
410 case MYK_LANE_0:
411 case MYK_LANE_1:
412 case MYK_LANE_2:
413 case MYK_LANE_3:
414 break;
415
416 default:
417 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER,
418 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER));
419 return MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER;
420 }
421
422 /* Check for error type */
423 switch (errType)
424 {
425 case MYK_CMM:
426 /* CMM has no lane selection */
427 error = MYKONOS_jesdIndRdReg(device, jesdCore, errType, &regRd);
428 if (error != MYKONOS_ERR_DBG_OK)
429 {
430 return error;
431 }
432
433 lane = MYK_LANE_0;
434 rstIrqBit = 0x10 | regRd;
435 break;
436
437 case MYK_BADDISP:
438 case MYK_NIT:
439 case MYK_UEKC:
440 break;
441
442 default:
443 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_ERROR_TYPE,
444 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_ERROR_TYPE));
445 return MYKONOS_ERR_DBG_ILLEGAL_ERROR_TYPE;
446 }
447
448 /* Reset selected IRQ */
449 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, errType, &regRd)) != MYKONOS_ERR_DBG_OK)
450 {
451 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
452 getDbgJesdMykonosErrorMessage(error));
453 return error;
454 }
455
456 if ((error = MYKONOS_jesdIndWrReg(device, jesdCore, errType, (rstIrqBit | ((uint8_t)lane)))) != MYKONOS_ERR_DBG_OK)
457 {
458 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
459 getDbgJesdMykonosErrorMessage(error));
460 return error;
461 }
462
463 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, errType, &regRd)) != MYKONOS_ERR_DBG_OK)
464 {
465 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
466 getDbgJesdMykonosErrorMessage(error));
467 }
468
469 return error;
470 }
471
472
473 /**
474 * \brief Performs read back of the error counters for selected lane of the JESD Deframer.
475 *
476 * This function reads the counters per the given lane for the bad disparity, not in table and unexpected K character errors and stores them in the
477 * structure laneErr.
478 * The structure laneErr must be initialised in the calling function as it will contain the values of the counters per error type for the given lane.
479 *
480 * <B>Dependencies</B>
481 * - device->spiSettings->chipSelectIndex
482 * - laneErr structure must be initialised
483 *
484 * \param device Pointer to Mykonos device data structure containing settings
485 * \param laneSel which JESD lane error counter to be read
486 * \param laneErr Pointer to a mykonosLaneErr_t structure type to store counter values for different errors
487 *
488 * \retval MYKONOS_ERR_OK Function completed successfully
489 * \retval MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER Data pointer passed laneErr is NULL
490 * \retval MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER Illegal laneSel parameter passed, valid laneSel are given in mykonosLaneSel_t
491 */
492 mykonosDbgErr_t MYKONOS_deframerRdErrCntr(mykonosDevice_t *device, mykonosLaneSel_t laneSel, mykonosLaneErr_t *laneErr)
493 {
494 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
495 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
496 uint8_t counterSel = 0;
497
498 const uint8_t ERR_CNT_ADDR = 0x6B;
499
500 #if (MYKONOS_VERBOSE == 1)
501 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdRdErrCntr()\n");
502 #endif
503
504 /* Check for valid laneErr pointer */
505 if(laneErr == NULL)
506 {
507 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER,
508 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER));
509 return MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER;
510 }
511
512 /* Check for valid laneSel */
513 switch (laneSel)
514 {
515 case MYK_LANE_0:
516 case MYK_LANE_1:
517 case MYK_LANE_2:
518 case MYK_LANE_3:
519 break;
520
521 default:
522 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER,
523 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER));
524 return MYKONOS_ERR_DBG_ILLEGAL_LANE_NUMBER;
525 }
526
527 /* Reading Bad disparity Counter */
528 if ((error = MYKONOS_jesdIndWrReg(device, jesdCore, ERR_CNT_ADDR, (((uint8_t)(laneSel) << 4) | counterSel++))) != MYKONOS_ERR_DBG_OK)
529 {
530 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
531 getDbgJesdMykonosErrorMessage(error));
532 return error;
533 }
534
535 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, ERR_CNT_ADDR, &laneErr->badDispCntr)) != MYKONOS_ERR_DBG_OK)
536 {
537 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
538 getDbgJesdMykonosErrorMessage(error));
539 return error;
540 }
541
542 /* Reading Not in table Counter */
543 if ((error = MYKONOS_jesdIndWrReg(device, jesdCore, ERR_CNT_ADDR, (((uint8_t)(laneSel) << 4) | counterSel++))) != MYKONOS_ERR_DBG_OK)
544 {
545 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
546 getDbgJesdMykonosErrorMessage(error));
547 return error;
548 }
549
550 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, ERR_CNT_ADDR, &laneErr->nitCntr)))
551 {
552 return error;
553 }
554
555 /* Reading unexpected K character Counter */
556 if ((error = MYKONOS_jesdIndWrReg(device, jesdCore, ERR_CNT_ADDR, (((uint8_t)(laneSel) << 4) | counterSel))) != MYKONOS_ERR_DBG_OK)
557 {
558 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
559 getDbgJesdMykonosErrorMessage(error));
560 return error;
561 }
562
563 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, ERR_CNT_ADDR, &laneErr->uekcCntr)) != MYKONOS_ERR_DBG_OK)
564 {
565 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
566 getDbgJesdMykonosErrorMessage(error));
567 }
568
569 return error;
570 }
571
572
573 /**
574 * \brief Performs set JESD Deframer error thresholds.
575 *
576 * The value for the error threshold will be applied to all the error counters for all the enabled lanes.
577 * Bad disparity, NIT disparity and Unexpected K char. Errors are counted and compared to the errThrs value.
578 * When the count is equal, then the user has the ability of raising an IRQ, see MYKONOS_deframerSetIrqMask,
579 * or asserted the SYNC signal per the mask register settings, see MYKONOS_deframerSetSyncMask,
580 * or do nothing upon threshold reach.
581 *
582 * <B>Dependencies</B>
583 * - device->spiSettings->chipSelectIndex
584 *
585 * \param device Pointer to Mykonos device data structure containing settings
586 * \param errThrs is the value that will be written to the error threshold, valid error threshold is in the range 0x00 to 0xFF.
587 *
588 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
589 */
590 mykonosDbgErr_t MYKONOS_deframerSetErrThrs(mykonosDevice_t *device, uint8_t errThrs)
591 {
592 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
593 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
594
595 const uint8_t DFM_ERROR_THRES = 0x7C;
596
597 #if MYKONOS_VERBOSE == 1
598 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdGetErrThrs()\n");
599 #endif
600
601 /* Writing internal registers 0x7C */
602 if ((error = MYKONOS_jesdIndWrReg(device, jesdCore, DFM_ERROR_THRES, errThrs)) != MYKONOS_ERR_DBG_OK)
603 {
604 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
605 getDbgJesdMykonosErrorMessage(error));
606 }
607
608 return error;
609 }
610
611 /**
612 * \brief Performs read JESD Deframer error thresholds.
613 *
614 * The value for the error threshold is common to all the error counters.
615 *
616 * <B>Dependencies</B>
617 * - device->spiSettings->chipSelectIndex
618 * - laneErr structure must be initialised
619 *
620 * \param device Pointer to Mykonos device data structure containing settings
621 * \param errThrs Pointer to store the error threshold value read back
622 *
623 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
624 * \retval MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER Data pointer passed errThrs is NULL
625 */
626 mykonosDbgErr_t MYKONOS_deframerGetErrThrs(mykonosDevice_t *device, uint8_t *errThrs)
627 {
628 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
629 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
630
631 const uint8_t DFM_ERROR_THRES = 0x7C;
632
633 #if MYKONOS_VERBOSE == 1
634 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdGetErrThrs()\n");
635 #endif
636
637 /* Check for null parameter */
638 if (errThrs == NULL)
639 {
640 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER,
641 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER));
642 return MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER;
643 }
644
645 /* Reading internal registers */
646 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, DFM_ERROR_THRES, errThrs)) != MYKONOS_ERR_DBG_OK)
647 {
648 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
649 getDbgJesdMykonosErrorMessage(error));
650 }
651
652 return error;
653 }
654
655
656 /**
657 * \brief Performs set JESD Deframer Sync mask.
658 *
659 * This function sets the syncMask that will be programmed in to Mykonos.
660 * When the error counter reaches the error threshold value programmed by MYKONOS_deframerSetErrThrs function, if the syncMask is set for the particular
661 * errors type then the SYNC~ is asserted.
662 * The syncMask is applied to all the enabled lanes.
663 *
664 * <B>Dependencies</B>
665 * - device->spiSettings->chipSelectIndex
666 *
667 * \param device Pointer to Mykonos device data structure containing settings
668 * \param errSyncMask is the mask that will be used in order to assert SYNC~
669 * Setting the syncMask bits causes the deframer to assert the SYNC~ when the count of the corresponding error reaches the
670 * errThrs value.
671 *
672 * Sync | Bit mask | Description of sync
673 * -------------|--------------|-----------------------
674 * SYNC_BADDISP | 2 | Bad disparity mask
675 * SYNC_NIT | 1 | Not in table
676 * SYNC_UEKC | 0 | Unexpected K character
677 *
678 * \retval MYKONOS_ERR_DBG_OK Function completed successfully.
679 * \retval MYKONOS_ERR_DBG_ERROR_SYNC_MASK Passed errSyncMask parameter is outside its boundaries, valid sync mask are in the range 0x00 to 0x07.
680 */
681 mykonosDbgErr_t MYKONOS_deframerSetSyncMask(mykonosDevice_t *device, uint8_t errSyncMask)
682 {
683 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
684 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
685 uint8_t regRd = 0x00;
686 uint8_t regWr = 0x00;
687
688 const uint8_t SYNC_MASK_CTRL = 0x7B;
689 const uint8_t SYNC_MASK = 0x07;
690 const uint8_t MASK = 0xE0;
691 const uint8_t SYNC_SHIFT = 5;
692
693 #if MYKONOS_VERBOSE == 1
694 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdSetSyncMask()\n");
695 #endif
696
697 /* Check for valid errSyncMask */
698 if (errSyncMask & ~SYNC_MASK)
699 {
700 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ERROR_SYNC_MASK,
701 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ERROR_SYNC_MASK));
702 return MYKONOS_ERR_DBG_ERROR_SYNC_MASK;
703 }
704
705 /* Writing internal registers do a read modify write */
706 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, SYNC_MASK_CTRL, &regRd)) != MYKONOS_ERR_DBG_OK)
707 {
708 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
709 getDbgJesdMykonosErrorMessage(error));
710 return error;
711 }
712 regRd &= ~(MASK);
713
714 regWr = regRd | (errSyncMask << SYNC_SHIFT);
715
716 if ((error = MYKONOS_jesdIndWrReg(device, jesdCore, SYNC_MASK_CTRL, regWr)) != MYKONOS_ERR_DBG_OK)
717 {
718 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
719 getDbgJesdMykonosErrorMessage(error));
720 }
721
722 return error;
723 }
724
725 /**
726 * \brief Performs get JESD Deframer SyncMask.
727 *
728 * This function read the SyncMask that is programmed into Mykonos.
729 *
730 * <B>Dependencies</B>
731 * - device->spiSettings->chipSelectIndex
732 *
733 * \param device Pointer to Mykonos device data structure containing settings
734 * \param errSyncMask Pointer to store the sync mask currently being used:
735 *
736 * Sync | Bit mask | Description of errSyncMask
737 *--------------|--------------|-----------------------
738 * SYNC_BADDISP | 2 | Bad disparity mask
739 * SYNC_NIT | 1 | Not in table
740 * SYNC_UEKC | 0 | Unexpected K character
741 *
742 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
743 * \retval MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER Data pointer passed errSyncMask is NULL
744 */
745 mykonosDbgErr_t MYKONOS_deframerGetSyncMask(mykonosDevice_t *device, uint8_t *errSyncMask)
746 {
747 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
748 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
749 uint8_t regRd = 0x00;
750
751 const uint8_t SYNC_MASK_CTRL = 0x7B;
752 const uint8_t SYNC_MASK = 0x07;
753 const uint8_t SYNC_SHIFT = 5;
754
755 #if MYKONOS_VERBOSE == 1
756 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdGetSyncMask()\n");
757 #endif
758
759 /* Check for valid errSyncMask pointer */
760 if (errSyncMask == NULL)
761 {
762 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER,
763 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER));
764 return MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER;
765 }
766
767 /*read sync mask internal reg */
768 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, SYNC_MASK_CTRL, &regRd)) != MYKONOS_ERR_DBG_OK)
769 {
770 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
771 getDbgJesdMykonosErrorMessage(error));
772 return error;
773 }
774
775 *errSyncMask = (regRd >> SYNC_SHIFT) & SYNC_MASK;
776
777 return error;
778 }
779
780
781 /**
782 * \brief Performs read of enabled JESD Deframer lanes.
783 *
784 * <B>Dependencies</B>
785 * - device->spiSettings->chipSelectIndex
786 *
787 * \param device Pointer to Mykonos device data structure containing settings
788 * \param lane Pointer to store the current enabled lanes
789 *
790 * Value | Description of Lane
791 * --------------|-----------------------
792 * 8 | Lane 3 is enabled
793 * 4 | Lane 2 is enabled
794 * 2 | Lane 1 is enabled
795 * 1 | Lane 0 is enabled
796 * 0 | No lanes are enabled
797 *
798 *
799 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
800 * \retval MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER Data pointer passed lane is NULL
801 */
802 mykonosDbgErr_t MYKONOS_deframerGetEnLanes(mykonosDevice_t *device, uint8_t *lane)
803 {
804 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
805 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
806 uint8_t regRd = 0x00;
807
808 const uint8_t DFM_LANE_EN = 0x7D;
809 const uint8_t LANE_MASK = 0x0F;
810
811 #if MYKONOS_VERBOSE == 1
812 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdGetEnLanes()\n");
813 #endif
814
815 /* Check for valid lane pointer */
816 if (lane == NULL)
817 {
818 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER,
819 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER));
820 return MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER;
821 }
822
823 /* Read enable lanes internal reg */
824 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, DFM_LANE_EN, &regRd)) != MYKONOS_ERR_DBG_OK)
825 {
826 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
827 getDbgJesdMykonosErrorMessage(error));
828 return error;
829 }
830
831 *lane = regRd & LANE_MASK;
832
833 return error;
834 }
835
836
837 /**
838 * \brief Performs Deframer Force SYNC requests
839 *
840 * Using this feature, the user can force SYNC request on the Deframer
841 *
842 * <B>Dependencies</B>
843 * - device->spiSettings->chipSelectIndex
844 *
845 * \param device Pointer to Mykonos device data structure containing settings
846 * \param syncReq sync Request parameter
847 * Setting the syncReq causes the deframer to assert the SYNC~.
848 * Clearing syncReq causes the deframer to de-assert the SYNC~.
849 *
850 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
851 */
852 mykonosDbgErr_t MYKONOS_deframerForceSyncReq(mykonosDevice_t *device, uint8_t syncReq)
853 {
854 uint8_t syncReqWr = 0x00;
855
856 const uint8_t SYNC_REQ_MASK = 0x01;
857
858 #if MYKONOS_VERBOSE == 1
859 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_deframerForceSyncReq()\n");
860 #endif
861
862 syncReqWr = (syncReq > 0) ? 0x01 : 0x00;
863
864 CMB_SPIWriteField(device->spiSettings, MYKONOS_ADDR_DEFRAMER_TEST, syncReqWr, SYNC_REQ_MASK, 0);
865
866 return MYKONOS_ERR_DBG_OK;
867 }
868
869 /**
870 * \brief Performs set JESD Deframer IRQ mask that will be used to generates interrupts
871 *
872 * Bad disparity, NIT disparity and Unexpected K char. Errors are counted and compared to the errThrs value.
873 * When the count is equal, either an IRQ is generated if the mask for the particular error is set.
874 * Configuration mismatch flag does not have a counter.
875 * Function is performed in all lanes.
876 *
877 * <B>Dependencies</B>
878 * - device->spiSettings->chipSelectIndex
879 *
880 * \param device Pointer to Mykonos device data structure containing settings
881 * \param errIrqMsk the value of the mask applied to the IRQ generation, possible combinations are:
882 *
883 * IRQ | Bit mask | Description of errIrq
884 * ------------|--------------|-----------------------
885 * CMM | 3 | Configuration mismatch flag 0 if is CMM ok, 1 if CMM is detected
886 * BADDISP | 2 | Incorrect disparity flag 0 if is BADDISP ok, 1 if BADDISP is detected
887 * NIT | 1 | Not in table flag 0 if is NIT ok, 1 if NIT character is detected
888 * UEKC | 0 | Unexpected K character flag 0 if is UEKC ok, 1 if UEKC is detected
889 *
890 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
891 * \retval MYKONOS_ERR_DBG_ERROR_IRQ_MASK Illegal parameter passed for errIrqMsk, valid parameter is in the range of 0x00 to 0x1FF
892 */
893 mykonosDbgErr_t MYKONOS_deframerSetIrqMask(mykonosDevice_t *device, uint8_t errIrqMsk)
894 {
895 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
896 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
897 uint8_t regRd = 0x0000;
898 uint8_t regWr = 0x0000;
899
900 const uint8_t IRQ_MSK_CTRL_ADDR = 0x7A;
901 const uint8_t IRQ_MSK = 0x0F;
902 const uint8_t CMMIRQ_MSK = 0x08;
903 const uint8_t CMMIRQ_CTRL = 0x7B;
904
905 #if MYKONOS_VERBOSE == 1
906 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdSetErrMask()\n");
907 #endif
908
909 /* Check for valid errIrqMask */
910 if (errIrqMsk & ~IRQ_MSK)
911 {
912 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ERROR_IRQ_MASK,
913 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ERROR_IRQ_MASK));
914 return MYKONOS_ERR_DBG_ERROR_IRQ_MASK;
915 }
916
917 /* Setting required IRQs */
918 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, CMMIRQ_CTRL, &regRd)) != MYKONOS_ERR_DBG_OK)
919 {
920 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
921 getDbgJesdMykonosErrorMessage(error));
922 return error;
923 }
924
925 regWr = (CMMIRQ_MSK & errIrqMsk) | (regRd & ~CMMIRQ_MSK);
926
927 if ((error = MYKONOS_jesdIndWrReg(device, jesdCore, CMMIRQ_CTRL, regWr)) != MYKONOS_ERR_DBG_OK)
928 {
929 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
930 getDbgJesdMykonosErrorMessage(error));
931 return error;
932 }
933
934 regWr = (errIrqMsk & 0x07) << 5;
935 if ((error = MYKONOS_jesdIndWrReg(device, jesdCore, IRQ_MSK_CTRL_ADDR, regWr)) != MYKONOS_ERR_DBG_OK)
936 {
937 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
938 getDbgJesdMykonosErrorMessage(error));
939 }
940
941 return error;
942 }
943
944 /**
945 * \brief Performs a read of the JESD IRQ vector for the deframer.
946 *
947 * <B>Dependencies</B>
948 * - device->spiSettings->chipSelectIndex
949 *
950 * \param device Pointer to Mykonos device data structure containing settings
951 * \param errIrq Pointer to store the deframer IRQ status, the different bits mask are:
952 *
953 * IRQ | Bit mask | Description of errIrq
954 * ------------|--------------|-----------------------
955 * CMM | 3 | Configuration mismatch 0 if is CMM ok, 1 if CMM is detected
956 * BADDISP | 2 | Incorrect disparity 0 if is BADDISP ok, 1 if BADDISP character is detected
957 * NIT | 1 | Not in table 0 if is NIT ok, 1 if NIT character is detected
958 * UEKC | 0 | Unexpected K character 0 if is UEKC ok, 1 if UEKC character is detected
959 *
960 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
961 * \retval MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER Data pointer passed errIrqMask is NULL
962 */
963 mykonosDbgErr_t MYKONOS_deframerGetIrq(mykonosDevice_t *device, uint8_t *errIrq)
964 {
965 mykonosDbgErr_t error = MYKONOS_ERR_DBG_OK;
966 mykonos_jesdcore_t jesdCore = MYK_DEFRAMER;
967 uint8_t regRd = 0x00;
968 uint8_t irqRd = 0x00;
969
970 const uint8_t IRQ_MSK_CTRL_ADDR = 0x7A;
971 const uint8_t CMMIRQ_CTRL = 0x7B;
972 const uint8_t CMMIRQ_MASK_REG = 0x10;
973
974 #if MYKONOS_VERBOSE == 1
975 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_jesdGetErrMask()\n");
976 #endif
977
978 /* Check for valid errIrq pointer */
979 if (errIrq == NULL)
980 {
981 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER,
982 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER));
983 return MYKONOS_ERR_DBG_ILLEGAL_DATA_POINTER;
984 }
985
986 /* Reading main IRQ */
987 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, IRQ_MSK_CTRL_ADDR, &regRd)))
988 {
989 return error;
990 }
991
992 irqRd = (regRd & 0xE0) >> 5;
993
994
995 /* Reading CMMIRQ */
996 if ((error = MYKONOS_jesdIndRdReg(device, jesdCore, CMMIRQ_CTRL, &regRd)))
997 {
998 return error;
999 }
1000
1001 irqRd |= ((regRd & CMMIRQ_MASK_REG) >> 1);
1002
1003 /* Computing final value */
1004 *errIrq = irqRd;
1005
1006 return error;
1007 }
1008
1009 /**
1010 * \brief Performs set JESD framer Pattern Generator.
1011 *
1012 * The Pattern Generator is a function for JESD testing. The JESD framer will be transmitting
1013 * the "pattern" once the enabled.
1014 *
1015 * <B>Dependencies</B>
1016 * - device->spiSettings->chipSelectIndex
1017 *
1018 * \param device Pointer to Mykonos device data structure containing settings
1019 * \param jesdCore selection for FRAMER and OBS_FRAMER
1020 * \param pattern pattern to be transmitted by the Framer, is a 20 bit field having a range from 0x00000 to 0xFFFFF
1021 * \param enable Bit used to enable the Pattern Generator facility
1022 * \param toggle if 0 the transfer data will be not modified, if 1 the transfered data will be toggling
1023 *
1024 * \retval MYKONOS_ERR_DBG_ILLEGAL_TOGGLE Toggle is not valid, valid values are 0 and 1.
1025 * \retval MYKONOS_ERR_DBG_ILLEGAL_FRAMER_PATTERN Pattern passed is outside the range valid range from 0x00000 to 0xFFFFF
1026 * \retval MYKONOS_ERR_DBG_ILLEGAL_ENABLE Enable not valid, valid values are 0 and 1.
1027 * \retval MYKONOS_ERR_DBG_PATTERN_GEN_ILLEGAL_JESD_CORE
1028 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
1029 */
1030 mykonosDbgErr_t MYKONOS_framerSetPatternGen(mykonosDevice_t *device, mykonos_jesdcore_t jesdCore, uint32_t pattern, uint8_t enable, uint8_t toggle)
1031 {
1032 mykonosDbgErr_t error = MYKONOS_ERR_DBG_FAIL;
1033 uint16_t baseAddr = 0x00;
1034 uint8_t rgWr = 0x00;
1035
1036 const uint32_t PATTERN_MSK = 0xFFFFF;
1037 const uint8_t ENABLE_MASK = 0x01;
1038 const uint8_t TOGGLE_MASK = 0x02;
1039
1040 #if MYKONOS_VERBOSE == 1
1041 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_framerSetPatternGen()\n");
1042 #endif
1043
1044 /* JESD framer core selection */
1045 if ((error = MYKONOS_framerCoreSel(jesdCore, MYKONOS_ADDR_FRAMER_PATTERN_GEN_EN, &baseAddr)) != MYKONOS_ERR_DBG_OK)
1046 {
1047 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
1048 getDbgJesdMykonosErrorMessage(error));
1049 return error;
1050 }
1051
1052 /* Check for valid enable */
1053 if (enable == 1)
1054 {
1055 rgWr = ENABLE_MASK;
1056 /* check for valid pattern */
1057 if (pattern & ~PATTERN_MSK)
1058 {
1059 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_FRAMER_PATTERN,
1060 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_FRAMER_PATTERN));
1061 return MYKONOS_ERR_DBG_ILLEGAL_FRAMER_PATTERN;
1062 }
1063
1064 /* Check for valid toggle */
1065 if (toggle == 1)
1066 {
1067 rgWr += TOGGLE_MASK;
1068
1069 }
1070 else if (toggle > 1)
1071 {
1072 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_TOGGLE,
1073 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_TOGGLE));
1074 return MYKONOS_ERR_DBG_ILLEGAL_TOGGLE;
1075 }
1076 }
1077 else if (enable ==0)
1078 {
1079 rgWr = 0x00;
1080 pattern = 0x5A5A5;
1081 }
1082 else if (enable > 1)
1083 {
1084 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ILLEGAL_ENABLE,
1085 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ILLEGAL_ENABLE));
1086 return MYKONOS_ERR_DBG_ILLEGAL_ENABLE;
1087 }
1088
1089 /* Write pattern and enable */
1090 CMB_SPIWriteByte(device->spiSettings, baseAddr, rgWr);
1091 CMB_SPIWriteByte(device->spiSettings, (baseAddr + 1), (uint8_t)(pattern & 0xFF));
1092 CMB_SPIWriteByte(device->spiSettings, (baseAddr + 2), (uint8_t)((pattern >> 8) & 0xFF));
1093 CMB_SPIWriteByte(device->spiSettings, (baseAddr + 3), (uint8_t)((pattern >> 16) & 0x0F));
1094
1095 return MYKONOS_ERR_DBG_OK;
1096 }
1097
1098 /**
1099 * \brief Gets JESD framer Pattern generator
1100 *
1101 * <B>Dependencies</B>
1102 * - device->spiSettings->chipSelectIndex
1103 *
1104 * \param device Pointer to Mykonos device data structure containing settings
1105 * \param jesdCore selection for FRAMER and OBS_FRAMER
1106 * \param pattern Pointer to store the programmed pattern
1107 * \param enable Pointer to store the programmed enable
1108 * \param toggle Pointer to store the programmed toggle
1109 *
1110 * \retval MYKONOS_ERR_DBG_PATTERN_GEN_NULL_PATTERN Function parameter pattern is a NULL pointer
1111 * \retval MYKONOS_ERR_DBG_PATTERN_GEN_NULL_ENABLE Function parameter enable is a NULL pointer
1112 * \retval MYKONOS_ERR_DBG_PATTERN_GEN_NULL_TOGGLE Function parameter toggle is a NULL pointer
1113 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
1114 */
1115 mykonosDbgErr_t MYKONOS_framerGetPatternGen(mykonosDevice_t *device, mykonos_jesdcore_t jesdCore, uint32_t *pattern, uint8_t *enable, uint8_t *toggle)
1116 {
1117 mykonosDbgErr_t error = MYKONOS_ERR_DBG_FAIL;
1118 uint16_t baseAddr = 0x00;
1119 uint8_t regRd = 0x00;
1120 uint32_t patRd = 0x00000;
1121 uint8_t toggleRd = 0x00;
1122 uint8_t enableRd = 0x00;
1123
1124 const uint8_t ENABLE_MASK = 0x01;
1125 const uint8_t TOGGLE_MASK = 0x02;
1126
1127 #ifdef MYKONOS_VERBOSE
1128 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_framerGetPatternGen()\n");
1129 #endif
1130
1131 /* Check null parameter passed */
1132 if (pattern == NULL)
1133 {
1134 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_PATTERN_GEN_NULL_PATTERN,
1135 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_PATTERN_GEN_NULL_PATTERN));
1136 return MYKONOS_ERR_DBG_PATTERN_GEN_NULL_PATTERN;
1137 }
1138
1139 /* Check null parameter passed */
1140 if (enable == NULL)
1141 {
1142 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_PATTERN_GEN_NULL_ENABLE,
1143 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_PATTERN_GEN_NULL_ENABLE));
1144 return MYKONOS_ERR_DBG_PATTERN_GEN_NULL_ENABLE;
1145 }
1146
1147 /* Check null parameter passed */
1148 if (toggle == NULL)
1149 {
1150 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_PATTERN_GEN_NULL_TOGGLE,
1151 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_PATTERN_GEN_NULL_TOGGLE));
1152 return MYKONOS_ERR_DBG_PATTERN_GEN_NULL_TOGGLE;
1153 }
1154
1155 /* JESD framer core selection */
1156 if ((error = MYKONOS_framerCoreSel(jesdCore, MYKONOS_ADDR_FRAMER_PATTERN_GEN_EN, &baseAddr)) != MYKONOS_ERR_DBG_OK)
1157 {
1158 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
1159 getDbgJesdMykonosErrorMessage(error));
1160 return error;
1161 }
1162
1163 /* Read back pattern generator */
1164 CMB_SPIReadByte(device->spiSettings, baseAddr, &regRd);
1165 toggleRd = (regRd & TOGGLE_MASK)>>1;
1166 enableRd = regRd & ENABLE_MASK;
1167
1168 CMB_SPIReadByte(device->spiSettings, (baseAddr + 1), &regRd);
1169 patRd = regRd;
1170
1171 CMB_SPIReadByte(device->spiSettings, (baseAddr + 2), &regRd);
1172 patRd |= (regRd << 8);
1173
1174 CMB_SPIReadByte(device->spiSettings, (baseAddr + 3), &regRd);
1175 patRd |= ((regRd & 0x0F) << 16);
1176
1177 /* Write to pointers */
1178 *pattern = patRd;
1179 *toggle = toggleRd;
1180 *enable = enableRd;
1181
1182 return MYKONOS_ERR_DBG_OK;
1183 }
1184
1185
1186 /**
1187 * \brief Performs set JESD framer Zero data samples per lane.
1188 *
1189 * This functions will zero the Framer data samples for the specify lane or lanes.
1190 * For the specified Framer or ObsFramer.
1191 *
1192 * <B>Dependencies</B>
1193 * - device->spiSettings->chipSelectIndex
1194 *
1195 * \param device Pointer to Mykonos device data structure containing settings
1196 * \param jesdCore selection for FRAMER and OBS_FRAMER
1197 * \param lane lanes to zero the Framer data samples
1198 *
1199 * \retval MYKONOS_ERR_DBG_ZERO_DATA_INV_LANE the lane selection is out of range
1200 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
1201 */
1202 mykonosDbgErr_t MYKONOS_framerSetZeroData(mykonosDevice_t *device, mykonos_jesdcore_t jesdCore, mykonosLaneSel_t lane)
1203 {
1204 mykonosDbgErr_t error = MYKONOS_ERR_DBG_FAIL;
1205 uint16_t baseAddr = 0x00;
1206
1207 const uint32_t LANE_MSK = 0x0F;
1208
1209 #if MYKONOS_VERBOSE == 1
1210 CMB_writeToLog(ADIHAL_LOG_MESSAGE, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_framerSetZeroData()\n");
1211 #endif
1212
1213 /* check for valid pattern */
1214 if (lane & ~LANE_MSK)
1215 {
1216 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ZERO_DATA_INV_LANE,
1217 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ZERO_DATA_INV_LANE));
1218 return MYKONOS_ERR_DBG_ZERO_DATA_INV_LANE;
1219 }
1220
1221 /* JESD framer core selection */
1222 if ((error = MYKONOS_framerCoreSel(jesdCore, MYKONOS_ADDR_FRAMER_DATA_SAMPLE_CTL, &baseAddr)) != MYKONOS_ERR_DBG_OK)
1223 {
1224 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
1225 getDbgJesdMykonosErrorMessage(error));
1226 return error;
1227 }
1228
1229 /* Write Framer Data Zero samples */
1230 CMB_SPIWriteByte(device->spiSettings, baseAddr, lane);
1231
1232 return MYKONOS_ERR_DBG_OK;
1233 }
1234
1235
1236 /**
1237 * \brief Performs get JESD framer Zero data samples.
1238 *
1239 * This functions will get the settings for zero the Framer data samples.
1240 *
1241 * <B>Dependencies</B>
1242 * - device->spiSettings->chipSelectIndex
1243 *
1244 * \param device Pointer to Mykonos device data structure containing settings
1245 * \param jesdCore selection for MYK_FRAMER and MYK_OBS_FRAMER
1246 * \param lane Pointer to store the programmed pattern
1247 *
1248 * \retval MYKONOS_ERR_DBG_ZERO_DATA_LANE_NULL Function parameter lane is a NULL pointer
1249 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
1250 */
1251 mykonosDbgErr_t MYKONOS_framerGetZeroData(mykonosDevice_t *device, mykonos_jesdcore_t jesdCore, mykonosLaneSel_t *lane)
1252 {
1253 mykonosDbgErr_t error = MYKONOS_ERR_DBG_FAIL;
1254 uint16_t baseAddr = 0x00;
1255 uint8_t regRd = 0x00;
1256
1257 const uint8_t LANE_MASK = 0x0F;
1258
1259 #ifdef MYKONOS_VERBOSE
1260 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_OK, "MYKONOS_framerGetZeroData()\n");
1261 #endif
1262
1263 /* Check null parameter passed */
1264 if (lane == NULL)
1265 {
1266 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, MYKONOS_ERR_DBG_ZERO_DATA_LANE_NULL,
1267 getDbgJesdMykonosErrorMessage(MYKONOS_ERR_DBG_ZERO_DATA_LANE_NULL));
1268 return MYKONOS_ERR_DBG_ZERO_DATA_LANE_NULL;
1269 }
1270
1271 /* JESD framer core selection */
1272 if ((error = MYKONOS_framerCoreSel(jesdCore, MYKONOS_ADDR_FRAMER_DATA_SAMPLE_CTL, &baseAddr)) != MYKONOS_ERR_DBG_OK)
1273 {
1274 CMB_writeToLog(ADIHAL_LOG_ERROR, device->spiSettings->chipSelectIndex, error,
1275 getDbgJesdMykonosErrorMessage(error));
1276 return error;
1277 }
1278
1279 /* Read back data zeroed register */
1280 CMB_SPIReadByte(device->spiSettings, baseAddr, &regRd);
1281 regRd = (regRd & LANE_MASK);
1282
1283 /* Write to pointers */
1284 *lane = regRd;
1285
1286 return MYKONOS_ERR_DBG_OK;
1287 }
1288
1289
1290 /**
1291 * \brief Helper function to perform JESD framer core selection.
1292 *
1293 *
1294 * <B>Dependencies</B>
1295 * - device->spiSettings->chipSelectIndex
1296 *
1297 * \param jesdCore selection for FRAMER and OBS_FRAMER
1298 * \param rxFramerAdd base address for Framer selection
1299 * \param baseAddr Pointer to store the selected address base
1300 *
1301 * \retval MYKONOS_ERR_DBG_FRAMER_SEL_BASE_ADD_NULL base address is null
1302 * \retval MYKONOS_ERR_DBG_FRAMER_ILLEGAL_JESD_CORE Only valid JESD cores are FRAMER and OBS_FRAMER
1303 * \retval MYKONOS_ERR_DBG_OK Function completed successfully
1304 */
1305 mykonosDbgErr_t MYKONOS_framerCoreSel(mykonos_jesdcore_t jesdCore, uint16_t rxFramerAdd, uint16_t *baseAddr)
1306 {
1307 const uint16_t OFFSET = 0xD67;
1308
1309 /* Check null parameter passed */
1310 if (baseAddr == NULL)
1311 {
1312 return MYKONOS_ERR_DBG_FRAMER_SEL_BASE_ADD_NULL;
1313 }
1314
1315 /* Check for jesdCore and address assignment */
1316 switch (jesdCore)
1317 {
1318 case MYK_FRAMER:
1319 *baseAddr = rxFramerAdd;
1320 break;
1321
1322 case MYK_OBS_FRAMER:
1323 *baseAddr = rxFramerAdd + OFFSET;
1324 break;
1325
1326 case MYK_DEFRAMER:
1327 default:
1328 return MYKONOS_ERR_DBG_FRAMER_ILLEGAL_JESD_CORE;
1329 break;
1330 }
1331
1332 return MYKONOS_ERR_DBG_OK;
1333 }