コード例 #1
0
        public static void ReadI2CWorker(object data)
        {
            WiiReaderV1 reader = ((WiiReaderV1)data);

            while (!reader.inShutdown)
            {
                I2CPacket packet = reader.packetPool[reader.currentPacketInPool];
                reader.currentPacketInPool += 1;
                reader.currentPacketInPool %= 100;

                uint  status         = 0;
                ulong timeSop        = 0;
                ulong timeDuration   = 0;
                uint  timeDataOffset = 0;

                packet.Length = BeagleApi.bg_i2c_read(
                    ((WiiReaderV1)data).hBeagle, ref status, ref timeSop,
                    ref timeDuration, ref timeDataOffset, 1024, packet.Data);

                if (packet.Length >= 1)
                {
                    reader.packetsToBeProcessed.Enqueue(packet);
                }
            }
        }
コード例 #2
0
        public List <string> snoop_i2c(int num_packets)
        {
            // Capture and print each transaction
            List <ushort> full_data = new List <ushort>();           //keep adding bytes to this as it goes
            List <string> lines     = new List <string>();

            for (int i = 0; i < num_packets || num_packets == 0; ++i)
            {
                uint  status = 0;
                ulong time_sop = 0, time_sop_ns = 0;
                ulong time_duration   = 0;
                uint  time_dataoffset = 0;
                int   count           = 0;

                // Read transaction with bit timing data
                try
                {
                    count = BeagleApi.bg_i2c_read(handle, ref status, ref time_sop, ref time_duration, ref time_dataoffset, max_bytes, data_in);
                    //count = BeagleApi.bg_i2c_read_bit_timing(handle, ref status, ref time_sop, ref time_duration, ref time_dataoffset, max_bytes, data_in, timing_size, timing);
                }
                catch
                {
                    Console.WriteLine("Error in I2C bit read, skipping");
                    continue;
                }
                string output        = "";// output_parse(data_in);			//for building console output
                string status_string = print_general_status(status);
                try
                {
                    buffer.AddRange(data_in); //add to my own buffer
                }
                catch (System.ArgumentOutOfRangeException)
                {
                    Console.WriteLine("Skipping measurement..");
                }
                ///lines.Add(status_string + " - " + output + " - " + "Iteration: " + i); //added this so see in gui

                if (status_string.Contains("TIMEOUT"))
                {
                    continue;                     //skip if no activity on bus
                }
                // Translate timestamp to ns
                time_sop_ns = TIMESTAMP_TO_NS(time_sop, sample_rate);

                ///Console.Write("{0:d},{1:d}", i, time_sop_ns);
                ///Console.Write(",I2C,(");

                if (count < 0)                 //error condition
                {
                    Console.Write("error={0:d},", count);
                }
                ///else
                ///	Console.Write("Read " + count + " bits. ");

                //print_general_status(status); //below reference funct -> moved up
                ///Console.Write(status_string);
                ///print_i2c_status(status); //below reference funct
                ///Console.Write(")");

                // Check for errors
                if (count <= 0)
                {
                    Console.Write("\n");
                    Console.Out.Flush();                     //what does this do?

                    if (count < 0)
                    {
                        break;
                    }

                    // If zero data captured, continue
                    continue;
                }

                // Print the address and read/write
                ///Console.Write(",");
                int offset = 0;

                /*
                 *              if ((status & BeagleApi.BG_READ_ERR_MIDDLE_OF_PACKET) == 0)
                 *              {
                 *                      // Display the start condition
                 *                      Console.Write("[S] ");
                 *
                 *                      if (count >= 1)
                 *                      {
                 *                              // Determine if byte was NACKed
                 *                              int nack = (data_in[0] & BeagleApi.BG_I2C_MONITOR_NACK);
                 *
                 *                              // Determine if this is a 10-bit address
                 *                              if (count == 1 || (data_in[0] & 0xf9) != 0xf0 ||
                 *                                      (nack != 0))
                 *                              {
                 *                                      // Display 7-bit address
                 *                                      Console.Write("<{0:x2}:{1:s}>{2:s} ",
                 *                                                 (data_in[0] & 0xff) >> 1,
                 *                                                 ((data_in[0] & 0x01) != 0) ? 'r' : 'w',
                 *                                                 (nack != 0) ? "*" : "");
                 *                                      offset = 1;
                 *                              }
                 *                              else
                 *                              {
                 *                                      // Display 10-bit address
                 *                                      Console.Write("<{0:x3}:{1:s}>{2:s} ", ((data_in[0] << 7) & 0x300) | (data_in[1] & 0xff), ((data_in[0] & 0x01) != 0) ? 'r' : 'w',
                 *                                                 (nack != 0) ? "*" : "");
                 *                                      offset = 2;
                 *                              }
                 *                      }
                 *              }
                 *///take out prints

                // Display rest of transaction - data
                count = count - offset;

                /*
                 *              for (int n = 0; n < count; ++n)
                 *              {
                 *                      // Determine if byte was NACKed
                 *                      int nack = (data_in[offset] & BeagleApi.BG_I2C_MONITOR_NACK);
                 *
                 *                      Console.Write("{0:x2}{1:s} ",
                 *                                      data_in[offset] & 0xff, (nack != 0) ? "*" : "");
                 ++offset;
                 *              }
                 */
            }

            // Stop the capture
            //BeagleApi.bg_disable(handle);
            return(lines);
        }