LCOV - code coverage report
Current view: top level - mu2e-pcie-utils/dtcInterfaceLib - rick_clock_test.cc (source / functions) Coverage Total Hit
Test: mu2edaq.info.cleaned Lines: 0.0 % 80 0
Test Date: 2026-07-30 01:56:44 Functions: 0.0 % 3 0

            Line data    Source code
       1              : // This file (my_cntl.cc) was created by Ron Rechenmacher <ron@fnal.gov> on
       2              : // Feb  6, 2014. "TERMS AND CONDITIONS" governing this file are in the README
       3              : // or COPYING file. If you do not have such a file, one can be obtained by
       4              : // contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.
       5              : // $RCSfile: .emacs.gnu,v $
       6              : static char* rev = (char*)"$Revision: 1.23 $$Date: 2012/01/23 15:32:40 $";
       7              : 
       8              : #include <fcntl.h>   // open, O_RDONLY
       9              : #include <getopt.h>  // getopt_long
      10              : #include <libgen.h>  // basename
      11              : #include <stdio.h>   // printf
      12              : #include <stdlib.h>  // strtoul
      13              : #include <string.h>  // strcmp
      14              : 
      15              : #include "mu2e_driver/mu2e_mmap_ioctl.h"  // m_ioc_cmd_t
      16              : #include "mu2edev.h"                      // mu2edev
      17              : 
      18              : #define USAGE \
      19              :         "\
      20              :    usage: %s <start|stop|dump>\n\
      21              :           %s read <offset>\n\
      22              :           %s write <offset> <val>\n\
      23              :           %s write_loopback_data [-p<packet_cnt>] [data]...\n\
      24              : examples: %s start\n\
      25              : ",            \
      26              :                 basename(argv[0]), basename(argv[0]), basename(argv[0]), basename(argv[0]), basename(argv[0])
      27              : 
      28            0 : void write(unsigned long addr, unsigned long val, int fd)
      29              : {
      30              :         m_ioc_reg_access_t reg_access;
      31            0 :         reg_access.reg_offset = addr;
      32            0 :         reg_access.access_type = 1;
      33            0 :         reg_access.val = val;
      34            0 :         int sts = ioctl(fd, M_IOC_REG_ACCESS, &reg_access);
      35            0 :         if (sts)
      36              :         {
      37            0 :                 perror("ioctl M_IOC_REG_ACCESS write");
      38            0 :                 exit(1);
      39              :         }
      40            0 : }
      41              : 
      42            0 : void write_and_check(unsigned long addr, int fd)
      43              : {
      44              :         m_ioc_reg_access_t reg_access;
      45            0 :         reg_access.reg_offset = addr;
      46            0 :         reg_access.access_type = 1;
      47            0 :         reg_access.val = 1;
      48            0 :         int sts = ioctl(fd, M_IOC_REG_ACCESS, &reg_access);
      49            0 :         if (sts)
      50              :         {
      51            0 :                 perror("ioctl M_IOC_REG_ACCESS write");
      52            0 :                 exit(1);
      53              :         }
      54              : 
      55            0 :         while (reg_access.val == 1)
      56              :         {
      57            0 :                 reg_access.access_type = 0;
      58            0 :                 sts = ioctl(fd, M_IOC_REG_ACCESS, &reg_access);
      59            0 :                 if (sts)
      60              :                 {
      61            0 :                         perror("ioctl M_IOC_REG_ACCESS read");
      62            0 :                         exit(1);
      63              :                 }
      64            0 :                 usleep(100);
      65              :         }
      66            0 : }
      67              : 
      68            0 : int main(int argc, char* argv[])
      69              : {
      70            0 :         int sts = 0;
      71              :         int fd;
      72            0 :         mu2edev dev;
      73              :         char devfile[11];
      74            0 :         int dtc = -1;
      75              : 
      76            0 :         int opt_v = 0;
      77              :         int opt;
      78              :         while (1)
      79              :         {
      80            0 :                 int option_index = 0;
      81              :                 static struct option long_options[] = {
      82              :                         /* name,   has_arg, int* flag, val_for_flag */
      83              :                         {"mem-to-malloc", 1, 0, 'm'},
      84              :                         {0, 0, 0, 0},
      85              :                 };
      86            0 :                 opt = getopt_long(argc, argv, "?hm:Vv", long_options, &option_index);
      87            0 :                 if (opt == -1) break;
      88            0 :                 switch (opt)
      89              :                 {
      90            0 :                         case '?':
      91              :                         case 'h':
      92            0 :                                 printf(USAGE);
      93            0 :                                 exit(0);
      94              :                                 break;
      95            0 :                         case 'V':
      96            0 :                                 printf("%s\n", rev);
      97            0 :                                 return (0);
      98              :                                 break;
      99            0 :                         case 'v':
     100            0 :                                 opt_v++;
     101            0 :                                 break;
     102            0 :                         case 'd':
     103            0 :                                 dtc = strtol(optarg, NULL, 0);
     104            0 :                                 break;
     105            0 :                         default:
     106            0 :                                 printf("?? getopt returned character code 0%o ??\n", opt);
     107              :                 }
     108            0 :         }
     109              : 
     110            0 :         if (dtc == -1)
     111              :         {
     112            0 :                 char* dtcE = getenv("DTCLIB_DTC");
     113            0 :                 if (dtcE != NULL)
     114            0 :                         dtc = strtol(dtcE, NULL, 0);
     115              :                 else
     116            0 :                         dtc = 0;
     117              :         }
     118              : 
     119            0 :         snprintf(devfile, 11, "/dev/" MU2E_DEV_FILE, dtc);
     120              : 
     121            0 :         fd = open(devfile, O_RDONLY);
     122            0 :         if (fd == -1)
     123              :         {
     124            0 :                 perror("open");
     125            0 :                 return (1);
     126              :         }
     127              : 
     128              :         // set xtal on timing card to 200mhz
     129              :         // freeze DCO
     130            0 :         write(0x9168, 0x5d891000, fd);
     131            0 :         write_and_check(0x916c, fd);
     132              : 
     133              :         // write new values for FRREQ, HS_DIV, N1
     134            0 :         write(0x9168, 0x5d076000, fd);
     135            0 :         write_and_check(0x916c, fd);
     136              : 
     137            0 :         write(0x9168, 0x5d08c300, fd);
     138            0 :         write_and_check(0x916c, fd);
     139              : 
     140            0 :         write(0x9168, 0x5d091000, fd);
     141            0 :         write_and_check(0x916c, fd);
     142              : 
     143            0 :         write(0x9168, 0x5d0a6900, fd);
     144            0 :         write_and_check(0x916c, fd);
     145              : 
     146            0 :         write(0x9168, 0x5d0b8d00, fd);
     147            0 :         write_and_check(0x916c, fd);
     148              : 
     149            0 :         write(0x9168, 0x5d0c7700, fd);
     150            0 :         write_and_check(0x916c, fd);
     151              : 
     152              :         // unfreeze DCO
     153            0 :         write(0x9168, 0x5d890000, fd);
     154            0 :         write_and_check(0x916c, fd);
     155              : 
     156              :         // Set NewFreq bit
     157            0 :         write(0x9168, 0x5d874000, fd);
     158            0 :         write_and_check(0x916c, fd);
     159              : 
     160            0 :         printf("sts=%d\n", sts);
     161            0 :         return (0);
     162            0 : }  // main
        

Generated by: LCOV version 2.0-1