├── .gitattributes ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── Cargo.toml ├── LICENSE ├── README.md ├── athena ├── include │ ├── FRC_FPGA_ChipObject │ │ ├── RoboRIO_FRC_ChipObject_Aliases.h │ │ ├── fpgainterfacecapi │ │ │ └── NiFpga.h │ │ ├── nRoboRIO_FPGANamespace │ │ │ ├── nInterfaceGlobals.h │ │ │ ├── tAI.h │ │ │ ├── tAO.h │ │ │ ├── tAccel.h │ │ │ ├── tAccumulator.h │ │ │ ├── tAlarm.h │ │ │ ├── tAnalogTrigger.h │ │ │ ├── tBIST.h │ │ │ ├── tCounter.h │ │ │ ├── tDIO.h │ │ │ ├── tDMA.h │ │ │ ├── tEncoder.h │ │ │ ├── tGlobal.h │ │ │ ├── tInterrupt.h │ │ │ ├── tPWM.h │ │ │ ├── tPower.h │ │ │ ├── tRelay.h │ │ │ ├── tSPI.h │ │ │ └── tSysWatchdog.h │ │ ├── printFpgaVersion.h │ │ ├── tDMAChannelDescriptor.h │ │ ├── tDMAManager.h │ │ ├── tInterruptManager.h │ │ ├── tSystem.h │ │ └── tSystemInterface.h │ ├── FRC_NetworkCommunication │ │ ├── AICalibration.h │ │ ├── CANInterfacePlugin.h │ │ ├── CANSessionMux.h │ │ ├── FRCComm.h │ │ ├── LoadOut.h │ │ └── UsageReporting.h │ ├── HAL │ │ ├── Accelerometer.h │ │ ├── AnalogAccumulator.h │ │ ├── AnalogGyro.h │ │ ├── AnalogInput.h │ │ ├── AnalogOutput.h │ │ ├── AnalogTrigger.h │ │ ├── CAN.h │ │ ├── ChipObject.h │ │ ├── Compressor.h │ │ ├── Constants.h │ │ ├── Counter.h │ │ ├── DIO.h │ │ ├── DriverStation.h │ │ ├── Encoder.h │ │ ├── Errors.h │ │ ├── HAL.h │ │ ├── I2C.h │ │ ├── Interrupts.h │ │ ├── LabVIEW │ │ │ └── HAL.h │ │ ├── Notifier.h │ │ ├── OSSerialPort.h │ │ ├── PDP.h │ │ ├── PWM.h │ │ ├── Ports.h │ │ ├── Power.h │ │ ├── Relay.h │ │ ├── SPI.h │ │ ├── SerialPort.h │ │ ├── Solenoid.h │ │ ├── Threads.h │ │ ├── Types.h │ │ ├── cpp │ │ │ ├── Log.h │ │ │ ├── Semaphore.h │ │ │ ├── SerialHelper.h │ │ │ ├── make_unique.h │ │ │ ├── priority_condition_variable.h │ │ │ └── priority_mutex.h │ │ └── handles │ │ │ ├── DigitalHandleResource.h │ │ │ ├── HandlesInternal.h │ │ │ ├── IndexedClassedHandleResource.h │ │ │ ├── IndexedHandleResource.h │ │ │ ├── LimitedClassedHandleResource.h │ │ │ ├── LimitedHandleResource.h │ │ │ └── UnlimitedHandleResource.h │ ├── ctre │ │ ├── CtreCanNode.h │ │ ├── PCM.h │ │ ├── PDP.h │ │ ├── ctre.h │ │ └── ctre_frames.h │ ├── edu_wpi_first_wpilibj_networktables_NetworkTablesJNI.h │ ├── edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_ConnectionListenerFunction.h │ ├── edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_EntryListenerFunction.h │ ├── edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_LoggerFunction.h │ ├── i2clib │ │ └── i2c-lib.h │ ├── llvm │ │ ├── AlignOf.h │ │ ├── ArrayRef.h │ │ ├── Compiler.h │ │ ├── ConvertUTF.h │ │ ├── DenseMap.h │ │ ├── DenseMapInfo.h │ │ ├── EpochTracker.h │ │ ├── Format.h │ │ ├── Hashing.h │ │ ├── MathExtras.h │ │ ├── None.h │ │ ├── Optional.h │ │ ├── PointerLikeTypeTraits.h │ │ ├── STLExtras.h │ │ ├── SmallPtrSet.h │ │ ├── SmallSet.h │ │ ├── SmallString.h │ │ ├── SmallVector.h │ │ ├── StringExtras.h │ │ ├── StringMap.h │ │ ├── StringRef.h │ │ ├── WindowsError.h │ │ ├── iterator_range.h │ │ ├── raw_os_ostream.h │ │ ├── raw_ostream.h │ │ └── type_traits.h │ ├── networktables │ │ └── NetworkTable.h │ ├── nt_Value.h │ ├── ntcore.h │ ├── ntcore_c.h │ ├── ntcore_cpp.h │ ├── ntcore_test.h │ ├── spilib │ │ └── spi-lib.h │ ├── support │ │ ├── Base64.h │ │ ├── ConcurrentQueue.h │ │ ├── Logger.h │ │ ├── SafeThread.h │ │ ├── atomic_static.h │ │ ├── deprecated.h │ │ ├── jni_util.h │ │ ├── leb128.h │ │ ├── raw_istream.h │ │ ├── raw_socket_istream.h │ │ ├── raw_socket_ostream.h │ │ └── timestamp.h │ ├── tables │ │ ├── ITable.h │ │ ├── ITableListener.h │ │ └── TableKeyNotDefinedException.h │ └── tcpsockets │ │ ├── NetworkAcceptor.h │ │ ├── NetworkStream.h │ │ ├── SocketError.h │ │ ├── TCPAcceptor.h │ │ ├── TCPConnector.h │ │ └── TCPStream.h ├── lib │ ├── libHALAthena.so │ ├── libHALAthena.so.debug │ ├── libntcore.so │ ├── libntcore.so.debug │ ├── libwpiutil.so │ └── libwpiutil.so.debug └── wpilibhal.rs ├── build.rs ├── examples └── test_robot.rs ├── ni-libraries ├── libFRC_NetworkCommunication.so ├── libNiFpga.so ├── libNiFpgaLv.so ├── libNiRioSrv.so ├── libRoboRIO_FRC_ChipObject.so ├── libi2c.so ├── libniriodevenum.so ├── libniriosession.so ├── libspi.so └── libvisa.so └── src ├── lib.rs └── wpilib ├── analog_input.rs ├── digital_input.rs ├── digital_output.rs ├── driverstation.rs ├── encoder.rs ├── fpga.rs ├── hal_call.rs ├── i2c.rs ├── interrupt.rs ├── joystick.rs ├── mod.rs ├── pdp.rs ├── pwm.rs ├── pwm_speed_controller.rs ├── robot.rs ├── robot_state.rs ├── sensor.rs ├── speed_controller.rs ├── spi.rs ├── throttler.rs ├── timer.rs ├── usage.rs └── wpilib_hal.rs /.gitattributes: -------------------------------------------------------------------------------- 1 | athena/* linguist-vendored 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | 3 | sudo: required 4 | dist: trusty 5 | 6 | before_install: 7 | - curl https://sh.rustup.rs -sSf > rustup.sh 8 | - chmod +x rustup.sh 9 | - ./rustup.sh -y 10 | 11 | addons: 12 | apt: 13 | sources: 14 | - sourceline: 'ppa:wpilib/toolchain' 15 | packages: 16 | - frc-toolchain 17 | 18 | install: 19 | - source ~/.cargo/env 20 | - rustup target add arm-unknown-linux-gnueabi 21 | - echo "[target.arm-unknown-linux-gnueabi]" >> ~/.cargo/config 22 | - echo 'linker = "arm-frc-linux-gnueabi-gcc"' >> ~/.cargo/config 23 | 24 | rust: 25 | - stable 26 | - beta 27 | - nightly 28 | matrix: 29 | allow_failures: 30 | - rust: nightly 31 | 32 | script: 33 | - cargo build --verbose --target=arm-unknown-linux-gnueabi 34 | - cargo build --verbose --example test_robot --target=arm-unknown-linux-gnueabi 35 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wpilib" 3 | version = "0.0.1" 4 | authors = ["Kyle Stachowicz "] 5 | build = "build.rs" 6 | 7 | [dependencies] 8 | atom="*" 9 | 10 | [lib] 11 | name = "wpilib" 12 | path = "src/lib.rs" 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Rust for Robotics Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rust WPILib [![Build Status](https://travis-ci.org/robotrs/rust-wpilib.svg?branch=master)](https://travis-ci.org/robotrs/rust-wpilib) 2 | 3 | rust-wpilib is an equivalent to [WPILib](https://www.github.com/wpilibsuite/allwpilib), rewritten in Rust. The goal of 4 | this project is to create a lightweight alternative to WPILib for FIRST Robotics Competition teams who would prefer to 5 | use the language for its safety guarantees. 6 | 7 | ## Getting started 8 | This repository is designed to be compiled for a [RoboRIO](http://sine.ni.com/nips/cds/view/p/lang/en/nid/213308), the 9 | processor used in the FIRST Robotics Competition. To cross compile for RoboRIO, you have to do a few things: 10 | 1. Install [Rustup](https://www.rustup.rs/) to help manage Rust toolchains. 11 | 2. Run `rustup target add arm-unknown-linux-gnueabi` to install the Rust stdlib for ARM-based Linux. 12 | 3. Install some variant of `arm-linux-gnueabi-gcc`. For example, the official FRC toolchain 13 | (`arm-frc-linux-gnueabi-gcc`) is available [here](https://launchpad.net/~wpilib/+archive/ubuntu/toolchain), or you 14 | can install a generic toolchain with your package manager of choice (`sudo apt-get install gcc-arm-linux-gnueabi` on 15 | Ubuntu). 16 | 4. Edit your `~/.cargo/config` file with the following information: 17 | 18 | ```toml 19 | [target.arm-unknown-linux-gnueabi] 20 | linker = "" 21 | ``` 22 | 23 | ## Using this library as a dependency: 24 | This library is not currently published on [crates.io](https://crates.io). However, you can directly declare it as a 25 | dependency: 26 | 27 | Cargo.toml: 28 | ```toml 29 | [dependencies] 30 | wpilib = { git = "https://github.com/robotrs/rust-wpilib" } 31 | ``` 32 | 33 | ## Building 34 | You can build your own project for the RoboRIO by passing `--target=arm-unknown-linux-gnueabi` when building. 35 | 36 | To build this library on its own, just run `cargo build --target=arm-unknown-linux-gnueabi`. To make sure that 37 | everything links properly, you may also want to run `cargo build --example test_robot 38 | --target=arm-unknown-linux-gnueabi`. 39 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/RoboRIO_FRC_ChipObject_Aliases.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __RoboRIO_FRC_ChipObject_Aliases_h__ 5 | #define __RoboRIO_FRC_ChipObject_Aliases_h__ 6 | 7 | #define nRoboRIO_FPGANamespace nFRC_2017_17_0_2 8 | 9 | #endif // __RoboRIO_FRC_ChipObject_Aliases_h__ 10 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/nInterfaceGlobals.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_nInterfaceGlobals_h__ 5 | #define __nFRC_2017_17_0_2_nInterfaceGlobals_h__ 6 | 7 | namespace nFPGA 8 | { 9 | namespace nFRC_2017_17_0_2 10 | { 11 | extern unsigned int g_currentTargetClass; 12 | } 13 | } 14 | 15 | #endif // __nFRC_2017_17_0_2_nInterfaceGlobals_h__ 16 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAO.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_AO_h__ 5 | #define __nFRC_2017_17_0_2_AO_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tAO 16 | { 17 | public: 18 | tAO(){} 19 | virtual ~tAO(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tAO* create(tRioStatusCode *status); 23 | 24 | typedef enum 25 | { 26 | kNumSystems = 1, 27 | } tIfaceConstants; 28 | 29 | 30 | 31 | 32 | 33 | 34 | typedef enum 35 | { 36 | kNumMXPRegisters = 2, 37 | } tMXP_IfaceConstants; 38 | 39 | virtual void writeMXP(unsigned char reg_index, unsigned short value, tRioStatusCode *status) = 0; 40 | virtual unsigned short readMXP(unsigned char reg_index, tRioStatusCode *status) = 0; 41 | 42 | 43 | private: 44 | tAO(const tAO&); 45 | void operator=(const tAO&); 46 | }; 47 | 48 | } 49 | } 50 | 51 | #endif // __nFRC_2017_17_0_2_AO_h__ 52 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAccel.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_Accel_h__ 5 | #define __nFRC_2017_17_0_2_Accel_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tAccel 16 | { 17 | public: 18 | tAccel(){} 19 | virtual ~tAccel(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tAccel* create(tRioStatusCode *status); 23 | 24 | typedef enum 25 | { 26 | kNumSystems = 1, 27 | } tIfaceConstants; 28 | 29 | 30 | 31 | 32 | typedef enum 33 | { 34 | } tSTAT_IfaceConstants; 35 | 36 | virtual unsigned char readSTAT(tRioStatusCode *status) = 0; 37 | 38 | 39 | typedef enum 40 | { 41 | } tCNTR_IfaceConstants; 42 | 43 | virtual void writeCNTR(unsigned char value, tRioStatusCode *status) = 0; 44 | virtual unsigned char readCNTR(tRioStatusCode *status) = 0; 45 | 46 | 47 | typedef enum 48 | { 49 | } tDATO_IfaceConstants; 50 | 51 | virtual void writeDATO(unsigned char value, tRioStatusCode *status) = 0; 52 | virtual unsigned char readDATO(tRioStatusCode *status) = 0; 53 | 54 | 55 | typedef enum 56 | { 57 | } tCNFG_IfaceConstants; 58 | 59 | virtual void writeCNFG(unsigned char value, tRioStatusCode *status) = 0; 60 | virtual unsigned char readCNFG(tRioStatusCode *status) = 0; 61 | 62 | 63 | typedef enum 64 | { 65 | } tCNTL_IfaceConstants; 66 | 67 | virtual void writeCNTL(unsigned char value, tRioStatusCode *status) = 0; 68 | virtual unsigned char readCNTL(tRioStatusCode *status) = 0; 69 | 70 | 71 | typedef enum 72 | { 73 | } tDATI_IfaceConstants; 74 | 75 | virtual unsigned char readDATI(tRioStatusCode *status) = 0; 76 | 77 | 78 | typedef enum 79 | { 80 | } tGO_IfaceConstants; 81 | 82 | virtual void strobeGO(tRioStatusCode *status) = 0; 83 | 84 | 85 | typedef enum 86 | { 87 | } tADDR_IfaceConstants; 88 | 89 | virtual void writeADDR(unsigned char value, tRioStatusCode *status) = 0; 90 | virtual unsigned char readADDR(tRioStatusCode *status) = 0; 91 | 92 | 93 | 94 | 95 | private: 96 | tAccel(const tAccel&); 97 | void operator=(const tAccel&); 98 | }; 99 | 100 | } 101 | } 102 | 103 | #endif // __nFRC_2017_17_0_2_Accel_h__ 104 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAccumulator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_Accumulator_h__ 5 | #define __nFRC_2017_17_0_2_Accumulator_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tAccumulator 16 | { 17 | public: 18 | tAccumulator(){} 19 | virtual ~tAccumulator(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tAccumulator* create(unsigned char sys_index, tRioStatusCode *status); 23 | virtual unsigned char getSystemIndex() = 0; 24 | 25 | 26 | typedef enum 27 | { 28 | kNumSystems = 2, 29 | } tIfaceConstants; 30 | 31 | typedef 32 | union{ 33 | struct{ 34 | signed long long Value; 35 | unsigned Count : 32; 36 | }; 37 | struct{ 38 | unsigned value : 32; 39 | unsigned value2 : 32; 40 | unsigned value3 : 32; 41 | }; 42 | } tOutput; 43 | 44 | 45 | typedef enum 46 | { 47 | } tOutput_IfaceConstants; 48 | 49 | virtual tOutput readOutput(tRioStatusCode *status) = 0; 50 | virtual signed long long readOutput_Value(tRioStatusCode *status) = 0; 51 | virtual unsigned int readOutput_Count(tRioStatusCode *status) = 0; 52 | 53 | 54 | typedef enum 55 | { 56 | } tCenter_IfaceConstants; 57 | 58 | virtual void writeCenter(signed int value, tRioStatusCode *status) = 0; 59 | virtual signed int readCenter(tRioStatusCode *status) = 0; 60 | 61 | 62 | typedef enum 63 | { 64 | } tDeadband_IfaceConstants; 65 | 66 | virtual void writeDeadband(signed int value, tRioStatusCode *status) = 0; 67 | virtual signed int readDeadband(tRioStatusCode *status) = 0; 68 | 69 | 70 | typedef enum 71 | { 72 | } tReset_IfaceConstants; 73 | 74 | virtual void strobeReset(tRioStatusCode *status) = 0; 75 | 76 | 77 | 78 | 79 | 80 | private: 81 | tAccumulator(const tAccumulator&); 82 | void operator=(const tAccumulator&); 83 | }; 84 | 85 | } 86 | } 87 | 88 | #endif // __nFRC_2017_17_0_2_Accumulator_h__ 89 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAlarm.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_Alarm_h__ 5 | #define __nFRC_2017_17_0_2_Alarm_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tAlarm 16 | { 17 | public: 18 | tAlarm(){} 19 | virtual ~tAlarm(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tAlarm* create(tRioStatusCode *status); 23 | 24 | typedef enum 25 | { 26 | kNumSystems = 1, 27 | } tIfaceConstants; 28 | 29 | 30 | 31 | 32 | typedef enum 33 | { 34 | } tEnable_IfaceConstants; 35 | 36 | virtual void writeEnable(bool value, tRioStatusCode *status) = 0; 37 | virtual bool readEnable(tRioStatusCode *status) = 0; 38 | 39 | 40 | typedef enum 41 | { 42 | } tTriggerTime_IfaceConstants; 43 | 44 | virtual void writeTriggerTime(unsigned int value, tRioStatusCode *status) = 0; 45 | virtual unsigned int readTriggerTime(tRioStatusCode *status) = 0; 46 | 47 | 48 | 49 | 50 | private: 51 | tAlarm(const tAlarm&); 52 | void operator=(const tAlarm&); 53 | }; 54 | 55 | } 56 | } 57 | 58 | #endif // __nFRC_2017_17_0_2_Alarm_h__ 59 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tBIST.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_BIST_h__ 5 | #define __nFRC_2017_17_0_2_BIST_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tBIST 16 | { 17 | public: 18 | tBIST(){} 19 | virtual ~tBIST(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tBIST* create(tRioStatusCode *status); 23 | 24 | typedef enum 25 | { 26 | kNumSystems = 1, 27 | } tIfaceConstants; 28 | 29 | 30 | 31 | 32 | typedef enum 33 | { 34 | } tDO0SquareTicks_IfaceConstants; 35 | 36 | virtual void writeDO0SquareTicks(unsigned int value, tRioStatusCode *status) = 0; 37 | virtual unsigned int readDO0SquareTicks(tRioStatusCode *status) = 0; 38 | 39 | 40 | typedef enum 41 | { 42 | } tEnable_IfaceConstants; 43 | 44 | virtual void writeEnable(bool value, tRioStatusCode *status) = 0; 45 | virtual bool readEnable(tRioStatusCode *status) = 0; 46 | 47 | 48 | typedef enum 49 | { 50 | } tDO1SquareEnable_IfaceConstants; 51 | 52 | virtual void writeDO1SquareEnable(bool value, tRioStatusCode *status) = 0; 53 | virtual bool readDO1SquareEnable(tRioStatusCode *status) = 0; 54 | 55 | 56 | typedef enum 57 | { 58 | } tDO0SquareEnable_IfaceConstants; 59 | 60 | virtual void writeDO0SquareEnable(bool value, tRioStatusCode *status) = 0; 61 | virtual bool readDO0SquareEnable(tRioStatusCode *status) = 0; 62 | 63 | 64 | typedef enum 65 | { 66 | } tDO1SquareTicks_IfaceConstants; 67 | 68 | virtual void writeDO1SquareTicks(unsigned int value, tRioStatusCode *status) = 0; 69 | virtual unsigned int readDO1SquareTicks(tRioStatusCode *status) = 0; 70 | 71 | 72 | 73 | 74 | typedef enum 75 | { 76 | kNumDORegisters = 2, 77 | } tDO_IfaceConstants; 78 | 79 | virtual void writeDO(unsigned char reg_index, bool value, tRioStatusCode *status) = 0; 80 | virtual bool readDO(unsigned char reg_index, tRioStatusCode *status) = 0; 81 | 82 | 83 | private: 84 | tBIST(const tBIST&); 85 | void operator=(const tBIST&); 86 | }; 87 | 88 | } 89 | } 90 | 91 | #endif // __nFRC_2017_17_0_2_BIST_h__ 92 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tGlobal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_Global_h__ 5 | #define __nFRC_2017_17_0_2_Global_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tGlobal 16 | { 17 | public: 18 | tGlobal(){} 19 | virtual ~tGlobal(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tGlobal* create(tRioStatusCode *status); 23 | 24 | typedef enum 25 | { 26 | kNumSystems = 1, 27 | } tIfaceConstants; 28 | 29 | typedef 30 | union{ 31 | struct{ 32 | #ifdef __vxworks 33 | unsigned Comm : 8; 34 | unsigned Mode : 8; 35 | unsigned RSL : 1; 36 | #else 37 | unsigned RSL : 1; 38 | unsigned Mode : 8; 39 | unsigned Comm : 8; 40 | #endif 41 | }; 42 | struct{ 43 | unsigned value : 17; 44 | }; 45 | } tLEDs; 46 | 47 | 48 | 49 | typedef enum 50 | { 51 | } tLEDs_IfaceConstants; 52 | 53 | virtual void writeLEDs(tLEDs value, tRioStatusCode *status) = 0; 54 | virtual void writeLEDs_Comm(unsigned char value, tRioStatusCode *status) = 0; 55 | virtual void writeLEDs_Mode(unsigned char value, tRioStatusCode *status) = 0; 56 | virtual void writeLEDs_RSL(bool value, tRioStatusCode *status) = 0; 57 | virtual tLEDs readLEDs(tRioStatusCode *status) = 0; 58 | virtual unsigned char readLEDs_Comm(tRioStatusCode *status) = 0; 59 | virtual unsigned char readLEDs_Mode(tRioStatusCode *status) = 0; 60 | virtual bool readLEDs_RSL(tRioStatusCode *status) = 0; 61 | 62 | 63 | typedef enum 64 | { 65 | } tVersion_IfaceConstants; 66 | 67 | virtual unsigned short readVersion(tRioStatusCode *status) = 0; 68 | 69 | 70 | typedef enum 71 | { 72 | } tLocalTime_IfaceConstants; 73 | 74 | virtual unsigned int readLocalTime(tRioStatusCode *status) = 0; 75 | 76 | 77 | typedef enum 78 | { 79 | } tUserButton_IfaceConstants; 80 | 81 | virtual bool readUserButton(tRioStatusCode *status) = 0; 82 | 83 | 84 | typedef enum 85 | { 86 | } tRevision_IfaceConstants; 87 | 88 | virtual unsigned int readRevision(tRioStatusCode *status) = 0; 89 | 90 | 91 | 92 | 93 | private: 94 | tGlobal(const tGlobal&); 95 | void operator=(const tGlobal&); 96 | }; 97 | 98 | } 99 | } 100 | 101 | #endif // __nFRC_2017_17_0_2_Global_h__ 102 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tInterrupt.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_Interrupt_h__ 5 | #define __nFRC_2017_17_0_2_Interrupt_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tInterrupt 16 | { 17 | public: 18 | tInterrupt(){} 19 | virtual ~tInterrupt(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tInterrupt* create(unsigned char sys_index, tRioStatusCode *status); 23 | virtual unsigned char getSystemIndex() = 0; 24 | 25 | 26 | typedef enum 27 | { 28 | kNumSystems = 8, 29 | } tIfaceConstants; 30 | 31 | typedef 32 | union{ 33 | struct{ 34 | #ifdef __vxworks 35 | unsigned Source_Channel : 4; 36 | unsigned Source_Module : 1; 37 | unsigned Source_AnalogTrigger : 1; 38 | unsigned RisingEdge : 1; 39 | unsigned FallingEdge : 1; 40 | unsigned WaitForAck : 1; 41 | #else 42 | unsigned WaitForAck : 1; 43 | unsigned FallingEdge : 1; 44 | unsigned RisingEdge : 1; 45 | unsigned Source_AnalogTrigger : 1; 46 | unsigned Source_Module : 1; 47 | unsigned Source_Channel : 4; 48 | #endif 49 | }; 50 | struct{ 51 | unsigned value : 9; 52 | }; 53 | } tConfig; 54 | 55 | 56 | typedef enum 57 | { 58 | } tFallingTimeStamp_IfaceConstants; 59 | 60 | virtual unsigned int readFallingTimeStamp(tRioStatusCode *status) = 0; 61 | 62 | 63 | typedef enum 64 | { 65 | } tConfig_IfaceConstants; 66 | 67 | virtual void writeConfig(tConfig value, tRioStatusCode *status) = 0; 68 | virtual void writeConfig_Source_Channel(unsigned char value, tRioStatusCode *status) = 0; 69 | virtual void writeConfig_Source_Module(unsigned char value, tRioStatusCode *status) = 0; 70 | virtual void writeConfig_Source_AnalogTrigger(bool value, tRioStatusCode *status) = 0; 71 | virtual void writeConfig_RisingEdge(bool value, tRioStatusCode *status) = 0; 72 | virtual void writeConfig_FallingEdge(bool value, tRioStatusCode *status) = 0; 73 | virtual void writeConfig_WaitForAck(bool value, tRioStatusCode *status) = 0; 74 | virtual tConfig readConfig(tRioStatusCode *status) = 0; 75 | virtual unsigned char readConfig_Source_Channel(tRioStatusCode *status) = 0; 76 | virtual unsigned char readConfig_Source_Module(tRioStatusCode *status) = 0; 77 | virtual bool readConfig_Source_AnalogTrigger(tRioStatusCode *status) = 0; 78 | virtual bool readConfig_RisingEdge(tRioStatusCode *status) = 0; 79 | virtual bool readConfig_FallingEdge(tRioStatusCode *status) = 0; 80 | virtual bool readConfig_WaitForAck(tRioStatusCode *status) = 0; 81 | 82 | 83 | typedef enum 84 | { 85 | } tRisingTimeStamp_IfaceConstants; 86 | 87 | virtual unsigned int readRisingTimeStamp(tRioStatusCode *status) = 0; 88 | 89 | 90 | 91 | 92 | 93 | private: 94 | tInterrupt(const tInterrupt&); 95 | void operator=(const tInterrupt&); 96 | }; 97 | 98 | } 99 | } 100 | 101 | #endif // __nFRC_2017_17_0_2_Interrupt_h__ 102 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tPWM.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_PWM_h__ 5 | #define __nFRC_2017_17_0_2_PWM_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tPWM 16 | { 17 | public: 18 | tPWM(){} 19 | virtual ~tPWM(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tPWM* create(tRioStatusCode *status); 23 | 24 | typedef enum 25 | { 26 | kNumSystems = 1, 27 | } tIfaceConstants; 28 | 29 | typedef 30 | union{ 31 | struct{ 32 | #ifdef __vxworks 33 | unsigned Period : 16; 34 | unsigned MinHigh : 16; 35 | #else 36 | unsigned MinHigh : 16; 37 | unsigned Period : 16; 38 | #endif 39 | }; 40 | struct{ 41 | unsigned value : 32; 42 | }; 43 | } tConfig; 44 | 45 | 46 | 47 | typedef enum 48 | { 49 | } tConfig_IfaceConstants; 50 | 51 | virtual void writeConfig(tConfig value, tRioStatusCode *status) = 0; 52 | virtual void writeConfig_Period(unsigned short value, tRioStatusCode *status) = 0; 53 | virtual void writeConfig_MinHigh(unsigned short value, tRioStatusCode *status) = 0; 54 | virtual tConfig readConfig(tRioStatusCode *status) = 0; 55 | virtual unsigned short readConfig_Period(tRioStatusCode *status) = 0; 56 | virtual unsigned short readConfig_MinHigh(tRioStatusCode *status) = 0; 57 | 58 | 59 | typedef enum 60 | { 61 | } tLoopTiming_IfaceConstants; 62 | 63 | virtual unsigned short readLoopTiming(tRioStatusCode *status) = 0; 64 | 65 | 66 | typedef enum 67 | { 68 | kNumPeriodScaleMXPElements = 10, 69 | } tPeriodScaleMXP_IfaceConstants; 70 | 71 | virtual void writePeriodScaleMXP(unsigned char bitfield_index, unsigned char value, tRioStatusCode *status) = 0; 72 | virtual unsigned char readPeriodScaleMXP(unsigned char bitfield_index, tRioStatusCode *status) = 0; 73 | 74 | 75 | typedef enum 76 | { 77 | kNumPeriodScaleHdrElements = 10, 78 | } tPeriodScaleHdr_IfaceConstants; 79 | 80 | virtual void writePeriodScaleHdr(unsigned char bitfield_index, unsigned char value, tRioStatusCode *status) = 0; 81 | virtual unsigned char readPeriodScaleHdr(unsigned char bitfield_index, tRioStatusCode *status) = 0; 82 | 83 | 84 | typedef enum 85 | { 86 | kNumZeroLatchElements = 20, 87 | } tZeroLatch_IfaceConstants; 88 | 89 | virtual void writeZeroLatch(unsigned char bitfield_index, bool value, tRioStatusCode *status) = 0; 90 | virtual bool readZeroLatch(unsigned char bitfield_index, tRioStatusCode *status) = 0; 91 | 92 | 93 | 94 | 95 | typedef enum 96 | { 97 | kNumHdrRegisters = 10, 98 | } tHdr_IfaceConstants; 99 | 100 | virtual void writeHdr(unsigned char reg_index, unsigned short value, tRioStatusCode *status) = 0; 101 | virtual unsigned short readHdr(unsigned char reg_index, tRioStatusCode *status) = 0; 102 | 103 | 104 | typedef enum 105 | { 106 | kNumMXPRegisters = 10, 107 | } tMXP_IfaceConstants; 108 | 109 | virtual void writeMXP(unsigned char reg_index, unsigned short value, tRioStatusCode *status) = 0; 110 | virtual unsigned short readMXP(unsigned char reg_index, tRioStatusCode *status) = 0; 111 | 112 | 113 | private: 114 | tPWM(const tPWM&); 115 | void operator=(const tPWM&); 116 | }; 117 | 118 | } 119 | } 120 | 121 | #endif // __nFRC_2017_17_0_2_PWM_h__ 122 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tRelay.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_Relay_h__ 5 | #define __nFRC_2017_17_0_2_Relay_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tRelay 16 | { 17 | public: 18 | tRelay(){} 19 | virtual ~tRelay(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tRelay* create(tRioStatusCode *status); 23 | 24 | typedef enum 25 | { 26 | kNumSystems = 1, 27 | } tIfaceConstants; 28 | 29 | typedef 30 | union{ 31 | struct{ 32 | #ifdef __vxworks 33 | unsigned Forward : 4; 34 | unsigned Reverse : 4; 35 | #else 36 | unsigned Reverse : 4; 37 | unsigned Forward : 4; 38 | #endif 39 | }; 40 | struct{ 41 | unsigned value : 8; 42 | }; 43 | } tValue; 44 | 45 | 46 | 47 | typedef enum 48 | { 49 | } tValue_IfaceConstants; 50 | 51 | virtual void writeValue(tValue value, tRioStatusCode *status) = 0; 52 | virtual void writeValue_Forward(unsigned char value, tRioStatusCode *status) = 0; 53 | virtual void writeValue_Reverse(unsigned char value, tRioStatusCode *status) = 0; 54 | virtual tValue readValue(tRioStatusCode *status) = 0; 55 | virtual unsigned char readValue_Forward(tRioStatusCode *status) = 0; 56 | virtual unsigned char readValue_Reverse(tRioStatusCode *status) = 0; 57 | 58 | 59 | 60 | 61 | private: 62 | tRelay(const tRelay&); 63 | void operator=(const tRelay&); 64 | }; 65 | 66 | } 67 | } 68 | 69 | #endif // __nFRC_2017_17_0_2_Relay_h__ 70 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tSPI.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_SPI_h__ 5 | #define __nFRC_2017_17_0_2_SPI_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tSPI 16 | { 17 | public: 18 | tSPI(){} 19 | virtual ~tSPI(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tSPI* create(tRioStatusCode *status); 23 | 24 | typedef enum 25 | { 26 | kNumSystems = 1, 27 | } tIfaceConstants; 28 | 29 | typedef 30 | union{ 31 | struct{ 32 | #ifdef __vxworks 33 | unsigned Hdr : 4; 34 | unsigned MXP : 1; 35 | #else 36 | unsigned MXP : 1; 37 | unsigned Hdr : 4; 38 | #endif 39 | }; 40 | struct{ 41 | unsigned value : 5; 42 | }; 43 | } tChipSelectActiveHigh; 44 | 45 | 46 | 47 | typedef enum 48 | { 49 | } tEnableDIO_IfaceConstants; 50 | 51 | virtual void writeEnableDIO(unsigned char value, tRioStatusCode *status) = 0; 52 | virtual unsigned char readEnableDIO(tRioStatusCode *status) = 0; 53 | 54 | 55 | typedef enum 56 | { 57 | } tChipSelectActiveHigh_IfaceConstants; 58 | 59 | virtual void writeChipSelectActiveHigh(tChipSelectActiveHigh value, tRioStatusCode *status) = 0; 60 | virtual void writeChipSelectActiveHigh_Hdr(unsigned char value, tRioStatusCode *status) = 0; 61 | virtual void writeChipSelectActiveHigh_MXP(unsigned char value, tRioStatusCode *status) = 0; 62 | virtual tChipSelectActiveHigh readChipSelectActiveHigh(tRioStatusCode *status) = 0; 63 | virtual unsigned char readChipSelectActiveHigh_Hdr(tRioStatusCode *status) = 0; 64 | virtual unsigned char readChipSelectActiveHigh_MXP(tRioStatusCode *status) = 0; 65 | 66 | 67 | 68 | 69 | private: 70 | tSPI(const tSPI&); 71 | void operator=(const tSPI&); 72 | }; 73 | 74 | } 75 | } 76 | 77 | #endif // __nFRC_2017_17_0_2_SPI_h__ 78 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tSysWatchdog.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | // Do Not Edit... this file is generated! 3 | 4 | #ifndef __nFRC_2017_17_0_2_SysWatchdog_h__ 5 | #define __nFRC_2017_17_0_2_SysWatchdog_h__ 6 | 7 | #include "../tSystem.h" 8 | #include "../tSystemInterface.h" 9 | 10 | namespace nFPGA 11 | { 12 | namespace nFRC_2017_17_0_2 13 | { 14 | 15 | class tSysWatchdog 16 | { 17 | public: 18 | tSysWatchdog(){} 19 | virtual ~tSysWatchdog(){} 20 | 21 | virtual tSystemInterface* getSystemInterface() = 0; 22 | static tSysWatchdog* create(tRioStatusCode *status); 23 | 24 | typedef enum 25 | { 26 | kNumSystems = 1, 27 | } tIfaceConstants; 28 | 29 | typedef 30 | union{ 31 | struct{ 32 | #ifdef __vxworks 33 | unsigned SystemActive : 1; 34 | unsigned PowerAlive : 1; 35 | unsigned SysDisableCount : 15; 36 | unsigned PowerDisableCount : 15; 37 | #else 38 | unsigned PowerDisableCount : 15; 39 | unsigned SysDisableCount : 15; 40 | unsigned PowerAlive : 1; 41 | unsigned SystemActive : 1; 42 | #endif 43 | }; 44 | struct{ 45 | unsigned value : 32; 46 | }; 47 | } tStatus; 48 | 49 | 50 | 51 | typedef enum 52 | { 53 | } tStatus_IfaceConstants; 54 | 55 | virtual tStatus readStatus(tRioStatusCode *status) = 0; 56 | virtual bool readStatus_SystemActive(tRioStatusCode *status) = 0; 57 | virtual bool readStatus_PowerAlive(tRioStatusCode *status) = 0; 58 | virtual unsigned short readStatus_SysDisableCount(tRioStatusCode *status) = 0; 59 | virtual unsigned short readStatus_PowerDisableCount(tRioStatusCode *status) = 0; 60 | 61 | 62 | typedef enum 63 | { 64 | } tCommand_IfaceConstants; 65 | 66 | virtual void writeCommand(unsigned short value, tRioStatusCode *status) = 0; 67 | virtual unsigned short readCommand(tRioStatusCode *status) = 0; 68 | 69 | 70 | typedef enum 71 | { 72 | } tChallenge_IfaceConstants; 73 | 74 | virtual unsigned char readChallenge(tRioStatusCode *status) = 0; 75 | 76 | 77 | typedef enum 78 | { 79 | } tActive_IfaceConstants; 80 | 81 | virtual void writeActive(bool value, tRioStatusCode *status) = 0; 82 | virtual bool readActive(tRioStatusCode *status) = 0; 83 | 84 | 85 | typedef enum 86 | { 87 | } tTimer_IfaceConstants; 88 | 89 | virtual unsigned int readTimer(tRioStatusCode *status) = 0; 90 | 91 | 92 | typedef enum 93 | { 94 | } tForcedKills_IfaceConstants; 95 | 96 | virtual unsigned short readForcedKills(tRioStatusCode *status) = 0; 97 | 98 | 99 | 100 | 101 | private: 102 | tSysWatchdog(const tSysWatchdog&); 103 | void operator=(const tSysWatchdog&); 104 | }; 105 | 106 | } 107 | } 108 | 109 | #endif // __nFRC_2017_17_0_2_SysWatchdog_h__ 110 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/printFpgaVersion.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | 3 | #ifndef __printFPGAVersion_h__ 4 | #define __printFPGAVersion_h__ 5 | 6 | namespace nFPGA 7 | { 8 | 9 | template 10 | inline void printFPGAVersion(ttGlobal &global) 11 | { 12 | tRioStatusCode cleanStatus=0; 13 | uint32_t hardwareGuid[4]; 14 | tSystemInterface &system = *global.getSystemInterface(); 15 | system.getHardwareFpgaSignature(hardwareGuid, &cleanStatus); 16 | const uint32_t *softwareGuid = system.getExpectedFPGASignature(); 17 | printf("FPGA Hardware GUID: 0x"); 18 | for(int i=0; i<4; i++) 19 | { 20 | printf("%08X", hardwareGuid[i]); 21 | } 22 | printf("\n"); 23 | printf("FPGA Software GUID: 0x"); 24 | for(int i=0; i<4; i++) 25 | { 26 | printf("%08X", softwareGuid[i]); 27 | } 28 | printf("\n"); 29 | uint16_t fpgaHardwareVersion = global.readVersion(&cleanStatus); 30 | uint16_t fpgaSoftwareVersion = system.getExpectedFPGAVersion(); 31 | printf("FPGA Hardware Version: %X\n", fpgaHardwareVersion); 32 | printf("FPGA Software Version: %X\n", fpgaSoftwareVersion); 33 | uint32_t fpgaHardwareRevision = global.readRevision(&cleanStatus); 34 | uint32_t fpgaSoftwareRevision = system.getExpectedFPGARevision(); 35 | printf("FPGA Hardware Revision: %X.%X.%X\n", (fpgaHardwareRevision >> 20) & 0xFFF, (fpgaHardwareRevision >> 12) & 0xFF, fpgaHardwareRevision & 0xFFF); 36 | printf("FPGA Software Revision: %X.%X.%X\n", (fpgaSoftwareRevision >> 20) & 0xFFF, (fpgaSoftwareRevision >> 12) & 0xFF, fpgaSoftwareRevision & 0xFFF); 37 | } 38 | 39 | } 40 | 41 | #endif // __printFPGAVersion_h__ 42 | 43 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/tDMAChannelDescriptor.h: -------------------------------------------------------------------------------- 1 | // Describes the information needed to configure a DMA channel. 2 | // Copyright (c) National Instruments 2008. All Rights Reserved. 3 | 4 | #include 5 | 6 | #ifndef __tDMAChannelDescriptor_h__ 7 | #define __tDMAChannelDescriptor_h__ 8 | 9 | struct tDMAChannelDescriptor 10 | { 11 | uint32_t channel; 12 | uint32_t baseAddress; 13 | uint32_t depth; 14 | bool targetToHost; 15 | }; 16 | 17 | #endif // __tDMAChannelDescriptor_h__ 18 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/tDMAManager.h: -------------------------------------------------------------------------------- 1 | // Class for handling DMA transfers. 2 | // Copyright (c) National Instruments 2008. All Rights Reserved. 3 | 4 | #ifndef __tDMAManager_h__ 5 | #define __tDMAManager_h__ 6 | 7 | #include "tSystem.h" 8 | #include 9 | 10 | namespace nFPGA 11 | { 12 | class tDMAManager : public tSystem 13 | { 14 | public: 15 | tDMAManager(uint32_t dmaChannel, uint32_t hostBufferSize, tRioStatusCode *status); 16 | ~tDMAManager(); 17 | void start(tRioStatusCode *status); 18 | void stop(tRioStatusCode *status); 19 | bool isStarted() {return _started;} 20 | void read( 21 | uint32_t* buf, 22 | size_t num, 23 | uint32_t timeout, 24 | size_t* remaining, 25 | tRioStatusCode *status); 26 | void write( 27 | uint32_t* buf, 28 | size_t num, 29 | uint32_t timeout, 30 | size_t* remaining, 31 | tRioStatusCode *status); 32 | private: 33 | bool _started; 34 | uint32_t _dmaChannel; 35 | uint32_t _hostBufferSize; 36 | 37 | }; 38 | 39 | } 40 | 41 | #endif // __tDMAManager_h__ 42 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/tInterruptManager.h: -------------------------------------------------------------------------------- 1 | // Class for handling interrupts. 2 | // Copyright (c) National Instruments 2008. All Rights Reserved. 3 | 4 | #ifndef __tInterruptManager_h__ 5 | #define __tInterruptManager_h__ 6 | 7 | #include "tSystem.h" 8 | 9 | namespace ni 10 | { 11 | namespace dsc 12 | { 13 | namespace osdep 14 | { 15 | class CriticalSection; 16 | } 17 | } 18 | } 19 | 20 | namespace nFPGA 21 | { 22 | 23 | typedef void (*tInterruptHandler)(uint32_t interruptAssertedMask, void *param); 24 | 25 | class tInterruptManager : public tSystem 26 | { 27 | public: 28 | tInterruptManager(uint32_t interruptMask, bool watcher, tRioStatusCode *status); 29 | ~tInterruptManager(); 30 | void registerHandler(tInterruptHandler handler, void *param, tRioStatusCode *status); 31 | uint32_t watch(int32_t timeoutInMs, bool ignorePrevious, tRioStatusCode *status); 32 | void enable(tRioStatusCode *status); 33 | void disable(tRioStatusCode *status); 34 | bool isEnabled(tRioStatusCode *status); 35 | private: 36 | class tInterruptThread; 37 | friend class tInterruptThread; 38 | void handler(); 39 | static int handlerWrapper(tInterruptManager *pInterrupt); 40 | 41 | void acknowledge(tRioStatusCode *status); 42 | void reserve(tRioStatusCode *status); 43 | void unreserve(tRioStatusCode *status); 44 | tInterruptHandler _handler; 45 | uint32_t _interruptMask; 46 | tInterruptThread *_thread; 47 | NiFpga_IrqContext _rioContext; 48 | bool _watcher; 49 | bool _enabled; 50 | void *_userParam; 51 | 52 | // maintain the interrupts that are already dealt with. 53 | static uint32_t _globalInterruptMask; 54 | static ni::dsc::osdep::CriticalSection *_globalInterruptMaskSemaphore; 55 | }; 56 | 57 | } 58 | 59 | 60 | #endif // __tInterruptManager_h__ 61 | 62 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/tSystem.h: -------------------------------------------------------------------------------- 1 | // Base class for generated chip objects 2 | // Copyright (c) National Instruments 2008. All Rights Reserved. 3 | 4 | #ifndef __tSystem_h__ 5 | #define __tSystem_h__ 6 | 7 | #include "fpgainterfacecapi/NiFpga.h" 8 | typedef NiFpga_Status tRioStatusCode; 9 | 10 | #define FRC_FPGA_PRELOAD_BITFILE 11 | 12 | typedef uint32_t NiFpga_Session; 13 | 14 | namespace nFPGA 15 | { 16 | 17 | class tSystem 18 | { 19 | public: 20 | tSystem(tRioStatusCode *status); 21 | ~tSystem(); 22 | void getFpgaGuid(uint32_t *guid_ptr, tRioStatusCode *status); 23 | void reset(tRioStatusCode *status); 24 | 25 | protected: 26 | static NiFpga_Session _DeviceHandle; 27 | 28 | #ifdef FRC_FPGA_PRELOAD_BITFILE 29 | void NiFpga_SharedOpen_common(const char* bitfile); 30 | NiFpga_Status NiFpga_SharedOpen(const char* bitfile, 31 | const char* signature, 32 | const char* resource, 33 | uint32_t attribute, 34 | NiFpga_Session* session); 35 | NiFpga_Status NiFpgaLv_SharedOpen(const char* const bitfile, 36 | const char* const apiSignature, 37 | const char* const resource, 38 | const uint32_t attribute, 39 | NiFpga_Session* const session); 40 | private: 41 | static char *_FileName; 42 | static char *_Bitfile; 43 | #endif 44 | }; 45 | 46 | } 47 | 48 | #endif // __tSystem_h__ 49 | -------------------------------------------------------------------------------- /athena/include/FRC_FPGA_ChipObject/tSystemInterface.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) National Instruments 2008. All Rights Reserved. 2 | 3 | #ifndef __tSystemInterface_h__ 4 | #define __tSystemInterface_h__ 5 | 6 | namespace nFPGA 7 | { 8 | 9 | class tSystemInterface 10 | { 11 | public: 12 | tSystemInterface(){} 13 | virtual ~tSystemInterface(){} 14 | 15 | virtual const uint16_t getExpectedFPGAVersion()=0; 16 | virtual const uint32_t getExpectedFPGARevision()=0; 17 | virtual const uint32_t * const getExpectedFPGASignature()=0; 18 | virtual void getHardwareFpgaSignature(uint32_t *guid_ptr, tRioStatusCode *status)=0; 19 | virtual uint32_t getLVHandle(tRioStatusCode *status)=0; 20 | virtual uint32_t getHandle()=0; 21 | virtual void reset(tRioStatusCode *status)=0; 22 | }; 23 | 24 | } 25 | 26 | #endif // __tSystemInterface_h__ 27 | 28 | -------------------------------------------------------------------------------- /athena/include/FRC_NetworkCommunication/AICalibration.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __AICalibration_h__ 3 | #define __AICalibration_h__ 4 | 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | uint32_t FRC_NetworkCommunication_nAICalibration_getLSBWeight(const uint32_t aiSystemIndex, const uint32_t channel, int32_t *status); 13 | int32_t FRC_NetworkCommunication_nAICalibration_getOffset(const uint32_t aiSystemIndex, const uint32_t channel, int32_t *status); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif // __AICalibration_h__ 20 | -------------------------------------------------------------------------------- /athena/include/FRC_NetworkCommunication/CANInterfacePlugin.h: -------------------------------------------------------------------------------- 1 | // CANInterfacePlugin.h 2 | // 3 | // Defines the API for building a CAN Interface Plugin to support 4 | // PWM-cable-free CAN motor control on FRC robots. This allows you 5 | // to connect any CAN interface to the secure Jaguar CAN driver. 6 | // 7 | 8 | #ifndef __CANInterfacePlugin_h__ 9 | #define __CANInterfacePlugin_h__ 10 | 11 | #include 12 | 13 | #define CAN_IS_FRAME_REMOTE 0x80000000 14 | #define CAN_IS_FRAME_11BIT 0x40000000 15 | #define CAN_29BIT_MESSAGE_ID_MASK 0x1FFFFFFF 16 | #define CAN_11BIT_MESSAGE_ID_MASK 0x000007FF 17 | 18 | class CANInterfacePlugin 19 | { 20 | public: 21 | CANInterfacePlugin() {} 22 | virtual ~CANInterfacePlugin() {} 23 | 24 | /** 25 | * This entry-point of the CANInterfacePlugin is passed a message that the driver needs to send to 26 | * a device on the CAN bus. 27 | * 28 | * This function may be called from multiple contexts and must therefore be reentrant. 29 | * 30 | * @param messageID The 29-bit CAN message ID in the lsbs. The msb can indicate a remote frame. 31 | * @param data A pointer to a buffer containing between 0 and 8 bytes to send with the message. May be NULL if dataSize is 0. 32 | * @param dataSize The number of bytes to send with the message. 33 | * @return Return any error code. On success return 0. 34 | */ 35 | virtual int32_t sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize) = 0; 36 | 37 | /** 38 | * This entry-point of the CANInterfacePlugin is passed buffers which should be populated with 39 | * any received messages from devices on the CAN bus. 40 | * 41 | * This function is always called by a single task in the Jaguar driver, so it need not be reentrant. 42 | * 43 | * This function is expected to block for some period of time waiting for a message from the CAN bus. 44 | * It may timeout periodically (returning non-zero to indicate no message was populated) to allow for 45 | * shutdown and unloading of the plugin. 46 | * 47 | * @param messageID A reference to be populated with a received 29-bit CAN message ID in the lsbs. 48 | * @param data A pointer to a buffer of 8 bytes to be populated with data received with the message. 49 | * @param dataSize A reference to be populated with the size of the data received (0 - 8 bytes). 50 | * @return This should return 0 if a message was populated, non-0 if no message was not populated. 51 | */ 52 | virtual int32_t receiveMessage(uint32_t &messageID, uint8_t *data, uint8_t &dataSize) = 0; 53 | 54 | #if defined(__linux) 55 | /** 56 | * This entry-point of the CANInterfacePlugin returns status of the CAN bus. 57 | * 58 | * This function may be called from multiple contexts and must therefore be reentrant. 59 | * 60 | * This function will return detailed hardware status if available for diagnostics of the CAN interface. 61 | * 62 | * @param busOffCount The number of times that sendMessage failed with a busOff error indicating that messages 63 | * are not successfully transmitted on the bus. 64 | * @param txFullCount The number of times that sendMessage failed with a txFifoFull error indicating that messages 65 | * are not successfully received by any CAN device. 66 | * @param receiveErrorCount The count of receive errors as reported by the CAN driver. 67 | * @param transmitErrorCount The count of transmit errors as reported by the CAN driver. 68 | * @return This should return 0 if all status was retrieved successfully or an error code if not. 69 | */ 70 | virtual int32_t getStatus(uint32_t &busOffCount, uint32_t &txFullCount, uint32_t &receiveErrorCount, uint32_t &transmitErrorCount) {return 0;} 71 | #endif 72 | }; 73 | 74 | /** 75 | * This function allows you to register a CANInterfacePlugin to provide access a CAN bus. 76 | * 77 | * @param interface A pointer to an object that inherits from CANInterfacePlugin and implements 78 | * the pure virtual interface. If NULL, unregister the current plugin. 79 | */ 80 | void FRC_NetworkCommunication_CANSessionMux_registerInterface(CANInterfacePlugin* interface); 81 | 82 | #endif // __CANInterfacePlugin_h__ 83 | -------------------------------------------------------------------------------- /athena/include/FRC_NetworkCommunication/CANSessionMux.h: -------------------------------------------------------------------------------- 1 | // CANSessionMux.h 2 | // 3 | // Defines the API for building a CAN Interface Plugin to support 4 | // PWM-cable-free CAN motor control on FRC robots. This allows you 5 | // to connect any CAN interface to the secure Jaguar CAN driver. 6 | // 7 | 8 | #ifndef __CANSessionMux_h__ 9 | #define __CANSessionMux_h__ 10 | 11 | #if defined(__vxworks) 12 | #include 13 | #else 14 | #include 15 | #endif 16 | 17 | #define CAN_SEND_PERIOD_NO_REPEAT 0 18 | #define CAN_SEND_PERIOD_STOP_REPEATING -1 19 | 20 | /* Flags in the upper bits of the messageID */ 21 | #define CAN_IS_FRAME_REMOTE 0x80000000 22 | #define CAN_IS_FRAME_11BIT 0x40000000 23 | 24 | #define ERR_CANSessionMux_InvalidBuffer -44086 25 | #define ERR_CANSessionMux_MessageNotFound -44087 26 | #define WARN_CANSessionMux_NoToken 44087 27 | #define ERR_CANSessionMux_NotAllowed -44088 28 | #define ERR_CANSessionMux_NotInitialized -44089 29 | #define ERR_CANSessionMux_SessionOverrun 44050 30 | 31 | struct tCANStreamMessage{ 32 | uint32_t messageID; 33 | uint32_t timeStamp; 34 | uint8_t data[8]; 35 | uint8_t dataSize; 36 | }; 37 | 38 | #ifdef __cplusplus 39 | namespace nCANSessionMux 40 | { 41 | void sendMessage_wrapper(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t periodMs, int32_t *status); 42 | void receiveMessage_wrapper(uint32_t *messageID, uint32_t messageIDMask, uint8_t *data, uint8_t *dataSize, uint32_t *timeStamp, int32_t *status); 43 | void openStreamSession(uint32_t *sessionHandle, uint32_t messageID, uint32_t messageIDMask, uint32_t maxMessages, int32_t *status); 44 | void closeStreamSession(uint32_t sessionHandle); 45 | void readStreamSession(uint32_t sessionHandle, struct tCANStreamMessage *messages, uint32_t messagesToRead, uint32_t *messagesRead, int32_t *status); 46 | void getCANStatus(float *percentBusUtilization, uint32_t *busOffCount, uint32_t *txFullCount, uint32_t *receiveErrorCount, uint32_t *transmitErrorCount, int32_t *status); 47 | } 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | extern "C" 52 | { 53 | #endif 54 | 55 | void FRC_NetworkCommunication_CANSessionMux_sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t periodMs, int32_t *status); 56 | void FRC_NetworkCommunication_CANSessionMux_receiveMessage(uint32_t *messageID, uint32_t messageIDMask, uint8_t *data, uint8_t *dataSize, uint32_t *timeStamp, int32_t *status); 57 | void FRC_NetworkCommunication_CANSessionMux_openStreamSession(uint32_t *sessionHandle, uint32_t messageID, uint32_t messageIDMask, uint32_t maxMessages, int32_t *status); 58 | void FRC_NetworkCommunication_CANSessionMux_closeStreamSession(uint32_t sessionHandle); 59 | void FRC_NetworkCommunication_CANSessionMux_readStreamSession(uint32_t sessionHandle, struct tCANStreamMessage *messages, uint32_t messagesToRead, uint32_t *messagesRead, int32_t *status); 60 | void FRC_NetworkCommunication_CANSessionMux_getCANStatus(float *percentBusUtilization, uint32_t *busOffCount, uint32_t *txFullCount, uint32_t *receiveErrorCount, uint32_t *transmitErrorCount, int32_t *status); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif // __CANSessionMux_h__ 67 | -------------------------------------------------------------------------------- /athena/include/FRC_NetworkCommunication/LoadOut.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __LoadOut_h__ 3 | #define __LoadOut_h__ 4 | 5 | #ifdef _WIN32 6 | #include 7 | #define EXPORT_FUNC __declspec(dllexport) __cdecl 8 | #elif defined (__vxworks) 9 | #include 10 | #define EXPORT_FUNC 11 | #else 12 | #include 13 | #define EXPORT_FUNC 14 | #endif 15 | 16 | #define kMaxModuleNumber 2 17 | namespace nLoadOut 18 | { 19 | #if defined(__vxworks) || defined(SIMULATION) 20 | typedef enum { 21 | kModuleType_Unknown = 0x00, 22 | kModuleType_Analog = 0x01, 23 | kModuleType_Digital = 0x02, 24 | kModuleType_Solenoid = 0x03, 25 | } tModuleType; 26 | bool EXPORT_FUNC getModulePresence(tModuleType moduleType, uint8_t moduleNumber); 27 | #endif 28 | typedef enum { 29 | kTargetClass_Unknown = 0x00, 30 | kTargetClass_FRC1 = 0x10, 31 | kTargetClass_FRC2 = 0x20, 32 | kTargetClass_FRC3 = 0x30, 33 | kTargetClass_RoboRIO = 0x40, 34 | #if defined(__vxworks) || defined(SIMULATION) 35 | kTargetClass_FRC2_Analog = kTargetClass_FRC2 | kModuleType_Analog, 36 | kTargetClass_FRC2_Digital = kTargetClass_FRC2 | kModuleType_Digital, 37 | kTargetClass_FRC2_Solenoid = kTargetClass_FRC2 | kModuleType_Solenoid, 38 | #endif 39 | kTargetClass_FamilyMask = 0xF0, 40 | kTargetClass_ModuleMask = 0x0F, 41 | } tTargetClass; 42 | tTargetClass EXPORT_FUNC getTargetClass(); 43 | } 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #if defined(__vxworks) || defined(SIMULATION) 50 | uint32_t EXPORT_FUNC FRC_NetworkCommunication_nLoadOut_getModulePresence(uint32_t moduleType, uint8_t moduleNumber); 51 | #endif 52 | uint32_t EXPORT_FUNC FRC_NetworkCommunication_nLoadOut_getTargetClass(); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif // __LoadOut_h__ 59 | -------------------------------------------------------------------------------- /athena/include/HAL/Accelerometer.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include "HAL/Types.h" 11 | 12 | enum HAL_AccelerometerRange { 13 | HAL_AccelerometerRange_k2G = 0, 14 | HAL_AccelerometerRange_k4G = 1, 15 | HAL_AccelerometerRange_k8G = 2, 16 | }; 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | void HAL_SetAccelerometerActive(HAL_Bool active); 22 | void HAL_SetAccelerometerRange(enum HAL_AccelerometerRange range); 23 | double HAL_GetAccelerometerX(void); 24 | double HAL_GetAccelerometerY(void); 25 | double HAL_GetAccelerometerZ(void); 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /athena/include/HAL/AnalogAccumulator.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle, 19 | int32_t* status); 20 | void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle, 21 | int32_t* status); 22 | void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle, 23 | int32_t* status); 24 | void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle, 25 | int32_t center, int32_t* status); 26 | void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle, 27 | int32_t deadband, int32_t* status); 28 | int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle, 29 | int32_t* status); 30 | int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle, 31 | int32_t* status); 32 | void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle, 33 | int64_t* value, int64_t* count, int32_t* status); 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /athena/include/HAL/AnalogGyro.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle handle, 19 | int32_t* status); 20 | void HAL_SetupAnalogGyro(HAL_GyroHandle handle, int32_t* status); 21 | void HAL_FreeAnalogGyro(HAL_GyroHandle handle); 22 | void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle, 23 | double voltsPerDegreePerSecond, double offset, 24 | int32_t center, int32_t* status); 25 | void HAL_SetAnalogGyroVoltsPerDegreePerSecond(HAL_GyroHandle handle, 26 | double voltsPerDegreePerSecond, 27 | int32_t* status); 28 | void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status); 29 | void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status); 30 | void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, double volts, 31 | int32_t* status); 32 | double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status); 33 | double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status); 34 | double HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status); 35 | int32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status); 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /athena/include/HAL/AnalogInput.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle, 19 | int32_t* status); 20 | void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle); 21 | HAL_Bool HAL_CheckAnalogModule(int32_t module); 22 | HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel); 23 | 24 | void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status); 25 | double HAL_GetAnalogSampleRate(int32_t* status); 26 | void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle, 27 | int32_t bits, int32_t* status); 28 | int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle, 29 | int32_t* status); 30 | void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle, 31 | int32_t bits, int32_t* status); 32 | int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle, 33 | int32_t* status); 34 | int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle, 35 | int32_t* status); 36 | int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle, 37 | int32_t* status); 38 | int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle, 39 | double voltage, int32_t* status); 40 | double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle, 41 | int32_t* status); 42 | double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle, 43 | int32_t* status); 44 | int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle, 45 | int32_t* status); 46 | int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle, 47 | int32_t* status); 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /athena/include/HAL/AnalogOutput.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle, 19 | int32_t* status); 20 | void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analogOutputHandle); 21 | void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle, 22 | double voltage, int32_t* status); 23 | double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle, 24 | int32_t* status); 25 | HAL_Bool HAL_CheckAnalogOutputChannel(int32_t channel); 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /athena/include/HAL/AnalogTrigger.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | enum HAL_AnalogTriggerType { 15 | HAL_Trigger_kInWindow = 0, 16 | HAL_Trigger_kState = 1, 17 | HAL_Trigger_kRisingPulse = 2, 18 | HAL_Trigger_kFallingPulse = 3 19 | }; 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger( 25 | HAL_AnalogInputHandle portHandle, int32_t* index, int32_t* status); 26 | void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle, 27 | int32_t* status); 28 | void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle, 29 | int32_t lower, int32_t upper, 30 | int32_t* status); 31 | void HAL_SetAnalogTriggerLimitsVoltage( 32 | HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper, 33 | int32_t* status); 34 | void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle, 35 | HAL_Bool useAveragedValue, int32_t* status); 36 | void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle, 37 | HAL_Bool useFilteredValue, int32_t* status); 38 | HAL_Bool HAL_GetAnalogTriggerInWindow( 39 | HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status); 40 | HAL_Bool HAL_GetAnalogTriggerTriggerState( 41 | HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status); 42 | HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle, 43 | enum HAL_AnalogTriggerType type, 44 | int32_t* status); 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /athena/include/HAL/CAN.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "FRC_NetworkCommunication/CANSessionMux.h" 13 | 14 | void canTxSend(uint32_t arbID, uint8_t length, 15 | int32_t period); 16 | 17 | void canTxPackInt8(uint32_t arbID, uint8_t offset, uint8_t value); 18 | void canTxPackInt16(uint32_t arbID, uint8_t offset, uint16_t value); 19 | void canTxPackInt32(uint32_t arbID, uint8_t offset, uint32_t value); 20 | void canTxPackFXP16(uint32_t arbID, uint8_t offset, double value); 21 | void canTxPackFXP32(uint32_t arbID, uint8_t offset, double value); 22 | 23 | uint8_t canTxUnpackInt8(uint32_t arbID, uint8_t offset); 24 | uint32_t canTxUnpackInt32(uint32_t arbID, uint8_t offset); 25 | uint16_t canTxUnpackInt16(uint32_t arbID, uint8_t offset); 26 | double canTxUnpackFXP16(uint32_t arbID, uint8_t offset); 27 | double canTxUnpackFXP32(uint32_t arbID, uint8_t offset); 28 | 29 | HAL_Bool canRxReceive(uint32_t arbID); 30 | 31 | uint8_t canRxUnpackInt8(uint32_t arbID, uint8_t offset); 32 | uint16_t canRxUnpackInt16(uint32_t arbID, uint8_t offset); 33 | uint32_t canRxUnpackInt32(uint32_t arbID, uint8_t offset); 34 | double canRxUnpackFXP16(uint32_t arbID, uint8_t offset); 35 | double canRxUnpackFXP32(uint32_t arbID, uint8_t offset); 36 | -------------------------------------------------------------------------------- /athena/include/HAL/ChipObject.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2008-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | #pragma GCC diagnostic push 10 | #pragma GCC diagnostic ignored "-Wpedantic" 11 | #pragma GCC diagnostic ignored "-Wignored-qualifiers" 12 | 13 | #include 14 | 15 | #include "FRC_FPGA_ChipObject/RoboRIO_FRC_ChipObject_Aliases.h" 16 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/nInterfaceGlobals.h" 17 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAI.h" 18 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAO.h" 19 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAccel.h" 20 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAccumulator.h" 21 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAlarm.h" 22 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tAnalogTrigger.h" 23 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tBIST.h" 24 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tCounter.h" 25 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDIO.h" 26 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDMA.h" 27 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tEncoder.h" 28 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tGlobal.h" 29 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tInterrupt.h" 30 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tPWM.h" 31 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tPower.h" 32 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tRelay.h" 33 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tSPI.h" 34 | #include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tSysWatchdog.h" 35 | #include "FRC_FPGA_ChipObject/tDMAChannelDescriptor.h" 36 | #include "FRC_FPGA_ChipObject/tDMAManager.h" 37 | #include "FRC_FPGA_ChipObject/tInterruptManager.h" 38 | #include "FRC_FPGA_ChipObject/tSystem.h" 39 | #include "FRC_FPGA_ChipObject/tSystemInterface.h" 40 | 41 | namespace hal { 42 | using namespace nFPGA; 43 | using namespace nRoboRIO_FPGANamespace; 44 | } // namespace hal 45 | 46 | #pragma GCC diagnostic pop 47 | -------------------------------------------------------------------------------- /athena/include/HAL/Compressor.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | HAL_CompressorHandle HAL_InitializeCompressor(int32_t module, int32_t* status); 19 | HAL_Bool HAL_CheckCompressorModule(int32_t module); 20 | 21 | HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressorHandle, 22 | int32_t* status); 23 | 24 | void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressorHandle, 25 | HAL_Bool value, int32_t* status); 26 | HAL_Bool HAL_GetCompressorClosedLoopControl( 27 | HAL_CompressorHandle compressorHandle, int32_t* status); 28 | 29 | HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressorHandle, 30 | int32_t* status); 31 | double HAL_GetCompressorCurrent(HAL_CompressorHandle compressorHandle, 32 | int32_t* status); 33 | 34 | HAL_Bool HAL_GetCompressorCurrentTooHighFault( 35 | HAL_CompressorHandle compressorHandle, int32_t* status); 36 | HAL_Bool HAL_GetCompressorCurrentTooHighStickyFault( 37 | HAL_CompressorHandle compressorHandle, int32_t* status); 38 | HAL_Bool HAL_GetCompressorShortedStickyFault( 39 | HAL_CompressorHandle compressorHandle, int32_t* status); 40 | HAL_Bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressorHandle, 41 | int32_t* status); 42 | HAL_Bool HAL_GetCompressorNotConnectedStickyFault( 43 | HAL_CompressorHandle compressorHandle, int32_t* status); 44 | HAL_Bool HAL_GetCompressorNotConnectedFault( 45 | HAL_CompressorHandle compressorHandle, int32_t* status); 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /athena/include/HAL/Constants.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | int32_t HAL_GetSystemClockTicksPerMicrosecond(void); 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /athena/include/HAL/DIO.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle, 19 | HAL_Bool input, int32_t* status); 20 | HAL_Bool HAL_CheckDIOChannel(int32_t channel); 21 | void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle); 22 | HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status); 23 | void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status); 24 | void HAL_SetDigitalPWMRate(double rate, int32_t* status); 25 | void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator, 26 | double dutyCycle, int32_t* status); 27 | void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator, 28 | int32_t channel, int32_t* status); 29 | void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value, 30 | int32_t* status); 31 | HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status); 32 | HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status); 33 | void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength, 34 | int32_t* status); 35 | HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status); 36 | HAL_Bool HAL_IsAnyPulsing(int32_t* status); 37 | 38 | void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex, 39 | int32_t* status); 40 | int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status); 41 | void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status); 42 | int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status); 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /athena/include/HAL/Encoder.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/AnalogTrigger.h" 13 | #include "HAL/Types.h" 14 | 15 | enum HAL_EncoderIndexingType { 16 | HAL_kResetWhileHigh, 17 | HAL_kResetWhileLow, 18 | HAL_kResetOnFallingEdge, 19 | HAL_kResetOnRisingEdge 20 | }; 21 | enum HAL_EncoderEncodingType { 22 | HAL_Encoder_k1X, 23 | HAL_Encoder_k2X, 24 | HAL_Encoder_k4X 25 | }; 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | HAL_EncoderHandle HAL_InitializeEncoder( 31 | HAL_Handle digitalSourceHandleA, enum HAL_AnalogTriggerType analogTriggerTypeA, 32 | HAL_Handle digitalSourceHandleB, enum HAL_AnalogTriggerType analogTriggerTypeB, 33 | HAL_Bool reverseDirection, enum HAL_EncoderEncodingType encodingType, 34 | int32_t* status); 35 | void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status); 36 | int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status); 37 | int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t* status); 38 | int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoderHandle, 39 | int32_t* status); 40 | void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status); 41 | double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status); 42 | void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod, 43 | int32_t* status); 44 | HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle, 45 | int32_t* status); 46 | HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle, 47 | int32_t* status); 48 | double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle, int32_t* status); 49 | double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t* status); 50 | void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate, 51 | int32_t* status); 52 | void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle, 53 | double distancePerPulse, int32_t* status); 54 | void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle, 55 | HAL_Bool reverseDirection, int32_t* status); 56 | void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle, 57 | int32_t samplesToAverage, int32_t* status); 58 | int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle, 59 | int32_t* status); 60 | 61 | void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle, 62 | HAL_Handle digitalSourceHandle, 63 | enum HAL_AnalogTriggerType analogTriggerType, 64 | enum HAL_EncoderIndexingType type, int32_t* status); 65 | 66 | int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle, 67 | int32_t* status); 68 | 69 | double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoderHandle, 70 | int32_t* status); 71 | 72 | double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle, 73 | int32_t* status); 74 | 75 | enum HAL_EncoderEncodingType HAL_GetEncoderEncodingType( 76 | HAL_EncoderHandle encoderHandle, int32_t* status); 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /athena/include/HAL/HAL.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2013-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #ifndef HAL_USE_LABVIEW 13 | 14 | #include "HAL/Accelerometer.h" 15 | #include "HAL/AnalogAccumulator.h" 16 | #include "HAL/AnalogGyro.h" 17 | #include "HAL/AnalogInput.h" 18 | #include "HAL/AnalogOutput.h" 19 | #include "HAL/AnalogTrigger.h" 20 | #include "HAL/CAN.h" 21 | #include "FRC_FPGA_ChipObject/fpgainterfacecapi/NiFpga.h" 22 | #include "HAL/Compressor.h" 23 | #include "HAL/Constants.h" 24 | #include "HAL/Counter.h" 25 | #include "HAL/DIO.h" 26 | #include "HAL/DriverStation.h" 27 | #include "HAL/Encoder.h" 28 | #include "HAL/Errors.h" 29 | #include "HAL/I2C.h" 30 | #include "HAL/Interrupts.h" 31 | #include "HAL/Notifier.h" 32 | #include "HAL/PDP.h" 33 | #include "HAL/PWM.h" 34 | #include "HAL/Ports.h" 35 | #include "HAL/Power.h" 36 | #include "HAL/Relay.h" 37 | #include "HAL/SPI.h" 38 | #include "HAL/SerialPort.h" 39 | #include "HAL/Solenoid.h" 40 | #include "HAL/Threads.h" 41 | 42 | #endif // HAL_USE_LABVIEW 43 | 44 | #include "FRC_NetworkCommunication/UsageReporting.h" 45 | #include "HAL/Types.h" 46 | 47 | enum HAL_RuntimeType { HAL_Athena, HAL_Mock }; 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | const char* HAL_GetErrorMessage(int32_t code); 54 | 55 | int32_t HAL_GetFPGAVersion(int32_t* status); 56 | int64_t HAL_GetFPGARevision(int32_t* status); 57 | 58 | enum HAL_RuntimeType HAL_GetRuntimeType(); 59 | HAL_Bool HAL_GetFPGAButton(int32_t* status); 60 | 61 | HAL_Bool HAL_GetSystemActive(int32_t* status); 62 | HAL_Bool HAL_GetBrownedOut(int32_t* status); 63 | 64 | void HAL_BaseInitialize(int32_t* status); 65 | 66 | #ifndef HAL_USE_LABVIEW 67 | 68 | HAL_PortHandle HAL_GetPort(int32_t channel); 69 | HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel); 70 | 71 | uint64_t HAL_GetFPGATime(int32_t* status); 72 | 73 | int32_t HAL_Initialize(int32_t mode); 74 | 75 | // ifdef's definition is to allow for default parameters in C++. 76 | #ifdef __cplusplus 77 | int64_t HAL_Report(int32_t resource, int32_t instanceNumber, 78 | int32_t context = 0, const char* feature = nullptr); 79 | #else 80 | int64_t HAL_Report(int32_t resource, int32_t instanceNumber, int32_t context, 81 | const char* feature); 82 | #endif 83 | 84 | #endif // HAL_USE_LABVIEW 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | -------------------------------------------------------------------------------- /athena/include/HAL/I2C.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | void HAL_InitializeI2C(int32_t port, int32_t* status); 17 | int32_t HAL_TransactionI2C(int32_t port, int32_t deviceAddress, 18 | uint8_t* dataToSend, int32_t sendSize, 19 | uint8_t* dataReceived, int32_t receiveSize); 20 | int32_t HAL_WriteI2C(int32_t port, int32_t deviceAddress, uint8_t* dataToSend, 21 | int32_t sendSize); 22 | int32_t HAL_ReadI2C(int32_t port, int32_t deviceAddress, uint8_t* buffer, 23 | int32_t count); 24 | void HAL_CloseI2C(int32_t port); 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /athena/include/HAL/Interrupts.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/AnalogTrigger.h" 13 | #include "HAL/Types.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef void (*HAL_InterruptHandlerFunction)(uint32_t interruptAssertedMask, 20 | void* param); 21 | 22 | HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher, int32_t* status); 23 | void HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status); 24 | 25 | int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle, 26 | double timeout, HAL_Bool ignorePrevious, 27 | int32_t* status); 28 | void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status); 29 | void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle, 30 | int32_t* status); 31 | double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, 32 | int32_t* status); 33 | double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle, 34 | int32_t* status); 35 | void HAL_RequestInterrupts(HAL_InterruptHandle interruptHandle, 36 | HAL_Handle digitalSourceHandle, 37 | enum HAL_AnalogTriggerType analogTriggerType, 38 | int32_t* status); 39 | void HAL_AttachInterruptHandler(HAL_InterruptHandle interruptHandle, 40 | HAL_InterruptHandlerFunction handler, 41 | void* param, int32_t* status); 42 | void HAL_AttachInterruptHandlerThreaded(HAL_InterruptHandle interruptHandle, 43 | HAL_InterruptHandlerFunction handler, 44 | void* param, int32_t* status); 45 | void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle, 46 | HAL_Bool risingEdge, HAL_Bool fallingEdge, 47 | int32_t* status); 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /athena/include/HAL/LabVIEW/HAL.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #define HAL_USE_LABVIEW 11 | 12 | #include "HAL/DriverStation.h" 13 | #include "HAL/HAL.h" 14 | #include "HAL/Types.h" 15 | -------------------------------------------------------------------------------- /athena/include/HAL/Notifier.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | typedef void (*HAL_NotifierProcessFunction)(uint64_t currentTime, 19 | HAL_NotifierHandle handle); 20 | 21 | HAL_NotifierHandle HAL_InitializeNotifier(HAL_NotifierProcessFunction process, 22 | void* param, int32_t* status); 23 | HAL_NotifierHandle HAL_InitializeNotifierThreaded( 24 | HAL_NotifierProcessFunction process, void* param, int32_t* status); 25 | void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status); 26 | void* HAL_GetNotifierParam(HAL_NotifierHandle notifierHandle, int32_t* status); 27 | void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle, 28 | uint64_t triggerTime, int32_t* status); 29 | void HAL_StopNotifierAlarm(HAL_NotifierHandle notifierHandle, int32_t* status); 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /athena/include/HAL/OSSerialPort.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "SerialPort.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | void HAL_InitializeOSSerialPort(HAL_SerialPort port, int32_t* status); 19 | void HAL_SetOSSerialBaudRate(HAL_SerialPort port, int32_t baud, 20 | int32_t* status); 21 | void HAL_SetOSSerialDataBits(HAL_SerialPort port, int32_t bits, 22 | int32_t* status); 23 | void HAL_SetOSSerialParity(HAL_SerialPort port, int32_t parity, 24 | int32_t* status); 25 | void HAL_SetOSSerialStopBits(HAL_SerialPort port, int32_t stopBits, 26 | int32_t* status); 27 | void HAL_SetOSSerialWriteMode(HAL_SerialPort port, int32_t mode, 28 | int32_t* status); 29 | void HAL_SetOSSerialFlowControl(HAL_SerialPort port, int32_t flow, 30 | int32_t* status); 31 | void HAL_SetOSSerialTimeout(HAL_SerialPort port, double timeout, 32 | int32_t* status); 33 | void HAL_EnableOSSerialTermination(HAL_SerialPort port, char terminator, 34 | int32_t* status); 35 | void HAL_DisableOSSerialTermination(HAL_SerialPort port, int32_t* status); 36 | void HAL_SetOSSerialReadBufferSize(HAL_SerialPort port, int32_t size, 37 | int32_t* status); 38 | void HAL_SetOSSerialWriteBufferSize(HAL_SerialPort port, int32_t size, 39 | int32_t* status); 40 | int32_t HAL_GetOSSerialBytesReceived(HAL_SerialPort port, int32_t* status); 41 | int32_t HAL_ReadOSSerial(HAL_SerialPort port, char* buffer, int32_t count, 42 | int32_t* status); 43 | int32_t HAL_WriteOSSerial(HAL_SerialPort port, const char* buffer, 44 | int32_t count, int32_t* status); 45 | void HAL_FlushOSSerial(HAL_SerialPort port, int32_t* status); 46 | void HAL_ClearOSSerial(HAL_SerialPort port, int32_t* status); 47 | void HAL_CloseOSSerial(HAL_SerialPort port, int32_t* status); 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /athena/include/HAL/PDP.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | void HAL_InitializePDP(int32_t module, int32_t* status); 19 | HAL_Bool HAL_CheckPDPChannel(int32_t channel); 20 | HAL_Bool HAL_CheckPDPModule(int32_t module); 21 | double HAL_GetPDPTemperature(int32_t module, int32_t* status); 22 | double HAL_GetPDPVoltage(int32_t module, int32_t* status); 23 | double HAL_GetPDPChannelCurrent(int32_t module, int32_t channel, 24 | int32_t* status); 25 | double HAL_GetPDPTotalCurrent(int32_t module, int32_t* status); 26 | double HAL_GetPDPTotalPower(int32_t module, int32_t* status); 27 | double HAL_GetPDPTotalEnergy(int32_t module, int32_t* status); 28 | void HAL_ResetPDPTotalEnergy(int32_t module, int32_t* status); 29 | void HAL_ClearPDPStickyFaults(int32_t module, int32_t* status); 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /athena/include/HAL/PWM.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, 19 | int32_t* status); 20 | void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status); 21 | 22 | HAL_Bool HAL_CheckPWMChannel(int32_t channel); 23 | 24 | void HAL_SetPWMConfig(HAL_DigitalHandle pwmPortHandle, double maxPwm, 25 | double deadbandMaxPwm, double centerPwm, 26 | double deadbandMinPwm, double minPwm, int32_t* status); 27 | void HAL_SetPWMConfigRaw(HAL_DigitalHandle pwmPortHandle, int32_t maxPwm, 28 | int32_t deadbandMaxPwm, int32_t centerPwm, 29 | int32_t deadbandMinPwm, int32_t minPwm, 30 | int32_t* status); 31 | void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwmPortHandle, int32_t* maxPwm, 32 | int32_t* deadbandMaxPwm, int32_t* centerPwm, 33 | int32_t* deadbandMinPwm, int32_t* minPwm, 34 | int32_t* status); 35 | void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle, 36 | HAL_Bool eliminateDeadband, int32_t* status); 37 | HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle, 38 | int32_t* status); 39 | void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value, 40 | int32_t* status); 41 | void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed, 42 | int32_t* status); 43 | void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double position, 44 | int32_t* status); 45 | void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status); 46 | int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status); 47 | double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status); 48 | double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status); 49 | void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status); 50 | void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask, 51 | int32_t* status); 52 | int32_t HAL_GetLoopTiming(int32_t* status); 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | -------------------------------------------------------------------------------- /athena/include/HAL/Ports.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | int32_t HAL_GetNumAccumulators(void); 17 | int32_t HAL_GetNumAnalogTriggers(void); 18 | int32_t HAL_GetNumAnalogInputs(void); 19 | int32_t HAL_GetNumAnalogOutputs(void); 20 | int32_t HAL_GetNumCounters(void); 21 | int32_t HAL_GetNumDigitalHeaders(void); 22 | int32_t HAL_GetNumPWMHeaders(void); 23 | int32_t HAL_GetNumDigitalChannels(void); 24 | int32_t HAL_GetNumPWMChannels(void); 25 | int32_t HAL_GetNumDigitalPWMOutputs(void); 26 | int32_t HAL_GetNumEncoders(void); 27 | int32_t HAL_GetNumInterrupts(void); 28 | int32_t HAL_GetNumRelayChannels(void); 29 | int32_t HAL_GetNumRelayHeaders(void); 30 | int32_t HAL_GetNumPCMModules(void); 31 | int32_t HAL_GetNumSolenoidChannels(void); 32 | int32_t HAL_GetNumPDPModules(void); 33 | int32_t HAL_GetNumPDPChannels(void); 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /athena/include/HAL/Power.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | double HAL_GetVinVoltage(int32_t* status); 19 | double HAL_GetVinCurrent(int32_t* status); 20 | double HAL_GetUserVoltage6V(int32_t* status); 21 | double HAL_GetUserCurrent6V(int32_t* status); 22 | HAL_Bool HAL_GetUserActive6V(int32_t* status); 23 | int32_t HAL_GetUserCurrentFaults6V(int32_t* status); 24 | double HAL_GetUserVoltage5V(int32_t* status); 25 | double HAL_GetUserCurrent5V(int32_t* status); 26 | HAL_Bool HAL_GetUserActive5V(int32_t* status); 27 | int32_t HAL_GetUserCurrentFaults5V(int32_t* status); 28 | double HAL_GetUserVoltage3V3(int32_t* status); 29 | double HAL_GetUserCurrent3V3(int32_t* status); 30 | HAL_Bool HAL_GetUserActive3V3(int32_t* status); 31 | int32_t HAL_GetUserCurrentFaults3V3(int32_t* status); 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /athena/include/HAL/Relay.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, 19 | int32_t* status); 20 | void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle); 21 | 22 | HAL_Bool HAL_CheckRelayChannel(int32_t channel); 23 | 24 | void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on, 25 | int32_t* status); 26 | HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status); 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /athena/include/HAL/SPI.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | void HAL_InitializeSPI(int32_t port, int32_t* status); 19 | int32_t HAL_TransactionSPI(int32_t port, uint8_t* dataToSend, 20 | uint8_t* dataReceived, int32_t size); 21 | int32_t HAL_WriteSPI(int32_t port, uint8_t* dataToSend, int32_t sendSize); 22 | int32_t HAL_ReadSPI(int32_t port, uint8_t* buffer, int32_t count); 23 | void HAL_CloseSPI(int32_t port); 24 | void HAL_SetSPISpeed(int32_t port, int32_t speed); 25 | void HAL_SetSPIOpts(int32_t port, HAL_Bool msbFirst, HAL_Bool sampleOnTrailing, 26 | HAL_Bool clkIdleHigh); 27 | void HAL_SetSPIChipSelectActiveHigh(int32_t port, int32_t* status); 28 | void HAL_SetSPIChipSelectActiveLow(int32_t port, int32_t* status); 29 | int32_t HAL_GetSPIHandle(int32_t port); 30 | void HAL_SetSPIHandle(int32_t port, int32_t handle); 31 | 32 | void HAL_InitSPIAccumulator(int32_t port, int32_t period, int32_t cmd, 33 | int32_t xferSize, int32_t validMask, 34 | int32_t validValue, int32_t dataShift, 35 | int32_t dataSize, HAL_Bool isSigned, 36 | HAL_Bool bigEndian, int32_t* status); 37 | void HAL_FreeSPIAccumulator(int32_t port, int32_t* status); 38 | void HAL_ResetSPIAccumulator(int32_t port, int32_t* status); 39 | void HAL_SetSPIAccumulatorCenter(int32_t port, int32_t center, int32_t* status); 40 | void HAL_SetSPIAccumulatorDeadband(int32_t port, int32_t deadband, 41 | int32_t* status); 42 | int32_t HAL_GetSPIAccumulatorLastValue(int32_t port, int32_t* status); 43 | int64_t HAL_GetSPIAccumulatorValue(int32_t port, int32_t* status); 44 | int64_t HAL_GetSPIAccumulatorCount(int32_t port, int32_t* status); 45 | double HAL_GetSPIAccumulatorAverage(int32_t port, int32_t* status); 46 | void HAL_GetSPIAccumulatorOutput(int32_t port, int64_t* value, int64_t* count, 47 | int32_t* status); 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /athena/include/HAL/SerialPort.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | enum HAL_SerialPort { 13 | HAL_SerialPort_Onboard = 0, 14 | HAL_SerialPort_MXP = 1, 15 | HAL_SerialPort_USB1 = 2, 16 | HAL_SerialPort_USB2 = 3 17 | }; 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | void HAL_InitializeSerialPort(enum HAL_SerialPort port, int32_t* status); 24 | void HAL_SetSerialBaudRate(enum HAL_SerialPort port, int32_t baud, int32_t* status); 25 | void HAL_SetSerialDataBits(enum HAL_SerialPort port, int32_t bits, int32_t* status); 26 | void HAL_SetSerialParity(enum HAL_SerialPort port, int32_t parity, int32_t* status); 27 | void HAL_SetSerialStopBits(enum HAL_SerialPort port, int32_t stopBits, 28 | int32_t* status); 29 | void HAL_SetSerialWriteMode(enum HAL_SerialPort port, int32_t mode, int32_t* status); 30 | void HAL_SetSerialFlowControl(enum HAL_SerialPort port, int32_t flow, 31 | int32_t* status); 32 | void HAL_SetSerialTimeout(enum HAL_SerialPort port, double timeout, int32_t* status); 33 | void HAL_EnableSerialTermination(enum HAL_SerialPort port, char terminator, 34 | int32_t* status); 35 | void HAL_DisableSerialTermination(enum HAL_SerialPort port, int32_t* status); 36 | void HAL_SetSerialReadBufferSize(enum HAL_SerialPort port, int32_t size, 37 | int32_t* status); 38 | void HAL_SetSerialWriteBufferSize(enum HAL_SerialPort port, int32_t size, 39 | int32_t* status); 40 | int32_t HAL_GetSerialBytesReceived(enum HAL_SerialPort port, int32_t* status); 41 | int32_t HAL_ReadSerial(enum HAL_SerialPort port, char* buffer, int32_t count, 42 | int32_t* status); 43 | int32_t HAL_WriteSerial(enum HAL_SerialPort port, const char* buffer, int32_t count, 44 | int32_t* status); 45 | void HAL_FlushSerial(enum HAL_SerialPort port, int32_t* status); 46 | void HAL_ClearSerial(enum HAL_SerialPort port, int32_t* status); 47 | void HAL_CloseSerial(enum HAL_SerialPort port, int32_t* status); 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /athena/include/HAL/Solenoid.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle, 19 | int32_t* status); 20 | void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoidPortHandle); 21 | HAL_Bool HAL_CheckSolenoidModule(int32_t module); 22 | HAL_Bool HAL_CheckSolenoidChannel(int32_t channel); 23 | HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoidPortHandle, 24 | int32_t* status); 25 | int32_t HAL_GetAllSolenoids(int32_t module, int32_t* status); 26 | void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value, 27 | int32_t* status); 28 | void HAL_SetAllSolenoids(int32_t module, int32_t state, int32_t* status); 29 | int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status); 30 | HAL_Bool HAL_GetPCMSolenoidVoltageStickyFault(int32_t module, int32_t* status); 31 | HAL_Bool HAL_GetPCMSolenoidVoltageFault(int32_t module, int32_t* status); 32 | void HAL_ClearAllPCMStickyFaults(int32_t module, int32_t* status); 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /athena/include/HAL/Threads.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include "HAL/Types.h" 11 | 12 | #ifdef _WIN32 13 | #include 14 | #define NativeThreadHandle const HANDLE* 15 | #else 16 | #include 17 | #define NativeThreadHandle const pthread_t* 18 | #endif 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | int32_t HAL_GetThreadPriority(NativeThreadHandle handle, HAL_Bool* isRealTime, 24 | int32_t* status); 25 | int32_t HAL_GetCurrentThreadPriority(HAL_Bool* isRealTime, int32_t* status); 26 | HAL_Bool HAL_SetThreadPriority(NativeThreadHandle handle, HAL_Bool realTime, 27 | int32_t priority, int32_t* status); 28 | HAL_Bool HAL_SetCurrentThreadPriority(HAL_Bool realTime, int32_t priority, 29 | int32_t* status); 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /athena/include/HAL/Types.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #define HAL_kInvalidHandle 0 13 | 14 | typedef int32_t HAL_Handle; 15 | 16 | typedef HAL_Handle HAL_PortHandle; 17 | 18 | typedef HAL_Handle HAL_AnalogInputHandle; 19 | 20 | typedef HAL_Handle HAL_AnalogOutputHandle; 21 | 22 | typedef HAL_Handle HAL_AnalogTriggerHandle; 23 | 24 | typedef HAL_Handle HAL_CompressorHandle; 25 | 26 | typedef HAL_Handle HAL_CounterHandle; 27 | 28 | typedef HAL_Handle HAL_DigitalHandle; 29 | 30 | typedef HAL_Handle HAL_DigitalPWMHandle; 31 | 32 | typedef HAL_Handle HAL_EncoderHandle; 33 | 34 | typedef HAL_Handle HAL_FPGAEncoderHandle; 35 | 36 | typedef HAL_Handle HAL_GyroHandle; 37 | 38 | typedef HAL_Handle HAL_InterruptHandle; 39 | 40 | typedef HAL_Handle HAL_NotifierHandle; 41 | 42 | typedef HAL_Handle HAL_RelayHandle; 43 | 44 | typedef HAL_Handle HAL_SolenoidHandle; 45 | 46 | typedef int32_t HAL_Bool; 47 | -------------------------------------------------------------------------------- /athena/include/HAL/cpp/Log.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | inline std::string NowTime(); 17 | 18 | enum TLogLevel { 19 | logNONE, 20 | logERROR, 21 | logWARNING, 22 | logINFO, 23 | logDEBUG, 24 | logDEBUG1, 25 | logDEBUG2, 26 | logDEBUG3, 27 | logDEBUG4 28 | }; 29 | 30 | class Log { 31 | public: 32 | Log(); 33 | virtual ~Log(); 34 | std::ostringstream& Get(TLogLevel level = logINFO); 35 | 36 | public: 37 | static TLogLevel& ReportingLevel(); 38 | static std::string ToString(TLogLevel level); 39 | static TLogLevel FromString(const std::string& level); 40 | 41 | protected: 42 | std::ostringstream os; 43 | 44 | private: 45 | Log(const Log&); 46 | Log& operator=(const Log&); 47 | }; 48 | 49 | inline Log::Log() {} 50 | 51 | inline std::ostringstream& Log::Get(TLogLevel level) { 52 | os << "- " << NowTime(); 53 | os << " " << ToString(level) << ": "; 54 | os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t'); 55 | return os; 56 | } 57 | 58 | inline Log::~Log() { 59 | os << std::endl; 60 | std::cerr << os.str(); 61 | } 62 | 63 | inline TLogLevel& Log::ReportingLevel() { 64 | static TLogLevel reportingLevel = logDEBUG4; 65 | return reportingLevel; 66 | } 67 | 68 | inline std::string Log::ToString(TLogLevel level) { 69 | static const char* const buffer[] = {"NONE", "ERROR", "WARNING", 70 | "INFO", "DEBUG", "DEBUG1", 71 | "DEBUG2", "DEBUG3", "DEBUG4"}; 72 | return buffer[level]; 73 | } 74 | 75 | inline TLogLevel Log::FromString(const std::string& level) { 76 | if (level == "DEBUG4") return logDEBUG4; 77 | if (level == "DEBUG3") return logDEBUG3; 78 | if (level == "DEBUG2") return logDEBUG2; 79 | if (level == "DEBUG1") return logDEBUG1; 80 | if (level == "DEBUG") return logDEBUG; 81 | if (level == "INFO") return logINFO; 82 | if (level == "WARNING") return logWARNING; 83 | if (level == "ERROR") return logERROR; 84 | if (level == "NONE") return logNONE; 85 | Log().Get(logWARNING) << "Unknown logging level '" << level 86 | << "'. Using INFO level as default."; 87 | return logINFO; 88 | } 89 | 90 | typedef Log FILELog; 91 | 92 | #define FILE_LOG(level) \ 93 | if (level > FILELog::ReportingLevel()) \ 94 | ; \ 95 | else \ 96 | Log().Get(level) 97 | 98 | inline std::string NowTime() { 99 | std::stringstream ss; 100 | ss << std::setfill('0') << std::setw(2); 101 | 102 | using namespace std::chrono; 103 | auto now = system_clock::now().time_since_epoch(); 104 | 105 | ss << duration_cast(now).count() % 24 << ":" 106 | << duration_cast(now).count() % 60 << ":" 107 | << duration_cast(now).count() % 60 << "." 108 | << duration_cast(now).count() % 1000; 109 | 110 | return ss.str(); 111 | } 112 | -------------------------------------------------------------------------------- /athena/include/HAL/cpp/Semaphore.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include "HAL/cpp/priority_mutex.h" 15 | #include "support/deprecated.h" 16 | 17 | class WPI_DEPRECATED( 18 | "Semaphore scheduled for removal in 2018. Recommended to replace with a " 19 | "std::mutex and std::condition_variable") Semaphore { 20 | public: 21 | explicit Semaphore(int32_t count = 0); 22 | Semaphore(Semaphore&&); 23 | Semaphore& operator=(Semaphore&&); 24 | 25 | void give(); 26 | void take(); 27 | 28 | // @return true if semaphore was locked successfully. false if not. 29 | bool tryTake(); 30 | 31 | static const int32_t kNoWait = 0; 32 | static const int32_t kWaitForever = -1; 33 | 34 | static const int32_t kEmpty = 0; 35 | static const int32_t kFull = 1; 36 | 37 | private: 38 | priority_mutex m_mutex; 39 | std::condition_variable_any m_condition; 40 | int32_t m_count = 0; 41 | }; 42 | -------------------------------------------------------------------------------- /athena/include/HAL/cpp/SerialHelper.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "HAL/SerialPort.h" 16 | #include "HAL/cpp/priority_mutex.h" 17 | #include "llvm/SmallString.h" 18 | #include "llvm/SmallVector.h" 19 | 20 | namespace hal { 21 | class SerialHelper { 22 | public: 23 | SerialHelper(); 24 | 25 | std::string GetVISASerialPortName(HAL_SerialPort port, int32_t* status); 26 | std::string GetOSSerialPortName(HAL_SerialPort port, int32_t* status); 27 | 28 | std::vector GetVISASerialPortList(int32_t* status); 29 | std::vector GetOSSerialPortList(int32_t* status); 30 | 31 | private: 32 | void SortHubPathVector(); 33 | void CoiteratedSort(llvm::SmallVectorImpl>& vec); 34 | void QueryHubPaths(int32_t* status); 35 | 36 | int32_t GetIndexForPort(HAL_SerialPort port, int32_t* status); 37 | 38 | // Vectors to hold data before sorting. 39 | // Note we will most likely have at max 2 instances, and the longest string 40 | // is around 12, so these should never touch the heap; 41 | llvm::SmallVector, 4> m_visaResource; 42 | llvm::SmallVector, 4> m_osResource; 43 | llvm::SmallVector, 4> m_unsortedHubPath; 44 | llvm::SmallVector, 4> m_sortedHubPath; 45 | 46 | int32_t m_resourceHandle; 47 | 48 | static priority_mutex m_nameMutex; 49 | static std::string m_usbNames[2]; 50 | }; 51 | } // namespace hal 52 | -------------------------------------------------------------------------------- /athena/include/HAL/cpp/make_unique.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | // Define make_unique for C++11-only compilers 11 | #if __cplusplus == 201103L 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace std { 18 | template 19 | struct _Unique_if { 20 | typedef unique_ptr _Single_object; 21 | }; 22 | 23 | template 24 | struct _Unique_if { 25 | typedef unique_ptr _Unknown_bound; 26 | }; 27 | 28 | template 29 | struct _Unique_if { 30 | typedef void _Known_bound; 31 | }; 32 | 33 | template 34 | typename _Unique_if::_Single_object make_unique(Args&&... args) { 35 | return unique_ptr(new T(std::forward(args)...)); 36 | } 37 | 38 | template 39 | typename _Unique_if::_Unknown_bound make_unique(size_t n) { 40 | typedef typename remove_extent::type U; 41 | return unique_ptr(new U[n]()); 42 | } 43 | 44 | template 45 | typename _Unique_if::_Known_bound make_unique(Args&&...) = delete; 46 | } // namespace std 47 | #endif 48 | -------------------------------------------------------------------------------- /athena/include/HAL/cpp/priority_mutex.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | // Allows usage with std::lock_guard without including separately 11 | #include 12 | 13 | #if defined(FRC_SIMULATOR) || defined(_WIN32) 14 | // We do not want to use pthreads if in the simulator; however, in the 15 | // simulator, we do not care about priority inversion. 16 | typedef std::mutex priority_mutex; 17 | typedef std::recursive_mutex priority_recursive_mutex; 18 | #else // Covers rest of file. 19 | 20 | #include 21 | 22 | class priority_recursive_mutex { 23 | public: 24 | typedef pthread_mutex_t* native_handle_type; 25 | 26 | constexpr priority_recursive_mutex() noexcept = default; 27 | priority_recursive_mutex(const priority_recursive_mutex&) = delete; 28 | priority_recursive_mutex& operator=(const priority_recursive_mutex&) = delete; 29 | 30 | // Lock the mutex, blocking until it's available. 31 | void lock(); 32 | 33 | // Unlock the mutex. 34 | void unlock(); 35 | 36 | // Tries to lock the mutex. 37 | bool try_lock() noexcept; 38 | 39 | pthread_mutex_t* native_handle(); 40 | 41 | private: 42 | // Do the equivalent of setting PTHREAD_PRIO_INHERIT and 43 | // PTHREAD_MUTEX_RECURSIVE_NP. 44 | #if __WORDSIZE == 64 45 | pthread_mutex_t m_mutex = { 46 | {0, 0, 0, 0, 0x20 | PTHREAD_MUTEX_RECURSIVE_NP, 0, 0, {0, 0}}}; 47 | #else 48 | pthread_mutex_t m_mutex = { 49 | {0, 0, 0, 0x20 | PTHREAD_MUTEX_RECURSIVE_NP, 0, {0}}}; 50 | #endif 51 | }; 52 | 53 | class priority_mutex { 54 | public: 55 | typedef pthread_mutex_t* native_handle_type; 56 | 57 | constexpr priority_mutex() noexcept = default; 58 | priority_mutex(const priority_mutex&) = delete; 59 | priority_mutex& operator=(const priority_mutex&) = delete; 60 | 61 | // Lock the mutex, blocking until it's available. 62 | void lock(); 63 | 64 | // Unlock the mutex. 65 | void unlock(); 66 | 67 | // Tries to lock the mutex. 68 | bool try_lock() noexcept; 69 | 70 | pthread_mutex_t* native_handle(); 71 | 72 | private: 73 | // Do the equivalent of setting PTHREAD_PRIO_INHERIT. 74 | #if __WORDSIZE == 64 75 | pthread_mutex_t m_mutex = {{0, 0, 0, 0, 0x20, 0, 0, {0, 0}}}; 76 | #else 77 | pthread_mutex_t m_mutex = {{0, 0, 0, 0x20, 0, {0}}}; 78 | #endif 79 | }; 80 | 81 | #endif // FRC_SIMULATOR 82 | -------------------------------------------------------------------------------- /athena/include/HAL/handles/DigitalHandleResource.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "HAL/Errors.h" 16 | #include "HAL/Types.h" 17 | #include "HAL/cpp/make_unique.h" 18 | #include "HAL/cpp/priority_mutex.h" 19 | #include "HAL/handles/HandlesInternal.h" 20 | 21 | namespace hal { 22 | 23 | /** 24 | * The DigitalHandleResource class is a way to track handles. This version 25 | * allows a limited number of handles that are allocated by index. 26 | * The enum value is seperate, as 2 enum values are allowed per handle 27 | * Because they are allocated by index, each individual index holds its own 28 | * mutex, which reduces contention heavily.] 29 | * 30 | * @tparam THandle The Handle Type (Must be typedefed from HAL_Handle) 31 | * @tparam TStruct The struct type held by this resource 32 | * @tparam size The number of resources allowed to be allocated 33 | * 34 | */ 35 | template 36 | class DigitalHandleResource { 37 | friend class DigitalHandleResourceTest; 38 | 39 | public: 40 | DigitalHandleResource() = default; 41 | DigitalHandleResource(const DigitalHandleResource&) = delete; 42 | DigitalHandleResource& operator=(const DigitalHandleResource&) = delete; 43 | 44 | THandle Allocate(int16_t index, HAL_HandleEnum enumValue, int32_t* status); 45 | std::shared_ptr Get(THandle handle, HAL_HandleEnum enumValue); 46 | void Free(THandle handle, HAL_HandleEnum enumValue); 47 | 48 | private: 49 | std::array, size> m_structures; 50 | std::array m_handleMutexes; 51 | }; 52 | 53 | template 54 | THandle DigitalHandleResource::Allocate( 55 | int16_t index, HAL_HandleEnum enumValue, int32_t* status) { 56 | // don't aquire the lock if we can fail early. 57 | if (index < 0 || index >= size) { 58 | *status = RESOURCE_OUT_OF_RANGE; 59 | return HAL_kInvalidHandle; 60 | } 61 | std::lock_guard sync(m_handleMutexes[index]); 62 | // check for allocation, otherwise allocate and return a valid handle 63 | if (m_structures[index] != nullptr) { 64 | *status = RESOURCE_IS_ALLOCATED; 65 | return HAL_kInvalidHandle; 66 | } 67 | m_structures[index] = std::make_shared(); 68 | return static_cast(hal::createHandle(index, enumValue)); 69 | } 70 | 71 | template 72 | std::shared_ptr DigitalHandleResource::Get( 73 | THandle handle, HAL_HandleEnum enumValue) { 74 | // get handle index, and fail early if index out of range or wrong handle 75 | int16_t index = getHandleTypedIndex(handle, enumValue); 76 | if (index < 0 || index >= size) { 77 | return nullptr; 78 | } 79 | std::lock_guard sync(m_handleMutexes[index]); 80 | // return structure. Null will propogate correctly, so no need to manually 81 | // check. 82 | return m_structures[index]; 83 | } 84 | 85 | template 86 | void DigitalHandleResource::Free( 87 | THandle handle, HAL_HandleEnum enumValue) { 88 | // get handle index, and fail early if index out of range or wrong handle 89 | int16_t index = getHandleTypedIndex(handle, enumValue); 90 | if (index < 0 || index >= size) return; 91 | // lock and deallocated handle 92 | std::lock_guard sync(m_handleMutexes[index]); 93 | m_structures[index].reset(); 94 | } 95 | } // namespace hal 96 | -------------------------------------------------------------------------------- /athena/include/HAL/handles/HandlesInternal.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "HAL/Types.h" 13 | 14 | /* General Handle Data Layout 15 | * Bits 0-15: Handle Index 16 | * Bits 16-23: Unused 17 | * Bits 24-30: Handle Type 18 | * Bit 31: 1 if handle error, 0 if no error 19 | * 20 | * Other specialized handles will use different formats, however Bits 24-31 are 21 | * always reserved for type and error handling. 22 | */ 23 | 24 | namespace hal { 25 | 26 | constexpr int16_t InvalidHandleIndex = -1; 27 | 28 | enum class HAL_HandleEnum { 29 | Undefined = 0, 30 | DIO = 1, 31 | Port = 2, 32 | Notifier = 3, 33 | Interrupt = 4, 34 | AnalogOutput = 5, 35 | AnalogInput = 6, 36 | AnalogTrigger = 7, 37 | Relay = 8, 38 | PWM = 9, 39 | DigitalPWM = 10, 40 | Counter = 11, 41 | FPGAEncoder = 12, 42 | Encoder = 13, 43 | Compressor = 14, 44 | Solenoid = 15, 45 | AnalogGyro = 16, 46 | Vendor = 17 47 | }; 48 | 49 | static inline int16_t getHandleIndex(HAL_Handle handle) { 50 | // mask and return last 16 bits 51 | return static_cast(handle & 0xffff); 52 | } 53 | static inline HAL_HandleEnum getHandleType(HAL_Handle handle) { 54 | // mask first 8 bits and cast to enum 55 | return static_cast((handle >> 24) & 0xff); 56 | } 57 | static inline bool isHandleType(HAL_Handle handle, HAL_HandleEnum handleType) { 58 | return handleType == getHandleType(handle); 59 | } 60 | static inline int16_t getHandleTypedIndex(HAL_Handle handle, 61 | HAL_HandleEnum enumType) { 62 | if (!isHandleType(handle, enumType)) return InvalidHandleIndex; 63 | return getHandleIndex(handle); 64 | } 65 | 66 | /* specialized functions for Port handle 67 | * Port Handle Data Layout 68 | * Bits 0-7: Channel Number 69 | * Bits 8-15: Module Number 70 | * Bits 16-23: Unused 71 | * Bits 24-30: Handle Type 72 | * Bit 31: 1 if handle error, 0 if no error 73 | */ 74 | 75 | // using a 16 bit value so we can store 0-255 and still report error 76 | static inline int16_t getPortHandleChannel(HAL_PortHandle handle) { 77 | if (!isHandleType(handle, HAL_HandleEnum::Port)) return InvalidHandleIndex; 78 | return static_cast(handle & 0xff); 79 | } 80 | 81 | // using a 16 bit value so we can store 0-255 and still report error 82 | static inline int16_t getPortHandleModule(HAL_PortHandle handle) { 83 | if (!isHandleType(handle, HAL_HandleEnum::Port)) return InvalidHandleIndex; 84 | return static_cast((handle >> 8) & 0xff); 85 | } 86 | 87 | // using a 16 bit value so we can store 0-255 and still report error 88 | static inline int16_t getPortHandleSPIEnable(HAL_PortHandle handle) { 89 | if (!isHandleType(handle, HAL_HandleEnum::Port)) return InvalidHandleIndex; 90 | return static_cast((handle >> 16) & 0xff); 91 | } 92 | 93 | HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module); 94 | 95 | HAL_PortHandle createPortHandleForSPI(uint8_t channel); 96 | 97 | HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType); 98 | } // namespace hal 99 | -------------------------------------------------------------------------------- /athena/include/HAL/handles/LimitedHandleResource.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "HAL/Types.h" 16 | #include "HAL/cpp/make_unique.h" 17 | #include "HAL/cpp/priority_mutex.h" 18 | #include "HandlesInternal.h" 19 | 20 | namespace hal { 21 | 22 | /** 23 | * The LimitedHandleResource class is a way to track handles. This version 24 | * allows a limited number of handles that are allocated sequentially. 25 | * 26 | * @tparam THandle The Handle Type (Must be typedefed from HAL_Handle) 27 | * @tparam TStruct The struct type held by this resource 28 | * @tparam size The number of resources allowed to be allocated 29 | * @tparam enumValue The type value stored in the handle 30 | * 31 | */ 32 | template 34 | class LimitedHandleResource { 35 | friend class LimitedHandleResourceTest; 36 | 37 | public: 38 | LimitedHandleResource() = default; 39 | LimitedHandleResource(const LimitedHandleResource&) = delete; 40 | LimitedHandleResource& operator=(const LimitedHandleResource&) = delete; 41 | 42 | THandle Allocate(); 43 | std::shared_ptr Get(THandle handle); 44 | void Free(THandle handle); 45 | 46 | private: 47 | std::array, size> m_structures; 48 | std::array m_handleMutexes; 49 | priority_mutex m_allocateMutex; 50 | }; 51 | 52 | template 54 | THandle LimitedHandleResource::Allocate() { 55 | // globally lock to loop through indices 56 | std::lock_guard sync(m_allocateMutex); 57 | int16_t i; 58 | for (i = 0; i < size; i++) { 59 | if (m_structures[i] == nullptr) { 60 | // if a false index is found, grab its specific mutex 61 | // and allocate it. 62 | std::lock_guard sync(m_handleMutexes[i]); 63 | m_structures[i] = std::make_shared(); 64 | return static_cast(createHandle(i, enumValue)); 65 | } 66 | } 67 | return HAL_kInvalidHandle; 68 | } 69 | 70 | template 72 | std::shared_ptr 73 | LimitedHandleResource::Get(THandle handle) { 74 | // get handle index, and fail early if index out of range or wrong handle 75 | int16_t index = getHandleTypedIndex(handle, enumValue); 76 | if (index < 0 || index >= size) { 77 | return nullptr; 78 | } 79 | std::lock_guard sync(m_handleMutexes[index]); 80 | // return structure. Null will propogate correctly, so no need to manually 81 | // check. 82 | return m_structures[index]; 83 | } 84 | 85 | template 87 | void LimitedHandleResource::Free( 88 | THandle handle) { 89 | // get handle index, and fail early if index out of range or wrong handle 90 | int16_t index = getHandleTypedIndex(handle, enumValue); 91 | if (index < 0 || index >= size) return; 92 | // lock and deallocated handle 93 | std::lock_guard sync(m_allocateMutex); 94 | std::lock_guard lock(m_handleMutexes[index]); 95 | m_structures[index].reset(); 96 | } 97 | } // namespace hal 98 | -------------------------------------------------------------------------------- /athena/include/HAL/handles/UnlimitedHandleResource.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2008-2017. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "HAL/Types.h" 16 | #include "HAL/cpp/priority_mutex.h" 17 | #include "HAL/handles/HandlesInternal.h" 18 | 19 | namespace hal { 20 | 21 | /** 22 | * The UnlimitedHandleResource class is a way to track handles. This version 23 | * allows an unlimted number of handles that are allocated sequentially. When 24 | * possible, indices are reused to save memory usage and keep the array length 25 | * down. 26 | * However, automatic array management has not been implemented, but might be in 27 | * the future. 28 | * Because we have to loop through the allocator, we must use a global mutex. 29 | 30 | * @tparam THandle The Handle Type (Must be typedefed from HAL_Handle) 31 | * @tparam TStruct The struct type held by this resource 32 | * @tparam enumValue The type value stored in the handle 33 | * 34 | */ 35 | template 36 | class UnlimitedHandleResource { 37 | friend class UnlimitedHandleResourceTest; 38 | 39 | public: 40 | UnlimitedHandleResource() = default; 41 | UnlimitedHandleResource(const UnlimitedHandleResource&) = delete; 42 | UnlimitedHandleResource& operator=(const UnlimitedHandleResource&) = delete; 43 | 44 | THandle Allocate(std::shared_ptr structure); 45 | std::shared_ptr Get(THandle handle); 46 | void Free(THandle handle); 47 | 48 | private: 49 | std::vector> m_structures; 50 | priority_mutex m_handleMutex; 51 | }; 52 | 53 | template 54 | THandle UnlimitedHandleResource::Allocate( 55 | std::shared_ptr structure) { 56 | std::lock_guard sync(m_handleMutex); 57 | size_t i; 58 | for (i = 0; i < m_structures.size(); i++) { 59 | if (m_structures[i] == nullptr) { 60 | m_structures[i] = structure; 61 | return static_cast(createHandle(i, enumValue)); 62 | } 63 | } 64 | if (i >= INT16_MAX) return HAL_kInvalidHandle; 65 | 66 | m_structures.push_back(structure); 67 | return static_cast(createHandle(static_cast(i), enumValue)); 68 | } 69 | 70 | template 71 | std::shared_ptr 72 | UnlimitedHandleResource::Get(THandle handle) { 73 | int16_t index = getHandleTypedIndex(handle, enumValue); 74 | std::lock_guard sync(m_handleMutex); 75 | if (index < 0 || index >= static_cast(m_structures.size())) 76 | return nullptr; 77 | return m_structures[index]; 78 | } 79 | 80 | template 81 | void UnlimitedHandleResource::Free( 82 | THandle handle) { 83 | int16_t index = getHandleTypedIndex(handle, enumValue); 84 | std::lock_guard sync(m_handleMutex); 85 | if (index < 0 || index >= static_cast(m_structures.size())) return; 86 | m_structures[index].reset(); 87 | } 88 | } // namespace hal 89 | -------------------------------------------------------------------------------- /athena/include/ctre/CtreCanNode.h: -------------------------------------------------------------------------------- 1 | #ifndef CtreCanNode_H_ 2 | #define CtreCanNode_H_ 3 | #include "ctre.h" //BIT Defines + Typedefs 4 | #include 5 | #include // memcpy 6 | #include 7 | class CtreCanNode 8 | { 9 | public: 10 | CtreCanNode(UINT8 deviceNumber); 11 | ~CtreCanNode(); 12 | 13 | UINT8 GetDeviceNumber() 14 | { 15 | return _deviceNumber; 16 | } 17 | protected: 18 | 19 | 20 | template class txTask{ 21 | public: 22 | uint32_t arbId; 23 | T * toSend; 24 | T * operator -> () 25 | { 26 | return toSend; 27 | } 28 | T & operator*() 29 | { 30 | return *toSend; 31 | } 32 | bool IsEmpty() 33 | { 34 | if(toSend == 0) 35 | return true; 36 | return false; 37 | } 38 | }; 39 | template class recMsg{ 40 | public: 41 | uint32_t arbId; 42 | uint8_t bytes[8]; 43 | CTR_Code err; 44 | T * operator -> () 45 | { 46 | return (T *)bytes; 47 | } 48 | T & operator*() 49 | { 50 | return *(T *)bytes; 51 | } 52 | }; 53 | UINT8 _deviceNumber; 54 | void RegisterRx(uint32_t arbId); 55 | /** 56 | * Schedule a CAN Frame for periodic transmit. Assume eight byte DLC and zero value for initial transmission. 57 | * @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids. 58 | * @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit. 59 | */ 60 | void RegisterTx(uint32_t arbId, uint32_t periodMs); 61 | /** 62 | * Schedule a CAN Frame for periodic transmit. 63 | * @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids. 64 | * @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit. 65 | * @param dlc Number of bytes to transmit (0 to 8). 66 | * @param initialFrame Ptr to the frame data to schedule for transmitting. Passing null will result 67 | * in defaulting to zero data value. 68 | */ 69 | void RegisterTx(uint32_t arbId, uint32_t periodMs, uint32_t dlc, const uint8_t * initialFrame); 70 | void UnregisterTx(uint32_t arbId); 71 | 72 | CTR_Code GetRx(uint32_t arbId,uint8_t * dataBytes,uint32_t timeoutMs); 73 | void FlushTx(uint32_t arbId); 74 | bool ChangeTxPeriod(uint32_t arbId, uint32_t periodMs); 75 | 76 | template txTask GetTx(uint32_t arbId) 77 | { 78 | txTask retval = {0, nullptr}; 79 | txJobs_t::iterator i = _txJobs.find(arbId); 80 | if(i != _txJobs.end()){ 81 | retval.arbId = i->second.arbId; 82 | retval.toSend = (T*)i->second.toSend; 83 | } 84 | return retval; 85 | } 86 | template void FlushTx(T & par) 87 | { 88 | FlushTx(par.arbId); 89 | } 90 | 91 | template recMsg GetRx(uint32_t arbId, uint32_t timeoutMs) 92 | { 93 | recMsg retval; 94 | retval.err = GetRx(arbId,retval.bytes, timeoutMs); 95 | return retval; 96 | } 97 | 98 | private: 99 | 100 | class txJob_t { 101 | public: 102 | uint32_t arbId; 103 | uint8_t toSend[8]; 104 | uint32_t periodMs; 105 | uint8_t dlc; 106 | }; 107 | 108 | class rxEvent_t{ 109 | public: 110 | uint8_t bytes[8]; 111 | struct timespec time; 112 | rxEvent_t() 113 | { 114 | bytes[0] = 0; 115 | bytes[1] = 0; 116 | bytes[2] = 0; 117 | bytes[3] = 0; 118 | bytes[4] = 0; 119 | bytes[5] = 0; 120 | bytes[6] = 0; 121 | bytes[7] = 0; 122 | } 123 | }; 124 | 125 | typedef std::map txJobs_t; 126 | txJobs_t _txJobs; 127 | 128 | typedef std::map rxRxEvents_t; 129 | rxRxEvents_t _rxRxEvents; 130 | }; 131 | #endif 132 | -------------------------------------------------------------------------------- /athena/include/ctre/PDP.h: -------------------------------------------------------------------------------- 1 | #ifndef PDP_H_ 2 | #define PDP_H_ 3 | #include "ctre.h" //BIT Defines + Typedefs 4 | #include "CtreCanNode.h" 5 | class PDP : public CtreCanNode 6 | { 7 | public: 8 | /* Get PDP Channel Current 9 | * 10 | * @Param - deviceNumber - Device ID for PDP. Factory default is 60. Function defaults to 60. 11 | */ 12 | PDP(UINT8 deviceNumber=0); 13 | ~PDP(); 14 | /* Get PDP Channel Current 15 | * 16 | * @Return - CTR_Code - Error code (if any) 17 | * 18 | * @Param - idx - ID of channel to return current for (channels 1-16) 19 | * 20 | * @Param - status - Current of channel 'idx' in Amps (A) 21 | */ 22 | CTR_Code GetChannelCurrent(UINT8 idx, double &status); 23 | 24 | /* Get Bus Voltage of PDP 25 | * 26 | * @Return - CTR_Code - Error code (if any) 27 | * 28 | * @Param - status - Voltage (V) across PDP 29 | */ 30 | CTR_Code GetVoltage(double &status); 31 | 32 | /* Get Temperature of PDP 33 | * 34 | * @Return - CTR_Code - Error code (if any) 35 | * 36 | * @Param - status - Temperature of PDP in Centigrade / Celcius (C) 37 | */ 38 | CTR_Code GetTemperature(double &status); 39 | 40 | CTR_Code GetTotalCurrent(double ¤tAmps); 41 | CTR_Code GetTotalPower(double &powerWatts); 42 | CTR_Code GetTotalEnergy(double &energyJoules); 43 | /* Clear sticky faults. 44 | * @Return - CTR_Code - Error code (if any) 45 | */ 46 | CTR_Code ClearStickyFaults(); 47 | 48 | /* Reset Energy Signals 49 | * @Return - CTR_Code - Error code (if any) 50 | */ 51 | CTR_Code ResetEnergy(); 52 | private: 53 | uint64_t ReadCurrents(uint8_t api); 54 | }; 55 | extern "C" { 56 | void * c_PDP_Init(); 57 | CTR_Code c_GetChannelCurrent(void * handle,UINT8 idx, double *status); 58 | CTR_Code c_GetVoltage(void * handle,double *status); 59 | CTR_Code c_GetTemperature(void * handle,double *status); 60 | void c_SetDeviceNumber_PDP(void * handle,UINT8 deviceNumber); 61 | } 62 | #endif /* PDP_H_ */ 63 | -------------------------------------------------------------------------------- /athena/include/ctre/ctre.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ctre.h 3 | * Common header for all CTRE HAL modules. 4 | */ 5 | #ifndef CTRE_H 6 | #define CTRE_H 7 | 8 | //Bit Defines 9 | #define BIT0 0x01 10 | #define BIT1 0x02 11 | #define BIT2 0x04 12 | #define BIT3 0x08 13 | #define BIT4 0x10 14 | #define BIT5 0x20 15 | #define BIT6 0x40 16 | #define BIT7 0x80 17 | #define BIT8 0x0100 18 | #define BIT9 0x0200 19 | #define BIT10 0x0400 20 | #define BIT11 0x0800 21 | #define BIT12 0x1000 22 | #define BIT13 0x2000 23 | #define BIT14 0x4000 24 | #define BIT15 0x8000 25 | 26 | //Signed 27 | typedef signed char INT8; 28 | typedef signed short INT16; 29 | typedef signed int INT32; 30 | typedef signed long long INT64; 31 | 32 | //Unsigned 33 | typedef unsigned char UINT8; 34 | typedef unsigned short UINT16; 35 | typedef unsigned int UINT32; 36 | typedef unsigned long long UINT64; 37 | 38 | //Other 39 | typedef unsigned char UCHAR; 40 | typedef unsigned short USHORT; 41 | typedef unsigned int UINT; 42 | typedef unsigned long ULONG; 43 | 44 | typedef enum { 45 | CTR_OKAY, //!< No Error - Function executed as expected 46 | CTR_RxTimeout, //!< CAN frame has not been received within specified period of time. 47 | CTR_TxTimeout, //!< Not used. 48 | CTR_InvalidParamValue, //!< Caller passed an invalid param 49 | CTR_UnexpectedArbId, //!< Specified CAN Id is invalid. 50 | CTR_TxFailed, //!< Could not transmit the CAN frame. 51 | CTR_SigNotUpdated, //!< Have not received an value response for signal. 52 | CTR_BufferFull, //!< Caller attempted to insert data into a buffer that is full. 53 | }CTR_Code; 54 | 55 | #include "ctre_frames.h" 56 | 57 | #endif /* CTRE_H */ 58 | -------------------------------------------------------------------------------- /athena/include/edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_ConnectionListenerFunction.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_ConnectionListenerFunction */ 4 | 5 | #ifndef _Included_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_ConnectionListenerFunction 6 | #define _Included_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_ConnectionListenerFunction 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | #endif 14 | -------------------------------------------------------------------------------- /athena/include/edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_EntryListenerFunction.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_EntryListenerFunction */ 4 | 5 | #ifndef _Included_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_EntryListenerFunction 6 | #define _Included_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_EntryListenerFunction 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | #endif 14 | -------------------------------------------------------------------------------- /athena/include/edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_LoggerFunction.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_LoggerFunction */ 4 | 5 | #ifndef _Included_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_LoggerFunction 6 | #define _Included_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_LoggerFunction 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | #endif 14 | -------------------------------------------------------------------------------- /athena/include/i2clib/i2c-lib.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_LIB_H__ 2 | #define __I2C_LIB_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | int i2clib_open(const char *device); 8 | void i2clib_close(int handle); 9 | int i2clib_read(int handle, uint8_t dev_addr, char *recv_buf, int32_t recv_size); 10 | int i2clib_write(int handle, uint8_t dev_addr, const char *send_buf, int32_t send_size); 11 | int i2clib_writeread(int handle, uint8_t dev_addr, const char *send_buf, int32_t send_size, char *recv_buf, int32_t recv_size); 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif /* __I2C_LIB_H__ */ -------------------------------------------------------------------------------- /athena/include/llvm/Compiler.h: -------------------------------------------------------------------------------- 1 | //===-- llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines several macros, based on the current compiler. This allows 11 | // use of compiler-specific features in a way that remains portable. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef LLVM_SUPPORT_COMPILER_H 16 | #define LLVM_SUPPORT_COMPILER_H 17 | 18 | #ifndef __has_feature 19 | # define __has_feature(x) 0 20 | #endif 21 | 22 | #ifndef __has_extension 23 | # define __has_extension(x) 0 24 | #endif 25 | 26 | #ifndef __has_attribute 27 | # define __has_attribute(x) 0 28 | #endif 29 | 30 | #ifndef __has_builtin 31 | # define __has_builtin(x) 0 32 | #endif 33 | 34 | /// \macro LLVM_GNUC_PREREQ 35 | /// \brief Extend the default __GNUC_PREREQ even if glibc's features.h isn't 36 | /// available. 37 | #ifndef LLVM_GNUC_PREREQ 38 | # if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) 39 | # define LLVM_GNUC_PREREQ(maj, min, patch) \ 40 | ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \ 41 | ((maj) << 20) + ((min) << 10) + (patch)) 42 | # elif defined(__GNUC__) && defined(__GNUC_MINOR__) 43 | # define LLVM_GNUC_PREREQ(maj, min, patch) \ 44 | ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10)) 45 | # else 46 | # define LLVM_GNUC_PREREQ(maj, min, patch) 0 47 | # endif 48 | #endif 49 | 50 | #ifndef LLVM_CONSTEXPR 51 | # ifdef _MSC_VER 52 | # if _MSC_VER >= 1900 53 | # define LLVM_CONSTEXPR constexpr 54 | # else 55 | # define LLVM_CONSTEXPR 56 | # endif 57 | # elif defined(__has_feature) 58 | # if __has_feature(cxx_constexpr) 59 | # define LLVM_CONSTEXPR constexpr 60 | # else 61 | # define LLVM_CONSTEXPR 62 | # endif 63 | # elif defined(__GXX_EXPERIMENTAL_CXX0X__) 64 | # define LLVM_CONSTEXPR constexpr 65 | # elif defined(__has_constexpr) 66 | # define LLVM_CONSTEXPR constexpr 67 | # else 68 | # define LLVM_CONSTEXPR 69 | # endif 70 | #endif 71 | 72 | #ifndef LLVM_ATTRIBUTE_UNUSED_RESULT 73 | #if __has_attribute(warn_unused_result) || LLVM_GNUC_PREREQ(3, 4, 0) 74 | #define LLVM_ATTRIBUTE_UNUSED_RESULT __attribute__((__warn_unused_result__)) 75 | #elif defined(_MSC_VER) 76 | #define LLVM_ATTRIBUTE_UNUSED_RESULT _Check_return_ 77 | #else 78 | #define LLVM_ATTRIBUTE_UNUSED_RESULT 79 | #endif 80 | #endif 81 | 82 | #ifndef LLVM_UNLIKELY 83 | #if __has_builtin(__builtin_expect) || LLVM_GNUC_PREREQ(4, 0, 0) 84 | #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true) 85 | #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false) 86 | #else 87 | #define LLVM_LIKELY(EXPR) (EXPR) 88 | #define LLVM_UNLIKELY(EXPR) (EXPR) 89 | #endif 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /athena/include/llvm/EpochTracker.h: -------------------------------------------------------------------------------- 1 | //===- llvm/ADT/EpochTracker.h - ADT epoch tracking --------------*- C++ -*-==// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the DebugEpochBase and DebugEpochBase::HandleBase classes. 11 | // These can be used to write iterators that are fail-fast when LLVM is built 12 | // with asserts enabled. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #ifndef LLVM_ADT_EPOCH_TRACKER_H 17 | #define LLVM_ADT_EPOCH_TRACKER_H 18 | 19 | #include 20 | 21 | namespace llvm { 22 | 23 | #ifdef NDEBUG //ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS 24 | 25 | class DebugEpochBase { 26 | public: 27 | void incrementEpoch() {} 28 | 29 | class HandleBase { 30 | public: 31 | HandleBase() = default; 32 | explicit HandleBase(const DebugEpochBase *) {} 33 | bool isHandleInSync() const { return true; } 34 | const void *getEpochAddress() const { return nullptr; } 35 | }; 36 | }; 37 | 38 | #else 39 | 40 | /// \brief A base class for data structure classes wishing to make iterators 41 | /// ("handles") pointing into themselves fail-fast. When building without 42 | /// asserts, this class is empty and does nothing. 43 | /// 44 | /// DebugEpochBase does not by itself track handles pointing into itself. The 45 | /// expectation is that routines touching the handles will poll on 46 | /// isHandleInSync at appropriate points to assert that the handle they're using 47 | /// is still valid. 48 | /// 49 | class DebugEpochBase { 50 | uint64_t Epoch; 51 | 52 | public: 53 | DebugEpochBase() : Epoch(0) {} 54 | 55 | /// \brief Calling incrementEpoch invalidates all handles pointing into the 56 | /// calling instance. 57 | void incrementEpoch() { ++Epoch; } 58 | 59 | /// \brief The destructor calls incrementEpoch to make use-after-free bugs 60 | /// more likely to crash deterministically. 61 | ~DebugEpochBase() { incrementEpoch(); } 62 | 63 | /// \brief A base class for iterator classes ("handles") that wish to poll for 64 | /// iterator invalidating modifications in the underlying data structure. 65 | /// When LLVM is built without asserts, this class is empty and does nothing. 66 | /// 67 | /// HandleBase does not track the parent data structure by itself. It expects 68 | /// the routines modifying the data structure to call incrementEpoch when they 69 | /// make an iterator-invalidating modification. 70 | /// 71 | class HandleBase { 72 | const uint64_t *EpochAddress; 73 | uint64_t EpochAtCreation; 74 | 75 | public: 76 | HandleBase() : EpochAddress(nullptr), EpochAtCreation(UINT64_MAX) {} 77 | 78 | explicit HandleBase(const DebugEpochBase *Parent) 79 | : EpochAddress(&Parent->Epoch), EpochAtCreation(Parent->Epoch) {} 80 | 81 | /// \brief Returns true if the DebugEpochBase this Handle is linked to has 82 | /// not called incrementEpoch on itself since the creation of this 83 | /// HandleBase instance. 84 | bool isHandleInSync() const { return *EpochAddress == EpochAtCreation; } 85 | 86 | /// \brief Returns a pointer to the epoch word stored in the data structure 87 | /// this handle points into. Can be used to check if two iterators point 88 | /// into the same data structure. 89 | const void *getEpochAddress() const { return EpochAddress; } 90 | }; 91 | }; 92 | 93 | #endif // LLVM_ENABLE_ABI_BREAKING_CHECKS 94 | 95 | } // namespace llvm 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /athena/include/llvm/None.h: -------------------------------------------------------------------------------- 1 | //===-- None.h - Simple null value for implicit construction ------*- C++ -*-=// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file provides None, an enumerator for use in implicit constructors 11 | // of various (usually templated) types to make such construction more 12 | // terse. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #ifndef LLVM_ADT_NONE_H 17 | #define LLVM_ADT_NONE_H 18 | 19 | namespace llvm { 20 | /// \brief A simple null object to allow implicit construction of Optional 21 | /// and similar types without having to spell out the specialization's name. 22 | enum class NoneType { None }; 23 | const NoneType None = None; 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /athena/include/llvm/PointerLikeTypeTraits.h: -------------------------------------------------------------------------------- 1 | //===- llvm/Support/PointerLikeTypeTraits.h - Pointer Traits ----*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the PointerLikeTypeTraits class. This allows data 11 | // structures to reason about pointers and other things that are pointer sized. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef LLVM_SUPPORT_POINTERLIKETYPETRAITS_H 16 | #define LLVM_SUPPORT_POINTERLIKETYPETRAITS_H 17 | 18 | #include "llvm/AlignOf.h" 19 | #include 20 | 21 | namespace llvm { 22 | 23 | /// A traits type that is used to handle pointer types and things that are just 24 | /// wrappers for pointers as a uniform entity. 25 | template class PointerLikeTypeTraits { 26 | // getAsVoidPointer 27 | // getFromVoidPointer 28 | // getNumLowBitsAvailable 29 | }; 30 | 31 | namespace detail { 32 | /// A tiny meta function to compute the log2 of a compile time constant. 33 | template 34 | struct ConstantLog2 35 | : std::integral_constant::value + 1> {}; 36 | template <> struct ConstantLog2<1> : std::integral_constant {}; 37 | } 38 | 39 | // Provide PointerLikeTypeTraits for non-cvr pointers. 40 | template class PointerLikeTypeTraits { 41 | public: 42 | static inline void *getAsVoidPointer(T *P) { return P; } 43 | static inline T *getFromVoidPointer(void *P) { return static_cast(P); } 44 | 45 | enum { 46 | NumLowBitsAvailable = detail::ConstantLog2::Alignment>::value 47 | }; 48 | }; 49 | 50 | template <> class PointerLikeTypeTraits { 51 | public: 52 | static inline void *getAsVoidPointer(void *P) { return P; } 53 | static inline void *getFromVoidPointer(void *P) { return P; } 54 | 55 | /// Note, we assume here that void* is related to raw malloc'ed memory and 56 | /// that malloc returns objects at least 4-byte aligned. However, this may be 57 | /// wrong, or pointers may be from something other than malloc. In this case, 58 | /// you should specify a real typed pointer or avoid this template. 59 | /// 60 | /// All clients should use assertions to do a run-time check to ensure that 61 | /// this is actually true. 62 | enum { NumLowBitsAvailable = 2 }; 63 | }; 64 | 65 | // Provide PointerLikeTypeTraits for const pointers. 66 | template class PointerLikeTypeTraits { 67 | typedef PointerLikeTypeTraits NonConst; 68 | 69 | public: 70 | static inline const void *getAsVoidPointer(const T *P) { 71 | return NonConst::getAsVoidPointer(const_cast(P)); 72 | } 73 | static inline const T *getFromVoidPointer(const void *P) { 74 | return NonConst::getFromVoidPointer(const_cast(P)); 75 | } 76 | enum { NumLowBitsAvailable = NonConst::NumLowBitsAvailable }; 77 | }; 78 | 79 | // Provide PointerLikeTypeTraits for uintptr_t. 80 | template <> class PointerLikeTypeTraits { 81 | public: 82 | static inline void *getAsVoidPointer(uintptr_t P) { 83 | return reinterpret_cast(P); 84 | } 85 | static inline uintptr_t getFromVoidPointer(void *P) { 86 | return reinterpret_cast(P); 87 | } 88 | // No bits are available! 89 | enum { NumLowBitsAvailable = 0 }; 90 | }; 91 | 92 | } // end namespace llvm 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /athena/include/llvm/WindowsError.h: -------------------------------------------------------------------------------- 1 | //===-- WindowsError.h - Support for mapping windows errors to posix-------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_SUPPORT_WINDOWSERROR_H 11 | #define LLVM_SUPPORT_WINDOWSERROR_H 12 | 13 | #include 14 | 15 | namespace llvm { 16 | std::error_code mapWindowsError(unsigned EV); 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /athena/include/llvm/iterator_range.h: -------------------------------------------------------------------------------- 1 | //===- iterator_range.h - A range adaptor for iterators ---------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | /// \file 10 | /// This provides a very simple, boring adaptor for a begin and end iterator 11 | /// into a range type. This should be used to build range views that work well 12 | /// with range based for loops and range based constructors. 13 | /// 14 | /// Note that code here follows more standards-based coding conventions as it 15 | /// is mirroring proposed interfaces for standardization. 16 | /// 17 | //===----------------------------------------------------------------------===// 18 | 19 | #ifndef LLVM_ADT_ITERATOR_RANGE_H 20 | #define LLVM_ADT_ITERATOR_RANGE_H 21 | 22 | #include 23 | #include 24 | 25 | namespace llvm { 26 | 27 | /// \brief A range adaptor for a pair of iterators. 28 | /// 29 | /// This just wraps two iterators into a range-compatible interface. Nothing 30 | /// fancy at all. 31 | template 32 | class iterator_range { 33 | IteratorT begin_iterator, end_iterator; 34 | 35 | public: 36 | //TODO: Add SFINAE to test that the Container's iterators match the range's 37 | // iterators. 38 | template 39 | iterator_range(Container &&c) 40 | //TODO: Consider ADL/non-member begin/end calls. 41 | : begin_iterator(c.begin()), end_iterator(c.end()) {} 42 | iterator_range(IteratorT begin_iterator, IteratorT end_iterator) 43 | : begin_iterator(std::move(begin_iterator)), 44 | end_iterator(std::move(end_iterator)) {} 45 | 46 | IteratorT begin() const { return begin_iterator; } 47 | IteratorT end() const { return end_iterator; } 48 | }; 49 | 50 | /// \brief Convenience function for iterating over sub-ranges. 51 | /// 52 | /// This provides a bit of syntactic sugar to make using sub-ranges 53 | /// in for loops a bit easier. Analogous to std::make_pair(). 54 | template iterator_range make_range(T x, T y) { 55 | return iterator_range(std::move(x), std::move(y)); 56 | } 57 | 58 | template iterator_range make_range(std::pair p) { 59 | return iterator_range(std::move(p.first), std::move(p.second)); 60 | } 61 | 62 | template 63 | iterator_range()))> drop_begin(T &&t, int n) { 64 | return make_range(std::next(begin(t), n), end(t)); 65 | } 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /athena/include/llvm/raw_os_ostream.h: -------------------------------------------------------------------------------- 1 | //===- raw_os_ostream.h - std::ostream adaptor for raw_ostream --*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the raw_os_ostream class. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef LLVM_SUPPORT_RAW_OS_OSTREAM_H 15 | #define LLVM_SUPPORT_RAW_OS_OSTREAM_H 16 | 17 | #include "llvm/raw_ostream.h" 18 | #include 19 | 20 | namespace llvm { 21 | 22 | /// raw_os_ostream - A raw_ostream that writes to an std::ostream. This is a 23 | /// simple adaptor class. It does not check for output errors; clients should 24 | /// use the underlying stream to detect errors. 25 | class raw_os_ostream : public raw_ostream { 26 | std::ostream &OS; 27 | 28 | /// write_impl - See raw_ostream::write_impl. 29 | void write_impl(const char *Ptr, size_t Size) override; 30 | 31 | /// current_pos - Return the current position within the stream, not 32 | /// counting the bytes currently in the buffer. 33 | uint64_t current_pos() const override; 34 | 35 | public: 36 | raw_os_ostream(std::ostream &O) : OS(O) {} 37 | ~raw_os_ostream() override; 38 | }; 39 | 40 | } // end llvm namespace 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /athena/include/llvm/type_traits.h: -------------------------------------------------------------------------------- 1 | //===- llvm/Support/type_traits.h - Simplfied type traits -------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file provides useful additions to the standard type_traits library. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef LLVM_SUPPORT_TYPE_TRAITS_H 15 | #define LLVM_SUPPORT_TYPE_TRAITS_H 16 | 17 | #include 18 | #include 19 | 20 | #include "llvm/Compiler.h" 21 | 22 | namespace llvm { 23 | 24 | /// isPodLike - This is a type trait that is used to determine whether a given 25 | /// type can be copied around with memcpy instead of running ctors etc. 26 | template 27 | struct isPodLike { 28 | // std::is_trivially_copyable is available in libc++ with clang, libstdc++ 29 | // that comes with GCC 5. 30 | #if (__has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)) || \ 31 | (defined(__GNUC__) && __GNUC__ >= 5) 32 | // If the compiler supports the is_trivially_copyable trait use it, as it 33 | // matches the definition of isPodLike closely. 34 | static const bool value = std::is_trivially_copyable::value; 35 | #elif __has_feature(is_trivially_copyable) 36 | // Use the internal name if the compiler supports is_trivially_copyable but we 37 | // don't know if the standard library does. This is the case for clang in 38 | // conjunction with libstdc++ from GCC 4.x. 39 | static const bool value = __is_trivially_copyable(T); 40 | #else 41 | // If we don't know anything else, we can (at least) assume that all non-class 42 | // types are PODs. 43 | static const bool value = !std::is_class::value; 44 | #endif 45 | }; 46 | 47 | // std::pair's are pod-like if their elements are. 48 | template 49 | struct isPodLike > { 50 | static const bool value = isPodLike::value && isPodLike::value; 51 | }; 52 | 53 | /// \brief Metafunction that determines whether the given type is either an 54 | /// integral type or an enumeration type, including enum classes. 55 | /// 56 | /// Note that this accepts potentially more integral types than is_integral 57 | /// because it is based on being implicitly convertible to an integral type. 58 | /// Also note that enum classes aren't implicitly convertible to integral types, 59 | /// the value may therefore need to be explicitly converted before being used. 60 | template class is_integral_or_enum { 61 | typedef typename std::remove_reference::type UnderlyingT; 62 | 63 | public: 64 | static const bool value = 65 | !std::is_class::value && // Filter conversion operators. 66 | !std::is_pointer::value && 67 | !std::is_floating_point::value && 68 | (std::is_enum::value || 69 | std::is_convertible::value); 70 | }; 71 | 72 | /// \brief If T is a pointer, just return it. If it is not, return T&. 73 | template 74 | struct add_lvalue_reference_if_not_pointer { typedef T &type; }; 75 | 76 | template 77 | struct add_lvalue_reference_if_not_pointer< 78 | T, typename std::enable_if::value>::type> { 79 | typedef T type; 80 | }; 81 | 82 | /// \brief If T is a pointer to X, return a pointer to const X. If it is not, 83 | /// return const T. 84 | template 85 | struct add_const_past_pointer { typedef const T type; }; 86 | 87 | template 88 | struct add_const_past_pointer< 89 | T, typename std::enable_if::value>::type> { 90 | typedef const typename std::remove_pointer::type *type; 91 | }; 92 | 93 | } // namespace llvm 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /athena/include/ntcore.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef NTCORE_H_ 9 | #define NTCORE_H_ 10 | 11 | /* C API */ 12 | #include "ntcore_c.h" 13 | 14 | #ifdef __cplusplus 15 | /* C++ API */ 16 | #include "ntcore_cpp.h" 17 | #endif /* __cplusplus */ 18 | 19 | #endif /* NTCORE_H_ */ 20 | -------------------------------------------------------------------------------- /athena/include/spilib/spi-lib.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPI_LIB_H__ 2 | #define __SPI_LIB_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | int spilib_open(const char *device); 8 | void spilib_close(int handle); 9 | int spilib_setspeed(int handle, uint32_t speed); 10 | int spilib_setbitsperword(int handle, uint8_t bpw); 11 | int spilib_setopts(int handle, int msb_first, int sample_on_trailing, int clk_idle_high); 12 | int spilib_read(int handle, char *recv_buf, int32_t size); 13 | int spilib_write(int handle, const char *send_buf, int32_t size); 14 | int spilib_writeread(int handle, const char *send_buf, char *recv_buf, int32_t size); 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif /* __SPI_LIB_H__ */ -------------------------------------------------------------------------------- /athena/include/support/Base64.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_SUPPORT_BASE64_H_ 9 | #define WPIUTIL_SUPPORT_BASE64_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include "llvm/StringRef.h" 15 | 16 | namespace wpi { 17 | 18 | std::size_t Base64Decode(llvm::StringRef encoded, std::string* plain); 19 | void Base64Encode(llvm::StringRef plain, std::string* encoded); 20 | 21 | } // namespace wpi 22 | 23 | #endif // WPIUTIL_SUPPORT_BASE64_H_ 24 | -------------------------------------------------------------------------------- /athena/include/support/ConcurrentQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Juan Palacios juan.palacios.puyana@gmail.com 3 | // Subject to the BSD 2-Clause License 4 | // - see < http://opensource.org/licenses/BSD-2-Clause> 5 | // 6 | 7 | #ifndef WPIUTIL_SUPPORT_CONCURRENT_QUEUE_H_ 8 | #define WPIUTIL_SUPPORT_CONCURRENT_QUEUE_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace wpi { 16 | 17 | template 18 | class ConcurrentQueue { 19 | public: 20 | bool empty() const { 21 | std::unique_lock mlock(mutex_); 22 | return queue_.empty(); 23 | } 24 | 25 | typename std::queue::size_type size() const { 26 | std::unique_lock mlock(mutex_); 27 | return queue_.size(); 28 | } 29 | 30 | T pop() { 31 | std::unique_lock mlock(mutex_); 32 | while (queue_.empty()) { 33 | cond_.wait(mlock); 34 | } 35 | auto item = std::move(queue_.front()); 36 | queue_.pop(); 37 | return item; 38 | } 39 | 40 | void pop(T& item) { 41 | std::unique_lock mlock(mutex_); 42 | while (queue_.empty()) { 43 | cond_.wait(mlock); 44 | } 45 | item = queue_.front(); 46 | queue_.pop(); 47 | } 48 | 49 | void push(const T& item) { 50 | std::unique_lock mlock(mutex_); 51 | queue_.push(item); 52 | mlock.unlock(); 53 | cond_.notify_one(); 54 | } 55 | 56 | void push(T&& item) { 57 | std::unique_lock mlock(mutex_); 58 | queue_.push(std::forward(item)); 59 | mlock.unlock(); 60 | cond_.notify_one(); 61 | } 62 | 63 | template 64 | void emplace(Args&&... args) { 65 | std::unique_lock mlock(mutex_); 66 | queue_.emplace(std::forward(args)...); 67 | mlock.unlock(); 68 | cond_.notify_one(); 69 | } 70 | 71 | ConcurrentQueue() = default; 72 | ConcurrentQueue(const ConcurrentQueue&) = delete; 73 | ConcurrentQueue& operator=(const ConcurrentQueue&) = delete; 74 | 75 | private: 76 | std::queue queue_; 77 | mutable std::mutex mutex_; 78 | std::condition_variable cond_; 79 | }; 80 | 81 | } // namespace wpi 82 | 83 | #endif // WPIUTIL_SUPPORT_CONCURRENT_QUEUE_H_ 84 | -------------------------------------------------------------------------------- /athena/include/support/Logger.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_SUPPORT_LOGGER_H_ 9 | #define WPIUTIL_SUPPORT_LOGGER_H_ 10 | 11 | #include 12 | 13 | #include "llvm/raw_ostream.h" 14 | #include "llvm/SmallString.h" 15 | 16 | namespace wpi { 17 | 18 | enum LogLevel { 19 | WPI_LOG_CRITICAL = 50, 20 | WPI_LOG_ERROR = 40, 21 | WPI_LOG_WARNING = 30, 22 | WPI_LOG_INFO = 20, 23 | WPI_LOG_DEBUG = 10, 24 | WPI_LOG_DEBUG1 = 9, 25 | WPI_LOG_DEBUG2 = 8, 26 | WPI_LOG_DEBUG3 = 7, 27 | WPI_LOG_DEBUG4 = 6 28 | }; 29 | 30 | class Logger { 31 | public: 32 | typedef std::function LogFunc; 34 | 35 | void SetLogger(LogFunc func) { m_func = func; } 36 | 37 | void set_min_level(unsigned int level) { m_min_level = level; } 38 | unsigned int min_level() const { return m_min_level; } 39 | 40 | void Log(unsigned int level, const char* file, unsigned int line, 41 | const char* msg) { 42 | if (!m_func || level < m_min_level) return; 43 | m_func(level, file, line, msg); 44 | } 45 | 46 | bool HasLogger() const { return m_func != nullptr; } 47 | 48 | private: 49 | LogFunc m_func; 50 | unsigned int m_min_level = 20; 51 | }; 52 | 53 | #define WPI_LOG(logger_inst, level, x) \ 54 | do { \ 55 | ::wpi::Logger& WPI_logger_ = logger_inst; \ 56 | if (WPI_logger_.min_level() <= level && WPI_logger_.HasLogger()) { \ 57 | llvm::SmallString<128> log_buf_; \ 58 | llvm::raw_svector_ostream log_os_{log_buf_}; \ 59 | log_os_ << x; \ 60 | WPI_logger_.Log(level, __FILE__, __LINE__, log_buf_.c_str()); \ 61 | } \ 62 | } while (0) 63 | 64 | #define WPI_ERROR(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_ERROR, x) 65 | #define WPI_WARNING(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_WARNING, x) 66 | #define WPI_INFO(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_INFO, x) 67 | 68 | #ifdef NDEBUG 69 | #define WPI_DEBUG(inst, x) do {} while (0) 70 | #define WPI_DEBUG1(inst, x) do {} while (0) 71 | #define WPI_DEBUG2(inst, x) do {} while (0) 72 | #define WPI_DEBUG3(inst, x) do {} while (0) 73 | #define WPI_DEBUG4(inst, x) do {} while (0) 74 | #else 75 | #define WPI_DEBUG(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG, x) 76 | #define WPI_DEBUG1(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG1, x) 77 | #define WPI_DEBUG2(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG2, x) 78 | #define WPI_DEBUG3(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG3, x) 79 | #define WPI_DEBUG4(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG4, x) 80 | #endif 81 | 82 | } // namespace wpi 83 | 84 | #endif // WPIUTIL_SUPPORT_LOGGER_H_ 85 | -------------------------------------------------------------------------------- /athena/include/support/atomic_static.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_SUPPORT_ATOMIC_STATIC_H_ 9 | #define WPIUTIL_SUPPORT_ATOMIC_STATIC_H_ 10 | 11 | #if !defined(_MSC_VER) || (_MSC_VER >= 1900) 12 | 13 | // Just use a local static. This is thread-safe per 14 | // http://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/ 15 | 16 | // Per https://msdn.microsoft.com/en-us/library/Hh567368.aspx "Magic Statics" 17 | // are supported in Visual Studio 2015 but not in earlier versions. 18 | #define ATOMIC_STATIC(cls, inst) static cls inst 19 | #define ATOMIC_STATIC_DECL(cls) 20 | #define ATOMIC_STATIC_INIT(cls) 21 | 22 | #else 23 | // From http://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/ 24 | #include 25 | #include 26 | 27 | #define ATOMIC_STATIC(cls, inst) \ 28 | cls* inst##tmp = m_instance.load(std::memory_order_acquire); \ 29 | if (inst##tmp == nullptr) { \ 30 | std::lock_guard lock(m_instance_mutex); \ 31 | inst##tmp = m_instance.load(std::memory_order_relaxed); \ 32 | if (inst##tmp == nullptr) { \ 33 | inst##tmp = new cls; \ 34 | m_instance.store(inst##tmp, std::memory_order_release); \ 35 | } \ 36 | } \ 37 | cls& inst = *inst##tmp 38 | 39 | #define ATOMIC_STATIC_DECL(cls) \ 40 | static std::atomic m_instance; \ 41 | static std::mutex m_instance_mutex; 42 | 43 | #define ATOMIC_STATIC_INIT(cls) \ 44 | std::atomic cls::m_instance; \ 45 | std::mutex cls::m_instance_mutex; 46 | 47 | #endif 48 | 49 | #endif // WPIUTIL_SUPPORT_ATOMIC_STATIC_H_ 50 | -------------------------------------------------------------------------------- /athena/include/support/deprecated.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef DEPRECATED_H_ 9 | #define DEPRECATED_H_ 10 | 11 | // [[deprecated(msg)]] is a C++14 feature not supported by MSVC or GCC < 4.9. 12 | // We provide an equivalent warning implementation for those compilers here. 13 | #ifndef WPI_DEPRECATED 14 | #if defined(_MSC_VER) 15 | #define WPI_DEPRECATED(msg) __declspec(deprecated(msg)) 16 | #elif defined(__GNUC__) 17 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 8) 18 | #if __cplusplus > 201103L 19 | #define WPI_DEPRECATED(msg) [[deprecated(msg)]] 20 | #else 21 | #define WPI_DEPRECATED(msg) [[gnu::deprecated(msg)]] 22 | #endif 23 | #else 24 | #define WPI_DEPRECATED(msg) __attribute__((deprecated(msg))) 25 | #endif 26 | #elif __cplusplus > 201103L 27 | #define WPI_DEPRECATED(msg) [[deprecated(msg)]] 28 | #else 29 | #define WPI_DEPRECATED(msg) /*nothing*/ 30 | #endif 31 | #endif 32 | 33 | #endif // DEPRECATED_H_ 34 | -------------------------------------------------------------------------------- /athena/include/support/leb128.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_SUPPORT_LEB128_H_ 9 | #define WPIUTIL_SUPPORT_LEB128_H_ 10 | 11 | #include 12 | 13 | #include "llvm/SmallVector.h" 14 | 15 | namespace wpi { 16 | 17 | class raw_istream; 18 | 19 | std::size_t SizeUleb128(unsigned long val); 20 | std::size_t WriteUleb128(llvm::SmallVectorImpl& dest, unsigned long val); 21 | std::size_t ReadUleb128(const char* addr, unsigned long* ret); 22 | bool ReadUleb128(raw_istream& is, unsigned long* ret); 23 | 24 | } // namespace wpi 25 | 26 | #endif // WPIUTIL_SUPPORT_LEB128_H_ 27 | -------------------------------------------------------------------------------- /athena/include/support/raw_istream.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_SUPPORT_RAW_ISTREAM_H_ 9 | #define WPIUTIL_SUPPORT_RAW_ISTREAM_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace wpi { 15 | 16 | class raw_istream { 17 | public: 18 | raw_istream() = default; 19 | virtual ~raw_istream() = default; 20 | 21 | raw_istream& read(char& c) { 22 | read_impl(&c, 1); 23 | return *this; 24 | } 25 | 26 | raw_istream& read(unsigned char& c) { 27 | read_impl(&c, 1); 28 | return *this; 29 | } 30 | 31 | raw_istream& read(signed char& c) { 32 | read_impl(&c, 1); 33 | return *this; 34 | } 35 | 36 | raw_istream& read(void* data, std::size_t len) { 37 | read_impl(data, len); 38 | return *this; 39 | } 40 | 41 | std::size_t readsome(void* data, std::size_t len) { 42 | std::size_t readlen = std::min(in_avail(), len); 43 | if (readlen == 0) return 0; 44 | read_impl(data, readlen); 45 | return readlen; 46 | }; 47 | 48 | virtual void close() = 0; 49 | virtual std::size_t in_avail() const = 0; 50 | 51 | bool has_error() const { return m_error; } 52 | void clear_error() { m_error = false; } 53 | 54 | raw_istream(const raw_istream&) = delete; 55 | raw_istream& operator=(const raw_istream&) = delete; 56 | 57 | protected: 58 | void error_detected() { m_error = true; } 59 | 60 | private: 61 | virtual void read_impl(void* data, std::size_t len) = 0; 62 | 63 | bool m_error = false; 64 | }; 65 | 66 | class raw_mem_istream : public raw_istream { 67 | public: 68 | raw_mem_istream(const char* mem, std::size_t len) : m_cur(mem), m_left(len) {} 69 | void close() override; 70 | std::size_t in_avail() const override; 71 | 72 | private: 73 | void read_impl(void* data, std::size_t len) override; 74 | 75 | const char* m_cur; 76 | std::size_t m_left; 77 | }; 78 | 79 | class raw_fd_istream : public raw_istream { 80 | public: 81 | raw_fd_istream(int fd, bool shouldClose, std::size_t bufSize = 4096); 82 | ~raw_fd_istream() override; 83 | void close() override; 84 | std::size_t in_avail() const override; 85 | 86 | private: 87 | void read_impl(void* data, std::size_t len) override; 88 | 89 | char* m_buf; 90 | char* m_cur; 91 | char* m_end; 92 | std::size_t m_bufSize; 93 | int m_fd; 94 | bool m_shouldClose; 95 | }; 96 | 97 | } // namespace wpi 98 | 99 | #endif // WPIUTIL_SUPPORT_RAW_ISTREAM_H_ 100 | -------------------------------------------------------------------------------- /athena/include/support/raw_socket_istream.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_SUPPORT_RAW_SOCKET_ISTREAM_H_ 9 | #define WPIUTIL_SUPPORT_RAW_SOCKET_ISTREAM_H_ 10 | 11 | #include "support/raw_istream.h" 12 | 13 | namespace wpi { 14 | 15 | class NetworkStream; 16 | 17 | class raw_socket_istream : public raw_istream { 18 | public: 19 | explicit raw_socket_istream(NetworkStream& stream, int timeout = 0) 20 | : m_stream(stream), m_timeout(timeout) {} 21 | 22 | void close() override; 23 | std::size_t in_avail() const override; 24 | 25 | private: 26 | void read_impl(void* data, std::size_t len) override; 27 | 28 | NetworkStream& m_stream; 29 | int m_timeout; 30 | }; 31 | 32 | } // namespace wpi 33 | 34 | #endif // WPIUTIL_SUPPORT_RAW_SOCKET_ISTREAM_H_ 35 | -------------------------------------------------------------------------------- /athena/include/support/raw_socket_ostream.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2016. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_SUPPORT_RAW_SOCKET_OSTREAM_H_ 9 | #define WPIUTIL_SUPPORT_RAW_SOCKET_OSTREAM_H_ 10 | 11 | #include "llvm/raw_ostream.h" 12 | 13 | namespace wpi { 14 | 15 | class NetworkStream; 16 | 17 | class raw_socket_ostream : public llvm::raw_ostream { 18 | public: 19 | raw_socket_ostream(NetworkStream& stream, bool shouldClose) 20 | : m_stream(stream), m_shouldClose(shouldClose) {} 21 | ~raw_socket_ostream(); 22 | 23 | void close(); 24 | 25 | bool has_error() const { return m_error; } 26 | void clear_error() { m_error = false; } 27 | 28 | protected: 29 | void error_detected() { m_error = true; } 30 | 31 | private: 32 | void write_impl(const char* data, std::size_t len) override; 33 | uint64_t current_pos() const override; 34 | 35 | NetworkStream& m_stream; 36 | bool m_error = false; 37 | bool m_shouldClose; 38 | }; 39 | 40 | } // namespace wpi 41 | 42 | #endif // WPIUTIL_SUPPORT_RAW_SOCKET_OSTREAM_H_ 43 | -------------------------------------------------------------------------------- /athena/include/support/timestamp.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | #ifndef WPIUTIL_SUPPORT_TIMESTAMP_H_ 8 | #define WPIUTIL_SUPPORT_TIMESTAMP_H_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | unsigned long long WPI_Now(void); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #ifdef __cplusplus 21 | namespace wpi { 22 | 23 | unsigned long long Now(); 24 | 25 | } // namespace wpi 26 | #endif 27 | 28 | #endif // WPIUTIL_SUPPORT_TIMESTAMP_H_ 29 | -------------------------------------------------------------------------------- /athena/include/tables/ITableListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ITableListener.h 3 | */ 4 | 5 | #ifndef ITABLELISTENER_H_ 6 | #define ITABLELISTENER_H_ 7 | 8 | #include 9 | 10 | #include "llvm/StringRef.h" 11 | #include "nt_Value.h" 12 | 13 | class ITable; 14 | 15 | /** 16 | * A listener that listens to changes in values in a {@link ITable} 17 | */ 18 | class ITableListener { 19 | public: 20 | virtual ~ITableListener() = default; 21 | /** 22 | * Called when a key-value pair is changed in a {@link ITable} 23 | * @param source the table the key-value pair exists in 24 | * @param key the key associated with the value that changed 25 | * @param value the new value 26 | * @param isNew true if the key did not previously exist in the table, 27 | * otherwise it is false 28 | */ 29 | virtual void ValueChanged(ITable* source, llvm::StringRef key, 30 | std::shared_ptr value, bool isNew) = 0; 31 | 32 | /** 33 | * Extended version of ValueChanged. Called when a key-value pair is 34 | * changed in a {@link ITable}. The default implementation simply calls 35 | * ValueChanged(). If this is overridden, ValueChanged() will not be called. 36 | * @param source the table the key-value pair exists in 37 | * @param key the key associated with the value that changed 38 | * @param value the new value 39 | * @param flags update flags; for example, NT_NOTIFY_NEW if the key did not 40 | * previously exist in the table 41 | */ 42 | virtual void ValueChangedEx(ITable* source, llvm::StringRef key, 43 | std::shared_ptr value, 44 | unsigned int flags); 45 | }; 46 | 47 | #endif /* ITABLELISTENER_H_ */ 48 | -------------------------------------------------------------------------------- /athena/include/tables/TableKeyNotDefinedException.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef TABLEKEYNOTDEFINEDEXCEPTION_H_ 9 | #define TABLEKEYNOTDEFINEDEXCEPTION_H_ 10 | 11 | #include 12 | #include "llvm/StringRef.h" 13 | 14 | #if defined(_MSC_VER) 15 | #define NT_NOEXCEPT throw() 16 | #else 17 | #define NT_NOEXCEPT noexcept 18 | #endif 19 | 20 | /** 21 | * An exception thrown when the lookup a a key-value fails in a {@link ITable} 22 | */ 23 | class TableKeyNotDefinedException : public std::exception { 24 | public: 25 | /** 26 | * @param key the key that was not defined in the table 27 | */ 28 | TableKeyNotDefinedException(llvm::StringRef key); 29 | ~TableKeyNotDefinedException() NT_NOEXCEPT; 30 | const char* what() const NT_NOEXCEPT override; 31 | 32 | private: 33 | std::string msg; 34 | }; 35 | 36 | #endif // TABLEKEYNOTDEFINEDEXCEPTION_H_ 37 | -------------------------------------------------------------------------------- /athena/include/tcpsockets/NetworkAcceptor.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_TCPSOCKETS_NETWORKACCEPTOR_H_ 9 | #define WPIUTIL_TCPSOCKETS_NETWORKACCEPTOR_H_ 10 | 11 | #include "tcpsockets/NetworkStream.h" 12 | 13 | namespace wpi { 14 | 15 | class NetworkAcceptor { 16 | public: 17 | NetworkAcceptor() = default; 18 | virtual ~NetworkAcceptor() = default; 19 | 20 | virtual int start() = 0; 21 | virtual void shutdown() = 0; 22 | virtual std::unique_ptr accept() = 0; 23 | 24 | NetworkAcceptor(const NetworkAcceptor&) = delete; 25 | NetworkAcceptor& operator=(const NetworkAcceptor&) = delete; 26 | }; 27 | 28 | } // namespace wpi 29 | 30 | #endif // WPIUTIL_TCPSOCKETS_NETWORKACCEPTOR_H_ 31 | -------------------------------------------------------------------------------- /athena/include/tcpsockets/NetworkStream.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_TCPSOCKETS_NETWORKSTREAM_H_ 9 | #define WPIUTIL_TCPSOCKETS_NETWORKSTREAM_H_ 10 | 11 | #include 12 | 13 | #include "llvm/StringRef.h" 14 | 15 | namespace wpi { 16 | 17 | class NetworkStream { 18 | public: 19 | NetworkStream() = default; 20 | virtual ~NetworkStream() = default; 21 | 22 | enum Error { 23 | kConnectionClosed = 0, 24 | kConnectionReset = -1, 25 | kConnectionTimedOut = -2, 26 | kWouldBlock = -3 27 | }; 28 | 29 | virtual std::size_t send(const char* buffer, std::size_t len, Error* err) = 0; 30 | virtual std::size_t receive(char* buffer, std::size_t len, Error* err, 31 | int timeout = 0) = 0; 32 | virtual void close() = 0; 33 | 34 | virtual llvm::StringRef getPeerIP() const = 0; 35 | virtual int getPeerPort() const = 0; 36 | virtual void setNoDelay() = 0; 37 | 38 | // returns false on failure 39 | virtual bool setBlocking(bool enabled) = 0; 40 | virtual int getNativeHandle() const = 0; 41 | 42 | NetworkStream(const NetworkStream&) = delete; 43 | NetworkStream& operator=(const NetworkStream&) = delete; 44 | }; 45 | 46 | } // namespace wpi 47 | 48 | #endif // WPIUTIL_TCPSOCKETS_NETWORKSTREAM_H_ 49 | -------------------------------------------------------------------------------- /athena/include/tcpsockets/SocketError.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------*/ 2 | /* Copyright (c) FIRST 2015. All Rights Reserved. */ 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ 5 | /* the project. */ 6 | /*----------------------------------------------------------------------------*/ 7 | 8 | #ifndef WPIUTIL_TCPSOCKETS_SOCKETERROR_H_ 9 | #define WPIUTIL_TCPSOCKETS_SOCKETERROR_H_ 10 | 11 | #include 12 | 13 | #ifdef _WIN32 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | namespace wpi { 20 | 21 | static inline int SocketErrno() { 22 | #ifdef _WIN32 23 | return WSAGetLastError(); 24 | #else 25 | return errno; 26 | #endif 27 | } 28 | 29 | std::string SocketStrerror(int code); 30 | 31 | static inline std::string SocketStrerror() { 32 | return SocketStrerror(SocketErrno()); 33 | } 34 | 35 | } // namespace wpi 36 | 37 | #endif // WPIUTIL_TCPSOCKETS_SOCKETERROR_H_ 38 | -------------------------------------------------------------------------------- /athena/include/tcpsockets/TCPAcceptor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/athena/include/tcpsockets/TCPAcceptor.h -------------------------------------------------------------------------------- /athena/include/tcpsockets/TCPConnector.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/athena/include/tcpsockets/TCPConnector.h -------------------------------------------------------------------------------- /athena/include/tcpsockets/TCPStream.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/athena/include/tcpsockets/TCPStream.h -------------------------------------------------------------------------------- /athena/lib/libHALAthena.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/athena/lib/libHALAthena.so -------------------------------------------------------------------------------- /athena/lib/libHALAthena.so.debug: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/athena/lib/libHALAthena.so.debug -------------------------------------------------------------------------------- /athena/lib/libntcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/athena/lib/libntcore.so -------------------------------------------------------------------------------- /athena/lib/libntcore.so.debug: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/athena/lib/libntcore.so.debug -------------------------------------------------------------------------------- /athena/lib/libwpiutil.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/athena/lib/libwpiutil.so -------------------------------------------------------------------------------- /athena/lib/libwpiutil.so.debug: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/athena/lib/libwpiutil.so.debug -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | fn main() { 4 | for lib in ["HALAthena", 5 | "wpiutil", 6 | "FRC_NetworkCommunication", 7 | "RoboRIO_FRC_ChipObject", 8 | "NiFpga", 9 | "NiFpgaLv", 10 | "niriosession", 11 | "spi", 12 | "i2c", 13 | "visa", 14 | "NiRioSrv", 15 | "niriodevenum"] 16 | .iter() { 17 | println!("cargo:rustc-link-lib=dylib={}", lib); 18 | } 19 | 20 | let path = env::current_dir().unwrap(); 21 | 22 | println!("cargo:rustc-link-search=native={}/ni-libraries", path.display()); 23 | println!("cargo:rustc-link-search=native={}/athena/lib", path.display()); 24 | } 25 | -------------------------------------------------------------------------------- /examples/test_robot.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate wpilib; 3 | use wpilib::*; 4 | 5 | struct TestRobot; 6 | 7 | impl Robot for TestRobot { 8 | fn run(self) { 9 | println!("Running!"); 10 | let mut stick = Joystick::new(0); 11 | loop { 12 | println!("{:?}", stick.get_raw_axis(1)); 13 | println!("{:?}", fpga::get_time_us()); 14 | } 15 | } 16 | 17 | fn new() -> TestRobot { 18 | TestRobot {} 19 | } 20 | } 21 | 22 | fn main() { 23 | TestRobot::main(); 24 | } 25 | -------------------------------------------------------------------------------- /ni-libraries/libFRC_NetworkCommunication.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libFRC_NetworkCommunication.so -------------------------------------------------------------------------------- /ni-libraries/libNiFpga.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libNiFpga.so -------------------------------------------------------------------------------- /ni-libraries/libNiFpgaLv.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libNiFpgaLv.so -------------------------------------------------------------------------------- /ni-libraries/libNiRioSrv.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libNiRioSrv.so -------------------------------------------------------------------------------- /ni-libraries/libRoboRIO_FRC_ChipObject.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libRoboRIO_FRC_ChipObject.so -------------------------------------------------------------------------------- /ni-libraries/libi2c.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libi2c.so -------------------------------------------------------------------------------- /ni-libraries/libniriodevenum.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libniriodevenum.so -------------------------------------------------------------------------------- /ni-libraries/libniriosession.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libniriosession.so -------------------------------------------------------------------------------- /ni-libraries/libspi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libspi.so -------------------------------------------------------------------------------- /ni-libraries/libvisa.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotrs/rust-wpilib/f80b21c089439c4c32b1ba88ebdd7d0d3920d416/ni-libraries/libvisa.so -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! # Rust WPILib 2 | //! This is a port of the WPILib library for FIRST Robotics Competition (FRC) to Rust. It is still 3 | //! very much a work in progress, and much of its functionality is untested. It is *not 4 | //! recommmended* to use this library in a competition setting. 5 | 6 | #![allow(dead_code)] 7 | #![deny(missing_docs)] 8 | 9 | extern crate atom; 10 | 11 | #[macro_use] 12 | mod wpilib; 13 | pub use wpilib::*; 14 | -------------------------------------------------------------------------------- /src/wpilib/digital_input.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | use wpilib::hal_call::*; 3 | use wpilib::sensor; 4 | use wpilib::usage::*; 5 | 6 | /// A digital input used to read boolean sensors from the RoboRIO. 7 | pub struct DigitalInput { 8 | channel: i32, 9 | handle: HAL_DigitalHandle, 10 | } 11 | 12 | impl DigitalInput { 13 | /// Create a new digital input on the specificed channel, returning an error if initialization 14 | /// fails. 15 | pub fn new(channel: i32) -> HalResult { 16 | if !sensor::check_digital_channel(channel) { 17 | return Err(HalError(0)); 18 | } 19 | 20 | let handle = hal_call!(HAL_InitializeDIOPort(HAL_GetPort(channel), true as i32))?; 21 | 22 | report_usage(ResourceType::DigitalInput, channel); 23 | 24 | Ok(DigitalInput { 25 | channel: channel, 26 | handle: handle, 27 | }) 28 | } 29 | 30 | /// Read from the digital input. 31 | pub fn get(&self) -> HalResult { 32 | Ok(hal_call!(HAL_GetDIO(self.handle))? != 0) 33 | } 34 | 35 | /// Get the channel for this DIO. 36 | pub fn get_channel(&self) -> i32 { 37 | self.channel 38 | } 39 | 40 | /// Get a handle to this DIO. 41 | pub fn get_handle(&self) -> HAL_Handle { 42 | self.handle 43 | } 44 | } 45 | 46 | impl Drop for DigitalInput { 47 | fn drop(&mut self) { 48 | unsafe { 49 | HAL_FreeDIOPort(self.handle); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/wpilib/digital_output.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | use wpilib::hal_call::*; 3 | use wpilib::sensor; 4 | use wpilib::usage::*; 5 | 6 | /// A digital output used to control lights, etc from the RoboRIO. 7 | pub struct DigitalOutput { 8 | channel: i32, 9 | handle: HAL_DigitalHandle, 10 | pwm: Option, 11 | } 12 | 13 | impl DigitalOutput { 14 | /// Create a new digital output on the specificed channel, returning an error if initialization 15 | /// fails. 16 | pub fn new(channel: i32) -> HalResult { 17 | if !sensor::check_digital_channel(channel) { 18 | return Err(HalError(0)); 19 | } 20 | 21 | let handle = hal_call!(HAL_InitializeDIOPort(HAL_GetPort(channel), false as i32))?; 22 | 23 | report_usage(ResourceType::DigitalOutput, channel); 24 | 25 | Ok(DigitalOutput { 26 | channel: channel, 27 | handle: handle, 28 | pwm: None, 29 | }) 30 | } 31 | 32 | /// Set the PWM rate for this output, from 0.6Hz to 19kHz. Will return an error if PWM has not 33 | /// been enabled. All digital channels will use the same PWM rate. 34 | pub fn set_pwm_rate(rate: f64) -> HalResult<()> { 35 | hal_call!(HAL_SetDigitalPWMRate(rate)) 36 | } 37 | 38 | /// Set the value to output. 39 | pub fn set(&mut self, value: bool) -> HalResult<()> { 40 | hal_call!(HAL_SetDIO(self.handle, value as i32)) 41 | } 42 | 43 | /// Get the previously-written output. 44 | pub fn get(&self) -> HalResult { 45 | Ok(hal_call!(HAL_GetDIO(self.handle))? != 0) 46 | } 47 | 48 | /// Get the channel for this DIO. 49 | pub fn get_channel(&self) -> i32 { 50 | self.channel 51 | } 52 | 53 | /// Get a handle to this DIO. 54 | pub fn get_handle(&self) -> HAL_DigitalHandle { 55 | self.handle 56 | } 57 | 58 | /// Write a pulse to this output. 59 | pub fn pulse(&mut self, length: f64) -> HalResult<()> { 60 | hal_call!(HAL_Pulse(self.handle, length)) 61 | } 62 | 63 | /// Is this output currently in the middle of a pulse? 64 | pub fn is_pulsing(&self) -> HalResult { 65 | Ok(hal_call!(HAL_IsPulsing(self.handle))? != 0) 66 | } 67 | 68 | /// Enable PWM for this output. 69 | pub fn enable_pwm(&mut self, initial_duty_cycle: f64) -> HalResult<()> { 70 | let pwm = hal_call!(HAL_AllocateDigitalPWM())?; 71 | hal_call!(HAL_SetDigitalPWMDutyCycle(pwm, initial_duty_cycle))?; 72 | hal_call!(HAL_SetDigitalPWMOutputChannel(pwm, self.channel))?; 73 | self.pwm = Some(pwm); 74 | Ok(()) 75 | } 76 | 77 | /// Turn off PWM for this output. 78 | pub fn disable_pwm(&mut self) -> HalResult<()> { 79 | if let Some(pwm) = self.pwm { 80 | hal_call!(HAL_SetDigitalPWMOutputChannel(pwm, sensor::num_digital_channels()))?; 81 | hal_call!(HAL_FreeDigitalPWM(pwm))?; 82 | self.pwm = None; 83 | } 84 | Ok(()) 85 | } 86 | 87 | /// Set a new duty cycle to use in PWM on this output. 88 | pub fn update_duty_cycle(&mut self, duty_cycle: f64) -> HalResult<()> { 89 | if let Some(pwm) = self.pwm { 90 | hal_call!(HAL_SetDigitalPWMDutyCycle(pwm, duty_cycle)) 91 | } else { 92 | Ok(()) 93 | } 94 | } 95 | } 96 | 97 | impl Drop for DigitalOutput { 98 | fn drop(&mut self) { 99 | let _ = self.disable_pwm(); 100 | unsafe { 101 | HAL_FreeDIOPort(self.handle); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/wpilib/encoder.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | use wpilib::hal_call::*; 3 | use wpilib::digital_input::DigitalInput; 4 | use wpilib::usage::*; 5 | use std::ptr; 6 | use std::mem; 7 | 8 | /// The indexing type for an encoder 9 | pub enum IndexingType { 10 | ResetWhileHigh, 11 | ResetWhileLow, 12 | ResetOnFallingEdge, 13 | ResetOnRisingEdge, 14 | } 15 | 16 | /// An encoder. 17 | /// 18 | /// Uses quadrature on two separate channels to read the distance and direction travelled by a 19 | /// shaft. All integration is done by the FPGA. 20 | pub struct Encoder { 21 | source_a: DigitalInput, 22 | source_b: DigitalInput, 23 | source_index: Option, 24 | encoder: HAL_EncoderHandle, 25 | } 26 | 27 | impl Encoder { 28 | /// Create a new encoder given two channels and an encoding type, returning an error if 29 | /// initialization fails. 30 | pub fn new(channel_a: i32, 31 | channel_b: i32, 32 | encoding: HAL_EncoderEncodingType) 33 | -> HalResult { 34 | let source_a = DigitalInput::new(channel_a)?; 35 | let source_b = DigitalInput::new(channel_b)?; 36 | 37 | let handle = hal_call!(HAL_InitializeEncoder(source_a.get_handle(), 38 | mem::transmute(0), 39 | source_b.get_handle(), 40 | mem::transmute(0), 41 | false as i32, 42 | encoding))?; 43 | let encoder = Encoder { 44 | source_a: source_a, 45 | source_b: source_b, 46 | source_index: None, 47 | encoder: handle, 48 | }; 49 | 50 | report_usage_extras(ResourceType::Encoder, 51 | encoder.get_fpga_index()?, 52 | encoding as i32, 53 | ptr::null()); 54 | 55 | Ok(encoder) 56 | } 57 | 58 | /// Get the FPGA index of this encoder. 59 | pub fn get_fpga_index(&self) -> HalResult { 60 | hal_call!(HAL_GetEncoderFPGAIndex(self.encoder)) 61 | } 62 | 63 | /// Get the current value read by this encoder, with any scaling factors applied. 64 | pub fn get(&self) -> HalResult { 65 | hal_call!(HAL_GetEncoder(self.encoder)) 66 | } 67 | 68 | /// Get the raw value of this encoder, without any scaling factors. 69 | pub fn get_raw(&self) -> HalResult { 70 | hal_call!(HAL_GetEncoderRaw(self.encoder)) 71 | } 72 | 73 | /// Get the current scaling factor for this encoder. 74 | pub fn get_encoding_scale(&self) -> HalResult { 75 | hal_call!(HAL_GetEncoderEncodingScale(self.encoder)) 76 | } 77 | 78 | /// Get the current (estimated) speed this encoder is travelling at. 79 | pub fn get_rate(&self) -> HalResult { 80 | hal_call!(HAL_GetEncoderRate(self.encoder)) 81 | } 82 | 83 | /// Set the minimum rate that this encoder must be moving at to be considered "moving". 84 | pub fn set_min_rate(&mut self, min_rate: f64) -> HalResult<()> { 85 | hal_call!(HAL_SetEncoderMinRate(self.encoder, min_rate)) 86 | } 87 | 88 | /// Reset the count of this encoder. 89 | pub fn reset(&mut self) -> HalResult<()> { 90 | hal_call!(HAL_ResetEncoder(self.encoder)) 91 | } 92 | } 93 | 94 | impl Drop for Encoder { 95 | fn drop(&mut self) { 96 | hal_call!(HAL_FreeEncoder(self.encoder)).unwrap(); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/wpilib/fpga.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | use wpilib::hal_call::*; 3 | 4 | /// Gets the FPGA version 5 | pub fn version() -> i32 { 6 | hal_call!(HAL_GetFPGAVersion()).unwrap() 7 | } 8 | 9 | /// Gets the FPGA revision 10 | pub fn revision() -> i64 { 11 | hal_call!(HAL_GetFPGARevision()).unwrap() 12 | } 13 | 14 | /// Gets the FPGA time in microseconds since the FPGA reset. Rolls over after 71 minutes. 15 | pub fn get_time_us() -> u64 { 16 | hal_call!(HAL_GetFPGATime()).unwrap() 17 | } 18 | 19 | /// Is the button on the RoboRIO pressed down? 20 | pub fn user_button_down() -> bool { 21 | hal_call!(HAL_GetFPGAButton()).unwrap() != 0 22 | } 23 | -------------------------------------------------------------------------------- /src/wpilib/hal_call.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | use std::{ffi, fmt}; 3 | 4 | #[derive(Copy, Clone)] 5 | pub struct HalError(pub i32); 6 | 7 | impl From for HalError { 8 | fn from(code: i32) -> Self { 9 | HalError(code) 10 | } 11 | } 12 | 13 | impl fmt::Debug for HalError { 14 | fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { 15 | let error_string = unsafe { ffi::CStr::from_ptr(HAL_GetErrorMessage(self.0)) }; 16 | write!(f, "HalError {{ {} }}", error_string.to_str().unwrap()) 17 | } 18 | } 19 | 20 | pub type HalResult = Result; 21 | 22 | // impl HalError { 23 | // pub fn unwrap(self) -> T { 24 | // match self { 25 | // Ok(value) => value, 26 | // Err(code) => { 27 | // let error_string = unsafe { ffi::CStr::from_ptr(HAL_GetErrorMessage(code)) }; 28 | // panic!("{}", error_string.as_str()); 29 | // } 30 | // } 31 | // } 32 | // } 33 | 34 | #[macro_export] 35 | macro_rules! hal_call { 36 | ($function:ident($($arg:expr),*)) => {{ 37 | let mut status = 0; 38 | let result = unsafe { $function($( 39 | $arg, 40 | )* &mut status as *mut i32) }; 41 | if status == 0 { Ok(result) } else { Err(HalError::from(status)) } 42 | }}; 43 | ($namespace:path, $function:ident($($arg:expr),*)) => {{ 44 | let mut status = 0; 45 | let result = unsafe { $namespace::$function($( 46 | $arg, 47 | )* &mut status as *mut i32) }; 48 | if status == 0 { Ok(result) } else { Err(HalError::from(status)) } 49 | }}; 50 | } 51 | -------------------------------------------------------------------------------- /src/wpilib/mod.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | mod robot; 3 | pub use self::robot::*; 4 | 5 | #[macro_use] 6 | mod hal_call; 7 | 8 | mod wpilib_hal; 9 | 10 | mod driverstation; 11 | pub use self::driverstation::DriverStation; 12 | 13 | mod throttler; 14 | pub use self::throttler::Throttler; 15 | 16 | /// Useful FPGA functions 17 | pub mod fpga; 18 | 19 | mod timer; 20 | pub use self::timer::*; 21 | 22 | /// Sensor info funcitons 23 | pub mod sensor; 24 | 25 | mod digital_input; 26 | pub use self::digital_input::DigitalInput; 27 | 28 | mod digital_output; 29 | pub use self::digital_output::DigitalOutput; 30 | 31 | mod encoder; 32 | pub use self::encoder::Encoder; 33 | 34 | mod pdp; 35 | pub use self::pdp::PowerDistributionPanel; 36 | 37 | /// Functions for information about the robot's state that are not contained anywhere else. 38 | pub mod robot_state; 39 | 40 | mod analog_input; 41 | pub use self::analog_input::AnalogInput; 42 | 43 | mod spi; 44 | pub use self::spi::SpiInterface; 45 | 46 | mod interrupt; 47 | pub use self::interrupt::Interrupt; 48 | 49 | mod pwm; 50 | pub use self::pwm::Pwm; 51 | 52 | pub mod usage; 53 | 54 | mod speed_controller; 55 | pub use self::speed_controller::*; 56 | 57 | mod pwm_speed_controller; 58 | pub use self::pwm_speed_controller::*; 59 | 60 | /// i2c communication 61 | mod i2c; 62 | pub use self::i2c::*; 63 | 64 | /// defines all joystick related traits and structs 65 | pub mod joystick; 66 | pub use self::joystick::*; 67 | -------------------------------------------------------------------------------- /src/wpilib/pdp.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | use wpilib::hal_call::*; 3 | use wpilib::usage::*; 4 | use wpilib::sensor; 5 | 6 | /// An interface to the PDP for getting information about robot power. 7 | pub struct PowerDistributionPanel { 8 | module: i32, 9 | } 10 | 11 | impl PowerDistributionPanel { 12 | /// Create a new PDP interface on the specified module. 13 | pub fn new(module: i32) -> HalResult { 14 | hal_call!(HAL_InitializePDP(module))?; 15 | report_usage(ResourceType::PDP, module); 16 | Ok(PowerDistributionPanel { module: module }) 17 | } 18 | 19 | /// Use the default module (0). 20 | pub fn default() -> HalResult { 21 | PowerDistributionPanel::new(0) 22 | } 23 | 24 | /// Get the voltage going into the PDP. 25 | pub fn get_voltage(&self) -> HalResult { 26 | hal_call!(HAL_GetPDPVoltage(self.module)) 27 | } 28 | 29 | /// Get the PDP's temperature, in degrees Celsius. 30 | pub fn get_temperature(&self) -> HalResult { 31 | hal_call!(HAL_GetPDPTemperature(self.module)) 32 | } 33 | 34 | /// Get the current on a specific channel on the PDP, in amps. 35 | pub fn get_current(&self, channel: i32) -> HalResult { 36 | if !sensor::check_pdp_channel(channel) { 37 | return Err(HalError(0)); 38 | } 39 | 40 | hal_call!(HAL_GetPDPChannelCurrent(self.module, channel)) 41 | } 42 | 43 | /// Get the total current drawn from the PDP, in amps. 44 | pub fn get_total_current(&self) -> HalResult { 45 | hal_call!(HAL_GetPDPTotalCurrent(self.module)) 46 | } 47 | 48 | /// Get the total power drawn from the PDP, in watts. 49 | pub fn get_total_power(&self) -> HalResult { 50 | hal_call!(HAL_GetPDPTotalPower(self.module)) 51 | } 52 | 53 | /// Get the total energy expended by the PDP, in joules. 54 | pub fn get_total_energy(&self) -> HalResult { 55 | hal_call!(HAL_GetPDPTotalEnergy(self.module)) 56 | } 57 | 58 | /// Reset the total energy count so far to zero. 59 | pub fn reset_total_energy(&mut self) -> HalResult<()> { 60 | hal_call!(HAL_ResetPDPTotalEnergy(self.module)) 61 | } 62 | 63 | /// Clear sticky faults in the PDP. 64 | pub fn clear_sticky_faults(&mut self) -> HalResult<()> { 65 | hal_call!(HAL_ClearPDPStickyFaults(self.module)) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/wpilib/robot.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | 3 | /// The base class from which all robots should be derived. 4 | /// 5 | /// # Usage 6 | /// 7 | /// ``` 8 | /// struct TestRobot {}; 9 | /// 10 | /// impl Robot for TestRobot { 11 | /// fn new() -> TestRobot { 12 | /// TestRobot{} 13 | /// } 14 | /// 15 | /// fn run(self) { 16 | /// // Do something... 17 | /// } 18 | /// } 19 | /// 20 | /// fn main() { 21 | /// TestRobot::main(); 22 | /// } 23 | /// ``` 24 | pub trait Robot: Sized { 25 | /// Run the robot class. This will be called once, at the beginning of the program, after 26 | /// initialization. 27 | fn run(self); 28 | 29 | /// Create an instance of the robot class. 30 | fn new() -> Self; 31 | 32 | /// Run the robot statically. 33 | fn main() { 34 | // Initialize HAL 35 | unsafe { 36 | let status = HAL_Initialize(0); 37 | if status != 1 { 38 | panic!("WPILib HAL failed to initialize!"); 39 | } 40 | } 41 | let robot = Self::new(); 42 | robot.run(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/wpilib/robot_state.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | use wpilib::hal_call::*; 3 | 4 | /// Is the robot browned out? 5 | pub fn is_browned_out() -> HalResult { 6 | Ok(hal_call!(HAL_GetBrownedOut())? != 0) 7 | } 8 | 9 | /// Are outputs enabled? A result of false here could be caused by a disabled robot or a brownout. 10 | pub fn is_system_active() -> HalResult { 11 | Ok(hal_call!(HAL_GetSystemActive())? != 0) 12 | } 13 | 14 | /// Get the robot's current battery voltage. 15 | pub fn get_battery_voltage() -> HalResult { 16 | hal_call!(HAL_GetVinVoltage()) 17 | } 18 | -------------------------------------------------------------------------------- /src/wpilib/sensor.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | 3 | /// The number of DIOs on the RoboRIO. 4 | pub fn num_digital_channels() -> i32 { 5 | unsafe { HAL_GetNumDigitalChannels() } 6 | } 7 | 8 | /// The number of analog inputs on the RoboRIO. 9 | pub fn num_analog_inputs() -> i32 { 10 | unsafe { HAL_GetNumAnalogInputs() } 11 | } 12 | 13 | /// The number of solenoid channels per PCM. 14 | pub fn num_solenoid_channels() -> i32 { 15 | unsafe { HAL_GetNumSolenoidChannels() } 16 | } 17 | 18 | /// The number of PCMs. 19 | pub fn num_solenoid_modules() -> i32 { 20 | unsafe { HAL_GetNumPCMModules() } 21 | } 22 | 23 | /// The number of hardware PWM channels on the RoboRIO. 24 | pub fn num_pwm_channels() -> i32 { 25 | unsafe { HAL_GetNumPWMChannels() } 26 | } 27 | 28 | /// The number of relay headers on the RoboRIO. 29 | pub fn num_relay_headers() -> i32 { 30 | unsafe { HAL_GetNumRelayHeaders() } 31 | } 32 | 33 | /// Check if a solenoid module is valid. 34 | pub fn check_solenoid_module(module: i32) -> bool { 35 | unsafe { HAL_CheckSolenoidModule(module) != 0 } 36 | } 37 | 38 | /// Check if a digital channel is valid. 39 | pub fn check_digital_channel(channel: i32) -> bool { 40 | unsafe { HAL_CheckDIOChannel(channel) != 0 } 41 | } 42 | 43 | /// Check if a relay channel is valid. 44 | pub fn check_relay_channel(channel: i32) -> bool { 45 | unsafe { HAL_CheckRelayChannel(channel) != 0 } 46 | } 47 | 48 | /// Check if a PWM channel is valid. 49 | pub fn check_pwm_channel(channel: i32) -> bool { 50 | unsafe { HAL_CheckPWMChannel(channel) != 0 } 51 | } 52 | 53 | /// Check if an analog input channel is valid. 54 | pub fn check_analog_input_channel(channel: i32) -> bool { 55 | unsafe { HAL_CheckAnalogInputChannel(channel) != 0 } 56 | } 57 | 58 | /// Check if an analog output channel is valid. 59 | pub fn check_analog_output_channel(channel: i32) -> bool { 60 | unsafe { HAL_CheckAnalogOutputChannel(channel) != 0 } 61 | } 62 | 63 | /// Check if a solenoid channel is valid. 64 | pub fn check_solenoid_channel(channel: i32) -> bool { 65 | unsafe { HAL_CheckSolenoidChannel(channel) != 0 } 66 | } 67 | 68 | /// Check if a PDP channel is valid. 69 | pub fn check_pdp_channel(channel: i32) -> bool { 70 | unsafe { HAL_CheckPDPModule(channel) != 0 } 71 | } 72 | -------------------------------------------------------------------------------- /src/wpilib/speed_controller.rs: -------------------------------------------------------------------------------- 1 | /// A generic interface to a speed controller with support for inverting the motor in case of a 2 | /// backwards motor. 3 | pub trait SpeedController { 4 | /// Set the speed for the speed controller to run at, from [-1, 1]. 5 | fn set(&mut self, speed: f64); 6 | /// Get the previously set speed. 7 | fn get(&self) -> f64; 8 | 9 | /// Set whether or not this speed controller should run backwards. 10 | fn invert(&mut self, inverted: bool); 11 | /// Get the previously set inversion value. 12 | fn is_inverted(&self) -> bool; 13 | 14 | /// Temporarily disable the speed controller. 15 | fn disable(&mut self); 16 | } 17 | -------------------------------------------------------------------------------- /src/wpilib/spi.rs: -------------------------------------------------------------------------------- 1 | use wpilib::wpilib_hal::*; 2 | use wpilib::hal_call::*; 3 | use wpilib::usage::*; 4 | use std::mem; 5 | 6 | #[repr(C)] 7 | #[derive(Debug, Copy, Clone)] 8 | /// Some SPI port on the RoboRIO 9 | pub enum SpiPort { 10 | Onboard0 = 0, 11 | Onboard1 = 1, 12 | Onboard2 = 2, 13 | Onboard3 = 3, 14 | MXP = 4, 15 | } 16 | 17 | /// An interface to the SPI bus 18 | pub struct SpiInterface { 19 | port: i32, 20 | } 21 | 22 | impl SpiInterface { 23 | /// Create a new SPI interface on the specified port, returning an error if the initialization 24 | /// fails. 25 | pub fn new(port: SpiPort) -> HalResult { 26 | let port = port as i32; 27 | hal_call!(HAL_InitializeSPI(port))?; 28 | 29 | report_usage(ResourceType::SPI, port); 30 | 31 | Ok(SpiInterface { port: port }) 32 | } 33 | 34 | /// Do a transaction on the SPI interface. `send` and `receive` must have the same length or 35 | /// the transaction will fail. Return the number of bytes read, or `None` if the transaction 36 | /// failed. 37 | pub fn transaction(&mut self, send: &[u8], receive: &mut [u8]) -> Option { 38 | if send.len() != receive.len() { 39 | return None; 40 | } 41 | 42 | let result = unsafe { 43 | HAL_TransactionSPI(self.port, 44 | mem::transmute(&send[0] as *const u8), 45 | &mut receive[0] as *mut u8, 46 | send.len() as i32) 47 | }; 48 | match result { 49 | -1 => None, 50 | b => Some(b), 51 | } 52 | } 53 | 54 | /// Write to the SPI interface and return the number of bytes written, or `None` for a failed 55 | /// write. 56 | pub fn write(&mut self, data: &[u8]) -> Option { 57 | let result = unsafe { 58 | HAL_WriteSPI(self.port, 59 | mem::transmute(&data[0] as *const u8), 60 | data.len() as i32) 61 | }; 62 | match result { 63 | -1 => None, 64 | b => Some(b), 65 | } 66 | } 67 | 68 | /// Initate a read sequence by putting a 0 in the transmit buffer and doing a transfer. 69 | pub fn initiate_read(&mut self, buffer: &mut [u8]) -> Option { 70 | let send = vec![0; buffer.len()]; 71 | self.transaction(&send, buffer) 72 | } 73 | 74 | /// Returns the number of bytes read from the receive queue (filled as a response to a previous 75 | /// write), or waits for the current transfer to complete if the queue is empty. If you want to 76 | /// initiate reading yourself, you probably want initiate_read. 77 | pub fn read(&self, data: &mut [u8]) -> Option { 78 | let result = unsafe { HAL_ReadSPI(self.port, &mut data[0] as *mut u8, data.len() as i32) }; 79 | match result { 80 | -1 => None, 81 | b => Some(b), 82 | } 83 | } 84 | 85 | /// Set the SPI clock rate, up to 4MHz 86 | pub fn set_clock_rate(&mut self, rate: i32) { 87 | unsafe { 88 | HAL_SetSPISpeed(self.port, rate); 89 | } 90 | } 91 | } 92 | 93 | impl Drop for SpiInterface { 94 | fn drop(&mut self) { 95 | unsafe { 96 | HAL_CloseSPI(self.port); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/wpilib/throttler.rs: -------------------------------------------------------------------------------- 1 | // use std::ops::Add; 2 | 3 | /// Handles only doing some task once per set interval. 4 | pub struct Throttler { 5 | next_send: T, 6 | interval: S, 7 | } 8 | 9 | // impl Throttler 10 | // where T: Add + PartialOrd, >::Output = T 11 | impl Throttler { 12 | /// Create a new throttler. 13 | pub fn new(now: f64, interval: f64) -> Throttler { 14 | Throttler { 15 | next_send: now + interval, 16 | interval: interval, 17 | } 18 | } 19 | 20 | /// Update the throttler. Returns true if the task should be performed. 21 | pub fn update(&mut self, now: f64) -> bool { 22 | if now > self.next_send { 23 | self.next_send = self.next_send + self.interval; 24 | true 25 | } else { 26 | false 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/wpilib/timer.rs: -------------------------------------------------------------------------------- 1 | use wpilib::fpga; 2 | 3 | /// Gets the FPGA time in seconds since the FPGA reset 4 | pub fn get_time_seconds() -> f64 { 5 | fpga::get_time_us() as f64 * 1e-6 6 | } 7 | 8 | /// A timer that can be paused and reset 9 | pub struct Timer { 10 | start_time: f64, 11 | accumulated_time: f64, 12 | running: bool, 13 | } 14 | 15 | impl Timer { 16 | /// Create a new timer with zero time on the clock. The timer will not start running until 17 | /// start() is called. 18 | pub fn new() -> Timer { 19 | Timer { 20 | start_time: 0f64, 21 | accumulated_time: 0f64, 22 | running: false, 23 | } 24 | } 25 | 26 | /// Create a new timer that will immediately begin running. 27 | pub fn new_running() -> Timer { 28 | Timer { 29 | start_time: get_time_seconds(), 30 | accumulated_time: 0f64, 31 | running: true, 32 | } 33 | } 34 | 35 | /// Start the timer. 36 | pub fn start(&mut self) { 37 | self.start_time = get_time_seconds(); 38 | self.running = true; 39 | self.accumulated_time = 0f64; 40 | } 41 | 42 | /// Get the elapsed time in seconds. 43 | pub fn get(&self) -> f64 { 44 | if self.running { 45 | get_time_seconds() - self.start_time 46 | } else { 47 | self.accumulated_time 48 | } 49 | } 50 | 51 | /// Stop the clock and freeze the elapsed time. 52 | pub fn stop(&mut self) { 53 | self.accumulated_time = self.get(); 54 | self.running = false; 55 | self.start_time = 0f64; 56 | } 57 | 58 | /// Reset the elapsed time to zero. 59 | pub fn reset(&mut self) { 60 | self.start_time = get_time_seconds(); 61 | self.accumulated_time = 0f64; 62 | } 63 | 64 | /// Has some period of time passed on the clock? 65 | pub fn has_period_passed(&self, time: f64) -> bool { 66 | self.get() > time 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/wpilib/usage.rs: -------------------------------------------------------------------------------- 1 | #![allow(missing_docs)] 2 | 3 | use wpilib::wpilib_hal::*; 4 | use std::ptr; 5 | use std::os::raw; 6 | 7 | #[repr(C)] 8 | #[derive(Debug, Copy, Clone)] 9 | pub enum ResourceType { 10 | Controller = 0, 11 | Module = 1, 12 | Language = 2, 13 | CANPlugin = 3, 14 | Accelerometer = 4, 15 | ADXL345 = 5, 16 | AnalogChannel = 6, 17 | AnalogTrigger = 7, 18 | AnalogTriggerOutput = 8, 19 | CANJaguar = 9, 20 | Compressor = 10, 21 | Counter = 11, 22 | Dashboard = 12, 23 | DigitalInput = 13, 24 | DigitalOutput = 14, 25 | DriverStationCIO = 15, 26 | DriverStationEIO = 16, 27 | DriverStationLCD = 17, 28 | Encoder = 18, 29 | GearTooth = 19, 30 | Gyro = 20, 31 | I2C = 21, 32 | Framework = 22, 33 | Jaguar = 23, 34 | Joystick = 24, 35 | Kinect = 25, 36 | KinectStick = 26, 37 | PIDController = 27, 38 | Preferences = 28, 39 | PWM = 29, 40 | Relay = 30, 41 | RobotDrive = 31, 42 | SerialPort = 32, 43 | Servo = 33, 44 | Solenoid = 34, 45 | SPI = 35, 46 | Task = 36, 47 | Ultrasonic = 37, 48 | Victor = 38, 49 | Button = 39, 50 | Command = 40, 51 | AxisCamera = 41, 52 | PCVideoServer = 42, 53 | SmartDashboard = 43, 54 | Talon = 44, 55 | HiTechnicColorSensor = 45, 56 | HiTechnicAccel = 46, 57 | HiTechnicCompass = 47, 58 | SRF08 = 48, 59 | AnalogOutput = 49, 60 | VictorSP = 50, 61 | TalonSRX = 51, 62 | CANTalonSRX = 52, 63 | ADXL362 = 53, 64 | ADXRS450 = 54, 65 | RevSPARK = 55, 66 | MindsensorsSD540 = 56, 67 | DigitalFilter = 57, 68 | ADIS16448 = 58, 69 | PDP = 59, 70 | PCM = 60, 71 | PigeonIMU = 61, 72 | } 73 | 74 | pub const LANGUAGE_RUST: i32 = 6; 75 | 76 | /// Report the usage of a specific resource type with an `instance` value attached. 77 | pub fn report_usage(resource: ResourceType, instance: i32) { 78 | unsafe { 79 | HAL_Report(resource as i32, instance, 0, ptr::null()); 80 | } 81 | } 82 | 83 | /// Just a safe wrapper around HAL_Report 84 | pub fn report_usage_extras(resource: ResourceType, 85 | instance: i32, 86 | context: i32, 87 | feature: *const raw::c_char) { 88 | unsafe { 89 | HAL_Report(resource as i32, instance, context, feature); 90 | } 91 | } 92 | --------------------------------------------------------------------------------