1 //
2 // Copyright 2015 Ettus Research LLC
3 // Copyright 2018 Ettus Research, a National Instruments Company
4 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7
8 #include <uhd.h>
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #define UHD_TEST_EXECUTE_OR_GOTO(label, ...) \
15 if(__VA_ARGS__){ \
16 fprintf(stderr, "Error occurred at %s:%d\n", __FILE__, (__LINE__-1)); \
17 return_code = EXIT_FAILURE; \
18 goto label; \
19 }
20
21 #define BUFFER_SIZE 1024
22
main()23 int main(){
24
25 // Variables
26 int return_code;
27 uhd_mboard_eeprom_handle mb_eeprom;
28 uhd_dboard_eeprom_handle db_eeprom;
29 int db_revision;
30 char str_buffer[BUFFER_SIZE];
31
32 return_code = EXIT_SUCCESS;
33
34 /*
35 * Motherboard EEPROM test
36 */
37
38 // Create EEPROM handle
39 UHD_TEST_EXECUTE_OR_GOTO(end_of_test,
40 uhd_mboard_eeprom_make(&mb_eeprom)
41 )
42
43 // Set a value, retrieve it, and make sure it matches
44 UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom,
45 uhd_mboard_eeprom_set_value(
46 mb_eeprom,
47 "serial",
48 "F12345"
49 )
50 )
51 UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom,
52 uhd_mboard_eeprom_get_value(
53 mb_eeprom,
54 "serial",
55 str_buffer,
56 BUFFER_SIZE
57 )
58 )
59 if(strcmp(str_buffer, "F12345")){
60 return_code = EXIT_FAILURE;
61 fprintf(stderr, "%s:%d: Mismatched EEPROM value: \"%s\" vs. \"F12345\"\n",
62 __FILE__, __LINE__,
63 str_buffer);
64 goto free_mboard_eeprom;
65 }
66
67 /*
68 * Daughterboard EEPROM test
69 */
70
71 // Create EEPROM handle
72 UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom,
73 uhd_dboard_eeprom_make(&db_eeprom)
74 )
75
76 // Set the ID, retrieve it, and make sure it matches
77 UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
78 uhd_dboard_eeprom_set_id(db_eeprom, "0x0067")
79 )
80 UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
81 uhd_dboard_eeprom_get_id(
82 db_eeprom,
83 str_buffer,
84 BUFFER_SIZE
85 )
86 )
87 if(strcmp(str_buffer, "0x0067")){
88 return_code = EXIT_FAILURE;
89 fprintf(stderr, "%s:%d: Mismatched daughterboard ID: \"%s\" vs. \"0x0067\"\n",
90 __FILE__, __LINE__,
91 str_buffer);
92 goto free_dboard_eeprom;
93 }
94
95 // Set the serial, retrieve it, and make sure it matches
96 UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
97 uhd_dboard_eeprom_set_serial(db_eeprom, "F12345")
98 )
99 UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
100 uhd_dboard_eeprom_get_serial(
101 db_eeprom,
102 str_buffer,
103 BUFFER_SIZE
104 )
105 )
106 if(strcmp(str_buffer, "F12345")){
107 return_code = EXIT_FAILURE;
108 fprintf(stderr, "%s:%d: Mismatched daughterboard serial: \"%s\" vs. \"F12345\"\n",
109 __FILE__, __LINE__,
110 str_buffer);
111 goto free_dboard_eeprom;
112 }
113
114 // Set the revision, retrieve it, and make sure it matches
115 UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
116 uhd_dboard_eeprom_set_revision(db_eeprom, 4)
117 )
118 UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
119 uhd_dboard_eeprom_get_revision(db_eeprom, &db_revision)
120 )
121 if(db_revision != 4){
122 return_code = EXIT_FAILURE;
123 fprintf(stderr, "%s:%d: Mismatched daughterboard revision: \"%d\" vs. 4\n",
124 __FILE__, __LINE__, db_revision);
125 goto free_dboard_eeprom;
126 }
127
128 free_dboard_eeprom:
129 if(return_code){
130 uhd_dboard_eeprom_last_error(db_eeprom, str_buffer, BUFFER_SIZE);
131 fprintf(stderr, "db_eeprom error: %s\n", str_buffer);
132 }
133 uhd_dboard_eeprom_free(&db_eeprom);
134
135 free_mboard_eeprom:
136 if(return_code){
137 uhd_mboard_eeprom_last_error(mb_eeprom, str_buffer, BUFFER_SIZE);
138 fprintf(stderr, "mb_eeprom error: %s\n", str_buffer);
139 }
140 uhd_mboard_eeprom_free(&mb_eeprom);
141
142 end_of_test:
143 if(!return_code){
144 printf("\nNo errors detected\n");
145 }
146 return return_code;
147 }
148