Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: platform_drivers adi_console_menu
ad5770r_console_app.c
00001 /*! 00002 ***************************************************************************** 00003 @file: ad5770r_console_app.c 00004 00005 @brief: Implementation for the menu functions that handle the AD5770R 00006 00007 @details: 00008 ----------------------------------------------------------------------------- 00009 * 00010 Copyright (c) 2020 Analog Devices, Inc. All Rights Reserved. 00011 00012 This software is proprietary to Analog Devices, Inc. and its licensors. 00013 By using this software you agree to the terms of the associated 00014 Analog Devices Software License Agreement. 00015 ******************************************************************************/ 00016 00017 /* includes */ 00018 #include <stdio.h> 00019 #include <stdlib.h> 00020 #include <string.h> 00021 #include <stdbool.h> 00022 #include <stdint.h> 00023 #include <assert.h> 00024 00025 #include "app_config.h" 00026 00027 #include "platform_drivers.h" 00028 #include "platform_support.h" 00029 #include "ad5770r.h" 00030 00031 #include "ad5770r_console_app.h" 00032 #include "ad5770r_user_config.h" 00033 #include "ad5770r_reset_config.h" 00034 00035 /* defines */ 00036 #define TOGGLE_MUX_BUFFER 1000 00037 #define TOGGLE_DIODE_EXT_BIAS 1001 00038 #define MENU_CHANNEL_OFFSET 100 00039 00040 /* Private Variables */ 00041 static struct ad5770r_dev * pAd5770r_dev = NULL; 00042 00043 static struct ad5770r_channel_switches sw_ldac_shadow; 00044 00045 // GPIO descriptor and init parameters for the HW LDACB pin 00046 static gpio_desc * hw_ldacb_desc = NULL; 00047 static gpio_init_param hw_ldacb_init_param = { HW_LDACB, NULL }; 00048 00049 00050 // Forward Declaration 00051 static console_menu general_configuration_menu; 00052 static console_menu monitor_setup_menu; 00053 static console_menu dac_channel_configuration_menu; 00054 static console_menu dac_operations_menu; 00055 00056 // Public Functions 00057 00058 /*! 00059 * @brief Initialize the AD7124 device and the SPI port as required 00060 * 00061 * @details This resets and then writes the default register map value to 00062 * the device. A call to init the SPI port is made, but may not 00063 * actually do very much, depending on the platform 00064 */ 00065 int32_t ad5770r_app_initialize(void) 00066 { 00067 00068 // Create a new descriptor for HW LDACB 00069 if(gpio_get(&hw_ldacb_desc, &hw_ldacb_init_param) == FAILURE) { 00070 return FAILURE; 00071 } 00072 00073 // Set the direction of HW LDACB 00074 if((gpio_direction_output(hw_ldacb_desc, GPIO_OUT)) == FAILURE) { 00075 return FAILURE; 00076 } 00077 00078 // Set the default output state of HW LDACB 00079 if((gpio_set_value(hw_ldacb_desc, GPIO_HIGH)) == FAILURE) { 00080 return FAILURE; 00081 } 00082 00083 return(ad5770r_init(&pAd5770r_dev, &ad5770r_user_param)); 00084 } 00085 00086 // Private Functions 00087 00088 /** 00089 * Performs a software reset. 00090 * @param dev - The device structure. 00091 * @return SUCCESS in case of success, negative error code otherwise. 00092 */ 00093 int32_t ad5770r_software_reset(struct ad5770r_dev *dev) 00094 { 00095 int32_t ret; 00096 00097 if (!dev) 00098 return FAILURE; 00099 00100 ret = ad5770r_spi_reg_write(dev, 00101 AD5770R_INTERFACE_CONFIG_A, 00102 AD5770R_INTERFACE_CONFIG_A_SW_RESET_MSK | 00103 AD5770R_INTERFACE_CONFIG_A_ADDR_ASCENSION_MSB( 00104 dev->dev_spi_settings.addr_ascension)); 00105 00106 if (ret) 00107 return ret; 00108 00109 // Save the spi_desc pointer field 00110 spi_desc * spi_interface = dev->spi_desc; 00111 // Copy over the reset state of the device 00112 memcpy(dev, &ad5770r_dev_reset, sizeof(ad5770r_dev_reset)); 00113 // Restore the spi_desc pointer field 00114 dev->spi_desc = spi_interface; 00115 00116 return ret; 00117 } 00118 00119 /* 00120 * @brief Sends a reset command on the SPI to reset the device 00121 * 00122 * @details 00123 */ 00124 static int32_t do_software_reset(uint32_t id) 00125 { 00126 int32_t ret; 00127 00128 if ((ret = ad5770r_software_reset(pAd5770r_dev)) == SUCCESS) { 00129 printf(EOL " --- Software Reset Succeeded ---" EOL); 00130 } else { 00131 printf(EOL " *** Software Reset Failure: %d ***" EOL, ret); 00132 } 00133 adi_press_any_key_to_continue(); 00134 return(MENU_CONTINUE); 00135 } 00136 00137 /* 00138 * @brief Creates and initializes a device with user configuration 00139 * 00140 * @details 00141 */ 00142 static int32_t do_device_init(uint32_t id) 00143 { 00144 00145 if (ad5770r_init(&pAd5770r_dev, &ad5770r_user_param) == SUCCESS) { 00146 } else { 00147 printf("\n\r *** Error device init ***\n\r"); 00148 } 00149 00150 adi_press_any_key_to_continue(); 00151 return(MENU_CONTINUE); 00152 } 00153 00154 /* 00155 * @brief Removes the device from memory 00156 * 00157 * @details 00158 */ 00159 static int32_t do_device_remove(uint32_t id) 00160 { 00161 if (ad5770r_remove(pAd5770r_dev) != SUCCESS) { 00162 printf("\n\r *** Error doing device remove ***\n\r"); 00163 } 00164 00165 pAd5770r_dev = NULL; 00166 00167 adi_press_any_key_to_continue(); 00168 return(MENU_CONTINUE); 00169 } 00170 00171 /*! 00172 * @brief toggles the int/ext ref resistor option 00173 * 00174 * @details 00175 */ 00176 static int32_t do_toggle_ref_resistor(uint32_t id) 00177 { 00178 int32_t status; 00179 00180 if ((status = ad5770r_set_reference(pAd5770r_dev, 00181 !pAd5770r_dev->external_reference, 00182 pAd5770r_dev->reference_selector)) != SUCCESS) { 00183 printf(EOL " *** Error toggling ref resistor setting: %d" EOL, status); 00184 adi_press_any_key_to_continue(); 00185 } 00186 00187 return(MENU_CONTINUE); 00188 } 00189 00190 00191 /*! 00192 * @brief sets the int/ext refer configuration options 00193 * 00194 * @details 00195 */ 00196 static int32_t do_set_reference(uint32_t ref_option) 00197 { 00198 int32_t status; 00199 00200 if ((status = ad5770r_set_reference(pAd5770r_dev, 00201 pAd5770r_dev->external_reference, 00202 (enum ad5770r_reference_voltage)ref_option)) != SUCCESS) { 00203 printf(EOL " *** Error toggling ref resistor setting: %d" EOL, status); 00204 adi_press_any_key_to_continue(); 00205 } 00206 00207 return(MENU_CONTINUE); 00208 } 00209 00210 /*! 00211 * @brief Sets the Alarm Menu option bits 00212 * 00213 * @details 00214 */ 00215 static int32_t do_set_alarm(uint32_t alarm_id) 00216 { 00217 int32_t status; 00218 struct ad5770r_alarm_cfg alarm_config; 00219 00220 alarm_config = pAd5770r_dev->alarm_config; 00221 00222 switch(alarm_id) { 00223 case AD5770R_ALARM_CONFIG_OPEN_DRAIN_EN(1): 00224 alarm_config.open_drain_en = !alarm_config.open_drain_en; 00225 break; 00226 case AD5770R_ALARM_CONFIG_THERMAL_SHUTDOWN_EN(1): 00227 alarm_config.thermal_shutdown_en = !alarm_config.thermal_shutdown_en; 00228 break; 00229 case AD5770R_ALARM_CONFIG_BACKGROUND_CRC_EN(1): 00230 alarm_config.background_crc_en = !alarm_config.background_crc_en; 00231 break; 00232 case AD5770R_ALARM_CONFIG_TEMP_WARNING_ALARM_MASK(1): 00233 alarm_config.temp_warning_msk = !alarm_config.temp_warning_msk; 00234 break; 00235 case AD5770R_ALARM_CONFIG_OVER_TEMP_ALARM_MASK(1): 00236 alarm_config.over_temp_msk = !alarm_config.over_temp_msk; 00237 break; 00238 case AD5770R_ALARM_CONFIG_NEGATIVE_CHANNEL0_ALARM_MASK(1): 00239 alarm_config.neg_ch0_msk = !alarm_config.neg_ch0_msk; 00240 break; 00241 case AD5770R_ALARM_CONFIG_IREF_FAULT_ALARM_MASK(1): 00242 alarm_config.iref_fault_msk = !alarm_config.iref_fault_msk; 00243 break; 00244 case AD5770R_ALARM_CONFIG_BACKGROUND_CRC_ALARM_MASK(1): 00245 alarm_config.background_crc_msk = !alarm_config.background_crc_msk; 00246 break; 00247 default: 00248 // not a supported menu option 00249 assert(false); 00250 } 00251 00252 if ((status = ad5770r_set_alarm(pAd5770r_dev, 00253 &alarm_config)) != SUCCESS) { 00254 printf(EOL " *** Error setting alarm config: %d" EOL, status); 00255 adi_press_any_key_to_continue(); 00256 } 00257 00258 return(MENU_CONTINUE); 00259 } 00260 00261 /*! 00262 * @brief Sets the Channel Configuration option bits 00263 * 00264 * @details 00265 */ 00266 static void ch_switches_toggle(struct ad5770r_channel_switches *ch_switches, 00267 uint32_t channel_id) 00268 { 00269 switch(channel_id) { 00270 case AD5770R_CHANNEL_CONFIG_CH0_SHUTDOWN_B(1): 00271 ch_switches->en0 = !ch_switches->en0; 00272 break; 00273 case AD5770R_CHANNEL_CONFIG_CH1_SHUTDOWN_B(1): 00274 ch_switches->en1 = !ch_switches->en1; 00275 break; 00276 case AD5770R_CHANNEL_CONFIG_CH2_SHUTDOWN_B(1): 00277 ch_switches->en2 = !ch_switches->en2; 00278 break; 00279 case AD5770R_CHANNEL_CONFIG_CH3_SHUTDOWN_B(1): 00280 ch_switches->en3 = !ch_switches->en3; 00281 break; 00282 case AD5770R_CHANNEL_CONFIG_CH4_SHUTDOWN_B(1): 00283 ch_switches->en4 = !ch_switches->en4; 00284 break; 00285 case AD5770R_CHANNEL_CONFIG_CH5_SHUTDOWN_B(1): 00286 ch_switches->en5 = !ch_switches->en5; 00287 break; 00288 case AD5770R_CHANNEL_CONFIG_CH0_SINK_EN(1): 00289 ch_switches->sink0 = !ch_switches->sink0; 00290 break; 00291 default: 00292 // not a supported menu option 00293 assert(false); 00294 } 00295 } 00296 00297 /*! 00298 * @brief Sets the Channel Configuration option bits 00299 * 00300 * @details 00301 */ 00302 static int32_t do_channel_config(uint32_t channel_id) 00303 { 00304 int32_t status; 00305 struct ad5770r_channel_switches channel_config; 00306 00307 channel_config = pAd5770r_dev->channel_config; 00308 00309 ch_switches_toggle(&channel_config, channel_id); 00310 00311 if ((status = ad5770r_channel_config(pAd5770r_dev, 00312 &channel_config)) != SUCCESS) { 00313 printf(EOL " *** Error setting channel config: %d" EOL, status); 00314 adi_press_any_key_to_continue(); 00315 } 00316 00317 return(MENU_CONTINUE); 00318 } 00319 00320 /*! 00321 * @brief prompts user for value to write to input register on channel 00322 * 00323 * @details 00324 */ 00325 static int32_t do_input_value(uint32_t channel_id) 00326 { 00327 int32_t status; 00328 uint16_t value; 00329 00330 printf(EOL "Enter Input register value (hex) for channel %d: " EOL, 00331 channel_id); 00332 value = adi_get_hex_integer(4); 00333 00334 /* Channels are 14-bits, mask off top 2 bits*/ 00335 value &= 0x3FFF; 00336 00337 if ((status = 00338 ad5770r_set_dac_input(pAd5770r_dev, value, 00339 (enum ad5770r_channels) channel_id)) != SUCCESS) { 00340 printf(EOL " *** Error writing DAC Input register: %d" EOL, status); 00341 adi_press_any_key_to_continue(); 00342 } 00343 00344 return(MENU_CONTINUE); 00345 } 00346 00347 /*! 00348 * @brief prompts user for value to write to input register on channel 00349 * 00350 * @details 00351 */ 00352 static int32_t do_dac_value(uint32_t channel_id) 00353 { 00354 int32_t status; 00355 uint16_t value; 00356 00357 printf(EOL "Enter DAC register value (hex) for channel %d: " EOL, channel_id); 00358 value = adi_get_hex_integer(4); 00359 00360 /* Channels are 14-bits, mask off top 2 bits*/ 00361 value &= 0x3FFF; 00362 00363 if ((status = 00364 ad5770r_set_dac_value(pAd5770r_dev, value, 00365 (enum ad5770r_channels) channel_id)) != SUCCESS) { 00366 printf(EOL " *** Error writing DAC value register: %d" EOL, status); 00367 adi_press_any_key_to_continue(); 00368 } 00369 00370 return(MENU_CONTINUE); 00371 } 00372 00373 /*! 00374 * @brief updating shadow SW LDAC, by toggling the channel bit 00375 * 00376 * @details 00377 */ 00378 static int32_t do_sw_ldac(uint32_t channel_id) 00379 { 00380 ch_switches_toggle(&sw_ldac_shadow, channel_id); 00381 00382 return(MENU_CONTINUE); 00383 } 00384 00385 /*! 00386 * @brief Writing SW LDAC to device 00387 * 00388 * @details 00389 */ 00390 static int32_t do_sw_ldac_write(uint32_t id) 00391 { 00392 int32_t status; 00393 00394 if ((status = ad5770r_set_sw_ldac(pAd5770r_dev, 00395 &sw_ldac_shadow)) != SUCCESS) { 00396 printf(EOL " *** Error writing SW LDAC: %d" EOL, status); 00397 adi_press_any_key_to_continue(); 00398 } 00399 00400 return(MENU_CONTINUE); 00401 } 00402 00403 /*! 00404 * @brief Toggles HW LDAC 00405 * 00406 * @details This toggles the LDAC pin on the device, but is independent to the driver 00407 * Therefore this does not update dac_values from input values. 00408 */ 00409 static int32_t do_hw_ldac_toggle(uint32_t id) 00410 { 00411 int32_t status; 00412 00413 do { 00414 if ((status = gpio_set_value(hw_ldacb_desc, GPIO_LOW)) == FAILURE) { 00415 break; 00416 } 00417 mdelay(1); 00418 if ((status = gpio_set_value(hw_ldacb_desc, GPIO_HIGH)) == FAILURE) { 00419 break; 00420 } 00421 } while (0); 00422 00423 if (status == SUCCESS) { 00424 printf(EOL " --- HW LDAC toggled ---" EOL); 00425 } else { 00426 printf(EOL " *** Error toggling HW LDACB ***" EOL); 00427 } 00428 00429 00430 adi_press_any_key_to_continue(); 00431 00432 return(MENU_CONTINUE); 00433 } 00434 00435 /*! 00436 * @brief displays general device configuration state 00437 * 00438 * @details 00439 */ 00440 static void display_gen_config(void) 00441 { 00442 printf("\tRef Resistor: %s\t\tRef Voltage: %d" EOL, 00443 pAd5770r_dev->external_reference == true ? "External" : "Internal", 00444 pAd5770r_dev->reference_selector); 00445 00446 printf("\tAlarms\tBgCRC Msk: %d\tIRef: %d\tneg: %d\tOT: %d " EOL \ 00447 "\t\tT Warn: %d\tBgCRC En: %d\tT Shdn: %d\tOD: %d" EOL, 00448 pAd5770r_dev->alarm_config.background_crc_msk, 00449 pAd5770r_dev->alarm_config.iref_fault_msk, 00450 pAd5770r_dev->alarm_config.neg_ch0_msk, 00451 pAd5770r_dev->alarm_config.over_temp_msk, 00452 pAd5770r_dev->alarm_config.temp_warning_msk, 00453 pAd5770r_dev->alarm_config.background_crc_en, 00454 pAd5770r_dev->alarm_config.thermal_shutdown_en, 00455 pAd5770r_dev->alarm_config.open_drain_en); 00456 } 00457 00458 /*! 00459 * @brief displays general device configuration state 00460 * 00461 * @details 00462 */ 00463 static void print_channel_switches(struct ad5770r_channel_switches *ch_switches, 00464 char * prefix, bool include_sink) 00465 { 00466 if (include_sink) { 00467 printf("\t%s - en0: %d sink0: %d en1: %d en2: %d " \ 00468 "en3: %d en4: %d en5: %d" EOL, prefix, 00469 ch_switches->en0, ch_switches->sink0, ch_switches->en1, 00470 ch_switches->en2, ch_switches->en3, ch_switches->en4, 00471 ch_switches->en5); 00472 } else { 00473 printf("\t%s - ch0: %d ch1: %d ch2: %d " \ 00474 "ch3: %d ch4: %d ch5: %d" EOL, prefix, 00475 ch_switches->en0, ch_switches->en1, ch_switches->en2, 00476 ch_switches->en3, ch_switches->en4, ch_switches->en5); 00477 } 00478 } 00479 00480 /*! 00481 * @brief displays general device configuration state 00482 * 00483 * @details 00484 */ 00485 static void display_dac_channel_configuration_header(void) 00486 { 00487 print_channel_switches(&pAd5770r_dev->channel_config, "Ch Configs", true); 00488 } 00489 00490 /*! 00491 * @brief displays the SW LDAC shadown and other channel output values 00492 * 00493 * @details 00494 */ 00495 static void display_dac_operations_header(void) 00496 { 00497 for (uint8_t i = 0; i < 6 ; i++) { 00498 printf("\tCh %i - Input: 0x%04X \t\tDAC: 0x%04X" EOL, i, 00499 pAd5770r_dev->input_value[i], pAd5770r_dev->dac_value[i]); 00500 } 00501 00502 printf(EOL); 00503 print_channel_switches(&sw_ldac_shadow, "SW LDAC shadow", false); 00504 } 00505 /*! 00506 * @brief prints the provided monitor config to the terminal 00507 * 00508 * @details 00509 * @param ad5770R_monitor_config monitor_config - struct for the monitor config to be displayed 00510 * @return SUCCESS in case of success, negative error otherwise 00511 */ 00512 static void print_monitor_setup(const struct ad5770r_monitor_setup * mon_setup) 00513 { 00514 printf("\tMonitor: "); 00515 switch (mon_setup->monitor_function) { 00516 case AD5770R_DISABLE: { 00517 printf("Disabled "); 00518 break; 00519 } 00520 case AD5770R_VOLTAGE_MONITORING: { 00521 printf("Voltage Ch %d", mon_setup->monitor_channel); 00522 break; 00523 } 00524 case AD5770R_CURRENT_MONITORING: { 00525 printf("Current Ch %d", mon_setup->monitor_channel); 00526 break; 00527 } 00528 case AD5770R_TEMPERATURE_MONITORING: { 00529 printf("Temperature"); 00530 break; 00531 } 00532 } 00533 00534 printf("\tBuffer: "); 00535 if (mon_setup->mux_buffer == true) { 00536 printf("On"); 00537 } else { 00538 printf("Off"); 00539 } 00540 00541 printf("\tIB_Ext: "); 00542 if (mon_setup->ib_ext_en == true) { 00543 printf("On"); 00544 } else { 00545 printf("Off"); 00546 } 00547 printf(EOL); 00548 } 00549 00550 /*! 00551 * @brief configure the Mux Monitor setup 00552 * 00553 * @details 00554 */ 00555 static void display_monitor_setup_header(void) 00556 { 00557 print_monitor_setup(&pAd5770r_dev->mon_setup); 00558 } 00559 00560 /*! 00561 * @brief configure the Mux Monitor setup 00562 * 00563 * @details 00564 */ 00565 static int32_t do_monitor_setup(uint32_t id) 00566 { 00567 int32_t status; 00568 struct ad5770r_monitor_setup monitor_setup; 00569 00570 monitor_setup = pAd5770r_dev->mon_setup; 00571 00572 switch(id) { 00573 case AD5770R_DISABLE: 00574 monitor_setup.monitor_function = AD5770R_DISABLE; 00575 break; 00576 case AD5770R_VOLTAGE_MONITORING: 00577 monitor_setup.monitor_function = AD5770R_VOLTAGE_MONITORING; 00578 break; 00579 case AD5770R_CURRENT_MONITORING: 00580 monitor_setup.monitor_function = AD5770R_CURRENT_MONITORING; 00581 break; 00582 case AD5770R_TEMPERATURE_MONITORING: 00583 monitor_setup.monitor_function = AD5770R_TEMPERATURE_MONITORING; 00584 break; 00585 case TOGGLE_MUX_BUFFER: 00586 monitor_setup.mux_buffer = !monitor_setup.mux_buffer; 00587 break; 00588 case TOGGLE_DIODE_EXT_BIAS: 00589 monitor_setup.ib_ext_en = !monitor_setup.ib_ext_en; 00590 break; 00591 default: 00592 // ensure the id is valid. 00593 assert(( id >= AD5770R_CH0 + MENU_CHANNEL_OFFSET ) 00594 && (id <= AD5770R_CH5 + MENU_CHANNEL_OFFSET)); 00595 monitor_setup.monitor_channel = (enum ad5770r_channels)( 00596 id - MENU_CHANNEL_OFFSET); 00597 } 00598 00599 if ((status = ad5770r_set_monitor_setup(pAd5770r_dev, 00600 &monitor_setup)) != SUCCESS) { 00601 printf(EOL " *** Error setting monitor setup: %d" EOL, status); 00602 adi_press_any_key_to_continue(); 00603 } 00604 00605 return(MENU_CONTINUE); 00606 } 00607 00608 /*! 00609 * @brief displays several pieces of status information above main menu 00610 * 00611 * @details 00612 */ 00613 static void display_main_menu_header(void) 00614 { 00615 int32_t ret; 00616 uint8_t device_status = 0, interface_status = 0, scratchpad = 0; 00617 00618 if (pAd5770r_dev == NULL) { 00619 printf(EOL " *** Device Not Initialized ***" EOL); 00620 return; 00621 } 00622 00623 do { 00624 if ((ret = ad5770r_get_status(pAd5770r_dev, &device_status)) != SUCCESS) { 00625 break; 00626 } 00627 if ((ret = ad5770r_get_interface_status(pAd5770r_dev, 00628 &interface_status)) != SUCCESS) { 00629 break; 00630 } 00631 if ((ret = ad5770r_spi_reg_read(pAd5770r_dev, AD5770R_SCRATCH_PAD, 00632 &scratchpad)) != SUCCESS) { 00633 break; 00634 } 00635 00636 } while(0); 00637 00638 if (ret != SUCCESS) { 00639 printf(EOL " *** Error in display state: %d **" EOL, ret); 00640 } 00641 00642 printf(EOL "\tInterface Status = 0x%02X\t\tDevice Status = 0x%02X" 00643 EOL "\tScratchpad = 0x%02X" EOL, 00644 interface_status, device_status, scratchpad); 00645 print_monitor_setup(&pAd5770r_dev->mon_setup); 00646 00647 // Increment the scratchpad by 1 to show a +1 delta in footer 00648 if((ret = ad5770r_spi_reg_write(pAd5770r_dev, AD5770R_SCRATCH_PAD, 00649 scratchpad + 1)) != SUCCESS) { 00650 printf(EOL " *** Error writing scratchpad + 1 : %d **" EOL, ret); 00651 } 00652 } 00653 00654 /*! 00655 * @brief displays several pieces of status information below main menu 00656 * 00657 * @details 00658 */ 00659 static void display_main_menu_footer(void) 00660 { 00661 int32_t ret; 00662 uint8_t scratchpad; 00663 00664 if (pAd5770r_dev == NULL) { 00665 printf(EOL " *** Device Not Initialized ***" EOL); 00666 return; 00667 } 00668 00669 if ((ret = ad5770r_spi_reg_read(pAd5770r_dev, AD5770R_SCRATCH_PAD, 00670 &scratchpad)) != SUCCESS) { 00671 printf(EOL " *** Error reading scratchpad: %d **" EOL, ret); 00672 } 00673 00674 printf(EOL "\tScratchpad = 0x%02X" EOL, scratchpad); 00675 } 00676 00677 /*! 00678 * @brief calls the general configuration menu 00679 */ 00680 static int32_t do_general_configuration_menu(uint32_t id) 00681 { 00682 return adi_do_console_menu(&general_configuration_menu); 00683 } 00684 00685 /*! 00686 * @brief calls the monitor setup menu 00687 */ 00688 static int32_t do_monitor_setup_menu(uint32_t id) 00689 { 00690 return adi_do_console_menu(&monitor_setup_menu); 00691 } 00692 00693 /*! 00694 * @brief calls the DAC channel confguration menu 00695 */ 00696 static int32_t do_dac_channel_configuration_menu(uint32_t id) 00697 { 00698 return adi_do_console_menu(&dac_channel_configuration_menu); 00699 } 00700 00701 /*! 00702 * @brief calls the DAC channel confguration menu 00703 */ 00704 static int32_t do_dac_operations_menu(uint32_t id) 00705 { 00706 return adi_do_console_menu(&dac_operations_menu); 00707 } 00708 00709 /* 00710 * DAC Operations Menu 00711 */ 00712 static console_menu_item dac_operations_menu_items[] = { 00713 {"\tSet Input Channel 0", 'Q', do_input_value, 0}, 00714 {"\tSet Input Channel 1", 'W', do_input_value, 1}, 00715 {"\tSet Input Channel 2", 'E', do_input_value, 2}, 00716 {"\tSet Input Channel 3", 'R', do_input_value, 3}, 00717 {"\tSet Input Channel 4", 'T', do_input_value, 4}, 00718 {"\tSet Input Channel 5", 'Y', do_input_value, 5}, 00719 {""}, 00720 {"\tToggle Channel 0 SW LDAC Shadow", '0', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 0)}, 00721 {"\tToggle Channel 1 SW LDAC Shadow", '1', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 1)}, 00722 {"\tToggle Channel 2 SW LDAC Shadow", '2', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 2)}, 00723 {"\tToggle Channel 3 SW LDAC Shadow", '3', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 3)}, 00724 {"\tToggle Channel 4 SW LDAC Shadow", '4', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 4)}, 00725 {"\tToggle Channel 5 SW LDAC Shadow", '5', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 5)}, 00726 {"\tWrite SW LDAC Shadow ", 'U', do_sw_ldac_write}, 00727 {""}, 00728 {"\tToggle HW LDAC digital input", 'J', do_hw_ldac_toggle}, 00729 {""}, 00730 {"\tSet DAC Channel 0", 'A', do_dac_value, 0}, 00731 {"\tSet DAC Channel 1", 'S', do_dac_value, 1}, 00732 {"\tSet DAC Channel 2", 'D', do_dac_value, 2}, 00733 {"\tSet DAC Channel 3", 'F', do_dac_value, 3}, 00734 {"\tSet DAC Channel 4", 'G', do_dac_value, 4}, 00735 {"\tSet DAC Channel 5", 'H', do_dac_value, 5}, 00736 }; 00737 00738 static console_menu dac_operations_menu = { 00739 .title = "DAC Operations", 00740 .items = dac_operations_menu_items, 00741 .itemCount = ARRAY_SIZE(dac_operations_menu_items), 00742 .headerItem = display_dac_operations_header, 00743 .footerItem = NULL, 00744 .enableEscapeKey = true 00745 }; 00746 00747 /* 00748 * Monitor Setup Menu 00749 */ 00750 static console_menu_item dac_channel_configuration_menu_items[] = { 00751 {"\tToggle Channel 0 Enable", '0', do_channel_config, AD5770R_CHANNEL_CONFIG_CH0_SHUTDOWN_B(1)}, 00752 {"\tToggle Channel 0 Sink Enable", 'S', do_channel_config, AD5770R_CHANNEL_CONFIG_CH0_SINK_EN(1)}, 00753 {"\tToggle Channel 1 Enable", '1', do_channel_config, AD5770R_CHANNEL_CONFIG_CH1_SHUTDOWN_B(1)}, 00754 {"\tToggle Channel 2 Enable", '2', do_channel_config, AD5770R_CHANNEL_CONFIG_CH2_SHUTDOWN_B(1)}, 00755 {"\tToggle Channel 3 Enable", '3', do_channel_config, AD5770R_CHANNEL_CONFIG_CH3_SHUTDOWN_B(1)}, 00756 {"\tToggle Channel 4 Enable", '4', do_channel_config, AD5770R_CHANNEL_CONFIG_CH4_SHUTDOWN_B(1)}, 00757 {"\tToggle Channel 5 Enable", '5', do_channel_config, AD5770R_CHANNEL_CONFIG_CH5_SHUTDOWN_B(1)} 00758 }; 00759 00760 static console_menu dac_channel_configuration_menu = { 00761 .title = "DAC Channel Configuration", 00762 .items = dac_channel_configuration_menu_items, 00763 .itemCount = ARRAY_SIZE(dac_channel_configuration_menu_items), 00764 .headerItem = display_dac_channel_configuration_header, 00765 .footerItem = NULL, 00766 .enableEscapeKey = true 00767 }; 00768 00769 /* 00770 * Monitor Setup Menu 00771 */ 00772 static console_menu_item monitor_setup_menu_items[] = { 00773 {"Disable Monitoring", 'Q', do_monitor_setup, AD5770R_DISABLE}, 00774 {"Enable Voltage Monitoring", 'W', do_monitor_setup, AD5770R_VOLTAGE_MONITORING}, 00775 {"Enable Current Monitoring", 'E', do_monitor_setup, AD5770R_CURRENT_MONITORING}, 00776 {"Enable Temperature Monitoring", 'R', do_monitor_setup, AD5770R_TEMPERATURE_MONITORING}, 00777 {"", '\00', NULL}, 00778 {"Toggle Mux Buffer", 'M', do_monitor_setup, TOGGLE_MUX_BUFFER}, 00779 {"Toggle Diode External Bias", 'X', do_monitor_setup, TOGGLE_DIODE_EXT_BIAS}, 00780 {"", '\00', NULL}, 00781 {"\tSelect Channel 0", '0', do_monitor_setup, AD5770R_CH0 + MENU_CHANNEL_OFFSET}, 00782 {"\tSelect Channel 1", '1', do_monitor_setup, AD5770R_CH1 + MENU_CHANNEL_OFFSET}, 00783 {"\tSelect Channel 2", '2', do_monitor_setup, AD5770R_CH2 + MENU_CHANNEL_OFFSET}, 00784 {"\tSelect Channel 3", '3', do_monitor_setup, AD5770R_CH3 + MENU_CHANNEL_OFFSET}, 00785 {"\tSelect Channel 4", '4', do_monitor_setup, AD5770R_CH4 + MENU_CHANNEL_OFFSET}, 00786 {"\tSelect Channel 5", '5', do_monitor_setup, AD5770R_CH5 + MENU_CHANNEL_OFFSET}, 00787 }; 00788 00789 static console_menu monitor_setup_menu = { 00790 .title = "Monitor Setup", 00791 .items = monitor_setup_menu_items, 00792 .itemCount = ARRAY_SIZE(monitor_setup_menu_items), 00793 .headerItem = display_monitor_setup_header, 00794 .footerItem = NULL, 00795 .enableEscapeKey = true 00796 }; 00797 00798 /* 00799 * General Configuration Menu 00800 */ 00801 static console_menu_item general_configuration_menu_items[] = { 00802 {"Select Int/External Reference Resistor", 'R', do_toggle_ref_resistor}, 00803 {""}, 00804 {"Set Ext 2.50V Reference", 'A', do_set_reference, AD5770R_EXT_REF_2_5_V}, 00805 {"Set Int 1.25V Reference, Vout: ON", 'S', do_set_reference, AD5770R_INT_REF_1_25_V_OUT_ON}, 00806 {"Set Ext 1.25V Reference", 'D', do_set_reference, AD5770R_EXT_REF_1_25_V}, 00807 {"Set Int 1.25V Reference, Vout: OFF", 'F', do_set_reference, AD5770R_INT_REF_1_25_V_OUT_OFF}, 00808 {""}, 00809 {" --Toggle Alarm Configuration bits --"}, 00810 {"\tOpen Drain Enable", '0', do_set_alarm, AD5770R_ALARM_CONFIG_OPEN_DRAIN_EN(1)}, 00811 {"\tThermal Shutdown Enable", '1', do_set_alarm, AD5770R_ALARM_CONFIG_THERMAL_SHUTDOWN_EN(1)}, 00812 {"\tBackground CRC Enable", '2', do_set_alarm, AD5770R_ALARM_CONFIG_BACKGROUND_CRC_EN(1)}, 00813 {"\tTemperature Warning Alarm Mask", '3', do_set_alarm, AD5770R_ALARM_CONFIG_TEMP_WARNING_ALARM_MASK(1)}, 00814 {"\tOver Temperature Alarm Mask", '4', do_set_alarm, AD5770R_ALARM_CONFIG_OVER_TEMP_ALARM_MASK(1)}, 00815 {"\tNegative Channel 0 Mask", '5', do_set_alarm, AD5770R_ALARM_CONFIG_NEGATIVE_CHANNEL0_ALARM_MASK(1)}, 00816 {"\tIREF Fault Alarm Mask", '6', do_set_alarm, AD5770R_ALARM_CONFIG_IREF_FAULT_ALARM_MASK(1)}, 00817 {"\tBackground CRC Alarm Mask", '7', do_set_alarm, AD5770R_ALARM_CONFIG_BACKGROUND_CRC_ALARM_MASK(1)}, 00818 }; 00819 00820 static console_menu general_configuration_menu = { 00821 .title = "General Configuration", 00822 .items = general_configuration_menu_items, 00823 .itemCount = ARRAY_SIZE(general_configuration_menu_items), 00824 .headerItem = display_gen_config, 00825 .footerItem = NULL, 00826 .enableEscapeKey = true 00827 }; 00828 00829 /* 00830 * Definition of the Main Menu Items and menu itself 00831 */ 00832 static console_menu_item main_menu_items[] = { 00833 {"Initialize Device to User Configuration", 'I', do_device_init}, 00834 {"Remove Device", 'X', do_device_remove}, 00835 {""}, 00836 {"Do Software Reset", 'R', do_software_reset}, 00837 {""}, 00838 {"General Configuration...", 'G', do_general_configuration_menu}, 00839 {"Monitor Setup...", 'M', do_monitor_setup_menu}, 00840 {""}, 00841 {"DAC Channel Configuration...", 'C', do_dac_channel_configuration_menu}, 00842 {"DAC Operations...", 'D', do_dac_operations_menu}, 00843 }; 00844 00845 console_menu ad5770r_main_menu = { 00846 #if ACTIVE_DEVICE==GENERIC_AD5770R 00847 .title = "AD5770R Console App", 00848 #elif ACTIVE_DEVICE==GENERIC_AD5772R 00849 .title = "AD5772R Terminal App", 00850 #else 00851 #error "Unsupported device" 00852 #endif 00853 .items = main_menu_items, 00854 .itemCount = ARRAY_SIZE(main_menu_items), 00855 .headerItem = display_main_menu_header, 00856 .footerItem = display_main_menu_footer, 00857 .enableEscapeKey = false 00858 };
Generated on Thu Jul 28 2022 09:39:03 by
1.7.2