upload fpga image command
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
Jakob Meier
2021-12-30 12:52:08 +01:00
parent 3833b7a875
commit 29e7ac210a
5 changed files with 172 additions and 14 deletions

View File

@ -85,6 +85,17 @@ ReturnValue_t StrHelper::performOperation(uint8_t operationCode) {
internalState = InternalState::IDLE;
break;
}
case InternalState::UPLOAD_FPGA_IMAGE: {
result = performFpgaUpload();
if (result == RETURN_OK){
triggerEvent(FPGA_UPLOAD_SUCCESSFUL);
}
else {
triggerEvent(FPGA_UPLOAD_FAILED);
}
internalState = InternalState::IDLE;
break;
}
default:
sif::debug << "StrHelper::performOperation: Invalid state" << std::endl;
break;
@ -114,7 +125,7 @@ ReturnValue_t StrHelper::startImageUpload(std::string uploadImage_) {
if(not std::filesystem::exists(uploadImage)) {
return FILE_NOT_EXISTS;
}
internalState = InternalState::UPLOAD_IMAGE;
internalState = InternalState::UPLOAD_FPGA_IMAGE;
semaphore.release();
terminate = false;
return RETURN_OK;
@ -147,6 +158,10 @@ void StrHelper::setFlashReadFilename(std::string filename) {
flashReadFile = filename;
}
void StrHelper::setDownloadFpgaImage(std::string filename) {
fpgaDownload.fileName = filename;
}
ReturnValue_t StrHelper::startFlashWrite(std::string flashWriteFile_, uint8_t region,
uint32_t address) {
ReturnValue_t result = checkPath(flashWriteFile_);
@ -195,6 +210,14 @@ ReturnValue_t StrHelper::startFpgaDownload(std::string path, uint32_t startPosit
return RETURN_OK;
}
ReturnValue_t StrHelper::startFpgaUpload(std::string uploadFile) {
fpgaUpload.uploadFile = uploadFile;
internalState = InternalState::UPLOAD_FPGA_IMAGE;
semaphore.release();
terminate = false;
return RETURN_OK;
}
ReturnValue_t StrHelper::performImageDownload() {
ReturnValue_t result;
struct DownloadActionRequest downloadReq;
@ -450,7 +473,7 @@ ReturnValue_t StrHelper::performFpgaDownload() {
file.close();
return result;
}
result = checkFpgaDownloadReply(req.pos, req.length);
result = checkFpgaActionReply(req.pos, req.length);
if (result != RETURN_OK) {
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
uartComIF->flushUartRxBuffer(comCookie);
@ -469,6 +492,47 @@ ReturnValue_t StrHelper::performFpgaDownload() {
return RETURN_OK;
}
ReturnValue_t StrHelper::performFpgaUpload() {
ReturnValue_t result = RETURN_OK;
uint32_t commandSize = 0;
uint32_t bytesUploaded = 0;
uint32_t fileSize = 0;
struct UploadFPGAImageActionRequest req;
if (not std::filesystem::exists(fpgaUpload.uploadFile)) {
triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState));
internalState = InternalState::IDLE;
return RETURN_FAILED;
}
std::ifstream file(flashWriteFile, std::ifstream::binary);
file.seekg(0, file.end);
fileSize = file.tellg();
req.pos = 0;
while(bytesUploaded <= fileSize) {
if (terminate) {
return RETURN_OK;
}
if (fileSize - bytesUploaded > FpgaUpload::MAX_DATA) {
req.length = FpgaUpload::MAX_DATA;
}
else {
req.length = fileSize - bytesUploaded;
}
file.seekg(bytesUploaded, file.beg);
file.read(reinterpret_cast<char*>(req.data), req.length);
arc_pack_uploadfpgaimage_action_req(&req, commandBuffer, &commandSize);
result = sendAndRead(commandSize, req.pos);
if (result != RETURN_OK) {
return RETURN_FAILED;
}
result = checkFpgaActionReply(req.pos, req.length);
if (result != RETURN_OK) {
return result;
}
bytesUploaded += req.length;
}
return RETURN_OK;
}
ReturnValue_t StrHelper::sendAndRead(size_t size, uint32_t parameter) {
ReturnValue_t result = RETURN_OK;
ReturnValue_t decResult = RETURN_OK;
@ -591,20 +655,20 @@ ReturnValue_t StrHelper::checkFlashActionReply(uint8_t region_, uint32_t address
return RETURN_OK;
}
ReturnValue_t StrHelper::checkFpgaDownloadReply(uint32_t expectedPosition,
ReturnValue_t StrHelper::checkFpgaActionReply(uint32_t expectedPosition,
uint32_t expectedLength) {
ReturnValue_t result = RETURN_OK;
result = checkActionReply();
if (result != RETURN_OK) {
return result;
}
const uint8_t* data = datalinkLayer.getReply() + FpgaDownload::POSITION_OFFSET;
const uint8_t* data = datalinkLayer.getReply() + ACTION_DATA_OFFSET;
uint32_t position;
size_t size = sizeof(position);
result = SerializeAdapter::deSerialize(&position, &data, &size,
SerializeIF::Endianness::LITTLE);
if (result != RETURN_OK) {
sif::warning << "StrHelper::checkFpgaDownloadReply: Deserialization of position failed"
sif::warning << "StrHelper::checkFpgaActionReply: Deserialization of position failed"
<< std::endl;
return result;
}
@ -613,11 +677,11 @@ ReturnValue_t StrHelper::checkFpgaDownloadReply(uint32_t expectedPosition,
result = SerializeAdapter::deSerialize(&length, &data, &size,
SerializeIF::Endianness::LITTLE);
if (result != RETURN_OK) {
sif::warning << "StrHelper::checkFpgaDownloadReply: Deserialization of length failed"
sif::warning << "StrHelper::checkFpgaActionReply: Deserialization of length failed"
<< std::endl;
return result;
}
return RETURN_OK;
return result;
}
ReturnValue_t StrHelper::checkPath(std::string name) {