Compare commits

...

110 Commits

Author SHA1 Message Date
Peter Johnson
e375b4a9ff CameraServer: auto-increment startAutomaticCapture(). (#468)
Also add GetServer() functions so the automatically created VideoSink can
be retrieved by user code if desired.
2017-01-20 01:07:37 -07:00
Thad House
ff141ab1ff Fixes exception on camera creation without plugged in camera (#470)
Would throw if the camera was disconnected. We handle this properly at
the JNI level to not have this crash the entire program, but the error
is still kind of annoying, and not really an error.
2017-01-20 01:02:27 -07:00
Peter Johnson
b8537be219 CameraServer: Remove NT-driven settings. (#467)
Unfortunately, due to the way NT synchronization is currently performed,
this has unexpected and undesirable behavior: when a dashboard (or any other
NT client) is left running between code restarts, when it reconnects, any
code settings will be overwritten by the NT synchronization process.  As
fixing this will require a fairly major NT change (and likely a user-visible
one), it's not desirable to do at this point in the year.

Instead, disable NT driven settings entirely (e.g. make the NT interface
publish only).  To emphasize the read-only nature of the NT values, attempts
to change the NT values will be immediately overridden by CameraServer.

To better inform users about the actual property names (e.g. for use in their
code), the "raw_" settings no longer have "raw_" removed from their names
(they are still placed in the "RawProperty" subtable).

This change also contains a couple of Java fixes:

* Make getInstance() thread-safe

* Properly synchronize access to m_tables between multiple threads.

* Use Hashtable instead of HashMap.
2017-01-19 12:30:07 -07:00
Austin Shalit
8f1b034b2f Fix typo in JavaDoc (#462) 2017-01-16 22:57:28 -07:00
Thad House
71d0a07e0a Fixes solenoid allocation error message (#455)
The error was NO_AVAILABLE_RESOURCES, which is not the proper error to
return. Instead,  just return the error directly from the allocation.
2017-01-14 23:59:05 -07:00
sciencewhiz
d322342494 Remove comments about Blue DS (#450)
It's unlikely that anyone is still using the Blue Kwikbyte DS from 2009,
and the reference is confusing to people who weren't around then.
2017-01-14 23:52:48 -07:00
Peter Johnson
bc7ab17692 CameraServer updates (#446)
* CameraServer: Add properties and video mode NT interchange.

* Automatically serve Axis cameras so they're accessible via USB.
2017-01-05 02:51:55 -08:00
Tyler Veness
7a049c29bd Added a conditional command that chooses 1 of 2 commands (#435)
Tests and documentation for ConditionalCommand were also added. This is a fixed version of #9, so it doesn't support lambdas.

Closes #9
2017-01-04 23:48:13 -08:00
Thad House
1fc375b31a Updates the gradle wrapper to version 3.3 (#445) 2017-01-04 22:08:48 -08:00
Austin Shalit
eee7f3991c Allow VisionRunner to stop (#442) 2017-01-04 19:41:07 -08:00
Thad House
2e3503517d Add OS level serial port (#426) 2017-01-04 19:38:17 -08:00
Austin Shalit
15e58acc76 Java SendableChooser no longer sets a default on addObject (#441) 2017-01-03 19:13:45 -08:00
Austin Shalit
5aa5e3e09e SendableChooser generic value (#433)
* Java SendableChooser now decorates with type (non-breaking change)

* C++ SendableChooser now is templated on the type instead of using void* and stores values (breaking change)

* C++ SendableChooser now uses llvm::StringMap instead of std::map
2017-01-03 14:40:31 -08:00
Tyler Veness
25ae7b2c2b Upgraded Doxygen gradle plugin to 0.3 (#440) 2017-01-02 10:03:37 -08:00
Tyler Veness
4b6dc9583a Corrected order of access specifiers in MockCommand class (#436) 2017-01-02 00:44:35 -08:00
Thad House
64eab1f7b3 Fixes missing Extern "C" from HAL Threads (#437)
Also fixes incorrect return value during set
2017-01-02 00:43:12 -08:00
Thad House
182f57216f Adds project and classpath ignores (#425)
VsCode now supports Java, but it creates these files, and there is no
way to turn it off. Will be adding this to a few other repos too.
2017-01-01 00:08:13 -08:00
Tyler Veness
65b091a39a Call SmartDashboard::init() in RobotBase constructor. (#428)
Fixes #427
2017-01-01 00:07:22 -08:00
Austin Shalit
ed1a94531a Update license headers to 2017 (#434) 2017-01-01 00:05:57 -08:00
Fred Silberberg
4e12ffb0ae Update the wpilib version plugin (#423) 2016-12-25 23:01:03 -08:00
Peter Johnson
4800c201e4 Add Axis camera creation functions and Http camera NT publishing. (#420) 2016-12-24 21:05:08 -06:00
Thad House
dc9a9e5d96 Fixes typo in SensorBase error message (#422) 2016-12-24 21:04:32 -06:00
Thad House
6844f05c3d Adds SetAllSolenoids function to CTRE PCM code (#419)
Closes #417.
2016-12-23 14:35:45 -06:00
Austin Shalit
8f67f2c24c Remove unused code and add pmd check (#395) 2016-12-23 13:20:13 -06:00
Thad House
cc246bb9ac Switches JNI to use new jni_util methods (#404)
* Uses WPIUtil string objects in JNI

* Switches JNI to use new jni_util classes
2016-12-23 13:13:17 -06:00
Sam Carlberg
bf9f0a9e6d Add vision pipeline API to make it easier to run OpenCV pipelines (#388) 2016-12-23 10:48:56 -06:00
Austin Shalit
c3160bad44 Update SendableChooser to use HashMap (#394) 2016-12-22 15:56:23 -08:00
Thad House
94b8ac42ca Adds CPP version of vision pipeline (#399) 2016-12-21 23:58:42 -06:00
Thad House
a03e3d7eb9 Fixes HAL to build without all headers included in HAL.h (#418) 2016-12-21 23:55:31 -06:00
Jaci R
a42ec08d16 Fix RoboRIO Cross-Toolchain GCC Status (#405)
* Dedicated RoboRIO Toolchain, allow Toolchain Path to change

* Add cCompiler Tool to correctly discover RoboRIO GCC on Mac

* Add @333fred requests for GString and ToolChainPath

* Add Toolchain Path option to README
2016-12-21 19:56:28 -08:00
Thad House
fddb6cd9d8 Fixes SPI Accumulator averages (#415) 2016-12-21 20:17:53 -06:00
Thad House
841f016017 Fixes SerialHelper when used with OS serial ports. (#411)
Also makes the SerialHelper API public so it can be used externally.
2016-12-21 00:16:05 -06:00
Thad House
8e4afc95c7 Switches C++ strings to StringRef (#336) 2016-12-21 00:08:24 -06:00
Tyler Veness
8cec948699 Fix typos (#409) 2016-12-19 22:06:39 -06:00
Tyler Veness
31ae7c942c Fixed signatures of deleted assignment operators (#408)
While it technically doesn't matter what the return type of the assignment operator is since it's deleted, assignment operators should return a reference instead of a value.
2016-12-19 11:24:23 -08:00
Tyler Veness
d0900626da Removed format.py shim (#393)
Now that our formatter is a Python package (wpiformat), the format.py shim for invoking it is no longer necessary. styleguide#29 should be merged before this patch.
2016-12-18 19:46:20 -08:00
Peter Johnson
0ee4cadca0 CameraServer: Workaround LabVIEW dashboard OpenCV compatibility. (#406)
The current LabVIEW dashboard (Beta 4) requires the source type to be either
"usb:" or "ip:" and does not support "cv:".  To work around this, use a source
type of "usb:" for OpenCV sources as well.

Workaround for #407.
2016-12-18 13:36:44 -08:00
Thad House
24b5a9c389 Adds UsageReporting include when using the LabVIEW shim (#401) 2016-12-16 22:42:45 -08:00
Austin Shalit
626220e9f3 Fix javadoc typo (#403) 2016-12-15 19:46:42 -08:00
Thad House
323d68d460 Fixes multiple initialization of HAL_BaseInitialize (#400) 2016-12-13 12:31:44 -08:00
Thad House
db2091dd94 Adds safe serial port write methods (#396)
The old method had a fairly large risk of undefined behavior, and the way the docs
were written could cause users to get confused.
Deprecate the old method and add StringRef method as preferred approach.
2016-12-10 22:40:44 -08:00
Thad House
8216d85e52 Adds check for PWM overallocation (#392) 2016-12-09 21:23:54 -08:00
Austin Shalit
a705eb1c61 Add PMD and solve issues (#389) 2016-12-07 21:24:44 -08:00
Thad House
77f664a6b1 Fixes simulator HAL builds (#391) 2016-12-06 19:56:31 -08:00
Austin Shalit
c30057e923 Remove unused imports (#387) 2016-12-05 21:36:52 -08:00
Peter Johnson
06108b9479 Update CameraServer support. (#386)
* Follow MixedCase rename.

* Add GetVideo function to get cameras by name.
2016-12-04 00:26:08 -08:00
sciencewhiz
16181523c9 Put language in version string (#377) 2016-12-02 20:36:22 -08:00
Jacob Caporuscio
7e0706cf83 Updated Usage Reporting for 2017 v8 Image (#385) 2016-12-02 18:16:49 -08:00
Thad House
bff67887fd Adds capabilities to support certain HAL functionality from LabVIEW (#382)
They can only include HAL/LV/HAL.h, HAL/cpp/*.h, and HAL/handles/*.h.
Nothing else will work properly.
2016-12-02 00:32:01 -08:00
Thad House
351ff5eb48 Adds new Threads API for priority setting while using std::thread (#379)
Also adds Java API for doing the same to Java threads (standard Java Thread.setPriority only works
when Java is run as root, even if the process has the right privileges).
2016-12-01 21:06:19 -08:00
Thad House
051df14046 Updates ni patch task to automatically switch all files to LF (#381)
Still requires manual intervention to make files not readonly, but
that's easier.
2016-11-29 20:20:49 -08:00
Thad House
ee0318f697 Updates NI Libraries to image 8 (#380) 2016-11-29 19:56:30 -08:00
Thad House
a6fb1efcbe Switches internal joystick errors to take StringRef (#378)
Previously this would have allocated the std::string every time, even if
the message wasn't printed. Now takes a StringRef, and only converts to
std::string when the message actually gets printed.
2016-11-26 21:22:39 -08:00
sciencewhiz
31fecc28a4 Check for NaN motor speed. Fixes artf5467. (#376) 2016-11-26 21:04:40 -08:00
Thad House
30b1efc354 Adds check to ensure all JNI symbols have been defined properly (#373) 2016-11-25 17:07:36 -08:00
Thad House
7d721eb569 Fixes memory leak in SerialHelper VISA (#366) 2016-11-25 15:52:21 -08:00
Fred Silberberg
d48aac5beb Gradle Update (#372)
This does a major cleanup on our gradle files, primarily converting all instances of manual dependency downloading to use the correct configuration-based method, which has the advantage of being both less code and more safe.
2016-11-24 23:44:35 -08:00
Fred Silberberg
14b56db99e Gradle 3.2.1 (#369)
Updated to gradle 3.2.1. This also moves all of the task graph listeners for dependency setup to use the gradle model, making it both safer and reducing line count.
2016-11-24 22:15:54 -08:00
Thad House
bfe429de51 Switches handles back to std::array (#367)
The binary size is being increased much less then when we originally
tried this. Using static arrays save a pointer indirection and will help
with cache in real time cases.
2016-11-24 21:55:20 -08:00
Thad House
57ef5cfd07 Splits out SerialHelper to allow using OS or VISA resources (#365)
Also removes regex and uses simple splits instead
2016-11-24 21:53:04 -08:00
Fred Silberberg
4bbb7c0bcc Fixed javadoc generation to actually download cscore and ntcore and include the source in its output. (#368) 2016-11-24 21:51:01 -08:00
Thad House
4de70bff5e Adds missing JNI method definitions (#371) 2016-11-24 21:49:34 -08:00
Peter Johnson
687f0c7dc0 Use const parameters in std::sort lambda. (#364)
This is more correct, and non-const fails on gcc 4.8.
2016-11-22 22:30:58 -08:00
Thad House
f3d66e92ec Searches for USB serial devices to get the correct VISA object (#363)
Fix was made in LabVIEW, and this matches what was done there.
2016-11-22 21:51:47 -08:00
Thad House
9a91ae54d6 Fixes incorrectly changed Java enums (#360)
Some enums need a specific value when they get passed to JNI
2016-11-20 20:32:52 -08:00
Tyler Veness
69422dc063 Replaced floats with doubles (#355)
This makes our APIs more consistent. With optimizations enabled, doubles are just as efficient as floats on ARMv7, so we should take advantage of the extra precision.
2016-11-20 07:25:03 -08:00
Dustin Spicuzza
7bcd243ec3 Reorder the HAL handle types (#357) 2016-11-20 00:01:24 -08:00
Thad House
8f70bea899 Fixes Athena Runtime build not including ntcore (#356) 2016-11-19 23:58:29 -08:00
Thad House
948c4275ad Fixes the wpilibj jar not getting updated during every build (#359) 2016-11-19 23:52:19 -08:00
Peter Johnson
03a1159915 Java CameraServer: Fix type cast exception. (#358)
Also fixes an unchecked warning.
2016-11-19 22:45:45 -08:00
Tyler Veness
1c8fb298b4 Ran formatter (#354) 2016-11-19 00:39:32 -08:00
Tyler Veness
b25a7cb370 Command::IsFinished() must be overriden by subclasses again (#353)
Documentation was added for InstantCommand and TimedCommand.
2016-11-19 00:26:22 -08:00
Tyler Veness
140c365e4b Added XboxController class (#140)
Joystick and Gamepad functionality was separated into cleaner interfaces.
2016-11-18 23:05:37 -08:00
Peter Johnson
8c93ceb728 Add cscore-based CameraServer. (#352)
Not fully functional yet, but implements basic functionality required for LabView dashboard interoperability.
2016-11-18 22:30:22 -08:00
Thad House
ac50d7cf8a Removes NiVision from allwpilib (#305) 2016-11-18 20:04:21 -08:00
Thad House
ecb873ff45 Fixes myRobotJava zipping before Java gets built (#351) 2016-11-18 19:44:13 -08:00
Thad House
78baa04ecc Adds OpenCV to myRobotJava (#350) 2016-11-18 16:20:30 -08:00
Krypton Cougars
b78f580d47 Adds default methods for Commands (#238) (#238)
Closes #235
2016-11-18 14:42:40 -08:00
Thad House
b115c75226 Adds SPI DIO to WPILib (#256) 2016-11-18 14:15:53 -08:00
Thad House
6bc092f3ae Updates SPI device pin (#348) 2016-11-18 14:14:51 -08:00
Thad House
f99a266ce4 Adds CsCore dependency to myRobotCpp (#349) 2016-11-18 14:14:11 -08:00
Fred Silberberg
1f724d58e0 Made the test scripts executable to fix -dirty on the version numbers. (#347) 2016-11-14 21:16:51 -08:00
Thad House
de4a246bb4 Adds OpenCV Loading to wpilib program startup (#338) 2016-11-11 22:32:13 -08:00
rrossbach
412b80da30 Fixes joystick button handling HAL JNI layer (buttons are in an (#341)
int, not a byte)
2016-11-10 20:21:54 -08:00
Thad House
47319960a5 Fixes a missed change to unique_ptr in the HAL (#337) 2016-11-08 16:53:17 -08:00
Thad House
b22d218236 Removes CANJaguar specific constants from JNI files (#339) 2016-11-08 16:52:24 -08:00
Thad House
6eb82bc314 Exclude genlinks.bat from HAL zip (#333) 2016-11-06 21:47:34 -08:00
Thad House
a06dd25d56 Adds cscore and opencv to wpilib (#332)
Unit tests now run using shared wpilib as well, since we had to add a ton
of sharedl ibraries anyway. Test scripts also updated to work properly.
2016-11-06 21:47:18 -08:00
Thad House
e1bb05bc52 Updates to the 2017 v7 image (#329) 2016-11-05 23:20:40 -07:00
Tyler Veness
8694a020ac Removed entries from .styleguide that are included in .gitignore (#331)
format.py now considers files that match patterns in .gitignore to be modifiable files. Therefore, listing them in .styleguide is redundant.
2016-11-05 08:39:46 -07:00
Thad House
1efb2e4d3d Deprecates Task and Semaphore, and changes other deprecations to use wpiutil version (#330) 2016-11-05 00:23:52 -07:00
Thad House
861726cefa Adds gradle task to fix NI libraries whenever new ones are added. (#325)
Generates genlinks, and modifies headers to make them self contained
2016-11-04 15:17:17 -07:00
Thad House
81212d80c6 Fixes ultrasonic declaration (#328)
Also adds test to ensure this doens't happen again
2016-11-04 15:02:29 -07:00
Thad House
2235a809c4 Fixes a missed change from the ni-libraries location change (#326) 2016-11-04 13:26:34 -07:00
Thad House
3fe0f49ac0 Moves NI headers to their own folder in the repo (#324) 2016-11-04 01:22:28 -07:00
Thad House
03d8f9193b Moves using namespace from ChipObject.h into hal namespace (#323) 2016-11-03 23:01:13 -07:00
Thad House
5e54969f6b Adds Task back into WPILibC (#320)
Note that deprecation has not been added yet, since we need to add the
deprecation API's for MSVC and GCC < 4.9.
2016-11-02 22:17:40 -07:00
Thad House
18ef5eb1bf C++ and Java tests for the new build system (#309) 2016-11-01 23:41:05 -07:00
Tyler Veness
b5e3d92e9d Remove errant "using namespace" in global namespace (#318) 2016-11-01 23:40:28 -07:00
Tyler Veness
ba8761e39e "using" directives are no longer used in global namespaces (#219) 2016-11-01 23:09:51 -07:00
Thad House
78f0b1562c Removes Task.h from wpilib.h header (#317) 2016-11-01 23:08:57 -07:00
Thad House
5c28b30028 Removes NetworkTables from Java executable jar (#303) 2016-11-01 22:34:52 -07:00
Peter Johnson
59267da72b Namespace all wpilibc functions/classes into "frc" namespace. (#311)
Base.h provides a backwards compatibility shim (enabled unless
NAMESPACED_WPILIB is defined) that does a "using namespace frc".
However, as some header files do not include Base.h, this may
be a breaking change in some corner cases (with an easy fix).

Fixes #218.
2016-11-01 22:33:12 -07:00
Dustin Spicuzza
36ad45c07d Delete .gitreview (#316) 2016-11-01 22:31:53 -07:00
Thad House
ecb2add791 Removes additional references to CANTalon from the library. (#312) 2016-11-01 20:13:26 -07:00
Thad House
9bbdaf300b Removes the task class from wpilib (#314)
Was required back on the cRIO, but there are much better alternatives
nowadays.
2016-11-01 20:12:08 -07:00
Thad House
bc492bb40e Removes the REAL definition from wpilib.h (#315)
Interferes with OpenCV, and is heavy namespace polution anyway.
2016-11-01 19:23:59 -07:00
Thad House
81221c4874 Moves JNI internal utility methods to frc namespace (#310) 2016-10-31 23:04:49 -07:00
Thad House
137b3d81fb Fixes JNI file not being copied to output directory for integration tests (#308) 2016-10-30 23:14:19 -07:00
Fred Silberberg
6741f47ef1 Update version plugin (#307) 2016-10-30 01:18:18 -07:00
963 changed files with 15985 additions and 75772 deletions

4
.gitignore vendored
View File

@@ -186,3 +186,7 @@ NO
# VSCode
.vscode/
#classpaths and projects
.project
.classpath

View File

@@ -1,5 +0,0 @@
[gerrit]
host=usfirst.collab.net
port=29418
project=allwpilib
defaultbranch=master

View File

@@ -15,7 +15,6 @@ otherExtensions {
}
genFolderExclude {
\.vscode
FRC_FPGA_ChipObject
NetworkCommunication
ctre
@@ -38,15 +37,11 @@ genFileExclude {
modifiableFolderExclude {
\.git
\.gradle
__pycache__
build
wpilibj/src/athena/cpp/include
wpilibj/src/athena/cpp/lib
}
modifiableFileExclude {
\.jar$
\.patch$
\.png$
\.py$

View File

@@ -8,7 +8,8 @@ before_install:
- sudo add-apt-repository ppa:wpilib/toolchain -y
- sudo apt-get update -q || true
- sudo apt-get install frc-toolchain libgazebo7-dev protobuf-compiler libprotobuf-dev python3 clang-format-3.8 -y
install:
- pip3 install wpiformat
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
@@ -17,10 +18,7 @@ cache:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
before_script:
- git clone git://github.com/wpilibsuite/styleguide $HOME/styleguide
script:
- WPI_FORMAT=$HOME/styleguide python3 styleguide/format.py
- wpiformat
- git --no-pager diff --exit-code HEAD # Ensure formatter made no changes
- ./gradlew build -PmakeSim

View File

@@ -37,7 +37,7 @@ So you want to contribute your changes back to WPILib. Great! We have a few cont
## Coding Guidelines
WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running format.py, which is in the styleguide directory, is required for all contributions and is enforced by our continuous integration system.
WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running wpiformat is required for all contributions and is enforced by our continuous integration system.
While the library should be fully formatted according to the styles, additional elements of the style guide were not followed when the library was initially created. All new code should follow the guidelines. If you are looking for some easy ramp-up tasks, finding areas that don't follow the style guide and fixing them is very welcome.

View File

@@ -25,13 +25,13 @@ Using Gradle makes building WPILib very straightforward. It only has a few depen
- [ARM Compiler Toolchain](http://first.wpi.edu/FRC/roborio/toolchains/)
- Doxygen (Only required if you want to build the C++ documentation)
- [format.py](https://github.com/wpilibsuite/styleguide)
- [wpiformat](https://github.com/wpilibsuite/styleguide)
## Setup
Clone the WPILib repository. If the toolchains are not installed, install them, and make sure they are available on the system PATH.
See the [styleguide README](https://github.com/wpilibsuite/styleguide/blob/master/README.md) for format.py setup instructions.
See the [styleguide README](https://github.com/wpilibsuite/styleguide/blob/master/README.md) for wpiformat setup instructions.
## Building
@@ -47,6 +47,12 @@ To build a specific subproject, such as WPILibC, you must access the subproject
./gradlew :wpilibc:build
```
If you have installed the FRC Toolchain to a directory other than the default, or if the Toolchain location is not on your System PATH, you can pass the `toolChainPath` property to specify where it is located. Example:
```bash
./gradlew build -PtoolChainPath=some/path/to/frc/toolchain/bin
```
If you also want simulation to be built, add -PmakeSim. This requires gazebo_transport. We have tested on 14.04 and 15.05, but any correct install of Gazebo should work, even on Windows if you build Gazebo from source. Correct means CMake needs to be able to find gazebo-config.cmake. See [The Gazebo website](https://gazebosim.org/) for installation instructions.
```bash
@@ -67,7 +73,7 @@ The gradlew wrapper only exists in the root of the main project, so be sure to r
There are a few tasks other than `build` available. To see them, run the meta-task `tasks`. This will print a list of all available tasks, with a description of each task.
format.py can be executed in either the styleguide or root directories of the repository via `python3 format.py` or `./format.py`.
wpiformat can be executed anywhere in the repository via `py -3 -m wpiformat` on Windows or `python3 -m wpiformat` on other platforms.
## Publishing

View File

@@ -1,23 +1,38 @@
plugins {
id 'net.ltgt.errorprone' version '0.0.8'
id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '1.2'
id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '1.6'
}
def enableSimulation = hasProperty('enableSimulation')
if (!hasProperty('repo')) {
ext.repo = 'development'
// Ensure that the WPILibVersioningPlugin is setup by setting the release type, if releaseType wasn't
// already specified on the command line
if (!hasProperty('releaseType')) {
WPILibVersion {
releaseType = 'dev'
}
}
def enableSimulation = hasProperty('makeSim')
ext.simulationInstallDir = "$rootDir/build/install/simulation"
allprojects {
ext.enableSimulation = enableSimulation
ext.repo = repo
repositories {
mavenCentral()
}
ext.ntcoreDep = { lang, classifier, extension = null ->
return "edu.wpi.first.wpilib.networktables.$lang:NetworkTables:+:$classifier${extension == null ? '' : '@' + extension}"
}
ext.cscoreDep = { lang, classifier, extension = null ->
return "edu.wpi.cscore.$lang:cscore:+:$classifier${extension == null ? '' : '@' + extension}"
}
ext.wpiUtilDep = { classifier ->
return "edu.wpi.first.wpilib:wpiutil:+:$classifier@zip"
}
}
subprojects {
@@ -47,6 +62,8 @@ subprojects {
apply from: 'cppSettings.gradle'
apply from: 'ni-libraries/ni-libraries.gradle'
task wrapper(type: Wrapper) {
gradleVersion = '3.0'
gradleVersion = '3.3'
}

View File

@@ -1,137 +1,70 @@
// These add the nilibraries shared library to the linker args
def niLibraryPath = file('ni-libraries').path
def niLibraryPath = file('ni-libraries/lib').path
def niLibrary = niLibraryPath + "/libnilibraries.so"
task downloadArmNetworkTables() {
description = 'Downloads the C++ ARM NetworkTables maven dependency.'
group = 'WPILib'
def depFolder = "$buildDir/dependencies"
def ntZip = file("$depFolder/ntcore-arm.zip")
outputs.file(ntZip)
def armNetTables
configurations.create('armDeps')
doFirst {
def armNtDependency = project.dependencies.create('edu.wpi.first.wpilib.networktables.cpp:NetworkTables:+:arm@zip')
def armConfig = project.configurations.detachedConfiguration(armNtDependency)
armConfig.setTransitive(false)
armNetTables = armConfig.files[0].canonicalFile
}
dependencies {
armDeps ntcoreDep('cpp', 'arm', 'zip')
armDeps wpiUtilDep('arm')
armDeps cscoreDep('cpp', 'athena-uberzip', 'zip')
}
doLast {
copy {
from armNetTables
rename 'NetworkTables(.+)', 'ntcore-arm.zip'
into depFolder
}
def depLocation = "$buildDir/dependencies"
configurations.armDeps.files.each { file ->
def depName = file.name.substring(0, file.name.indexOf('-'))
def t = tasks.create("downloadArm${depName.capitalize()}", Copy) {
description = "Downloads and unzips the $depName dependency."
group = 'Dependencies'
from zipTree(file)
into "$depLocation/${depName.toLowerCase()}"
}
}
if (project.hasProperty('makeSim')) {
task downloadDesktopNetworkTables() {
description = 'Downloads the C++ Desktop NetworkTables maven dependency.'
group = 'WPILib'
def depFolder = "$buildDir/dependencies"
def ntZip = file("$depFolder/ntcore-desk.zip")
outputs.file(ntZip)
def desktopNetTables
doFirst {
def desktopNtDependency = project.dependencies.create("edu.wpi.first.wpilib.networktables.cpp:NetworkTables:+:desktop@zip")
def desktopConfig = project.configurations.detachedConfiguration(desktopNtDependency)
desktopConfig.setTransitive(false)
desktopNetTables = desktopConfig.files[0].canonicalFile
}
doLast {
copy {
from desktopNetTables
rename 'NetworkTables(.+)', 'ntcore-desk.zip'
into depFolder
}
}
}
}
def netTablesUnzipLocation = "$buildDir/networktables"
// Create a task that will unzip the networktables files into a temporary build directory
task unzipNetworkTables(type: Copy) {
description = 'Unzips the networktables maven dependency so that the include files and libraries can be used'
group = 'WPILib'
task downloadNetworkTables {
description = 'Downloads all needed versions of networktables.'
group = 'Dependencies'
dependsOn downloadArmNetworkTables
if (project.hasProperty('makeSim')) {
dependsOn downloadDesktopNetworkTables
from zipTree(downloadDesktopNetworkTables.outputs.files.singleFile)
}
from zipTree(downloadArmNetworkTables.outputs.files.singleFile)
into netTablesUnzipLocation
}
task downloadArmWpiUtil() {
description = 'Downloads the C++ ARM wpiutil maven dependency.'
group = 'WPILib'
def depFolder = "$buildDir/dependencies"
def utilZip = file("$depFolder/wpiutil-arm.zip")
outputs.file(utilZip)
def armWpiUtil
task downloadWpiutil {
description = 'Downloads all needed versions of WPIUtil.'
group = 'Dependencies'
dependsOn downloadArmWpiutil
}
doFirst {
def armWpiUtilDependency = project.dependencies.create("edu.wpi.first.wpilib:wpiutil:+:arm@zip")
def armWpiUtilConfig = project.configurations.detachedConfiguration(armWpiUtilDependency)
armWpiUtilConfig.setTransitive(false)
armWpiUtil = armWpiUtilConfig.files[0].canonicalFile
task downloadCscore {
description = 'Downloads all needed versions of cscore.'
group = 'Dependencies'
dependsOn downloadArmCscore
}
if (enableSimulation) {
configurations.create('nativeDeps')
dependencies {
nativeDeps ntcoreDep('cpp', 'desktop', 'zip')
nativeDeps wpiUtilDep('desktop')
}
doLast {
copy {
from armWpiUtil
rename 'wpiutil(.+)', 'wpiutil-arm.zip'
into depFolder
configurations.nativeDeps.files.each { file ->
def depName = file.name.substring(0, file.name.indexOf('-'))
def t = tasks.create("downloadNative${depName.capitalize()}", Copy) {
description = "Downloads and unzips the $depName dependency."
group = 'Dependencies'
from zipTree(file)
into "$depLocation/${depName.toLowerCase()}"
}
}
downloadNetworkTables.dependsOn downloadNativeNetworkTables
downloadWpiutil.dependsOn downloadNativeWpiutil
}
if (project.hasProperty('makeSim')) {
task downloadDesktopWpiUtil() {
description = 'Downloads the C++ Desktop wpiutil maven dependency.'
group = 'WPILib'
def depFolder = "$buildDir/dependencies"
def wpiutilZip = file("$depFolder/wpiutil-desk.zip")
outputs.file(wpiutilZip)
def wpiUtil
doFirst {
def desktopWpiUtilDependency = project.dependencies.create("edu.wpi.first.wpilib:wpiutil:+:desktop@zip")
def desktopWpiUtilConfig = project.configurations.detachedConfiguration(desktopWpiUtilDependency)
desktopWpiUtilConfig.setTransitive(false)
wpiUtil = desktopWpiUtilConfig.files[0].canonicalFile
}
doLast {
copy {
from wpiUtil
rename 'wpiutil(.+)', 'wpiutil-desk.zip'
into depFolder
}
}
}
}
def wpiUtilUnzipLocation = "$buildDir/wpiutil"
// Create a task that will unzip the wpiutil files into a temporary build directory
task unzipWpiUtil(type: Copy) {
description = 'Unzips the wpiutil maven dependency so that the include files and libraries can be used'
group = 'WPILib'
dependsOn downloadArmWpiUtil
if (project.hasProperty('makeSim')) {
dependsOn downloadDesktopWpiUtil
from zipTree(downloadDesktopWpiUtil.outputs.files.singleFile)
}
from zipTree(downloadArmWpiUtil.outputs.files.singleFile)
into wpiUtilUnzipLocation
}
def netTablesUnzipLocation = "$depLocation/networktables"
def wpiUtilUnzipLocation = "$depLocation/wpiutil"
def csCoreUnzipLocation = "$depLocation/cscore"
task clean(type: Delete) {
description = "Deletes the build directory"
@@ -139,12 +72,16 @@ task clean(type: Delete) {
delete buildDir
}
if (!hasProperty("toolChainPath")) {
ext.toolChainPath = null
}
subprojects {
ext.defineWpiUtilProperties = {
ext.wpiUtil = wpiUtilUnzipLocation
ext.wpiUtilInclude = "$wpiUtilUnzipLocation/include"
ext.wpiUtilLibArmLocation = "$wpiUtilUnzipLocation/Linux/arm"
if (project.hasProperty('makeSim')) {
if (enableSimulation) {
ext.wpiUtilLibDesktopLocation = "$wpiUtilUnzipLocation/Linux/amd64"
}
ext.wpiUtilSharedLib = "$wpiUtilLibArmLocation/libwpiutil.so"
@@ -152,7 +89,7 @@ subprojects {
ext.wpiUtilStaticLib = "$wpiUtilLibArmLocation/libwpiutil.a"
ext.addWpiUtilLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').unzipWpiUtil
compileTask.dependsOn project(':').downloadWpiutil
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args wpiUtilSharedLib
@@ -160,7 +97,7 @@ subprojects {
}
ext.addStaticWpiUtilLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').unzipWpiUtil
compileTask.dependsOn project(':').downloadWpiutil
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args wpiUtilStaticLib
@@ -173,7 +110,7 @@ subprojects {
ext.netTables = netTablesUnzipLocation
ext.netTablesInclude = "$netTablesUnzipLocation/include"
ext.netLibArmLocation = "$netTablesUnzipLocation/Linux/arm"
if (project.hasProperty('makeSim')) {
if (enableSimulation) {
ext.netLibDesktopLocation = "$netTablesUnzipLocation/Linux/amd64"
}
ext.netSharedLib = "$netLibArmLocation/libntcore.so"
@@ -181,7 +118,7 @@ subprojects {
ext.netStaticLib = "$netLibArmLocation/libntcore.a"
ext.addNetworkTablesLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').unzipNetworkTables
compileTask.dependsOn project(':').downloadNetworkTables
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args netSharedLib
@@ -190,7 +127,7 @@ subprojects {
}
ext.addStaticNetworkTablesLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').unzipNetworkTables
compileTask.dependsOn project(':').downloadNetworkTables
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args netStaticLib
@@ -198,18 +135,45 @@ subprojects {
addStaticWpiUtilLibraryLinks(compileTask, linker, targetPlatform)
}
}
plugins.withType(CppPlugin).whenPluginAdded {
// This defines a project property that projects depending on cscore can use to setup that dependency.
ext.defineCsCoreProperties = {
ext.csCore = csCoreUnzipLocation
ext.csCoreInclude = "$csCoreUnzipLocation/include"
ext.csLibArmLocation = "$csCoreUnzipLocation/lib"
ext.csSharedLib = "$csLibArmLocation/libcscore.so"
ext.cvSharedLib = "$csLibArmLocation/libopencv.so"
ext.addCsCoreLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').downloadCscore
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args << '-L' + csLibArmLocation
linker.args csSharedLib
linker.args cvSharedLib
}
}
}
ext.defineCrossCompilerProperties = {
// We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name>
// If this ever changes, the prefix will need to be changed here
def compilerPrefix = 'arm-frc-linux-gnueabi-'
ext.compilerPrefix = 'arm-frc-linux-gnueabi-'
}
plugins.withType(CppPlugin).whenPluginAdded {
defineCrossCompilerProperties()
model {
buildTypes {
debug
}
// Adds a custom toolchain for our compiler prefix and options
toolChains {
gcc(Gcc) {
target('arm') {
roborioGcc(Gcc) {
if (toolChainPath != null)
path toolChainPath
target('roborio-arm') {
cCompiler.executable = compilerPrefix + cCompiler.executable
cppCompiler.executable = compilerPrefix + cppCompiler.executable
linker.executable = compilerPrefix + linker.executable
assembler.executable = compilerPrefix + assembler.executable
@@ -231,43 +195,24 @@ subprojects {
staticLibArchiver.executable = compilerPrefix + staticLibArchiver.executable
}
}
// Workaround for OS X. Macs for some reason want to use Xcode's gcc
// (which just wraps Clang), so we have to explicitly make it so
// that trying to compile with Clang will call gcc instead
macGcc(Clang) {
target('arm') {
cppCompiler.executable = compilerPrefix + 'g++'
linker.executable = compilerPrefix + 'g++'
assembler.executable = compilerPrefix + 'gcc'
// Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports
// arm, and doesn't understand this flag, so it is removed from both
cppCompiler.withArguments { args ->
args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-Og' << '-g3' << '-rdynamic'
//TODO: When the compiler allows us to actually call deprecated functions from within
// deprecated function, remove this line (this will cause calling deprecated functions
// to be treated as a warning rather than an error).
args << '-Wno-error=deprecated-declarations'
args.remove('-m32')
}
linker.withArguments { args ->
args << '-rdynamic'
args.remove('-m32')
}
staticLibArchiver.executable = compilerPrefix + 'ar'
}
}
}
// The only platform is arm linux
platforms {
arm {
'roborio-arm' {
architecture 'arm'
operatingSystem 'linux'
}
}
}
ext.niLibraryHeadersRoot = "${rootDir}/ni-libraries/include"
ext.niLibraryHeadersChipObject = "${rootDir}/ni-libraries/include/FRC_FPGA_ChipObject"
ext.binTool = { tool ->
if (toolChainPath != null) return "${toolChainPath}/${compilerPrefix}${tool}"
return "${compilerPrefix}${tool}"
}
// This task adds the appropriate linker flags for the NI libraries
ext.addNiLibraryLinks = { linker, targetPlatform ->
String architecture = targetPlatform.architecture
@@ -286,9 +231,9 @@ subprojects {
def library = task.outputFile.absolutePath
def debugLibrary = task.outputFile.absolutePath + ".debug"
task.doLast {
exec { commandLine "${compilerPrefix}objcopy", '--only-keep-debug', library, debugLibrary }
exec { commandLine "${compilerPrefix}strip", '-g', library }
exec { commandLine "${compilerPrefix}objcopy", "--add-gnu-debuglink=$debugLibrary", library }
exec { commandLine binTool('objcopy'), '--only-keep-debug', library, debugLibrary }
exec { commandLine binTool('strip'), '-g', library }
exec { commandLine binTool('objcopy'), "--add-gnu-debuglink=$debugLibrary", library }
}
}
}

Binary file not shown.

View File

@@ -1,6 +1,6 @@
#Mon Aug 22 20:26:07 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip
#Wed Jan 04 21:49:36 PST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip

19
gradlew vendored
View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
##############################################################################
##
@@ -154,16 +154,19 @@ if $cygwin ; then
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save ( ) {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"

View File

@@ -14,7 +14,7 @@ debugStripSetup(project)
model {
components {
HALAthena(NativeLibrarySpec) {
targetPlatform 'arm'
targetPlatform 'roborio-arm'
binaries.all {
tasks.withType(CppCompile) {
addNiLibraryLinks(linker, targetPlatform)
@@ -24,35 +24,19 @@ model {
sources {
cpp {
source {
srcDirs = ["lib/athena", "lib/athena/FRC_FPGA_ChipObject", "lib/shared"]
srcDirs = ["lib/athena", niLibraryHeadersRoot, "lib/shared"]
includes = ["**/*.cpp"]
}
exportedHeaders {
srcDirs = ["include", "lib/athena/FRC_FPGA_ChipObject", wpiUtilInclude]
srcDirs = ["include", niLibraryHeadersRoot, wpiUtilInclude]
}
}
}
}
// HALSim(NativeLibrarySpec) {
// binaries.all {
// if (toolChain in Gcc){
// cppCompiler.args "-std=c++1y"
// }
// }
//
// sources {
// cpp {
// source {
// srcDirs = ["lib/sim", "lib/shared"]
// includes = ["**/*.cpp"]
// }
// exportedHeaders {
// srcDirs = ["include", "lib/sim", "lib/shared"]
// }
// }
// }
// }
}
tasks { tasks ->
tasks.halZip.dependsOn tasks.HALAthenaSharedLibrary
tasks.athenaRuntimeZip.dependsOn tasks.HALAthenaSharedLibrary
}
}
@@ -70,6 +54,7 @@ task halZip(type: Zip) {
spec.headerDirs.each {
def normalizedIt = it.toString().replace('/', '\\')
def normalizedWPIUtil = wpiUtilInclude.toString().replace('/', '\\')
// exclude the wpiUtil library, and any NI libraries (NI libraries grabbed later)
if (normalizedIt != normalizedWPIUtil) {
from(it) {
into 'include'
@@ -89,18 +74,12 @@ task halZip(type: Zip) {
}
// Finally, include all of the shared library objects from the ni directory
from(project.file('../ni-libraries')) {
from(project.file('../ni-libraries/lib')) {
into 'lib'
exclude 'genlinks'
exclude 'genlinks.bat'
exclude 'libwpi.so'
}
// Add the hal static and shared libraries as a dependency
project(':hal').tasks.whenTaskAdded { task ->
if (task.name.toLowerCase() == 'halathenastaticlibrary' || task.name.toLowerCase() == 'halathenasharedlibrary') {
halZip.dependsOn task
}
}
}
task athenaRuntimeZip(type: Zip) {
@@ -132,6 +111,7 @@ task athenaRuntimeZip(type: Zip) {
}
defineNetworkTablesProperties()
dependsOn project(':').downloadNetworkTables
from(project.file(netTablesInclude)) {
into 'include'
@@ -152,13 +132,6 @@ task athenaRuntimeZip(type: Zip) {
from (file(wpiUtilSharedLibDebug)) {
into 'lib'
}
// Add the hal static and shared libraries as a dependency
project(':hal').tasks.whenTaskAdded { task ->
if (task.name.toLowerCase() == 'halathenastaticlibrary' || task.name.toLowerCase() == 'halathenasharedlibrary') {
athenaRuntimeZip.dependsOn task
}
}
}

View File

@@ -1,66 +0,0 @@
// CANSessionMux.h
//
// Defines the API for building a CAN Interface Plugin to support
// PWM-cable-free CAN motor control on FRC robots. This allows you
// to connect any CAN interface to the secure Jaguar CAN driver.
//
#ifndef __CANSessionMux_h__
#define __CANSessionMux_h__
#if defined(__vxworks)
#include <vxWorks.h>
#else
#include <stdint.h>
#endif
#define CAN_SEND_PERIOD_NO_REPEAT 0
#define CAN_SEND_PERIOD_STOP_REPEATING -1
/* Flags in the upper bits of the messageID */
#define CAN_IS_FRAME_REMOTE 0x80000000
#define CAN_IS_FRAME_11BIT 0x40000000
#define ERR_CANSessionMux_InvalidBuffer -44086
#define ERR_CANSessionMux_MessageNotFound -44087
#define WARN_CANSessionMux_NoToken 44087
#define ERR_CANSessionMux_NotAllowed -44088
#define ERR_CANSessionMux_NotInitialized -44089
#define ERR_CANSessionMux_SessionOverrun 44050
struct tCANStreamMessage{
uint32_t messageID;
uint32_t timeStamp;
uint8_t data[8];
uint8_t dataSize;
};
#ifdef __cplusplus
namespace nCANSessionMux
{
void sendMessage_wrapper(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t periodMs, int32_t *status);
void receiveMessage_wrapper(uint32_t *messageID, uint32_t messageIDMask, uint8_t *data, uint8_t *dataSize, uint32_t *timeStamp, int32_t *status);
void openStreamSession(uint32_t *sessionHandle, uint32_t messageID, uint32_t messageIDMask, uint32_t maxMessages, int32_t *status);
void closeStreamSession(uint32_t sessionHandle);
void readStreamSession(uint32_t sessionHandle, struct tCANStreamMessage *messages, uint32_t messagesToRead, uint32_t *messagesRead, int32_t *status);
void getCANStatus(float *percentBusUtilization, uint32_t *busOffCount, uint32_t *txFullCount, uint32_t *receiveErrorCount, uint32_t *transmitErrorCount, int32_t *status);
}
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void FRC_NetworkCommunication_CANSessionMux_sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t periodMs, int32_t *status);
void FRC_NetworkCommunication_CANSessionMux_receiveMessage(uint32_t *messageID, uint32_t messageIDMask, uint8_t *data, uint8_t *dataSize, uint32_t *timeStamp, int32_t *status);
void FRC_NetworkCommunication_CANSessionMux_openStreamSession(uint32_t *sessionHandle, uint32_t messageID, uint32_t messageIDMask, uint32_t maxMessages, int32_t *status);
void FRC_NetworkCommunication_CANSessionMux_closeStreamSession(uint32_t sessionHandle);
void FRC_NetworkCommunication_CANSessionMux_readStreamSession(uint32_t sessionHandle, struct tCANStreamMessage *messages, uint32_t messagesToRead, uint32_t *messagesRead, int32_t *status);
void FRC_NetworkCommunication_CANSessionMux_getCANStatus(float *percentBusUtilization, uint32_t *busOffCount, uint32_t *txFullCount, uint32_t *receiveErrorCount, uint32_t *transmitErrorCount, int32_t *status);
#ifdef __cplusplus
}
#endif
#endif // __CANSessionMux_h__

View File

@@ -1,163 +0,0 @@
/*************************************************************
* NOTICE
*
* These are the only externally exposed functions to the
* NetworkCommunication library
*
* This is an implementation of FRC Spec for Comm Protocol
* Revision 4.5, June 30, 2008
*
* Copyright (c) National Instruments 2008. All Rights Reserved.
*
*************************************************************/
#ifndef __FRC_COMM_H__
#define __FRC_COMM_H__
#ifdef WIN32
# include <vxWorks_compat.h>
#ifdef USE_THRIFT
# define EXPORT_FUNC
# else
# define EXPORT_FUNC __declspec(dllexport) __cdecl
# endif
#elif defined(__vxworks)
# include <vxWorks.h>
# define EXPORT_FUNC
#elif defined(__linux)
# include <stdint.h>
# include <pthread.h>
# define EXPORT_FUNC
#endif
#define ERR_FRCSystem_NetCommNotResponding -44049
#define ERR_FRCSystem_NoDSConnection -44018
#ifdef WIN32
# define __DEPRECATED__ __declspec(deprecated)
#else
# define __DEPRECATED__ __attribute__((__deprecated__))
#endif
enum AllianceStationID_t {
kAllianceStationID_red1,
kAllianceStationID_red2,
kAllianceStationID_red3,
kAllianceStationID_blue1,
kAllianceStationID_blue2,
kAllianceStationID_blue3,
};
enum MatchType_t {
kMatchType_none,
kMatchType_practice,
kMatchType_qualification,
kMatchType_elimination,
};
struct ControlWord_t {
#ifndef __vxworks
uint32_t enabled : 1;
uint32_t autonomous : 1;
uint32_t test :1;
uint32_t eStop : 1;
uint32_t fmsAttached:1;
uint32_t dsAttached:1;
uint32_t control_reserved : 26;
#else
uint32_t control_reserved : 26;
uint32_t dsAttached:1;
uint32_t fmsAttached:1;
uint32_t eStop : 1;
uint32_t test :1;
uint32_t autonomous : 1;
uint32_t enabled : 1;
#endif
};
struct JoystickAxes_t {
uint16_t count;
int16_t axes[1];
};
struct JoystickPOV_t {
uint16_t count;
int16_t povs[1];
};
#ifdef __cplusplus
extern "C" {
#endif
int EXPORT_FUNC FRC_NetworkCommunication_Reserve(void *instance);
#ifndef SIMULATION
void EXPORT_FUNC getFPGAHardwareVersion(uint16_t *fpgaVersion, uint32_t *fpgaRevision);
#endif
/**
* Safely copy data into the status packet to be sent back to the driver station.
* @deprecated battery is the only parameter to this function that is still used, and only on cRIO / simulation.
*/
__DEPRECATED__ int EXPORT_FUNC setStatusData(float battery, uint8_t dsDigitalOut, uint8_t updateNumber,
const char *userDataHigh, int userDataHighLength,
const char *userDataLow, int userDataLowLength, int wait_ms);
/**
* Send error data to the DS
* @deprecated This old method is hard to parse on the DS side. It will be removed soon. Use FRC_NetworkCommunication_sendError instead.
* @param errorData is a cstr of the error message
* @param errorDataLength is the length of the errorData
* @param wait_ms is ignored (included for binary compatibility)
* @return 0 on success, 1 on no DS connection
*/
__DEPRECATED__ int EXPORT_FUNC setErrorData(const char *errors, int errorsLength, int wait_ms);
/**
* Send a console output line to the Driver Station
* @param line a null-terminated string
* @return 0 on success, other on failure
*/
int EXPORT_FUNC FRC_NetworkCommunication_sendConsoleLine(const char *line);
/**
* Send an error to the Driver Station
* @param isError true if error, false if warning
* @param errorCode value of error condition
* @param isLVCode true if error code is defined in errors.txt, false if not (i.e. made up for C++)
* @param details error description that contains details such as which resource number caused the failure
* @param location Source file, function, and line number that the error was generated - optional
* @param callStack The details about what functions were called through before the error was reported - optional
* @return 0 on success, other on failure
*/
int EXPORT_FUNC FRC_NetworkCommunication_sendError(int isError, int32_t errorCode, int isLVCode,
const char *details, const char *location, const char *callStack);
#ifdef WIN32
void EXPORT_FUNC setNewDataSem(HANDLE);
#elif defined (__vxworks)
void EXPORT_FUNC setNewDataSem(SEM_ID);
#else
void EXPORT_FUNC setNewDataSem(pthread_cond_t *);
#endif
// this uint32_t is really a LVRefNum
int EXPORT_FUNC setNewDataOccurRef(uint32_t refnum);
int EXPORT_FUNC FRC_NetworkCommunication_getControlWord(struct ControlWord_t *controlWord);
int EXPORT_FUNC FRC_NetworkCommunication_getAllianceStation(enum AllianceStationID_t *allianceStation);
int EXPORT_FUNC FRC_NetworkCommunication_getMatchTime(float *matchTime);
int EXPORT_FUNC FRC_NetworkCommunication_getJoystickAxes(uint8_t joystickNum, struct JoystickAxes_t *axes, uint8_t maxAxes);
int EXPORT_FUNC FRC_NetworkCommunication_getJoystickButtons(uint8_t joystickNum, uint32_t *buttons, uint8_t *count);
int EXPORT_FUNC FRC_NetworkCommunication_getJoystickPOVs(uint8_t joystickNum, struct JoystickPOV_t *povs, uint8_t maxPOVs);
int EXPORT_FUNC FRC_NetworkCommunication_setJoystickOutputs(uint8_t joystickNum, uint32_t hidOutputs, uint16_t leftRumble, uint16_t rightRumble);
int EXPORT_FUNC FRC_NetworkCommunication_getJoystickDesc(uint8_t joystickNum, uint8_t *isXBox, uint8_t *type, char *name,
uint8_t *axisCount, uint8_t *axisTypes, uint8_t *buttonCount, uint8_t *povCount);
void EXPORT_FUNC FRC_NetworkCommunication_getVersionString(char *version);
int EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramStarting(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramDisabled(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramAutonomous(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramTeleop(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramTest(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,58 +0,0 @@
#ifndef __LoadOut_h__
#define __LoadOut_h__
#ifdef WIN32
#include <vxWorks_compat.h>
#define EXPORT_FUNC __declspec(dllexport) __cdecl
#elif defined (__vxworks)
#include <vxWorks.h>
#define EXPORT_FUNC
#else
#include <stdint.h>
#define EXPORT_FUNC
#endif
#define kMaxModuleNumber 2
namespace nLoadOut
{
#if defined(__vxworks) || defined(SIMULATION)
typedef enum {
kModuleType_Unknown = 0x00,
kModuleType_Analog = 0x01,
kModuleType_Digital = 0x02,
kModuleType_Solenoid = 0x03,
} tModuleType;
bool EXPORT_FUNC getModulePresence(tModuleType moduleType, uint8_t moduleNumber);
#endif
typedef enum {
kTargetClass_Unknown = 0x00,
kTargetClass_FRC1 = 0x10,
kTargetClass_FRC2 = 0x20,
kTargetClass_FRC3 = 0x30,
kTargetClass_RoboRIO = 0x40,
#if defined(__vxworks) || defined(SIMULATION)
kTargetClass_FRC2_Analog = kTargetClass_FRC2 | kModuleType_Analog,
kTargetClass_FRC2_Digital = kTargetClass_FRC2 | kModuleType_Digital,
kTargetClass_FRC2_Solenoid = kTargetClass_FRC2 | kModuleType_Solenoid,
#endif
kTargetClass_FamilyMask = 0xF0,
kTargetClass_ModuleMask = 0x0F,
} tTargetClass;
tTargetClass EXPORT_FUNC getTargetClass();
}
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__vxworks) || defined(SIMULATION)
uint32_t EXPORT_FUNC FRC_NetworkCommunication_nLoadOut_getModulePresence(uint32_t moduleType, uint8_t moduleNumber);
#endif
uint32_t EXPORT_FUNC FRC_NetworkCommunication_nLoadOut_getTargetClass();
#ifdef __cplusplus
}
#endif
#endif // __LoadOut_h__

View File

@@ -1,149 +0,0 @@
#ifndef __UsageReporting_h__
#define __UsageReporting_h__
#ifdef WIN32
#include <vxWorks_compat.h>
#define EXPORT_FUNC __declspec(dllexport) __cdecl
#elif defined (__vxworks)
#include <vxWorks.h>
#define EXPORT_FUNC
#else
#include <stdint.h>
#include <stdlib.h>
#define EXPORT_FUNC
#endif
#define kUsageReporting_version 1
namespace nUsageReporting
{
typedef enum
{
kResourceType_Controller,
kResourceType_Module,
kResourceType_Language,
kResourceType_CANPlugin,
kResourceType_Accelerometer,
kResourceType_ADXL345,
kResourceType_AnalogChannel,
kResourceType_AnalogTrigger,
kResourceType_AnalogTriggerOutput,
kResourceType_CANJaguar,
kResourceType_Compressor,
kResourceType_Counter,
kResourceType_Dashboard,
kResourceType_DigitalInput,
kResourceType_DigitalOutput,
kResourceType_DriverStationCIO,
kResourceType_DriverStationEIO,
kResourceType_DriverStationLCD,
kResourceType_Encoder,
kResourceType_GearTooth,
kResourceType_Gyro,
kResourceType_I2C,
kResourceType_Framework,
kResourceType_Jaguar,
kResourceType_Joystick,
kResourceType_Kinect,
kResourceType_KinectStick,
kResourceType_PIDController,
kResourceType_Preferences,
kResourceType_PWM,
kResourceType_Relay,
kResourceType_RobotDrive,
kResourceType_SerialPort,
kResourceType_Servo,
kResourceType_Solenoid,
kResourceType_SPI,
kResourceType_Task,
kResourceType_Ultrasonic,
kResourceType_Victor,
kResourceType_Button,
kResourceType_Command,
kResourceType_AxisCamera,
kResourceType_PCVideoServer,
kResourceType_SmartDashboard,
kResourceType_Talon,
kResourceType_HiTechnicColorSensor,
kResourceType_HiTechnicAccel,
kResourceType_HiTechnicCompass,
kResourceType_SRF08,
kResourceType_AnalogOutput,
kResourceType_VictorSP,
kResourceType_TalonSRX,
kResourceType_CANTalonSRX,
kResourceType_ADXL362,
kResourceType_ADXRS450,
kResourceType_RevSPARK,
kResourceType_MindsensorsSD540,
kResourceType_DigitalFilter,
} tResourceType;
typedef enum
{
kLanguage_LabVIEW = 1,
kLanguage_CPlusPlus = 2,
kLanguage_Java = 3,
kLanguage_Python = 4,
kCANPlugin_BlackJagBridge = 1,
kCANPlugin_2CAN = 2,
kFramework_Iterative = 1,
kFramework_Simple = 2,
kFramework_CommandControl = 3,
kRobotDrive_ArcadeStandard = 1,
kRobotDrive_ArcadeButtonSpin = 2,
kRobotDrive_ArcadeRatioCurve = 3,
kRobotDrive_Tank = 4,
kRobotDrive_MecanumPolar = 5,
kRobotDrive_MecanumCartesian = 6,
kDriverStationCIO_Analog = 1,
kDriverStationCIO_DigitalIn = 2,
kDriverStationCIO_DigitalOut = 3,
kDriverStationEIO_Acceleration = 1,
kDriverStationEIO_AnalogIn = 2,
kDriverStationEIO_AnalogOut = 3,
kDriverStationEIO_Button = 4,
kDriverStationEIO_LED = 5,
kDriverStationEIO_DigitalIn = 6,
kDriverStationEIO_DigitalOut = 7,
kDriverStationEIO_FixedDigitalOut = 8,
kDriverStationEIO_PWM = 9,
kDriverStationEIO_Encoder = 10,
kDriverStationEIO_TouchSlider = 11,
kADXL345_SPI = 1,
kADXL345_I2C = 2,
kCommand_Scheduler = 1,
kSmartDashboard_Instance = 1,
} tInstances;
/**
* Report the usage of a resource of interest.
*
* @param resource one of the values in the tResourceType above (max value 51).
* @param instanceNumber an index that identifies the resource instance.
* @param context an optional additional context number for some cases (such as module number). Set to 0 to omit.
* @param feature a string to be included describing features in use on a specific resource. Setting the same resource more than once allows you to change the feature string.
*/
uint32_t EXPORT_FUNC report(tResourceType resource, uint8_t instanceNumber, uint8_t context = 0, const char *feature = NULL);
}
#ifdef __cplusplus
extern "C" {
#endif
uint32_t EXPORT_FUNC FRC_NetworkCommunication_nUsageReporting_report(uint8_t resource, uint8_t instanceNumber, uint8_t context, const char *feature);
#ifdef __cplusplus
}
#endif
#endif // __UsageReporting_h__

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -10,12 +10,6 @@
#pragma GCC diagnostic ignored "-Wpedantic"
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#include "FRC_FPGA_ChipObject/tDMAChannelDescriptor.h" // NOLINT
#include "FRC_FPGA_ChipObject/tDMAManager.h" // NOLINT
#include "FRC_FPGA_ChipObject/tInterruptManager.h" // NOLINT
#include "FRC_FPGA_ChipObject/tSystem.h" // NOLINT
#include "FRC_FPGA_ChipObject/tSystemInterface.h" // NOLINT
#include <stdint.h>
#include "FRC_FPGA_ChipObject/RoboRIO_FRC_ChipObject_Aliases.h"
@@ -38,8 +32,15 @@
#include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tRelay.h"
#include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tSPI.h"
#include "FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tSysWatchdog.h"
#include "FRC_FPGA_ChipObject/tDMAChannelDescriptor.h"
#include "FRC_FPGA_ChipObject/tDMAManager.h"
#include "FRC_FPGA_ChipObject/tInterruptManager.h"
#include "FRC_FPGA_ChipObject/tSystem.h"
#include "FRC_FPGA_ChipObject/tSystemInterface.h"
// FIXME: these should not be here!
namespace hal {
using namespace nFPGA;
using namespace nRoboRIO_FPGANamespace;
} // namespace hal
#pragma GCC diagnostic pop

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2013-2016. All Rights Reserved. */
/* Copyright (c) FIRST 2013-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -104,6 +104,8 @@ int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
int32_t leftRumble, int32_t rightRumble);
double HAL_GetMatchTime(int32_t* status);
#ifndef HAL_USE_LABVIEW
void HAL_WaitForDSData(void);
void HAL_InitializeDriverStation(void);
@@ -112,6 +114,9 @@ void HAL_ObserveUserProgramDisabled(void);
void HAL_ObserveUserProgramAutonomous(void);
void HAL_ObserveUserProgramTeleop(void);
void HAL_ObserveUserProgramTest(void);
#endif // HAL_USE_LABVIEW
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -83,6 +83,26 @@
#define HAL_HANDLE_ERROR_MESSAGE \
"HAL: A handle parameter was passed incorrectly"
#define HAL_SERIAL_PORT_NOT_FOUND -1123
#define HAL_SERIAL_PORT_NOT_FOUND_MESSAGE \
"HAL: The specified serial port device was not found"
#define HAL_SERIAL_PORT_OPEN_ERROR -1124
#define HAL_SERIAL_PORT_OPEN_ERROR_MESSAGE \
"HAL: The serial port could not be opened"
#define HAL_SERIAL_PORT_ERROR -1125
#define HAL_SERIAL_PORT_ERROR_MESSAGE \
"HAL: There was an error on the serial port"
#define HAL_THREAD_PRIORITY_ERROR -1152
#define HAL_THREAD_PRIORITY_ERROR_MESSAGE \
"HAL: Getting or setting the priority of a thread has failed";
#define HAL_THREAD_PRIORITY_RANGE_ERROR -1153
#define HAL_THREAD_PRIORITY_RANGE_ERROR_MESSAGE \
"HAL: The priority requested to be set is invalid"
#define VI_ERROR_SYSTEM_ERROR_MESSAGE "HAL - VISA: System Error";
#define VI_ERROR_INV_OBJECT_MESSAGE "HAL - VISA: Invalid Object"
#define VI_ERROR_RSRC_LOCKED_MESSAGE "HAL - VISA: Resource Locked"

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2013-2016. All Rights Reserved. */
/* Copyright (c) FIRST 2013-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,7 +9,8 @@
#include <stdint.h>
#include "FRC_NetworkCommunication/UsageReporting.h"
#ifndef HAL_USE_LABVIEW
#include "HAL/Accelerometer.h"
#include "HAL/AnalogAccumulator.h"
#include "HAL/AnalogGyro.h"
@@ -33,7 +34,10 @@
#include "HAL/SPI.h"
#include "HAL/SerialPort.h"
#include "HAL/Solenoid.h"
#include "HAL/Task.h"
#endif // HAL_USE_LABVIEW
#include "FRC_NetworkCommunication/UsageReporting.h"
#include "HAL/Types.h"
namespace HALUsageReporting = nUsageReporting;
@@ -43,13 +47,11 @@ enum HAL_RuntimeType : int32_t { HAL_Athena, HAL_Mock };
#ifdef __cplusplus
extern "C" {
#endif
HAL_PortHandle HAL_GetPort(int32_t channel);
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);
const char* HAL_GetErrorMessage(int32_t code);
int32_t HAL_GetFPGAVersion(int32_t* status);
int64_t HAL_GetFPGARevision(int32_t* status);
uint64_t HAL_GetFPGATime(int32_t* status);
HAL_RuntimeType HAL_GetRuntimeType();
HAL_Bool HAL_GetFPGAButton(int32_t* status);
@@ -57,6 +59,15 @@ HAL_Bool HAL_GetFPGAButton(int32_t* status);
HAL_Bool HAL_GetSystemActive(int32_t* status);
HAL_Bool HAL_GetBrownedOut(int32_t* status);
void HAL_BaseInitialize(int32_t* status);
#ifndef HAL_USE_LABVIEW
HAL_PortHandle HAL_GetPort(int32_t channel);
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);
uint64_t HAL_GetFPGATime(int32_t* status);
int32_t HAL_Initialize(int32_t mode);
// ifdef's definition is to allow for default parameters in C++.
@@ -67,6 +78,8 @@ int64_t HAL_Report(int32_t resource, int32_t instanceNumber,
int64_t HAL_Report(int32_t resource, int32_t instanceNumber, int32_t context,
const char* feature);
#endif
#endif // HAL_USE_LABVIEW
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -7,14 +7,8 @@
#pragma once
#include "ColorImage.h"
#define HAL_USE_LABVIEW
/**
* A color image represented in RGB color space at 3 bytes per pixel.
*/
class RGBImage : public ColorImage {
public:
RGBImage();
explicit RGBImage(const char* fileName);
virtual ~RGBImage() = default;
};
#include "HAL/DriverStation.h"
#include "HAL/HAL.h"
#include "HAL/Types.h"

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -0,0 +1,50 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <stdint.h>
#include "SerialPort.h"
#ifdef __cplusplus
extern "C" {
#endif
void HAL_InitializeOSSerialPort(HAL_SerialPort port, int32_t* status);
void HAL_SetOSSerialBaudRate(HAL_SerialPort port, int32_t baud,
int32_t* status);
void HAL_SetOSSerialDataBits(HAL_SerialPort port, int32_t bits,
int32_t* status);
void HAL_SetOSSerialParity(HAL_SerialPort port, int32_t parity,
int32_t* status);
void HAL_SetOSSerialStopBits(HAL_SerialPort port, int32_t stopBits,
int32_t* status);
void HAL_SetOSSerialWriteMode(HAL_SerialPort port, int32_t mode,
int32_t* status);
void HAL_SetOSSerialFlowControl(HAL_SerialPort port, int32_t flow,
int32_t* status);
void HAL_SetOSSerialTimeout(HAL_SerialPort port, double timeout,
int32_t* status);
void HAL_EnableOSSerialTermination(HAL_SerialPort port, char terminator,
int32_t* status);
void HAL_DisableOSSerialTermination(HAL_SerialPort port, int32_t* status);
void HAL_SetOSSerialReadBufferSize(HAL_SerialPort port, int32_t size,
int32_t* status);
void HAL_SetOSSerialWriteBufferSize(HAL_SerialPort port, int32_t size,
int32_t* status);
int32_t HAL_GetOSSerialBytesReceived(HAL_SerialPort port, int32_t* status);
int32_t HAL_ReadOSSerial(HAL_SerialPort port, char* buffer, int32_t count,
int32_t* status);
int32_t HAL_WriteOSSerial(HAL_SerialPort port, const char* buffer,
int32_t count, int32_t* status);
void HAL_FlushOSSerial(HAL_SerialPort port, int32_t* status);
void HAL_ClearOSSerial(HAL_SerialPort port, int32_t* status);
void HAL_CloseOSSerial(HAL_SerialPort port, int32_t* status);
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -31,7 +31,6 @@ int32_t HAL_GetNumPCMModules(void);
int32_t HAL_GetNumSolenoidChannels(void);
int32_t HAL_GetNumPDPModules(void);
int32_t HAL_GetNumPDPChannels(void);
int32_t HAL_GetNumCanTalons(void);
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,31 +9,42 @@
#include <stdint.h>
enum HAL_SerialPort : int32_t {
HAL_SerialPort_Onboard = 0,
HAL_SerialPort_MXP = 1,
HAL_SerialPort_USB1 = 2,
HAL_SerialPort_USB2 = 3
};
#ifdef __cplusplus
extern "C" {
#endif
void HAL_InitializeSerialPort(int32_t port, int32_t* status);
void HAL_SetSerialBaudRate(int32_t port, int32_t baud, int32_t* status);
void HAL_SetSerialDataBits(int32_t port, int32_t bits, int32_t* status);
void HAL_SetSerialParity(int32_t port, int32_t parity, int32_t* status);
void HAL_SetSerialStopBits(int32_t port, int32_t stopBits, int32_t* status);
void HAL_SetSerialWriteMode(int32_t port, int32_t mode, int32_t* status);
void HAL_SetSerialFlowControl(int32_t port, int32_t flow, int32_t* status);
void HAL_SetSerialTimeout(int32_t port, double timeout, int32_t* status);
void HAL_EnableSerialTermination(int32_t port, char terminator,
void HAL_InitializeSerialPort(HAL_SerialPort port, int32_t* status);
void HAL_SetSerialBaudRate(HAL_SerialPort port, int32_t baud, int32_t* status);
void HAL_SetSerialDataBits(HAL_SerialPort port, int32_t bits, int32_t* status);
void HAL_SetSerialParity(HAL_SerialPort port, int32_t parity, int32_t* status);
void HAL_SetSerialStopBits(HAL_SerialPort port, int32_t stopBits,
int32_t* status);
void HAL_SetSerialWriteMode(HAL_SerialPort port, int32_t mode, int32_t* status);
void HAL_SetSerialFlowControl(HAL_SerialPort port, int32_t flow,
int32_t* status);
void HAL_SetSerialTimeout(HAL_SerialPort port, double timeout, int32_t* status);
void HAL_EnableSerialTermination(HAL_SerialPort port, char terminator,
int32_t* status);
void HAL_DisableSerialTermination(int32_t port, int32_t* status);
void HAL_SetSerialReadBufferSize(int32_t port, int32_t size, int32_t* status);
void HAL_SetSerialWriteBufferSize(int32_t port, int32_t size, int32_t* status);
int32_t HAL_GetSerialBytesReceived(int32_t port, int32_t* status);
int32_t HAL_ReadSerial(int32_t port, char* buffer, int32_t count,
void HAL_DisableSerialTermination(HAL_SerialPort port, int32_t* status);
void HAL_SetSerialReadBufferSize(HAL_SerialPort port, int32_t size,
int32_t* status);
void HAL_SetSerialWriteBufferSize(HAL_SerialPort port, int32_t size,
int32_t* status);
int32_t HAL_GetSerialBytesReceived(HAL_SerialPort port, int32_t* status);
int32_t HAL_ReadSerial(HAL_SerialPort port, char* buffer, int32_t count,
int32_t* status);
int32_t HAL_WriteSerial(int32_t port, const char* buffer, int32_t count,
int32_t HAL_WriteSerial(HAL_SerialPort port, const char* buffer, int32_t count,
int32_t* status);
void HAL_FlushSerial(int32_t port, int32_t* status);
void HAL_ClearSerial(int32_t port, int32_t* status);
void HAL_CloseSerial(int32_t port, int32_t* status);
void HAL_FlushSerial(HAL_SerialPort port, int32_t* status);
void HAL_ClearSerial(HAL_SerialPort port, int32_t* status);
void HAL_CloseSerial(HAL_SerialPort port, int32_t* status);
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -25,6 +25,7 @@ HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoidPortHandle,
int32_t HAL_GetAllSolenoids(int32_t module, int32_t* status);
void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value,
int32_t* status);
void HAL_SetAllSolenoids(int32_t module, int32_t state, int32_t* status);
int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status);
HAL_Bool HAL_GetPCMSolenoidVoltageStickyFault(int32_t module, int32_t* status);
HAL_Bool HAL_GetPCMSolenoidVoltageFault(int32_t module, int32_t* status);

View File

@@ -1,43 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <pthread.h>
#include <stdint.h>
#ifndef _STATUS_DEFINED
#define _STATUS_DEFINED
typedef int32_t STATUS;
#endif /* _STATUS_DEFINED */
#ifndef OK
#define OK 0
#endif /* OK */
#ifndef ERROR
#define ERROR (-1)
#endif /* ERROR */
typedef pthread_t* TASK;
#ifdef __cplusplus
extern "C" {
#endif
// Note: These constants used to be declared extern and were defined in
// Task.cpp. This caused issues with the JNI bindings for java, and so the
// instantiations were moved here.
const int32_t HAL_TaskLib_ILLEGAL_PRIORITY = 22; // 22 is EINVAL
STATUS HAL_VerifyTaskID(TASK task);
// valid priority [1..99]
STATUS HAL_SetTaskPriority(TASK task, int32_t priority);
STATUS HAL_GetTaskPriority(TASK task, int32_t* priority);
#ifdef __cplusplus
}
#endif

28
hal/include/HAL/Threads.h Normal file
View File

@@ -0,0 +1,28 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "HAL/Types.h"
#ifdef _WIN32
#include <windows.h>
#define NativeThreadHandle const HANDLE*
#else
#include <pthread.h>
#define NativeThreadHandle const pthread_t*
#endif
extern "C" {
int32_t HAL_GetThreadPriority(NativeThreadHandle handle, HAL_Bool* isRealTime,
int32_t* status);
int32_t HAL_GetCurrentThreadPriority(HAL_Bool* isRealTime, int32_t* status);
HAL_Bool HAL_SetThreadPriority(NativeThreadHandle handle, HAL_Bool realTime,
int32_t priority, int32_t* status);
HAL_Bool HAL_SetCurrentThreadPriority(HAL_Bool realTime, int32_t priority,
int32_t* status);
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -15,32 +15,32 @@ typedef int32_t HAL_Handle;
typedef HAL_Handle HAL_PortHandle;
typedef HAL_Handle HAL_InterruptHandle;
typedef HAL_Handle HAL_NotifierHandle;
typedef HAL_Handle HAL_AnalogInputHandle;
typedef HAL_Handle HAL_AnalogOutputHandle;
typedef HAL_Handle HAL_AnalogInputHandle;
typedef HAL_Handle HAL_AnalogTriggerHandle;
typedef HAL_Handle HAL_RelayHandle;
typedef HAL_Handle HAL_CompressorHandle;
typedef HAL_Handle HAL_CounterHandle;
typedef HAL_Handle HAL_DigitalHandle;
typedef HAL_Handle HAL_DigitalPWMHandle;
typedef HAL_Handle HAL_CounterHandle;
typedef HAL_Handle HAL_CompressorHandle;
typedef HAL_Handle HAL_SolenoidHandle;
typedef HAL_Handle HAL_EncoderHandle;
typedef HAL_Handle HAL_FPGAEncoderHandle;
typedef HAL_Handle HAL_EncoderHandle;
typedef HAL_Handle HAL_GyroHandle;
typedef HAL_Handle HAL_InterruptHandle;
typedef HAL_Handle HAL_NotifierHandle;
typedef HAL_Handle HAL_RelayHandle;
typedef HAL_Handle HAL_SolenoidHandle;
typedef int32_t HAL_Bool;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -12,8 +12,11 @@
#include <condition_variable>
#include "HAL/cpp/priority_mutex.h"
#include "support/deprecated.h"
class Semaphore {
class WPI_DEPRECATED(
"Semaphore scheduled for removal in 2018. Recommended to replace with a "
"std::mutex and std::condition_variable") Semaphore {
public:
explicit Semaphore(int32_t count = 0);
Semaphore(Semaphore&&);

View File

@@ -0,0 +1,51 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <stdint.h>
#include <string>
#include <vector>
#include "HAL/SerialPort.h"
#include "HAL/cpp/priority_mutex.h"
#include "llvm/SmallString.h"
#include "llvm/SmallVector.h"
namespace hal {
class SerialHelper {
public:
SerialHelper();
std::string GetVISASerialPortName(HAL_SerialPort port, int32_t* status);
std::string GetOSSerialPortName(HAL_SerialPort port, int32_t* status);
std::vector<std::string> GetVISASerialPortList(int32_t* status);
std::vector<std::string> GetOSSerialPortList(int32_t* status);
private:
void SortHubPathVector();
void CoiteratedSort(llvm::SmallVectorImpl<llvm::SmallString<16>>& vec);
void QueryHubPaths(int32_t* status);
int32_t GetIndexForPort(HAL_SerialPort port, int32_t* status);
// Vectors to hold data before sorting.
// Note we will most likely have at max 2 instances, and the longest string
// is around 12, so these should never touch the heap;
llvm::SmallVector<llvm::SmallString<16>, 4> m_visaResource;
llvm::SmallVector<llvm::SmallString<16>, 4> m_osResource;
llvm::SmallVector<llvm::SmallString<16>, 4> m_unsortedHubPath;
llvm::SmallVector<llvm::SmallString<16>, 4> m_sortedHubPath;
int32_t m_resourceHandle;
static priority_mutex m_nameMutex;
static std::string m_usbNames[2];
};
} // namespace hal

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -10,7 +10,7 @@
// Allows usage with std::lock_guard without including <mutex> separately
#include <mutex>
#ifdef FRC_SIMULATOR
#if defined(FRC_SIMULATOR) || defined(_WIN32)
// We do not want to use pthreads if in the simulator; however, in the
// simulator, we do not care about priority inversion.
typedef std::mutex priority_mutex;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,8 +9,8 @@
#include <stdint.h>
#include <array>
#include <memory>
#include <vector>
#include "HAL/Errors.h"
#include "HAL/Types.h"
@@ -37,25 +37,19 @@ class DigitalHandleResource {
friend class DigitalHandleResourceTest;
public:
DigitalHandleResource() = default;
DigitalHandleResource(const DigitalHandleResource&) = delete;
DigitalHandleResource operator=(const DigitalHandleResource&) = delete;
DigitalHandleResource();
DigitalHandleResource& operator=(const DigitalHandleResource&) = delete;
THandle Allocate(int16_t index, HAL_HandleEnum enumValue, int32_t* status);
std::shared_ptr<TStruct> Get(THandle handle, HAL_HandleEnum enumValue);
void Free(THandle handle, HAL_HandleEnum enumValue);
private:
// Dynamic array to shrink HAL file size.
std::unique_ptr<std::shared_ptr<TStruct>[]> m_structures;
std::unique_ptr<priority_mutex[]> m_handleMutexes;
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<priority_mutex, size> m_handleMutexes;
};
template <typename THandle, typename TStruct, int16_t size>
DigitalHandleResource<THandle, TStruct, size>::DigitalHandleResource() {
m_structures = std::make_unique<std::shared_ptr<TStruct>[]>(size);
m_handleMutexes = std::make_unique<priority_mutex[]>(size);
}
template <typename THandle, typename TStruct, int16_t size>
THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
int16_t index, HAL_HandleEnum enumValue, int32_t* status) {

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -84,7 +84,15 @@ static inline int16_t getPortHandleModule(HAL_PortHandle handle) {
return static_cast<uint8_t>((handle >> 8) & 0xff);
}
// using a 16 bit value so we can store 0-255 and still report error
static inline int16_t getPortHandleSPIEnable(HAL_PortHandle handle) {
if (!isHandleType(handle, HAL_HandleEnum::Port)) return InvalidHandleIndex;
return static_cast<uint8_t>((handle >> 16) & 0xff);
}
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module);
HAL_PortHandle createPortHandleForSPI(uint8_t channel);
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType);
} // namespace hal

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -39,10 +39,11 @@ class IndexedClassedHandleResource {
friend class IndexedClassedHandleResourceTest;
public:
IndexedClassedHandleResource(const IndexedClassedHandleResource&) = delete;
IndexedClassedHandleResource operator=(const IndexedClassedHandleResource&) =
delete;
IndexedClassedHandleResource();
IndexedClassedHandleResource(const IndexedClassedHandleResource&) = delete;
IndexedClassedHandleResource& operator=(const IndexedClassedHandleResource&) =
delete;
THandle Allocate(int16_t index, std::shared_ptr<TStruct> toSet,
int32_t* status);
std::shared_ptr<TStruct> Get(THandle handle);

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,8 +9,8 @@
#include <stdint.h>
#include <array>
#include <memory>
#include <vector>
#include "HAL/Errors.h"
#include "HAL/Types.h"
@@ -38,27 +38,19 @@ class IndexedHandleResource {
friend class IndexedHandleResourceTest;
public:
IndexedHandleResource() = default;
IndexedHandleResource(const IndexedHandleResource&) = delete;
IndexedHandleResource operator=(const IndexedHandleResource&) = delete;
IndexedHandleResource();
IndexedHandleResource& operator=(const IndexedHandleResource&) = delete;
THandle Allocate(int16_t index, int32_t* status);
std::shared_ptr<TStruct> Get(THandle handle);
void Free(THandle handle);
private:
// Dynamic array to shrink HAL file size.
std::unique_ptr<std::shared_ptr<TStruct>[]> m_structures;
std::unique_ptr<priority_mutex[]> m_handleMutexes;
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<priority_mutex, size> m_handleMutexes;
};
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
IndexedHandleResource<THandle, TStruct, size,
enumValue>::IndexedHandleResource() {
m_structures = std::make_unique<std::shared_ptr<TStruct>[]>(size);
m_handleMutexes = std::make_unique<priority_mutex[]>(size);
}
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,8 +9,8 @@
#include <stdint.h>
#include <array>
#include <memory>
#include <vector>
#include "HAL/Types.h"
#include "HAL/cpp/make_unique.h"
@@ -36,29 +36,21 @@ class LimitedClassedHandleResource {
friend class LimitedClassedHandleResourceTest;
public:
LimitedClassedHandleResource() = default;
LimitedClassedHandleResource(const LimitedClassedHandleResource&) = delete;
LimitedClassedHandleResource operator=(const LimitedClassedHandleResource&) =
LimitedClassedHandleResource& operator=(const LimitedClassedHandleResource&) =
delete;
LimitedClassedHandleResource();
THandle Allocate(std::shared_ptr<TStruct> toSet);
std::shared_ptr<TStruct> Get(THandle handle);
void Free(THandle handle);
private:
// Dynamic array to shrink HAL file size.
std::unique_ptr<std::shared_ptr<TStruct>[]> m_structures;
std::unique_ptr<priority_mutex[]> m_handleMutexes;
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<priority_mutex, size> m_handleMutexes;
priority_mutex m_allocateMutex;
};
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
LimitedClassedHandleResource<THandle, TStruct, size,
enumValue>::LimitedClassedHandleResource() {
m_structures = std::make_unique<std::shared_ptr<TStruct>[]>(size);
m_handleMutexes = std::make_unique<priority_mutex[]>(size);
}
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
THandle

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,8 +9,8 @@
#include <stdint.h>
#include <array>
#include <memory>
#include <vector>
#include "HAL/Types.h"
#include "HAL/cpp/make_unique.h"
@@ -35,28 +35,20 @@ class LimitedHandleResource {
friend class LimitedHandleResourceTest;
public:
LimitedHandleResource() = default;
LimitedHandleResource(const LimitedHandleResource&) = delete;
LimitedHandleResource operator=(const LimitedHandleResource&) = delete;
LimitedHandleResource();
LimitedHandleResource& operator=(const LimitedHandleResource&) = delete;
THandle Allocate();
std::shared_ptr<TStruct> Get(THandle handle);
void Free(THandle handle);
private:
// Dynamic array to shrink HAL file size.
std::unique_ptr<std::shared_ptr<TStruct>[]> m_structures;
std::unique_ptr<priority_mutex[]> m_handleMutexes;
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<priority_mutex, size> m_handleMutexes;
priority_mutex m_allocateMutex;
};
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
LimitedHandleResource<THandle, TStruct, size,
enumValue>::LimitedHandleResource() {
m_structures = std::make_unique<std::shared_ptr<TStruct>[]>(size);
m_handleMutexes = std::make_unique<priority_mutex[]>(size);
}
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
THandle LimitedHandleResource<THandle, TStruct, size, enumValue>::Allocate() {

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -37,9 +37,10 @@ class UnlimitedHandleResource {
friend class UnlimitedHandleResourceTest;
public:
UnlimitedHandleResource(const UnlimitedHandleResource&) = delete;
UnlimitedHandleResource operator=(const UnlimitedHandleResource&) = delete;
UnlimitedHandleResource() = default;
UnlimitedHandleResource(const UnlimitedHandleResource&) = delete;
UnlimitedHandleResource& operator=(const UnlimitedHandleResource&) = delete;
THandle Allocate(std::shared_ptr<TStruct> structure);
std::shared_ptr<TStruct> Get(THandle handle);
void Free(THandle handle);

View File

@@ -16,6 +16,13 @@ public:
*/
CTR_Code SetSolenoid(unsigned char idx, bool en);
/* Set all PCM solenoid states
*
* @Return - CTR_Code - Error code (if any) for setting solenoids
* @Param - state Bitfield to set all solenoids to
*/
CTR_Code SetAllSolenoids(UINT8 state);
/* Enables PCM Closed Loop Control of Compressor via pressure switch
* @Return - CTR_Code - Error code (if any) for setting solenoid
* @Param - en - Enable / Disable Closed Loop Control
@@ -192,6 +199,7 @@ public:
extern "C" {
void * c_PCM_Init(void);
CTR_Code c_SetSolenoid(void * handle,unsigned char idx,INT8 param);
CTR_Code c_SetAllSolenoids(void * handle,UINT8 state);
CTR_Code c_SetClosedLoopControl(void * handle,INT8 param);
CTR_Code c_ClearStickyFaults(void * handle,INT8 param);
CTR_Code c_GetSolenoid(void * handle,UINT8 idx,INT8 * status);

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -13,9 +13,11 @@
#include <cstdio>
#include <memory>
#include "ChipObject.h"
#include "HAL/ChipObject.h"
#include "HAL/HAL.h"
using namespace hal;
// The 7-bit I2C address with a 0 "send" bit
static const uint8_t kSendAddress = (0x1c << 1) | 0;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -87,13 +87,13 @@ void HAL_SetupAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
if (*status != 0) return;
HAL_SetAnalogOversampleBits(gyro->handle, kOversampleBits, status);
if (*status != 0) return;
float sampleRate =
double sampleRate =
kSamplesPerSecond * (1 << (kAverageBits + kOversampleBits));
HAL_SetAnalogSampleRate(sampleRate, status);
if (*status != 0) return;
Wait(0.1);
HAL_SetAnalogGyroDeadband(handle, 0.0f, status);
HAL_SetAnalogGyroDeadband(handle, 0.0, status);
if (*status != 0) return;
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -99,7 +99,7 @@ HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel) {
*/
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
// TODO: This will change when variable size scan lists are implemented.
// TODO: Need float comparison with epsilon.
// TODO: Need double comparison with epsilon.
// wpi_assert(!sampleRateSet || GetSampleRate() == samplesPerSecond);
initializeAnalog(status);
if (*status != 0) return;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,8 +9,8 @@
#include <atomic>
#include "ChipObject.h"
#include "HAL/AnalogInput.h"
#include "HAL/ChipObject.h"
#include "HAL/cpp/priority_mutex.h"
#include "PortsInternal.h"
@@ -80,7 +80,7 @@ int32_t getAnalogNumChannelsToActivate(int32_t* status) {
*/
void setAnalogSampleRate(double samplesPerSecond, int32_t* status) {
// TODO: This will change when variable size scan lists are implemented.
// TODO: Need float comparison with epsilon.
// TODO: Need double comparison with epsilon.
// wpi_assert(!sampleRateSet || GetSampleRate() == samplesPerSecond);
analogSampleRateSet = true;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -11,7 +11,7 @@
#include <memory>
#include "ChipObject.h"
#include "HAL/ChipObject.h"
#include "HAL/Ports.h"
#include "HAL/cpp/priority_mutex.h"
#include "HAL/handles/IndexedHandleResource.h"

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -58,7 +58,24 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
tDIO::tOutputEnable outputEnable = digitalSystem->readOutputEnable(status);
if (port->channel < kNumDigitalHeaders) {
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
if (!getPortHandleSPIEnable(portHandle)) {
// if this flag is not set, we actually want DIO.
uint32_t bitToSet = 1u << remapSPIChannel(port->channel);
uint16_t specialFunctions = spiSystem->readEnableDIO(status);
// Set the field to enable SPI DIO
spiSystem->writeEnableDIO(specialFunctions | bitToSet, status);
if (input) {
outputEnable.SPIPort =
outputEnable.SPIPort & (~bitToSet); // clear the field for read
} else {
outputEnable.SPIPort =
outputEnable.SPIPort | bitToSet; // set the bits for write
}
}
} else if (port->channel < kNumDigitalHeaders) {
uint32_t bitToSet = 1u << port->channel;
if (input) {
outputEnable.Headers =
@@ -93,8 +110,26 @@ HAL_Bool HAL_CheckDIOChannel(int32_t channel) {
}
void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
// no status, so no need to check for a proper free.
digitalChannelHandles.Free(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) return;
int32_t status = 0;
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
// Unset the SPI flag
int32_t bitToUnset = 1 << remapSPIChannel(port->channel);
uint16_t specialFunctions = spiSystem->readEnableDIO(&status);
spiSystem->writeEnableDIO(specialFunctions & ~bitToUnset, &status);
} else if (port->channel >= kNumDigitalHeaders) {
// Unset the MXP flag
uint32_t bitToUnset = 1u << remapMXPChannel(port->channel);
uint16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(&status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions | bitToUnset,
&status);
}
}
/**
@@ -200,7 +235,9 @@ void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
return;
}
int32_t id = *port;
if (channel >= kNumDigitalHeaders) { // If it is on the MXP
if (channel >= kNumDigitalHeaders &&
channel <
kNumDigitalHeaders + kNumDigitalMXPChannels) { // If it is on the MXP
/* Then to write as a digital PWM channel an offset is needed to write on
* the correct channel
*/
@@ -231,7 +268,15 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
tDIO::tDO currentDIO = digitalSystem->readDO(status);
if (port->channel < kNumDigitalHeaders) {
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
if (value == 0) {
currentDIO.SPIPort =
currentDIO.SPIPort & ~(1u << remapSPIChannel(port->channel));
} else if (value == 1) {
currentDIO.SPIPort =
currentDIO.SPIPort | (1u << remapSPIChannel(port->channel));
}
} else if (port->channel < kNumDigitalHeaders) {
if (value == 0) {
currentDIO.Headers = currentDIO.Headers & ~(1u << port->channel);
} else if (value == 1) {
@@ -245,12 +290,6 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
currentDIO.MXP =
currentDIO.MXP | (1u << remapMXPChannel(port->channel));
}
int32_t bitToSet = 1 << remapMXPChannel(port->channel);
uint16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
status);
}
digitalSystem->writeDO(currentDIO, status);
}
@@ -275,16 +314,11 @@ HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
// if it == 0, then return false
// else return true
if (port->channel < kNumDigitalHeaders) {
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
return ((currentDIO.SPIPort >> remapSPIChannel(port->channel)) & 1) != 0;
} else if (port->channel < kNumDigitalHeaders) {
return ((currentDIO.Headers >> port->channel) & 1) != 0;
} else {
// Disable special functions
int32_t bitToSet = 1 << remapMXPChannel(port->channel);
uint16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
status);
return ((currentDIO.MXP >> remapMXPChannel(port->channel)) & 1) != 0;
}
}
@@ -309,7 +343,10 @@ HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
// if it == 0, then return false
// else return true
if (port->channel < kNumDigitalHeaders) {
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
return ((currentOutputEnable.SPIPort >> remapSPIChannel(port->channel)) &
1) != 0;
} else if (port->channel < kNumDigitalHeaders) {
return ((currentOutputEnable.Headers >> port->channel) & 1) != 0;
} else {
return ((currentOutputEnable.MXP >> remapMXPChannel(port->channel)) & 1) !=
@@ -334,7 +371,9 @@ void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
}
tDIO::tPulse pulse;
if (port->channel < kNumDigitalHeaders) {
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
pulse.SPIPort = 1u << remapSPIChannel(port->channel);
} else if (port->channel < kNumDigitalHeaders) {
pulse.Headers = 1u << port->channel;
} else {
pulse.MXP = 1u << remapMXPChannel(port->channel);
@@ -360,7 +399,9 @@ HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status) {
}
tDIO::tPulse pulseRegister = digitalSystem->readPulse(status);
if (port->channel < kNumDigitalHeaders) {
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
return (pulseRegister.SPIPort & (1 << remapSPIChannel(port->channel))) != 0;
} else if (port->channel < kNumDigitalHeaders) {
return (pulseRegister.Headers & (1 << port->channel)) != 0;
} else {
return (pulseRegister.MXP & (1 << remapMXPChannel(port->channel))) != 0;
@@ -376,7 +417,8 @@ HAL_Bool HAL_IsAnyPulsing(int32_t* status) {
initializeDigital(status);
if (*status != 0) return false;
tDIO::tPulse pulseRegister = digitalSystem->readPulse(status);
return pulseRegister.Headers != 0 && pulseRegister.MXP != 0;
return pulseRegister.Headers != 0 && pulseRegister.MXP != 0 &&
pulseRegister.SPIPort != 0;
}
/**
@@ -396,7 +438,11 @@ void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
}
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
if (port->channel < kNumDigitalHeaders) {
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
// Channels 10-15 are SPI channels, so subtract our MXP channels
digitalSystem->writeFilterSelectHdr(port->channel - kNumDigitalMXPChannels,
filterIndex, status);
} else if (port->channel < kNumDigitalHeaders) {
digitalSystem->writeFilterSelectHdr(port->channel, filterIndex, status);
} else {
digitalSystem->writeFilterSelectMXP(remapMXPChannel(port->channel),
@@ -420,7 +466,11 @@ int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
}
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
if (port->channel < kNumDigitalHeaders) {
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
// Channels 10-15 are SPI channels, so subtract our MXP channels
return digitalSystem->readFilterSelectHdr(
port->channel - kNumDigitalMXPChannels, status);
} else if (port->channel < kNumDigitalHeaders) {
return digitalSystem->readFilterSelectHdr(port->channel, status);
} else {
return digitalSystem->readFilterSelectMXP(remapMXPChannel(port->channel),

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -11,10 +11,10 @@
#include <mutex>
#include <thread>
#include "ChipObject.h"
#include "ConstantsInternal.h"
#include "FRC_NetworkCommunication/LoadOut.h"
#include "HAL/AnalogTrigger.h"
#include "HAL/ChipObject.h"
#include "HAL/HAL.h"
#include "HAL/Ports.h"
#include "HAL/cpp/priority_mutex.h"
@@ -27,6 +27,7 @@ priority_recursive_mutex digitalPwmMutex;
std::unique_ptr<tDIO> digitalSystem;
std::unique_ptr<tRelay> relaySystem;
std::unique_ptr<tPWM> pwmSystem;
std::unique_ptr<tSPI> spiSystem;
static std::atomic<bool> digitalSystemsInitialized{false};
static priority_mutex initializeMutex;
@@ -94,9 +95,18 @@ void initializeDigital(int32_t* status) {
}
}
// SPI setup
spiSystem.reset(tSPI::create(status));
digitalSystemsInitialized = true;
}
/**
* Map SPI channel numbers from their physical number (27 to 31) to their
* position in the bit field.
*/
int32_t remapSPIChannel(int32_t channel) { return channel - 26; }
/**
* Map DIO channel numbers from their physical number (10 to 26) to their
* position in the bit field.
@@ -130,7 +140,11 @@ bool remapDigitalSource(HAL_Handle digitalSourceHandle,
return true;
} else if (isHandleType(digitalSourceHandle, HAL_HandleEnum::DIO)) {
int32_t index = getHandleIndex(digitalSourceHandle);
if (index >= kNumDigitalHeaders) {
if (index > kNumDigitalHeaders + kNumDigitalMXPChannels) {
// channels 10-15, so need to add headers to remap index
channel = remapSPIChannel(index) + kNumDigitalHeaders;
module = 0;
} else if (index >= kNumDigitalHeaders) {
channel = remapMXPChannel(index);
module = 1;
} else {

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -11,8 +11,8 @@
#include <memory>
#include "ChipObject.h"
#include "HAL/AnalogTrigger.h"
#include "HAL/ChipObject.h"
#include "HAL/Ports.h"
#include "HAL/Types.h"
#include "HAL/handles/DigitalHandleResource.h"
@@ -45,11 +45,11 @@ constexpr int32_t kExpectedLoopTiming = 40;
* scaling is implemented as an output squelch to get longer periods for old
* devices.
*/
constexpr float kDefaultPwmPeriod = 5.05;
constexpr double kDefaultPwmPeriod = 5.05;
/**
* kDefaultPwmCenter is the PWM range center in ms
*/
constexpr float kDefaultPwmCenter = 1.5;
constexpr double kDefaultPwmCenter = 1.5;
/**
* kDefaultPWMStepsDown is the number of PWM steps below the centerpoint
*/
@@ -62,6 +62,7 @@ extern priority_recursive_mutex digitalPwmMutex;
extern std::unique_ptr<tDIO> digitalSystem;
extern std::unique_ptr<tRelay> relaySystem;
extern std::unique_ptr<tPWM> pwmSystem;
extern std::unique_ptr<tSPI> spiSystem;
struct DigitalPort {
uint8_t channel;
@@ -82,6 +83,7 @@ void initializeDigital(int32_t* status);
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
uint8_t& channel, uint8_t& module, bool& analogTrigger);
int32_t remapSPIChannel(int32_t channel);
int32_t remapMXPPWMChannel(int32_t channel);
int32_t remapMXPChannel(int32_t channel);
} // namespace hal

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -7,9 +7,9 @@
#include "HAL/Encoder.h"
#include "ChipObject.h"
#include "EncoderInternal.h"
#include "FPGAEncoder.h"
#include "HAL/ChipObject.h"
#include "HAL/Counter.h"
#include "HAL/Errors.h"
#include "HAL/handles/LimitedClassedHandleResource.h"

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,17 +1,18 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <limits>
#include "FRC_NetworkCommunication/FRCComm.h"
#include "HAL/HAL.h"
#include "HAL/DriverStation.h"
#include "HAL/cpp/priority_condition_variable.h"
#include "HAL/cpp/priority_mutex.h"
@@ -41,16 +42,24 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
static constexpr int KEEP_MSGS = 5;
std::lock_guard<priority_mutex> lock(msgMutex);
static std::string prevMsg[KEEP_MSGS];
static uint64_t prevMsgTime[KEEP_MSGS] = {0, 0, 0};
static std::chrono::time_point<std::chrono::steady_clock>
prevMsgTime[KEEP_MSGS];
static bool initialized = false;
if (!initialized) {
for (int i = 0; i < KEEP_MSGS; i++) {
prevMsgTime[i] =
std::chrono::steady_clock::now() - std::chrono::seconds(2);
}
initialized = true;
}
int32_t status = 0;
uint64_t curTime = HAL_GetFPGATime(&status);
auto curTime = std::chrono::steady_clock::now();
int i;
for (i = 0; i < KEEP_MSGS; ++i) {
if (prevMsg[i] == details) break;
}
int retval = 0;
if (i == KEEP_MSGS || (curTime - prevMsgTime[i]) >= 1000000) {
if (i == KEEP_MSGS || (curTime - prevMsgTime[i]) >= std::chrono::seconds(1)) {
retval = FRC_NetworkCommunication_sendError(isError, errorCode, isLVCode,
details, location, callStack);
if (printMsg) {
@@ -66,7 +75,7 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
if (i == KEEP_MSGS) {
// replace the oldest one
i = 0;
uint64_t first = prevMsgTime[0];
auto first = prevMsgTime[0];
for (int j = 1; j < KEEP_MSGS; ++j) {
if (prevMsgTime[j] < first) {
first = prevMsgTime[j];
@@ -100,16 +109,16 @@ int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes) {
joystickNum, reinterpret_cast<JoystickAxes_t*>(&axesInt),
HAL_kMaxJoystickAxes);
// copy integer values to float values
// copy integer values to double values
axes->count = axesInt.count;
// current scaling is -128 to 127, can easily be patched in the future by
// changing this function.
for (int32_t i = 0; i < axesInt.count; i++) {
int8_t value = axesInt.axes[i];
if (value < 0) {
axes->axes[i] = value / 128.0f;
axes->axes[i] = value / 128.0;
} else {
axes->axes[i] = value / 127.0f;
axes->axes[i] = value / 127.0;
}
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -11,22 +11,27 @@
#include <sys/prctl.h>
#include <unistd.h>
#include <atomic>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <mutex>
#include <thread>
#include "ChipObject.h"
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include "FRC_NetworkCommunication/FRCComm.h"
#include "FRC_NetworkCommunication/LoadOut.h"
#include "HAL/ChipObject.h"
#include "HAL/DriverStation.h"
#include "HAL/Errors.h"
#include "HAL/Notifier.h"
#include "HAL/cpp/priority_mutex.h"
#include "HAL/handles/HandlesInternal.h"
#include "ctre/ctre.h"
#include "visa/visa.h"
using namespace hal;
static std::unique_ptr<tGlobal> global;
static std::unique_ptr<tSysWatchdog> watchdog;
@@ -159,6 +164,16 @@ const char* HAL_GetErrorMessage(int32_t code) {
return VI_ERROR_INV_PARAMETER_MESSAGE;
case HAL_PWM_SCALE_ERROR:
return HAL_PWM_SCALE_ERROR_MESSAGE;
case HAL_SERIAL_PORT_NOT_FOUND:
return HAL_SERIAL_PORT_NOT_FOUND_MESSAGE;
case HAL_THREAD_PRIORITY_ERROR:
return HAL_THREAD_PRIORITY_ERROR_MESSAGE;
case HAL_THREAD_PRIORITY_RANGE_ERROR:
return HAL_THREAD_PRIORITY_RANGE_ERROR_MESSAGE;
case HAL_SERIAL_PORT_OPEN_ERROR:
return HAL_SERIAL_PORT_OPEN_ERROR_MESSAGE;
case HAL_SERIAL_PORT_ERROR:
return HAL_SERIAL_PORT_ERROR_MESSAGE;
default:
return "Unknown error status";
}
@@ -247,20 +262,30 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status) {
return !(watchdog->readStatus_PowerAlive(status));
}
static void HALCleanupAtExit() {
global = nullptr;
watchdog = nullptr;
// Unregister our new data condition variable.
setNewDataSem(nullptr);
}
static void timerRollover(uint64_t currentTime, HAL_NotifierHandle handle) {
// reschedule timer for next rollover
int32_t status = 0;
HAL_UpdateNotifierAlarm(handle, currentTime + 0x80000000ULL, &status);
}
void HAL_BaseInitialize(int32_t* status) {
static std::atomic_bool initialized{false};
static priority_mutex initializeMutex;
// Initial check, as if it's true initialization has finished
if (initialized) return;
std::lock_guard<priority_mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (initialized) return;
// image 4; Fixes errors caused by multiple processes. Talk to NI about this
nFPGA::nRoboRIO_FPGANamespace::g_currentTargetClass =
nLoadOut::kTargetClass_RoboRIO;
global.reset(tGlobal::create(status));
watchdog.reset(tSysWatchdog::create(status));
initialized = true;
}
/**
* Call this to start up HAL. This is required for robot programs.
*/
@@ -271,15 +296,14 @@ int32_t HAL_Initialize(int32_t mode) {
prctl(PR_SET_PDEATHSIG, SIGTERM);
FRC_NetworkCommunication_Reserve(nullptr);
// image 4; Fixes errors caused by multiple processes. Talk to NI about this
nFPGA::nRoboRIO_FPGANamespace::g_currentTargetClass =
nLoadOut::kTargetClass_RoboRIO;
std::atexit([]() {
// Unregister our new data condition variable.
setNewDataSem(nullptr);
});
int32_t status = 0;
global.reset(tGlobal::create(&status));
watchdog.reset(tSysWatchdog::create(&status));
std::atexit(HALCleanupAtExit);
HAL_BaseInitialize(&status);
if (!rolloverNotifier)
rolloverNotifier = HAL_InitializeNotifier(timerRollover, nullptr, &status);

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,8 +9,8 @@
#include <memory>
#include "ChipObject.h"
#include "DigitalInternal.h"
#include "HAL/ChipObject.h"
#include "HAL/Errors.h"
#include "HAL/cpp/make_unique.h"
#include "HAL/handles/HandlesInternal.h"

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -14,13 +14,16 @@
#include <memory>
#include <mutex>
#include "ChipObject.h"
#include "HAL/ChipObject.h"
#include "HAL/Errors.h"
#include "HAL/HAL.h"
#include "HAL/cpp/make_unique.h"
#include "HAL/cpp/priority_mutex.h"
#include "HAL/handles/UnlimitedHandleResource.h"
#include "support/SafeThread.h"
using namespace hal;
static const int32_t kTimerInterruptNumber = 28;
static priority_mutex notifierInterruptMutex;

View File

@@ -0,0 +1,232 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "HAL/OSSerialPort.h"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
#include <chrono>
#include <cstring>
#include <string>
#include "HAL/Errors.h"
#include "HAL/cpp/SerialHelper.h"
static int portHandles[4]{-1, -1, -1, -1};
static std::chrono::milliseconds portTimeouts[4]{
std::chrono::milliseconds(0), std::chrono::milliseconds(0),
std::chrono::milliseconds(0), std::chrono::milliseconds(0)};
extern "C" {
void HAL_InitializeOSSerialPort(HAL_SerialPort port, int32_t* status) {
std::string portName;
hal::SerialHelper serialHelper;
portName = serialHelper.GetOSSerialPortName(port, status);
if (*status < 0) {
return;
}
int fs = open(portName.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
if (fs == -1) {
*status = HAL_SERIAL_PORT_OPEN_ERROR;
return;
}
portHandles[port] = fs;
struct termios options;
tcgetattr(fs, &options);
options.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
options.c_iflag = 0;
options.c_oflag = 0;
options.c_lflag = 0;
tcflush(fs, TCIFLUSH);
tcsetattr(fs, TCSANOW, &options);
}
void HAL_SetOSSerialBaudRate(HAL_SerialPort port, int32_t baud,
int32_t* status) {
int baudRate = -1;
switch (baud) {
case 9600:
baudRate = B9600;
break;
case 19200:
baudRate = B19200;
break;
case 38400:
baudRate = B38400;
break;
case 57600:
baudRate = B57600;
break;
case 115200:
baudRate = B115200;
break;
default:
*status = PARAMETER_OUT_OF_RANGE;
return;
}
struct termios options;
tcgetattr(portHandles[port], &options);
auto set = cfsetospeed(&options, baudRate);
if (set != 0) {
*status = HAL_SERIAL_PORT_ERROR;
return;
}
set = tcsetattr(portHandles[port], TCSANOW, &options);
if (set != 0) {
*status = HAL_SERIAL_PORT_ERROR;
return;
}
}
void HAL_SetOSSerialDataBits(HAL_SerialPort port, int32_t bits,
int32_t* status) {
int numBits = -1;
switch (bits) {
case 5:
numBits = CS5;
break;
case 6:
numBits = CS6;
break;
case 7:
numBits = CS7;
break;
case 8:
numBits = CS8;
break;
default:
*status = PARAMETER_OUT_OF_RANGE;
return;
}
struct termios options;
tcgetattr(portHandles[port], &options);
options.c_cflag &= ~CSIZE;
options.c_cflag |= numBits;
auto set = tcsetattr(portHandles[port], TCSANOW, &options);
if (set != 0) {
*status = HAL_SERIAL_PORT_ERROR;
return;
}
}
void HAL_SetOSSerialParity(HAL_SerialPort port, int32_t parity,
int32_t* status) {
// Just set none parity
struct termios options;
tcgetattr(portHandles[port], &options);
options.c_cflag &= ~PARENB;
auto set = tcsetattr(portHandles[port], TCSANOW, &options);
if (set != 0) {
*status = HAL_SERIAL_PORT_ERROR;
return;
}
}
void HAL_SetOSSerialStopBits(HAL_SerialPort port, int32_t stopBits,
int32_t* status) {
// Force 1 stop bit
struct termios options;
tcgetattr(portHandles[port], &options);
options.c_cflag &= ~CSTOPB;
auto set = tcsetattr(portHandles[port], TCSANOW, &options);
if (set != 0) {
*status = HAL_SERIAL_PORT_ERROR;
return;
}
}
void HAL_SetOSSerialWriteMode(HAL_SerialPort port, int32_t mode,
int32_t* status) {
// No op
}
void HAL_SetOSSerialFlowControl(HAL_SerialPort port, int32_t flow,
int32_t* status) {
// No op
}
void HAL_SetOSSerialTimeout(HAL_SerialPort port, double timeout,
int32_t* status) {
// Convert to millis
int t = timeout / 1000;
portTimeouts[port] = std::chrono::milliseconds(t);
}
void HAL_EnableOSSerialTermination(HAL_SerialPort port, char terminator,
int32_t* status) {
// \n is hardcoded for now. Will fix later
// Seems like a VISA only setting, need to check
}
void HAL_DisableOSSerialTermination(HAL_SerialPort port, int32_t* status) {
// Seems like a VISA only setting, need to check
}
void HAL_SetOSSerialReadBufferSize(HAL_SerialPort port, int32_t size,
int32_t* status) {
// No op
}
void HAL_SetOSSerialWriteBufferSize(HAL_SerialPort port, int32_t size,
int32_t* status) {
// No op
}
int32_t HAL_GetOSSerialBytesReceived(HAL_SerialPort port, int32_t* status) {
int bytes = 0;
ioctl(portHandles[port], FIONREAD, &bytes);
return bytes;
}
int32_t HAL_ReadOSSerial(HAL_SerialPort port, char* buffer, int32_t count,
int32_t* status) {
auto endTime = std::chrono::steady_clock::now() + portTimeouts[port];
int bytesRead = 0;
unsigned char buf[256];
do {
int rx = read(portHandles[port], buf, count - bytesRead);
std::memcpy(&buffer[bytesRead], buf, rx);
bytesRead += rx;
if (bytesRead >= count) break;
llvm::StringRef tmp(buffer, bytesRead);
auto loc = tmp.find('\n');
if (loc != llvm::StringRef::npos) {
bytesRead = loc;
break;
}
} while (std::chrono::steady_clock::now() < endTime);
return bytesRead;
}
int32_t HAL_WriteOSSerial(HAL_SerialPort port, const char* buffer,
int32_t count, int32_t* status) {
return write(portHandles[port], buffer, count);
}
void HAL_FlushOSSerial(HAL_SerialPort port, int32_t* status) {
tcdrain(portHandles[port]);
}
void HAL_ClearOSSerial(HAL_SerialPort port, int32_t* status) {
tcflush(portHandles[port], TCIOFLUSH);
}
void HAL_CloseOSSerial(HAL_SerialPort port, int32_t* status) {
close(portHandles[port]);
}
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -7,6 +7,8 @@
#include "HAL/PWM.h"
#include <cmath>
#include "ConstantsInternal.h"
#include "DigitalInternal.h"
#include "HAL/handles/HandlesInternal.h"
@@ -48,7 +50,7 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
if (*status != 0) return HAL_kInvalidHandle;
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
if (channel == InvalidHandleIndex || channel >= kNumPWMChannels) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
@@ -241,6 +243,8 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
speed = -1.0;
} else if (speed > 1.0) {
speed = 1.0;
} else if (!std::isfinite(speed)) {
speed = 0.0;
}
// calculate the desired output pwm value by scaling the speed appropriately

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -30,5 +30,4 @@ int32_t HAL_GetNumPCMModules(void) { return kNumPCMModules; }
int32_t HAL_GetNumSolenoidChannels(void) { return kNumSolenoidChannels; }
int32_t HAL_GetNumPDPModules(void) { return kNumPDPModules; }
int32_t HAL_GetNumPDPChannels(void) { return kNumPDPChannels; }
int32_t HAL_GetNumCanTalons(void) { return kNumCanTalons; }
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,7 +9,7 @@
#include <stdint.h>
#include "ChipObject.h"
#include "HAL/ChipObject.h"
namespace hal {
constexpr int32_t kNumAccumulators = tAccumulator::kNumSystems;
@@ -18,8 +18,11 @@ constexpr int32_t kNumAnalogInputs = 8;
constexpr int32_t kNumAnalogOutputs = tAO::kNumMXPRegisters;
constexpr int32_t kNumCounters = tCounter::kNumSystems;
constexpr int32_t kNumDigitalHeaders = 10;
constexpr int32_t kNumDigitalMXPChannels = 16;
constexpr int32_t kNumDigitalSPIPortChannels = 5;
constexpr int32_t kNumPWMHeaders = tPWM::kNumHdrRegisters;
constexpr int32_t kNumDigitalChannels = 26;
constexpr int32_t kNumDigitalChannels =
kNumDigitalHeaders + kNumDigitalMXPChannels + kNumDigitalSPIPortChannels;
constexpr int32_t kNumPWMChannels = tPWM::kNumMXPRegisters + kNumPWMHeaders;
constexpr int32_t kNumDigitalPWMOutputs =
tDIO::kNumPWMDutyCycleAElements + tDIO::kNumPWMDutyCycleBElements;
@@ -31,5 +34,4 @@ constexpr int32_t kNumPCMModules = 63;
constexpr int32_t kNumSolenoidChannels = 8;
constexpr int32_t kNumPDPModules = 63;
constexpr int32_t kNumPDPChannels = 16;
constexpr int32_t kNumCanTalons = 63;
} // namespace hal

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,7 +9,9 @@
#include <memory>
#include "ChipObject.h"
#include "HAL/ChipObject.h"
using namespace hal;
static std::unique_ptr<tPower> power;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -13,8 +13,10 @@
#include "DigitalInternal.h"
#include "HAL/DIO.h"
#include "HAL/HAL.h"
#include "HAL/Notifier.h"
#include "HAL/cpp/make_unique.h"
#include "HAL/cpp/priority_mutex.h"
#include "HAL/handles/HandlesInternal.h"
#include "spilib/spi-lib.h"
using namespace hal;
@@ -26,12 +28,11 @@ static int32_t m_spiCS3Handle = 0;
static int32_t m_spiMXPHandle = 0;
static priority_recursive_mutex spiOnboardMutex;
static priority_recursive_mutex spiMXPMutex;
static tSPI* spiSystem;
static HAL_DigitalHandle spiMXPDigitalHandle1 = HAL_kInvalidHandle;
static HAL_DigitalHandle spiMXPDigitalHandle2 = HAL_kInvalidHandle;
static HAL_DigitalHandle spiMXPDigitalHandle3 = HAL_kInvalidHandle;
static HAL_DigitalHandle spiMXPDigitalHandle4 = HAL_kInvalidHandle;
// MXP SPI does not count towards this
std::atomic<int32_t> spiPortCount{0};
static HAL_DigitalHandle digitalHandles[9]{HAL_kInvalidHandle};
/**
* Get the semaphore for a SPI port
@@ -73,56 +74,115 @@ struct SPIAccumulator {
};
std::unique_ptr<SPIAccumulator> spiAccumulators[5];
static void CommonSPIPortInit(int32_t* status) {
// All false cases will set
if (spiPortCount.fetch_add(1) == 0) {
// Have not been initialized yet
initializeDigital(status);
if (*status != 0) return;
// MISO
if ((digitalHandles[3] = HAL_InitializeDIOPort(createPortHandleForSPI(29),
false, status)) ==
HAL_kInvalidHandle) {
std::printf("Failed to allocate DIO 29 (MISO)\n");
return;
}
// MOSI
if ((digitalHandles[4] = HAL_InitializeDIOPort(createPortHandleForSPI(30),
false, status)) ==
HAL_kInvalidHandle) {
std::printf("Failed to allocate DIO 30 (MOSI)\n");
HAL_FreeDIOPort(digitalHandles[3]); // free the first port allocated
return;
}
}
}
static void CommonSPIPortFree() {
if (spiPortCount.fetch_sub(1) == 1) {
// Clean up SPI Handles
HAL_FreeDIOPort(digitalHandles[3]);
HAL_FreeDIOPort(digitalHandles[4]);
}
}
/*
* Initialize the spi port. Opens the port if necessary and saves the handle.
* If opening the MXP port, also sets up the channel functions appropriately
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param port The number of the port to use. 0-3 for Onboard CS0-CS3, 4 for MXP
*/
void HAL_InitializeSPI(int32_t port, int32_t* status) {
if (spiSystem == nullptr) spiSystem = tSPI::create(status);
if (HAL_GetSPIHandle(port) != 0) return;
switch (port) {
case 0:
CommonSPIPortInit(status);
if (*status != 0) return;
// CS0 is not a DIO port, so nothing to allocate
HAL_SetSPIHandle(0, spilib_open("/dev/spidev0.0"));
break;
case 1:
CommonSPIPortInit(status);
if (*status != 0) return;
// CS1, Allocate
if ((digitalHandles[0] = HAL_InitializeDIOPort(
HAL_GetPort(26), false, status)) == HAL_kInvalidHandle) {
std::printf("Failed to allocate DIO 26 (CS1)\n");
CommonSPIPortFree();
return;
}
HAL_SetSPIHandle(1, spilib_open("/dev/spidev0.1"));
break;
case 2:
CommonSPIPortInit(status);
if (*status != 0) return;
// CS2, Allocate
if ((digitalHandles[1] = HAL_InitializeDIOPort(
HAL_GetPort(27), false, status)) == HAL_kInvalidHandle) {
std::printf("Failed to allocate DIO 27 (CS2)\n");
CommonSPIPortFree();
return;
}
HAL_SetSPIHandle(2, spilib_open("/dev/spidev0.2"));
break;
case 3:
CommonSPIPortInit(status);
if (*status != 0) return;
// CS3, Allocate
if ((digitalHandles[2] = HAL_InitializeDIOPort(
HAL_GetPort(28), false, status)) == HAL_kInvalidHandle) {
std::printf("Failed to allocate DIO 28 (CS3)\n");
CommonSPIPortFree();
return;
}
HAL_SetSPIHandle(3, spilib_open("/dev/spidev0.3"));
break;
case 4:
initializeDigital(status);
if (*status != 0) return;
if ((spiMXPDigitalHandle1 = HAL_InitializeDIOPort(
if ((digitalHandles[5] = HAL_InitializeDIOPort(
HAL_GetPort(14), false, status)) == HAL_kInvalidHandle) {
std::printf("Failed to allocate DIO 14\n");
return;
}
if ((spiMXPDigitalHandle2 = HAL_InitializeDIOPort(
if ((digitalHandles[6] = HAL_InitializeDIOPort(
HAL_GetPort(15), false, status)) == HAL_kInvalidHandle) {
std::printf("Failed to allocate DIO 15\n");
HAL_FreeDIOPort(spiMXPDigitalHandle1); // free the first port allocated
HAL_FreeDIOPort(digitalHandles[5]); // free the first port allocated
return;
}
if ((spiMXPDigitalHandle3 = HAL_InitializeDIOPort(
if ((digitalHandles[7] = HAL_InitializeDIOPort(
HAL_GetPort(16), false, status)) == HAL_kInvalidHandle) {
std::printf("Failed to allocate DIO 16\n");
HAL_FreeDIOPort(spiMXPDigitalHandle1); // free the first port allocated
HAL_FreeDIOPort(
spiMXPDigitalHandle2); // free the second port allocated
HAL_FreeDIOPort(digitalHandles[5]); // free the first port allocated
HAL_FreeDIOPort(digitalHandles[6]); // free the second port allocated
return;
}
if ((spiMXPDigitalHandle4 = HAL_InitializeDIOPort(
if ((digitalHandles[8] = HAL_InitializeDIOPort(
HAL_GetPort(17), false, status)) == HAL_kInvalidHandle) {
std::printf("Failed to allocate DIO 17\n");
HAL_FreeDIOPort(spiMXPDigitalHandle1); // free the first port allocated
HAL_FreeDIOPort(
spiMXPDigitalHandle2); // free the second port allocated
HAL_FreeDIOPort(spiMXPDigitalHandle3); // free the third port allocated
HAL_FreeDIOPort(digitalHandles[5]); // free the first port allocated
HAL_FreeDIOPort(digitalHandles[6]); // free the second port allocated
HAL_FreeDIOPort(digitalHandles[7]); // free the third port allocated
return;
}
digitalSystem->writeEnableMXPSpecialFunction(
@@ -205,11 +265,28 @@ void HAL_CloseSPI(int32_t port) {
}
spilib_close(HAL_GetSPIHandle(port));
HAL_SetSPIHandle(port, 0);
if (port == 4) {
HAL_FreeDIOPort(spiMXPDigitalHandle1);
HAL_FreeDIOPort(spiMXPDigitalHandle2);
HAL_FreeDIOPort(spiMXPDigitalHandle3);
HAL_FreeDIOPort(spiMXPDigitalHandle4);
if (port < 4) {
CommonSPIPortFree();
}
switch (port) {
// Case 0 does not need to do anything
case 1:
HAL_FreeDIOPort(digitalHandles[0]);
break;
case 2:
HAL_FreeDIOPort(digitalHandles[1]);
break;
case 3:
HAL_FreeDIOPort(digitalHandles[2]);
break;
case 4:
HAL_FreeDIOPort(digitalHandles[5]);
HAL_FreeDIOPort(digitalHandles[6]);
HAL_FreeDIOPort(digitalHandles[7]);
HAL_FreeDIOPort(digitalHandles[8]);
break;
default:
break;
}
return;
}
@@ -558,7 +635,7 @@ int64_t HAL_GetSPIAccumulatorCount(int32_t port, int32_t* status) {
double HAL_GetSPIAccumulatorAverage(int32_t port, int32_t* status) {
int64_t value;
int64_t count;
HAL_GetAccumulatorOutput(port, &value, &count, status);
HAL_GetSPIAccumulatorOutput(port, &value, &count, status);
if (count == 0) return 0.0;
return static_cast<double>(value) / count;
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -7,109 +7,118 @@
#include "HAL/SerialPort.h"
#include <string>
#include "HAL/cpp/SerialHelper.h"
#include "visa/visa.h"
static int32_t m_resourceManagerHandle;
static int32_t m_portHandle[2];
static int32_t resourceManagerHandle;
static HAL_SerialPort portHandles[4];
extern "C" {
void HAL_InitializeSerialPort(int32_t port, int32_t* status) {
char const* portName;
void HAL_InitializeSerialPort(HAL_SerialPort port, int32_t* status) {
std::string portName;
if (m_resourceManagerHandle == 0)
viOpenDefaultRM(reinterpret_cast<ViSession*>(&m_resourceManagerHandle));
if (resourceManagerHandle == 0)
viOpenDefaultRM(reinterpret_cast<ViSession*>(&resourceManagerHandle));
if (port == 0)
portName = "ASRL1::INSTR";
else if (port == 1)
portName = "ASRL2::INSTR";
else
portName = "ASRL3::INSTR";
hal::SerialHelper serialHelper;
*status =
viOpen(m_resourceManagerHandle, const_cast<char*>(portName), VI_NULL,
VI_NULL, reinterpret_cast<ViSession*>(&m_portHandle[port]));
portName = serialHelper.GetVISASerialPortName(port, status);
if (*status < 0) {
return;
}
*status = viOpen(resourceManagerHandle, const_cast<char*>(portName.c_str()),
VI_NULL, VI_NULL,
reinterpret_cast<ViSession*>(&portHandles[port]));
if (*status > 0) *status = 0;
}
void HAL_SetSerialBaudRate(int32_t port, int32_t baud, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_BAUD, baud);
void HAL_SetSerialBaudRate(HAL_SerialPort port, int32_t baud, int32_t* status) {
*status = viSetAttribute(portHandles[port], VI_ATTR_ASRL_BAUD, baud);
if (*status > 0) *status = 0;
}
void HAL_SetSerialDataBits(int32_t port, int32_t bits, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_DATA_BITS, bits);
void HAL_SetSerialDataBits(HAL_SerialPort port, int32_t bits, int32_t* status) {
*status = viSetAttribute(portHandles[port], VI_ATTR_ASRL_DATA_BITS, bits);
if (*status > 0) *status = 0;
}
void HAL_SetSerialParity(int32_t port, int32_t parity, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_PARITY, parity);
void HAL_SetSerialParity(HAL_SerialPort port, int32_t parity, int32_t* status) {
*status = viSetAttribute(portHandles[port], VI_ATTR_ASRL_PARITY, parity);
if (*status > 0) *status = 0;
}
void HAL_SetSerialStopBits(int32_t port, int32_t stopBits, int32_t* status) {
*status =
viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_STOP_BITS, stopBits);
void HAL_SetSerialStopBits(HAL_SerialPort port, int32_t stopBits,
int32_t* status) {
*status = viSetAttribute(portHandles[port], VI_ATTR_ASRL_STOP_BITS, stopBits);
if (*status > 0) *status = 0;
}
void HAL_SetSerialWriteMode(int32_t port, int32_t mode, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_WR_BUF_OPER_MODE, mode);
void HAL_SetSerialWriteMode(HAL_SerialPort port, int32_t mode,
int32_t* status) {
*status = viSetAttribute(portHandles[port], VI_ATTR_WR_BUF_OPER_MODE, mode);
if (*status > 0) *status = 0;
}
void HAL_SetSerialFlowControl(int32_t port, int32_t flow, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_FLOW_CNTRL, flow);
void HAL_SetSerialFlowControl(HAL_SerialPort port, int32_t flow,
int32_t* status) {
*status = viSetAttribute(portHandles[port], VI_ATTR_ASRL_FLOW_CNTRL, flow);
if (*status > 0) *status = 0;
}
void HAL_SetSerialTimeout(int32_t port, double timeout, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_TMO_VALUE,
void HAL_SetSerialTimeout(HAL_SerialPort port, double timeout,
int32_t* status) {
*status = viSetAttribute(portHandles[port], VI_ATTR_TMO_VALUE,
static_cast<uint32_t>(timeout * 1e3));
if (*status > 0) *status = 0;
}
void HAL_EnableSerialTermination(int32_t port, char terminator,
void HAL_EnableSerialTermination(HAL_SerialPort port, char terminator,
int32_t* status) {
viSetAttribute(m_portHandle[port], VI_ATTR_TERMCHAR_EN, VI_TRUE);
viSetAttribute(m_portHandle[port], VI_ATTR_TERMCHAR, terminator);
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_END_IN,
viSetAttribute(portHandles[port], VI_ATTR_TERMCHAR_EN, VI_TRUE);
viSetAttribute(portHandles[port], VI_ATTR_TERMCHAR, terminator);
*status = viSetAttribute(portHandles[port], VI_ATTR_ASRL_END_IN,
VI_ASRL_END_TERMCHAR);
if (*status > 0) *status = 0;
}
void HAL_DisableSerialTermination(int32_t port, int32_t* status) {
viSetAttribute(m_portHandle[port], VI_ATTR_TERMCHAR_EN, VI_FALSE);
void HAL_DisableSerialTermination(HAL_SerialPort port, int32_t* status) {
viSetAttribute(portHandles[port], VI_ATTR_TERMCHAR_EN, VI_FALSE);
*status =
viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_END_IN, VI_ASRL_END_NONE);
viSetAttribute(portHandles[port], VI_ATTR_ASRL_END_IN, VI_ASRL_END_NONE);
if (*status > 0) *status = 0;
}
void HAL_SetSerialReadBufferSize(int32_t port, int32_t size, int32_t* status) {
*status = viSetBuf(m_portHandle[port], VI_READ_BUF, size);
void HAL_SetSerialReadBufferSize(HAL_SerialPort port, int32_t size,
int32_t* status) {
*status = viSetBuf(portHandles[port], VI_READ_BUF, size);
if (*status > 0) *status = 0;
}
void HAL_SetSerialWriteBufferSize(int32_t port, int32_t size, int32_t* status) {
*status = viSetBuf(m_portHandle[port], VI_WRITE_BUF, size);
void HAL_SetSerialWriteBufferSize(HAL_SerialPort port, int32_t size,
int32_t* status) {
*status = viSetBuf(portHandles[port], VI_WRITE_BUF, size);
if (*status > 0) *status = 0;
}
int32_t HAL_GetSerialBytesReceived(int32_t port, int32_t* status) {
int32_t HAL_GetSerialBytesReceived(HAL_SerialPort port, int32_t* status) {
int32_t bytes = 0;
*status = viGetAttribute(m_portHandle[port], VI_ATTR_ASRL_AVAIL_NUM, &bytes);
*status = viGetAttribute(portHandles[port], VI_ATTR_ASRL_AVAIL_NUM, &bytes);
if (*status > 0) *status = 0;
return bytes;
}
int32_t HAL_ReadSerial(int32_t port, char* buffer, int32_t count,
int32_t HAL_ReadSerial(HAL_SerialPort port, char* buffer, int32_t count,
int32_t* status) {
uint32_t retCount = 0;
*status =
viRead(m_portHandle[port], (ViPBuf)buffer, count, (ViPUInt32)&retCount);
viRead(portHandles[port], (ViPBuf)buffer, count, (ViPUInt32)&retCount);
if (*status == VI_ERROR_IO || *status == VI_ERROR_ASRL_OVERRUN ||
*status == VI_ERROR_ASRL_FRAMING || *status == VI_ERROR_ASRL_PARITY) {
@@ -121,29 +130,29 @@ int32_t HAL_ReadSerial(int32_t port, char* buffer, int32_t count,
return static_cast<int32_t>(retCount);
}
int32_t HAL_WriteSerial(int32_t port, const char* buffer, int32_t count,
int32_t HAL_WriteSerial(HAL_SerialPort port, const char* buffer, int32_t count,
int32_t* status) {
uint32_t retCount = 0;
*status =
viWrite(m_portHandle[port], (ViPBuf)buffer, count, (ViPUInt32)&retCount);
viWrite(portHandles[port], (ViPBuf)buffer, count, (ViPUInt32)&retCount);
if (*status > 0) *status = 0;
return static_cast<int32_t>(retCount);
}
void HAL_FlushSerial(int32_t port, int32_t* status) {
*status = viFlush(m_portHandle[port], VI_WRITE_BUF);
void HAL_FlushSerial(HAL_SerialPort port, int32_t* status) {
*status = viFlush(portHandles[port], VI_WRITE_BUF);
if (*status > 0) *status = 0;
}
void HAL_ClearSerial(int32_t port, int32_t* status) {
*status = viClear(m_portHandle[port]);
void HAL_ClearSerial(HAL_SerialPort port, int32_t* status) {
*status = viClear(portHandles[port]);
if (*status > 0) *status = 0;
}
void HAL_CloseSerial(int32_t port, int32_t* status) {
*status = viClose(m_portHandle[port]);
void HAL_CloseSerial(HAL_SerialPort port, int32_t* status) {
*status = viClose(portHandles[port]);
if (*status > 0) *status = 0;
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -7,8 +7,8 @@
#include "HAL/Solenoid.h"
#include "ChipObject.h"
#include "FRC_NetworkCommunication/LoadOut.h"
#include "HAL/ChipObject.h"
#include "HAL/Errors.h"
#include "HAL/Ports.h"
#include "HAL/handles/HandlesInternal.h"
@@ -55,8 +55,7 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle,
auto handle =
solenoidHandles.Allocate(module * kNumSolenoidChannels + channel, status);
if (handle == HAL_kInvalidHandle) { // out of resources
*status = NO_AVAILABLE_RESOURCES;
if (*status != 0) {
return HAL_kInvalidHandle;
}
auto solenoidPort = solenoidHandles.Get(handle);
@@ -116,6 +115,12 @@ void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value,
*status = PCM_modules[port->module]->SetSolenoid(port->channel, value);
}
void HAL_SetAllSolenoids(int32_t module, int32_t state, int32_t* status) {
if (!checkPCMInit(module, status)) return;
*status = PCM_modules[module]->SetAllSolenoids(state);
}
int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status) {
if (!checkPCMInit(module, status)) return 0;
uint8_t value;

View File

@@ -1,59 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "HAL/Task.h"
#include <signal.h>
#ifndef OK
#define OK 0
#endif /* OK */
#ifndef ERROR
#define ERROR (-1)
#endif /* ERROR */
extern "C" {
STATUS HAL_VerifyTaskID(TASK task) {
if (task != nullptr && pthread_kill(*task, 0) == 0) {
return OK;
} else {
return ERROR;
}
}
STATUS HAL_SetTaskPriority(TASK task, int32_t priority) {
int32_t policy = 0;
struct sched_param param;
if (HAL_VerifyTaskID(task) == OK &&
pthread_getschedparam(*task, &policy, &param) == 0) {
param.sched_priority = priority;
if (pthread_setschedparam(*task, SCHED_FIFO, &param) == 0) {
return OK;
} else {
return ERROR;
}
} else {
return ERROR;
}
}
STATUS HAL_GetTaskPriority(TASK task, int32_t* priority) {
int32_t policy = 0;
struct sched_param param;
if (HAL_VerifyTaskID(task) == OK &&
pthread_getschedparam(*task, &policy, &param) == 0) {
*priority = param.sched_priority;
return OK;
} else {
return ERROR;
}
}
} // extern "C"

122
hal/lib/athena/Threads.cpp Normal file
View File

@@ -0,0 +1,122 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "HAL/Threads.h"
#include <pthread.h>
#include <sched.h>
#include "HAL/Errors.h"
extern "C" {
/**
* Get the thread priority for the specified thread.
*
* @param handle Native handle pointer to the thread to get the priority for
* @param isRealTime Set to true if thread is realtime, otherwise false
* @param status Error status variable. 0 on success
* @return The current thread priority. Scaled 1-99, with 1 being highest.
*/
int32_t HAL_GetThreadPriority(NativeThreadHandle handle, HAL_Bool* isRealTime,
int32_t* status) {
sched_param sch;
int policy;
int success = pthread_getschedparam(*handle, &policy, &sch);
if (success == 0) {
*status = 0;
} else {
*status = HAL_THREAD_PRIORITY_ERROR;
return -1;
}
if (policy == SCHED_FIFO || policy == SCHED_RR) {
*isRealTime = true;
return sch.sched_priority;
} else {
*isRealTime = false;
// 0 is the only suppored priority for non-realtime, so scale to 1
return 1;
}
}
/**
* Get the thread priority for the current thread.
*
* @param handle Native handle pointer to the thread to get the priority for
* @param isRealTime Set to true if thread is realtime, otherwise false
* @param status Error status variable. 0 on success
* @return The current thread priority. Scaled 1-99, with 1 being highest.
*/
int32_t HAL_GetCurrentThreadPriority(HAL_Bool* isRealTime, int32_t* status) {
auto thread = pthread_self();
return HAL_GetThreadPriority(&thread, isRealTime, status);
}
/**
* Sets the thread priority for the specified thread
*
* @param thread Reference to the thread to set the priority of
* @param realTime Set to true to set a realtime priority, false for standard
* priority
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
* highest
* @param status Error status variable. 0 on success
*
* @return The success state of setting the priority
*/
HAL_Bool HAL_SetThreadPriority(NativeThreadHandle handle, HAL_Bool realTime,
int32_t priority, int32_t* status) {
if (handle == nullptr) {
*status = NULL_PARAMETER;
return false;
}
int scheduler = realTime ? SCHED_FIFO : SCHED_OTHER;
if (realTime) {
// We don't support setting priorities for non RT threads
// so we don't need to check for proper range
if (priority < sched_get_priority_min(scheduler) ||
priority > sched_get_priority_max(scheduler)) {
*status = HAL_THREAD_PRIORITY_RANGE_ERROR;
return false;
}
}
sched_param sch;
int policy;
pthread_getschedparam(*handle, &policy, &sch);
if (scheduler == SCHED_FIFO || scheduler == SCHED_RR)
sch.sched_priority = priority;
else
// Only need to set 0 priority for non RT thread
sch.sched_priority = 0;
if (pthread_setschedparam(*handle, scheduler, &sch)) {
*status = HAL_THREAD_PRIORITY_ERROR;
return false;
} else {
*status = 0;
return true;
}
}
/**
* Sets the thread priority for the current thread
*
* @param thread Reference to the thread to set the priority of
* @param realTime Set to true to set a realtime priority, false for standard
* priority
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
* highest
* @param status Error status variable. 0 on success
*
* @return The success state of setting the priority
*/
HAL_Bool HAL_SetCurrentThreadPriority(HAL_Bool realTime, int32_t priority,
int32_t* status) {
auto thread = pthread_self();
return HAL_SetThreadPriority(&thread, realTime, priority, status);
}
}

Some files were not shown because too many files have changed in this diff Show More