Ejemplo n.º 1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Starts the PRU with the  PRU1_StepperIO binary. Very specific to the
        /// data needs of the PRU1_StepperIO binary
        ///
        /// In this function, the PASM binary to load is hard coded. It is designed
        /// to monitor incoming data from the client and control step and dir pins
        /// for up to six stepper motors.
        ///
        /// </summary>
        /// <param name="pruID">The pruID</param>
        /// <history>
        ///    19 Nov 18  Cynic - Originally written
        /// </history>
        public void StartPRUWithDefaults(PRUEnum pruID)
        {
            // this is the array we use to pass in the data to the PRU. The
            // single byte will act as a toggle flag. Because we are only
            // transmitting a byte (an atomic value) we do not need to set
            // up any complicated semaphore system.

            // The size of this array is the number of
            byte[] dataBytes = new byte[NUM_DATA_UINTS * sizeof(UInt32)];

            // sanity checks
            if (pruID == PRUEnum.PRU_NONE)
            {
                throw new Exception("No such PRU: " + pruID.ToString());
            }
            string binaryToRun = "./PRU1_StepperIO.bin";

            // build the driver
            pruDriver = new PRUDriver(pruID);

            // initialize the dataBytes array. the PRU code expects to see a
            // zero semaphore, and enable flags when it starts
            Array.Clear(dataBytes, 0, dataBytes.Length);

            // run the binary, pass in our initial array
            pruDriver.ExecutePRUProgram(binaryToRun, dataBytes);

            Console.WriteLine("PRU now running.");
            LogMessage("PRU now running.");
        }
Ejemplo n.º 2
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Configures a PRU and runs a compiled binary in it.
        /// </summary>
        /// <param name="pruID">The pruID</param>
        /// <param name="binaryToRun">The binary file to run</param>
        /// <history>
        ///    19 Nov 18  Cynic - Originally written
        /// </history>
        public void PRUBlinkUSR3LED(PRUEnum pruID, string binaryToRun)
        {
            // sanity checks
            if (pruID == PRUEnum.PRU_NONE)
            {
                throw new Exception("No such PRU: " + pruID.ToString());
            }
            if ((binaryToRun == null) || (binaryToRun.Length == 0))
            {
                throw new Exception("Null or zero length binary file name specified");
            }

            // build the driver
            PRUDriver pruDriver = new PRUDriver(pruID);

            // run the binary
            pruDriver.ExecutePRUProgram(binaryToRun);

            // close the driver, the code in the PRU remains running
            pruDriver.Dispose();
        }
Ejemplo n.º 3
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Sample code to launch various PASM binaries in a PRU.
        ///
        /// </summary>
        /// <param name="pruID">The pruID</param>
        /// <param name="binaryToRun">The binary file to run</param>
        /// <history>
        ///    19 Nov 18  Cynic - Originally written
        /// </history>
        public void PRUToggleFromConsole(PRUEnum pruID, string binaryToRun)
        {
            uint tmpInt = 0;

            // ###
            // ### these are the offsets into the data store we pass into the PRU
            // ### each data item is a uint (it is simpler that way)
            // ###

            // our semaphore flag is stored at this offset
            const uint SEMAPHORE_OFFSET = 0;
            // the all steppers enabled flag is stored at this offset
            const uint ALLSTEP_ENABLE_OFFSET = 4;

            // STEP0
            const uint STEP0_ENABLED_OFFSET = 8;     // 0 disabled, 1 enabled
            const uint STEP0_FULLCOUNT      = 12;    // this is the count we reset to when we toggle
            const uint STEP0_DIRSTATE       = 16;    // this is the state of the direction pin

            // ###
            // ### this is the END of the data items, we need to allocate space for the
            // ### above number of UINTS
            // ###
            const int NUM_DATA_UINTS = 5;


            // this is the array we use to pass in the data to the PRU. The
            // single byte will act as a toggle flag. Because we are only
            // transmitting a byte (an atomic value) we do not need to set
            // up any complicated semaphore system.

            // The size of this array is the number of
            byte[] dataBytes = new byte[NUM_DATA_UINTS * sizeof(UInt32)];

            // sanity checks
            if (pruID == PRUEnum.PRU_NONE)
            {
                throw new Exception("No such PRU: " + pruID.ToString());
            }
            if ((binaryToRun == null) || (binaryToRun.Length == 0))
            {
                throw new Exception("Null or zero length binary file name specified");
            }

            // build the driver
            PRUDriver pruDriver = new PRUDriver(pruID);

            // initialize the dataBytes array. the PRU code expects to see a
            // zero semaphore, and enable flags when it starts
            Array.Clear(dataBytes, 0, dataBytes.Length);

            // run the binary, pass in our initial array
            pruDriver.ExecutePRUProgram(binaryToRun, dataBytes);

            Console.WriteLine("Now toggling. Press 0, 1 or 2 to quit");

            // our outer loop we operate until the user quits
            while (true)
            {
                Console.WriteLine("Enter value: ");
                string inputStr = Console.ReadLine();
                try
                {
                    tmpInt = Convert.ToUInt32(inputStr);
                }
                catch (Exception)
                {
                    Console.WriteLine("The value " + inputStr + " is not an integer");
                    continue;
                }
                // write the allstep_enable flag
                pruDriver.WritePRUDataUInt32(tmpInt, ALLSTEP_ENABLE_OFFSET);

                // write the STEP0 enable/disable flag
                pruDriver.WritePRUDataUInt32(1, STEP0_ENABLED_OFFSET);
                // write the STEP0 fullcount value
                pruDriver.WritePRUDataUInt32(5000000, STEP0_FULLCOUNT);
                // write the STEP0 direction flag
                pruDriver.WritePRUDataUInt32(1, STEP0_DIRSTATE);

                // write the semaphore. This must come last
                pruDriver.WritePRUDataUInt32(1, SEMAPHORE_OFFSET);

                // wait for a bit,
                Thread.Sleep(100);

                if (tmpInt == 0)
                {
                    Console.WriteLine("Pin low");
                }
                else if (tmpInt == 1)
                {
                    Console.WriteLine("Pin high");
                }
                else
                {
                    // it is time to go
                    // tell the user
                    Console.WriteLine("Done ");
                    break;
                }
            }

            // close the driver, the code in the PRU remains running
            pruDriver.Dispose();
        }