示例#1
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 */
}
示例#2
0
文件: Fls.c 项目: uincore/OpenSAR
void Fls_MainFunction(void) {
	/** @req FLS255 */
	/** @req FLS266 */
	/** @req FLS038 */
	/** !req FLS040  No support for Fls_ConfigSetType.FlsMaxXXXX */
	/** !req FLS104 */
	/** !req FLS105 */
	/** !req FLS106 */
	/** !req FLS154 */
	/** !req FLS200 */
	/** !req FLS022 */
	/** !req FLS055 */
	/** !req FLS056 */
	/** !req FLS052 */
	/** !req FLS232 */
	/** !req FLS233 */
	/** !req FLS234 */
	/** !req FLS235 */
	/** !req FLS272 */
	/** !req FLS196 */



	uint32 flashStatus;
	int result;
	uint32 eccErrReg = 0;

	uint32 chunkSize;

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

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

			// NOT implemented. Hardware error = FLS_E_COMPARE_FAILED
			// ( we are reading directly from flash so it makes no sense )

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

		    /** @req FLS244 */
			result = memcmp((void *)Fls_Global.ramAddr,
					        (void *)Fls_Global.flashAddr, chunkSize );

			Fls_Global.ramAddr += chunkSize;
			Fls_Global.flashAddr += chunkSize;
			Fls_Global.length -= chunkSize;

			McuE_GetECCError(&eccErrReg);
			if( eccErrReg & FLASH_NON_CORRECTABLE_ERROR ){
				fls_ReadFail();
			} else {
				if( 0 != Fls_Global.length ) {
					if (result == 0) {
						Fls_Global.jobResultType = MEMIF_JOB_OK;
					} else {
						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_t *)Fls_Global.flashAddr, Fls_Global.length );

			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
				fls_EraseFail();
			}
            break;
		}
		case FLS_JOB_READ:
			/** @req FLS238 */
			/** @req FLS239 */

			// 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
			McuE_GetECCError(&eccErrReg);


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

			memcpy( (void *)Fls_Global.ramAddr, (void *) Fls_Global.flashAddr, chunkSize );

			Fls_Global.ramAddr += chunkSize;
			Fls_Global.flashAddr += chunkSize;
			Fls_Global.length -= chunkSize;

			McuE_GetECCError(&eccErrReg);
			if( eccErrReg & FLASH_NON_CORRECTABLE_ERROR ){
				fls_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,
			 */



			int32_t chunkSize = MIN(Fls_Global.flashWriteInfo.chunkSize, Fls_Global.flashWriteInfo.left);

		    do {
				flashStatus = Flash_CheckStatus(
										Fls_Global.config->FlsInfo,
										(uint32_t *) Fls_Global.flashWriteInfo.pDest,
										Fls_Global.flashWriteInfo.pLeft - Fls_Global.flashWriteInfo.left);



				if (flashStatus == EE_OK) {

					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) {
						fls_WriteFail();
						break;
					}

					chunkSize = chunkSize - (int32_t)(Fls_Global.flashWriteInfo.pLeft - Fls_Global.flashWriteInfo.left);

				} else if (flashStatus == EE_INFO_HVOP_INPROGRESS) {
					/* Wait for it */
				} else {
					fls_WriteFail();
					/* Nothing to do, quit loop */
					break;
				}

			} while (chunkSize > 0 );

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

		default:
		    break;
		} /* switch */

	}   /* if */
}