2017-10-19 02:01:58 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2017-2018 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <limits>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/mutex.h>
|
2017-11-13 09:51:48 -08:00
|
|
|
|
2017-10-19 02:01:58 -04:00
|
|
|
#include "MockData/NotifyListenerVector.h"
|
|
|
|
|
#include "MockData/SPIData.h"
|
|
|
|
|
|
|
|
|
|
namespace hal {
|
2017-12-31 15:37:14 -05:00
|
|
|
|
|
|
|
|
typedef HalCallbackListenerVectorImpl<HAL_SpiReadAutoReceiveBufferCallback>
|
|
|
|
|
SpiAutoReceiveDataListenerVector;
|
|
|
|
|
|
2017-10-19 02:01:58 -04:00
|
|
|
class SPIData {
|
|
|
|
|
public:
|
|
|
|
|
SPIData();
|
|
|
|
|
~SPIData();
|
|
|
|
|
|
|
|
|
|
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
|
|
|
|
|
HAL_Bool initialNotify);
|
|
|
|
|
void CancelInitializedCallback(int32_t uid);
|
|
|
|
|
void InvokeInitializedCallback(HAL_Value value);
|
|
|
|
|
HAL_Bool GetInitialized();
|
|
|
|
|
void SetInitialized(HAL_Bool initialized);
|
|
|
|
|
|
|
|
|
|
int32_t RegisterReadCallback(HAL_BufferCallback callback, void* param);
|
|
|
|
|
void CancelReadCallback(int32_t uid);
|
|
|
|
|
|
2017-11-17 10:01:49 -08:00
|
|
|
int32_t RegisterWriteCallback(HAL_ConstBufferCallback callback, void* param);
|
2017-10-19 02:01:58 -04:00
|
|
|
void CancelWriteCallback(int32_t uid);
|
|
|
|
|
|
2017-12-31 15:37:14 -05:00
|
|
|
int32_t RegisterReadAutoReceivedDataCallback(
|
|
|
|
|
HAL_SpiReadAutoReceiveBufferCallback callback, void* param);
|
|
|
|
|
void CancelReadAutoReceivedDataCallback(int32_t uid);
|
2017-10-19 02:01:58 -04:00
|
|
|
|
|
|
|
|
int32_t Read(uint8_t* buffer, int32_t count);
|
2017-11-14 00:00:45 -08:00
|
|
|
int32_t Write(const uint8_t* dataToSend, int32_t sendSize);
|
|
|
|
|
int32_t Transaction(const uint8_t* dataToSend, uint8_t* dataReceived,
|
|
|
|
|
int32_t size);
|
2017-12-31 15:37:14 -05:00
|
|
|
|
|
|
|
|
int32_t ReadAutoReceivedData(uint8_t* buffer, int32_t numToRead,
|
|
|
|
|
double timeout, int32_t* status);
|
2017-10-19 02:01:58 -04:00
|
|
|
|
|
|
|
|
void ResetData();
|
|
|
|
|
|
|
|
|
|
private:
|
2017-11-13 09:51:48 -08:00
|
|
|
wpi::mutex m_registerMutex;
|
|
|
|
|
wpi::mutex m_dataMutex;
|
2017-10-19 02:01:58 -04:00
|
|
|
std::atomic<HAL_Bool> m_initialized{false};
|
|
|
|
|
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
|
|
|
|
std::shared_ptr<BufferListenerVector> m_readCallbacks = nullptr;
|
2017-11-17 10:01:49 -08:00
|
|
|
std::shared_ptr<ConstBufferListenerVector> m_writeCallbacks = nullptr;
|
2017-12-31 15:37:14 -05:00
|
|
|
std::shared_ptr<SpiAutoReceiveDataListenerVector> m_autoReceiveDataCallbacks =
|
|
|
|
|
nullptr;
|
2017-10-19 02:01:58 -04:00
|
|
|
};
|
2017-12-10 19:38:53 -08:00
|
|
|
extern SPIData* SimSPIData;
|
2017-10-19 02:01:58 -04:00
|
|
|
} // namespace hal
|