eive-obsw/linux/obc/PapbVcInterface.cpp

105 lines
3.0 KiB
C++
Raw Normal View History

2021-09-19 12:27:48 +02:00
#include <linux/obc/PapbVcInterface.h>
#include "fsfw/serviceinterface/ServiceInterface.h"
PapbVcInterface::PapbVcInterface(object_id_t objectId, LinuxLibgpioIF* gpioComIF,
gpioId_t papbBusyId, gpioId_t papbEmptyId, uint32_t vcOffset) :
2021-09-26 08:29:30 +02:00
SystemObject(objectId), gpioComIF(gpioComIF), papbBusyId(
2021-09-19 12:27:48 +02:00
papbBusyId), papbEmptyId(papbEmptyId), vcOffset(vcOffset) {
}
PapbVcInterface::~PapbVcInterface() {
}
void PapbVcInterface::setRegisterAddress(uint32_t* ptmeBaseAddress) {
vcBaseReg = ptmeBaseAddress + vcOffset;
}
2021-09-26 08:29:30 +02:00
ReturnValue_t PapbVcInterface::write(const uint8_t * data, size_t size) {
2021-09-19 12:27:48 +02:00
if(pollPapbBusySignal() == RETURN_OK) {
startPacketTransfer();
}
2021-09-26 08:29:30 +02:00
for(size_t idx = 0; idx < size; idx++) {
2021-09-19 12:27:48 +02:00
if(pollPapbBusySignal() == RETURN_OK) {
*(vcBaseReg + DATA_REG_OFFSET) = static_cast<uint32_t>(*(data + idx));
}
else {
2021-09-29 14:47:20 +02:00
sif::warning << "PapbVcInterface::write: Only written " << idx << " of "
2021-09-26 08:29:30 +02:00
<< size << " data" << std::endl;
2021-09-19 12:27:48 +02:00
return RETURN_FAILED;
}
}
if(pollPapbBusySignal() == RETURN_OK) {
endPacketTransfer();
}
return RETURN_OK;
}
void PapbVcInterface::startPacketTransfer() {
*vcBaseReg = CONFIG_START;
}
void PapbVcInterface::endPacketTransfer() {
*vcBaseReg = CONFIG_END;
}
ReturnValue_t PapbVcInterface::pollPapbBusySignal() {
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) {
2021-09-22 16:54:55 +02:00
sif::warning << "PapbVcInterface::pollPapbBusySignal: Failed to read papb busy signal"
2021-09-19 12:27:48 +02:00
<< std::endl;
return RETURN_FAILED;
}
if (!papbBusyState) {
2021-09-22 16:54:55 +02:00
sif::warning << "PapbVcInterface::pollPapbBusySignal: PAPB busy" << std::endl;
2021-09-19 12:27:48 +02:00
return PAPB_BUSY;
}
return RETURN_OK;
}
void PapbVcInterface::isVcInterfaceBufferEmpty() {
ReturnValue_t result = RETURN_OK;
int papbEmptyState = 1;
result = gpioComIF->readGpio(papbEmptyId, &papbEmptyState);
if (result != RETURN_OK) {
2021-09-22 16:54:55 +02:00
sif::warning << "PapbVcInterface::isVcInterfaceBufferEmpty: Failed to read papb empty signal"
2021-09-19 12:27:48 +02:00
<< std::endl;
return;
}
if (papbEmptyState == 1) {
sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is empty" << std::endl;
}
else {
sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is not empty" << std::endl;
}
return;
}
ReturnValue_t PapbVcInterface::sendTestFrame() {
/** Size of one complete transfer frame data field amounts to 1105 bytes */
uint8_t testPacket[1105];
/** Fill one test packet */
for(int idx = 0; idx < 1105; idx++) {
testPacket[idx] = static_cast<uint8_t>(idx & 0xFF);
}
2021-09-26 08:29:30 +02:00
ReturnValue_t result = write(testPacket, 1105);
2021-09-19 12:27:48 +02:00
if(result != RETURN_OK) {
return result;
}
return RETURN_OK;
}