Exemplo n.º 1
0
void MatFileDump::finaliseAndClose()
{
  if(finalised)
    return;

  quint32 columns = valuesWritten / rows;
  quint32 remainder = valuesWritten % rows;

  // add zeros to end of file if the last column hasn't been filled
  if(remainder > 0)
  {
    qDebug() << "Last column of" << rows << "row matrix in" << fileName() << "not filled, adding zeros";
    quint32 zeros = rows - remainder;
    double zero = 0;

    valuesWritten += zeros;
    ++columns;

    while(zeros--)
    {
      if( write((char*)&zero, 8) != 8 )
        writeFail();
    }
  }

  quint32 totalDataBytes = valuesWritten * 8;
  quint32 elementSize    = elementHeaderSize + totalDataBytes;


  // write total element size
  if( seek(elementSizeOffset) == false )
    seekFail(elementSizeOffset);

  if( write((char*)&elementSize, 4) != 4 )
    writeFail();


  // write numbers of columns and rows in matrix
  if( seek(columnsRowsOffset) == false )
    seekFail(columnsRowsOffset);

  if( write((char*)&rows, 4) != 4 )
    writeFail();

  if( write((char*)&columns, 4) != 4 )
    writeFail();


  // write the number of bytes of actual data
  if( seek(totalDataBytesOffset) == false )
    seekFail(totalDataBytesOffset);

  if( write((char*)&totalDataBytes, 4) != 4 )
    writeFail();


  close();
  finalised = true;
}
Exemplo n.º 2
0
void MatFileDump::operator<<(const double &data)
{
  if(write((const char*)&data, 8) != 8)
    writeFail();

  ++valuesWritten;
}
Exemplo n.º 3
0
MatFileDump::MatFileDump(quint32 rows, const QString &name) :
    QFile(name),
    rows(rows),
    valuesWritten(0),
    finalised(false)
{
  if( open(QIODevice::WriteOnly | QIODevice::Truncate) == false )
  {
    qDebug() << "Failed opening" << name;
    QCoreApplication::exit(1);
  }

  if( write(matFileHeaderDoubleLE2D, sizeof(matFileHeaderDoubleLE2D)) != sizeof(matFileHeaderDoubleLE2D) )
    writeFail();
}
Exemplo n.º 4
0
void MatFileDump::newFile(quint32 rows, const QString &name)
{
  finaliseAndClose();

  setFileName(name);

  if( open(QIODevice::WriteOnly | QIODevice::Truncate) == false )
  {
    qDebug() << "Failed opening" << name;
    QCoreApplication::exit(1);
  }

  if( write(matFileHeaderDoubleLE2D, sizeof(matFileHeaderDoubleLE2D)) != sizeof(matFileHeaderDoubleLE2D) )
    writeFail();

  this->rows = rows;
  valuesWritten = 0;
  finalised = false;
}
Exemplo n.º 5
0
void Fls_MainFunction(void) {
	/** @req SWS_Fls_00038 */

    static uint32 progressCntr = 0;
	uint32 flashStatus;
	sint32 result;
	uint8 eccError = 0;

	uint32 chunkSize;

	/** @req SWS_Fls_117 */
	VALIDATE_NO_RV(Fls_Global.status != MEMIF_UNINIT,FLS_MAIN_FUNCTION_ID, FLS_E_UNINIT );

	/** @req SWS_Fls_00039 */
	if ( Fls_Global.jobResultType == MEMIF_JOB_PENDING) {
		switch (Fls_Global.jobType) {
		case FLS_JOB_COMPARE:
		    /** @req SWS_Fls_00243 */

			// !req SWS_Fls_00154  Hardware error = FLS_E_COMPARE_FAILED
			// ( we are reading directly from flash so it makes no sense )
		    // Read ECC-error to clear it
		    Mcu_Arc_GetECCError(&eccError); /*lint !e934 Only used in this function  */

		    chunkSize = MIN( Fls_Global.length, Fls_Global.readChunkSize );

		    /** @req SWS_Fls_00244 */
		    /*lint -e{923} flashAddr set by AUTOSAR and it is justified to cast in this case */
			result = (sint32)memcmp((void *)Fls_Global.ramAddr,
					                (void *)Fls_Global.flashAddr, (size_t)chunkSize );

			Fls_Global.ramAddr = &Fls_Global.ramAddr[chunkSize];
			Fls_Global.flashAddr += chunkSize;
			Fls_Global.length -= chunkSize;

			Mcu_Arc_GetECCError(&eccError);  /*lint !e934 Only used in this function  */
			if( eccError > 0u ){
				readFail();
			} else {
				if( 0 != Fls_Global.length ) {
					if (result == 0) {
						Fls_Global.jobResultType = MEMIF_JOB_OK;
					} else {
						/* @req SWS_Fls_00200 */
						Fls_Global.jobResultType = MEMIF_BLOCK_INCONSISTENT;
					}
					Fls_Global.status = MEMIF_IDLE;
					Fls_Global.jobType = FLS_JOB_NONE;
				} else {
					/* Do nothing, wait for next loop */
				}
			}

			break;
		case FLS_JOB_ERASE: {

			flashStatus = Flash_CheckStatus(Fls_Global.config->FlsInfo, (uint32*)Fls_Global.flashAddr, Fls_Global.length ); /*lint !e923 Intended  */

			if (flashStatus == EE_OK ) {
				Fls_Global.jobResultType = MEMIF_JOB_OK;
				Fls_Global.jobType = FLS_JOB_NONE;
				Fls_Global.status = MEMIF_IDLE;
				FEE_JOB_END_NOTIFICATION();
			} else if (flashStatus == EE_INFO_HVOP_INPROGRESS) {
				/* Busy, Do nothing */
			} else {
				// Error
				eraseFail();
			}
			break;
		}
		case FLS_JOB_READ:
			/** @req SWS_Fls_00238 */
			/** @req SWS_Fls_00239 */

			// NOT implemented. Hardware error = FLS_E_READ_FAILED
			// ( we are reading directly from flash so it makes no sense )
			// Read ECC-error to clear it
			Mcu_Arc_GetECCError(&eccError); /*lint !e934 Only used in this function  */


			chunkSize = MIN( Fls_Global.length, Fls_Global.readChunkSize );

			memcpy( (void *)Fls_Global.ramAddr, (void *) Fls_Global.flashAddr, (size_t)chunkSize );  /*lint !e923 Inteded use  */

			Fls_Global.ramAddr += chunkSize; /*lint !e9016 Intended use */
			Fls_Global.flashAddr += chunkSize;
			Fls_Global.length -= chunkSize;

			Mcu_Arc_GetECCError(&eccError);  /*lint !e934 Only used in this function  */
			if( eccError > 0u ){
				readFail();
			} else {
				if( 0 == Fls_Global.length ) {
					Fls_Global.jobResultType = MEMIF_JOB_OK;
					Fls_Global.status = MEMIF_IDLE;
					Fls_Global.jobType = FLS_JOB_NONE;
					FEE_JOB_END_NOTIFICATION();
					LOG_STR("Fls_RP() OK\n");
				}
			}
			break;

		case FLS_JOB_WRITE:
		{
			/* We are writing in chunks. If we want to write 6 chunks in total but
			 * only 2 at a time:
			 *
			 * Call
			 *  #1   The Fls_Write
			 *  #2   Wait for Flash_CheckStatus(), Flash_ProgramPageStart().. function return
			 *      -> 1 verified write, 1 pending
			 *  #3  Wait for Flash_CheckStatus(), Flash_ProgramPageStart()
			 *      Wait for Flash_CheckStatus(), Flash_ProgramPageStart() .. function return
			 *      -> 3 verified writes, 1 pending
			 *  #4  Wait for Flash_CheckStatus(), Flash_ProgramPageStart()
			 *      Wait for Flash_CheckStatus(), Flash_ProgramPageStart() .. function return
			 *      -> 5 verified writes, 1 pending
			 *  #5  Wait for Flash_CheckStatus(), ...function return
			 *      -> 6 verified writes,
			 */

			uint32 bytesLeftToBeWritten = MIN(Fls_Global.flashWriteInfo.chunkSize, Fls_Global.flashWriteInfo.left);

		    do {
				flashStatus = Flash_CheckStatus(
										Fls_Global.config->FlsInfo,
										(uint32 *) Fls_Global.flashWriteInfo.pDest, /*lint !e923 Intended use */
										Fls_Global.flashWriteInfo.pLeft - Fls_Global.flashWriteInfo.left);

				if (flashStatus == EE_OK) {
				    progressCntr = 0;

					LOG_HEX1("Fls_CS() OK ",Fls_Global.flashWriteInfo.pDest);

					if (Fls_Global.flashWriteInfo.left == 0) {
						/* Done! */
						Fls_Global.jobResultType = MEMIF_JOB_OK;
						Fls_Global.status = MEMIF_IDLE;
						Fls_Global.jobType = FLS_JOB_NONE;
						FEE_JOB_END_NOTIFICATION();
						break;
					}

					/* Write more */
					Fls_Global.flashWriteInfo.pDest = Fls_Global.flashWriteInfo.dest;
					Fls_Global.flashWriteInfo.pLeft = Fls_Global.flashWriteInfo.left;

					/* Double word programming */
					LOG_HEX2("Fls_PP() ",Fls_Global.flashWriteInfo.dest," ", Fls_Global.flashWriteInfo.left);

					flashStatus = Flash_ProgramPageStart(
											Fls_Global.config->FlsInfo,
											&Fls_Global.flashWriteInfo.dest,
											&Fls_Global.flashWriteInfo.source,
											&Fls_Global.flashWriteInfo.left, NULL);
					if (flashStatus != EE_OK) {
						writeFail();
						break;  /*lint !e9011 Better readability this way */
					}
					else {
					    uint32 bytesWritten = Fls_Global.flashWriteInfo.pLeft - Fls_Global.flashWriteInfo.left;
					    bytesLeftToBeWritten = (bytesWritten > bytesLeftToBeWritten) ? 0u : (bytesLeftToBeWritten - bytesWritten);
					}

				} else if (flashStatus == EE_INFO_HVOP_INPROGRESS) {
					/* Wait for it */

				    // One return cycle takes approx ~130 instructions.
				    if (MAX_PROGRESS_CNTR < progressCntr) {
				        progressCntr = 0;
				        writeFail();
				        break; /*lint !e9011 Better readability this way */
				    }

				    progressCntr++;

				} else {
				    progressCntr = 0;
					writeFail();
					/* Nothing to do, quit loop */
					break;  /*lint !e9011 Better readability this way */
				}

			} while (bytesLeftToBeWritten > 0 );

			break;
		}
		case FLS_JOB_NONE:
			assert(FALSE);
			break;

		default:
		    break;
		} /* switch */

	}   /* if */
}