Exemplo n.º 1
0
/*
 * These configuration parameters specify how to clock the
 * bits that are sent and received on the Cheetah SPI
 * interface.
 *
 * The polarity option specifies which transition
 * constitutes the leading edge and which transition is the
 * falling edge.  For example, CH_SPI_POL_RISING_FALLING
 * would configure the SPI to idle the SCK clock line low.
 * The clock would then transition low-to-high on the
 * leading edge and high-to-low on the trailing edge.
 *
 * The phase option determines whether to sample or setup on
 * the leading edge.  For example, CH_SPI_PHASE_SAMPLE_SETUP
 * would configure the SPI to sample on the leading edge and
 * setup on the trailing edge.
 *
 * The bitorder option is used to indicate whether LSB or
 * MSB is shifted first.
 *
 * The SS polarity option is to indicate the polarity of the
 * slave select pin (active high or active low).  Each of
 * the lower three bits of ss_polarity corresponds to each
 * of the SS lines.  Set the bit value for a given SS line
 * to 0 for active low or 1 for active high.
 */
// enum CheetahSpiPolarity  (from declaration above)
//     CH_SPI_POL_RISING_FALLING = 0
//     CH_SPI_POL_FALLING_RISING = 1

// enum CheetahSpiPhase  (from declaration above)
//     CH_SPI_PHASE_SAMPLE_SETUP = 0
//     CH_SPI_PHASE_SETUP_SAMPLE = 1

// enum CheetahSpiBitorder  (from declaration above)
//     CH_SPI_BITORDER_MSB = 0
//     CH_SPI_BITORDER_LSB = 1

/* Configure the SPI master interface */
        public static int ch_spi_configure(
            int cheetah,
            CheetahSpiPolarity polarity,
            CheetahSpiPhase phase,
            CheetahSpiBitorder bitorder,
            byte ss_polarity
            )
        {
            if (!CH_LIBRARY_LOADED)
            {
                return((int)CheetahStatus.CH_INCOMPATIBLE_LIBRARY);
            }
            return(net_ch_spi_configure(cheetah, polarity, phase, bitorder, ss_polarity));
        }
Exemplo n.º 2
0
    /*======================================================================
     | 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;
    }
Exemplo n.º 3
0
 private static extern int net_ch_spi_configure(int cheetah, CheetahSpiPolarity polarity, CheetahSpiPhase phase, CheetahSpiBitorder bitorder, byte ss_polarity);