Ejemplo n.º 1
0
    /*======================================================================
     | FUNCTIONS
     | =====================================================================*/
    static void _blast_async(int handle, int txnlen, int iter)
    {
        double elapsed = 0;

        byte[] noresult = new byte[1];

        // Make a simple queue to just assert OE.
        CheetahApi.ch_spi_queue_clear(handle);
        CheetahApi.ch_spi_queue_oe(handle, (byte)1);
        CheetahApi.ch_spi_batch_shift(handle, 0, noresult);


        // Queue the batch which is a sequence of SPI packets
        // (back-to-back) each of length 4.
        CheetahApi.ch_spi_queue_clear(handle);
        int i;
        int count = 0;

        byte[] data_out = new byte[4];
        for (i = 0; i < txnlen; ++i)
        {
            CheetahApi.ch_spi_queue_ss(handle, 0x1);

            data_out[0] = (byte)((count >> 24) & 0xff);
            data_out[1] = (byte)((count >> 16) & 0xff);
            data_out[2] = (byte)((count >> 8) & 0xff);
            data_out[3] = (byte)((count >> 0) & 0xff);

            ++count;

            CheetahApi.ch_spi_queue_array(handle, 4, data_out);
            CheetahApi.ch_spi_queue_ss(handle, 0x0);
        }

        ulong start = _timeMillis();

        // First, submit first batch
        CheetahApi.ch_spi_async_submit(handle);

        int n, ret;

        for (n = 0; n < iter - 1; ++n)
        {
            // Submit another batch, while the previous one is in
            // progress.  The application may even clear the current
            // batch queue and queue a different set of SPI
            // transactions before submitting this batch
            // asynchronously.
            CheetahApi.ch_spi_async_submit(handle);

            // The application can now perform some other functions
            // while the Cheetah is both finishing the previous batch
            // and shifting the current batch as well.  In order to
            // keep the Cheetah's pipe full, this entire loop must
            // complete AND another batch must be submitted
            // before the current batch completes.
            CheetahApi.ch_sleep_ms(25);

            // Collect the previous batch
            ret     = CheetahApi.ch_spi_async_collect(handle, 0, noresult);
            elapsed = ((double)(_timeMillis() - start)) / 1000;
            Console.Write("collected batch #{0:d3} in {1:f2} seconds\n",
                          n + 1, elapsed);
            if (ret < 0)
            {
                Console.Write("status error: {0:s}\n",
                              CheetahApi.ch_status_string(ret));
            }
            Console.Out.Flush();

            start = _timeMillis();

            // The current batch is now shifting out on the SPI
            // interface. The application can again do some more tasks
            // here but this entire loop must finish so that a new
            // batch is armed before the current batch completes.
            CheetahApi.ch_sleep_ms(25);
        }

        // Collect batch the last batch
        ret     = CheetahApi.ch_spi_async_collect(handle, 0, noresult);
        elapsed = ((double)(_timeMillis() - start)) / 1000;
        Console.Write("collected batch #{0:d3} in {1:f2} seconds\n",
                      n + 1, elapsed);
        if (ret < 0)
        {
            Console.Write("status error: {0:s}\n",
                          CheetahApi.ch_status_string(ret));
        }
        Console.Out.Flush();
    }