Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_commands/AD525x/Command.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file Command.c
3 * @brief Implementation of the commands given by user through UART for ad525x driver.
4 * @author Istvan Csomortani ([email protected])
5 *
6 ********************************************************************************
7 * Copyright 2013(c) Analog Devices, Inc.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 * - Neither the name of Analog Devices, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 * - The use of this software may or may not infringe the patent rights
23 * of one or more patent holders. This license does not release you
24 * from the requirement that you obtain separate licenses from these
25 * patent holders to use this software.
26 * - Use of the software either in source or binary form, must be run
27 * on or directly connected to an Analog Devices Inc. component.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 *******************************************************************************/
41
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 #include "Command.h"
46 #include "Console.h"
47 #include "ad525x.h"
48 #include "TIME.h"
49
50 /******************************************************************************/
51 /************************ Constants Definitions *******************************/
52 /******************************************************************************/
53 const struct cmd_info cmdList[] = {
54 [0] = {
55 .name = "help?",
56 .description = "Displays all available commands.",
57 .acceptedValue = "None",
58 .example = "",
59 },
60 [1] = {
61 .name = "rdac=",
62 .description = "Load the wiper register with a given value.",
63 .acceptedValue = "Accepted value:\r\n\
64 \tchannel:\r\n\
65 \t0 to 3 in function of the device type\r\n\
66 \tvalue:\r\n\
67 \t0 .. 255 or 0 .. 1024 - wiper register value",
68 .example = "To load the wiper register of channel B with 128, \
69 type: rdac=1 128",
70 },
71 [2] = {
72 .name = "rdac?",
73 .description = "Read back the value of the wiper register.",
74 .acceptedValue = "Accepted values:\r\n\
75 \tchannel:\r\n\
76 \t0 .. 3 in function of the device type",
77 .example = "To read back the value of the wiper register of channel B, \
78 type: rdac?1",
79 },
80 [3] = {
81 .name = "reset!",
82 .description = "Reset all wiper register to its stored values",
83 .acceptedValue = "None",
84 .example = "",
85 },
86 [4] = {
87 .name = "restore=",
88 .description = "Restore the specified wiper register setting form the \
89 memory",
90 .acceptedValue = "Accepted value:\r\n\
91 \tchannel:\r\n\
92 \t0 to 3 in function of the device type",
93 .example = "To restore the wiper register of channel B, \
94 type: restore=1",
95 },
96 [5] = {
97 .name = "save=",
98 .description = "Save the given wiper register settings to the memory",
99 .acceptedValue = "Accepted value:\r\n\
100 \tchannel:\r\n\
101 \t0 to 3 in function of the device type",
102 .example = "To save the wiper register of channel B, \
103 type: save=1",
104 },
105 [6] = {
106 .name = "writemem=",
107 .description = "Write to one of the user memory address",
108 .acceptedValue = "Accepted value:\r\n\
109 \taddress:\r\n\
110 \t0x0 to 0xF (may vary at some devices)\r\n\
111 \tdata:\r\n\
112 \t0 .. 255 or 0 .. 1023 in function of the position number of the current device.",
113 .example = "To write 127 to address 0x8 into the EEMEM memory, type: \
114 writemem=0x8 127",
115 },
116 [7] = {
117 .name = "readmem=",
118 .description = "Read data from the EEMEM memory.",
119 .acceptedValue = "Accepted value:\r\n\
120 \taddress:\r\n\
121 \t0x0 to 0xF (may vary at some devices)",
122 .example = "To read the 0x8 address from the EEMEM memory, type: \
123 readmem=0x8",
124 },
125 [8] = {
126 .name = "decrdacdb=",
127 .description = "Decrement a given wiper register by 6dB.",
128 .acceptedValue = "Accepted value:\r\n\
129 \tchannel:\r\n\
130 \t0 to 3 in function of the device type",
131 .example = "To decrement the wiper register of channel A by 6dB, \
132 type: decrdacdb=0",
133 },
134 [9] = {
135 .name = "decrdacdball!",
136 .description = "Decrement all wiper register by 6dB.",
137 .acceptedValue = "None",
138 .example = "To decrement all the wiper register by 6dB, \
139 type: decrdacdball!",
140 },
141 [10] = {
142 .name = "decrdac=",
143 .description = "Decrement a given wiper register by one.",
144 .acceptedValue = "Accepted value:\r\n\
145 \tchannel:\r\n\
146 \t0 to 3 in function of the device type",
147 .example = "To decrement the wiper register of channel A by one, \
148 type: decrdac=0",
149 },
150 [11] = {
151 .name = "decrdacall!",
152 .description = "Decrement all wiper register by one.",
153 .acceptedValue = "None",
154 .example = "To decrement all the wiper register by one, \
155 type: decrdacall!",
156 },
157 [12] = {
158 .name = "incrdacdb=",
159 .description = "Increment a given wiper register by 6dB.",
160 .acceptedValue = "Accepted value:\r\n\
161 \tchannel:\r\n\
162 \t0 to 3 in function of the device type",
163 .example = "To increment the wiper register of channel A by 6dB, \
164 type: incrdacdb=0",
165 },
166 [13] = {
167 .name = "incrdacdball!",
168 .description = "Increment all wiper register by 6dB.",
169 .acceptedValue = "None",
170 .example = "To increment all the wiper register by 6dB, \
171 type: incrdacdball!",
172 },
173 [14] = {
174 .name = "incrdac=",
175 .description = "Increment a given wiper register by one.",
176 .acceptedValue = "Accepted value:\r\n\
177 \tchannel:\r\n\
178 \t0 to 3 in function of the device type",
179 .example = "To increment the wiper register of channel A by one, \
180 type: incrdacdb=0",
181 },
182 [15] = {
183 .name = "incrdacall!",
184 .description = "Increment all wiper register by one.",
185 .acceptedValue = "None",
186 .example = "To increment all the wiper register by one, \
187 type: incrdacall!",
188 },
189 [16] = {
190 .name = "setwp=",
191 .description = "Set the state of the Write Protect (WP) pin",
192 .acceptedValue = "Accepted value:\r\n\
193 \tdesire state of the pin:\r\n\
194 \t0 - inactive\r\n\
195 \t1 - active",
196 .example = "To activate the WP pin, type: setwp=1",
197 },
198 [17] = {
199 .name = "getwp?",
200 .description = "Return the current value of the Write Protect (WP) pin",
201 .acceptedValue = "None",
202 .example = "",
203 },
204 [18] = {
205 .name = "sethwreset=",
206 .description = "Set the state of the Hardware Override Preset (PR) pin",
207 .acceptedValue = "Accepted value:\r\n\
208 \tdesire state of the pin:\r\n\
209 \t0 - inactive\r\n\
210 \t1 - active",
211 .example = "To activate the hardware RESET pin, type: sethwreset=1",
212 },
213 [19] = {
214 .name = "gethwreset?",
215 .description = "Return the current value of the Hardware Override \
216 Preset (PR) pin",
217 .acceptedValue = "None",
218 .example = "",
219 },
220 [20] = {
221 .name = "tolerance=",
222 .description = "Read one of the Tolerance register.",
223 .acceptedValue = "Accepted value:\r\n\
224 \tchannel:\r\n\
225 \t0 to 7 in function of the device type",
226 .example = "To read the value of the first tolerance register, \
227 type: tolerance=0",
228 }
229 };
230
231 const char cmdNo = (sizeof(cmdList) / sizeof(struct cmd_info));
232
233 /******************************************************************************/
234 /************************ Variables Definitions *******************************/
235 /******************************************************************************/
236 cmdFunction cmdFunctions[21] = {GetHelp, SetRdac, GetRdac, DoReset, DoRestore, \
237 SaveSettings, WriteToMem, ReadFromMem, \
238 DecRdac6dB, DecAllRdac6dB, DecRdac, DecAllRdac,\
239 IncRdac6dB, IncAllRdac6dB, IncRdac, IncAllRdac, \
240 SetWrPin, GetWrPin, SetPrPin, GetPrPin, \
241 GetTolerance};
242
243 AD525X_type_t deviceType;
244
245 unsigned char deviceSlaveId = 1;
246 unsigned char channelNo = 0;
247 unsigned short maxPosition = 0;
248 /* Memory address limits */
249 unsigned char lowerAddressLimit = 0;
250 unsigned char upperAddressLimit = 0;
251 unsigned char nrToleranceReg = 0;
252 /* Buffers to store control pin's voltage level */
253 unsigned char writeProtectBuff = 0;
254 unsigned char overridePreset = 0;
255
256 /******************************************************************************/
257 /************************ Functions Definitions *******************************/
258 /******************************************************************************/
259
260 /***************************************************************************//**
261 * @brief Internal function for displaying error messages.
262 *
263 * @param funcNo - the index of the function in 'cmdFunctions' constant array
264 *
265 * @return None.
266 *******************************************************************************/
267 void DisplayError(unsigned char funcNo)
268 {
269 /* Display error messages */
270 CONSOLE_Print("Invalid parameter!\r\n");
271 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[funcNo].name, \
272 (char*)cmdList[funcNo].description,
273 (char*)cmdList[funcNo].acceptedValue);
274 CONSOLE_Print("Example: %s\r\n", (char*)cmdList[funcNo].example);
275 }
276
277 /***************************************************************************//**
278 * @brief Internal function for displaying all the command with its description.
279 *
280 * @return None.
281 *******************************************************************************/
282 void DisplayCmdList()
283 {
284 unsigned char displayCmd;
285
286 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
287 {
288 CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \
289 (char*)cmdList[displayCmd].description);
290 }
291 }
292
293 /***************************************************************************//**
294 * @brief Internal function for verify if the given parameter is between his
295 * valid limits.
296 *
297 * @param None.
298 *
299 * @return None.
300 *******************************************************************************/
301 void paramLimit(double* param,
302 unsigned short lowerLimit,
303 unsigned short upperLimit)
304 {
305 if(*param < lowerLimit)
306 {
307 *param = lowerLimit;
308 }
309 else
310 {
311 if(*param > upperLimit)
312 {
313 *param = upperLimit;
314 }
315 }
316 }
317
318 /***************************************************************************//**
319 * @brief Displays all available commands.
320 *
321 * @return None.
322 *******************************************************************************/
323 void GetHelp(double* param, char paramNo) // "help?" command
324 {
325 unsigned char displayCmd;
326
327 CONSOLE_Print("Available commands:\r\n");
328 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
329 {
330 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[displayCmd].name,
331 (char*)cmdList[displayCmd].description,
332 (char*)cmdList[displayCmd].acceptedValue);
333 }
334 }
335
336 /***************************************************************************//**
337 * @brief Set the current device type.
338 *
339 * @return None.
340 *******************************************************************************/
341 void DoDeviceLock(void)
342 {
343 char device = 0;
344 char deviceLocked = -1;
345
346 while(deviceLocked < 0)
347 {
348 CONSOLE_Print("Please specify your device.\r\n\
349 For AD5232 type: 0\r\n\
350 For AD5235 type: 1\r\n\
351 For AD5252 type: 2\r\n\
352 For AD5254 type: 3\r\n\
353 For ADN2850 type: 4\r\n");
354
355 CONSOLE_GetCommand(&device);
356 if((device >= 0x30) && (device <= 0x34))
357 {
358 deviceLocked = 1;
359 switch(device)
360 {
361 case 0x30 :
362 deviceType = ID_AD5232;
363 channelNo = 2;
364 maxPosition = 255;
365 deviceSlaveId = 1;
366 lowerAddressLimit = 0x2;
367 upperAddressLimit = 0xF;
368 nrToleranceReg = 0;
369 break;
370 case 0x31 :
371 deviceType = ID_AD5235;
372 channelNo = 2;
373 maxPosition = 1023;
374 deviceSlaveId = 1;
375 lowerAddressLimit = 0x2;
376 upperAddressLimit = 0xE;
377 nrToleranceReg = 1;
378 break;
379 case 0x32 :
380 deviceType = ID_AD5252;
381 channelNo = 2;
382 maxPosition = 255;
383 deviceSlaveId = 1;
384 lowerAddressLimit = 0x4;
385 upperAddressLimit = 0xF;
386 nrToleranceReg = 4;
387 break;
388 case 0x33 :
389 deviceType = ID_AD5254;
390 channelNo = 4;
391 maxPosition = 255;
392 deviceSlaveId = 0;
393 lowerAddressLimit = 0x4;
394 upperAddressLimit = 0xF;
395 nrToleranceReg = 8;
396 break;
397 case 0x34 :
398 deviceType = ID_ADN2850;
399 channelNo = 2;
400 maxPosition = 1023;
401 deviceSlaveId = 1;
402 lowerAddressLimit = 0x2;
403 upperAddressLimit = 0xE;
404 nrToleranceReg = 1;
405 break;
406 }
407 }
408 else
409 {
410 CONSOLE_Print("Please type the number corresponding for \
411 your device!\r\n");
412 }
413 }
414 }
415
416 /***************************************************************************//**
417 * @brief Initializes the device.
418 *
419 * @return - The result of the initialization.
420 * Example: ERROR - the device was not initialized or the device
421 * is not present.
422 * SUCCES - the device was initialized and the device
423 * is present.
424 *******************************************************************************/
425 char DoDeviceInit(void)
426 {
427 DoDeviceLock();
428
429 if(AD525X_Init(deviceType) == 0)
430 {
431 CONSOLE_Print("Device OK\r\n");
432 DisplayCmdList();
433 return SUCCESS;
434 }
435 else
436 {
437 CONSOLE_Print("Device Error\r\n");
438 return ERROR;
439 }
440 }
441
442 /***************************************************************************//**
443 * @brief Set wiper register value.
444 *
445 * @param - param[0] - The number of the channel, which have to updated
446 * - param[1] - The desired value of the resistor
447 *
448 * @return - NONE
449 *
450 *******************************************************************************/
451 void SetRdac(double* param, char paramNo)
452 {
453 unsigned char channel = 0;
454 unsigned short data = 0;
455
456 /* Check if the parameter is valid */
457 if(paramNo >= 2)
458 {
459 paramLimit(&param[0], 0, channelNo-1);
460 paramLimit(&param[1], 0, maxPosition);
461 channel = (unsigned char)param[0];
462 data = (unsigned short)param[1];
463 /* Write to RDAC register */
464 AD525X_WriteRdac(deviceSlaveId, channel, data);
465 CONSOLE_Print("RDAC[%d]=%d\r\n", channel, data);
466 }
467 else
468 {
469 /* Display error messages */
470 DisplayError(1);
471 }
472 }
473
474 /***************************************************************************//**
475 * @brief Get wiper register value.
476 *
477 * @param - param[0] - The number of the channel, which have to updated
478 *
479 * @return - NONE
480 *
481 *******************************************************************************/
482 void GetRdac(double* param, char paramNo)
483 {
484 unsigned char channel = 0;
485 unsigned short data = 0;
486
487 /* Check if the parameter is valid */
488 if(paramNo >= 1)
489 {
490 paramLimit(&param[0], 0, channelNo-1);
491 channel = (unsigned char)param[0];
492 data = AD525X_ReadRdac(deviceSlaveId, channel);
493 CONSOLE_Print("RDAC[%d]=%d\r\n", channel, data);
494 }
495 else
496 {
497 /* Display error messages */
498 DisplayError(2);
499 }
500 }
501
502 /***************************************************************************//**
503 * @brief Reset all wiper register to its stored values.
504 *
505 * @param - NONE
506 *
507 * @return - NONE
508 *
509 *******************************************************************************/
510 void DoReset(double* param, char paramNo)
511 {
512 AD525X_WriteCommand(deviceSlaveId,
513 AD525X_CMD_RESET,
514 0x0);
515 CONSOLE_Print("Reset done.\r\n");
516 }
517
518 /***************************************************************************//**
519 * @brief Restore the specified wiper register setting form the memory
520 *
521 * @param - param[0] - The number of the channel, which have to updated
522 *
523 * @return - NONE
524 *
525 *******************************************************************************/
526 void DoRestore(double* param, char paramNo)
527 {
528 unsigned char channel = 0;
529
530 /* Check if the parameter is valid */
531 if(paramNo >= 1)
532 {
533 paramLimit(&param[0], 0, (channelNo - 1));
534 channel = (unsigned char)param[0];
535 AD525X_WriteCommand(deviceSlaveId,
536 AD525X_CMD_MEM2RDAC,
537 channel);
538 CONSOLE_Print("The channel %d was restored to its saved value.\r\n", \
539 channel);
540 }
541 else
542 {
543 /* Display error messages */
544 DisplayError(4);
545 }
546 }
547
548 /***************************************************************************//**
549 * @brief Save the current wiper register settings to the memory
550 *
551 * @param - param[0] - The number of the channel, which have to updated
552 *
553 * @return - NONE
554 *
555 *******************************************************************************/
556 void SaveSettings(double* param, char paramNo)
557 {
558 unsigned char channel = 0;
559
560 /* Check if the parameter is valid */
561 if(paramNo >= 1)
562 {
563 paramLimit(&param[0], 0, (channelNo - 1));
564 channel = (unsigned char)param[0];
565 AD525X_WriteCommand(deviceSlaveId,
566 AD525X_CMD_RDAC2MEM,
567 channel);
568 CONSOLE_Print("The value of channel %d was saved to memory.\r\n", \
569 channel);
570 }
571 else
572 {
573 /* Display error messages */
574 DisplayError(5);
575 }
576 }
577
578 /***************************************************************************//**
579 * @brief Write to a given memory address
580 *
581 * @param - param[0] - EEMEM memory address
582 * - param[1] - the value which will be written into the memory
583 *
584 * @return - NONE
585 *
586 *******************************************************************************/
587 void WriteToMem(double* param, char paramNo)
588 {
589 unsigned char address = 0;
590 unsigned short data = 0;
591
592 if(paramNo >= 2)
593 {
594 paramLimit(&param[0], lowerAddressLimit, upperAddressLimit);
595 paramLimit(&param[1], 0, maxPosition);
596 address = (unsigned char)param[0];
597 data = (unsigned short)param[1];
598 AD525X_WriteMem(deviceSlaveId,
599 address,
600 data);
601 CONSOLE_Print("EEMEM[0x%.2x]=%d\r\n", address, data);
602 }
603 else
604 {
605 /* Display error messages */
606 DisplayError(6);
607 }
608 }
609
610 /***************************************************************************//**
611 * @brief Read from a given memory address
612 *
613 * @param - param[0] - EEMEM memory address
614 *
615 * @return - The data stored at the given memory address
616 *
617 *******************************************************************************/
618 void ReadFromMem(double* param, char paramNo)
619 {
620 unsigned char address = 0;
621 unsigned short data = 0;
622
623 if(paramNo >= 1)
624 {
625 paramLimit(&param[0], lowerAddressLimit, upperAddressLimit);
626 address = (unsigned char)param[0];
627 data = AD525X_ReadMem(deviceSlaveId,
628 address);
629 CONSOLE_Print("EEMEM[0x%.2x]=%d\r\n", address, data);
630 }
631 else
632 {
633 /* Display error messages */
634 DisplayError(7);
635 }
636 }
637
638 /***************************************************************************//**
639 * @brief Decrement a wiper register by 6dB
640 *
641 * @param - param[0] - The number of the channel, which have to updated
642 *
643 * @return - NONE
644 *
645 *******************************************************************************/
646 void DecRdac6dB(double* param, char paramNo)
647 {
648 unsigned char channel = 0;
649
650 if(paramNo >= 1)
651 {
652 paramLimit(&param[0], 0, (channelNo - 1));
653 channel = (unsigned char)param[0];
654 AD525X_WriteCommand(deviceSlaveId,
655 AD525X_CMD_DECRDAC_6DB,
656 channel);
657 CONSOLE_Print("The value of channel %d was decremented by 6 dB.\r\n", \
658 channel);
659 }
660 else
661 {
662 /* Display error messages */
663 DisplayError(8);
664 }
665 }
666
667 /***************************************************************************//**
668 * @brief Decrement all wiper register by 6dB
669 *
670 * @param - NONE
671 *
672 * @return - NONE
673 *
674 *******************************************************************************/
675 void DecAllRdac6dB(double* param, char paramNo)
676 {
677 AD525X_WriteCommand(deviceSlaveId,
678 AD525X_CMD_DECALLRDAC_6DB,
679 0x0);
680 CONSOLE_Print("All channels were decremented by 6 dB.\r\n");
681 }
682
683 /***************************************************************************//**
684 * @brief Decrement a wiper register by one
685 *
686 * @param - param[0] - The number of the channel, which have to updated
687 *
688 * @return - NONE
689 *
690 *******************************************************************************/
691 void DecRdac(double* param, char paramNo)
692 {
693 unsigned char channel = 0;
694
695 if(paramNo >= 1)
696 {
697 paramLimit(&param[0], 0, (channelNo - 1));
698 channel = (unsigned char)param[0];
699 AD525X_WriteCommand(deviceSlaveId,
700 AD525X_CMD_DECRDAC_ONE,
701 channel);
702 CONSOLE_Print("The value of channel %d was decremented by one.\r\n", \
703 channel);
704 }
705 else
706 {
707 /* Display error messages */
708 DisplayError(10);
709 }
710 }
711
712 /***************************************************************************//**
713 * @brief Decrement all wiper register by one
714 *
715 * @param - NONE
716 *
717 * @return - NONE
718 *
719 *******************************************************************************/
720 void DecAllRdac(double* param, char paramNo)
721 {
722 AD525X_WriteCommand(deviceSlaveId,
723 AD525X_CMD_DECALLRDAC_ONE,
724 0x0);
725 CONSOLE_Print("All channels were decremented by one.\r\n");
726 }
727
728 /***************************************************************************//**
729 * @brief Increment a wiper register by 6dB
730 *
731 * @param - param[0] - The number of the channel, which have to updated
732 *
733 * @return - NONE
734 *
735 *******************************************************************************/
736 void IncRdac6dB(double* param, char paramNo)
737 {
738 unsigned char channel = 0;
739
740 if(paramNo >= 1)
741 {
742 paramLimit(&param[0], 0, (channelNo - 1));
743 channel = (unsigned char)param[0];
744 AD525X_WriteCommand(deviceSlaveId,
745 AD525X_CMD_INCRDAC_6DB,
746 channel);
747 CONSOLE_Print("The value of channel %d was incremented by 6 dB.\r\n", \
748 channel);
749 }
750 else
751 {
752 /* Display error messages */
753 DisplayError(12);
754 }
755 }
756
757 /***************************************************************************//**
758 * @brief Increment all wiper register by 6dB
759 *
760 * @param - NONE
761 *
762 * @return - NONE
763 *
764 *******************************************************************************/
765 void IncAllRdac6dB(double* param, char paramNo)
766 {
767 AD525X_WriteCommand(deviceSlaveId,
768 AD525X_CMD_INCALLRDAC_6DB,
769 0x0);
770 CONSOLE_Print("All channels were incremented by 6 dB.\r\n");
771 }
772
773 /***************************************************************************//**
774 * @brief Increment a wiper register by one
775 *
776 * @param - param[0] - The number of the channel, which have to updated
777 *
778 * @return - NONE
779 *
780 *******************************************************************************/
781 void IncRdac(double* param, char paramNo)
782 {
783 unsigned char channel = 0;
784
785 if(paramNo >= 1)
786 {
787 paramLimit(&param[0], 0, (channelNo - 1));
788 channel = (unsigned char)param[0];
789 AD525X_WriteCommand(deviceSlaveId,
790 AD525X_CMD_INCRDAC_ONE,
791 channel);
792 CONSOLE_Print("The value of channel %d was incremented by one.\r\n", \
793 channel);
794 }
795 else
796 {
797 /* Display error messages */
798 DisplayError(14);
799 }
800 }
801
802 /***************************************************************************//**
803 * @brief Increment all wiper register by one
804 *
805 * @param - param[0] - The number of the channel, which have to updated
806 *
807 * @return - NONE
808 *
809 *******************************************************************************/
810 void IncAllRdac(double* param, char paramNo)
811 {
812 AD525X_WriteCommand(deviceSlaveId,
813 AD525X_CMD_INCALLRDAC_ONE,
814 0x0);
815 CONSOLE_Print("All channels were incremented by one.\r\n");
816 }
817
818 /***************************************************************************//**
819 * @brief Set the state of the Write Protect (WP) pin. When active low, WP
820 * prevents any changes to the present register contents, except PR,
821 * Command Instruction 1, and Command Instruction 8, which refresh the
822 * RDACx register from EEMEM.
823 *
824 * @param - param[0] - The desired state of the WR pin
825 * - '0' - WR pin is inactive, voltage level high
826 * - '1' - WR pin is active, voltage level low
827 *
828 * @return - NONE
829 *
830 *******************************************************************************/
831 void SetWrPin(double* param, char paramNo)
832 {
833 if(paramNo >= 1)
834 {
835 paramLimit(&param[0], 0, 1);
836 if((param[0] == 0) && (writeProtectBuff == 1)) // inactivate
837 {
838 /* NOP instruction before returning WP to HIGH */
839 AD525X_WriteCommand(deviceSlaveId,
840 AD525X_CMD_NOP,
841 0);
842 TIME_DelayUs(50);
843 AD525X_WP_BF_HIGH; // change the logical state of the pin
844 writeProtectBuff = 0; // save the new state into the buffer
845 CONSOLE_Print("WP is inactive.\r\n");
846 }
847 else if((param[0] == 1) && (writeProtectBuff == 0)) // activate
848 {
849 AD525X_WP_BF_LOW;
850 writeProtectBuff = 1;
851 CONSOLE_Print("WP was activated.\r\n");
852 }
853 }
854 else
855 {
856 /* Display error messages */
857 DisplayError(16);
858 }
859 }
860
861 /***************************************************************************//**
862 * @brief Get the current state of the Write Protect (WP) pin.
863 *
864 * @param - NONE
865 *
866 * @return - NONE
867 *
868 *******************************************************************************/
869 void GetWrPin(double* param, char paramNo)
870 {
871 if(writeProtectBuff)
872 {
873 CONSOLE_Print("The WR pin is at active low state.\r\n");
874 }
875 else
876 {
877 CONSOLE_Print("The WR pin is at inactive high state.\r\n");
878 }
879 }
880
881 /***************************************************************************//**
882 * @brief Set the state of the Hardware Override Preset (PR) pin. Refresh the
883 * scratch pad register with current contents of the EEMEMx register.
884 *
885 * @param - param[0] - The desired state of the WR pin
886 * - '1' - WR pin is inactive, voltage level high
887 * - '0' - WR pin is active, voltage level low
888 *
889 * @return - NONE
890 *
891 *******************************************************************************/
892 void SetPrPin(double* param, char paramNo)
893 {
894 if((deviceType == ID_AD5252) || (deviceType == ID_AD5254))
895 {
896 CONSOLE_Print("This function is not supported by the current device.\r\n");
897 }
898 else
899 {
900 if(paramNo >= 1)
901 {
902 paramLimit(&param[0], 0, 1);
903 if((param[0] == 1) && (overridePreset == 0)) // activate
904 {
905 AD525X_RESET_LOW;
906 overridePreset = 1;
907 CONSOLE_Print("The hardware RESET is activated.\r\n");
908 } else if((param[0] == 0) && (overridePreset == 1)) // inactivate
909 {
910 AD525X_RESET_HIGH;
911 overridePreset = 0;
912 CONSOLE_Print("The hardware RESET is inactive.\r\n");
913 }
914 }
915 else
916 {
917 /* Display error messages */
918 DisplayError(18);
919 }
920 }
921
922 }
923
924 /***************************************************************************//**
925 * @brief Set the state of the Hardware Override Preset (PR) pin.
926 *
927 * @param - NONE
928 *
929 * @return - NONE
930 *
931 *******************************************************************************/
932 void GetPrPin(double* param, char paramNo)
933 {
934 if((deviceType == ID_AD5252) || (deviceType == ID_AD5254))
935 {
936 CONSOLE_Print("This function is not supported by the current device.\r\n");
937 }
938 else
939 {
940 if(overridePreset)
941 {
942 CONSOLE_Print("The RESET pin is at active low state.\r\n");
943 }
944 else
945 {
946 CONSOLE_Print("The RESET pin is at inactive high state.\r\n");
947 }
948 }
949 }
950
951 /***************************************************************************//**
952 * @brief Read one of the Tolerance register.
953 *
954 * @param - param[0] - The relative address of the tolerance register.
955 * The number of available tolerance register varying in
956 * case of every device. Accepted value: (0 .. NrTolReg - 1)
957 *
958 * @return - NONE
959 *
960 * Note : To get a usable data, have to make some conversation with the result.
961 * You can find more information in the data sheet.
962 *******************************************************************************/
963 void GetTolerance(double* param, char paramNo)
964 {
965 unsigned char address = 0;
966 unsigned short data = 0;
967
968 if(deviceType == ID_AD5232)
969 {
970 CONSOLE_Print("This function is not supported by the current device.\r\n");
971 }
972 else
973 {
974 if(paramNo >= 1)
975 {
976 /* Define the address in function of the device type */
977 paramLimit(&param[0], 0, (nrToleranceReg - 1));
978 switch(deviceType)
979 {
980 case ID_AD5235 :
981 address = 0xF + (unsigned char)param[0];
982 break;
983 case ID_AD5252 :
984 address = (param[0]>1) ? (0x1C + (unsigned char)param[0]) :
985 (0x1A + (unsigned char)param[0]);
986 break;
987 case ID_AD5254 :
988 address = 0x18 + (unsigned char)param[0];
989 break;
990 case ID_ADN2850 :
991 address = 0xF + (unsigned char)param[0];
992 break;
993 default :
994 break;
995 }
996 data = AD525X_ReadMem(deviceSlaveId,
997 address);
998 CONSOLE_Print("TolReg[0x%02x]=0x%4x\r\n", \
999 (unsigned char)param[0], data);
1000 }
1001 else
1002 {
1003 /* Display error messages */
1004 DisplayError(20);
1005 }
1006 }
1007 }