Compare commits
11 Commits
1.0.0
...
2fe1a66836
Author | SHA1 | Date | |
---|---|---|---|
2fe1a66836 | |||
9203a30bcf | |||
a0f698fffa | |||
6341da2212 | |||
e5da8b194d | |||
c601e1dff7 | |||
d929352417 | |||
49da48dc0d | |||
99ba9d9346 | |||
425cfd2aba | |||
8a38c7958b |
@@ -82,7 +82,7 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular
|
|||||||
chipname = regularGpio->chipname;
|
chipname = regularGpio->chipname;
|
||||||
chip = gpiod_chip_open_by_name(chipname.c_str());
|
chip = gpiod_chip_open_by_name(chipname.c_str());
|
||||||
if (!chip) {
|
if (!chip) {
|
||||||
sif::warning << "LinuxLibgpioIF::configureGpios: Failed to open chip "
|
sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open chip "
|
||||||
<< chipname << ". Gpio ID: " << gpioId << std::endl;
|
<< chipname << ". Gpio ID: " << gpioId << std::endl;
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@@ -90,9 +90,10 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular
|
|||||||
lineNum = regularGpio->lineNum;
|
lineNum = regularGpio->lineNum;
|
||||||
lineHandle = gpiod_chip_get_line(chip, lineNum);
|
lineHandle = gpiod_chip_get_line(chip, lineNum);
|
||||||
if (!lineHandle) {
|
if (!lineHandle) {
|
||||||
sif::warning << "LinuxLibgpioIF::configureGpios: Failed to open line for GPIO" << std::endl;
|
sif::debug << "LinuxLibgpioIF::configureRegularGpio: Failed to open line " << std::endl;
|
||||||
sif::warning << "GPIO ID " << gpioId << "with line number " << lineNum <<
|
sif::debug << "GPIO ID: " << gpioId << ", line number: " << lineNum <<
|
||||||
" and chipname " << chipname << std::endl;
|
", chipname: " << chipname << std::endl;
|
||||||
|
sif::debug << "Check if linux GPIO configuration has changed. " << std::endl;
|
||||||
gpiod_chip_close(chip);
|
gpiod_chip_close(chip);
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@@ -105,7 +106,7 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular
|
|||||||
result = gpiod_line_request_output(lineHandle, consumer.c_str(),
|
result = gpiod_line_request_output(lineHandle, consumer.c_str(),
|
||||||
regularGpio->initValue);
|
regularGpio->initValue);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line " << lineNum <<
|
sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " << lineNum <<
|
||||||
" from GPIO instance with ID: " << gpioId << std::endl;
|
" from GPIO instance with ID: " << gpioId << std::endl;
|
||||||
gpiod_line_release(lineHandle);
|
gpiod_line_release(lineHandle);
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
|
@@ -5,7 +5,6 @@
|
|||||||
#include <FSFWConfig.h>
|
#include <FSFWConfig.h>
|
||||||
|
|
||||||
#include <fsfw/ipc/MutexFactory.h>
|
#include <fsfw/ipc/MutexFactory.h>
|
||||||
#include <fsfw/ipc/MutexGuard.h>
|
|
||||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||||
|
|
||||||
#include <linux/spi/spidev.h>
|
#include <linux/spi/spidev.h>
|
||||||
@@ -22,7 +21,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF): SystemObject(objectId),
|
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF): SystemObject(objectId),
|
||||||
gpioComIF(gpioComIF) {
|
gpioComIF(gpioComIF) {
|
||||||
if(gpioComIF == nullptr) {
|
if(gpioComIF == nullptr) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
@@ -139,7 +138,6 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) {
|
ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) {
|
||||||
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
int retval = 0;
|
|
||||||
|
|
||||||
if(spiCookie == nullptr) {
|
if(spiCookie == nullptr) {
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
@@ -159,12 +157,27 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
return DeviceCommunicationIF::TOO_MUCH_DATA;
|
return DeviceCommunicationIF::TOO_MUCH_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(spiCookie->getComIfMode() == spi::SpiComIfModes::REGULAR) {
|
||||||
|
result = performRegularSendOperation(spiCookie, sendData, sendLen);
|
||||||
|
}
|
||||||
|
else if(spiCookie->getComIfMode() == spi::SpiComIfModes::CALLBACK) {
|
||||||
|
spi::send_callback_function_t sendFunc = nullptr;
|
||||||
|
void* funcArgs = nullptr;
|
||||||
|
spiCookie->getCallback(&sendFunc, &funcArgs);
|
||||||
|
if(sendFunc != nullptr) {
|
||||||
|
result = sendFunc(spiCookie, sendData, sendLen, funcArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const uint8_t *sendData, size_t sendLen) {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
int retval = 0;
|
||||||
/* Prepare transfer */
|
/* Prepare transfer */
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
std::string device = spiCookie->getSpiDevice();
|
std::string device = spiCookie->getSpiDevice();
|
||||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR,
|
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage: ");
|
||||||
"SpiComIF::sendMessage: ");
|
|
||||||
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return OPENING_FILE_FAILED;
|
return OPENING_FILE_FAILED;
|
||||||
}
|
}
|
||||||
@@ -178,11 +191,15 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
bool fullDuplex = spiCookie->isFullDuplex();
|
bool fullDuplex = spiCookie->isFullDuplex();
|
||||||
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
||||||
|
|
||||||
/* GPIO access is mutex protected */
|
|
||||||
MutexGuard(spiMutex, timeoutType, timeoutMs);
|
|
||||||
|
|
||||||
/* Pull SPI CS low. For now, no support for active high given */
|
/* Pull SPI CS low. For now, no support for active high given */
|
||||||
if(gpioId != gpio::NO_GPIO) {
|
if(gpioId != gpio::NO_GPIO) {
|
||||||
|
result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl;
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
gpioComIF->pullLow(gpioId);
|
gpioComIF->pullLow(gpioId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +244,13 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
|
|
||||||
if(gpioId != gpio::NO_GPIO) {
|
if(gpioId != gpio::NO_GPIO) {
|
||||||
gpioComIF->pullHigh(gpioId);
|
gpioComIF->pullHigh(gpioId);
|
||||||
|
result = spiMutex->unlockMutex();
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "SpiComIF::sendMessage: Failed to unlock mutex" << std::endl;
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -236,7 +260,6 @@ ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
|
||||||
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
||||||
if(spiCookie == nullptr) {
|
if(spiCookie == nullptr) {
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
@@ -247,6 +270,12 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLe
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return performHalfDuplexReception(spiCookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
std::string device = spiCookie->getSpiDevice();
|
std::string device = spiCookie->getSpiDevice();
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR,
|
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR,
|
||||||
@@ -263,8 +292,14 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLe
|
|||||||
}
|
}
|
||||||
|
|
||||||
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
||||||
MutexGuard(spiMutex, timeoutType, timeoutMs);
|
|
||||||
if(gpioId != gpio::NO_GPIO) {
|
if(gpioId != gpio::NO_GPIO) {
|
||||||
|
result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "SpiComIF::getSendSuccess: Failed to lock mutex" << std::endl;
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
gpioComIF->pullLow(gpioId);
|
gpioComIF->pullLow(gpioId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,9 +316,16 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLe
|
|||||||
|
|
||||||
if(gpioId != gpio::NO_GPIO) {
|
if(gpioId != gpio::NO_GPIO) {
|
||||||
gpioComIF->pullHigh(gpioId);
|
gpioComIF->pullHigh(gpioId);
|
||||||
|
result = spiMutex->unlockMutex();
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "SpiComIF::getSendSuccess: Failed to unlock mutex" << std::endl;
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) {
|
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) {
|
||||||
@@ -302,6 +344,10 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MutexIF* SpiComIF::getMutex() {
|
||||||
|
return spiMutex;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) {
|
ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) {
|
||||||
if(buffer == nullptr) {
|
if(buffer == nullptr) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
class SpiCookie;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Encapsulates access to linux SPI driver for FSFW objects
|
* @brief Encapsulates access to linux SPI driver for FSFW objects
|
||||||
* @details
|
* @details
|
||||||
@@ -39,6 +41,12 @@ public:
|
|||||||
size_t requestLen) override;
|
size_t requestLen) override;
|
||||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||||
size_t *size) override;
|
size_t *size) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the mutex which can be used to protect the spi bus when
|
||||||
|
* the chip select must be driven from outside of the com if.
|
||||||
|
*/
|
||||||
|
MutexIF* getMutex();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct SpiInstance {
|
struct SpiInstance {
|
||||||
@@ -56,6 +64,8 @@ private:
|
|||||||
|
|
||||||
SpiDeviceMap spiDeviceMap;
|
SpiDeviceMap spiDeviceMap;
|
||||||
|
|
||||||
|
ReturnValue_t performRegularSendOperation(SpiCookie* spiCookie, const uint8_t *sendData, size_t sendLen);
|
||||||
|
ReturnValue_t performHalfDuplexReception(SpiCookie* spiCookie);
|
||||||
|
|
||||||
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
|
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
|
||||||
void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed);
|
void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed);
|
||||||
|
@@ -1,14 +1,33 @@
|
|||||||
#include "SpiCookie.h"
|
#include "SpiCookie.h"
|
||||||
|
|
||||||
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
||||||
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed): spiAddress(spiAddress),
|
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed):
|
||||||
chipSelectPin(chipSelect), spiDevice(spiDev), maxSize(maxSize), spiMode(spiMode),
|
SpiCookie(spi::SpiComIfModes::REGULAR, spiAddress, chipSelect, spiDev, maxSize, spiMode,
|
||||||
spiSpeed(spiSpeed) {
|
spiSpeed, nullptr, nullptr) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpiCookie::SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxSize,
|
SpiCookie::SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxSize,
|
||||||
spi::SpiModes spiMode, uint32_t spiSpeed):
|
spi::SpiModes spiMode, uint32_t spiSpeed):
|
||||||
SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {
|
SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
|
||||||
|
spi::send_callback_function_t callback, void *args):
|
||||||
|
SpiCookie(spi::SpiComIfModes::CALLBACK, spiAddress, chipSelect, spiDev, maxSize,
|
||||||
|
spi::SpiModes::MODE_0, 0, callback, args) {
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiCookie::SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect,
|
||||||
|
std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
|
||||||
|
spi::send_callback_function_t callback, void* args): spiAddress(spiAddress),
|
||||||
|
chipSelectPin(chipSelect), spiDevice(spiDev), comIfMode(comIfMode),
|
||||||
|
maxSize(maxSize), spiMode(spiMode), spiSpeed(spiSpeed), sendCallback(callback),
|
||||||
|
callbackArgs(args) {
|
||||||
|
}
|
||||||
|
|
||||||
|
spi::SpiComIfModes SpiCookie::getComIfMode() const {
|
||||||
|
return this->comIfMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed,
|
void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed,
|
||||||
@@ -78,6 +97,13 @@ void SpiCookie::assignWriteBuffer(const uint8_t* tx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpiCookie::setCallbackMode(spi::send_callback_function_t callback,
|
||||||
|
void *args) {
|
||||||
|
this->comIfMode = spi::SpiComIfModes::CALLBACK;
|
||||||
|
this->sendCallback = callback;
|
||||||
|
this->callbackArgs = args;
|
||||||
|
}
|
||||||
|
|
||||||
spi_ioc_transfer* SpiCookie::getTransferStructHandle() {
|
spi_ioc_transfer* SpiCookie::getTransferStructHandle() {
|
||||||
return &spiTransferStruct;
|
return &spiTransferStruct;
|
||||||
}
|
}
|
||||||
@@ -105,3 +131,9 @@ void SpiCookie::setSpiSpeed(uint32_t newSpeed) {
|
|||||||
void SpiCookie::setSpiMode(spi::SpiModes newMode) {
|
void SpiCookie::setSpiMode(spi::SpiModes newMode) {
|
||||||
this->spiMode = newMode;
|
this->spiMode = newMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpiCookie::getCallback(spi::send_callback_function_t *callback,
|
||||||
|
void **args) {
|
||||||
|
*callback = this->sendCallback;
|
||||||
|
*args = this->callbackArgs;
|
||||||
|
}
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
class SpiCookie: public CookieIF {
|
class SpiCookie: public CookieIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Each SPI device will have a corresponding cookie. The cookie is used by the communication
|
* Each SPI device will have a corresponding cookie. The cookie is used by the communication
|
||||||
* interface and contains device specific information like the largest expected size to be
|
* interface and contains device specific information like the largest expected size to be
|
||||||
@@ -19,7 +18,7 @@ public:
|
|||||||
* @param maxSize
|
* @param maxSize
|
||||||
*/
|
*/
|
||||||
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
||||||
const size_t maxReplySize, spi::SpiModes spiMode, uint32_t spiSpeed);
|
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like constructor above, but without a dedicated GPIO CS. Can be used for hardware
|
* Like constructor above, but without a dedicated GPIO CS. Can be used for hardware
|
||||||
@@ -28,16 +27,29 @@ public:
|
|||||||
SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxReplySize,
|
SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxReplySize,
|
||||||
spi::SpiModes spiMode, uint32_t spiSpeed);
|
spi::SpiModes spiMode, uint32_t spiSpeed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the callback mode of the SPI communication interface. The user can pass the callback
|
||||||
|
* function here or by using the setter function #setCallbackMode
|
||||||
|
*/
|
||||||
|
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
|
||||||
|
spi::send_callback_function_t callback, void *args);
|
||||||
|
|
||||||
|
void getCallback(spi::send_callback_function_t* callback, void** args);
|
||||||
|
|
||||||
address_t getSpiAddress() const;
|
address_t getSpiAddress() const;
|
||||||
std::string getSpiDevice() const;
|
std::string getSpiDevice() const;
|
||||||
gpioId_t getChipSelectPin() const;
|
gpioId_t getChipSelectPin() const;
|
||||||
size_t getMaxBufferSize() const;
|
size_t getMaxBufferSize() const;
|
||||||
|
|
||||||
|
spi::SpiComIfModes getComIfMode() const;
|
||||||
|
|
||||||
/** Enables changing SPI speed at run-time */
|
/** Enables changing SPI speed at run-time */
|
||||||
void setSpiSpeed(uint32_t newSpeed);
|
void setSpiSpeed(uint32_t newSpeed);
|
||||||
/** Enables changing the SPI mode at run-time */
|
/** Enables changing the SPI mode at run-time */
|
||||||
void setSpiMode(spi::SpiModes newMode);
|
void setSpiMode(spi::SpiModes newMode);
|
||||||
|
|
||||||
|
void setCallbackMode(spi::send_callback_function_t callback, void* args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if SPI transfers should be performed in full duplex mode
|
* True if SPI transfers should be performed in full duplex mode
|
||||||
* @return
|
* @return
|
||||||
@@ -99,17 +111,40 @@ public:
|
|||||||
|
|
||||||
spi_ioc_transfer* getTransferStructHandle();
|
spi_ioc_transfer* getTransferStructHandle();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal constructor which initializes every field
|
||||||
|
* @param spiAddress
|
||||||
|
* @param chipSelect
|
||||||
|
* @param spiDev
|
||||||
|
* @param maxSize
|
||||||
|
* @param spiMode
|
||||||
|
* @param spiSpeed
|
||||||
|
* @param callback
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect,
|
||||||
|
std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
|
||||||
|
spi::send_callback_function_t callback, void* args);
|
||||||
|
|
||||||
size_t currentTransferSize = 0;
|
size_t currentTransferSize = 0;
|
||||||
|
|
||||||
address_t spiAddress;
|
address_t spiAddress;
|
||||||
gpioId_t chipSelectPin;
|
gpioId_t chipSelectPin;
|
||||||
std::string spiDevice;
|
std::string spiDevice;
|
||||||
|
|
||||||
|
spi::SpiComIfModes comIfMode;
|
||||||
|
|
||||||
|
// Required for regular mode
|
||||||
const size_t maxSize;
|
const size_t maxSize;
|
||||||
spi::SpiModes spiMode;
|
spi::SpiModes spiMode;
|
||||||
uint32_t spiSpeed;
|
uint32_t spiSpeed;
|
||||||
bool halfDuplex = false;
|
bool halfDuplex = false;
|
||||||
|
|
||||||
|
// Required for callback mode
|
||||||
|
spi::send_callback_function_t sendCallback = nullptr;
|
||||||
|
void* callbackArgs = nullptr;
|
||||||
|
|
||||||
struct spi_ioc_transfer spiTransferStruct = {};
|
struct spi_ioc_transfer spiTransferStruct = {};
|
||||||
UncommonParameters uncommonParameters;
|
UncommonParameters uncommonParameters;
|
||||||
};
|
};
|
||||||
|
@@ -1,8 +1,15 @@
|
|||||||
#ifndef LINUX_SPI_SPIDEFINITONS_H_
|
#ifndef LINUX_SPI_SPIDEFINITONS_H_
|
||||||
#define LINUX_SPI_SPIDEFINITONS_H_
|
#define LINUX_SPI_SPIDEFINITONS_H_
|
||||||
|
|
||||||
|
#include "../../common/gpio/gpioDefinitions.h"
|
||||||
|
|
||||||
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include <linux/spi/spidev.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
class SpiCookie;
|
||||||
|
|
||||||
namespace spi {
|
namespace spi {
|
||||||
|
|
||||||
enum SpiModes: uint8_t {
|
enum SpiModes: uint8_t {
|
||||||
@@ -12,6 +19,14 @@ enum SpiModes: uint8_t {
|
|||||||
MODE_3
|
MODE_3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum SpiComIfModes {
|
||||||
|
REGULAR,
|
||||||
|
CALLBACK
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
using send_callback_function_t = ReturnValue_t (*) (SpiCookie *cookie, const uint8_t *sendData, size_t sendLen, void* args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* LINUX_SPI_SPIDEFINITONS_H_ */
|
#endif /* LINUX_SPI_SPIDEFINITONS_H_ */
|
||||||
|
Reference in New Issue
Block a user