WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
HAL.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#include <stddef.h>
13#endif
14
15#include "wpi/hal/Types.h"
16#include "wpi/util/string.h"
17
18/**
19 * @defgroup hal_capi WPILib HAL API
20 * Hardware Abstraction Layer (HAL) to hardware or simulator
21 * @{
22 */
23
24/**
25 * Runtime type.
26 */
28 /** Systemcore runtime */
30 /** Simulation runtime */
32};
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/**
39 * Gets the last error set on this thread, or the message for the status code.
40 *
41 * If passed HAL_USE_LAST_ERROR, the last error set on the thread will be
42 * returned.
43 *
44 * @param[out] status the status code, set to the error status code if input is
45 * HAL_USE_LAST_ERROR
46 * @return the error message for the code. This does not need to be freed,
47 * but can be overwritten by another hal call on the same thread.
48 */
49const char* HAL_GetLastError(HAL_Status* status);
50
51/**
52 * Gets the error message for a specific status code.
53 *
54 * @param code the status code
55 * @return the error message for the code. This does not need to be freed.
56 */
57const char* HAL_GetErrorMessage(int32_t code);
58
59/**
60 * Returns the roboRIO serial number.
61 *
62 * @param[out] serialNumber The roboRIO serial number. Free with WPI_FreeString
63 */
64void HAL_GetSerialNumber(struct WPI_String* serialNumber);
65
66/**
67 * Returns the comments from the roboRIO web interface.
68 *
69 * @param[out] comments The comments string. Free with WPI_FreeString
70 */
71void HAL_GetComments(struct WPI_String* comments);
72
73/**
74 * Returns the team number configured for the robot controller.
75 * @return team number, or 0 if not found.
76 */
77int32_t HAL_GetTeamNumber(void);
78
79/**
80 * Returns the runtime type of the HAL.
81 *
82 * @return HAL Runtime Type
83 */
85
86/**
87 * Gets if the system outputs are currently active.
88 *
89 * @param[out] status the error code, or 0 for success
90 * @return true if the system outputs are active, false if disabled
91 */
93
94/**
95 * Gets if the system is in a browned out state.
96 *
97 * @param[out] status the error code, or 0 for success
98 * @return true if the system is in a low voltage brown out, false otherwise
99 */
101
102/**
103 * Gets the number of times the system has been disabled due to communication
104 * errors with the Driver Station.
105 * @return number of disables due to communication errors.
106 */
107int32_t HAL_GetCommsDisableCount(int32_t* status);
108
109/**
110 * Reads the microsecond-resolution monotonic timer.
111 *
112 * @return The current monotonic time in microseconds.
113 */
114uint64_t HAL_GetMonotonicTime(void);
115
116/**
117 * Gets the current state of the Robot Signal Light (RSL).
118 *
119 * @param[out] status the error code, or 0 for success
120 * @return The current state of the RSL- true if on, false if off
121 */
122HAL_Bool HAL_GetRSLState(int32_t* status);
123
124/**
125 * Gets if the system time is valid.
126 *
127 * @param[out] status the error code, or 0 for success
128 * @return True if the system time is valid, false otherwise
129 */
131
132/**
133 * Call this to start up HAL. This is required for robot programs.
134 *
135 * This must be called before any other HAL functions. Failure to do so will
136 * result in undefined behavior, and likely segmentation faults. This means that
137 * any statically initialized variables in a program MUST call this function in
138 * their constructors if they want to use other HAL calls.
139 *
140 * The common parameters are 500 for timeout and 0 for mode.
141 *
142 * This function is safe to call from any thread, and as many times as you wish.
143 * It internally guards from any reentrancy.
144 *
145 * The applicable modes are:
146 * 0: Try to kill an existing HAL from another program, if not successful,
147 * error.
148 * 1: Force kill a HAL from another program.
149 * 2: Just warn if another hal exists and cannot be killed. Will likely result
150 * in undefined behavior.
151 *
152 * @param timeout the initialization timeout (ms)
153 * @param mode the initialization mode (see remarks)
154 * @return true if initialization was successful, otherwise false.
155 */
156HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode);
157
158/**
159 * Call this to shut down HAL.
160 *
161 * This must be called at termination of the robot program to avoid potential
162 * segmentation faults with simulation extensions at exit.
163 */
164void HAL_Shutdown(void);
165
166/**
167 * Calls registered SimPeriodic "before" callbacks (only in simulation mode).
168 * This should be called prior to user code periodic simulation functions.
169 */
171
172/**
173 * Calls registered SimPeriodic "after" callbacks (only in simulation mode).
174 * This should be called after user code periodic simulation functions.
175 */
177
178#ifdef __cplusplus
179} // extern "C"
180#endif
181/** @} */
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 glfw and nanopb were 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:118
int32_t HAL_GetTeamNumber(void)
Returns the team number configured for the robot controller.
uint64_t HAL_GetMonotonicTime(void)
Reads the microsecond-resolution monotonic timer.
HAL_Bool HAL_GetSystemActive(int32_t *status)
Gets if the system outputs are currently active.
HAL_RuntimeType
Runtime type.
Definition HAL.h:27
void HAL_GetComments(struct WPI_String *comments)
Returns the comments from the roboRIO web interface.
const char * HAL_GetLastError(HAL_Status *status)
Gets the last error set on this thread, or the message for the status code.
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.
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.
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_SYSTEMCORE
Systemcore runtime.
Definition HAL.h:29
@ HAL_RUNTIME_SIMULATION
Simulation runtime.
Definition HAL.h:31
int32_t HAL_Bool
Definition Types.h:65
int32_t HAL_Status
Definition Types.h:67
#define HAL_ENUM(name)
Definition Types.h:82
A const UTF8 string.
Definition string.h:40