WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
Notifier.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#include <wpi/nodiscard.h>
10
11#include "hal/Types.h"
12
13/**
14 * @defgroup hal_notifier Notifier Functions
15 * @ingroup hal_capi
16 * @{
17 */
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/**
24 * Initializes a notifier.
25 *
26 * A notifier is an FPGA controller timer that triggers at requested intervals
27 * based on the FPGA time. This can be used to make precise control loops.
28 *
29 * @param[out] status Error status variable. 0 on success.
30 * @return the created notifier
31 */
33
34/**
35 * Sets the HAL notifier thread priority.
36 *
37 * The HAL notifier thread is responsible for managing the FPGA's notifier
38 * interrupt and waking up user's Notifiers when it's their time to run.
39 * Giving the HAL notifier thread real-time priority helps ensure the user's
40 * real-time Notifiers, if any, are notified to run in a timely manner.
41 *
42 * @param[in] realTime Set to true to set a real-time priority, false for
43 * standard priority.
44 * @param[in] priority Priority to set the thread to. For real-time, this is
45 * 1-99 with 99 being highest. For non-real-time, this is
46 * forced to 0. See "man 7 sched" for more details.
47 * @param[out] status Error status variable. 0 on success.
48 * @return True on success.
49 */
51 int32_t* status);
52
53/**
54 * Sets the name of a notifier.
55 *
56 * @param[in] notifierHandle the notifier handle
57 * @param[in] name name
58 * @param[out] status Error status variable. 0 on success.
59 */
60void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char* name,
61 int32_t* status);
62
63/**
64 * Stops a notifier from running.
65 *
66 * This will cause any call into HAL_WaitForNotifierAlarm to return with time =
67 * 0.
68 *
69 * @param[in] notifierHandle the notifier handle
70 * @param[out] status Error status variable. 0 on success.
71 */
72void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status);
73
74/**
75 * Cleans a notifier.
76 *
77 * Note this also stops a notifier if it is already running.
78 *
79 * @param[in] notifierHandle the notifier handle
80 */
82
83/**
84 * Updates the trigger time for a notifier.
85 *
86 * Note that this time is an absolute time relative to HAL_GetFPGATime()
87 *
88 * @param[in] notifierHandle the notifier handle
89 * @param[in] triggerTime the updated trigger time
90 * @param[out] status Error status variable. 0 on success.
91 */
93 uint64_t triggerTime, int32_t* status);
94
95/**
96 * Cancels the next notifier alarm.
97 *
98 * This does not cause HAL_WaitForNotifierAlarm to return.
99 *
100 * @param[in] notifierHandle the notifier handle
101 * @param[out] status Error status variable. 0 on success.
102 */
104 int32_t* status);
105
106/**
107 * Waits for the next alarm for the specific notifier.
108 *
109 * This is a blocking call until either the time elapses or HAL_StopNotifier
110 * gets called. If the latter occurs, this function will return zero and any
111 * loops using this function should exit. Failing to do so can lead to
112 * use-after-frees.
113 *
114 * @param[in] notifierHandle the notifier handle
115 * @param[out] status Error status variable. 0 on success.
116 * @return the FPGA time the notifier returned
117 */
120 int32_t* status);
121
122#ifdef __cplusplus
123} // extern "C"
124#endif
125/** @} */
HAL_Bool HAL_SetNotifierThreadPriority(HAL_Bool realTime, int32_t priority, int32_t *status)
Sets the HAL notifier thread priority.
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle)
Cleans a notifier.
HAL_NotifierHandle HAL_InitializeNotifier(int32_t *status)
Initializes a notifier.
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t triggerTime, int32_t *status)
Updates the trigger time for a notifier.
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, int32_t *status)
Cancels the next notifier alarm.
void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char *name, int32_t *status)
Sets the name of a notifier.
WPI_NODISCARD uint64_t HAL_WaitForNotifierAlarm(HAL_NotifierHandle notifierHandle, int32_t *status)
Waits for the next alarm for the specific notifier.
void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t *status)
Stops a notifier from running.
int32_t HAL_Bool
Definition Types.h:73
HAL_Handle HAL_NotifierHandle
Definition Types.h:43
#define WPI_NODISCARD
Definition nodiscard.h:12