WPILibC++ 2024.3.2
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 * @param[out] status Error status variable. 0 on success.
81 */
82void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status);
83
84/**
85 * Updates the trigger time for a notifier.
86 *
87 * Note that this time is an absolute time relative to HAL_GetFPGATime()
88 *
89 * @param[in] notifierHandle the notifier handle
90 * @param[in] triggerTime the updated trigger time
91 * @param[out] status Error status variable. 0 on success.
92 */
94 uint64_t triggerTime, int32_t* status);
95
96/**
97 * Cancels the next notifier alarm.
98 *
99 * This does not cause HAL_WaitForNotifierAlarm to return.
100 *
101 * @param[in] notifierHandle the notifier handle
102 * @param[out] status Error status variable. 0 on success.
103 */
105 int32_t* status);
106
107/**
108 * Waits for the next alarm for the specific notifier.
109 *
110 * This is a blocking call until either the time elapses or HAL_StopNotifier
111 * gets called. If the latter occurs, this function will return zero and any
112 * loops using this function should exit. Failing to do so can lead to
113 * use-after-frees.
114 *
115 * @param[in] notifierHandle the notifier handle
116 * @param[out] status Error status variable. 0 on success.
117 * @return the FPGA time the notifier returned
118 */
121 int32_t* status);
122
123#ifdef __cplusplus
124} // extern "C"
125#endif
126/** @} */
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, int32_t *status)
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
constexpr const char * name(const T &)
#define WPI_NODISCARD
Definition: nodiscard.h:12