001    /*----------------------------------------------------------------------------*/
002    /* Copyright (c) FIRST 2008-2012. All Rights Reserved.                        */
003    /* Open Source Software - may be modified and shared by FRC teams. The code   */
004    /* must be accompanied by the FIRST BSD license file in the root directory of */
005    /* the project.                                                               */
006    /*----------------------------------------------------------------------------*/
007    
008    package edu.wpi.first.wpilibj;
009    
010    import com.sun.squawk.Isolate;
011    import com.sun.squawk.VM;
012    import edu.wpi.first.wpilibj.fpga.tGlobal;
013    import edu.wpi.first.wpilibj.parsing.IUtility;
014    
015    /**
016     * Contains global utility functions
017     */
018    public class Utility implements IUtility {
019    
020        /**
021         * Make sure that the FPGA is initialized properly before any of these
022         * functions are used.
023         */
024        static {
025            new tGlobal();
026        }
027    
028        private Utility() {
029        }
030    
031        /**
032         * Return the FPGA Version number.
033         * For now, expect this to be 2009.
034         * @return FPGA Version number.
035         */
036        int getFPGAVersion() {
037            return tGlobal.readVersion();
038        }
039    
040        /**
041         * Return the FPGA Revision number.
042         * The format of the revision is 3 numbers.
043         * The 12 most significant bits are the Major Revision.
044         * the next 8 bits are the Minor Revision.
045         * The 12 least significant bits are the Build Number.
046         * @return FPGA Revision number.
047         */
048        long getFPGARevision() {
049            return tGlobal.readRevision();
050        }
051    
052        /**
053         * Read the microsecond timer from the FPGA.
054         *
055         * @return The current time in microseconds according to the FPGA.
056         */
057        public static long getFPGATime() {
058            return tGlobal.readLocalTime();
059        }
060    
061        /**
062         * Control whether to send System.err output to the driver station's error pane.
063         * @param enabled if true, send error stream to driver station, otherwise disable sending error stream
064         */
065        public static void sendErrorStreamToDriverStation(boolean enabled) {
066            final String url = "dserror:edu.wpi.first.wpilibj.Utility"; // the path is just a comment.
067            Isolate isolate = VM.getCurrentIsolate();
068            if (enabled) {
069                isolate.addErr(url);
070            } else {
071                isolate.removeErr(url);
072            }
073        }
074        
075    }