2022-01-24 16:33:22 +01:00
|
|
|
#include <fsfw_hal/linux/uio/UioMapper.h>
|
2022-11-02 10:26:45 +01:00
|
|
|
#include <linux/ipcore/PapbVcInterface.h>
|
2022-01-26 17:59:31 +01:00
|
|
|
|
2021-09-19 12:27:48 +02:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
|
|
|
|
2022-01-25 14:33:06 +01:00
|
|
|
PapbVcInterface::PapbVcInterface(LinuxLibgpioIF* gpioComIF, gpioId_t papbBusyId,
|
|
|
|
gpioId_t papbEmptyId, std::string uioFile, int mapNum)
|
|
|
|
: gpioComIF(gpioComIF),
|
|
|
|
papbBusyId(papbBusyId),
|
|
|
|
papbEmptyId(papbEmptyId),
|
2022-10-27 14:02:34 +02:00
|
|
|
uioFile(std::move(uioFile)),
|
2022-01-25 14:33:06 +01:00
|
|
|
mapNum(mapNum) {}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-01-25 14:33:06 +01:00
|
|
|
PapbVcInterface::~PapbVcInterface() {}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-01-24 16:33:22 +01:00
|
|
|
ReturnValue_t PapbVcInterface::initialize() {
|
2022-01-25 14:33:06 +01:00
|
|
|
UioMapper uioMapper(uioFile, mapNum);
|
|
|
|
return uioMapper.getMappedAdress(&vcBaseReg, UioMapper::Permissions::WRITE_ONLY);
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
ReturnValue_t PapbVcInterface::write(const uint8_t* data, size_t size) {
|
2022-08-24 17:27:47 +02:00
|
|
|
if (pollPapbBusySignal() == returnvalue::OK) {
|
2022-01-25 14:33:06 +01:00
|
|
|
startPacketTransfer();
|
|
|
|
}
|
|
|
|
for (size_t idx = 0; idx < size; idx++) {
|
2022-08-24 17:27:47 +02:00
|
|
|
if (pollPapbBusySignal() == returnvalue::OK) {
|
2022-01-25 14:33:06 +01:00
|
|
|
*(vcBaseReg + DATA_REG_OFFSET) = static_cast<uint32_t>(*(data + idx));
|
|
|
|
} else {
|
|
|
|
sif::warning << "PapbVcInterface::write: Only written " << idx << " of " << size << " data"
|
|
|
|
<< std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-24 16:33:22 +01:00
|
|
|
}
|
2022-01-25 14:33:06 +01:00
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
if (pollPapbBusySignal() == returnvalue::OK) {
|
2022-01-25 14:33:06 +01:00
|
|
|
endPacketTransfer();
|
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 14:33:06 +01:00
|
|
|
void PapbVcInterface::startPacketTransfer() { *vcBaseReg = CONFIG_START; }
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-01-25 14:33:06 +01:00
|
|
|
void PapbVcInterface::endPacketTransfer() { *vcBaseReg = CONFIG_END; }
|
2021-09-19 12:27:48 +02:00
|
|
|
|
|
|
|
ReturnValue_t PapbVcInterface::pollPapbBusySignal() {
|
2022-05-04 14:08:27 +02:00
|
|
|
gpio::Levels papbBusyState = gpio::Levels::LOW;
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-01-25 14:33:06 +01:00
|
|
|
|
|
|
|
/** Check if PAPB interface is ready to receive data */
|
2022-05-04 14:08:27 +02:00
|
|
|
result = gpioComIF->readGpio(papbBusyId, papbBusyState);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-25 14:33:06 +01:00
|
|
|
sif::warning << "PapbVcInterface::pollPapbBusySignal: Failed to read papb busy signal"
|
|
|
|
<< std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-25 14:33:06 +01:00
|
|
|
}
|
2022-05-04 14:08:27 +02:00
|
|
|
if (papbBusyState == gpio::Levels::LOW) {
|
2022-01-25 14:33:06 +01:00
|
|
|
sif::warning << "PapbVcInterface::pollPapbBusySignal: PAPB busy" << std::endl;
|
|
|
|
return PAPB_BUSY;
|
|
|
|
}
|
|
|
|
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PapbVcInterface::isVcInterfaceBufferEmpty() {
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-05-04 14:08:27 +02:00
|
|
|
gpio::Levels papbEmptyState = gpio::Levels::HIGH;
|
2022-01-24 16:33:22 +01:00
|
|
|
|
2022-05-04 14:08:27 +02:00
|
|
|
result = gpioComIF->readGpio(papbEmptyId, papbEmptyState);
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-25 14:33:06 +01:00
|
|
|
sif::warning << "PapbVcInterface::isVcInterfaceBufferEmpty: Failed to read papb empty signal"
|
|
|
|
<< std::endl;
|
2021-09-19 12:27:48 +02:00
|
|
|
return;
|
2022-01-25 14:33:06 +01:00
|
|
|
}
|
|
|
|
|
2022-05-04 14:08:27 +02:00
|
|
|
if (papbEmptyState == gpio::Levels::HIGH) {
|
2022-01-25 14:33:06 +01:00
|
|
|
sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is empty" << std::endl;
|
|
|
|
} else {
|
|
|
|
sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is not empty" << std::endl;
|
|
|
|
}
|
|
|
|
return;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PapbVcInterface::sendTestFrame() {
|
2022-01-25 14:33:06 +01:00
|
|
|
/** Size of one complete transfer frame data field amounts to 1105 bytes */
|
|
|
|
uint8_t testPacket[1105];
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-01-25 14:33:06 +01:00
|
|
|
/** Fill one test packet */
|
|
|
|
for (int idx = 0; idx < 1105; idx++) {
|
|
|
|
testPacket[idx] = static_cast<uint8_t>(idx & 0xFF);
|
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-01-25 14:33:06 +01:00
|
|
|
ReturnValue_t result = write(testPacket, 1105);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-25 14:33:06 +01:00
|
|
|
return result;
|
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|