Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file Command.c
3 * @brief Implementation of the commands given by user through UART for AD5629R.
4 * @author Lucian Sin ([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 "ad5629r.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 = "",
58 .example = "",
59 },
60 [1] = {
61 .name = "reset!",
62 .description = "Makes a power-on reset.",
63 .acceptedValue = "",
64 .example = "",
65 },
66 [2] = {
67 .name = "powerMode=",
68 .description = "Selects a given power mode for selected DAC.",
69 .acceptedValue = "Accepted values:\r\n\
70 \tchannel:\r\n\
71 \t0 .. 7 - selected DAC A .. H.\r\n\
72 \tpower mode:\r\n\
73 \t0 - normal operation.\r\n\
74 \t1 - 1KOhm to GND.\r\n\
75 \t2 - 100KOhms to GND.\r\n\
76 \t3 - three-state.",
77 .example = "To select 1KOhm to GND power mode for DAC A, type: \
78 powerMode=0 1",
79 },
80 [3] = {
81 .name = "powerMode?",
82 .description = "Displays the power mode for one selected DAC.",
83 .acceptedValue = "Accepted values:\r\n\
84 \tchannel:\r\n\
85 \t0 .. 7 - selected DAC A .. H.",
86 .example = "To display the power mode for DAC B, type:powerMode?1",
87 },
88 [4] = {
89 .name = "intRef=",
90 .description = "Turns on/off the internal reference.",
91 .acceptedValue = "Accepted values:\r\n\
92 \t0 - turns off the internal reference.\r\n\
93 \t1 - turns on the internal reference.",
94 .example = "To power on the internal reference, type: intRef=1",
95 },
96 [5] = {
97 .name = "intRef?",
98 .description = "Displays the status of the internal reference.",
99 .acceptedValue = "",
100 .example = "",
101 },
102 [6] = {
103 .name = "loadN=",
104 .description = "Loads selected DAC register with a given value.",
105 .acceptedValue = "Accepted values:\r\n\
106 \tchannel:\r\n\
107 \t0 .. 7 - selected DAC A .. H.\r\n\
108 \t15 - all DACs. \r\n\
109 \tvalue:\r\n\
110 \t0 .. (2^DacResolution)-1 - value to be written in register.",
111 .example = "To load DAC B register with 1000, type: loadN=1 1000",
112 },
113 [7] = {
114 .name = "updateN=",
115 .description = "Updates the selected DAC with the last value written in register.",
116 .acceptedValue = "Accepted values:\r\n\
117 \tchannel:\r\n\
118 \t0 .. 7 - selected DAC A .. H.\r\n\
119 \t15 - all DACs. \r\n\
120 \tvalue:\r\n\
121 \t0 .. (2^DacResolution)-1 - value to be written in register.",
122 .example = "To update DAC H output, type: updateN=7",
123 },
124 [8] = {
125 .name = "loadNUpdateN=",
126 .description = "Loads and updates the selected DAC with a given value.",
127 .acceptedValue = "Accepted values:\r\n\
128 \tchannel:\r\n\
129 \t0 .. 7 - selected DAC A .. H.\r\n\
130 \t15 - all DACs. \r\n\
131 \tvalue:\r\n\
132 \t0 .. (2^DacResolution)-1 - value to be written in register.",
133 .example = "To load and update DAC A with 2000, type: loadNUpdateN=0 \
134 2000",
135 },
136 [9] = {
137 .name = "loadNUpdateAll=",
138 .description = "Loads the selected DAC with a given value and updates \
139 all DACs.",
140 .acceptedValue = "Accepted values:\r\n\
141 \tchannel:\r\n\
142 \t0 .. 7 - selected DAC A .. H.\r\n\
143 \t15 - all DACs. \r\n\
144 \tvalue:\r\n\
145 \t0 .. (2^DacResolution)-1 - value to be written in register.",
146 .example = "To load DAC C with 4000 and update all DAC outputs, type: \
147 loadNUpdateAll=2 4000",
148 },
149 [10] = {
150 .name = "enLdacPin=",
151 .description = "Enables/Disables the LDAC pin for selected DAC.",
152 .acceptedValue = "Accepted values:\r\n\
153 \tchannel:\r\n\
154 \t0 .. 7 - selected DAC A .. H.\r\n\
155 \tvalue:\r\n\
156 \t1 - disable LDAC pin.\r\n\
157 \t0 - enable LDAC pin.",
158 .example = "To disable the LDAC pin for DAC H, type: enLdacPin=7 1",
159 },
160 [11] = {
161 .name = "enLdacPin?",
162 .description = "Displays the status(enabled or disabled) of the LDAC \
163 pin for a selected DAC.",
164 .acceptedValue = "Accepted values:\r\n\
165 \tchannel:\r\n\
166 \t0 .. 7 - selected DAC A .. H.",
167 .example = "To display the status of LDAC pin for DAC D, type: \
168 enLdacPin?3",
169 },
170 [12] = {
171 .name = "clrCode=",
172 .description = "Loads Clear Code Register with specific clear code.",
173 .acceptedValue = "Accepted values:\r\n\
174 \t0 - clears code to zero scale when CLR pin goes from high to low.\r\n\
175 \t1 - clears code to midscale when CLR pin goes from high to low.\r\n\
176 \t2 - clears code to full scale when CLR pin goes from high to low.\r\n\
177 \t3 - no operation.",
178 .example = "To set the active clear code to midscale, type: clrCode=1",
179 },
180 [13] = {
181 .name = "clrCode?",
182 .description = "Displays the active clear code.",
183 .acceptedValue = "",
184 .example = "",
185 },
186 [14] = {
187 .name = "ldacPin=",
188 .description = "Sets the output value of LDAC pin.",
189 .acceptedValue = "Accepted values:\r\n\
190 \t0 - sets LDAC pin low.(default)\r\n\
191 \t1 - sets LDAC pin high.",
192 .example = "To set the LDAC pin high, type: ldacPin=1",
193 },
194 [15] = {
195 .name = "ldacPin?",
196 .description = "Displays the value of LDAC pin.",
197 .acceptedValue = "",
198 .example = "",
199 },
200 [16] = {
201 .name = "clrPin=",
202 .description = "Sets the output value of CLR pin.",
203 .acceptedValue = "Accepted values:\r\n\
204 \t0 - sets CLR pin low.\r\n\
205 \t1 - sets CLR pin high.(default)",
206 .example = "To set the CLR pin low, type: clrPin=0",
207 },
208 [17] = {
209 .name = "clrPin?",
210 .description = "Displays the value of CLR pin.",
211 .acceptedValue = "",
212 .example = "",
213 }
214 };
215
216 const char cmdNo = (sizeof(cmdList) / sizeof(struct cmd_info));
217
218 /******************************************************************************/
219 /************************ Variables Definitions *******************************/
220 /******************************************************************************/
221 cmdFunction cmdFunctions[18] = {GetHelp, DoReset, SetPowerMode, GetPowerMode,
222 SetIntRef,GetIntRef, SetLoadN, SetUpdateN,
223 SetLoadNAndUpdateN, SetLoadNAndUpdateAll,
224 SetEnLdacPin, GetEnLdacPin, SetClrCode,
225 GetClrCode, SetLdacPin, GetLdacPin,
226 SetClrPin, GetClrPin};
227
228 /* Variables holding information about the device */
229 AD5629R_type deviceType;
230 unsigned char ldac = 0;
231 unsigned char clr = 1;
232 unsigned short max_value = 0;
233 unsigned char ref = 0;
234 unsigned char clrCode = 0;
235 unsigned char powerMode[8] = {0, 0, 0, 0, 0, 0, 0, 0};
236 unsigned char ldacRegVal = 0;
237
238
239 /***************************************************************************//**
240 * @brief Internal function for displaying error messages.
241 *
242 * @return None.
243 *******************************************************************************/
244 void DisplayError(unsigned char funcNo)
245 {
246 /* Display error messages */
247 CONSOLE_Print("Invalid parameter!\r\n");
248 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[funcNo].name, \
249 (char*)cmdList[funcNo].description,
250 (char*)cmdList[funcNo].acceptedValue);
251 CONSOLE_Print("Example: %s\r\n", (char*)cmdList[funcNo].example);
252 }
253
254 /***************************************************************************//**
255 * @brief Internal function for displaying all the command with its description.
256 *
257 * @return None.
258 *******************************************************************************/
259 void DisplayCmdList()
260 {
261 unsigned char displayCmd;
262
263 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
264 {
265 CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \
266 (char*)cmdList[displayCmd].description);
267 }
268 }
269
270 /***************************************************************************//**
271 * @brief Displays all available commands.
272 *
273 * @return None.
274 *******************************************************************************/
275 void GetHelp(double* param, char paramNo) // "help?" command
276 {
277 unsigned char displayCmd;
278
279 CONSOLE_Print("Available commands:\r\n");
280 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
281 {
282 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[displayCmd].name,
283 (char*)cmdList[displayCmd].description,
284 (char*)cmdList[displayCmd].acceptedValue);
285 }
286 }
287
288 /***************************************************************************//**
289 * @brief Set the current device type.
290 *
291 * @return None.
292 *******************************************************************************/
293 void DoDeviceLock(void)
294 {
295 char device = 0;
296 char deviceLocked = -1;
297
298 while(deviceLocked < 0)
299 {
300 CONSOLE_Print("Please specify your device.\r\n\
301 For AD5629R type: 0\r\n\
302 For AD5669R type: 1\r\n\
303 For AD5668 type: 2\r\n\
304 For AD5648 type: 3\r\n\
305 For AD5628 type: 4\r\n\
306 ");
307 CONSOLE_GetCommand(&device);
308 if((device >= 0x30) && (device <= 0x34))
309 {
310 deviceLocked = 1;
311 switch(device)
312 {
313 case 0x30 :
314 {
315 deviceType = ID_AD5629R;
316 max_value = 0xFFF;
317 break;
318 }
319 case 0x31 :
320 {
321 deviceType = ID_AD5669R;
322 max_value = 0xFFFF;
323 break;
324 }
325 case 0x32 :
326 {
327 deviceType = ID_AD5668;
328 max_value = 0xFFFF;
329 break;
330 }
331 case 0x33 :
332 {
333 deviceType = ID_AD5648;
334 max_value = 0x3FFF;
335 break;
336 }
337 case 0x34 :
338 {
339 deviceType = ID_AD5628;
340 max_value = 0xFFF;
341 break;
342 }
343 }
344 }
345 else
346 {
347 CONSOLE_Print("Please type the number corresponding for \
348 your device!\r\n");
349 }
350 }
351 }
352
353 /***************************************************************************//**
354 * @brief Initializes the device.
355 *
356 * @return - The result of the initialization.
357 * Example: ERROR - the device was not initialized or the device
358 * is not present.
359 * SUCCES - the device was initialized and the device
360 * is present.
361 *******************************************************************************/
362 char DoDeviceInit(void)
363 {
364 DoDeviceLock();
365
366 if(AD5629R_Init(AD5629R_I2C_ADDR_2, deviceType) == 0)
367 {
368 CONSOLE_Print("Device OK\r\n");
369 DisplayCmdList();
370 return SUCCESS;
371 }
372 else
373 {
374 CONSOLE_Print("Device Error\r\n");
375 return ERROR;
376 }
377 }
378
379 /***************************************************************************//**
380 * @brief Makes a power-on reset.
381 *
382 * @param - none.
383 *
384 * @return - none.
385 *
386 *******************************************************************************/
387 void DoReset(double* param, char paramNo) // "reset!" command
388 {
389 AD5629R_Reset();
390 /* Send feedback to user */
391 CONSOLE_Print("Device was reset.\r\n");
392 }
393
394 /***************************************************************************//**
395 * @brief Selects a given power mode for selected DAC.
396 *
397 * @param param[0] - selected DAC.
398 * param[1] - selected power mode.
399 *
400 * @return None.
401 *******************************************************************************/
402 void SetPowerMode(double* param, char paramNo) // "powerMode=" command
403 {
404
405 unsigned char channel = 0;
406 unsigned char mode = 0;
407
408 /* Check if the parameters are valid */
409 if(paramNo >= 2)
410 {
411 if(param[0] < 0)
412 {
413 param[0] = 0;
414 }
415 else
416 {
417 if(param[0] > 7)
418 {
419 param[0] = 7;
420 }
421 }
422
423 if(param[1] < 0)
424 {
425 param[1] = 0;
426 }
427 else
428 {
429 if(param[1] > 3)
430 {
431 param[1] = 3;
432 }
433 }
434
435 channel = (unsigned char)param[0];
436 mode = (unsigned char)param[1];
437 AD5629R_SetPowerMode((1 << channel), mode);
438 powerMode[channel] = mode;
439 /* Send feedback to user */
440 CONSOLE_Print("channel=%d; powerMode=%d\r\n",channel, mode);
441 }
442 else
443 {
444 /* Display error messages */
445 DisplayError(2);
446 }
447 }
448
449 /***************************************************************************//**
450 * @brief Displays the power mode for one selected DAC.
451 *
452 * @param param[0] - selected DAC.
453 *
454 * @return None.
455 *******************************************************************************/
456 void GetPowerMode(double* param, char paramNo) // "powerMode?" command
457 {
458 unsigned char channel = 0;
459
460 /* Check if the parameters are valid */
461 if(paramNo >= 1)
462 {
463 if(param[0] < 0)
464 {
465 param[0] = 0;
466 }
467 else
468 {
469 if(param[0] > 7)
470 {
471 param[0] = 7;
472 }
473 }
474
475 channel = (unsigned char)param[0];
476 /* Send requested value to user */
477 CONSOLE_Print("channel=%d; powerMode=%d\r\n",channel, powerMode[channel]);
478 }
479 else
480 {
481 /* Display error messages */
482 DisplayError(3);
483 }
484 }
485
486 /***************************************************************************//**
487 * @brief Turns on/off the internal reference.
488 *
489 * @param param[0] - status of internal reference(on/off).
490 *
491 * @return None.
492 *******************************************************************************/
493 void SetIntRef(double* param, char paramNo) // "intRef=" command
494 {
495 unsigned char status = 0;
496
497 /* Check if the parameter is valid */
498 if(paramNo >= 1)
499 {
500 if(param[0] < 0)
501 {
502 param[0] = 0;
503 }
504 else
505 {
506 if(param[0] > 1)
507 {
508 param[0] = 1;
509 }
510 }
511
512 status = (unsigned char)param[0];
513 AD5629R_SetRef(status);
514 ref = status;
515 /* Send feedback to user */
516 if (status == 0)
517 {
518 CONSOLE_Print("The internal reference is disabled.\r\n");
519 }
520 else
521 {
522 CONSOLE_Print("The internal reference is enabled.\r\n");
523 }
524 }
525 else
526 {
527 /* Display error messages */
528 DisplayError(4);
529 }
530 }
531
532 /***************************************************************************//**
533 * @brief Displays the status of the internal reference.
534 *
535 * @param None.
536 *
537 * @return None.
538 *******************************************************************************/
539 void GetIntRef(double* param, char paramNo) // "IntRef?" command
540 {
541 /* Send requested value to user */
542 if (ref == 0)
543 {
544 CONSOLE_Print("The internal reference is disabled.\r\n");
545 }
546 else
547 {
548 CONSOLE_Print("The internal reference is enabled.\r\n");
549 }
550 }
551
552 /***************************************************************************//**
553 * @brief Loads selected DAC register with a given value.
554 *
555 * @param param[0] - selected DAC.
556 * param[1] - value to be written in register.
557 *
558 * @return None.
559 *******************************************************************************/
560 void SetLoadN(double* param, char paramNo) // "loadN=" command
561 {
562
563 unsigned char channel = 0;
564 unsigned short dacValue = 0;
565
566 /* Check if the parameters are valid */
567 if(paramNo >= 2)
568 {
569 if(param[0] < 0)
570 {
571 param[0] = 0;
572 }
573 else
574 {
575 if(param[0] > 7)
576 {
577 if(param[0] < 15)
578 {
579 param[0] = 7;
580 }
581 else
582 {
583 param[0] = 15;
584 }
585 }
586 }
587
588 if(param[1] < 0)
589 {
590 param[1] = 0;
591 }
592 else
593 {
594 if(param[1] > max_value)
595 {
596 param[1] = max_value;
597 }
598 }
599
600 channel = (unsigned char)param[0];
601 dacValue = (unsigned short)param[1];
602 AD5629R_WriteRegN(channel, dacValue);
603 /* Send feedback to user */
604 if (channel == 15)
605 {
606 CONSOLE_Print("channel=all; value=%d\r\n", dacValue);
607 }
608 else
609 {
610 CONSOLE_Print("channel=%d; value=%d\r\n",channel, dacValue);
611 }
612 }
613 else
614 {
615 /* Display error messages */
616 DisplayError(6);
617 }
618 }
619
620
621 /***************************************************************************//**
622 * @brief Updates the selected DAC with the last value written in register.
623 *
624 * @param param[0] - selected DAC.
625 *
626 * @return None.
627 *******************************************************************************/
628 void SetUpdateN(double* param, char paramNo) // "updateN=" command
629 {
630 unsigned char channel = 0;
631
632 /* Check if the parameters are valid */
633 if(paramNo >= 1)
634 {
635 if(param[0] < 0)
636 {
637 param[0] = 0;
638 }
639 else
640 {
641 if(param[0] > 7)
642 {
643 if(param[0] < 15)
644 {
645 param[0] = 7;
646 }
647 else
648 {
649 param[0] = 15;
650 }
651 }
652 }
653
654 channel = (unsigned char)param[0];
655 AD5629R_UpdateDacN(channel);
656 /* Send feedback to user */
657
658 if (channel == 15)
659 {
660 CONSOLE_Print("all channels were updated\r\n");
661 }
662 else
663 {
664 CONSOLE_Print("channel %d was updated\r\n",channel);
665 }
666 }
667 else
668 {
669 /* Display error messages */
670 DisplayError(7);
671 }
672 }
673
674 /***************************************************************************//**
675 * @brief Loads and updates the selected DAC with a given value.
676 *
677 * @param param[0] - selected DAC.
678 * param[1] - value to be written in register.
679 *
680 * @return None.
681 *******************************************************************************/
682 void SetLoadNAndUpdateN(double* param, char paramNo)//"loadNUpdateN=" command
683 {
684
685 unsigned char channel = 0;
686 unsigned short dacValue = 0;
687
688 /* Check if the parameters are valid */
689 if(paramNo >= 2)
690 {
691 if(param[0] < 0)
692 {
693 param[0] = 0;
694 }
695 else
696 {
697 if(param[0] > 7)
698 {
699 if(param[0] < 15)
700 {
701 param[0] = 7;
702 }
703 else
704 {
705 param[0] = 15;
706 }
707 }
708 }
709
710 if(param[1] < 0)
711 {
712 param[1] = 0;
713 }
714 else
715 {
716 if(param[1] > max_value)
717 {
718 param[1] = max_value;
719 }
720 }
721
722 channel = (unsigned char)param[0];
723 dacValue = (unsigned short)param[1];
724 AD5629R_WriteRegNUpdateN(channel, dacValue);
725 /* Send feedback to user */
726 if (channel == 15)
727 {
728 CONSOLE_Print("channel=all; value=%d\r\n", dacValue);
729 }
730 else
731 {
732 CONSOLE_Print("channel=%d; value=%d\r\n",channel, dacValue);
733 }
734 }
735 else
736 {
737 /* Display error messages */
738 DisplayError(8);
739 }
740 }
741
742 /***************************************************************************//**
743 * @brief Loads the selected DAC with a given value and updates all DACs.
744 *
745 * @param param[0] - selected DAC.
746 * param[1] - value to be written in register.
747 *
748 * @return None.
749 *******************************************************************************/
750 void SetLoadNAndUpdateAll(double* param, char paramNo)//"loadNUpdateAll=" command
751 {
752
753 unsigned char channel = 0;
754 unsigned short dacValue = 0;
755
756 /* Check if the parameters are valid */
757 if(paramNo >= 2)
758 {
759 if(param[0] < 0)
760 {
761 param[0] = 0;
762 }
763 else
764 {
765 if(param[0] > 7)
766 {
767 if(param[0] < 15)
768 {
769 param[0] = 7;
770 }
771 else
772 {
773 param[0] = 15;
774 }
775 }
776 }
777
778 if(param[1] < 0)
779 {
780 param[1] = 0;
781 }
782 else
783 {
784 if(param[1] > max_value)
785 {
786 param[1] = max_value;
787 }
788 }
789
790 channel = (unsigned char)param[0];
791 dacValue = (unsigned short)param[1];
792 AD5629R_WriteRegNUpdateAll(channel, dacValue);
793 /* Send feedback to user */
794 if (channel == 15)
795 {
796 CONSOLE_Print("channel=all; value=%d\r\n", dacValue);
797 }
798 else
799 {
800 CONSOLE_Print("channel=%d; value=%d\r\n",channel, dacValue);
801 }
802 }
803 else
804 {
805 /* Display error messages */
806 DisplayError(9);
807 }
808 }
809
810 /***************************************************************************//**
811 * @brief Enables/Disables the LDAC pin for selected DAC.
812 *
813 * @param param[0] - selected DAC.
814 * param[1] - enable/disable LDAC pin.
815 *
816 * @return None.
817 *******************************************************************************/
818 void SetEnLdacPin(double* param, char paramNo) // "enLdacPin=" command
819 {
820
821 unsigned char channel = 0;
822 unsigned char status = 0;
823
824 /* Check if the parameters are valid */
825 if(paramNo >= 2)
826 {
827 if(param[0] < 0)
828 {
829 param[0] = 0;
830 }
831 else
832 {
833 if(param[0] > 7)
834 {
835 param[0] = 7;
836 }
837 }
838
839 if(param[1] < 0)
840 {
841 param[1] = 0;
842 }
843 else
844 {
845 if(param[1] > 1)
846 {
847 param[1] = 1;
848 }
849 }
850 channel = (unsigned char)param[0];
851 status = (unsigned short)param[1];
852 ldacRegVal &= ~(1 << channel);
853 ldacRegVal |= (status == 0) ? 0 : (1 << channel);
854 AD5629R_LoadLdacReg(ldacRegVal);
855
856 /* Send feedback to user */
857 if (status == 1)
858 {
859 CONSOLE_Print("For channel %d, LDAC pin is disabled. It sees LDAC pin as 0.\r\n",channel);
860 }
861 else
862 {
863 CONSOLE_Print("For channel %d, LDAC pin is enabled.\r\n",channel);
864 }
865 }
866 else
867 {
868 /* Display error messages */
869 DisplayError(10);
870 }
871 }
872
873 /***************************************************************************//**
874 * @brief Displays the status(enabled or disabled) of the LDAC pin for a
875 * selected DAC.
876 *
877 * @param param[0] - selected DAC.
878 *
879 * @return None.
880 *******************************************************************************/
881 void GetEnLdacPin(double* param, char paramNo) // "enLdacPin?" command
882 {
883 unsigned char channel = 0;
884
885 /* Check if the parameters are valid */
886 if(paramNo >= 1)
887 {
888 if(param[0] < 0)
889 {
890 param[0] = 0;
891 }
892 else
893 {
894 if(param[0] > 7)
895 {
896 param[0] = 7;
897 }
898 }
899
900 channel = (unsigned char)param[0];
901 /* Send requested value to user */
902 if (ldacRegVal & (1 << channel))
903 {
904 CONSOLE_Print("For channel %d, LDAC pin is disabled. It sees LDAC pin as 0.\r\n",channel);
905 }
906 else
907 {
908 CONSOLE_Print("For channel %d, LDAC pin is enabled.\r\n",channel);
909 }
910 }
911 else
912 {
913 /* Display error messages */
914 DisplayError(11);
915 }
916 }
917
918 /***************************************************************************//**
919 * @brief Loads Clear Code Register with specific clear code.
920 *
921 * @param param[0] - selected clear code.
922 *
923 * @return None.
924 *******************************************************************************/
925 void SetClrCode(double* param, char paramNo) // "clrCode=" command
926 {
927 unsigned char code = 0;
928
929 /* Check if the parameters are valid */
930 if(paramNo >= 1)
931 {
932 if(param[0] < 0)
933 {
934 param[0] = 0;
935 }
936 else
937 {
938 if(param[0] > 3)
939 {
940 param[0] = 3;
941 }
942 }
943
944 code = (unsigned char)param[0];
945 AD5629R_LoadClearCodeReg(code);
946 clrCode = code;
947 /* Send feedback to user */
948 CONSOLE_Print("clearCode=%d\r\n",code);
949 }
950 else
951 {
952 /* Display error messages */
953 DisplayError(12);
954 }
955 }
956
957 /***************************************************************************//**
958 * @brief Displays the active clear code.
959 *
960 * @param None.
961 *
962 * @return None.
963 *******************************************************************************/
964 void GetClrCode(double* param, char paramNo) // "clrCode?" command
965 {
966 /* Send requested value to user */
967 CONSOLE_Print("clearCode=%d\r\n",clrCode);
968 }
969
970 /***************************************************************************//**
971 * @brief Sets the output value of LDAC pin.
972 *
973 * @param param[0] - value to be set for LDAC pin.
974 *
975 * @return None.
976 *******************************************************************************/
977 void SetLdacPin(double* param, char paramNo) // "ldacPin=" command
978 {
979 unsigned char status = 0;
980
981 /* Check if the parameter is valid */
982 if(paramNo >= 1)
983 {
984 if(param[0] < 0)
985 {
986 param[0] = 0;
987 }
988 else
989 {
990 if(param[0] > 1)
991 {
992 param[0] = 1;
993 }
994 }
995
996 status = (unsigned char) param[0];
997
998 if (status == 0)
999 {
1000 AD5629R_LDAC_LOW
1001 ldac = 0;
1002 }
1003 else
1004 {
1005 if (status == 1)
1006 {
1007 AD5629R_LDAC_HIGH
1008 ldac = 1;
1009 }
1010 }
1011
1012 /* Send feedback to user */
1013 CONSOLE_Print("LDAC=%d\r\n",status);
1014 }
1015 else
1016 {
1017 /* Display error messages */
1018 DisplayError(14);
1019 }
1020 }
1021
1022 /***************************************************************************//**
1023 * @brief Displays the value of LDAC pin.
1024 *
1025 * @param None.
1026 *
1027 * @return None.
1028 *******************************************************************************/
1029 void GetLdacPin(double* param, char paramNo) // "ldacPin?" command
1030 {
1031 /* Send requested value to user */
1032 CONSOLE_Print("LDAC=%d\r\n",ldac);
1033 }
1034
1035 /***************************************************************************//**
1036 * @brief Sets the output value of CLR pin.
1037 *
1038 * @param param[0] - value to be set for CLR pin.
1039 *
1040 * @return None.
1041 *******************************************************************************/
1042 void SetClrPin(double* param, char paramNo) // "clrPin=" command
1043 {
1044 unsigned char status = 0;
1045
1046 /* Check if the parameter is valid */
1047 if(paramNo >= 1)
1048 {
1049 if(param[0] < 0)
1050 {
1051 param[0] = 0;
1052 }
1053 else
1054 { if(param[0] > 1)
1055 {
1056 param[0] = 1;
1057 }
1058 }
1059
1060 status = (unsigned char) param[0];
1061
1062 if (status == 0)
1063 {
1064 AD5629R_CLR_LOW;
1065 clr = 0;
1066 }
1067 else
1068 {
1069 if (status == 1)
1070 {
1071 AD5629R_CLR_HIGH;
1072 clr = 1;
1073 }
1074 }
1075
1076 /* Send feedback to user */
1077 CONSOLE_Print("CLR=%d\r\n",status);
1078 }
1079 else
1080 {
1081 /* Display error messages */
1082 DisplayError(16);
1083 }
1084 }
1085
1086 /***************************************************************************//**
1087 * @brief Displays the value of CLR pin.
1088 *
1089 * @param None.
1090 *
1091 * @return None.
1092 *******************************************************************************/
1093 void GetClrPin(double* param, char paramNo) // "clrPin?" command
1094 {
1095 /* Send requested value to user */
1096 CONSOLE_Print("CLR=%d\r\n",clr);
1097 }