mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Add FPGA Duty Cycle support (#1987)
This commit is contained in:
committed by
Peter Johnson
parent
509819d83f
commit
1d695a1660
63
hal/src/main/native/sim/mockdata/DutyCycleData.cpp
Normal file
63
hal/src/main/native/sim/mockdata/DutyCycleData.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "../PortsInternal.h"
|
||||
#include "DutyCycleDataInternal.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeDutyCycleData() {
|
||||
static DutyCycleData sed[kNumDutyCycles];
|
||||
::hal::SimDutyCycleData = sed;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
DutyCycleData* hal::SimDutyCycleData;
|
||||
|
||||
void DutyCycleData::ResetData() {
|
||||
digitalChannel = 0;
|
||||
initialized.Reset(false);
|
||||
simDevice = 0;
|
||||
frequency.Reset(0);
|
||||
output.Reset(0);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void HALSIM_ResetDutyCycleData(int32_t index) {
|
||||
SimDutyCycleData[index].ResetData();
|
||||
}
|
||||
int32_t HALSIM_GetDutyCycleDigitalChannel(int32_t index) {
|
||||
return SimDutyCycleData[index].digitalChannel;
|
||||
}
|
||||
|
||||
HAL_SimDeviceHandle HALSIM_GetDutyCycleSimDevice(int32_t index) {
|
||||
return SimDutyCycleData[index].simDevice;
|
||||
}
|
||||
|
||||
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
||||
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, DutyCycle##CAPINAME, \
|
||||
SimDutyCycleData, LOWERNAME)
|
||||
|
||||
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
|
||||
DEFINE_CAPI(int32_t, Frequency, frequency)
|
||||
DEFINE_CAPI(double, Output, output)
|
||||
|
||||
#define REGISTER(NAME) \
|
||||
SimDutyCycleData[index].NAME.RegisterCallback(callback, param, initialNotify)
|
||||
|
||||
void HALSIM_RegisterDutyCycleAllCallbacks(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify) {
|
||||
REGISTER(initialized);
|
||||
REGISTER(frequency);
|
||||
REGISTER(output);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
Reference in New Issue
Block a user