Spi COM IF update #7

Merged
meierj merged 15 commits from mueller/master into master 2021-05-27 13:47:27 +02:00
5 changed files with 95 additions and 85 deletions
Showing only changes of commit 2fe1a66836 - Show all commits

View File

@ -138,7 +138,6 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
int retval = 0;
if(spiCookie == nullptr) {
return NULLPOINTER;
@ -159,11 +158,26 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
}
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 */
int fileDescriptor = 0;
std::string device = spiCookie->getSpiDevice();
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR,
"SpiComIF::sendMessage: ");
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage: ");
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
return OPENING_FILE_FAILED;
}
@ -238,16 +252,6 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
return result;
}
}
}
else if(spiCookie->getComIfMode() == spi::SpiComIfModes::CALLBACK) {
spi::send_callback_function_t sendFunc = nullptr;
void* funcArgs = nullptr;
spiCookie->getCallback(&sendFunc, &funcArgs);
if(sendFunc != nullptr) {
// sendFunc()
}
}
return result;
}

View File

@ -64,6 +64,7 @@ private:
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);

View File

@ -12,9 +12,9 @@ SpiCookie::SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxS
SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {
}
SpiCookie::SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxSize,
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, gpio::NO_GPIO, spiDev, maxSize,
SpiCookie(spi::SpiComIfModes::CALLBACK, spiAddress, chipSelect, spiDev, maxSize,
spi::SpiModes::MODE_0, 0, callback, args) {
}

View File

@ -31,7 +31,7 @@ public:
* 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, std::string spiDev, const size_t maxSize,
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);

View File

@ -1,10 +1,15 @@
#ifndef 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>
class SpiCookie;
namespace spi {
enum SpiModes: uint8_t {
@ -20,7 +25,7 @@ enum SpiComIfModes {
};
using send_callback_function_t = ReturnValue_t (*) (uint8_t** replyData, void* args);
using send_callback_function_t = ReturnValue_t (*) (SpiCookie *cookie, const uint8_t *sendData, size_t sendLen, void* args);
}