mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Removes statics from hal sim (#825)
Based off of #824, the equivelent in sim.
This commit is contained in:
committed by
Peter Johnson
parent
8bd48d6c34
commit
d2e7a90f41
@@ -60,23 +60,37 @@ struct SynchronousWaitData {
|
||||
} // namespace
|
||||
|
||||
static LimitedHandleResource<HAL_InterruptHandle, Interrupt, kNumInterrupts,
|
||||
HAL_HandleEnum::Interrupt>
|
||||
interruptHandles;
|
||||
HAL_HandleEnum::Interrupt>* interruptHandles;
|
||||
|
||||
typedef HAL_Handle SynchronousWaitDataHandle;
|
||||
static UnlimitedHandleResource<SynchronousWaitDataHandle, SynchronousWaitData,
|
||||
HAL_HandleEnum::Vendor>
|
||||
HAL_HandleEnum::Vendor>*
|
||||
synchronousInterruptHandles;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeInterrupts() {
|
||||
static LimitedHandleResource<HAL_InterruptHandle, Interrupt, kNumInterrupts,
|
||||
HAL_HandleEnum::Interrupt>
|
||||
iH;
|
||||
interruptHandles = &iH;
|
||||
static UnlimitedHandleResource<SynchronousWaitDataHandle, SynchronousWaitData,
|
||||
HAL_HandleEnum::Vendor>
|
||||
siH;
|
||||
synchronousInterruptHandles = &siH;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher,
|
||||
int32_t* status) {
|
||||
HAL_InterruptHandle handle = interruptHandles.Allocate();
|
||||
HAL_InterruptHandle handle = interruptHandles->Allocate();
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
*status = NO_AVAILABLE_RESOURCES;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
auto anInterrupt = interruptHandles.Get(handle);
|
||||
auto anInterrupt = interruptHandles->Get(handle);
|
||||
if (anInterrupt == nullptr) { // would only occur on thread issue.
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
@@ -91,8 +105,8 @@ HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher,
|
||||
}
|
||||
void HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status) {
|
||||
HAL_DisableInterrupts(interruptHandle, status);
|
||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
||||
interruptHandles.Free(interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||
interruptHandles->Free(interruptHandle);
|
||||
}
|
||||
|
||||
static void ProcessInterruptDigitalSynchronous(const char* name, void* param,
|
||||
@@ -102,9 +116,9 @@ static void ProcessInterruptDigitalSynchronous(const char* name, void* param,
|
||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||
SynchronousWaitDataHandle handle =
|
||||
static_cast<SynchronousWaitDataHandle>(handleTmp);
|
||||
auto interruptData = synchronousInterruptHandles.Get(handle);
|
||||
auto interruptData = synchronousInterruptHandles->Get(handle);
|
||||
if (interruptData == nullptr) return;
|
||||
auto interrupt = interruptHandles.Get(interruptData->interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptData->interruptHandle);
|
||||
if (interrupt == nullptr) return;
|
||||
// Have a valid interrupt
|
||||
if (value->type != HAL_Type::HAL_BOOLEAN) return;
|
||||
@@ -135,9 +149,9 @@ static void ProcessInterruptAnalogSynchronous(const char* name, void* param,
|
||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||
SynchronousWaitDataHandle handle =
|
||||
static_cast<SynchronousWaitDataHandle>(handleTmp);
|
||||
auto interruptData = synchronousInterruptHandles.Get(handle);
|
||||
auto interruptData = synchronousInterruptHandles->Get(handle);
|
||||
if (interruptData == nullptr) return;
|
||||
auto interrupt = interruptHandles.Get(interruptData->interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptData->interruptHandle);
|
||||
if (interrupt == nullptr) return;
|
||||
// Have a valid interrupt
|
||||
if (value->type != HAL_Type::HAL_DOUBLE) return;
|
||||
@@ -168,13 +182,13 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
|
||||
bool ignorePrevious) {
|
||||
auto data = std::make_shared<SynchronousWaitData>();
|
||||
|
||||
auto dataHandle = synchronousInterruptHandles.Allocate(data);
|
||||
auto dataHandle = synchronousInterruptHandles->Allocate(data);
|
||||
if (dataHandle == HAL_kInvalidHandle) {
|
||||
// Error allocating data
|
||||
return WaitResult::Timeout;
|
||||
}
|
||||
|
||||
// auto data = synchronousInterruptHandles.Get(dataHandle);
|
||||
// auto data = synchronousInterruptHandles->Get(dataHandle);
|
||||
data->waitPredicate = false;
|
||||
data->interruptHandle = handle;
|
||||
|
||||
@@ -216,7 +230,7 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
|
||||
|
||||
// Cancel our callback
|
||||
SimDIOData[digitalIndex].CancelValueCallback(uid);
|
||||
synchronousInterruptHandles.Free(dataHandle);
|
||||
synchronousInterruptHandles->Free(dataHandle);
|
||||
|
||||
// Check for what to return
|
||||
if (timedOut) return WaitResult::Timeout;
|
||||
@@ -236,7 +250,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
||||
bool ignorePrevious) {
|
||||
auto data = std::make_shared<SynchronousWaitData>();
|
||||
|
||||
auto dataHandle = synchronousInterruptHandles.Allocate(data);
|
||||
auto dataHandle = synchronousInterruptHandles->Allocate(data);
|
||||
if (dataHandle == HAL_kInvalidHandle) {
|
||||
// Error allocating data
|
||||
return WaitResult::Timeout;
|
||||
@@ -286,7 +300,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
||||
|
||||
// Cancel our callback
|
||||
SimAnalogInData[analogIndex].CancelVoltageCallback(uid);
|
||||
synchronousInterruptHandles.Free(dataHandle);
|
||||
synchronousInterruptHandles->Free(dataHandle);
|
||||
|
||||
// Check for what to return
|
||||
if (timedOut) return WaitResult::Timeout;
|
||||
@@ -304,7 +318,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
||||
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle,
|
||||
double timeout, HAL_Bool ignorePrevious,
|
||||
int32_t* status) {
|
||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||
if (interrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return WaitResult::Timeout;
|
||||
@@ -331,7 +345,7 @@ static void ProcessInterruptDigitalAsynchronous(const char* name, void* param,
|
||||
// convert to uintptr_t first, then to handle
|
||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
|
||||
auto interrupt = interruptHandles.Get(handle);
|
||||
auto interrupt = interruptHandles->Get(handle);
|
||||
if (interrupt == nullptr) return;
|
||||
// Have a valid interrupt
|
||||
if (value->type != HAL_Type::HAL_BOOLEAN) return;
|
||||
@@ -363,7 +377,7 @@ static void ProcessInterruptAnalogAsynchronous(const char* name, void* param,
|
||||
// convert to intptr_t first, then to handle
|
||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
|
||||
auto interrupt = interruptHandles.Get(handle);
|
||||
auto interrupt = interruptHandles->Get(handle);
|
||||
if (interrupt == nullptr) return;
|
||||
// Have a valid interrupt
|
||||
if (value->type != HAL_Type::HAL_DOUBLE) return;
|
||||
@@ -426,7 +440,7 @@ static void EnableInterruptsAnalog(HAL_InterruptHandle handle,
|
||||
|
||||
void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
int32_t* status) {
|
||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||
if (interrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
@@ -452,7 +466,7 @@ void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
}
|
||||
void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
int32_t* status) {
|
||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||
if (interrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
@@ -479,7 +493,7 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
}
|
||||
double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
|
||||
int32_t* status) {
|
||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||
if (interrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
@@ -489,7 +503,7 @@ double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
|
||||
}
|
||||
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle,
|
||||
int32_t* status) {
|
||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||
if (interrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
@@ -501,7 +515,7 @@ void HAL_RequestInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType analogTriggerType,
|
||||
int32_t* status) {
|
||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||
if (interrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
@@ -525,7 +539,7 @@ void HAL_RequestInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
void HAL_AttachInterruptHandler(HAL_InterruptHandle interruptHandle,
|
||||
HAL_InterruptHandlerFunction handler,
|
||||
void* param, int32_t* status) {
|
||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||
if (interrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
@@ -544,7 +558,7 @@ void HAL_AttachInterruptHandlerThreaded(HAL_InterruptHandle interruptHandle,
|
||||
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle,
|
||||
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
||||
int32_t* status) {
|
||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
||||
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||
if (interrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user