lib_msdv.c

00001 /* #pragma ident "@(#)set_ss_vco.c      1.17 01/17/05 EDT" */
00002 
00003 #include <stdio.h>
00004 #include <math.h>
00005 
00006 #include <string.h>
00007 
00008 #include <stdlib.h>
00009 
00010 #include "edtinc.h"
00011 
00012 #include <stddef.h>
00013 
00014 #include "edt_si5326.h"
00015 
00016 #include "edt_msdv.h"
00017 
00018 #include "edt_ocm.h"
00019 
00020 #include "lib_two_wire.h"
00021 
00022 #include "edt_bitload.h"
00023 
00024 
00025 #define  MSDV_PORT_OFFSET 0
00026 #define  MSDV_DATA_OFFSET 1
00027 #define  MSDV_REFRAME_OFF 2
00028 #define  MSDV_DISP_OFF    3
00029 #define  MSDV_CODE_OFF    4
00030 #define  MSDV_PSTAT_OFF   5
00031 
00032 static int msdv_channel_base[4] = 
00033 {
00034     MSDV_CH0_PORT_CONFIG,
00035     MSDV_CH1_PORT_CONFIG,
00036     MSDV_CH2_PORT_CONFIG,
00037     MSDV_CH3_PORT_CONFIG
00038 };
00039 
00040 #define MSDV_PORT_CONFIG(chan) (msdv_channel_base[chan])
00041 #define MSDV_DATA_CONFIG(chan) (msdv_channel_base[chan]+MSDV_DATA_OFFSET)
00042 #define MSDV_REFRAME_COUNT(chan) (msdv_channel_base[chan]+MSDV_REFRAME_OFF)
00043 #define MSDV_DISP_ERR_COUNT(chan) (msdv_channel_base[chan]+MSDV_DISP_OFF)
00044 #define MSDV_CODE_ERR_COUNT(chan) (msdv_channel_base[chan]+MSDV_CODE_OFF)
00045 #define MSDV_PORT_STATUS(chan) (msdv_channel_base[chan]+MSDV_PSTAT_OFF)
00046 
00047 static char * msdv_mode_names[8] = 
00048 
00049 {
00050     "raw",
00051     "bit aligned",
00052     "decoded",
00053     "data only",
00054     "TS frames",
00055     "timestamp TS",
00056     "PRBS15",
00057     "test"
00058 
00059 };
00060 
00061 
00062 Edt2WireRegArray msdv_148p5_2[EDT_SI5326_NREGS+1] = {
00063     {  0, 0x14},
00064     {  1, 0xe4},
00065     {  2, 0x12},
00066     {  3, 0x5},
00067     {  4, 0x92},
00068     {  5, 0xed},
00069     {  6, 0x2d},
00070     {  7, 0x2a},
00071     {  8, 0x0},
00072     {  9, 0xc0},
00073     { 10, 0x8},
00074     { 11, 0x48},
00075     { 16, 0x0},
00076     { 17, 0x80},
00077     { 18, 0x0},
00078     { 19, 0x29},
00079     { 20, 0x3e},
00080     { 21, 0xff},
00081     { 22, 0xdf},
00082     { 23, 0x1f},
00083     { 24, 0x3f},
00084     { 25, 0xa0},
00085     { 31, 0x0},
00086     { 32, 0x0},
00087     { 33, 0x3},
00088     { 34, 0x0},
00089     { 35, 0x0},
00090     { 36, 0x3},
00091     { 40, 0xa2},
00092     { 41, 0x2f},
00093     { 42, 0x79},
00094     { 43, 0x0},
00095     { 44, 0x9},
00096     { 45, 0xc3},
00097     { 46, 0x0},
00098     { 47, 0x9},
00099     { 48, 0xc3},
00100     { 55, 0x0},
00101     {128, 0, 1},
00102     {129, 0, 1},
00103     {130, 0, 1},
00104     {131, 0x1f},
00105     {132, 0x2},
00106     {134, 0, 1},
00107     {135, 0, 1},
00108     {136, 0x40},
00109     {142, 0x0},
00110     {143, 0x0},
00111     {256,0}
00112 };
00113 
00114 Edt2WireRegArray msdv_148p5[EDT_SI5326_NREGS+1] = {
00115     {  0,0x14},
00116     {  1,0xe4},
00117     {  2,0x22},
00118     {  3,0x5},
00119     {  4,0x92},
00120     {  5,0xed},
00121     {  6,0x2d},
00122     {  7,0x2a},
00123     {  8,0x0},
00124     {  9,0xc0},
00125     { 10,0x8},
00126     { 11,0x48},
00127     { 16,0x0},
00128     { 17,0x80},
00129     { 18,0x0},
00130     { 19,0x29},
00131     { 20,0x3e},
00132     { 21,0xff},
00133     { 22,0xdf},
00134     { 23,0x1f},
00135     { 24,0x3f},
00136     { 25,0xa0},
00137     { 31,0x0},
00138     { 32,0x0},
00139     { 33,0x3},
00140     { 34,0x0},
00141     { 35,0x0},
00142     { 36,0x3},
00143     { 40,0xa1},
00144     { 41,0x17},
00145     { 42,0xbd},
00146     { 43,0x0},
00147     { 44,0x4},
00148     { 45,0xe1},
00149     { 46,0x0},
00150     { 47,0x4},
00151     { 48,0xe1},
00152     { 55,0x0},
00153     {128, 0, 1},
00154     {129, 0, 1},
00155     {130, 0, 1},
00156     {131,0x1f},
00157     {132,0x2},
00158     {134, 0, 1},
00159     {135, 0, 1},
00160     {136,0x40},
00161     {142,0x0},
00162     {143,0x0},
00163     {256,0}
00164 };
00165 
00166 
00167 static int
00168 msdv_get_si5326_value(void *target, int device, int offset, int shift, int mask)
00169 
00170 {
00171     EdtDev *edt_p = (EdtDev *) target;
00172     int shiftmask = (mask << shift);
00173     int v;
00174 
00175     v = edt_serial_dev_reg_read(edt_p, MSDV_SERIAL_DEV, device, offset);
00176 
00177     if (mask != 0xff)
00178     {
00179         v = (v & shiftmask) >> shift;
00180     }
00181 
00182     return v;
00183 
00184 }
00185 
00186 static int
00187 msdv_set_si5326_value(void *target, int device, int offset, int value, int shift, int mask)
00188 
00189 {
00190     EdtDev *edt_p = (EdtDev *) target;
00191     int invmask = ~(mask << shift);
00192     int v = value;
00193 
00194     if (mask != 0xff)
00195     {
00196         v = edt_serial_dev_reg_read(edt_p, MSDV_SERIAL_DEV, device, offset);
00197 
00198         v &= invmask;
00199         v |= (value << shift);
00200     }
00201 
00202     edt_serial_dev_reg_write(edt_p, MSDV_SERIAL_DEV, device, offset, v);
00203 
00204     return 0;
00205 
00206 }
00207 
00208 int
00209 edt_msdv_si5326_dump(EdtDev *edt_p)
00210 
00211 {
00212 
00213     int mapindex;
00214 
00215     for (mapindex = 0; si5326regs_map[mapindex].name != NULL ; mapindex++)
00216     {
00217         u_int v = edt_get_two_wire_value(edt_p, 
00218             si5326regs_map + mapindex,
00219             MSDV_SERIAL_DEV, 
00220             0);
00221 
00222         printf("%-20s: %02x\n", si5326regs_map[mapindex].name, v);
00223 
00224     }
00225 
00226     return 0;
00227 
00228 }
00229 
00230 int
00231 edt_msdv_si5326_load_array(EdtDev *edt_p,  Edt2WireRegArray *vec)
00232 
00233 {
00234     int mapindex;
00235     int r;
00236     for (mapindex = 0; vec[mapindex].offset < 256 && mapindex < EDT_SI5326_NREGS ; mapindex++)
00237     {
00238         if (!vec[mapindex].read_only)
00239         {
00240             edt_serial_dev_reg_write(edt_p, MSDV_SERIAL_DEV, 0, vec[mapindex].offset, vec[mapindex].value);
00241             r = edt_serial_dev_reg_read(edt_p, MSDV_SERIAL_DEV, 0, vec[mapindex].offset);
00242 
00243             if (r != vec[mapindex].value)
00244                 printf("Unable to write at offset %d value %02x != %02x\n",
00245                 vec[mapindex].offset, vec[mapindex].value, r);
00246 
00247 
00248         }
00249     }
00250     return 0;
00251 
00252 }
00253 
00254 int
00255 edt_msdv_set_mode(EdtDev *edt_p, int mode)
00256 
00257 {
00258     int r;
00259 
00260     if (mode < 0 || mode > 7)
00261     {
00262         edt_msg(EDTLIB_MSG_FATAL,"MSDV mode must be in 0..7\n");
00263         return -1;
00264     }
00265 
00266     r = edt_reg_read(edt_p, MSDV_DATA_CONFIG(edt_p->channel_no));
00267     r = (r & ~0x7) | mode;
00268     edt_reg_write(edt_p, MSDV_DATA_CONFIG(edt_p->channel_no), r);
00269 
00270     return 0;
00271 }
00272 
00273 int
00274 edt_msdv_get_mode(EdtDev *edt_p)
00275 
00276 {
00277     int r;
00278 
00279     r = edt_reg_read(edt_p, MSDV_DATA_CONFIG(edt_p->channel_no));
00280 
00281     return (r & ~0x7);
00282 }
00283 
00284 int
00285 edt_msdv_get_status(EdtDev *edt_p)
00286 
00287 {
00288 
00289     return edt_reg_read(edt_p, MSDV_PORT_STATUS(edt_p->channel_no));
00290 }
00291 
00292 int
00293 edt_msdv_set_direction(EdtDev *edt_p, int direction)
00294 
00295 {
00296     int r;
00297     int channel = edt_p->channel_no;
00298 
00299     /* set port direction */
00300 
00301     r = edt_reg_read(edt_p, MSDV_PORT_CONFIG(channel));
00302     r = (r & ~0x1) | direction;
00303     edt_reg_write(edt_p, MSDV_PORT_CONFIG(channel), r);
00304 
00305     /* set channel direction */
00306 
00307     r = edt_reg_read(edt_p, SSD16_CHDIR);
00308     r = (r & ~(1 << channel)) | (direction)?(1 << channel):0;
00309     edt_reg_write(edt_p, SSD16_CHDIR, r);
00310 
00311 
00312     return 0;
00313 }
00314 
00315 int
00316 edt_msdv_get_direction(EdtDev *edt_p)
00317 
00318 {
00319     int r;
00320     /* get port direction */
00321 
00322     r = edt_reg_read(edt_p, MSDV_PORT_CONFIG(edt_p->channel_no));
00323     return (r & ~0x1);
00324 }
00325 
00326 int
00327 edt_msdv_set_definition(EdtDev *edt_p, int onoff)
00328 
00329 {
00330     return edt_reg_set_bitmask(edt_p, MSDV_PORT_CONFIG(edt_p->channel_no),
00331         MSDV_XMIT_STDDEF, onoff);
00332 
00333 }
00334 
00335 int
00336 edt_msdv_get_definition(EdtDev *edt_p)
00337 
00338 {
00339     return ((edt_reg_read(edt_p, MSDV_PORT_CONFIG(edt_p->channel_no)) & 
00340         MSDV_XMIT_STDDEF) != 0)?1:0;
00341 }
00342 
00343 
00344 int
00345 edt_msdv_set_mute(EdtDev *edt_p, int onoff)
00346 
00347 {
00348     return edt_reg_set_bitmask(edt_p, MSDV_PORT_CONFIG(edt_p->channel_no),
00349         MSDV_MUTE_INPUT, onoff);
00350 
00351 }
00352 
00353 int
00354 edt_msdv_get_mute(EdtDev *edt_p)
00355 
00356 {
00357     return ((edt_reg_read(edt_p, MSDV_PORT_CONFIG(edt_p->channel_no)) & 
00358         MSDV_MUTE_INPUT) != 0)?1:0;
00359 
00360 }
00361 
00362 
00363 int
00364 edt_msdv_set_bypass(EdtDev *edt_p, int onoff)
00365 
00366 {
00367     return edt_reg_set_bitmask(edt_p, MSDV_PORT_CONFIG(edt_p->channel_no),
00368         MSDV_BYPASS, onoff);
00369 
00370 }
00371 
00372 int
00373 edt_msdv_get_bypass(EdtDev *edt_p)
00374 
00375 {
00376     return ((edt_reg_read(edt_p, MSDV_PORT_CONFIG(edt_p->channel_no)) & 
00377         MSDV_BYPASS) != 0)?1:0;
00378 
00379 }
00380 
00381 
00382 int
00383 edt_msdv_set_error_enable(EdtDev *edt_p, int onoff)
00384 
00385 {
00386     return edt_reg_set_bitmask(edt_p, MSDV_PORT_CONFIG(edt_p->channel_no),
00387         MSDV_ERR_COUNT_EN, onoff);
00388 }
00389 
00390 int
00391 edt_msdv_get_error_enable(EdtDev *edt_p)
00392 
00393 {
00394     return ((edt_reg_read(edt_p, MSDV_PORT_CONFIG(edt_p->channel_no)) & 
00395         MSDV_ERR_COUNT_EN) != 0)?1:0;
00396 }
00397 
00398 
00399 int
00400 edt_msdv_set_invert_prbs(EdtDev *edt_p, int onoff)
00401 
00402 {
00403     return edt_reg_set_bitmask(edt_p, MSDV_DATA_CONFIG(edt_p->channel_no),
00404         MSDV_INVERT_PRBS, onoff);
00405 }
00406 
00407 int
00408 edt_msdv_get_invert_prbs(EdtDev *edt_p)
00409 
00410 {
00411     return ((edt_reg_read(edt_p, MSDV_DATA_CONFIG(edt_p->channel_no)) & 
00412         MSDV_INVERT_PRBS) != 0)?1:0;
00413 }
00414 
00415 
00416 int
00417 edt_msdv_set_filter_idle(EdtDev *edt_p, int onoff)
00418 
00419 {
00420     return edt_reg_set_bitmask(edt_p, MSDV_DATA_CONFIG(edt_p->channel_no),
00421         MSDV_FILTER_IDLE, onoff);
00422 
00423 }
00424 
00425 int
00426 edt_msdv_get_filter_idle(EdtDev *edt_p)
00427 
00428 {
00429     return ((edt_reg_read(edt_p, MSDV_DATA_CONFIG(edt_p->channel_no)) & 
00430         MSDV_FILTER_IDLE) != 0)?1:0;
00431 
00432 }
00433 
00434 
00435 static char *
00436 status_bit_string(char *s, char *fmt, int *r, int bitmask, char *onstring, char * offstring)
00437 
00438 {
00439     sprintf(s, fmt, 
00440         (r[0] & bitmask)?onstring:offstring,
00441         (r[1] & bitmask)?onstring:offstring,
00442         (r[2] & bitmask)?onstring:offstring,
00443         (r[3] & bitmask)?onstring:offstring);
00444 
00445     return s;
00446 }
00447 
00448 
00449 
00450 int
00451 edt_msdv_print_status(FILE *f, EdtDev *edt_p)
00452 
00453 {
00454     int channel;
00455     char s[80];
00456     int ch;
00457     int r[4];
00458 
00459     if (f == NULL)
00460         f = stdout;
00461 
00462     fprintf(f,"MSDV Status\n\n");
00463 
00464     ch = edt_reg_read(edt_p, SSD16_CHEN);
00465     for (channel=0;channel<4;channel++)
00466         r[channel] = (ch & (1 << channel));
00467 
00468     fprintf(f,"Channel Enable   = %s\n", status_bit_string(s, "%12s%12s%12s%12s",r,0xf,"on","off"));
00469 
00470     for (channel = 0;channel<4;channel++)
00471         r[channel] = edt_reg_read(edt_p, MSDV_PORT_CONFIG(channel));
00472 
00473 
00474     fprintf(f,"Port Config     \n");
00475     fprintf(f,"    direction    = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 1,"output","input"));
00476     fprintf(f,"    definition   = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 4,"std","hidef"));
00477     fprintf(f,"    mute         = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 8,"on","off"));
00478     fprintf(f,"    bypass       = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 0x10,"on","off"));
00479     fprintf(f,"    error count  = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 0x80,"enabled","disabled"));
00480 
00481 
00482     for (channel = 0;channel<4;channel++)
00483         r[channel] = edt_reg_read(edt_p, MSDV_DATA_CONFIG(channel));
00484 
00485     fprintf(f,"\nData Config\n");
00486     sprintf(s,"%12s%12s%12s%12s",
00487         msdv_mode_names[(r[0]&7)],
00488         msdv_mode_names[(r[1]&7)],
00489         msdv_mode_names[(r[2]&7)],
00490         msdv_mode_names[(r[3]&7)]);
00491 
00492     fprintf(f,"    mode         = %s\n",s);
00493     fprintf(f,"    invert prbs  = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 8,"on","off"));
00494     fprintf(f,"    filter idle  = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 0x10,"on","off"));
00495 
00496     for (channel = 0;channel<4;channel++)
00497         r[channel] = edt_reg_read(edt_p, MSDV_PORT_STATUS(channel));
00498 
00499     fprintf(f, "\nPort Status\n");
00500     fprintf(f,"    carrier det  = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 1,"on","off"));
00501     fprintf(f,"    reset        = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 2,"on","off"));
00502     fprintf(f,"    lock         = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 4,"on","off"));
00503     fprintf(f,"    bit align    = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 8,"on","off"));
00504     fprintf(f,"    TS frame     = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 0x10,"on","off")); 
00505     fprintf(f,"    TS 206       = %s\n",status_bit_string(s, "%12s%12s%12s%12s",r, 0x20,"on","off"));
00506 
00507 
00508     for (channel = 0;channel<4;channel++)
00509         r[channel] = edt_reg_read(edt_p, MSDV_REFRAME_COUNT(channel));
00510 
00511     fprintf(f, "\nReframe Count    = %12d%12d%12d%12d\n",r[0],r[1],r[2],r[3]);
00512 
00513 
00514     for (channel = 0;channel<4;channel++)
00515         r[channel] = edt_reg_read(edt_p, MSDV_CODE_ERR_COUNT(channel));
00516 
00517     fprintf(f, "Coder Errors     = %12d%12d%12d%12d\n",r[0],r[1],r[2],r[3]);
00518 
00519     for (channel = 0;channel<4;channel++)
00520         r[channel] = edt_reg_read(edt_p, MSDV_DISP_ERR_COUNT(channel));
00521 
00522     fprintf(f, "Disparity Errors = %12d%12d%12d%12d\n",r[0],r[1],r[2],r[3]);
00523 
00524     return 0;
00525 }
00526 
00527 int
00528 edt_msdv_configure(EdtDev *edt_p, int mode)
00529 
00530 {
00531     edt_reg_write(edt_p, MSDV_CLK0_CFG_STAT, SI532X_ENABLE);
00532 
00533     /* initialize msdv clock to 148.5 */
00534 
00535     edt_msdv_si5326_load_array(edt_p, msdv_148p5);
00536 
00537     edt_msdv_set_mode(edt_p, mode);
00538 
00539     return 0;
00540 
00541 }

Generated on 19 Jun 2015 by  doxygen 1.4.7