WPILibC++ 2024.3.2
WPILib HAL API

Hardware Abstraction Layer (HAL) to hardware or simulator. More...

Modules

 Notifier Functions
 
 SPI Functions
 
 Addressable LED Functions
 
 Analog Trigger Functions
 
 Driver Station Functions
 
 Simulator Extensions
 HAL Simulator Extensions.
 
 Constants Functions
 
 Type Definitions
 
 PWM Output Functions
 
 Encoder Functions
 
 DMA Functions
 
 Main loop functions
 
 Simulator Device Framework
 HAL Simulator Device Framework.
 
 Analog Accumulator Functions
 
 Ports Functions
 
 CAN Stream Functions
 
 Analog Output Functions
 
 Analog Gyro Functions
 
 Relay Output Functions
 
 DIO Functions
 
 Accelerometer Functions
 
 I2C Functions
 
 CAN API Functions
 
 REV Pneumatic Hub (PH) Functions
 
 Analog Input Functions
 
 Counter Functions
 
 Serial Port Functions
 
 Threads Functions
 
 Power Distribution Functions
 Functions to control Power Distribution devices.
 
 Power Functions
 
 Error Defines
 
 Interrupts Functions
 
 DutyCycle Functions
 
 CTRE Pneumatic Control Module (PCM) Functions
 

Enumerations

enum  HAL_RuntimeType : int32_t { HAL_Runtime_RoboRIO , HAL_Runtime_RoboRIO2 , HAL_Runtime_Simulation }
 

Functions

const char * HAL_GetLastError (int32_t *status)
 Gets the last error set on this thread, or the message for the status code. More...
 
const char * HAL_GetErrorMessage (int32_t code)
 Gets the error message for a specific status code. More...
 
int32_t HAL_GetFPGAVersion (int32_t *status)
 Returns the FPGA Version number. More...
 
int64_t HAL_GetFPGARevision (int32_t *status)
 Returns the FPGA Revision number. More...
 
size_t HAL_GetSerialNumber (char *buffer, size_t size)
 Returns the roboRIO serial number. More...
 
size_t HAL_GetComments (char *buffer, size_t size)
 Returns the comments from the roboRIO web interface. More...
 
int32_t HAL_GetTeamNumber (void)
 Returns the team number configured for the robot controller. More...
 
HAL_RuntimeType HAL_GetRuntimeType (void)
 Returns the runtime type of the HAL. More...
 
HAL_Bool HAL_GetFPGAButton (int32_t *status)
 Gets the state of the "USER" button on the roboRIO. More...
 
HAL_Bool HAL_GetSystemActive (int32_t *status)
 Gets if the system outputs are currently active. More...
 
HAL_Bool HAL_GetBrownedOut (int32_t *status)
 Gets if the system is in a browned out state. More...
 
HAL_PortHandle HAL_GetPort (int32_t channel)
 Gets a port handle for a specific channel. More...
 
HAL_PortHandle HAL_GetPortWithModule (int32_t module, int32_t channel)
 Gets a port handle for a specific channel and module. More...
 
uint64_t HAL_GetFPGATime (int32_t *status)
 Reads the microsecond-resolution timer on the FPGA. More...
 
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. More...
 
HAL_Bool HAL_GetRSLState (int32_t *status)
 Gets the current state of the Robot Signal Light (RSL). More...
 
HAL_Bool HAL_GetSystemTimeValid (int32_t *status)
 Gets if the system time is valid. More...
 
HAL_Bool HAL_Initialize (int32_t timeout, int32_t mode)
 Call this to start up HAL. More...
 
void HAL_Shutdown (void)
 Call this to shut down HAL. More...
 
void HAL_SimPeriodicBefore (void)
 Calls registered SimPeriodic "before" callbacks (only in simulation mode). More...
 
void HAL_SimPeriodicAfter (void)
 Calls registered SimPeriodic "after" callbacks (only in simulation mode). More...
 

Detailed Description

Hardware Abstraction Layer (HAL) to hardware or simulator.

Enumeration Type Documentation

◆ HAL_RuntimeType

enum HAL_RuntimeType : int32_t
Enumerator
HAL_Runtime_RoboRIO 
HAL_Runtime_RoboRIO2 
HAL_Runtime_Simulation 

Function Documentation

◆ HAL_ExpandFPGATime()

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.

Note: This is making the assumption that the timestamp being converted is always in the past. If you call this with a future timestamp, it probably will make it in the past. If you wait over 70 minutes between capturing the bottom 32 bits of the timestamp and expanding it, you will be off by multiples of 1<<32 microseconds.

Parameters
[in]unexpandedLower32 bit FPGA time
[out]statusthe error code, or 0 for success
Returns
The current time in microseconds according to the FPGA (since FPGA reset) as a 64 bit number.

◆ HAL_GetBrownedOut()

HAL_Bool HAL_GetBrownedOut ( int32_t *  status)

Gets if the system is in a browned out state.

Parameters
[out]statusthe error code, or 0 for success
Returns
true if the system is in a low voltage brown out, false otherwise

◆ HAL_GetComments()

size_t HAL_GetComments ( char *  buffer,
size_t  size 
)

Returns the comments from the roboRIO web interface.

Parameters
[out]bufferThe comments string.
sizeThe maximum characters to copy into buffer.
Returns
Number of characters copied into buffer.

◆ HAL_GetErrorMessage()

const char * HAL_GetErrorMessage ( int32_t  code)

Gets the error message for a specific status code.

