Spi COM IF update #7
@ -138,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,11 +158,26 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(spiCookie->getComIfMode() == spi::SpiComIfModes::REGULAR) {
|
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;
|
||||||
}
|
}
|
||||||
@ -238,16 +252,6 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
return result;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ private:
|
|||||||
|
|
||||||
SpiDeviceMap spiDeviceMap;
|
SpiDeviceMap spiDeviceMap;
|
||||||
|
|
||||||
|
ReturnValue_t performRegularSendOperation(SpiCookie* spiCookie, const uint8_t *sendData, size_t sendLen);
|
||||||
ReturnValue_t performHalfDuplexReception(SpiCookie* spiCookie);
|
ReturnValue_t performHalfDuplexReception(SpiCookie* spiCookie);
|
||||||
|
|
||||||
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
|
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
|
||||||
|
@ -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(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):
|
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) {
|
spi::SpiModes::MODE_0, 0, callback, args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
* Use the callback mode of the SPI communication interface. The user can pass the callback
|
* Use the callback mode of the SPI communication interface. The user can pass the callback
|
||||||
* function here or by using the setter function #setCallbackMode
|
* 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);
|
spi::send_callback_function_t callback, void *args);
|
||||||
|
|
||||||
void getCallback(spi::send_callback_function_t* callback, void** args);
|
void getCallback(spi::send_callback_function_t* callback, void** args);
|
||||||
|
@ -1,10 +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 "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 {
|
||||||
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user