[hal] Add function for changing HAL Notifier thread priority (#3218)

This commit is contained in:
Tyler Veness
2021-02-28 22:05:26 -08:00
committed by GitHub
parent 40b367513f
commit 3cf44e0a53
8 changed files with 86 additions and 0 deletions

View File

@@ -17,6 +17,7 @@
#include "hal/ChipObject.h"
#include "hal/Errors.h"
#include "hal/HAL.h"
#include "hal/Threads.h"
#include "hal/handles/UnlimitedHandleResource.h"
using namespace hal;
@@ -156,6 +157,12 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
return handle;
}
HAL_Bool HAL_SetNotifierThreadPriority(HAL_Bool realTime, int32_t priority,
int32_t* status) {
auto native = notifierThread.native_handle();
return HAL_SetThreadPriority(&native, realTime, priority, status);
}
void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char* name,
int32_t* status) {}

View File

@@ -36,6 +36,19 @@ Java_edu_wpi_first_hal_NotifierJNI_initializeNotifier
return (jint)notifierHandle;
}
/*
* Class: edu_wpi_first_hal_NotifierJNI
* Method: setHALThreadPriority
* Signature: (ZI)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_NotifierJNI_setHALThreadPriority
(JNIEnv* env, jclass, jboolean realTime, jint priority)
{
int32_t status = 0;
return HAL_SetNotifierThreadPriority(realTime, priority, &status);
}
/*
* Class: edu_wpi_first_hal_NotifierJNI
* Method: setNotifierName

View File

@@ -30,6 +30,25 @@ extern "C" {
*/
HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status);
/**
* Sets the HAL notifier thread priority.
*
* The HAL notifier thread is responsible for managing the FPGA's notifier
* interrupt and waking up user's Notifiers when it's their time to run.
* Giving the HAL notifier thread real-time priority helps ensure the user's
* real-time Notifiers, if any, are notified to run in a timely manner.
*
* @param realTime Set to true to set a real-time priority, false for standard
* priority.
* @param priority Priority to set the thread to. For real-time, this is 1-99
* with 99 being highest. For non-real-time, this is forced to
* 0. See "man 7 sched" for more details.
* @param status Error status variable. 0 on success.
* @return True on success.
*/
HAL_Bool HAL_SetNotifierThreadPriority(HAL_Bool realTime, int32_t priority,
int32_t* status);
/**
* Sets the name of a notifier.
*

View File

@@ -174,6 +174,11 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
return handle;
}
HAL_Bool HAL_SetNotifierThreadPriority(HAL_Bool realTime, int32_t priority,
int32_t* status) {
return true;
}
void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char* name,
int32_t* status) {
auto notifier = notifierHandles->Get(notifierHandle);