WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
HALBase.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#ifdef __cplusplus
10#include <cstddef>
11#else
12
13#include <stddef.h> // NOLINT(build/include_order)
14
15#endif
16
17#include <wpi/string.h>
18
19#include "hal/Types.h"
20
21/**
22 * @defgroup hal_capi WPILib HAL API
23 * Hardware Abstraction Layer (HAL) to hardware or simulator
24 * @{
25 */
26
27/**
28 * Runtime type.
29 */
31 /** roboRIO 1.0 */
33 /** roboRIO 2.0 */
35 /** Simulation runtime */
37};
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/**
44 * Gets the last error set on this thread, or the message for the status code.
45 *
46 * If passed HAL_USE_LAST_ERROR, the last error set on the thread will be
47 * returned.
48 *
49 * @param[out] status the status code, set to the error status code if input is
50 * HAL_USE_LAST_ERROR
51 * @return the error message for the code. This does not need to be freed,
52 * but can be overwritten by another hal call on the same thread.
53 */
54const char* HAL_GetLastError(int32_t* status);
55
56/**
57 * Gets the error message for a specific status code.
58 *
59 * @param code the status code
60 * @return the error message for the code. This does not need to be freed.
61 */
62const char* HAL_GetErrorMessage(int32_t code);
63
64/**
65 * Returns the FPGA Version number.
66 *
67 * For now, expect this to be competition year.
68 *
69 * @param[out] status the error code, or 0 for success
70 * @return FPGA Version number.
71 */
72int32_t HAL_GetFPGAVersion(int32_t* status);
73
74/**
75 * Returns the FPGA Revision number.
76 *
77 * The format of the revision is 3 numbers.
78 * The 12 most significant bits are the Major Revision.
79 * the next 8 bits are the Minor Revision.
80 * The 12 least significant bits are the Build Number.
81 *
82 * @param[out] status the error code, or 0 for success
83 * @return FPGA Revision number.
84 */
85int64_t HAL_GetFPGARevision(int32_t* status);
86
87/**
88 * Returns the roboRIO serial number.
89 *
90 * @param[out] serialNumber The roboRIO serial number. Free with WPI_FreeString
91 */
92void HAL_GetSerialNumber(struct WPI_String* serialNumber);
93
94/**
95 * Returns the comments from the roboRIO web interface.
96 *
97 * @param[out] comments The comments string. Free with WPI_FreeString
98 */
99void HAL_GetComments(struct WPI_String* comments);
100
101/**
102 * Returns the team number configured for the robot controller.
103 * @return team number, or 0 if not found.
104 */
105int32_t HAL_GetTeamNumber(void);
106
107/**
108 * Returns the runtime type of the HAL.
109 *
110 * @return HAL Runtime Type
111 */
113
114/**
115 * Gets the state of the "USER" button on the roboRIO.
116 *
117 * @warning the User Button is used to stop user programs from automatically
118 * loading if it is held for more then 5 seconds. Because of this, it's not
119 * recommended to be used by teams for any other purpose.
120 *
121 * @param[out] status the error code, or 0 for success
122 * @return true if the button is currently pressed down
123 */
125
126/**
127 * Gets if the system outputs are currently active.
128 *
129 * @param[out] status the error code, or 0 for success
130 * @return true if the system outputs are active, false if disabled
131 */
133
134/**
135 * Gets if the system is in a browned out state.
136 *
137 * @param[out] status the error code, or 0 for success
138 * @return true if the system is in a low voltage brown out, false otherwise
139 */
141
142/**
143 * Gets the number of times the system has been disabled due to communication
144 * errors with the Driver Station.
145 * @return number of disables due to communication errors.
146 */
147int32_t HAL_GetCommsDisableCount(int32_t* status);
148
149/**
150 * Gets a port handle for a specific channel.
151 *
152 * The created handle does not need to be freed.
153 *
154 * @param channel the channel number
155 * @return the created port
156 */
158
159/**
160 * Gets a port handle for a specific channel and module.
161 *
162 * This is expected to be used for PCMs, as the roboRIO does not work with
163 * modules anymore.
164 *
165 * The created handle does not need to be freed.
166 *
167 * @param module the module number
168 * @param channel the channel number
169 * @return the created port
170 */
171HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);
172
173/**
174 * Reads the microsecond-resolution timer on the FPGA.
175 *
176 * @param[out] status the error code, or 0 for success
177 * @return The current time in microseconds according to the FPGA (since FPGA
178 * reset).
179 */
180uint64_t HAL_GetFPGATime(int32_t* status);
181
182/**
183 * Given an 32 bit FPGA time, expand it to the nearest likely 64 bit FPGA time.
184 *
185 * Note: This is making the assumption that the timestamp being converted is
186 * always in the past. If you call this with a future timestamp, it probably
187 * will make it in the past. If you wait over 70 minutes between capturing the
188 * bottom 32 bits of the timestamp and expanding it, you will be off by
189 * multiples of 1<<32 microseconds.
190 *
191 * @param[in] unexpandedLower 32 bit FPGA time
192 * @param[out] status the error code, or 0 for success
193 * @return The current time in microseconds according to the FPGA (since FPGA
194 * reset) as a 64 bit number.
195 */
196uint64_t HAL_ExpandFPGATime(uint32_t unexpandedLower, int32_t* status);
197
198/**
199 * Gets the current state of the Robot Signal Light (RSL).
200 *
201 * @param[out] status the error code, or 0 for success
202 * @return The current state of the RSL- true if on, false if off
203 */
204HAL_Bool HAL_GetRSLState(int32_t* status);
205
206/**
207 * Gets if the system time is valid.
208 *
209 * @param[out] status the error code, or 0 for success
210 * @return True if the system time is valid, false otherwise
211 */
213
214/**
215 * Call this to start up HAL. This is required for robot programs.
216 *
217 * This must be called before any other HAL functions. Failure to do so will
218 * result in undefined behavior, and likely segmentation faults. This means that
219 * any statically initialized variables in a program MUST call this function in
220 * their constructors if they want to use other HAL calls.
221 *
222 * The common parameters are 500 for timeout and 0 for mode.
223 *
224 * This function is safe to call from any thread, and as many times as you wish.
225 * It internally guards from any reentrancy.
226 *
227 * The applicable modes are:
228 * 0: Try to kill an existing HAL from another program, if not successful,
229 * error.
230 * 1: Force kill a HAL from another program.
231 * 2: Just warn if another hal exists and cannot be killed. Will likely result
232 * in undefined behavior.
233 *
234 * @param timeout the initialization timeout (ms)
235 * @param mode the initialization mode (see remarks)
236 * @return true if initialization was successful, otherwise false.
237 */
238HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode);
239
240/**
241 * Call this to shut down HAL.
242 *
243 * This must be called at termination of the robot program to avoid potential
244 * segmentation faults with simulation extensions at exit.
245 */
246void HAL_Shutdown(void);
247
248/**
249 * Calls registered SimPeriodic "before" callbacks (only in simulation mode).
250 * This should be called prior to user code periodic simulation functions.
251 */
253
254/**
255 * Calls registered SimPeriodic "after" callbacks (only in simulation mode).
256 * This should be called after user code periodic simulation functions.
257 */
259
260#ifdef __cplusplus
261} // extern "C"
262#endif
263/** @} */
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or and nanopb were all modified for use in Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source code
Definition ThirdPartyNotices.txt:123
int32_t HAL_GetTeamNumber(void)
Returns the team number configured for the robot controller.
HAL_PortHandle HAL_GetPort(int32_t channel)
Gets a port handle for a specific channel.
HAL_Bool HAL_GetFPGAButton(int32_t *status)
Gets the state of the "USER" button on the roboRIO.
const char * HAL_GetLastError(int32_t *status)
Gets the last error set on this thread, or the message for the status code.
HAL_Bool HAL_GetSystemActive(int32_t *status)
Gets if the system outputs are currently active.
HAL_RuntimeType
Runtime type.
Definition HALBase.h:30
void HAL_GetComments(struct WPI_String *comments)
Returns the comments from the roboRIO web interface.
uint64_t HAL_ExpandFPGATime(uint32_t unexpandedLower, int32_t *status)
Given an 32 bit FPGA time, expand it to the nearest likely 64 bit FPGA time.
const char * HAL_GetErrorMessage(int32_t code)
Gets the error message for a specific status code.
HAL_RuntimeType HAL_GetRuntimeType(void)
Returns the runtime type of the HAL.
uint64_t HAL_GetFPGATime(int32_t *status)
Reads the microsecond-resolution timer on the FPGA.
int64_t HAL_GetFPGARevision(int32_t *status)
Returns the FPGA Revision number.
int32_t HAL_GetFPGAVersion(int32_t *status)
Returns the FPGA Version number.
HAL_Bool HAL_GetBrownedOut(int32_t *status)
Gets if the system is in a browned out state.
void HAL_GetSerialNumber(struct WPI_String *serialNumber)
Returns the roboRIO serial number.
HAL_Bool HAL_GetSystemTimeValid(int32_t *status)
Gets if the system time is valid.
int32_t HAL_GetCommsDisableCount(int32_t *status)
Gets the number of times the system has been disabled due to communication errors with the Driver Sta...
HAL_Bool HAL_GetRSLState(int32_t *status)
Gets the current state of the Robot Signal Light (RSL).
HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode)
Call this to start up HAL.
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel)
Gets a port handle for a specific channel and module.
void HAL_SimPeriodicAfter(void)
Calls registered SimPeriodic "after" callbacks (only in simulation mode).
void HAL_SimPeriodicBefore(void)
Calls registered SimPeriodic "before" callbacks (only in simulation mode).
void HAL_Shutdown(void)
Call this to shut down HAL.
@ HAL_Runtime_RoboRIO2
roboRIO 2.0
Definition HALBase.h:34
@ HAL_Runtime_RoboRIO
roboRIO 1.0
Definition HALBase.h:32
@ HAL_Runtime_Simulation
Simulation runtime.
Definition HALBase.h:36
int32_t HAL_Bool
Definition Types.h:73
HAL_Handle HAL_PortHandle
Definition Types.h:19
#define HAL_ENUM(name)
Definition Types.h:76
A const UTF8 string.
Definition string.h:14