From 30f87afcba71a07fbd28d51318e791448c28314e Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Thu, 6 Aug 2015 10:42:23 -0700 Subject: uhd: C API wrapper * multi_usrp, multi_usrp_clock, and associated classes accessible through C * Added Doxygen documentation explaining structure and API * Simple RX and TX streaming examples * Unit tests for different parts of C interface and C++ error conversion --- host/tests/eeprom_c_test.c | 155 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 host/tests/eeprom_c_test.c (limited to 'host/tests/eeprom_c_test.c') diff --git a/host/tests/eeprom_c_test.c b/host/tests/eeprom_c_test.c new file mode 100644 index 000000000..0f03295e8 --- /dev/null +++ b/host/tests/eeprom_c_test.c @@ -0,0 +1,155 @@ +// +// Copyright 2015 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include + +#include +#include +#include + +#define UHD_TEST_EXECUTE_OR_GOTO(label, ...) \ + if(__VA_ARGS__){ \ + fprintf(stderr, "Error occurred at %s:%d\n", __FILE__, (__LINE__-1)); \ + return_code = EXIT_FAILURE; \ + goto label; \ + } + +#define BUFFER_SIZE 1024 + +int main(){ + + // Variables + int return_code; + uhd_mboard_eeprom_handle mb_eeprom; + uhd_dboard_eeprom_handle db_eeprom; + int db_revision; + char str_buffer[BUFFER_SIZE]; + + return_code = EXIT_SUCCESS; + + /* + * Motherboard EEPROM test + */ + + // Create EEPROM handle + UHD_TEST_EXECUTE_OR_GOTO(end_of_test, + uhd_mboard_eeprom_make(&mb_eeprom) + ) + + // Set a value, retrieve it, and make sure it matches + UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom, + uhd_mboard_eeprom_set_value( + mb_eeprom, + "serial", + "F12345" + ) + ) + UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom, + uhd_mboard_eeprom_get_value( + mb_eeprom, + "serial", + str_buffer, + BUFFER_SIZE + ) + ) + if(strcmp(str_buffer, "F12345")){ + return_code = EXIT_FAILURE; + fprintf(stderr, "%s:%d: Mismatched EEPROM value: \"%s\" vs. \"F12345\"\n", + __FILE__, __LINE__, + str_buffer); + goto free_mboard_eeprom; + } + + /* + * Daughterboard EEPROM test + */ + + // Create EEPROM handle + UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom, + uhd_dboard_eeprom_make(&db_eeprom) + ) + + // Set the ID, retrieve it, and make sure it matches + UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, + uhd_dboard_eeprom_set_id(db_eeprom, "0x0067") + ) + UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, + uhd_dboard_eeprom_get_id( + db_eeprom, + str_buffer, + BUFFER_SIZE + ) + ) + if(strcmp(str_buffer, "0x0067")){ + return_code = EXIT_FAILURE; + fprintf(stderr, "%s:%d: Mismatched daughterboard ID: \"%s\" vs. \"0x0067\"\n", + __FILE__, __LINE__, + str_buffer); + goto free_dboard_eeprom; + } + + // Set the serial, retrieve it, and make sure it matches + UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, + uhd_dboard_eeprom_set_serial(db_eeprom, "F12345") + ) + UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, + uhd_dboard_eeprom_get_serial( + db_eeprom, + str_buffer, + BUFFER_SIZE + ) + ) + if(strcmp(str_buffer, "F12345")){ + return_code = EXIT_FAILURE; + fprintf(stderr, "%s:%d: Mismatched daughterboard serial: \"%s\" vs. \"F12345\"\n", + __FILE__, __LINE__, + str_buffer); + goto free_dboard_eeprom; + } + + // Set the revision, retrieve it, and make sure it matches + UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, + uhd_dboard_eeprom_set_revision(db_eeprom, 4) + ) + UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, + uhd_dboard_eeprom_get_revision(db_eeprom, &db_revision) + ) + if(db_revision != 4){ + return_code = EXIT_FAILURE; + fprintf(stderr, "%s:%d: Mismatched daughterboard revision: \"%d\" vs. 4\n", + __FILE__, __LINE__, db_revision); + goto free_dboard_eeprom; + } + + free_dboard_eeprom: + if(return_code){ + uhd_dboard_eeprom_last_error(db_eeprom, str_buffer, BUFFER_SIZE); + fprintf(stderr, "db_eeprom error: %s\n", str_buffer); + } + + free_mboard_eeprom: + if(return_code){ + uhd_mboard_eeprom_last_error(mb_eeprom, str_buffer, BUFFER_SIZE); + fprintf(stderr, "mb_eeprom error: %s\n", str_buffer); + } + + end_of_test: + if(!return_code){ + printf("\nNo errors detected\n"); + } + return return_code; +} -- cgit v1.2.3