Parameters
codethe status code
Returns
the error message for the code. This does not need to be freed.

◆ HAL_GetFPGAButton()

HAL_Bool HAL_GetFPGAButton ( int32_t *  status)

Gets the state of the "USER" button on the roboRIO.

Warning
the User Button is used to stop user programs from automatically loading if it is held for more then 5 seconds. Because of this, it's not recommended to be used by teams for any other purpose.
Parameters
[out]statusthe error code, or 0 for success
Returns
true if the button is currently pressed down

◆ HAL_GetFPGARevision()

int64_t HAL_GetFPGARevision ( int32_t *  status)

Returns the FPGA Revision number.

The format of the revision is 3 numbers. The 12 most significant bits are the Major Revision. the next 8 bits are the Minor Revision. The 12 least significant bits are the Build Number.

Parameters
[out]statusthe error code, or 0 for success
Returns
FPGA Revision number.

◆ HAL_GetFPGATime()

uint64_t HAL_GetFPGATime ( int32_t *  status)

Reads the microsecond-resolution timer on the FPGA.

Parameters
[out]statusthe error code, or 0 for success
Returns
The current time in microseconds according to the FPGA (since FPGA reset).

◆ HAL_GetFPGAVersion()

int32_t HAL_GetFPGAVersion ( int32_t *  status)

Returns the FPGA Version number.

For now, expect this to be competition year.

Parameters
[out]statusthe error code, or 0 for success
Returns
FPGA Version number.

◆ HAL_GetLastError()

const char * HAL_GetLastError ( int32_t *  status)

Gets the last error set on this thread, or the message for the status code.

If passed HAL_USE_LAST_ERROR, the last error set on the thread will be returned.

Parameters
[out]statusthe status code, set to the error status code if input is HAL_USE_LAST_ERROR
Returns
the error message for the code. This does not need to be freed, but can be overwritten by another hal call on the same thread.

◆ HAL_GetPort()

HAL_PortHandle HAL_GetPort ( int32_t  channel)

Gets a port handle for a specific channel.

The created handle does not need to be freed.

Parameters
channelthe channel number
Returns
the created port

◆ HAL_GetPortWithModule()

HAL_PortHandle HAL_GetPortWithModule ( int32_t  module,
int32_t  channel 
)

Gets a port handle for a specific channel and module.

This is expected to be used for PCMs, as the roboRIO does not work with modules anymore.

The created handle does not need to be freed.

Parameters
modulethe module number
channelthe channel number
Returns
the created port

◆ HAL_GetRSLState()

HAL_Bool HAL_GetRSLState ( int32_t *  status)

Gets the current state of the Robot Signal Light (RSL).

Parameters
[out]statusthe error code, or 0 for success
Returns
The current state of the RSL- true if on, false if off

◆ HAL_GetRuntimeType()

HAL_RuntimeType HAL_GetRuntimeType ( void  )

Returns the runtime type of the HAL.

Returns
HAL Runtime Type

◆ HAL_GetSerialNumber()

size_t HAL_GetSerialNumber ( char *  buffer,
size_t  size 
)

Returns the roboRIO serial number.

Parameters
[out]bufferThe roboRIO serial number.
sizeThe maximum characters to copy into buffer.
Returns
Number of characters copied into buffer.

◆ HAL_GetSystemActive()

HAL_Bool HAL_GetSystemActive ( int32_t *  status)

Gets if the system outputs are currently active.

Parameters
[out]statusthe error code, or 0 for success
Returns
true if the system outputs are active, false if disabled

◆ HAL_GetSystemTimeValid()

HAL_Bool HAL_GetSystemTimeValid ( int32_t *  status)

Gets if the system time is valid.

Parameters
[out]statusthe error code, or 0 for success
Returns
True if the system time is valid, false otherwise

◆ HAL_GetTeamNumber()

int32_t HAL_GetTeamNumber ( void  )

Returns the team number configured for the robot controller.

Returns
team number, or 0 if not found.

◆ HAL_Initialize()

HAL_Bool HAL_Initialize ( int32_t  timeout,
int32_t  mode 
)

Call this to start up HAL.

This is required for robot programs.

This must be called before any other HAL functions. Failure to do so will result in undefined behavior, and likely segmentation faults. This means that any statically initialized variables in a program MUST call this function in their constructors if they want to use other HAL calls.

The common parameters are 500 for timeout and 0 for mode.

This function is safe to call from any thread, and as many times as you wish. It internally guards from any reentrancy.

The applicable modes are: 0: Try to kill an existing HAL from another program, if not successful, error. 1: Force kill a HAL from another program. 2: Just warn if another hal exists and cannot be killed. Will likely result in undefined behavior.

Parameters
timeoutthe initialization timeout (ms)
modethe initialization mode (see remarks)
Returns
true if initialization was successful, otherwise false.

◆ HAL_Shutdown()

void HAL_Shutdown ( void  )

Call this to shut down HAL.

This must be called at termination of the robot program to avoid potential segmentation faults with simulation extensions at exit.

◆ HAL_SimPeriodicAfter()

void HAL_SimPeriodicAfter ( void  )

Calls registered SimPeriodic "after" callbacks (only in simulation mode).

This should be called after user code periodic simulation functions.

◆ HAL_SimPeriodicBefore()

void HAL_SimPeriodicBefore ( void  )

Calls registered SimPeriodic "before" callbacks (only in simulation mode).

This should be called prior to user code periodic simulation functions.