* So how much data should be read from MemIf if a CRC checksum is used. Assuming that we use a physical layout where the CRC is located\r
* after the NV Block it would be BALIGN(NvNvmBlockLength,4) + 4 bytes. The same applies to the RAM block (ROM block to not have CRC, NVM127)\r
*\r
+ * CRC\r
+ * NVM121: NvM_SetRamBlockStatus(), calculate CRC in background if NvmCalcRamBlockCrc==TRUE\r
+ * NVM362: NvM_ReadAll() , if (NvmCalcRamBlockCrc == TRUE && permanent RAM block) re-calc CRC.\r
+ *\r
+ * NvmBlockUseCrc - Global CRC switch. Space is allocated in both RAM and NV block\r
+ * NvmCalcRamBlockCrc - CRC re-calculation. For example during startup, you may don't want\r
+ * to verify all the checksums again, but instead just copy from NV\r
+ * to RAM.\r
+ *\r
+ * There is also explicit RAM checksum calculations for example NVM253 (Nvm_WriteAll()) where a CRC calculation\r
+ * is requested (although not stated should be dependent on NvmBlockUseCrc only, not NvmCalcRamBlockCrc).\r
+ * You have to calculate the checksum at some point....\r
+ *\r
+ * QUEUES\r
+ * NVM185: Says "successful enqueueing a request".."set to NVM_REQ_PENDING"\r
+ * NVM380: The queue length for multi block request shall be one (NvM_ReadAll, NvM_WriteAll)\r
+ * NVM381+NVM567 : Multi block requests shall not be interrupted.\r
+ * NVM243+NVM245: Do not unqueue the multi block request until all single block queues are empty.\r
+ * So, when NvmState==IDLE and we have a multi-request\r
+ *\r
+ *\r
+ *\r
+ *\r
+ *\r
* SPEED\r
* To get some speed into this multiple thing must be done in the same MainFunction loop.\r
*\r
#include "cirq_buffer.h"\r
#include "Modules.h"\r
#include <stdio.h>\r
+#include "io.h"\r
+#include "Crc.h"\r
\r
#if NVM_NUM_OF_NVRAM_BLOCKS != 5\r
#error nOOOOO\r
\r
\r
/* ----------------------------[private macro]-------------------------------*/\r
+\r
+#define NVM_ASSERT(_exp) assert(_exp)\r
+\r
#if ( NVM_DEV_ERROR_DETECT == STD_ON )\r
#include "Det.h"\r
#define VALIDATE(_exp,_api,_err ) \\r
} NvmStateType;\r
\r
typedef enum {\r
- BLOCK_STATE_IDLE,\r
- BLOCK_STATE_START,\r
- BLOCK_STATE_PROCESS,\r
+ BLOCK_STATE_MEMIF_REQ,\r
+// BLOCK_STATE_START,\r
+ BLOCK_STATE_MEMIF_PROCESS,\r
+ BLOCK_STATE_MEMIF_CRC_PROCESS,\r
BLOCK_STATE_CALC_CRC,\r
- BLOCK_STATE_CALC_CRC_WRITE_MULTIBLOCK,\r
+// BLOCK_STATE_MEMIF_PROCESS_CRC,\r
BLOCK_STATE_CALC_CRC_WRITE,\r
+ BLOCK_STATE_CALC_CRC_READ,\r
// BLOCK_STATE_LOAD_FROM_NV,\r
} BlockStateType;\r
\r
} Nvm_SubStates;\r
\r
\r
-\r
+union Nvm_CRC {\r
+ uint16 crc16;\r
+ uint32 crc32;\r
+};\r
\r
\r
typedef struct {\r
boolean BlockChanged; // Block changed?\r
boolean BlockValid; // Block valid? (RAM block only?)\r
uint8 NumberOfWriteFailed; // Current write retry cycle\r
+ union Nvm_CRC crc;\r
} AdministrativeBlockType;\r
\r
/*\r
\r
\r
typedef struct {\r
- Nvm_OpType op;\r
+ NvmStateType op;\r
NvM_BlockIdType blockId;\r
uint8 * dataPtr; /* Src or Dest ptr */\r
} Nvm_QueueType;\r
\r
static Nvm_QueueType nvmQueueImmData[NVM_SIZE_IMMEDIATE_JOB_QUEUE];\r
static Nvm_QueueType nvmQueueData[NVM_SIZE_STANDARD_JOB_QUEUE];\r
+\r
#if (NVM_SIZE_STANDARD_JOB_QUEUE == 0)\r
#error NVM_SIZE_STANDARD_JOB_QUEUE have size 0\r
#endif\r
.BlockAdmin = NULL\r
};\r
\r
+enum Nvm_MultiBlockReq {\r
+ MB_REQ_NONE,\r
+ MB_REQ_READ_ALL,\r
+ MB_REQ_WRITE_ALL,\r
+};\r
+\r
typedef struct {\r
+ NvmStateType state;\r
uint16 currBlockIndex; // Keeps track of next unfinished block\r
NvM_RequestResultType PendingErrorStatus; // Status from multi block requests i.e. Read/Write/CancelWrite-all\r
} AdminMultiReqType;\r
static AdminMultiReqType AdminMultiReq;\r
\r
\r
-\r
/*\r
* Set the MemIf job as busy
*/\r
/*\r
* Request a read of a block from MemIf
*/\r
-static void ReadBlock(const NvM_BlockDescriptorType *blockDescriptor, AdministrativeBlockType *adminBlock, uint8 setNumber, uint8 *destAddress)\r
+static void ReadBlock(const NvM_BlockDescriptorType *blockDescriptor,\r
+ AdministrativeBlockType *adminBlock,\r
+ uint8 setNumber,\r
+ uint8 *destAddress,\r
+ uint16 length )\r
{\r
Std_ReturnType returnCode;\r
uint16 blockOffset = 0; // TODO: How to calculate this?\r
SetMemifJobBusy();\r
MemIfJobAdmin.BlockAdmin = adminBlock;\r
MemIfJobAdmin.BlockDescriptor = blockDescriptor;\r
- returnCode = MemIf_Read(blockDescriptor->NvramDeviceId, BLOCK_BASE_AND_SET_TO_BLOCKNR(blockDescriptor->NvBlockBaseNumber, setNumber), blockOffset, destAddress, blockDescriptor->NvBlockLength);\r
+ returnCode = MemIf_Read(blockDescriptor->NvramDeviceId, BLOCK_BASE_AND_SET_TO_BLOCKNR(blockDescriptor->NvBlockBaseNumber, setNumber), blockOffset, destAddress, length );\r
if (returnCode != E_OK) {\r
AbortMemIfJob(MEMIF_JOB_FAILED);\r
}\r
AdministrativeBlockType *AdminBlockTable = AdminBlock;\r
uint16 i;\r
\r
+ // Set status to pending in the administration blocks\r
+ AdminMultiBlock.ErrorStatus = NVM_REQ_PENDING; /** @req 3.1.5/NVM304 */\r
AdminMultiReq.PendingErrorStatus = NVM_REQ_OK;\r
AdminMultiReq.currBlockIndex = 0;\r
\r
) {\r
VALIDATE_NO_RV(BlockDescriptorList->RamBlockDataAddress != NULL, NVM_READ_ALL_ID, NVM_E_WRONG_CONFIG);\r
VALIDATE_NO_RV(BlockDescriptorList->BlockManagementType != NVM_BLOCK_DATASET, NVM_READ_ALL_ID, NVM_E_WRONG_CONFIG);\r
- if (BlockDescriptorList->CalcRamBlockCrc) {\r
- VALIDATE(BlockDescriptorList->BlockUseCrc == STD_ON, NVM_READ_ALL_ID, NVM_E_BLOCK_CONFIG);\r
- AdminBlockTable->BlockState = BLOCK_STATE_CALC_CRC;\r
- } else {\r
- AdminBlockTable->BlockState = BLOCK_STATE_IDLE;\r
- }\r
+\r
+ AdminBlockTable->ErrorStatus = NVM_REQ_PENDING;\r
+ AdminBlockTable->BlockState = BLOCK_STATE_MEMIF_REQ;\r
} else {\r
AdminBlockTable->ErrorStatus = NVM_REQ_BLOCK_SKIPPED; /* @req 3.1.5/NVM287 */\r
}\r
\r
static void DriveBlock( const NvM_BlockDescriptorType *bPtr,\r
AdministrativeBlockType *admPtr,\r
+ void *dataPtr,\r
boolean write,\r
boolean multiBlock )\r
{\r
bool blockDone = 0;\r
\r
\r
- assert( admPtr->ErrorStatus == NVM_REQ_PENDING);\r
+ NVM_ASSERT( admPtr->ErrorStatus == NVM_REQ_PENDING);\r
\r
switch (admPtr->BlockState) {\r
- case BLOCK_STATE_IDLE:\r
+ case BLOCK_STATE_MEMIF_REQ:\r
{\r
- /* Read block from NV */\r
if( write ) {\r
- WriteBlock(bPtr, admPtr, 0, bPtr->RamBlockDataAddress);\r
+ if( multiBlock && (dataPtr!=NULL)) {\r
+ NVM_ASSERT(0);\r
+ }\r
+\r
+ if (dataPtr != NULL ) {\r
+ WriteBlock(bPtr, admPtr, 0, dataPtr);\r
+ } else {\r
+ WriteBlock(bPtr, admPtr, 0, bPtr->RamBlockDataAddress);\r
+ }\r
} else {\r
- ReadBlock(bPtr, admPtr, 0, bPtr->RamBlockDataAddress);\r
+ ReadBlock(bPtr, admPtr, 0, bPtr->RamBlockDataAddress, bPtr->NvBlockLength);\r
}\r
\r
- admPtr->BlockState = BLOCK_STATE_PROCESS;\r
+ admPtr->BlockState = BLOCK_STATE_MEMIF_PROCESS;\r
break;\r
}\r
\r
- case BLOCK_STATE_PROCESS:\r
+ case BLOCK_STATE_MEMIF_PROCESS:\r
+ case BLOCK_STATE_MEMIF_CRC_PROCESS:\r
{\r
/* Check read */\r
MemIf_JobResultType jobResult = MemIf_GetJobResult(0);\r
} else if( MEMIF_JOB_OK == jobResult ) {\r
/* We are done */\r
\r
+ if( BLOCK_STATE_MEMIF_CRC_PROCESS == admPtr->BlockState ) {\r
+ /* @req 3.1.5/NVM362 NvM_ReadAll*/\r
+ admPtr->BlockState = BLOCK_STATE_CALC_CRC_READ;\r
+ break;\r
+ }\r
\r
- if( bPtr->BlockUseCrc ) {\r
- if( write ) {\r
- if( multiblock ) {\r
+ if( write ) {\r
+ if( bPtr->BlockUseCrc ) {\r
+ /* Explicit CRC calc (not dependent on NvmCalcRamBlockCrc) */\r
+ /* @req 3.1.5/NVM212 NvM_WriteBlock */\r
+ /* @req 3.1.5/NVM253 NvM_WriteAll */\r
+ admPtr->BlockState = BLOCK_STATE_CALC_CRC_WRITE;\r
+ } else {\r
+ /* Done */\r
+ admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;\r
+ admPtr->ErrorStatus = NVM_REQ_OK;\r
+ blockDone = 1;\r
+ }\r
+ } else {\r
+ /* read */\r
+ if( bPtr->BlockUseCrc ) {\r
+ if( bPtr->CalcRamBlockCrc) {\r
+ /* The CRC does not fit into RAM block so we have to read\r
+ * it now..\r
+ */\r
+ ReadBlock(bPtr, admPtr, 0, bPtr->RamBlockDataAddress + bPtr->NvBlockLength,\r
+ (bPtr->BlockCRCType == NVM_CRC16) ? 2 : 4 );\r
\r
- /* Can't calculate checksum on something that does not have a permanent\r
- * RAM block, in multiblock */\r
- assert ( bPtr->RamBlockDataAddress != NULL );\r
+ admPtr->BlockState = BLOCK_STATE_MEMIF_CRC_PROCESS;\r
\r
- if( bPtr->CalcRamBlockCrc ){\r
- /* @req 3.1.5/NVM253 */\r
- admPtr->BlockState = BLOCK_STATE_CALC_CRC_WRITE_MULTIBLOCK;\r
- }\r
} else {\r
- if( bPtr->CalcRamBlockCrc ) {\r
- /* !req 3.1.5/NVM212 */\r
- admPtr->BlockState = BLOCK_STATE_CALC_CRC_WRITE;\r
- }\r
- }\r
- } else {\r
- if( multiblock ) {\r
- if( bPtr->CalcRamBlockCrc && (bPtr->RamBlockDataAddress != NULL ) ){\r
- /* @req 3.1.5/NVM362 */\r
- admPtr->BlockState = BLOCK_STATE_CALC_CRC;\r
- }\r
- } else {\r
- assert(0);\r
+ /* The data is transferred from NV to RAM (including checksums) */\r
+ /* Done */\r
+ admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;\r
+ admPtr->ErrorStatus = NVM_REQ_OK;\r
+ blockDone = 1;\r
}\r
+ } else {\r
+ /* Done */\r
+ admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;\r
+ admPtr->ErrorStatus = NVM_REQ_OK;\r
+ blockDone = 1;\r
}\r
- } else {\r
- admPtr->BlockState = BLOCK_STATE_IDLE;\r
- admPtr->ErrorStatus = NVM_REQ_OK;\r
- blockDone = 1;\r
}\r
break;\r
} else {\r
/* Something failed */\r
AdminMultiReq.PendingErrorStatus = NVM_REQ_NOT_OK;\r
blockDone = 1;\r
- admPtr->BlockState = BLOCK_STATE_IDLE; /* TODO, this really true for all result below */\r
+ admPtr->BlockState = BLOCK_STATE_MEMIF_REQ; /* TODO, this really true for all result below */\r
\r
switch( jobResult ) {\r
case MEMIF_BLOCK_INVALID:\r
admPtr->ErrorStatus = NVM_REQ_NOT_OK;\r
DEM_REPORTERRORSTATUS(NVM_E_REQ_FAILED,DEM_EVENT_STATUS_FAILED);\r
default:\r
- assert(0);\r
+ NVM_ASSERT(0);\r
break;\r
}\r
}\r
break;\r
}\r
+\r
case BLOCK_STATE_CALC_CRC:\r
- assert(0);\r
+ NVM_ASSERT(0);\r
+ break;\r
+\r
+ case BLOCK_STATE_CALC_CRC_WRITE:\r
+ {\r
+ uint32 crc32;\r
+ NVM_ASSERT(bPtr->RamBlockDataAddress != NULL );\r
+\r
+ /* Calculate RAM CRC checksum */\r
+ if( bPtr->BlockCRCType == NVM_CRC16 ) {\r
+#error HERE HERE\r
+ crc16 = Crc_CalculateCRC16(bPtr->RamBlockDataAddress,bPtr->NvBlockLength,0xffff);\r
+ } else {\r
+ /* @req 3.1.5/NVM253 */\r
+ crc32 = Crc_CalculateCRC32(bPtr->RamBlockDataAddress,bPtr->NvBlockLength,0xffffffffUL);\r
+ if( crc32 != admPtr->crc.crc32 ) {\r
+ /* The checksum is wrong, something have written to the RAM area without\r
+ * telling the NVM */\r
+ NVM_ASSERT(0);\r
+ } else {\r
+ admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;\r
+ }\r
+ admPtr->crc.crc32 = crc32;\r
+ }\r
break;\r
- case BLOCK_STATE_CALC_CRC_WRITE_MULTIBLOCK:\r
+ }\r
+ case BLOCK_STATE_CALC_CRC_READ:\r
+ NVM_ASSERT(bPtr->RamBlockDataAddress != NULL );\r
\r
/* Calculate RAM CRC checksum */\r
if( bPtr->BlockCRCType == NVM_CRC16 ) {\r
- assert(0); /* TOOD: No support, yet */\r
+ NVM_ASSERT(0); /* TOOD: Not supported, yet */\r
} else {\r
+ /* @req 3.1.5/NVM253 */\r
\r
+ /* Calculate CRC on the data we just read to RAM. Compare with CRC that is located in NV block */\r
+ admPtr->crc.crc32 = Crc_CalculateCRC32(bPtr->RamBlockDataAddress,bPtr->NvBlockLength,0xffffffffUL);\r
+ if( READ32_NA(bPtr->RamBlockDataAddress + bPtr->NvBlockLength ) != admPtr->crc.crc32 ) {\r
+ /* TODO: Corrupt CRC */\r
+ NVM_ASSERT(0);\r
+ } else {\r
+ admPtr->BlockChanged = BLOCK_STATE_MEMIF_REQ;\r
+ }\r
}\r
- case BLOCK_STATE_CALC_CRC_WRITE:\r
- assert(0);\r
break;\r
default:\r
- assert(0);\r
+ NVM_ASSERT(0);\r
+ break;\r
}\r
\r
if( blockDone ) {\r
\r
DriveBlock( &NvM_Config.BlockDescriptor[AdminMultiReq.currBlockIndex],\r
&AdminBlock[AdminMultiReq.currBlockIndex],\r
+ NULL,\r
false,\r
true );\r
}\r
if (MemIfJobAdmin.BlockDescriptor->BlockUseCrc) {\r
MemIfJobAdmin.BlockAdmin->BlockState = BLOCK_STATE_POSTCALC_CRC; /** @req NVM292 */\r
} else {\r
- MemIfJobAdmin.BlockAdmin->BlockState = BLOCK_STATE_IDLE;\r
+ MemIfJobAdmin.BlockAdmin->BlockState = BLOCK_STATE_MEMIF_REQ;\r
MemIfJobAdmin.BlockAdmin->ErrorStatus = NVM_REQ_OK;\r
MemIfJobAdmin.BlockAdmin->BlockValid = TRUE;\r
MemIfJobAdmin.BlockAdmin->BlockChanged = FALSE;\r
// Read has failed\r
AdminMultiReq.PendingErrorStatus = NVM_REQ_NOT_OK;\r
\r
- MemIfJobAdmin.BlockAdmin->BlockState = BLOCK_STATE_IDLE;\r
+ MemIfJobAdmin.BlockAdmin->BlockState = BLOCK_STATE_MEMIF_REQ;\r
MemIfJobAdmin.BlockAdmin->BlockValid = FALSE;\r
MemIfJobAdmin.BlockAdmin->BlockChanged = FALSE;\r
\r
&& (AdminBlockTable->BlockValid) /** @req NVM682 */\r
&& (AdminBlockTable->BlockChanged) /** @req NVM682 */\r
#endif\r
- && (!AdminBlockTable->BlockWriteProtected)){ /** @req NVM432 *//** @req NVM433 */\r
+ && (!AdminBlockTable->BlockWriteProtected)) /** @req NVM432 *//** @req NVM433 */\r
+ {\r
+ AdminBlockTable->ErrorStatus = NVM_REQ_PENDING;\r
+\r
if (BlockDescriptorList->BlockUseCrc) {\r
- AdminBlockTable->BlockState = BLOCK_STATE_CALC_CRC; /** @req NVM253 */\r
+ AdminBlockTable->BlockState = BLOCK_STATE_CALC_CRC_WRITE; /** @req NVM253 */\r
} else {\r
- AdminBlockTable->BlockState = BLOCK_STATE_IDLE;\r
+ AdminBlockTable->BlockState = BLOCK_STATE_MEMIF_REQ;\r
AdminBlockTable->NumberOfWriteFailed = 0;\r
}\r
} else {\r
\r
DriveBlock( &NvM_Config.BlockDescriptor[AdminMultiReq.currBlockIndex],\r
&AdminBlock[AdminMultiReq.currBlockIndex],\r
+ NULL,\r
false,\r
true );\r
\r
if (MemIfJobAdmin.BlockDescriptor->WriteBlockOnce) {\r
MemIfJobAdmin.BlockAdmin->BlockWriteProtected = TRUE; /** @req NVM329 */\r
}\r
- MemIfJobAdmin.BlockAdmin->BlockState = BLOCK_STATE_IDLE;\r
+ MemIfJobAdmin.BlockAdmin->BlockState = BLOCK_STATE_MEMIF_REQ;\r
MemIfJobAdmin.BlockAdmin->ErrorStatus = NVM_REQ_OK;\r
\r
if (MemIfJobAdmin.BlockDescriptor->SingleBlockCallback != NULL) {\r
// Write has failed\r
AdminMultiReq.PendingErrorStatus = NVM_REQ_NOT_OK;\r
\r
- MemIfJobAdmin.BlockAdmin->BlockState = BLOCK_STATE_IDLE;\r
+ MemIfJobAdmin.BlockAdmin->BlockState = BLOCK_STATE_MEMIF_REQ;\r
MemIfJobAdmin.BlockAdmin->ErrorStatus = NVM_REQ_NOT_OK; /** @req NVM296 */\r
#if defined(USE_DEM)\r
Dem_ReportErrorStatus(NVM_E_REQ_FAILED,DEM_EVENT_STATUS_FAILED);\r
*/\r
void NvM_ReadAll(void)\r
{\r
- uint16 i;\r
-\r
VALIDATE_NO_RV(nvmState != NVM_UNINITIALIZED, NVM_READ_ALL_ID, NVM_E_NOT_INITIALIZED);\r
- // Check queue\r
- // TODO: Check queue\r
\r
- // Check state\r
- if (nvmState == NVM_IDLE) {\r
-\r
- /** !req 3.1.5/NVM243 TODO: Must check that queue is empty */\r
- nvmState = NVM_READ_ALL;\r
-\r
- // Set status to pending in the administration blocks\r
- AdminMultiBlock.ErrorStatus = NVM_REQ_PENDING; /** @req 3.1.5/NVM304 */\r
+ NVM_ASSERT(nvmState == NVM_IDLE);\r
\r
- /** @req 3.1.5/NVM244 */\r
- for (i = 0; i < (NVM_NUM_OF_NVRAM_BLOCKS); i++) {\r
- AdminBlock[i].ErrorStatus = NVM_REQ_PENDING;\r
- }\r
- }\r
+ AdminMultiReq.state = NVM_READ_ALL;\r
+ AdminMultiBlock.ErrorStatus = NVM_REQ_PENDING;\r
}\r
\r
\r
*/\r
void NvM_WriteAll(void)\r
{\r
-\r
- AdministrativeBlockType *AdminBlockTable = AdminBlock;\r
+#if 0\r
+ AdministrativeBlockType *admPtr = AdminBlock;\r
+ const NvM_BlockDescriptorType *bPtr = NvM_Config.BlockDescriptor;\r
uint16 i;\r
+#endif\r
\r
VALIDATE_NO_RV(nvmState != NVM_UNINITIALIZED, NVM_READ_ALL_ID, NVM_E_NOT_INITIALIZED);\r
- // Check queue\r
- // TODO: Check queue\r
\r
+ NVM_ASSERT(nvmState == NVM_IDLE);\r
+\r
+ AdminMultiReq.state = NVM_WRITE_ALL;\r
+ AdminMultiBlock.ErrorStatus = NVM_REQ_PENDING;\r
+\r
+#if 0\r
// Check state\r
if (nvmState == NVM_IDLE) {\r
// nvmState = NVM_WRITE_ALL_REQUESTED; /** @req NVM254 */\r
AdminMultiBlock.ErrorStatus = NVM_REQ_PENDING;\r
\r
for (i = 0; i < NVM_NUM_OF_NVRAM_BLOCKS; i++) {\r
- AdminBlockTable->ErrorStatus = NVM_REQ_PENDING; /** @req NVM549 */\r
- AdminBlockTable++;\r
+ admPtr->ErrorStatus = NVM_REQ_PENDING; /** @req NVM549 */\r
+ if( bPtr->BlockUseCrc ) {\r
+ NVM_ASSERT ( bPtr->RamBlockDataAddress != NULL );\r
+ /* @req 3.1.5/NVM253 */\r
+ admPtr->BlockState = BLOCK_STATE_CALC_CRC_WRITE;\r
+\r
+ } else {\r
+ admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;\r
+ }\r
+\r
+ admPtr++;\r
+ bPtr++;\r
}\r
}\r
+#endif\r
}\r
\r
\r
int rv;\r
\r
/** @req 3.1.5/NVM196 */ /** @req 3.1.5/NVM278 */\r
- if( (NvM_DstPtr == NULL) && ( NvM_Config.BlockDescriptor[blockId].RamBlockDataAddress == NULL ) ) {\r
+ if( (NvM_DstPtr == NULL) && ( NvM_Config.BlockDescriptor[blockId-1].RamBlockDataAddress == NULL ) ) {\r
/* It must be a permanent RAM block but no RamBlockDataAddress -> error */\r
return E_NOT_OK;\r
}\r
qEntry.blockId = blockId;\r
qEntry.dataPtr = NvM_DstPtr;\r
rv = CirqBuffPush(&nvmQueue,&qEntry);\r
- assert(rv == 0 );\r
+ NVM_ASSERT(rv == 0 );\r
\r
/* @req 3.1.5/NVM615 */\r
VALIDATE_RV( (AdminBlock[blockId-1].ErrorStatus != NVM_REQ_PENDING), 0, NVM_E_BLOCK_PENDING , E_NOT_OK );\r
\r
- if( AdminBlock[blockId-1].ErrorStatus != NVM_REQ_PENDING)\r
/* req 3.1.5/NVM185 */\r
AdminBlock[blockId-1].ErrorStatus = NVM_REQ_PENDING;\r
\r
*/\r
Std_ReturnType NvM_WriteBlock( NvM_BlockIdType blockId, const uint8* NvM_SrcPtr ) {\r
\r
- const NvM_BlockDescriptorType * bList = NvM_Config.BlockDescriptor;\r
- AdministrativeBlockType * aList = AdminBlock;\r
+ const NvM_BlockDescriptorType * bPtr;\r
+ AdministrativeBlockType * admPtr;\r
+ Nvm_QueueType qEntry;\r
+ int rv;\r
+\r
+ NVM_ASSERT( blockId >= 2 ); /* No support for lower numbers, yet */\r
+\r
+ /* @req 3.1.5/NVM618 */\r
+ VALIDATE_RV( blockId <= NVM_NUM_OF_NVRAM_BLOCKS,\r
+ NVM_WRITE_BLOCK_ID,NVM_E_PARAM_BLOCK_ID,E_NOT_OK );\r
+\r
+ bPtr = &NvM_Config.BlockDescriptor[blockId-1];\r
+ admPtr = &AdminBlock[blockId-1];\r
+\r
+ /** @req 3.1.5/NVM196 */ /** @req 3.1.5/NVM278 */\r
+ if( (NvM_SrcPtr == NULL) && ( bPtr->RamBlockDataAddress == NULL ) ) {\r
+ /* It must be a permanent RAM block but no RamBlockDataAddress -> error */\r
+ NVM_ASSERT(0); // TODO: See NVM210, DET error\r
+ return E_NOT_OK;\r
+ }\r
+\r
+ /* @req 3.1.5/NVM195 */\r
+ qEntry.blockId = blockId;\r
+ qEntry.op = NVM_WRITE_BLOCK;\r
+ qEntry.blockId = blockId;\r
+ qEntry.dataPtr = (uint8_t *)NvM_SrcPtr;\r
+ rv = CirqBuffPush(&nvmQueue,&qEntry);\r
+ NVM_ASSERT(rv == 0 );\r
+\r
+ /* @req 3.1.5/NVM620 */\r
+ VALIDATE_RV( (admPtr->ErrorStatus != NVM_REQ_PENDING), 0, NVM_E_BLOCK_PENDING , E_NOT_OK );\r
+\r
+ /* req 3.1.5/NVM185 */\r
+ admPtr->ErrorStatus = NVM_REQ_PENDING;\r
+\r
+ if( bPtr->BlockUseCrc) {\r
+ admPtr->BlockState = BLOCK_STATE_CALC_CRC_WRITE;\r
+ } else {\r
+ admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;\r
+ }\r
+\r
\r
- WriteBlock(&bList[blockId], &aList[blockId], 0, bList[blockId].RamBlockDataAddress);\r
return E_OK;\r
}\r
\r
if( rv == 0 ) {\r
/* Buffer not empty */\r
nvmState = qEntry.op;\r
- nvmBlock = &bList[qEntry.blockId];\r
- admBlock = &AdminBlock[qEntry.blockId];\r
+ nvmBlock = &bList[qEntry.blockId-1];\r
+ admBlock = &AdminBlock[qEntry.blockId-1];\r
nvmSubState = 0;\r
admBlock->ErrorStatus = NVM_REQ_PENDING;\r
+ } else {\r
+ /* Check multiblock req */\r
+ if( AdminMultiReq.state != NVM_UNINITIALIZED ) {\r
+ nvmState = AdminMultiReq.state ;\r
+ nvmSubState = 0;\r
+ nvmBlock = 0;\r
+ admBlock = 0;\r
+ AdminMultiReq.state = NVM_UNINITIALIZED;\r
+ }\r
}\r
}\r
\r
/** @req 3.1.5/NVM196 */\r
if( qEntry.dataPtr == NULL) {\r
/* Its a permanent RAM block */\r
- assert( nvmBlock->RamBlockDataAddress != NULL ); /** @req 3.1.5/NVM278 */\r
+ NVM_ASSERT( nvmBlock->RamBlockDataAddress != NULL ); /** @req 3.1.5/NVM278 */\r
admBlock->BlockValid = 0; /** @req 3.1.5/NVM198 */\r
qEntry.dataPtr = nvmBlock->RamBlockDataAddress;\r
}\r
/** @req 3.1.5/NVM199 */\r
switch(nvmBlock->BlockManagementType) {\r
case NVM_BLOCK_REDUNDANT:\r
- assert(nvmBlock->NvBlockNum == 2); /* at least 2 block according to NVM480 */\r
+ NVM_ASSERT(nvmBlock->NvBlockNum == 2); /* at least 2 block according to NVM480 */\r
break;\r
case NVM_BLOCK_NATIVE:\r
/* TODO */\r
ReadAllMain();\r
}\r
break;\r
+\r
case NVM_READ_BLOCK:\r
- DriveBlock(nvmBlock,admBlock, false, false );\r
+ DriveBlock(nvmBlock,admBlock, qEntry.dataPtr, false, false );\r
+ break;\r
+\r
+ case NVM_WRITE_BLOCK:\r
+ DriveBlock(nvmBlock,admBlock, qEntry.dataPtr, false, false );\r
break;\r
\r
case NVM_WRITE_ALL:\r
--- /dev/null
+/*\r
+ * Copyright 2001-2010 Georges Menie (www.menie.org)\r
+ * All rights reserved.\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions are met:\r
+ *\r
+ * * Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * * Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * * Neither the name of the University of California, Berkeley nor the\r
+ * names of its contributors may be used to endorse or promote products\r
+ * derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY\r
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#include "Crc.h"\r
+\r
+/* CRC16 implementation according to CCITT standards */\r
+\r
+static const uint16 crc16tab[256]= {\r
+ 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,\r
+ 0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,\r
+ 0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,\r
+ 0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,\r
+ 0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,\r
+ 0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,\r
+ 0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,\r
+ 0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,\r
+ 0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,\r
+ 0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,\r
+ 0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,\r
+ 0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,\r
+ 0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,\r
+ 0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,\r
+ 0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,\r
+ 0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,\r
+ 0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,\r
+ 0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,\r
+ 0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,\r
+ 0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,\r
+ 0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,\r
+ 0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,\r
+ 0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,\r
+ 0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,\r
+ 0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,\r
+ 0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,\r
+ 0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,\r
+ 0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,\r
+ 0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,\r
+ 0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,\r
+ 0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,\r
+ 0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0\r
+};\r
+\r
+\r
+uint16 Crc_CalculateCRC16( const uint8* dataPtr,\r
+ uint32 len,\r
+ uint16 startVal ) {\r
+ int counter;\r
+ uint16 crc = startVal;\r
+\r
+ for( counter = 0; counter < len; counter++) {\r
+ crc = (crc<<8) ^ crc16tab[((crc>>8) ^ *(char *)dataPtr++)&0x00FF];\r
+ }\r
+ return crc;\r
+}\r