00001
00002 #include "edtinc.h"
00003
00004 #include "pdv_irig.h"
00005
00006 #define IRIG_REGISTER(pdv_p,reg) \
00007 ((pdv_p->channel_no == 0)?(reg):(reg)-0x40)
00008 int
00009 pdv_reset_dma_framecount(PdvDev *pdv_p)
00010
00011 {
00012 u_int util;
00013
00014 util = edt_reg_read(pdv_p, PDV_UTILITY);
00015 edt_reg_write(pdv_p, PDV_UTILITY, util & ~0xC0);
00016 edt_reg_write(pdv_p, PDV_UTILITY, util);
00017 return 0;
00018 }
00019
00020 pdv_irig_set_offset(PdvDev *pdv_p, int offset)
00021 {
00022 edt_set_timecode_seconds_offset(pdv_p,offset);
00023 pdv_p->dd_p->irig_offset = offset;
00024 return 0;
00025 }
00026
00027 int
00028 pdv_irig_set_bcd(PdvDev *pdv_p, int bcd)
00029
00030 {
00031
00032 if (pdv_p->spi_reg_base == 0)
00033 pdv_p->spi_reg_base = IRIG_REGISTER(pdv_p,PDV_IRIG_SPI_BASE);
00034
00035 edt_set_timecode_raw(pdv_p, bcd);
00036 pdv_p->dd_p->irig_raw = bcd;
00037 return 0;
00038 }
00039
00040 Irig2Record *
00041 pdv_irig_get_footer(PdvDev *pdv_p, u_char * imagedata)
00042
00043 {
00044 Irig2Record *footer;
00045
00046 int offset = pdv_get_header_offset(pdv_p);
00047
00048 footer = (Irig2Record *) (imagedata + offset);
00049
00050 return footer;
00051
00052 }
00053
00054 double pdv_irig_process_time(Irig2Record * footer)
00055
00056 {
00057 footer->timestamp = footer->t.seconds + (double) footer->clocks/(double)footer->tickspps;
00058 return footer->timestamp;
00059 }
00060
00061 void pdv_irig_reset_errors(PdvDev *pdv_p)
00062
00063 {
00064 edt_reg_write(pdv_p, IRIG_REGISTER(pdv_p,IRIG2_FIFO), IRIG2_RESET_ERRS);
00065 edt_reg_write(pdv_p, IRIG_REGISTER(pdv_p,IRIG2_FIFO), 0);
00066
00067 }
00068
00069 void pdv_irig_set_slave(PdvDev *pdv_p, int onoff)
00070
00071 {
00072 u_char mask = edt_reg_read(pdv_p, IRIG_REGISTER(pdv_p,IRIG2_CTRL));
00073
00074 mask &= ~IRIG2_SLAVE;
00075
00076 mask |= (onoff)?IRIG2_SLAVE:0;
00077
00078 edt_reg_write(pdv_p, IRIG_REGISTER(pdv_p,IRIG2_CTRL), mask);
00079
00080 pdv_p->dd_p->irig_slave = onoff;
00081 }
00082
00083 int pdv_irig_is_slave(PdvDev *pdv_p)
00084
00085 {
00086 return (edt_reg_read(pdv_p, IRIG_REGISTER(pdv_p,IRIG2_CTRL)) & IRIG2_SLAVE)?1:0;
00087 }
00088
00089 int pdv_irig_get_current(PdvDev *pdv_p, Irig2Record *footer)
00090
00091 {
00092 int i;
00093 u_char data[16];
00094 u_int *wp = (u_int *) data;
00095
00096 u_char mask = edt_reg_read(pdv_p, IRIG_REGISTER(pdv_p,IRIG2_CTRL)) & 0x80;
00097 edt_reg_write(pdv_p, IRIG_REGISTER(pdv_p,IRIG2_READWRITE), 0);
00098
00099 for (i=15 ; i>= 0 ; i--)
00100 {
00101 edt_reg_write(pdv_p, IRIG_REGISTER(pdv_p,IRIG2_CTRL), mask | i);
00102 data[i] = edt_reg_read(pdv_p, IRIG_REGISTER(pdv_p,IRIG2_READWRITE));
00103 }
00104
00105 footer->t.seconds = wp[2];
00106 footer->clocks = wp[3];
00107 footer->tickspps = wp[1];
00108 memcpy(&footer->status, &data[3], 1);
00109
00110 return 0;
00111
00112 }