Ejemplo n.º 1
0
        public bool SetFilter(int index)
        {
            if (index < 0 || index > 98)
            {
                return(false);
            }

            byte[] cmd = new byte[2];
            byte[] buf = new byte[9];

            cmd[0] = (byte)(0x65 + index);
            cmd[1] = 1;

            lock (Lock)
            {
                if (!I2CDevice.I2CWriteBytes(BusID, cmd))
                {
                    return(false);
                }

                /* make sure the atmel is done */
                WaitMs(SetFilterDelay);

                if (!I2CDevice.I2CReadBytes(BusID, buf))
                {
                    return(false);
                }
            }

            this.FilterClock = buf[5] + buf[6] * 0x100 + buf[7] * 0x10000 + buf[8] * 0x1000000;
            this.FilterWidth = buf[1] + buf[2] * 0x100 + buf[3] * 0x10000 + buf[4] * 0x1000000;

            return(true);
        }
Ejemplo n.º 2
0
        public bool AutodetectAddressing()
        {
            byte[] buffer   = new byte[3];
            byte[] backup8  = new byte[2];
            byte[] backup16 = new byte[1];

            /* first backup data at 0x00 and 0x01 */
            /* transmit read address */
            if (!I2CDevice.I2CWriteBytes(BusID, new byte[] { (byte)0 }))
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Failed to read header in 8 bit mode.");
                return(false);
            }

            Thread.Sleep(10);

            /* read data */
            if (!I2CDevice.I2CReadBytes(BusID, backup8))
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Failed to receive header in 8 bit mode.");
                return(false);
            }


            /* first backup data at 0x00 for 16 bit eeproms */
            /* transmit read address */
            if (!I2CDevice.I2CWriteBytes(BusID, new byte[] { (byte)0, (byte)0 }))
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Failed to read header in 16 bit mode.");
                return(false);
            }

            Thread.Sleep(10);

            /* read data */
            if (!I2CDevice.I2CReadBytes(BusID, backup16))
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Failed to receive header in 16 bit mode.");
                return(false);
            }


            /* write the test word */
            buffer[0] = (byte)0;
            buffer[1] = (byte)0;
            buffer[2] = (byte)0xAA;

            if (!I2CDevice.I2CWriteBytes(BusID, buffer))
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Failed to write test header in 16 bit mode.");
                return(false);
            }

            Thread.Sleep(10);

            /* read back what was placed in EEPROM */
            if (!I2CDevice.I2CWriteBytes(BusID, new byte[] { (byte)0 }))
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Failed to read test header in 8 bit mode.");
                return(false);
            }

            Thread.Sleep(10);

            if (!I2CDevice.I2CReadBytes(BusID, buffer))
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Failed to receive test header in 8 bit mode.");
                return(false);
            }

            /* the second 0x00 upon address write got interpreted as data - its a 8 bit eeprom */
            if (buffer[0] == 0x00 && buffer[1] == 0xAA)
            {
                Use16Bit = false;

                /* addressig is determined now, write back backed up data. may be crap if the eeprom is 16 bit wide. */
                WriteBytes(0, backup8);

                return(true);
            }


            /* read back what was placed in EEPROM, but use 16 bit addressing */
            if (!I2CDevice.I2CWriteBytes(BusID, new byte[] { (byte)0, (byte)0 }))
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Failed to read test header in 16 bit mode.");
                return(false);
            }

            Thread.Sleep(10);

            if (!I2CDevice.I2CReadBytes(BusID, buffer))
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Failed to receive test header in 16 bit mode.");
                return(false);
            }


            if (buffer[0] == 0xAA)
            {
                Use16Bit = true;

                /* addressig is determined now, write back backed up data. */
                WriteBytes(0, backup16);
            }
            else
            {
                Log.AddMessage("EEPROM:AutodetectAddressing(): Inexpected result when reading in 16 bit mode: 0x" + buffer[0].ToString("X2"));
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public bool OpenTuner()
        {
            if (DeviceTypeDisabled)
            {
                return(false);
            }

            if (!I2cDevice.I2CDeviceAck(BusID))
            {
                return(false);
            }

            byte[] buffer = new byte[32];
            if (!I2cDevice.I2CWriteByte(BusID, 211))
            {
                return(false);
            }
            if (!I2cDevice.I2CReadBytes(BusID, buffer))
            {
                return(false);
            }

            byte[] wordBuffer = new byte[4];

            /* read PFD - 4 byte LSB first */
            if (!I2cDevice.I2CWriteByte(BusID, 215))
            {
                return(false);
            }
            if (!I2cDevice.I2CReadBytes(BusID, wordBuffer))
            {
                return(false);
            }
            PFD = (wordBuffer[3] << 24) | (wordBuffer[2] << 16) | (wordBuffer[1] << 8) | wordBuffer[0];

            /* read Modulus - 1 byte */
            if (!I2cDevice.I2CWriteByte(BusID, 217))
            {
                return(false);
            }
            if (!I2cDevice.I2CReadByte(BusID, wordBuffer))
            {
                return(false);
            }
            Modulus = wordBuffer[0];

            /* enable LNA */
            if (!I2cDevice.I2CWriteByte(BusID, 229))
            {
                return(false);
            }

            /* disable ATT */
            if (!I2cDevice.I2CWriteBytes(BusID, new byte[] { 231, 0 }))
            {
                return(false);
            }

            if (PFD == 0)
            {
                PFD = 20000000;
            }

            if (Modulus == 0)
            {
                Modulus = 40;
            }

            long oldFreq = GetStartupFrequency();

            Init();
            SetFrequency(oldFreq);

            return(true);
        }