2021-05-16 19:22:04 +02:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2021-06-21 17:25:13 +02:00
|
|
|
#include <linux/obc/CCSDSIPCoreBridge.h>
|
2021-05-16 19:22:04 +02:00
|
|
|
|
|
|
|
CCSDSIPCoreBridge::CCSDSIPCoreBridge(object_id_t objectId, object_id_t tcDestination,
|
|
|
|
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) {
|
|
|
|
}
|
|
|
|
|
|
|
|
CCSDSIPCoreBridge::~CCSDSIPCoreBridge() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t CCSDSIPCoreBridge::initialize() {
|
|
|
|
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
|
|
|
|
*/
|
2021-05-27 13:07:57 +02:00
|
|
|
ptmeBaseAddress = static_cast<uint32_t*>(mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE,
|
|
|
|
MAP_SHARED, fd, 0));
|
2021-05-16 19:22:04 +02:00
|
|
|
|
|
|
|
if (ptmeBaseAddress == MAP_FAILED) {
|
|
|
|
sif::error << "CCSDSIPCoreBridge::initialize: Failed to map uio address" << std::endl;
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t CCSDSIPCoreBridge::handleTm() {
|
|
|
|
|
2021-05-27 13:07:57 +02:00
|
|
|
#if PERFORM_PTME_TEST == 1
|
|
|
|
return sendTestFrame();
|
|
|
|
#else
|
|
|
|
return TmTcBridge::handleTm();
|
|
|
|
#endif
|
2021-05-16 19:22:04 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t CCSDSIPCoreBridge::sendTm(const uint8_t * data, size_t dataLen) {
|
|
|
|
|
2021-05-27 13:07:57 +02:00
|
|
|
if(pollPapbBusySignal() == RETURN_OK) {
|
2021-05-16 19:22:04 +02:00
|
|
|
startPacketTransfer();
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t idx = 0; idx < dataLen; idx++) {
|
2021-05-27 13:07:57 +02:00
|
|
|
if(pollPapbBusySignal() == RETURN_OK) {
|
|
|
|
*(ptmeBaseAddress + PTME_DATA_REG_OFFSET) = static_cast<uint32_t>(*(data + idx));
|
2021-05-16 19:22:04 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sif::debug << "CCSDSIPCoreBridge::sendTm: Only written " << idx - 1 << " of " << dataLen
|
|
|
|
<< " data" << std::endl;
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 13:07:57 +02:00
|
|
|
if(pollPapbBusySignal() == RETURN_OK) {
|
2021-05-16 19:22:04 +02:00
|
|
|
endPacketTransfer();
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSDSIPCoreBridge::startPacketTransfer() {
|
2021-05-27 13:07:57 +02:00
|
|
|
*ptmeBaseAddress = PTME_CONFIG_START;
|
2021-05-16 19:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCSDSIPCoreBridge::endPacketTransfer() {
|
2021-05-27 13:07:57 +02:00
|
|
|
*ptmeBaseAddress = PTME_CONFIG_END;
|
2021-05-16 19:22:04 +02:00
|
|
|
}
|
|
|
|
|
2021-05-27 13:07:57 +02:00
|
|
|
ReturnValue_t CCSDSIPCoreBridge::pollPapbBusySignal() {
|
2021-05-16 19:22:04 +02: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) {
|
2021-05-27 13:07:57 +02:00
|
|
|
sif::debug << "CCSDSIPCoreBridge::pollPapbBusySignal: Failed to read papb busy signal"
|
2021-05-16 19:22:04 +02:00
|
|
|
<< std::endl;
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
if (!papbBusyState) {
|
2021-05-27 13:07:57 +02:00
|
|
|
sif::debug << "CCSDSIPCoreBridge::pollPapbBusySignal: PAPB busy" << std::endl;
|
2021-05-16 19:22:04 +02:00
|
|
|
return PAPB_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
2021-05-17 13:47:10 +02:00
|
|
|
|
2021-05-27 13:07:57 +02:00
|
|
|
void CCSDSIPCoreBridge::isPtmeBufferEmpty() {
|
2021-05-17 13:47:10 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
int papbEmptyState = 1;
|
|
|
|
|
|
|
|
result = gpioComIF->readGpio(papbEmptyId, &papbEmptyState);
|
|
|
|
|
|
|
|
if (result != RETURN_OK) {
|
2021-05-27 13:07:57 +02:00
|
|
|
sif::debug << "CCSDSIPCoreBridge::isPtmeBufferEmpty: Failed to read papb empty signal"
|
2021-05-17 13:47:10 +02:00
|
|
|
<< std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (papbEmptyState == 1) {
|
2021-05-27 13:07:57 +02:00
|
|
|
sif::debug << "CCSDSIPCoreBridge::isPtmeBufferEmpty: Buffer is empty" << std::endl;
|
2021-05-17 13:47:10 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-05-27 13:07:57 +02:00
|
|
|
sif::debug << "CCSDSIPCoreBridge::isPtmeBufferEmpty: Buffer is not empty" << std::endl;
|
2021-05-17 13:47:10 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-05-27 13:07:57 +02:00
|
|
|
|
|
|
|
ReturnValue_t CCSDSIPCoreBridge::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t result = sendTm(testPacket, 1105);
|
|
|
|
if(result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|