@@ -545,6 +545,30 @@ int radio_write_register(
545545 return result ;
546546}
547547
548+ int radio_lock_register (
549+ hackrf_device * device ,
550+ const uint16_t register_number ,
551+ const bool register_locked )
552+ {
553+ int result = HACKRF_SUCCESS ;
554+ result = hackrf_radio_lock_register (
555+ device ,
556+ (uint8_t ) register_number ,
557+ register_locked );
558+
559+ if (result == HACKRF_SUCCESS ) {
560+ printf ("register [%2d] -> %s\n" ,
561+ register_number ,
562+ register_locked ? "locked" : "unlocked" );
563+ } else {
564+ printf ("hackrf_radio_lock_register() failed: %s (%d)\n" ,
565+ hackrf_error_name (result ),
566+ result );
567+ }
568+
569+ return result ;
570+ }
571+
548572int read_register (
549573 hackrf_device * device ,
550574 uint8_t part ,
@@ -621,6 +645,20 @@ int write_register(
621645 return HACKRF_ERROR_INVALID_PARAM ;
622646}
623647
648+ int lock_register (
649+ hackrf_device * device ,
650+ uint8_t part ,
651+ const uint16_t register_number ,
652+ const bool register_locked )
653+ {
654+ switch (part ) {
655+ case PART_RADIO :
656+ return radio_lock_register (device , register_number , register_locked );
657+ default :
658+ return HACKRF_ERROR_INVALID_PARAM ;
659+ }
660+ }
661+
624662static const char * mode_name (uint32_t mode )
625663{
626664 const char * mode_names [] = {"IDLE" , "WAIT" , "RX" , "TX_START" , "TX_RUN" };
@@ -675,6 +713,7 @@ static void usage()
675713 printf ("\t-n, --register <n>: set register number for read/write operations\n" );
676714 printf ("\t-r, --read: read register specified by last -n argument, or all registers\n" );
677715 printf ("\t-w, --write <v>: write register specified by last -n argument with value <v>\n" );
716+ printf ("\t-L, --lock <state>: lock register specified by last -n argument (0 for unlocked, 1 for locked)\n" );
678717 printf ("\t-c, --config: print SI5351C multisynth configuration information\n" );
679718 printf ("\t-d, --device <s>: specify a particular device by serial number\n" );
680719 printf ("\t-m, --max283x: target MAX283x\n" );
@@ -709,6 +748,7 @@ static struct option long_options[] = {
709748 {"register" , required_argument , 0 , 'n' },
710749 {"write" , required_argument , 0 , 'w' },
711750 {"read" , no_argument , 0 , 'r' },
751+ {"lock" , required_argument , 0 , 'L' },
712752 {"device" , required_argument , 0 , 'd' },
713753 {"help" , no_argument , 0 , 'h' },
714754 {"max2837" , no_argument , 0 , 'm' },
@@ -740,10 +780,12 @@ int main(int argc, char** argv)
740780 int bank = -1 ;
741781 uint64_t register_number = REGISTER_INVALID ;
742782 uint64_t register_value ;
783+ uint64_t register_locked ;
743784 hackrf_device * device = NULL ;
744785 int option_index = 0 ;
745786 bool read = false;
746787 bool write = false;
788+ bool lock = false;
747789 bool dump_config = false;
748790 bool dump_state = false;
749791 uint8_t part = PART_NONE ;
@@ -782,7 +824,7 @@ int main(int argc, char** argv)
782824 while ((opt = getopt_long (
783825 argc ,
784826 argv ,
785- "b:n:rw:d:cmsfgi1:2:C:N:P:ST:R:h?u:l:ta:o" ,
827+ "b:n:rw:l: d:cmsfgi1:2:C:N:P:ST:R:h?u:l:ta:o" ,
786828 long_options ,
787829 & option_index )) != EOF ) {
788830 switch (opt ) {
@@ -805,6 +847,11 @@ int main(int argc, char** argv)
805847 read = true;
806848 break ;
807849
850+ case 'L' :
851+ lock = true;
852+ result = parse_int (optarg , & register_locked );
853+ break ;
854+
808855 case 'c' :
809856 dump_config = true;
810857 break ;
@@ -931,8 +978,8 @@ int main(int argc, char** argv)
931978 }
932979 }
933980
934- if (write && read ) {
935- fprintf (stderr , "Read and write options are mutually exclusive.\n" );
981+ if (( write && read ) || ( lock && write ) || ( lock && read ) ) {
982+ fprintf (stderr , "Read, write and lock options are mutually exclusive.\n" );
936983 usage ();
937984 return EXIT_FAILURE ;
938985 }
@@ -949,6 +996,10 @@ int main(int argc, char** argv)
949996 return EXIT_FAILURE ;
950997 }
951998
999+ if (lock && part != PART_RADIO ) {
1000+ fprintf (stderr , "Lock option is only valid for radio.\n" );
1001+ }
1002+
9521003 if ((bank > -1 ) && (part != PART_RADIO )) {
9531004 fprintf (stderr , "Bank valid only for radio.\n" );
9541005 usage ();
@@ -959,11 +1010,11 @@ int main(int argc, char** argv)
9591010 bank = 0 ;
9601011 }
9611012
962- if (!(write || read || dump_config || dump_state || set_tx_limit ||
1013+ if (!(write || read || lock || dump_config || dump_state || set_tx_limit ||
9631014 set_rx_limit || set_ui || set_leds || set_p1 || set_p2 || set_clkin ||
9641015 set_narrowband || set_fpga_bitstream || read_selftest || test_rtc_osc ||
9651016 read_adc )) {
966- fprintf (stderr , "Specify read, write, or config option.\n" );
1017+ fprintf (stderr , "Specify read, write, lock, or config option.\n" );
9671018 usage ();
9681019 return EXIT_FAILURE ;
9691020 }
@@ -1016,6 +1067,10 @@ int main(int argc, char** argv)
10161067 }
10171068 }
10181069
1070+ if (lock ) {
1071+ result = lock_register (device , part , register_number , register_locked );
1072+ }
1073+
10191074 if (dump_config ) {
10201075 si5351c_read_configuration (device );
10211076 }
0 commit comments