2017-10-19 02:01:58 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-10-03 12:21:03 -04:00
|
|
|
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
|
2017-10-19 02:01:58 -04:00
|
|
|
/* 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 "SPIDataInternal.h"
|
|
|
|
|
|
|
|
|
|
using namespace hal;
|
|
|
|
|
|
2017-12-10 19:38:53 -08:00
|
|
|
namespace hal {
|
|
|
|
|
namespace init {
|
|
|
|
|
void InitializeSPIData() {
|
|
|
|
|
static SPIData ssd[5];
|
|
|
|
|
::hal::SimSPIData = ssd;
|
|
|
|
|
}
|
|
|
|
|
} // namespace init
|
|
|
|
|
} // namespace hal
|
2017-10-19 02:01:58 -04:00
|
|
|
|
2017-12-10 19:38:53 -08:00
|
|
|
SPIData* hal::SimSPIData;
|
2017-10-19 02:01:58 -04:00
|
|
|
void SPIData::ResetData() {
|
2018-09-03 16:08:07 -07:00
|
|
|
initialized.Reset(false);
|
|
|
|
|
read.Reset();
|
|
|
|
|
write.Reset();
|
|
|
|
|
autoReceivedData.Reset();
|
2017-10-19 02:01:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t SPIData::Read(uint8_t* buffer, int32_t count) {
|
2018-09-03 16:08:07 -07:00
|
|
|
read(buffer, count);
|
2017-10-19 02:01:58 -04:00
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 00:00:45 -08:00
|
|
|
int32_t SPIData::Write(const uint8_t* dataToSend, int32_t sendSize) {
|
2018-09-03 16:08:07 -07:00
|
|
|
write(dataToSend, sendSize);
|
2017-10-19 02:01:58 -04:00
|
|
|
return sendSize;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 00:00:45 -08:00
|
|
|
int32_t SPIData::Transaction(const uint8_t* dataToSend, uint8_t* dataReceived,
|
2017-10-19 02:01:58 -04:00
|
|
|
int32_t size) {
|
2018-09-03 16:08:07 -07:00
|
|
|
write(dataToSend, size);
|
|
|
|
|
read(dataReceived, size);
|
2017-10-19 02:01:58 -04:00
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 22:29:20 -08:00
|
|
|
int32_t SPIData::ReadAutoReceivedData(uint32_t* buffer, int32_t numToRead,
|
2017-12-31 15:37:14 -05:00
|
|
|
double timeout, int32_t* status) {
|
|
|
|
|
int32_t outputCount = 0;
|
2018-09-03 16:08:07 -07:00
|
|
|
autoReceivedData(buffer, numToRead, &outputCount);
|
2017-12-31 15:37:14 -05:00
|
|
|
return outputCount;
|
2017-10-19 02:01:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
void HALSIM_ResetSPIData(int32_t index) { SimSPIData[index].ResetData(); }
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
|
|
|
|
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, SPI##CAPINAME, SimSPIData, \
|
|
|
|
|
LOWERNAME)
|
2017-10-19 02:01:58 -04:00
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
|
2017-10-19 02:01:58 -04:00
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
#undef DEFINE_CAPI
|
|
|
|
|
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
|
|
|
|
HAL_SIMCALLBACKREGISTRY_DEFINE_CAPI(TYPE, HALSIM, SPI##CAPINAME, SimSPIData, \
|
|
|
|
|
LOWERNAME)
|
2017-10-19 02:01:58 -04:00
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
DEFINE_CAPI(HAL_BufferCallback, Read, read)
|
|
|
|
|
DEFINE_CAPI(HAL_ConstBufferCallback, Write, write)
|
|
|
|
|
DEFINE_CAPI(HAL_SpiReadAutoReceiveBufferCallback, ReadAutoReceivedData,
|
|
|
|
|
autoReceivedData)
|
2017-10-19 02:01:58 -04:00
|
|
|
|
2017-10-26 19:28:59 -07:00
|
|
|
} // extern "C"
|