/*====================================================================== | MAIN PROGRAM | =====================================================================*/ public static void Main(String[] args) { int handle = 0; int port = 0; // open port 0 by default int bitrate = 0; int mode = 0; ushort arg5 = 0; ushort arg6 = 0; String command = ""; String binfilepath = ""; Byte[] data; if (args.Length < 6) { print_usage(); Environment.Exit(1); } port = Convert.ToInt32(args[0]); bitrate = Convert.ToInt32(args[1]); mode = Convert.ToInt32(args[2]); command = args[3]; arg5 = Convert.ToUInt16(args[4]); arg6 = Convert.ToUInt16(args[5]); if (args.Length > 6) { binfilepath = args[6]; } handle = CheetahApi.ch_open(port); if (handle <= 0) { Console.Error.Write( "Unable to open Cheetah device on port {0:d}\n", port); Console.Error.Write("Error code = {0:d} ({1:s})\n", handle, CheetahApi.ch_status_string(handle)); Environment.Exit(1); } Console.Write("Opened Cheetah device on port {0:d}\n", port); Console.Write("Host interface is {0:s}\n", ((CheetahApi.ch_host_ifce_speed(handle)) != 0) ? "high speed" : "full speed"); // Ensure that the SPI subsystem is configured. CheetahApi.ch_spi_configure( handle, (TotalPhase.CheetahSpiPolarity)(mode >> 1), (TotalPhase.CheetahSpiPhase)(mode & 1), CheetahSpiBitorder.CH_SPI_BITORDER_MSB, 0x0); Console.Write("SPI configuration set to mode {0:d}, {1:s} shift, " + "SS[2:0] active low\n", mode, "MSB"); Console.Out.Flush(); // Power off the target using the Cheetah adapter's power supply. CheetahApi.ch_target_power(handle, CheetahApi.CH_TARGET_POWER_OFF); CheetahApi.ch_sleep_ms(100); // Power the target using the Cheetah adapter's power supply. CheetahApi.ch_target_power(handle, CheetahApi.CH_TARGET_POWER_ON); CheetahApi.ch_sleep_ms(100); // Set the bitrate. bitrate = CheetahApi.ch_spi_bitrate(handle, bitrate); Console.Write("Bitrate set to {0:d} kHz\n", bitrate); Console.Out.Flush(); // Determine which command transaction type was requested. int commandID = -1; if (command == "read") { commandID = COMMAND_READ; } else if (command == "write") { commandID = COMMAND_WRITE; } else if (command == "erase") { commandID = COMMAND_ERASE; } else if (command == "verify") { commandID = COMMAND_VERIFY; } else { Console.Write("Unknown option: {0:s}\n", command); Console.Write("Valid options are: read, write, erase, " + "and verify\n\n"); print_usage(); Environment.Exit(1); } // Execute the appropriate command. switch (commandID) { case COMMAND_READ: _read(handle, arg5, arg6, out data); break; case COMMAND_WRITE: _write(handle, arg5, binfilepath); break; case COMMAND_ERASE: _erase(handle, arg5, arg6); break; case COMMAND_VERIFY: _verify(handle, arg5 * 1024, arg6 * 1024); break; } // Power off the target using the Cheetah adapter's power supply. CheetahApi.ch_target_power(handle, CheetahApi.CH_TARGET_POWER_OFF); // Close the device. CheetahApi.ch_close(handle); return; }
/*====================================================================== | MAIN PROGRAM | =====================================================================*/ public static void Main(String[] args) { int handle = 0; int port = 0; // open port 0 by default int bitrate = 0; int mode = 0; int bitorder = 0; int length = 0; if (args.Length < 5) { print_usage(); Environment.Exit(1); } port = Convert.ToInt32(args[0]); bitrate = Convert.ToInt32(args[1]); mode = Convert.ToInt32(args[2]); bitorder = Convert.ToInt32(args[3]); length = Convert.ToInt32(args[4]); handle = CheetahApi.ch_open(port); if (handle <= 0) { Console.Error.Write( "Unable to open Cheetah device on port {0:d}\n", port); Console.Error.Write("Error code = {0:d} ({1:s})\n", handle, CheetahApi.ch_status_string(handle)); Environment.Exit(1); } Console.Write("Opened Cheetah device on port {0:d}\n", port); Console.Write("Host interface is {0:s}\n", ((CheetahApi.ch_host_ifce_speed(handle)) != 0) ? "high speed" : "full speed"); // Ensure that the SPI subsystem is configured. // Make sure that the bitorder parameter is valid, defaulting to LSB CheetahSpiBitorder spi_bitorder = (bitorder == (int)CheetahSpiBitorder.CH_SPI_BITORDER_MSB) ? CheetahSpiBitorder.CH_SPI_BITORDER_MSB : CheetahSpiBitorder.CH_SPI_BITORDER_LSB; CheetahApi.ch_spi_configure( handle, (CheetahSpiPolarity)(mode >> 1), (CheetahSpiPhase)(mode & 1), spi_bitorder, 0x0); Console.Write( "SPI configuration set to mode {0:d}, {1:s} shift, " + "SS[2:0] active low\n", mode, (spi_bitorder == CheetahSpiBitorder.CH_SPI_BITORDER_MSB) ? "MSB" : "LSB"); Console.Out.Flush(); // Power the target using the Cheetah adapter's power supply. CheetahApi.ch_target_power(handle, CheetahApi.CH_TARGET_POWER_ON); CheetahApi.ch_sleep_ms(100); // Set the bitrate. bitrate = CheetahApi.ch_spi_bitrate(handle, bitrate); Console.Write("Bitrate set to {0:d} kHz\n", bitrate); Console.Out.Flush(); _blast(handle, length); // Close and exit. CheetahApi.ch_close(handle); return; }
/*========================================================================= | MAIN PROGRAM | ========================================================================*/ public static void Main(String[] args) { int handle = 0; int port = 0; // open port 0 by default int bitrate = 0; int mode = 0; ushort addr = 0; ushort length = 0; String command = ""; if (args.Length < 6) { print_usage(); Environment.Exit(1); } port = Convert.ToInt32(args[0]); bitrate = Convert.ToInt32(args[1]); mode = Convert.ToInt32(args[2]); command = args[3]; addr = Convert.ToUInt16(args[4]); length = Convert.ToUInt16(args[5]); // Open the device handle = CheetahApi.ch_open(port); if (handle <= 0) { Console.Error.Write( "Unable to open Cheetah device on port {0:d}\n", port); Console.Error.Write("Error code = {0:d} ({1:s})\n", handle, CheetahApi.ch_status_string(handle)); Environment.Exit(1); } Console.Write("Opened Cheetah device on port {0:d}\n", port); Console.Write("Host interface is {0:s}\n", ((CheetahApi.ch_host_ifce_speed(handle)) != 0) ? "high speed" : "full speed"); // Ensure that the SPI subsystem is configured CheetahApi.ch_spi_configure( handle, (TotalPhase.CheetahSpiPolarity)(mode >> 1), (TotalPhase.CheetahSpiPhase)(mode & 1), CheetahSpiBitorder.CH_SPI_BITORDER_MSB, 0x0); Console.Write("SPI configuration set to mode {0:d}, {1:s} shift, " + "SS[2:0] active low\n", mode, "MSB"); Console.Out.Flush(); // Power the target using the Cheetah adapter's power supply CheetahApi.ch_target_power(handle, CheetahApi.CH_TARGET_POWER_ON); CheetahApi.ch_sleep_ms(100); // Set the bitrate bitrate = CheetahApi.ch_spi_bitrate(handle, bitrate); Console.Write("Bitrate set to {0:d} kHz\n", bitrate); Console.Out.Flush(); byte[] noresult = new byte[1]; // Shift a dummy byte to clear the EEPROM state CheetahApi.ch_spi_queue_clear(handle); CheetahApi.ch_spi_queue_oe(handle, 1); CheetahApi.ch_spi_queue_ss(handle, 0x1); CheetahApi.ch_spi_queue_byte(handle, 1, 0x00); CheetahApi.ch_spi_queue_ss(handle, 0); CheetahApi.ch_spi_batch_shift(handle, 0, noresult); // Perform the requested operation if (command == "write") { _writeMemory(handle, addr, length, 0); Console.Write("Wrote to EEPROM\n"); } else if (command == "read") { _readMemory(handle, addr, length); } else if (command == "zero") { _writeMemory(handle, addr, length, 1); Console.Write("Zeroed EEPROM\n"); } else { Console.Write("unknown command: {0:s}\n", command); } // Close and exit CheetahApi.ch_close(handle); return; }