2021-05-16 19:22:04 +02:00
|
|
|
#include <fcntl.h>
|
2021-09-19 12:27:48 +02:00
|
|
|
#include <linux/obc/Ptme.h>
|
2022-01-17 13:48:55 +01:00
|
|
|
#include <sys/mman.h>
|
2021-05-16 19:22:04 +02:00
|
|
|
|
|
|
|
CCSDSIPCoreBridge::CCSDSIPCoreBridge(object_id_t objectId, object_id_t tcDestination,
|
2022-01-17 13:48:55 +01:00
|
|
|
object_id_t tmStoreId, object_id_t tcStoreId,
|
|
|
|
LinuxLibgpioIF* gpioComIF, std::string uioPtme,
|
|
|
|
gpioId_t papbBusyId, gpioId_t papbEmptyId)
|
|
|
|
: TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId),
|
|
|
|
gpioComIF(gpioComIF),
|
|
|
|
uioPtme(uioPtme),
|
|
|
|
papbBusyId(papbBusyId),
|
|
|
|
papbEmptyId(papbEmptyId) {}
|
2021-05-16 19:22:04 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
CCSDSIPCoreBridge::~CCSDSIPCoreBridge() {}
|
2021-05-16 19:22:04 +02:00
|
|
|
|
|
|
|
ReturnValue_t CCSDSIPCoreBridge::initialize() {
|
2022-01-17 13:48:55 +01:00
|
|
|
ReturnValue_t result = TmTcBridge::initialize();
|
|
|
|
|
|
|
|
fd = open("/dev/uio0", O_RDWR);
|
|
|
|
if (fd < 1) {
|
|
|
|
sif::debug << "CCSDSIPCoreBridge::initialize: Invalid UIO device file" << std::endl;
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map uio device in virtual address space
|
|
|
|
* PROT_WRITE: Map uio device in writable only mode
|
|
|
|
*/
|
|
|
|
ptmeBaseAddress =
|
|
|
|
static_cast<uint32_t*>(mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
|
|
|
|
|
|
|
|
if (ptmeBaseAddress == MAP_FAILED) {
|
|
|
|
sif::error << "CCSDSIPCoreBridge::initialize: Failed to map uio address" << std::endl;
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2021-05-16 19:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t CCSDSIPCoreBridge::handleTm() {
|
2021-08-17 17:48:51 +02:00
|
|
|
#if OBSW_TEST_CCSDS_PTME == 1
|
2022-01-17 13:48:55 +01:00
|
|
|
return sendTestFrame();
|
2021-05-27 13:07:57 +02:00
|
|
|
#else
|
2022-01-17 13:48:55 +01:00
|
|
|
return TmTcBridge::handleTm();
|
2021-05-27 13:07:57 +02:00
|
|
|
#endif
|
2021-05-16 19:22:04 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
ReturnValue_t CCSDSIPCoreBridge::sendTm(const uint8_t* data, size_t dataLen) {
|
|
|
|
if (pollPapbBusySignal() == RETURN_OK) {
|
|
|
|
startPacketTransfer();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t idx = 0; idx < dataLen; idx++) {
|
|
|
|
if (pollPapbBusySignal() == RETURN_OK) {
|
|
|
|
*(ptmeBaseAddress + PTME_DATA_REG_OFFSET) = static_cast<uint32_t>(*(data + idx));
|
|
|
|
} else {
|
|
|
|
sif::debug << "CCSDSIPCoreBridge::sendTm: Only written " << idx - 1 << " of " << dataLen
|
|
|
|
<< " data" << std::endl;
|
|
|
|
return RETURN_FAILED;
|
2021-05-16 19:22:04 +02:00
|
|
|
}
|
2022-01-17 13:48:55 +01:00
|
|
|
}
|
2021-05-16 19:22:04 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
if (pollPapbBusySignal() == RETURN_OK) {
|
|
|
|
endPacketTransfer();
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
2021-05-16 19:22:04 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
void CCSDSIPCoreBridge::startPacketTransfer() { *ptmeBaseAddress = PTME_CONFIG_START; }
|
2021-05-16 19:22:04 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
void CCSDSIPCoreBridge::endPacketTransfer() { *ptmeBaseAddress = PTME_CONFIG_END; }
|
2021-05-16 19:22:04 +02:00
|
|
|
|
2021-05-27 13:07:57 +02:00
|
|
|
ReturnValue_t CCSDSIPCoreBridge::pollPapbBusySignal() {
|
2022-01-17 13:48:55 +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::debug << "CCSDSIPCoreBridge::pollPapbBusySignal: Failed to read papb busy signal"
|
|
|
|
<< std::endl;
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
if (!papbBusyState) {
|
|
|
|
sif::debug << "CCSDSIPCoreBridge::pollPapbBusySignal: PAPB busy" << std::endl;
|
|
|
|
return PAPB_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RETURN_OK;
|
2021-05-16 19:22:04 +02:00
|
|
|
}
|
2021-05-17 13:47:10 +02:00
|
|
|
|
2021-05-27 13:07:57 +02:00
|
|
|
void CCSDSIPCoreBridge::isPtmeBufferEmpty() {
|
2022-01-17 13:48:55 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
int papbEmptyState = 1;
|
2021-05-17 13:47:10 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
result = gpioComIF->readGpio(papbEmptyId, &papbEmptyState);
|
2021-05-17 13:47:10 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "CCSDSIPCoreBridge::isPtmeBufferEmpty: Failed to read papb empty signal"
|
|
|
|
<< std::endl;
|
2021-05-17 13:47:10 +02:00
|
|
|
return;
|
2022-01-17 13:48:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (papbEmptyState == 1) {
|
|
|
|
sif::debug << "CCSDSIPCoreBridge::isPtmeBufferEmpty: Buffer is empty" << std::endl;
|
|
|
|
} else {
|
|
|
|
sif::debug << "CCSDSIPCoreBridge::isPtmeBufferEmpty: Buffer is not empty" << std::endl;
|
|
|
|
}
|
|
|
|
return;
|
2021-05-17 13:47:10 +02:00
|
|
|
}
|
2021-05-27 13:07:57 +02:00
|
|
|
|
|
|
|
ReturnValue_t CCSDSIPCoreBridge::sendTestFrame() {
|
2022-01-17 13:48:55 +01:00
|
|
|
/** Size of one complete transfer frame data field amounts to 1105 bytes */
|
|
|
|
uint8_t testPacket[1105];
|
2021-05-27 13:07:57 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
/** Fill one test packet */
|
|
|
|
for (int idx = 0; idx < 1105; idx++) {
|
|
|
|
testPacket[idx] = static_cast<uint8_t>(idx & 0xFF);
|
|
|
|
}
|
2021-05-27 13:07:57 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
ReturnValue_t result = sendTm(testPacket, 1105);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2021-05-27 13:07:57 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
return RETURN_OK;
|
2021-05-27 13:07:57 +02:00
|
|
|
}
|