eive-obsw/linux/obc/PapbVcInterface.cpp

102 lines
3.1 KiB
C++
Raw Normal View History

2021-09-19 12:27:48 +02:00
#include <linux/obc/PapbVcInterface.h>
2022-01-24 16:33:22 +01:00
#include <fsfw_hal/linux/uio/UioMapper.h>
2021-09-19 12:27:48 +02:00
#include "fsfw/serviceinterface/ServiceInterface.h"
PapbVcInterface::PapbVcInterface(object_id_t objectId, LinuxLibgpioIF* gpioComIF,
2022-01-24 16:33:22 +01:00
gpioId_t papbBusyId, gpioId_t papbEmptyId, std::string uioFile, int mapNum) :
SystemObject(objectId), gpioComIF(gpioComIF), papbBusyId(papbBusyId), papbEmptyId(
papbEmptyId), uioFile(uioFile), mapNum(mapNum) {
}
2021-09-19 12:27:48 +02:00
2022-01-24 16:33:22 +01:00
PapbVcInterface::~PapbVcInterface() {
}
2021-09-19 12:27:48 +02:00
2022-01-24 16:33:22 +01:00
ReturnValue_t PapbVcInterface::initialize() {
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) {
if (pollPapbBusySignal() == RETURN_OK) {
2022-01-24 16:33:22 +01:00
startPacketTransfer();
2021-09-19 12:27:48 +02:00
}
2022-01-24 16:33:22 +01:00
for (size_t idx = 0; idx < size; idx++) {
if (pollPapbBusySignal() == RETURN_OK) {
*(vcBaseReg + DATA_REG_OFFSET) = static_cast<uint32_t>(*(data + idx));
} else {
sif::warning << "PapbVcInterface::write: Only written " << idx << " of " << size
<< " data" << std::endl;
return RETURN_FAILED;
}
}
if (pollPapbBusySignal() == RETURN_OK) {
endPacketTransfer();
}
return RETURN_OK;
2021-09-19 12:27:48 +02:00
}
2022-01-24 16:33:22 +01:00
void PapbVcInterface::startPacketTransfer() {
*vcBaseReg = CONFIG_START;
}
2021-09-19 12:27:48 +02:00
2022-01-24 16:33:22 +01:00
void PapbVcInterface::endPacketTransfer() {
*vcBaseReg = CONFIG_END;
}
2021-09-19 12:27:48 +02:00
ReturnValue_t PapbVcInterface::pollPapbBusySignal() {
2022-01-24 16:33:22 +01:00
int papbBusyState = 0;
ReturnValue_t result = RETURN_OK;
/** Check if PAPB interface is ready to receive data */
result = gpioComIF->readGpio(papbBusyId, &papbBusyState);
if (result != RETURN_OK) {
sif::warning << "PapbVcInterface::pollPapbBusySignal: Failed to read papb busy signal"
<< std::endl;
return RETURN_FAILED;
}
if (!papbBusyState) {
sif::warning << "PapbVcInterface::pollPapbBusySignal: PAPB busy" << std::endl;
return PAPB_BUSY;
}
return RETURN_OK;
2021-09-19 12:27:48 +02:00
}
void PapbVcInterface::isVcInterfaceBufferEmpty() {
2022-01-24 16:33:22 +01:00
ReturnValue_t result = RETURN_OK;
int papbEmptyState = 1;
result = gpioComIF->readGpio(papbEmptyId, &papbEmptyState);
2021-09-19 12:27:48 +02:00
2022-01-24 16:33:22 +01:00
if (result != RETURN_OK) {
sif::warning
<< "PapbVcInterface::isVcInterfaceBufferEmpty: Failed to read papb empty signal"
<< std::endl;
return;
}
2021-09-19 12:27:48 +02:00
2022-01-24 16:33:22 +01:00
if (papbEmptyState == 1) {
sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is empty" << std::endl;
} else {
sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is not empty" << std::endl;
}
2021-09-19 12:27:48 +02:00
return;
}
ReturnValue_t PapbVcInterface::sendTestFrame() {
2022-01-24 16:33:22 +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-24 16:33:22 +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-24 16:33:22 +01:00
ReturnValue_t result = write(testPacket, 1105);
if (result != RETURN_OK) {
return result;
}
2021-09-19 12:27:48 +02:00
2022-01-24 16:33:22 +01:00
return RETURN_OK;
2021-09-19 12:27:48 +02:00
}