code
stringlengths 1
1.05M
| repo_name
stringlengths 6
83
| path
stringlengths 3
242
| language
stringclasses 222
values | license
stringclasses 20
values | size
int64 1
1.05M
|
|---|---|---|---|---|---|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef EA_CBK_H_
#define EA_CBK_H_
/** @req EA114 */
void Ea_JobEndNotification(void); /** @req EA094 */
void Ea_JobErrorNotification(void); /** @req EA095 */
#endif /*EA_CBK_H_*/
|
2301_81045437/classic-platform
|
memory/Ea/inc/Ea_Cbk.h
|
C
|
unknown
| 952
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef EA_TYPES_H_
#define EA_TYPES_H_
#include "Std_Types.h"
/*
ITEM NAME: <Ea_JobType>
SCOPE: <EA Module>
DESCRIPTION:
define all job in EA module
*/
typedef enum
{
EA_JOB_NONE,
EA_JOB_COMPARE,
EA_JOB_ERASE,
EA_JOB_READ,
EA_JOB_WRITE
} Ea_JobType;
#endif
|
2301_81045437/classic-platform
|
memory/Ea/inc/Ea_Types.h
|
C
|
unknown
| 1,086
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/* General requirement tags */
/** !req EA113 *//* Include structure */
/** @req EA083 *//* Imported types */
/** @req EA117 *//* Not change imported types */
/** @req EA097 *//* Mandatory interface */
/** @req EA163 *//* VARIANT-PRE-COMPILE */
/** @req EA174 *//* No internal management operations performed */
/** @req EA068 *//* Logical blocks must not overlap each other and must not be contained within one another. */
#include "arc_assert.h"
#include "string.h"
#include "Ea.h"
#include "Ea_Cbk.h"
#include "Ea_Types.h"
#include "Cpu.h"
//#include "Mcu.h"
#include "SchM_Ea.h"
/*lint -emacro(904,VALIDATE_NO_RV,VALIDATE_RV) *//*904 PC-Lint exception to MISRA 14.7 (validate DET macros).*/
/** @req EA011 */
/** @req EA045 */
#if (STD_ON == EA_DEV_ERROR_DETECT)
/* @req EA059 */
#if defined(USE_DET)
#include "Det.h"
#endif
/* @req EA098 *//* Optional interface Det_ReportError */
#define DET_REPORT_ERROR(_api, _error) (void)Det_ReportError(EA_MODULE_ID, 0, (_api), (_error))
#define VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
DET_REPORT_ERROR((_api), (_err)); \
return; \
}
#define VALIDATE_RV(_exp,_api,_err,_ret ) \
if( !(_exp) ) { \
DET_REPORT_ERROR((_api), (_err)); \
return (_ret); \
}
#else
#define DET_REPORT_ERROR(_api, _error)
#define VALIDATE_NO_RV(_exp,_api,_err )
#define VALIDATE_RV(_exp,_api,_err,_ret )
#endif
#define IS_VALID_BLOCK_NO(_x) ((0x0 != (_x)) && (0xFFFF != (_x)))
// States used by EA_MainFunction to control the internal state of the module.
typedef enum
{
EA_PENDING_NONE,
EA_PENDING_WRITE,
EA_PENDING_READ,
EA_PENDING_ERASE,
EA_PENDING_ADMIN_WRITE
} Ea_JobStatus;
/*
define EA module notification callback macro
*/
#define EA_JOB_END_NOTIFICATION() \
if (Ea_Global.EaGeneralPtr->EaNvmJobEndNotification != NULL_PTR){ \
Ea_Global.EaGeneralPtr->EaNvmJobEndNotification(); \
}
#define EA_JOB_ERROR_NOTIFICATION() \
if (Ea_Global.EaGeneralPtr->EaNvmJobErrorNotification != NULL_PTR) { \
Ea_Global.EaGeneralPtr->EaNvmJobErrorNotification(); \
}
/*
* Defines for blockstates
*/
/** @req EA047 */
#define BLOCK_INCONSISTENT 0x23
#define BLOCK_CONSISTENT 0x45
#define BLOCK_INVALIDATED 0x67
/*
* Definition of the Admin block type
*/
/** @req EA046 */
typedef struct {
uint16 blockNum;
uint8 blockState;
uint8 check; // Simple checksum
} Ea_AdminBlock;
/*
* Define EA Module Global Type
*/
typedef struct {
const Ea_BlockConfigType *EaBlockConfig;
const Ea_GeneralType *EaGeneralPtr;
MemIf_StatusType ModuleStatus;
MemIf_JobResultType JobResult;
Ea_JobType JobType;
uint16 CurrentBlock; // The block we are currentlty working on
Eep_AddressType EepAddress; // Start adress to read from
uint16 Length; // The length to read i.e the blockSize
Ea_JobStatus JobStatus; // Internal state to be used by main function.
void* Address; // The adress to put the result into
uint16 ReadLength; // The length of the block to read/write
uint16 Offset; // The offset in the block to read from.
}Ea_GlobalType;
/*
* Define EA Module Global
*/
/* !req EA155 */
static Ea_GlobalType Ea_Global = {
.EaBlockConfig = NULL_PTR,
.EaGeneralPtr = NULL_PTR,
.ModuleStatus = MEMIF_UNINIT,
.JobResult = MEMIF_JOB_OK,
.JobType = EA_JOB_NONE,
};
/* This needs to be aligned since it is accessed as a structure in the code. Hence,
* the two variables below
*/
static uint32 tempBuffer[((EA_MAX_BLOCK_SIZE + sizeof(Ea_AdminBlock)) / 4) +1 ];
static uint8* Ea_TempBuffer = (uint8*)tempBuffer;
/*
* Function prototypes
*/
static uint16 EA_GET_BLOCK(uint16 BlockNumber);
static Eep_AddressType calculateEepAddress(uint16 BlockIndex);
static uint16 calculateBlockLength(uint16 BlockIndex);
static void handleLowerLayerRead(MemIf_JobResultType jobResult);
static void handleLowerLayerWrite(MemIf_JobResultType jobResult);
static void handleLowerLayerErase(MemIf_JobResultType jobResult);
static uint8 verifyChecksum(Ea_AdminBlock* block);
static void addChecksum(Ea_AdminBlock* block);
/* @req EA084 */
/* !req EA017 */
void Ea_Init(void)
{
/*init internal variables*/
Ea_Global.EaBlockConfig = Ea_BlockConfigData;
Ea_Global.EaGeneralPtr = &Ea_GeneralData;
Ea_Global.JobResult = MEMIF_JOB_OK; /* @req EA128 */
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE; /* @req EA128 */
}
/* @req EA150 */
#if (STD_ON == EA_SET_MODE_SUPPORTED)
/* @req EA085 */
/* @req EA020 */
void Ea_SetMode(MemIf_ModeType Mode)
{
/* @req EA129 */
VALIDATE_NO_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_SETMODE_ID, EA_E_UNINIT);
/* @req EA165 */
VALIDATE_NO_RV(Ea_Global.ModuleStatus != MEMIF_BUSY, EA_SETMODE_ID, EA_E_BUSY);
/* @req EA166 */
VALIDATE_NO_RV(Ea_Global.ModuleStatus != MEMIF_BUSY_INTERNAL, EA_SETMODE_ID, EA_E_BUSY_INTERNAL);
/* @req EA020 */
Eep_SetMode(Mode);
}
#endif
/* @req EA086 */
/* @req EA021 */
Std_ReturnType Ea_Read(uint16 BlockNumber, uint16 BlockOffset, uint8* DataBufferPtr, uint16 Length)
{
/* @req EA158 */
uint16 BlockIndex;
const Ea_BlockConfigType *EaBlockCon = Ea_Global.EaBlockConfig;
/* @req EA130 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_READ_ID, EA_E_UNINIT, E_NOT_OK);
/* @req EA147 */
VALIDATE_RV(IS_VALID_BLOCK_NO(BlockNumber), EA_READ_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
BlockIndex = EA_GET_BLOCK(BlockNumber);
VALIDATE_RV(BlockIndex < EA_NUMBER_OF_BLOCKS, EA_READ_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req EA170 */
VALIDATE_RV(NULL != DataBufferPtr, EA_READ_ID, EA_E_INVALID_DATA_PTR, E_NOT_OK);
/* @req EA168 */
VALIDATE_RV(BlockOffset < EaBlockCon[BlockIndex].EaBlockSize, EA_READ_ID, EA_E_INVALID_BLOCK_OFS, E_NOT_OK);
/* @req EA169 */
VALIDATE_RV((BlockOffset + Length) <= EaBlockCon[BlockIndex].EaBlockSize, EA_READ_ID, EA_E_INVALID_BLOCK_LEN, E_NOT_OK);
/* @req EA137 */
/* Lock down the module to ourself */
SchM_Enter_Ea_EA_0();
if (Ea_Global.ModuleStatus != MEMIF_IDLE)
{
/* @req EA167 *//* @req EA179 *//* @req EA180 */
DET_REPORT_ERROR(EA_READ_ID, (MEMIF_BUSY == Ea_Global.ModuleStatus) ? EA_E_BUSY : EA_E_BUSY_INTERNAL);
SchM_Exit_Ea_EA_0();
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/*set current state is internal busy*/
Ea_Global.ModuleStatus = MEMIF_BUSY_INTERNAL;
SchM_Exit_Ea_EA_0();
/*whether block device index match underlying driver in which Eep_Read will be invoked*/
Ea_Global.Address = DataBufferPtr;
/* @req EA021 :calculate the corresponding memory read address for underlying Eep_Read*/
Ea_Global.EepAddress = calculateEepAddress(BlockIndex);
Ea_Global.Length = EaBlockCon[BlockIndex].EaBlockSize + sizeof(Ea_AdminBlock);
Ea_Global.Offset = BlockOffset;
Ea_Global.ReadLength = Length;
Ea_Global.CurrentBlock = BlockNumber;
/* @req EA022 */
Ea_Global.ModuleStatus = MEMIF_BUSY;
Ea_Global.JobType = EA_JOB_READ;
Ea_Global.JobResult = MEMIF_JOB_PENDING;
Ea_Global.JobStatus = EA_PENDING_NONE;
return E_OK;
}
/* @req EA087 */
/* @req EA024 */
/* @req EA026 */
Std_ReturnType Ea_Write(uint16 BlockNumber, uint8* DataBufferPtr)
{
/* !req EA182 */
/* @req EA159 */
uint16 BlockIndex;
const Ea_BlockConfigType *EaBlockCon;
Ea_AdminBlock* adminBlock;
/* @req EA131 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_WRITE_ID, EA_E_UNINIT, E_NOT_OK);
/* @req EA148 */
VALIDATE_RV(IS_VALID_BLOCK_NO(BlockNumber), EA_WRITE_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
BlockIndex = EA_GET_BLOCK(BlockNumber);
VALIDATE_RV(BlockIndex < EA_NUMBER_OF_BLOCKS, EA_WRITE_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req EA172 */
VALIDATE_RV(NULL != DataBufferPtr, EA_WRITE_ID, EA_E_INVALID_DATA_PTR, E_NOT_OK);
/* @req EA137
*/
/* Lock down the module to ourself */
SchM_Enter_Ea_EA_0();
if (Ea_Global.ModuleStatus != MEMIF_IDLE)
{
/* @req EA171 *//* @req EA181 *//* @req EA183 */
DET_REPORT_ERROR(EA_WRITE_ID, (MEMIF_BUSY == Ea_Global.ModuleStatus) ? EA_E_BUSY : EA_E_BUSY_INTERNAL);
SchM_Exit_Ea_EA_0();
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/*set current state is internal busy*/
Ea_Global.ModuleStatus = MEMIF_BUSY_INTERNAL;
SchM_Exit_Ea_EA_0();
/*whether block device index match underlying driver in which Eep_Read will be invoked*/
EaBlockCon = Ea_Global.EaBlockConfig;
/*calculate the EepAddress*/
Ea_Global.EepAddress = calculateEepAddress(BlockIndex);
/* IMPROVMENT: Should the length be aligned to the virtual page size? */
Ea_Global.Length = EaBlockCon[BlockIndex].EaBlockSize + sizeof(Ea_AdminBlock);/* @req EA151 */
Ea_Global.Address = (void*)DataBufferPtr;
Ea_Global.CurrentBlock = BlockNumber;
/* Setup the admin block */
/* @req EA047 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
adminBlock->blockNum = BlockNumber;
adminBlock->blockState = BLOCK_INCONSISTENT;
addChecksum(adminBlock);
/* Copy the data to the buffer */
uint8* destMem = (uint8*) (Ea_TempBuffer + sizeof(Ea_AdminBlock));
memcpy(destMem, DataBufferPtr, EaBlockCon[BlockIndex].EaBlockSize);
/* @req EA025 [set internal variables set the EA module status to MEMIF_BUSY, set the job result to MEMIF_JOB_PENDING.]*/
Ea_Global.ModuleStatus = MEMIF_BUSY;
Ea_Global.JobType = EA_JOB_WRITE;
Ea_Global.JobResult = MEMIF_JOB_PENDING;
Ea_Global.JobStatus = EA_PENDING_NONE;
return E_OK;
}
/* @req EA088 */
void Ea_Cancel(void)
{
/* @req EA132 */
VALIDATE_NO_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_CANCEL_ID, EA_E_UNINIT);
/* @req EA078 [Reset the Ea module's internal variables to make the module ready for a new job request.]*/
if( MEMIF_BUSY == Ea_Global.ModuleStatus ) {
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
Ea_Global.JobResult = MEMIF_JOB_CANCELED;
/* @req EA077 [Call the cancel function of the underlying EEPROM driver.]*/
Eep_Cancel();
} else {
/* @req EA160 */
/* @req EA173 */
DET_REPORT_ERROR(EA_CANCEL_ID, EA_E_INVALID_CANCEL);
}
}
/* @req EA089 */
MemIf_StatusType Ea_GetStatus(void)
{
/* @req EA034 */
/* @req EA156 */
/* @req EA073 */
/* @req EA157 */
return Ea_Global.ModuleStatus;
}
/* @req EA090 */
MemIf_JobResultType Ea_GetJobResult(void)
{
/* @req EA134 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_GETJOBRESULT_ID, EA_E_UNINIT, MEMIF_JOB_FAILED);
/* @req EA035 */
return Ea_Global.JobResult;
}
/* @req EA091 */
Std_ReturnType Ea_InvalidateBlock(uint16 BlockNumber)
{
/* @req EA161 */
uint16 BlockIndex;
const Ea_BlockConfigType *EaBlockCon;
Ea_AdminBlock* adminBlock;
Std_ReturnType result;
/* @req EA135 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_INVALIDATEBLOCK_ID, EA_E_UNINIT, E_NOT_OK);
/* @req EA149 */
VALIDATE_RV(IS_VALID_BLOCK_NO(BlockNumber), EA_INVALIDATEBLOCK_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
BlockIndex = EA_GET_BLOCK(BlockNumber);
VALIDATE_RV(BlockIndex < EA_NUMBER_OF_BLOCKS, EA_INVALIDATEBLOCK_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req EA137
*/
/* Lock down the module to ourself */
SchM_Enter_Ea_EA_0();
if (Ea_Global.ModuleStatus != MEMIF_IDLE)
{
/* @req EA175 *//* @req EA184 */
DET_REPORT_ERROR(EA_INVALIDATEBLOCK_ID, (MEMIF_BUSY == Ea_Global.ModuleStatus) ? EA_E_BUSY : EA_E_BUSY_INTERNAL);
SchM_Exit_Ea_EA_0();
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/*set current state is internal busy*/
Ea_Global.ModuleStatus = MEMIF_BUSY_INTERNAL;
SchM_Exit_Ea_EA_0();
/*whether block device index match underlying driver in which Eep_Read will be invoked*/
EaBlockCon = Ea_Global.EaBlockConfig;
/* @req EA036 [calculate address]*/
Ea_Global.EepAddress = calculateEepAddress(BlockIndex);
Ea_Global.Length = EaBlockCon[BlockIndex].EaBlockSize;
Ea_Global.CurrentBlock = BlockNumber;
Ea_Global.ModuleStatus = MEMIF_BUSY;
Ea_Global.JobType = EA_JOB_WRITE;
Ea_Global.JobStatus = EA_PENDING_ADMIN_WRITE;
Ea_Global.JobResult = MEMIF_JOB_PENDING;
/* @req EA037 [now we calling the erase function of the underlying device driver]*/
/* We just set the Invalidate status of the admin block */
/* Setup the admin block to be consistent again*/
/* @req EA047 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
adminBlock->blockNum = BlockNumber;
adminBlock->blockState = BLOCK_INVALIDATED;
addChecksum(adminBlock);
/* IMPROVMENT: Should the length be aligned to the virtual page size? */
result = Eep_Write(Ea_Global.EepAddress, (const uint8*) Ea_TempBuffer, sizeof(Ea_AdminBlock));
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
MemIf_StatusType status = Eep_GetStatus();
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_ADMIN_WRITE;
}
SchM_Exit_Ea_EA_0();
}
else
{
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobResult = MEMIF_JOB_FAILED;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
return E_NOT_OK;
}
return E_OK;
}
/* @req EA093 */
Std_ReturnType Ea_EraseImmediateBlock(uint16 BlockNumber)
{
/* !req EA064 ?? */
/* @req EA162 */
uint16 BlockIndex;
const Ea_BlockConfigType *EaBlockCon;
/* @req EA136 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_ERASEIMMEDIATEBLOCK_ID, EA_E_UNINIT, E_NOT_OK);
/* @req EA152 */
VALIDATE_RV(IS_VALID_BLOCK_NO(BlockNumber), EA_ERASEIMMEDIATEBLOCK_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
BlockIndex = EA_GET_BLOCK(BlockNumber);
VALIDATE_RV(BlockIndex < EA_NUMBER_OF_BLOCKS, EA_ERASEIMMEDIATEBLOCK_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req EA137
*/
/* Lock down the module to ourself */
SchM_Enter_Ea_EA_0();
if (Ea_Global.ModuleStatus != MEMIF_IDLE)
{
/* @req EA176 *//* @req EA185 */
DET_REPORT_ERROR(EA_ERASEIMMEDIATEBLOCK_ID, (MEMIF_BUSY == Ea_Global.ModuleStatus) ? EA_E_BUSY : EA_E_BUSY_INTERNAL);
SchM_Exit_Ea_EA_0();
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/*set current state is internal busy*/
Ea_Global.ModuleStatus = MEMIF_BUSY_INTERNAL;
SchM_Exit_Ea_EA_0();
EaBlockCon = Ea_Global.EaBlockConfig;
/* @req EA065 [check whether the addressed logical block is configured as containing immediate data]*/
if (!EaBlockCon[BlockIndex].EaImmediateData)
{
DET_REPORT_ERROR(EA_ERASEIMMEDIATEBLOCK_ID, EA_E_INVALID_BLOCK_NO);
Ea_Global.ModuleStatus = MEMIF_IDLE;
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/* @req EA063 [take the block number and calculate the corresponding memory block address.]*/
Ea_Global.EepAddress = calculateEepAddress(BlockIndex);
Ea_Global.Length = calculateBlockLength(BlockIndex); // Calculate the block length in full pages
Ea_Global.CurrentBlock = BlockNumber;
/* @req EA025 [set internal variables set the EA module status to MEMIF_BUSY, set the job result to MEMIF_JOB_PENDING.]*/
Ea_Global.ModuleStatus = MEMIF_BUSY;
Ea_Global.JobType = EA_JOB_ERASE;
Ea_Global.JobResult = MEMIF_JOB_PENDING;
Ea_Global.JobStatus = EA_PENDING_NONE;
return E_OK;
}
/* @req EA096 */
/* @req EA056 */
void Ea_MainFunction(void)
{
Std_ReturnType result;
if ((MEMIF_JOB_PENDING == Ea_Global.JobResult) && (Ea_Global.JobStatus == EA_PENDING_NONE))
{
switch (Ea_Global.JobType)
{
case EA_JOB_WRITE:
/* @req EA026 */
if (MEMIF_IDLE == Eep_GetStatus())
{
result = Eep_Write(Ea_Global.EepAddress, (const uint8*) Ea_TempBuffer, Ea_Global.Length);
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
MemIf_StatusType status = Eep_GetStatus();
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_WRITE;
}
SchM_Exit_Ea_EA_0();
}
}
break;
case EA_JOB_READ:
/* @req EA072 */
if (MEMIF_IDLE == Eep_GetStatus())
{
result = Eep_Read(Ea_Global.EepAddress, (uint8*) Ea_TempBuffer, Ea_Global.Length);
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
MemIf_StatusType status = Eep_GetStatus();
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_READ;
}
SchM_Exit_Ea_EA_0();
}
}
break;
case EA_JOB_ERASE:
if (MEMIF_IDLE == Eep_GetStatus())
{
result = Eep_Erase(Ea_Global.EepAddress, Ea_Global.Length);
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
MemIf_StatusType status = Eep_GetStatus();
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_ERASE;
}
SchM_Exit_Ea_EA_0();
}
}
break;
default:
break;
}
}
else
{
// We have pending jobs. Wait for them to finish.
}
}
/*Callback notifications of the Ea module*/
/* @req EA094 */
/* @req EA153 */
void Ea_JobEndNotification(void)
{
MemIf_JobResultType jobResult = Eep_GetJobResult();
if (MEMIF_JOB_CANCELED == jobResult)
{
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobResult = MEMIF_JOB_CANCELED;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
// Should we call upper layer here?
} else {
/* @req EA051 */
/* @req EA054 */
switch(Ea_Global.JobStatus)
{
case EA_PENDING_READ:
handleLowerLayerRead(jobResult);
break;
case EA_PENDING_WRITE:
handleLowerLayerWrite(jobResult);
break;
case EA_PENDING_ERASE:
handleLowerLayerErase(jobResult);
break;
case EA_PENDING_ADMIN_WRITE:
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
Ea_Global.JobResult = jobResult;
/* @req EA141 */
/* @req EA054 */
/* @req EA142 */
/* @req EA143 */
EA_JOB_END_NOTIFICATION();
break;
default:
ASSERT(0); // Should never come here
break;
}
}
return;
}
static void handleLowerLayerRead(MemIf_JobResultType jobResult)
{
Ea_AdminBlock* adminBlock;
/* Check the admin block i.e the block is consistent */
/* @req EA104 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
if ((!verifyChecksum(adminBlock)) || (adminBlock->blockState == BLOCK_INCONSISTENT)
|| (adminBlock->blockNum != Ea_Global.CurrentBlock))
{
Ea_Global.JobType = EA_JOB_NONE;
/* @req EA055 */
Ea_Global.JobResult = MEMIF_BLOCK_INCONSISTENT;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_ERROR_NOTIFICATION();
}
/* Check if block is invalidated */
/* @req EA074 */
else if (adminBlock->blockState == BLOCK_INVALIDATED)
{
Ea_Global.JobType = EA_JOB_NONE;
/* @req EA055 */
Ea_Global.JobResult = MEMIF_BLOCK_INVALID;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_ERROR_NOTIFICATION();
} else {
// Copy the data to the destination
uint8* srcadress = (uint8*) (Ea_TempBuffer + sizeof (Ea_AdminBlock) + Ea_Global.Offset);
memcpy(Ea_Global.Address, srcadress, Ea_Global.ReadLength);
/* Sucess */
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
Ea_Global.JobResult = jobResult;
/* @req EA054 */
EA_JOB_END_NOTIFICATION();
}
}
static void handleLowerLayerWrite(MemIf_JobResultType jobResult)
{
Ea_AdminBlock* adminBlock;
Std_ReturnType result;
if (jobResult == MEMIF_JOB_OK)
{
/* Setup the admin block to be consistent again*/
/* @req EA047 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
adminBlock->blockNum = Ea_Global.CurrentBlock;
adminBlock->blockState = BLOCK_CONSISTENT;
addChecksum(adminBlock);
result = Eep_Write(Ea_Global.EepAddress, (const uint8*) Ea_TempBuffer, sizeof(Ea_AdminBlock));
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
MemIf_StatusType status = Eep_GetStatus();
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_ADMIN_WRITE;
}
SchM_Exit_Ea_EA_0();
}
else
{
Ea_Global.JobResult = MEMIF_JOB_FAILED;
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_END_NOTIFICATION();/* IMPROVEMENT: Should this be EA_JOB_ERROR_NOTIFICATION? */
}
}
else
{
/* Report error upstreams */
Ea_Global.JobType = EA_JOB_NONE;
/* @req EA055 */
Ea_Global.JobResult = MEMIF_BLOCK_INVALID;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_END_NOTIFICATION();/* IMPROVEMENT: Should this be EA_JOB_ERROR_NOTIFICATION? */
}
}
static void handleLowerLayerErase(MemIf_JobResultType jobResult)
{
Ea_AdminBlock* adminBlock;
Std_ReturnType result;
if (jobResult == MEMIF_JOB_OK)
{
/* Setup the admin block to be consistent again*/
/* @req EA047 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
adminBlock->blockNum = Ea_Global.CurrentBlock;
adminBlock->blockState = BLOCK_INCONSISTENT;
addChecksum(adminBlock);
result = Eep_Write(Ea_Global.EepAddress, (const uint8*) Ea_TempBuffer, sizeof(Ea_AdminBlock));
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
MemIf_StatusType status = Eep_GetStatus();
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_ADMIN_WRITE;
}
SchM_Exit_Ea_EA_0();
} else
{
Ea_Global.JobResult = MEMIF_JOB_FAILED;
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_END_NOTIFICATION();/* IMPROVEMENT: Should this be EA_JOB_ERROR_NOTIFICATION? */
}
}
else
{
/* Report error upstreams */
Ea_Global.JobType = EA_JOB_NONE;
/* @req EA055 */
Ea_Global.JobResult = MEMIF_BLOCK_INVALID;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_END_NOTIFICATION();/* IMPROVEMENT: Should this be EA_JOB_ERROR_NOTIFICATION? */
}
}
/* @req EA095 */
void Ea_JobErrorNotification(void)
{
SchM_Enter_Ea_EA_0();
/* @req EA154*/
if (Ea_Global.JobResult == MEMIF_JOB_PENDING){
Ea_Global.JobResult = MEMIF_JOB_FAILED;
}
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
SchM_Exit_Ea_EA_0();
/* @req EA055 */
/* @req EA144 */
/* @req EA145 */
/* @req EA146 */
/* @req EA100 */
/* @req EA053 */
EA_JOB_ERROR_NOTIFICATION();
}
/*
* Local service to get block index in Ea_Lcfg.c
*/
static uint16 EA_GET_BLOCK(uint16 BlockNumber)
{
const Ea_BlockConfigType *EaBlockCon;
uint16 BlockIndex;
EaBlockCon = Ea_Global.EaBlockConfig;
for (BlockIndex = 0; BlockIndex < EA_NUMBER_OF_BLOCKS; BlockIndex++)
{
if (EaBlockCon[BlockIndex].EaBlockNumber == BlockNumber)
{
break;
}
}
return BlockIndex;
}
/*
* Local service to calculate the actual eep address.
*/
/* @req EA007 */
static Eep_AddressType calculateEepAddress(uint16 BlockIndex)
{
const Ea_BlockConfigType *EaBlockCon;
uint32 totalNumOfBlocks = 0;
uint16 i;
EaBlockCon = Ea_Global.EaBlockConfig;
uint16 blockNum = EaBlockCon[BlockIndex].EaBlockNumber;
uint8 device = EaBlockCon[BlockIndex].EaDeviceIndex;
for (i = 0; i < EA_NUMBER_OF_BLOCKS; i++)
{
if (EaBlockCon[i].EaDeviceIndex == device) // Check that this is the same device
{
if (EaBlockCon[i].EaBlockNumber < blockNum) // Check that blocknum is less than the searched one
{
int blocksize = EaBlockCon[i].EaBlockSize + sizeof(Ea_AdminBlock);
int numOfBlocks = blocksize / EA_VIRTUAL_PAGE_SIZE;
if (blocksize % EA_VIRTUAL_PAGE_SIZE){
numOfBlocks++;
}
totalNumOfBlocks = totalNumOfBlocks + numOfBlocks;
}
}
}
return totalNumOfBlocks * EA_VIRTUAL_PAGE_SIZE;
}
static uint16 calculateBlockLength(uint16 BlockIndex)
{
const Ea_BlockConfigType *EaBlockCon;
EaBlockCon = Ea_Global.EaBlockConfig;
int blocksize = EaBlockCon[BlockIndex].EaBlockSize + sizeof(Ea_AdminBlock);
int numOfBlocks = blocksize / EA_VIRTUAL_PAGE_SIZE;
if (blocksize % EA_VIRTUAL_PAGE_SIZE){
numOfBlocks++;
}
return numOfBlocks * EA_VIRTUAL_PAGE_SIZE;
}
/* Some very simple checksum calculations */
/* Better than nothing :-) */
static uint8 verifyChecksum(Ea_AdminBlock* block)
{
uint8 result;
uint8* array = (uint8*) block;
result = array[0];
result += array[1];
result += array[2];
result = result ^ 0xaaU;
return (result == block->check);
}
static void addChecksum(Ea_AdminBlock* block)
{
uint8 result;
uint8* array = (uint8*) block;
result = array[0];
result += array[1];
result += array[2];
result = result ^ 0xaaU;
block->check = result;
}
|
2301_81045437/classic-platform
|
memory/Ea/src/Ea.c
|
C
|
unknown
| 29,192
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/* General requirement tags */
/** !req EA113 *//* Include structure */
/** @req EA083 *//* Imported types */
/** @req EA117 *//* Not change imported types */
/** @req EA097 *//* Mandatory interface */
/** @req EA163 *//* VARIANT-PRE-COMPILE */
/** @req EA174 *//* No internal management operations performed */
/** @req EA068 *//* Logical blocks must not overlap each other and must not be contained within one another. */
#include "arc_assert.h"
#include "string.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "Ea.h"
#include "Ea_Cbk.h"
#include "Ea_Types.h"
#include "Cpu.h"
//#include "Mcu.h"
#include "SchM_Ea.h"
/*lint -emacro(904,VALIDATE_NO_RV,VALIDATE_RV) *//*904 PC-Lint exception to MISRA 14.7 (validate DET macros).*/
/** @req EA011 */
/** @req EA045 */
#if (STD_ON == EA_DEV_ERROR_DETECT)
/* @req EA059 */
#if defined(USE_DET)
#include "Det.h"
#endif
/* @req EA098 *//* Optional interface Det_ReportError */
#define DET_REPORT_ERROR(_api, _error) (void)Det_ReportError(EA_MODULE_ID, 0, (_api), (_error))
#define VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
DET_REPORT_ERROR((_api), (_err)); \
return; \
}
#define VALIDATE_RV(_exp,_api,_err,_ret ) \
if( !(_exp) ) { \
DET_REPORT_ERROR((_api), (_err)); \
return (_ret); \
}
#else
#define DET_REPORT_ERROR(_api, _error)
#define VALIDATE_NO_RV(_exp,_api,_err )
#define VALIDATE_RV(_exp,_api,_err,_ret )
#endif
#define IS_VALID_BLOCK_NO(_x) ((0x0 != (_x)) && (0xFFFF != (_x)))
// States used by EA_MainFunction to control the internal state of the module.
typedef enum
{
EA_PENDING_NONE,
EA_PENDING_WRITE,
EA_PENDING_READ,
EA_PENDING_ERASE,
EA_PENDING_ADMIN_WRITE
} Ea_JobStatus;
/*
define EA module notification callback macro
*/
#define EA_JOB_END_NOTIFICATION() \
if (Ea_Global.EaGeneralPtr->EaNvmJobEndNotification != NULL_PTR){ \
Ea_Global.EaGeneralPtr->EaNvmJobEndNotification(); \
}
#define EA_JOB_ERROR_NOTIFICATION() \
if (Ea_Global.EaGeneralPtr->EaNvmJobErrorNotification != NULL_PTR) { \
Ea_Global.EaGeneralPtr->EaNvmJobErrorNotification(); \
}
/*
* Defines for blockstates
*/
/** @req EA047 */
#define BLOCK_INCONSISTENT 0x23
#define BLOCK_CONSISTENT 0x45
#define BLOCK_INVALIDATED 0x67
/*
* Definition of the Admin block type
*/
/** @req EA046 */
typedef struct {
uint16 blockNum;
uint8 blockState;
uint8 check; // Simple checksum
} Ea_AdminBlock;
/*
* Define EA Module Global Type
*/
typedef struct {
const Ea_BlockConfigType *EaBlockConfig;
const Ea_GeneralType *EaGeneralPtr;
MemIf_StatusType ModuleStatus;
MemIf_JobResultType JobResult;
Ea_JobType JobType;
uint16 CurrentBlock; // The block we are currentlty working on
uint32 EepAddress; // Start adress to read from
uint16 Length; // The length to read i.e the blockSize
Ea_JobStatus JobStatus; // Internal state to be used by main function.
void* Address; // The adress to put the result into
uint16 ReadLength; // The length of the block to read/write
uint16 Offset; // The offset in the block to read from.
}Ea_GlobalType;
/*
* Define EA Module Global
*/
/* !req EA155 */
static Ea_GlobalType Ea_Global = {
.EaBlockConfig = NULL_PTR,
.EaGeneralPtr = NULL_PTR,
.ModuleStatus = MEMIF_UNINIT,
.JobResult = MEMIF_JOB_OK,
.JobType = EA_JOB_NONE,
};
/* This needs to be aligned since it is accessed as a structure in the code. Hence,
* the two variables below
*/
static uint32 tempBuffer[((EA_MAX_BLOCK_SIZE + sizeof(Ea_AdminBlock)) / 4) +1 ];
static uint8* Ea_TempBuffer = (uint8*)tempBuffer;
char EaBlockNames[EA_NUMBER_OF_BLOCKS][20];
FILE *EA_Ptr;
MemIf_JobResultType lowerJobStatus = MEMIF_JOB_OK;
/*
* Function prototypes
*/
static uint16 EA_GET_BLOCK(uint16 BlockNumber);
static uint32 calculateEepAddress(uint16 BlockIndex);
static uint16 calculateBlockLength(uint16 BlockIndex);
static void handleLowerLayerRead(MemIf_JobResultType jobResult);
static void handleLowerLayerWrite(MemIf_JobResultType jobResult);
static void handleLowerLayerErase(MemIf_JobResultType jobResult);
static uint8 verifyChecksum(Ea_AdminBlock* block);
static void addChecksum(Ea_AdminBlock* block);
static Std_ReturnType initFile(void);
static Std_ReturnType readFile(uint8 *DataBufferPtr, uint16 Length);
static Std_ReturnType writeFile(const uint8 *DataBufferPtr, uint16 Length);
static Std_ReturnType eraseFile(uint16 Length);
static int file_exist (char *filename);
static Std_ReturnType eraseFile(uint16 Length){
uint16 BlockIndex;
Std_ReturnType ret = E_OK;
char blank[] = { 0xff };
BlockIndex = EA_GET_BLOCK(Ea_Global.CurrentBlock);
printf("Erasing from file %s \n", EaBlockNames[BlockIndex]);
EA_Ptr = fopen(EaBlockNames[BlockIndex], "rb+");
if (EA_Ptr == NULL) {
printf("Unable to open file %s!\n", EaBlockNames[BlockIndex]);
perror("Error");
ret = E_NOT_OK;
} else {
printf("File open!\n");
/* Goto begining of the file */
fseek(EA_Ptr, 0, SEEK_SET);
fwrite(blank, sizeof(char), Length, EA_Ptr);
fflush( EA_Ptr );
fclose(EA_Ptr);
}
return ret;
}
static Std_ReturnType writeFile(const uint8 *DataBufferPtr, uint16 Length){
uint16 BlockIndex;
Std_ReturnType ret = E_OK;
BlockIndex = EA_GET_BLOCK(Ea_Global.CurrentBlock);
printf("Writing to file %s \n", EaBlockNames[BlockIndex]);
EA_Ptr = fopen(EaBlockNames[BlockIndex], "rb+");
if (EA_Ptr == NULL) {
printf("Unable to open file %s!\n", EaBlockNames[BlockIndex]);
perror("Error");
ret = E_NOT_OK;
} else {
printf("File open!\n");
/* Goto begining of the file */
fseek(EA_Ptr, 0, SEEK_SET);
printf("DataBufferPtr:: %d \n", DataBufferPtr);
fwrite(DataBufferPtr, sizeof(char), Length, EA_Ptr);
fflush( EA_Ptr );
fclose(EA_Ptr);
}
return ret;
}
Std_ReturnType readFile(uint8 *DataBufferPtr, uint16 Length) {
uint16 BlockIndex;
Std_ReturnType ret = E_OK;
BlockIndex = EA_GET_BLOCK(Ea_Global.CurrentBlock);
printf("Reading from file %s \n", EaBlockNames[BlockIndex]);
EA_Ptr = fopen(EaBlockNames[BlockIndex], "rb+");
if (EA_Ptr == NULL) {
printf("Unable to open file %s!\n", EaBlockNames[BlockIndex]);
perror("Error");
ret = E_NOT_OK;
} else {
printf("File open!\n");
/* Goto begining of the file */
fseek(EA_Ptr, 0, SEEK_SET);
/* Goto position to be written in the file of the file */
//fseek(EA_Ptr, Ea_Global.Offset + sizeof(Ea_AdminBlock), SEEK_SET);
fread (DataBufferPtr, 1, Length, EA_Ptr);
fclose(EA_Ptr);
printf("DATA:: %s \n", DataBufferPtr);
}
return ret;
}
static int file_exist (char *filename){
struct stat buffer;
return (stat (filename, &buffer) == 0);
}
/**
* init
* Initialize the file that will emulate the flash
*
* @return: Error in case there is a problem.
*/
static Std_ReturnType initFile(void) {
Std_ReturnType ret = E_OK;
char command[50];
int i=0;
char blank[] = { 0xff };
strcpy( command, "ls -l" );
printf("%s\n",command);
system(command);
strcpy( command, "pwd" );
printf("%s\n",command);
system(command);
printf("Check if all required files are already present in current folder\n");
for( i=0 ; i<EA_NUMBER_OF_BLOCKS ; i++ ) {
EaBlockNames[i][0] = '\0';
strcpy( EaBlockNames[i], "EA_" );
char tempBlockNumber[10];
sprintf(tempBlockNumber, "%d", Ea_Global.EaBlockConfig[i].EaBlockNumber);
printf("%s\n",tempBlockNumber);
(void)strcat(EaBlockNames[i], tempBlockNumber);
(void)strcat(EaBlockNames[i], ".bin");
printf("%s\n",EaBlockNames[i]);
if (file_exist (EaBlockNames[i]))
{
printf ("It exists\n");
} else {
printf ("File does not exist\n");
printf ("Creating file with name %s\n", EaBlockNames[i]);
strcpy(command, "touch " );
strcat(command, EaBlockNames[i]);
printf("%s\n",command);
system(command);
strcpy(command, "chmod 777 " );
strcat(command, EaBlockNames[i]);
printf("%s\n",command);
system(command);
}
EA_Ptr = fopen(EaBlockNames[i], "rb+");
if (EA_Ptr == NULL) {
printf("Unable to open file %s!\n", EaBlockNames[i]);
perror("Error");
ret = E_NOT_OK;
} else {
//File size check
fseek(EA_Ptr, 0L, SEEK_END);
int size = ftell(EA_Ptr);
rewind(EA_Ptr);
printf("Current Size of file %s is %d\n", EaBlockNames[i], size);
if(size != Ea_Global.EaBlockConfig[i].EaBlockSize + sizeof(Ea_AdminBlock)){
printf("the expected size is %d", Ea_Global.EaBlockConfig[i].EaBlockSize + sizeof(Ea_AdminBlock));
for (int counter = 0; counter < Ea_Global.EaBlockConfig[i].EaBlockSize + sizeof(Ea_AdminBlock); counter++)
fwrite(blank, sizeof(char), 1, EA_Ptr);
fseek(EA_Ptr, 0L, SEEK_END);
size = ftell(EA_Ptr);
rewind(EA_Ptr);
printf("Current Size of file %s is %d\n", EaBlockNames[i], size);
}
printf("Initialization done for %s\n", EaBlockNames[i]);
fclose(EA_Ptr);
}
}
return ret;
}
/* @req EA084 */
/* !req EA017 */
void Ea_Init(void)
{
/*init internal variables*/
Ea_Global.EaBlockConfig = Ea_BlockConfigData;
Ea_Global.EaGeneralPtr = &Ea_GeneralData;
Ea_Global.JobResult = MEMIF_JOB_OK; /* @req EA128 */
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE; /* @req EA128 */
initFile();
}
/* @req EA150 */
#if (STD_ON == EA_SET_MODE_SUPPORTED)
/* @req EA085 */
/* @req EA020 */
void Ea_SetMode(MemIf_ModeType Mode)
{
/* @req EA129 */
VALIDATE_NO_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_SETMODE_ID, EA_E_UNINIT);
/* @req EA165 */
VALIDATE_NO_RV(Ea_Global.ModuleStatus != MEMIF_BUSY, EA_SETMODE_ID, EA_E_BUSY);
/* @req EA166 */
VALIDATE_NO_RV(Ea_Global.ModuleStatus != MEMIF_BUSY_INTERNAL, EA_SETMODE_ID, EA_E_BUSY_INTERNAL);
/* @req EA020 */
//Not making any special modes
//Eep_SetMode(Mode);
}
#endif
/* @req EA086 */
/* @req EA021 */
Std_ReturnType Ea_Read(uint16 BlockNumber, uint16 BlockOffset, uint8* DataBufferPtr, uint16 Length)
{
printf ("Ea_Read! \n");
/* @req EA158 */
uint16 BlockIndex;
const Ea_BlockConfigType *EaBlockCon = Ea_Global.EaBlockConfig;
/* @req EA130 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_READ_ID, EA_E_UNINIT, E_NOT_OK);
/* @req EA147 */
VALIDATE_RV(IS_VALID_BLOCK_NO(BlockNumber), EA_READ_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
BlockIndex = EA_GET_BLOCK(BlockNumber);
VALIDATE_RV(BlockIndex < EA_NUMBER_OF_BLOCKS, EA_READ_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req EA170 */
VALIDATE_RV(NULL != DataBufferPtr, EA_READ_ID, EA_E_INVALID_DATA_PTR, E_NOT_OK);
/* @req EA168 */
VALIDATE_RV(BlockOffset < EaBlockCon[BlockIndex].EaBlockSize, EA_READ_ID, EA_E_INVALID_BLOCK_OFS, E_NOT_OK);
/* @req EA169 */
VALIDATE_RV((BlockOffset + Length) <= EaBlockCon[BlockIndex].EaBlockSize, EA_READ_ID, EA_E_INVALID_BLOCK_LEN, E_NOT_OK);
/* @req EA137 */
/* Lock down the module to ourself */
SchM_Enter_Ea_EA_0();
if (Ea_Global.ModuleStatus != MEMIF_IDLE)
{
/* @req EA167 *//* @req EA179 *//* @req EA180 */
DET_REPORT_ERROR(EA_READ_ID, (MEMIF_BUSY == Ea_Global.ModuleStatus) ? EA_E_BUSY : EA_E_BUSY_INTERNAL);
SchM_Exit_Ea_EA_0();
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/*set current state is internal busy*/
Ea_Global.ModuleStatus = MEMIF_BUSY_INTERNAL;
SchM_Exit_Ea_EA_0();
/*whether block device index match underlying driver in which Eep_Read will be invoked*/
Ea_Global.Address = DataBufferPtr;
/* @req EA021 :calculate the corresponding memory read address for underlying Eep_Read*/
Ea_Global.EepAddress = calculateEepAddress(BlockIndex);
Ea_Global.Length = EaBlockCon[BlockIndex].EaBlockSize + sizeof(Ea_AdminBlock);
Ea_Global.Offset = BlockOffset;
Ea_Global.ReadLength = Length;
Ea_Global.CurrentBlock = BlockNumber;
/* @req EA022 */
Ea_Global.ModuleStatus = MEMIF_BUSY;
Ea_Global.JobType = EA_JOB_READ;
Ea_Global.JobResult = MEMIF_JOB_PENDING;
Ea_Global.JobStatus = EA_PENDING_NONE;
return E_OK;
}
/* @req EA087 */
/* @req EA024 */
/* @req EA026 */
Std_ReturnType Ea_Write(uint16 BlockNumber, uint8* DataBufferPtr)
{
printf ("Ea_Write!\n");
/* !req EA182 */
/* @req EA159 */
uint16 BlockIndex;
const Ea_BlockConfigType *EaBlockCon;
Ea_AdminBlock* adminBlock;
/* @req EA131 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_WRITE_ID, EA_E_UNINIT, E_NOT_OK);
/* @req EA148 */
VALIDATE_RV(IS_VALID_BLOCK_NO(BlockNumber), EA_WRITE_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
BlockIndex = EA_GET_BLOCK(BlockNumber);
VALIDATE_RV(BlockIndex < EA_NUMBER_OF_BLOCKS, EA_WRITE_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req EA172 */
VALIDATE_RV(NULL != DataBufferPtr, EA_WRITE_ID, EA_E_INVALID_DATA_PTR, E_NOT_OK);
/* @req EA137
*/
/* Lock down the module to ourself */
SchM_Enter_Ea_EA_0();
if (Ea_Global.ModuleStatus != MEMIF_IDLE)
{
/* @req EA171 *//* @req EA181 *//* @req EA183 */
DET_REPORT_ERROR(EA_WRITE_ID, (MEMIF_BUSY == Ea_Global.ModuleStatus) ? EA_E_BUSY : EA_E_BUSY_INTERNAL);
SchM_Exit_Ea_EA_0();
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/*set current state is internal busy*/
Ea_Global.ModuleStatus = MEMIF_BUSY_INTERNAL;
SchM_Exit_Ea_EA_0();
/*whether block device index match underlying driver in which Eep_Read will be invoked*/
EaBlockCon = Ea_Global.EaBlockConfig;
/*calculate the EepAddress*/
Ea_Global.EepAddress = calculateEepAddress(BlockIndex);
/* IMPROVMENT: Should the length be aligned to the virtual page size? */
Ea_Global.Length = EaBlockCon[BlockIndex].EaBlockSize + sizeof(Ea_AdminBlock);/* @req EA151 */
Ea_Global.Address = (void*)DataBufferPtr;
Ea_Global.CurrentBlock = BlockNumber;
/* Setup the admin block */
/* @req EA047 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
adminBlock->blockNum = BlockNumber;
adminBlock->blockState = BLOCK_INCONSISTENT;
addChecksum(adminBlock);
/* Copy the data to the buffer */
uint8* destMem = (uint8*) (Ea_TempBuffer + sizeof(Ea_AdminBlock));
memcpy(destMem, DataBufferPtr, EaBlockCon[BlockIndex].EaBlockSize);
/* @req EA025 [set internal variables set the EA module status to MEMIF_BUSY, set the job result to MEMIF_JOB_PENDING.]*/
Ea_Global.ModuleStatus = MEMIF_BUSY;
Ea_Global.JobType = EA_JOB_WRITE;
Ea_Global.JobResult = MEMIF_JOB_PENDING;
Ea_Global.JobStatus = EA_PENDING_NONE;
return E_OK;
}
/* @req EA088 */
void Ea_Cancel(void)
{
/* @req EA132 */
VALIDATE_NO_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_CANCEL_ID, EA_E_UNINIT);
/* @req EA078 [Reset the Ea module's internal variables to make the module ready for a new job request.]*/
if( MEMIF_BUSY == Ea_Global.ModuleStatus ) {
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
Ea_Global.JobResult = MEMIF_JOB_CANCELED;
/* @req EA077 [Call the cancel function of the underlying EEPROM driver.]*/
//Eep_Cancel();
lowerJobStatus = MEMIF_JOB_CANCELED;
} else {
/* @req EA160 */
/* @req EA173 */
DET_REPORT_ERROR(EA_CANCEL_ID, EA_E_INVALID_CANCEL);
}
}
/* @req EA089 */
MemIf_StatusType Ea_GetStatus(void)
{
/* @req EA034 */
/* @req EA156 */
/* @req EA073 */
/* @req EA157 */
return Ea_Global.ModuleStatus;
}
/* @req EA090 */
MemIf_JobResultType Ea_GetJobResult(void)
{
/* @req EA134 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_GETJOBRESULT_ID, EA_E_UNINIT, MEMIF_JOB_FAILED);
/* @req EA035 */
return Ea_Global.JobResult;
}
/* @req EA091 */
Std_ReturnType Ea_InvalidateBlock(uint16 BlockNumber)
{
/* @req EA161 */
uint16 BlockIndex;
const Ea_BlockConfigType *EaBlockCon;
Ea_AdminBlock* adminBlock;
Std_ReturnType result;
/* @req EA135 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_INVALIDATEBLOCK_ID, EA_E_UNINIT, E_NOT_OK);
/* @req EA149 */
VALIDATE_RV(IS_VALID_BLOCK_NO(BlockNumber), EA_INVALIDATEBLOCK_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
BlockIndex = EA_GET_BLOCK(BlockNumber);
VALIDATE_RV(BlockIndex < EA_NUMBER_OF_BLOCKS, EA_INVALIDATEBLOCK_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req EA137
*/
/* Lock down the module to ourself */
SchM_Enter_Ea_EA_0();
if (Ea_Global.ModuleStatus != MEMIF_IDLE)
{
/* @req EA175 *//* @req EA184 */
DET_REPORT_ERROR(EA_INVALIDATEBLOCK_ID, (MEMIF_BUSY == Ea_Global.ModuleStatus) ? EA_E_BUSY : EA_E_BUSY_INTERNAL);
SchM_Exit_Ea_EA_0();
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/*set current state is internal busy*/
Ea_Global.ModuleStatus = MEMIF_BUSY_INTERNAL;
SchM_Exit_Ea_EA_0();
/*whether block device index match underlying driver in which Eep_Read will be invoked*/
EaBlockCon = Ea_Global.EaBlockConfig;
/* @req EA036 [calculate address]*/
Ea_Global.EepAddress = calculateEepAddress(BlockIndex);
Ea_Global.Length = EaBlockCon[BlockIndex].EaBlockSize;
Ea_Global.CurrentBlock = BlockNumber;
Ea_Global.ModuleStatus = MEMIF_BUSY;
Ea_Global.JobType = EA_JOB_WRITE;
Ea_Global.JobStatus = EA_PENDING_ADMIN_WRITE;
Ea_Global.JobResult = MEMIF_JOB_PENDING;
/* @req EA037 [now we calling the erase function of the underlying device driver]*/
/* We just set the Invalidate status of the admin block */
/* Setup the admin block to be consistent again*/
/* @req EA047 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
adminBlock->blockNum = BlockNumber;
adminBlock->blockState = BLOCK_INVALIDATED;
addChecksum(adminBlock);
/* IMPROVMENT: Should the length be aligned to the virtual page size? */
//result = Eep_Write(Ea_Global.EepAddress, (const uint8*) Ea_TempBuffer, sizeof(Ea_AdminBlock));
result = writeFile((const uint8*) Ea_TempBuffer, sizeof(Ea_AdminBlock));
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
//MemIf_StatusType status = Eep_GetStatus();
MemIf_StatusType status = MEMIF_BUSY;
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_ADMIN_WRITE;
}
SchM_Exit_Ea_EA_0();
}
else
{
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobResult = MEMIF_JOB_FAILED;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
return E_NOT_OK;
}
return E_OK;
}
/* @req EA093 */
Std_ReturnType Ea_EraseImmediateBlock(uint16 BlockNumber)
{
/* !req EA064 ?? */
/* @req EA162 */
uint16 BlockIndex;
const Ea_BlockConfigType *EaBlockCon;
/* @req EA136 */
VALIDATE_RV(Ea_Global.ModuleStatus != MEMIF_UNINIT, EA_ERASEIMMEDIATEBLOCK_ID, EA_E_UNINIT, E_NOT_OK);
/* @req EA152 */
VALIDATE_RV(IS_VALID_BLOCK_NO(BlockNumber), EA_ERASEIMMEDIATEBLOCK_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
BlockIndex = EA_GET_BLOCK(BlockNumber);
VALIDATE_RV(BlockIndex < EA_NUMBER_OF_BLOCKS, EA_ERASEIMMEDIATEBLOCK_ID, EA_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req EA137
*/
/* Lock down the module to ourself */
SchM_Enter_Ea_EA_0();
if (Ea_Global.ModuleStatus != MEMIF_IDLE)
{
/* @req EA176 *//* @req EA185 */
DET_REPORT_ERROR(EA_ERASEIMMEDIATEBLOCK_ID, (MEMIF_BUSY == Ea_Global.ModuleStatus) ? EA_E_BUSY : EA_E_BUSY_INTERNAL);
SchM_Exit_Ea_EA_0();
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/*set current state is internal busy*/
Ea_Global.ModuleStatus = MEMIF_BUSY_INTERNAL;
SchM_Exit_Ea_EA_0();
EaBlockCon = Ea_Global.EaBlockConfig;
/* @req EA065 [check whether the addressed logical block is configured as containing immediate data]*/
if (!EaBlockCon[BlockIndex].EaImmediateData)
{
DET_REPORT_ERROR(EA_ERASEIMMEDIATEBLOCK_ID, EA_E_INVALID_BLOCK_NO);
Ea_Global.ModuleStatus = MEMIF_IDLE;
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/* @req EA063 [take the block number and calculate the corresponding memory block address.]*/
Ea_Global.EepAddress = calculateEepAddress(BlockIndex);
Ea_Global.Length = calculateBlockLength(BlockIndex); // Calculate the block length in full pages
Ea_Global.CurrentBlock = BlockNumber;
/* @req EA025 [set internal variables set the EA module status to MEMIF_BUSY, set the job result to MEMIF_JOB_PENDING.]*/
Ea_Global.ModuleStatus = MEMIF_BUSY;
Ea_Global.JobType = EA_JOB_ERASE;
Ea_Global.JobResult = MEMIF_JOB_PENDING;
Ea_Global.JobStatus = EA_PENDING_NONE;
return E_OK;
}
/* @req EA096 */
/* @req EA056 */
void Ea_MainFunction(void)
{
//printf ("Ea_Mainfunction!");
Std_ReturnType result;
if ((MEMIF_JOB_PENDING == Ea_Global.JobResult) && (Ea_Global.JobStatus == EA_PENDING_NONE))
{
switch (Ea_Global.JobType)
{
case EA_JOB_WRITE:
/* @req EA026 */
// if (MEMIF_IDLE == Eep_GetStatus())
// {
//result = Eep_Write(Ea_Global.EepAddress, (const uint8*) Ea_TempBuffer, Ea_Global.Length);
result = writeFile((const uint8*) Ea_TempBuffer, Ea_Global.Length);
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
//MemIf_StatusType status = Eep_GetStatus();
MemIf_StatusType status = MEMIF_BUSY;
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_WRITE;
}
SchM_Exit_Ea_EA_0();
}
// }
break;
case EA_JOB_READ:
/* @req EA072 */
// if (MEMIF_IDLE == Eep_GetStatus())
// {
//result = Eep_Read(Ea_Global.EepAddress, (uint8*) Ea_TempBuffer, Ea_Global.Length);
result = readFile((uint8*) Ea_TempBuffer, Ea_Global.Length);
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
//MemIf_StatusType status = Eep_GetStatus();
MemIf_StatusType status = MEMIF_BUSY;
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_READ;
}
SchM_Exit_Ea_EA_0();
}
// }
break;
case EA_JOB_ERASE:
// if (MEMIF_IDLE == Eep_GetStatus())
// {
//result = Eep_Erase(Ea_Global.EepAddress, Ea_Global.Length);
result = eraseFile(Ea_Global.Length);
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
//MemIf_StatusType status = Eep_GetStatus();
MemIf_StatusType status = MEMIF_BUSY;
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_ERASE;
}
SchM_Exit_Ea_EA_0();
}
// }
break;
default:
break;
}
}
else
{
// We have pending jobs. Wait for them to finish.
if(Ea_Global.JobStatus != EA_PENDING_NONE) {
Ea_JobEndNotification();
}
}
}
/*Callback notifications of the Ea module*/
/* @req EA094 */
/* @req EA153 */
void Ea_JobEndNotification(void)
{
//MemIf_JobResultType jobResult = Eep_GetJobResult();
MemIf_JobResultType jobResult = lowerJobStatus;
if (MEMIF_JOB_CANCELED == jobResult)
{
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobResult = MEMIF_JOB_CANCELED;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
// Should we call upper layer here?
} else {
/* @req EA051 */
/* @req EA054 */
switch(Ea_Global.JobStatus)
{
case EA_PENDING_READ:
handleLowerLayerRead(jobResult);
break;
case EA_PENDING_WRITE:
handleLowerLayerWrite(jobResult);
break;
case EA_PENDING_ERASE:
handleLowerLayerErase(jobResult);
break;
case EA_PENDING_ADMIN_WRITE:
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
Ea_Global.JobResult = jobResult;
/* @req EA141 */
/* @req EA054 */
/* @req EA142 */
/* @req EA143 */
EA_JOB_END_NOTIFICATION();
break;
default:
ASSERT(0); // Should never come here
break;
}
}
return;
}
static void handleLowerLayerRead(MemIf_JobResultType jobResult)
{
Ea_AdminBlock* adminBlock;
/* Check the admin block i.e the block is consistent */
/* @req EA104 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
if ((!verifyChecksum(adminBlock)) || (adminBlock->blockState == BLOCK_INCONSISTENT)
|| (adminBlock->blockNum != Ea_Global.CurrentBlock))
{
Ea_Global.JobType = EA_JOB_NONE;
/* @req EA055 */
Ea_Global.JobResult = MEMIF_BLOCK_INCONSISTENT;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_ERROR_NOTIFICATION();
}
/* Check if block is invalidated */
/* @req EA074 */
else if (adminBlock->blockState == BLOCK_INVALIDATED)
{
Ea_Global.JobType = EA_JOB_NONE;
/* @req EA055 */
Ea_Global.JobResult = MEMIF_BLOCK_INVALID;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_ERROR_NOTIFICATION();
} else {
// Copy the data to the destination
uint8* srcadress = (uint8*) (Ea_TempBuffer + sizeof (Ea_AdminBlock) + Ea_Global.Offset);
memcpy(Ea_Global.Address, srcadress, Ea_Global.ReadLength);
/* Sucess */
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
Ea_Global.JobResult = jobResult;
/* @req EA054 */
EA_JOB_END_NOTIFICATION();
}
}
static void handleLowerLayerWrite(MemIf_JobResultType jobResult)
{
Ea_AdminBlock* adminBlock;
Std_ReturnType result;
if (jobResult == MEMIF_JOB_OK)
{
/* Setup the admin block to be consistent again*/
/* @req EA047 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
adminBlock->blockNum = Ea_Global.CurrentBlock;
adminBlock->blockState = BLOCK_CONSISTENT;
addChecksum(adminBlock);
//result = Eep_Write(Ea_Global.EepAddress, (const uint8*) Ea_TempBuffer, sizeof(Ea_AdminBlock));
result = writeFile((const uint8*) Ea_TempBuffer, sizeof(Ea_AdminBlock));
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
//MemIf_StatusType status = Eep_GetStatus();
MemIf_StatusType status = MEMIF_BUSY;
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_ADMIN_WRITE;
}
SchM_Exit_Ea_EA_0();
}
else
{
Ea_Global.JobResult = MEMIF_JOB_FAILED;
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_END_NOTIFICATION();/* IMPROVEMENT: Should this be EA_JOB_ERROR_NOTIFICATION? */
}
}
else
{
/* Report error upstreams */
Ea_Global.JobType = EA_JOB_NONE;
/* @req EA055 */
Ea_Global.JobResult = MEMIF_BLOCK_INVALID;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_END_NOTIFICATION();/* IMPROVEMENT: Should this be EA_JOB_ERROR_NOTIFICATION? */
}
}
static void handleLowerLayerErase(MemIf_JobResultType jobResult)
{
Ea_AdminBlock* adminBlock;
Std_ReturnType result;
if (jobResult == MEMIF_JOB_OK)
{
/* Setup the admin block to be consistent again*/
/* @req EA047 */
adminBlock = (Ea_AdminBlock*) Ea_TempBuffer;
adminBlock->blockNum = Ea_Global.CurrentBlock;
adminBlock->blockState = BLOCK_INCONSISTENT;
addChecksum(adminBlock);
//result = Eep_Write(Ea_Global.EepAddress, (const uint8*) Ea_TempBuffer, sizeof(Ea_AdminBlock));
result = writeFile((const uint8*) Ea_TempBuffer, sizeof(Ea_AdminBlock));
if (E_OK == result)
{
SchM_Enter_Ea_EA_0();
//MemIf_StatusType status = Eep_GetStatus();
MemIf_StatusType status = MEMIF_BUSY;
if ((status == MEMIF_BUSY) || (status == MEMIF_BUSY_INTERNAL)){
Ea_Global.JobStatus = EA_PENDING_ADMIN_WRITE;
}
SchM_Exit_Ea_EA_0();
} else
{
Ea_Global.JobResult = MEMIF_JOB_FAILED;
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_END_NOTIFICATION();/* IMPROVEMENT: Should this be EA_JOB_ERROR_NOTIFICATION? */
}
}
else
{
/* Report error upstreams */
Ea_Global.JobType = EA_JOB_NONE;
/* @req EA055 */
Ea_Global.JobResult = MEMIF_BLOCK_INVALID;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
EA_JOB_END_NOTIFICATION();/* IMPROVEMENT: Should this be EA_JOB_ERROR_NOTIFICATION? */
}
}
/* @req EA095 */
void Ea_JobErrorNotification(void)
{
SchM_Enter_Ea_EA_0();
/* @req EA154*/
if (Ea_Global.JobResult == MEMIF_JOB_PENDING){
Ea_Global.JobResult = MEMIF_JOB_FAILED;
}
Ea_Global.JobType = EA_JOB_NONE;
Ea_Global.JobStatus = EA_PENDING_NONE;
Ea_Global.ModuleStatus = MEMIF_IDLE;
SchM_Exit_Ea_EA_0();
/* @req EA055 */
/* @req EA144 */
/* @req EA145 */
/* @req EA146 */
/* @req EA100 */
/* @req EA053 */
EA_JOB_ERROR_NOTIFICATION();
}
/*
* Local service to get block index in Ea_Lcfg.c
*/
static uint16 EA_GET_BLOCK(uint16 BlockNumber)
{
const Ea_BlockConfigType *EaBlockCon;
uint16 BlockIndex;
EaBlockCon = Ea_Global.EaBlockConfig;
for (BlockIndex = 0; BlockIndex < EA_NUMBER_OF_BLOCKS; BlockIndex++)
{
if (EaBlockCon[BlockIndex].EaBlockNumber == BlockNumber)
{
break;
}
}
return BlockIndex;
}
/*
* Local service to calculate the actual eep address.
*/
/* @req EA007 */
static uint32 calculateEepAddress(uint16 BlockIndex)
{
const Ea_BlockConfigType *EaBlockCon;
uint32 totalNumOfBlocks = 0;
uint16 i;
EaBlockCon = Ea_Global.EaBlockConfig;
uint16 blockNum = EaBlockCon[BlockIndex].EaBlockNumber;
uint8 device = EaBlockCon[BlockIndex].EaDeviceIndex;
for (i = 0; i < EA_NUMBER_OF_BLOCKS; i++)
{
if (EaBlockCon[i].EaDeviceIndex == device) // Check that this is the same device
{
if (EaBlockCon[i].EaBlockNumber < blockNum) // Check that blocknum is less than the searched one
{
int blocksize = EaBlockCon[i].EaBlockSize + sizeof(Ea_AdminBlock);
int numOfBlocks = blocksize / EA_VIRTUAL_PAGE_SIZE;
if (blocksize % EA_VIRTUAL_PAGE_SIZE){
numOfBlocks++;
}
totalNumOfBlocks = totalNumOfBlocks + numOfBlocks;
}
}
}
return totalNumOfBlocks * EA_VIRTUAL_PAGE_SIZE;
}
static uint16 calculateBlockLength(uint16 BlockIndex)
{
const Ea_BlockConfigType *EaBlockCon;
EaBlockCon = Ea_Global.EaBlockConfig;
int blocksize = EaBlockCon[BlockIndex].EaBlockSize + sizeof(Ea_AdminBlock);
int numOfBlocks = blocksize / EA_VIRTUAL_PAGE_SIZE;
if (blocksize % EA_VIRTUAL_PAGE_SIZE){
numOfBlocks++;
}
return numOfBlocks * EA_VIRTUAL_PAGE_SIZE;
}
/* Some very simple checksum calculations */
/* Better than nothing :-) */
static uint8 verifyChecksum(Ea_AdminBlock* block)
{
uint8 result;
uint8* array = (uint8*) block;
result = array[0];
result += array[1];
result += array[2];
result = result ^ 0xaaU;
return (result == block->check);
}
static void addChecksum(Ea_AdminBlock* block)
{
uint8 result;
uint8* array = (uint8*) block;
result = array[0];
result += array[1];
result += array[2];
result = result ^ 0xaaU;
block->check = result;
}
|
2301_81045437/classic-platform
|
memory/Ea/src/Ea_gnulinux.c
|
C
|
unknown
| 35,396
|
# Fee
obj-$(USE_FEE) += Fee.o
obj-$(USE_FEE) += Fee_Cfg.o
inc-$(USE_FEE) += $(ROOTDIR)/memory/Fee/inc
vpath-$(USE_FEE) += $(ROOTDIR)/memory/Fee/src
|
2301_81045437/classic-platform
|
memory/Fee/Fee.mod.mk
|
Makefile
|
unknown
| 153
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
#ifndef FEE_H_
#define FEE_H_
/* @req FEE185 */
#define FEE_MODULE_ID 21u
#define FEE_VENDOR_ID 60u
#define FEE_SW_MAJOR_VERSION 1u
#define FEE_SW_MINOR_VERSION 0u
#define FEE_SW_PATCH_VERSION 0u
#define FEE_AR_RELEASE_MAJOR_VERSION 4u
#define FEE_AR_RELEASE_MINOR_VERSION 0u
#define FEE_AR_RELEASE_REVISION_VERSION 3u
#define FEE_AR_MAJOR_VERSION FEE_AR_RELEASE_MAJOR_VERSION
#define FEE_AR_MINOR_VERSION FEE_AR_RELEASE_MINOR_VERSION
#define FEE_AR_PATCH_VERSION FEE_AR_RELEASE_REVISION_VERSION
#include "Std_Types.h"
#include "Fee_Cfg.h"
#if defined(USE_FLS)
#include "Fls.h"
#endif
#if (FEE_DEV_ERROR_DETECT == STD_ON)
// Error codes reported by this module defined by AUTOSAR
/* !req FEE010 *//* Errors missing */
/* @req FEE048 */
#define FEE_E_UNINIT 0x01u
#define FEE_E_INVALID_BLOCK_NO 0x02u
#define FEE_E_INVALID_BLOCK_OFS 0x03u
#define FEE_E_INVALID_DATA_PTR 0x04u
#define FEE_E_INVALID_BLOCK_LEN 0x05u
#define FEE_E_BUSY 0x06u
#define FEE_E_BUSY_INTERNAL 0x07u
// Other error codes reported by this module
#define FEE_PARAM_OUT_OF_RANGE 0x40u
#define FEE_UNEXPECTED_STATE 0x41u
#define FEE_FLASH_CORRUPT 0xfau
#define FEE_UNEXPECTED_STATUS 0xfbu
#define FEE_E_WRONG_CONFIG 0xfcu
#define FEE_E_UNEXPECTED_EXECUTION 0xfdu
#define FEE_E_NOT_SUPPORTED 0xfeu
#define FEE_E_NOT_IMPLEMENTED_YET 0xffu
// Service ID in this module
#define FEE_INIT 0x00u
#define FEE_SET_MODE_ID 0x01u
#define FEE_READ_ID 0x02u
#define FEE_WRITE_ID 0x03u
#define FEE_CANCEL_ID 0x04u
#define FEE_GET_STATUS_ID 0x05u
#define FEE_GET_JOB_RESULT_ID 0x06u
#define FEE_INVALIDATE_BLOCK_ID 0x07u
#define FEE_GET_VERSION_INFO_ID 0x08u
#define FEE_ERASE_IMMEDIATE_ID 0x09u
#define FEE_JOB_END_NOTIFICTION_ID 0x10u
#define FEE_JOB_ERROR_NOTIFICTION_ID 0x11u
#define FEE_MAIN_FUNCTION_ID 0x12u
#define FEE_STARTUP_ID 0x40u
#define FEE_GARBAGE_WRITE_HEADER_ID 0x41u
#define FEE_GLOBAL_ID 0xffu
#endif
/* @req FEE065 */
#if ( FEE_VERSION_INFO_API == STD_ON )
/* @req FEE064 */
/* @req FEE082 */
/* !req FEE147 */
#define Fee_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi, FEE) /** @req FEE093 */
#endif /* FEE_VERSION_INFO_API */
void Fee_MainFunction(void); /** @req FEE097 */
void Fee_Init(void); /** @req FEE085 */
void Fee_SetMode(MemIf_ModeType mode); /** @req FEE086 */
Std_ReturnType Fee_Read(uint16 blockNumber, uint16 blockOffset, uint8* dataBufferPtr, uint16 length); /** @req FEE087 */
Std_ReturnType Fee_Write(uint16 blockNumber, uint8* dataBufferPtr); /** @req FEE088 */
void Fee_Cancel(void);
MemIf_StatusType Fee_GetStatus(void); /** @req FEE090 */
MemIf_JobResultType Fee_GetJobResult(void); /** @req FEE091 */
Std_ReturnType Fee_InvalidateBlock(uint16 blockNumber); /** @req FEE092 */
Std_ReturnType Fee_EraseImmediateBlock(uint16 blockNumber);
#endif /*FEE_H_*/
|
2301_81045437/classic-platform
|
memory/Fee/inc/Fee.h
|
C
|
unknown
| 3,838
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
#ifndef FEE_CBK_H_
#define FEE_CBK_H_
/* @req FEE069 */
void Fee_JobEndNotification(void); /** @req FEE095 */
void Fee_JobErrorNotification(void); /** @req FEE096 */
#endif /*FEE_CBK_H_*/
|
2301_81045437/classic-platform
|
memory/Fee/inc/Fee_Cbk.h
|
C
|
unknown
| 1,018
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
#ifndef FEE_CONFIG_TYPES_H_
#define FEE_CONFIG_TYPES_H_
#include "Std_Types.h"
//#include "Fee_Types.h"
/*
* Callback function prototypes
*/
typedef void (*Fee_JobEndCallbackFunctionType)(void); /** @req FEE098 */
typedef void (*Fee_JobErrorCallbackFunctionType)(void); /** @req FEE099 */
/*
* Containers and configuration parameters
*/
typedef struct {
Fee_JobEndCallbackFunctionType NvmJobEndCallbackNotificationCallback;
Fee_JobErrorCallbackFunctionType NvmJobErrorCallbackNotificationCallback;
// The rest of the parameters is realized in Fee_Cfg.h
} Fee_GeneralType;
typedef struct {
uint8 DeviceIndex;
uint16 BlockNumber;
uint16 BlockSize;
boolean ImmediateData;
uint32 NumberOfWriteCycles;
} Fee_BlockConfigType;
typedef struct {
// Containers
Fee_GeneralType General; // 1
const Fee_BlockConfigType *BlockConfig; // 1..*
} Fee_ConfigType;
/*
* Make the Fee_Config visible for others.
*/
extern const Fee_ConfigType Fee_Config;
#endif /*FEE_CONFIG_TYPES_H_*/
|
2301_81045437/classic-platform
|
memory/Fee/inc/Fee_ConfigTypes.h
|
C
|
unknown
| 1,904
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
/*
* Author: pete+maho
*
* Part of Release:
* 4.0.3
*
* Description:
* Implements the Fee module
*
* Support:
* General Have Support
* -------------------------------------------
* FEE_DEV_ERROR_DETECT Y
* FeeIndex N (always 0)
* FEE_NVM_JOB_END_NOTIFICATION Y (Under ArcCore FEE_USE_JOB_NOTIFICATIONS is used)
* FEE_NVM_JOB_ERROR_NOTIFICATION Y (Under ArcCore FEE_USE_JOB_NOTIFICATIONS is used)
* FEE_POLLING_MODE Y
* FEE_VERSION_INFO_API Y
* FEE_VIRTUAL_PAGE_SIZE Y
*
* Block Have Support
* -------------------------------------------
* FeeBlockNumber Y
* FeeBlockSize Y
* FeeImmediateData N
* FeeNumberOfWriteCycles N
* FeeDeviceIndex N
*
* Published Information Have Support
* -------------------------------------------
* FEE_BLOCK_OVERHEAD N
* FEE_MAXIMUM_BLOCKING_TIME N
* FEE_PAGE_OVERHEAD N
*
* Implementation Notes:
* "Corrupt block"
* The FEE and NVM specifications are very fussy when it comes to "corrupt"
* blocks. The FEE says when a write operation starts that the block should
* be marked as corrupt and when it's done to become "not corrupt" again.
* These requirements seems to relate to flash with very small blocks that store
* block information in the same place in flash. This FEE driver instead writes
* in a new place in flash and keeps track of latest valid block. The driver will
* always use the latest valid block. So when will it return what?
*
*
* MemIf Description
* --------------------------------------------------------------------------------
* MEMIF_BLOCK_INCONSISTENT Virgin start
* MEMIF_BLOCK_INVALID
*
* So that means that the first read must check the
*
*
*/
/* General requirements */
/* @req FEE049 *//* BlockDataAddress used for marking block as corrupted */
/* @req FEE071 *//* Logical blocks must not overlap each other and must not be contained within one another. */
/* @req FEE084 *//* Imported types */
/* !req FEE105 *//* Mandatory interface, Fls_Cancel and Fls_Compare not used */
/* @req FEE167 *//* VARIANT_PRE_COMPILE */
/* ----------------------------[includes]------------------------------------*/
#include "Fee.h"
#include "Fee_Cbk.h"
#include "Fee_Memory_Cfg.h"
#include "Fls.h"
#if defined(USE_DEM)
/* @req FEE060 *//* Although not needed since Fee has no production errors */
#include "Dem.h"
#endif
#include <string.h>
#include "MemMap.h"
#include "Cpu.h"
#include "SchM_Fee.h"
/* The FLS_ERASED_VALIUE is not published by some MCALs,
* this is a way around this.
*/
#if !defined(FLS_ERASED_VALUE)
#define FLS_ERASED_VALUE 0xFF
#endif
/* ----------------------------[private define]------------------------------*/
/*lint -emacro(904,DET_VALIDATE,DET_VALIDATE_RV) *//*904 PC-Lint exception to MISRA 14.7 (validate DET macros).*/
//#define DEBUG_FEE 1
#if defined(DEBUG_FEE)
#define DEBUG_PREFIX "## "
#define DEBUG_PRINTF(format,...) printf( DEBUG_PREFIX format,## __VA_ARGS__ );
#define FLS_READ(_fls_addr,_target_addr,_length) \
({\
Std_ReturnType _rv; \
/*printf( DEBUG_PREFIX "%s: Fls_Read(): 0x%x, %d\n",__FUNCTION__,_fls_addr,_length); */ \
_rv = Fls_Read(_fls_addr,_target_addr,_length); \
_rv; \
})
#define FLS_WRITE(_fls_addr,_source_addr,_length) \
({\
Std_ReturnType _rv; \
/* printf( DEBUG_PREFIX "%s: Fls_Write(): 0x%x 0x%x, %d\n",__FUNCTION__,_fls_addr,_source_addr,_length); */ \
_rv = Fls_Write(_fls_addr,_source_addr,_length); \
_rv; \
})
#else
#define DEBUG_PRINTF(format,...)
#define FLS_READ(_fls_addr,_target_addr,_length) Fls_Read(_fls_addr,_target_addr,_length)
#define FLS_WRITE(_fls_addr,_target_addr,_length) Fls_Write(_fls_addr,_target_addr,_length)
#endif
#define INVALIDATED_BLOCK 0xfffffffdUL
#define BLOCK_CORRUPT 0xffffffffUL
#define NUM_OF_BANKS 2u
#define FORCED_GARBAGE_COLLECT_MARGIN 0u
#define BANK_COUNTER_INVALID 0x0
#define BANK_COUNTER_EMPTY 0xFF
#define BANK_CTRL_SIZE PAGE_ALIGN(sizeof(FlsBankControlDataType))
#define BLOCK_CTRL_DATA_PAGE_SIZE PAGE_ALIGN(sizeof(FlsBlockCtrlDataType))
#define ADMIN_SIZE PAGE_ALIGN(sizeof(FlsBlockControlType))
#define BLOCK_CTRL_ID_PAGE_SIZE PAGE_ALIGN(sizeof(FlsBlockCtrlIdType))
#define RWBUFFER_SIZE sizeof(ReadWriteBufferType)
#define MAX_NOF_FAILED_WRITE_ATTEMPTS 5
#define MAX_NOF_FAILED_GC_ATTEMPTS 5
#define MAX_NOF_FAILED_STARTUP_ATTEMPTS 2
/* ----------------------------[private macro]-------------------------------*/
#define NEXT_BANK_IDX(var) (((var) >= (NUM_OF_BANKS -1))? 0 : ((var) + 1))
#define NEXT_BANK_COUNTERVAL(var) (((var) == 0xFE)? 1 : ((var) + 1))
#define IS_ADDRESS_WITHIN_BANK(addr, bank) ((addr >= BankProp[bank].Start) && (addr < BankProp[bank].End))
/* @req FEE011 */
#if ( FEE_DEV_ERROR_DETECT == STD_ON )
/* @req FEE045 */
/* @req FEE062 */
/* @req FEE104 */
#include "Det.h"
#define DET_VALIDATE(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(FEE_MODULE_ID, 0, _api, _err); \
return; \
}
#define DET_VALIDATE_RV(_exp,_api,_err,_rv ) \
if( !(_exp) ) { \
(void)Det_ReportError(FEE_MODULE_ID, 0, _api, _err); \
return _rv; \
}
#define DET_VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(FEE_MODULE_ID, 0, _api, _err); \
return; \
}
#define DET_REPORTERROR(_api,_err) (void)Det_ReportError(FEE_MODULE_ID,0,(_api),(_err))
#else
#define DET_VALIDATE(_exp,_api,_err )
#define DET_VALIDATE_RV(_exp,_api,_err,_rv )
#define DET_VALIDATE_NO_RV(_exp,_api,_err )
#define DET_REPORTERROR(_api,_err)
#endif
/*
* Page alignment macros
*/
#define PAGE_ALIGN(var) ((((uint32)(var) + FEE_VIRTUAL_PAGE_SIZE - 1u) / FEE_VIRTUAL_PAGE_SIZE) * FEE_VIRTUAL_PAGE_SIZE)
#define SET_FEE_STATUS( _status ) ModuleStatus = (_status); DEBUG_PRINTF("-- SetStatus=%s (%s)\n",memIfStatusToStr[_status],__FUNCTION__);
#define SET_FEE_JOBRESULT( _status ) JobResult = (_status); DEBUG_PRINTF("-- SetJobResult=%s (%s)\n",memIfJobToStr[_status],__FUNCTION__);
/* ----------------------------[private typedef]-----------------------------*/
typedef struct {
Fls_AddressType Start;
Fls_LengthType End;
} BankPropType;
typedef uint32 BankMagicType;
typedef uint8 FlsBankCounterType;
typedef struct {
BankMagicType Magic;
FlsBankCounterType BankCounter;
FlsBankCounterType InvBankCounter;
} FlsBankControlDataType;
typedef union {
FlsBankControlDataType Data;
uint8 Byte[BANK_CTRL_SIZE];
} FlsBankControlType;
typedef struct {
uint16 BlockDataLength; // == 0 if invalidated
uint16 InvBlockDataLength;
Fls_AddressType BlockDataAddress;
} FlsBlockCtrlDataType;
typedef union {
FlsBlockCtrlDataType Data;
uint8 Byte[BLOCK_CTRL_DATA_PAGE_SIZE];
} FlsBlockCtrlDataPageType;
typedef uint32 BlockMagicType;
typedef struct {
BlockMagicType Magic;
uint16 BlockNo;
uint16 InvBlockNo;
} FlsBlockCtrlIdType;
typedef union {
FlsBlockCtrlIdType Data;
uint8 Byte[BLOCK_CTRL_ID_PAGE_SIZE];
} FlsBlockCtrlIdPageType;
typedef struct {
FlsBlockCtrlDataPageType DataPage;
FlsBlockCtrlIdPageType IdPage;
} FlsBlockControlType;
typedef union {
FlsBlockControlType BlockCtrl;
FlsBankControlType BankCtrl;
uint8 Byte[ADMIN_SIZE];
} ReadWriteBufferType;
/*
* Variables for flash administration
*/
typedef struct {
Fls_AddressType BlockDataAddress;
} AdminFlsBlockType;
/*
* Variables for the current job
*/
typedef enum {
FEE_UNINITIALIZED = 0,
FEE_STARTUP_REQUESTED, // setup startup
FEE_STARTUP_READ_BANK_HEADER, // request bank header read
FEE_STARTUP_READ_BANK_HEADER_WAIT, // wait band header read done
FEE_STARTUP_READ_BLOCK_ADMIN, // request admin block read
FEE_STARTUP_READ_BLOCK_ADMIN_WAIT, // wait admin block read done
FEE_IDLE,
FEE_READ, // request data read
FEE_READ_WAIT, // wait data read done
FEE_WRITE,
FEE_WRITE_ADMIN_DATA, // request admin block write
FEE_WRITE_ADMIN_DATA_WAIT, // wait admin block write
FEE_WRITE_DATA, // request data write
FEE_WRITE_DATA_WAIT, // // wait data write done
FEE_WRITE_ADMIN_ID, // request write of "data write done"
FEE_WRITE_ADMIN_ID_WAIT, // wait write of "data write done" done
FEE_WRITE_CHECK_ADMIN_DATA, // write failure of admin data, read it back to check status
FEE_WRITE_CHECK_ADMIN_DATA_WAIT, // wait for admin data to check status
FEE_ERASE_BANK, // request bank erase
FEE_ERASE_BANK_WAIT, // wait bank erase done
FEE_WRITE_BANK_HEADER, // write bank erase done in bank header
FEE_WRITE_BANK_HEADER_WAIT, // wait write of bank erase done
FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA, // request admin block write
FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA_WAIT, // wait admin block write
FEE_GARBAGE_COLLECT_READ, // read all or rwbuffersize bytes of data from old bank
FEE_GARBAGE_COLLECT_READ_WAIT, // wait for read done
FEE_GARBAGE_COLLECT_WRITE_DATA, // request data write
FEE_GARBAGE_COLLECT_WRITE_DATA_WAIT, // // wait data write done
FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID, // request write of "data write done"
FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID_WAIT, // wait write of "data write done" done
FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA, // write failure of admin data, read it back to check status
FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA_WAIT, // wait for admin data to check status
FEE_CORRUPTED
} CurrentJobStateType;
enum {
NO_JOB = 0,
PENDING_READ_JOB = 1,
PENDING_WRITE_JOB = 2,
PENDING_ERASE_JOB = 4,
PENDING_FORCED_GARBAGE_COLLECT_JOB = 8,
PENDING_GARBAGE_COLLECT_JOB = 16,
}pendingJobEnumType;
typedef uint8 PendingJobType;
typedef struct {
CurrentJobStateType State;
PendingJobType pendingJob; // pending job flags
uint8 FailCounter;
AdminFlsBlockType BlockDescrTbl[FEE_NUM_OF_BLOCKS];
struct {
Fls_AddressType NewBlockAdminAddress; // ptr to next free admin block
Fls_AddressType NewBlockDataAddress; // ptr to next free data storage
uint8 BankIdx;
}Write;
struct {
uint32 TotalFeeSize;
uint16 Offset; // garbageCollect data offset
uint16 BlockIdx; // current garbage collect block index
uint8 BankIdx; // current garbage collect bank index
} GarbageCollect;
struct {
uint8 BankIdx; // current erase bank index
uint8 NextBankCounter;
}Erase;
} AdminFlsType;
static AdminFlsType AdminFls = {
.State = FEE_UNINITIALIZED,
};
typedef union {
struct {
uint8 *DataPtr; // read ram buffer ptr
uint16 BlockIdx; // read block index
uint16 Length; // read block length
uint16 DataOffset; // read data offset
} Read;
struct {
uint8 *DataPtr; // write ram buffer ptr
uint16 BlockIdx; // write block index
uint8 Invalidate; // invalidate flag
}Write;
struct {
Fls_AddressType BlockAdminAddress;
Fls_AddressType BlockDataAddress;
FlsBankCounterType BankStatus[NUM_OF_BANKS];
uint8 BankIdx;
uint8 MinBankIdx;
}Startup;
} CurrentJobType;
/* ----------------------------[private function prototypes]-----------------*/
void StartupRequested(void);
/* ----------------------------[private variables]---------------------------*/
#if defined(DEBUG_FEE)
#define STR_ENTRY(_x) [_x] = #_x
static const char *stateToStr[] = {
STR_ENTRY(FEE_UNINITIALIZED), STR_ENTRY(FEE_STARTUP_REQUESTED),
STR_ENTRY( FEE_STARTUP_READ_BANK_HEADER), STR_ENTRY( FEE_STARTUP_READ_BANK_HEADER_WAIT),
STR_ENTRY( FEE_STARTUP_READ_BLOCK_ADMIN),
STR_ENTRY( FEE_STARTUP_READ_BLOCK_ADMIN_WAIT),
STR_ENTRY( FEE_IDLE),
STR_ENTRY( FEE_READ), STR_ENTRY( FEE_READ_WAIT),
STR_ENTRY( FEE_WRITE), STR_ENTRY( FEE_WRITE_ADMIN_DATA), STR_ENTRY( FEE_WRITE_ADMIN_DATA_WAIT),
STR_ENTRY( FEE_WRITE_DATA),STR_ENTRY( FEE_WRITE_DATA_WAIT),
STR_ENTRY( FEE_WRITE_ADMIN_ID), STR_ENTRY( FEE_WRITE_ADMIN_ID_WAIT),
STR_ENTRY( FEE_WRITE_CHECK_ADMIN_DATA), STR_ENTRY( FEE_WRITE_CHECK_ADMIN_DATA_WAIT),
STR_ENTRY( FEE_ERASE_BANK), STR_ENTRY( FEE_ERASE_BANK_WAIT), STR_ENTRY( FEE_WRITE_BANK_HEADER),
STR_ENTRY( FEE_WRITE_BANK_HEADER_WAIT),
STR_ENTRY( FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA), STR_ENTRY( FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA_WAIT),
STR_ENTRY( FEE_GARBAGE_COLLECT_READ), STR_ENTRY( FEE_GARBAGE_COLLECT_READ_WAIT),
STR_ENTRY( FEE_GARBAGE_COLLECT_WRITE_DATA), STR_ENTRY( FEE_GARBAGE_COLLECT_WRITE_DATA_WAIT),
STR_ENTRY( FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID), STR_ENTRY( FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID_WAIT),
STR_ENTRY( FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA),
STR_ENTRY( FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA_WAIT),
STR_ENTRY(FEE_CORRUPTED)
};
static const char *memIfJobToStr[] = {
STR_ENTRY(MEMIF_JOB_OK), STR_ENTRY(MEMIF_JOB_FAILED),
STR_ENTRY(MEMIF_JOB_PENDING), STR_ENTRY(MEMIF_JOB_CANCELED),
STR_ENTRY(MEMIF_BLOCK_INCONSISTENT), STR_ENTRY(MEMIF_BLOCK_INVALID),
};
static const char *memIfStatusToStr[] = {
STR_ENTRY(MEMIF_UNINIT), STR_ENTRY(MEMIF_IDLE),
STR_ENTRY(MEMIF_BUSY), STR_ENTRY(MEMIF_BUSY_INTERNAL),
};
#endif
static const BankPropType BankProp[NUM_OF_BANKS] = {
{
.Start = FEE_BANK1_OFFSET,
.End = FEE_BANK1_OFFSET + FEE_BANK1_LENGTH
},
{
.Start = FEE_BANK2_OFFSET,
.End = FEE_BANK2_OFFSET + FEE_BANK2_LENGTH
},
};
static const BankMagicType BankMagicMaster = 0x2345babe; // compatibility id
static const BlockMagicType BlockMagicMaster = 0xebbababeUL;
static ReadWriteBufferType RWBuffer; /*lint !e9018 Union usage is required so it is considered as lint exception */
/*
* Variables for quick reporting of status and job result
*/
static MemIf_StatusType ModuleStatus = MEMIF_UNINIT;
static MemIf_JobResultType JobResult = MEMIF_JOB_OK;
static CurrentJobType CurrentJob; /*lint !e9018 Union usage is required so it is considered as lint exception */
/* ----------------------------[private functions]---------------------------*/
/* ----------------------------[public functions]----------------------------*/
static uint16 GetBlockIdxFromBlockNumber(uint16 blockNumber) {
const Fee_BlockConfigType *FeeBlockCon;
uint16 BlockIndex = FEE_NUM_OF_BLOCKS + 1; // An invalid block
FeeBlockCon = Fee_Config.BlockConfig;
for (uint16 i = 0; i < FEE_NUM_OF_BLOCKS; i++)
{
if (FeeBlockCon[i].BlockNumber == blockNumber)
{
BlockIndex = i;
break;
}
}
return BlockIndex;
}
#if (FEE_POLLING_MODE == STD_ON)
#define SetFlsJobBusy() /* Nothing needs to be done here */
static boolean CheckFlsJobFinished(void)
{
MemIf_JobResultType flsJobResult;
flsJobResult = Fls_GetJobResult();
return (flsJobResult != MEMIF_JOB_PENDING);
}
#else
static boolean FlsJobReady = TRUE;
static void SetFlsJobBusy()
{
FlsJobReady = FALSE;
}
static boolean CheckFlsJobFinished(void)
{
return (FlsJobReady);
}
#endif
static uint32 BlankCheck(const uint8 *data, uint8_t val, size_t size) {
uint32 retVal = 0;
for(size_t i = 0; i < size; i++) {
if(data[i] != val) {
retVal = (uint32)i+1;
break;
}
}
return retVal;
}
static void AbortStartup(MemIf_JobResultType result)
{
(void)result; /* Avoid compiler warning - remove it ?*/
AdminFls.FailCounter++;
if(AdminFls.FailCounter >= MAX_NOF_FAILED_STARTUP_ATTEMPTS) {
DET_REPORTERROR(FEE_STARTUP_ID, FEE_FLASH_CORRUPT);
AdminFls.State = FEE_CORRUPTED;
SET_FEE_STATUS(MEMIF_IDLE);
} else {
AdminFls.State = FEE_STARTUP_REQUESTED;
}
}
static void FinishStartup(void) {
AdminFls.FailCounter = 0;
AdminFls.State = FEE_IDLE;
SET_FEE_STATUS(MEMIF_IDLE);/* @req FEE169 */
}
static void FinishJob(MemIf_JobResultType jobResult)
{
/* !req FEE155 *//* Failed garbage collect will affect return from Fee_GetJobResult */
AdminFls.FailCounter = 0;
AdminFls.State = FEE_IDLE;
SET_FEE_STATUS(MEMIF_IDLE);
SET_FEE_JOBRESULT(jobResult);
if(jobResult == MEMIF_JOB_OK) {
/* !req FEE055 *//* Read job OK, write job OK or invalidate job OK */
/* Parts of FEE055 but we do not support erase for
* immediate data.. */
if (Fee_Config.General.NvmJobEndCallbackNotificationCallback != NULL) {
Fee_Config.General.NvmJobEndCallbackNotificationCallback();
}
} else {
/* !req FEE056 *//* Read job failed, write job failed or invalidate job failed*/
/* Part of FEE056 but we do not support erase for
* immediate data.. */
if (Fee_Config.General.NvmJobErrorCallbackNotificationCallback != NULL) {
Fee_Config.General.NvmJobErrorCallbackNotificationCallback();
}
}
}
inline static void IncrementFlsState(CurrentJobStateType *adminFlsCurrentState){
switch (*adminFlsCurrentState) {
case FEE_WRITE_ADMIN_DATA:
*adminFlsCurrentState = FEE_WRITE_ADMIN_DATA_WAIT;
break;
case FEE_WRITE_ADMIN_DATA_WAIT:
*adminFlsCurrentState = FEE_WRITE_DATA;
break;
case FEE_WRITE_DATA:
*adminFlsCurrentState = FEE_WRITE_DATA_WAIT;
break;
case FEE_WRITE_DATA_WAIT:
*adminFlsCurrentState = FEE_WRITE_ADMIN_ID;
break;
case FEE_WRITE_ADMIN_ID:
*adminFlsCurrentState = FEE_WRITE_ADMIN_ID_WAIT;
break;
case FEE_WRITE_ADMIN_ID_WAIT:
*adminFlsCurrentState = FEE_WRITE_CHECK_ADMIN_DATA;
break;
case FEE_WRITE_CHECK_ADMIN_DATA:
*adminFlsCurrentState = FEE_WRITE_CHECK_ADMIN_DATA_WAIT;
break;
case FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA:
*adminFlsCurrentState = FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA_WAIT;
break;
case FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA_WAIT:
*adminFlsCurrentState = FEE_GARBAGE_COLLECT_READ;
break;
case FEE_GARBAGE_COLLECT_READ:
*adminFlsCurrentState = FEE_GARBAGE_COLLECT_READ_WAIT;
break;
case FEE_GARBAGE_COLLECT_READ_WAIT:
*adminFlsCurrentState = FEE_GARBAGE_COLLECT_WRITE_DATA;
break;
case FEE_GARBAGE_COLLECT_WRITE_DATA:
*adminFlsCurrentState = FEE_GARBAGE_COLLECT_WRITE_DATA_WAIT;
break;
case FEE_GARBAGE_COLLECT_WRITE_DATA_WAIT:
*adminFlsCurrentState = FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID;
break;
case FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID:
*adminFlsCurrentState = FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID_WAIT;
break;
case FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID_WAIT:
*adminFlsCurrentState = FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA;
break;
case FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA:
*adminFlsCurrentState = FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA_WAIT;
break;
case FEE_CORRUPTED:
default:
/*do nothing*/
break;
}
}
static void AbortWriteJob(void) {
if(CurrentJob.Write.Invalidate==0) {
// only update DataPtr if not an invalidate job
AdminFls.Write.NewBlockDataAddress += PAGE_ALIGN(Fee_Config.BlockConfig[CurrentJob.Write.BlockIdx].BlockSize);
}
AdminFls.Write.NewBlockAdminAddress -= ADMIN_SIZE;
// increase error counter
AdminFls.FailCounter++;
if(AdminFls.FailCounter > MAX_NOF_FAILED_WRITE_ATTEMPTS) {
FinishJob(MEMIF_JOB_FAILED);
} else {
AdminFls.State = FEE_IDLE; // set idle state to restart write job
}
}
static void AbortGCJob(void) {
AdminFls.Write.NewBlockDataAddress += PAGE_ALIGN(Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockSize);
AdminFls.Write.NewBlockAdminAddress -= ADMIN_SIZE;
// increase error counter
AdminFls.FailCounter++;
if(AdminFls.FailCounter > MAX_NOF_FAILED_GC_ATTEMPTS) {
if(ModuleStatus != MEMIF_IDLE) {
FinishJob(MEMIF_JOB_FAILED);
}
AdminFls.State = FEE_CORRUPTED;
SET_FEE_STATUS(MEMIF_IDLE);
} else {
AdminFls.State = FEE_IDLE; // set idle state to restart job
}
}
/*
* request bank header read
*/
static void StartupReadBankHeader(void) {
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
Std_ReturnType ret = FLS_READ(BankProp[CurrentJob.Startup.BankIdx].End - BANK_CTRL_SIZE, RWBuffer.Byte, BANK_CTRL_SIZE);
if (ret == E_OK) {
AdminFls.State = FEE_STARTUP_READ_BANK_HEADER_WAIT;
} else {
AbortStartup(Fls_GetJobResult());
}
}
SchM_Exit_Fee_EA_0();
}
/*
* Start of bank header 1 read
*/
void StartupRequested(void) {
CurrentJob.Startup.BankIdx = 0;
for (uint16 i = 0; i < FEE_NUM_OF_BLOCKS; i++) {
AdminFls.BlockDescrTbl[i].BlockDataAddress = BLOCK_CORRUPT;
}
AdminFls.State = FEE_STARTUP_READ_BANK_HEADER;
AdminFls.pendingJob = (uint8)NO_JOB;
StartupReadBankHeader();
}
/*
* Check job result of bank header read
*/
static void StartupReadBankHeaderWait(void) {
MemIf_JobResultType readRes;
if (CheckFlsJobFinished() == TRUE) {
Std_ReturnType retVal = E_OK;
readRes = Fls_GetJobResult();
if((MEMIF_JOB_OK == readRes) &&
(RWBuffer.BankCtrl.Data.Magic == BankMagicMaster) &&
(RWBuffer.BankCtrl.Data.BankCounter != BANK_COUNTER_INVALID )&&
(RWBuffer.BankCtrl.Data.InvBankCounter != BANK_COUNTER_INVALID) &&
(RWBuffer.BankCtrl.Data.BankCounter == (0xFFu & (~RWBuffer.BankCtrl.Data.InvBankCounter)))) {
// magic ok, bank index ok and inv bankindex correct. Bank is ok
CurrentJob.Startup.BankStatus[CurrentJob.Startup.BankIdx] = RWBuffer.BankCtrl.Data.BankCounter;
} else if((MEMIF_JOB_OK == readRes) || (MEMIF_BLOCK_INCONSISTENT == readRes)) {
/* Either bank header was not valid or inconsistent */
DEBUG_PRINTF("Bank invalid\n");
CurrentJob.Startup.BankStatus[CurrentJob.Startup.BankIdx] = BANK_COUNTER_INVALID;
} else {
AbortStartup(Fls_GetJobResult());
retVal = E_NOT_OK;
}
if(retVal == E_OK) {
CurrentJob.Startup.BankIdx++;
if(CurrentJob.Startup.BankIdx < NUM_OF_BANKS) {
AdminFls.State = FEE_STARTUP_READ_BANK_HEADER;
StartupReadBankHeader();
} else {
// all read
uint8 minIndex = 0;
FlsBankCounterType counterVal = 0;
uint32 numValid = 0;
for(uint8 i = 0; i < NUM_OF_BANKS; i++) {
if(CurrentJob.Startup.BankStatus[i] != BANK_COUNTER_INVALID) {
FlsBankCounterType bankstat = CurrentJob.Startup.BankStatus[i] - counterVal;
if((numValid == 0) || ((sint8)( bankstat) < 0)) {
minIndex = i;
counterVal = CurrentJob.Startup.BankStatus[i];
}
numValid++;
}
}
if(numValid < NUM_OF_BANKS) {
// all banks aren't valid: set garbage collect job flag which will erase invalid banks.
AdminFls.pendingJob |=(uint8)PENDING_ERASE_JOB;
} else {
// all banks ok, none to erase. Next bank to erase is minIndex
AdminFls.Erase.BankIdx = minIndex;
// next bank counter val is counter val for bank before minIndex
AdminFls.Erase.NextBankCounter = NEXT_BANK_COUNTERVAL(CurrentJob.Startup.BankStatus[(minIndex == 0)? (NUM_OF_BANKS -1) : (minIndex - 1)]);
}
if(numValid == 0) {
DEBUG_PRINTF("No valid banks\n");
// no valid bank:
// set bandIdx to 0 to ensure that bank 0 will be erased first
AdminFls.Erase.NextBankCounter = 1;
AdminFls.Erase.BankIdx = 0;
// also set AdminFls.GarbageCollect.BankIdx to 0: next bank to garbage collect
AdminFls.GarbageCollect.BankIdx = 0;
// configure admin data as bank 0 is valid. It will be valid and empty when state is idle
AdminFls.Write.BankIdx = 0;
AdminFls.Write.NewBlockAdminAddress = BankProp[0].End - (ADMIN_SIZE + BANK_CTRL_SIZE);
AdminFls.Write.NewBlockDataAddress = BankProp[0].Start;
// finish startup
FinishStartup();
// force state to erase to ensure that erase will be performed before any read/write jobs
AdminFls.State = FEE_ERASE_BANK;
} else {
// minimum one bank is valid, read admin data
CurrentJob.Startup.BankIdx = minIndex;
CurrentJob.Startup.MinBankIdx = minIndex;
CurrentJob.Startup.BlockAdminAddress = BankProp[CurrentJob.Startup.BankIdx].End - (ADMIN_SIZE + BANK_CTRL_SIZE);
CurrentJob.Startup.BlockDataAddress = BankProp[CurrentJob.Startup.BankIdx].Start;
AdminFls.State = FEE_STARTUP_READ_BLOCK_ADMIN;
// set garbage collect bank index to minindex: next bank to garbage collect
AdminFls.GarbageCollect.BankIdx = minIndex;
}
}
}
}
}
/*
* Start of block admin read
*/
static void StartupReadBlockAdmin(void)
{
/* Start reading the banks */
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
memset(RWBuffer.Byte, FLS_ERASED_VALUE, ADMIN_SIZE);
Std_ReturnType ret = FLS_READ(CurrentJob.Startup.BlockAdminAddress, RWBuffer.Byte, ADMIN_SIZE);
if (ret == E_OK) {
AdminFls.State = FEE_STARTUP_READ_BLOCK_ADMIN_WAIT;
} else {
AbortStartup(Fls_GetJobResult());
}
}
SchM_Exit_Fee_EA_0();
}
static void HandleHeadAdminBlock(void) {
if(CurrentJob.Startup.BlockAdminAddress != (BankProp[CurrentJob.Startup.BankIdx].End - (ADMIN_SIZE + BANK_CTRL_SIZE))) {
// this bank was not empty, set head of this bank as next write position
AdminFls.Write.BankIdx = CurrentJob.Startup.BankIdx;
AdminFls.Write.NewBlockAdminAddress = CurrentJob.Startup.BlockAdminAddress;
AdminFls.Write.NewBlockDataAddress = CurrentJob.Startup.BlockDataAddress;
if(AdminFls.Write.BankIdx != CurrentJob.Startup.MinBankIdx) {
// more than one bank with data, set garbage collect flag
AdminFls.pendingJob |= (uint8)PENDING_GARBAGE_COLLECT_JOB;
AdminFls.GarbageCollect.BlockIdx = 0;
}
// next bank
uint8 prevBankIdx = CurrentJob.Startup.BankIdx;
CurrentJob.Startup.BankIdx = NEXT_BANK_IDX(CurrentJob.Startup.BankIdx);
if(CurrentJob.Startup.BankIdx == CurrentJob.Startup.MinBankIdx) {
// this was the last bank, startup done
if((AdminFls.Write.NewBlockAdminAddress - AdminFls.Write.NewBlockDataAddress) < AdminFls.GarbageCollect.TotalFeeSize) {
// not room for all data in block, set forced garbage collect flag
AdminFls.pendingJob |= (uint8)PENDING_FORCED_GARBAGE_COLLECT_JOB;
}
// finish startup
FinishStartup();
} else if(CurrentJob.Startup.BankStatus[CurrentJob.Startup.BankIdx] == BANK_COUNTER_INVALID) {
// next bank is invalid, startup done
AdminFls.Erase.NextBankCounter = NEXT_BANK_COUNTERVAL(CurrentJob.Startup.BankStatus[prevBankIdx]);
AdminFls.Erase.BankIdx = CurrentJob.Startup.BankIdx;
FinishStartup();
} else {
// read next bank
CurrentJob.Startup.BlockAdminAddress = BankProp[CurrentJob.Startup.BankIdx].End - (ADMIN_SIZE + BANK_CTRL_SIZE);
CurrentJob.Startup.BlockDataAddress = BankProp[CurrentJob.Startup.BankIdx].Start;
AdminFls.State = FEE_STARTUP_READ_BLOCK_ADMIN;
StartupReadBlockAdmin();
}
} else {
// empty bank
if(CurrentJob.Startup.BankIdx == CurrentJob.Startup.MinBankIdx) {
// lowest id with empty bank: all banks are empty
// set head of this bank as next write position
AdminFls.Write.BankIdx = CurrentJob.Startup.BankIdx;
AdminFls.Write.NewBlockAdminAddress = CurrentJob.Startup.BlockAdminAddress;
AdminFls.Write.NewBlockDataAddress = CurrentJob.Startup.BlockDataAddress;
}
if((AdminFls.pendingJob & (uint8)PENDING_ERASE_JOB)!=0) {
// pending garbage collect job: all banks aren't valid
// set garbage collect bank idx to next bank to ensure that all remaining banks gets erased
AdminFls.Erase.NextBankCounter = NEXT_BANK_COUNTERVAL(CurrentJob.Startup.BankStatus[CurrentJob.Startup.BankIdx]);
AdminFls.Erase.BankIdx = NEXT_BANK_IDX(CurrentJob.Startup.BankIdx);
} else {
// all banks ok.
}
// startup done
FinishStartup();
}
}
/*
* Check job result of block admin read, if all block processed finish
* otherwise request for a new block admin read
*/
static void StartupReadBlockAdminWait(void)
{
MemIf_JobResultType readResult;
if (CheckFlsJobFinished()==TRUE) {
readResult = Fls_GetJobResult();
if ((MEMIF_JOB_OK == readResult) || (MEMIF_BLOCK_INCONSISTENT == readResult)) {
// we ignore ECC errors and check data for validity
if((RWBuffer.BlockCtrl.DataPage.Data.BlockDataLength == (uint16)~RWBuffer.BlockCtrl.DataPage.Data.InvBlockDataLength) && (
(RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress == INVALIDATED_BLOCK )|| (
(RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress >= CurrentJob.Startup.BlockDataAddress)&&
(RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress < CurrentJob.Startup.BlockAdminAddress) &&
(RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress == PAGE_ALIGN(RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress)) &&
((RWBuffer.BlockCtrl.DataPage.Data.BlockDataLength + RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress) <= CurrentJob.Startup.BlockAdminAddress)))) {
// invalidated address or DataAddress within bank and has valid alignment, InvBlockDataLength valid, BlockDataLength has a reasonable value, we assume that BlockDataLength is valid
uint16 blockIndex = GetBlockIdxFromBlockNumber(RWBuffer.BlockCtrl.IdPage.Data.BlockNo);
if((MEMIF_JOB_OK == readResult) &&
(blockIndex < FEE_NUM_OF_BLOCKS) &&
(RWBuffer.BlockCtrl.IdPage.Data.Magic == BlockMagicMaster) &&
(RWBuffer.BlockCtrl.IdPage.Data.BlockNo == (uint16)~RWBuffer.BlockCtrl.IdPage.Data.InvBlockNo )&&
(Fee_Config.BlockConfig[blockIndex].BlockSize == RWBuffer.BlockCtrl.DataPage.Data.BlockDataLength)) {
// active blockindex, valid magic, valid InvBlockNo, BlockSize is same as in configuration: we assume that data is correct
AdminFls.BlockDescrTbl[blockIndex].BlockDataAddress = RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress;
}
DEBUG_PRINTF("Reading next admin block\n");
if(RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress != INVALIDATED_BLOCK) {
// increase data pointer
CurrentJob.Startup.BlockDataAddress = PAGE_ALIGN(RWBuffer.BlockCtrl.DataPage.Data.BlockDataLength) + RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress;
}
// next admin block
CurrentJob.Startup.BlockAdminAddress -= ADMIN_SIZE;
// check if room for more admin blocks
if(CurrentJob.Startup.BlockAdminAddress >= CurrentJob.Startup.BlockDataAddress) {
// still room for admin blocks, read next admin block
AdminFls.State = FEE_STARTUP_READ_BLOCK_ADMIN;
StartupReadBlockAdmin();
} else {
HandleHeadAdminBlock();
}
} else if((MEMIF_JOB_OK == readResult) &&
(0 == BlankCheck(RWBuffer.Byte, FLS_ERASED_VALUE, ADMIN_SIZE))) {
// admin block empty, assume that this was the head of data
DEBUG_PRINTF("MemIf==MEMIF_JOB_OK and blankcheck OK\n");
HandleHeadAdminBlock();
} else {
DEBUG_PRINTF("Invalid Adminblock\n");
// invalid admin block: ignore
CurrentJob.Startup.BlockAdminAddress -= ADMIN_SIZE;
// check if room for more admin blocks
if(CurrentJob.Startup.BlockAdminAddress >= CurrentJob.Startup.BlockDataAddress) {
// still room for admin blocks, read next admin block
AdminFls.State = FEE_STARTUP_READ_BLOCK_ADMIN;
StartupReadBlockAdmin();
} else {
HandleHeadAdminBlock();
}
}
} else { /* ErrorStatus not E_OK */
AbortStartup(readResult);
}
}
}
/*
* Request data read
*/
static void Reading(void)
{
/* @req FEE023 */
Fls_AddressType addr = AdminFls.BlockDescrTbl[CurrentJob.Read.BlockIdx].BlockDataAddress;
if(addr == INVALIDATED_BLOCK ) {
// data invalidated
/* @req FEE075 */
AdminFls.pendingJob &=(uint8)(~(uint8)PENDING_READ_JOB);
FinishJob(MEMIF_BLOCK_INVALID);
} else if(addr == BLOCK_CORRUPT ) {
// no data
AdminFls.pendingJob &= (uint8)(~(uint8)PENDING_READ_JOB);
FinishJob(MEMIF_BLOCK_INCONSISTENT);
} else {
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
Std_ReturnType ret = FLS_READ(AdminFls.BlockDescrTbl[CurrentJob.Read.BlockIdx].BlockDataAddress + CurrentJob.Read.DataOffset, CurrentJob.Read.DataPtr, CurrentJob.Read.Length);
if (ret == E_OK) {
AdminFls.State = FEE_READ_WAIT;
} else {
AdminFls.BlockDescrTbl[CurrentJob.Read.BlockIdx].BlockDataAddress = BLOCK_CORRUPT;
AdminFls.pendingJob &= ~(uint8)PENDING_READ_JOB;
FinishJob(MEMIF_BLOCK_INCONSISTENT);
}
}
SchM_Exit_Fee_EA_0();
}
}
/*
* Request data read
*/
static void ReadWait(void)
{
if (CheckFlsJobFinished()==TRUE) {
MemIf_JobResultType jobResult = Fls_GetJobResult();
AdminFls.pendingJob &= ~(uint8)PENDING_READ_JOB;
if(jobResult == MEMIF_JOB_OK) {
FinishJob(MEMIF_JOB_OK);
} else {
FinishJob(MEMIF_BLOCK_INCONSISTENT);
}
}
}
static void WriteAdminData(void) {
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
#if defined(DEBUG_FEE)
DEBUG_PRINTF("AdminData: 0x%x\n",RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress );
#endif
Std_ReturnType ret = FLS_WRITE(AdminFls.Write.NewBlockAdminAddress, RWBuffer.BlockCtrl.DataPage.Byte, BLOCK_CTRL_DATA_PAGE_SIZE);
if (ret == E_OK) {
IncrementFlsState(&AdminFls.State);
} else {
AbortWriteJob();
}
}
SchM_Exit_Fee_EA_0();
}
/*
* Check if bank switch needed:
* - Yes, start mark current bank as old
* - No, start of header write
*/
static void WriteStartJob(void)
{
// init the rw buffer
if(CurrentJob.Write.Invalidate!=0) {
RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress = INVALIDATED_BLOCK;
} else {
RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress = AdminFls.Write.NewBlockDataAddress;
}
RWBuffer.BlockCtrl.DataPage.Data.BlockDataLength = Fee_Config.BlockConfig[CurrentJob.Write.BlockIdx].BlockSize;
RWBuffer.BlockCtrl.DataPage.Data.InvBlockDataLength = ~RWBuffer.BlockCtrl.DataPage.Data.BlockDataLength;
// write the data part of the admin block
AdminFls.State = FEE_WRITE_ADMIN_DATA;
WriteAdminData();
}
static void WriteData(void) {
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
Std_ReturnType ret = FLS_WRITE(AdminFls.Write.NewBlockDataAddress, CurrentJob.Write.DataPtr, PAGE_ALIGN(Fee_Config.BlockConfig[CurrentJob.Write.BlockIdx].BlockSize));
if (ret == E_OK) {
AdminFls.State = FEE_WRITE_DATA_WAIT;
} else {
AbortWriteJob();
}
}
SchM_Exit_Fee_EA_0();
}
static void WriteAdminId(void) {
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
Std_ReturnType ret = FLS_WRITE(AdminFls.Write.NewBlockAdminAddress + BLOCK_CTRL_DATA_PAGE_SIZE, RWBuffer.BlockCtrl.IdPage.Byte, BLOCK_CTRL_ID_PAGE_SIZE);
if (ret == E_OK) {
IncrementFlsState(&AdminFls.State);
} else {
AbortWriteJob();
}
}
SchM_Exit_Fee_EA_0();
}
static void WriteDataWait(void) {
MemIf_JobResultType readResult;
if (CheckFlsJobFinished()==TRUE) {
readResult = Fls_GetJobResult();
if (MEMIF_JOB_OK == readResult) {
// data written, write remaining part of admin block
RWBuffer.BlockCtrl.IdPage.Data.BlockNo = Fee_Config.BlockConfig[CurrentJob.Write.BlockIdx].BlockNumber;
RWBuffer.BlockCtrl.IdPage.Data.InvBlockNo = ~Fee_Config.BlockConfig[CurrentJob.Write.BlockIdx].BlockNumber;
RWBuffer.BlockCtrl.IdPage.Data.Magic = BlockMagicMaster;
AdminFls.State = FEE_WRITE_ADMIN_ID;
WriteAdminId();
} else {
AbortWriteJob();
}
}
}
static void WriteCheckAdminData(void) {
// read admin data
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
Std_ReturnType ret = FLS_READ(AdminFls.Write.NewBlockAdminAddress, RWBuffer.Byte, ADMIN_SIZE);
if (ret == E_OK) {
IncrementFlsState(&AdminFls.State);
} else {
AbortWriteJob();
}
}
SchM_Exit_Fee_EA_0();
}
static void WriteAdminDataWait(void) {
MemIf_JobResultType writeResult;
if (CheckFlsJobFinished()==TRUE) {
writeResult = Fls_GetJobResult();
if (MEMIF_JOB_OK == writeResult) {
// admin data written, write data
if(CurrentJob.Write.Invalidate!=0) {
// invalidate data, no data to be written, write admin block id instead
// call WriteDataWait since it will setup the write of remaining part of admin block
AdminFls.State = FEE_WRITE_DATA_WAIT;
WriteDataWait();
} else {
AdminFls.State = FEE_WRITE_DATA;
WriteData();
}
} else {
// failed to write, check is anything was written
memset(RWBuffer.Byte, ~FLS_ERASED_VALUE, ADMIN_SIZE);
AdminFls.State = FEE_WRITE_CHECK_ADMIN_DATA;
WriteCheckAdminData();
}
}
}
static void WriteAdminIdWait(void) {
MemIf_JobResultType writeResult;
if (CheckFlsJobFinished()==TRUE) {
writeResult = Fls_GetJobResult();
// all data written. Update admin data
if (MEMIF_JOB_OK == writeResult) {
if(CurrentJob.Write.Invalidate!=0) {
AdminFls.BlockDescrTbl[CurrentJob.Write.BlockIdx].BlockDataAddress = INVALIDATED_BLOCK;
} else {
AdminFls.BlockDescrTbl[CurrentJob.Write.BlockIdx].BlockDataAddress = AdminFls.Write.NewBlockDataAddress;
}
AdminFls.pendingJob &= ~(uint8)PENDING_WRITE_JOB;
FinishJob(MEMIF_JOB_OK);
} else {
// failed to write, set mode to idle to restart
AdminFls.State = FEE_IDLE;
// increase error counter
AdminFls.FailCounter++;
}
if(CurrentJob.Write.Invalidate==0) {
// update data head ptr if not an invalidate operation
AdminFls.Write.NewBlockDataAddress += PAGE_ALIGN(Fee_Config.BlockConfig[CurrentJob.Write.BlockIdx].BlockSize);
}
AdminFls.Write.NewBlockAdminAddress -= ADMIN_SIZE;
}
}
static void WriteCheckAdminDataWait(void) {
MemIf_JobResultType readResult;
if (CheckFlsJobFinished()==TRUE) {
readResult = Fls_GetJobResult();
if((MEMIF_JOB_OK == readResult) && (0 == BlankCheck(RWBuffer.Byte, FLS_ERASED_VALUE, ADMIN_SIZE))) {
// admin block empty, do not increase data pointers
// set state to idle to retry to write
AdminFls.State = FEE_IDLE;
} else {
// either was data not empty or read result not ok: assume that something was written. Increase datapointers
AbortWriteJob();
}
}
}
static void EraseBank(void) {
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
Std_ReturnType ret = Fls_Erase(BankProp[AdminFls.Erase.BankIdx].Start, BankProp[AdminFls.Erase.BankIdx].End - BankProp[AdminFls.Erase.BankIdx].Start);
if (ret == E_OK) {
AdminFls.State =FEE_ERASE_BANK_WAIT;
} else {
// failed to write, set mode to idle to restart
AdminFls.State = FEE_IDLE;
// increase error counter
AdminFls.FailCounter++;
}
}
SchM_Exit_Fee_EA_0();
}
static void WriteBankHeader() {
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
Std_ReturnType ret = FLS_WRITE(BankProp[AdminFls.Erase.BankIdx].End - BANK_CTRL_SIZE, RWBuffer.BankCtrl.Byte, BANK_CTRL_SIZE);
if (ret == E_OK) {
AdminFls.State =FEE_WRITE_BANK_HEADER_WAIT;
} else {
// failed to write, set mode to idle to restart
AdminFls.State = FEE_IDLE;
// increase error counter
AdminFls.FailCounter++;
}
}
SchM_Exit_Fee_EA_0();
}
static void EraseBankWait(void) {
MemIf_JobResultType readResult;
if (CheckFlsJobFinished()==TRUE) {
readResult = Fls_GetJobResult();
if (MEMIF_JOB_OK == readResult) {
// erase done, request header write
RWBuffer.BankCtrl.Data.BankCounter = AdminFls.Erase.NextBankCounter;
RWBuffer.BankCtrl.Data.InvBankCounter = ~RWBuffer.BankCtrl.Data.BankCounter;
RWBuffer.BankCtrl.Data.Magic = BankMagicMaster;
AdminFls.State = FEE_WRITE_BANK_HEADER;
WriteBankHeader();
} else {
// failed to erase, set mode to idle to restart
AdminFls.State = FEE_IDLE;
// increase error counter
AdminFls.FailCounter++;
}
}
}
static void WriteBankHeaderWait() {
MemIf_JobResultType readResult;
if (CheckFlsJobFinished()==TRUE) {
readResult = Fls_GetJobResult();
if (MEMIF_JOB_OK == readResult) {
// bank header written, update admin block status
AdminFls.Erase.NextBankCounter = NEXT_BANK_COUNTERVAL(AdminFls.Erase.NextBankCounter);
AdminFls.Erase.BankIdx = NEXT_BANK_IDX(AdminFls.Erase.BankIdx);
if(AdminFls.GarbageCollect.BankIdx == AdminFls.Erase.BankIdx) {
// next bank is next garbage collect bank: all erase jobs done
AdminFls.pendingJob &= ~(uint8)PENDING_ERASE_JOB;
}
AdminFls.State = FEE_IDLE;
} else {
// increase error counter
AdminFls.FailCounter++;
if(AdminFls.FailCounter > MAX_NOF_FAILED_GC_ATTEMPTS) {
AdminFls.State = FEE_CORRUPTED;
if(ModuleStatus != MEMIF_IDLE) {
FinishJob(MEMIF_JOB_FAILED);
}
} else {
// failed to write, set mode to idle to restart
AdminFls.State = FEE_ERASE_BANK;
}
}
}
}
static void GarbageCollectStartJob(void)
{
// init the rw buffer
if(AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress == INVALIDATED_BLOCK) {
RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress = INVALIDATED_BLOCK;
} else {
RWBuffer.BlockCtrl.DataPage.Data.BlockDataAddress = AdminFls.Write.NewBlockDataAddress;
}
RWBuffer.BlockCtrl.DataPage.Data.BlockDataLength = Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockSize;
RWBuffer.BlockCtrl.DataPage.Data.InvBlockDataLength = ~RWBuffer.BlockCtrl.DataPage.Data.BlockDataLength;
// write the data part of the admin block
AdminFls.State = FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA;
WriteAdminData();
}
static void GarbageCollectRead(void)
{
uint16 size = Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockSize - AdminFls.GarbageCollect.Offset;
size = (size > RWBUFFER_SIZE)? RWBUFFER_SIZE : size;
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
Std_ReturnType ret = FLS_READ(AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress + AdminFls.GarbageCollect.Offset, RWBuffer.Byte, size);
if (ret == E_OK) {
IncrementFlsState(&AdminFls.State);
} else {
// failed to read data, set data to corrupt
AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress = BLOCK_CORRUPT;
AdminFls.GarbageCollect.BlockIdx++;
AbortGCJob();
}
}
SchM_Exit_Fee_EA_0();
}
static void GarbageCollectWriteCheckAdminData(void) {
// read admin data
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
SetFlsJobBusy();
Std_ReturnType ret = FLS_READ(AdminFls.Write.NewBlockAdminAddress, RWBuffer.Byte, ADMIN_SIZE);
if (ret == E_OK) {
IncrementFlsState(&AdminFls.State);
} else {
AbortGCJob();
}
}
SchM_Exit_Fee_EA_0();
}
static void GarbageCollectWriteAdminDataWait(void) {
MemIf_JobResultType writeResult;
if (CheckFlsJobFinished()==TRUE) {
writeResult = Fls_GetJobResult();
if (MEMIF_JOB_OK == writeResult) {
if(AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress == INVALIDATED_BLOCK) {
// no data to write, write remaining part of admin block
RWBuffer.BlockCtrl.IdPage.Data.BlockNo = Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockNumber;
RWBuffer.BlockCtrl.IdPage.Data.InvBlockNo = ~Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockNumber;
RWBuffer.BlockCtrl.IdPage.Data.Magic = BlockMagicMaster;
AdminFls.State = FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID;
WriteAdminId();
} else {
// admin data written, read data
AdminFls.GarbageCollect.Offset = 0;
AdminFls.State = FEE_GARBAGE_COLLECT_READ;
GarbageCollectRead();
}
} else {
// failed to write, check is anything was written
memset(RWBuffer.Byte, ~FLS_ERASED_VALUE, ADMIN_SIZE);
AdminFls.State = FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA;
GarbageCollectWriteCheckAdminData();
}
}
}
static void GarbageCollectWriteData(void) {
SchM_Enter_Fee_EA_0();
if(Fls_GetStatus() == MEMIF_IDLE) {
uint16 size = Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockSize - AdminFls.GarbageCollect.Offset;
size = (size > RWBUFFER_SIZE)? RWBUFFER_SIZE : (uint16)PAGE_ALIGN(size);
SetFlsJobBusy();
Std_ReturnType ret = FLS_WRITE(AdminFls.Write.NewBlockDataAddress + AdminFls.GarbageCollect.Offset, RWBuffer.Byte, size);
if (ret == E_OK) {
AdminFls.GarbageCollect.Offset += size;
IncrementFlsState(&AdminFls.State);
} else {
AbortGCJob();
}
}
SchM_Exit_Fee_EA_0();
}
static void GarbageCollectReadWait(void)
{
if (CheckFlsJobFinished()==TRUE) {
MemIf_JobResultType jobResult = Fls_GetJobResult();
if(jobResult == MEMIF_JOB_OK) {
// read done, write data
AdminFls.State = FEE_GARBAGE_COLLECT_WRITE_DATA;
GarbageCollectWriteData();
} else {
// failed to read data, set data to invalid
AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress = BLOCK_CORRUPT;
AdminFls.GarbageCollect.BlockIdx++;
AbortGCJob();
}
}
}
static void GarbageCollectWriteDataWait(void) {
MemIf_JobResultType readResult;
if (CheckFlsJobFinished()==TRUE) {
readResult = Fls_GetJobResult();
if (MEMIF_JOB_OK == readResult) {
// check if more data to write
if(AdminFls.GarbageCollect.Offset >= Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockSize) {
// data written, write remaining part of admin block
RWBuffer.BlockCtrl.IdPage.Data.BlockNo = Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockNumber;
RWBuffer.BlockCtrl.IdPage.Data.InvBlockNo = ~Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockNumber;
RWBuffer.BlockCtrl.IdPage.Data.Magic = BlockMagicMaster;
AdminFls.State = FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID;
WriteAdminId();
} else {
// continue to read
AdminFls.State = FEE_GARBAGE_COLLECT_READ;
GarbageCollectRead();
}
} else {
AbortGCJob();
}
}
}
static void GarbageCollectWriteAdminIdWait(void) {
MemIf_JobResultType readResult;
if (CheckFlsJobFinished()==TRUE) {
readResult = Fls_GetJobResult();
if (MEMIF_JOB_OK == readResult) {
// garbage collect of block is done
if(AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress != INVALIDATED_BLOCK) {
AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress = AdminFls.Write.NewBlockDataAddress;
// all data written. Update admin data
AdminFls.Write.NewBlockDataAddress += PAGE_ALIGN(Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockSize);
}
AdminFls.Write.NewBlockAdminAddress -= ADMIN_SIZE;
AdminFls.GarbageCollect.BlockIdx++;
// change state to idle to continue with next block
AdminFls.State = FEE_IDLE;
} else {
AbortGCJob();
}
}
}
static void GarbageCollectWriteCheckAdminDataWait(void) {
MemIf_JobResultType readResult;
if (CheckFlsJobFinished()==TRUE) {
readResult = Fls_GetJobResult();
if((MEMIF_JOB_OK == readResult) &&( 0 == BlankCheck(RWBuffer.Byte, FLS_ERASED_VALUE, ADMIN_SIZE))) {
// admin block empty, do not increase data pointers
AdminFls.FailCounter++;
// set state to idle to retry to garbage collect
AdminFls.State = FEE_IDLE;
} else {
// either was data not empty or read result not ok: assume that something was written. Increase datapointers
AbortGCJob();
}
}
}
static void Idle(void) {
boolean whilebreakflag = FALSE;
if((AdminFls.pendingJob & (uint8)PENDING_READ_JOB)!=0) {
// start read job
AdminFls.State = FEE_READ;
Reading();
} else if(((AdminFls.pendingJob & (uint8) PENDING_WRITE_JOB)!=0) && (
((AdminFls.pendingJob & (uint8)PENDING_FORCED_GARBAGE_COLLECT_JOB) == 0 )||
(CurrentJob.Write.Invalidate == 1 )||
(IS_ADDRESS_WITHIN_BANK(AdminFls.BlockDescrTbl[CurrentJob.Write.BlockIdx].BlockDataAddress, AdminFls.GarbageCollect.BankIdx)) )
) {
// pending write job while not in forced garbage collect or data to write is not garbage collected
uint8 nextBank = NEXT_BANK_IDX(AdminFls.Write.BankIdx);
/*lint -e{713} as per the logic sin32 value of address difference can not be more than is range */
sint32 remainingBytesInBank = (AdminFls.Write.NewBlockAdminAddress - AdminFls.Write.NewBlockDataAddress); // This value might be negative: use signed type
sint32 bytesToWrite = (CurrentJob.Write.Invalidate == 1)? 0 : (sint32)Fee_Config.BlockConfig[CurrentJob.Write.BlockIdx].BlockSize;
sint32 identifybytes = ((sint32)AdminFls.GarbageCollect.TotalFeeSize + bytesToWrite + (sint32) ADMIN_SIZE + (sint32) FORCED_GARBAGE_COLLECT_MARGIN);
if(((AdminFls.pendingJob & (uint8)PENDING_FORCED_GARBAGE_COLLECT_JOB) == 0) &&
(remainingBytesInBank < identifybytes) &&
(nextBank == AdminFls.GarbageCollect.BankIdx)
) {
// no room for all data when this data written, and all banks written: set forced garbage collect
AdminFls.pendingJob |= (uint8)PENDING_FORCED_GARBAGE_COLLECT_JOB;
// stay in idle and perform a new evaluation in next main loop
} else if(remainingBytesInBank < bytesToWrite) {
// no room for this block, is it possible to switch bank?
if(nextBank == AdminFls.GarbageCollect.BankIdx) {
// next bank is garbage collect bank, not possible to switch bank
// throw stored data and hope that garbage collect will finish before power is switched off and new data written. set fault code?
AdminFls.BlockDescrTbl[CurrentJob.Write.BlockIdx].BlockDataAddress = BLOCK_CORRUPT; // next call to idle will continue with garbage collect of the other blocks, stay in idle
} else if (nextBank == AdminFls.Erase.BankIdx) {
// next bank isn't erased and not garbage collect bank: erase job pending, erase bank to get room for new data
AdminFls.State = FEE_ERASE_BANK;
} else {
// next bank is erased: switch bank
AdminFls.Write.BankIdx = nextBank;
AdminFls.Write.NewBlockAdminAddress = BankProp[AdminFls.Write.BankIdx].End - (ADMIN_SIZE + BANK_CTRL_SIZE);
AdminFls.Write.NewBlockDataAddress = BankProp[AdminFls.Write.BankIdx].Start;
AdminFls.pendingJob |= (uint8)PENDING_GARBAGE_COLLECT_JOB; // set pending garbage collect flag since more than one bank with data
AdminFls.State = FEE_WRITE;
WriteStartJob();
}
} else {
AdminFls.State = FEE_WRITE;
WriteStartJob();
}
} else if((AdminFls.pendingJob & (uint8)PENDING_ERASE_JOB)!=0) {
AdminFls.State = FEE_ERASE_BANK;
} else if((AdminFls.pendingJob & (uint8)PENDING_FORCED_GARBAGE_COLLECT_JOB)!=0) {
// search for next block to garbage collect
while((AdminFls.GarbageCollect.BlockIdx < FEE_NUM_OF_BLOCKS) && (
(AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress == BLOCK_CORRUPT) ||
((AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress != INVALIDATED_BLOCK )&&
(!IS_ADDRESS_WITHIN_BANK(AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress ,AdminFls.GarbageCollect.BankIdx)))
)
) {
// block isn't in the bank that currently is garbage collected: try next block
AdminFls.GarbageCollect.BlockIdx++;
}
if(AdminFls.GarbageCollect.BlockIdx >= FEE_NUM_OF_BLOCKS) {
// garbage collect done
AdminFls.GarbageCollect.BankIdx = NEXT_BANK_IDX(AdminFls.GarbageCollect.BankIdx);
AdminFls.GarbageCollect.BlockIdx = 0;
if(AdminFls.GarbageCollect.BankIdx == AdminFls.Write.BankIdx) {
// no more data to garbage collect, clear flags
AdminFls.pendingJob &= ~(uint8)((uint8)PENDING_FORCED_GARBAGE_COLLECT_JOB |(uint8) PENDING_GARBAGE_COLLECT_JOB);
} else {
// one bank free, not in forced garbage collect mode anymore
AdminFls.pendingJob &= ~(uint8)PENDING_FORCED_GARBAGE_COLLECT_JOB;
}
// set pending erase job to erase block freed by garbage collect
AdminFls.pendingJob |= (uint8)PENDING_ERASE_JOB;
} else {
/*lint -e{713} as per the logic sin32 value of address difference can not be more than is range */
sint32 remainingBytes = AdminFls.Write.NewBlockAdminAddress - AdminFls.Write.NewBlockDataAddress;
sint32 bytesToWrite = (AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress == INVALIDATED_BLOCK)? 0 : (sint32)(Fee_Config.BlockConfig[AdminFls.GarbageCollect.BlockIdx].BlockSize);
if (bytesToWrite > remainingBytes) {
// no room in bank. Throw data, set fault code?
AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress = BLOCK_CORRUPT;
AdminFls.GarbageCollect.BlockIdx++;
} else {
GarbageCollectStartJob();
}
}
} else if((AdminFls.pendingJob & (uint8)PENDING_GARBAGE_COLLECT_JOB)!=0) {
// search for next block to garbage collect
while((AdminFls.GarbageCollect.BlockIdx < FEE_NUM_OF_BLOCKS)&&(whilebreakflag==FALSE)) {
if(AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress == INVALIDATED_BLOCK) {
// block invalidated, invalidate again to garbage collect the invalidation
/*lint -e{713} as per the logic sin32 value of address difference can not be more than is range */
sint32 remainingBytes = (AdminFls.Write.NewBlockAdminAddress - AdminFls.Write.NewBlockDataAddress);
sint32 bytesToWrite = 0;
if (bytesToWrite > remainingBytes) {
// no room in bank. Throw data, set fault code?
AdminFls.GarbageCollect.BlockIdx++;
} else {
GarbageCollectStartJob();
whilebreakflag = TRUE;
}
} else if(IS_ADDRESS_WITHIN_BANK(AdminFls.BlockDescrTbl[AdminFls.GarbageCollect.BlockIdx].BlockDataAddress ,AdminFls.GarbageCollect.BankIdx)) {
// block not garbage collected
whilebreakflag = TRUE;
} else {
// block isn't in the bank that currently is garbage collected: try next block
AdminFls.GarbageCollect.BlockIdx++;
}
}
if(AdminFls.GarbageCollect.BlockIdx >= FEE_NUM_OF_BLOCKS) {
// garbage collect done
AdminFls.GarbageCollect.BankIdx = NEXT_BANK_IDX(AdminFls.GarbageCollect.BankIdx);
AdminFls.GarbageCollect.BlockIdx = 0;
if(AdminFls.GarbageCollect.BankIdx == AdminFls.Write.BankIdx) {
// no more data to garbage collect, clear flags
AdminFls.pendingJob &= ~(uint8)PENDING_GARBAGE_COLLECT_JOB;
}
// set pending erase job to erase block freed by garbage collect
AdminFls.pendingJob |= (uint8) PENDING_ERASE_JOB;
}
}else{
/* Do nothing */
}
}
/***************************************
* External accessible functions *
***************************************/
/*
* Procedure: Fee_Init
* Reentrant: No
*/
void Fee_Init(void)
{
/* Reporting information */
/* @req FEE120 */
SET_FEE_STATUS(MEMIF_BUSY_INTERNAL);
SET_FEE_JOBRESULT(MEMIF_JOB_OK);
memset(&CurrentJob, 0 , sizeof(CurrentJob));
memset(&AdminFls, 0 , sizeof(AdminFls));
/* State of device */
AdminFls.State = FEE_STARTUP_REQUESTED;
#if (FEE_POLLING_MODE == STD_OFF)
FlsJobReady = TRUE;
#endif
for(uint16 i = 0; i < FEE_NUM_OF_BLOCKS; i++) {
AdminFls.GarbageCollect.TotalFeeSize += PAGE_ALIGN(Fee_Config.BlockConfig[i].BlockSize) + ADMIN_SIZE;
}
}
/*
* Procedure: Fee_SetMode
* Reentrant: No
*/
void Fee_SetMode(MemIf_ModeType mode)
{
/* @req FEE121 */
DET_VALIDATE(ModuleStatus != MEMIF_UNINIT, FEE_SET_MODE_ID, FEE_E_UNINIT);
/* @req FEE170 */
DET_VALIDATE(ModuleStatus != MEMIF_BUSY, FEE_SET_MODE_ID, FEE_E_BUSY);
/* @req FEE171 */
DET_VALIDATE(ModuleStatus != MEMIF_BUSY_INTERNAL, FEE_SET_MODE_ID, FEE_E_BUSY_INTERNAL);
#if ( FLS_SET_MODE_API == STD_ON )
/* @req FEE020 */
Fls_SetMode(mode);
#else
(void)mode; /* Avoid compiler warning */
DET_REPORTERROR(FEE_SET_MODE_ID, FEE_E_NOT_SUPPORTED);
#endif
}
/*
* Procedure: Fee_Read
* Reentrant: No
*/
Std_ReturnType Fee_Read(uint16 blockNumber, uint16 blockOffset, uint8* dataBufferPtr, uint16 length)
{
Std_ReturnType status;
status = E_OK;
uint16 blockIndex;
DEBUG_PRINTF("Fee_Read %d %d\n",blockNumber, blockOffset);
/* @req FEE122 */
DET_VALIDATE_RV(ModuleStatus != MEMIF_UNINIT, FEE_READ_ID, FEE_E_UNINIT, E_NOT_OK);
if(FEE_CORRUPTED == AdminFls.State){
status = E_NOT_OK;
} else {
/* @req FEE133 *//* @req FEE172 *//* @req FEE173 */
if(ModuleStatus != MEMIF_IDLE) {
DET_REPORTERROR(FEE_READ_ID, (ModuleStatus == MEMIF_BUSY_INTERNAL) ? FEE_E_BUSY_INTERNAL : FEE_E_BUSY);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
blockIndex = GetBlockIdxFromBlockNumber(blockNumber);
/* @req FEE134 */
DET_VALIDATE_RV(blockIndex < FEE_NUM_OF_BLOCKS, FEE_READ_ID, FEE_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req FEE136 */
DET_VALIDATE_RV(dataBufferPtr != NULL, FEE_READ_ID, FEE_E_INVALID_DATA_PTR, E_NOT_OK);
/* @req FEE135 */
DET_VALIDATE_RV(blockOffset < Fee_Config.BlockConfig[blockIndex].BlockSize, FEE_READ_ID, FEE_E_INVALID_BLOCK_OFS, E_NOT_OK);
/* @req FEE137 */
DET_VALIDATE_RV((blockOffset + length) <= Fee_Config.BlockConfig[blockIndex].BlockSize, FEE_READ_ID, FEE_E_INVALID_BLOCK_LEN, E_NOT_OK);
/* @req FEE162 *//* Will have returned above */
/** @req FEE022 */
SET_FEE_STATUS(MEMIF_BUSY);
SET_FEE_JOBRESULT(MEMIF_JOB_PENDING);
CurrentJob.Read.BlockIdx = blockIndex;
CurrentJob.Read.DataOffset = blockOffset;
CurrentJob.Read.DataPtr = dataBufferPtr;
CurrentJob.Read.Length = length;
AdminFls.pendingJob |= (uint8)PENDING_READ_JOB;
}
return status;
}
/*
* Procedure: Fee_Write
* Reentrant: No
*/
/* @req FEE088 */
Std_ReturnType Fee_Write(uint16 blockNumber, uint8* dataBufferPtr)
{
/* !req FEE153 */
/* !req FEE154 */
Std_ReturnType status;
status = E_OK;
uint16 blockIndex;
/* @req FEE123 */
DET_VALIDATE_RV(ModuleStatus != MEMIF_UNINIT, FEE_WRITE_ID, FEE_E_UNINIT, E_NOT_OK);
if(FEE_CORRUPTED == AdminFls.State){
status = E_NOT_OK;
} else {
/* @req FEE144 *//* @req FEE174 *//* @req FEE175 */
if(ModuleStatus != MEMIF_IDLE) {
DET_REPORTERROR(FEE_WRITE_ID, (ModuleStatus == MEMIF_BUSY_INTERNAL) ? FEE_E_BUSY_INTERNAL : FEE_E_BUSY);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
blockIndex = GetBlockIdxFromBlockNumber(blockNumber);
/* @req FEE138 */
DET_VALIDATE_RV(blockIndex < FEE_NUM_OF_BLOCKS, FEE_WRITE_ID, FEE_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req FEE139 */
DET_VALIDATE_RV(dataBufferPtr != NULL, FEE_WRITE_ID, FEE_E_INVALID_DATA_PTR, E_NOT_OK);
/* @req FEE163 *//* Will have returned above */
/** @req FEE025 */
SET_FEE_STATUS(MEMIF_BUSY);
SET_FEE_JOBRESULT(MEMIF_JOB_PENDING);
CurrentJob.Write.BlockIdx = blockIndex;
CurrentJob.Write.DataPtr = dataBufferPtr;
CurrentJob.Write.Invalidate = 0;
AdminFls.pendingJob |= (uint8)PENDING_WRITE_JOB;
}
return status;
}
/*
* Procedure: Fee_Cancel
* Reentrant: No
*/
void Fee_Cancel(void)
{
DET_REPORTERROR(FEE_CANCEL_ID, FEE_E_NOT_IMPLEMENTED_YET);
}
/*
* Procedure: Fee_GetStatus
* Reentrant: No
*/
MemIf_StatusType Fee_GetStatus(void)
{
DEBUG_PRINTF("%s: %s\n",__FUNCTION__,memIfStatusToStr[ModuleStatus]);
/* @req FEE034 *//* Module status initialized to MEMIF_UNINIT */
/* @req FEE128 */
/* @req FEE129 */
return ModuleStatus;
}
/*
* Procedure: Fee_GetJobResult
* Reentrant: No
*/
MemIf_JobResultType Fee_GetJobResult(void)
{
/* @req FEE125 */
DET_VALIDATE_RV(ModuleStatus != MEMIF_UNINIT, FEE_GET_JOB_RESULT_ID, FEE_E_UNINIT, MEMIF_JOB_FAILED);
DEBUG_PRINTF("%s: %s\n",__FUNCTION__,memIfJobToStr[JobResult]);
/* @req FEE035 */
/* @req FEE156 */
/* !req FEE157 */
/* @req FEE158 */
/* @req FEE159 */
/* @req FEE160 */
return JobResult;
}
/*
* Procedure: Fee_InvalidateBlock
* Reentrant: No
*/
Std_ReturnType Fee_InvalidateBlock(uint16 blockNumber)
{
/* @req FEE037 *//* Trigger write job where block is invalidated */
uint16 blockIndex;
Std_ReturnType status;
status = E_OK;
/* @req FEE126 */
DET_VALIDATE_RV(ModuleStatus != MEMIF_UNINIT, FEE_INVALIDATE_BLOCK_ID, FEE_E_UNINIT, E_NOT_OK);
if(FEE_CORRUPTED == AdminFls.State){
status = E_NOT_OK;
} else {
/* @req FEE145 *//* @req FEE176 *//* @req FEE177 */
if( !(ModuleStatus == MEMIF_IDLE) ) {
DET_REPORTERROR(FEE_INVALIDATE_BLOCK_ID, (ModuleStatus == MEMIF_BUSY_INTERNAL) ? FEE_E_BUSY_INTERNAL : FEE_E_BUSY);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
blockIndex = GetBlockIdxFromBlockNumber(blockNumber);
/* @req FEE140 */
DET_VALIDATE_RV(blockIndex < FEE_NUM_OF_BLOCKS, FEE_INVALIDATE_BLOCK_ID, FEE_E_INVALID_BLOCK_NO, E_NOT_OK);
/* @req FEE165 *//* Will return above */
SET_FEE_STATUS(MEMIF_BUSY);
SET_FEE_JOBRESULT(MEMIF_JOB_PENDING);
CurrentJob.Write.BlockIdx = blockIndex;
CurrentJob.Write.Invalidate = 1;
AdminFls.pendingJob |= (uint8)PENDING_WRITE_JOB;
}
return status;
}
/*
* Procedure: Fee_EraseImmediateBlock
* Reentrant: No
*/
Std_ReturnType Fee_EraseImmediateBlock(uint16 blockNumber)
{
(void)blockNumber; /* Avoid compiler warning */
DET_REPORTERROR(FEE_ERASE_IMMEDIATE_ID, FEE_E_NOT_IMPLEMENTED_YET);
return E_NOT_OK;
}
/***************************************
* Scheduled functions *
***************************************/
/*
* Procedure: Fee_MainFunction
* Reentrant: No
*/
/* @req FEE097 */
void Fee_MainFunction(void)
{
/* @req FEE057 */
DEBUG_PRINTF("State: %s (Fee_MainFunction())\n",stateToStr[AdminFls.State]);
switch (AdminFls.State) {
case FEE_UNINITIALIZED:
break;
case FEE_IDLE:
Idle();
break;
/*
* Startup states
*/
case FEE_STARTUP_REQUESTED:
StartupRequested();
break;
case FEE_STARTUP_READ_BANK_HEADER:
StartupReadBankHeader();
break;
case FEE_STARTUP_READ_BANK_HEADER_WAIT:
StartupReadBankHeaderWait();
break;
case FEE_STARTUP_READ_BLOCK_ADMIN:
StartupReadBlockAdmin();
break;
case FEE_STARTUP_READ_BLOCK_ADMIN_WAIT:
StartupReadBlockAdminWait();
break;
/*
* Read states
*/
/* @req FEE073 */
case FEE_READ:
Reading();
break;
case FEE_READ_WAIT:
ReadWait();
break;
/*
* Write states
*/
/* @req FEE026 */
case FEE_WRITE:
WriteStartJob();
break;
case FEE_WRITE_ADMIN_DATA:
WriteAdminData();
break;
case FEE_WRITE_ADMIN_DATA_WAIT:
WriteAdminDataWait();
break;
case FEE_WRITE_DATA:
WriteData();
break;
case FEE_WRITE_DATA_WAIT:
WriteDataWait();
break;
case FEE_WRITE_ADMIN_ID:
WriteAdminId();
break;
case FEE_WRITE_ADMIN_ID_WAIT:
WriteAdminIdWait();
break;
case FEE_WRITE_CHECK_ADMIN_DATA:
WriteCheckAdminData();
break;
case FEE_WRITE_CHECK_ADMIN_DATA_WAIT:
WriteCheckAdminDataWait();
break;
/*
* Erase bank states
*/
case FEE_ERASE_BANK:
EraseBank();
break;
case FEE_ERASE_BANK_WAIT:
EraseBankWait();
break;
case FEE_WRITE_BANK_HEADER:
WriteBankHeader();
break;
case FEE_WRITE_BANK_HEADER_WAIT:
WriteBankHeaderWait();
break;
/*
* Garbage collection states
*/
case FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA:
WriteAdminData();
break;
case FEE_GARBAGE_COLLECT_WRITE_ADMIN_DATA_WAIT:
GarbageCollectWriteAdminDataWait();
break;
case FEE_GARBAGE_COLLECT_READ:
GarbageCollectRead();
break;
case FEE_GARBAGE_COLLECT_READ_WAIT:
GarbageCollectReadWait();
break;
case FEE_GARBAGE_COLLECT_WRITE_DATA:
GarbageCollectWriteData();
break;
case FEE_GARBAGE_COLLECT_WRITE_DATA_WAIT:
GarbageCollectWriteDataWait();
break;
case FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID:
WriteAdminId();
break;
case FEE_GARBAGE_COLLECT_WRITE_ADMIN_ID_WAIT:
GarbageCollectWriteAdminIdWait();
break;
case FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA:
GarbageCollectWriteCheckAdminData();
break;
case FEE_GARBAGE_COLLECT_WRITE_CHECK_ADMIN_DATA_WAIT:
GarbageCollectWriteCheckAdminDataWait();
break;
/*
* Corrupted state
*/
case FEE_CORRUPTED:
break;
/*
* Other
*/
default:
break;
}
}
/***************************************
* Call-back notifications functions *
***************************************/
#if (FEE_POLLING_MODE == STD_OFF)
/*
* Procedure: Fee_JobEndNotification
* Reentrant: No
*/
/* @req FEE095 */
void Fee_JobEndNotification(void)
{
/* @req FEE052 *//* Done asynchronously */
/* @req FEE142 *//* If no job is being processed, flag never checked */
FlsJobReady = TRUE;
}
/*
* Procedure: Fee_JobErrorNotification
* Reentrant: No
*/
/* @req FEE096 */
void Fee_JobErrorNotification(void)
{
/* @req FEE054 *//* Done asynchronously */
/* @req FEE143 *//* If no job is being processed, flag never checked */
FlsJobReady = TRUE;
}
#endif
|
2301_81045437/classic-platform
|
memory/Fee/src/Fee.c
|
C
|
unknown
| 75,123
|
#MemIf
obj-$(USE_MEMIF) += MemIf.o
inc-$(USE_MEMIF) += $(ROOTDIR)/memory/MemIf/inc
vpath-$(USE_MEMIF) += $(ROOTDIR)/memory/MemIf/src
|
2301_81045437/classic-platform
|
memory/MemIf/MemIf.mod.mk
|
Makefile
|
unknown
| 137
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
#ifndef MEMIF_H_
#define MEMIF_H_
#define MEMIF_MODULE_ID 22u
#define MEMIF_VENDOR_ID 60u
/* @req MemIf064 */
#define MEMIF_SW_MAJOR_VERSION 1u
#define MEMIF_SW_MINOR_VERSION 0u
#define MEMIF_SW_PATCH_VERSION 0u
#define MEMIF_AR_MAJOR_VERSION 4u
#define MEMIF_AR_MINOR_VERSION 0u
#define MEMIF_AR_PATCH_VERSION 3u
#define MEMIF_AR_RELEASE_MAJOR_VERSION MEMIF_AR_MAJOR_VERSION
#define MEMIF_AR_RELEASE_MINOR_VERSION MEMIF_AR_MINOR_VERSION
#define MEMIF_AR_RELEASE_REVISION_VERSION MEMIF_AR_PATCH_VERSION
/* Service ids */
#define MEMIF_SETMODE_ID 0x01u
#define MEMIF_READ_ID 0x02u
#define MEMIF_WRITE_ID 0x03u
#define MEMIF_CANCEL_ID 0x04u
#define MEMIF_GETSTATUS_ID 0x05u
#define MEMIF_GETJOBRESULT_ID 0x06u
#define MEMIF_INVALIDATEBLOCK_ID 0x07u
#define MEMIF_GETVERSIONINFO_ID 0x08u
#define MEMIF_ERASEIMMEDIATEBLOCK_ID 0x09u
/* Error Ids */
/* @req MemIf030 */
#define MEMIF_E_PARAM_DEVICE 0x01u
#define MEMIF_E_PARAM_POINTER 0x02u
/* @req MemIf037 */
#include "Std_Types.h"
#include "MemIf_Cfg.h"
#if defined(USE_FEE)
#include "Fee.h"
#endif
#if defined(USE_EA)
#include "Ea.h"
#endif
/* @req MemIf061 */
#if (MEMIF_NUMBER_OF_DEVICES > 2)
#error "MemIf: Only 2 devices supported"
#endif
/* @req MemIf057 */
#if (MEMIF_VERSION_INFO_API == STD_ON)
/* @req MemIf045 */
/* !req MemIf063 */
#define MemIf_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi, MEMIF)
#endif /* MEMIF_VERSION_INFO_API */
/* @req MemIf011 */
/* @req MemIf017 */
/* @req MemIf018 */
#if (MEMIF_NUMBER_OF_DEVICES == 0)
#define _MemIf_SetMode(_mode)
#define _MemIf_Read(_deviceIndex,_blockNumber,_blockOffset,_dataBufferPtr,_length)
#define _MemIf_Write(_deviceIndex,_blockNumber,_dataBufferPtr)
#define _MemIf_Cancel(_deviceIndex)
#define _MemIf_GetStatus(_deviceIndex)
#define _MemIf_GetJobResult(_deviceIndex)
#define _MemIf_InvalidateBlock(_deviceIndex,_blockNumber)
#define _MemIf_EraseImmediateBlock(_deviceIndex,_blockNumber)
#elif (MEMIF_NUMBER_OF_DEVICES == 1)
/* @req MemIf019 */
#if (MEMIF_DEVICE_TO_USE == FLS_DRIVER_INDEX)
#define _MemIf_SetMode(_mode) Fee_SetMode(_mode)
#define _MemIf_Read(_deviceIndex,_blockNumber,_blockOffset,_dataBufferPtr,_length) Fee_Read(_blockNumber,_blockOffset,_dataBufferPtr,_length)
#define _MemIf_Write(_deviceIndex,_blockNumber,_dataBufferPtr) Fee_Write(_blockNumber,_dataBufferPtr)
#define _MemIf_Cancel(_deviceIndex) Fee_Cancel()
#define _MemIf_GetStatus(_deviceIndex) Fee_GetStatus()
#define _MemIf_GetJobResult(_deviceIndex) Fee_GetJobResult()
#define _MemIf_InvalidateBlock(_deviceIndex,_blockNumber) Fee_InvalidateBlock(_blockNumber)
#define _MemIf_EraseImmediateBlock(_deviceIndex,_blockNumber) Fee_EraseImmediateBlock(_blockNumber)
#elif (MEMIF_DEVICE_TO_USE == EEP_DRIVER_INDEX)
#define _MemIf_SetMode(_mode) Ea_SetMode(_mode)
#define _MemIf_Read(_deviceIndex,_blockNumber,_blockOffset,_dataBufferPtr,_length) Ea_Read(_blockNumber,_blockOffset,_dataBufferPtr,_length)
#define _MemIf_Write(_deviceIndex,_blockNumber,_dataBufferPtr) Ea_Write(_blockNumber,_dataBufferPtr)
#define _MemIf_Cancel(_deviceIndex) Ea_Cancel()
#define _MemIf_GetStatus(_deviceIndex) Ea_GetStatus()
#define _MemIf_GetJobResult(_deviceIndex) Ea_GetJobResult()
#define _MemIf_InvalidateBlock(_deviceIndex,_blockNumber) Ea_InvalidateBlock(_blockNumber)
#define _MemIf_EraseImmediateBlock(_deviceIndex,_blockNumber) Ea_EraseImmediateBlock(_blockNumber)
#else
#error "Memory device unknown (MEMIF_DEVICE_TO_USE)"
#endif
#endif
/* Supported APIs */
/* @req MemIf038 *//* MemIf_SetMode */
/* @req MemIf039 *//* MemIf_Read */
/* @req MemIf040 *//* MemIf_Write */
/* @req MemIf041 *//* MemIf_Cancel */
/* @req MemIf042 *//* MemIf_GetStatus */
/* @req MemIf043 *//* MemIf_GetJobResult */
/* @req MemIf044 *//* MemIf_InvalidateBlock */
/* @req MemIf046 *//* MemIf_EraseImmediateBlock */
#if (MEMIF_NUMBER_OF_DEVICES > 1)
void MemIf_SetMode(MemIf_ModeType Mode);
Std_ReturnType MemIf_Read(uint8 DeviceIndex, uint16 BlockNumber, uint16 BlockOffset, uint8 *DataBufferPtr, uint16 Length);
Std_ReturnType MemIf_Write(uint8 DeviceIndex, uint16 BlockNumber, uint8 *DataBufferPtr);
void MemIf_Cancel(uint8 DeviceIndex);
MemIf_StatusType MemIf_GetStatus(uint8 DeviceIndex);
MemIf_JobResultType MemIf_GetJobResult(uint8 DeviceIndex);
Std_ReturnType MemIf_InvalidateBlock(uint8 DeviceIndex, uint16 BlockNumber);
Std_ReturnType MemIf_EraseImmediateBlock(uint8 DeviceIndex, uint16 BlockNumber);
#else
#define MemIf_SetMode(_mode) _MemIf_SetMode(_mode)
#define MemIf_Read(_deviceIndex,_blockNumber,_blockOffset,_dataBufferPtr,_length) _MemIf_Read(_deviceIndex, _blockNumber,_blockOffset,_dataBufferPtr,_length)
#define MemIf_Write(_deviceIndex,_blockNumber,_dataBufferPtr) _MemIf_Write(_deviceIndex,_blockNumber,_dataBufferPtr)
#define MemIf_Cancel(_deviceIndex) _MemIf_Cancel(_deviceIndex)
#define MemIf_GetStatus(_deviceIndex) _MemIf_GetStatus(_deviceIndex)
#define MemIf_GetJobResult(_deviceIndex) _MemIf_GetJobResult(_deviceIndex)
#define MemIf_InvalidateBlock(_deviceIndex,_blockNumber) _MemIf_InvalidateBlock(_deviceIndex,_blockNumber)
#define MemIf_EraseImmediateBlock(_deviceIndex,_blockNumber) _MemIf_EraseImmediateBlock(_deviceIndex,_blockNumber)
#endif
#endif /*MEMIF_H_*/
|
2301_81045437/classic-platform
|
memory/MemIf/inc/MemIf.h
|
C
|
unknown
| 6,243
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
#ifndef MEMIF_TYPES_H_
#define MEMIF_TYPES_H_
/* @req MemIf009 */
/* @req MemIf010 */
typedef enum {
// The underlying abstraction module or device driver has
// not been initialized (yet).
MEMIF_UNINIT,
// The underlying abstraction module or device driver is
// currently idle.
MEMIF_IDLE,
// The underlying abstraction module or device driver is
// currently busy.
MEMIF_BUSY,
// The underlying abstraction module is busy with internal
// management operations. The underlying device driver
// can be busy or idle.
MEMIF_BUSY_INTERNAL
} MemIf_StatusType;
typedef enum {
//The job has been finished successfully.
MEMIF_JOB_OK,
// The job has not been finished successfully.
MEMIF_JOB_FAILED,
// The job has not yet been finished.
MEMIF_JOB_PENDING,
// The job has been canceled.
MEMIF_JOB_CANCELED,
// The requested block is inconsistent, it may contain
// corrupted data.
MEMIF_BLOCK_INCONSISTENT,
// The requested block has been marked as invalid,
// the requested operation can not be performed.
MEMIF_BLOCK_INVALID
} MemIf_JobResultType;
typedef enum {
// The underlying memory abstraction modules and
// drivers are working in slow mode.
MEMIF_MODE_SLOW,
// The underlying memory abstraction modules and
// drivers are working in fast mode.
MEMIF_MODE_FAST
} MemIf_ModeType;
// Definition of broadcast device ID
#define MEMIF_BROADCAST_ID 0xff
#endif /*MEMIF_TYPES_H_*/
|
2301_81045437/classic-platform
|
memory/MemIf/inc/MemIf_Types.h
|
C
|
unknown
| 2,429
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
/* @req MemIf033 */
/* !req MemIf062 *//* No version check of included modules is done */
/* @req MemIf006 */
#include "MemIf.h"
/*lint -emacro(904,VALIDATE_RV,VALIDATE)*/ /*904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/
#if (MEMIF_NUMBER_OF_DEVICES > 1)
#if (MEMIF_NUMBER_OF_DEVICES > 2)
#error "MemIf: Only 2 devices supported"
#endif
/* @req MemIf007 */
#if (MEMIF_DEV_ERROR_DETECT == STD_ON)
/* @req MemIf058 */
/* @req MemIf059 */
/* @req MemIf048 */
#include "Det.h"
#define VALIDATE_RV(_exp,_api,_err,_rv ) \
if( !(_exp) ) { \
(void)Det_ReportError(MEMIF_MODULE_ID, 0, _api, _err); \
return (_rv); \
}
#define VALIDATE(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(MEMIF_MODULE_ID, 0, _api, _err); \
return; \
}
#else
#define VALIDATE_RV(_exp,_api,_err,_rv )
#define VALIDATE(_exp,_api,_err )
#endif /* MEMIF_DEV_ERROR_DETECT */
#define MEMIF_EA_DEVICE_INDEX 0u
#define MEMIF_FEE_DEVICE_INDEX 1u
#define MEMIF_NOF_SUPPORTED_DEVICES 2u
#define MEMIF_BROADCAST_DEVICE_ID 0xFFu
#define IS_VALID_DEVICE_ID(_x) ((_x) < MEMIF_NOF_SUPPORTED_DEVICES)
#define IS_BROADCAST_DEVICE_ID(_x) ((_x) == MEMIF_BROADCAST_DEVICE_ID)
#if (2 == MEMIF_NUMBER_OF_DEVICES)
/* @req MemIf020 */
/* @req MemIf047 */
typedef void (*SetModeFcnPtrType)(MemIf_ModeType Mode);
typedef Std_ReturnType (*ReadFcnPtrType)(uint16 BlockNumber, uint16 BlockOffset, uint8 *DataBufferPtr, uint16 Length);
typedef Std_ReturnType (*WriteFcnPtrType)(uint16 blockNumber, uint8* dataBufferPtr);
typedef void (*CancelFcnPtrType)(void);
typedef MemIf_StatusType (*GetStatusFcnPtrType)(void);
typedef MemIf_JobResultType (*GetJobResultFcnPtrType)(void);
typedef Std_ReturnType (*InvalidateBlockFcnPtrType)(uint16 blockNumber);
typedef Std_ReturnType (*EraseImmediateBlockFcnPtrType)(uint16 blockNumber);
typedef struct {
const SetModeFcnPtrType SetMode;
const ReadFcnPtrType Read;
const WriteFcnPtrType Write;
const CancelFcnPtrType Cancel;
const GetStatusFcnPtrType GetStatus;
const GetJobResultFcnPtrType GetJobResult;
const InvalidateBlockFcnPtrType InvalidateBlock;
const EraseImmediateBlockFcnPtrType EraseImmediateBlock;
}MemIfDeviceAPIType;
const MemIfDeviceAPIType MemIfDevice[MEMIF_NOF_SUPPORTED_DEVICES] = {
[MEMIF_EA_DEVICE_INDEX] = {
.SetMode = Ea_SetMode,
.Read = Ea_Read,
.Write = Ea_Write,
.Cancel = Ea_Cancel,
.GetStatus = Ea_GetStatus,
.GetJobResult = Ea_GetJobResult,
.InvalidateBlock = Ea_InvalidateBlock,
.EraseImmediateBlock = Ea_EraseImmediateBlock
},
[MEMIF_FEE_DEVICE_INDEX] = {
.SetMode = Fee_SetMode,
.Read = Fee_Read,
.Write = Fee_Write,
.Cancel = Fee_Cancel,
.GetStatus = Fee_GetStatus,
.GetJobResult = Fee_GetJobResult,
.InvalidateBlock = Fee_InvalidateBlock,
.EraseImmediateBlock = Fee_EraseImmediateBlock
}
};
#endif
/**
* Invokes the "GetStatus" function of the underlying memory abstraction module
* selected by the parameter DeviceIndex
* @param Mode
*/
void MemIf_SetMode(MemIf_ModeType Mode) {
for(uint8 deviceIndex = 0; deviceIndex < MEMIF_NOF_SUPPORTED_DEVICES; deviceIndex++) {
MemIfDevice[deviceIndex].SetMode(Mode);
}
}
/**
* Invokes the "Read" function of the underlying memory abstraction module selected
* by the parameter DeviceIndex
* @param DeviceIndex
* @param BlockNumber
* @param BlockOffset
* @param DataBufferPtr
* @param Length
* @return In case development error detection is enabled for the Memory Abstraction
* Interface and a development error is detected according to MemIf022 the
* function shall return E_NOT_OK else it shall return the value of the
* called function of the underlying module
*/
Std_ReturnType MemIf_Read(uint8 DeviceIndex, uint16 BlockNumber, uint16 BlockOffset, uint8 *DataBufferPtr, uint16 Length) {
/* @req MemIf022 */
/* @req MemIf023 */
/* @req MemIf024 */
VALIDATE_RV(IS_VALID_DEVICE_ID(DeviceIndex), MEMIF_READ_ID, MEMIF_E_PARAM_DEVICE, E_NOT_OK);
VALIDATE_RV((NULL != DataBufferPtr), MEMIF_READ_ID, MEMIF_E_PARAM_POINTER, E_NOT_OK);
return MemIfDevice[DeviceIndex].Read(BlockNumber, BlockOffset, DataBufferPtr, Length);
}
/**
* Invokes the "Write" function of the underlying memory abstraction module selected
* by the parameter DeviceIndex
* @param DeviceIndex
* @param BlockNumber
* @param DataBufferPtr
* @return In case development error detection is enabled for the Memory Abstraction
* Interface and a development error is detected according to MemIf022 the
* function shall return E_NOT_OK else it shall return the value of the
* called function of the underlying module
*/
Std_ReturnType MemIf_Write(uint8 DeviceIndex, uint16 BlockNumber, uint8 *DataBufferPtr) {
/* @req MemIf022 */
/* @req MemIf023 */
/* @req MemIf024 */
VALIDATE_RV(IS_VALID_DEVICE_ID(DeviceIndex), MEMIF_WRITE_ID, MEMIF_E_PARAM_DEVICE, E_NOT_OK);
VALIDATE_RV((NULL != DataBufferPtr), MEMIF_WRITE_ID, MEMIF_E_PARAM_POINTER, E_NOT_OK);
return MemIfDevice[DeviceIndex].Write(BlockNumber, DataBufferPtr);
}
/**
* Invokes the "Cancel" function of the underlying memory abstraction module
* selected by the parameter DeviceIndex
* @param DeviceIndex
*/
void MemIf_Cancel(uint8 DeviceIndex) {
/* @req MemIf022 */
/* @req MemIf023 */
/* @req MemIf024 */
VALIDATE(IS_VALID_DEVICE_ID(DeviceIndex), MEMIF_CANCEL_ID, MEMIF_E_PARAM_DEVICE);
MemIfDevice[DeviceIndex].Cancel();
}
/**
* Invokes the "GetStatus" function of the underlying memory abstraction module
* selected by the parameter DeviceIndex
* @param DeviceIndex
* @return See MemIf035
*/
MemIf_StatusType MemIf_GetStatus(uint8 DeviceIndex) {
/* @req MemIf022 */
/* @req MemIf023 */
/* @req MemIf024 */
MemIf_StatusType totalStatus = MEMIF_IDLE;
MemIf_StatusType deviceStatus;
VALIDATE_RV((IS_VALID_DEVICE_ID(DeviceIndex) || IS_BROADCAST_DEVICE_ID(DeviceIndex)), MEMIF_GETSTATUS_ID, MEMIF_E_PARAM_DEVICE, MEMIF_UNINIT);
if(IS_BROADCAST_DEVICE_ID(DeviceIndex)) {
for(uint8 devIdx = 0; devIdx < MEMIF_NOF_SUPPORTED_DEVICES; devIdx++) {
/* @req MemIf035 */
deviceStatus = MemIfDevice[devIdx].GetStatus();
if( (MEMIF_UNINIT == deviceStatus) || (MEMIF_UNINIT == totalStatus) ) {
totalStatus = MEMIF_UNINIT;
} else if( (MEMIF_BUSY == deviceStatus) || (MEMIF_BUSY == totalStatus) ) {
totalStatus = MEMIF_BUSY;
} else if( MEMIF_BUSY_INTERNAL == deviceStatus ) {
totalStatus = MEMIF_BUSY_INTERNAL;
}
}
} else {
totalStatus = MemIfDevice[DeviceIndex].GetStatus();
}
return totalStatus;
}
/**
* Invokes the "GetJobResult" function of the underlying memory abstraction module
* selected by the parameter DeviceIndex.
* @param DeviceIndex
* @param BlockNumber
* @param BlockOffset
* @param DataBufferPtr
* @param Length
* @return In case development error detection is enabled for the
* Memory Abstraction Interface and a development error is detected
* according to MemIf022 the function shall return E_JOB_FAILED else
* it shall return the value of the called function of the underlying module
*/
MemIf_JobResultType MemIf_GetJobResult(uint8 DeviceIndex) {
/* @req MemIf022 */
/* @req MemIf023 */
/* @req MemIf024 */
VALIDATE_RV(IS_VALID_DEVICE_ID(DeviceIndex), MEMIF_GETJOBRESULT_ID, MEMIF_E_PARAM_DEVICE, MEMIF_JOB_FAILED);
return MemIfDevice[DeviceIndex].GetJobResult();
}
/**
* Invokes the "InvalidateBlock" function of the underlying memory abstraction
* module selected by the parameter DeviceIndex
* @param DeviceIndex
* @param BlockNumber
* @return In case development error detection is enabled for the Memory
* Abstraction Interface and a development error is detected according
* to MemIf022 the function shall return E_NOT_OK else it shall return
* the value of the called function of the underlying module
*/
Std_ReturnType MemIf_InvalidateBlock(uint8 DeviceIndex, uint16 BlockNumber) {
/* @req MemIf022 */
/* @req MemIf023 */
/* @req MemIf024 */
VALIDATE_RV((IS_VALID_DEVICE_ID(DeviceIndex)), MEMIF_INVALIDATEBLOCK_ID, MEMIF_E_PARAM_DEVICE, E_NOT_OK);
return MemIfDevice[DeviceIndex].InvalidateBlock(BlockNumber);
}
/**
* Invokes the "EraseImmediateBlock" function of the underlying memory abstraction
* module selected by the parameter DeviceIndex
* @param DeviceIndex
* @param BlockNumber
* @return In case devlopment error detection is enabled for the Memory Abstraction
* Interface and a development error is detected according to MemIf022 the
* function shall return E_NOT_OK else it shall return the value of the
* called function of the underlying module
*/
Std_ReturnType MemIf_EraseImmediateBlock(uint8 DeviceIndex, uint16 BlockNumber) {
/* @req MemIf022 */
/* @req MemIf023 */
/* @req MemIf024 */
VALIDATE_RV(IS_VALID_DEVICE_ID(DeviceIndex), MEMIF_ERASEIMMEDIATEBLOCK_ID, MEMIF_E_PARAM_DEVICE, E_NOT_OK);
return MemIfDevice[DeviceIndex].EraseImmediateBlock(BlockNumber);
}
#endif
|
2301_81045437/classic-platform
|
memory/MemIf/src/MemIf.c
|
C
|
unknown
| 10,838
|
# NvM
obj-$(USE_NVM) += NvM.o
obj-$(USE_NVM) += NvM_Cfg.o
inc-$(USE_NVM) += $(ROOTDIR)/memory/NvM/inc
vpath-$(USE_NVM) += $(ROOTDIR)/memory/NvM/src
|
2301_81045437/classic-platform
|
memory/NvM/NvM.mod.mk
|
Makefile
|
unknown
| 153
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
/** @req NVM077 */ /* Function prototypes */
#ifndef NVM_H_
#define NVM_H_
/* @req NVM743 */
#define NVM_MODULE_ID 20u
#define NVM_VENDOR_ID 60u
#define NVM_SW_MAJOR_VERSION 1u
#define NVM_SW_MINOR_VERSION 2u
#define NVM_SW_PATCH_VERSION 1u
#define NVM_AR_RELEASE_MAJOR_VERSION 4u
#define NVM_AR_RELEASE_MINOR_VERSION 0u
#define NVM_AR_RELEASE_REVISION_VERSION 3u
#define NVM_AR_MAJOR_VERSION NVM_AR_RELEASE_MAJOR_VERSION
#define NVM_AR_MINOR_VERSION NVM_AR_RELEASE_MINOR_VERSION
#define NVM_AR_PATCH_VERSION NVM_AR_RELEASE_REVISION_VERSION
/* @req NVM553 */
#include "NvM_Cfg.h"
/** @req NVM028 */ // NvmCommon configuration block is implemented in the NvM_Cfg.h file
// Error codes reported by this module defined by AUTOSAR
/* @req NVM187 */
#define NVM_E_PARAM_BLOCK_ID 0x0Au
#define NVM_E_PARAM_BLOCK_TYPE 0x0Bu
#define NVM_E_PARAM_BLOCK_DATA_IDX 0x0Cu
#define NVM_E_PARAM_ADDRESS 0x0Du
#define NVM_E_PARAM_DATA 0x0Eu
/* !req NVM023 NVM_E_PARAM_POINTER not detected (NvM_GetVersionInfo) */
//#define NVM_E_PARAM_POINTER 0x0Fu
/* @req NVM586 */
#define NVM_E_NOT_INITIALIZED 0x14u
/* @req NVM587 */
#define NVM_E_BLOCK_PENDING 0x15u
/* !req NVM590 */
//#define NVM_E_BLOCK_CONFIG 0x18u
/* Arccore extra errors */
/* @req NVM024 */
#define NVM_E_LIST_OVERFLOW 0x50u
#define NVM_E_NV_WRITE_PROTECTED 0x51u
// Other error codes reported by this module
#define NVM_PARAM_OUT_OF_RANGE 0x40u
#define NVM_UNEXPECTED_STATE 0x41u
#define NVM_E_WRONG_CONFIG 0xfdu
#define NVM_E_UNEXPECTED_EXECUTION 0xfeu
#define NVM_E_NOT_IMPLEMENTED_YET 0xffu
// Service ID in this module
#define NVM_INIT_ID 0x00u
#define NVM_SET_DATA_INDEX_ID 0x01u
#define NVM_GET_DATA_INDEX_ID 0x02u
#define NVM_SET_BLOCK_PROTECTION_ID 0x03u
#define NVM_GET_ERROR_STATUS_ID 0x04u
#define NVM_SET_RAM_BLOCK_STATUS_ID 0x05u
#define NVM_READ_BLOCK_ID 0x06u
#define NVM_WRITE_BLOCK_ID 0x07u
#define NVM_RESTORE_BLOCK_DEFAULTS_ID 0x08u
#define NVM_ERASE_NV_BLOCK_ID 0x09u
#define NVM_CANCEL_WRITE_ALL_ID 0x0au
#define NVM_INVALIDATENV_BLOCK_ID 0x0bu
#define NVM_READ_ALL_ID 0x0cu
#define NVM_WRITE_ALL_ID 0x0du
#define NVM_MAIN_FUNCTION_ID 0x0eu
#define NVM_GET_VERSION_INFO_ID 0x0fu
#define NVM_LOC_READ_BLOCK_ID 0x40u
#define NVM_LOC_WRITE_BLOCK_ID 0x41u
#define NVM_GLOBAL_ID 0xffu
/* APIs */
/* @req NVM149 *//* API configuration classes */
/* !req NVM560 API support missing */
/* !req NVM561 API support missing */
/* !req NVM562 API support missing */
/** @req NVM286 */
/** @req NVM650 */
#if ( NVM_VERSION_INFO_API == STD_ON )
/** @req NVM452 */
/** @req NVM285 */
/** !req NVM613 */
#define NvM_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi, NVM)
#endif /* NVM_VERSION_INFO_API */
void NvM_MainFunction(void); /** @req NVM464 */
void NvM_Init( void ); /** @req NVM447 */
void NvM_ReadAll( void ); /** @req NVM460 */
void NvM_WriteAll( void ); /** @req NVM461 */
void NvM_CancelWriteAll( void );
Std_ReturnType NvM_GetErrorStatus( NvM_BlockIdType blockId, NvM_RequestResultType *requestResultPtr ); /** @req NVM451 */
void NvM_SetBlockLockStatus( NvM_BlockIdType blockId, boolean blockLocked );
#if (NVM_SET_RAM_BLOCK_STATUS_API == STD_ON)
Std_ReturnType NvM_SetRamBlockStatus( NvM_BlockIdType blockId, boolean blockChanged ); /** @req NVM453 */
#endif
#if (NVM_API_CONFIG_CLASS > NVM_API_CONFIG_CLASS_1)
Std_ReturnType NvM_SetDataIndex( NvM_BlockIdType blockId, uint8 dataIndex ); /** @req NVM448 */
Std_ReturnType NvM_GetDataIndex( NvM_BlockIdType blockId, uint8 *dataIndexPtr ); /** @req NVM449 */
Std_ReturnType NvM_ReadBlock( NvM_BlockIdType blockId, void *NvM_DstPtr ); /** @req NVM454 */
Std_ReturnType NvM_WriteBlock( NvM_BlockIdType blockId, const void *NvM_SrcPtr ); /** @req NVM455 */
Std_ReturnType NvM_RestoreBlockDefaults( NvM_BlockIdType blockId, void *NvM_DstPtr ); /** @req NVM456 */
#endif
#if (NVM_API_CONFIG_CLASS > NVM_API_CONFIG_CLASS_2)
Std_ReturnType NvM_SetBlockProtection( NvM_BlockIdType blockId, boolean protectionEnabled );
Std_ReturnType NvM_EraseNvBlock( NvM_BlockIdType blockId );
Std_ReturnType NvM_InvalidateNvBlock( NvM_BlockIdType blockId ); /** @req NVM459 */
#endif
#endif /*NVM_H_*/
|
2301_81045437/classic-platform
|
memory/NvM/inc/NvM.h
|
C
|
unknown
| 5,228
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
/** @req NVM551 *//* Include file structure should include: A callback interface NvM_Cbk.h that provides the callback function prototypes */
/** @req NVM384 *//* The NvM module shall provide a callback interface */
/** @req NVM438 *//* NvM shall provide callback functions */
#ifndef NVM_CBK_H_
#define NVM_CBK_H_
void NvM_JobEndNotification(void); /** @req NVM462 */
void NvM_JobErrorNotification(void); /** @req NVM463 */
#endif /*NVM_CBK_H_*/
|
2301_81045437/classic-platform
|
memory/NvM/inc/NvM_Cbk.h
|
C
|
unknown
| 1,280
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
#ifndef NVM_CONFIG_TYPES_H_
#define NVM_CONFIG_TYPES_H_
#include "NvM_Types.h"
#if defined(USE_DEM)
#include "Dem.h"
#endif
/* NvM_ApiConfigClassType */
#define NVM_API_CONFIG_CLASS_1 0
#define NVM_API_CONFIG_CLASS_2 1
#define NVM_API_CONFIG_CLASS_3 2
typedef enum {
NVM_CRC8,
NVM_CRC16,
NVM_CRC32
} Nvm_BlockCRCTypeType;
/* @req NVM137 */
typedef enum {
NVM_BLOCK_NATIVE,
NVM_BLOCK_REDUNDANT,
NVM_BLOCK_DATASET
} NvM_BlockManagementTypeType;
/*
* Callback function prototypes
*/
typedef Std_ReturnType (*NvM_SingleBlockCallbackFunctionType)(uint8 ServiceId, NvM_RequestResultType JobResult); /** @req NVM467 */
typedef void (*NvM_MultiBlockCallbackFunctionType)(uint8 ServiceId, NvM_RequestResultType JobResult); /** @req NVM468 */
typedef Std_ReturnType (*NvM_InitBlockCallbackFunctionType)(void); /** @req NVM469 */
/*
* Containers and configuration parameters
*/
typedef struct {
NvM_MultiBlockCallbackFunctionType MultiBlockCallback; /* @req NVM331 */
// The rest of the parameters is realized in NvM_Cfg.h
} NvM_CommonType;
typedef struct {
// NVRAM block global settings
NvM_BlockManagementTypeType BlockManagementType;
uint8 BlockJobPriority;
boolean BlockWriteProt;
boolean WriteBlockOnce;
boolean SelectBlockForReadall;
boolean ResistantToChangesSw;
NvM_SingleBlockCallbackFunctionType SingleBlockCallback; /* @req NVM330 */
uint16 NvBlockLength;
// CRC usage of RAM and NV blocks
boolean BlockUseCrc;
Nvm_BlockCRCTypeType BlockCRCType;
// RAM block, RamBlockDataAddress == NULL means temporary block otherwise permanent block
uint8 *RamBlockDataAddress;/* @req NVM088 */
boolean CalcRamBlockCrc;
// NV block, FEE/EA references
uint8 NvBlockNum;
uint32 NvramDeviceId;
uint16 NvBlockBaseNumber;
// ROM block, reference, if RomBlockDataAdress == NULL no ROM data is available
uint16 RomBlockNum;
uint8 *RomBlockDataAdress;
NvM_InitBlockCallbackFunctionType InitBlockCallback; /* @req NVM352 */
// Containers
#if 0 // Currently not used
NvM_TargetBlockReferenceType TargetBlockReference;
#endif
} NvM_BlockDescriptorType;
#if defined(USE_DEM)
typedef struct {
Dem_EventIdType NvMIntegrityFailedDemEventId;
Dem_EventIdType NvMReqFailedDemEventId;
} NvM_DemEventReferencesType;
#endif
typedef struct {
// Containers
NvM_CommonType Common; // 1
#if defined(USE_DEM)
const NvM_DemEventReferencesType DemEvents; // 1
#endif
const NvM_BlockDescriptorType *BlockDescriptor; // 1..65536
} NvM_ConfigType;
/*
* Make the NvM_Config visible for others.
*/
extern const NvM_ConfigType NvM_Config;
#endif /*NVM_CONFIG_TYPES_H_*/
|
2301_81045437/classic-platform
|
memory/NvM/inc/NvM_ConfigTypes.h
|
C
|
unknown
| 3,787
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
/** @req NVM550 */
#ifndef NVM_TYPES_H_
#define NVM_TYPES_H_
/* @req NVM690 */
#include "Std_Types.h"
/* @req NVM755 */
#include "Rte_NvM_Type.h"
#endif /*NVM_TYPES_H_*/
|
2301_81045437/classic-platform
|
memory/NvM/inc/NvM_Types.h
|
C
|
unknown
| 1,005
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.0.3 */
/*
* Author: Peter+mahi
*
* Part of Release:
* 4.0.3
*
* Description:
* Implements the NVRAM Manager module.
*
* Support:
* General Have Support
* -------------------------------------------
* NVM_API_CONFIG_CLASS Y NVM_API_CONFIG_CLASS_1 and NVM_API_CONFIG_CLASS_2
* (Only NvM_InvalidateNvBlock of NVM_API_CONFIG_CLASS_3 )
* NVM_COMPILED_CONFIG_ID N
* NVM_CRC_NUM_OF_BYTES N
* NVM_DATASET_SELECTION_BITS Y
* NVM_DEV_ERROR_DETECT Y
* NVM_DRV_MODE_SWITCH N
* NVM_DYNAMIC_CONFIGURATION N
* NVM_JOB_PRIORITIZATION N
* NVM_MULTI_BLOCK_CALLBACK Y
* NVM_POLLING_MODE N
* NVM_SET_RAM_BLOCK_STATUS_API Y
* NVM_SIZE_IMMEDIATE_JOB_QUEUE N
* NVM_SIZE_STANDARD_JOB_QUEUE Y
* NVM_VERSION_INFO_API Y
*
* NvmBlockDescriptor Have Support
* -------------------------------------------
* NvmBlockCRCType Y
* NvmBlockJobPriority N
* NvmBlockManagementType Y, All blocks supported
* NvmBlockUseCrc Y
* NvmBlockWriteProt N
* NvmCalcRamBlockCrc Y
* NvmInitBlockCallback Y
* NvmNvBlockBaseNumber Y
* NvmNvBlockLength Y
* NvmNvBlockNum Y
* NvmNvramBlockIdentifier Y
* NvmNvramDeviceId N (always device Id 0)
* NvmResistantToChangedSw N
* NvmRomBlockDataAddress Y
* NvmRomBlockNum Y
* NvmSelectBlockForReadall Y
* NvmSingleBlockCallback Y
* NvmWriteBlockOnce N
*
* Implementation notes:
* - The Configuration ID NV Block is generated to the configuration but can't be configured.
* The Editor should really force you to pick a block in Ea/Fee that should hold the configuration
* ID. The NVM_COMPILED_CONFIG_ID is always generated as 0 now.
* - Differences from 3.1.5 Release (Follow release 4.0.2 here)
* NvM_SetDataIndex(), NvM_GetDataIndex, NvM_SetBlockProtection, NvM_GetErrorStatus, NvM_SetRamBlockStatus,
* etc....all return Std_ReturnType instead of void since the RTE expects it.
* - NvM_GetErrorStatus() uses NvM_GetErrorStatus instead of uint8 *
*/
/*
* RamBlockDataAddress
* NULL is no permanent RAM block. Otherwise allocate the number of bytes in space (like the stack)
*
*
* Understanding block numbering:
*
* NVM_DATASET_SELECTION_BIT=2
*
* NvBlockBaseNumber
* 0 Reserved (NVM478)
* 1 NVM_BLOCK_NATIVE, NvBlockNum=1
* 2 NVM_BLOCK_REDUNDANT, NvBlockNum=2
* 3 NVM_BLOCK_DATASET, NvBlockNum=4
*
* NvM_ReadBlock( 0, ... ) - Reserved for "multi block requests"
* NvM_ReadBlock( 1, ... ) - Reserved for redundant NVRAM block which holds the configuration ID.
* NvM_ReadBlock( 2--x, ... ) - "Normal" blocks
*
*
* NvM_BlockIdType*) NvBlockBaseNumber EA_BLOCK_NUMBER
* 0**)
* 1**) ***)
* 2 1 4, (5,6,7) ****)
* 3 2 8, R9,(10,11) ****)
* 4 3 12, D13,D14,D15 ****)
*
* Should
*
*
* *) Type used in the API.
* **) Reserved ID's ( 0 - multiblock, 1 - redundant NVRAM block which hold configuration ID)
* ***) Reserved ID
* ****) FEE/EA_BLOCK_NUMBER = NvBlockBaseNumber << NvmDatasetSelectionBits = NvBlockBaseNumber * 4
* () - Cannot be accesses due to NvBlockNum
* R9 - Redundant block
* Dx - Data blocks
*
* SIZES
* Both NvM and EA/FEE have block sizes. NvM have NvNvmBlockLength (NVM479) and FEE/EA have EaBlockSize.
* FEE/EA also have virtual page that is the alignment of a block, with the smallest block=size of the virtual page.
*
* So, who allocates space for this. FEE/EA only have EaBlockSize.
* NvM have NvmRamBlockDataAddress, NvmRomBlockDataAddress and mapping to a MemIf Blocks (FEE/EA blocks)
*
* ASSUME: I can't really see a point for the FEE/EA EaBlockSize.. it will just a multiple of NvNvmBlockLength*NvBlockNum + overhead?
* Click-box in EA/FEE that leaves the size calculation to NvM?
* This also means that enabling NvmBlockUseCrc or set a block from NVM_BLOCK_NATIVE to NVM_BLOCK_DATASET would be "automatic"
* in calculation of the EaBlockSize.
*
* 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
* 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)
*
* CRC
* NVM121: NvM_SetRamBlockStatus(), calculate CRC in background if NvmCalcRamBlockCrc==TRUE
* NVM362: NvM_ReadAll() , if (NvmCalcRamBlockCrc == TRUE && permanent RAM block) re-calc CRC.
*
* NvmBlockUseCrc - Global CRC switch. Space is allocated in both RAM and NV block
* NvmCalcRamBlockCrc - CRC re-calculation. For example during startup, you may don't want
* to verify all the checksums again, but instead just copy from NV
* to RAM.
*
* There is also explicit RAM checksum calculations for example NVM253 (Nvm_WriteAll()) where a CRC calculation
* is requested (although not stated should be dependent on NvmBlockUseCrc only, not NvmCalcRamBlockCrc).
* You have to calculate the checksum at some point....
*
* QUEUES
* NVM185: Says "successful enqueueing a request".."set to NVM_REQ_PENDING"
* NVM380: The queue length for multi block request shall be one (NvM_ReadAll, NvM_WriteAll)
* NVM381+NVM567 : Multi block requests shall not be interrupted.
* NVM243+NVM245: Do not unqueue the multi block request until all single block queues are empty.
* So, when NvmState==IDLE and we have a multi-request
*
*
*
*
*
* SPEED
* To get some speed into this multiple thing must be done in the same MainFunction loop.
*
* MEMIF
* The interface is actually quite strange, so you may read from any address (through MemIf_Read())
* but MemIf_Write(..) only takes a logical block and a pointer to the data to write.
*
* See two alternatives here:
* 1. If the NVBlock also contains the checksum after the data then writing the data needs a
* RAM that is as big as the biggest RAM block + room for checksum.
* 2. If checksums would be kept in a separate EA/FEE block the ALL the checksum need to be written.
* For example after a NvM_WriteBlock() the checksum block would need to be written. This
* will probably lead consistency problems also... what happens if we fail to write the checksum
* block?
*
*
*
* MANUAL
*
*
*
* Provide Data for the first/initial read
* When a block have no
*
* NVM085
* NVM061
* NVM083
*
* Configuring CRCs
* BlockUseCrc (A): If the block (both RAM and NV) should use CRC
* CalcRamBlockCrc (B): If the permanent RAM block should re-calculate it's CRC.
*
* A B
* ------------
* 0 0 No error detection or recovery
* 0 1 N/A
* 1 0 ?
* 1 1 ?
*
* RAM BLOCK VALID/UNCHANGED
* Figure 8 and 9 in 3.1.5/NVM is more confusing than good.
* What we have to know is:
* 1. Initially the RAM block is in INVALID/UNCHANGED
* ALT 2. After a NvM_ReadAll() and all is well the state goes to VALID/UNCHANGED
* ALT 2. If ROM values are used we go to VALID/CHANGED (We failed to read from NVRAM)
*
* For NvM_WriteAll()
* 1. A block that is INVALID can't be written
* 2. A block that is UNCHANGED should not be written.
* -> Write only blocks that are VALID/CHANGED.
*
* VALID/UNCHANGED - RAM == NV
* VALID/CHANGED - RAM != NV (analog to cache memories, "dirty")
*
* Analog to cache
* VALID/CHANGED state - Dirty (since RAM != NV)
* WriteBlock - Flush (Flush the RAM block to NV)
* ReadBlock - Invalidate (NV block is read to RAM)
*/
/*
* General requirements
*/
/** @req NVM076 */
/** @req NVM552 */
/** @req NVM689 */
/** @req NVM446 *//* Included types */
/** @req NVM475 *//* Block IDs in sequential order */
/** @req NVM076 *//* One or more c files containing NvM code */
/** @req NVM051 *//* The Memory Abstraction Interface provide the NvM module with a virtual linear 32bit address space */
/** @req NVM000 *//* The Native NVRAM block consists of a single NV block, RAM block and Administrative block. */
/** @req NVM001 *//* The Redundant NVRAM block consists of two NV blocks, a RAM block and an Administrative block. */
/** @req NVM006 *//* The Dataset NVRAM block consists of multiple NV user data, (optionally) CRC areas, (optional) NV block headers, a RAM block and an Admin block. */
/** @req NVM374 *//* The NvM module shall be able to read all assigned NV blocks. */
/** @req NVM375 *//* The NvM module shall only be able to write to all assigned NV blocks if (and only if) write protection is disabled. */
/** @req NVM380 *//* Job queue length for multi block requests should be one */
/** @req NVM568 *//* The NvM module shall rather queue read jobs that are requested during an ongoing NvM_ReadAll request and executed them subsequently */
/** @req NVM569 *//* The NvM module shall rather queue write jobs that are requested during an ongoing NvM_WriteAll request and executed them subsequently */
/** @req NVM725 *//* The NvM module shall rather queue write jobs that are requested during an ongoing NvM_ReadAll request and executed them subsequently */
/** @req NVM726 *//* The NvM module shall rather queue read jobs that are requested during an ongoing NvM_WriteAll request and executed them subsequently. */
/** @req NVM160 *//* The NvM module shall not store the currently used Dataset index automatically in a persistent way. */
/** @req NVM162 *//* Requests queued (although no support for priority) */
/** @req NVM164 *//* The NvM module shall provide implicit techniques to check the data consistency of NVRAM blocks */
/** @req NVM571 *//* The data consistency check of a NVRAM block shall be done by CRC recalculations of its corresponding NV block(s). */
/** @req NVM165 *//* The implicit consistency check shall be configurable for each NVRAM block (parameters NvMBlockUseCrc and NvMCalcRamBlockCrc) */
/** @req NVM020 *//* The ROM block is a basic storage object, resides in the ROM (FLASH) and is used to provide default data in case of an empty or damaged NV block. */
/** @req NVM040 *//* The NvM module shall implement implicit mechanisms for consistency / integrity checks of data saved in NV memory */
/** @req NVM047 *//* The NvM module shall provide techniques for error recovery. The error recovery depends on the NVRAM block management type */
/** @req NVM069 *//* A single NVRAM block to deal with will be selected via the NvM module API by providing a subsequently assigned Block ID. */
/** @req NVM138 *//* The NVRAM block shall consist of the mandatory basic storage objects NV block, RAM block and Administrative block. */
/** @req NVM171 *//* The NvM module shall provide implicit(fallback on read failure) and explicit(NvM_RestoreBlockDefaults) recovery techniques */
/** @req NVM174 *//* The detection of an incomplete write operation to a NV block is out of scope of the NvM module. Handled by lower layer */
/** @req NVM175 *//* Request result indicated in the error/status field of the Admin block */
/** @req NVM181 *//* Multiple concurrent single block requests shall be queueable. */
/** @req NVM373 *//* The RAM block data shall contain the permanently or temporarily assigned user data. */
/** @req NVM396 *//* The multi block requests shall indicate individual block status */
/** @req NVM443 *//* The NvM module shall not modify the configured block identifiers. */
/** @req NVM038 *//* The NvM module only provides an implicit way of accessing blocks in the NVRAM and in the shared memory (RAM). */
/** @req NVM125 *//* The NV block represents a memory area consisting of NV user data and (optionally) a CRC and (optionally) a NV block header.*/
/** @req NVM126 *//* The RAM block represents an area in RAM consisting of user data and (optionally) a CRC value and (optionally) a NV block header. */
/** @req NVM127 *//* CRC on RAM only used if */
/** @req NVM129 *//* The user data area of a RAM block can reside in a different RAM address location (global data section) than the state of the RAM block. */
/** @req NVM130 *//* The data area of a RAM block shall be accessible from NVRAM Manager and from the application side */
/** @req NVM332 *//* NvM relies on the scheduler. Do not use any OS objects or services */
/** @req NVM557 *//* Configuration validated */
/** @req NVM558 *//* Configuration validated */
/** @req NVM559 *//* Configuration validated */
/** @req NVM696 *//* Application responsible for providing valid data before next write in case of failed read */
/* Not supported(?) unclear requirements */
/** !req NVM573 *//* What does this mean? Should crc be checked in RAM before attempting to read? */
/** !req NVM574 *//* What does this mean? Should crc be checked in RAM before attempting to read? */
/** !req NVM575 *//* What does this mean? Should crc be checked in RAM before attempting to read? */
/** !req NVM123 *//* What does this mean? Store where? */
/*
* NB! Even though some code exist for handling RamCrc, the functionality is not complete
* and shall not be used.
*/
//lint -esym(522,CalcCrc) // 522 PC-Lint exception for empty functions
// Exception made as a result of that NVM_DATASET_SELECTION_BITS can be zero
//lint -emacro(835, BLOCK_BASE_AND_SET_TO_BLOCKNR) // 835 PC-lint: A zero has been given as right argument to operator '<<' or '>>'
//lint -emacro(506, NVM_ASSERT) // 506 PC-lint: Ok, to have constant value.
/*lint -emacro(904,DET_VALIDATE_NO_RV)*/ /*904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/
/* ----------------------------[includes]------------------------------------*/
/* @req NVM554 *//* NvM module shall include NvM.h, Dem.h, MemIf.h, SchM_NvM.h, MemMap.h. */
#include "arc_assert.h"
#include "NvM.h"
#include "NvM_Cbk.h"
#if defined(CFG_NVM_USE_SERVICE_PORTS)
#include "Rte.h" // ???
#endif
#if defined(USE_DEM)
#include "Dem.h"
#endif
#include "MemIf.h"
#include "SchM_NvM.h"
#include "MemMap.h"
#include "cirq_buffer.h"
#include "io.h"
/* @req NVM555 */
#include "Crc.h"
#include <string.h>
#include "Cpu.h"
//#define DEBUG_BLOCK 1
#if defined(DEBUG_BLOCK)
#define DEBUG_BLOCK_STATE(_str,_block,_state) printf("%s BLOCK NR:%d STATE:%d\n",_str,_block, _state); fflush(stdout);
#define DEBUG_STATE(_state,_substate) printf("MAIN_STATE:%s/%d\n",StateToStr[_state],_substate); fflush(stdout);
#define DEBUG_PRINTF(format,...) printf(format,## __VA_ARGS__ ); fflush(stdout);
#define DEBUG_CHECKSUM(_str,_crc) printf("%s crc=%x\n",_str,_crc);
#define DEBUG_FPUTS(_str) fputs((_str),stdout); fflush(stdout);
#else
#define DEBUG_BLOCK_STATE(_str,_block,_state)
#define DEBUG_STATE(_state,_substate)
#define DEBUG_PRINTF(format,...)
#define DEBUG_CHECKSUM(_str,_crc)
#define DEBUG_FPUTS(_str)
#endif
/* ----------------------------[private define]------------------------------*/
/* ----------------------------[private macro]-------------------------------*/
#if defined(DEBUG_BLOCK)
#define NVM_ASSERT(_exp) if( !(_exp) ) { while(1) {}; } //ASSERT(_exp)
#else
#define NVM_ASSERT(_exp) if( !(_exp) ) { ASSERT(_exp); } //
#endif
/*lint -emacro(904,DET_VALIDATE_RV)*/ /*904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/
/* @req NVM025 *//* @req NVM596 *//* @req NVM597 *//* @req NVM188 *//* @req NVM191 */
#if ( NVM_DEV_ERROR_DETECT == STD_ON )
#if defined(USE_DET)
/* @req NVM556 */
#include "Det.h"
#endif
#define DET_VALIDATE(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(NVM_MODULE_ID, 0, _api, _err); \
}
#define DET_VALIDATE_RV(_exp,_api,_err,_rv ) \
if( !(_exp) ) { \
(void)Det_ReportError(NVM_MODULE_ID, 0, _api, _err); \
return _rv; \
}
#define DET_VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(NVM_MODULE_ID, 0, _api, _err); \
return; \
}
#define DET_REPORTERROR(_api,_err) (void)Det_ReportError(NVM_MODULE_ID, 0,_api,_err)
#else
#define DET_VALIDATE(_exp,_api,_err )
#define DET_VALIDATE_RV(_exp,_api,_err,_rv )
#define DET_VALIDATE_NO_RV(_exp,_api,_err )
#define DET_REPORTERROR(_api,_err)
#endif
/* @req NVM122 */
#define BLOCK_BASE_AND_SET_TO_BLOCKNR(_blockbase, _set) ((uint16)((_blockbase)<<NVM_DATASET_SELECTION_BITS) +(_set))
/* @req NVM189 *//* Cannot be disabled unless Dem is not used at all */
/* @req NVM026 */
#if defined(USE_DEM)
/* @req NVM739 */
#define DEM_REPORTERRORSTATUS(_err,_ev ) if (_err != DEM_EVENT_ID_NULL) { Dem_ReportErrorStatus(_err, DEM_EVENT_STATUS_FAILED); }
#else
#define DEM_REPORTERRORSTATUS(_err,_ev )
#endif
#define BLOCK_NR_FROM_PTR(_bptr) (((_bptr) - NvM_Config.BlockDescriptor + 1)) // sizeof(NvM_BlockDescriptorType))
/*lint --e{773} Expression-like macro 'CREATE_ENTRY' not parenthesized */
#define CREATE_ENTRY(_val) [_val] = #_val
/* ----------------------------[private typedef]-----------------------------*/
// State variable
typedef enum {
NVM_UNINITIALIZED = 0,
NVM_IDLE,
NVM_READ_ALL,
NVM_WRITE_ALL,
NVM_READ_BLOCK,
NVM_WRITE_BLOCK,
NVM_RESTORE_BLOCK_DEFAULTS,
NVM_SETDATAINDEX,
NVM_GETDATAINDEX,
NVM_SETRAMBLOCKSTATUS,
NVM_INVALIDATE_NV_BLOCK,
} NvmStateType;
const char_t *StateToStr[NVM_INVALIDATE_NV_BLOCK] = {
CREATE_ENTRY(NVM_UNINITIALIZED),
CREATE_ENTRY(NVM_IDLE),
CREATE_ENTRY(NVM_READ_ALL),
CREATE_ENTRY(NVM_WRITE_ALL),
CREATE_ENTRY(NVM_READ_BLOCK),
CREATE_ENTRY(NVM_WRITE_BLOCK),
CREATE_ENTRY(NVM_RESTORE_BLOCK_DEFAULTS),
CREATE_ENTRY(NVM_SETDATAINDEX),
CREATE_ENTRY(NVM_GETDATAINDEX),
CREATE_ENTRY(NVM_SETRAMBLOCKSTATUS),
};
typedef enum {
BLOCK_STATE_MEMIF_REQ,
// BLOCK_STATE_START,
BLOCK_STATE_MEMIF_PROCESS,
// BLOCK_STATE_MEMIF_CRC_PROCESS,
BLOCK_STATE_CALC_CRC,
// BLOCK_STATE_MEMIF_PROCESS_CRC,
BLOCK_STATE_CALC_CRC_WRITE,
BLOCK_STATE_CALC_CRC_READ,
// BLOCK_STATE_LOAD_FROM_NV,
} BlockStateType;
typedef enum {
BLOCK_SUBSTATE_0,
BLOCK_SUBSTATE_1,
} BlockSubStateType;
typedef enum {
NS_INIT = 0,
NS_PENDING,
// RB_PROCESSING,
} Nvm_SubStates;
union Nvm_CRC {
uint16 crc16;
uint32 crc32;
};
typedef struct {
NvM_RequestResultType ErrorStatus; // Status from multi block requests i.e. Read/Write/CancelWrite-all @req NVM393
} AdministrativeMultiBlockType;
typedef struct {
BlockStateType BlockState;
BlockSubStateType BlockSubState;
uint8 DataIndex; // Selected data index if "Data Set" type @req NVM144
boolean BlockWriteProtected; // Block write protected? @req NVM054
NvM_RequestResultType ErrorStatus; // Status of block @req NVM136
boolean BlockChanged; // Block changed?
boolean BlockValid; // Block valid? (RAM block only?) @req NVM128 @req NVM132 @req NVM133
uint8 NumberOfWriteFailed; // Current write retry cycle
union Nvm_CRC RamCrc;
union Nvm_CRC NvCrc; // The CRC of this block, read from NV
void * savedDataPtr; //
uint8 flags; // Used for all sorts of things.
} AdministrativeBlockType;
typedef struct {
NvmStateType op;
NvM_BlockIdType blockId;
uint8 * dataPtr; /* Src or Dest ptr */
uint8 serviceId;
} Nvm_QueueType;
/* ----------------------------[private function prototypes]-----------------*/
/* ----------------------------[private variables]---------------------------*/
static NvmStateType nvmState = NVM_UNINITIALIZED;
static Nvm_SubStates nvmSubState = NS_INIT;
static uint8 serviceId = NVM_INIT_ID;
//static int nvmSetNr;
/* @req NVM134 *//* @req NVM135 */
static AdministrativeBlockType AdminBlock[NVM_NUM_OF_NVRAM_BLOCKS];
static AdministrativeMultiBlockType AdminMultiBlock;
#define _ALIGN(_x,_a) (((_x) + (_a) - 1u) & (~ ((_a) - 1u)))
#ifndef EA_VIRTUAL_PAGE_SIZE
#define EA_VIRTUAL_PAGE_SIZE 0
#endif
#ifndef FEE_VIRTUAL_PAGE_SIZE
#define FEE_VIRTUAL_PAGE_SIZE 0
#endif
/* Assume undefined is 0 (all compilers do?) */
#if FEE_VIRTUAL_PAGE_SIZE > EA_VIRTUAL_PAGE_SIZE
#define VIRTUAL_PAGE_SIZE FEE_VIRTUAL_PAGE_SIZE
#else
#define VIRTUAL_PAGE_SIZE EA_VIRTUAL_PAGE_SIZE
#endif
#if (NVM_SIZE_STANDARD_JOB_QUEUE == 0)
#error NVM_SIZE_STANDARD_JOB_QUEUE have size 0
#endif
CirqBufferType nvmQueue;
/* ----------------------------[private functions]---------------------------*/
#if (NVM_SET_RAM_BLOCK_STATUS_API == STD_ON)
static void setRamBlockStatus( const NvM_BlockDescriptorType *bPtr,
AdministrativeBlockType *admPtr,
boolean blockChanged );
#endif
/* ----------------------------[public functions]----------------------------*/
/*
* This function needs to be implemented!
*/
static void CalcCrc(void)
{
// IMPROVEMENT: Calculate CRC
}
typedef struct {
boolean JobFinished;
Std_ReturnType JobStatus;
MemIf_JobResultType JobResult;
const NvM_BlockDescriptorType * BlockDescriptor;
AdministrativeBlockType * BlockAdmin;
} MemIfJobAdminType;
static MemIfJobAdminType MemIfJobAdmin = {
.JobFinished = TRUE,
.JobStatus = E_OK,
.JobResult = MEMIF_JOB_OK,
.BlockDescriptor = NULL,
.BlockAdmin = NULL
};
typedef struct {
NvmStateType state;
uint16 currBlockIndex; // Keeps track of next unfinished block
NvM_RequestResultType PendingErrorStatus; // Status from multi block requests i.e. Read/Write/CancelWrite-all
uint8 serviceId;
} AdminMultiReqType;
static AdminMultiReqType AdminMultiReq;
/*
* Set the MemIf job as busy
*/
static void SetMemifJobBusy()
{
MemIfJobAdmin.JobFinished = FALSE;
}
/*
* Abort the MemIf job with E_NOT_OK
*/
static void AbortMemIfJob(MemIf_JobResultType jobResult)
{
MemIfJobAdmin.JobFinished = TRUE;
MemIfJobAdmin.JobStatus = E_NOT_OK;
MemIfJobAdmin.JobResult = jobResult;
}
/*
* Initiate the read all job
*/
static boolean ReadAllInit(void)
{
/*
* Initiate the read all job
*/
const NvM_BlockDescriptorType *BlockDescriptorList = NvM_Config.BlockDescriptor;
AdministrativeBlockType *AdminBlockTable = AdminBlock;
uint16 i;
boolean needsProcessing = FALSE;
// Set status to pending in the administration blocks
AdminMultiBlock.ErrorStatus = NVM_REQ_PENDING;
AdminMultiReq.PendingErrorStatus = NVM_REQ_OK;
AdminMultiReq.currBlockIndex = 0;
for (i = 0; i < ( NVM_NUM_OF_NVRAM_BLOCKS ); i++) {
/* @req NVM304 *//* @req NVM118 */
if ((BlockDescriptorList->SelectBlockForReadall == TRUE)
#if (NVM_SET_RAM_BLOCK_STATUS_API == STD_ON) /** @req NVM345 */
&& ((AdminBlockTable->BlockValid==FALSE) // IMPROVEMENT: Check if this is to be done like this
|| (AdminBlockTable->BlockChanged==FALSE)) // IMPROVEMENT: Check if this is to be done like this
#endif
) {
NVM_ASSERT((BlockDescriptorList->RamBlockDataAddress != NULL));
DET_VALIDATE_RV((BlockDescriptorList->RamBlockDataAddress != NULL), NVM_READ_ALL_ID, NVM_E_WRONG_CONFIG, FALSE );
/* @req NVM245 */
NVM_ASSERT((BlockDescriptorList->BlockManagementType != NVM_BLOCK_DATASET));
DET_VALIDATE_RV((BlockDescriptorList->BlockManagementType != NVM_BLOCK_DATASET), NVM_READ_ALL_ID, NVM_E_WRONG_CONFIG, FALSE );
AdminBlockTable->ErrorStatus = NVM_REQ_PENDING;
AdminBlockTable->BlockState = BLOCK_STATE_MEMIF_REQ;
needsProcessing = TRUE;
} else {
AdminBlockTable->ErrorStatus = NVM_REQ_BLOCK_SKIPPED; /* @req NVM287 */
}
AdminBlockTable++;
BlockDescriptorList++;
}
return needsProcessing;
}
static void writeCrcToBuffer( uint8 *bufPtr,
const NvM_BlockDescriptorType *bPtr,
const AdministrativeBlockType *admPtr )
{
if( bPtr->BlockUseCrc == TRUE ) {
if(bPtr->BlockCRCType == NVM_CRC16) {
WRITE16_NA((&bufPtr[bPtr->NvBlockLength]),admPtr->RamCrc.crc16);
} else {
WRITE32_NA((&bufPtr[bPtr->NvBlockLength]),admPtr->RamCrc.crc32);
}
}
}
#define REDUNDANT_BLOCK_OK 0
#define REDUNDANT_BLOCK_BOTH_FAIL 1
static boolean handleRedundantBlock(const NvM_BlockDescriptorType *bPtr,
AdministrativeBlockType *admPtr ) {
boolean cont = 0;
/* According to 3.1.5/NVM137 we have 2 NV Blocks and 0..1 ROM Blocks */
/* Req 3.1.5/NVM199 , 3.1.5/NVM279 , 3.1.5/NVM317
* 3.1.5/NVM288, 3.1.5/NVM315
* */
/* @req NVM199 */
/* @req NVM288 */
/* @req NVM343 *//* Use of data index */
if ( bPtr->BlockManagementType == NVM_BLOCK_REDUNDANT ) {
if( admPtr->flags == 1 ) {
NVM_ASSERT((bPtr->NvBlockNum == 2)); /* Configuration error */
admPtr->DataIndex = ((admPtr->DataIndex!=0u) ? 0u : 1u);
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
DEBUG_FPUTS(" # First redundant NV block failed\n");
cont = 1;
} else {
DEBUG_FPUTS(" # Both redundant NV blocks failed\n");
}
admPtr->flags++;
}
return cont;
}
/*
* Drive the read state-machine
*
*
*
*/
static boolean DriveBlock( const NvM_BlockDescriptorType *bPtr,
AdministrativeBlockType *admPtr,
void *dataPtr,
boolean isWrite,
boolean multiBlock,
boolean restoreFromRom )
{
/* Define a work buffer that needs have size aligned to atleast xxx_VIRTUAL_PAGE_SIZE
* + 4 is since the buffer may have CRC */
/* !req NVM544 Depending on the config, NvM module shall allocate memory for the largest CRC used.*/
static uint8 Nvm_WorkBuffer[ _ALIGN(NVM_MAX_BLOCK_LENGTH,VIRTUAL_PAGE_SIZE) + VIRTUAL_PAGE_SIZE ];
/* @req NVM270 *//* If the NvM module has successfully processed a job, it shall return NVM_REQ_OK as job result. */
boolean blockDone;
boolean status;
status = TRUE;
blockDone = 0;
DEBUG_BLOCK_STATE("DriveBlock", BLOCK_NR_FROM_PTR(bPtr), admPtr->BlockState );
NVM_ASSERT((admPtr->ErrorStatus == NVM_REQ_PENDING));
switch (admPtr->BlockState) {
case BLOCK_STATE_MEMIF_REQ:
{
boolean fail = FALSE;
Std_ReturnType rv;
void *ramData;
ramData = (dataPtr != NULL) ? dataPtr : bPtr->RamBlockDataAddress;
admPtr->savedDataPtr = ramData;
if( isWrite == TRUE) {
/* @req NVM209 *//* NvM_WriteBlock checks write protection. But we don't do it here */
if( (multiBlock!=0u) && (dataPtr!=NULL)) {
NVM_ASSERT(FALSE); /*lint !e9027 !e774 Boolean within 'if' always evaluates to True is exception */
}
/* Copy to work buffer */
memcpy( Nvm_WorkBuffer, ramData, bPtr->NvBlockLength );
/* Add the CRC to write */
writeCrcToBuffer(Nvm_WorkBuffer, bPtr, admPtr );
/*
* Write the block
*/
/* @req NVM445 */
if (admPtr->DataIndex < bPtr->NvBlockNum) {
SetMemifJobBusy();
MemIfJobAdmin.BlockAdmin = admPtr;
MemIfJobAdmin.BlockDescriptor = bPtr;
SchM_Enter_NvM_EA_0();
/* @req NVM338 *//* @req NVM339 */
rv = MemIf_Write(bPtr->NvramDeviceId, BLOCK_BASE_AND_SET_TO_BLOCKNR(bPtr->NvBlockBaseNumber, admPtr->DataIndex), Nvm_WorkBuffer);
if (rv != E_OK) {
if ( MemIf_GetStatus(bPtr->NvramDeviceId) == MEMIF_IDLE ) {
AbortMemIfJob(MEMIF_JOB_FAILED);
fail = TRUE;
} else {
/* Do nothing. For MEMIF_UNINIT, MEMIF_BUSY and MEMIF_BUSY_INTERNAL we just stay in the
* same state. Better in the next run */
SchM_Exit_NvM_EA_0();
break; /* Do NOT advance to next state */
}
}
SchM_Exit_NvM_EA_0();
} else {
// Error: setNumber out of range
DET_REPORTERROR(NVM_LOC_WRITE_BLOCK_ID, NVM_PARAM_OUT_OF_RANGE);
fail = TRUE;
}
if (fail==TRUE) {
/* Fail the job */
admPtr->ErrorStatus = NVM_REQ_NOT_OK;
blockDone = 1;
/* @req NVM680 *//* We do not change the validity of the ram block and it is set to invalid at init */
break; /* Do NOT advance to next state */
}
} else {
uint8 crcLen = 0;
/* Read to workbuffer */
if( bPtr->BlockUseCrc == TRUE ) {
crcLen = (bPtr->BlockCRCType == NVM_CRC16) ? 2: 4;
}
if( restoreFromRom==TRUE ) {
/* @req NVM267 */
/* !req NVM266 Restoring defaults via callback not supported */
/* @req NVM392 */
NVM_ASSERT(( bPtr->RomBlockDataAdress != NULL ));
/* No CRC on the ROM block */
memcpy((void*)ramData,bPtr->RomBlockDataAdress,bPtr->NvBlockLength);
admPtr->ErrorStatus = NVM_REQ_OK;
blockDone = 1;
break; /* Do NOT advance to next state */
} else {
uint8 setNumber = admPtr->DataIndex;
uint16 length = bPtr->NvBlockLength+crcLen;
/*
* Read the Block
*/
/* @req NVM445 */
if (setNumber < bPtr->NvBlockNum) {
SetMemifJobBusy();
MemIfJobAdmin.BlockAdmin = admPtr;
MemIfJobAdmin.BlockDescriptor = bPtr;
/* First reading the MemIf block and then checking MemIf_GetStatus() to determine
* if the device BUSY in anyway...is not threadsafe. The way Autosar have defined
* it you would have to lock over the MemIf_Read() to be sure.
*/
SchM_Enter_NvM_EA_0();
/* We want to read from MemIf, but the device may be busy.
*/
rv = MemIf_Read(bPtr->NvramDeviceId,
BLOCK_BASE_AND_SET_TO_BLOCKNR(bPtr->NvBlockBaseNumber, setNumber),
0,
Nvm_WorkBuffer,
length );
if (rv != E_OK) {
/* !req NVM657 Default values not loaded */
/* !req NVM679 Default values not loaded */
if ( MemIf_GetStatus(bPtr->NvramDeviceId) == MEMIF_IDLE ) {
AbortMemIfJob(MEMIF_JOB_FAILED);
fail = TRUE;
} else {
/* Do nothing. For MEMIF_UNINIT, MEMIF_BUSY and MEMIF_BUSY_INTERNAL we just stay in the
* same state. Better in the next run */
SchM_Exit_NvM_EA_0();
break; /* Do NOT advance to next state */
}
}
SchM_Exit_NvM_EA_0();
} else if (setNumber < (bPtr->NvBlockNum + bPtr->RomBlockNum)) {
// IMPROVEMENT: Read from ROM
/* !req NVM354 *//* !req NVM340 *//* !req NVM376 */
fail = TRUE;
} else {
// Error: setNumber out of range
DET_REPORTERROR(NVM_LOC_READ_BLOCK_ID, NVM_PARAM_OUT_OF_RANGE);
fail = TRUE;
}
if( TRUE == fail ) {
/* Fail the job */
admPtr->ErrorStatus = NVM_REQ_NOT_OK;
blockDone = 1;
break; /* Do NOT advance to next state */
}
}
}
admPtr->BlockState = BLOCK_STATE_MEMIF_PROCESS;
break;
}
case BLOCK_STATE_MEMIF_PROCESS:
{
void *ramData;
ramData = ( dataPtr != NULL ) ? dataPtr : bPtr->RamBlockDataAddress;
if( ramData == NULL ){
blockDone = TRUE;
status = FALSE;
} else {
/* Check read */
MemIf_JobResultType jobResult = MemIf_GetJobResult(bPtr->NvramDeviceId);
if( MEMIF_JOB_PENDING == jobResult ) {
/* Keep on waiting */
} else if( MEMIF_JOB_OK == jobResult ) {
/* We are done */
if( isWrite==TRUE ) {
/* @req NVM284 *//* @req NVM337 */
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
admPtr->ErrorStatus = NVM_REQ_OK;
blockDone = 1;
} else {
/* read */
if( bPtr->BlockUseCrc ==TRUE ) {
/* The read data is in the work buffer, read the CRC */
if( bPtr->BlockCRCType == NVM_CRC16) {
admPtr->NvCrc.crc16 = READ16_NA( (&Nvm_WorkBuffer[bPtr->NvBlockLength]) );
DEBUG_PRINTF(">> Nv CRC %04x\n",admPtr->NvCrc.crc16);
admPtr->RamCrc.crc16 = admPtr->NvCrc.crc16; /* Set RAM CRC = NvRAM CRC */
} else {
admPtr->NvCrc.crc32 = READ32_NA( (&Nvm_WorkBuffer[bPtr->NvBlockLength]) );
DEBUG_PRINTF(">> Nv CRC %08x\n",admPtr->NvCrc.crc32);
admPtr->RamCrc.crc32 = admPtr->NvCrc.crc32; /* Set RAM CRC = NvRAM CRC */
}
/* 3.1.5/NVM201 + 3.1.5/NVM292 NvM_ReadBlock() + NvM_ReadAll() should request
* recalculation of the RAM block data if configured with CRC.
*/
/* savedDataPtr points to the real data buffers and they do no contain the
* crcLen */
/* IMPROVEMENT: Should we really copy here in case crc should be checked? */
memcpy(admPtr->savedDataPtr, Nvm_WorkBuffer, bPtr->NvBlockLength );
/* Check if we should re-calculate the RAM checksum now when it's in RAM
* 3.1.5/NVM165 */
if( bPtr->CalcRamBlockCrc==TRUE) {
/* This block want its RAM block CRC checked *//* @req NVM201 *//* @req NVM292 */
DEBUG_PRINTF(">> Recalculation of RAM checksum \n",admPtr->NvCrc.crc16);
ASSERT( bPtr->BlockUseCrc == 1);
admPtr->BlockState = BLOCK_STATE_CALC_CRC_READ;
admPtr->BlockSubState = BLOCK_SUBSTATE_0;
admPtr->flags = 0;
} else {
/* Done */
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
admPtr->ErrorStatus = NVM_REQ_OK;/* @req NVM206 *//* @req NVM279 *//* @req NVM290 *//* @req NVM291 */
blockDone = 1;
}
} else {
DEBUG_FPUTS(">> Block have NO CRC\n");
memcpy(admPtr->savedDataPtr, Nvm_WorkBuffer, bPtr->NvBlockLength );
/* Done */
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
admPtr->ErrorStatus = NVM_REQ_OK;/* @req NVM206 *//* @req NVM279 *//* @req NVM290 *//* @req NVM291 */
blockDone = 1;
}
/* Copy from Workbuffer to the real buffer */
}
break;
} else {
/* Something failed */
DEBUG_FPUTS(">> Read/Write FAILED\n");
if( isWrite==TRUE ) {
/* @req NVM213 *//* @req NVM296 */
admPtr->NumberOfWriteFailed++;
/* !req NVM216 Num write retries should be configurable per block */
/* !req NVM683 Num write retries should be configurable per block */
/* @req NVM168 */
if( admPtr->NumberOfWriteFailed > NVM_MAX_NUMBER_OF_WRITE_RETRIES ) {
/* !req NVM659 Error not reported to Dem */
/* !req NVM684 Error not reported to Dem */
DEBUG_FPUTS(">> Write FAILED COMPLETELY (all retries)\n");
blockDone = 1;
admPtr->NumberOfWriteFailed = 0;
}
} else {
blockDone = 1;
}
/*
* MEMIF have failed. Now what?
* 1. Check if redundant, if so read the other block
* 2. If point 1 fails and not redundant nor rom-block/initcallback,
* fail with MEMIF_BLOCK_INVALID, MEMIF_BLOCK_INCONSISTENT or MEMIF_JOB_FAILED
*/
if( blockDone == 1 ) {
/* All write have failed or we are reading? */
/* @req NVM655 *//* We don't report error if first block fails (REDUNDANT) */
if( 0 == handleRedundantBlock(bPtr,admPtr) ) {
/* block is NOT redundant or both blocks have failed */
/*
*
* Returned status are:
*
* MEMIF_BLOCK_INVALID
* The block is currenlty under some strange service (Fee_InvalidateBlock)
*
* MEMIF_BLOCK_INCONSISTENT
* Ea/Fee have detected that something is strange with the block. This may
* happen for a virgin unit.
*
* MEMIF_JOB_FAILED
* We failed for some reason.
*
* At this point a lot of requirements NVM360, NVM342,etc will not be active
* if there is a configured ROM block/InitCallback.
*/
switch (jobResult) {
case MEMIF_BLOCK_INVALID:
/* @req NVM355 *//* @req NVM341 *//* @req NVM652 *//* @req NVM317 *//* @req NVM315 *//* @req NVM342 *//* @req NVM676 */
admPtr->ErrorStatus = NVM_REQ_NV_INVALIDATED;
break;
case MEMIF_BLOCK_INCONSISTENT:
/* /NVM360 but is overridden by NVM172 (implicit revovery) */
/* @req NVM651 *//* @req NVM358 *//* @req NVM360 */
admPtr->ErrorStatus = NVM_REQ_INTEGRITY_FAILED;
/* @req NVM653 *//* @req NVM677 *//* @req NVM591 */
DEM_REPORTERRORSTATUS(NvM_Config.DemEvents.NvMIntegrityFailedDemEventId, DEM_EVENT_STATUS_FAILED);
break;
case MEMIF_JOB_FAILED:
/* @req NVM361 */
/* @req NVM359 *//* @req NVM213 (Assuming that we get job failed on write failure) */
admPtr->ErrorStatus = NVM_REQ_NOT_OK;
/* @req NVM654 *//* @req NVM678 *//* @req NVM302 *//* @req NVM592 */
DEM_REPORTERRORSTATUS(NvM_Config.DemEvents.NvMReqFailedDemEventId, DEM_EVENT_STATUS_FAILED);
break;
default:
DEBUG_PRINTF("## Unexpected jobResult:%d\n",jobResult);
NVM_ASSERT(FALSE);/*lint !e9027 !e774 Boolean within 'if' always evaluates to True exception is required */
break;
}
/* IMPROVEMENT: No copy of ROM block if DATASET */
/* @req NVM172 NV block not changed during implicit recovery */
/* @req NVM388 *//* @req NVM389 *//* @req NVM390 */
/* @req NVM572 (ROM block configured == by the parameter NvMRomBlockDataAddress or the parameter NvMInitBlockCallback) */
if( ( FALSE == isWrite ) && (( bPtr->RomBlockDataAdress != NULL) ||( bPtr->InitBlockCallback != NULL) ) ){
if( bPtr->RomBlockDataAdress != NULL ) {/* @req NVM139 */
DEBUG_FPUTS("Copying ROM data to block\n");
memcpy(ramData, bPtr->RomBlockDataAdress,bPtr->NvBlockLength);
admPtr->ErrorStatus = NVM_REQ_OK;
} else if( bPtr->InitBlockCallback != NULL ) {
/* @req NVM469 */
DEBUG_FPUTS("Filling block with default data\n");
/* @req NVM369 */
(void)bPtr->InitBlockCallback();
admPtr->ErrorStatus = NVM_REQ_OK;
}else{
/* do nothing */
}
} else {
/* @req NVM085 */
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ; /* NOTE, this really true for all result below */
AdminMultiReq.PendingErrorStatus = NVM_REQ_NOT_OK;
}
}
}
}
}
break;
}
case BLOCK_STATE_CALC_CRC:
NVM_ASSERT(FALSE); /*lint !e9027 !e774 Boolean within 'if' always evaluates to True */
break;
case BLOCK_STATE_CALC_CRC_WRITE:
{
uint16 crc16;
uint32 crc32;
/* bPtr->RamBlockDataAddress dataPtr
* NULL NULL #BAD
* NULL data Use dataPtr
* data NULL Use RamBlockDataAddress
* data data Use dataPtr
* */
const void *ramData = ( dataPtr != NULL ) ? dataPtr : bPtr->RamBlockDataAddress;
NVM_ASSERT( (ramData != NULL) );
/* Calculate RAM CRC checksum */
/* !req NVM351 Initial values published by CRC module not used */
if( bPtr->BlockCRCType == NVM_CRC16 ) {
crc16 = Crc_CalculateCRC16(ramData,bPtr->NvBlockLength, 0xffff, TRUE);
DEBUG_CHECKSUM("RAM",crc16);
/* Just save the checksum */
admPtr->RamCrc.crc16 = crc16;
/* Write the block */
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
} else {
crc32 = Crc_CalculateCRC32(ramData,bPtr->NvBlockLength,0xffffffffUL, TRUE);
DEBUG_CHECKSUM("RAM",crc32);
admPtr->RamCrc.crc32 = crc32;
}
/* Write the block */
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
break;
}
case BLOCK_STATE_CALC_CRC_READ:
{
//NVM_ASSERT(bPtr->RamBlockDataAddress != NULL );
NVM_ASSERT((bPtr->CalcRamBlockCrc == true));
uint16 crc16 = 0;
uint32 crc32 = 0;
boolean checksumOk;
/* Calculate CRC on the data we just read to RAM. Compare with CRC that is located in NV block */
/* !req NVM351 Initial values published by CRC module not used */
if( bPtr->BlockCRCType == NVM_CRC16 ) {
crc16 = Crc_CalculateCRC16(admPtr->savedDataPtr,bPtr->NvBlockLength,0xffff, TRUE);
} else {
crc32 = Crc_CalculateCRC32(admPtr->savedDataPtr,bPtr->NvBlockLength,0xffffffffUL, TRUE);
}
switch( admPtr->BlockSubState ) {
case BLOCK_SUBSTATE_0:
checksumOk = ( bPtr->BlockCRCType == NVM_CRC16 ) ? ( crc16 == admPtr->RamCrc.crc16 ) : ( crc32 == admPtr->RamCrc.crc32 );
/* @req NVM387 */
if( checksumOk == true) {
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
DEBUG_CHECKSUM("RAM checksum ok with ", ( bPtr->BlockCRCType == NVM_CRC16 ) ? crc16 : crc32 );
admPtr->ErrorStatus = NVM_REQ_OK;/* @req NVM206 *//* @req NVM279 *//* @req NVM290 *//* @req NVM291 */
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
blockDone = 1;
} else {
/* NVM387, NVM388
* Corrupt CRC, what choices are there:
* 1. Default data (=ROM) configured, just copy it.
* 2. Data redundancy, get it.
* 3. None of the above. Catastrophic failure. (NVM203)
*/
if( 0 == handleRedundantBlock(bPtr,admPtr) ) {
/* block is NOT redundant or both blocks have failed */
/* IMPROVEMENT: No copy from ROM if DATASET? */
/* @req NVM202 *//* @req NVM363 *//* @req NVM293 *//* @req NVM169 */
/* @req NVM172 NV block not changed during implicit recovery */
/* @req NVM388 *//* @req NVM389 *//* @req NVM390 */
/* @req NVM572 (ROM block configured == by the parameter NvMRomBlockDataAddress or the parameter NvMInitBlockCallback) */
if( bPtr->RomBlockDataAdress != NULL ) {/* @req NVM139 */
DEBUG_FPUTS("Copying ROM data to block\n");
/* IMPROVEMENT: Shouldn't this copy be to admPtr->savedDataPtr? */
memcpy(admPtr->savedDataPtr, bPtr->RomBlockDataAdress,bPtr->NvBlockLength);
admPtr->BlockSubState = BLOCK_SUBSTATE_1;
} else {
/* @req NVM469 */
if( bPtr->InitBlockCallback != NULL ) {
DEBUG_FPUTS("Filling block with default data\n");
/* @req NVM369 */
(void)bPtr->InitBlockCallback();
admPtr->BlockSubState = BLOCK_SUBSTATE_1;
/* The RAM CRC is at this point not calculated...so we must do this
* .. so just stay in this state one more MainFunction.
* */
} else {
/* @req NVM085 */
/* We have CRC mismatch -> FAIL */
DEBUG_FPUTS("### Block FAILED with NVM_REQ_INTEGRITY_FAILED\n");
/* @req NVM203 *//* @req NVM294 *//* @req NVM591 */
DEM_REPORTERRORSTATUS(NvM_Config.DemEvents.NvMIntegrityFailedDemEventId, DEM_EVENT_STATUS_FAILED);
/* @req NVM204 *//* @req NVM295 */
admPtr->ErrorStatus = NVM_REQ_INTEGRITY_FAILED;
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
blockDone = 1;
}
}
}
}
break;
case BLOCK_SUBSTATE_1:
/* The checksum is on the ROM data so just save it */
DEBUG_CHECKSUM("RAM checksum after ROM copy ", ( bPtr->BlockCRCType == NVM_CRC16 ) ? crc16 : crc32 );
if( bPtr->BlockCRCType == NVM_CRC16 ) {
admPtr->RamCrc.crc16 = crc16;
} else {
admPtr->RamCrc.crc32 = crc32;
}
admPtr->BlockSubState = BLOCK_SUBSTATE_0;
admPtr->ErrorStatus = NVM_REQ_INTEGRITY_FAILED;
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
blockDone = 1;
break;
default:
break;
}
break;
}
default:
NVM_ASSERT(FALSE);/*lint !e9027 !e774 Boolean within 'if' always evaluates to True exception is required */
break;
}
if (status == TRUE) {
if( blockDone==TRUE ) {
DEBUG_FPUTS("# Block Done\n");
if( admPtr->ErrorStatus == NVM_REQ_OK ) {
/* @req NVM200 *//* @req NVM251 *//* @req NVM472 */
/* !req NVM366 Block not assumed changed when default values copied */
/* !req NVM228 Block not assumed changed when default values copied */
/* @req NVM367 *//* ErrorStatus set to OK if default values copied */
admPtr->BlockChanged = FALSE;
admPtr->BlockValid = TRUE;
}
/* @req NVM281 *//* @req NVM742 */
if( bPtr->SingleBlockCallback != NULL ) {
/* @req NVM368 *//* @req NVM740 *//* @req NVM741 *//* @req NVM176 */
(void)bPtr->SingleBlockCallback(serviceId, admPtr->ErrorStatus);
}
if( multiBlock==FALSE ) {
nvmState = NVM_IDLE;
nvmSubState =NS_INIT;
}
}
}
return blockDone;
}
static void MultiblockMain( boolean isWrite ) {
/* Cases:
* 1. We process each block until it's finished
* 2. We start to process a lot of blocks. The blocks may use different devices
* and should be able to read a lot of them. This includes CRC.
*
* 1) is much simpler and 2) probably much faster.
* This implementation will use 1) since it's simpler and maximum time that is
* spent in MainFunction() can be controlled much better.
*/
/* @req NVM244 */
while ( (AdminMultiReq.currBlockIndex < NVM_NUM_OF_NVRAM_BLOCKS) ) {
/* @req NVM434 */
if( AdminBlock[AdminMultiReq.currBlockIndex].ErrorStatus != NVM_REQ_BLOCK_SKIPPED) {
if( FALSE == DriveBlock( &NvM_Config.BlockDescriptor[AdminMultiReq.currBlockIndex],
&AdminBlock[AdminMultiReq.currBlockIndex],
NULL, isWrite, true, false ) )
{
/* Drive block have more job to do.. wait until next time */
break;
}
}
AdminMultiReq.currBlockIndex++;
}
/* Check if we are the last block */
if( AdminMultiReq.currBlockIndex >= NVM_NUM_OF_NVRAM_BLOCKS ) {
AdminMultiReq.currBlockIndex = 0;
/* @req NVM301 *//* @req NVM318 *//* @req NVM395 */
if( NVM_REQ_NOT_OK == AdminMultiReq.PendingErrorStatus ) {
AdminMultiBlock.ErrorStatus = NVM_REQ_NOT_OK;
} else {
AdminMultiBlock.ErrorStatus = NVM_REQ_OK;
}
/* Reset state machine */
nvmState = NVM_IDLE;
nvmSubState = NS_INIT;
/* @req NVM468 */
if( NvM_Config.Common.MultiBlockCallback != NULL ) {
/* @req NVM686 */
NvM_Config.Common.MultiBlockCallback(serviceId, AdminMultiBlock.ErrorStatus);
}
}
}
/*
* Initiate the write all job
*/
static boolean WriteAllInit(void)
{
/* !req NVM252 Parameter NvMSelectBlockForWriteAll not supported */
const NvM_BlockDescriptorType *BlockDescriptorList = NvM_Config.BlockDescriptor;
AdministrativeBlockType *AdminBlockTable = AdminBlock;
uint16 i;
boolean needsProcessing = FALSE;
// nvmState = NVM_WRITE_ALL_PROCESSING;
AdminMultiReq.PendingErrorStatus = NVM_REQ_OK;
AdminMultiReq.currBlockIndex = 0;
for (i = 0; i < NVM_NUM_OF_NVRAM_BLOCKS; i++) {
if ((BlockDescriptorList->RamBlockDataAddress != NULL)
#if (NVM_SET_RAM_BLOCK_STATUS_API == STD_ON) /** @req NVM344 */
&& (AdminBlockTable->BlockValid == TRUE) /** @req NVM682 */
&& (AdminBlockTable->BlockChanged == TRUE) /** @req NVM682 */
#endif
&& (AdminBlockTable->BlockWriteProtected == FALSE) /** @req NVM432 *//** @req NVM433 */
&& (AdminBlockTable->DataIndex < BlockDescriptorList->NvBlockNum))/* @req NVM377 *//* Treat write to ROM block like write to protected */
{
AdminBlockTable->ErrorStatus = NVM_REQ_PENDING;/* @req NVM549 */
if (BlockDescriptorList->BlockUseCrc == TRUE) {
AdminBlockTable->BlockState = BLOCK_STATE_CALC_CRC_WRITE; /** @req NVM253 */
} else {
AdminBlockTable->BlockState = BLOCK_STATE_MEMIF_REQ;
AdminBlockTable->NumberOfWriteFailed = 0;
}
needsProcessing = TRUE;
} else {
AdminBlockTable->ErrorStatus = NVM_REQ_BLOCK_SKIPPED; /** @req NVM298 */
}
AdminBlockTable++;
BlockDescriptorList++;
}
return needsProcessing;
}
/***************************************
* External accessible functions *
***************************************/
/*
* Procedure: NvM_Init
* Reentrant: No
*/
/* @req NVM447 */
void NvM_Init(void)
{
/* IMPROVEMENT: Validate configuration? E.g. NATIVE block has 1 nvBlock. */
/** @req NVM399 *//** @req NVM193 *//** @req NVM400 */
/* @req NVM091 */
/* @req NVM157 */
static Nvm_QueueType nvmQueueData[NVM_SIZE_STANDARD_JOB_QUEUE];
const NvM_BlockDescriptorType *BlockDescriptorList = NvM_Config.BlockDescriptor;
AdministrativeBlockType *AdminBlockTable = AdminBlock;
uint16 i;
CirqBuff_Init(&nvmQueue,nvmQueueData,sizeof(nvmQueueData)/sizeof(Nvm_QueueType),sizeof(Nvm_QueueType));
// Initiate the administration blocks
for (i = 0; i< NVM_NUM_OF_NVRAM_BLOCKS; i++) {
if (BlockDescriptorList->BlockManagementType == NVM_BLOCK_DATASET) {
AdminBlockTable->DataIndex = 0; /** @req NVM192 */
}
AdminBlockTable->BlockWriteProtected = BlockDescriptorList->BlockWriteProt;/* @req NVM326 */
AdminBlockTable->ErrorStatus = NVM_REQ_NOT_OK;
AdminBlockTable->BlockChanged = FALSE;
AdminBlockTable->BlockValid = FALSE;
AdminBlockTable->NumberOfWriteFailed = 0;
AdminBlockTable++;
BlockDescriptorList++;
}
AdminMultiBlock.ErrorStatus = NVM_REQ_NOT_OK;
(void)MemIfJobAdmin.JobFinished;/* Just to make lint happy */
// Set status to initialized
nvmState = NVM_IDLE;
}
/**
*
* Note!
* NvM_ReadAll() does not set status here or need to check status of the
* any blocks since it's done after all single reads are done.
*/
/* @req NVM460 */
void NvM_ReadAll(void)
{
/* !req NVM364 *//* What does this mean? Should we recalculate the RAM crc before requesting block read? */
/* !req NVM362 *//* What does this mean? Should we recalculate the RAM crc and not read the block if crc mtches the stored crc? */
/* !req NVM226 *//* What does this mean? */
/* @req NVM356 */
/* @req NVM646 */
DET_VALIDATE_NO_RV((nvmState != NVM_UNINITIALIZED), NVM_READ_ALL_ID, NVM_E_NOT_INITIALIZED);
SchM_Enter_NvM_EA_0();
/* @req NVM243 *//* Signal request and return */
AdminMultiReq.state = NVM_READ_ALL;
AdminMultiBlock.ErrorStatus = NVM_REQ_PENDING;/* @req NVM667 */
AdminMultiReq.serviceId = NVM_READ_ALL_ID;
SchM_Exit_NvM_EA_0();
}
/*
* Procedure: NvM_WriteAll
* Reentrant: No
*/
/* @req NVM461 */
void NvM_WriteAll(void)
{
/* @req NVM018 */
/* @req NVM647 */
DET_VALIDATE_NO_RV((nvmState != NVM_UNINITIALIZED), NVM_WRITE_ALL_ID, NVM_E_NOT_INITIALIZED);
SchM_Enter_NvM_EA_0();
/* @req NVM254 *//* Signal request and return */
AdminMultiReq.state = NVM_WRITE_ALL;
AdminMultiBlock.ErrorStatus = NVM_REQ_PENDING;
AdminMultiReq.serviceId = NVM_WRITE_ALL_ID;
SchM_Exit_NvM_EA_0();
}
/*
* Procedure: NvM_CancelWriteAll
* Reentrant: No
*/
void NvM_CancelWriteAll(void)
{
}
#if (NVM_API_CONFIG_CLASS > NVM_API_CONFIG_CLASS_2)
/* @req NVM459 */
Std_ReturnType NvM_InvalidateNvBlock( NvM_BlockIdType blockId )
{
Std_ReturnType status;
status = E_OK;
/* !req NVM385 Request queued if block already queued (when not using Det) or currently in progress */
Nvm_QueueType qEntry;
const NvM_BlockDescriptorType * bPtr;
AdministrativeBlockType * admPtr;
uint32 rv;
NVM_ASSERT( blockId >= 2 ); /* No support for lower numbers, yet */
/* @req NVM642 */
DET_VALIDATE_RV(blockId <= NVM_NUM_OF_NVRAM_BLOCKS,
NVM_INVALIDATENV_BLOCK_ID, NVM_E_PARAM_BLOCK_ID, E_NOT_OK);
/* @req NVM638 */
DET_VALIDATE_RV(nvmState != NVM_UNINITIALIZED,
NVM_INVALIDATENV_BLOCK_ID, NVM_E_NOT_INITIALIZED, E_NOT_OK);
bPtr = &NvM_Config.BlockDescriptor[blockId-1];
admPtr = &AdminBlock[blockId-1];
/* @req NVM639 ErrorStatus PENDING until finished */
DET_VALIDATE_RV((admPtr->ErrorStatus != NVM_REQ_PENDING),
NVM_INVALIDATENV_BLOCK_ID, NVM_E_BLOCK_PENDING , E_NOT_OK );
/* @req NVM423 */
/* @req NVM272 */
/* !req NVM273 Wrong Dem error reported*/
/* @req NVM664 */
if( (admPtr->BlockWriteProtected == TRUE) ||(admPtr->DataIndex >= bPtr->NvBlockNum)) {
/* If write protected or ROM block in dataset, return E_NOT_OK */
/* IMPROVEMENT: Wrong Dem error */
DEM_REPORTERRORSTATUS(NvM_Config.DemEvents.NvMIntegrityFailedDemEventId, DEM_EVENT_STATUS_FAILED);
DET_REPORTERROR(NVM_INVALIDATENV_BLOCK_ID, NVM_E_NV_WRITE_PROTECTED);
status = E_NOT_OK;
} else {
/* @req NVM424 */
/* @req NVM239 */
qEntry.blockId = blockId;
qEntry.op = NVM_INVALIDATE_NV_BLOCK;
qEntry.serviceId = NVM_INVALIDATENV_BLOCK_ID;
rv = (uint32)CirqBuffPush(&nvmQueue,&qEntry);
/* @req NVM386 */
if(0 != rv) {
DET_REPORTERROR(NVM_INVALIDATENV_BLOCK_ID, NVM_E_LIST_OVERFLOW);
/* @req NVM184 */
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/* @req NVM185 */
admPtr->ErrorStatus = NVM_REQ_PENDING;
}
return status;
/* @req NVM422 Leave the RAM block unmodified */
}
Std_ReturnType NvM_SetBlockProtection( NvM_BlockIdType blockId, boolean protectionEnabled ) {
(void) blockId;
(void) protectionEnabled;
// Empty for now
return E_NOT_OK;
}
Std_ReturnType NvM_EraseNvBlock( NvM_BlockIdType blockId ) {
(void) blockId;
// Empty for now
return E_NOT_OK;
}
#endif
/*
* Procedure: NvM_GetErrorStatus
* Reentrant: Yes
*/
/* @req NVM451 */
Std_ReturnType NvM_GetErrorStatus(NvM_BlockIdType blockId, NvM_RequestResultType *requestResultPtr)
{
/* @req NVM083 */
/* @req NVM610 */
DET_VALIDATE_RV((nvmState != NVM_UNINITIALIZED), NVM_GET_ERROR_STATUS_ID, NVM_E_NOT_INITIALIZED, E_NOT_OK );
/* @req NVM611 */
DET_VALIDATE_RV((blockId < (NVM_NUM_OF_NVRAM_BLOCKS+1)), NVM_GET_ERROR_STATUS_ID, NVM_E_PARAM_BLOCK_ID, E_NOT_OK );
/* @req NVM612 */
DET_VALIDATE_RV((NULL != requestResultPtr), NVM_GET_ERROR_STATUS_ID, NVM_E_PARAM_DATA, E_NOT_OK );
/* @req NVM015 */
if (blockId == 0) {
// Multiblock ID
/* @req NVM394 */
*requestResultPtr = AdminMultiBlock.ErrorStatus;
} else if (blockId == 1) {
/* IMPROVEMENT Configuration ID */
*requestResultPtr = NVM_REQ_OK;
} else {
*requestResultPtr = AdminBlock[blockId-1].ErrorStatus;
}
return E_OK;
}
#if (NVM_SET_RAM_BLOCK_STATUS_API == STD_ON) /** @req NVM408 */
/*
* Procedure: Nvm_SetRamBlockStatus
* Reentrant: Yes
*/
/* @req NVM453 */
Std_ReturnType NvM_SetRamBlockStatus(NvM_BlockIdType blockId, boolean blockChanged)
{
AdministrativeBlockType * admPtr;
/* @req NVM645 */
DET_VALIDATE_RV((blockId < (NVM_NUM_OF_NVRAM_BLOCKS+1)), NVM_SET_RAM_BLOCK_STATUS_ID, NVM_E_PARAM_BLOCK_ID, E_NOT_OK);
admPtr = &AdminBlock[blockId-1];
/* @req NVM643 */
DET_VALIDATE_RV((nvmState != NVM_UNINITIALIZED), NVM_SET_RAM_BLOCK_STATUS_ID, NVM_E_NOT_INITIALIZED, E_NOT_OK);
DET_VALIDATE_RV((blockId > 1u), NVM_SET_RAM_BLOCK_STATUS_ID, NVM_E_PARAM_BLOCK_ID, E_NOT_OK );
/* @req NVM644 ErrorStatus PENDING until finished */
DET_VALIDATE_RV( (admPtr->ErrorStatus != NVM_REQ_PENDING), NVM_SET_RAM_BLOCK_STATUS_ID, NVM_E_BLOCK_PENDING , E_NOT_OK );
setRamBlockStatus(&NvM_Config.BlockDescriptor[blockId-1],admPtr,blockChanged );
return E_OK;
}
static void setRamBlockStatus( const NvM_BlockDescriptorType *bPtr, AdministrativeBlockType *admPtr, boolean blockChanged ) {
if (bPtr->RamBlockDataAddress != NULL) { /** @req NVM240 */
if (blockChanged == TRUE) {
admPtr->BlockChanged = TRUE; /** @req NVM406 */
admPtr->BlockValid = TRUE; /** @req NVM241 */
// IMPROVEMENT if (bPtr->BlockUseCrc) {
// admPtr->BlockState = BLOCK_STATE_CALC_CRC; /** !req NVM121 */
// }
} else {
admPtr->BlockChanged = FALSE; /** @req NVM405 */
admPtr->BlockValid = FALSE;
} // else blockChanged
} // if permanent block
}
#endif
void NvM_SetBlockLockStatus( NvM_BlockIdType blockId, boolean blockLocked ) {
(void)blockId;
(void)blockLocked;
}
/**
* Restore default data to its corresponding RAM block.
*
* @param BlockId NVRAM block identifier.
* @param NvM_DestPtr Pointer to the RAM block
* @return
*/
/* @req NVM456 */
Std_ReturnType NvM_RestoreBlockDefaults( NvM_BlockIdType blockId, void* NvM_DestPtr )
{
/* @req NVM012 */
/* !req NVM628 */
/* !req NVM385 Request queued if block already queued (when not using Det) or currently in progress */
/* @req NVM391 */
Std_ReturnType status;
status = E_OK;
const NvM_BlockDescriptorType * bPtr;
AdministrativeBlockType * admPtr;
Nvm_QueueType qEntry;
uint32 rv;
NVM_ASSERT( blockId >= 2 ); /* No support for lower numbers, yet */
/* @req NVM625 */
DET_VALIDATE_RV(nvmState != NVM_UNINITIALIZED, NVM_RESTORE_BLOCK_DEFAULTS_ID, NVM_E_NOT_INITIALIZED, E_NOT_OK );
/* @req NVM630 */
DET_VALIDATE_RV( (blockId <= NVM_NUM_OF_NVRAM_BLOCKS), NVM_RESTORE_BLOCK_DEFAULTS_ID, NVM_E_PARAM_BLOCK_ID,E_NOT_OK );
bPtr = &NvM_Config.BlockDescriptor[blockId-1];
admPtr = &AdminBlock[blockId-1];
/* It must be a permanent RAM block but no RamBlockDataAddress -> error */
/* @req NVM435 *//* @req NVM436 *//* @req NVM629 */
DET_VALIDATE_RV( !((NvM_DestPtr == NULL) && ( bPtr->RamBlockDataAddress == NULL )),
NVM_RESTORE_BLOCK_DEFAULTS_ID,NVM_E_PARAM_ADDRESS,E_NOT_OK );
/* @req NVM626 ErrorStatus PENDING until finished */
DET_VALIDATE_RV( (admPtr->ErrorStatus != NVM_REQ_PENDING), NVM_RESTORE_BLOCK_DEFAULTS_ID, NVM_E_BLOCK_PENDING , E_NOT_OK );
/* @req NVM353 */
if( (NVM_BLOCK_DATASET == bPtr->BlockManagementType) && (0 != bPtr->RomBlockNum) && (admPtr->DataIndex < bPtr->NvBlockNum) ) {
status = E_NOT_OK;
} else {
/* @req NVM224 */
qEntry.blockId = blockId;
qEntry.op = NVM_RESTORE_BLOCK_DEFAULTS;
qEntry.blockId = blockId;
qEntry.dataPtr = (uint8_t *)NvM_DestPtr;
qEntry.serviceId = NVM_RESTORE_BLOCK_DEFAULTS_ID;
rv = (uint32)CirqBuffPush(&nvmQueue,&qEntry);
/* @req NVM386 */
if(0 != rv) {
DET_REPORTERROR(NVM_RESTORE_BLOCK_DEFAULTS_ID, NVM_E_LIST_OVERFLOW);
/* @req NVM184 */
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/* @req NVM185 */
admPtr->ErrorStatus = NVM_REQ_PENDING;
if( bPtr->BlockUseCrc==TRUE) {
/* @req NVM229 */
admPtr->BlockState = BLOCK_STATE_CALC_CRC_WRITE;
} else {
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
}
}
return status;
}
/**
* Service to copy the data NV block to the RAM block
*
* @param blockId 0 and 1 reserved. The block ID are sequential.
* @param NvM_DstPtr
* @return
*/
/* @req NVM454 */
Std_ReturnType NvM_ReadBlock( NvM_BlockIdType blockId, void* NvM_DstPtr )
{
/* @req NVM010 */
/* !req NVM385 Request queued if block already queued (when not using Det) or currently in progress */
/* logical block:
*
* 1 1 1 1 1 1
* |5 4 3 2 1 0 9 8|7 6 5 4 3 2 1 0|
* b b b b b b b b b b d d d d d d
*
* Here we have 10 bits for block id, 16-5 for DataSetSelection bits.
* - 2^10, 1024 blocks
* - 64 datasets for each NVRAM block
*
* How are the block numbers done in EA? Assume virtual page=8
* logical
* Block size
* 1 32
* 2
* 3
* 4
* 5 12
* 6
* 7
*
* How can NVM/NvmNvBlockLength and EA/EaBlockSize be different?
* It seems that EA/FEE does not care about that logical block 2 above is
* "blocked"
*
*/
Nvm_QueueType qEntry;
uint32 rv;
/* !req NVM311 Request for reading block ID 1 allowed */
/* @req NVM614 */
DET_VALIDATE_RV(nvmState != NVM_UNINITIALIZED, NVM_READ_BLOCK_ID, NVM_E_NOT_INITIALIZED, E_NOT_OK );
/* @req NVM618 */
DET_VALIDATE_RV( blockId <= NVM_NUM_OF_NVRAM_BLOCKS, NVM_READ_BLOCK_ID,NVM_E_PARAM_BLOCK_ID,E_NOT_OK );
/** @req NVM196 */ /** @req NVM278 *//** @req NVM616 */
DET_VALIDATE_RV( !(( NvM_DstPtr == NULL) &&
( NvM_Config.BlockDescriptor[blockId-1].RamBlockDataAddress == NULL )),
0, NVM_E_PARAM_ADDRESS , E_NOT_OK );
/* @req NVM615 ErrorStatus PENDING until finished */
DET_VALIDATE_RV( (AdminBlock[blockId-1].ErrorStatus != NVM_REQ_PENDING), NVM_READ_BLOCK_ID, NVM_E_BLOCK_PENDING , E_NOT_OK );
/* @req NVM195 */
qEntry.op = NVM_READ_BLOCK;
qEntry.blockId = blockId;
qEntry.dataPtr = NvM_DstPtr;
qEntry.serviceId = NVM_READ_BLOCK_ID;
rv =(uint32)CirqBuffPush(&nvmQueue,&qEntry);
/* @req NVM386 */
if(0 != rv) {
DET_REPORTERROR(NVM_READ_BLOCK_ID, NVM_E_LIST_OVERFLOW);
/* @req NVM184 */
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/* @req NVM185 */
AdminBlock[blockId-1].ErrorStatus = NVM_REQ_PENDING;
return E_OK;
}
/**
* Service to copy a RAM block to its correspnding NVRAM block
*
* @param blockId
* @param NvM_SrcPtr
* @return
*/
/* @req NVM455 */
Std_ReturnType NvM_WriteBlock( NvM_BlockIdType blockId, const void* NvM_SrcPtr ) {
/* @req NVM410 */
/* !req NVM385 Request queued if block already queued (when not using Det) or currently in progress */
const NvM_BlockDescriptorType * bPtr;
AdministrativeBlockType * admPtr;
Nvm_QueueType qEntry;
uint32 rv;
NVM_ASSERT( blockId >= 2 ); /* No support for lower numbers, yet */
/* @req NVM619 */
DET_VALIDATE_RV(nvmState != NVM_UNINITIALIZED, NVM_WRITE_BLOCK_ID, NVM_E_NOT_INITIALIZED, E_NOT_OK );
/* @req NVM624 */
DET_VALIDATE_RV( blockId <= NVM_NUM_OF_NVRAM_BLOCKS, NVM_WRITE_BLOCK_ID, NVM_E_PARAM_BLOCK_ID, E_NOT_OK );
bPtr = &NvM_Config.BlockDescriptor[blockId-1];
admPtr = &AdminBlock[blockId-1];
/* !req NVM411 Error not reported to Dem */
/* @req NVM377 *//* Treat write to ROM block as write to protected nv block */
if((admPtr->BlockWriteProtected == TRUE) || !(admPtr->DataIndex < bPtr->NvBlockNum)) {
DET_REPORTERROR(NVM_WRITE_BLOCK_ID, NVM_E_NV_WRITE_PROTECTED);
/* @req NVM217 */
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/* @req NVM210 *//* @req NVM280 *//* @req NVM622 */
DET_VALIDATE_RV( !((NvM_SrcPtr == NULL) && ( bPtr->RamBlockDataAddress == NULL )),
NVM_WRITE_BLOCK_ID, NVM_E_PARAM_ADDRESS, E_NOT_OK );
/* @req NVM620 ErrorStatus PENDING until finished */
DET_VALIDATE_RV( (admPtr->ErrorStatus != NVM_REQ_PENDING), NVM_WRITE_BLOCK_ID, NVM_E_BLOCK_PENDING , E_NOT_OK );
/* @req NVM424 *//* @req NVM239 *//* @req NVM208 */
qEntry.blockId = blockId;
qEntry.op = NVM_WRITE_BLOCK;
qEntry.blockId = blockId;
qEntry.dataPtr = (uint8 *)NvM_SrcPtr; /*lint !e9005 attempt to cast away const/volatile from a pointer is rquired */
qEntry.serviceId = NVM_WRITE_BLOCK_ID;
rv =(uint32) CirqBuffPush(&nvmQueue,&qEntry);
/* @req NVM386 */
if(0 != rv) {
DET_REPORTERROR(NVM_WRITE_BLOCK_ID, NVM_E_LIST_OVERFLOW);
/* @req NVM184 */
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/* @req NVM185 */
admPtr->ErrorStatus = NVM_REQ_PENDING;
if( bPtr->BlockUseCrc==TRUE) {
/* @req NVM212 */
admPtr->BlockState = BLOCK_STATE_CALC_CRC_WRITE;
} else {
admPtr->BlockState = BLOCK_STATE_MEMIF_REQ;
}
return E_OK;
}
/* Missing from Class 2
* - NvM_CancelWriteAll
* */
#if (NVM_API_CONFIG_CLASS > NVM_API_CONFIG_CLASS_1)
/*
* Note!
* This function returns void in 3.1.5 and in 4.0 it returns Std_ReturnType.
*
*
* return
* x NVM_E_NOT_INITIALIZED
* x NVM_E_BLOCK_PENDING
* NVM_E_PARAM_BLOCK_DATA_IDX
* NVM_E_PARAM_BLOCK_TYPE
* x NVM_E_PARAM_BLOCK_ID
*
*/
/* @req NVM448 */
Std_ReturnType NvM_SetDataIndex( NvM_BlockIdType blockId, uint8 dataIndex ) {
/* @req NVM263 */
const NvM_BlockDescriptorType * bPtr = &NvM_Config.BlockDescriptor[blockId-1];
AdministrativeBlockType * admPtr = &AdminBlock[blockId-1];
NVM_ASSERT( blockId >= 2 ); /* No support for lower numbers, yet */
/* @req NVM027 */
DET_VALIDATE_RV(nvmState != NVM_UNINITIALIZED, NVM_SET_DATA_INDEX_ID, NVM_E_NOT_INITIALIZED, E_NOT_OK);
/* @req NVM601 */
DET_VALIDATE_RV(blockId < (NVM_NUM_OF_NVRAM_BLOCKS+1), NVM_SET_DATA_INDEX_ID, NVM_E_PARAM_BLOCK_ID, E_NOT_OK);
if( bPtr->BlockManagementType != NVM_BLOCK_DATASET ) {
/* @req NVM264 *//* @req NVM600 */
DET_REPORTERROR(NVM_SET_DATA_INDEX_ID, NVM_E_PARAM_BLOCK_TYPE);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/* @req NVM599 *//* @req NVM146 */
DET_VALIDATE_RV(dataIndex < (bPtr->NvBlockNum + bPtr->RomBlockNum) , NVM_SET_DATA_INDEX_ID, NVM_E_PARAM_BLOCK_DATA_IDX ,E_NOT_OK);
/* @req NVM598 ErrorStatus PENDING until finished */
DET_VALIDATE_RV( (admPtr->ErrorStatus != NVM_REQ_PENDING), NVM_SET_DATA_INDEX_ID, NVM_E_BLOCK_PENDING , E_NOT_OK);
/* @req NVM014 */
admPtr->DataIndex = dataIndex;
admPtr->ErrorStatus = NVM_REQ_OK;
return E_OK;
}
/* @req NVM449 */
Std_ReturnType NvM_GetDataIndex( NvM_BlockIdType blockId, uint8 *dataIndexPtr ) {
const NvM_BlockDescriptorType * bPtr = &NvM_Config.BlockDescriptor[blockId-1];
AdministrativeBlockType * admPtr = &AdminBlock[blockId-1];
NVM_ASSERT( blockId >= 2 ); /* No support for lower numbers, yet */
/* @req NVM602 */
DET_VALIDATE_RV(nvmState != NVM_UNINITIALIZED, NVM_GET_DATA_INDEX_ID, NVM_E_NOT_INITIALIZED, E_NOT_OK);
/* @req NVM604 */
DET_VALIDATE_RV(blockId < (NVM_NUM_OF_NVRAM_BLOCKS+1), NVM_GET_DATA_INDEX_ID, NVM_E_PARAM_BLOCK_ID, E_NOT_OK);
/* @req NVM603 */
DET_VALIDATE_RV(bPtr->BlockManagementType == NVM_BLOCK_DATASET , NVM_GET_DATA_INDEX_ID, NVM_E_PARAM_BLOCK_TYPE , E_NOT_OK);
/* @req NVM605 */
DET_VALIDATE_RV( (dataIndexPtr != NULL) , NVM_GET_DATA_INDEX_ID, NVM_E_PARAM_DATA ,E_NOT_OK);
/* @req NVM021 */
if(NVM_BLOCK_DATASET == bPtr->BlockManagementType) {
*dataIndexPtr = admPtr->DataIndex;
} else {
/* @req NVM265 */
*dataIndexPtr = 0;
}
admPtr->ErrorStatus = NVM_REQ_OK;/* IMPROVEMENT: Is this really correct??? */
return E_OK;
}
#endif
/**
* Service for performing the processing of the NvM jobs.
*/
/* @req NVM464 */
void NvM_MainFunction(void)
{
/* @req NVM256 */
/* @req NVM333 *//* Done before writing */
/* @req NVM334 */
/* @req NVM257 */
/* @req NVM346 *//* Always polling */
/* @req NVM347 */
/* !req NVM350 *//* Broadcast id not used */
/* @req NVM349 */
/* @req NVM324 */
/* @req NVM381 *//* The NvM module shall not interrupt jobs originating from the NvM_ReadAll request by other requests */
/* @req NVM567 *//* The NvM module shall not interrupt jobs originating from the NvM_WriteAll request by other requests */
static const NvM_BlockDescriptorType * nvmBlock;
static AdministrativeBlockType *admBlock;
uint32 rv;
uint16 blkNum;
uint16 set;
static Nvm_QueueType qEntry;
const NvM_BlockDescriptorType * bList = NvM_Config.BlockDescriptor;
/* Check for new requested state changes */
if( nvmState == NVM_IDLE ) {
rv = (uint32)CirqBuffPop( &nvmQueue, &qEntry );
if( rv == 0 ) {
/* Found something in buffer */
nvmState = qEntry.op;
nvmBlock = &bList[qEntry.blockId-1];
admBlock = &AdminBlock[qEntry.blockId-1];
nvmSubState = NS_INIT;
admBlock->ErrorStatus = NVM_REQ_PENDING;
serviceId = qEntry.serviceId;
DEBUG_PRINTF("### Popped Single FIFO : %s\n",StateToStr[qEntry.op]);
DEBUG_PRINTF("### CRC On:%d Ram:%d Type:%d\n",nvmBlock->BlockUseCrc, nvmBlock->CalcRamBlockCrc, nvmBlock->BlockCRCType );
DEBUG_PRINTF("### RAM:%x ROM:%x\n", nvmBlock->RamBlockDataAddress, nvmBlock->RomBlockDataAdress );
} else {
/* Check multiblock req and do after all single block reads */
/* @req NVM243 *//* Processed when single block job queue is empty */
/* @req NVM254 *//* Processed when single block job queue is empty */
if( AdminMultiReq.state != NVM_UNINITIALIZED ) {
nvmState = AdminMultiReq.state;
nvmSubState = NS_INIT;
nvmBlock = NULL_PTR;
admBlock = NULL_PTR;
serviceId = AdminMultiReq.serviceId;
AdminMultiReq.state = NVM_UNINITIALIZED;
DEBUG_FPUTS("### Popped MULTI\n");
}
}
}
DEBUG_STATE(nvmState,nvmSubState);
switch (nvmState) {
case NVM_UNINITIALIZED:
break;
case NVM_IDLE:
{
CalcCrc();
break;
}
case NVM_READ_ALL:
if( NS_INIT == nvmSubState ) {
if( ReadAllInit()==TRUE) {
nvmSubState = NS_PENDING;
} else {
/* Nothing to do, everything is OK */
AdminMultiBlock.ErrorStatus = NVM_REQ_OK;
nvmState = NVM_IDLE;
nvmSubState = NS_INIT;
/* @req NVM468 */
if( NvM_Config.Common.MultiBlockCallback != NULL ) {
/* @req NVM686 */
NvM_Config.Common.MultiBlockCallback(serviceId, AdminMultiBlock.ErrorStatus);
}
}
} else if( NS_PENDING == nvmSubState ) {
MultiblockMain( false /* read */ );
}else{
/* do nothing */
}
break;
case NVM_READ_BLOCK:
(void)DriveBlock(nvmBlock,admBlock, qEntry.dataPtr, false, false, false );
break;
case NVM_RESTORE_BLOCK_DEFAULTS:
(void)DriveBlock(nvmBlock,admBlock, qEntry.dataPtr, false, false, true );
break;
case NVM_WRITE_BLOCK:
(void)DriveBlock(nvmBlock,admBlock, qEntry.dataPtr, true /*write*/, false , false );
break;
case NVM_WRITE_ALL:
if( NS_INIT == nvmSubState ) {
if( WriteAllInit()==TRUE ) {
nvmSubState = NS_PENDING;
} else {
/* Nothing to do, everything is OK */
AdminMultiBlock.ErrorStatus = NVM_REQ_OK;
nvmState = NVM_IDLE;
nvmSubState = NS_INIT;
/* @req NVM468 */
if( NvM_Config.Common.MultiBlockCallback != NULL ) {
/* @req NVM686 */
NvM_Config.Common.MultiBlockCallback(serviceId, AdminMultiBlock.ErrorStatus);
}
}
} else if( NS_PENDING == nvmSubState ) {
MultiblockMain(true /* write */ );
}else{
/* do nothing */
}
break;
case NVM_INVALIDATE_NV_BLOCK:
{
/* @req NVM665 */
Std_ReturnType ret;
MemIf_JobResultType jobResult;
static uint8 blockIndex = 0;
switch(nvmSubState ) {
case NS_INIT:
set = (uint16)admBlock->DataIndex + (uint16)blockIndex;
blkNum = BLOCK_BASE_AND_SET_TO_BLOCKNR(nvmBlock->NvBlockBaseNumber, set);
/* @req NVM421 */
ret = MemIf_InvalidateBlock(nvmBlock->NvramDeviceId,blkNum);
if (ret != E_OK) {
/* Do nothing. For MEMIF_UNINIT, MEMIF_BUSY and MEMIF_BUSY_INTERNAL we just stay in the
* same state. Better in the next run */
} else {
nvmSubState = NS_PENDING;
}
break;
case NS_PENDING:
jobResult = MemIf_GetJobResult(nvmBlock->NvramDeviceId);
if( MEMIF_JOB_PENDING == jobResult ) {
/* Keep on waiting */
} else if( MEMIF_JOB_OK == jobResult ) {
/* @req NVM274 */
if( (nvmBlock->BlockManagementType == NVM_BLOCK_REDUNDANT) &&
(blockIndex == 0)) {
/* First block in the redundant case - need to invalidate more blocks */
blockIndex = 1;
nvmSubState = NS_INIT;
} else {
/* Both block invalidated when redundant and the single block
* invalidated when not redundant.
*/
blockIndex = 0;
nvmState = NVM_IDLE;
nvmSubState = NS_INIT;
admBlock->ErrorStatus = NVM_REQ_OK;
}
} else {
/* MemIf job failed.... */
/* @req NVM275 *//* @req NVM666 *//* @req NVM592 */
DEM_REPORTERRORSTATUS(NvM_Config.DemEvents.NvMReqFailedDemEventId, DEM_EVENT_STATUS_FAILED);
AbortMemIfJob(MEMIF_JOB_FAILED);
nvmState = NVM_IDLE;
nvmSubState = NS_INIT;
admBlock->ErrorStatus = NVM_REQ_NOT_OK;
blockIndex = 0;
}
break;
default:
/* do nothing */
break;
}
break;
}
default:
DET_REPORTERROR(NVM_MAIN_FUNCTION_ID, NVM_UNEXPECTED_STATE);
break;
}
}
/***************************************
* Call-back notifications functions *
***************************************/
#if (NVM_POLLING_MODE == STD_OFF)
/* @req NVM156 *//* Callback runtime is reasonably short */
/*
* Procedure: NvM_JobEndNotification
* Reentrant: No
*/
/* @req NVM440 */
/* @req NVM462 */
void NvM_JobEndNotification(void)
{
MemIfJobAdmin.JobFinished = TRUE;
MemIfJobAdmin.JobStatus = E_OK;
if(NULL != MemIfJobAdmin.BlockDescriptor) {
MemIfJobAdmin.JobResult = MemIf_GetJobResult(MemIfJobAdmin.BlockDescriptor->NvramDeviceId);
} else {
/* IMPROVEMENT: Det error */
MemIfJobAdmin.JobResult = MEMIF_JOB_FAILED;
}
}
/*
* Procedure: NvM_JobErrorNotification
* Reentrant: No
*/
/* @req NVM463 */
/* @req NVM441 */
void NvM_JobErrorNotification(void)
{
MemIfJobAdmin.JobFinished = TRUE;
MemIfJobAdmin.JobStatus = E_NOT_OK;
if(NULL != MemIfJobAdmin.BlockDescriptor) {
MemIfJobAdmin.JobResult = MemIf_GetJobResult(MemIfJobAdmin.BlockDescriptor->NvramDeviceId);
} else {
/* IMPROVEMENT: Det error */
MemIfJobAdmin.JobResult = MEMIF_JOB_FAILED;
}
}
#endif
|
2301_81045437/classic-platform
|
memory/NvM/src/NvM.c
|
C
|
unknown
| 81,135
|
#RamTst
obj-$(USE_RAMTST) += RamTst.o
obj-$(USE_RAMTST) += RamTst_Cfg.o
inc-$(USE_RAMTST) += $(ROOTDIR)/memory/RamTst/inc
vpath-$(USE_RAMTST) += $(ROOTDIR)/memory/RamTst/src
|
2301_81045437/classic-platform
|
memory/RamTst/RamTst.mod.mk
|
Makefile
|
unknown
| 179
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.2 */
/** @tagSettings DEFAULT_ARCHITECTURE=GENERIC */
#ifndef RAMTST_H_
#define RAMTST_H_
#include "Std_Types.h"
#define RAMTST_VENDOR_ID 60u
#define RAMTST_MODULE_ID 93u /* TBD cannot find any in spec */
#define RAMTST_AR_MAJOR_VERSION 4u
#define RAMTST_AR_MINOR_VERSION 1u
#define RAMTST_AR_PATCH_VERSION 2u
#define RAMTST_SW_MAJOR_VERSION 2u
#define RAMTST_SW_MINOR_VERSION 2u
#define RAMTST_SW_PATCH_VERSION 0u
/* Service ids */
#define RAMTST_INIT_SERVICE_ID 0x00u
#define RAMTST_DEINIT_SERVICE_ID 0x0cu
#define RAMTST_STOP_SERVICE_ID 0x02u
#define RAMTST_ALLOW_SERVICE_ID 0x03u
#define RAMTST_GETVERSIONINFO_SERVICE_ID 0x0au
#define RAMTST_SUSPEND_SERVICE_ID 0x0du
#define RAMTST_RESUME_SERVICE_ID 0x0eu
#define RAMTST_GETEXECUTIONSTATUS_SERVICE_ID 0x04u
#define RAMTST_GETTESTRESULT_SERVICE_ID 0x05u
#define RAMTST_GETRESULTPERBLOCK_SERVICE_ID 0x06u
#define RAMTST_GETALGPARAMS_SERVICE_ID 0x12u
#define RAMTST_GETTESTALGORITHM_SERVICE_ID 0x07u
#define RAMTST_GETNUMBEROFTESTEDCELLS_SERVICE_ID 0x09u
#define RAMTST_SELECTALGPARAMS_SERVICE_ID 0x0bu
#define RAMTST_CHANGENUMBEROFTESTEDCELLS_SERVICE_ID 0x08u
#define RAMTST_RUNPARTIALTEST_SERVICE_ID 0x11u
#define RAMTST_MAINFUNCTION_SERVICE_ID 0x01u
#define RAMTST_RUNFULLTEST_SERVICE_ID 0x10u
/* Development errors */
#define RAMTST_E_STATUS_FAILURE 0x1u
#define RAMTST_E_OUT_OF_RANGE 0x2u
#define RAMTST_E_UNINIT 0x3u
#define RAMTST_E_PARAM_POINTER 0x4u
#include "RamTst_Types.h"
/*@req SWS_RamTst_00003 */
#include "RamTst_Cfg.h"
/* @req SWS_RamTst_00099 */
void RamTst_Init(void);
/* @req SWS_RamTst_00146 */
void RamTst_DeInit( void );
#if (RAMTST_STOP_API == STD_ON)
/* @req SWS_RamTst_00100 */
void RamTst_Stop( void );
#endif
#if(RAMTST_ALLOW_API == STD_ON)
/* @req SWS_RamTst_00149 */
void RamTst_Allow( void );
#endif
#if(RAMTST_SUSPEND_API == STD_ON)
void RamTst_Suspend( void );
#endif
#if(RAMTST_RESUME_API == STD_ON)
void RamTst_Resume( void );
#endif
#if(RAMTST_GET_EXECUTION_STATUS_API == STD_ON)
RamTst_ExecutionStatusType RamTst_GetExecutionStatus( void );
#endif
#if(RAMTST_GET_TEST_RESULT_API == STD_ON)
/* @req SWS_RamTst_00103 */
RamTst_TestResultType RamTst_GetTestResult( void );
#endif
#if(RAMTST_GET_TEST_RESULT_PER_BLOCK_API == STD_ON)
/* @req SWS_RamTst_00104 */
RamTst_TestResultType RamTst_GetTestResultPerBlock( RamTst_NumberOfBlocksType BlockID );
#endif
#if(RAMTST_GET_ALG_PARAMS_API == STD_ON)
/* @req SWS_RamTst_00193 */
RamTst_AlgParamsIdType RamTst_GetAlgParams( void );
#endif
#if(RAMTST_GET_TEST_ALGORITHM_API == STD_ON)
/* @req SWS_RamTst_00106 */
RamTst_AlgorithmType RamTst_GetTestAlgorithm( void );
#endif
#if(RAMTST_GET_NUMBER_OF_TESTED_CELLS_API == STD_ON)
RamTst_NumberOfTestedCellsType RamTst_GetNumberOfTestedCells( void );
#endif
#if(RAMTST_SELECT_ALG_PARAMS_API == STD_ON)
/* @req SWS_RamTst_00105 */
void RamTst_SelectAlgParams( RamTst_AlgParamsIdType NewAlgParamsId );
#endif
#if(RAMTST_CHANGE_NUMBER_OF_TESTED_CELLS_API == STD_ON)
void RamTst_ChangeNumberOfTestedCells( RamTst_NumberOfTestedCellsType NewNumberOfTestedCells );
#endif
#if(RAMTST_RUN_PARTIAL_TEST_API == STD_ON)
void RamTst_RunPartialTest(RamTst_NumberOfBlocksType BlockId );
#endif
#if(RAMTST_RUN_FULL_TEST_API == STD_ON)
void RamTst_RunFullTest( void );
#endif
void RamTst_MainFunction( void );
#if (RAMTST_GET_VERSION_INFO_API == STD_ON)
/* @req SWS_RamTst_00109 */
void RamTst_GetVersionInfo( Std_VersionInfoType *versionInfo );
#endif
#endif /* RAMTST_H_ */
|
2301_81045437/classic-platform
|
memory/RamTst/inc/RamTst.h
|
C
|
unknown
| 4,659
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.2 */
/** @tagSettings DEFAULT_ARCHITECTURE=GENERIC */
#ifndef RAMTST_TYPES_H_
#define RAMTST_TYPES_H_
#if defined(USE_DEM)
#include "Dem.h" /* For Dem_EventIdType */
#endif
typedef union {
uint32 address;
uint32* dataPtr;
}RamTst_AddrType;
/* @req SWS_RamTst_00189 */
typedef enum
{
RAMTST_EXECUTION_UNINIT = 0,
RAMTST_EXECUTION_STOPPED,
RAMTST_EXECUTION_RUNNING,
RAMTST_EXECUTION_SUSPENDED,
}RamTst_ExecutionStatusType;
/* @req SWS_RamTst_00190 */
typedef enum
{
RAMTST_RESULT_NOT_TESTED = 0,
RAMTST_RESULT_OK,
RAMTST_RESULT_NOT_OK,
RAMTST_RESULT_UNDEFINED,
}RamTst_TestResultType;
/* @req SWS_RamTst_00191 */
typedef uint8 RamTst_AlgParamsIdType;
/* @req SWS_RamTst_00173 */
typedef uint32 RamTst_NumberOfTestedCellsType;
/* @req SWS_RamTst_00174 */
typedef uint16 RamTst_NumberOfBlocksType;
/* @req SWS_RamTst_00227 */
/* !req SWS_RamTst_00058 */
typedef enum
{
RAMTST_ALGORITHM_UNDEFINED = 0,
RAMTST_CHECKERBOARD_TEST,
RAMTST_MARCH_TEST,
RAMTST_WALK_PATH_TEST,
RAMTST_GALPAT_TEST,
RAMTST_TRANSP_GALPAT_TEST,
RAMTST_ABRAHAM_TEST,
}RamTst_AlgorithmType;
typedef enum
{
RAMTEST_DESTRUCTIVE = 0,
RAMTEST_NON_DESTRUCTIVE,
}RamTst_TestPolicyType;
typedef void (*RamTst_TestCompletedNotificationType)();
typedef void (*RamTst_TestErrorNotificationType)();
typedef struct
{
RamTst_AddrType RamTstEndAddress;
RamTst_AddrType RamTstStartAddress;
RamTst_NumberOfBlocksType RamTstBlockId;
RamTst_NumberOfBlocksType RamTstBlockIndex;
}RamTst_BlockParamsType;
typedef struct
{
RamTst_AlgParamsIdType RamTstAlgParamsId;
RamTst_AlgorithmType RamTstAlgorithm;
RamTst_NumberOfBlocksType RamTstNumberOfBlocks;
const RamTst_BlockParamsType * const RamTstBlockParams;
}RamTst_AlgParamsType;
typedef struct
{
RamTst_AlgParamsIdType RamTstDefaultAlgParamsId;
RamTst_AlgParamsIdType RamTstNumberOfAlgParamSets;
#if defined(USE_DEM)
Dem_EventIdType RAMTST_E_RAM_FAILURE;
#endif
const RamTst_AlgParamsType * const RamTstAlgParams;
}RamTst_ConfigParamsType;
#endif /* RAMTST_TYPES_H_ */
|
2301_81045437/classic-platform
|
memory/RamTst/inc/RamTst_Types.h
|
C
|
unknown
| 2,996
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.2 */
/** @tagSettings DEFAULT_ARCHITECTURE=GENERIC */
/* General requirements */
/* @req SWS_RamTst_00067 *//* Errors detected */
/* @req SWS_RamTst_00098 *//* Imported types */
/* @req SWS_RamTst_00167 *//* Variant pre-compile */
/* !req SWS_RamTst_00168 *//* Variant link-time */
/* @req SWS_RamTst_00206 *//* Foreground RAM test as an synchronous service. */
#include "RamTst.h"
#if ( RAMTST_DEV_ERROR_DETECT == STD_ON )
#include "Det.h"
#if !defined(USE_DET)
#error RamTst: Module Det required when dev error detect enabled
#endif
#endif
#if defined(USE_DEM)
#include "Dem.h"
#endif
typedef enum {
RAMTST_UNINIT,
RAMTST_INIT
}RamTstInitInitStatus;
typedef struct {
RamTst_TestResultType RamTst_BlockResultBuffer[RAMTST_NUM_BLOCKS];
RamTst_ExecutionStatusType ExecStatus;
#if (RAMTST_STOP_API == STD_ON)
RamTst_ExecutionStatusType OrderedStatus;
#endif
RamTst_AlgParamsIdType ActiveAlgParamID;
RamTstInitInitStatus InitStatus;
RamTst_TestResultType CurrentTestResult;
}RamTstInternalType;
static RamTstInternalType RamTst_Internal = {
.ExecStatus = RAMTST_EXECUTION_UNINIT,/* @req SWS_RamTst_00006 */
#if (RAMTST_STOP_API == STD_ON)
.OrderedStatus = RAMTST_EXECUTION_UNINIT,
#endif
.ActiveAlgParamID = 0,/* @req SWS_RamTst_00013 */
.InitStatus = RAMTST_UNINIT,
.CurrentTestResult = RAMTST_RESULT_NOT_TESTED/* @req SWS_RamTst_00012 */
};
/*lint -emacro(904,VALIDATE,VALIDATE_W_RV)*/ /*904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/
/* Development error macros. */
#if ( RAMTST_DEV_ERROR_DETECT == STD_ON )
/* @req SWS_RamTst_00112 */
#define VALIDATE(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(RAMTST_MODULE_ID,0,_api,_err); \
return; \
}
#define VALIDATE_W_RV(_exp,_api,_err,_rv ) \
if( !(_exp) ) { \
(void)Det_ReportError(RAMTST_MODULE_ID,0,_api,_err); \
return (_rv); \
}
#else
#define VALIDATE(_exp,_api,_err )
#define VALIDATE_W_RV(_exp,_api,_err,_rv )
#endif
#if (RAMTST_MARCH_TEST_SELECTED == STD_ON)
static RamTst_TestResultType ramTstMarchX(uint32 *sa, uint32 *ea);
#endif
#ifdef HOST_TEST
static uint8 induceerror_flag;
static RamTst_NumberOfBlocksType induceErrorBlockId = 0;
void InduceErrorOnce(RamTst_NumberOfBlocksType BlockID);
void Getexecstatus(RamTst_ExecutionStatusType **ptr);
void getActiveAlgParamID(RamTst_AlgParamsIdType **ptr);
void getResultBuffer(RamTst_TestResultType **ptr);
void InduceErrorOnce(RamTst_NumberOfBlocksType BlockID) {
induceErrorBlockId = BlockID;
}
void Getexecstatus(RamTst_ExecutionStatusType **ptr) {
if (NULL == ptr) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
*ptr = &RamTst_Internal.ExecStatus;
}
#if (RAMTST_STOP_API == STD_ON)
void Getorderedstatus(RamTst_ExecutionStatusType **ptr);
void Getorderedstatus(RamTst_ExecutionStatusType **ptr) {
if (NULL == ptr) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
*ptr = &RamTst_Internal.OrderedStatus;
}
#endif
void getActiveAlgParamID(RamTst_AlgParamsIdType **ptr) {
if (NULL == ptr) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
*ptr = &RamTst_Internal.ActiveAlgParamID;
}
void getResultBuffer(RamTst_TestResultType **ptr) {
if (NULL == ptr) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
*ptr = &RamTst_Internal.RamTst_BlockResultBuffer[0];
}
#endif
/* @req SWS_RamTst_00099 */
/* @req SWS_RamTst_00093 */
void RamTst_Init(void)
{
/* @req SWS_RamTst_00089 */
RamTst_Internal.InitStatus = RAMTST_INIT;
/* @req SWS_RamTst_00096 */
VALIDATE( ( RAMTST_EXECUTION_UNINIT == RamTst_Internal.ExecStatus ), RAMTST_INIT_SERVICE_ID, RAMTST_E_STATUS_FAILURE);
/* @req SWS_RamTst_00007 */
RamTst_Internal.ExecStatus = RAMTST_EXECUTION_STOPPED;
RamTst_Internal.ActiveAlgParamID = RamTst_ConfigParams.RamTstDefaultAlgParamsId;
for( RamTst_NumberOfBlocksType i = 0; i < RAMTST_NUM_BLOCKS; i++ ) {
RamTst_Internal.RamTst_BlockResultBuffer[i] = RAMTST_RESULT_NOT_TESTED;
}
RamTst_Internal.CurrentTestResult = RAMTST_RESULT_NOT_TESTED;
}
/* @req SWS_RamTst_00146 */
void RamTst_DeInit( void )
{
/* @req SWS_RamTst_00089 */
VALIDATE( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_INIT_SERVICE_ID, RAMTST_E_UNINIT);
/* @req SWS_RamTst_00147 */
RamTst_Internal.ExecStatus = RAMTST_EXECUTION_UNINIT;
RamTst_Internal.InitStatus = RAMTST_UNINIT;
RamTst_Internal.CurrentTestResult = RAMTST_RESULT_NOT_TESTED;
}
#if (RAMTST_STOP_API == STD_ON)
/* @req SWS_RamTst_00100 */
void RamTst_Stop( void )
{
/* @req SWS_RamTst_00089 */
VALIDATE( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_INIT_SERVICE_ID, RAMTST_E_UNINIT);
/* @req SWS_RamTst_00033 */
VALIDATE( !((RamTst_Internal.ExecStatus == RAMTST_EXECUTION_UNINIT) || (RamTst_Internal.ExecStatus == RAMTST_EXECUTION_STOPPED)), RAMTST_STOP_SERVICE_ID, RAMTST_E_STATUS_FAILURE);
/* @req SWS_RamTst_00014 */
RamTst_Internal.OrderedStatus = RAMTST_EXECUTION_STOPPED;
}
#endif
#if(RAMTST_ALLOW_API == STD_ON)
/* @req SWS_RamTst_00149 */
void RamTst_Allow( void )
{
/* @req SWS_RamTst_00089 */
VALIDATE( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_INIT_SERVICE_ID, RAMTST_E_UNINIT);
/* @req SWS_RamTst_00170 */
VALIDATE( ( (RAMTST_EXECUTION_STOPPED) == RamTst_Internal.ExecStatus ), RAMTST_ALLOW_SERVICE_ID, RAMTST_E_STATUS_FAILURE);
/* @req SWS_RamTst_00169 */
RamTst_Internal.ExecStatus = RAMTST_EXECUTION_RUNNING;
}
#endif
#if(RAMTST_SUSPEND_API == STD_ON)
void RamTst_Suspend( void )
{
/* Not supported */
}
#endif
#if(RAMTST_RESUME_API == STD_ON)
void RamTst_Resume( void )
{
/* Not supported */
}
#endif
/* @req SWS_RamTst_00109 */
#if(RAMTST_GET_VERSION_INFO_API == STD_ON)
void RamTst_GetVersionInfo( Std_VersionInfoType* versioninfo )
{
/* @req SWS_RamTst_00089 */
VALIDATE( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_INIT_SERVICE_ID, RAMTST_E_UNINIT);
/* @req SWS_RamTst_00222*/
VALIDATE( (versioninfo != NULL), RAMTST_GETVERSIONINFO_SERVICE_ID, RAMTST_E_PARAM_POINTER );
if(versioninfo != NULL) { /*lint !e774 Can be evaluated as false if used incorrectly by the user */
versioninfo->vendorID = RAMTST_VENDOR_ID;
versioninfo->moduleID = RAMTST_MODULE_ID;
versioninfo->sw_major_version = RAMTST_SW_MAJOR_VERSION;
versioninfo->sw_minor_version = RAMTST_SW_MINOR_VERSION;
versioninfo->sw_patch_version = RAMTST_SW_PATCH_VERSION;
}
}
#endif
#if(RAMTST_GET_EXECUTION_STATUS_API == STD_ON)
RamTst_ExecutionStatusType RamTst_GetExecutionStatus( void )
{
/* Not supported */
}
#endif
#if(RAMTST_GET_TEST_RESULT_API == STD_ON)
RamTst_TestResultType RamTst_GetTestResult( void )
{
/* @req SWS_RamTst_00089 */
VALIDATE_W_RV( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_GETTESTRESULT_SERVICE_ID, RAMTST_E_UNINIT, RAMTST_RESULT_NOT_TESTED);
/* @req SWS_RamTst_00024 */
return RamTst_Internal.CurrentTestResult;
}
#endif
#if(RAMTST_GET_TEST_RESULT_PER_BLOCK_API == STD_ON)
RamTst_TestResultType RamTst_GetTestResultPerBlock( RamTst_NumberOfBlocksType BlockID )
{
RamTst_TestResultType status;
/* @req SWS_RamTst_00089 */
VALIDATE_W_RV( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_GETRESULTPERBLOCK_SERVICE_ID, RAMTST_E_UNINIT, RAMTST_RESULT_NOT_TESTED);
/* Find the block */
const RamTst_BlockParamsType *blockParamPtr = NULL;
const RamTst_AlgParamsType *algParams = NULL;
for(RamTst_AlgParamsIdType i = 0; (i < RamTst_ConfigParams.RamTstNumberOfAlgParamSets) && (NULL == blockParamPtr); i++) {
algParams = &RamTst_ConfigParams.RamTstAlgParams[i];
/* Run for all blocks */
for(RamTst_NumberOfBlocksType block = 0; (block < algParams->RamTstNumberOfBlocks) && (NULL == blockParamPtr); block++) {
if(algParams->RamTstBlockParams[block].RamTstBlockId == BlockID) {
blockParamPtr = &algParams->RamTstBlockParams[block];
}
}
}
if(NULL != blockParamPtr) {
/* @req SWS_RamTst_00038 */
status = RamTst_Internal.RamTst_BlockResultBuffer[blockParamPtr->RamTstBlockIndex];
} else {
/* Invalid block id */
#if ( RAMTST_DEV_ERROR_DETECT == STD_ON )
/* @req SWS_RamTst_00039 */
(void)Det_ReportError(RAMTST_MODULE_ID, 0, RAMTST_GETRESULTPERBLOCK_SERVICE_ID, RAMTST_E_OUT_OF_RANGE);
#endif
status = RAMTST_RESULT_UNDEFINED;
}
return status;
}
#endif
#if(RAMTST_GET_ALG_PARAMS_API == STD_ON)
RamTst_AlgParamsIdType RamTst_GetAlgParams( void )
{
/* @req SWS_RamTst_00089 */
VALIDATE_W_RV( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_GETALGPARAMS_SERVICE_ID, RAMTST_E_UNINIT, 0);
/* @req SWS_RamTst_00194 */
return RamTst_Internal.ActiveAlgParamID;
}
#endif
#if(RAMTST_GET_TEST_ALGORITHM_API == STD_ON)
RamTst_AlgorithmType RamTst_GetTestAlgorithm( void )
{
/* @req SWS_RamTst_00089 */
VALIDATE_W_RV( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_GETTESTALGORITHM_SERVICE_ID, RAMTST_E_UNINIT, RAMTST_ALGORITHM_UNDEFINED);
RamTst_AlgorithmType algorithm = RAMTST_ALGORITHM_UNDEFINED;/* @req SWS_RamTst_00188 */
for(RamTst_AlgParamsIdType i = 0; (i < RamTst_ConfigParams.RamTstNumberOfAlgParamSets) && (RAMTST_ALGORITHM_UNDEFINED == algorithm); i++) {
if( RamTst_ConfigParams.RamTstAlgParams[i].RamTstAlgParamsId == RamTst_Internal.ActiveAlgParamID ) {
algorithm = RamTst_ConfigParams.RamTstAlgParams[i].RamTstAlgorithm;
}
}
/* @req SWS_RamTst_00021 */
return algorithm;
}
#endif
#if(RAMTST_GET_NUMBER_OF_TESTED_CELLS_API == STD_ON)
RamTst_NumberOfTestedCellsType RamTst_GetNumberOfTestedCells( void )
{
/* Not supported */
}
#endif
#if(RAMTST_SELECT_ALG_PARAMS_API == STD_ON)
void RamTst_SelectAlgParams( RamTst_AlgParamsIdType NewAlgParamsId )
{
/* @req SWS_RamTst_00089 */
VALIDATE( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_SELECTALGPARAMS_SERVICE_ID, RAMTST_E_UNINIT);
/* @req SWS_RamTst_00097 */
VALIDATE( ( RamTst_Internal.ExecStatus == RAMTST_EXECUTION_STOPPED ), RAMTST_SELECTALGPARAMS_SERVICE_ID, RAMTST_E_STATUS_FAILURE);
/* Check parameter NewAlgParamsId */
const RamTst_AlgParamsType *algParams = NULL;
for(RamTst_AlgParamsIdType i = 0; (i < RamTst_ConfigParams.RamTstNumberOfAlgParamSets) && (NULL == algParams); i++) {
if( RamTst_ConfigParams.RamTstAlgParams[i].RamTstAlgParamsId == NewAlgParamsId ) {
algParams = &RamTst_ConfigParams.RamTstAlgParams[i];
/* @req SWS_RamTst_00094 */
for(RamTst_NumberOfBlocksType block = 0; block < algParams->RamTstNumberOfBlocks; block++) {
RamTst_Internal.RamTst_BlockResultBuffer[algParams->RamTstBlockParams[block].RamTstBlockIndex] = RAMTST_RESULT_NOT_TESTED;
}
/* @req SWS_RamTst_00085 */
RamTst_Internal.ActiveAlgParamID = NewAlgParamsId;/* @req SWS_RamTst_00083 */
RamTst_Internal.ExecStatus = RAMTST_EXECUTION_STOPPED;
RamTst_Internal.CurrentTestResult = RAMTST_RESULT_NOT_TESTED;
}
}
/* @req SWS_RamTst_00084 */
VALIDATE( ( NULL != algParams ), RAMTST_SELECTALGPARAMS_SERVICE_ID, RAMTST_E_OUT_OF_RANGE);
}
#endif
#if(RAMTST_CHANGE_NUMBER_OF_TESTED_CELLS_API == STD_ON)
void RamTst_ChangeNumberOfTestedCells( RamTst_NumberOfTestedCellsType NewNumberOfTestedCells )
{
/* Not supported */
}
#endif
#if (RAMTST_MARCH_TEST_SELECTED == STD_ON)
/* Algorithm March X
Step1: write 0 with up addressing order;
Step2: read 0 and write 1 with up addressing order;
Step3: read 1 and write 0 with down addressing order;
Step4: read0 with down addressing order.
*/
static RamTst_TestResultType ramTstMarchX(uint32 *sa, uint32 *ea)
/*lint --e{946} Pointing at hardware RAM, which can be considered as a single object*/
{
RamTst_TestResultType status;
boolean ret;
uint32 *ptr_start;
uint32 *ptr_end;
status = RAMTST_RESULT_OK;
ptr_end = ea;
ptr_start = sa;
ret = TRUE;
/* Step1:write 0 with up addressing order */
for( ;ptr_start < ptr_end;ptr_start++){
*ptr_start = 0;
}
#ifdef HOST_TEST
//inducing error
if(induceerror_flag == 1){
ptr_start = sa;
for( ;ptr_start < ptr_end;ptr_start++){
*ptr_start = 1;
}
}
#endif
/* Step2: read 0 and write 1 with up addressing order */
ptr_start = sa;
for( ;ptr_start < ptr_end;ptr_start++){
if(0 != *ptr_start){
status = RAMTST_RESULT_NOT_OK;
ret = FALSE;
break;
}
*ptr_start = 1;
}
if (ret == TRUE) {
/* Step3: read 1 and write 0 with down addressing order */
ptr_start = sa;
ptr_end--;
for( ; ptr_end >= ptr_start;ptr_end--){
if(1 != *ptr_end){
status = RAMTST_RESULT_NOT_OK;
ret = FALSE;
break;
}
*ptr_end = 0;
}
if (ret == TRUE) {
/* Step4: read0 with down addressing order. */
ptr_end = ea;
ptr_end--;
for( ; ptr_end >= ptr_start;ptr_end--){
if(0 != *ptr_end){
status = RAMTST_RESULT_NOT_OK;
break;
}
}
}
}
return status;
}
#endif
#if (RAMTST_GALPAT_TEST_SELECTED == STD_ON)
RamTst_TestResultType RamTst_Galpat(uint32 start_addr, uint32 end_addr)
{
/* Not supported */
}
#endif
#if (RAMTST_ABRAHAM_TEST_SELECTED == STD_ON)
RamTst_TestResultType RamTst_Abraham(uint32 start_addr, uint32 end_addr)
{
/* Not supported */
}
#endif
#if (RAMTST_TRANSP_GALPAT_TEST_SELECTED == STD_ON)
RamTst_TestResultType RamTst_Transp_Galpat(uint32 start_addr, uint32 end_addr)
{
/* Not supported */
}
#endif
#if (RAMTST_WALK_PATH_TEST_SELECTED == STD_ON)
RamTst_TestResultType RamTst_Walk_Path(uint32 start_addr, uint32 end_addr)
{
/* Not supported */
}
#endif
#if (RAMTST_CHECKERBOARD_TEST_SELECTED == STD_ON)
/* Algorithm Checkerboard
* Step1: Write 0 and Write 1 to alternate cells to form checkboard pattern
* Step2: Read all cells
* Step3: Write 1 and Write 0 to alternate cells to form checkboard pattern
* Step4: Read all cells
* */
RamTst_TestResultType RamTst_CheckerBoard(uint32 start_addr, uint32 end_addr)
{
/* Not supported */
}
#endif
#if(RAMTST_RUN_PARTIAL_TEST_API == STD_ON)
void RamTst_RunPartialTest(RamTst_NumberOfBlocksType BlockId )
{
/* Not supported */
}
#endif
#if(RAMTST_RUN_FULL_TEST_API == STD_ON)
/* @req SWS_RamTst_00195 */
void RamTst_RunFullTest( void )
{
/* @req SWS_RamTst_00202 */
/* !req SWS_RamTst_00207 *//* While test running block is NOT_TESTED */
/* @req SWS_RamTst_00089 */
VALIDATE( ( RamTst_Internal.InitStatus != RAMTST_UNINIT ), RAMTST_INIT_SERVICE_ID, RAMTST_E_UNINIT);
/* @req SWS_RamTst_00210 */
VALIDATE( ( (RAMTST_EXECUTION_STOPPED) == RamTst_Internal.ExecStatus ), RAMTST_RUNFULLTEST_SERVICE_ID, RAMTST_E_STATUS_FAILURE);
const RamTst_AlgParamsType *algParams = NULL;
/* Find config for the active algorithm */
for(RamTst_AlgParamsIdType i = 0; (i < RamTst_ConfigParams.RamTstNumberOfAlgParamSets) && (NULL == algParams); i++) {
if( RamTst_ConfigParams.RamTstAlgParams[i].RamTstAlgParamsId == RamTst_Internal.ActiveAlgParamID ) {
algParams = &RamTst_ConfigParams.RamTstAlgParams[i];
}
}
if( NULL != algParams ) {
/* @req SWS_RamTst_00211 */
RamTst_Internal.ExecStatus = RAMTST_EXECUTION_RUNNING;
RamTst_Internal.CurrentTestResult = RAMTST_RESULT_UNDEFINED;
/* @req SWS_RamTst_00196 */
/* Run for all blocks */
for(RamTst_NumberOfBlocksType i = 0; i<algParams->RamTstNumberOfBlocks;i++)
{
RamTst_Internal.RamTst_BlockResultBuffer[algParams->RamTstBlockParams[i].RamTstBlockIndex] = RAMTST_RESULT_NOT_TESTED;
}
for(RamTst_NumberOfBlocksType i = 0; i < algParams->RamTstNumberOfBlocks; i++)
{
RamTst_TestResultType res;
#ifdef HOST_TEST
if( algParams->RamTstBlockParams[i].RamTstBlockId == induceErrorBlockId ) {
induceerror_flag = 1;
}
#endif
switch(algParams->RamTstAlgorithm) {
#if (RAMTST_MARCH_TEST_SELECTED == STD_ON)
case RAMTST_MARCH_TEST:
res = ramTstMarchX(algParams->RamTstBlockParams[i].RamTstStartAddress.dataPtr, algParams->RamTstBlockParams[i].RamTstEndAddress.dataPtr);
break;
#endif
default:// not implemented yet
res = RAMTST_RESULT_NOT_OK;
break;
}
/* @req SWS_RamTst_00212 */
/* @req SWS_RamTst_00213 */
if(res != RAMTST_RESULT_OK){
#if defined(USE_DEM)
if(DEM_EVENT_ID_NULL != RamTst_ConfigParams.RAMTST_E_RAM_FAILURE) {
/* @req SWS_RamTst_00071 */
/* @req SWS_RamTst_00111 */
(void)Dem_ReportErrorStatus(RamTst_ConfigParams.RAMTST_E_RAM_FAILURE, DEM_EVENT_STATUS_FAILED);
}
#endif
RamTst_Internal.CurrentTestResult = RAMTST_RESULT_NOT_OK;
}
RamTst_Internal.RamTst_BlockResultBuffer[algParams->RamTstBlockParams[i].RamTstBlockIndex] = res;
#ifdef HOST_TEST
induceerror_flag = 0;
#endif
}
if( RAMTST_RESULT_UNDEFINED == RamTst_Internal.CurrentTestResult ) {
RamTst_Internal.CurrentTestResult = RAMTST_RESULT_OK;
}
/* @req SWS_RamTst_00211 */
RamTst_Internal.ExecStatus = RAMTST_EXECUTION_STOPPED;
}
#ifdef HOST_TEST
induceErrorBlockId = 0;
#endif
}
#endif
|
2301_81045437/classic-platform
|
memory/RamTst/src/RamTst.c
|
C
|
unknown
| 19,710
|
#Crc
obj-$(USE_CRC) += Crc.o
obj-$(USE_CRC) += Crc_8.o
obj-$(USE_CRC) += Crc_16.o
obj-$(USE_CRC) += Crc_32.o
obj-$(USE_CRC) += Crc_32P4.o
inc-$(USE_CRC) += $(ROOTDIR)/safety_security/SafeLib/Crc/inc
inc-$(USE_CRC) += $(ROOTDIR)/safety_security/SafeLib/Crc/src
vpath-$(USE_CRC) += $(ROOTDIR)/safety_security/SafeLib/Crc/src
|
2301_81045437/classic-platform
|
safety_security/SafeLib/Crc/Crc.mod.mk
|
Makefile
|
unknown
| 330
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @file Crc.h
*
* The Crc Library provides functions for 8 bit, 16 bit and 32 bit CRC (cyclic redundancy check) calculations.
* The Crc library can be scaled in terms of
* * Table based calculation (fast, but higher code size)
* * Runtime calculation (slow, but smaller code size)
* * Different standard CRC generator polynomials
*/
#ifndef CRC_H_
#define CRC_H_
/* @req SWS_CRC_00048
* Additional module-specific published parameters are listed below
*
* @req SWS_CRC_00050
* The standardized common published parameters
* shall be published within the header file of this module.
*
* @req SWS_BSW_00059 The Published information of the BSW Module shall be provided within
* all header files by defining preprocessor directives.
*/
#define CRC_VENDOR_ID 60u
#define CRC_MODULE_ID 201u
#define CRC_AR_RELEASE_MAJOR_VERSION 4u
#define CRC_AR_RELEASE_MINOR_VERSION 3u
#define CRC_AR_RELEASE_REVISION_VERSION 0u
#define CRC_SW_MAJOR_VERSION 2u
#define CRC_SW_MINOR_VERSION 0u
#define CRC_SW_PATCH_VERSION 0u
/* SWS_CRC_00023
* Users of the Crc module (e.g. NVRAM Manager) shall only include Crc.h
* This requirement is only applicable to users. That's why it is not verified in the unit tests
*
* @req SWS_CRC_00024
* The Crc module shall provide the following files:
* C file Crc_xxx.c containing parts of CRC code
* An API interface Crc.h providing the function prototypes to access the library CRC functions
* A header file Crc_Cfg.h providing specific parameters for the CRC.
*/
/* @req SWS_CRC_00022
* The Crc module shall comply with the following include file structure:
* Crc.h shall include Crc_Cfg.h, Std_Types.h and Crc_MemMap.h
* Crc_xxx.c shall include Crc.h
*/
#include "Crc_Cfg.h"
/* @req SWS_CRC_00018
* All types included shall be only Std_Types
*/
#include "Std_Types.h"
/* These two applies to the caller and it set by the interface
*
* @req SWS_CRC_00014
* The CRC function (with parameter Crc_IsFirstCall = TRUE) shall do the specified operations.
*
* @req SWS_CRC_00041
* The CRC function (with parameter Crc_IsFirstCall = FALSE) shall do the specified operations.
*
* For the details of the specified operations refer to AUTOSAR_SWS_CRCLibrary.pdf
*/
#ifdef Crc_8_Mode
/** @brief This service makes a CRC8 calculation on Crc_Length data bytes,
* using the polynomial 0x1D.
*
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue8 Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 8 bit result of CRC calculation.
*/
/* @req SWS_CRC_00031 API for 8-bit SAE J1850 CRC Calculation */
uint8 Crc_CalculateCRC8(const uint8* Crc_DataPtr, uint32 Crc_Length, uint8 Crc_StartValue8, boolean Crc_IsFirstCall);
#endif
#ifdef Crc_8_8H2FMode
/** @brief This service makes a CRC8 calculation on Crc_Length data bytes,
* using the polynomial 0x2F.
*
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue8H2F Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 8 bit result of CRC calculation.
*/
/* @req SWS_CRC_00043 API for 8-bit 0x2F polynomial CRC Calculation */
uint8 Crc_CalculateCRC8H2F(const uint8* Crc_DataPtr, uint32 Crc_Length, uint8 Crc_StartValue8H2F, boolean Crc_IsFirstCall);
#endif
#ifdef Crc_16_Mode
/** @brief This service makes a CRC16 calculation on Crc_Length data bytes,
* using the polynomial 0x1021.
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue16 Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 16 bit result of CRC calculation.
*/
/* @req SWS_CRC_00019 API for 16-bit CCITT-FALSE CRC16 */
uint16 Crc_CalculateCRC16(const uint8* Crc_DataPtr, uint32 Crc_Length, uint16 Crc_StartValue16, boolean Crc_IsFirstCall);
#endif
#ifdef Crc_32_Mode
/** @brief This service makes a CRC32 calculation on Crc_Length data bytes,
* using the polynomial 0x04C11DB7.
*
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue32 Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 32 bit result of CRC calculation.
*/
/* @req SWS_CRC_00020 API for 32-bit Ethernet CRC Calculation */
uint32 Crc_CalculateCRC32(const uint8* Crc_DataPtr, uint32 Crc_Length, uint32 Crc_StartValue32, boolean Crc_IsFirstCall);
#endif
#ifdef Crc_32P4_Mode
/** @brief This service makes a CRC32 calculation on Crc_Length data bytes,
* using the polynomial 0xF4ACFB13. This CRC routine is used by E2E Profile 4.
*
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue32P4 Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 32 bit result of CRC calculation.
*/
/* @req SWS_CRC_00058 API for 32-bit 0xF4ACFB13 polynomial CRC calculation */
uint32 Crc_CalculateCRC32P4(const uint8* Crc_DataPtr, uint32 Crc_Length, uint32 Crc_StartValue32P4, boolean Crc_IsFirstCall);
#endif
/* @req SWS_CRC_00011 The function Crc_GetVersionInfo shall return the version information of the Crc module */
/* @req SWS_CRC_00021 API for Crc_GetVersionInfo */
/** @brief Return the version information of Crc module.
*
* The function Crc_GetVersionInfo shall return the version
* information of the Crc module.
* The version information includes:
* - Module Id
* - Vendor Id
* - sw_major_version
* - sw_minor_version
* - sw_patch_version
*
* @param Std_VersionInfoType The type including Module and Vendor ID for the Crc Module.
* @return void.
*/
#if (SAFELIB_VERSIONINFO_API == STD_ON)
void Crc_GetVersionInfo(Std_VersionInfoType* versioninfo);
#endif
#endif /* CRC_H_ */
|
2301_81045437/classic-platform
|
safety_security/SafeLib/Crc/inc/Crc.h
|
C
|
unknown
| 7,839
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void make_crc_table(unsigned long crcTable[])
{
//unsigned long POLYNOMIAL = 0xEDB88320; // <-- reversed: 0x04C11DB7, Ethernet
unsigned long POLYNOMIAL = 0xC8DF352F; // <-- reversed: 0xF4ACFB13
//F 4 A C F B 1 3
//1111 0100 1010 1100 1111 1011 0001 0011
//F 2 5 3 F D 8 C
unsigned long remainder;
unsigned char b = 0;
do{
// Start with the data byte
remainder = b;
for (unsigned long bit = 8; bit > 0; --bit)
{
if (remainder & 1)
remainder = (remainder >> 1) ^ POLYNOMIAL;
else
remainder = (remainder >> 1);
}
crcTable[(size_t)b] = remainder;
} while(0 != ++b);
}
unsigned long gen_crc(unsigned char *p, size_t n, unsigned long crcTable[])
{
unsigned long crc = 0xfffffffful;
size_t i;
for(i = 0; i < n; i++)
crc = crcTable[*p++ ^ (crc&0xff)] ^ (crc>>8);
return(~crc);
}
int main()
{
std::ofstream outfile;
outfile.open("crc32.txt");
unsigned long crcTable[256];
make_crc_table(crcTable);
// Print the CRC table
for (size_t i = 0; i < 256; i++)
{
std::cout << "0x" << std::setfill('0') << std::setw(8)
<< std::hex << std::uppercase << crcTable[i] << "U";
std::cout << ", ";
if (i % 8 == 7)
std::cout << std::endl;
outfile << "0x" << std::setfill('0') << std::setw(8)
<< std::hex << std::uppercase << crcTable[i] << "U";
outfile << ", ";
if (i % 8 == 7)
outfile << std::endl;
}
outfile.close();
return 0;
}
|
2301_81045437/classic-platform
|
safety_security/SafeLib/Crc/models/crcTableGen/main.cpp
|
C++
|
unknown
| 2,561
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_CRC_00022 The Crc module shall comply with the following include file structure */
#include "Crc.h"
#define CRC_AR_RELEASE_MAJOR_VERSION_INT 4u
#define CRC_AR_RELEASE_MINOR_VERSION_INT 3u
#define CRC_AR_RELEASE_REVISION_VERSION_INT 0u
#define CRC_SW_MAJOR_VERSION_INT 2
#define CRC_SW_MINOR_VERSION_INT 0
/* @req SWS_CRC_00005 Version check SWS_BSWGeneral, chapter 5.1.8 */
/* @req SWS_BSW_00036 Inter Module Checks to avoid integration of incompatible files */
#if (CRC_SW_MAJOR_VERSION != CRC_SW_MAJOR_VERSION_INT) || (CRC_SW_MINOR_VERSION != CRC_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between Crc.c and Crc.h"
#endif
#if (CRC_AR_RELEASE_MAJOR_VERSION != CRC_AR_RELEASE_MAJOR_VERSION_INT) || (CRC_AR_RELEASE_MINOR_VERSION != CRC_AR_RELEASE_MINOR_VERSION_INT) || \
(CRC_AR_RELEASE_REVISION_VERSION != CRC_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between Crc.c and Crc.h"
#endif
/* @req SWS_CRC_00011 The function Crc_GetVersionInfo shall return the version information of the Crc module */
/* @req SWS_CRC_00021 API for Crc_GetVersionInfo */
/* @req SWS_BSW_00064 Get Version Information function shall be executed synchronously to its call and shall be reentrant */
/* @req SWS_BSW_00052 Get Version Information function shall have only one parameter. */
/* @req SWS_BSW_00164 Ther should be no restriction to Get Version Information calling context */
/* @req SWS_BSW_00051*/
/** @brief Return the version information of Crc module.
*
* The function Crc_GetVersionInfo shall return the version
* information of the Crc module.
* The version information includes:
* - Module Id
* - Vendor Id
* - sw_major_version
* - sw_minor_version
* - sw_patch_version
*
* @param Std_VersionInfoType The type including Module and Vendor ID for the Crc Module.
* @return void.
*/
#if (SAFELIB_VERSIONINFO_API == STD_ON)
void Crc_GetVersionInfo(Std_VersionInfoType* versioninfo) {
/* @req SWS_BSW_00212 NULL pointer checking */
if (versioninfo != NULL_PTR) {
versioninfo->vendorID = CRC_VENDOR_ID;
versioninfo->moduleID = CRC_MODULE_ID;
versioninfo->sw_major_version = CRC_SW_MAJOR_VERSION;
versioninfo->sw_minor_version = CRC_SW_MINOR_VERSION;
versioninfo->sw_patch_version = CRC_SW_PATCH_VERSION;
}
}
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/Crc/src/Crc.c
|
C
|
unknown
| 3,226
|
/*
* Copyright 2001-2010 Georges Menie (www.menie.org)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the University of California, Berkeley nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_CRC_00024 The Crc module shall provide the following files */
/* @req SWS_CRC_00022 The Crc module shall comply with the following include file structure */
#include "Crc.h"
#define CRC_16_AR_RELEASE_MAJOR_VERSION_INT 4u
#define CRC_16_AR_RELEASE_MINOR_VERSION_INT 3u
#define CRC_16_AR_RELEASE_REVISION_VERSION_INT 0u
#define CRC_16_SW_MAJOR_VERSION_INT 2
#define CRC_16_SW_MINOR_VERSION_INT 0
/* @req SWS_CRC_00005 Version check SWS_BSWGeneral, chapter 5.1.8, SWS_BSW_00036
* Inter Module Checks to avoid integration of incompatible files */
#if (CRC_SW_MAJOR_VERSION != CRC_16_SW_MAJOR_VERSION_INT) || (CRC_SW_MINOR_VERSION != CRC_16_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between Crc_16.c and Crc.h"
#endif
#if (CRC_AR_RELEASE_MAJOR_VERSION != CRC_16_AR_RELEASE_MAJOR_VERSION_INT) || (CRC_AR_RELEASE_MINOR_VERSION != CRC_16_AR_RELEASE_MINOR_VERSION_INT) || \
(CRC_AR_RELEASE_REVISION_VERSION != CRC_16_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between Crc_16.c and Crc.h"
#endif
#ifndef Crc_16_Mode
#define Crc_16_Mode 0
#endif
/* Check that the CRC 16 configuration is consistent */
#if Crc_16_Mode == CRC_16_HARDWARE
#error "Crc_16_Mode is set to CRC_16_HARDWARE which isn't supported"
#endif
/* For CRC16, https://en.wikipedia.org/wiki/Cyclic_redundancy_check */
#ifdef Crc_16_Mode
#define Crc_16_CCITTStartValue 0xFFFFU
#define Crc_16_CCITTPolynomial 0x1021U
#define Crc_16_CCITTXor 0x0000U
#endif
/* CRC16 implementation according to CCITT standards */
#if Crc_16_Mode == CRC_16_RUNTIME
/** @brief Calculation of 16-bit CRC, used to compare result with the table lookup in the actual implementation
* in the CRC module.
*
* @param message Pointer to start address of data block to be calculated.
* @param nBytes Length of data block to be calculated in bytes.
* @param start Start value when the algorithm starts.
*
* @return 16 bit result of CRC calculation.
*/
static uint16 calculateCRC16(const uint8* message, uint32 nBytes, uint16 start)
{
uint16 remainder = start;
uint8 bit;
const uint16 topbit = 0x8000;
/* @req SWS_BSW_00212 NULL pointer checking */
/* @CODECOV:PARAMETER_VALIDATION_PRIVATE_FUNCTION:This will always be TRUE due to already validated in public function */
__CODE_COVERAGE_IGNORE__
if (message != NULL_PTR) {
/* Perform modulo-2 division, a byte at a time. */
for (uint32 byte = 0; byte < nBytes; byte++) {
/* Bring the next byte into the remainder. */
uint16 messageToShift = *message;
remainder ^= (uint16)(messageToShift << 8u);
message++;
/* Perform modulo-2 division, a bit at a time. */
for (bit = 8; bit > 0; bit--) {
/* Try to divide the current data bit. */
if ((remainder & topbit) != 0) {
remainder = (uint16)(remainder << 1u) ^ Crc_16_CCITTPolynomial;
}
else {
remainder = (uint16)(remainder << 1u);
}
}
}
}
return remainder;
}
#endif
#if (Crc_16_Mode == CRC_16_RUNTIME) || (Crc_16_Mode == CRC_16_TABLE)
/* @req SWS_CRC_00002 The CRC module shall implement the CRC16 routine based on the CCITT-FALSE CRC16 Standard */
/* @req SWS_CRC_00015 The function Crc_CalculateCRC16 shall perform a CRC16 calculation on Crc_Length data bytes,
* pointed to by Crc_DataPtr, with the starting value of Crc_StartValue16 */
/* @req SWS_CRC_00019 API for 16-bit CCITT-FALSE CRC16 */
/* @req SWS_CRC_00054 The function shall provide the specified CRC results in AUTOSAR_SWS_CRCLibrary.pdf */
/** @brief This service makes a CRC16 calculation on Crc_Length data bytes,
* using the polynomial 0x1021.
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue16 Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 16 bit result of CRC calculation.
*/
uint16 Crc_CalculateCRC16(const uint8* Crc_DataPtr, uint32 Crc_Length, uint16 Crc_StartValue16, boolean Crc_IsFirstCall) {
uint16 crc = 0; /* Default return value if NULL pointer */
#if Crc_16_Mode == CRC_16_TABLE
static const uint16 Crc_16_Tab[256] = { 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
};
#endif
/* @req SWS_BSW_00212 NULL pointer checking */
if (Crc_DataPtr != NULL_PTR) {
crc = (TRUE == Crc_IsFirstCall) ? Crc_16_CCITTStartValue : (Crc_StartValue16 ^ Crc_16_CCITTXor); /*lint !e835 LINT:OTHER:Readability */
#if Crc_16_Mode == CRC_16_RUNTIME
crc = calculateCRC16(Crc_DataPtr, Crc_Length, crc);
#elif Crc_16_Mode == CRC_16_TABLE
for(uint32 byte = 0; byte < Crc_Length; byte++) {
crc = (uint16)(crc<<8) ^ Crc_16_Tab[((crc>>8) ^ *Crc_DataPtr)&0x00FFU];
Crc_DataPtr++;
}
#endif
crc = crc ^ Crc_16_CCITTXor;
}
return crc;
}
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/Crc/src/Crc_16.c
|
C
|
unknown
| 10,102
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_CRC_00024 The Crc module shall provide the following files */
/* @req SWS_CRC_00022 The Crc module shall comply with the following include file structure */
#include "Crc.h"
#define CRC_32_AR_RELEASE_MAJOR_VERSION_INT 4u
#define CRC_32_AR_RELEASE_MINOR_VERSION_INT 3u
#define CRC_32_AR_RELEASE_REVISION_VERSION_INT 0u
#define CRC_32_SW_MAJOR_VERSION_INT 2
#define CRC_32_SW_MINOR_VERSION_INT 0
/* @req SWS_CRC_00005 Version check SWS_BSWGeneral, chapter 5.1.8, SWS_BSW_00036
* Inter Module Checks to avoid integration of incompatible files */
#if (CRC_SW_MAJOR_VERSION != CRC_32_SW_MAJOR_VERSION_INT) || (CRC_SW_MINOR_VERSION != CRC_32_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between Crc_32.c and Crc.h"
#endif
#if (CRC_AR_RELEASE_MAJOR_VERSION != CRC_32_AR_RELEASE_MAJOR_VERSION_INT) || (CRC_AR_RELEASE_MINOR_VERSION != CRC_32_AR_RELEASE_MINOR_VERSION_INT) || \
(CRC_AR_RELEASE_REVISION_VERSION != CRC_32_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between Crc_32.c and Crc.h"
#endif
#ifndef Crc_32_Mode
#define Crc_32_Mode 0
#endif
/* Check that the CRC 32 configuration is consistent */
#if Crc_32_Mode == CRC_32_HARDWARE
#error "Crc_32_Mode is set to CRC_32_HARDWARE which isn't supported"
#endif
/* For CRC32, https://en.wikipedia.org/wiki/Cyclic_redundancy_check */
#ifdef Crc_32_Mode
#define Crc_32_StartValue 0xFFFFFFFFU
#define Crc_32_Polynomial 0x04C11DB7U
#define Crc_32_Xor 0xFFFFFFFFU
#endif
#if Crc_32_Mode == CRC_32_RUNTIME
/** @brief Reflects the result bit by bit
*
* @param data Input data
*
* @return reflected data
*/
static INLINE uint32 reflectResult(uint32 data)
{
uint32 reflection = 0x00000000U;
uint8 bit;
uint32 tmpData = data;
for (bit = 0; bit < 32; bit++) {
/* Set reflection */
if ((tmpData & 0x01U) != 0) {
reflection |= (1UL << (31UL - bit));
}
tmpData = tmpData >> 1;
}
return reflection;
}
/** @brief Reflects the indata bit by bit
*
* @param data Input data
*
* @return reflected data
*/
static INLINE uint8 reflectInData(uint8 data)
{
uint8 reflection = 0x00;
uint8 bit;
uint32 tmpData = data;
for (bit = 0; bit < 8; bit++) {
if ((tmpData & 0x01U) != 0) {
reflection |= (uint8)(1U << (7U-bit));
}
tmpData = (tmpData >> 1U);
}
return reflection;
}
/** @brief Calculation of 32-bit CRC,
* used to compare result with the table lookup in the actual implementation in the CRC module.
*
* @param message Pointer to start address of data block to be calculated.
* @param nBytes Length of data block to be calculated in bytes.
* @param start Start value when the algorithm starts.
*
* @return 32 bit result of CRC calculation.
*/
static uint32 calculateCRC32(const uint8* message, uint32 nBytes, uint32 start)
{
uint32 remainder = reflectResult(start);
uint8 bit;
const uint32 topbit = 0x80000000U;
/* @req SWS_BSW_00212 NULL pointer checking */
/* @CODECOV:PARAMETER_VALIDATION_PRIVATE_FUNCTION:This will always be TRUE due to already validated in public function */
__CODE_COVERAGE_IGNORE__
if (message != NULL_PTR) {
/* Perform modulo-2 division, a byte at a time. */
for (uint32 byte = 0; byte < nBytes; byte++) {
/* Bring the next byte into the remainder. */
uint32 reflectedData = reflectInData(*message);
remainder ^= (reflectedData << 24u);
message++;
/* Perform modulo-2 division, a bit at a time. */
for (bit = 8; bit > 0; bit--) {
/* Try to divide the current data bit. */
if ((remainder & topbit) != 0) {
remainder = (remainder << 1u) ^ Crc_32_Polynomial;
}
else {
remainder = (remainder << 1u);
}
}
}
}
return reflectResult(remainder);
}
#endif
#if (Crc_32_Mode == CRC_32_RUNTIME) || (Crc_32_Mode == CRC_32_TABLE)
/* @req SWS_CRC_00003 The CRC module shall implement the CRC32 routine based on the IEEE-802.3 CRC32 Ethernet Standard */
/* @req SWS_CRC_00016 The function Crc_CalculateCRC32 shall perform a CRC32 calculation on Crc_Length data bytes,
* pointed to by Crc_DataPtr, with the starting value of Crc_StartValue32 */
/* @req SWS_CRC_00020 API for 32-bit Ethernet CRC Calculation */
/* @req SWS_CRC_00055 The function shall provide the specified CRC results in AUTOSAR_SWS_CRCLibrary.pdf */
/** @brief This service makes a CRC32 calculation on Crc_Length data bytes,
* using the polynomial 0x04C11DB7.
*
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue32 Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 32 bit result of CRC calculation.
*/
uint32 Crc_CalculateCRC32(const uint8* Crc_DataPtr, uint32 Crc_Length, uint32 Crc_StartValue32, boolean Crc_IsFirstCall) {
uint32 crc = 0; /* Default return value if NULL pointer */
#if Crc_32_Mode == CRC_32_TABLE
static const uint32 Crc_32_Tab[] = { 0x00000000U,0x77073096U,0xEE0E612CU,0x990951BAU,0x076DC419U,0x706AF48FU,0xE963A535U,0x9E6495A3U,
0x0EDB8832U,0x79DCB8A4U,0xE0D5E91EU,0x97D2D988U,0x09B64C2BU,0x7EB17CBDU,0xE7B82D07U,0x90BF1D91U,
0x1DB71064U,0x6AB020F2U,0xF3B97148U,0x84BE41DEU,0x1ADAD47DU,0x6DDDE4EBU,0xF4D4B551U,0x83D385C7U,
0x136C9856U,0x646BA8C0U,0xFD62F97AU,0x8A65C9ECU,0x14015C4FU,0x63066CD9U,0xFA0F3D63U,0x8D080DF5U,
0x3B6E20C8U,0x4C69105EU,0xD56041E4U,0xA2677172U,0x3C03E4D1U,0x4B04D447U,0xD20D85FDU,0xA50AB56BU,
0x35B5A8FAU,0x42B2986CU,0xDBBBC9D6U,0xACBCF940U,0x32D86CE3U,0x45DF5C75U,0xDCD60DCFU,0xABD13D59U,
0x26D930ACU,0x51DE003AU,0xC8D75180U,0xBFD06116U,0x21B4F4B5U,0x56B3C423U,0xCFBA9599U,0xB8BDA50FU,
0x2802B89EU,0x5F058808U,0xC60CD9B2U,0xB10BE924U,0x2F6F7C87U,0x58684C11U,0xC1611DABU,0xB6662D3DU,
0x76DC4190U,0x01DB7106U,0x98D220BCU,0xEFD5102AU,0x71B18589U,0x06B6B51FU,0x9FBFE4A5U,0xE8B8D433U,
0x7807C9A2U,0x0F00F934U,0x9609A88EU,0xE10E9818U,0x7F6A0DBBU,0x086D3D2DU,0x91646C97U,0xE6635C01U,
0x6B6B51F4U,0x1C6C6162U,0x856530D8U,0xF262004EU,0x6C0695EDU,0x1B01A57BU,0x8208F4C1U,0xF50FC457U,
0x65B0D9C6U,0x12B7E950U,0x8BBEB8EAU,0xFCB9887CU,0x62DD1DDFU,0x15DA2D49U,0x8CD37CF3U,0xFBD44C65U,
0x4DB26158U,0x3AB551CEU,0xA3BC0074U,0xD4BB30E2U,0x4ADFA541U,0x3DD895D7U,0xA4D1C46DU,0xD3D6F4FBU,
0x4369E96AU,0x346ED9FCU,0xAD678846U,0xDA60B8D0U,0x44042D73U,0x33031DE5U,0xAA0A4C5FU,0xDD0D7CC9U,
0x5005713CU,0x270241AAU,0xBE0B1010U,0xC90C2086U,0x5768B525U,0x206F85B3U,0xB966D409U,0xCE61E49FU,
0x5EDEF90EU,0x29D9C998U,0xB0D09822U,0xC7D7A8B4U,0x59B33D17U,0x2EB40D81U,0xB7BD5C3BU,0xC0BA6CADU,
0xEDB88320U,0x9ABFB3B6U,0x03B6E20CU,0x74B1D29AU,0xEAD54739U,0x9DD277AFU,0x04DB2615U,0x73DC1683U,
0xE3630B12U,0x94643B84U,0x0D6D6A3EU,0x7A6A5AA8U,0xE40ECF0BU,0x9309FF9DU,0x0A00AE27U,0x7D079EB1U,
0xF00F9344U,0x8708A3D2U,0x1E01F268U,0x6906C2FEU,0xF762575DU,0x806567CBU,0x196C3671U,0x6E6B06E7U,
0xFED41B76U,0x89D32BE0U,0x10DA7A5AU,0x67DD4ACCU,0xF9B9DF6FU,0x8EBEEFF9U,0x17B7BE43U,0x60B08ED5U,
0xD6D6A3E8U,0xA1D1937EU,0x38D8C2C4U,0x4FDFF252U,0xD1BB67F1U,0xA6BC5767U,0x3FB506DDU,0x48B2364BU,
0xD80D2BDAU,0xAF0A1B4CU,0x36034AF6U,0x41047A60U,0xDF60EFC3U,0xA867DF55U,0x316E8EEFU,0x4669BE79U,
0xCB61B38CU,0xBC66831AU,0x256FD2A0U,0x5268E236U,0xCC0C7795U,0xBB0B4703U,0x220216B9U,0x5505262FU,
0xC5BA3BBEU,0xB2BD0B28U,0x2BB45A92U,0x5CB36A04U,0xC2D7FFA7U,0xB5D0CF31U,0x2CD99E8BU,0x5BDEAE1DU,
0x9B64C2B0U,0xEC63F226U,0x756AA39CU,0x026D930AU,0x9C0906A9U,0xEB0E363FU,0x72076785U,0x05005713U,
0x95BF4A82U,0xE2B87A14U,0x7BB12BAEU,0x0CB61B38U,0x92D28E9BU,0xE5D5BE0DU,0x7CDCEFB7U,0x0BDBDF21U,
0x86D3D2D4U,0xF1D4E242U,0x68DDB3F8U,0x1FDA836EU,0x81BE16CDU,0xF6B9265BU,0x6FB077E1U,0x18B74777U,
0x88085AE6U,0xFF0F6A70U,0x66063BCAU,0x11010B5CU,0x8F659EFFU,0xF862AE69U,0x616BFFD3U,0x166CCF45U,
0xA00AE278U,0xD70DD2EEU,0x4E048354U,0x3903B3C2U,0xA7672661U,0xD06016F7U,0x4969474DU,0x3E6E77DBU,
0xAED16A4AU,0xD9D65ADCU,0x40DF0B66U,0x37D83BF0U,0xA9BCAE53U,0xDEBB9EC5U,0x47B2CF7FU,0x30B5FFE9U,
0xBDBDF21CU,0xCABAC28AU,0x53B39330U,0x24B4A3A6U,0xBAD03605U,0xCDD70693U,0x54DE5729U,0x23D967BFU,
0xB3667A2EU,0xC4614AB8U,0x5D681B02U,0x2A6F2B94U,0xB40BBE37U,0xC30C8EA1U,0x5A05DF1BU,0x2D02EF8D };
#endif
/* @req SWS_BSW_00212 NULL pointer checking */
if (Crc_DataPtr != NULL_PTR) {
crc = (TRUE == Crc_IsFirstCall) ? Crc_32_StartValue : (Crc_StartValue32 ^ Crc_32_Xor);
#if Crc_32_Mode == CRC_32_RUNTIME
crc = calculateCRC32(Crc_DataPtr, Crc_Length, crc);
#elif Crc_32_Mode == CRC_32_TABLE
for( uint32 byte = 0; byte < Crc_Length; byte++) {
crc = ((crc >> 8) & 0x00FFFFFFU) ^ Crc_32_Tab[(crc ^ *Crc_DataPtr) & 0xFFU];
Crc_DataPtr++;
}
#endif
crc = crc ^ Crc_32_Xor;
}
return crc;
}
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/Crc/src/Crc_32.c
|
C
|
unknown
| 11,284
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_CRC_00024 The Crc module shall provide the following files */
/* @req SWS_CRC_00022 The Crc module shall comply with the following include file structure */
#include "Crc.h"
#define CRC_32P4_AR_RELEASE_MAJOR_VERSION_INT 4u
#define CRC_32P4_AR_RELEASE_MINOR_VERSION_INT 3u
#define CRC_32P4_AR_RELEASE_REVISION_VERSION_INT 0u
#define CRC_32P4_SW_MAJOR_VERSION_INT 2
#define CRC_32P4_SW_MINOR_VERSION_INT 0
/* @req SWS_CRC_00005 Version check SWS_BSWGeneral, chapter 5.1.8, SWS_BSW_00036
* Inter Module Checks to avoid integration of incompatible files */
#if (CRC_SW_MAJOR_VERSION != CRC_32P4_SW_MAJOR_VERSION_INT) || (CRC_SW_MINOR_VERSION != CRC_32P4_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between Crc_32P4.c and Crc.h"
#endif
#if (CRC_AR_RELEASE_MAJOR_VERSION != CRC_32P4_AR_RELEASE_MAJOR_VERSION_INT) || (CRC_AR_RELEASE_MINOR_VERSION != CRC_32P4_AR_RELEASE_MINOR_VERSION_INT) || \
(CRC_AR_RELEASE_REVISION_VERSION != CRC_32P4_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between Crc_32P4.c and Crc.h"
#endif
#ifndef Crc_32P4_Mode
#define Crc_32P4_Mode 0
#endif
/* Check that the CRC 32 P4 configuration is consistent */
#if Crc_32P4_Mode == CRC_32P4_HARDWARE
#error "Crc_32P4_Mode is set to CRC_32_HARDWARE which isn't supported"
#endif
/* For CRC32, https://en.wikipedia.org/wiki/Cyclic_redundancy_check */
#ifdef Crc_32P4_Mode
#define Crc_32P4_StartValue 0xFFFFFFFFU
#define Crc_32P4_Polynomial 0xF4ACFB13U
#define Crc_32P4_Xor 0xFFFFFFFFU
#endif
#if Crc_32P4_Mode == CRC_32P4_RUNTIME
/** @brief Reflects the result bit by bit
*
* @param data Input data
*
* @return reflected data
*/
static INLINE uint32 reflectResult(uint32 data)
{
uint32 reflection = 0x00000000U;
uint8 bit;
uint32 tmpData = data;
for (bit = 0; bit < 32; bit++) {
/* Set reflection */
if ((tmpData & 0x01U) != 0) {
reflection |= (1UL << (31UL - bit));
}
tmpData = tmpData >> 1;
}
return reflection;
}
/** @brief Reflects the indata bit by bit
*
* @param data Input data
*
* @return reflected data
*/
static INLINE uint8 reflectInData(uint8 data)
{
uint8 reflection = 0x00;
uint8 bit;
uint32 tmpData = data;
for (bit = 0; bit < 8; bit++) {
if ((tmpData & 0x01U) != 0) {
reflection |= (uint8)(1U << (7U-bit));
}
tmpData = (tmpData >> 1U);
}
return reflection;
}
/** @brief Calculation of 32-bit CRC,
* used to compare result with the table lookup in the actual implementation in the CRC module.
*
* @param message Pointer to start address of data block to be calculated.
* @param nBytes Length of data block to be calculated in bytes.
* @param start Start value when the algorithm starts.
*
* @return 32 bit result of CRC calculation.
*/
static uint32 calculateCRC32P4(const uint8* message, uint32 nBytes, uint32 start)
{
uint32 remainder = reflectResult(start);
uint8 bit;
const uint32 topbit = 0x80000000U;
/* @req SWS_BSW_00212 NULL pointer checking */
/* @CODECOV:PARAMETER_VALIDATION_PRIVATE_FUNCTION:This will always be TRUE due to already validated in public function */
__CODE_COVERAGE_IGNORE__
if (message != NULL_PTR) {
/* Perform modulo-2 division, a byte at a time. */
for (uint32 byte = 0; byte < nBytes; byte++) {
/* Bring the next byte into the remainder. */
uint32 reflectedData = reflectInData(*message);
remainder ^= (reflectedData << 24u);
message++;
/* Perform modulo-2 division, a bit at a time. */
for (bit = 8; bit > 0; bit--) {
/* Try to divide the current data bit. */
if ((remainder & topbit) != 0) {
remainder = (remainder << 1u) ^ Crc_32P4_Polynomial;
}
else {
remainder = (remainder << 1u);
}
}
}
}
return reflectResult(remainder);
}
#endif
#if (Crc_32P4_Mode == CRC_32P4_RUNTIME) || (Crc_32P4_Mode == CRC_32P4_TABLE)
/* @req SWS_CRC_00056 The CRC module shall implement the CRC32 routine using the 0x1’F4’AC’FB’13 (0xF4’AC’FB’13) polynomial */
/* @req SWS_CRC_00059 The function Crc_CalculateCRC32P4 shall perform a CRC32 calculation using polynomial 0xF4ACFB13 on Crc_Length data bytes,
* pointed to by Crc_DataPtr, with the starting value of Crc_StartValue32 */
/* @req SWS_CRC_00058 API for 32-bit 0xF4ACFB13 polynomial CRC calculation */
/* @req SWS_CRC_00057 The function shall provide the specified CRC results in AUTOSAR_SWS_CRCLibrary.pdf */
/** @brief This service makes a CRC32 calculation on Crc_Length data bytes,
* using the polynomial 0xF4ACFB13. This CRC routine is used by E2E Profile 4.
*
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue32P4 Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 32 bit result of CRC calculation.
*/
uint32 Crc_CalculateCRC32P4(const uint8* Crc_DataPtr, uint32 Crc_Length, uint32 Crc_StartValue32, boolean Crc_IsFirstCall) {
uint32 crc = 0; /* Default return value if NULL pointer */
#if Crc_32P4_Mode == CRC_32P4_TABLE
static const uint32 Crc_32P4_Tab[] = { 0x00000000U, 0x30850FF5U, 0x610A1FEAU, 0x518F101FU, 0xC2143FD4U, 0xF2913021U, 0xA31E203EU, 0x939B2FCBU,
0x159615F7U, 0x25131A02U, 0x749C0A1DU, 0x441905E8U, 0xD7822A23U, 0xE70725D6U, 0xB68835C9U, 0x860D3A3CU,
0x2B2C2BEEU, 0x1BA9241BU, 0x4A263404U, 0x7AA33BF1U, 0xE938143AU, 0xD9BD1BCFU, 0x88320BD0U, 0xB8B70425U,
0x3EBA3E19U, 0x0E3F31ECU, 0x5FB021F3U, 0x6F352E06U, 0xFCAE01CDU, 0xCC2B0E38U, 0x9DA41E27U, 0xAD2111D2U,
0x565857DCU, 0x66DD5829U, 0x37524836U, 0x07D747C3U, 0x944C6808U, 0xA4C967FDU, 0xF54677E2U, 0xC5C37817U,
0x43CE422BU, 0x734B4DDEU, 0x22C45DC1U, 0x12415234U, 0x81DA7DFFU, 0xB15F720AU, 0xE0D06215U, 0xD0556DE0U,
0x7D747C32U, 0x4DF173C7U, 0x1C7E63D8U, 0x2CFB6C2DU, 0xBF6043E6U, 0x8FE54C13U, 0xDE6A5C0CU, 0xEEEF53F9U,
0x68E269C5U, 0x58676630U, 0x09E8762FU, 0x396D79DAU, 0xAAF65611U, 0x9A7359E4U, 0xCBFC49FBU, 0xFB79460EU,
0xACB0AFB8U, 0x9C35A04DU, 0xCDBAB052U, 0xFD3FBFA7U, 0x6EA4906CU, 0x5E219F99U, 0x0FAE8F86U, 0x3F2B8073U,
0xB926BA4FU, 0x89A3B5BAU, 0xD82CA5A5U, 0xE8A9AA50U, 0x7B32859BU, 0x4BB78A6EU, 0x1A389A71U, 0x2ABD9584U,
0x879C8456U, 0xB7198BA3U, 0xE6969BBCU, 0xD6139449U, 0x4588BB82U, 0x750DB477U, 0x2482A468U, 0x1407AB9DU,
0x920A91A1U, 0xA28F9E54U, 0xF3008E4BU, 0xC38581BEU, 0x501EAE75U, 0x609BA180U, 0x3114B19FU, 0x0191BE6AU,
0xFAE8F864U, 0xCA6DF791U, 0x9BE2E78EU, 0xAB67E87BU, 0x38FCC7B0U, 0x0879C845U, 0x59F6D85AU, 0x6973D7AFU,
0xEF7EED93U, 0xDFFBE266U, 0x8E74F279U, 0xBEF1FD8CU, 0x2D6AD247U, 0x1DEFDDB2U, 0x4C60CDADU, 0x7CE5C258U,
0xD1C4D38AU, 0xE141DC7FU, 0xB0CECC60U, 0x804BC395U, 0x13D0EC5EU, 0x2355E3ABU, 0x72DAF3B4U, 0x425FFC41U,
0xC452C67DU, 0xF4D7C988U, 0xA558D997U, 0x95DDD662U, 0x0646F9A9U, 0x36C3F65CU, 0x674CE643U, 0x57C9E9B6U,
0xC8DF352FU, 0xF85A3ADAU, 0xA9D52AC5U, 0x99502530U, 0x0ACB0AFBU, 0x3A4E050EU, 0x6BC11511U, 0x5B441AE4U,
0xDD4920D8U, 0xEDCC2F2DU, 0xBC433F32U, 0x8CC630C7U, 0x1F5D1F0CU, 0x2FD810F9U, 0x7E5700E6U, 0x4ED20F13U,
0xE3F31EC1U, 0xD3761134U, 0x82F9012BU, 0xB27C0EDEU, 0x21E72115U, 0x11622EE0U, 0x40ED3EFFU, 0x7068310AU,
0xF6650B36U, 0xC6E004C3U, 0x976F14DCU, 0xA7EA1B29U, 0x347134E2U, 0x04F43B17U, 0x557B2B08U, 0x65FE24FDU,
0x9E8762F3U, 0xAE026D06U, 0xFF8D7D19U, 0xCF0872ECU, 0x5C935D27U, 0x6C1652D2U, 0x3D9942CDU, 0x0D1C4D38U,
0x8B117704U, 0xBB9478F1U, 0xEA1B68EEU, 0xDA9E671BU, 0x490548D0U, 0x79804725U, 0x280F573AU, 0x188A58CFU,
0xB5AB491DU, 0x852E46E8U, 0xD4A156F7U, 0xE4245902U, 0x77BF76C9U, 0x473A793CU, 0x16B56923U, 0x263066D6U,
0xA03D5CEAU, 0x90B8531FU, 0xC1374300U, 0xF1B24CF5U, 0x6229633EU, 0x52AC6CCBU, 0x03237CD4U, 0x33A67321U,
0x646F9A97U, 0x54EA9562U, 0x0565857DU, 0x35E08A88U, 0xA67BA543U, 0x96FEAAB6U, 0xC771BAA9U, 0xF7F4B55CU,
0x71F98F60U, 0x417C8095U, 0x10F3908AU, 0x20769F7FU, 0xB3EDB0B4U, 0x8368BF41U, 0xD2E7AF5EU, 0xE262A0ABU,
0x4F43B179U, 0x7FC6BE8CU, 0x2E49AE93U, 0x1ECCA166U, 0x8D578EADU, 0xBDD28158U, 0xEC5D9147U, 0xDCD89EB2U,
0x5AD5A48EU, 0x6A50AB7BU, 0x3BDFBB64U, 0x0B5AB491U, 0x98C19B5AU, 0xA84494AFU, 0xF9CB84B0U, 0xC94E8B45U,
0x3237CD4BU, 0x02B2C2BEU, 0x533DD2A1U, 0x63B8DD54U, 0xF023F29FU, 0xC0A6FD6AU, 0x9129ED75U, 0xA1ACE280U,
0x27A1D8BCU, 0x1724D749U, 0x46ABC756U, 0x762EC8A3U, 0xE5B5E768U, 0xD530E89DU, 0x84BFF882U, 0xB43AF777U,
0x191BE6A5U, 0x299EE950U, 0x7811F94FU, 0x4894F6BAU, 0xDB0FD971U, 0xEB8AD684U, 0xBA05C69BU, 0x8A80C96EU,
0x0C8DF352U, 0x3C08FCA7U, 0x6D87ECB8U, 0x5D02E34DU, 0xCE99CC86U, 0xFE1CC373U, 0xAF93D36CU, 0x9F16DC99U };
#endif
/* @req SWS_BSW_00212 NULL pointer checking */
if (Crc_DataPtr != NULL_PTR) {
crc = (TRUE == Crc_IsFirstCall) ? Crc_32P4_StartValue : (Crc_StartValue32 ^ Crc_32P4_Xor);
#if Crc_32P4_Mode == CRC_32P4_RUNTIME
crc = calculateCRC32P4(Crc_DataPtr, Crc_Length, crc);
#elif Crc_32P4_Mode == CRC_32P4_TABLE
for( uint32 byte = 0; byte < Crc_Length; byte++) {
crc = ((crc >> 8) & 0x00FFFFFFU) ^ Crc_32P4_Tab[(crc ^ *Crc_DataPtr) & 0xFFU];
Crc_DataPtr++;
}
#endif
crc = crc ^ Crc_32P4_Xor;
}
return crc;
}
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/Crc/src/Crc_32P4.c
|
C
|
unknown
| 11,769
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_CRC_00024 The Crc module shall provide the following files */
/* @req SWS_CRC_00022 The Crc module shall comply with the following include file structure */
#include "Crc.h"
#define CRC_8_AR_RELEASE_MAJOR_VERSION_INT 4u
#define CRC_8_AR_RELEASE_MINOR_VERSION_INT 3u
#define CRC_8_AR_RELEASE_REVISION_VERSION_INT 0u
#define CRC_8_SW_MAJOR_VERSION_INT 2
#define CRC_8_SW_MINOR_VERSION_INT 0
/* @req SWS_CRC_00005 Version check SWS_BSWGeneral, chapter 5.1.8, SWS_BSW_00036
* Inter Module Checks to avoid integration of incompatible files */
#if (CRC_SW_MAJOR_VERSION != CRC_8_SW_MAJOR_VERSION_INT) || (CRC_SW_MINOR_VERSION != CRC_8_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between Crc_8.c and Crc.h"
#endif
#if (CRC_AR_RELEASE_MAJOR_VERSION != CRC_8_AR_RELEASE_MAJOR_VERSION_INT) || (CRC_AR_RELEASE_MINOR_VERSION != CRC_8_AR_RELEASE_MINOR_VERSION_INT) || \
(CRC_AR_RELEASE_REVISION_VERSION != CRC_8_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between Crc_8.c and Crc.h"
#endif
#ifndef Crc_8_Mode
#define Crc_8_Mode 0
#endif
/* Check that the CRC 8 configuration is consistent */
#if Crc_8_Mode == CRC_8_HARDWARE
#error "Crc_8_Mode is set to Crc_8_Hardware which isn't supported"
#endif
#ifndef Crc_8_8H2FMode
#define Crc_8_8H2FMode 0
#endif
/* Check that the CRC 8H2F configuration is consistent */
#if Crc_8_8H2FMode == CRC_8H2F_HARDWARE
#error "Crc_8_8H2FMode is set to Crc_8_8H2FHardware which isn't supported"
#endif
/* For CRC 8 SAE-1850, compare https://en.wikipedia.org/wiki/Cyclic_redundancy_check */
#if Crc_8_Mode == CRC_8_RUNTIME
#define Crc_8_Polynomial 0x1D
#endif
/* For CRC 8H2F, https://en.wikipedia.org/wiki/Cyclic_redundancy_check */
#if Crc_8_8H2FMode == CRC_8H2F_RUNTIME
#define Crc_8_8H2FPolynomial 0x2F
#endif
/* For CRC 8*/
#if (Crc_8_Mode == CRC_8_RUNTIME) || (Crc_8_Mode == CRC_8_TABLE)
#define Crc_8_StartValue 0xFFU
#define Crc_8_Xor 0xFFU
#endif
/* For CRC 8H2F */
#if (Crc_8_8H2FMode == CRC_8H2F_RUNTIME) || (Crc_8_8H2FMode == CRC_8H2F_TABLE)
#define Crc_8_8H2FStartValue 0xFFU
#define Crc_8_8H2FXor 0xFFU
#endif
#if (Crc_8_Mode == CRC_8_RUNTIME) || (Crc_8_8H2FMode == CRC_8H2F_RUNTIME)
/** @brief Calculation of 8-bit CRC, used to compare result with the table lookup in the actual implementation
* in the CRC module.
*
* @param message Pointer to start address of data block to be calculated.
* @param nBytes Length of data block to be calculated in bytes.
* @param start Start value when the algorithm starts.
* @param poly Polynomial used for CRC calculation.
*
* @return 8 bit result of CRC calculation.
*/
static uint8 calculateCRC8(const uint8* message, uint32 nBytes, uint8 start, uint8 poly)
{
uint8 remainder = start;
uint8 bit;
const uint8 topbit = 0x80;
/* @req SWS_BSW_00212 NULL pointer checking */
/* @CODECOV:PARAMETER_VALIDATION_PRIVATE_FUNCTION:This will always be TRUE due to already validated in public function */
__CODE_COVERAGE_IGNORE__
if (message != NULL_PTR) {
/* Perform modulo-2 division, a byte at a time. */
for (uint32 byte = 0; byte < nBytes; byte++) {
/* Bring the next byte into the remainder. */
remainder ^= *message;
message++;
/* Perform modulo-2 division, a bit at a time. */
for (bit = 8; bit > 0; bit--) {
/* Try to divide the current data bit. */
if ((remainder & topbit) != 0u) {
remainder = (uint8)(remainder << 1u) ^ poly;
}
else {
remainder = (uint8)(remainder << 1u);
}
}
}
}
return remainder;
}
#endif
/** @brief This service makes a CRC8 calculation on Crc_Length data bytes,
* using the polynomial 0x1D.
*
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue8 Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 8 bit result of CRC calculation.
*/
#if (Crc_8_Mode == CRC_8_RUNTIME) || (Crc_8_Mode == CRC_8_TABLE)
/* @req SWS_CRC_00030 The function of the CRC module shall implement
* the CRC8 routine based on the SAE-J1850 CRC8 Standard */
/* @req SWS_CRC_00031 API for 8-bit SAE J1850 CRC Calculation */
/* @req SWS_CRC_00032 The function Crc_CalculateCRC8 shall perform a CRC8 calculation
* on Crc_Length data bytes, pointed to by Crc_DataPtr, with the starting value of Crc_StartValue8 */
/* @req SWS_CRC_00052 The function shall provide the specified CRC results in AUTOSAR_SWS_CRCLibrary.pdf */
uint8 Crc_CalculateCRC8(const uint8* Crc_DataPtr, uint32 Crc_Length, uint8 Crc_StartValue8, boolean Crc_IsFirstCall) {
uint8 crc = 0; /* Default return value if NULL pointer */
#if Crc_8_Mode == CRC_8_TABLE
static const uint8 Crc_8_Tab[256] = {0x0, 0x1d, 0x3a, 0x27, 0x74, 0x69, 0x4e, 0x53,
0xe8, 0xf5, 0xd2, 0xcf, 0x9c, 0x81, 0xa6, 0xbb,
0xcd, 0xd0, 0xf7, 0xea, 0xb9, 0xa4, 0x83, 0x9e,
0x25, 0x38, 0x1f, 0x2, 0x51, 0x4c, 0x6b, 0x76,
0x87, 0x9a, 0xbd, 0xa0, 0xf3, 0xee, 0xc9, 0xd4,
0x6f, 0x72, 0x55, 0x48, 0x1b, 0x6, 0x21, 0x3c,
0x4a, 0x57, 0x70, 0x6d, 0x3e, 0x23, 0x4, 0x19,
0xa2, 0xbf, 0x98, 0x85, 0xd6, 0xcb, 0xec, 0xf1,
0x13, 0xe, 0x29, 0x34, 0x67, 0x7a, 0x5d, 0x40,
0xfb, 0xe6, 0xc1, 0xdc, 0x8f, 0x92, 0xb5, 0xa8,
0xde, 0xc3, 0xe4, 0xf9, 0xaa, 0xb7, 0x90, 0x8d,
0x36, 0x2b, 0xc, 0x11, 0x42, 0x5f, 0x78, 0x65,
0x94, 0x89, 0xae, 0xb3, 0xe0, 0xfd, 0xda, 0xc7,
0x7c, 0x61, 0x46, 0x5b, 0x8, 0x15, 0x32, 0x2f,
0x59, 0x44, 0x63, 0x7e, 0x2d, 0x30, 0x17, 0xa,
0xb1, 0xac, 0x8b, 0x96, 0xc5, 0xd8, 0xff, 0xe2,
0x26, 0x3b, 0x1c, 0x1, 0x52, 0x4f, 0x68, 0x75,
0xce, 0xd3, 0xf4, 0xe9, 0xba, 0xa7, 0x80, 0x9d,
0xeb, 0xf6, 0xd1, 0xcc, 0x9f, 0x82, 0xa5, 0xb8,
0x3, 0x1e, 0x39, 0x24, 0x77, 0x6a, 0x4d, 0x50,
0xa1, 0xbc, 0x9b, 0x86, 0xd5, 0xc8, 0xef, 0xf2,
0x49, 0x54, 0x73, 0x6e, 0x3d, 0x20, 0x7, 0x1a,
0x6c, 0x71, 0x56, 0x4b, 0x18, 0x5, 0x22, 0x3f,
0x84, 0x99, 0xbe, 0xa3, 0xf0, 0xed, 0xca, 0xd7,
0x35, 0x28, 0xf, 0x12, 0x41, 0x5c, 0x7b, 0x66,
0xdd, 0xc0, 0xe7, 0xfa, 0xa9, 0xb4, 0x93, 0x8e,
0xf8, 0xe5, 0xc2, 0xdf, 0x8c, 0x91, 0xb6, 0xab,
0x10, 0xd, 0x2a, 0x37, 0x64, 0x79, 0x5e, 0x43,
0xb2, 0xaf, 0x88, 0x95, 0xc6, 0xdb, 0xfc, 0xe1,
0x5a, 0x47, 0x60, 0x7d, 0x2e, 0x33, 0x14, 0x9,
0x7f, 0x62, 0x45, 0x58, 0xb, 0x16, 0x31, 0x2c,
0x97, 0x8a, 0xad, 0xb0, 0xe3, 0xfe, 0xd9, 0xc4};
#endif
/* @req SWS_BSW_00212 NULL pointer checking */
if (Crc_DataPtr != NULL_PTR) {
crc = (TRUE == Crc_IsFirstCall) ? Crc_8_StartValue : (Crc_StartValue8 ^ Crc_8_Xor);
#if Crc_8_Mode == CRC_8_RUNTIME
crc = calculateCRC8(Crc_DataPtr, Crc_Length, crc, Crc_8_Polynomial);
#elif Crc_8_Mode == CRC_8_TABLE
for (uint32 byte = 0; byte < Crc_Length; byte++) {
crc = Crc_8_Tab[crc ^ *Crc_DataPtr];
Crc_DataPtr++;
}
#endif
/* Only XOR value if any calculation was done */
crc = crc ^ Crc_8_Xor;
}
return crc;
}
#endif
#if (Crc_8_8H2FMode == CRC_8H2F_RUNTIME) || (Crc_8_8H2FMode == CRC_8H2F_TABLE)
/* @req SWS_CRC_00042 The Crc_CalculateCRC8H2F() function of the CRC module shall implement
* the CRC8 routine based on the generator polynomial 0x2F */
/* @req SWS_CRC_00043 API for 8-bit 0x2F polynomial CRC Calculation */
/* @req SWS_CRC_00044 The function Crc_CalculateCRC8H2F shall perform a CRC8 calculation
* with the polynomial 0x2F on Crc_Length data bytes, pointed to by Crc_DataPtr, with the starting value of Crc_StartValue8H2F */
/* @req SWS_CRC_00053 The function shall provide the specified CRC results in AUTOSAR_SWS_CRCLibrary.pdf */
/** @brief This service makes a CRC8 calculation on Crc_Length data bytes,
* using the polynomial 0x2F.
*
* @param Crc_DataPtr Pointer to start address of data block to be calculated.
* @param Crc_Length Length of data block to be calculated in bytes.
* @param Crc_StartValue8H2F Start value when the algorithm starts.
* @param Crc_IsFirstCall TRUE: First call in a sequence or individual CRC calculation;
* FALSE: Subsequent call in a call sequence.
* @return 8 bit result of CRC calculation.
*/
uint8 Crc_CalculateCRC8H2F(const uint8* Crc_DataPtr, uint32 Crc_Length, uint8 Crc_StartValue8H2F, boolean Crc_IsFirstCall) {
uint8 crc = 0;
#if Crc_8_8H2FMode == CRC_8H2F_TABLE
static const uint8 Crc_8_8H2FTab[256] = {0x0, 0x2f, 0x5e, 0x71, 0xbc, 0x93, 0xe2, 0xcd,
0x57, 0x78, 0x9, 0x26, 0xeb, 0xc4, 0xb5, 0x9a,
0xae, 0x81, 0xf0, 0xdf, 0x12, 0x3d, 0x4c, 0x63,
0xf9, 0xd6, 0xa7, 0x88, 0x45, 0x6a, 0x1b, 0x34,
0x73, 0x5c, 0x2d, 0x2, 0xcf, 0xe0, 0x91, 0xbe,
0x24, 0xb, 0x7a, 0x55, 0x98, 0xb7, 0xc6, 0xe9,
0xdd, 0xf2, 0x83, 0xac, 0x61, 0x4e, 0x3f, 0x10,
0x8a, 0xa5, 0xd4, 0xfb, 0x36, 0x19, 0x68, 0x47,
0xe6, 0xc9, 0xb8, 0x97, 0x5a, 0x75, 0x4, 0x2b,
0xb1, 0x9e, 0xef, 0xc0, 0xd, 0x22, 0x53, 0x7c,
0x48, 0x67, 0x16, 0x39, 0xf4, 0xdb, 0xaa, 0x85,
0x1f, 0x30, 0x41, 0x6e, 0xa3, 0x8c, 0xfd, 0xd2,
0x95, 0xba, 0xcb, 0xe4, 0x29, 0x6, 0x77, 0x58,
0xc2, 0xed, 0x9c, 0xb3, 0x7e, 0x51, 0x20, 0xf,
0x3b, 0x14, 0x65, 0x4a, 0x87, 0xa8, 0xd9, 0xf6,
0x6c, 0x43, 0x32, 0x1d, 0xd0, 0xff, 0x8e, 0xa1,
0xe3, 0xcc, 0xbd, 0x92, 0x5f, 0x70, 0x1, 0x2e,
0xb4, 0x9b, 0xea, 0xc5, 0x8, 0x27, 0x56, 0x79,
0x4d, 0x62, 0x13, 0x3c, 0xf1, 0xde, 0xaf, 0x80,
0x1a, 0x35, 0x44, 0x6b, 0xa6, 0x89, 0xf8, 0xd7,
0x90, 0xbf, 0xce, 0xe1, 0x2c, 0x3, 0x72, 0x5d,
0xc7, 0xe8, 0x99, 0xb6, 0x7b, 0x54, 0x25, 0xa,
0x3e, 0x11, 0x60, 0x4f, 0x82, 0xad, 0xdc, 0xf3,
0x69, 0x46, 0x37, 0x18, 0xd5, 0xfa, 0x8b, 0xa4,
0x5, 0x2a, 0x5b, 0x74, 0xb9, 0x96, 0xe7, 0xc8,
0x52, 0x7d, 0xc, 0x23, 0xee, 0xc1, 0xb0, 0x9f,
0xab, 0x84, 0xf5, 0xda, 0x17, 0x38, 0x49, 0x66,
0xfc, 0xd3, 0xa2, 0x8d, 0x40, 0x6f, 0x1e, 0x31,
0x76, 0x59, 0x28, 0x7, 0xca, 0xe5, 0x94, 0xbb,
0x21, 0xe, 0x7f, 0x50, 0x9d, 0xb2, 0xc3, 0xec,
0xd8, 0xf7, 0x86, 0xa9, 0x64, 0x4b, 0x3a, 0x15,
0x8f, 0xa0, 0xd1, 0xfe, 0x33, 0x1c, 0x6d, 0x42};
#endif
/* @req SWS_BSW_00212 NULL pointer checking */
if (Crc_DataPtr != NULL_PTR) {
crc = (TRUE == Crc_IsFirstCall) ? Crc_8_8H2FStartValue : (Crc_StartValue8H2F ^ Crc_8_8H2FXor);
#if Crc_8_8H2FMode == CRC_8H2F_RUNTIME
crc = calculateCRC8(Crc_DataPtr, Crc_Length, crc, Crc_8_8H2FPolynomial);
#elif Crc_8_8H2FMode == CRC_8H2F_TABLE
for (uint32 byte = 0; byte < Crc_Length; byte++) {
crc = Crc_8_8H2FTab[crc ^ *Crc_DataPtr];
Crc_DataPtr++;
}
#endif
crc = crc ^ Crc_8_8H2FXor;
}
return crc;
}
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/Crc/src/Crc_8.c
|
C
|
unknown
| 14,271
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
#ifndef CRC_MEMMAP_H_
#define CRC_MEMMAP_H_
#include "MemMap.h"
#endif /* CRC_MEMMAP_H_ */
|
2301_81045437/classic-platform
|
safety_security/SafeLib/Crc/src/Crc_MemMap.h
|
C
|
unknown
| 916
|
#E2E
obj-$(USE_E2E) += E2E.o
obj-$(USE_E2E) += E2E_P01.o
obj-$(USE_E2E) += E2E_P02.o
obj-$(USE_E2E) += E2E_P04.o
obj-$(USE_E2E) += E2E_P05.o
obj-$(USE_E2E) += E2E_P06.o
obj-$(USE_E2E) += E2E_SM.o
inc-$(USE_E2E) += $(ROOTDIR)/safety_security/SafeLib/E2E/inc
inc-$(USE_E2E) += $(ROOTDIR)/safety_security/SafeLib/E2E/src
vpath-$(USE_E2E) += $(ROOTDIR)/safety_security/SafeLib/E2E/src
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/E2E.mod.mk
|
Makefile
|
unknown
| 390
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @file E2E.h
*
* The E2E library provides
* *The definition of profiles 1,2,4,5 and 6 including check and protect functions
* *A state machine describing the logical algorithm of E2E monitoring independent of the used profile
*/
#ifndef E2E_H_
#define E2E_H_
/* @req SWS_E2E_00037 The E2E library shall not have any configuration options. */
/* @req SWS_E2E_00050 The implementation of the E2E Library shall comply with the requirements
* for the development of safety-related software for the automotive domain. */
/* @req SWS_E2E_00311 The configuration of the E2E Library and of the code invoking it
* (e.g. E2E wrapper or E2E callouts) shall be implemented and configured
* (including configuration options used from other subsystems, e.g. COM signal to I-PDU mapping)
* according to the requirements for the development of safety-related software for the automotive domain. */
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00048 E2E library shall be built of the following files:
* E2E.h (common header), E2E.c (implementation of common parts),
* E2E_PXX.c and E2E_PXX.h (where XX: e.g. 01, 02, … representing the profile)
* and E2E_SM.c and E2E_SM.h
*/
/* @req SWS_E2E_00110 The E2E library shall not call any functions from external
* modules apart from explicitly listed expected interfaces of E2E Library:
* Crc.h: Crc_CalculateCRC8, Crc_CalculateCRC16, Crc_CalculateCRC32P4, Crc_CalculateCRC8H2F*/
#include "Crc.h"
/* @req SWS_E2E_00017
* All types included shall be only Std_Types and Std_VersionInfoType
*/
#include "Std_Types.h"
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E_MemMap.h is included from all E2E files
*/
#include "E2E_MemMap.h"
/* @req SWS_E2E_00038
* The standardized common published parameters
* shall be published within the header file of this module.
*/
#define E2E_VENDOR_ID 60
#define E2E_MODULE_ID 207
#define E2E_AR_RELEASE_MAJOR_VERSION 4u
#define E2E_AR_RELEASE_MINOR_VERSION 3u
#define E2E_AR_RELEASE_REVISION_VERSION 0u
#define E2E_SW_MAJOR_VERSION 2u
#define E2E_SW_MINOR_VERSION 0u
#define E2E_SW_PATCH_VERSION 0u
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_AR_RELEASE_MAJOR_VERSION != CRC_AR_RELEASE_MAJOR_VERSION) || (E2E_AR_RELEASE_MINOR_VERSION != CRC_AR_RELEASE_MINOR_VERSION)
#error "SW Version mismatch between E2E.h and Crc.h"
#endif
/* @req SWS_E2E_00011
* The E2E Library shall report errors detected by library-internal
* mechanisms to callers of E2E functions through return value.
*/
/* @req SWS_E2E_00047 The following error flags for errors shall be used by all E2E Library functions: */
#define E2E_E_INPUTERR_NULL 0x13 //ASR4.3.0 At least one pointer parameter is a NULL pointer
#define E2E_E_INPUTERR_WRONG 0x17 //ASR4.3.0 At least one input parameter is erroneous, e.g. out of range
#define E2E_E_INTERR 0x19 //ASR4.3.0 An internal library error has occurred (e.g. error detected by program flow monitoring, violated invariant or postcondition)
#define E2E_E_OK 0x00 //ASR4.3.0 Function completed successfully
#define E2E_E_WRONGSTATE 0x1A //ASR4.3.0 Function executed in wrong state
/* @req SWS_E2E_00032 API: E2E_GetVersionInfo */
/* @req SWS_E2E_00033 The function E2E_GetVersionInfo shall return the version information of the E2E module */
/** @brief Return the version information of E2E module.
*
* The function E2E_GetVersionInfo shall return the version
* information of the E2E module.
* The version information includes:
* - Module Id
* - Vendor Id
* - sw_major_version
* - sw_minor_version
* - sw_patch_version
*
* @param Std_VersionInfoType The type including Module and Vendor ID for the E2E Module.
* @return void.
*/
#if (SAFELIB_VERSIONINFO_API == STD_ON)
void E2E_GetVersionInfo(Std_VersionInfoType* versioninfo);
#endif
#endif /* E2E_H_ */
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/inc/E2E.h
|
C
|
unknown
| 5,083
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @file E2E_P01.h
*
* The E2E Profile 1 provides a consistent set of data protection mechanisms,
* designed to protecting against the faults considered in the fault model.
*/
#ifndef E2E_P01_H_
#define E2E_P01_H_
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00217 The implementation of the E2E Library shall provide at least one of the E2E Profiles. */
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E.h is included from E2E_P01.h files
*/
#include "E2E.h"
/* AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies,
* does not show any requirement on E2E_SM.* files. But as the API
* is defined for E2E_P01, it is necessary to include E2E_SM.h here
*/
#include "E2E_SM.h"
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E_MemMap.h is included from all E2E files
*/
#include "E2E_MemMap.h"
#define E2E_P01_AR_RELEASE_MAJOR_VERSION 4u
#define E2E_P01_AR_RELEASE_MINOR_VERSION 3u
#define E2E_P01_AR_RELEASE_REVISION_VERSION 0u
#define E2E_P01_SW_MAJOR_VERSION 2
#define E2E_P01_SW_MINOR_VERSION 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_AR_RELEASE_MAJOR_VERSION != E2E_P01_AR_RELEASE_MAJOR_VERSION) || (E2E_AR_RELEASE_MINOR_VERSION != E2E_P01_AR_RELEASE_MINOR_VERSION)
#error "SW Version mismatch between E2E.h and E1E_P01.h"
#endif
#if (E2E_SM_AR_RELEASE_MAJOR_VERSION != E2E_P01_AR_RELEASE_MAJOR_VERSION) || (E2E_SM_AR_RELEASE_MINOR_VERSION != E2E_P01_AR_RELEASE_MINOR_VERSION)
#error "SW Version mismatch between E2E_SM.h and E1E_P01.h"
#endif
/* @req SWS_E2E_00200 */
/**
* The Data ID is two bytes long in E2E Profile 1.
* There are four inclusion modes how the implicit two-byte Data ID is included in the one-byte CRC.
*/
typedef enum {
/**
* Two bytes are included in the CRC (double ID configuration) This is used in E2E variant 1A.
*/
E2E_P01_DATAID_BOTH = 0x0,
/**
* One of the two bytes byte is included,
* alternating high and low byte, depending on parity of the counter (alternating ID configuration).
* For an even counter, the low byte is included. For an odd counter, the high byte is included.
* This is used in E2E variant 1B.
*/
E2E_P01_DATAID_ALT = 0x1,
/**
* Only the low byte is included, the high byte is never used.
* This is applicable if the IDs in a particular system are 8 bits.
*/
E2E_P01_DATAID_LOW = 0x2,
/**
* The low byte is included in the implicit CRC calculation,
* the low nibble of the high byte is transmitted along with the data (i.e. it is explicitly included),
* the high nibble of the high byte is not used.
* This is applicable for the IDs up to 12 bits. This is used in E2E variant 1C.
*/
E2E_P01_DATAID_NIBBLE = 0x3
} E2E_P01DataIDMode;
/* @req SWS_E2E_00085
* In E2E Profile 1, with E2E_P01DataIDMode equal to E2E_P01_DATAID_BOTH or E2E_P01_DATAID_ALT the length of the Data
* ID shall be 16 bits */
/* @req SWS_E2E_00227 Profile variant 1A, No explicit support for variants but the configuration allows such a configuration
* The E2E Profile variant 1A is defined as follows:
* 1. CRC is the 0th byte in the signal group (i.e. starts with bit offset 0)
* 2. Alive counter is located in lowest 4 bits of 1st byte (i.e. starts with bit offset 8)
* 3. E2E_P01DataIDMode = E2E_P01_DATAID_BOTH
* 4. SignalIPdu.unusedBitPattern = 0xFF.
*/
/* @req SWS_E2E_00228 Profile variant 1B, No explicit support for variants but the configuration allows such a configuration
* The E2E Profile variant 1B is defined as follows:
* 1. CRC is the 0th byte in the signal group (i.e. starts with bit offset 0)
* 2. Alive counter is located in lowest 4 bits of 1st byte (i.e. starts with bit offset 8)
* 3. E2E_P01DataIDMode = E2E_P01_DATAID_ALTERNATING
* 4. SignalIPdu.unusedBitPattern = 0xFF.
*/
/* @req SWS_E2E_00307 Profile variant 1C, No explicit support for variants but the configuration allows such a configuration
* The E2E Profile variant 1C is defined as follows:
* 1. CRC is the 0th byte in the signal group (i.e. starts with bit offset 0)
* 2. Alive counter is located in lowest 4 bits of 1st byte (i.e. starts with bit offset 8)
* 3. The Data ID nibble is located in the highest 4 bits of 1st byte (i.e. starts with bit offset 12)
* 4. E2E_P01DataIDMode = E2E_P01_DATAID_NIBBLE
* 5. SignalIPdu.unusedBitPattern = 0xFF.
*/
/* @req SWS_E2E_00018 */
/**
* Configuration of transmitted Data (Data Element or I-PDU), for E2E Profile 1.
* For each transmitted Data, there is an instance of this typedef.
*/
typedef struct {
/**
* Bit offset of Counter in MSB first order. In variants 1A and 1B, CounterOffset is 8.
* The offset shall be a multiple of 4.
*/
uint16 CounterOffset;
/**
* Bit offset of CRC (i.e. since *Data) in MSB first order. In variants 1A and 1B, CRCOffset is 0.
* The offset shall be a multiple of 8.
*/
uint16 CRCOffset;
/**
* A unique identifier, for protection against masquerading. There are some constraints on the selection of ID values,
* described in section "Configuration constraints on Data IDs".
*/
uint16 DataID;
/**
* Bit offset of the low nibble of the high byte of Data ID. This parameter is used by E2E Library only if
* DataIDMode = E2E_P01_DATAID_NIBBLE (otherwise it is ignored by E2E Library).
* For DataIDMode different than E2E_P01_DATAID_NIBBLE, DataIDNibbleOffset shall be initialized to 0 (even if it is ignored by E2E Library).
*/
uint16 DataIDNibbleOffset;
/**
* Inclusion mode of ID in CRC computation (both bytes, alternating, or low byte only of ID included).
*/
E2E_P01DataIDMode DataIDMode;
/**
* Length of data, in bits. The value shall be a multiple of 8 and shall be ≤ 240.
*/
uint16 DataLength;
/**
* Initial maximum allowed gap between two counter values of two consecutively received valid Data.
* For example, if the receiver gets Data with counter 1 and MaxDeltaCounterInit is 1,
* then at the next reception the receiver can accept Counters with values 2 and 3, but not 4.
* Note that if the receiver does not receive new Data at a consecutive read, then the receiver increments the tolerance by 1.
*/
uint8 MaxDeltaCounterInit;
/**
* The maximum amount of missing or repeated Data which the receiver does not expect to exceed under normal communication conditions.
*/
uint8 MaxNoNewOrRepeatedData;
/**
* Number of Data required for validating the consistency of the counter that must be received with a valid counter
* (i.e. counter within the allowed lock-in range) after the detection of an unexpected behavior of a received counter.
*/
uint8 SyncCounterInit;
} E2E_P01ConfigType;
/* @req SWS_E2E_00020 */
/**
* State of the sender for a Data protected with E2E Profile 1.
*/
typedef struct {
/**
* Counter to be used for protecting the next Data.
* The initial value is 0, which means that the first Data will have the counter 0.
* After the protection by the Counter, the Counter is incremented modulo 0xF.
* The value 0xF is skipped (after 0xE the next is 0x0), as 0xF value represents the error value.
* The four high bits are always 0.
*/
uint8 Counter;
} E2E_P01ProtectStateType;
/* @req SWS_E2E_00022 */
/**
* Result of the verification of the Data in E2E Profile 1, determined by the Check function.
*/
typedef enum {
/**
* OK: The new data has been received according to communication medium, the CRC is correct,
* the Counter is incremented by 1 with respect to the most recent Data received with Status _INITIAL, _OK, or _OKSOMELOST.
* This means that no Data has been lost since the last correct data reception.
*/
E2E_P01STATUS_OK = 0x00,
/**
* Error: the Check function has been invoked but no new Data is not available since the last call,
* according to communication medium (e.g. RTE, COM). As a result, no E2E checks of Data have been consequently executed.
*/
E2E_P01STATUS_NONEWDATA = 0x1,
/**
* Error: The data has been received according to communication medium, but
* 1. the CRC is incorrect (applicable for all E2E Profile 1 configurations) or
* 2. the low nibble of the high byte of Data ID is incorrect (applicable only for E2E Profile 1 with E2E_P01DataIDMode = E2E_P01_DATAID_NIBBLE).
* The two above errors can be a result of corruption, incorrect addressing or masquerade.
*/
E2E_P01STATUS_WRONGCRC = 0x2,
/**
* NOT VALID: The new data has been received after detection of an unexpected behavior of counter.
* The data has a correct CRC and a counter within the expected range with respect to the most recent Data received,
* but the determined continuity check for the counter is not finalized yet.
*/
E2E_P01STATUS_SYNC = 0x03,
/**
* Initial: The new data has been received according to communication medium, the CRC is correct,
* but this is the first Data since the receiver's initialization or reinitialization, so the Counter cannot be verified yet.
*/
E2E_P01STATUS_INITIAL = 0x4,
/**
* Error: The new data has been received according to communication medium, the CRC is correct,
* but the Counter is identical to the most recent Data received with Status _INITIAL, _OK, or _OKSOMELOST.
*/
E2E_P01STATUS_REPEATED = 0x8,
/**
* OK: The new data has been received according to communication medium, the CRC is correct,
* the Counter is incremented by DeltaCounter (1 < DeltaCounter = MaxDeltaCounter) with respect to
* the most recent Data received with Status _INITIAL, _OK, or _OKSOMELOST.
* This means that some Data in the sequence have been probably lost since the last correct/initial reception,
* but this is within the configured tolerance range.
*/
E2E_P01STATUS_OKSOMELOST = 0x20,
/**
* Error: The new data has been received according to communication medium, the CRC is correct,
* but the Counter Delta is too big (DeltaCounter > MaxDeltaCounter) with respect to
* the most recent Data received with Status _INITIAL, _OK, or _OKSOMELOST.
* This means that too many Data in the sequence have been probably lost since the last correct/initial reception.
*/
E2E_P01STATUS_WRONGSEQUENCE = 0x40
} E2E_P01CheckStatusType;
/* @req SWS_E2E_00021 */
/**
* State of the receiver for a Data protected with E2E Profile 1.
*/
typedef struct {
/**
* Counter value most recently received. If no data has been yet received, then the value is 0x0.
* After each reception, the counter is updated with the value received.
*/
uint8 LastValidCounter;
/**
* MaxDeltaCounter specifies the maximum allowed difference between two counter values
* of consecutively received valid messages.
*/
uint8 MaxDeltaCounter;
/**
* If true means that no correct data (with correct Data ID and CRC) has been yet received
* after the receiver initialization or reinitialization.
*/
boolean WaitForFirstData;
/**
* Indicates to E2E Library that a new data is available for Library to be checked.
* This attribute is set by the E2E Library caller, and not by the E2E Library.
*/
boolean NewDataAvailable;
/**
* Number of data (messages) lost since reception of last valid one. This attribute is set only if Status equals
* E2E_P01STATUS_OK or E2E_P01STATUS_OKSOMELOST. For other values of Status, the value of LostData is undefined.
* E2E_P01CheckStatusType Status Result of the verification of the Data, determined by the Check function.
*/
uint8 LostData;
/**
* Result of the verification of the Data, determined by the Check function.
*/
E2E_P01CheckStatusType Status;
/**
* Number of Data required for validating the consistency of the counter that must be received with a valid counter
* (i.e. counter within the allowed lock-in range) after the detection of an unexpected behavior of a received counter.
*/
uint8 SyncCounter;
/**
* Amount of consecutive reception cycles in which either (1) there was no new data, or (2) when the data was repeated.
*/
uint8 NoNewOrRepeatedDataCounter;
} E2E_P01CheckStateType; //new name E2E_P01CheckStateType according to ASR4.2.2
/** @brief Protects the array/buffer to be transmitted using the E2E profile 1.
* This includes checksum calculation, handling of counter and Data ID.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to Data to be transmitted.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00166 API for E2E_P01Protect */
Std_ReturnType E2E_P01Protect(const E2E_P01ConfigType* ConfigPtr, E2E_P01ProtectStateType* StatePtr, uint8* DataPtr);
/** @brief Checks the Data received using the E2E profile 1.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to received data.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00158 API for E2E_P01Check */
Std_ReturnType E2E_P01Check(const E2E_P01ConfigType* ConfigPtr, E2E_P01CheckStateType* StatePtr, const uint8* DataPtr);
/** @brief Initializes the protection state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00385 API for E2E_P01ProtectInit */
Std_ReturnType E2E_P01ProtectInit(E2E_P01ProtectStateType* StatePtr);
/** @brief Initializes the check state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00390 API for E2E_P01CheckInit */
Std_ReturnType E2E_P01CheckInit(E2E_P01CheckStateType* StatePtr);
/** @brief The function maps the check status of Profile 1 to a generic check status,
* which can be used by E2E state machine check function.
* The E2E Profile 1 delivers a more fine-granular status,
* but this is not relevant for the E2E state machine.
*
* @param CheckReturn Return value of the E2E_P01Check function.
* @param Status Status determined by E2E_P01Check function.
* @param profileBehavior FALSE: check has the legacy behavior, before R4.2
* TRUE: check behaves like new P4/P5/P6 profiles introduced in R4.2
* @return Profile-independent status of the reception on one single Data in one cycle.
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00382 API for E2E_P01MapStatusToSM */
E2E_PCheckStatusType E2E_P01MapStatusToSM(Std_ReturnType CheckReturn, E2E_P01CheckStatusType Status, boolean profileBehavior);
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/inc/E2E_P01.h
|
C
|
unknown
| 16,978
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @file E2E_P02.h
*
* The E2E Profile 2 provides a consistent set of data protection mechanisms,
* designed to protecting against the faults considered in the fault model.
*/
#ifndef E2E_P02_H_
#define E2E_P02_H_
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00217 The implementation of the E2E Library shall provide at least one of the E2E Profiles. */
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E.h is included from E2E_P01.h files
*/
#include "E2E.h"
/* AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies,
* does not show any requirement on E2E_SM.* files. But as the API
* is defined for E2E_P01, it is necessary to include E2E_SM.h here
*/
#include "E2E_SM.h"
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E_MemMap.h is included from all E2E files
*/
#include "E2E_MemMap.h"
#define E2E_P02_AR_RELEASE_MAJOR_VERSION 4u
#define E2E_P02_AR_RELEASE_MINOR_VERSION 3u
#define E2E_P02_AR_RELEASE_REVISION_VERSION 0u
#define E2E_P02_SW_MAJOR_VERSION 2
#define E2E_P02_SW_MINOR_VERSION 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_AR_RELEASE_MAJOR_VERSION != E2E_P02_AR_RELEASE_MAJOR_VERSION) || (E2E_AR_RELEASE_MINOR_VERSION != E2E_P02_AR_RELEASE_MINOR_VERSION)
#error "SW Version mismatch between E2E.h and E2E_P02.h"
#endif
#if (E2E_SM_AR_RELEASE_MAJOR_VERSION != E2E_P02_AR_RELEASE_MAJOR_VERSION) || (E2E_SM_AR_RELEASE_MINOR_VERSION != E2E_P02_AR_RELEASE_MINOR_VERSION)
#error "SW Version mismatch between E2E_SM.h and E1E_P02.h"
#endif
/* @req SWS_E2E_00214 */
/**
* Result of the verification of the Data in E2E Profile 2, determined by the Check function.
* As the enum data are not defined in the AUTOSAR_SWS_E2ELibrary.pdf, use UC_E2E_0302 for definition.
*/
typedef enum {
/**
* OK: The new data has been received according to communication medium, the CRC is correct,
* the Counter is incremented by 1 with respect to the most recent Data received with Status _INITIAL, _OK, or _OKSOMELOST.
* This means that no Data has been lost since the last correct data reception.
*/
E2E_P02STATUS_OK = 0x00,
/**
* Error: the Check function has been invoked but no new Data is not available since the last call,
* according to communication medium (e.g. RTE, COM). As a result, no E2E checks of Data have been consequently executed.
*/
E2E_P02STATUS_NONEWDATA = 0x01,
/**
* Error: The data has been received according to communication medium, but
*/
E2E_P02STATUS_WRONGCRC = 0x02,
/**
* NOT VALID: The new data has been received after detection of an unexpected behavior of counter.
* The data has a correct CRC and a counter within the expected range with respect to the most recent Data received,
* but the determined continuity check for the counter is not finalized yet.
*/
E2E_P02STATUS_SYNC = 0x03,
/**
* Initial: The new data has been received according to communication medium, the CRC is correct,
* but this is the first Data since the receiver's initialization or reinitialization, so the Counter cannot be verified yet.
*/
E2E_P02STATUS_INITIAL = 0x04,
/**
* Error: The new data has been received according to communication medium, the CRC is correct,
* but the Counter is identical to the most recent Data received with Status _INITIAL, _OK, or _OKSOMELOST.
*/
E2E_P02STATUS_REPEATED = 0x08,
/**
* OK: The new data has been received according to communication medium, the CRC is correct,
* the Counter is incremented by DeltaCounter (1 < DeltaCounter = MaxDeltaCounter) with respect to
* the most recent Data received with Status _INITIAL, _OK, or _OKSOMELOST.
* This means that some Data in the sequence have been probably lost since the last correct/initial reception,
* but this is within the configured tolerance range.
*/
E2E_P02STATUS_OKSOMELOST = 0x20,
/**
* Error: The new data has been received according to communication medium, the CRC is correct,
* but the Counter Delta is too big (DeltaCounter > MaxDeltaCounter) with respect to
* the most recent Data received with Status _INITIAL, _OK, or _OKSOMELOST.
* This means that too many Data in the sequence have been probably lost since the last correct/initial reception.
*/
E2E_P02STATUS_WRONGSEQUENCE = 0x40
} E2E_P02CheckStatusType;
/* @req SWS_E2E_00152 */
/**
* Non-modifiable configuration of the data element sent over an RTE port, for E2E profile 2.
* The position of the counter and CRC is not configurable in profile 2.
*/
typedef struct {
/**
* Length of Data, in bits. The value shall be a multiple of 8.
*/
uint16 DataLength;
/**
* An array of appropriately chosen Data IDs for protection against masquerading.
*/
uint8 DataIDList[16];
/**
* Initial maximum allowed gap between two counter values of two consecutively received valid Data. For example,
* if the receiver gets Data with counter 1 and MaxDeltaCounterInit is 1, then at the next reception the receiver
* can accept Counters with values 2 and 3, but not 4. Note that if the receiver does not receive new Data at a consecutive
* read, then the receiver increments the tolerance by 1.
*/
uint8 MaxDeltaCounterInit;
/**
* The maximum amount of missing or repeated Data which the receiver does not expect to exceed under normal communication conditions.
*/
uint8 MaxNoNewOrRepeatedData;
/**
* Number of Data required for validating the consistency of the counter that must be received with a valid counter
* (i.e. counter within the allowed lock-in range) after the detection of an unexpected behavior of a received counter.
*/
uint8 SyncCounterInit;
/**
* Offset of the E2E header in the Data[] array in bits. It shall be: 0 ≤ Offset ≤ MaxDataLength-(2*8).
*/
uint16 Offset;
} E2E_P02ConfigType;
/* @req SWS_E2E_00153 */
/**
* State of the sender for a Data protected with E2E Profile 2.
*/
typedef struct {
/**
* Counter to be used for protecting the Data.
* The initial value is 0, which means that the first Data will have the counter 0.
* After the protection by the counter, the counter is incremented modulo 16.
*/
uint8 Counter;
} E2E_P02ProtectStateType;
/* @req SWS_E2E_00154 */
/**
State of the sender for a Data protected with E2E Profile 2.
*/
typedef struct {
/**
* Counter of last valid received message.
*/
uint8 LastValidCounter;
/**
* MaxDeltaCounter specifies the maximum allowed difference between two counter values
* of consecutively received valid messages.
*/
uint8 MaxDeltaCounter;
/**
* If true means that no correct data (with correct Data ID and CRC) has been yet received
* after the receiver initialization or reinitialization.
*/
boolean WaitForFirstData;
/**
* Indicates to E2E Library that a new data is available for Library to be checked.
* This attribute is set by the E2E Library caller, and not by the E2E Library.
*/
boolean NewDataAvailable;
/**
* Number of data (messages) lost since reception of last valid one.
*/
uint8 LostData;
/**
* Result of the verification of the Data, determined by the Check function.
*/
E2E_P02CheckStatusType Status;
/**
* Number of Data required for validating the consistency of the counter that must be received with a valid counter
* (i.e. counter within the allowed lock-in range) after the detection of an unexpected behavior of a received counter.
*/
uint8 SyncCounter;
/**
* Amount of consecutive reception cycles in which either (1) there was no new data, or (2) when the data was repeated.
*/
uint8 NoNewOrRepeatedDataCounter;
} E2E_P02CheckStateType; //new name E2E_P02CheckStateType according to ASR4.2.2
/** @brief Protects the array/buffer to be transmitted using the E2E profile 2.
* This includes checksum calculation, handling of sequence counter and Data ID.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to Data to be transmitted.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00160 API for E2E_P02Protect */
Std_ReturnType E2E_P02Protect(const E2E_P02ConfigType* ConfigPtr, E2E_P02ProtectStateType* StatePtr, uint8* DataPtr);
/** @brief Check the array/buffer using the E2E profile 2.
* This includes checksum calculation, handling of sequence counter and Data ID.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to received data.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00161 API for E2E_P02Check*/
Std_ReturnType E2E_P02Check(const E2E_P02ConfigType* ConfigPtr, E2E_P02CheckStateType* StatePtr, const uint8* DataPtr);
/** @brief Initializes the protection state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00387 API for E2E_P02ProtectInit */
Std_ReturnType E2E_P02ProtectInit(E2E_P02ProtectStateType* StatePtr);
/** @brief Initializes the check state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00391 API for E2E_P02CheckInit */
Std_ReturnType E2E_P02CheckInit(E2E_P02CheckStateType* StatePtr);
/** @brief The function maps the check status of Profile 2 to a generic check status,
* which can be used by E2E state machine check function.
* The E2E Profile 2 delivers a more fine-granular status,
* but this is not relevant for the E2E state machine.
*
* @param CheckReturn Return value of the E2E_P02Check function.
* @param Status Status determined by E2E_P02Check function.
* @param profileBehavior FALSE: check has the legacy behavior, before R4.2
* TRUE: check behaves like new P4/P5/P6 profiles introduced in R4.2
* @return Profile-independent status of the reception on one single Data in one cycle.
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00379 API for E2E_P02MapStatusToSM */
E2E_PCheckStatusType E2E_P02MapStatusToSM(Std_ReturnType CheckReturn, E2E_P02CheckStatusType Status, boolean profileBehavior);
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/inc/E2E_P02.h
|
C
|
unknown
| 12,447
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @file E2E_P04.h
*
* The E2E Profile 4 provides a consistent set of data protection mechanisms,
* designed to protecting against the faults considered in the fault model.
*/
#ifndef E2E_P04_H_
#define E2E_P04_H_
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00217 The implementation of the E2E Library shall provide at least one of the E2E Profiles. */
/* AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies,
* does not show any requirement on E2E_SM.* files. But as the API
* is defined for E2E_P01, it is necessary to include E2E_SM.h here
*/
#include "E2E_SM.h"
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E_MemMap.h is included from all E2E files
*/
#include "E2E_MemMap.h"
#define E2E_P04_AR_RELEASE_MAJOR_VERSION 4u
#define E2E_P04_AR_RELEASE_MINOR_VERSION 3u
#define E2E_P04_AR_RELEASE_REVISION_VERSION 0u
#define E2E_P04_SW_MAJOR_VERSION 2
#define E2E_P04_SW_MINOR_VERSION 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_SM_AR_RELEASE_MAJOR_VERSION != E2E_P04_AR_RELEASE_MAJOR_VERSION) || (E2E_SM_AR_RELEASE_MINOR_VERSION != E2E_P04_AR_RELEASE_MINOR_VERSION)
#error "SW Version mismatch between E2E_SM.h and E1E_P04.h"
#endif
/* @req SWS_E2E_00337 */
/**
* Status of the reception on one single Data in one cycle, protected with E2E Profile 4.
*/
typedef enum {
/**
* OK: the checks of the Data in this cycle were successful
* (including counter check, which was incremented by 1).
*/
E2E_P04STATUS_OK = 0x00,
/**
* Error: the Check function has been invoked but no new Data is not available since the last call,
* according to communication medium (e.g. RTE, COM). As a result, no E2E checks of Data have been consequently executed.
* This may be considered similar to E2E_P04STATUS_REPEATED.
*/
E2E_P04STATUS_NONEWDATA = 0x01,
/**
* Error: error not related to counters occurred (e.g. wrong crc, wrong length, wrong options, wrong Data ID).
*/
E2E_P04STATUS_ERROR = 0x02,
/**
* Error: the checks of the Data in this cycle were successful, with the exception of the repetition.
*/
E2E_P04STATUS_REPEATED = 0x08,
/**
* OK: the checks of the Data in this cycle were successful (including counter check,
* which was incremented within the allowed configured delta).
*/
E2E_P04STATUS_OKSOMELOST = 0x20,
/**
* Error: the checks of the Data in this cycle were successful,
* with the exception of counter jump, which changed more than the allowed delta.
*/
E2E_P04STATUS_WRONGSEQUENCE = 0x40
} E2E_P04CheckStatusType;
/* @req SWS_E2E_00326
* In the E2E Profile 4, the Data ID shall be explicitly transmitted,
* i.e. it shall be the part of the transmitted E2E header. */
/* @req SWS_E2E_00372 Profile 4 shall provide the following control fields,
* transmitted at runtime together with the protected data:
*/
/* @req SWS_E2E_00334 */
/**
* Configuration of transmitted Data (Data Element or I-PDU), for E2E Profile 4.
* For each transmitted Data, there is an instance of this typedef.
*/
typedef struct {
/**
* A system-unique identifier of the Data.
*/
uint32 DataID;
/**
* Bit offset of the first bit of the E2E header from the beginning of the Data (bit numbering: bit 0 is the least important).
* The offset shall be a multiple of 8 and 0 ≤ Offset ≤ MaxDataLength-(12*8).
* Example: If Offset equals 8, then the high byte of the E2E Length (16 bit) is written to Byte 1, the low Byte is written to Byte 2.
*/
uint16 Offset;
/**
* Minimal length of Data, in bits. E2E checks that Length is ≥ MinDataLength. The value shall be = 4096*8 (4kB) and shall be ≥ 12*8.
*/
uint16 MinDataLength;
/**
* Maximal length of Data, in bits. E2E checks that DataLength is ≤ MinDataLength. The value shall be = 4096*8 (4kB) and it shall be ≥ MinDataLength.
*/
uint16 MaxDataLength;
/**
* Maximum allowed gap between two counter values of two consecutively received valid Data.
* For example, if the receiver gets Data with counter 1 and MaxDeltaCounter is 3,
* then at the next reception the receiver can accept Counters with values 2, 3 or 4.
*/
uint8 MaxDeltaCounter;
} E2E_P04ConfigType;
/* @req SWS_E2E_00335 */
/**
* State of the sender for a Data protected with E2E Profile 4.
*/
typedef struct {
/**
* Counter to be used for protecting the next Data. The initial value is 0, which means that in the first cycle,
* Counter is 0. Each time E2E_P04Protect() is called, it increments the counter up to 0xFF'FF.
* After the maximum value is reached, the next value is 0x0. The overflow is not reported to the caller.
*/
uint16 Counter;
} E2E_P04ProtectStateType;
/* @req SWS_E2E_00336 */
/**
* State of the reception on one single Data protected with E2E Profile 4.
*/
typedef struct {
/**
* Result of the verification of the Data in this cycle, determined by the Check function.
*/
E2E_P04CheckStatusType Status;
/**
* Counter of the data in previous cycle.
*/
uint16 Counter;
} E2E_P04CheckStateType;
/** @brief Protects the array/buffer to be transmitted using the E2E profile 4.
* This includes checksum calculation, handling of counter and Data ID.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to Data to be transmitted.
* @param Length Length of the data in bytes.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00338 API for E2E_P04Protect */
Std_ReturnType E2E_P04Protect(const E2E_P04ConfigType* ConfigPtr, E2E_P04ProtectStateType* StatePtr, uint8* DataPtr, uint16 Length);
/** @brief Checks the Data received using the E2E profile 4.
* This includes CRC calculation, handling of Counter and Data ID.
* The function checks only one single data in one cycle,
* it does not determine/compute the accumulated state of the communication link.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to received data.
* @param Length Length of the data in bytes.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00339 API for E2E_P04Check */
Std_ReturnType E2E_P04Check(const E2E_P04ConfigType* ConfigPtr, E2E_P04CheckStateType* StatePtr, const uint8* DataPtr, uint16 Length);
/** @brief Initializes the protection state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00373 API for E2E_P04ProtectInit */
Std_ReturnType E2E_P04ProtectInit(E2E_P04ProtectStateType* StatePtr);
/** @brief Initializes the check state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00350 API for E2E_P04CheckInit */
Std_ReturnType E2E_P04CheckInit(E2E_P04CheckStateType* StatePtr);
/** @brief The function maps the check status of Profile 4 to a generic check status,
* which can be used by E2E state machine check function.
* The E2E Profile 4 delivers a more fine-granular status,
* but this is not relevant for the E2E state machine.
*
* @param CheckReturn Return value of the E2E_P04Check function.
* @param Status Status determined by E2E_P04Check function.
* @return Profile-independent status of the reception on one single Data in one cycle.
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00349 API for E2E_P04MapStatusToSM */
E2E_PCheckStatusType E2E_P04MapStatusToSM(Std_ReturnType CheckReturn, E2E_P04CheckStatusType Status);
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/inc/E2E_P04.h
|
C
|
unknown
| 9,675
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @file E2E_P05.h
*
* The E2E Profile 5 provides a consistent set of data protection mechanisms,
* designed to protecting against the faults considered in the fault model.
*/
#ifndef E2E_P05_H_
#define E2E_P05_H_
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00217 The implementation of the E2E Library shall provide at least one of the E2E Profiles. */
/* AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies,
* does not show any requirement on E2E_SM.* files. But as the API
* is defined for E2E_P01, it is necessary to include E2E_SM.h here
*/
#include "E2E_SM.h"
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E_MemMap.h is included from all E2E files
*/
#include "E2E_MemMap.h"
#define E2E_P05_AR_RELEASE_MAJOR_VERSION 4u
#define E2E_P05_AR_RELEASE_MINOR_VERSION 3u
#define E2E_P05_AR_RELEASE_REVISION_VERSION 0u
#define E2E_P05_SW_MAJOR_VERSION 2
#define E2E_P05_SW_MINOR_VERSION 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_SM_AR_RELEASE_MAJOR_VERSION != E2E_P05_AR_RELEASE_MAJOR_VERSION) || (E2E_SM_AR_RELEASE_MINOR_VERSION != E2E_P05_AR_RELEASE_MINOR_VERSION)
#error "SW Version mismatch between E2E_SM.h and E1E_P05.h"
#endif
/* @req SWS_E2E_00440 */
/**
* Status of the reception on one single Data in one cycle, protected with E2E Profile 5.
*/
typedef enum {
/**
* OK: the checks of the Data in this cycle were successful
* (including counter check, which was incremented by 1).
*/
E2E_P05STATUS_OK = 0x00,
/**
* Error: the Check function has been invoked but no new Data is not available since the last call,
* according to communication medium (e.g. RTE, COM). As a result, no E2E checks of Data have been consequently executed.
* This may be considered similar to E2E_P05STATUS_REPEATED.
*/
E2E_P05STATUS_NONEWDATA = 0x01,
/**
* Error: error not related to counters occurred (e.g. wrong crc, wrong length, wrong options, wrong Data ID).
*/
E2E_P05STATUS_ERROR = 0x07,
/**
* Error: the checks of the Data in this cycle were successful, with the exception of the repetition.
*/
E2E_P05STATUS_REPEATED = 0x08,
/**
* OK: the checks of the Data in this cycle were successful (including counter check,
* which was incremented within the allowed configured delta).
*/
E2E_P05STATUS_OKSOMELOST = 0x20,
/**
* Error: the checks of the Data in this cycle were successful,
* with the exception of counter jump, which changed more than the allowed delta.
*/
E2E_P05STATUS_WRONGSEQUENCE = 0x40
} E2E_P05CheckStatusType;
/* @req SWS_E2E_00399
* In the E2E Profile 5, the Data ID shall be implicitly transmitted,
* by adding the Data ID after the user data in the CRC calculation.
*/
/* @req SWS_E2E_00394
* Profile 5 shall provide the following control fields,
* transmitted at runtime together with the protected data:
*/
/* @req SWS_E2E_00437 */
/**
* Configuration of transmitted Data (Data Element or I-PDU), for E2E Profile 5.
* For each transmitted Data, there is an instance of this typedef.
*/
typedef struct {
/**
* Bit offset of the first bit of the E2E header from the beginning of the Data (bit numbering: bit 0 is the least important).
* The offset shall be a multiple of 8 and 0 ≤ Offset ≤ DataLength-(3*8).
* Example: If Offset equals 8, then the low byte of the E2E Crc (16 bit) is written to Byte 1,
* the high Byte is written to Byte 2.
*/
uint16 Offset;
/**
* Length of Data, in bits. The value shall be = 4096*8 (4kB) and shall be ≥ 3*8
*/
uint16 DataLength;
/**
* A system-unique identifier of the Data.
*/
uint16 DataID;
/**
* Maximum allowed gap between two counter values of two consecutively received valid Data. For example,
* if the receiver gets Data with counter 1 and MaxDeltaCounter is 3,
* then at the next reception the receiver can accept Counters with values 2, 3 or 4.
*/
uint8 MaxDeltaCounter;
} E2E_P05ConfigType;
/* @req SWS_E2E_00438 */
/**
* State of the sender for a Data protected with E2E Profile 5.
*/
typedef struct {
/**
* Counter to be used for protecting the next Data. The initial value is 0,
* which means that in the first cycle, Counter is 0.
* Each time E2E_P05Protect() is called, it increments the counter up to 0xFF.
*/
uint8 Counter;
} E2E_P05ProtectStateType;
/* @req SWS_E2E_00439 */
/**
* State of the reception on one single Data protected with E2E Profile 5.
*/
typedef struct {
/**
* Result of the verification of the Data in this cycle, determined by the Check function.
*/
E2E_P05CheckStatusType Status;
/**
* Counter of the data in previous cycle.
*/
uint8 Counter;
} E2E_P05CheckStateType;
/** @brief Protects the array/buffer to be transmitted using the E2E profile 5.
* This includes checksum calculation, handling of counter.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to Data to be transmitted.
* @param Length Length of the data in bytes.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00446 API for E2E_P05Protect */
Std_ReturnType E2E_P05Protect(const E2E_P05ConfigType* ConfigPtr, E2E_P05ProtectStateType* StatePtr, uint8* DataPtr, uint16 Length);
/** @brief Checks the Data received using the E2E profile 5.
* This includes CRC calculation, handling of Counter.
* The function checks only one single data in one cycle,
* it does not determine/compute the accumulated state of the communication link.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to received data.
* @param Length Length of the data in bytes.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00449 API for E2E_P05Check */
Std_ReturnType E2E_P05Check(const E2E_P05ConfigType* ConfigPtr, E2E_P05CheckStateType* StatePtr, const uint8* DataPtr, uint16 Length);
/** @brief Initializes the protection state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00447 API for E2E_P05ProtectInit */
Std_ReturnType E2E_P05ProtectInit(E2E_P05ProtectStateType* StatePtr);
/** @brief Initializes the check state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00450 API for E2E_P05CheckInit */
Std_ReturnType E2E_P05CheckInit(E2E_P05CheckStateType* StatePtr);
/** @brief The function maps the check status of Profile 5 to a generic check status,
* which can be used by E2E state machine check function.
* The E2E Profile 5 delivers a more fine-granular status,
* but this is not relevant for the E2E state machine.
*
* @param CheckReturn Return value of the E2E_P05Check function.
* @param Status Status determined by E2E_P05Check function.
* @return Profile-independent status of the reception on one single Data in one cycle.
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00452 API for E2E_P05MapStatusToSM */
E2E_PCheckStatusType E2E_P05MapStatusToSM(Std_ReturnType CheckReturn, E2E_P05CheckStatusType Status);
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/inc/E2E_P05.h
|
C
|
unknown
| 9,295
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @file E2E_P06.h
*
* The E2E Profile 6 provides a consistent set of data protection mechanisms,
* designed to protecting against the faults considered in the fault model.
*/
#ifndef E2E_P06_H_
#define E2E_P06_H_
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00217 The implementation of the E2E Library shall provide at least one of the E2E Profiles. */
/* AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies,
* does not show any requirement on E2E_SM.* files. But as the API
* is defined for E2E_P01, it is necessary to include E2E_SM.h here
*/
#include "E2E_SM.h"
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E_MemMap.h is included from all E2E files
*/
#include "E2E_MemMap.h"
#define E2E_P06_AR_RELEASE_MAJOR_VERSION 4u
#define E2E_P06_AR_RELEASE_MINOR_VERSION 3u
#define E2E_P06_AR_RELEASE_REVISION_VERSION 0u
#define E2E_P06_SW_MAJOR_VERSION 2
#define E2E_P06_SW_MINOR_VERSION 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_SM_AR_RELEASE_MAJOR_VERSION != E2E_P06_AR_RELEASE_MAJOR_VERSION) || (E2E_SM_AR_RELEASE_MINOR_VERSION != E2E_P06_AR_RELEASE_MINOR_VERSION)
#error "SW Version mismatch between E2E_SM.h and E1E_P06.h"
#endif
/* @req SWS_E2E_00445 */
/**
* Status of the reception on one single Data in one cycle, protected with E2E Profile 6.
*/
typedef enum {
/**
* OK: the checks of the Data in this cycle were successful
* (including counter check, which was incremented by 1).
*/
E2E_P06STATUS_OK = 0x00,
/**
* Error: the Check function has been invoked but no new Data is not available since the last call,
* according to communication medium (e.g. RTE, COM). As a result, no E2E checks of Data have been consequently executed.
* This may be considered similar to E2E_P06STATUS_REPEATED.
*/
E2E_P06STATUS_NONEWDATA = 0x01,
/**
* Error: error not related to counters occurred (e.g. wrong crc, wrong length, wrong options, wrong Data ID).
*/
E2E_P06STATUS_ERROR = 0x07,
/**
* Error: the checks of the Data in this cycle were successful, with the exception of the repetition.
*/
E2E_P06STATUS_REPEATED = 0x08,
/**
* OK: the checks of the Data in this cycle were successful (including counter check,
* which was incremented within the allowed configured delta).
*/
E2E_P06STATUS_OKSOMELOST = 0x20,
/**
* Error: the checks of the Data in this cycle were successful,
* with the exception of counter jump, which changed more than the allowed delta.
*/
E2E_P06STATUS_WRONGSEQUENCE = 0x40
} E2E_P06CheckStatusType;
/* @req SWS_E2E_00419
* In the E2E Profile 6, the Data ID shall be implicitly transmitted,
* by adding the Data ID after the user data in the CRC calculation.
*/
/* @req SWS_E2E_00479
* Profile 6 shall provide the following control fields, transmitted at runtime together with the protected data:
*/
/* @req SWS_E2E_00441 */
/**
* Configuration of transmitted Data (Data Element or I-PDU), for E2E Profile 6.
* For each transmitted Data, there is an instance of this typedef.
*/
typedef struct {
/**
* Bit offset of the first bit of the E2E headerfrom the beginning of the Data (bit numbering: bit 0 is the least important).
* The offset shall be a multiple of 8 and 0 ≤ Offset ≤ MaxDataLength-(5*8).
* Example: If Offset equals 8, then the high byte of the E2E Crc (16 bit) is written to Byte 1, the low Byte is written to Byte 2.
*/
uint16 Offset;
/**
* Minimal length of Data, in bits (i.e. the length of the E2E-protected message, without counting the field Length itself).
* E2E checks that Length is ≥ MinDataLength. The value shall be = 4096*8 (4kB) and shall be ≥ 5*8
*/
uint16 MinDataLength;
/**
* Maximal length of Data, in bits. E2E checks that DataLength is ≤ MaxDataLength.
* The value shall be = 4096*8 (4kB). MaxDataLength shall be ≥ MinDataLength.
*/
uint16 MaxDataLength;
/**
* A system-unique identifier of the Data.
*/
uint16 DataID;
/**
* Maximum allowed gap between two counter values of two consecutively received valid Data. For example,
* if the receiver gets Data with counter 1 and MaxDeltaCounter is 3,
* then at the next reception the receiver can accept Counters with values 2, 3 or 4.
*/
uint8 MaxDeltaCounter;
} E2E_P06ConfigType;
/* @req SWS_E2E_00443 */
/**
* State of the sender for a Data protected with E2E Profile 6.
*/
typedef struct {
/**
* Counter to be used for protecting the next Data. The initial value is 0, which means that in the first cycle, Counter is 0.
* Each time E2E_P06Protect() is called, it increments the counter up to 0xFF. After the maximum value is reached,
* the next value is 0x0. The overflow is not reported to the caller.
*/
uint8 Counter;
} E2E_P06ProtectStateType;
/* @req SWS_E2E_00444 */
/**
* State of the reception on one single Data protected with E2E Profile 6.
*/
typedef struct {
/**
* Result of the verification of the Data in this cycle, determined by the Check function.
*/
E2E_P06CheckStatusType Status;
/**
* Counter of the data in previous cycle.
*/
uint8 Counter;
} E2E_P06CheckStateType;
/** @brief Protects the array/buffer to be transmitted using the E2E profile 6.
* This includes checksum calculation, handling of counter.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to Data to be transmitted.
* @param Length Length of the data in bytes.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00393 API for E2E_P06Protect */
Std_ReturnType E2E_P06Protect(const E2E_P06ConfigType* ConfigPtr, E2E_P06ProtectStateType* StatePtr, uint8* DataPtr, uint16 Length);
/** @brief Checks the Data received using the E2E profile 6.
* This includes CRC calculation, handling of Counter.
* The function checks only one single data in one cycle,
* it does not determine/compute the accumulated state of the communication link.
*
* @param ConfigPtr Pointer to static configuration.
* @param StatePtr Pointer to port/data communication state.
* @param DataPtr Pointer to received data.
* @param Length Length of the data in bytes.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00457 API for E2E_P06Check */
Std_ReturnType E2E_P06Check(const E2E_P06ConfigType* ConfigPtr, E2E_P06CheckStateType* StatePtr, const uint8* DataPtr, uint16 Length);
/** @brief Initializes the protection state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00455 API for E2E_P06ProtectInit */
Std_ReturnType E2E_P06ProtectInit(E2E_P06ProtectStateType* StatePtr);
/** @brief Initializes the check state.
*
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00458 API for E2E_P06CheckInit */
Std_ReturnType E2E_P06CheckInit(E2E_P06CheckStateType* StatePtr);
/** @brief The function maps the check status of Profile 6 to a generic check status,
* which can be used by E2E state machine check function.
* The E2E Profile 6 delivers a more fine-granular status,
* but this is not relevant for the E2E state machine.
*
* @param CheckReturn Return value of the E2E_P06Check function.
* @param Status Status determined by E2E_P06Check function.
* @return Profile-independent status of the reception on one single Data in one cycle.
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00460 API for E2E_P06MapStatusToSM */
E2E_PCheckStatusType E2E_P06MapStatusToSM(Std_ReturnType CheckReturn, E2E_P06CheckStatusType Status);
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/inc/E2E_P06.h
|
C
|
unknown
| 9,761
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @file E2E_SM.h
*
* A state machine describing the logical algorithm of E2E monitoring independent of the used profile.
*/
#ifndef E2E_SM_H_
#define E2E_SM_H_
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E.h is included from E2E_P01.h files
*/
#include "E2E.h"
/* According to AUTOSAR_SWS_E2ELibrary.pdf, Figure5-1: File dependencies:
* E2E_MemMap.h is included from all E2E files
*/
#include "E2E_MemMap.h"
#define E2E_SM_AR_RELEASE_MAJOR_VERSION 4u
#define E2E_SM_AR_RELEASE_MINOR_VERSION 3u
#define E2E_SM_AR_RELEASE_REVISION_VERSION 0u
#define E2E_SM_SW_MAJOR_VERSION 2
#define E2E_SM_SW_MINOR_VERSION 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_AR_RELEASE_MAJOR_VERSION != E2E_SM_AR_RELEASE_MAJOR_VERSION) || (E2E_AR_RELEASE_MINOR_VERSION != E2E_SM_AR_RELEASE_MINOR_VERSION)
#error "SW Version mismatch between E2E.h and E1E_SM.h"
#endif
/* @req SWS_E2E_00347 */
/**
* Profile-independent status of the reception on one single Data in one cycle.
*/
typedef enum {
/**
* OK: the checks of the Data in this cycle were successful (including counter check).
*/
E2E_P_OK = 0x00,
/**
* Data has a repeated counter.
*/
E2E_P_REPEATED = 0x01,
/**
* The checks of the Data in this cycle were successful,
* with the exception of counter jump, which changed more than the allowed delta.
*/
E2E_P_WRONGSEQUENCE = 0x02,
/**
* Error not related to counters occurred (e.g. wrong crc, wrong length, wrong Data ID)
* or the return of the check function was not OK.
*/
E2E_P_ERROR = 0x03,
/**
* No value has been received yet (e.g. during initialization).
* This is used as the initialization value for the buffer, it is not returned by any E2E profile.
*/
E2E_P_NOTAVAILABLE = 0x04,
/**
* No new data is available.
*/
E2E_P_NONEWDATA = 0x05
} E2E_PCheckStatusType;
/* @req SWS_E2E_00344 */
/**
* Status of the communication channel exchanging the data. If the status is OK, then the data may be used.
*/
typedef enum {
/**
* Communication functioning properly according to E2E, data can be used.
*/
E2E_SM_VALID = 0x00,
/**
* State before E2E_SMCheckInit() is invoked, data cannot be used.
*/
E2E_SM_DEINIT = 0x01,
/**
* No data from the sender is available since the initialization, data cannot be used.
*/
E2E_SM_NODATA = 0x02,
/**
* There has been some data received since startup, but it is not yet possible use it, data cannot be used.
*/
E2E_SM_INIT = 0x03,
/**
* Communication not functioning properly, data cannot be used.
*/
E2E_SM_INVALID = 0x04
} E2E_SMStateType;
/* @req SWS_E2E_00342 */
/**
* Configuration of a communication channel for exchanging Data.
*/
typedef struct {
/**
* Size of the monitoring window for the state machine.
*/
uint8 WindowSize;
/**
* Minimal number of checks in which ProfileStatus equal to E2E_P_OK was determined within the last WindowSize checks
* (for the state E2E_SM_INIT) required to change to state E2E_SM_VALID.
*/
uint8 MinOkStateInit;
/**
* Maximal number of checks in which ProfileStatus equal to E2E_P_ERROR was determined,
* within the last WindowSize checks (for the state E2E_SM_INIT).
*/
uint8 MaxErrorStateInit;
/**
* Minimal number of checks in which ProfileStatus equal to E2E_P_OK was determined
* within the lastWindowSize checks (for the state E2E_SM_VALID) required to keep in state E2E_SM_VALID.
*/
uint8 MinOkStateValid;
/**
* Maximal number of checks in which ProfileStatus equal to E2E_P_ERROR was determined,
* within the last WindowSize checks (for the state E2E_SM_VALID).
*/
uint8 MaxErrorStateValid;
/**
* Minimum number of checks in which ProfileStatus equal to E2E_P_OK was determined
* within the last WindowSize checks (for the state E2E_SM_INVALID) required to change to state E2E_SM_VALID.
*/
uint8 MinOkStateInvalid;
/**
* Maximal number of checks in which ProfileStatus equal to E2E_P_ERROR was determined,
* within the last WindowSize checks (for the state E2E_SM_INVALID).
*/
uint8 MaxErrorStateInvalid;
} E2E_SMConfigType;
/* @req SWS_E2E_00343 */
/**
* State of the protection of a communication channel.
*/
typedef struct {
/**
* Pointer to an array, in which the ProfileStatus-es of the last E2E-checks are stored. The array size shall be WindowSize.
*/
uint8* ProfileStatusWindow;
/**
* Index in the array, at which the next ProfileStatus is to be written.
*/
uint8 WindowTopIndex;
/**
* Count of checks in which ProfileStatus equal to E2E_P_OK was determined, within the last WindowSize checks.
*/
uint8 OkCount;
/**
* Count of checks in which ProfileStatus equal to E2E_P_ERROR was determined, within the last WindowSize checks.
*/
uint8 ErrorCount;
/**
* The current state in the state machine.
* The value is not explicitly used in the pseudocode of the state machine,
* because it is expressed in UML as UML states.
*/
E2E_SMStateType SMState;
} E2E_SMCheckStateType;
/** @brief Checks the communication channel.
* It determines if the data can be used for safety-related application,
* based on history of checks performed by a corresponding E2E_P0XCheck() function.
*
* @param ProfileStatus Profile-independent status of the reception on one single Data in one cycle.
* @param ConfigPtr Pointer to configuration of the state machine.
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL || E2E_E_INPUTERR_WRONG || E2E_E_INTERR || E2E_E_OK || E2E_E_WRONGSTATE).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00340 API for E2E_SMCheck */
Std_ReturnType E2E_SMCheck(E2E_PCheckStatusType ProfileStatus, const E2E_SMConfigType* ConfigPtr, E2E_SMCheckStateType* StatePtr);
/** @brief Initializes the state machine.
*
* @param ConfigPtr Pointer to configuration of the state machine.
* @param StatePtr Pointer to port/data communication state.
*
* @return Error code (E2E_E_INPUTERR_NULL - null pointer passed E2E_E_OK).
*/
/* @req SWS_E2E_00047 error flags for errors shall be used by all E2E Library functions */
/* @req SWS_E2E_00353 API for E2E_SMCheckInit */
/* Initializes the state machine. */
Std_ReturnType E2E_SMCheckInit(E2E_SMCheckStateType* StatePtr, const E2E_SMConfigType* ConfigPtr);
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/inc/E2E_SM.h
|
C
|
unknown
| 7,967
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00216
* The E2E Library shall not call BSW modules for error reporting (in particular DEM and DET), nor for any other purpose.
* The E2E Library shall not call RTE. */
#define E2E_AR_RELEASE_MAJOR_VERSION_INT 4u
#define E2E_AR_RELEASE_MINOR_VERSION_INT 3u
#define E2E_AR_RELEASE_REVISION_VERSION_INT 0u
#define E2E_SW_MAJOR_VERSION_INT 2
#define E2E_SW_MINOR_VERSION_INT 0
#include "E2E.h"
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_AR_RELEASE_MAJOR_VERSION != E2E_AR_RELEASE_MAJOR_VERSION_INT) || (E2E_AR_RELEASE_MINOR_VERSION != E2E_AR_RELEASE_MINOR_VERSION_INT)
#error "SW Version mismatch between E2E.c and E2E.h"
#endif
#if (E2E_AR_RELEASE_MAJOR_VERSION != E2E_AR_RELEASE_MAJOR_VERSION_INT) || (E2E_AR_RELEASE_MINOR_VERSION != E2E_AR_RELEASE_MINOR_VERSION_INT) || \
(E2E_AR_RELEASE_REVISION_VERSION != E2E_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between E2E.c and E2E.h"
#endif
/* @req SWS_E2E_00032 API: E2E_GetVersionInfo */
/* @req SWS_E2E_00033 The function E2E_GetVersionInfo shall return the version information of the E2E module */
/* @req SWS_BSW_00051*/
/** @brief Return the version information of E2E module.
*
* The function E2E_GetVersionInfo shall return the version
* information of the E2E module.
* The version information includes:
* - Module Id
* - Vendor Id
* - sw_major_version
* - sw_minor_version
* - sw_patch_version
*
* @param Std_VersionInfoType The type including Module and Vendor ID for the E2E Module.
* @return void.
*/
#if (SAFELIB_VERSIONINFO_API == STD_ON)
void E2E_GetVersionInfo(Std_VersionInfoType* versioninfo) {
if (versioninfo != NULL_PTR) {
versioninfo->vendorID = E2E_VENDOR_ID;
versioninfo->moduleID = E2E_MODULE_ID;
versioninfo->sw_major_version = E2E_SW_MAJOR_VERSION;
versioninfo->sw_minor_version = E2E_SW_MINOR_VERSION;
versioninfo->sw_patch_version = E2E_SW_PATCH_VERSION;
}
}
#endif
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/src/E2E.c
|
C
|
unknown
| 3,105
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
#ifndef E2E_MEMMAP_H_
#define E2E_MEMMAP_H_
#include "MemMap.h"
#endif /* E2E_MEMMAP_H_ */
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/src/E2E_MemMap.h
|
C
|
unknown
| 916
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00216
* The E2E Library shall not call BSW modules for error reporting (in particular DEM and DET), nor for any other purpose.
* The E2E Library shall not call RTE. */
/* @req SWS_E2E_00215 Files E2E_P01.c and E2E_P01.h shall contain implementation parts specific of each profile. */
/* @req SWS_E2E_00049 The E2E library shall not contain library-internal mechanisms for error detection to be traced as development errors. */
/* @req SWS_E2E_00221 Each E2E Profile shall use a subset of the data protection mechanisms defined in AUTOSAR_SWS_E2ELibrary.pdf, 7.2. */
/* @req SWS_E2E_00011 The E2E Library shall report errors detected by library-internal mechanisms
* to callers of E2E functions through return value.
*/
/* @req SWS_E2E_00012 The internal library mechanisms shall detect and report errors
* shall be implemented according to the pre-defined E2E Profiles specified in sections 7.3 and 7.4.
*/
#include "E2E_P01.h"
//#define USE_LDEBUG_PRINTF // Uncomment this to turn debug statements on.
//#include "debug.h"
/* @req SWS_E2E_00018 Length of data, in bits. The value shall be a multiple of 8 and shall be ≤ 240. */
#define MAX_P01_DATA_LENGTH_IN_BITS (240)
/* @req SWS_E2E_00020 Counter to be used for protecting the next Data.
* The value 0xF is skipped (after 0xE the next is 0x0), as 0xF value represents the error value.
*/
#define MAX_P01_COUNTER_VALUE (14)
/* For CRC 8*/
#define Crc_8_Xor 0xFFU
#define E2E_P01_AR_RELEASE_MAJOR_VERSION_INT 4u
#define E2E_P01_AR_RELEASE_MINOR_VERSION_INT 3u
#define E2E_P01_AR_RELEASE_REVISION_VERSION_INT 0u
#define E2E_P01_SW_MAJOR_VERSION_INT 2
#define E2E_P01_SW_MINOR_VERSION_INT 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_P01_SW_MAJOR_VERSION != E2E_P01_SW_MAJOR_VERSION_INT) || (E2E_P01_SW_MINOR_VERSION != E2E_P01_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between E2E_P01.c and E2E_P01.h"
#endif
#if (E2E_P01_AR_RELEASE_MAJOR_VERSION != E2E_P01_AR_RELEASE_MAJOR_VERSION_INT) || (E2E_P01_AR_RELEASE_MINOR_VERSION != E2E_P01_AR_RELEASE_MINOR_VERSION_INT) || \
(E2E_P01_AR_RELEASE_REVISION_VERSION != E2E_P01_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between E2E_P01.c and E2E_P01.h"
#endif
/* Calculation of the delta counter value taken into account the overflow.
*/
static INLINE uint8 calculateDeltaCounterP01(uint8 receivedCounter, uint8 lastValidCounter) {
uint8 res;
res = 0;
if (receivedCounter >= lastValidCounter) {
res = receivedCounter - lastValidCounter;
}
else {
res = MAX_P01_COUNTER_VALUE + 1 + receivedCounter - lastValidCounter;
}
return res;
}
/* @req SWS_E2E_00018 Configuration constraints defined for E2E_P01ConfigType */
/* @req SWS_E2E_00047 Definition of error flags for all E2E units */
/* @req SWS_E2E_00169 In E2E Profile 1, with E2E_P01DataIDMode equal to E2E_P01_DATAID_LOW, the high byte of Data ID shall be set to 0x00. */
/* @req SWS_E2E_00227 Profile variant 1A, No explicit support for variants but the config allows such a configuration */
/* @req SWS_E2E_00228 Profile variant 1B, No explicit support for variants but the config allows such a configuration */
/* @req SWS_E2E_00306 In E2E Profile 1, with E2E_P01DataIDMode equal to E2E_P01_DATAID_NIBBLE, the high nibble of the high byte shall be 0x0. */
/* @req SWS_E2E_00307 Profile variant 1C, No explicit support for variants but the config allows such a configuration */
/* UC_E2E_00053 Any user of E2E Profile 1 shall use whenever possible the defined E2E variants. */
/* Checks the correctness of the configuration parameter.
*/
static INLINE Std_ReturnType checkConfigP01(const E2E_P01ConfigType* Config) {
Std_ReturnType status;
status = E2E_E_OK;
/* Check for NULL pointers */
if (Config == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
}
/* Check input parameters values */
else if ((Config->DataLength > MAX_P01_DATA_LENGTH_IN_BITS) || ((Config->DataLength % 8) != 0) ||
((Config->CounterOffset % 4) != 0) || ((Config->CRCOffset % 8) != 0)) {
status = E2E_E_INPUTERR_WRONG;
}
/* Check that input parameters do not overlap and fits into the data array. It is enough to
* check if the CRC and Counter are in the same byte since the CRC is one byte long */
else if (((Config->CRCOffset + 8) > Config->DataLength) || ((Config->CounterOffset + 4) > Config->DataLength) ||
((Config->CRCOffset/8) == (Config->CounterOffset/8))) {
status = E2E_E_INPUTERR_WRONG;
}
/* For DataIDMode different than E2E_P01_DATAID_NIBBLE, DataIDNibbleOffset shall be initialized to 0 (even if it is ignored by E2E Library). */
else if ((Config->DataIDMode != E2E_P01_DATAID_NIBBLE) && (Config->DataIDNibbleOffset != 0)) {
status = E2E_E_INPUTERR_WRONG;
}
/* In E2E Profile 1, with E2E_P01DataIDMode equal to E2E_P01_DATAID_LOW, the high byte of Data ID shall be set to 0x00. */
else if ((Config->DataIDMode == E2E_P01_DATAID_LOW) && ((Config->DataID>>8) != 0)) {
status = E2E_E_INPUTERR_WRONG;
}
/* In E2E Profile 1, with E2E_P01DataIDMode equal to E2E_P01_DATAID_NIBBLE, the high nibble of the high byte shall be 0x0. */
else if ((Config->DataIDMode == E2E_P01_DATAID_NIBBLE) && ((Config->DataID>>12) != 0)) {
status = E2E_E_INPUTERR_WRONG;
}
else {
/* return E2E_E_OK*/
status = E2E_E_OK;
}
return status;
}
/* @req SWS_E2E_00070 E2E Profile 1 shall use the polynomial of CRC-8-SAE J1850 */
/* @req SWS_E2E_00082 In E2E Profile 1, the CRC is calculated over:
* 1. First over the one or two bytes of the Data ID (depending on Data ID configuration) and then
* 2. over all transmitted bytes of a safety-related complex data element/signal group (except the CRC byte). */
/* @req SWS_E2E_00083 E2E Profile 1 shall use CRC-8-SAE J1850 for CRC calculation.
* It shall use 0x00 as the start value and XOR value.*/
/* @req SWS_E2E_00163 Defines inclusion modes for the two-byte Data ID into the calculation of the one-byte CRC. */
/* @req SWS_E2E_00190 E2E Profile 1 shall use the Crc_CalculateCRC8 () function of the SWS CRC Library for calculating CRC checksums. */
/* @req SWS_E2E_00218 Specification of E2E Profile 1 */
/* Calculate CRC over Data ID and Data
*/
static uint8 calculateCrcP01(const E2E_P01ConfigType* Config, uint8 Counter, const uint8* Data)
{
/* The start value is 0x00 for E2E (0xFF is standard in the CRC lib). The final
* XOR is 0x00 (0xFF is standard) so we must XOR the crc with 0xFF
*/
uint8 crc = 0x00u ^ Crc_8_Xor; /* Need to cancel first XOR in CRC */
uint8 lowerByteId = (uint8)Config->DataID;
uint8 upperByteId = (uint8)(Config->DataID>>8);
/* Calculate CRC on the Data ID */
if (Config->DataIDMode == E2E_P01_DATAID_BOTH)
{
crc = Crc_CalculateCRC8(&lowerByteId, 1, crc, FALSE);
crc = Crc_CalculateCRC8(&upperByteId, 1, crc, FALSE);
}
else if (Config->DataIDMode == E2E_P01_DATAID_LOW)
{
crc = Crc_CalculateCRC8(&lowerByteId, 1, crc, FALSE);
}
else if (Config->DataIDMode == E2E_P01_DATAID_NIBBLE)
{
crc = Crc_CalculateCRC8(&lowerByteId, 1, crc, FALSE);
upperByteId = 0;
crc = Crc_CalculateCRC8(&upperByteId, 1, crc, FALSE);
}
else if ((Counter % 2) == 0) //E2E_P01_DATAID_ALT: even counter
{
crc = Crc_CalculateCRC8(&lowerByteId, 1, crc, FALSE);
}
else //E2E_P01_DATAID_ALT: odd counter
{
crc = Crc_CalculateCRC8(&upperByteId, 1, crc, FALSE);
}
/* Calculate CRC on the data */
if (Config->CRCOffset >= 8) {
crc = Crc_CalculateCRC8 (Data, (Config->CRCOffset / 8), crc, FALSE);
}
if ((Config->CRCOffset / 8) < ((Config->DataLength / 8) - 1)) {
crc = Crc_CalculateCRC8 (&Data[(Config->CRCOffset/8) + 1],
(((Config->DataLength / 8) - (Config->CRCOffset / 8)) - 1),
crc, FALSE);
}
return crc ^ Crc_8_Xor; /* Need to cancel last XOR in CRC */
}
/* @req SWS_E2E_00070 E2E Profile 1 shall use the polynomial of CRC-8-SAE J1850 */
/* @req SWS_E2E_00075 In E2E Profile 1, on the sender side,
* for the first transmission request of a data element the counter shall be initialized with 0 and
* shall be incremented by 1 for every subsequent send request.
* When the counter reaches the value 14 (0xE),
* then it shall restart with 0 for the next send request (i.e. value 0xF shall be skipped).
*/
/* @req SWS_E2E_00169 In E2E Profile 1, with E2E_P01DataIDMode equal to E2E_P01_DATAID_LOW,
* the high byte of Data ID shall be set to 0x00.
*/
/* @req SWS_E2E_00195 The function E2E_P01Protect() shall write data as specified
* by Figure 7-5 and Figure 7-6 in AUTOSAR_SWS_E2ELibrary.pdf
*/
/* @req SWS_E2E_00218 Profile 1 shall provide the following mechanisms as specified in 7.3 */
/* @req SWS_E2E_00306 In E2E Profile 1, with E2E_P01DataIDMode equal to E2E_P01_DATAID_NIBBLE,
* the high nibble of the high byte shall be 0x0.
*/
/* @req SWS_E2E_00166 API for E2E_P01Protect */
/* Protects the array/buffer to be transmitted using the E2E profile 1.
*/
Std_ReturnType E2E_P01Protect(const E2E_P01ConfigType* ConfigPtr, E2E_P01ProtectStateType* StatePtr, uint8* DataPtr) {
Std_ReturnType status;
status = E2E_E_OK;
Std_ReturnType returnValue = checkConfigP01(ConfigPtr);
if (E2E_E_OK != returnValue) {
status = returnValue;
}
else if ((StatePtr == NULL_PTR) || (DataPtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
else {
/* Put counter in data*/
if ((ConfigPtr->CounterOffset % 8) == 0) {
DataPtr[ConfigPtr->CounterOffset/8] = (DataPtr[(ConfigPtr->CounterOffset/8)] & 0xF0u) | (StatePtr->Counter & 0x0Fu);
}
else {
DataPtr[ConfigPtr->CounterOffset/8] = (DataPtr[ConfigPtr->CounterOffset/8] & 0x0Fu) | ((StatePtr->Counter<<4) & 0xF0u);
}
/* Put counter in data for E2E_P01_DATAID_NIBBLE */ // ASR4.2.2
if (ConfigPtr->DataIDMode == E2E_P01_DATAID_NIBBLE) {
if ((ConfigPtr->DataIDNibbleOffset % 8) == 0) {
DataPtr[ConfigPtr->DataIDNibbleOffset/8] = (DataPtr[(ConfigPtr->DataIDNibbleOffset/8)] & 0xF0u) | ((uint8)((ConfigPtr->DataID>>8) & 0x0Fu));
}
else {
DataPtr[ConfigPtr->DataIDNibbleOffset/8] = (DataPtr[ConfigPtr->DataIDNibbleOffset/8] & 0x0Fu) | ((uint8)((ConfigPtr->DataID>>4) & 0xF0u));
}
}
/* Calculate CRC */
DataPtr[(ConfigPtr->CRCOffset/8)] = calculateCrcP01(ConfigPtr, StatePtr->Counter, DataPtr);
/* Update counter */
StatePtr->Counter = (StatePtr->Counter+1) % 15;
}
return status;
}
/* Reads the counter value
*/
static INLINE uint8 readCounterP01(const E2E_P01ConfigType* ConfigPtr, const uint8* DataPtr) {
uint8 receivedCounter = 0;
/* Counter offset is 4-bit aligned, this check is used to find out if high or low nibble */
if ((ConfigPtr->CounterOffset % 8) == 0) {
receivedCounter = DataPtr[ConfigPtr->CounterOffset/8] & 0x0Fu;
}
else {
receivedCounter = (DataPtr[ConfigPtr->CounterOffset/8] >> 4) & 0x0Fu;
}
return receivedCounter;
}
/* Reads the data id nibble offset
*/
static INLINE uint8 readDataIDNibbleOffsetP01(const E2E_P01ConfigType* ConfigPtr, const uint8* DataPtr) {
uint8 receivedDataIDNibble = 0;
if (ConfigPtr->DataIDMode == E2E_P01_DATAID_NIBBLE) {
if ((ConfigPtr->DataIDNibbleOffset % 8) == 0) {
receivedDataIDNibble = DataPtr[(ConfigPtr->DataIDNibbleOffset)/8] & 0x0Fu;
}
else {
receivedDataIDNibble = (DataPtr[(ConfigPtr->DataIDNibbleOffset)/8] >> 4) & 0x0Fu;
}
}
return receivedDataIDNibble;
}
/* Check if that is the first data since initialisation
*/
static INLINE boolean isFirstDataSinceInitialisationP01(const E2E_P01ConfigType* ConfigPtr, E2E_P01CheckStateType* StatePtr, uint8 receivedCounter) {
boolean status;
status = FALSE;
if (StatePtr->WaitForFirstData == TRUE) {
StatePtr->WaitForFirstData = FALSE;
StatePtr->MaxDeltaCounter = ConfigPtr->MaxDeltaCounterInit;
StatePtr->LastValidCounter = receivedCounter;
StatePtr->Status = E2E_P01STATUS_INITIAL;
status = TRUE;
}
return status;
}
/* Check first if the received CRC and calculated CRC is identical or not
*/
static INLINE boolean isCheckOfReceivedDataNotOkP01(const E2E_P01ConfigType* ConfigPtr, E2E_P01CheckStateType* StatePtr, uint8 receivedCounter, uint8 receivedCrc, uint8 calculatedCrc, uint8 receivedDataIDNibble) {
boolean status = FALSE;
if ( (receivedCrc != calculatedCrc) ||
( (ConfigPtr->DataIDMode == E2E_P01_DATAID_NIBBLE) && (receivedDataIDNibble != ((ConfigPtr->DataID)>>8)) )
) {
// LDEBUG_PRINTF("receivedCrcreceivedDataIDNibble check");
// LDEBUG_PRINTF("\n");
StatePtr->Status = E2E_P01STATUS_WRONGCRC;
status = TRUE;
}
/* Check if this is the first data since initialization, this should only be done if the CRC check above
* has been done without errors
*/
else if (isFirstDataSinceInitialisationP01(ConfigPtr, StatePtr, receivedCounter) == TRUE) {
// LDEBUG_PRINTF("first data check");
// LDEBUG_PRINTF("\n");
status = TRUE;
}
/* @CODECOV:DEFAULT_CASE:Else statement is required for defensive programming. */
__CODE_COVERAGE_IGNORE__
else {
/* Do nnothing but needed for MISRA */
}
return status;
}
/* Checks the Data received using the E2E profile 1.
* This is the normal case. Calculate delta counter, Check the counter delta.
*/
static INLINE void doChecksP01(const E2E_P01ConfigType* ConfigPtr, E2E_P01CheckStateType* StatePtr, uint8 receivedCounter) {
uint8 delta;
delta = calculateDeltaCounterP01(receivedCounter, StatePtr->LastValidCounter);
if (delta == 0) {
// LDEBUG_PRINTF("deltaCounter=0");
// LDEBUG_PRINTF("\n");
if (StatePtr->NoNewOrRepeatedDataCounter < MAX_P01_COUNTER_VALUE) {
StatePtr->NoNewOrRepeatedDataCounter++;
}
StatePtr->Status = E2E_P01STATUS_REPEATED;
}
else if (delta == 1) {
// LDEBUG_PRINTF("deltaCounter=1");
// LDEBUG_PRINTF("\n");
StatePtr->MaxDeltaCounter = ConfigPtr->MaxDeltaCounterInit;
StatePtr->LastValidCounter = receivedCounter;
StatePtr->LostData = 0;
if (StatePtr->NoNewOrRepeatedDataCounter <= ConfigPtr->MaxNoNewOrRepeatedData) {
StatePtr->NoNewOrRepeatedDataCounter = 0;
if (StatePtr->SyncCounter > 0) {
StatePtr->SyncCounter--;
StatePtr->Status = E2E_P01STATUS_SYNC;
}
else {
StatePtr->Status = E2E_P01STATUS_OK;
}
}
else {
StatePtr->NoNewOrRepeatedDataCounter = 0;
StatePtr->SyncCounter = ConfigPtr->SyncCounterInit;
StatePtr->Status = E2E_P01STATUS_SYNC;
}
}
else if (delta <= StatePtr->MaxDeltaCounter) { // 1 < delta <= MaxDeltaCounter
// LDEBUG_PRINTF("1<deltaCounter<=Max");
// LDEBUG_PRINTF("\n");
StatePtr->MaxDeltaCounter = ConfigPtr->MaxDeltaCounterInit;
StatePtr->LastValidCounter = receivedCounter;
StatePtr->LostData = delta - 1;
if (StatePtr->NoNewOrRepeatedDataCounter <= ConfigPtr->MaxNoNewOrRepeatedData) {
StatePtr->NoNewOrRepeatedDataCounter= 0;
if (StatePtr->SyncCounter > 0) {
StatePtr->SyncCounter--;
StatePtr->Status = E2E_P01STATUS_SYNC;
}
else {
StatePtr->Status = E2E_P01STATUS_OKSOMELOST;
}
}
else {
StatePtr->NoNewOrRepeatedDataCounter= 0;
StatePtr->SyncCounter = ConfigPtr->SyncCounterInit;
StatePtr->Status = E2E_P01STATUS_SYNC;
}
}
else { // delta > MaxDeltaCounter
// LDEBUG_PRINTF("deltaCounter>Max");
// LDEBUG_PRINTF("\n");
StatePtr->NoNewOrRepeatedDataCounter= 0;
StatePtr->SyncCounter = ConfigPtr->SyncCounterInit;
if (StatePtr->SyncCounter > 0) {
StatePtr->MaxDeltaCounter = ConfigPtr->MaxDeltaCounterInit;
StatePtr->LastValidCounter = receivedCounter;
}
StatePtr->Status = E2E_P01STATUS_WRONGSEQUENCE;
}
}
/* @req SWS_E2E_00076 In E2E Profile 1, on the receiver side,
* by evaluating the counter of received data against the counter of previously received data,
* the following shall be detected: */
/* @req SWS_E2E_00196 The function E2E_P01Check shall check as specified
* by Figure 7-7 and Figure 7-6 in AUTOSAR_SWS_E2ELibrary.
*/
/* @req SWS_E2E_00218 Profile 1 shall provide the following mechanisms as specified in 7.3. */
/* @req SWS_E2E_00306 In E2E Profile 1, with E2E_P01DataIDMode equal to E2E_P01_DATAID_NIBBLE,
* the high nibble of the high byte shall be 0x0. */
/* @req SWS_E2E_00158 API for E2E_P01Check */
/* Checks the Data received using the E2E profile 1.
*/
Std_ReturnType E2E_P01Check(const E2E_P01ConfigType* ConfigPtr, E2E_P01CheckStateType* StatePtr, const uint8* DataPtr) {
Std_ReturnType status;
status = E2E_E_OK;
boolean ret;
ret = TRUE;
uint8 receivedCounter;
uint8 receivedCrc;
uint8 calculatedCrc;
uint8 receivedDataIDNibble;
Std_ReturnType returnValue = checkConfigP01(ConfigPtr);
if (E2E_E_OK != returnValue) {
status = returnValue;
}
else if ((StatePtr == NULL_PTR) || (DataPtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
else {
/* This is the stated behavior in figure 7-6 but it seems wrong. This means that if more than 15
* messages are received with wrong CRC, the first message with correct CRC will be have state
* OKSOMELOST even though it should be WRONGSEQUENCE.
*/
// changed in ASR 4.2.2, figure is now 7-7
if (StatePtr->MaxDeltaCounter < MAX_P01_COUNTER_VALUE) {
StatePtr->MaxDeltaCounter++;
}
if (StatePtr->NewDataAvailable == FALSE) {
if (StatePtr->NoNewOrRepeatedDataCounter < MAX_P01_COUNTER_VALUE) {
StatePtr->NoNewOrRepeatedDataCounter++;
}
StatePtr->Status = E2E_P01STATUS_NONEWDATA;
status = E2E_E_OK;
ret = FALSE;
}
if (ret == TRUE){
receivedCounter = readCounterP01(ConfigPtr, DataPtr);
if (receivedCounter > MAX_P01_COUNTER_VALUE) {
status = E2E_E_INPUTERR_WRONG;
} else {
receivedCrc = DataPtr[(ConfigPtr->CRCOffset/8)];
receivedDataIDNibble = readDataIDNibbleOffsetP01(ConfigPtr, DataPtr);
calculatedCrc = calculateCrcP01(ConfigPtr, receivedCounter, DataPtr);
if (isCheckOfReceivedDataNotOkP01(ConfigPtr, StatePtr, receivedCounter, receivedCrc, calculatedCrc, receivedDataIDNibble) == TRUE) {
status = E2E_E_OK;
} else {
doChecksP01(ConfigPtr, StatePtr, receivedCounter);
}
}
}
}
return status;
}
/* @req SWS_E2E_00075 In E2E Profile 1, on the sender side,
* for the first transmission request of a data element the counter shall be initialized with 0
*/
/* @req SWS_E2E_00386 In case State is NULL, E2E_P01ProtectInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall intialize the state structure, setting Counter to 0.
*/
/* @req SWS_E2E_00385 API for E2E_P01ProtectInit */
/* Initializes the protection state.
*/
Std_ReturnType E2E_P01ProtectInit(E2E_P01ProtectStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
} else {
StatePtr->Counter = 0;
}
return status;
}
/* @req SWS_E2E_00389 In case State is NULL, E2E_P01CheckInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall initialize the state structure */
/* UC_E2E_00208, UC_E2E_00297, SWS_E2E_00324SWS_E2E_00325 overwrites init values NewDataAvailable */
/* @req SWS_E2E_00390 API for E2E_P01CheckInit */
/* @req ARC_SWS_E2E_00001 */
/* Initializes the check state.
*/
Std_ReturnType E2E_P01CheckInit(E2E_P01CheckStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
} else {
StatePtr->LastValidCounter = 0;
StatePtr->MaxDeltaCounter = 0;
StatePtr->WaitForFirstData = TRUE;
StatePtr->NewDataAvailable = FALSE;
StatePtr->LostData = 0;
StatePtr->Status = E2E_P01STATUS_NONEWDATA;
StatePtr->SyncCounter = 0;
StatePtr->NoNewOrRepeatedDataCounter = 0;
}
return status;
}
/* @req SWS_E2E_00383 If CheckReturn == E2E_E_OK and ProfileBehavior == TRUE,
* then the function E2E_P01MapStatusToSM shall return the values depending on the value of Status.
*/
/* The function maps the check status of Profile 1 to a generic check status in case ProfileBehavior == True
*/
static INLINE E2E_PCheckStatusType doE2E_P01MapStatusToSM_TRUE(E2E_P01CheckStatusType Status) {
E2E_PCheckStatusType retValue = E2E_P_ERROR;
switch(Status) {
case E2E_P01STATUS_OK:
case E2E_P01STATUS_OKSOMELOST:
case E2E_P01STATUS_SYNC:
retValue = E2E_P_OK;
break;
case E2E_P01STATUS_REPEATED:
retValue = E2E_P_REPEATED;
break;
case E2E_P01STATUS_NONEWDATA:
retValue = E2E_P_NONEWDATA;
break;
case E2E_P01STATUS_WRONGSEQUENCE:
case E2E_P01STATUS_INITIAL:
retValue = E2E_P_WRONGSEQUENCE;
break;
/* @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming. If this happens the state will be restored to E2E_P_ERROR */
__CODE_COVERAGE_IGNORE__
default:
retValue = E2E_P_ERROR;
break;
}
return retValue;
}
/* @req SWS_E2E_00476 If CheckReturn == E2E_E_OK and ProfileBehavior == FALSE,
* then the function E2E_P01MapStatusToSM shall return the values depending on the value of Status.
*/
/* The function maps the check status of Profile 1 to a generic check status in case ProfileBehavior == False
*/
static INLINE E2E_PCheckStatusType doE2E_P01MapStatusToSM_FALSE(E2E_P01CheckStatusType Status) {
E2E_PCheckStatusType retValue = E2E_P_ERROR;
switch(Status) {
case E2E_P01STATUS_OK:
case E2E_P01STATUS_OKSOMELOST:
case E2E_P01STATUS_INITIAL:
retValue = E2E_P_OK;
break;
case E2E_P01STATUS_REPEATED:
retValue = E2E_P_REPEATED;
break;
case E2E_P01STATUS_NONEWDATA:
retValue = E2E_P_NONEWDATA;
break;
case E2E_P01STATUS_WRONGSEQUENCE:
case E2E_P01STATUS_SYNC:
retValue = E2E_P_WRONGSEQUENCE;
break;
/* @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming. If this happens the state will be restored to E2E_P_ERROR */
__CODE_COVERAGE_IGNORE__
default:
retValue = E2E_P_ERROR;
break;
}
return retValue;
}
/* @req SWS_E2E_00382 API for E2E_P01MapStatusToSM */
/* @req SWS_E2E_00384 If CheckReturn != E2E_E_OK,
* then the function E2E_P01MapStatusToSM() shall return E2E_P_ERROR (regardless of value of Status).
*/
/* The function maps the check status of Profile 1 to a generic check status
*/
E2E_PCheckStatusType E2E_P01MapStatusToSM(Std_ReturnType CheckReturn, E2E_P01CheckStatusType Status, boolean profileBehavior) {
E2E_PCheckStatusType retValue = E2E_P_ERROR;
if (CheckReturn != E2E_E_OK) {
retValue = E2E_P_ERROR;
}
else if (profileBehavior == TRUE) { //ASR4.2.2 or higher behavior
retValue = doE2E_P01MapStatusToSM_TRUE(Status);
}
else { //ASR4.2.2 pre-behavior
retValue = doE2E_P01MapStatusToSM_FALSE(Status);
}
return retValue;
}
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/src/E2E_P01.c
|
C
|
unknown
| 26,345
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00216
* The E2E Library shall not call BSW modules for error reporting (in particular DEM and DET), nor for any other purpose.
* The E2E Library shall not call RTE. */
/* @req SWS_E2E_00215 Files E2E_P02.c and E2E_P02.h shall contain implementation parts specific of each profile. */
/* @req SWS_E2E_00049 The E2E library shall not contain library-internal mechanisms for error detection to be traced as development errors. */
/* @req SWS_E2E_00221 Each E2E Profile shall use a subset of the data protection mechanisms defined in AUTOSAR_SWS_E2ELibrary.pdf, 7.2. */
/* @req SWS_E2E_00011 The E2E Library shall report errors detected by library-internal mechanisms
* to callers of E2E functions through return value.
*/
/* @req SWS_E2E_00012 The internal library mechanisms shall detect and report errors
* shall be implemented according to the pre-defined E2E Profiles specified in sections 7.3 and 7.4.
*/
#include "E2E_P02.h"
//#define USE_LDEBUG_PRINTF // Uncomment this to turn debug statements on.
//#include "debug.h"
/* @req SWS_E2E_00153 the counter is incremented modulo 16. */
#define MAX_P02_COUNTER_VALUE (15)
/* @req SWS_E2E_00121 Length of data, in bits.
* E2E checks that Length is ≥ MinDataLength. The value shall be ≥ 2*8.
* E2E checks that DataLength is ≤ MaxDataLength. The value shall be = 256*8.
*/
#define MAX_P02_DATA_LENGTH_IN_BITS (8*256)
#define MIN_P02_DATA_LENGTH_IN_BITS (8*2)
#define E2E_P02_AR_RELEASE_MAJOR_VERSION_INT 4u
#define E2E_P02_AR_RELEASE_MINOR_VERSION_INT 3u
#define E2E_P02_AR_RELEASE_REVISION_VERSION_INT 0u
#define E2E_P02_SW_MAJOR_VERSION_INT 2
#define E2E_P02_SW_MINOR_VERSION_INT 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_P02_SW_MAJOR_VERSION != E2E_P02_SW_MAJOR_VERSION_INT) || (E2E_P02_SW_MINOR_VERSION != E2E_P02_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between E2E_P02.c and E2E_P02.h"
#endif
#if (E2E_P02_AR_RELEASE_MAJOR_VERSION != E2E_P02_AR_RELEASE_MAJOR_VERSION_INT) || (E2E_P02_AR_RELEASE_MINOR_VERSION != E2E_P02_AR_RELEASE_MINOR_VERSION_INT) || \
(E2E_P02_AR_RELEASE_REVISION_VERSION != E2E_P02_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between E2E_P02.c and E2E_P02.h"
#endif
/* @req SWS_E2E_00135 In E2E Profile 2, the local variable DeltaCounter shall be calculated
* by subtracting LastValidCounter from Counter in Data,
* considering an overflow due to the range of values [0…15].
*/
/* Calculation of the delta counter value taken into account the overflow.
*/
static INLINE uint8 calculateDeltaCounterP02(uint8 receivedCounter, uint8 lastValidCounter) {
uint8 status;
if (receivedCounter >= lastValidCounter) {
status = receivedCounter - lastValidCounter;
}
else {
status = MAX_P02_COUNTER_VALUE + 1 + receivedCounter - lastValidCounter;
}
return status;
}
/* @req SWS_E2E_00047 Definition of error flags for all E2E units */
/* @req SWS_E2E_00152 Non-modifiable configuration of the data element sent over an RTE port,
* for E2E profile 2. The position of the counter and CRC is not configurable in profile 2. */
/* Checks the correctness of the configuration parameter.
*/
static INLINE Std_ReturnType checkConfigP02(const E2E_P02ConfigType* Config) {
/* Check for NULL pointers */
Std_ReturnType status;
status = E2E_E_OK;
if (Config == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
}
/* Check input parameters values */
else if (((Config->DataLength % 8) != 0) || (Config->DataLength < MIN_P02_DATA_LENGTH_IN_BITS) ||
(Config->DataLength > MAX_P02_DATA_LENGTH_IN_BITS)) {
status = E2E_E_INPUTERR_WRONG;
}
/* Offset of the E2E header in the Data[] array in bits. It shall be: 0 ≤ Offset ≤ MaxDataLength-(2*8). */
else if (Config->Offset > (MAX_P02_DATA_LENGTH_IN_BITS-MIN_P02_DATA_LENGTH_IN_BITS)) {
status = E2E_E_INPUTERR_WRONG;
}
else {
status = E2E_E_OK;
}
return status;
}
/* @req SWS_E2E_00117 E2E Profile 2 shall use the Crc_CalculateCRC8H2F() function
* of the SWS CRC Library for calculating CRC checksums. */
/* @req SWS_E2E_00118 E2E Profile 2 shall use 0xFF as the start value CRC_StartValue8 for CRC calculation. */
/* @req SWS_E2E_00119 In E2E Profile 2, the specific Data ID used to calculate a specific CRC shall be of length 8 bit. */
/* @req SWS_E2E_00120 In E2E Profile 2, the specific Data ID used for CRC calculation shall be selected from a
* pre-defined DataIDList[16] using the value of the Counter as an index. */
/* @req SWS_E2E_00122 In E2E Profile 2, the CRC shall be Data[0]. */
/* @req SWS_E2E_00123 In E2E Profile 2, the Counter shall be the low nibble (Bit 0…Bit 3) of Data[1]. */
/* @req SWS_E2E_00124 In E2E Profile 2, the E2E_P02Protect() function shall not modify any bit of Data
* except the bits representing the CRC and the Counter. */
/* @req SWS_E2E_00126 In E2E Profile 2, the E2E_P02Protect() function shall perform the activities
* as specified in Figure 7-8 and Figure 7-9 in AUTOSAR_SWS_E2ELibrary.pdf. */
/* @req SWS_E2E_00127 In E2E Profile 2, the E2E_P02Protect() function shall increment the Counter
* of the state (E2E_P02ProtectStateType) by 1 on every transmission request from the sending SW-C,
* i.e. on every call of E2E_P02Protect(). */
/* @req SWS_E2E_00128 In E2E Profile 2, the range of the value of the Counter shall be [0…15]. */
/* @req SWS_E2E_00129 When the Counter has reached its upper bound of 15 (0xF),
* it shall restart at 0 for the next call of the E2E_P02Protect() from the sending SW-C. */
/* @req SWS_E2E_00130 In E2E Profile 2, the E2E_P02Protect() function shall update the Counter
* (i.e. low nibble (Bit 0…Bit 3) of Data byte 1) in the data buffer (Data) after incrementing the Counter. */
/* @req SWS_E2E_00132 In E2E Profile 2, after determining the specific Data ID, the E2E_P02Protect() function shall
* calculate the CRC over Data[1], Data[2], … Data[Config->DataLength/8-1] of the data buffer (Data)
* extended with the Data ID. */
/* @req SWS_E2E_00133 In E2E Profile 2, the E2E_P02Protect() function shall update the CRC (i.e. Data[0])
* in the data buffer (Data) after computing the CRC. */
/* @req SWS_E2E_00160 API for E2E_P02Protect */
/* @req SWS_E2E_00219 Profile 2 shall provide the following mechanisms as specified in 7.4 */
/* Protects the array/buffer to be transmitted using the E2E profile 2.
*/
Std_ReturnType E2E_P02Protect(const E2E_P02ConfigType* ConfigPtr, E2E_P02ProtectStateType* StatePtr, uint8* DataPtr) {
Std_ReturnType status;
status = E2E_E_OK;
uint8 dataId;
uint8 crc;
Std_ReturnType returnValue = checkConfigP02(ConfigPtr);
if (E2E_E_OK != returnValue) {
status = returnValue;
}
else if ((StatePtr == NULL_PTR) || (DataPtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
else {
/* Increase counter*/
StatePtr->Counter = (StatePtr->Counter + 1) % (MAX_P02_COUNTER_VALUE + 1);
/* Add counter to data */
DataPtr[1] = (DataPtr[1] & 0xF0u) | (StatePtr->Counter & 0x0Fu);
/* Get the data id */
dataId = ConfigPtr->DataIDList[StatePtr->Counter];
/* Calculate CRC over data and then data id */
crc = Crc_CalculateCRC8H2F(&DataPtr[1], (ConfigPtr->DataLength/8)-1, 0x00, TRUE);
crc = Crc_CalculateCRC8H2F(&dataId, 1, crc, FALSE);
/* Write crc to data */
DataPtr[0] = crc;
}
return status;
}
/* Check if that is the first data since initialisation
*/
static INLINE boolean isFirstDataSinceInitialisationP02(const E2E_P02ConfigType* ConfigPtr, E2E_P02CheckStateType* StatePtr, uint8 receivedCounter) {
boolean status;
status = FALSE;
if (StatePtr->WaitForFirstData == TRUE) {
StatePtr->WaitForFirstData = FALSE;
StatePtr->MaxDeltaCounter = ConfigPtr->MaxDeltaCounterInit;
StatePtr->LastValidCounter = receivedCounter;
StatePtr->Status= E2E_P02STATUS_INITIAL;
status = TRUE;
}
return status;
}
/* Checks the Data received using the E2E profile 2.
* Ok, this is the normal case. Calculate delta counter, Check the counter delta */
static INLINE void doChecksP02(const E2E_P02ConfigType* ConfigPtr, E2E_P02CheckStateType* StatePtr, uint8 receivedCounter) {
uint8 delta;
delta = calculateDeltaCounterP02(receivedCounter, StatePtr->LastValidCounter);
// LDEBUG_PRINTF("delta= 0x%02x", delta);
// LDEBUG_PRINTF("\n");
if (delta == 0) {
// LDEBUG_PRINTF("delta == 0, %d, %d", StatePtr->NoNewOrRepeatedDataCounter, MAX_P02_COUNTER_VALUE);
// LDEBUG_PRINTF("\n");
if (StatePtr->NoNewOrRepeatedDataCounter < MAX_P02_COUNTER_VALUE) {
StatePtr->NoNewOrRepeatedDataCounter++;
}
StatePtr->Status= E2E_P02STATUS_REPEATED;
}
else if (delta == 1) {
//LDEBUG_PRINTF("deltaCounter == 1");
//LDEBUG_PRINTF("\n");
StatePtr->MaxDeltaCounter = ConfigPtr->MaxDeltaCounterInit;
StatePtr->LastValidCounter = receivedCounter;
StatePtr->LostData = 0;
if (StatePtr->NoNewOrRepeatedDataCounter <= ConfigPtr->MaxNoNewOrRepeatedData) {
StatePtr->NoNewOrRepeatedDataCounter = 0;
if (StatePtr->SyncCounter > 0) {
StatePtr->SyncCounter--;
StatePtr->Status = E2E_P02STATUS_SYNC;
}
else {
StatePtr->Status = E2E_P02STATUS_OK;
}
}
else {
StatePtr->NoNewOrRepeatedDataCounter = 0;
StatePtr->SyncCounter = ConfigPtr->SyncCounterInit;
StatePtr->Status = E2E_P02STATUS_SYNC;
}
}
else if (delta > StatePtr->MaxDeltaCounter) {
// LDEBUG_PRINTF("deltaCounter > StatePtr->MaxDeltaCounter, %d, %d", StatePtr->SyncCounter, ConfigPtr->SyncCounterInit);
// LDEBUG_PRINTF("\n");
StatePtr->NoNewOrRepeatedDataCounter= 0;
StatePtr->SyncCounter = ConfigPtr->SyncCounterInit;
if (StatePtr->SyncCounter > 0) {
// LDEBUG_PRINTF("StatePtr->SyncCounter > 0");
// LDEBUG_PRINTF("\n");
StatePtr->MaxDeltaCounter = ConfigPtr->MaxDeltaCounterInit;
StatePtr->LastValidCounter = receivedCounter;
}
StatePtr->Status= E2E_P02STATUS_WRONGSEQUENCE;
} // delta > MaxDeltaCounter
else {
// LDEBUG_PRINTF("delta > MaxDeltaCounter, %d, %d", StatePtr->NoNewOrRepeatedDataCounter, ConfigPtr->MaxNoNewOrRepeatedData);
// LDEBUG_PRINTF("\n");
StatePtr->MaxDeltaCounter = ConfigPtr->MaxDeltaCounterInit;
StatePtr->LastValidCounter = receivedCounter;
StatePtr->LostData = delta - 1;
if (StatePtr->NoNewOrRepeatedDataCounter <= ConfigPtr->MaxNoNewOrRepeatedData) {
StatePtr->NoNewOrRepeatedDataCounter= 0;
// LDEBUG_PRINTF("StatePtr->NoNewOrRepeatedDataCounter %d", StatePtr->NoNewOrRepeatedDataCounter);
// LDEBUG_PRINTF("\n");
if (StatePtr->SyncCounter > 0) {
// LDEBUG_PRINTF("StatePtr->SyncCounter > 0");
// LDEBUG_PRINTF("\n");
StatePtr->SyncCounter--;
StatePtr->Status = E2E_P02STATUS_SYNC;
}
else {
StatePtr->Status = E2E_P02STATUS_OKSOMELOST;
}
}
else {
StatePtr->NoNewOrRepeatedDataCounter= 0;
StatePtr->SyncCounter = ConfigPtr->SyncCounterInit;
StatePtr->Status = E2E_P02STATUS_SYNC;
}
} // 1 < delta <= MaxDeltaCounter
}
/* @req SWS_E2E_00118 E2E Profile 2 shall use 0xFF as the start value CRC_StartValue8 for CRC calculation. */
/* @req SWS_E2E_00119 In E2E Profile 2, the specific Data ID used to calculate a specific CRC shall be of length 8 bit. */
/* @req SWS_E2E_00120 In E2E Profile 2, the specific Data ID used for CRC calculation shall be selected from a
* pre-defined DataIDList[16] using the value of the Counter as an index. */
/* @req SWS_E2E_00122 In E2E Profile 2, the CRC shall be Data[0]. */
/* @req SWS_E2E_00123 In E2E Profile 2, the Counter shall be the low nibble (Bit 0…Bit 3) of Data[1]. */
/* @req SWS_E2E_00125 In E2E Profile 2, the E2E_P02Check() function shall not modify any bit in Data. */
/* @req SWS_E2E_00134 In E2E Profile 2, the E2E_P02Check() function shall perform the activities as specified
* in Figure 7-10, Figure 7-11and Figure 7-12 of AUTOSAR_SWS_E2ELibrary. */
/* @req SWS_E2E_00136 In E2E Profile 2, MaxDeltaCounter shall specify the maximum allowed difference
* between two Counter values of two consecutively received valid messages. */
/* @req SWS_E2E_00137 In E2E Profile 2, MaxDeltaCounter shall be incremented by 1 every time the E2E_P02Check()
* function is called, up to the maximum value of 15 (0xF). */
/* @req SWS_E2E_00138 In E2E Profile 2, the E2E_P02Check() function shall set Status to E2E_P02STATUS_NONEWDATA
* if the attribute NewDataAvailable is FALSE. */
/* @req SWS_E2E_00139 In E2E Profile 2, the E2E_P02Check() function shall determine the specific Data ID
* from DataIDList using the Counter of the received Data as index. */
/* @req SWS_E2E_00140 In E2E Profile 2, the E2E_P02Check() function shall calculate CalculatedCRC over
* Data[1], Data[2], … Data[Config->DataLength/8-1] of the data buffer (Data) extended with the determined Data ID. */
/* @req SWS_E2E_00141 In E2E Profile 2, the E2E_P02Check() function shall set Status to E2E_P02STATUS_WRONGCRC
* if the calculated CalculatedCRC value differs from the value of the CRC in Data. */
/* @req SWS_E2E_00142 In E2E Profile 2, the E2E_P02Check() function shall set Status to E2E_P02STATUS_INITIAL
* if the flag WaitForFirstData is TRUE. */
/* @req SWS_E2E_00143 In E2E Profile 2, the E2E_P02Check() function shall clear the flag WaitForFirstData
* if it returns with Status E2E_P02STATUS_INITIAL. */
/* @req SWS_E2E_00145 The E2E_P02Check() function shall
* * set Status to E2E_P02STATUS_WRONGSEQUENCE; and
* * re-initialize SyncCounter with SyncCounterInit
* if the calculated value of DeltaCounter exceeds the value of MaxDeltaCounter. */
/* @req SWS_E2E_00146 The E2E_P02Check() function shall set Status to E2E_P02STATUS_REPEATED
* if the calculated DeltaCounter equals 0. */
/* @req SWS_E2E_00147 The E2E_P02Check() function shall set Status to E2E_P02STATUS_OK
* if the following conditions are true:
* * the calculated DeltaCounter equals 1; and
* * the value of the NoNewOrRepeatedDataCounter is less than or equal to MaxNoNewOrRepeatedData
* (i.e. State -> NoNewOrRepeatedDataCounter ≤ Config -> MaxNoNewOrRepeatedData); and
* * the SyncCounter equals 0.*/
/* @req SWS_E2E_00148 The E2E_P02Check() function shall set Status to E2E_P02STATUS_OKSOMELOST
* if the following conditions are true: compare AUTOSAR_SWS_E2ELibrary.pdf. */
/* @req SWS_E2E_00149 The E2E_P02Check() function shall set the value LostData to (DeltaCounter – 1)
* if the calculated DeltaCounter is greater-than 1 but less-than or equal to MaxDeltaCounter. */
/* @req SWS_E2E_00150 The E2E_P02Check() function shall re-initialize MaxDeltaCounter with MaxDeltaCounterInit
* if it returns one of the following Status */
/* @req SWS_E2E_00151 The E2E_P02Check() function shall set LastValidCounter to Counter of Data
* if it returns one of the following Status */
/* @req SWS_E2E_00161 API for E2E_P02Check */
/* @req SWS_E2E_00219 Profile 2 shall provide the following mechanisms as specified in 7.4 */
/* @req SWS_E2E_00298 The E2E_P02Check() function shall
* *re-initialize SyncCounter with SyncCounterInit; and
* * set Status to E2E_P02STATUS_SYNC;
* if the following conditions are true: */
/* @req SWS_E2E_00299 The E2E_P02Check() function shall
* * decrement SyncCounter by 1; and
* * set Status to E2E_P02STATUS_SYNC
* if the following conditions are true: */
/* @req SWS_E2E_00300 The E2E_P02Check() function shall reset the NoNewOrRepeatedDataCounter to 0
* if it returns one of the following status: */
/* @req SWS_E2E_00301 The E2E_P02Check() function shall increment NoNewOrRepeatedDataCounter by 1
* if it returns the Status E2E_P02STATUS_NONEWDATA or E2E_P02STATUS_REPEATED
* up to the maximum value of Counter (i.e. 15 or 0xF). */
/* Checks the Data received using the E2E profile 2.
*/
Std_ReturnType E2E_P02Check(const E2E_P02ConfigType* ConfigPtr, E2E_P02CheckStateType* StatePtr, const uint8* DataPtr) {
Std_ReturnType status;
status = E2E_E_OK;
boolean ret;
ret = TRUE;
uint8 receivedCounter;
uint8 dataId;
uint8 crc;
Std_ReturnType returnValue = checkConfigP02(ConfigPtr);
if (E2E_E_OK != returnValue) {
status = returnValue;
}
else if ((StatePtr == NULL_PTR) || (DataPtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
else {
/* This is the stated behavior in figure 7-10 but it seems wrong. This means that if more than 15
* messages are received with wrong CRC, the first message with correct CRC will be have state
* OKSOMELOST even though it should be WRONGSEQUENCE.
*/
if (StatePtr->MaxDeltaCounter < MAX_P02_COUNTER_VALUE) {
StatePtr->MaxDeltaCounter++;
}
if (StatePtr->NewDataAvailable == FALSE) {
if (StatePtr->NoNewOrRepeatedDataCounter < MAX_P02_COUNTER_VALUE) {
StatePtr->NoNewOrRepeatedDataCounter++;
}
StatePtr->Status = E2E_P02STATUS_NONEWDATA;
status = E2E_E_OK;
ret = FALSE;
}
if (ret == TRUE) {
receivedCounter = DataPtr[1] & 0xFu;
dataId = ConfigPtr->DataIDList[receivedCounter];
/* Calculate CRC over data and then data id */
crc = Crc_CalculateCRC8H2F(&DataPtr[1], (ConfigPtr->DataLength/8)-1, 0x00, TRUE);
crc = Crc_CalculateCRC8H2F(&dataId, 1, crc, FALSE);
/* Compare calculate and received crc */
if (crc != DataPtr[0]) {
StatePtr->Status = E2E_P02STATUS_WRONGCRC;
status = E2E_E_OK;
}
/* Check if this is the first data since initialization */
else if (isFirstDataSinceInitialisationP02(ConfigPtr, StatePtr, receivedCounter) == TRUE) {
status = E2E_E_OK;
} else {
doChecksP02(ConfigPtr, StatePtr, receivedCounter);
}
}
}
return status;
}
/* @req SWS_E2E_00387 API for E2E_P02ProtectInit */
/* @req SWS_E2E_00388 In case State is NULL, E2E_P02ProtectInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall intialize the state structure, setting Counter to 0. */
/* Initializes the protection state.
*/
Std_ReturnType E2E_P02ProtectInit(E2E_P02ProtectStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
} else {
StatePtr->Counter = 0;
}
return status;
}
/* @req SWS_E2E_00391 API for E2E_P02CheckInit */
/* @req SWS_E2E_00392 In case State is NULL, E2E_P02CheckInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall initialize the state structure, setting: */
/* UC_E2E_00208, UC_E2E_00297, SWS_E2E_00324, SWS_E2E_00325 overwrites init values NewDataAvailable */
/* @req ARC_SWS_E2E_00001 */
/* Initializes the check state.
*/
Std_ReturnType E2E_P02CheckInit(E2E_P02CheckStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
} else {
StatePtr->LastValidCounter = 0;
StatePtr->MaxDeltaCounter = 0;
StatePtr->WaitForFirstData = TRUE;
StatePtr->NewDataAvailable = FALSE;
StatePtr->LostData = 0;
StatePtr->Status = E2E_P02STATUS_NONEWDATA;
StatePtr->SyncCounter = 0;
StatePtr->NoNewOrRepeatedDataCounter = 0;
}
return status;
}
/* @req SWS_E2E_00380 If CheckReturn == E2E_E_OK and ProfileBehavior == 1,
* then the function E2E_P02MapStatusToSM shall return the values depending on the value of Status: */
/* The function maps the check status of Profile 2 to a generic check status in case ProfileBehavior == True
*/
static INLINE E2E_PCheckStatusType doE2E_P02MapStatusToSM_TRUE(E2E_P02CheckStatusType Status) {
E2E_PCheckStatusType retValue = E2E_P_ERROR;
switch(Status) {
case E2E_P02STATUS_OK:
case E2E_P02STATUS_OKSOMELOST:
case E2E_P02STATUS_SYNC:
retValue = E2E_P_OK;
break;
case E2E_P02STATUS_REPEATED:
retValue = E2E_P_REPEATED;
break;
case E2E_P02STATUS_NONEWDATA:
retValue = E2E_P_NONEWDATA;
break;
case E2E_P02STATUS_WRONGSEQUENCE:
case E2E_P02STATUS_INITIAL:
retValue = E2E_P_WRONGSEQUENCE;
break;
/* @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming. If this happens the state will be restored to E2E_P_ERROR */
__CODE_COVERAGE_IGNORE__
default:
retValue = E2E_P_ERROR;
break;
}
return retValue;
}
/* @req SWS_E2E_00477 If CheckReturn == E2E_E_OK and ProfileBehavior == 0,
* then the function E2E_P02MapStatusToSM shall return the values depending on the value of Status: */
/* The function maps the check status of Profile 2 to a generic check status in case ProfileBehavior == False
*/
static INLINE E2E_PCheckStatusType doE2E_P02MapStatusToSM_FALSE(E2E_P02CheckStatusType Status) {
E2E_PCheckStatusType retValue = E2E_P_ERROR;
switch(Status) {
case E2E_P02STATUS_OK:
case E2E_P02STATUS_OKSOMELOST:
case E2E_P02STATUS_INITIAL:
retValue = E2E_P_OK;
break;
case E2E_P02STATUS_REPEATED:
retValue = E2E_P_REPEATED;
break;
case E2E_P02STATUS_NONEWDATA:
retValue = E2E_P_NONEWDATA;
break;
case E2E_P02STATUS_WRONGSEQUENCE:
case E2E_P02STATUS_SYNC:
retValue = E2E_P_WRONGSEQUENCE;
break;
/* @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming. If this happens the state will be restored to E2E_P_ERROR */
__CODE_COVERAGE_IGNORE__
default:
retValue = E2E_P_ERROR;
break;
}
return retValue;
}
/* @req SWS_E2E_00379 API for E2E_P02MapStatusToSM */
/* @req SWS_E2E_00381 If CheckReturn != E2E_E_OK, then the function E2E_P02MapStatusToSM()
* shall return E2E_P_ERROR (regardless of value of Status). */
/* The function maps the check status of Profile 2 to a generic check status
*/
E2E_PCheckStatusType E2E_P02MapStatusToSM(Std_ReturnType CheckReturn, E2E_P02CheckStatusType Status, boolean profileBehavior) {
E2E_PCheckStatusType retValue = E2E_P_ERROR;
if (CheckReturn != E2E_E_OK) {
retValue = E2E_P_ERROR;
}
else if (profileBehavior == TRUE) { //ASR4.2.2 or higher behavior
retValue = doE2E_P02MapStatusToSM_TRUE(Status);
}
else { //ASR4.2.2 pre-behavior
retValue = doE2E_P02MapStatusToSM_FALSE(Status);
}
return retValue;
}
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/src/E2E_P02.c
|
C
|
unknown
| 25,025
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00216
* The E2E Library shall not call BSW modules for error reporting (in particular DEM and DET), nor for any other purpose.
* The E2E Library shall not call RTE. */
/* @req SWS_E2E_00215 Files E2E_P04.c and E2E_P04.h shall contain implementation parts specific of each profile. */
/* @req SWS_E2E_00049 The E2E library shall not contain library-internal mechanisms for error detection to be traced as development errors. */
/* @req SWS_E2E_00221 Each E2E Profile shall use a subset of the data protection mechanisms defined in AUTOSAR_SWS_E2ELibrary.pdf, 7.2. */
/* @req SWS_E2E_00011 The E2E Library shall report errors detected by library-internal mechanisms
* to callers of E2E functions through return value.
*/
/* @req SWS_E2E_00012 The internal library mechanisms shall detect and report errors
* shall be implemented according to the pre-defined E2E Profiles specified in sections 7.3 and 7.4.
*/
#include "E2E_P04.h"
/* @req SWS_E2E_00478 Counter maximum value (0xFFFF) */
#define MAX_P04_COUNTER_VALUE (65535)
/* @req SWS_E2E_00334 Length of Data, in bits.
* E2E checks that Length is ≥ MinDataLength. The value shall be ≥ 12*8.
* E2E checks that DataLength is ≤ MaxDataLength. The value shall be = 4096*8 (4kB) */
#define MAX_P04_DATA_LENGTH_IN_BITS (8*4096)
#define MIN_P04_DATA_LENGTH_IN_BITS (8*12)
#define E2E_P04_AR_RELEASE_MAJOR_VERSION_INT 4u
#define E2E_P04_AR_RELEASE_MINOR_VERSION_INT 3u
#define E2E_P04_AR_RELEASE_REVISION_VERSION_INT 0u
#define E2E_P04_SW_MAJOR_VERSION_INT 2
#define E2E_P04_SW_MINOR_VERSION_INT 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_P04_SW_MAJOR_VERSION != E2E_P04_SW_MAJOR_VERSION_INT) || (E2E_P04_SW_MINOR_VERSION != E2E_P04_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between E2E_P04.c and E2E_P04.h"
#endif
#if (E2E_P04_AR_RELEASE_MAJOR_VERSION != E2E_P04_AR_RELEASE_MAJOR_VERSION_INT) || (E2E_P04_AR_RELEASE_MINOR_VERSION != E2E_P04_AR_RELEASE_MINOR_VERSION_INT) || \
(E2E_P04_AR_RELEASE_REVISION_VERSION != E2E_P04_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between E2E_P04.c and E2E_P04.h"
#endif
/* @req SWS_E2E_00047 Definition of error flags for all E2E units */
/* @req SWS_E2E_00334 Checks Min and Max Length */
/* @req SWS_E2E_00363 The step “Verify inputs of the protect function” in E2E_P04Protect() shall
* have the following behavior: */
/* Verifies the input of the function Protect Input for the Profile 04.
*/
static INLINE Std_ReturnType verifyProtectInputsP04(const E2E_P04ConfigType* ConfigPtr, const E2E_P04ProtectStateType* StatePtr, const uint8* DataPtr, uint16 Length) {
Std_ReturnType status;
status = E2E_E_OK;
/* Check for NULL pointers */
if ((ConfigPtr == NULL_PTR) || (StatePtr == NULL_PTR) || (DataPtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
/* Check input parameters values */
else if ((ConfigPtr->MinDataLength < MIN_P04_DATA_LENGTH_IN_BITS) || (ConfigPtr->MaxDataLength < MIN_P04_DATA_LENGTH_IN_BITS) ||
(ConfigPtr->MinDataLength > MAX_P04_DATA_LENGTH_IN_BITS) || (ConfigPtr->MaxDataLength > MAX_P04_DATA_LENGTH_IN_BITS) ||
(ConfigPtr->MinDataLength > ConfigPtr->MaxDataLength)) {
status = E2E_E_INPUTERR_WRONG;
}
/* Transmitted length shall be MinDataLength ≤ Length ≤ MaxDataLength */
else if ( ((Length*8) < ConfigPtr->MinDataLength) || ((Length*8) > ConfigPtr->MaxDataLength) ) {
status = E2E_E_INPUTERR_WRONG;
}
/* The offset shall be configured to a multiple of 8 and 0 ≤ Offset ≤ (Max)DataLength-(12*8). Compared to transmitted length as E2E header has to fit data */
else if ( ((ConfigPtr->Offset % 8) != 0) || (ConfigPtr->Offset > ((Length*8)-MIN_P04_DATA_LENGTH_IN_BITS))) {
status = E2E_E_INPUTERR_WRONG;
}
else {
status = E2E_E_OK;
}
return status;
}
/* @req SWS_E2E_00376 The step “Compute offset” in E2E_P04Protect() and E2E_P04Check() shall
* have the following behavior: */
/* Return local variable uint16 Offset, which is in [byte].
*/
static INLINE uint16 computeOffsetP04(const E2E_P04ConfigType* ConfigPtr) {
return (ConfigPtr->Offset/8);
}
/* @req SWS_E2E_00364 The step “Write Length” in E2E_P04Protect() shall
* have the following behavior: */
/* Writes the Length value to the right position within the data byte stream.
*/
static INLINE void writeLengthP04(uint8* DataPtr, uint16 offset, uint16 Length) {
DataPtr[offset ] = ((Length & 0xFF00u) >> 8) & 0xFFu;
DataPtr[offset+1] = (Length & 0x00FFu) & 0xFFu;
}
/* @req SWS_E2E_00365 The step “Write Counter” in E2E_P04Protect() shall
* have the following behavior: */
/* Writes the Counter value to the right position within the data byte stream.
*/
static INLINE void writeCounterP04(uint8* DataPtr, uint16 offset, const E2E_P04ProtectStateType* StatePtr) {
DataPtr[offset+2] = ((StatePtr->Counter & 0xFF00u) >> 8) & 0xFFu;
DataPtr[offset+3] = (StatePtr->Counter & 0x00FFu) & 0xFFu;
}
/* @req SWS_E2E_00366 The step “Write DataID” in E2E_P04Protect() shall have the following behavior: */
/* Writes the Data ID value to the right position within the data byte stream.
*/
static INLINE void writeDataIDP04(uint8* DataPtr, uint16 offset, const E2E_P04ConfigType* ConfigPtr) {
DataPtr[offset+4] = ((ConfigPtr->DataID & 0xFF000000u) >> 24) & 0xFFu;
DataPtr[offset+5] = ((ConfigPtr->DataID & 0x00FF0000u) >> 16) & 0xFFu;
DataPtr[offset+6] = ((ConfigPtr->DataID & 0x0000FF00u) >> 8) & 0xFFu;
DataPtr[offset+7] = ((ConfigPtr->DataID & 0x000000FFu) ) & 0xFFu;
}
/* @req SWS_E2E_00330 In E2E Profile 4, the CRC shall
* be calculated over the entire E2E header (excluding the CRC bytes) and over the user data. */
/* @req SWS_E2E_00326 In the E2E Profile 4, the Data ID shall be explicitly transmitted,
* i.e. it shall be the part of the transmitted E2E header. */
/* @req SWS_E2E_00329 E2E Profile 4 shall use the Crc_CalculateCRC32P4 () function of the SWS CRC Library
* for calculating the CRC.*/
/* @req SWS_E2E_00372 Profile 4 shall provide the control fields as defined in AUTOSAR_SWS_E2ELibrary, 7.5,
* transmitted at runtime together with the protected data: */
/* @req SWS_E2E_00367 The step “ComputeCRC” in E2E_P04Protect() and in E2E_P04Check()
* shall have the following behavior: */
/* Returns the CRC value for the Protect and Check function of the Profile 04.
*/
static INLINE uint32 computeCRCP04(const uint8* DataPtr, uint16 offset, uint16 Length) {
uint32 offsetBytes = (offset+8);
uint32 crc;
/* compute CRC over bytes that are before CRC */
crc = Crc_CalculateCRC32P4(&DataPtr[0], offsetBytes, 0xFFFFFFFFu, TRUE);
/* Compute CRC over bytes that are after CRC (if any) */
if ((offset + 12) < Length) {
offsetBytes = ((Length-offset)-12);
crc = Crc_CalculateCRC32P4(&DataPtr[offset+12], offsetBytes, crc, FALSE);
}
return crc;
}
/* @req SWS_E2E_00368 The step “Write CRC” in E2E_P04Protect() shall have the following behavior: */
/* Writes the CRC value to the right position within the data byte stream.
*/
static INLINE void writeCRCP04(uint8* DataPtr, uint16 offset, uint32 crc) {
DataPtr[offset+ 8] = ((crc & 0xFF000000u) >> 24) & 0xFFu;
DataPtr[offset+ 9] = ((crc & 0x00FF0000u) >> 16) & 0xFFu;
DataPtr[offset+10] = ((crc & 0x0000FF00u) >> 8) & 0xFFu;
DataPtr[offset+11] = ((crc & 0x000000FFu) ) & 0xFFu;
}
/* @req SWS_E2E_00478 In E2E Profile 4, on the sender side, for the first transmission request
* of a data element the counter shall be initialized with 0 and shall be incremented by 1
* for every subsequent send request. When the counter reaches the maximum value (0xFF’FF),
* then it shall restart with 0 for the next send request. */
/* @req SWS_E2E_00369 The step “Increment Counter” in E2E_P04Protect() shall have the following behavior: */
/* Increments the Counter Value on the sender side.
*/
static INLINE void incrementCounterP04(E2E_P04ProtectStateType* StatePtr) {
StatePtr->Counter = (StatePtr->Counter + 1) % (MAX_P04_COUNTER_VALUE + 1);
}
/* @req SWS_E2E_00338 API for E2E_P04Protect */
/* @req SWS_E2E_00362 The function E2E_P04Protect() shall have the following overall behavior: */
/* Protects the array/buffer to be transmitted using the E2E profile 4.
* This includes checksum calculation, handling of counter and Data ID.
*/
Std_ReturnType E2E_P04Protect(const E2E_P04ConfigType* ConfigPtr, E2E_P04ProtectStateType* StatePtr, uint8* DataPtr, uint16 Length) {
uint16 offset;
uint32 crc;
Std_ReturnType returnValue = verifyProtectInputsP04(ConfigPtr, StatePtr, DataPtr, Length);
if (E2E_E_OK == returnValue) {
offset = computeOffsetP04(ConfigPtr);
writeLengthP04(DataPtr, offset, Length);
writeCounterP04(DataPtr, offset, StatePtr);
writeDataIDP04(DataPtr, offset, ConfigPtr);
crc = computeCRCP04(DataPtr, offset, Length);
writeCRCP04(DataPtr, offset, crc);
incrementCounterP04(StatePtr);
}
return returnValue;
}
/* @req SWS_E2E_00047 Definition of error flags for all E2E units */
/* @req SWS_E2E_00356 The step “Verify inputs of the check function” in E2E_P04Check()
* shall have the following behavior: */
/* Verifies the input of the function Check Input for the Profile 04.
*/
static INLINE Std_ReturnType verifyCheckInputsP04(boolean* NewDataAvailable, const E2E_P04ConfigType* ConfigPtr, const E2E_P04CheckStateType* StatePtr, const uint8* DataPtr, uint16 Length) {
Std_ReturnType status;
status = E2E_E_OK;
*NewDataAvailable = FALSE;
/* Check for NULL pointers */
if ((ConfigPtr == NULL_PTR) || (StatePtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
/* Check input parameters values */
else if ((ConfigPtr->MinDataLength < MIN_P04_DATA_LENGTH_IN_BITS) || (ConfigPtr->MaxDataLength < MIN_P04_DATA_LENGTH_IN_BITS) ||
(ConfigPtr->MinDataLength > MAX_P04_DATA_LENGTH_IN_BITS) || (ConfigPtr->MaxDataLength > MAX_P04_DATA_LENGTH_IN_BITS) ||
(ConfigPtr->MinDataLength > ConfigPtr->MaxDataLength)) {
status = E2E_E_INPUTERR_WRONG;
}
else if ( !(((DataPtr != NULL_PTR) && (Length != 0)) || ((DataPtr == NULL_PTR) && (Length == 0))) ) {
status = E2E_E_INPUTERR_WRONG;
}
else if (DataPtr == NULL_PTR) {
status = E2E_E_OK;
}
/* Received length shall be MinDataLength ≤ Length ≤ MaxDataLength */
else if ( ((Length*8) < ConfigPtr->MinDataLength) || ((Length*8) > ConfigPtr->MaxDataLength) ) {
status = E2E_E_INPUTERR_WRONG;
}
/* The offset shall be configured to a multiple of 8 and 0 ≤ Offset ≤ (Max)DataLength-(12*8). Compared to received length as E2E header has to fit data */
else if ( ((ConfigPtr->Offset % 8) != 0) || (ConfigPtr->Offset > ((Length*8)-MIN_P04_DATA_LENGTH_IN_BITS))) {
status = E2E_E_INPUTERR_WRONG;
}
else {
*NewDataAvailable = TRUE;
}
return status;
}
/* @req SWS_E2E_00357 The step “Read Length” in E2E_P04Check()
* shall have the following behavior: */
/* Reads the Length value from the right position within the data byte stream.
*/
static INLINE uint16 readLengthP04(const uint8* DataPtr, uint16 offset) {
uint16 receivedLength = 0;
receivedLength |= (((uint16)DataPtr[offset ]) << 8) & 0xFF00u;
receivedLength |= (((uint16)DataPtr[offset+1]) ) & 0x00FFu;
return receivedLength;
}
/* @req SWS_E2E_00358 The step “Read Counter” in E2E_P04Check()
* shall have the following behavior: */
/* Reads the Counter value from the right position within the data byte stream.
*/
static INLINE uint16 readCounterP04(const uint8* DataPtr, uint16 offset) {
uint16 receivedCounter = 0;
receivedCounter |= (((uint16)DataPtr[offset+2]) << 8) & 0xFF00u;
receivedCounter |= (((uint16)DataPtr[offset+3]) ) & 0x00FFu;
return receivedCounter;
}
/* @req SWS_E2E_00359 The step “Read DataID” in E2E_P04Check()
* shall have the following behavior: */
/* Reads the Data ID value from the right position within the data byte stream.
*/
static INLINE uint32 readDataIDP04(const uint8* DataPtr, uint16 offset) {
uint32 receivedDataID = 0;
receivedDataID |= (((uint32)DataPtr[offset+4]) << 24) & 0xFF000000u;
receivedDataID |= (((uint32)DataPtr[offset+5]) << 16) & 0x00FF0000u;
receivedDataID |= (((uint32)DataPtr[offset+6]) << 8) & 0x0000FF00u;
receivedDataID |= (((uint32)DataPtr[offset+7]) ) & 0x000000FFu;
return receivedDataID;
}
/* @req SWS_E2E_00360 The step “Read CRC” in E2E_P04Check() shall have the following behavior: */
/* Reads the CRC value from the right position within the data byte stream.
*/
static INLINE uint32 readCRCP04(const uint8* DataPtr, uint16 offset) {
uint32 receivedCRC = 0;
receivedCRC |= (((uint32)DataPtr[offset+ 8]) << 24) & 0xFF000000u;
receivedCRC |= (((uint32)DataPtr[offset+ 9]) << 16) & 0x00FF0000u;
receivedCRC |= (((uint32)DataPtr[offset+10]) << 8) & 0x0000FF00u;
receivedCRC |= (((uint32)DataPtr[offset+11]) ) & 0x000000FFu;
return receivedCRC;
}
/* Calculates the delta counter value out of received and last valid counter values.
*/
static INLINE uint16 calculateDeltaCounterP04(uint16 receivedCounter, uint16 lastValidCounter)
{
uint16 status;
if (receivedCounter >= lastValidCounter) {
status = receivedCounter - lastValidCounter;
}
else {
status = (uint16)((uint32)MAX_P04_COUNTER_VALUE + 1 + (uint32)receivedCounter - (uint32)lastValidCounter);
}
return status;
}
/* @req SWS_E2E_00361 The step “Do Checks” in E2E_P04Check() shall have the following behavior: */
/* Do checks to determine the next status value of the receiver.
*/
static INLINE void doChecksP04(E2E_P04CheckStateType* StatePtr, const boolean* NewDataAvailable, const E2E_P04ConfigType* ConfigPtr, uint32 receivedCRC, uint32 computedCRC, uint32 receivedDataID, uint16 receivedLength, uint16 Length, uint16 receivedCounter) {
uint16 deltaCounter;
if (*NewDataAvailable == FALSE) {
StatePtr->Status = E2E_P04STATUS_NONEWDATA;
}
else if ( (receivedCRC != computedCRC) || (receivedDataID != ConfigPtr->DataID)
/** @CODECOV PARAMETER_VALIDATION_PRIVATE_FUNCTION:CRC check will always fail if lengths are different, length check will never occur */
__CODE_COVERAGE_IGNORE__
|| (receivedLength != Length)) {
StatePtr->Status = E2E_P04STATUS_ERROR;
}
else {
deltaCounter = calculateDeltaCounterP04(receivedCounter, StatePtr->Counter);
if (deltaCounter > ConfigPtr->MaxDeltaCounter) {
StatePtr->Status = E2E_P04STATUS_WRONGSEQUENCE;
}
else if (deltaCounter == 0) {
StatePtr->Status = E2E_P04STATUS_REPEATED;
}
else if (deltaCounter == 1) {
StatePtr->Status = E2E_P04STATUS_OK;
}
else {
StatePtr->Status = E2E_P04STATUS_OKSOMELOST;
}
StatePtr->Counter = receivedCounter;
}
}
/* @req SWS_E2E_00339 API for E2E_P04Check */
/* @req SWS_E2E_00337 Definition of E2E_P04CheckStatusType */
/* @req SWS_E2E_00355 The function E2E_P04Check() shall have the following overall behavior: */
/* Checks the Data received using the E2E profile 4. This includes CRC calculation, handling of Counter and Data ID.
* The function checks only one single data in one cycle, it does not determine/compute the accumulated
* state of the communication link.
*/
Std_ReturnType E2E_P04Check(const E2E_P04ConfigType* ConfigPtr, E2E_P04CheckStateType* StatePtr, const uint8* DataPtr, uint16 Length) {
boolean NewDataAvailable;
uint16 offset;
uint16 receivedLength = 0;
uint16 receivedCounter = 0;
uint32 receivedDataID = 0;
uint32 receivedCRC = 0;
uint32 computedCRC = 0;
Std_ReturnType returnValue = verifyCheckInputsP04(&NewDataAvailable, ConfigPtr, StatePtr, DataPtr, Length);
if (E2E_E_OK == returnValue) {
if (NewDataAvailable == TRUE) {
offset = computeOffsetP04(ConfigPtr);
receivedLength = readLengthP04(DataPtr, offset);
receivedCounter = readCounterP04(DataPtr, offset);
receivedDataID = readDataIDP04(DataPtr, offset);
receivedCRC = readCRCP04(DataPtr, offset);
computedCRC = computeCRCP04(DataPtr, offset, Length);
}
doChecksP04(StatePtr, &NewDataAvailable, ConfigPtr, receivedCRC, computedCRC, receivedDataID, receivedLength, Length, receivedCounter);
}
return returnValue;
}
/* @req SWS_E2E_00335 Definition of E2E_P04ProtectStateType */
/* @req SWS_E2E_00373 API for E2E_P04ProtectInit */
/* @req SWS_E2E_00377 In case State is NULL, E2E_P04ProtectInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall intialize the state structure, setting Counter to 0. */
/* Initializes the protection state.
*/
Std_ReturnType E2E_P04ProtectInit(E2E_P04ProtectStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
} else {
StatePtr->Counter = 0;
}
return status;
}
/* @req SWS_E2E_00336 Definition of the State of the reception on one single Data protected with E2E Profile 4. */
/* @req SWS_E2E_00350 API for E2E_P04CheckInit */
/* @req SWS_E2E_00378 In case State is NULL, E2E_P04CheckInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall initialize the state structure, setting:
* 1. Counter to 0xFF’FF.
* 2. Status to E2E_P04STATUS_ERROR.
*/
/* Initializes the check state.
*/
Std_ReturnType E2E_P04CheckInit(E2E_P04CheckStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
} else {
StatePtr->Status = E2E_P04STATUS_ERROR;
StatePtr->Counter = 0xFFFF;
}
return status;
}
/* @req SWS_E2E_00349 API for E2E_P04MapStatusToSM */
/* @req SWS_E2E_00351 If CheckReturn = E2E_E_OK, then the function E2E_P04MapStatusToSM shall
* return the values depending on the value of Status: */
/* @req SWS_E2E_00352 If CheckReturn != E2E_E_OK, then the function E2E_P04MapStatusToSM() shall
* return E2E_P_ERROR (regardless of value of Status). */
/* The function maps the check status of Profile 4 to a generic check status,
* which can be used by E2E state machine check function.
* The E2E Profile 4 delivers a more fine-granular status, but this is not relevant for the E2E state machine.
*/
E2E_PCheckStatusType E2E_P04MapStatusToSM(Std_ReturnType CheckReturn, E2E_P04CheckStatusType Status) {
E2E_PCheckStatusType retValue = E2E_P_ERROR;
if (CheckReturn == E2E_E_OK) {
switch( Status ) {
case E2E_P04STATUS_OK:
case E2E_P04STATUS_OKSOMELOST:
retValue = E2E_P_OK;
break;
case E2E_P04STATUS_REPEATED:
retValue = E2E_P_REPEATED;
break;
case E2E_P04STATUS_NONEWDATA:
retValue = E2E_P_NONEWDATA;
break;
case E2E_P04STATUS_WRONGSEQUENCE:
retValue = E2E_P_WRONGSEQUENCE;
break;
/* @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming. If this happens the state will be restored to E2E_P_ERROR */
__CODE_COVERAGE_IGNORE__
default:
retValue = E2E_P_ERROR;
break;
}
}
return retValue;
}
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/src/E2E_P04.c
|
C
|
unknown
| 21,366
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00216
* The E2E Library shall not call BSW modules for error reporting (in particular DEM and DET), nor for any other purpose.
* The E2E Library shall not call RTE. */
/* @req SWS_E2E_00215 Files E2E_P05.c and E2E_P05.h shall contain implementation parts specific of each profile. */
/* @req SWS_E2E_00049 The E2E library shall not contain library-internal mechanisms for error detection to be traced as development errors. */
/* @req SWS_E2E_00221 Each E2E Profile shall use a subset of the data protection mechanisms defined in AUTOSAR_SWS_E2ELibrary.pdf, 7.2. */
/* @req SWS_E2E_00011 The E2E Library shall report errors detected by library-internal mechanisms
* to callers of E2E functions through return value.
*/
/* @req SWS_E2E_00012 The internal library mechanisms shall detect and report errors
* shall be implemented according to the pre-defined E2E Profiles specified in sections 7.3 and 7.4.
*/
#include "E2E_P05.h"
/* @req SWS_E2E_00397 Counter maximum value (0xFF) */
#define MAX_P05_COUNTER_VALUE (255)
/* @req SWS_E2E_00437 Length of Data, in bits.
* The maximum value shall be = 4096*8 (4kB) and shall be ≥ 3*8
*/
#define MAX_P05_DATA_LENGTH_IN_BITS (8*4096)
#define MIN_P05_DATA_LENGTH_IN_BITS (8*3)
#define E2E_P05_AR_RELEASE_MAJOR_VERSION_INT 4u
#define E2E_P05_AR_RELEASE_MINOR_VERSION_INT 3u
#define E2E_P05_AR_RELEASE_REVISION_VERSION_INT 0u
#define E2E_P05_SW_MAJOR_VERSION_INT 2
#define E2E_P05_SW_MINOR_VERSION_INT 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_P05_SW_MAJOR_VERSION != E2E_P05_SW_MAJOR_VERSION_INT) || (E2E_P05_SW_MINOR_VERSION != E2E_P05_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between E2E_P05.c and E2E_P05.h"
#endif
#if (E2E_P05_AR_RELEASE_MAJOR_VERSION != E2E_P05_AR_RELEASE_MAJOR_VERSION_INT) || (E2E_P05_AR_RELEASE_MINOR_VERSION != E2E_P05_AR_RELEASE_MINOR_VERSION_INT) || \
(E2E_P05_AR_RELEASE_REVISION_VERSION != E2E_P05_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between E2E_P05.c and E2E_P05.h"
#endif
/* @req SWS_E2E_00047 Definition of error flags for all E2E units */
/* @req SWS_E2E_00404 The step “Verify inputs of the protect function” in E2E_P05Protect()
* shall have the following behavior: */
/* @req SWS_E2E_00437 Checks Min and Max Length */
/* Verifies the input of the function Protect Input for the Profile 05.
*/
static INLINE Std_ReturnType verifyProtectInputsP05(const E2E_P05ConfigType* ConfigPtr, const E2E_P05ProtectStateType* StatePtr, const uint8* DataPtr, uint16 Length) {
Std_ReturnType status;
status = E2E_E_OK;
/* Check for NULL pointers */
if ((ConfigPtr == NULL_PTR) || (StatePtr == NULL_PTR) || (DataPtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
/* Transmitted length shall be 3*8 ≤ Length ≤ 4KB. It must also be equal to the configured length. */
else if ( ((8*Length) < MIN_P05_DATA_LENGTH_IN_BITS) || ((8*Length) > MAX_P05_DATA_LENGTH_IN_BITS) || ((8*Length) != ConfigPtr->DataLength) ) {
status = E2E_E_INPUTERR_WRONG;
}
/* The offset shall be a multiple of 8 and 0 ≤ Offset ≤ DataLength-(3*8). */
else if ( ((ConfigPtr->Offset % 8) != 0) || (ConfigPtr->Offset > ((8*Length)-MIN_P05_DATA_LENGTH_IN_BITS))) {
status = E2E_E_INPUTERR_WRONG;
}
else {
status = E2E_E_OK;
}
return status;
}
/* @req SWS_E2E_00469 The step “Compute offset” in E2E_P05Protect() and E2E_P05Check()
* shall have the following behavior: */
/* Return local variable uint16 Offset, which is in [byte].
*/
static INLINE uint16 computeOffsetP05(const E2E_P05ConfigType* ConfigPtr) {
return (ConfigPtr->Offset/8);
}
/* @req SWS_E2E_00405 The step “Write Counter” in E2E_P05Protect()
* shall have the following behavior: */
/* Writes the Counter value to the right position within the data byte stream.
*/
static INLINE void writeCounterP05(uint8* DataPtr, uint16 offset, const E2E_P05ProtectStateType* StatePtr) {
DataPtr[offset+2] = (StatePtr->Counter & 0xFFu) & 0xFFu;
}
/* @req SWS_E2E_00399 In the E2E Profile 5, the Data ID shall be implicitly transmitted,
* by adding the Data ID after the user data in the CRC calculation. */
/* @req SWS_E2E_00400 E2E Profile 5 shall use the Crc_CalculateCRC16() function of the SWS CRC Library
* for calculating the CRC (Polynomial: 0x1021; Autosar notation). */
/* @req SWS_E2E_00401 In E2E Profile 5, the CRC shall be calculated over the entire E2E header
* (excluding the CRC bytes), including the user data extended at the end with the Data ID. */
/* @req SWS_E2E_00394 Profile 5 shall provide the following control fields as defined in AUTOSAR_SWS_E2ELibrary, 7.6,
* transmitted at runtime together with the protected data: */
/* @req SWS_E2E_00406 The step “Compute CRC” in E2E_P05Protect() and in E2E_P05Check
* shall have the following behavior: */
/* Returns the CRC value for the Protect and Check function of the Profile 05.
*/
static INLINE uint16 computeCRCP05(const uint8* DataPtr, uint16 length, uint16 offset, uint16 dataId) {
uint16 lengthBytes = (length-offset)-2;
uint16 crc;
uint8 dataIdNibble;
if (offset > 0) {
/* compute CRC over bytes that are before CRC */
crc = Crc_CalculateCRC16(&DataPtr[0], offset, 0xFFFFu, TRUE);
/* Compute CRC over bytes that are after CRC (if any) */
crc = Crc_CalculateCRC16(&DataPtr[offset+2], lengthBytes, crc, FALSE);
}
else {
/* Compute CRC over bytes that are after CRC (if any) */
crc = Crc_CalculateCRC16(&DataPtr[offset+2], lengthBytes, 0xFFFFu, TRUE);
}
dataIdNibble = ((dataId) & 0xFFu);
crc = Crc_CalculateCRC16(&dataIdNibble, 1, crc, FALSE);
dataIdNibble = ((dataId>>8) & 0xFFu);
crc = Crc_CalculateCRC16(&dataIdNibble, 1, crc, FALSE);
return crc;
}
/* @req SWS_E2E_00407 The step “Write CRC” in E2E_P05Protect()
* shall have the following behavior: */
/* Writes the CRC value to the right position within the data byte stream.
*/
static INLINE void writeCRCP05(uint8* DataPtr, uint16 offset, uint16 crc) {
DataPtr[offset ] = ((crc & 0x00FFu) ) & 0xFFu;
DataPtr[offset+1] = ((crc & 0xFF00u) >> 8) & 0xFFu;
}
/* @req SWS_E2E_00397 In E2E Profile 5, on the sender side, for the first transmission
* request of a data element the counter shall be initialized with 0 and shall be incremented by 1
* for every subsequent send request. When the counter reaches the maximum value (0xFF),
* then it shall restart with 0 for the next send request. */
/* @req SWS_E2E_00409 The step “Increment Counter” in E2E_P05Protect()
* shall have the following behavior: */
/* Increments the Counter Value on the sender side.
*/
static INLINE void incrementCounterP05(E2E_P05ProtectStateType* StatePtr) {
StatePtr->Counter = (StatePtr->Counter + 1) % (MAX_P05_COUNTER_VALUE + 1);
}
/* @req SWS_E2E_00403 The function E2E_P05Protect() shall have the following overall behavior: */
/* @req SWS_E2E_00446 API for E2E_P05Protect */
/* Protects the array/buffer to be transmitted using the E2E profile 5.
* This includes checksum calculation, handling of counter.
*/
Std_ReturnType E2E_P05Protect(const E2E_P05ConfigType* ConfigPtr, E2E_P05ProtectStateType* StatePtr, uint8* DataPtr, uint16 Length) {
uint16 offset;
uint16 crc;
Std_ReturnType returnValue = verifyProtectInputsP05(ConfigPtr, StatePtr, DataPtr, Length);
if (E2E_E_OK == returnValue) {
offset = computeOffsetP05(ConfigPtr);
writeCounterP05(DataPtr, offset, StatePtr);
crc = computeCRCP05(DataPtr, Length, offset, ConfigPtr->DataID);
writeCRCP05(DataPtr, offset, crc);
incrementCounterP05(StatePtr);
}
return returnValue;
}
/* @req SWS_E2E_00047 Definition of error flags for all E2E units */
/* @req SWS_E2E_00412 The step “Verify inputs of the check function” in E2E_P05Check()
* shall have the following behavior: */
/* Verifies the input of the function Check Input for the Profile 05.
*/
static INLINE Std_ReturnType verifyCheckInputsP05(boolean* NewDataAvailable, const E2E_P05ConfigType* ConfigPtr, const E2E_P05CheckStateType* StatePtr, const uint8* DataPtr, uint16 Length) {
Std_ReturnType status;
status = E2E_E_OK;
*NewDataAvailable = FALSE;
/* Check for NULL pointers */
if ((ConfigPtr == NULL_PTR) || (StatePtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
else if ( !(((DataPtr != NULL_PTR) && (Length != 0)) || ((DataPtr == NULL_PTR) && (Length == 0))) ) {
status = E2E_E_INPUTERR_WRONG;
}
else if (DataPtr == NULL_PTR) {
status = E2E_E_OK;
}
/* Check input parameters values */
/* Received length shall be 3*8 ≤ Length ≤ 4KB. It must also be equal to the configured length. */
else if ( ((8*Length) < MIN_P05_DATA_LENGTH_IN_BITS) || ((8*Length) > MAX_P05_DATA_LENGTH_IN_BITS) || ((8*Length) != ConfigPtr->DataLength) ) {
status = E2E_E_INPUTERR_WRONG;
}
/* The offset shall be a multiple of 8 and 0 ≤ Offset ≤ DataLength-(3*8). */
else if ( ((ConfigPtr->Offset % 8) != 0) || (ConfigPtr->Offset > ((8*Length)-MIN_P05_DATA_LENGTH_IN_BITS))) {
status = E2E_E_INPUTERR_WRONG;
}
else {
*NewDataAvailable = TRUE;
}
return status;
}
/* @req SWS_E2E_00413 The step “Read Counter” in E2E_P05Check()
* shall have the following behavior: */
/* Reads the Counter value from the right position within the data byte stream.
*/
static INLINE uint8 readCounterP05(const uint8* DataPtr, uint16 offset) {
uint8 receivedCounter = 0;
receivedCounter |= (DataPtr[offset+2] & 0xFFu);
return receivedCounter;
}
/* @req SWS_E2E_00414 The step “Read CRC” in E2E_P05Check()
* shall have the following behavior: */
/* Reads the CRC value from the right position within the data byte stream.
*/
static INLINE uint16 readCRCP05(const uint8* DataPtr, uint16 offset) {
uint16 receivedCRC = 0;
receivedCRC |= (((uint16)DataPtr[offset ] ) & 0x00FFu);
receivedCRC |= (((uint16)DataPtr[offset+1] << 8) & 0xFF00u);
return receivedCRC;
}
/* Calculates the delta counter value out of received and last valid counter values.
*/
static INLINE uint8 calculateDeltaCounterP05(uint8 receivedCounter, uint8 lastValidCounter)
{
uint8 status;
if (receivedCounter >= lastValidCounter) {
status = receivedCounter - lastValidCounter;
}
else {
status = (uint8)((uint32)MAX_P05_COUNTER_VALUE + 1 + (uint32)receivedCounter - (uint32)lastValidCounter);
}
return status;
}
/* @req SWS_E2E_00416 The step “Do Checks” in E2E_P05Check() shall have the following behavior: */
/* Do checks to determine the next status value of the receiver.
*/
static INLINE void doChecksP05(E2E_P05CheckStateType* StatePtr, const boolean* NewDataAvailable, const E2E_P05ConfigType* ConfigPtr, uint16 receivedCRC, uint16 computedCRC, uint8 receivedCounter) {
uint8 deltaCounter;
if (*NewDataAvailable == FALSE) {
StatePtr->Status = E2E_P05STATUS_NONEWDATA;
}
else if (receivedCRC != computedCRC) {
StatePtr->Status = E2E_P05STATUS_ERROR;
}
else {
deltaCounter = calculateDeltaCounterP05(receivedCounter, StatePtr->Counter);
if (deltaCounter > ConfigPtr->MaxDeltaCounter) {
StatePtr->Status = E2E_P05STATUS_WRONGSEQUENCE;
}
else if (deltaCounter == 0) {
StatePtr->Status = E2E_P05STATUS_REPEATED;
}
else if (deltaCounter == 1) {
StatePtr->Status = E2E_P05STATUS_OK;
}
else {
StatePtr->Status = E2E_P05STATUS_OKSOMELOST;
}
StatePtr->Counter = receivedCounter;
}
}
/* @req SWS_E2E_00411 The function E2E_P05Check() shall have the following overall behavior: */
/* @req SWS_E2E_00440 Definition of E2E_P05CheckStatusType */
/* @req SWS_E2E_00449 API for E2E_P05Check */
/* Checks the Data received using the E2E profile 5. This includes CRC calculation, handling of Counter.
* The function checks only one single data in one cycle, it does not determine/compute the accumulated
* state of the communication link.
*/
Std_ReturnType E2E_P05Check(const E2E_P05ConfigType* ConfigPtr, E2E_P05CheckStateType* StatePtr, const uint8* DataPtr, uint16 Length) {
boolean NewDataAvailable;
uint16 offset;
uint8 receivedCounter = 0;
uint16 receivedCRC = 0;
uint16 computedCRC = 0;
Std_ReturnType returnValue = verifyCheckInputsP05(&NewDataAvailable, ConfigPtr, StatePtr, DataPtr, Length);
if (E2E_E_OK == returnValue) {
if (NewDataAvailable == TRUE) {
offset = computeOffsetP05(ConfigPtr);
receivedCounter = readCounterP05(DataPtr, offset);
receivedCRC = readCRCP05(DataPtr, offset);
computedCRC = computeCRCP05(DataPtr, Length, offset, ConfigPtr->DataID);
}
doChecksP05(StatePtr, &NewDataAvailable, ConfigPtr, receivedCRC, computedCRC, receivedCounter);
}
return returnValue;
}
/* @req SWS_E2E_00438 Definition of E2E_P05ProtectStateType */
/* @req SWS_E2E_00447 API for E2E_P05ProtectInit */
/* @req SWS_E2E_00448 In case State is NULL, E2E_P05ProtectInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall intialize the state structure, setting Counter to 0. */
/* Initializes the protection state.
*/
Std_ReturnType E2E_P05ProtectInit(E2E_P05ProtectStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
}
else {
StatePtr->Counter = 0;
}
return status;
}
/* @req SWS_E2E_00439 Definition of the State of the reception on one single Data protected with E2E Profile 5. */
/* @req SWS_E2E_00450 API for E2E_P05CheckInit */
/* @req SWS_E2E_00451 In case State is NULL, E2E_P05CheckInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall initialize the state structure, setting:
* 1. Counter to 0xFF
* 2. Status to E2E_P05STATUS_ERROR.
*/
/* Initializes the check state.
*/
Std_ReturnType E2E_P05CheckInit(E2E_P05CheckStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
}
else {
StatePtr->Status = E2E_P05STATUS_ERROR;
StatePtr->Counter = 0xFF;
}
return status;
}
/* @req SWS_E2E_00452 API for E2E_P05MapStatusToSM */
/* @req SWS_E2E_00453 If CheckReturn = E2E_E_OK, then the function E2E_P05MapStatusToSM shall
* return the values depending on the value of Status: */
/* @req SWS_E2E_00454 If CheckReturn != E2E_E_OK, then the function E2E_P05MapStatusToSM() shall
* return E2E_P_ERROR (regardless of value of Status). */
/* The function maps the check status of Profile 5 to a generic check status,
* which can be used by E2E state machine check function. The E2E Profile 5 delivers a more fine-granular status,
* but this is not relevant for the E2E state machine.
*/
E2E_PCheckStatusType E2E_P05MapStatusToSM(Std_ReturnType CheckReturn, E2E_P05CheckStatusType Status) {
E2E_PCheckStatusType retValue = E2E_P_ERROR;
if (CheckReturn == E2E_E_OK) {
switch( Status ) {
case E2E_P05STATUS_OK:
case E2E_P05STATUS_OKSOMELOST:
retValue = E2E_P_OK;
break;
case E2E_P05STATUS_REPEATED:
retValue = E2E_P_REPEATED;
break;
case E2E_P05STATUS_NONEWDATA:
retValue = E2E_P_NONEWDATA;
break;
case E2E_P05STATUS_WRONGSEQUENCE:
retValue = E2E_P_WRONGSEQUENCE;
break;
/* @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming. If this happens the state will be restored to E2E_P_ERROR */
__CODE_COVERAGE_IGNORE__
default:
retValue = E2E_P_ERROR;
break;
}
}
return retValue;
}
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/src/E2E_P05.c
|
C
|
unknown
| 17,684
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00216
* The E2E Library shall not call BSW modules for error reporting (in particular DEM and DET), nor for any other purpose.
* The E2E Library shall not call RTE. */
/* @req SWS_E2E_00215 Files E2E_P06.c and E2E_P06.h shall contain implementation parts specific of each profile. */
/* @req SWS_E2E_00049 The E2E library shall not contain library-internal mechanisms for error detection to be traced as development errors. */
/* @req SWS_E2E_00221 Each E2E Profile shall use a subset of the data protection mechanisms defined in AUTOSAR_SWS_E2ELibrary.pdf, 7.2. */
/* @req SWS_E2E_00011 The E2E Library shall report errors detected by library-internal mechanisms
* to callers of E2E functions through return value.
*/
/* @req SWS_E2E_00012 The internal library mechanisms shall detect and report errors
* shall be implemented according to the pre-defined E2E Profiles specified in sections 7.3 and 7.4.
*/
#include "E2E_P06.h"
/* @req SWS_E2E_00443 Each time E2E_P06Protect() is called, it increments the counter up to 0xFF. */
#define MAX_P06_COUNTER_VALUE (255)
/* @req SWS_E2E_00441 Maximal length of Data, in bits. E2E checks that DataLength is ≤ MaxDataLength.
* The value shall be = 4096*8 (4kB). MaxDataLength shall be ≥ MinDataLength. The value shall be ≥ 5*8.
*/
#define MAX_P06_DATA_LENGTH_IN_BITS (8*4096)
#define MIN_P06_DATA_LENGTH_IN_BITS (8*5)
#define E2E_P06_AR_RELEASE_MAJOR_VERSION_INT 4u
#define E2E_P06_AR_RELEASE_MINOR_VERSION_INT 3u
#define E2E_P06_AR_RELEASE_REVISION_VERSION_INT 0u
#define E2E_P06_SW_MAJOR_VERSION_INT 2
#define E2E_P06_SW_MINOR_VERSION_INT 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_P06_SW_MAJOR_VERSION != E2E_P06_SW_MAJOR_VERSION_INT) || (E2E_P06_SW_MINOR_VERSION != E2E_P06_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between E2E_P06.c and E2E_P06.h"
#endif
#if (E2E_P06_AR_RELEASE_MAJOR_VERSION != E2E_P06_AR_RELEASE_MAJOR_VERSION_INT) || (E2E_P06_AR_RELEASE_MINOR_VERSION != E2E_P06_AR_RELEASE_MINOR_VERSION_INT) || \
(E2E_P06_AR_RELEASE_REVISION_VERSION != E2E_P06_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between E2E_P06.c and E2E_P06.h"
#endif
/* @req SWS_E2E_00047 Definition of error flags for all E2E units */
/* @req SWS_E2E_00424 The step “Verify inputs of the protect function” in E2E_P06Protect() shall have the following behavior: */
/* @req SWS_E2E_00441 Checks Min and Max Length */
/* Verifies the input of the function Protect Input for the Profile 06.
*/
static INLINE Std_ReturnType verifyProtectInputsP06(const E2E_P06ConfigType* ConfigPtr, const E2E_P06ProtectStateType* StatePtr, const uint8* DataPtr, uint16 Length) {
Std_ReturnType status;
status = E2E_E_OK;
/* Check for NULL pointers */
if ((ConfigPtr == NULL_PTR) || (StatePtr == NULL_PTR) || (DataPtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
/* Check input parameters values */
else if ((ConfigPtr->MinDataLength < MIN_P06_DATA_LENGTH_IN_BITS) || (ConfigPtr->MaxDataLength < MIN_P06_DATA_LENGTH_IN_BITS) ||
(ConfigPtr->MinDataLength > MAX_P06_DATA_LENGTH_IN_BITS) || (ConfigPtr->MaxDataLength > MAX_P06_DATA_LENGTH_IN_BITS) ||
(ConfigPtr->MinDataLength > ConfigPtr->MaxDataLength)) {
status = E2E_E_INPUTERR_WRONG;
}
/* Transmitted length shall be MinDataLength ≤ Length ≤ MaxDataLength */
else if ( ((8*Length) < ConfigPtr->MinDataLength) || ((8*Length) > ConfigPtr->MaxDataLength) ) {
status = E2E_E_INPUTERR_WRONG;
}
/* The offset shall be a multiple of 8 and 0 ≤ Offset ≤ (Max)DataLength-(5*8). Compared to transmitted length as E2E header has to fit data */
else if ( ((ConfigPtr->Offset % 8) != 0) || (ConfigPtr->Offset > ((8*Length)-MIN_P06_DATA_LENGTH_IN_BITS))) {
status = E2E_E_INPUTERR_WRONG;
}
else {
status = E2E_E_OK;
}
return status;
}
/* Changes the Bit Endianness of a byte value
*/
static INLINE uint8 changeBitEndiannessP06(uint8 value)
{
uint8 result = 0;
result |= (value & 0x01u) << 7;
result |= (value & 0x02u) << 5;
result |= (value & 0x04u) << 3;
result |= (value & 0x08u) << 1;
result |= (value & 0x10u) >> 1;
result |= (value & 0x20u) >> 3;
result |= (value & 0x40u) >> 5;
result |= (value & 0x80u) >> 7;
return result;
}
/* @req SWS_E2E_00470 The step “Compute offset” in E2E_P06Protect() and
* E2E_P06Check() shall have the following behavior: */
/* Return local variable uint16 Offset, which is in [byte].
*/
static INLINE uint16 computeOffsetP06(const E2E_P06ConfigType* ConfigPtr) {
return (ConfigPtr->Offset/8);
}
/* @req SWS_E2E_00425 The step “Write Length” in E2E_P06Protect()
* shall have the following behavior: */
/* Writes the Length value to the right position within the data byte stream.
*/
static INLINE void writeLengthP06(uint8* DataPtr, uint16 offset, uint16 Length) {
DataPtr[offset+2] = changeBitEndiannessP06(((Length & 0xFF00u) >> 8) & 0xFFu);
DataPtr[offset+3] = changeBitEndiannessP06( (Length & 0x00FFu) & 0xFFu);
}
/* @req SWS_E2E_00426 The step “Write Counter” in E2E_P06Protect()
* shall have the following behavior: */
/* Writes the Counter value to the right position within the data byte stream.
*/
static INLINE void writeCounterP06(uint8* DataPtr, uint16 offset, const E2E_P06ProtectStateType* StatePtr) {
DataPtr[offset+4] = changeBitEndiannessP06( (StatePtr->Counter & 0xFFu) & 0xFFu);
}
/* @req SWS_E2E_00427 The step “Compute CRC” in E2E_P06Protect() and E2E_P06Check()
* shall have the following behavior: */
/* @req SWS_E2E_00419 In the E2E Profile 6, the Data ID shall be implicitly transmitted,
* by adding the Data ID after the user data in the CRC calculation. */
/* @req SWS_E2E_00420 E2E Profile 6 shall use the Crc_CalculateCRC16() function of the
* SWS CRC Library for calculating the CRC (Polynomial: 0x1021; Autosar notation). */
/* @req SWS_E2E_00421 In E2E Profile 6, the CRC shall be calculated over the entire E2E header
* (excluding the CRC bytes), including the user data extended with the Data ID. */
/* @req SWS_E2E_00479 Profile 6 shall provide the control fields as defined in AUTOSAR_SWS_E2ELibrary, 7.7,
* transmitted at runtime together with the protected data*/
/* Returns the CRC value for the Protect and Check function of the Profile 06.
*/
static INLINE uint16 computeCRCP06(const uint8* DataPtr, uint16 offset, uint16 dataId, uint16 Length) {
uint16 lengthBytes = (Length-offset)-2;
uint16 crc;
uint8 dataIdNibble;
if (offset > 0) {
/* compute CRC over bytes that are before CRC */
crc = Crc_CalculateCRC16(&DataPtr[0], offset, 0xFFFFu, TRUE);
/* Compute CRC over bytes that are after CRC (if any) */
crc = Crc_CalculateCRC16(&DataPtr[offset+2], lengthBytes, crc, FALSE);
}
else {
/* Compute CRC over bytes that are after CRC (if any) */
crc = Crc_CalculateCRC16(&DataPtr[offset+2], lengthBytes, 0xFFFFu, TRUE);
}
dataIdNibble = ((dataId>>8) & 0xFFu);
crc = Crc_CalculateCRC16(&dataIdNibble, 1, crc, FALSE);
dataIdNibble = ((dataId) & 0xFFu);
crc = Crc_CalculateCRC16(&dataIdNibble, 1, crc, FALSE);
return crc;
}
/* @req SWS_E2E_00428 The step “Write CRC” in E2E_P06Protect()
* shall have the following behavior: */
/* Writes the CRC value to the right position within the data byte stream.
*/
static INLINE void writeCRCP06(uint8* DataPtr, uint16 offset, uint16 crc) {
DataPtr[offset ] = changeBitEndiannessP06(((crc & 0xFF00u) >> 8) & 0xFFu);
DataPtr[offset+1] = changeBitEndiannessP06(((crc & 0x00FFu) ) & 0xFFu);
}
/* @req SWS_E2E_00417 In E2E Profile 6, on the sender side, for the first transmission request
* of a data element the counter shall be initialized with 0 and shall be incremented by 1
* for every subsequent send request. When the counter reaches the maximum value (0xFF),
* then it shall restart with 0 for the next send request.
*/
/* @req SWS_E2E_00429 The step “Increment Counter” in E2E_P06Protect()
* shall have the following behavior: */
/* Increments the Counter Value on the sender side.
*/
static INLINE void incrementCounterP06(E2E_P06ProtectStateType* StatePtr) {
StatePtr->Counter = (StatePtr->Counter + 1) % (MAX_P06_COUNTER_VALUE + 1);
}
/* @req SWS_E2E_00423 The function E2E_P06Protect() shall have the following overall behavior: */
/* @req SWS_E2E_00393 API for E2E_P06Protect */
/* Protects the array/buffer to be transmitted using the E2E profile 6.
* This includes checksum calculation, handling of counter.
*/
Std_ReturnType E2E_P06Protect(const E2E_P06ConfigType* ConfigPtr, E2E_P06ProtectStateType* StatePtr, uint8* DataPtr, uint16 Length) {
uint16 offset;
uint16 crc;
Std_ReturnType returnValue = verifyProtectInputsP06(ConfigPtr, StatePtr, DataPtr, Length);
if (E2E_E_OK == returnValue) {
offset = computeOffsetP06(ConfigPtr);
writeLengthP06(DataPtr, offset, Length);
writeCounterP06(DataPtr, offset, StatePtr);
crc = computeCRCP06(DataPtr, offset, ConfigPtr->DataID, Length);
writeCRCP06(DataPtr, offset, crc);
incrementCounterP06(StatePtr);
}
return returnValue;
}
/* @req SWS_E2E_00047 Definition of error flags for all E2E units */
/* @req SWS_E2E_00431 The step “Verify inputs of the check function” in E2E_P06Check()
* shall have the following behavior: */
/* Verifies the input of the function Check Input for the Profile 06.
*/
static INLINE Std_ReturnType verifyCheckInputsP06(boolean* NewDataAvailable, const E2E_P06ConfigType* ConfigPtr, const E2E_P06CheckStateType* StatePtr, const uint8* DataPtr, uint16 Length) {
Std_ReturnType status;
status = E2E_E_OK;
*NewDataAvailable = FALSE;
/* Check for NULL pointers */
if ((ConfigPtr == NULL_PTR) || (StatePtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
/* Check input parameters values */
else if ((ConfigPtr->MinDataLength < MIN_P06_DATA_LENGTH_IN_BITS) || (ConfigPtr->MaxDataLength < MIN_P06_DATA_LENGTH_IN_BITS) ||
(ConfigPtr->MinDataLength > MAX_P06_DATA_LENGTH_IN_BITS) || (ConfigPtr->MaxDataLength > MAX_P06_DATA_LENGTH_IN_BITS) ||
(ConfigPtr->MinDataLength > ConfigPtr->MaxDataLength)) {
status = E2E_E_INPUTERR_WRONG;
}
else if ( !(((DataPtr != NULL_PTR) && (Length != 0)) || ((DataPtr == NULL_PTR) && (Length == 0))) ) {
status = E2E_E_INPUTERR_WRONG;
}
else if (DataPtr == NULL_PTR) {
status = E2E_E_OK;
}
/* Received length shall be MinDataLength ≤ Length ≤ MaxDataLength */
else if ( ((8*Length) < ConfigPtr->MinDataLength) || ((8*Length) > ConfigPtr->MaxDataLength) ) {
status = E2E_E_INPUTERR_WRONG;
}
/* The offset shall be a multiple of 8 and 0 ≤ Offset ≤ (Max)DataLength-(5*8). Compared to received length as E2E header has to fit data */
else if ( ((ConfigPtr->Offset % 8) != 0) || (ConfigPtr->Offset > ((8*Length)-MIN_P06_DATA_LENGTH_IN_BITS))) {
status = E2E_E_INPUTERR_WRONG;
}
else {
*NewDataAvailable = TRUE;
}
return status;
}
/* @req SWS_E2E_00432 The step “Read Length” in E2E_P06Check()
* shall have the following behavior: */
/* Reads the Length value from the right position within the data byte stream.
*/
static INLINE uint16 readLengthP06(const uint8* DataPtr, uint16 offset) {
uint16 receivedLength = 0;
receivedLength |= (((uint16)changeBitEndiannessP06(DataPtr[offset+2]) << 8) & 0xFF00u);
receivedLength |= (((uint16)changeBitEndiannessP06(DataPtr[offset+3]) ) & 0x00FFu);
return receivedLength;
}
/* @req SWS_E2E_00433 The step “Read Counter” in E2E_P06Check()
* shall have the following behavior: */
/* Reads the Counter value from the right position within the data byte stream.
*/
static INLINE uint8 readCounterP06(const uint8* DataPtr, uint16 offset) {
uint8 receivedCounter = 0;
receivedCounter |= ((changeBitEndiannessP06(DataPtr[offset+4]) ) & 0xFFu);
return receivedCounter;
}
/* @req SWS_E2E_00434 The step “Read CRC” in E2E_P06Check()
* shall have the following behavior: */
/* Reads the CRC value from the right position within the data byte stream.
*/
static INLINE uint16 readCRCP06(const uint8* DataPtr, uint16 offset) {
uint16 receivedCRC = 0;
receivedCRC |= (((uint16)changeBitEndiannessP06(DataPtr[offset ]) << 8) & 0xFF00u);
receivedCRC |= (((uint16)changeBitEndiannessP06(DataPtr[offset+1]) ) & 0x00FFu);
return receivedCRC;
}
/* Calculates the delta counter value out of received and last valid counter values.
*/
static INLINE uint8 calculateDeltaCounterP06(uint8 receivedCounter, uint8 lastValidCounter)
{
uint8 status;
if (receivedCounter >= lastValidCounter) {
status = receivedCounter - lastValidCounter;
}
else {
status = (uint8)((uint32)MAX_P06_COUNTER_VALUE + 1 + (uint32)receivedCounter - (uint32)lastValidCounter);
}
return status;
}
/* @req SWS_E2E_00436 The step “Do Checks” in E2E_P06Check() shall have the following behavior: */
/* Do checks to determine the next status value of the receiver.
*/
static INLINE void doChecksP06(E2E_P06CheckStateType* StatePtr, const boolean* NewDataAvailable, const E2E_P06ConfigType* ConfigPtr, uint16 receivedCRC, uint16 computedCRC, uint16 receivedLength, uint16 Length, uint8 receivedCounter) {
uint8 deltaCounter;
if (*NewDataAvailable == FALSE) {
StatePtr->Status = E2E_P06STATUS_NONEWDATA;
}
else if ( (receivedCRC != computedCRC) || (receivedLength != Length)) {
StatePtr->Status = E2E_P06STATUS_ERROR;
}
else {
deltaCounter = calculateDeltaCounterP06(receivedCounter, StatePtr->Counter);
if (deltaCounter > ConfigPtr->MaxDeltaCounter) {
StatePtr->Status = E2E_P06STATUS_WRONGSEQUENCE;
}
else if (deltaCounter == 0) {
StatePtr->Status = E2E_P06STATUS_REPEATED;
}
else if (deltaCounter == 1) {
StatePtr->Status = E2E_P06STATUS_OK;
}
else {
StatePtr->Status = E2E_P06STATUS_OKSOMELOST;
}
StatePtr->Counter = receivedCounter;
}
}
/* @req SWS_E2E_00430 The function E2E_P06Check()
* shall have the following overall behavior: */
/* @req SWS_E2E_00445 Definition of E2E_P06CheckStatusType */
/* @req SWS_E2E_00457 API for E2E_P06Check */
/* Checks the Data received using the E2E profile 6. This includes CRC calculation, handling of Counter.
* The function checks only one single data in one cycle,
* it does not determine/compute the accumulated state of the communication link.
*/
Std_ReturnType E2E_P06Check(const E2E_P06ConfigType* ConfigPtr, E2E_P06CheckStateType* StatePtr, const uint8* DataPtr, uint16 Length) {
boolean NewDataAvailable;
uint16 offset;
uint16 receivedLength = 0;
uint8 receivedCounter = 0;
uint16 receivedCRC = 0;
uint16 computedCRC = 0;
Std_ReturnType returnValue = verifyCheckInputsP06(&NewDataAvailable, ConfigPtr, StatePtr, DataPtr, Length);
if (E2E_E_OK == returnValue) {
if (NewDataAvailable == TRUE) {
offset = computeOffsetP06(ConfigPtr);
receivedLength = readLengthP06(DataPtr, offset);
receivedCounter = readCounterP06(DataPtr, offset);
receivedCRC = readCRCP06(DataPtr, offset);
computedCRC = computeCRCP06(DataPtr, offset, ConfigPtr->DataID, Length);
}
doChecksP06(StatePtr, &NewDataAvailable, ConfigPtr, receivedCRC, computedCRC, receivedLength, Length, receivedCounter);
}
return returnValue;
}
/* @req SWS_E2E_00443 Definition of E2E_P06ProtectStateType */
/* @req SWS_E2E_00455 API for E2E_P06ProtectInit */
/* @req SWS_E2E_00456 In case State is NULL, E2E_P06ProtectInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall intialize the state structure, setting Counter to 0. */
/* Initializes the protection state.
*/
Std_ReturnType E2E_P06ProtectInit(E2E_P06ProtectStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
}
else {
StatePtr->Counter = 0;
}
return status;
}
/* @req SWS_E2E_00444 Definition of the State of the reception on one single Data protected with E2E Profile 6. */
/* @req SWS_E2E_00458 API for E2E_P06CheckInit */
/* @req SWS_E2E_00459 In case State is NULL, E2E_P06CheckInit shall return immediately with E2E_E_INPUTERR_NULL.
* Otherwise, it shall initialize the state structure, setting:
* 1. Counter to 0xFF
* 2. Status to E2E_P06STATUS_ERROR.
*/
/* Initializes the check state.
*/
Std_ReturnType E2E_P06CheckInit(E2E_P06CheckStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if (StatePtr == NULL_PTR) {
status = E2E_E_INPUTERR_NULL;
}
else {
StatePtr->Status = E2E_P06STATUS_ERROR;
StatePtr->Counter = 0xFF;
}
return status;
}
/* @req SWS_E2E_00460 API for E2E_P06MapStatusToSM */
/* @req SWS_E2E_00461 If CheckReturn = E2E_E_OK, then the function E2E_P06MapStatusToSM shall
* return the values depending on the value of Status: */
/* @req SWS_E2E_00462 If CheckReturn != E2E_E_OK, then the function E2E_P06MapStatusToSM() shall
* return E2E_P_ERROR (regardless of value of Status). */
/* The function maps the check status of Profile 6 to a generic check status,
* which can be used by E2E state machine check function. The E2E Profile 6 delivers a more fine-granular status,
* but this is not relevant for the E2E state machine.
*/
E2E_PCheckStatusType E2E_P06MapStatusToSM(Std_ReturnType CheckReturn, E2E_P06CheckStatusType Status) {
E2E_PCheckStatusType retValue = E2E_P_ERROR;
if (CheckReturn == E2E_E_OK) {
switch( Status ) {
case E2E_P06STATUS_OK:
case E2E_P06STATUS_OKSOMELOST:
retValue = E2E_P_OK;
break;
case E2E_P06STATUS_REPEATED:
retValue = E2E_P_REPEATED;
break;
case E2E_P06STATUS_NONEWDATA:
retValue = E2E_P_NONEWDATA;
break;
case E2E_P06STATUS_WRONGSEQUENCE:
retValue = E2E_P_WRONGSEQUENCE;
break;
/* @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming. If this happens the state will be restored to E2E_P_ERROR */
__CODE_COVERAGE_IGNORE__
default:
retValue = E2E_P_ERROR;
break;
}
}
return retValue;
}
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/src/E2E_P06.c
|
C
|
unknown
| 20,418
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* @req SWS_E2E_00115 E2E library files (i.e. E2E_*.*) shall not include any RTE files */
/* @req SWS_E2E_00216
* The E2E Library shall not call BSW modules for error reporting (in particular DEM and DET), nor for any other purpose.
* The E2E Library shall not call RTE. */
/* @req SWS_E2E_00049 The E2E library shall not contain library-internal mechanisms for error detection to be traced as development errors. */
#include "E2E_SM.h"
#define E2E_SM_AR_RELEASE_MAJOR_VERSION_INT 4u
#define E2E_SM_AR_RELEASE_MINOR_VERSION_INT 3u
#define E2E_SM_AR_RELEASE_REVISION_VERSION_INT 0u
#define E2E_SM_SW_MAJOR_VERSION_INT 2
#define E2E_SM_SW_MINOR_VERSION_INT 0
/* @req SWS_E2E_00327
* The implementer of the E2E Library shall avoid the integration of incompatible files. Minimum implementation is the version check of the header files.
*/
#if (E2E_SM_SW_MAJOR_VERSION != E2E_SM_SW_MAJOR_VERSION_INT) || (E2E_SM_SW_MINOR_VERSION != E2E_SM_SW_MINOR_VERSION_INT)
#error "SW Version mismatch between E2E_SM.c and E2E_SM.h"
#endif
#if (E2E_SM_AR_RELEASE_MAJOR_VERSION != E2E_SM_AR_RELEASE_MAJOR_VERSION_INT) || (E2E_SM_AR_RELEASE_MINOR_VERSION != E2E_SM_AR_RELEASE_MINOR_VERSION_INT) || \
(E2E_SM_AR_RELEASE_REVISION_VERSION != E2E_SM_AR_RELEASE_REVISION_VERSION_INT)
#error "AR Version mismatch between E2E_SM.c and E2E_SM.h"
#endif
/* @req SWS_E2E_00467 The step E2E_SMClearStatus(ProfileStatus, State) in E2E_SMCheck()
* shall have the following behavior: */
/* Clear all in the observed window.
*/
static INLINE void E2E_SMClearStatus(E2E_SMCheckStateType* StatePtr, uint8 windowSize) {
uint8 i;
for (i=0; i<windowSize; i++) {
StatePtr->ProfileStatusWindow[i] = (uint8)E2E_P_NOTAVAILABLE;
}
StatePtr->OkCount = 0;
StatePtr->ErrorCount = 0;
StatePtr->WindowTopIndex = 0;
}
/* @req SWS_E2E_00466 The step E2E_SMAddStatus(ProfileStatus, State) in E2E_SMCheck()
* shall have the following behavior: */
/* Adds the new status to the observed window
*/
static INLINE void E2E_SMAddStatus(E2E_PCheckStatusType ProfileStatus, E2E_SMCheckStateType* StatePtr, uint8 windowSize) {
uint8 i;
uint8 count;
StatePtr->ProfileStatusWindow[StatePtr->WindowTopIndex] = (uint8)ProfileStatus;
count=0;
for (i=0; i<windowSize; i++) {
if (StatePtr->ProfileStatusWindow[i] == (uint8)E2E_P_OK) {
count++;
}
}
StatePtr->OkCount = count;
count=0;
for (i=0; i<windowSize; i++) {
if (StatePtr->ProfileStatusWindow[i] == (uint8)E2E_P_ERROR) {
count++;
}
}
StatePtr->ErrorCount = count;
if (StatePtr->WindowTopIndex >= (windowSize-1)) {
StatePtr->WindowTopIndex = 0;
}
else {
StatePtr->WindowTopIndex++;
}
}
/* Checks and Set status for state NODATA
*/
static INLINE void E2E_SMCheck_NODATA(E2E_PCheckStatusType ProfileStatus, E2E_SMCheckStateType* StatePtr) {
if ((ProfileStatus != E2E_P_ERROR) && (ProfileStatus != E2E_P_NONEWDATA)) {
StatePtr->SMState = E2E_SM_INIT;
}
else {
StatePtr->SMState = E2E_SM_NODATA;
}
}
/* Checks and Set status for state INIT
*/
static INLINE void E2E_SMCheck_INIT(const E2E_SMConfigType* ConfigPtr, E2E_SMCheckStateType* StatePtr) {
if ((StatePtr->ErrorCount <= ConfigPtr->MaxErrorStateInit) && (StatePtr->OkCount >= ConfigPtr->MinOkStateInit)) {
StatePtr->SMState = E2E_SM_VALID;
}
else if (StatePtr->ErrorCount > ConfigPtr->MaxErrorStateInit) {
StatePtr->SMState = E2E_SM_INVALID;
}
else {
StatePtr->SMState = E2E_SM_INIT;
}
}
/* Checks and Set status for state VALID
*/
static INLINE void E2E_SMCheck_VALID(const E2E_SMConfigType* ConfigPtr, E2E_SMCheckStateType* StatePtr) {
if ((StatePtr->ErrorCount <= ConfigPtr->MaxErrorStateValid) && (StatePtr->OkCount >= ConfigPtr->MinOkStateValid)) {
StatePtr->SMState = E2E_SM_VALID;
}
else {
StatePtr->SMState = E2E_SM_INVALID;
}
}
/* Checks and Set status for state INVALID
*/
static INLINE void E2E_SMCheck_INVALID( const E2E_SMConfigType* ConfigPtr, E2E_SMCheckStateType* StatePtr ) {
if ((StatePtr->ErrorCount <= ConfigPtr->MaxErrorStateInvalid) && (StatePtr->OkCount >= ConfigPtr->MinOkStateInvalid)) {
StatePtr->SMState = E2E_SM_VALID;
}
else {
StatePtr->SMState = E2E_SM_INVALID;
}
}
/* @req SWS_E2E_00340 API for E2E_SMCheck */
/* @req SWS_E2E_00345 The E2E State machine shall have the following behavior with respect to the function E2E_SMCheck(): */
/* @req SWS_E2E_00354 The E2E state machine shall be implemented by the functions E2E_SMCheck() and E2E_SMCheckInit() */
/* @req SWS_E2E_00371 In case State is NULL or Config is NULL,
* the function E2E_SMCheck shall return immediately with E2E_E_INPUTERR_NULL. */
/* Checks the communication channel. It determines if the data can be used for safety-related application,
* based on history of checks performed by a corresponding E2E_P0XCheck() function.
*/
Std_ReturnType E2E_SMCheck(E2E_PCheckStatusType ProfileStatus, const E2E_SMConfigType* ConfigPtr, E2E_SMCheckStateType* StatePtr) {
Std_ReturnType status;
status = E2E_E_OK;
if ((StatePtr == NULL_PTR) || (ConfigPtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
/* Size of the monitoring window for the state machine can also be 0, check here consistency */
else if ((StatePtr->ProfileStatusWindow == NULL_PTR) && (ConfigPtr->WindowSize>0)) {
status = E2E_E_INPUTERR_WRONG;
}
else if (StatePtr->SMState == E2E_SM_DEINIT) {
status = E2E_E_WRONGSTATE;
}
else {
switch (StatePtr->SMState) {
case E2E_SM_NODATA:
E2E_SMCheck_NODATA(ProfileStatus, StatePtr);
break;
case E2E_SM_INIT:
E2E_SMAddStatus(ProfileStatus, StatePtr, ConfigPtr->WindowSize);
E2E_SMCheck_INIT(ConfigPtr, StatePtr );
break;
case E2E_SM_VALID:
E2E_SMAddStatus(ProfileStatus, StatePtr, ConfigPtr->WindowSize);
E2E_SMCheck_VALID(ConfigPtr, StatePtr);
break;
case E2E_SM_INVALID:
E2E_SMAddStatus(ProfileStatus, StatePtr, ConfigPtr->WindowSize);
E2E_SMCheck_INVALID(ConfigPtr, StatePtr);
break;
/* @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming. If this happens the state will be restored to E2E_SM_DEINIT */
__CODE_COVERAGE_IGNORE__
default:
/*Do nothing*/
break;
}
}
return status;
}
/* @req SWS_E2E_00353 API for E2E_SMCheckInit */
/* @req SWS_E2E_00354 The E2E state machine shall be implemented by the functions E2E_SMCheck() and E2E_SMCheckInit() */
/* @req SWS_E2E_00370 In case State is NULL or Config is NULL,
* the function E2E_SMCheckInit shall return immediately with E2E_E_INPUTERR_NULL. */
/* @req SWS_E2E_00375 The E2E State machine shall have the following behavior with
* respect to the function E2E_SMCheckInit(): */
/* Initializes the state machine.
*/
Std_ReturnType E2E_SMCheckInit(E2E_SMCheckStateType* StatePtr, const E2E_SMConfigType* ConfigPtr) {
Std_ReturnType status;
status = E2E_E_OK;
if ((StatePtr == NULL_PTR) || (ConfigPtr == NULL_PTR)) {
status = E2E_E_INPUTERR_NULL;
}
/* Size of the monitoring window for the state machine can also be 0, check here consistency */
else if ((StatePtr->ProfileStatusWindow == NULL_PTR) && (ConfigPtr->WindowSize>0)) {
status = E2E_E_INPUTERR_WRONG;
}
else {
E2E_SMClearStatus(StatePtr, ConfigPtr->WindowSize);
StatePtr->SMState=E2E_SM_NODATA;
}
return status;
}
|
2301_81045437/classic-platform
|
safety_security/SafeLib/E2E/src/E2E_SM.c
|
C
|
unknown
| 8,890
|
#WdgIf
obj-$(USE_WDGIF) += WdgIf.o
obj-$(USE_WDGIF) += WdgIf_Cfg.o
inc-y += $(ROOTDIR)/safety_security/WdgIf/inc
vpath-y += $(ROOTDIR)/safety_security/WdgIf/src
|
2301_81045437/classic-platform
|
safety_security/WdgIf/WdgIf.mod.mk
|
Makefile
|
unknown
| 166
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/* globally fullfilled reqs */
/** @req SWS_WdgIf_00003 */ /*The Watchdog Interface shall not add functionality to the watchdog drivers*/
/** @req SWS_WdgIf_00028 */ /*If more than one watchdog driver is configured and the default error detection is enabled for this module, the parameter DeviceIndex shall be checked for being an existing device within the module’s services*/
/** @req SWS_WdgIf_00017 */ /*The Watchdog Interface shall map the APIs specified in this chapter to the API of the underlying drivers*/
/** @req ARC_SWS_WdgIf_00002 */ /*The file structure. It is inspired by the AUTOSAR file structure but do have some deviations*/
/** @req SWS_WdgIf_00001 */ /* The Watchdog Interface shall comprise a header file WdgIf.h declaring the API of the Watchdog Interface*/
#ifndef WDGIF_H_
#define WDGIF_H_
#define WDGIF_AR_RELEASE_MAJOR_VERSION 4u
#define WDGIF_AR_RELEASE_MINOR_VERSION 3u
#define WDGIF_AR_RELEASE_REVISION_VERSION 0u
/* @req SWS_BSW_00059 Published information */
#define WDGIF_VENDOR_ID 60u
#define WDGIF_MODULE_ID 43u
#define WDGIF_AR_MAJOR_VERSION WDGIF_AR_RELEASE_MAJOR_VERSION
#define WDGIF_AR_MINOR_VERSION WDGIF_AR_RELEASE_MINOR_VERSION
#define WDGIF_AR_PATCH_VERSION WDGIF_AR_RELEASE_REVISION_VERSION
#define WDGIF_SW_MAJOR_VERSION 2u
#define WDGIF_SW_MINOR_VERSION 0u
#define WDGIF_SW_PATCH_VERSION 0u
/** @req SWS_WdgIf_00049 */
/** @req SWS_WdgIf_00050 */
#include "WdgIf_Cfg.h"
#include "Wdg.h"
#define WDGIF_SETMODE_ID 0x01u
#define WDGIF_SETTRIGGERCONDITION_ID 0x02u
#define WDGIF_GETVERSIONINFO_ID 0x03u
/** @req SWS_WdgIf_00006 */
/** @req SWS_WdgIf_00030 */
/** @req SWS_BSW_00201 Development errors should be of type uint8 */
/** @req SWS_BSW_00073 Implementation specific errors */
#define WDGIF_E_PARAM_DEVICE 0x01u
#define WDGIF_E_INV_POINTER 0x02u
extern const WdgIf_ConfigType WdgIfConfig;
/** @req SWS_WdgIf_00016 */
/** @req SWS_WdgIf_00018 */
/** @req SWS_WdgIf_00013 */
/** @req SWS_WdgIf_00042 */
#if (WDGIF_DEVICES > 1)
/** Map the service WdgIf_SetMode to the service Wdg_SetMode of the corresponding Watchdog Driver.
* @param[in] DeviceIndex Identifies the Watchdog Driver instance.
* @param[in] Mode The watchdog driver mode (see Watchdog Driver).
*/
Std_ReturnType WdgIf_SetMode(uint8 DeviceIndex, WdgIf_ModeType Mode);
/** @req SWS_WdgIf_00044 */
/** Map the service WdgIf_SetTriggerCondition to the service Wdg_SetTriggerCondition of the corresponding Watchdog Driver.
* @param[in] DeviceIndex Identifies the Watchdog Driver instance.
* @param[in] Timeout Timeout value (milliseconds) for setting the trigger counter.
*/
void WdgIf_SetTriggerCondition(uint8 DeviceIndex, uint16 Timeout);
#else
/** @req SWS_WdgIf_00019 */
#define WdgIf_SetMode(DeviceIndex, Mode) \
WdgIfConfig.WdgIf_Device[0u].WdgRef->Wdg_SetModeLocationPtr(Mode)
#define WdgIf_SetTriggerCondition(DeviceIndex, Timeout) \
WdgIfConfig.WdgIf_Device[0u].WdgRef->Wdg_TriggerLocationPtr(Timeout)
#endif
#if (WDGIF_VERSION_INFO_API == STD_ON)
/** @req SWS_WdgIf_00046 */
/** Returns the version information.
* @param[out] *VersionInfoPtr Pointer to where to store the version information of this module.
*/
void WdgIf_GetVersionInfo(Std_VersionInfoType *VersionInfoPtr);
#endif
#endif /* WDGIF_H_ */
|
2301_81045437/classic-platform
|
safety_security/WdgIf/inc/WdgIf.h
|
C
|
unknown
| 4,230
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @file WdgIf_Types.h
*
* This file contains the types used in Wdg module.
*/
#ifndef WDGIF_TYPES_H_
#define WDGIF_TYPES_H_
/** @req SWS_WdgIf_00010 */ /*The Watchdog Interface’s implementer shall place the type definitions of the Watchdog Interface in the file WdgIf_Types.h*/
/* @req SWS_WdgIf_00041 */
/* @req SWS_BSW_00024 Include AUTOSAR Standard Types Header in implementation header */
#include "Std_Types.h"
/** @enum WdgIf_ModeType
* @brief AUTOSAR Specified Watchdog Mode Type Definition.
* The WdgIf_ModeType values shall be passed as parameters to the watchdog drivers mode switching function (Wdg_SetMode).
*/
/* @req SWS_WdgIf_00061 */
typedef enum
{
WDGIF_OFF_MODE,
WDGIF_SLOW_MODE,
WDGIF_FAST_MODE
}WdgIf_ModeType;
/** @brief ArcCore Specified Trigger Location Pointer type.
* It is a function pointer.
*/
typedef void (*Wdg_TriggerLocationPtrType)(uint16 timeout);
/** @brief ArcCore Specified Set Mode Location Pointer type.
* It is a function pointer.
*/
typedef Std_ReturnType (*Wdg_SetModeLocationPtrType)(WdgIf_ModeType Mode);
/**
* @brief ArcCore Specified Wdg General type.
*/
typedef struct
{
const uint8 Wdg_Index;
Wdg_TriggerLocationPtrType Wdg_TriggerLocationPtr;
Wdg_SetModeLocationPtrType Wdg_SetModeLocationPtr;
}Wdg_GeneralType;
typedef struct
{
uint8 WdgIf_DeviceIndex;
const Wdg_GeneralType *WdgRef;
}WdgIf_DeviceType;
typedef struct
{
uint8 WdgIf_NumberOfDevices;
}WdgIf_GeneralType;
typedef struct
{
const WdgIf_GeneralType *WdgIf_General;
const WdgIf_DeviceType *WdgIf_Device;
}WdgIf_ConfigType;
#endif /* WDGIF_TYPES_H_ */
|
2301_81045437/classic-platform
|
safety_security/WdgIf/inc/WdgIf_Types.h
|
C
|
unknown
| 2,536
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/** @req SWS_WdgIf_00026 */ /*The Watchdog Interface provides uniform access to services of the underlying watchdog drivers*/
/** @req SWS_WdgIf_00047 */ /* Wdg_SetMode and Wdg_SetTriggerCondition are available*/
#include "WdgIf.h"
#if !(((WDGIF_SW_MAJOR_VERSION == 2u) && (WDGIF_SW_MINOR_VERSION == 0u)) )
#error WdgIf: Expected BSW module version to be 2.0.*
#endif
#if !(((WDGIF_AR_RELEASE_MAJOR_VERSION == 4u) && (WDGIF_AR_RELEASE_MINOR_VERSION == 3u)) )
#error WdgIf: Expected AUTOSAR version to be 4.3.*
#endif
#if (WDGIF_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif
/*lint -e904 MISRA:STANDARDIZED_INTERFACE:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/** @req SWS_WdgIf_00048 */
/** @req SWS_BSW_00203 API parameter checking enablement. */
/** @req SWS_BSW_00042 Detection of DevErrors should only be performed if configuration parameter for Development errors is set. */
#if (WDGIF_DEV_ERROR_DETECT == STD_ON)
/* @req SWS_BSW_00045 Development errors should be reported to DET module */
/* @req SWS_BSW_00049 API parameter checking */
#define WDGIF_VALIDATE_RV(_expr, _api, _errorcode) \
if(!_expr) { \
(void)Det_ReportError(WDGIF_MODULE_ID,0u,_api,_errorcode ); \
return E_NOT_OK; \
}
/* @req SWS_BSW_00045 Development errors should be reported to DET module */
/* @req SWS_BSW_00049 API parameter checking */
#define WDGIF_VALIDATE_NO_RV(_expr, _api, _errorcode) \
if(!_expr) { \
(void)Det_ReportError(WDGIF_MODULE_ID,0u,_api,_errorcode ); \
return; \
}
#else
#define WDGIF_VALIDATE_RV(_expr, _api, _errorcode) \
if(!_expr) { \
return E_NOT_OK; \
}
#define WDGIF_VALIDATE_NO_RV(_expr, _api, _errorcode) \
if(!_expr) { \
return; \
}
#endif
#if (WDGIF_DEVICES > 1u)
/** @req SWS_WdgIf_00020 */
Std_ReturnType WdgIf_SetMode (uint8 DeviceIndex, WdgIf_ModeType Mode)
{
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGIF_VALIDATE_RV((WdgIfConfig.WdgIf_General->WdgIf_NumberOfDevices > DeviceIndex), WDGIF_SETMODE_ID, WDGIF_E_PARAM_DEVICE);
/** @req SWS_WdgIf_00043 */
/** @req SWS_WdgIf_00057 */
/*Wdg_SetModeLocationPtr points to the Wdg<XXX>_SetMode function for the Wdg device with index DeviceIndex*/
return WdgIfConfig.WdgIf_Device[DeviceIndex].WdgRef->Wdg_SetModeLocationPtr(Mode);
}
void WdgIf_SetTriggerCondition(uint8 DeviceIndex, uint16 Timeout)
{
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGIF_VALIDATE_NO_RV((DeviceIndex < WdgIfConfig.WdgIf_General->WdgIf_NumberOfDevices), WDGIF_SETTRIGGERCONDITION_ID, WDGIF_E_PARAM_DEVICE);
/** @req SWS_WdgIf_00045 */
/*Wdg_TriggerLocationPtr points to the Wdg<XXX>_SetTriggerCondition function for the Wdg device with index DeviceIndex*/
WdgIfConfig.WdgIf_Device[DeviceIndex].WdgRef->Wdg_TriggerLocationPtr(Timeout);
}
#endif
/* @req SWS_BSW_00064 GetVersionInfo shall execute synchonously */
/* @req SWS_BSW_00052 GetVersion info shall only have one parameter */
/* @req SWS_BSW_00164 No restriction on calling context */
#if (WDGIF_VERSION_INFO_API == STD_ON)
void WdgIf_GetVersionInfo(Std_VersionInfoType *VersionInfoPtr)
{
/** @req SWS_WdgIf_00058 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
/* @req SWS_BSW_00212 NULL pointer check */
WDGIF_VALIDATE_NO_RV((VersionInfoPtr != NULL_PTR), WDGIF_GETVERSIONINFO_ID, WDGIF_E_INV_POINTER);
/** @req SWS_WdgIf_00035 */
VersionInfoPtr->moduleID = WDGIF_MODULE_ID;
VersionInfoPtr->vendorID = WDGIF_VENDOR_ID;
VersionInfoPtr->sw_major_version = WDGIF_SW_MAJOR_VERSION;
VersionInfoPtr->sw_minor_version = WDGIF_SW_MINOR_VERSION;
VersionInfoPtr->sw_patch_version = WDGIF_SW_PATCH_VERSION;
}
#endif
|
2301_81045437/classic-platform
|
safety_security/WdgIf/src/WdgIf.c
|
C
|
unknown
| 5,069
|
#WdgM
obj-$(USE_WDGM) += WdgM.o
obj-$(USE_WDGM) += WdgM_PBcfg.o
inc-y += $(ROOTDIR)/safety_security/WdgM/inc
inc-y += $(ROOTDIR)/safety_security/WdgM/src
vpath-y += $(ROOTDIR)/safety_security/WdgM/src
|
2301_81045437/classic-platform
|
safety_security/WdgM/WdgM.mod.mk
|
Makefile
|
unknown
| 207
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
#ifndef WDGM_H
#define WDGM_H
#define WDGM_AR_RELEASE_MAJOR_VERSION 4u
#define WDGM_AR_RELEASE_MINOR_VERSION 3u
#define WDGM_AR_RELEASE_REVISION_VERSION 0u
/* @req SWS_BSW_00059 Published information */
#define WDGM_VENDOR_ID 60u
#define WDGM_MODULE_ID 13u
#define WDGM_AR_MAJOR_VERSION WDGM_AR_RELEASE_MAJOR_VERSION
#define WDGM_AR_MINOR_VERSION WDGM_AR_RELEASE_MINOR_VERSION
#define WDGM_AR_PATCH_VERSION WDGM_AR_RELEASE_REVISION_VERSION
#define WDGM_SW_MAJOR_VERSION 3u
#define WDGM_SW_MINOR_VERSION 0u
#define WDGM_SW_PATCH_VERSION 0u
/* globally fulfilled requirements */
/** @req SWS_WdgM_00200 */ /*The Watchdog Manager module shall track the Local Supervision Status of each Supervised Entity*/
/** @req SWS_WdgM_00085 */ /*The Watchdog Manager module shall derive the required number of independent data resources to perform the Alive Supervision*/
/** @req SWS_WdgM_00293 */ /*The Watchdog Manager module shall derive the required number of independent data resources to perform the Deadline Supervision*/
/** @req ARC_SWS_WdgM_00014 */ /* ARCCORE defined file structure. */
#define WDGM_SID_INIT 0x00u
#define WDGM_SID_DEINIT 0x01u
#define WDGM_SID_GETVERSIONINFO 0x02u
#define WDGM_SID_SETMODE 0x03u
#define WDGM_SID_GETMODE 0x0Bu
#define WDGM_SID_CHECKPOINTREACHED 0x0Eu
#define WDGM_SID_UPDATEALIVECOUNTER 0x04u
#define WDGM_SID_GETLOCALSTATUS 0x0Cu
#define WDGM_SID_GETGLOBALSTATUS 0x0Du
#define WDGM_SID_PERFORMRESET 0x0Fu
#define WDGM_SID_GETFIRSTEXPIREDSEID 0x10u
#define WDGM_SID_MAINFUNCTION 0x08u
/** @req SWS_WdgM_00004 */
/** @req SWS_BSW_00201 Development errors should be of type uint8 */
/** @req SWS_BSW_00073 Implementation specific errors */
#define WDGM_E_NO_INIT 0x10u
#define WDGM_E_NO_DEINIT 0x1Au
#define WDGM_E_PARAM_CONFIG 0x11u
#define WDGM_E_PARAM_MODE 0x12u
#define WDGM_E_PARAM_SEID 0x13u
#define WDGM_E_INV_POINTER 0x14u
#define WDGM_E_DISABLE_NOT_ALLOWED 0x15u
#define WDGM_E_CPID 0x16u
#define WDGM_E_DEPRECATED 0x17u
#define WDGM_E_AMBIGIOUS 0x18u
#define WDGM_E_SEDEACTIVATED 0x19u
/** @req SWS_WdgM_00369 */
#include "Rte_WdgM_Type.h"
#include "WdgM_runtimeTypes.h"
/** @req SWS_WdgM_00002 */ /*The Watchdog Manager module shall support the parallel usage of multiple watchdogs*/
/** @req SWS_WdgM_00011 */ /*The following data types are used by Watchdog Manager module*/
/** @req SWS_WdgM_00161 */ /*Required interfaces from other modules*/
/** @req SWS_WdgM_00162 */ /*Optional interfaces from other modules*/
/** @req SWS_WdgM_00151 */
/** Function which initializes the module
* @param[in] *ConfigPtr Pointer to post-build configuration data
*/
void WdgM_Init(const WdgM_ConfigType *ConfigPtr);
/** @req SWS_WdgM_00261 */
/** Function which deinitializes the module
*/
void WdgM_DeInit( void );
/** @req SWS_WdgM_00153 */
#if ( WDGM_VERSION_INFO_API == STD_ON )
/** Returns the version information of this module.
* @param[out] *ConfigPtr Pointer to where to store the version information of the module WdgM.
*/
void WdgM_GetVersionInfo( Std_VersionInfoType* VersionInfo );
#endif
/** @req SWS_WdgM_00154 */
/** Sets the current mode of Watchdog Manager.
* @param[in] Mode One of the configured Watchdog Manager modes.
*/
Std_ReturnType WdgM_SetMode( WdgM_ModeType Mode);
/** @req SWS_WdgM_00168 */
/** Gets the current mode of Watchdog Manager.
* @param[out] *Mode Current mode of the Watchdog Manager.
*/
Std_ReturnType WdgM_GetMode( WdgM_ModeType *Mode);
/** @req SWS_WdgM_00263 */
/** Indicates to the Watchdog Manager that a Checkpoint within a Supervised Entity has been reached.
* @param[in] SEID Identifier of the Supervised Entity that reports a Checkpoint.
* @param[in] CheckpointID Identifier of the Checkpoint within a Supervised Entity that has been reached.
*/
Std_ReturnType WdgM_CheckpointReached( WdgM_SupervisedEntityIdType SEID, WdgM_CheckpointIdType CheckpointID);
/** @req SWS_WdgM_00169 */
/** Returns the supervision status of an individual Supervised Entity.
* @param[in] SEID Identifier of the supervised entity whose supervision status shall be returned.
* @param[out] *Status Supervision status of the given supervised entity.
*/
Std_ReturnType WdgM_GetLocalStatus( WdgM_SupervisedEntityIdType SEID, WdgM_LocalStatusType *Status);
/** @req SWS_WdgM_00175 */
/** Returns the global supervision status of the Watchdog Manager.
* @param[out] *Status Global supervision status of the Watchdog Manager.
*/
Std_ReturnType WdgM_GetGlobalStatus( WdgM_GlobalStatusType *Status);
/** @req SWS_WdgM_00264 */
/** Instructs the Watchdog Manager to cause a watchdog reset.
*/
void WdgM_PerformReset( void );
/** @req SWS_WdgM_00346 */
/** Returns SEID that first reached the state WDGM_LOCAL_STATUS_EXPIRED.
* @param[out] *SEID Identifier of the supervised entity that first reached the state WDGM_LOCAL_STATUS_EXPIRED.
*/
Std_ReturnType WdgM_GetFirstExpiredSEID( WdgM_SupervisedEntityIdType *SEID);
/** @req SWS_WdgM_00159 */
/** Performs the processing of the cyclic Watchdog Manager jobs.
*/
void WdgM_MainFunction( void );
#if (WDGM_OFF_MODE_ENABLED != STD_OFF)
/** Checks if at least onw watchdog is enabled
* @param[in] Mode Current mode of the Watchdog Manager.
* @param[in] SID Software function ID for the function which called WdgM_internal_isAtLeastOneWdogEnabled in case none is active
* @param[in] errID error ID which shall be reported to DET in case none is active
*/
boolean WdgM_internal_isAtLeastOneWdogEnabled(WdgM_ModeType Mode, uint8 SID, uint8 errID);
#endif
/*lint -e9003 MISRA:OTHER:defining external variable:[MISRA 2012 Rule 8.9, advisory]*/
extern WdgM_RuntimeData WdgM_runtimeData; /* Declared in config, used in WdgM.c */
#endif
|
2301_81045437/classic-platform
|
safety_security/WdgM/inc/WdgM.h
|
C
|
unknown
| 6,962
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
#ifndef WDGM_TYPES_H
#define WDGM_TYPES_H
/** @req SWS_WdgM_00025 */
#include "WdgM_Cfg.h"
#include "WdgIf.h"
#if defined(USE_DEM)
#include "Dem.h"
#endif
#include "Os.h"
typedef uint8 WdgM_Substate;
#define WDGM_SUBSTATE_INCORRECT (WdgM_Substate)0x00
#define WDGM_SUBSTATE_CORRECT (WdgM_Substate)0x01
typedef struct
{
const uint16 TriggerConditionValue;
const WdgIf_ModeType WatchdogMode; /** @req SWS_WdgM_00181 */
const uint8 WatchdogId;
} WdgM_Trigger;
typedef struct
{
const uint16 CheckpointId;
const uint16 ExpectedAliveIndications;
const uint8 MinMargin;
const uint8 MaxMargin;
const uint16 SupervisionReferenceCycle;
} WdgM_AliveSupervision;
typedef struct
{
const uint16 CheckpointIdStart;
const uint16 CheckpointIdFinish;
const uint32 DeadlineMin;
const uint32 DeadlineMax;
} WdgM_DeadlineSupervision;
typedef struct
{
const uint16 CheckpointIdSource;
const uint16 CheckpointIdDestination;
} WdgM_InternalTransition;
typedef struct
{
const uint16 Id;
const uint16 *CheckpointIds;
const uint16 Length_CheckpointIds; /* only 65535 possible */
const WdgM_InternalTransition *Transitions;
const uint16 Length_Transitions; /* only 65535 possible */
const uint16 *StartCheckpointIds;
const uint16 Length_StartCheckpointIds; /* only 65535 possible */
const uint16 *FinalCheckpointIds;
const uint16 Length_FinalCheckpointIds; /* only 65535 possible */
const boolean isOsApplicationRefSet;
const ApplicationType OsApplicationRef;
} WdgM_SupervisedEntity;
typedef struct
{
const uint16 SupervisedEntityId; /** @req SWS_WdgM_00282 */
const boolean CheckInternalLogic;
const WdgM_AliveSupervision *AliveSupervisions;
const uint16 Length_AliveSupervisions; /* only 65535 possible */
const WdgM_DeadlineSupervision *DeadlineSupervisions;
const uint16 Length_DeadlineSupervisions; /* only 65535 possible */
const uint8 FailedAliveSupervisionReferenceCycleTol;
const uint8 OSCounter;
} WdgM_SupervisedEntityConfiguration;
typedef struct
{
const uint8 Id;
const uint16 ExpiredSupervisionCycleTol;
const uint32 SupervisionCycle;
const WdgM_SupervisedEntityConfiguration *SEConfigurations; /** @req SWS_WdgM_00283 */ /* only activated SEs are configured */
const uint16 Length_SEConfigurations; /* only 65535 possible */
const WdgM_Trigger *Triggers;
const uint8 Length_Triggers; /* only 255 possible */
} WdgM_Mode;
typedef struct
{
const uint8 WatchdogId;
const uint8 WatchdogDeviceId;
} WdgM_Watchdog;
#if defined(USE_DEM)
typedef struct
{
const Dem_EventIdType Supervision;
const Dem_EventIdType SetMode;
} WdgM_DEMEventIdRefs;
#endif
typedef struct
{
const WdgM_SupervisedEntity *SupervisedEntities;
const uint16 Length_SupervisedEntities; /* only 65535 possible */
const WdgM_Watchdog *Watchdogs;
const uint8 Length_Watchdogs; /* only 255 possible */
} WdgM_General;
typedef struct
{
#if defined(USE_DEM)
const WdgM_DEMEventIdRefs DemEventIdRefs;
#endif
const uint8 initialModeId;
const WdgM_Mode *Modes;
const uint8 Length_Modes; /* only 255 possible */
} WdgM_ConfigSet;
/** @req SWS_WdgM_00355 */
typedef struct
{
const WdgM_General General;
const WdgM_ConfigSet ConfigSet;
} WdgM_ConfigType;
extern const WdgM_ConfigType WdgMConfig;
#endif
|
2301_81045437/classic-platform
|
safety_security/WdgM/inc/WdgM_ConfigTypes.h
|
C
|
unknown
| 5,190
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
#ifndef WDGM_RUNTIMETYPES_H
#define WDGM_RUNTIMETYPES_H
#include "WdgM_ConfigTypes.h"
typedef struct
{
uint32 AliveCounter;
uint16 SupervisionCycleCounter;
boolean wasEvaluated;
} WdgM_runtime_AliveSupervision;
typedef struct
{
TickType LastTickValue;
} WdgM_runtime_DeadlineSupervision;
typedef struct
{
WdgM_LocalStatusType LocalState;
WdgM_Substate SubstateAlive;
WdgM_Substate SubstateDeadline;
WdgM_Substate SubstateLogical;
boolean IsInternalGraphActive; /* active flag for the internal graph */ /** @req SWS_WdgM_00271 */
uint16 PreviousCheckpointId_internalLogic; /** @req SWS_WdgM_00246 */
uint8 FailedAliveCyclesCounter;
} WdgM_runtime_SupervisedEntity;
typedef struct
{
WdgM_runtime_AliveSupervision *AliveSupervisions;
const uint16 Length_AliveSupervisions;
WdgM_runtime_DeadlineSupervision *DeadlineSupervisions;
const uint16 Length_DeadlineSupervisions;
} WdgM_runtime_SupervisedEntityConfig;
typedef struct
{
WdgM_runtime_SupervisedEntityConfig *SE_Configs;
const uint16 Length_SEConfigs;
uint16 ExpiredSupervisionCycleCounter;
} WdgM_runtime_Mode;
typedef struct
{
WdgM_runtime_SupervisedEntity *SEs;
const uint16 Length_SEs;
WdgM_runtime_Mode *Modes;
const uint16 Length_Modes;
} WdgM_RuntimeData;
typedef struct
{
const WdgM_ConfigType *ConfigPtr;
WdgM_RuntimeData *runtimeDataPtr;
boolean isInitiated;
WdgM_GlobalStatusType GlobalState; /** @req SWS_WdgM_00213 */
const WdgM_Mode *CurrentMode;
boolean ResetInitiated;
boolean isFirstExpiredSet;
} WdgM_debuggable_runtimeData;
#endif
|
2301_81045437/classic-platform
|
safety_security/WdgM/inc/WdgM_runtimeTypes.h
|
C
|
unknown
| 2,959
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/*Globaly fulfilled requirements*/
/** @req SWS_WdgM_00011 */ /*Data types used by Watchdog Manager module defined in other modules*/
/** @req SWS_WdgM_91001 */ /*Port intefaces for module*/
/** @req SWS_WdgM_00333 */ /*Port intefaces for module*/
/** @req SWS_WdgM_91004 */ /*Port intefaces for module*/
/** @req SWS_WdgM_00150 */ /*Port intefaces for module*/
/** @req SWS_WdgM_00149 */ /*Port intefaces for module*/
/** @req SWS_WdgM_91002 */ /*Naming of service ports for module*/
/** @req SWS_WdgM_00147 */ /*Naming of service ports for module*/
/** @req SWS_WdgM_91003 */ /*Naming of service ports for module*/
#include "WdgM.h"
#if defined(USE_RTE)
/** @req SWS_WdgM_00334 */ /*Defined in Rte_WdgM_Type.h*/
/** @req SWS_WdgM_00360 */ /*Defined in Rte_WdgM_Type.h*/
/** @req SWS_WdgM_00359 */ /*Defined in Rte_WdgM_Type.h*/
/** @req SWS_WdgM_00357 */ /*Defined in Rte_WdgM_Type.h*/
/** @req SWS_WdgM_00356 */ /*Defined in Rte_WdgM_Type.h*/
/** @req SWS_WdgM_00358 */ /*Defined in Rte_WdgM_Type.h*/
#include "Rte_WdgM.h"
#endif
#include "Os.h"
/** @req SWS_WdgM_00126 */
#if defined(USE_DEM)
#include "Dem.h"
#endif
#include "WdgIf.h"
#if defined(USE_BSWM)
#include "BswM.h"
#endif
#if !(((WDGM_SW_MAJOR_VERSION == 3u) && (WDGM_SW_MINOR_VERSION == 0u)) )
#error WdgM: Expected BSW module version to be 3.0.*
#endif
#if !(((WDGM_AR_RELEASE_MAJOR_VERSION == 4u) && (WDGM_AR_RELEASE_MINOR_VERSION == 3u)) )
#error WdgM: Expected AUTOSAR version to be 4.3.*
#endif
#if (WDGM_IMMEDIATE_RESET == STD_ON)
#include "Mcu.h"
#endif
/* @req SWS_BSW_00045 Development errors should be reported to DET module */
#if (WDGM_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#define WDGM_REPORT_DET_ERROR(functionID, error) (void)Det_ReportError(WDGM_MODULE_ID, 0u, functionID, error)
#else
#define WDGM_REPORT_DET_ERROR(functionID, error)
#endif
#if defined(USE_DEM)
#define WDGM_REPORT_DEM_ERROR(eventId) if (eventId != DEM_EVENT_ID_NULL) { Dem_ReportErrorStatus(eventId, DEM_EVENT_STATUS_FAILED); }
#else
#define WDGM_REPORT_DEM_ERROR(eventId)
#define DEM_EVENT_ID_NULL 0
#endif
/*lint -save -e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/* ARGUMENT_CHECK Macros used for checking arguments before performing any functionality*/
/* @req SWS_BSW_00203 API parameter checking enablement. */
/* @req SWS_BSW_00042 Detection of DevErrors should only be performed if configuration parameter for Development errors is set. */
#if (WDGM_DEV_ERROR_DETECT == STD_ON)
/* @req SWS_BSW_00049 API parameter checking */
#define WDGM_CHECK_INIT_NO_RV(functionID) \
{ \
if (WdgM_instance.isInitiated == (boolean)FALSE) \
{ \
WDGM_REPORT_DET_ERROR(functionID, WDGM_E_NO_INIT); \
return; \
} \
}
/* @req SWS_BSW_00049 API parameter checking */
#define WDGM_CHECK_DEINIT_NO_RV(functionID) \
{ \
if (WdgM_instance.isInitiated == (boolean)TRUE) \
{ \
WDGM_REPORT_DET_ERROR(functionID, WDGM_E_NO_DEINIT); \
return; \
} \
}
/* @req SWS_BSW_00049 API parameter checking */
#define WDGM_CHECK_INIT_RV(functionID) \
{ \
if (WdgM_instance.isInitiated == (boolean)FALSE) \
{ \
WDGM_REPORT_DET_ERROR(functionID, WDGM_E_NO_INIT); \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_NULL_POINTER_NO_RV(ptr, functionID) \
{ \
if (ptr == NULL_PTR) \
{ \
WDGM_REPORT_DET_ERROR(functionID, WDGM_E_INV_POINTER); \
return; \
} \
}
#define WDGM_CHECK_NULL_POINTER_RV(ptr, functionID) \
{ \
if (ptr == NULL_PTR) \
{ \
WDGM_REPORT_DET_ERROR(functionID, WDGM_E_INV_POINTER); \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_MODE_RV(mode, functionID, error) \
{ \
if (mode >= WdgM_instance.ConfigPtr->ConfigSet.Length_Modes) \
{ \
WDGM_REPORT_DET_ERROR(functionID, error); \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_SEID_RV(SEId, functionID, error) \
{ \
if (SEId >= WdgM_instance.ConfigPtr->General.Length_SupervisedEntities) \
{ \
WDGM_REPORT_DET_ERROR(functionID, error); \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_CP_RV(se, CPId, functionID) \
{ \
if (CPId >= se->Length_CheckpointIds) \
{ \
WDGM_REPORT_DET_ERROR(functionID, WDGM_E_CPID); \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_VALID_SEID_POINTER_RV(ptr, functionID, error) \
{ \
if (ptr == NULL_PTR) \
{ \
WDGM_REPORT_DET_ERROR(functionID, error); \
return E_NOT_OK; \
} \
}
#else
#define WDGM_CHECK_INIT_NO_RV(functionID) \
{ \
if (WdgM_instance.isInitiated == (boolean)FALSE) \
{ \
return; \
} \
}
#define WDGM_CHECK_DEINIT_NO_RV(functionID) \
{ \
if (WdgM_instance.isInitiated == (boolean)TRUE) \
{ \
return; \
} \
}
#define WDGM_CHECK_INIT_RV(functionID) \
{ \
if (WdgM_instance.isInitiated == (boolean)FALSE) \
{ \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_NULL_POINTER_NO_RV(ptr, functionID) \
{ \
if (ptr == NULL_PTR) \
{ \
return; \
} \
}
#define WDGM_CHECK_NULL_POINTER_RV(ptr, functionID) \
{ \
if (ptr == NULL_PTR) \
{ \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_MODE_RV(mode, functionID, error) \
{ \
if (mode >= WdgM_instance.ConfigPtr->ConfigSet.Length_Modes) \
{ \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_SEID_RV(SEId, functionID, error) \
{ \
if (SEId >= WdgM_instance.ConfigPtr->General.Length_SupervisedEntities) \
{ \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_CP_RV(se, CPId, functionID) \
{ \
if (CPId >= se->Length_CheckpointIds) \
{ \
return E_NOT_OK; \
} \
}
#define WDGM_CHECK_VALID_SEID_POINTER_RV(ptr, functionID, error) \
{ \
if (ptr == NULL_PTR) \
{ \
return E_NOT_OK; \
} \
}
#endif
/*lint -restore */
/** @req SWS_WdgM_00387 */
#define WDGM_START_SEC_VAR_INIT_UNSPECIFIED
#include "WdgM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
WdgM_debuggable_runtimeData WdgM_instance = {.GlobalState = WDGM_GLOBAL_STATUS_DEACTIVATED, .isInitiated = (boolean)FALSE}; /*lint !e785 OTHER [MISRA 2012 Rule 9.3, required] the GlobalState needs to be initialized according to requirement and isInitiated need to be FALSE, while the other are loaded at WdgM_Init function*/
#define WDGM_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "WdgM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define WDGM_START_SEC_VAR_NO_INIT_16
#include "WdgM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static uint16 firstExpiredSEID;
#define WDGM_STOP_SEC_VAR_NO_INIT_16
#include "WdgM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define WDGM_START_SEC_VAR_NO_INIT_16
#include "WdgM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static uint16 firstExpiredSEIDInverse;
#define WDGM_STOP_SEC_VAR_NO_INIT_16
#include "WdgM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static void WdgM_internal_DeactivateAndResetSE(uint16 SEIndex);
static void WdgM_internal_CheckAlives(void);
static WdgM_Substate WdgM_internal_IsAliveHold(const WdgM_AliveSupervision *aliveCP, WdgM_runtime_AliveSupervision *runtime_aliveCP);
static void WdgM_internal_CalculateGlobalState(void);
static void WdgM_internal_ResetSEConfigsForMode(WdgM_runtime_Mode *runtime_Mode);
static void WdgM_internal_AliveMonitoring(const WdgM_SupervisedEntityConfiguration *seConf, const WdgM_runtime_SupervisedEntityConfig *runtime_seConf, WdgM_CheckpointIdType CPId);
static WdgM_Substate WdgM_internal_DeadlineMonitoring(const WdgM_SupervisedEntityConfiguration *seConf, const WdgM_runtime_SupervisedEntityConfig *runtime_seConf, WdgM_CheckpointIdType CPId);
static WdgM_Substate WdgM_internalIsDeadlineHold(const CounterType counter_id, const WdgM_DeadlineSupervision *deadlineCP, WdgM_runtime_DeadlineSupervision *runtime_deadlineCP);
static WdgM_Substate WdgM_internal_LogicalMonitoring(const WdgM_SupervisedEntity *se, WdgM_runtime_SupervisedEntity *runtime_se, WdgM_CheckpointIdType CPId);
static Std_ReturnType WdgM_internal_deactivateCurrentTriggers(uint16 errID);
static Std_ReturnType WdgM_internal_activateTriggers(const WdgM_Mode *Mode, uint16 errID);
static void WdgM_Internal_ReportLocalModeChange(const WdgM_runtime_SupervisedEntity *runtime_se, const uint16 SEIndex);
static void Wdgm_internal_ReportGlobalModeChange(void);
#if (WDGM_OFF_MODE_ENABLED != STD_ON)
static boolean WdgM_internal_isAtLeastOneWdogEnabled(WdgM_ModeType Mode, uint8 SID, uint8 errID);
#endif
/* @req SWS_BSW_00064 GetVersionInfo shall execute synchonously */
/* @req SWS_BSW_00052 GetVersion info shall only have one parameter */
/* @req SWS_BSW_00164 No restriction on calling context */
#if ( WDGM_VERSION_INFO_API == STD_ON )
void WdgM_GetVersionInfo( Std_VersionInfoType* VersionInfo )
{
/** @req SWS_WdgM_00256 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
/* @req SWS_BSW_00212 NULL pointer check */
/*lint -e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
WDGM_CHECK_NULL_POINTER_NO_RV(VersionInfo, WDGM_SID_GETVERSIONINFO);
VersionInfo->vendorID = WDGM_VENDOR_ID;
VersionInfo->moduleID = WDGM_MODULE_ID;
VersionInfo->sw_major_version = WDGM_SW_MAJOR_VERSION;
VersionInfo->sw_minor_version = WDGM_SW_MINOR_VERSION;
VersionInfo->sw_patch_version = WDGM_SW_PATCH_VERSION;
}
#endif
/** @req SWS_WdgM_00018 */
/** @req SWS_WdgM_00135 */
void WdgM_Init(const WdgM_ConfigType *ConfigPtr)
{
const WdgM_Mode *initialMode;
uint16 i;
boolean status = (boolean)TRUE;
Std_ReturnType ret = E_OK;
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
/* @req SWS_BSW_00212 NULL pointer check */
WDGM_CHECK_NULL_POINTER_NO_RV(ConfigPtr, WDGM_SID_INIT);
/** @req SWS_WdgM_00389 */ /*The error code in the requirement seems misspelled and the reuirement is missing a "not"*/
/** @req SWS_WdgM_00390 */
WDGM_CHECK_DEINIT_NO_RV(WDGM_SID_INIT);
WdgM_instance.ConfigPtr = ConfigPtr;
WdgM_instance.runtimeDataPtr = &WdgM_runtimeData;
initialMode = &WdgM_instance.ConfigPtr->ConfigSet.Modes[WdgM_instance.ConfigPtr->ConfigSet.initialModeId];
#if (WDGM_OFF_MODE_ENABLED != STD_ON)
/** @req SWS_WdgM_00030 */
/*lint -e838 MISRA:OTHER:Previously assigned value to variable 'status' has not been used:[MISRA 2004 Info, advisory] */
status = WdgM_internal_isAtLeastOneWdogEnabled(initialMode->Id, WDGM_SID_INIT, WDGM_E_DISABLE_NOT_ALLOWED);
#endif
if ((boolean)TRUE == status) {/*lint !e774 MISRA:CONFIGURATION:Boolean within 'if' always evaluates to True:[MISRA 2012 Rule 14.3, required] */
/* cycle through all SEs and deactivate them (afterwards active the ones which are configured for the initMode)
* also set active-flag to false and reset the internal-previous-cps */
for (i = 0u; i < WdgM_instance.ConfigPtr->General.Length_SupervisedEntities; i++)
{
/** @req SWS_WdgM_00269 */
/** @req SWS_WdgM_00296 */
WdgM_internal_DeactivateAndResetSE(i);
}
/* cycle trough all SEs which are configured for the initial-mode and activate them*/
for (i = 0u; i < initialMode->Length_SEConfigurations; i++)
{
uint16 SEId = initialMode->SEConfigurations[i].SupervisedEntityId;
WdgM_runtime_SupervisedEntity *runtime_se = &WdgM_instance.runtimeDataPtr->SEs[SEId];
/** @req SWS_WdgM_00268 */
runtime_se->LocalState = WDGM_LOCAL_STATUS_OK;
WdgM_Internal_ReportLocalModeChange(runtime_se, SEId);
}
/** @req SWS_WdgM_00298 */
/* reset all timestamps and counters for mode */
WdgM_internal_ResetSEConfigsForMode(&WdgM_instance.runtimeDataPtr->Modes[initialMode->Id]);
/** @req SWS_WdgM_00285 */
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_OK;
Wdgm_internal_ReportGlobalModeChange();
/** @req SWS_WdgM_00370 */
WdgM_instance.isFirstExpiredSet = (boolean)FALSE;
firstExpiredSEIDInverse = 0;
firstExpiredSEID = 0;
WdgM_instance.CurrentMode = initialMode;
WdgM_instance.ResetInitiated = (boolean)FALSE;
/* now setmode */
/** @req SWS_WdgM_00135 */
#if defined(USE_DEM)
ret = WdgM_internal_activateTriggers(initialMode,WdgM_instance.ConfigPtr->ConfigSet.DemEventIdRefs.SetMode);
#else
ret = WdgM_internal_activateTriggers(initialMode,DEM_EVENT_ID_NULL);
#endif
if (E_OK == ret)
{
/** @req SWS_WdgM_00179 */
WdgM_instance.isInitiated = (boolean)TRUE;
}
}
}
void WdgM_DeInit( void )
{
Std_ReturnType ret;
ret = E_OK;
/** @req SWS_WdgM_00288 */
/** @req SWS_WdgM_00388 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGM_CHECK_INIT_NO_RV(WDGM_SID_DEINIT);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
if (WdgM_instance.GlobalState == WDGM_GLOBAL_STATUS_OK)
{
uint8 i ;
/** @req SWS_WdgM_00286 */
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_DEACTIVATED;
Wdgm_internal_ReportGlobalModeChange();
/* set all currently active wdogs (only the ones that are configured by wdgm!!) to off */
ret = WdgM_internal_deactivateCurrentTriggers(DEM_EVENT_ID_NULL);
if (E_OK == ret) {
/** @req SWS_WdgM_00223 */ /* not really a requirement here but spec says that in deactiveated state triggerconditions have to be 0. since deinit gets globalstate in deactiveated we do this here as well.. */
if (WdgM_instance.ResetInitiated == (boolean)FALSE)
{
for(i = 0u; i < WdgM_instance.ConfigPtr->General.Length_Watchdogs; i++)
{
WdgIf_SetTriggerCondition(WdgM_instance.ConfigPtr->General.Watchdogs[i].WatchdogDeviceId, 0u);
}
}
WdgM_instance.isInitiated = (boolean)FALSE;
}
}
}
Std_ReturnType WdgM_SetMode( WdgM_ModeType Mode)
{
uint16 SetModeEventId;
Std_ReturnType retVal = E_OK;
boolean status = (boolean)TRUE;
/** @req SWS_WdgM_00021 */
/** @req SWS_WdgM_00393 */
/** @req SWS_WdgM_00392 */
/** @req SWS_WdgM_00394 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGM_CHECK_INIT_RV(WDGM_SID_SETMODE);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/** @req SWS_WdgM_00020 */
WDGM_CHECK_MODE_RV(Mode, WDGM_SID_SETMODE, WDGM_E_PARAM_MODE);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
#if (WDGM_OFF_MODE_ENABLED != STD_ON)
/** @req SWS_WdgM_00031 */
/*lint -e838 MISRA:OTHER:Previously assigned value to variable 'status' has not been used:[MISRA 2004 Info, advisory] */
status = WdgM_internal_isAtLeastOneWdogEnabled(Mode, WDGM_SID_SETMODE, WDGM_E_DISABLE_NOT_ALLOWED);
#endif
if ((boolean)TRUE == status) {/*lint !e774 MISRA:CONFIGURATION:Boolean within 'if' always evaluates to True:[MISRA 2012 Rule 14.3, required] */
/** @req SWS_WdgM_00316 */
/** @req SWS_WdgM_00145 */
if ((WdgM_instance.GlobalState == WDGM_GLOBAL_STATUS_OK) || (WdgM_instance.GlobalState == WDGM_GLOBAL_STATUS_FAILED)) {
const WdgM_Mode *newMode = &WdgM_instance.ConfigPtr->ConfigSet.Modes[Mode];
/* we now have to disable all SEs which aren't used in this mode */
/* since global state is OK or FAILED there should be no mode which has bad local state value => we don't have to check this */
/* we consider that all SEconfigurations are sorted in the way that the config with the lowest SEId is in first place */
uint16 SEIndex = 0u;
uint16 ConfigIndex = 0u;
/** @req SWS_WdgM_00182 */
while (ConfigIndex <= newMode->Length_SEConfigurations) { /* we need "<=" for deactivating all SEs when the last SEId from the config was < the greatest SEId */
/* get next SEId of SEConfig */
uint16 untilID;
if (ConfigIndex < newMode->Length_SEConfigurations) {
untilID = newMode->SEConfigurations[ConfigIndex].SupervisedEntityId;
}
else {
/* we need this for deactivating all SEs when the last SEId from the config was < the greatest SEId */
untilID = WdgM_instance.ConfigPtr->General.Length_SupervisedEntities;
}
/* until there deactivate all SEs */
for(; SEIndex < untilID; SEIndex++) {
/** @req SWS_WdgM_00207 */
/** @req SWS_WdgM_00291 */
/** @req SWS_WdgM_00315 */
WdgM_internal_DeactivateAndResetSE(SEIndex);
}
if (ConfigIndex < newMode->Length_SEConfigurations) {
/* now we are at the SE we don't want to activate or leave it like it is */
/** @req SWS_WdgM_00209 */
WdgM_runtime_SupervisedEntity *runtime_se = &WdgM_instance.runtimeDataPtr->SEs[SEIndex];
/* since deactivation already reseted everything we just have to activate the se */
/* when already active we don't have to do anything in order to retain all values */
if (runtime_se->LocalState == WDGM_LOCAL_STATUS_DEACTIVATED) {
runtime_se->LocalState = WDGM_LOCAL_STATUS_OK;
WdgM_Internal_ReportLocalModeChange(runtime_se, SEIndex);
}
/* stepover this id since there is nothing more to do */
SEIndex++;
}
/* get next ConfigId with the next cycle */
ConfigIndex++;
}
/* the modechange was successfully so reset all data from the last mode */
WdgM_internal_ResetSEConfigsForMode(&WdgM_instance.runtimeDataPtr->Modes[WdgM_instance.CurrentMode->Id]);
/* deactivate all old triggers and activate all new ones (depending on the new mode) */
#if defined(USE_DEM)
SetModeEventId = (uint16)WdgM_instance.ConfigPtr->ConfigSet.DemEventIdRefs.SetMode;
#else
SetModeEventId = DEM_EVENT_ID_NULL;
#endif
retVal = WdgM_internal_deactivateCurrentTriggers(SetModeEventId);
if (retVal == E_OK) {
retVal = WdgM_internal_activateTriggers(newMode, SetModeEventId);
}
WdgM_instance.CurrentMode = newMode;
}
} else {
retVal = E_NOT_OK;
}
return retVal;
}
Std_ReturnType WdgM_GetMode( WdgM_ModeType *Mode)
{
/** @req SWS_WdgM_00253 */
/** @req SWS_WdgM_00395 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGM_CHECK_INIT_RV(WDGM_SID_GETMODE);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/* @req SWS_BSW_00212 NULL pointer check */
/* @req SWS_WdgM_00254 */
WDGM_CHECK_NULL_POINTER_RV(Mode, WDGM_SID_GETMODE);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/** @req SWS_WdgM_00170 */ /*WdgM_instance.CurrentMode is set last in SetMode*/
*Mode = WdgM_instance.CurrentMode->Id;
return E_OK;
}
/** @req SWS_WdgM_00295 */
/** @req SWS_WdgM_00297 */
Std_ReturnType WdgM_CheckpointReached( WdgM_SupervisedEntityIdType SEID, WdgM_CheckpointIdType CheckpointID)
{
/** @req SWS_WdgM_00279 */
/** @req SWS_WdgM_00396 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGM_CHECK_INIT_RV(WDGM_SID_CHECKPOINTREACHED);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/** @req SWS_WdgM_00278 */
WDGM_CHECK_SEID_RV(SEID, WDGM_SID_CHECKPOINTREACHED, WDGM_E_PARAM_SEID);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
Std_ReturnType retVal = E_NOT_OK;
/* first get the right SE */
const WdgM_SupervisedEntity *se = &WdgM_instance.ConfigPtr->General.SupervisedEntities[SEID];
WdgM_runtime_SupervisedEntity *runtime_se = &WdgM_instance.runtimeDataPtr->SEs[SEID];
/** @req SWS_WdgM_00284 */
WDGM_CHECK_CP_RV(se, CheckpointID, WDGM_SID_CHECKPOINTREACHED);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/** @req SWS_WdgM_00208 */
if (runtime_se->LocalState!= WDGM_LOCAL_STATUS_DEACTIVATED)
{
/* and now the right config for the current mode */
uint16 i;
const WdgM_SupervisedEntityConfiguration *seConf = NULL_PTR;
const WdgM_runtime_SupervisedEntityConfig *runtime_seConf = NULL_PTR;
/** @CODECOV:SEARCHING_FOR_ELEMENT_IN_ARRAY:The end of the for-loop is not reached as we break once the element is found. **/
__CODE_COVERAGE_IGNORE__
for(i = 0u; i < WdgM_instance.CurrentMode->Length_SEConfigurations; i++)
{
if(WdgM_instance.CurrentMode->SEConfigurations[i].SupervisedEntityId == SEID)
{
seConf = &WdgM_instance.CurrentMode->SEConfigurations[i];
runtime_seConf = &WdgM_instance.runtimeDataPtr->Modes[WdgM_instance.CurrentMode->Id].SE_Configs[i];
break;
}
}
WDGM_CHECK_VALID_SEID_POINTER_RV(seConf,WDGM_SID_CHECKPOINTREACHED,WDGM_E_PARAM_SEID);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
WDGM_CHECK_VALID_SEID_POINTER_RV(runtime_seConf,WDGM_SID_CHECKPOINTREACHED,WDGM_E_PARAM_SEID);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/* value stays correct */
WdgM_internal_AliveMonitoring(seConf, runtime_seConf, CheckpointID);
/** @req SWS_WdgM_00322 */
/* if this algo doesn't find anything value stays correct */
runtime_se->SubstateDeadline = WdgM_internal_DeadlineMonitoring(seConf, runtime_seConf, CheckpointID);
if (seConf->CheckInternalLogic == (boolean)TRUE)
{
/** @req SWS_WdgM_00323 */
runtime_se->SubstateLogical = WdgM_internal_LogicalMonitoring(se, runtime_se, CheckpointID);
}
retVal = E_OK;
}
#if (WDGM_DEV_ERROR_DETECT == STD_ON)
else
{
/** @req SWS_WdgM_00319 */
WDGM_REPORT_DET_ERROR(WDGM_SID_CHECKPOINTREACHED, WDGM_E_SEDEACTIVATED);
}
#endif
return retVal;
}
/** @req SWS_WdgM_00171 */
Std_ReturnType WdgM_GetLocalStatus( WdgM_SupervisedEntityIdType SEID, WdgM_LocalStatusType *Status)
{
/** @req SWS_WdgM_00173 */
/** @req SWS_WdgM_00397 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGM_CHECK_INIT_RV(WDGM_SID_GETLOCALSTATUS);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/** @req SWS_WdgM_00257 */
/* @req SWS_BSW_00212 NULL pointer check */
WDGM_CHECK_NULL_POINTER_RV(Status, WDGM_SID_GETLOCALSTATUS);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/** @req SWS_WdgM_00172 */
WDGM_CHECK_SEID_RV(SEID, WDGM_SID_GETLOCALSTATUS, WDGM_E_PARAM_SEID);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
*Status = WdgM_instance.runtimeDataPtr->SEs[SEID].LocalState;
return E_OK;
}
Std_ReturnType WdgM_GetGlobalStatus( WdgM_GlobalStatusType *Status)
{
/** @req SWS_WdgM_00176 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGM_CHECK_INIT_RV(WDGM_SID_GETGLOBALSTATUS);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/** @req SWS_WdgM_00344 */
/** @req SWS_WdgM_00258 */
/* @req SWS_BSW_00212 NULL pointer check */
WDGM_CHECK_NULL_POINTER_RV(Status, WDGM_SID_GETGLOBALSTATUS);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
*Status = WdgM_instance.GlobalState;
return E_OK;
}
void WdgM_PerformReset( void )
{
/** @req SWS_WdgM_00270 */
/** @req SWS_WdgM_00401 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGM_CHECK_INIT_NO_RV(WDGM_SID_PERFORMRESET);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
if (WdgM_instance.ResetInitiated == (boolean)FALSE)
{
/** @req SWS_WdgM_00233 */
WdgM_instance.ResetInitiated = (boolean)TRUE;
/** @req SWS_WdgM_00232 */
uint8 i;
for(i = 0u; i < WdgM_instance.ConfigPtr->General.Length_Watchdogs; i++)
{
WdgIf_SetTriggerCondition(WdgM_instance.ConfigPtr->General.Watchdogs[i].WatchdogDeviceId, 0u);
}
}
}
Std_ReturnType WdgM_GetFirstExpiredSEID( WdgM_SupervisedEntityIdType *SEID)
{
/** @req SWS_WdgM_00348 */
/* there is no init check because function should be available before init is called */
Std_ReturnType retVal = E_NOT_OK;
/** @req SWS_WdgM_00347 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
/* @req SWS_BSW_00212 NULL pointer check */
WDGM_CHECK_NULL_POINTER_RV(SEID, WDGM_SID_GETFIRSTEXPIREDSEID);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
/** @req SWS_WdgM_00349 */
uint16 invertedSEID = (~firstExpiredSEID);
if (invertedSEID == firstExpiredSEIDInverse) {
*SEID = firstExpiredSEID;
retVal = E_OK;
} else {
*SEID = 0u;
retVal = E_NOT_OK;
}
return retVal;
}
/** @req SWS_WdgM_00327 */
void WdgM_MainFunction( void )
{
/** @req SWS_WdgM_00039 */
/* Validates parameters, and if it fails will immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
WDGM_CHECK_INIT_NO_RV(WDGM_SID_MAINFUNCTION);/*lint !e904 MISRA:ARGUMENT_CHECK:argument check:[MISRA 2012 Rule 15.5, advisory]*/
uint8 i;
/** @req SWS_WdgM_00324 */
/* now do alive monitoring */
WdgM_internal_CheckAlives();
/** @req SWS_WdgM_00325 */
/** @req SWS_WdgM_00326 */
/** @req SWS_WdgM_00214 */
/* now do the other stuff - local states are implicitly calculated during global state calculation */
WdgM_internal_CalculateGlobalState();
if (WdgM_instance.GlobalState == WDGM_GLOBAL_STATUS_STOPPED)
{
#if (WDGM_DEM_ALIVE_SUPERVISION_REPORT == STD_ON)
/** @req SWS_WdgM_00129 */
/** @req SWS_WdgM_00375 */
WDGM_REPORT_DEM_ERROR(WdgM_instance.ConfigPtr->ConfigSet.DemEventIdRefs.Supervision);
#endif
#if (WDGM_IMMEDIATE_RESET == STD_ON)
/** @req SWS_WdgM_00133 */
/** @req SWS_WdgM_00134 */
Mcu_PerformReset();
#endif
}
/* set the triggers for all wdgdevices != WDGIF_OFF_MODE */
/** @req SWS_WdgM_00328 */
/** @req SWS_WdgM_00223 */
for(i = 0u; i < WdgM_instance.CurrentMode->Length_Triggers; i++)
{
/** @req SWS_WdgM_00119 */
/** @req SWS_WdgM_00120 */
/** @req SWS_WdgM_00121 */
/** @req SWS_WdgM_00122 */
if (WdgM_instance.CurrentMode->Triggers[i].WatchdogMode != WDGIF_OFF_MODE)
{
uint16 triggerValue = (WdgM_instance.GlobalState == WDGM_GLOBAL_STATUS_STOPPED)? 0u : WdgM_instance.CurrentMode->Triggers[i].TriggerConditionValue;
if (WdgM_instance.ResetInitiated == (boolean)FALSE)
{
WdgIf_SetTriggerCondition(WdgM_instance.ConfigPtr->General.Watchdogs[WdgM_instance.CurrentMode->Triggers[i].WatchdogId].WatchdogDeviceId, triggerValue);
}
}
}
}
#if (WDGM_OFF_MODE_ENABLED != STD_ON)
static boolean WdgM_internal_isAtLeastOneWdogEnabled(WdgM_ModeType Mode, uint8 SID, uint8 errID) {
/* check wheter one Watchdog is != WDGIF_OFF_MODE */
/* if not => DET-Error and return without doing anything */
uint8 i;
boolean WdgActive = (boolean)FALSE;
const WdgM_Mode *newMode = &WdgM_instance.ConfigPtr->ConfigSet.Modes[Mode];
for(i = 0u; i < newMode->Length_Triggers; i++)
{
if (newMode->Triggers[i].WatchdogMode != WDGIF_OFF_MODE)
{
WdgActive = (boolean)TRUE;
break;
}
}
if ((boolean)FALSE == WdgActive)
{
WDGM_REPORT_DET_ERROR(SID, errID);
}
return WdgActive;
}
#endif
static Std_ReturnType WdgM_internal_deactivateCurrentTriggers(uint16 errID)
{
uint8 i;
Std_ReturnType ret = E_OK;
/* set all currently used watchdogs to off (only the onces configured for that mode!!) */
for(i = 0u; (i < WdgM_instance.CurrentMode->Length_Triggers) && (E_OK == ret); i++)
{
uint8 DeviceIndex = WdgM_instance.ConfigPtr->General.Watchdogs[WdgM_instance.CurrentMode->Triggers[i].WatchdogId].WatchdogDeviceId;
(void)DeviceIndex; /* Remove compile warning when using only one watch dog driver */
Std_ReturnType potError = WdgIf_SetMode(DeviceIndex, WDGIF_OFF_MODE);
if (potError != E_OK)
{
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_STOPPED;
Wdgm_internal_ReportGlobalModeChange();
WDGM_REPORT_DEM_ERROR(errID);
ret = E_NOT_OK;
}
}
return ret;
}
static Std_ReturnType WdgM_internal_activateTriggers(const WdgM_Mode *Mode, uint16 errID)
{
uint8 i;
Std_ReturnType ret = E_OK;
/* turn on all wdogs configured for the new mode */
for(i = 0u; (i < Mode->Length_Triggers) && (E_OK == ret); i++)
{
/** @req SWS_WdgM_00186 */
uint8 DeviceIndex = WdgM_instance.ConfigPtr->General.Watchdogs[Mode->Triggers[i].WatchdogId].WatchdogDeviceId;
(void)DeviceIndex; /* Remove compile warning when using only one watch dog driver */
Std_ReturnType potError = WdgIf_SetMode(DeviceIndex, Mode->Triggers[i].WatchdogMode);
if ((potError == E_OK) && (Mode->Triggers[i].WatchdogMode != WDGIF_OFF_MODE))
{
if (WdgM_instance.ResetInitiated == (boolean)FALSE)
{
WdgIf_SetTriggerCondition(DeviceIndex, Mode->Triggers[i].TriggerConditionValue);
}
}
if (potError != E_OK)
{
/** @req SWS_WdgM_00139 */
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_STOPPED;
Wdgm_internal_ReportGlobalModeChange();
/** @req SWS_WdgM_00142 */
/** @req SWS_WdgM_00376 */
WDGM_REPORT_DEM_ERROR(errID);
ret = E_NOT_OK;
}
}
return ret;
}
static void WdgM_internal_CheckAlives(void)
{
/* cycle through all seConfigs and check the alive states and update the internal substate of the corresponding se */
uint16 i;
for(i = 0u; i < WdgM_instance.CurrentMode->Length_SEConfigurations; i++)
{
const WdgM_SupervisedEntityConfiguration *seConf = &WdgM_instance.CurrentMode->SEConfigurations[i];
WdgM_runtime_SupervisedEntity *runtime_se = &WdgM_instance.runtimeDataPtr->SEs[seConf->SupervisedEntityId];
WdgM_Substate result = WDGM_SUBSTATE_CORRECT;
boolean writeResult = (boolean)FALSE;
uint16 a;
/** @req SWS_WdgM_00083 */
for(a = 0u; a < seConf->Length_AliveSupervisions; a++)
{
const WdgM_AliveSupervision *aliveCP = &seConf->AliveSupervisions[a];
WdgM_runtime_AliveSupervision *runtime_aliveCP = &WdgM_instance.runtimeDataPtr->Modes[WdgM_instance.CurrentMode->Id].SE_Configs[i].AliveSupervisions[a];
/* first increment the supervisioncyclecounter */
runtime_aliveCP->SupervisionCycleCounter++;
/** @req SWS_WdgM_00074 */
WdgM_Substate tempRes = WdgM_internal_IsAliveHold(aliveCP, runtime_aliveCP);
if ((boolean)TRUE == runtime_aliveCP->wasEvaluated) {
writeResult = TRUE;
}
/** @req SWS_WdgM_00115 */
if (tempRes == WDGM_SUBSTATE_INCORRECT)
{
/* when once there was an incorrect result don't update again to correct */
result = tempRes;
}
}
/* when one aliveCP was evaluated then the result is written - if no aliveCP was evaluated the state stays the same */
if ((boolean)TRUE == writeResult) {
runtime_se->SubstateAlive = result;
}
}
}
static WdgM_Substate WdgM_internal_SpecAliveAlgo(const WdgM_AliveSupervision *aliveCP, WdgM_runtime_AliveSupervision *runtimeAliveCP)
{
WdgM_Substate retVal = WDGM_SUBSTATE_INCORRECT;
sint16 temp = (sint16)runtimeAliveCP->AliveCounter - (sint16)aliveCP->ExpectedAliveIndications;
if ((temp <= (sint16)aliveCP->MaxMargin) && (temp >= (0 - (sint16)aliveCP->MinMargin)))
{
retVal = WDGM_SUBSTATE_CORRECT;
}
runtimeAliveCP->AliveCounter = 0u; /* reset counter for next check */
runtimeAliveCP->SupervisionCycleCounter = 0u; /* reset counter in order to count cycles from beginning again */
return retVal;
}
static WdgM_Substate WdgM_internal_IsAliveHold(const WdgM_AliveSupervision *aliveCP, WdgM_runtime_AliveSupervision *runtime_aliveCP)
{
WdgM_Substate retVal = WDGM_SUBSTATE_CORRECT;
/* check all constraints */
/* checking depends on supervisionreferencecycle */
/* so if src == 1 we have to check each cycle */
/* when src > 1 we have to check when src is reached */
runtime_aliveCP->wasEvaluated = (boolean)FALSE;
/** @req SWS_WdgM_00098 */
if (aliveCP->SupervisionReferenceCycle == 1u)
{
/* each cycle */
retVal = WdgM_internal_SpecAliveAlgo(aliveCP, runtime_aliveCP);
runtime_aliveCP->wasEvaluated = (boolean)TRUE;
}
else
{
/* multiple cycle */
/* check if multiple is already reached => therefore we can use the SupervisionCycleCounter */
if (runtime_aliveCP->SupervisionCycleCounter == aliveCP->SupervisionReferenceCycle)
{
retVal = WdgM_internal_SpecAliveAlgo(aliveCP, runtime_aliveCP);
runtime_aliveCP->wasEvaluated = (boolean)TRUE;
}
}
return retVal;
}
static void WdgM_internal_CalculateLocalState_FromFailedNoError(WdgM_runtime_SupervisedEntity *runtime_se, const WdgM_SupervisedEntityConfiguration *seConf)
{
/** @req SWS_WdgM_00300 */
if (runtime_se->FailedAliveCyclesCounter > 1u)
{
/* decrement and stay in failed */
runtime_se->FailedAliveCyclesCounter--;
}
else
/** @req SWS_WdgM_00205 */
{
runtime_se->FailedAliveCyclesCounter = 0u;
runtime_se->LocalState = WDGM_LOCAL_STATUS_OK;
WdgM_Internal_ReportLocalModeChange(runtime_se, seConf->SupervisedEntityId);
}
}
static void WdgM_internal_CalculateLocalState_FromOKOneError(WdgM_runtime_SupervisedEntity *runtime_se, const WdgM_SupervisedEntityConfiguration *seConf)
{
/** @req SWS_WdgM_00203 */
/*runtime_se->FailedAliveCyclesCounter will alwys be equal or less than <= seConf->FailedAliveSupervisionReferenceCycleTol when arriving at this function, it is therefore not needed to be checked*/
if (runtime_se->SubstateAlive == WDGM_SUBSTATE_INCORRECT)
{
runtime_se->LocalState = WDGM_LOCAL_STATUS_FAILED;
WdgM_Internal_ReportLocalModeChange(runtime_se, seConf->SupervisedEntityId);
/* The ReportModeChange shall not be performed here, it may be expired directly depending on configuration parameters*/
/* Increment the first time, it may be expired directly */
runtime_se->FailedAliveCyclesCounter++;
}
/** @req SWS_WdgM_00202 */
if ((runtime_se->FailedAliveCyclesCounter > seConf->FailedAliveSupervisionReferenceCycleTol) || (runtime_se->SubstateAlive == WDGM_SUBSTATE_CORRECT)) /* one of the others have to be incorrect (not alive ) */
{
runtime_se->LocalState = WDGM_LOCAL_STATUS_EXPIRED;
WdgM_Internal_ReportLocalModeChange(runtime_se, seConf->SupervisedEntityId);
}
}
static void WdgM_internal_CalculateLocalState_FromFailedOneError(WdgM_runtime_SupervisedEntity *runtime_se, const WdgM_SupervisedEntityConfiguration *seConf, const WdgM_runtime_SupervisedEntityConfig *runtime_seConf)
{
/** @req SWS_WdgM_00204 */
/*runtime_se->FailedAliveCyclesCounter will alwys be equal or less than <= seConf->FailedAliveSupervisionReferenceCycleTol when arriving at this function, it is therefore not needed to be checked*/
if (runtime_se->SubstateAlive == WDGM_SUBSTATE_INCORRECT)
{
boolean wasEval = (boolean)FALSE;
uint16 i;
for(i = 0u; i < runtime_seConf->Length_AliveSupervisions; i++)
{
if (runtime_seConf->AliveSupervisions[i].wasEvaluated == (boolean)TRUE)
{
wasEval = (boolean)TRUE;
break;
}
}
/*No mode change has occured, so runtime_se->LocalState is still equal to WDGM_LOCAL_STATUS_FAILED and no reporting is needed (unless it goes to expired)*/
if ((boolean)TRUE == wasEval)
{
/* only increment when aliveSV was evaluated and is still FAILED */
runtime_se->FailedAliveCyclesCounter++;
}
}
/** @req SWS_WdgM_00206 */
if (runtime_se->FailedAliveCyclesCounter > seConf->FailedAliveSupervisionReferenceCycleTol)
{
runtime_se->LocalState = WDGM_LOCAL_STATUS_EXPIRED;
WdgM_Internal_ReportLocalModeChange(runtime_se, seConf->SupervisedEntityId);
}
}
#define WDGM_ALLSUBSTATECORRECT 3U
#define WDGM_ONESUBSTATEINCORRECT 2U
static void WdgM_internal_CalculateLocalState(WdgM_runtime_SupervisedEntity *runtime_se, const WdgM_SupervisedEntityConfiguration *seConf, const WdgM_runtime_SupervisedEntityConfig *runtime_seConf)
{
/* calculate local state for the given SE, the value of each substate can be either 0 (WDGM_SUBSTATE_INCORRECT) or 1 (WDGM_SUBSTATE_CORRECT) so the value of nrOfCorrectSubstates can be between 0 and 3 */
uint8 nrOfCorrectSubstates = runtime_se->SubstateAlive + runtime_se->SubstateDeadline + runtime_se->SubstateLogical;
switch (nrOfCorrectSubstates) {
case WDGM_ALLSUBSTATECORRECT:
/* everything is fine - nothing needs to be done */
/** @req SWS_WdgM_00201 */
if (runtime_se->LocalState == WDGM_LOCAL_STATUS_FAILED)
{
WdgM_internal_CalculateLocalState_FromFailedNoError(runtime_se, seConf);
}
break;
case WDGM_ONESUBSTATEINCORRECT:
/* maybe it's still working */
if (runtime_se->LocalState == WDGM_LOCAL_STATUS_OK)
{
WdgM_internal_CalculateLocalState_FromOKOneError(runtime_se, seConf);
break;
}
if (runtime_se->LocalState == WDGM_LOCAL_STATUS_FAILED)
{
WdgM_internal_CalculateLocalState_FromFailedOneError(runtime_se, seConf, runtime_seConf);
break;
}
break;
default:
runtime_se->LocalState = WDGM_LOCAL_STATUS_EXPIRED;
WdgM_Internal_ReportLocalModeChange(runtime_se, seConf->SupervisedEntityId);
break;
}
}
/* @req SWS_WdgM_00197 */
static void WdgM_Internal_ReportLocalModeChange(const WdgM_runtime_SupervisedEntity *runtime_se, const uint16 SEIndex)
{
#if defined(USE_RTE)
switch (runtime_se->LocalState) {
case WDGM_LOCAL_STATUS_OK:
(void)modeFunctionSwitchPointer[SEIndex](RTE_MODE_WdgMMode_SUPERVISION_OK);
break;
case WDGM_LOCAL_STATUS_FAILED:
(void)modeFunctionSwitchPointer[SEIndex](RTE_MODE_WdgMMode_SUPERVISION_FAILED);
break;
case WDGM_LOCAL_STATUS_EXPIRED:
(void)modeFunctionSwitchPointer[SEIndex](RTE_MODE_WdgMMode_SUPERVISION_EXPIRED);
break;
case WDGM_LOCAL_STATUS_DEACTIVATED:
(void)modeFunctionSwitchPointer[SEIndex](RTE_MODE_WdgMMode_SUPERVISION_DEACTIVATED);
break;
/** @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming.**/
__CODE_COVERAGE_IGNORE__
default:
break;
}
#endif
}
/* @req SWS_WdgM_00198 */
static void Wdgm_internal_ReportGlobalModeChange()
{
#if defined(USE_RTE)
switch (WdgM_instance.GlobalState) {
case WDGM_GLOBAL_STATUS_OK:
(void)Rte_Switch_globalMode_currentMode(RTE_MODE_WdgMMode_SUPERVISION_OK);
break;
case WDGM_GLOBAL_STATUS_FAILED:
(void)Rte_Switch_globalMode_currentMode(RTE_MODE_WdgMMode_SUPERVISION_FAILED);
break;
case WDGM_GLOBAL_STATUS_EXPIRED:
(void)Rte_Switch_globalMode_currentMode(RTE_MODE_WdgMMode_SUPERVISION_EXPIRED);
break;
case WDGM_GLOBAL_STATUS_STOPPED:
(void)Rte_Switch_globalMode_currentMode(RTE_MODE_WdgMMode_SUPERVISION_STOPPED);
break;
case WDGM_GLOBAL_STATUS_DEACTIVATED:
(void)Rte_Switch_globalMode_currentMode(RTE_MODE_WdgMMode_SUPERVISION_DEACTIVATED);
break;
/** @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming.**/
__CODE_COVERAGE_IGNORE__
default:
break;
}
#endif
}
static void WdgM_internal_updateFromGlobalOK(uint16 expired, uint16 failed)
{
/** @req SWS_WdgM_00076 */
if (failed > 0u) /*How many local states which are in failed state*/
{
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_FAILED;
/* no return since expired isn't evaluated yet */
}
if (expired > 0u) { /*How many local states which are in expired state*/
if (WdgM_instance.runtimeDataPtr->Modes[WdgM_instance.CurrentMode->Id].ExpiredSupervisionCycleCounter < WdgM_instance.CurrentMode->ExpiredSupervisionCycleTol) {
/** @req SWS_WdgM_00215 */
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_EXPIRED;
} else {
/** @req SWS_WdgM_00216 */
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_STOPPED;
}
} else {
/** @req SWS_WdgM_00078 */ /* there is nothing to do when status is ok or deactivated */
}
}
static void WdgM_internal_updateFromGlobalFAILED(uint16 expired, uint16 failed)
{
/** @req SWS_WdgM_00218 */
if ((failed == 0u) && (expired == 0u)) { /*How many local states which are in failed state and in expired state*/
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_OK;
} else if (expired > 0u){
if (WdgM_instance.runtimeDataPtr->Modes[WdgM_instance.CurrentMode->Id].ExpiredSupervisionCycleCounter < WdgM_instance.CurrentMode->ExpiredSupervisionCycleTol) {
/** @req SWS_WdgM_00077 */
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_EXPIRED;
} else {
/** @req SWS_WdgM_00117 */
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_STOPPED;
}
} else {
/** @req SWS_WdgM_00217 */
/* remain in failed when nothing applies (failed > 0 && expired == 0).. so just do nothing */
}
}
static void WdgM_internal_updateFromGlobalEXPIRED(uint16 expired)
{
/** @req SWS_WdgM_00219 */
if (expired > 0u) { /*How many local states which are in expired state*/
if (WdgM_instance.runtimeDataPtr->Modes[WdgM_instance.CurrentMode->Id].ExpiredSupervisionCycleCounter < WdgM_instance.CurrentMode->ExpiredSupervisionCycleTol) {
/* stay in expired and increment the counter */
WdgM_instance.runtimeDataPtr->Modes[WdgM_instance.CurrentMode->Id].ExpiredSupervisionCycleCounter++;
} else {
/** @req SWS_WdgM_00220 */
WdgM_instance.GlobalState = WDGM_GLOBAL_STATUS_STOPPED;
}
} else {
/* Do nothing */
}
}
static void WdgM_internal_CalculateGlobalState()
{
/* go trough all active SEs and calc the global state depending on their local states */
uint16 expiredCounter = 0u;
uint16 failedCounter = 0u;
uint16 i;
WdgM_GlobalStatusType initalState = WdgM_instance.GlobalState;
for (i = 0u; i < WdgM_instance.CurrentMode->Length_SEConfigurations; i++)
{
const WdgM_SupervisedEntityConfiguration *seConf = &WdgM_instance.CurrentMode->SEConfigurations[i];
const WdgM_runtime_SupervisedEntityConfig *runtime_seConf = &WdgM_instance.runtimeDataPtr->Modes[WdgM_instance.CurrentMode->Id].SE_Configs[i];
WdgM_runtime_SupervisedEntity *runtime_se = &WdgM_instance.runtimeDataPtr->SEs[seConf->SupervisedEntityId];
WdgM_internal_CalculateLocalState(runtime_se, seConf, runtime_seConf);
if (runtime_se->LocalState == WDGM_LOCAL_STATUS_EXPIRED)
{
/** @req SWS_WdgM_00351 */
if (WdgM_instance.isFirstExpiredSet == (boolean)FALSE)
{
firstExpiredSEID = i;
firstExpiredSEIDInverse = ~i;
WdgM_instance.isFirstExpiredSet = (boolean)TRUE;
}
expiredCounter++;
}
if (runtime_se->LocalState == WDGM_LOCAL_STATUS_FAILED)
{
failedCounter++;
}
}
switch(WdgM_instance.GlobalState) {
case WDGM_GLOBAL_STATUS_OK:
WdgM_internal_updateFromGlobalOK(expiredCounter, failedCounter);
break;
case WDGM_GLOBAL_STATUS_FAILED:
WdgM_internal_updateFromGlobalFAILED(expiredCounter, failedCounter);
break;
case WDGM_GLOBAL_STATUS_EXPIRED:
WdgM_internal_updateFromGlobalEXPIRED(expiredCounter);
break;
case WDGM_GLOBAL_STATUS_STOPPED:
/** @req SWS_WdgM_00221 */
/* when stopped then stay in stopped */
break;
/** @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming.**/
__CODE_COVERAGE_IGNORE__
default:
/* Invalid state because it shouldn't be possible with WDGM_GLOBAL_STATUS_DEACTIVATED if WdgM is initialized */
break;
}
if (initalState != WdgM_instance.GlobalState) {
/* @req SWS_WdgM_00199 */
Wdgm_internal_ReportGlobalModeChange();
}
}
static void WdgM_internal_ResetSEConfigsForMode(WdgM_runtime_Mode *runtime_Mode)
{
uint16 i;
runtime_Mode->ExpiredSupervisionCycleCounter = 0u;
for (i = 0u; i < runtime_Mode->Length_SEConfigs; i++)
{
/* reset timestamps, alivecounters, previous cp and external active-flag */
uint16 a ;
for (a = 0u; a < runtime_Mode->SE_Configs[i].Length_AliveSupervisions; a++)
{
runtime_Mode->SE_Configs[i].AliveSupervisions[a].AliveCounter = 0u;
runtime_Mode->SE_Configs[i].AliveSupervisions[a].SupervisionCycleCounter = 0u;
}
for (a = 0u; a < runtime_Mode->SE_Configs[i].Length_DeadlineSupervisions; a++)
{
/** @req SWS_WdgM_00298 */
runtime_Mode->SE_Configs[i].DeadlineSupervisions[a].LastTickValue = 0u;
}
}
}
static void WdgM_internal_AliveMonitoring(const WdgM_SupervisedEntityConfiguration *seConf, const WdgM_runtime_SupervisedEntityConfig *runtime_seConf, WdgM_CheckpointIdType CPId)
{
uint16 i;
WdgM_runtime_AliveSupervision *runtime_aliveCP = NULL_PTR;
/* search for the checkpoint */
for(i = 0u; i < seConf->Length_AliveSupervisions; i++)
{
if (seConf->AliveSupervisions[i].CheckpointId == CPId)
{
runtime_aliveCP = &runtime_seConf->AliveSupervisions[i];
break;
}
}
if (runtime_aliveCP != NULL_PTR)
{
/** @req SWS_WdgM_00321 */
runtime_aliveCP->AliveCounter++;
}
}
/** @req SWS_WdgM_00299 */
static WdgM_Substate WdgM_internal_DeadlineMonitoring(const WdgM_SupervisedEntityConfiguration *seConf, const WdgM_runtime_SupervisedEntityConfig *runtime_seConf, WdgM_CheckpointIdType CPId)
{
WdgM_Substate result = WDGM_SUBSTATE_CORRECT;
uint16 i;
/* search for checkpoints */
for(i = 0u; i < seConf->Length_DeadlineSupervisions; i++)
{
/* if it's a start dlcp then set timestamp */
if (seConf->DeadlineSupervisions[i].CheckpointIdStart == CPId)
{
TickType elapsedTicks = 0u;
TickRefType elapsedTicksPointer;
elapsedTicksPointer = &elapsedTicks;
/** @req SWS_WdgM_00228 */
TickRefType LastTickPointer = (TickRefType)&(runtime_seConf->DeadlineSupervisions[i].LastTickValue);/*lint !e929 MISRA:CONFIGURATION:cast from one pointer to other:[MISRA 2012 Rule 11.3, required] */
(void)GetElapsedValue(seConf->OSCounter, LastTickPointer, elapsedTicksPointer); /*Choosing which counter shall be used is not supported*/
}
/* if it's a finsih dlcp then do evaluation */
if ((seConf->DeadlineSupervisions[i].CheckpointIdFinish == CPId) && (runtime_seConf->DeadlineSupervisions[i].LastTickValue != 0u))
{
/** @req SWS_WdgM_00229 */
/* measure the time and get calculate result */
if (WdgM_internalIsDeadlineHold(seConf->OSCounter, &seConf->DeadlineSupervisions[i], &runtime_seConf->DeadlineSupervisions[i]) == WDGM_SUBSTATE_INCORRECT)
{
result = WDGM_SUBSTATE_INCORRECT;
break;
}
/** @req SWS_WdgM_00354 */
runtime_seConf->DeadlineSupervisions[i].LastTickValue = 0u;
}
}
return result;
}
#define WDGM_OSTICKSPERSECOND (1000000000UL / OSTICKDURATION)
static WdgM_Substate WdgM_internalIsDeadlineHold(const CounterType counter_id, const WdgM_DeadlineSupervision *deadlineCP, WdgM_runtime_DeadlineSupervision *runtime_deadlineCP)
{
WdgM_Substate ret;
TickType elapsedTicks = 0u;
TickRefType elapsedTicksPointer;
elapsedTicksPointer = &elapsedTicks;
/** @req SWS_WdgM_00373 */
/** @req SWS_WdgM_00374 */ /*The computation has the same effect as 00374 but does not use that procedure*/
TickRefType LastTickPointer = (TickRefType)&(runtime_deadlineCP->LastTickValue);/*lint !e929 MISRA:CONFIGURATION:cast from one pointer to other:[MISRA 2012 Rule 11.3, required] */
(void)GetElapsedValue(counter_id, LastTickPointer, elapsedTicksPointer); /*Choosing which counter shall be used is not supported*/
ret = WDGM_SUBSTATE_INCORRECT;
/** @req SWS_WdgM_00294 */
if ((elapsedTicks >= (deadlineCP->DeadlineMin * WDGM_OSTICKSPERSECOND)) && (elapsedTicks <= (deadlineCP->DeadlineMax * WDGM_OSTICKSPERSECOND)))
{
ret = WDGM_SUBSTATE_CORRECT;
}
return ret;
}
static WdgM_Substate WdgM_internal_LogicalMonitoring_GraphActive(const WdgM_SupervisedEntity *se, WdgM_runtime_SupervisedEntity *runtime_se, WdgM_CheckpointIdType CPId)
{
WdgM_Substate retVal = WDGM_SUBSTATE_INCORRECT;
/* check whether the transition from the previous checkpoint to the current is allowed */
uint16 i;
for(i = 0u; i < se->Length_Transitions; i++)
{
if(se->Transitions[i].CheckpointIdSource == runtime_se->PreviousCheckpointId_internalLogic)
{
if(se->Transitions[i].CheckpointIdDestination == CPId)
{
retVal = WDGM_SUBSTATE_CORRECT;
/** @req SWS_WdgM_00246 */
runtime_se->PreviousCheckpointId_internalLogic = CPId;
break;
}
}
}
if (retVal == WDGM_SUBSTATE_CORRECT)
{
/* now check if this cp is a finishcp */
for(i = 0u; i < se->Length_FinalCheckpointIds; i++)
{
if (se->FinalCheckpointIds[i] == CPId)
{
/** @req SWS_WdgM_00331 */
runtime_se->IsInternalGraphActive = (boolean)FALSE;
break;
}
}
}
return retVal;
}
static WdgM_Substate WdgM_internal_LogicalMonitoring_GraphInactive(const WdgM_SupervisedEntity *se, WdgM_runtime_SupervisedEntity *runtime_se, WdgM_CheckpointIdType CPId)
{
WdgM_Substate retVal = WDGM_SUBSTATE_INCORRECT;
/* check whether the reported cp is a startcp */
uint16 i;
for(i = 0u; i < se->Length_StartCheckpointIds; i++)
{
if (se->StartCheckpointIds[i] == CPId)
{
retVal = WDGM_SUBSTATE_CORRECT;
/** @req SWS_WdgM_00332 */
/** @req SWS_WdgM_00273 */
/** @req SWS_WdgM_00329 */
runtime_se->IsInternalGraphActive = (boolean)TRUE;
/** @req SWS_WdgM_00246 */
runtime_se->PreviousCheckpointId_internalLogic = CPId;
break;
}
}
return retVal;
}
static WdgM_Substate WdgM_internal_LogicalMonitoring(const WdgM_SupervisedEntity *se, WdgM_runtime_SupervisedEntity *runtime_se, WdgM_CheckpointIdType CPId)
{
WdgM_Substate retVal = WDGM_SUBSTATE_INCORRECT;
/** @req SWS_WdgM_00274 */
if (runtime_se->IsInternalGraphActive == (boolean)TRUE)
{
retVal = WdgM_internal_LogicalMonitoring_GraphActive(se, runtime_se, CPId);
}
else
{
retVal = WdgM_internal_LogicalMonitoring_GraphInactive(se, runtime_se, CPId);
}
return retVal;
}
static void WdgM_internal_DeactivateAndResetSE(uint16 SEIndex)
{
WdgM_runtime_SupervisedEntity *runtime_se = &WdgM_instance.runtimeDataPtr->SEs[SEIndex];
runtime_se->LocalState = WDGM_LOCAL_STATUS_DEACTIVATED;
WdgM_Internal_ReportLocalModeChange(runtime_se, SEIndex);
runtime_se->IsInternalGraphActive = (boolean)FALSE;
runtime_se->PreviousCheckpointId_internalLogic = 0u; /* be aware that 0 is a valid value => but flag is inactive so this dosn't matter */
runtime_se->FailedAliveCyclesCounter = 0u;
runtime_se->SubstateAlive = WDGM_SUBSTATE_CORRECT;
runtime_se->SubstateDeadline = WDGM_SUBSTATE_CORRECT;
runtime_se->SubstateLogical = WDGM_SUBSTATE_CORRECT;
}
|
2301_81045437/classic-platform
|
safety_security/WdgM/src/WdgM.c
|
C
|
unknown
| 63,262
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */
/*lint -e451 -e9021 AUTOSAR API SWS_MemMap_00003 */
#define WDGM_MEMMAP_ERROR
#ifdef WDGM_START_SEC_VAR_INIT_UNSPECIFIED
#include "MemMap.h" /*lint !e451 !e9019 MISRA:STANDARDIZED_INTERFACE:AUTOSAR Require Inclusion:[MISRA 2012 Directive 4.10, required] [MISRA 2012 Rule 20.1, advisory] */
#undef WDGM_MEMMAP_ERROR
#undef WDGM_START_SEC_VAR_INIT_UNSPECIFIED
#endif
#ifdef WDGM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "MemMap.h" /*lint !e451 !e9019 MISRA:STANDARDIZED_INTERFACE:AUTOSAR Require Inclusion:[MISRA 2012 Directive 4.10, required] [MISRA 2012 Rule 20.1, advisory] */
#undef WDGM_MEMMAP_ERROR
#undef WDGM_START_SEC_VAR_CLEARED_UNSPECIFIED
#endif
#ifdef WDGM_START_SEC_VAR_NO_INIT_16
#include "MemMap.h" /*lint !e451 !e9019 MISRA:STANDARDIZED_INTERFACE:AUTOSAR Require Inclusion:[MISRA 2012 Directive 4.10, required] [MISRA 2012 Rule 20.1, advisory] */
#undef WDGM_MEMMAP_ERROR
#undef WDGM_START_SEC_VAR_NO_INIT_16
#endif
#ifdef WDGM_STOP_SEC_VAR_NO_INIT_16
#include "MemMap.h" /*lint !e451 !e9019 MISRA:STANDARDIZED_INTERFACE:AUTOSAR Require Inclusion:[MISRA 2012 Directive 4.10, required] [MISRA 2012 Rule 20.1, advisory] */
#undef WDGM_MEMMAP_ERROR
#undef WDGM_STOP_SEC_VAR_NO_INIT_16
#endif
#ifdef WDGM_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "MemMap.h" /*lint !e451 !e9019 MISRA:STANDARDIZED_INTERFACE:AUTOSAR Require Inclusion:[MISRA 2012 Directive 4.10, required] [MISRA 2012 Rule 20.1, advisory] */
#undef WDGM_MEMMAP_ERROR
#undef WDGM_STOP_SEC_VAR_INIT_UNSPECIFIED
#endif
#ifdef WDGM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "MemMap.h" /*lint !e451 !e9019 MISRA:STANDARDIZED_INTERFACE:AUTOSAR Require Inclusion:[MISRA 2012 Directive 4.10, required] [MISRA 2012 Rule 20.1, advisory] */
#undef WDGM_MEMMAP_ERROR
#undef WDGM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#endif
#ifdef WDGM_MEMMAP_ERROR
#error "WdgM_BswMemMap.h error, section not mapped"
#endif
|
2301_81045437/classic-platform
|
safety_security/WdgM/src/WdgM_BswMemMap.h
|
C
|
unknown
| 2,736
|
# -*- coding: utf-8 -*-
import argparse
import json
import os
import subprocess
#ECLIPSE_BIN = "/c/Projects/ides/com.arccore.cli.product-win32.win32.x86_64-6.0.0/eclipsec.exe"
json_file_name = "generation_registry.json"
if __name__ =='__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--action", dest = "action", help="What to do: register/generate")
parser.add_argument("-x", "--arxml_files", nargs='*', dest = "arxml_files", help="Arxml files to load")
parser.add_argument("-m", "--module", dest = "module", help="Module to generate")
parser.add_argument("-i", "--project_id", dest = "project_id", help="A unique string to identify the project.")
parser.add_argument("-e", "--eclipse_executable", dest = "eclipse_executable", help = "Path to the generator executable (eclipsec/arcgen)")
parser.add_argument("-v", "--verbosity", dest = "verbosity", help = "Verbosity level for the generator (DEBUG/INFO/WARN)")
parser.add_argument("-c", "--ecuc", dest = "ecuc", help = "Ecuc Value Collection")
parser.add_argument("-o", "--output", dest = "output", help = "Path to output dir")
parser.add_argument("-d", "--data", dest = "data", help = "Workspace location (path)")
parser.add_argument("-p", "--project", dest = "project", help = "Name of temporary project")
parser.add_argument("-j", "--vm", dest = "vm", help = "Path to java VM (bin folder)")
arguments = parser.parse_args()
if( arguments.action == "register" ):
if( os.path.isfile(json_file_name) ):
json_input_file = open(json_file_name)
json_data = json_input_file.readline()
json_input_file.close()
entrys_in = json.loads(json_data)
if( arguments.project_id in entrys_in ):
arxml_set = set(entrys_in[arguments.project_id]['x'])
arxml_set.update(arguments.arxml_files)
entrys_in[arguments.project_id]['x'] = list(arxml_set)
module_set = set(entrys_in[arguments.project_id]['m'])
module_set.update([arguments.module])
entrys_in[arguments.project_id]['m'] = list(module_set)
else:
entrys_in[arguments.project_id] = { 'x' : arguments.arxml_files, 'm' : [arguments.module] }
else:
entrys_in = { arguments.project_id : { 'x' : arguments.arxml_files, 'm' : [arguments.module] } }
json_file = open(json_file_name,"w")
json_file.write(json.dumps(entrys_in))
json_file.close()
elif( arguments.action == "generate"):
if( os.path.isfile(json_file_name) ):
json_input_file = open(json_file_name)
json_data = json_input_file.readline()
entrys_in = json.loads(json_data)
if( arguments.project_id in entrys_in ):
arxml_files_comma = ",".join(entrys_in[arguments.project_id]['x'])
modules_comma = ",".join(entrys_in[arguments.project_id]['m'])
call = [
arguments.eclipse_executable,
"-application", "com.arccore.cli.generator",
"-data", arguments.data,
"-project", arguments.project,
"-ecuc", arguments.ecuc,
"-output", arguments.output,
"-external", arxml_files_comma,
"-modules", modules_comma
]
if( arguments.vm != None ):
call.extend(["-vm", arguments.vm])
print( " ".join(call) )
subprocess.call(call)
else:
print("Project not registered")
else:
print("No modules registered for generation (nothing to be done for target)")
else:
print( "Unknown action" )
|
2301_81045437/classic-platform
|
scripts/CLIGeneration/gen_buffer.py
|
Python
|
unknown
| 3,402
|
MKIMAGE?=/c/Users/mahi/git/bootloader/bin/mkimage
SRECORD_PATH?=/c/devtools/srecord
SREC_CAT=$(Q)$(SRECORD_PATH)/srec_cat.exe
SREC_INFO=$(Q)$(SRECORD_PATH)/srec_info.exe
# "downloader" need an srecord file
build-srec-image-y = $(PROJECTNAME)_srec_image.srec
build-srec-y = $(PROJECTNAME).srec
build-bin-image-y = $(PROJECTNAME)_bin_image.bin
# To add a header with mkimage we need a binary file
build-bin-y = $(PROJECTNAME).bin
all-mod += $(build-srec-image-y)
all-mod += $(build-srec-y)
all-mod += $(build-bin-image-y)
# To srecord again to load in tool
$(build-srec-image-y): $(build-bin-image-y)
@echo ">> Binary to SREC to load with tool"
$(SREC_CAT) $< -binary -offset ${BOOT_IMAGE_ADDR} -o $@
$(SREC_INFO) $@
$(build-srec-y) : $(build-exe-y)
@echo
@echo " >> OBJCOPY $@"
$(Q)$(CROSS_COMPILE)objcopy -O srec $< $@
$(SREC_INFO) $@
# Binary image down to 0
$(build-bin-y) : $(build-srec-y)
@echo ">> srec to binary with offset 0"
$(SREC_INFO) $<
$(SREC_CAT) $< -offset - -minimum-addr $< -o $@ -binary
# Add image header
# Should extract the start address with "objdump -f"
$(build-bin-image-y): $(build-bin-y)
@echo ">> Adding header"
$(MKIMAGE) -o $@ -l $(BOOT_BLOB_LOAD_ADDR) -s $(BOOT_BLOB_START_ADDR) -m "APP" -v $<
|
2301_81045437/classic-platform
|
scripts/bootloader_image.mk
|
Makefile
|
unknown
| 1,297
|
#/bin/bash
# Usage:
#
# build_all
#
SCRIPT_DIR=`dirname $0`
. ${SCRIPT_DIR}/build_ppc.sh
. ${SCRIPT_DIR}/build_arm.sh
exit 0
|
2301_81045437/classic-platform
|
scripts/build_all.sh
|
Shell
|
unknown
| 160
|
#/bin/bash
function quit {
echo
echo "### BUILD FAILED"
echo
exit $1
}
SCRIPT_DIR=`dirname $0`
ARCH=ARM
source ${SCRIPT_DIR}/guess_cc.sh
export BDIR=examples/tiny
make BOARDDIR=stm32_stm3210c clean
make BOARDDIR=stm32_stm3210c all
if [ $? -ne 0 ]; then quit 1
fi
export BDIR=examples/simple
make BOARDDIR=stm32_stm3210c clean
make BOARDDIR=stm32_stm3210c all
if [ $? -ne 0 ]; then quit 1
fi
# Problems memory..
#export BDIR=system/kernel/testsystem/suite_01,system/kernel/testsystem/suite_02, system/kernel/testsystem/suite_03
#make BOARDDIR=stm32_stm3210c clean
#make BOARDDIR=stm32_stm3210c all
#if [ $? -ne 0 ]; then quit 1
#fi
|
2301_81045437/classic-platform
|
scripts/build_arm.sh
|
Shell
|
unknown
| 696
|
#/bin/bash
# Usage:
# build_example <all|clean> <arch> <board> <example>
#
# Example: build_example all|clean ARM|PPC mpc551xsim| simple|tiny|.....
#
function quit {
echo
echo "### BUILD FAILED"
echo
exit $1
}
if [ $# -ne 4 ]; then
echo "usage:"
echo " build_example <build_target> <arch> <board> <example>"
echo " <build target> - all | clean"
echo " <arch> - ARM | PPC | HCS12"
echo " <board> - mpc551xsim | ..."
echo " <example> - simple | tiny | ..."
echo ""
echo "example:"
echo " $build_example all PPC mpc551xsim examples/simple"
quit 1;
fi
SCRIPT_DIR=`dirname $0`
ARCH=$2
source ${SCRIPT_DIR}/guess_cc.sh
export BDIR=$4
make BOARDDIR=$3 $1
if [ $? -ne 0 ]; then quit 1
fi
|
2301_81045437/classic-platform
|
scripts/build_example.sh
|
Shell
|
unknown
| 757
|
#/bin/bash
# Usage:
#
# build_ppc
#
# This script file is quite braindead... remake when time..
function quit {
echo
echo "### BUILD FAILED"
echo
exit $1
}
SCRIPT_DIR=`dirname $0`
ARCH=PPC
source ${SCRIPT_DIR}/guess_cc.sh
export BDIR=system/kernel/testsystem/suite_01,system/kernel/testsystem/suite_02,,system/kernel/testsystem/suite_03
make BOARDDIR=mpc5554sim clean
make BOARDDIR=mpc5554sim all
if [ $? -ne 0 ]; then quit 1
fi
make BOARDDIR=mpc551xsim clean
make BOARDDIR=mpc551xsim all
if [ $? -ne 0 ]; then quit 1
fi
make BOARDDIR=mpc5516it clean
make BOARDDIR=mpc5516it all
if [ $? -ne 0 ]; then quit 1
fi
export examples/blinker_node
make BOARDDIR=mpc5567qrtech clean
make BOARDDIR=mpc5567qrtech all
if [ $? -ne 0 ]; then quit 1
fi
# Build the examples...
export BDIR=examples/blinker_node
make BOARDDIR=mpc5516it clean
make BOARDDIR=mpc5516it all
if [ $? -ne 0 ]; then quit 1
fi
export BDIR=examples/pwm_node
make BOARDDIR=mpc5516it clean
make BOARDDIR=mpc5516it all
if [ $? -ne 0 ]; then quit 1
fi
export BDIR=examples/pwm_node2
make BOARDDIR=mpc5516it clean
make BOARDDIR=mpc5516it all
if [ $? -ne 0 ]; then quit 1
fi
export BDIR=examples/simple
make BOARDDIR=mpc551xsim clean
make BOARDDIR=mpc551xsim all
if [ $? -ne 0 ]; then quit 1
fi
export BDIR=examples/switch_node
make BOARDDIR=mpc5516it clean
make BOARDDIR=mpc5516it all
if [ $? -ne 0 ]; then quit 1
fi
export BDIR=examples/tiny
make BOARDDIR=mpc5516it clean
make BOARDDIR=mpc5516it all
if [ $? -ne 0 ]; then quit 1
fi
|
2301_81045437/classic-platform
|
scripts/build_ppc.sh
|
Shell
|
unknown
| 1,653
|
ARMCC_BIN = $(ARMCC_COMPILE)/bin
ARMCC_TARGET?=--cpu=Cortex-A9
# ---------------------------------------------------------------------------
# Compiler
# CCFLAGS - compile flags
CC = $(ARMCC_BIN)/armcc
cflags-$(CFG_OPT_RELEASE) +=
cflags-$(CFG_OPT_DEBUG) += -g -O0
cflags-$(CFG_OPT_SIZE) += -g -O3
cflags-$(CFG_OPT_FLAGS) += $(SELECT_OPT)
cflags-y += -c
cflags-y += --c99
# Move to target part
cflags-y += $(ARMCC_TARGET)
cflags-y += --fpu=vfpv3
cflags-y += --thumb
cflags-y += --diag_style=gnu
cflags-y += --dwarf2
cflags-y += --min_array_alignment=4
cflags-y += --no_unaligned_access
cflags-y += --library_interface=none
# aeabi_clib99
# Generate dependencies
cflags-y += --md
CFLAGS = $(cflags-y) $(cflags-yy) $(CFLAGS_ARMCC_$@)
CCOUT = -o $@
CFG_ARC_CLIB?=y
inc-system2-y += $(ARMCC_COMPILE)/include
# ---------------------------------------------------------------------------
# Preprocessor
CPP = $(CC) -E
CPPOUT = -o
CPP_ASM_FLAGS = $(ARMCC_TARGET)
# ---------------------------------------------------------------------------
# Linker
#
# LDFLAGS - linker flags
# LDOUT - How to Generate linker output file
# LDMAPFILE - How to generate mapfile
# ldcmdfile-y - link cmd file
# libpath-y - lib paths
# libitem-y - the libs with path
# lib-y - the libs, without path
# Note!
# gnu ld scripts are not supported by armcc for bare metal links
LD = $(ARMCC_BIN)/armlink.exe
LDOUT = -o $@
TE = elf
LDMAPFILE =--map --info=sizes,totals --show_cmdline --symbols --list=$(strip $(subst .elf,.map, $@))
# --verbose --xref --xrefdbg
LD_FILE2= --scatter=
ldflags-y += --entry=0
ldflags-y += --no_legacyalign
ldflags-y += --thumb2_library
ldflags-y += --datacompressor=off
libitem-y += $(libitem-yy)
LDFLAGS += $(ARMCC_TARGET)
LDFLAGS += $(ldflags-y)
# ---------------------------------------------------------------------------
# Assembler
# ---------------------------------------------------------------------------
AS = $(ARMCC_BIN)/armasm
ASFLAGS += $(ARMCC_TARGET)
ASFLAGS += -g
ASFLAGS += --diag_style=gnu
ASFLAGS += --thumb
ASFLAGS += --dwarf2
ASFLAGS += --apcs=//interwork
ASOUT = -o $@
|
2301_81045437/classic-platform
|
scripts/cc_armcc.mk
|
Makefile
|
unknown
| 2,260
|
HOST := $(shell uname)
export prefix
# CW and paths...
# Bin: PowerPC_EABI_Tools/Command_Line_Tools/mwXXXXXX
# libs: PowerPC_EABI_Support/Runtime/Lib/Runtime.XXXX
# PowerPC_EABI_Support/MSL/MSL_C/PPC_EABI/Lib
#CW_COMPILE=/c/devtools/cw_55xx
CW_BIN = $(CW_COMPILE)/PowerPC_EABI_Tools/Command_Line_Tools
CW_LIB = $(CW_COMPILE)/PowerPC_EABI_Support/Runtime/Lib
# ---------------------------------------------------------------------------
# Compiler
# CCFLAGS - compile flags
CC = $(CW_BIN)/mwcceppc.exe
cflags-y += -c
cflags-y += -cpp_exceptions=off
cflags-y += -readonlystrings
cflags-y += -RTTI=off
cflags-y += -dialect=c99
cflags-y += -gccext=on
cflags-y += -gdwarf-2
cflags-y += -gccinc
cflags-y += -cwd explicit
cflags-y += -msgstyle gcc
cflags-y += -maxerrors 10
cflags-y += -maxwarnings 10
cflags-$(CFG_OPT_RELEASE) += -opt level=2
cflags-$(CFG_OPT_DEBUG) += -opt off
cflags-$(CFG_OPT_FLAGS) += $(SELECT_OPT)
def-y += CFG_SPE_INIT
# Generate dependencies,
# Should be -MMD here but it only gives the *.c files (for some reason
# the compiler thinks all include files are system file, option?)
cflags-y += -gccdepends -MD
# Warnings
cflags-y += -W=most
#cflags-y += -requireprotos
# Conformance
cflags-y += -abi=eabi
cflags-$(CFG_VLE) += -ppc_asm_to_vle # Convert ppc to vle ppc
cflags-$(CFG_VLE) += -vle # Convert ppc to vle ppc
cflags-y += -abi=eabi
cflags-y += -proc=5565
cflags-$(CFG_EFPU)+= -fp=efpu
cflags-$(CFG_SPE_FPU_SCALAR_SINGLE) += -fp=spfp # spfp
cflags-$(CFG_SPE_FPU_SCALAR_SINGLE) += -spe_vector
#cflags-y += -use_isel=on
cflags-y += -sdata=0 -sdata2=0
# Get machine cflags
#cflags-y += $(cflags-$(CFG_ARCH))
CFLAGS = $(cflags-y) $(cflags-yy) $(CFLAGS_cw_$@)
CCOUT = -o $@
SELECT_CLIB?=CLIB_CW
# ---------------------------------------------------------------------------
# Preprocessor
CPP = $(CC) -E -P
CPPOUT = -precompile
CPP_ASM_FLAGS += -ppopt noline -ppopt nopragma -dialect c
comma = ,
empty =
space = $(empty) $(empty)
cw_lib_path += -L$(CW_COMPILE)/PowerPC_EABI_Support/Runtime/Lib
cw_lib_path += -L$(CW_COMPILE)/PowerPC_EABI_Support/MSL/MSL_C/PPC_EABI/Lib
cc_inc_path += $(CW_COMPILE)/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include
cc_inc_path += $(CW_COMPILE)/PowerPC_EABI_Support/MSL/MSL_C/PPC_EABI/Include
inc-y += $(cc_inc_path)
libpath-y += $(cw_lib_path)
# MSL library magic:
# MSL_C.PPCEABI.bare.SZ.VS.a
# - Softfloat, sdata=8
# -
# libnames .bare - No operating system
# V - VLE
# S - software float
# E - e500, e200
# UC - Noooooo, unsigned char??
# SZ - Size optimized
# nothing really matches.......
lib-$(CFG_VLE)-$(CFG_EFPU) += -lRuntime.PPCEABI.V.a
lib-$(CFG_VLE)-$(CFG_EFPU) += -lMSL_C.PPCEABI.bare.SZ.V.a
ifneq ($(CFG_VLE),y)
lib-$(CFG_EFPU) += -lRuntime.PPCEABI.E.a
lib-$(CFG_EFPU) += -lMSL_C.PPCEABI.bare.SZ.E.a
ifneq ($(CFG_EFPU),y)
lib-y += -lRuntime.PPCEABI.S.a
lib-y += -lMSL_C.PPCEABI.bare.SZ.S.a
endif
endif
ifneq ($(CFG_EFPU),y)
lib-$(CFG_VLE) += -lRuntime.PPCEABI.VS.a
lib-$(CFG_VLE) += -lMSL_C.PPCEABI.bare.SZ.VS.a
endif
lib-y += $(lib-y-y)
C_TO_ASM = -P
# ---------------------------------------------------------------------------
# Linker
#
# LDFLAGS - linker flags
# LDOUT - How to Generate linker output file
# LDMAPFILE - How to generate mapfile
# ldcmdfile-y - link cmd file
# libpath-y - lib paths
# libitem-y - the libs with path
# lib-y - the libs, without path
LD = $(CW_BIN)/mwldeppc.exe
LDSCRIPT = -lcf
# allow config to override base address
CFG_FLASH_ADR ?= 0x0
CFG_FLASH_LEN ?= 0x0
def-y += CFG_FLASH_ADR=$(CFG_FLASH_ADR)
def-y += CFG_FLASH_LEN=$(CFG_FLASH_LEN)
# To make "rom" images (make LOAD() work)
ldflags-y += -romaddr $(CFG_FLASH_ADR)
ldflags-y += -rambuffer $(CFG_FLASH_ADR)
#ldflags-y += -nodefaults
ldflags-y += -gdwarf-2
APP_START_SYMBOL?=_start
ldflags-y += -m $(APP_START_SYMBOL)
ldflags-y += -nostdlib
#ldflags-y += -code_merging all
TE = elf
ldflags-y += -map $(subst .$(TE),.map, $@)
ldflags-$(CFG_CREATE_SREC) += -srec $(subst .$(TE),.s3, $@)
LDFLAGS += $(ldflags-y)
LDOUT = -o $@
LD_FILE = -lcf
libitem-y += $(libitem-yy)
# ---------------------------------------------------------------------------
# Assembler
#
# ASFLAGS - assembler flags
# ASOUT - how to generate output file
AS = $(CW_BIN)/mwasmeppc.exe
asflags-y += -gnu_mode
asflags-y += -proc e500 -gdwarf-2
asflags-y += -maxerrors 10
asflags-y += -maxwarnings 10
asflags-$(CFG_VLE) += -vle
ASFLAGS += $(asflags-y)
ASOUT = -o $@
# ---------------------------------------------------------------------------
# Archiver
#
# AROUT - archiver flags
AR = $(CW_BIN)/mwldeppc.exe
ARFLAGS = -library
AROUT = $@
# CW license trick (since it does not cache license requests)
# - if there is license_arccore.dat file copy it to license.dat..remove after link again.
define do-ld-pre
${Q}if [ -f $(CW_COMPILE)/license_arccore.dat ]; then cp -v $(CW_COMPILE)/license_arccore.dat $(CW_COMPILE)/license.dat; fi
endef
define do-ld-post
${Q}if [ -f $(CW_COMPILE)/license_arccore.dat ];then rm -v $(CW_COMPILE)/license.dat; fi
endef
# Memory footprint
define do-memory-footprint
@gawk --non-decimal-data -f $(ROOTDIR)/scripts/memory_footprint_$(COMPILER).awk $(subst .elf,.map,$@)
endef
# Dependency generation
define do-compile-post
@sed -e "/.*PowerPC_EABI_Support/d;s/ \\\/ qqaass/;s/\\\/\//g;s/qqaass/\\\/" $(subst .o,.d,$@) > $(subst .o,.d,$@)d
@mv $(subst .o,.d,$@)d $(subst .o,.d,$@)
endef
define do-memory-footprint2-$(CFG_MEMORY_FOOTPRINT2)
@gawk -f $(ROOTDIR)/scripts/memory_footprint2_$(COMPILER).awk $(subst .$(TE),.map, $@)
endef
|
2301_81045437/classic-platform
|
scripts/cc_cw.mk
|
Makefile
|
unknown
| 5,981
|
# Diab versions and "features"
# - Can't handle initializtion with a depth more that 2,e.g. .NBYTESu.B.SMLOE = 1;
# - 5.6.0.0
# - Do NOT use. dialect-c99 makes const (.text) end up in .data section
# Seems to be no workarounds
# - 5.7.0.0
# - "-g3" option -Xkill-opt=0x080000
#
# Diab SPE
# The SPE consist of up to 4 APUs.
# 1. SPE APU - Vector stuff. 64-bit GPRS
# 2. Vector Single Prec. FP APU. 64-bit GPRS
# 3. Scalar Single Prec. FP APU. 32-bit GPRS
# 4. Scalar Double Prec. FP APU. 64-bit GPRS
# For more information see E500CORERM.pdf chapter
# 3.8.1 (SPE and Embedded Floating-Point APUs)
#
# Most cores with SPE have 1-3 and very few have 4 (e500v2)
#
# What does Diab generate for?
#
DIAB_VERSION?=5.9.3.0
DIAB_COMPILE ?= /c/devtools/WindRiver/diab/5.9.3.0/WIN32
DIAB_BIN = $(DIAB_COMPILE)/bin
# ---------------------------------------------------------------------------
# Compiler
# CCFLAGS - compile flags
CC = $(DIAB_BIN)/dcc
opt-cflags-$(CFG_OPT_RELEASE) += -g3 -O
opt-cflags-$(CFG_OPT_DEBUG) += -g2 -Xoptimized-debug-off
opt-cflags-$(CFG_OPT_SIZE) += -XO -Xsize-opt -g3
opt-cflags-$(CFG_OPT_FLAGS) += $(SELECT_OPT)
cflags-y+= -DBUILD_OPT_FLAGS="$(opt-cflags-y)"
cflags-y += $(opt-cflags-y)
ifeq ($(DIAB_TARGET),)
$(error DIAB_TARGET is not defined. Check your build_config.mk for it)
endif
cflags-y += -c
cflags-y += -Xdialect-c99
cflags-y += -Xc-new
cflags-y += -Xlibc-new
cflags-y += -Xkill-opt=0x080000 # Generates wrong code on 5.7 and 5.8
cflags-y += -Xsmall-data=0
cflags-y += -Xsmall-const=0
cflags-y += -Xno-common
cflags-y += -Xnested-interrupts
#cflags-y += -Xstop-on-warning
cflags-y += -Xsection-split
cflags-y += -Xforce-prototypes
cflags-y += -Xforce-declarations
#cflags-y += -XO
cflags-y += -D__BIG_ENDIAN__
# Enable inline and __ev64_opaque__
cflags-y += -Xkeywords=0x900004
#cflags-y += -Xstmw-slow
cflags-y += -ei4618
cflags-y += -Xmake-dependency=6
cflags-y += $(DIAB_TARGET)
cflags-y += -ei5388,5387
CFLAGS = $(cflags-y) $(cflags-yy) $(CFLAGS_diab_$@)
CCOUT = -o $@
SELECT_CLIB=CLIB_DIAB
CFG_ARC_CLIB?=y
cc_inc_path := $(realpath $(DIAB_BIN)/../../include/cnew) $(realpath $(DIAB_BIN)/../../include/diab)
# ---------------------------------------------------------------------------
# Preprocessor
CPP = $(CC) -P
CPPOUT = -o
CPP_ASM_FLAGS = $(DIAB_TARGET)
CPP_ASM_FLAGS += -Xpreprocess-assembly
#CPP_ASM_FLAGS += -Xkeep-assembly-file
# ---------------------------------------------------------------------------
# Linker
#
# LDFLAGS - linker flags
# LDOUT - How to Generate linker output file
# LDMAPFILE - How to generate mapfile
# ldcmdfile-y - link cmd file
# libpath-y - lib paths
# libitem-y - the libs with path
# lib-y - the libs, without path
LD = $(DIAB_BIN)/dld
LDFLAGS += $(DIAB_TARGET)
LDFLAGS += -m6
LDFLAGS += -Xremove-unused-sections
ifeq ($(DIAB_VERSION),5.9.3.0)
# Diab is having problems finding the right libs,
# so do it manually
lib-y +=-li
lib-y +=-lchar
lib-y +=-limpl
lib-y +=-limpfp
lib-y +=-lg
lib-y +=-lc
lib-y +=-lcfp
lib-y +=-lm
else ifeq ($(DIAB_VERSION),5.9.4.8)
# Picking libs manually as in 5.9.3.0
lib-y +=-li
lib-y +=-lchar
lib-y +=-limpl
lib-y +=-limpfp
lib-y +=-lg
lib-y +=-lc
lib-y +=-lcfp
lib-y +=-lm
else
lib-y +=-lc
lib-y +=-limpl
lib-y +=-lm
endif
LDOUT = -o $@
TE = elf
LDMAPFILE = > $(subst .elf,.map, $@)
libitem-y += $(libitem-yy)
LDFLAGS += $(ldflags-y)
# ---------------------------------------------------------------------------
# Assembler
# ---------------------------------------------------------------------------
AS = $(DIAB_BIN)/das
asflags-$(CFG_OPT_DEBUG) += -g
asflags-y += -Xsemi-is-newline
asflags-y += $(DIAB_TARGET)
ASOUT = -o $@
ASFLAGS += $(asflags-y)
# ---------------------------------------------------------------------------
OBJCOPY = $(DIAB_BIN)/ddump
# dump srecord, S3, no .bss
OBJCOPY_FLAGS = -Rv -m3
OBJCOPYOUT = -o
define do-objcopy
$(OBJCOPY) $(OBJCOPY_FLAGS) $< -o $@
endef
# ---------------------------------------------------------------------------
NM = $(tprefix-y)nm
# ---------------------------------------------------------------------------
# Archiver
AR = $(tprefix-y)ar
AROUT = $@
# ---------------------------------------------------------------------------
# PCLint
PCLINT_COMPILER_MAKEFILE = $(PCLINT_FILES_DIR)/co-gcc.mak GCC_BIN=$(CC)
PCLINT_COMPILER_SETTINGS_FILE = $(PCLINT_FILES_DIR)/co-gcc.lnt
# Memory footprint
define do-memory-footprint
@gawk --non-decimal-data -f $(ROOTDIR)/scripts/memory_footprint_$(COMPILER).awk $(subst .elf,.map,$@)
endef
define do-memory-footprint2-$(CFG_MEMORY_FOOTPRINT2)
@gawk -f $(ROOTDIR)/scripts/memory_footprint2_$(COMPILER).awk $(subst .$(TE),.map, $@)
endef
|
2301_81045437/classic-platform
|
scripts/cc_diab.mk
|
Makefile
|
unknown
| 5,026
|
HOST := $(shell uname)
export prefix
# If we are using codesourcery and cygwin..
ifneq ($(findstring CYGWIN,$(UNAME)),)
cygpath:= $(shell cygpath -m $(shell which cygpath))
export CYGPATH=$(cygpath)
endif
# Normal msys32: MINGW32_NT-6.2
# msys2-32bit : MINGW32_NT-6.3
# msys2-64bit : MINGW64_NT-6.3
ifneq ($(findstring MINGW32,$(HOST)),)
OS_32BIT=y
else
OS_64BIT=y
endif
# Arch specific settings
ifneq ($(ARCH),)
include $(ROOTDIR)/$(ARCH_KERNEL_PATH-y)/scripts/gcc.mk
endif
# Find version
gcc_version = $(shell ${CROSS_COMPILE}gcc --version | gawk -v VER=$(1) '{ if( VER >= strtonum(gensub(/\./,"","g",$$3)) ) print "y";exit }' )
CC_INFO := "$(shell ${CROSS_COMPILE}gcc --version | sed -n 1p )"
ifneq (,$(wildcard ${CROSS_COMPILE}g++))
CXX_INFO := "$(shell ${CROSS_COMPILE}g++ --version | sed -n 1p )"
endif
GCC_V430 = $(call gcc_version,430)
GCC_V340 = $(call gcc_version,340)
c_common_flags-y += -DCC_INFO=$(CC_INFO)
cxxflags-y += -DCXX_INFO=$(CXX_INFO)
#$(error $(gcc_info))
# ---------------------------------------------------------------------------
# Compiler
# CCFLAGS - compile flags
ifeq ($(CFG_BULLSEYE),y)
# Note!, trailing space after "-i"
CC_PRE=$(COV_BULLSEYE_PATH)/bin/covc -i
# Do sanity check...
# COV_BULLSEYE_REQ_VERSION
# $(error $(shell cat $(COV_BULLSEYE_PATH)/include/BullseyeCoverage.h))
# $(error adad)
endif
ifeq ($(CLANG_COMPILE),)
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
ifeq ($(CFG_BULLSEYE),y)
CC = $(CROSS_COMPILE)gcc
endif
else
CC = $(CROSS_COMPILE)$(CLANG_COMPILE)/clang
CFG_CLANG=y
endif
opt-cflags-$(CFG_OPT_RELEASE) += -O2
opt-cflags-$(CFG_OPT_DEBUG) += -g -O0
opt-cflags-$(CFG_OPT_SIZE) += -g -Os
opt-cflags-$(CFG_OPT_FLAGS) += $(SELECT_OPT)
c_common_flags-y+= -DBUILD_OPT_FLAGS="$(opt-cflags-y)"
c_common_flags-y += $(opt-cflags-y)
#cflags-$(CFG_CLANG) += -Weverything
# Remove sections if needed.. may be problems with other compilers here.
ifneq ($(CROSS_COMPILE),)
c_common_flags-y += -ffunction-sections
endif
#ifneq ($(filter -O2 -O3 -O1,$(cflags-y)),)
# cflags-y += -fno-schedule-insns -fno-schedule-insns2
#endif
c_common_flags-y += -c
#cflags-y += -fno-common
#cflags-y += -fmax-errors=20
c_common_flags-$(CFG_CLANG_SAFECODE) += -fmemsafety
# Generate dependencies
c_common_flags-y += -MMD
# Set C/C++ Standard
cflags-y += -std=gnu99
# Warnings
c_common_flags-y += -Wall
cflags-$(CFG_GNULINUX) += -fPIC
c_common_flags-$(GCC_V340) += -Wextra
#cflags-y += -Wstrict-prototypes # 3.4.6
#cflags-y += -Wold-style-definition # 3.4.6
#cflags-y += -Wmissing-prototypes # 3.4.6
#cflags-y += -Wmissing-declarations # 3.4.6
#cflags-y += -Wredundant-decls # 3.4.6
#cflags-y += -Wpointer-arith # 3.4.6
#cflags-y += -Wpadded # 3.4.6
#cflags-y += -Wconversion # 3.4.6 but not usable until 4.3.0
#cflags-$(GCC_V340)+= -Wextra
#cflags-$(GCC_V430)+= -Wconversion
#cflags-y += -pedantic
# Conformance
c_common_flags-y += -fno-strict-aliasing # Use restict keyword instead.
c_common_flags-y += -fno-builtin
# gcov
c_common_flags-$(CFG_GCOV) += -fprofile-arcs
c_common_flags-$(CFG_GCOV) += -ftest-coverage
# Get machine cflags
#cflags-y += $(cflags-$(ARCH))
c_common_flags-y += -gdwarf-2
cxxflags += $(c_common_flags-y)
CFLAGS = $(c_common_flags-y) $(cflags-y) $(cflags-yy)
CXXFLAGS = $(c_common_flags-y) $(cxxflags-y) $(cxxflags-yy)
CCOUT = -o $@
# ---------------------------------------------------------------------------
# Preprocessor
CPP = $(CC) -E -P
CPPOUT = -o
CPP_ASM_FLAGS = -x assembler-with-cpp
comma = ,
empty =
space = $(empty) $(empty)
# Note!
# Libs related to GCC(libgcc.a, libgcov.a) is located under
# lib/gcc/<machine>/<version>/<multilib>
# Libs related to the library (libc.a,libm.a,etc) are under:
# <machine>/lib/<multilib>
#
# Can't remember why haven't I just used gcc to link instead of ld? (it should
# figure out the things below by itself)
# It seems some versions of make want "\=" and some "="
# "=" - msys cpmake on windows 7
gcc_lib_path := "$(subst /libgcc.a,,$(shell $(CC) $(CFLAGS) --print-libgcc-file-name))"
gcc_lib_path := $(subst \libgcc.a,,$(gcc_lib_path))
ifeq ($(COMPILER_FLAVOR),s32_newlib)
gcc-sysroot="--sysroot=$(dir $(CC))../powerpc-eabivle/newlib"
endif
lib_lib_path := "$(subst /libc.a,,$(shell $(CC) $(CFLAGS) $(gcc-sysroot) --print-file-name=libc.a))"
lib_lib_path := $(subst \libc.a,,$(lib_lib_path))
ifeq ($(COMPILER_FLAVOR),hightec_dnk)
SELECT_CLIB?=CLIB_DNK
endif
#$(error $(lib_lib_path))
# Convert from
# c:/devtools/freescale/s32_power_v1.0/cross_tools/powerpc-eabivle-4_9/bin/../lib/gcc/powerpc-eabivle/4.9.2/fp/e200z3
# into
# c:/devtools/freescale/s32_power_v1.0/cross_tools/powerpc-eabivle-4_9/powerpc-eabivle/newlib/lib/fp/e200z3
# Get information from GCC and save it in gcc_path_probe.tmp
gcc_info := $(shell touch gcc_path_probe.c;$(CC) -v -c gcc_path_probe.c &> gcc_path_probe.tmp; rm gcc_path_probe.c)
# Extract the built in include paths from the information
gcc_include := $(subst \,/,$(shell gawk -f $(TOPDIR)/scripts/gcc_getinclude.awk gcc_path_probe.tmp; rm gcc_path_probe.tmp))
cc_inc_path := $(realpath $(gcc_include))
libpath-y += -L$(lib_lib_path)
libpath-y += -L$(gcc_lib_path)
ifeq ($(CC),gcc)
SELECT_CLIB?=CLIB_NATIVE
else
SELECT_CLIB?=CLIB_NEWLIB
endif
ifeq ($(SELECT_CLIB),CLIB_NEWLIB)
CFG_ARC_CLIB?=y
endif
ifeq ($(SELECT_CLIB),CLIB_DNK)
CFG_ARC_CLIB?=y
endif
# ---------------------------------------------------------------------------
# Linker
#
# LDFLAGS - linker flags
# LDOUT - How to Generate linker output file
# LDMAPFILE - How to generate mapfile
# ldcmdfile-y - link cmd file
# libpath-y - lib paths
# libitem-y - the libs with path
# lib-y - the libs, without path
LD = $(CROSS_COMPILE)ld
LD_FILE = -T
LDOUT = -o $@
ifeq ($(CROSS_COMPILE),)
TE=out
else
TE = elf
endif
ifneq ($(CROSS_COMPILE),)
ifneq ($(BOARDDIR),gnulinux)
LDFLAGS += --gc-section
endif
endif
ldflags-$(CFG_CLANG_SAFECODE) += -fmemsafety
ldflags-$(CFG_CLANG_SAFECODE) += -L$(CLANG_COMPILE)/../lib
# Don't use a map file if we are compiling for native target.
# gnulinux defines its own map file argument.
ifneq ($(CROSS_COMPILE),)
ifneq ($(BOARDDIR),gnulinux)
LDFLAGS += -Map $(subst .$(TE),.map, $@)
endif
endif
LDFLAGS += $(ldflags-y)
lib-$(CFG_GCOV) += -lgcov
libitem-y += $(libitem-yy)
ifdef CFG_CXX
LD_START_GRP = $(strip $(subst ",,$(gcc_lib_path)))/crti.o $(strip $(subst ",,$(gcc_lib_path)))/crtbegin.o --start-group
LD_END_GRP = --end-group $(strip $(subst ",,$(gcc_lib_path)))/crtend.o $(strip $(subst ",,$(gcc_lib_path)))/crtn.o
else
LD_START_GRP = --start-group
LD_END_GRP = --end-group
endif
#LDFLAGS += --gc-section
ifeq ($(CROSS_COMPILE)$(COMPILER),gcc)
ifeq ($(CFG_TCPIP_TEST),y)
LDFLAGS +=-lpthread
endif
endif
# ---------------------------------------------------------------------------
# Assembler
#
# ASFLAGS - assembler flags
# ASOUT - how to generate output file
AS = $(CROSS_COMPILE)as
ASFLAGS += $(asflags-y) $(asflags-y-y)
ASFLAGS += --gdwarf2
ASOUT = -o $@
# ---------------------------------------------------------------------------
# Dumper
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJCOPY_FLAGS = -O srec
# ---------------------------------------------------------------------------
# Archiver
#
# AROUT - archiver flags
AR = $(CROSS_COMPILE)ar
AROUT = $@
ARFLAGS =
define do-objcopy
$(OBJCOPY) $(OBJCOPY_FLAGS) $< $@
endef
ifdef CFG_HC1X
define do-memory-footprint
@$(CROSS_COMPILE)objdump -h $@ | gawk -f $(ROOTDIR)/scripts/hc1x_memory.awk
endef
else
define do-memory-footprint
@gawk --non-decimal-data -f $(ROOTDIR)/scripts/memory_footprint_gcc.awk $(subst .elf,.map,$@)
endef
endif
|
2301_81045437/classic-platform
|
scripts/cc_gcc.mk
|
Makefile
|
unknown
| 8,152
|
GHS_VERSION=201254
GHS_COMPILE?=/d/devtools/ghs/comp_201254
GHS_BIN = $(GHS_COMPILE)
#GHS_TARGET?=ppc560xc
GHS_TARGET?=ppc5514
# Arch specific settings
ifneq ($(ARCH),)
include $(ROOTDIR)/$(ARCH_KERNEL_PATH-y)/scripts/ghs.mk
endif
# ---------------------------------------------------------------------------
# Compiler
# CCFLAGS - compile flags
opt-cflags-$(CFG_OPT_RELEASE) += -Ospeed -OI -OB
opt-cflags-$(CFG_OPT_DEBUG) += -g -dwarf2 -Onone
opt-cflags-$(CFG_OPT_SIZE) += -g -dwarf2 -Osize
opt-cflags-$(CFG_OPT_FLAGS) += $(SELECT_OPT)
cflags-y+= -DBUILD_OPT_FLAGS="$(opt-cflags-y)"
cflags-y += $(opt-cflags-y)
ifeq ($(GHS_TARGET),)
$(error GHS_TARGET is not defined. Check your build_config.mk for it)
endif
cflags-y += -c
cflags-y += -c99
cflags-y += -cpu=$(GHS_TARGET)
# Generate dependencies
cflags-y += -MMD
# Diagnostics
cflags-y += -errmax=10
cflags-y += --diag_suppress 618
cflags-y += --diag_suppress 619
cflags-y += --no_wrap_diagnostics
CFLAGS = $(cflags-y) $(cflags-yy) $(CFLAGS_GHS_$@)
CCOUT = -o $@
CFG_ARC_CLIB?=y
# ---------------------------------------------------------------------------
# Preprocessor
CPP = $(CC) -E
CPPOUT = -o
CPP_ASM_FLAGS = -cpu=$(GHS_TARGET)
# ---------------------------------------------------------------------------
# Linker
#
# LDFLAGS - linker flags
# LDOUT - How to Generate linker output file
# LDMAPFILE - How to generate mapfile
# ldcmdfile-y - link cmd file
# libpath-y - lib paths
# libitem-y - the libs with path
# lib-y - the libs, without path
LDOUT = -o $@
TE = elf
LDMAPFILE =-map=$(strip $(subst .elf,.map, $@))
#LD_FILE2=-lnkcmd=
LD_FILE= -T
libitem-y += $(libitem-yy)
LDFLAGS += --nocpp
# Use our own startup, not GHS
LDFLAGS += -nostartfiles
#LDFLAGS += -v
LDFLAGS += -cpu=$(GHS_TARGET)
LDFLAGS += $(ldflags-y)
# ---------------------------------------------------------------------------
# Assembler
# ---------------------------------------------------------------------------
AS ?= $(GHS_BIN)/asppc
ASFLAGS-$(CFG_OPT_DEBUG) += -g
#ASFLAGS += -Xsemi-is-newline
ASFLAGS += -g
ASOUT = -o $@
# ---------------------------------------------------------------------------
OBJCOPY = $(GHS_BIN)/gsrec
OBJCOPY_FLAGS += -B -S3
# ---------------------------------------------------------------------------
NM = $(tprefix-y)nm
# ---------------------------------------------------------------------------
# Archiver
AR = $(tprefix-y)ar
AROUT = $@
# ---------------------------------------------------------------------------
# PCLint
PCLINT_COMPILER_MAKEFILE = $(PCLINT_FILES_DIR)/co-gcc.mak GCC_BIN=$(CC)
PCLINT_COMPILER_SETTINGS_FILE = $(PCLINT_FILES_DIR)/co-gcc.lnt
define do-objcopy
$(OBJCOPY) $(OBJCOPY_FLAGS) $< -o $@
endef
# GHS does not have multiline assembler sepateted by ";"... do we do it here manually
define do-sx-to-s-post
$(Q)gawk '{gsub(/;/,"\n")};1' $@ > $@.tmp; cp $@.tmp $@
endef
# Memory footprint
define do-memory-footprint
@gawk --non-decimal-data -f $(ROOTDIR)/scripts/memory_footprint_$(COMPILER).awk $(subst .elf,.map,$@)
endef
define do-memory-footprint2-$(CFG_MEMORY_FOOTPRINT2)
@gawk -f $(ROOTDIR)/scripts/memory_footprint2_$(COMPILER).awk $(subst .$(TE),.map, $@)
endef
|
2301_81045437/classic-platform
|
scripts/cc_ghs.mk
|
Makefile
|
unknown
| 3,390
|
# ========================================================================= #
# IAR compiler - Generic settings #
# ========================================================================= #
# ---------------------------------------------------------------------------
# Setting CC <compiler>
# ---------------------------------------------------------------------------
IAR_VERSION=8_0
IAR_COMPILE=/c/devtools/IAR/IAR_Systems/Embedded_Workbench_$(IAR_VERSION)/arm
IAR_BIN=$(IAR_COMPILE)/bin
IAR_LIB=$(IAR_COMPILE)/lib/dlib
# ---------------------------------------------------------------------------
# Arch specific settings
# Setting CC <compiler>
# Setting architecture specific cflags <compiler flags>
# Setting architecture specific asflags <assembler flags>
ifneq ($(ARCH),)
include $(ROOTDIR)/$(ARCH_KERNEL_PATH-y)/scripts/iar.mk
endif
cflags-y += -e
cflags-y += -c
#cflags-y += --no_clustering
#cflags-y += --no_mem_idioms
#cflags-y += --no_explicit_zero_opt
cflags-y += --thumb
cflags-y += -DDEBUG_HARDFAULT
cflags-y += --debug
cflags-y += --diag_suppress=Pa050,Pe550,Pe301,Pe047
#cflags-y += --aeabi
#cflags-y += --guard_calls
# z is the size options
cflags-$(CFG_OPT_RELEASE) += -Ohs
cflags-$(CFG_OPT_DEBUG) += -On
opt-cflags-$(CFG_OPT_SIZE) += -Ohz
cflags-$(CFG_OPT_FLAGS) += $(SELECT_OPT)
CFLAGS = $(cflags-y) $(cflags-yy)
CCOUT = -o $@
SELECT_CLIB?=CLIB_IAR
# ---------------------------------------------------------------------------
# Preprocessor
CPP = $(CC) --preprocess=n
comma = ,
empty =
space = $(empty) $(empty)
cc_inc_path += $(IAR_COMPILE)/inc/c
inc-y += $(cc_inc_path)
#libpath-y += $(IAR_COMPILE)/lib/rt7M_tl.a
# ---------------------------------------------------------------------------
# Linker
#
# LDFLAGS - linker flags
# LDOUT - How to Generate linker output file
# LDMAPFILE - How to generate mapfile
# ldcmdfile-y - link cmd file
# libpath-y - lib paths
# libitem-y - the libs with path
# lib-y - the libs, without path
#ldflags-y += --skip_dynamic_initialization
#ldflags-y += --enable_stack_usage
ldflags-y += --entry Reset_Handler
#ldflags-y += --no_library_search
#ldflags-y += --no_entry
ldflags-y += --diag_suppress Lp049
TE = elf
LDMAPFILE = --map $(subst .$(TE),.map, $@)
LDFLAGS += $(ldflags-y)
libitem-y += $(libitem-yy)
############################################
#ldflags-y += -s _start
#ldflags-y += -Felf -xms
# ---------------------------------------------------------------------------
# Assembler
#
# ASFLAGS - assembler flags
# ASOUT - how to generate output file
asflags-y += -r
ASFLAGS += $(asflags-y)
# Memory footprint
define do-memory-footprint
@gawk --non-decimal-data -f $(ROOTDIR)/scripts/memory_footprint_$(COMPILER).awk $(subst .elf,.map,$@)
endef
# Dependency generation
#define do-compile-post
# @sed -e "/.*PowerPC_EABI_Support/d;s/ \\\/ qqaass/;s/\\\/\//g;s/qqaass/\\\/" $(subst .o,.d,$@) > $(subst .o,.d,$@)d
# @mv $(subst .o,.d,$@)d $(subst .o,.d,$@)
#endef
define do-memory-footprint2-$(CFG_MEMORY_FOOTPRINT2)
@gawk -f $(ROOTDIR)/scripts/memory_footprint2_$(COMPILER).awk $(subst .$(TE),.map, $@)
endef
|
2301_81045437/classic-platform
|
scripts/cc_iar.mk
|
Makefile
|
unknown
| 3,267
|
lintdef_ext=-d
lintinc_ext=-i
ifeq (${COMPILER},cw)
lint_extra=+v -b -i$(TOPDIR)/scripts/pclint -i$(TOPDIR)/scripts/pclint/lnt cw.lnt
else ifeq (${COMPILER},ghs)
ifeq (${ARCH},rh850_x)
lint_extra=-i$(GHS_COMPILE)/include/v800 -d__v800__ -d__LITTLE_ENDIAN__ -d__V850__ -d__V850
else
lint_extra=-i$(GHS_COMPILE)/include/ppc -d__ppc
endif
lint_extra+=+v -b -i$(TOPDIR)/scripts/pclint -i$(GHS_COMPILE)/ansi -i$(TOPDIR)/scripts/pclint/lnt ghs.lnt
else ifeq (${COMPILER},armcc)
lint_extra=+v -b -i$(ARMCC_COMPILE)/include -i$(TOPDIR)/scripts/pclint -i$(TOPDIR)/scripts/pclint/lnt armcc.lnt
else
# Use Gcc settings for all other compilers
lint_extra=+v -b -i$(TOPDIR)/scripts/pclint -i$(TOPDIR)/scripts/pclint/lnt $(addprefix $(lintinc_ext),$(cc_inc_path)) gcc.lnt
ifeq (${ARCH},aurix)
lint_extra+=-d__HIGHTEC__
endif
endif
ifeq (${ALLOW_LINT_WARNINGS},y)
lint_extra += -zero
endif
lint_extra += ${LINT_EXTRA}
|
2301_81045437/classic-platform
|
scripts/cc_pclint.mk
|
Makefile
|
unknown
| 946
|
lintdef_ext=-D
lintinc_ext=-I
#splint_extra=+v -b -i$(TOPDIR)/scripts/pclint -i$(TOPDIR)/scripts/pclint/lnt std.lnt
splint_extra=+nolib
inc-y += $(cc_inc_path)
#lint_files=$(TOPDIR)/scripts/lint/std.lnt
#lint_files=$(TOPDIR)/scripts/lint/lnt/au-misra2.lnt
#lint_files+=$(TOPDIR)/scripts/lint/lnt/au-misra2.lnt
#$(addprefix -i,$(abs-inc-y)) /C/lint/std.lnt $(abspath $<))
|
2301_81045437/classic-platform
|
scripts/cc_splint.mk
|
Makefile
|
unknown
| 387
|
import optparse
import re
import math
app = []
sec = []
bla = []
if __name__ == '__main__':
parser = optparse.OptionParser()
(options, args) = parser.parse_args()
print args
f = open(args[0],'r')
# __OS_START_SEC_app_bss_<app>
# __OS_START_SEC_app_bss_<app>
for line in iter(f):
m = re.match(r'.*(0x.*?)[ ]+__OS_(START|STOP)_SEC_(.*?)_(.*?)_(.*?) =.*',line)
if (m):
_addr = m.group(1)
_addr_type = m.group(2)
_group = m.group(3)
_subgroup = m.group(4)
_id = m.group(5)
t=(_addr,_addr_type,_group,_subgroup,_id)
sec.append(t)
f.close()
# sort it
sec_sorted = sorted(sec,key=lambda x: x[4]+x[3]+x[2]+x[1])
for e in sec_sorted:
if ("STOP" in e[1]):
size = int(e[0],0) - int(start,0)
if (size != 0):
q = math.pow(2,math.ceil(math.log((size*2 - 1),2)) - 1 )
else:
q = 0
print "%20s %5s %10s %10s %6X %06X" % (e[4],e[3],start,e[0],size,q)
if ((int(start,0)+q) != int(e[0],0)):
print "[The above region is not aligned]"
else:
start=e[0]
#print e
|
2301_81045437/classic-platform
|
scripts/extract_regions.py
|
Python
|
unknown
| 1,319
|
#!/bin/bash
DIR=`pwd`;
HEADER_FILES=`find $DIR -name '*.h'`;
#echo "Header files: $HEADER_FILES"
echo "Mismatches:"
for HEADER_FILE in $HEADER_FILES; do
SHORTNAME=`basename $HEADER_FILE`
MATCHNAME=`echo $SHORTNAME|sed 's/\./\\\\./'`
echo "Investigating references to $SHORTNAME (found at $HEADER_FILE)..."
grep -rniI [/\"]$MATCHNAME --exclude '*.d' $DIR/* | grep -v $MATCHNAME
done;
echo "Done!";
|
2301_81045437/classic-platform
|
scripts/fix_includes.sh
|
Shell
|
unknown
| 423
|
#
# Get include dirs from:
# touch apa.c
# gcc -v -c apa.c
#
# "#include <...> search starts here:" to "End of search list."
#
/#include <...> search starts here:/,/End of search list/ {
if (!(($1=="#include")||($1=="End")))
print $0
}
|
2301_81045437/classic-platform
|
scripts/gcc_getinclude.awk
|
Awk
|
unknown
| 262
|
/^#define[ \t]+_ARCTIC_CORE_MAJOR_/ {
core_major=strtonum($3)
}
/^#define[ \t]+_ARCTIC_CORE_MINOR_/ {
core_minor=strtonum($3)
}
/^#define[ \t]+_ARCTIC_CORE_PATCHLEVEL_/ {
core_patch=strtonum($3)
}
/^#define[ \t]+_ARCTIC_CORE_BUILDTYPE_/ {
core_buildtype=$3
}
END {
printf "v%d%c%d%c%d%c%s\n", core_major,type,core_minor,type,core_patch,type,core_buildtype;
}
|
2301_81045437/classic-platform
|
scripts/get_version.awk
|
Awk
|
unknown
| 387
|
#/bin/bash
#
# Tries to get a compiler depending on SHELL/OS. On Windows it defaults
# to CodeSourcery installed at c:\devtools\Codesourcery\<arch>
#
UNAME=`uname`
echo $UNAME
echo $1
if [ "$ARCH" == "PPC" ]; then
if test x${UNAME:0:7} = xMINGW32; then
COMPILER=/c/devtools/Codesourcery/freescale-4.3/bin/powerpc-eabi-
elif test x${UNAME:0:9} = xCYGWIN_NT; then
COMPILER=/cygdrive/c/devtools/Codesourcery/freescale-4.3/bin/powerpc-eabi-
elif test x${UNAME:0:5} = xDarwin; then
COMPILER=/opt/powerpc-eabi/bin/powerpc-eabi-
else
echo No default path for $UNAME set. Quitting.
fi
elif [ "$ARCH" == "ARM" ]; then
if test x${UNAME:0:7} = xMINGW32; then
COMPILER=/c/devtools/Codesourcery/arm-2009q1/bin/arm-none-eabi-
elif test x${UNAME:0:9} = xCYGWIN_NT; then
COMPILER=/cygdrive/c/devtools/Codesourcery/arm-2009q1/bin/arm-none-eabi-
elif test x${UNAME:0:5} = xDarwin; then
COMPILER=/opt/arm-elf/bin/arm-none-eabi-
else
echo No default path for $UNAME set. Quitting.
fi
elif [ "$ARCH" == "HCS12" ]; then
COMPILER=/opt/m6812-elf/bin/m6812-elf-
else
echo baaaad
fi
if [ -f ${COMPILER}gcc ]; then
echo Using compiler: ${COMPILER}
else
echo ${COMPILER} does not exist...
exit 1
fi
export CROSS_COMPILE=$COMPILER
|
2301_81045437/classic-platform
|
scripts/guess_cc.sh
|
Shell
|
unknown
| 1,296
|
"""
Description
Will generate some files to aid in writing MemMap jobs. Files created are:
For linker file:
- linkscript_bss_diab.ldf
- linkscript_data_diab.ldf
- linkscript_data_rom_diab.ldf
For MemMap file:
- MemMap_part1.h
- MemMap_part2.h
Include the MemMap files into the normal MemMap.h file.
Include the linker file parts into the linker file.
It will only generate sections that are related to the RTE, e.g.
- <PREFIX>_START_SEC_VAR_CLEARED_UNSPECIFIED
- <PREFIX>_START_SEC_VAR_INIT_UNSPECIFIED
- <PREFIX>_START_SEC_VAR_CALIB_UNSPECIFIED
Usage:
python ../../../core/scripts/memmap.py config/mpc5516it/Rte/MemMap/
Limitations:
The obvious way to do find "mapping" between the SWC and a partition would
be to read the model... but short of time.
- STOP sections are generated but contains nothing
"""
import optparse
import re
import os
mapping = {
'ApplicationModeManagerType':'TrustedPartition',
'ApplicationModeUserType':'TrustedPartition',
'CalibrationComponentType':'TrustedPartition',
'ComplexDeviceDriverComponentType':'TrustedPartition',
'Dem':'TrustedPartition',
'EcuAbstractionComponentType':'TrustedPartition',
'ExclusiveAreaComponentType':'TrustedPartition',
'ExclusiveAreaMultiComponentType':'TrustedPartition',
'ExclusiveAreaRelayType':'TrustedPartition',
'MonitorComponentType':'TrustedPartition',
'MultiComponentType2':'UntrustedPartion1',
'MultiComponentType':'UntrustedPartion1',
'ParameterComponentType':'TrustedPartition',
'PimComponentType':'TrustedPartition',
'ReaderComponentType':'TrustedPartition',
'Rte':'TrustedPartition',
'SensorComponentType':'TrustedPartition',
'SingleReaderComponentType':'UntrustedPartion2',
'SingleWriterComponentType':'UntrustedPartion2',
'SlaveCoreComponentType':'SlaveCoreParition',
'UntrustedComponentType1':'UntrustedPartion1',
'UntrustedComponentType2':'UntrustedPartion2',
'UntrustedParameterComponentType':'UntrustedPartion1',
'WriterComponentType':'TrustedPartition',
}
taskMapping = {
'UntrustedPartion1':['AsynchronousServers1','UntrustedTask1'],
'UntrustedPartion2':['UntrustedTask2','AsynchronousServers2','SingleWriterComponent_ServerPort1_enumOp'],
'TrustedPartition':['BasicTask2','BasicTask5','BasicTask7','BasicTask9','EventsBasicTask','EventsExtendedTask','ExtendedTask1','ExtendedTask2','TestMaster'],
'SlaveCoreParition':['SlaveCoreTask']
}
class Emitter_MemMap:
def __init__(self):
self.file_def = open("MemMap_part1.h",'w')
self.file = open("MemMap_part2.h",'w')
def __del__(self):
self.file.close()
self.file_def.close()
def addPartition(self,partition):
self.file_def.write("#define " + partition.upper() + "_VAR_INIT_UNSPECIFIED __attribute__ ((section (\"." + partition.lower() + "_data\")))\n")
self.file_def.write("#define " + partition.upper() + "_VAR_CLEARED_UNSPECIFIED __attribute__ ((section (\"." + partition.lower() + "_bss\")))\n")
def add(self, swc, partition ):
self.file.write("#ifdef %s_START_SEC_VAR_CLEARED_UNSPECIFIED\n" % (swc))
self.file.write("%s_VAR_CLEARED_UNSPECIFIED\n" % (partition))
self.file.write("#endif\n\n")
self.file.write("#ifdef %s_START_SEC_VAR_INIT_UNSPECIFIED\n" % (swc))
self.file.write("%s_VAR_INIT_UNSPECIFIED\n" % (partition))
self.file.write("#endif\n\n")
self.file.write("")
self.file.write("#ifdef %s_START_SEC_VAR_CALIB_UNSPECIFIED\n" % (swc))
self.file.write("%s_VAR_CALIB_UNSPECIFIED\n" % (partition))
self.file.write("#endif\n\n")
self.file.write("#ifdef %s_STOP_SEC_VAR_CLEARED_UNSPECIFIED\n" % (swc))
self.file.write("#endif\n\n")
self.file.write("#ifdef %s_STOP_SEC_VAR_INIT_UNSPECIFIED\n" % (swc))
self.file.write("#endif\n\n")
self.file.write("")
self.file.write("#ifdef %s_STOP_SEC_VAR_CALIB_UNSPECIFIED\n" % (swc))
self.file.write("#endif\n\n")
class Emitter_Linker:
def __init__(self):
self.file_bss_diab = open("linkscript_bss_diab.ldf",'w')
self.file_data_diab = open("linkscript_data_diab.ldf",'w')
self.file_data_rom_diab = open("linkscript_data_rom_diab.ldf",'w')
def __del__(self):
self.file_bss_diab.close()
self.file_data_diab.close()
self.file_data_rom_diab.close()
def add(self, partition, tasks ):
for x in tasks:
self.file_data_diab.write("__OS_START_SEC_data_" + x + " = .;\n")
self.file_bss_diab.write("__OS_START_SEC_bss_" + x + " = .;\n")
self.file_data_diab.write("." + partition.lower() + "_data (DATA) LOAD(__" + partition.upper() + "_ROM) : {}\n")
self.file_bss_diab.write("." + partition.lower() + "_bss (BSS) : {}\n")
self.file_data_rom_diab.write("__" + partition.upper() + "_ROM = .;\n")
self.file_data_rom_diab.write(".=.+SIZEOF(." + partition.lower() + "_data);\n" )
for x in tasks:
self.file_data_diab.write("__OS_STOP_SEC_data_" + x + " = .;\n")
self.file_bss_diab.write("__OS_STOP_SEC_bss_" + x + " = .;\n")
if __name__ == "__main__":
parser = optparse.OptionParser()
(options, args) = parser.parse_args()
if len(args) != 1:
parser.error("Need path to RTE MemMap files")
# Grab all swc's
memmap = Emitter_MemMap()
linker_diab = Emitter_Linker()
apa=os.listdir(args[0]);
for file in apa:
m = re.search('^(.*)_MemMap.h',file)
swc = m.group(1)
# print swc
partition = mapping[swc];
memmap.add(swc, partition.upper())
for partition in taskMapping:
linker_diab.add(partition, taskMapping[partition])
memmap.addPartition(partition)
|
2301_81045437/classic-platform
|
scripts/memmap.py
|
Python
|
unknown
| 5,695
|
#
# A small script that parses a codewarrior mapfile and produces
# lists of object files and how much .data and .bss they take.
#
# Usage: gawk -f <this_file> <mapfile>
function collect( section ) {
getline
getline
getline
while( getline > 0 ) {
if( $0 ~ /^.$/ ) {
break;
}
if ( $6 ~ /^\.[a-z]/ ) {
curr_obj = $7
section[curr_obj]=strtonum("0x" $2)
}
}
}
# sorting
# http://stackoverflow.com/questions/5342782/sort-associative-array-with-awk
function sort_and_print( arr , indices , tmpidx ) {
for (i in arr) {
tmpidx[sprintf("%12s", arr[i]),i] = i
}
num = asorti(tmpidx)
j = 0
for (i=1; i<=num; i++) {
split(tmpidx[i], tmp, SUBSEP)
indices[++j] = tmp[2]
}
for (i=num; i>0; i--) {
printf("%35s %d\n",indices[i], arr[indices[i]])
}
}
/^\.data/{
collect(data_sec)
}
/^\.bss/{
collect(bss_sec)
}
END {
printf " .data\n----------------------------------------------\n"
sort_and_print(data_sec)
printf " .bss\n----------------------------------------------\n"
sort_and_print(bss_sec)
}
|
2301_81045437/classic-platform
|
scripts/memory_footprint2_cw.awk
|
Awk
|
unknown
| 1,111
|
/^[ \t]+__rom_start/ {
rom_start=strtonum("0x"$2)
}
/^[ \t]+__rom_end/ {
rom_end=strtonum("0x"$2)
}
/^[ \t]+__ram_start/ {
ram_start=strtonum("0x"$2)
}
/^[ \t]+__ram_end/ {
ram_end=strtonum("0x"$2)
}
END {
kilobyte = 1024
printf " ROM %8x %8x %10.1f\n", rom_start, rom_end, (rom_end-rom_start)/kilobyte;
printf " RAM %8x %8x %10.1f\n", ram_start, ram_end, (ram_end-ram_start)/kilobyte;
}
|
2301_81045437/classic-platform
|
scripts/memory_footprint_cw.awk
|
Awk
|
unknown
| 426
|
/^[ \t]+__rom_start/ {
rom_start=strtonum("0x"$2)
}
/^[ \t]+__rom_end/ {
rom_end=strtonum("0x"$2)
}
/^[ \t]+__ram_start/ {
ram_start=strtonum("0x"$2)
}
/^[ \t]+__ram_end/ {
ram_end=strtonum("0x"$2)
}
END {
kilobyte = 1024
printf " ROM %8x %8x %10.1f\n", rom_start, rom_end, (rom_end-rom_start)/kilobyte;
printf " RAM %8x %8x %10.1f\n", ram_start, ram_end, (ram_end-ram_start)/kilobyte;
}
|
2301_81045437/classic-platform
|
scripts/memory_footprint_diab.awk
|
Awk
|
unknown
| 426
|
BEGIN {
kilobyte = 1024
print " >> Image size: (decimal)"
}
/^\.text/ {
text += $3;
rom+=$3
};
/^\.data/ {
data += $3;
rom+=$3;
ram+=$3
};
/^\.bss/ {
bss += $3;
ram+=$3
};
END {
printf "%-10s %10s %10.1f %s\n", " text:", text " B", text/kilobyte, "kB";
printf "%-10s %10s %10.1f %s\n", " data:", data " B", data/kilobyte, "kB";
printf "%-10s %10s %10.1f %s\n", " bss:", bss " B", bss/kilobyte, "kB";
printf "%-10s %10s %10.1f %s\n", " ROM:", rom " B", rom/kilobyte, "kB";
printf "%-10s %10s %10.1f %s\n", " RAM:", ram " B", ram/kilobyte, "kB";
}
|
2301_81045437/classic-platform
|
scripts/memory_footprint_gcc.awk
|
Awk
|
unknown
| 613
|
/^[ \t]+[0-9a-f]+\+[0-9a-f]+[ \t]+__rom_start/ {
rom_start=strtonum("0x"$1)
}
/^[ \t]+[0-9a-f]+\+[0-9a-f]+[ \t]+__rom_end/ {
rom_end=strtonum("0x"$1)
}
/^[ \t]+[0-9a-f]+\+[0-9a-f]+[ \t]+__ram_start/ {
ram_start=strtonum("0x"$1)
}
/^[ \t]+[0-9a-f]+\+[0-9a-f]+[ \t]+__ram_end/ {
ram_end=strtonum("0x"$1)
}
/^[ \t]+[0-9a-f]+\+[0-9a-f]+[ \t]+__total_ram/ {
total_ram=strtonum("0x"$1)
}
END {
kilobyte = 1024
printf " ROM %8x %8x %10.1f\n", rom_start, rom_end, (rom_end-rom_start)/kilobyte;
printf " RAM %8x %8x %10.1f\n", ram_start, ram_end, (ram_end-ram_start)/kilobyte;
printf " TOTAL RAM %8x %8x %10.1f\n", ram_start, total_ram, (total_ram-ram_start)/kilobyte;
}
|
2301_81045437/classic-platform
|
scripts/memory_footprint_ghs.awk
|
Awk
|
unknown
| 713
|
#ifndef CO_GCC_H_
#define CO_GCC_H_
#ifdef _lint /* Make sure no compiler comes this way */
#ifdef __cplusplus
extern "C" {
#endif
/* Standard library headers typically define the assert macro so that it
expands to a complicated conditional expression that uses special
funtions that Lint does not know about by default. For linting
purposes, we can simplify things a bit by forcing assert() to expand to
a call to a special function that has the appropriate 'assert'
semantics.
*/
//lint -function( __assert, __lint_assert )
void __lint_assert( int );
//lint ++d"assert(e)=__lint_assert(!!(e))"
//(++d makes this definition permanently immutable for the Lint run.)
//Now that we've made our own 'assert', we need to keep people from being
//punished when the marco in 'assert.h' appears not to be used:
//lint -efile(766,*assert.h)
/*
The headers included below must be generated; For C++, generate
with:
g++ [usual build options] -E -dM t.cpp >lint_cppmac.h
For C, generate with:
gcc [usual build options] -E -dM t.c >lint_cmac.h
...where "t.cpp" and "t.c" are empty source files.
It's important to use the same compiler options used when compiling
project code because they can affect the existence and precise
definitions of certain predefined macros. See gcc-readme.txt for
details and a tutorial.
*/
#if defined(__cplusplus)
# include "lint_cppmac.h"
#else
# include "lint_cmac.h"
#endif
/* If the macro set given by the generated macro files must be adjusted in
order for Lint to cope, then you can make those adjustments here.
*/
#define LINT_CO_GCC_H_GCC_VERSION ( __GNUC__ * 10000 + \
__GNUC_MINOR__ * 100 + \
__GNUC_PATCHLEVEL__ )
/* The following is a workaround for versions of GCC with bug 25717, in
which the preprocessor does not dump a #define directive for __STDC__
when -dM is given:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25717
We know the unconditional definition of __STDC__ was introduced no
later than version 3.0; the preprocessor bug was fixed no later than
version 4.1.0.
*/
#if ( LINT_CO_GCC_H_GCC_VERSION >= 30000 && \
LINT_CO_GCC_H_GCC_VERSION < 40100 )
# define __STDC__ 1
#endif
#if LINT_CO_GCC_H_GCC_VERSION >= 40300
# define __COUNTER__ __lint__COUNTER__
//lint +rw( *type_traits ) // Enable type traits support
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _lint */
#endif /* CO_GCC_H_ */
|
2301_81045437/classic-platform
|
scripts/pclint/lnt/co-gcc.h
|
C
|
unknown
| 2,659
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#define my_get_spr(a) ((uint32_t)(*(volatile uint32_t *)a))
#define my_set_spr(a,b) ((void)b)
|
2301_81045437/classic-platform
|
scripts/pclint/lnt/lint-cw.h
|
C
|
unknown
| 852
|
#define __DBL_MIN_EXP__ (-1021)
#define __UINT_LEAST16_MAX__ 65535
#define __FLT_MIN__ 1.17549435082228750797e-38F
#define __UINT_LEAST8_TYPE__ unsigned char
#define _WIN32 1
#define __INTMAX_C(c) c ## LL
#define __CHAR_BIT__ 8
#define __UINT8_MAX__ 255
#define __WINT_MAX__ 65535
#define __SIZE_MAX__ 4294967295U
#define __WCHAR_MAX__ 65535
#define __DBL_DENORM_MIN__ ((double)4.94065645841246544177e-324L)
#define __FLT_EVAL_METHOD__ 2
#define __UINT_FAST64_MAX__ 18446744073709551615ULL
#define __SIG_ATOMIC_TYPE__ int
#define __DBL_MIN_10_EXP__ (-307)
#define __FINITE_MATH_ONLY__ 0
#define __GNUC_PATCHLEVEL__ 0
#define __UINT_FAST8_MAX__ 255
#define _stdcall __attribute__((__stdcall__))
#define __DEC64_MAX_EXP__ 385
#define __INT8_C(c) c
#define __UINT_LEAST64_MAX__ 18446744073709551615ULL
#define __SHRT_MAX__ 32767
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
#define __UINT_LEAST8_MAX__ 255
#define __GXX_TYPEINFO_EQUALITY_INLINE 0
#define __UINTMAX_TYPE__ long long unsigned int
#define __DEC32_EPSILON__ 1E-6DF
#define __UINT32_MAX__ 4294967295U
#define __LDBL_MAX_EXP__ 16384
#define __WINT_MIN__ 0
#define __SCHAR_MAX__ 127
#define __WCHAR_MIN__ 0
#define __INT64_C(c) c ## LL
#define __DBL_DIG__ 15
#define __SIZEOF_INT__ 4
#define __SIZEOF_POINTER__ 4
#define __USER_LABEL_PREFIX__ _
#define __STDC_HOSTED__ 1
#define __WIN32 1
#define __LDBL_HAS_INFINITY__ 1
#define __FLT_EPSILON__ 1.19209289550781250000e-7F
#define __LDBL_MIN__ 3.36210314311209350626e-4932L
#define __DEC32_MAX__ 9.999999E96DF
#define __MINGW32__ 1
#define __INT32_MAX__ 2147483647
#define __SIZEOF_LONG__ 4
#define __UINT16_C(c) c
#define __DECIMAL_DIG__ 21
#define __LDBL_HAS_QUIET_NAN__ 1
#define __GNUC__ 4
#define _cdecl __attribute__((__cdecl__))
#define __FLT_HAS_DENORM__ 1
#define __SIZEOF_LONG_DOUBLE__ 12
#define __BIGGEST_ALIGNMENT__ 16
#define __DBL_MAX__ ((double)1.79769313486231570815e+308L)
#define __INT_FAST32_MAX__ 2147483647
#define __WINNT 1
#define __DBL_HAS_INFINITY__ 1
#define __WINNT__ 1
#define __DEC32_MIN_EXP__ (-94)
#define __INT_FAST16_TYPE__ short int
#define _fastcall __attribute__((__fastcall__))
#define __LDBL_HAS_DENORM__ 1
#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
#define __INT_LEAST32_MAX__ 2147483647
#define __DEC32_MIN__ 1E-95DF
#define __DBL_MAX_EXP__ 1024
#define __DEC128_EPSILON__ 1E-33DL
#define __WIN32__ 1
#define __PTRDIFF_MAX__ 2147483647
#define __LONG_LONG_MAX__ 9223372036854775807LL
#define __SIZEOF_SIZE_T__ 4
#define __SIZEOF_WINT_T__ 2
#define __GXX_ABI_VERSION 1002
#define __FLT_MIN_EXP__ (-125)
#define __INT_FAST64_TYPE__ long long int
#define __DBL_MIN__ ((double)2.22507385850720138309e-308L)
#define __tune_i386__ 1
#define __DEC128_MIN__ 1E-6143DL
#define __REGISTER_PREFIX__
#define __UINT16_MAX__ 65535
#define __DBL_HAS_DENORM__ 1
#define __cdecl __attribute__((__cdecl__))
#define __UINT8_TYPE__ unsigned char
#define __NO_INLINE__ 1
#define __i386 1
#define __FLT_MANT_DIG__ 24
#define __VERSION__ "4.5.0 20100311 (experimental)"
#define __UINT64_C(c) c ## ULL
#define _X86_ 1
#define __INT32_C(c) c
#define __DEC64_EPSILON__ 1E-15DD
#define __DEC128_MIN_EXP__ (-6142)
#define __INT_FAST32_TYPE__ int
#define __UINT_LEAST16_TYPE__ short unsigned int
#define __INT16_MAX__ 32767
#define __i386__ 1
#define __SIZE_TYPE__ unsigned int
#define __UINT64_MAX__ 18446744073709551615ULL
#define __INT8_TYPE__ signed char
#define __FLT_RADIX__ 2
#define __INT_LEAST16_TYPE__ short int
#define __LDBL_EPSILON__ 1.08420217248550443401e-19L
#define __UINTMAX_C(c) c ## ULL
#define __SIG_ATOMIC_MAX__ 2147483647
#define __SIZEOF_PTRDIFF_T__ 4
#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
#define __MSVCRT__ 1
#define __INT_FAST16_MAX__ 32767
#define __UINT_FAST32_MAX__ 4294967295U
#define __UINT_LEAST64_TYPE__ long long unsigned int
#define __FLT_HAS_QUIET_NAN__ 1
#define __FLT_MAX_10_EXP__ 38
#define __LONG_MAX__ 2147483647L
#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
#define __FLT_HAS_INFINITY__ 1
#define __UINT_FAST16_TYPE__ short unsigned int
#define __DEC64_MAX__ 9.999999999999999E384DD
#define __CHAR16_TYPE__ short unsigned int
#define __PRAGMA_REDEFINE_EXTNAME 1
#define __INT_LEAST16_MAX__ 32767
#define __DEC64_MANT_DIG__ 16
#define __INT64_MAX__ 9223372036854775807LL
#define __UINT_LEAST32_MAX__ 4294967295U
#define __INT_LEAST64_TYPE__ long long int
#define __INT16_TYPE__ short int
#define __INT_LEAST8_TYPE__ signed char
#define __DEC32_MAX_EXP__ 97
#define __INT_FAST8_MAX__ 127
#define __INTPTR_MAX__ 2147483647
#define __GXX_MERGED_TYPEINFO_NAMES 0
#define __stdcall __attribute__((__stdcall__))
#define __LDBL_MANT_DIG__ 64
#define __DBL_HAS_QUIET_NAN__ 1
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
#define __INTPTR_TYPE__ int
#define __UINT16_TYPE__ short unsigned int
#define __WCHAR_TYPE__ short unsigned int
#define __SIZEOF_FLOAT__ 4
#define __UINTPTR_MAX__ 4294967295U
#define __DEC64_MIN_EXP__ (-382)
#define __INT_FAST64_MAX__ 9223372036854775807LL
#define __FLT_DIG__ 6
#define __UINT_FAST64_TYPE__ long long unsigned int
#define __INT_MAX__ 2147483647
#define WIN32 1
#define __INT64_TYPE__ long long int
#define __FLT_MAX_EXP__ 128
#define __DBL_MANT_DIG__ 53
#define __INT_LEAST64_MAX__ 9223372036854775807LL
#define __DEC64_MIN__ 1E-383DD
#define __WINT_TYPE__ short unsigned int
#define __UINT_LEAST32_TYPE__ unsigned int
#define __SIZEOF_SHORT__ 2
#define __LDBL_MIN_EXP__ (-16381)
#define __INT_LEAST8_MAX__ 127
#define __LDBL_MAX_10_EXP__ 4932
#define __DBL_EPSILON__ ((double)2.22044604925031308085e-16L)
#define __UINT8_C(c) c
#define __INT_LEAST32_TYPE__ int
#define __SIZEOF_WCHAR_T__ 2
#define __UINT64_TYPE__ long long unsigned int
#define __INT_FAST8_TYPE__ signed char
#define __fastcall __attribute__((__fastcall__))
#define __DEC_EVAL_METHOD__ 2
#define __UINT32_C(c) c ## U
#define __INTMAX_MAX__ 9223372036854775807LL
#define WINNT 1
#define __FLT_DENORM_MIN__ 1.40129846432481707092e-45F
#define __INT8_MAX__ 127
#define __UINT_FAST32_TYPE__ unsigned int
#define __CHAR32_TYPE__ unsigned int
#define __FLT_MAX__ 3.40282346638528859812e+38F
#define __INT32_TYPE__ int
#define __SIZEOF_DOUBLE__ 8
#define __FLT_MIN_10_EXP__ (-37)
#define __INTMAX_TYPE__ long long int
#define i386 1
#define _INTEGRAL_MAX_BITS 64
#define __DEC128_MAX_EXP__ 6145
#define __GNUC_MINOR__ 5
#define __UINTMAX_MAX__ 18446744073709551615ULL
#define __DEC32_MANT_DIG__ 7
#define __DBL_MAX_10_EXP__ 308
#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
#define __INT16_C(c) c
#define __STDC__ 1
#define __PTRDIFF_TYPE__ int
#define __UINT32_TYPE__ unsigned int
#define __UINTPTR_TYPE__ unsigned int
#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
#define __DEC128_MANT_DIG__ 34
#define __LDBL_MIN_10_EXP__ (-4931)
#define __SIZEOF_LONG_LONG__ 8
#define __LDBL_DIG__ 18
#define __UINT_FAST16_MAX__ 65535
#define __GNUC_GNU_INLINE__ 1
#define __UINT_FAST8_TYPE__ unsigned char
#define __declspec(x) __attribute__((x))
|
2301_81045437/classic-platform
|
scripts/pclint/lnt/lint_cmac.h
|
C
|
unknown
| 7,189
|
#
# Default build settings. Included in project makefile
#
# This makefile also helps to build the examples. It tries to figure out if
# it is an in-tree-build or if it is a seperate project (it's then invoked
# from the top makefile)
#
ifndef PROJECTNAME
$(error PROJECTNAME is not set. . This makefile is invoked the wrong way))
endif
ifndef ROOTDIR
$(error ROOTDIR is not set. This makefile is invoked the wrong way)
endif
ifneq (${MAKELEVEL},0)
#####################################################################
# Default settings
#####################################################################
PROJECT_DIR:=$(abspath $(CURDIR)/..)
ifneq ($(findstring RTE,$(MOD_USE)),)
VPATH := $(PROJECT_DIR)/config/$(board_name)/Rte/Config $(PROJECT_DIR)/config/Rte/Config $(VPATH)
VPATH := $(PROJECT_DIR)/config/$(board_name)/Rte/Contract $(PROJECT_DIR)/config/Rte/Contract $(VPATH)
VPATH := $(PROJECT_DIR)/config/$(board_name)/Rte/MemMap $(PROJECT_DIR)/config/Rte/MemMap $(VPATH)
inc-y := $(PROJECT_DIR)/config/$(board_name)/Rte/Config $(PROJECT_DIR)/config/Rte/Config $(inc-y)
inc-y := $(PROJECT_DIR)/config/$(board_name)/Rte/Contract $(PROJECT_DIR)/config/Rte/Contract $(inc-y)
inc-y := $(PROJECT_DIR)/config/$(board_name)/Rte/MemMap $(PROJECT_DIR)/config/Rte/MemMap $(inc-y)
endif
VPATH += ..
# The more precise configuration, the higher preceedance.
VPATH := ../config/$(board_name) ../config $(VPATH)
inc-y := ../config/$(board_name) ../config $(inc-y)
ldcmdfile-y = linkscript_$(COMPILER).lcf
vpath %.ldf $(ROOTDIR)/$(ARCH_KERNEL_PATH-y)/scripts
vpath %.ldf $(board_path)
# What I want to build
ifeq (${CFG_BUILD_AS_LIB},y)
build-lib-y = $(PROJECTNAME).a
else
ifneq ($(findstring HOST_TEST,$(def-y)),)
build-exe-y = $(PROJECTNAME).out
else
build-exe-y = $(PROJECTNAME).elf
build-srec-$(CFG_CREATE_SREC) = $(PROJECTNAME).s3
build-srec-fill-$(CFG_CREATE_SREC) = $(PROJECTNAME)_fill.s3
ifeq (${CFG_POSTBUILD},y)
build-srec-pb-$(CFG_CREATE_SREC) = $(PROJECTNAME)_pb.s3
endif
os-orti-$(USE_KERNEL) = $(PROJECTNAME).orti
endif
endif
else
#####################################################################
# In-tree-build (for examples)
#####################################################################
# ifneq ($(BOARDDIR),)
# $(warning BOARDDIR defined in an in-tree-build)
# endif
BUILD_IN_TREE=y
# Try to get name of board
ifeq ($(boarddir),)
boardpath=$(realpath $(CURDIR)/../..)
boarddir=$(subst $(realpath $(ROOTDIR)/boards)/,,$(boardpath))
endif
# Redirect to normal build
.PHONY: all clean
all:
@echo "==========[ Building \"$(example)\" ]=========="
$(Q)$(MAKE) -C $(ROOTDIR) BOARDDIR=$(boarddir) BDIR=$(CURDIR) all
clean:
@echo Removing dir $(boarddir)
rm -rfv obj_$(boarddir)
rm -rfv $(ROOTDIR)/binaries/$(boarddir)/$(PROJECTNAME)*
@echo done!
endif
|
2301_81045437/classic-platform
|
scripts/project_defaults.mk
|
Makefile
|
unknown
| 2,982
|
###############################################################################
# BUILD SETTINGS #
###############################################################################
# By default, create a srec file.
# Board settings
include $(ROOTDIR)/boards/build_config_bsw.mk
include $(board_path)/build_config.mk
# Project settings
-include ../build_config.mk
# Perform build system version check
include $(ROOTDIR)/scripts/version_check.mk
###############################################################################
# MODULE CONFIGURATION #
###############################################################################
# Some useful vars
CFG_ARCH_$(ARCH):=y
RELDIR := $(subst $(TOPDIR)/,,$(CURDIR))
target := $(subst /,_,$(SUBDIR))
goal=$@
define MOD_AVAIL_template
MOD_$(1)=y
endef
define MOD_USE_template
USE_$(1)=y
def-y += USE_$(1)
endef
define CFG_template
CFG_$(1)=y
def-y += CFG_$(1)
endef
$(foreach mod,$(MOD_AVAIL),$(eval $(call MOD_AVAIL_template,${mod})))
$(foreach mod,$(sort $(MOD_USE)),$(eval $(call MOD_USE_template,${mod})))
$(foreach mod,$(CFG),$(eval $(call CFG_template,${mod})))
#def-y += $(ARCH) $(ARCH_FAM) $(ARCH_MCU)
# Select console / debug
$(foreach mod,$(SELECT_OS_CONSOLE),$(eval $(call MOD_USE_template,${mod})))
$(foreach mod,$(SELECT_CONSOLE),$(eval $(call MOD_USE_template,${mod})))
def-y += SELECT_OS_CONSOLE=$(if $(SELECT_OS_CONSOLE),$(SELECT_OS_CONSOLE),TTY_NONE)
def-y += SELECT_CONSOLE=$(if $(SELECT_CONSOLE),$(SELECT_CONSOLE),TTY_NONE)
def-$(USE_DEBUG_PRINTF) += USE_DEBUG_PRINTF
not_avail = $(filter-out $(MOD_AVAIL),$(sort $(MOD_USE)))
ifneq ($(not_avail),)
$(error Trying to build a module that is not available: $(not_avail))
endif
COMPILER?=gcc
ifeq (${COMPILER},gcc)
# Assume that the board have set DEFAULT_CROSS_COMPILE
CROSS_COMPILE?=${DEFAULT_CROSS_COMPILE}
endif
ifeq (${COMPILER},cw)
CW_COMPILE?=${DEFAULT_CW_COMPILE}
endif
ifeq (${COMPILER},iar)
IAR_COMPILE?=${DEFAULT_IAR_COMPILE}
endif
ifeq (${COMPILER},diab)
DIAB_COMPILE?=${DEFAULT_DIAB_COMPILE}
endif
ifeq (${COMPILER},ghs)
GHS_COMPILE?=${DEFAULT_GHS_COMPILE}
endif
ifeq (${COMPILER},armcc)
ARMCC_COMPILE?=${DEFAULT_ARMCC_COMPILE}
endif
DATE=$(shell date +"%F %X")
cflags-y += -DBUILD_DATE="$(DATE)"
###############################################################################
# TOOLS CONFIGURATION #
###############################################################################
# set debug optimization level as default
SELECT_OPT?=OPT_DEBUG
# Create srecords by default
CFG_CREATE_SREC?=n
# Do a library build
CFG_BUILD_AS_LIB = $(BUILD_AS_LIB)
ifeq ($(findstring OPT_,$(SELECT_OPT)),OPT_)
$(eval CFG_$(SELECT_OPT)=y)
else
CFG_OPT_FLAGS=y
endif
$(info SELECT_OPT=$(SELECT_OPT) $(origin SELECT_OPT))
ECUM_INC=system/EcuM/inc
OS_TEST_FOLDER?=system/Os/utest
OS_INC=Os/rtos/inc
OSAL_ARCH=system/Os/osal
ARCH_KERNEL_PATH-y = $(OSAL_ARCH)/$(ARCH_FAM)/$(ARCH)
ARCH_DRIVER_PATH-y = mcal/arch/$(ARCH)
CFG_CC_$(COMPILER)=y
# Include compiler settings
include $(ROOTDIR)/scripts/cc_$(COMPILER).mk
# Include pclint or splint settings
ifneq ($(PCLINT),)
include $(ROOTDIR)/scripts/cc_pclint.mk
endif
ifneq ($(SPLINT),)
include $(ROOTDIR)/scripts/cc_splint.mk
endif
SRECORD_PATH?=/c/devtools/srecord
SREC_CAT=$(SRECORD_PATH)/srec_cat.exe
SREC_INFO=$(SRECORD_PATH)/srec_info.exe
SREC_CMP=$(SRECORD_PATH)/srec_cmp.exe
###############################################################################
# PROJECT MAKEFILE #
###############################################################################
$(info from rules.mk, $(abspath $(CURDIR)))
# Include project makefile
include ../makefile
# All module object files (guarded for backwards compatability)
ifndef _BOARD_COMMON_MK
include $(ROOTDIR)/boards/board_common.mk
endif
# Misc tools
ifneq ($(CFG_BOOT),)
include $(board_path)/boot_info.mk
include $(ROOTDIR)/scripts/bootloader_image.mk
endif
#####
inc-y += ../include
inc-y += $(ROOTDIR)/include
inc-y += $(ROOTDIR)/include/rte
inc-y += $(ROOTDIR)/include/$(ARCH_FAM)
inc-y += $(ROOTDIR)/include/$(ARCH_FAM)/$(ARCH)
inc-y += $(ROOTDIR)/$(ECUM_INC)
inc-y += $(inc-y-y)
# Override system includes...
ifeq ($(COMPILER),armcc)
cflags-y += $(addprefix -J,$(inc-system-y) $(inc-system2-y) )
else
inc-y := $(inc-system-y) $(inc-system2-y) $(inc-y) $(inc-last-y)
endif
# Find default linker files
inc-y += $(ROOTDIR)/scripts/linker
VPATH := $(vpath-first-y) $(VPATH) $(vpath-last-y)
###############################################################################
# POST BUILD #
###############################################################################
all-mod-post += $(build-srec-pb-y)
ifeq ($(CFG_POSTBUILD),y)
all-mod += PreCompiledDataHash.h
endif
# The memory bounderies for post build section shall be defined in build_config.mk
def-$(CFG_POSTBUILD) += POSTBUILD_ADDRESS=$(POSTBUILD_ADDRESS_START)
def-$(CFG_POSTBUILD) += POSTBUILD_ADDRESS_END=$(POSTBUILD_ADDRESS_STOP)
###############################################################################
# LINT #
###############################################################################
LINT_EXCLUDE_PATHS := $(foreach path,$(LINT_EXCLUDE_PATHS), $(abspath $(path)) )
$(info $(LINT_EXCLUDE_PATHS))
LINT_BAD_EXCLUDE_PATHS := $(filter %/,$(LINT_EXCLUDE_PATHS))
ifneq ($(LINT_BAD_EXCLUDE_PATHS),)
$(warning LINT_EXCLUDE_PATHS entries must not end in '/'. Ignoring $(LINT_BAD_EXCLUDE_PATHS))
endif
LINT_NICE_EXCLUDE_PATHS := $(filter-out %/,$(LINT_EXCLUDE_PATHS))
LINT_NICE_EXCLUDE_PATHS := $(foreach path,$(LINT_NICE_EXCLUDE_PATHS),$(path)/)
LINT_NICE_EXCLUDE_PATHS := $(foreach path,$(LINT_NICE_EXCLUDE_PATHS),$(subst /C/, , $(path)))
ifneq ($(PCLINT),)
define run_pclint
$(if
$(filter "match", $(foreach ex_path,$(LINT_NICE_EXCLUDE_PATHS), $(if $(findstring $(ex_path), $(dir $(abspath $<))),"match", ))),
$(info $(abspath $<):0:0: Info: Not running lint check on $(abspath $<)),
$(Q)$(PCLINT) $(addprefix $(lintinc_ext),$(inc-y)) $(lint_extra) $(addprefix $(lintdef_ext),$(def-y) $(DEF_$@)) $(abspath $<))
endef
endif
ifneq ($(SPLINT),)
define run_splint
$(if
$(filter $(dir $(abspath $<)),$(LINT_NICE_EXCLUDE_PATHS)),
$(info $(abspath $<):0:0: Info: Not running lint check on $(abspath $<)),
$(Q)$(SPLINT) $(splint_extra) $(addprefix $(lintinc_ext),$(inc-y)) $(addprefix $(lintdef_ext),$(def-y) $(DEF_$@)) $(abspath $<))
endef
endif
###############################################################################
# TOP-LEVEL TARGETS #
###############################################################################
.PHONY : distro_dir
distro_dir : FORCE
@echo ">>>> Creating ditribution directory: " $(DISTRONAME)
@mkdir -p $(BDIR)/$(DISTRONAME)
@chmod 777 $(BDIR)/$(DISTRONAME)
.PHONY : copydist
copydist : FORCE
@echo ">>>> Copying files"
@cp -R $(ROOTDIR)/.settings $(BDIR)/$(DISTRONAME)
@cp -R $(ROOTDIR)/include $(BDIR)/$(DISTRONAME)
@cp $(ROOTDIR)/base/*.* $(BDIR)/$(DISTRONAME)/include/
@cp $(ROOTDIR)/base/compiler/*.* $(BDIR)/$(DISTRONAME)/include/
@cp -R $(ROOTDIR)/scripts $(BDIR)/$(DISTRONAME)
@cp -R $(ROOTDIR)/arxml $(BDIR)/$(DISTRONAME)
@mkdir -p $(BDIR)/$(DISTRONAME)/boards
@cp -R $(ROOTDIR)/boards/$(BOARDDIR) $(BDIR)/$(DISTRONAME)/boards/
@cp -R $(ROOTDIR)/boards/generic $(BDIR)/$(DISTRONAME)/boards/
@cp -R $(ROOTDIR)/boards/board_common.mk $(BDIR)/$(DISTRONAME)/boards/
@cp -R $(ROOTDIR)/boards/build_config_bsw.mk $(BDIR)/$(DISTRONAME)/boards/
@mkdir -p $(BDIR)/$(DISTRONAME)/$(OSAL_ARCH)
@mkdir -p $(BDIR)/$(DISTRONAME)/$(OSAL_ARCH)/$(ARCH_FAM)
@mkdir -p $(BDIR)/$(DISTRONAME)/$(OSAL_ARCH)/$(ARCH_FAM)/$(ARCH)
@mkdir -p $(BDIR)/$(DISTRONAME)/$(OSAL_ARCH)/$(ARCH_FAM)/$(ARCH)/kernel
@cp -R $(ROOTDIR)/$(OSAL_ARCH)/$(ARCH_FAM)/$(ARCH)/scripts $(BDIR)/$(DISTRONAME)/$(OSAL_ARCH)/$(ARCH_FAM)/$(ARCH)/
@cp -R $(ROOTDIR)/$(OSAL_ARCH)/$(ARCH_FAM)/$(ARCH)/kernel/*.h $(BDIR)/$(DISTRONAME)/$(OSAL_ARCH)/$(ARCH_FAM)/$(ARCH)/kernel
@cp $(ROOTDIR)/system/Os/rtos/inc/Os.h $(BDIR)/$(DISTRONAME)/include
@cp -R $(ROOTDIR)/integration $(BDIR)/$(DISTRONAME)/
@cp $(ROOTDIR)/scripts/project_tmpl.txt $(BDIR)/$(DISTRONAME)/.project
@cp $(ROOTDIR)/makefile $(BDIR)/$(DISTRONAME)/
.PHONY : copyapp
copyapp : $(COPY_APP_INCLUDES)
@mkdir -p $(BDIR)/$(DISTRONAME)/libs
@cp $(ROOTDIR)/binaries/$(board_name)/$(PROJECTNAME).a $(BDIR)/$(DISTRONAME)/libs
.PHONY: distro
distro: distro_dir copydist copyapp
@echo ">>>> DONE"
.PHONY: clean_distro
clean_distro:
rm -R $(BDIR)/$(DISTRONAME)
# Clean rules are split, clean_obj only removes the local obj folder
.PHONY clean clean_obj:
clean_obj: FORCE
@echo
@echo " >> Rules Clean $(CURDIR)"
$(Q)-rm -v *
# Clean both the local obj folder, and the central binaries folder
clean: clean_obj
$(Q)-rm -v $(ROOTDIR)/binaries/$(board_name)/*
.PHONY : config
config: FORCE
@echo ">>>> Available modules:" $(sort $(MOD_AVAIL))
@echo ">>>> Used modules: " $(sort $(MOD_USE))
@echo $(MOD) ${def-y}
.PHONY : module_config
module_config: FORCE
@echo ">>>> Available modules:" $(sort $(MOD_AVAIL))
@echo ">>>> Used modules: " $(sort $(MOD_USE))
.PHONY : show_build
show_build: FORCE
@echo ""
@echo "==========[ BUILD INFO ]==========="
@echo " Core version: $(core_version)"
@echo " BDIR: $(BDIR) [$(origin BDIR)]"
@echo " BOARDDIR: $(BOARDDIR) [$(origin BOARDDIR)]"
@echo " COMPILER: $(COMPILER) [$(origin COMPILER)]"
ifeq ($(COMPILER),diab)
@echo " DIAB_COMPILE: $(DIAB_COMPILE) [$(origin DIAB_COMPILE)]"
@echo " Compiler info: $(shell ${DIAB_COMPILE}/bin/dcc -V)"
else ifeq ($(COMPILER),cw)
@echo " CW_COMPILE: $(CW_COMPILE) [$(origin CW_COMPILE)]"
@echo " Compiler info: $(shell ${CW_COMPILE}/PowerPC_EABI_Tools/Command_Line_Tools/mwcceppc.exe -version)"
else ifeq ($(COMPILER),iar)
@echo " IAR_COMPILE: $(IAR_COMPILE) [$(origin IAR_COMPILE)]"
else ifeq ($(COMPILER),ghs)
@echo " GHS_COMPILE: $(GHS_COMPILE) [$(origin GHS_COMPILE)]"
ifneq ($(wildcard ${GHS_COMPILE}/ccrh850.exe),)
@echo " Compiler info: $(shell ${GHS_COMPILE}/ccrh850.exe -V dummy)"
endif
ifneq ($(wildcard ${GHS_COMPILE}/ccppc.exe),)
@echo " Compiler info: $(shell ${GHS_COMPILE}/ccppc.exe -V dummy)"
endif
else ifeq ($(COMPILER),iar)
@echo " IAR_COMPILE: $(IAR_COMPILE) [$(origin IAR_COMPILE)]"
else ifeq ($(COMPILER),armcc)
@echo " ARMCC_COMPILE: $(ARMCC_COMPILE) [$(origin ARMCC_COMPILE)]"
@echo " Compiler info: $(shell $(ARMCC_COMPILE)/bin/armcc --version_number)"
else
ifneq ($(CLANG_COMPILE),)
@echo " CLANG_COMPILE: $(CLANG_COMPILE) [$(origin CLANG_COMPILE)]"
@echo " CFG_CLANG_SAFECODE: $(CFG_CLANG_SAFECODE) [$(origin CFG_CLANG_SAFECODE)]"
endif
@echo " CROSS_COMPILE: $(CROSS_COMPILE) [$(origin CROSS_COMPILE)]"
@echo " Compiler info: $(shell ${CROSS_COMPILE}gcc --version)"
endif
@echo " SELECT_OPT: $(SELECT_OPT) [$(origin SELECT_OPT)]"
@echo " CURDIR: $(CURDIR)"
@echo " SELECT_CONSOLE: $(SELECT_CONSOLE) [$(origin SELECT_CONSOLE)]"
FORCE:
$(ROOTDIR)/binaries/$(board_name):
@mkdir -p $@
all-mod += $(build-hex-y) $(build-exe-y) $(build-srec-y)
all-mod += $(build-lib-y) $(build-bin-y)
ifneq ($(wildcard $(SREC_CAT)),)
all-mod-post += $(build-srec-fill-y)
endif
.PHONY all:
all: | show_build module_config $(ROOTDIR)/binaries/$(board_name) $(all-mod) $(all-mod-post)
all: show_build module_config $(all-mod) $(all-mod-post) $(ROOTDIR)/binaries/$(board_name)
@cp -v $(all-mod) $(all-mod-post) $(os-orti-y) $(ROOTDIR)/binaries/$(board_name)
.SUFFIXES:
.PRECIOUS: %.s
###############################################################################
# TARGETS #
###############################################################################
obj-y := $(filter-out $(rm-obj-y),$(obj-y))
# Simple depencendy stuff
-include $(subst .o,.d,$(obj-y))
# Some dependency for xxx_offset.c/h also
-include $(subst .h,.d,$(dep-y))
# Compile
%.o: %.c
@echo " >> CC $(notdir $<)"
$(Q)$(CC_PRE)$(CC) $(filter-out $(rm-cflags),$(CFLAGS)) $(CFLAGS_$@) $(cflags-post-y) -o $(goal) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y) $(DEF_$@)) $(abspath $<)
$(do-compile-post)
# run lint if enabled
$(run_pclint)
$(run_splint)
%.o: %.cpp
@echo " >> CXX $(notdir $<)"
$(Q)$(CXX) $(filter-out $(rm-cxxflags),$(CXXFLAGS)) $(CFLAGS_$@) $(cflags-post-y) -o $(goal) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y) $(DEF_$@)) $(abspath $<)
$(do-compile-post)
# Assembler
%.o: %.s
@echo " >> AS $(notdir $<)"
$(Q)$(AS) $(filter-out $(rm-asflags),$(ASFLAGS)) -o $(goal) $<
# PP Assembler
%.s: %.sx
@echo " >> CPP $(notdir $<)"
$(Q)$(CPP) $(CPP_ASM_FLAGS) $(CPPOUT) $@ $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $<
$(do-sx-to-s-post)
# cat $@
# Board linker files are in the board directory
inc-y += $(board_path)
# *.ldf (file on disc) -> *.lcf (preprocessed *.ldf file)
# Preprocess linker files..
%.lcf: %.ldf
@echo " >> CPP $(notdir $<)"
ifeq ($(COMPILER),iar)
@cp $< $@
else
$(Q)$(CPP) $(CPP_ASM_FLAGS) $(CPPOUT) $@ $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $<
endif
#$(error $(os-orti-y))
# ORTI file
$(os-orti-y): Os.orti
@cp $< $@
.PHONY $(ROOTDIR)/libs:
$(ROOTDIR)/libs:
$(Q)mkdir -p $@
dep-y += $(ROOTDIR)/libs
# lib output
$(build-lib-y): $(dep-y) $(obj-y)
@echo
@echo " >> AR $@"
$(Q)$(AR) $(ARFLAGS) -r -o $@ $(obj-y) 2> /dev/null
# hex output
$(build-hex-y): $(build-exe-y)
@echo
@echo " >> OBJCOPY $@"
$(Q)$(CROSS_COMPILE)objcopy -O ihex $< $@
# srecord output
$(build-srec-y): $(build-exe-y)
$(do-objcopy)
CROP_SREC?=0
# srecord filled output
$(build-srec-fill-y): $(build-srec-y)
$(Q)$(SREC_CAT) $< -fill 0xff -over $< -o $@
ifneq (${CROP_SREC},0)
$(Q)$(SREC_CAT) $@ -crop 0x0 ${CROP_SREC} -o $@
endif
$(Q)$(SREC_INFO) $@
# Create Post build image
$(build-srec-pb-y): $(build-srec-fill-y)
$(Q)$(SREC_CAT) $< -crop $(POSTBUILD_ADDRESS_START) $(POSTBUILD_ADDRESS_STOP) -o $@
$(Q)$(SREC_INFO) $@
# bin output
#$(build-bin-y): $(build-exe-y)
# @echo
# @echo " >> OBJCOPY $@"
# $(Q)$(CROSS_COMPILE)objcopy -O binary $< $@
ifeq ($(BOARDDIR),gnulinux)
$(build-exe-y): $(dep-y) $(obj-y) $(os-orti-y) $(sim-y) $(libitem-y)
@echo
@echo " >> LD Using gcc to link gnulinux board. $@"
$(Q)$(CC) -Xlinker -Map=$(basename $(@F)).map -o $@ $(libpath-y) $(obj-y) $(lib-y) $(libitem-y) $(filter-out $(rm-ldflags),$(LDFLAGS))
$(do-ld-post)
@echo
@echo " >>>>>>> DONE <<<<<<<<<"
@echo
else
$(build-exe-y): $(dep-y) $(obj-y) $(os-orti-y) $(sim-y) $(libitem-y) $(ldcmdfile-y)
@echo
@echo " >> LD $@"
$(do-ld-pre)
ifeq ($(COMPILER),iar)
$(Q)$(LD) $(filter-out $(rm-ldflags),$(LDFLAGS)) --config $(ldcmdfile-y) --map $(basename $(@F)).map $(sort $(obj-y)) $(libpath-y) $(lib-y) $(libitem-y) -o $@
else ifeq ($(CROSS_COMPILE)$(COMPILER),gcc)
$(Q)$(CC_PRE)$(CC) -Xlinker -Map=$(basename $(@F)).map -o $@ $(libpath-y) $(obj-y) $(lib-y) $(libitem-y) $(filter-out $(rm-ldflags),$(LDFLAGS))
else
$(Q)$(LD) $(filter-out $(rm-ldflags),$(LDFLAGS)) $(LD_FILE) $(LD_FILE2)$(ldcmdfile-y) -o $@ $(libpath-y) $(LD_START_GRP) $(obj-y) $(lib-y) $(libitem-y) $(LD_END_GRP) $(LDMAPFILE)
$(do-memory-footprint)
$(do-memory-footprint2-y)
endif #($(CROSS_COMPILE),)
$(do-ld-post)
@echo
@echo " >>>>>>> DONE <<<<<<<<<"
@echo
endif #($(BOARDDIR),gnulinux)
# Create the Post-Build checksum file
#
# Note: Since we cant use VPATH for these file, the path to the config folder is needed.
# The variable pb-pc-path must be specified in the application build-config.mk
PreCompiledDataHash.h: $(addprefix $(pb-pc-path)/,$(pb-pc-file-y))
$(Q)cat $(^) | $(SED) $$'s/$$/\r/' | md5sum | $(SED) 's/\([a-f0-9]\{16\}\)\([a-f0-9]\{16\}\).*/#define PRE_COMPILED_DATA_HASH_LOW 0x\1=#define PRE_COMPILED_DATA_HASH_HIGH 0x\2/' | tr "=" "\n" > $@
|
2301_81045437/classic-platform
|
scripts/rules.mk
|
Makefile
|
unknown
| 16,780
|
#!/bin/sh
UNAME=`uname`
echo $UNAME
#if expr match "$UNAME" 'MINGW32_NT-.*' > 6 ]; then
# compiler=/c/devtools/Codesourcery/arm-2009q1/bin/arm-none-eabi-
#elif if expr match "$UNAME" 'CYGWIN_NT_NT-.*'; then
# compiler=/cygdrive/c/devtools/Codesourcery/arm-2009q1/bin/arm-none-eabi-
#else
# echo No default path for $UNAME set. Quitting.
#fi
if test x${UNAME:0:7} = xMINGW32; then
compiler=/c/devtools/Codesourcery/arm-2009q1/bin/arm-none-eabi-
elif test x${UNAME:0:9} = xCYGWIN_NT; then
compiler=/cygdrive/c/devtools/Codesourcery/arm-2009q1/bin/arm-none-eabi-
else
echo No default path for $UNAME set. Quitting.
fi
#if test x$UNAME = xMINGW32_NT-5.1; then
# compiler=/c/devtools/Codesourcery/arm-2009q1/bin/arm-none-eabi-
#elif test x$UNAME = xCYGWIN_NT-5.1; then
# compiler=/cygdrive/c/devtools/Codesourcery/arm-2009q1/bin/arm-none-eabi-
#else
# echo No default path for $UNAME set. Quitting.
#fi
if [ "$compiler" != "" ]; then
export CROSS_COMPILE=$compiler
export BOARDDIR=et_stm32_stamp
export BDIR=examples/tiny
echo $CROSS_COMPILE
echo $BOARDDIR
echo $BDIR
fi
|
2301_81045437/classic-platform
|
scripts/set_env_win_arm_cs.sh
|
Shell
|
unknown
| 1,151
|
#!/bin/bash
#rm -rf _build_can/html/
#rm -rf _build_can/latex/
#rm -rf _build_can/html_mcu_mpc55xx/
#rm -rf _build_can/html_mcu_tms570/
#rm -rf _build_can/latex_mcu_mpc55xx/
#rm -rf _build_can/latex_mcu_tms570/
# 1 - module
# 2 - mcu
# 3 - type (um or dd)
function build_mcal_doc() {
# Create conf.py files
cat $cdir/conf_main.py > $rdir/mcal/$1/doc/$3/conf.py
cat $rdir/mcal/$1/doc/$3/conf_part.py >> $rdir/mcal/$1/doc/$3/conf.py
# Generate html
sphinx-build.exe -b html -t $2 $rdir/mcal/$1/doc/$3 $rdir/_build_$3_$1/html_$2/
# Generate pdf
sphinx-build.exe -b latex -t $2 $rdir/mcal/$1/doc/$3 $rdir/_build_$3_$1/latex_$2/
pushd $rdir/_build_$3_$1/latex_$2/
pdfLatex can_$3_$2.tex
popd
}
function build_mcal_dd_doc() {
# Create conf.py files
cat $cdir/conf_main.py > $rdir/mcal/doc/dd/conf.py
cat $rdir/mcal/doc/dd/conf_part.py >> $rdir/mcal/doc/dd/conf.py
sphinx-build.exe -b html $rdir/mcal/doc/dd $rdir/_build_mcal_dd/html_mcal/
# Generate pdf
sphinx-build.exe -b latex $rdir/mcal/doc/dd $rdir/_build_mcal_dd/latex_mcal/
pushd $rdir/_build_mcal_dd/latex_mcal/
pdfLatex mcal_dd.tex
popd
}
# Get script path
cdir=$(dirname "$(readlink -f "$0")")
rdir=$cdir/../..
# export path so extension can be found by sphinx.
export ARC_DOC_ROOT=$cdir
export PATH=$PATH:/d/tmp/miktex/texmfs/install/miktex/bin
#-----------------------------------
# MCAL
#-----------------------------------
# MCAL design description
build_mcal_dd_doc
# MCAL modules ( um and um_<mcu> )
#build_mcal_doc can mcu_mpc5xxx um
# MCAL module design description
#build_mcal_doc can mcu_mpc5xxx dd
exit
#sphinx-build.exe -b html -t mcu_tms570 mcal/Can/doc/ _build_can/html_mcu_tms570/
#sphinx-build.exe -b html -t mcu_mpc5xxx mcal/Can/doc/ _build_can/html_mcu_all/
#sphinx-build.exe -b latex -t mcu_mpc5xxx mcal/Can/doc _build_can/latex_mcu_mpc5xxx/
#sphinx-build.exe -b latex -t mcu_tms570 mcal/Can/doc _build_can/latex_mcu_tms570/
pushd _build_can/latex_mcu_mpc5xxx/
pdfLatex CANUM.tex
pdfLatex CANUM.tex
popd
pushd _build_can/latex_mcu_tms570/
pdfLatex CANUM.tex
pdfLatex CANUM.tex
popd
#sphinx-build.exe -b html mcal/Dio/doc/ _build_dio/html/
#sphinx-build.exe -b html mcal/doc/ _build_mcal/html/
#sphinx-build.exe -b latex mcal/doc/ _build_mcal/latex/
#pushd _build_mcal/latex/
#pdfLatex MCALdocumentation.tex
#popd
|
2301_81045437/classic-platform
|
scripts/sphinx/build_doc
|
Shell
|
unknown
| 2,447
|
# Invokation:
# From any directory
# - make -f ../../../../scripts/sphinx/build_doc.mk quick-start
#
# There should always be a index.rst file
#
#.PHONY: build_doc
# Some useful variables..
comma:= ,
empty:=
space:= $(empty) $(empty)
split = $(subst $(comma), ,$(1))
$(call split,$(BDIR))
# This dir.
#export ARC_DOC_ROOT=$(CURDIR)
# Root of the core directory
export ROOTDIR=$(CURDIR)/../..
export PYTHON_ROOT=/c/Python27
export MIKTEX_ROOT?=/c/devtools/miktex/texmfs/install/miktex/bin
export PATH:=$(PATH):$(PYTHON_ROOT):$(MIKTEX_ROOT):$(PYTHON_ROOT)/Scripts
SPHINXBUILD=python -msphinx
SPHINXQUICKSTART=sphinx-quickstart.exe
mkfile_path := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
export ARC_DOC_ROOT=$(mkfile_path)
$(info $(doc_module))
$(info $(doc_type))
$(info $(doc_mcu))
ifdef doc_mcu
doc_name=$(doc_module)_$(doc_type)_$(doc_mcu)
conf_opt=-m $(doc_module) -t $(doc_type) -a $(doc_mcu)
tag_opt=-t $(doc_mcu)
else
doc_name=$(doc_module)_$(doc_type)
conf_opt=-m $(doc_module) -t $(doc_type)
endif
%.rst: %.rstp
gcc -E -P -x c -traditional-cpp -Dcfg_$(doc_mcu) $< > $@
# Create conf.py from template (conf_main.py)
conf.py: $(SPHINXDIR)/conf_main.py $(SPHINXDIR)/create_conf.py
$(Q)echo Creating $<
cp $(SPHINXDIR)/conf_main.py conf.py
python $(SPHINXDIR)/create_conf.py $(conf_opt) >> conf.py
all: conf.py $(rstp-y)
$(SPHINXBUILD) $(tag_opt) -b html . obj_doc/html
$(SPHINXBUILD) $(tag_opt) -b latex . obj_doc/latex
#echo $doc_module_$doc_type
pushd obj_doc/latex && pdfLatex $(doc_name).tex && pdfLatex $(doc_name).tex
clean:
rm -rf obj_doc/* conf.py
quick-start:
$(SPHINXQUICKSTART)
|
2301_81045437/classic-platform
|
scripts/sphinx/build_doc.mk
|
Makefile
|
unknown
| 1,707
|
#!/bin/bash
#rm -rf _build_can/html/
#rm -rf _build_can/latex/
#rm -rf _build_can/html_mcu_mpc55xx/
#rm -rf _build_can/html_mcu_tms570/
#rm -rf _build_can/latex_mcu_mpc55xx/
#rm -rf _build_can/latex_mcu_tms570/
function check_precond() {
# Check gcc
if ! [ -x "$(command -v gcc)" ]; then
echo 'Error: gcc is not installed.' >&2
exit 1
fi
}
# 1 - to
# 2 - from
function create_symlink() {
if [ -f $1 ]; then
rm $1
fi
ln -s $2 $1
}
function to_upper() {
a=`echo $1 | awk '{print toupper($0)}'`
echo $a
}
# 1 - module
# 2 - type (um or dd)
# 3 - mcu
function build_mcal_doc() {
# Create conf.py files
cat $cdir/conf_main.py > $rdir/mcal/$1/doc/$2/conf.py
python create_conf.py -m $1 -t $2 -a $3 >> $rdir/mcal/$1/doc/$2/conf.py
#
# Create symlink to arch
#
pushd $rdir/mcal/$1/doc/$2
create_symlink ug_arch.rst arch/ug_$3.rst
create_symlink arch/docref_arch.rst arch/docref_$3.rst
# Preprocess if exist...
if [ -f intro.rstp ]; then
mcu_cap=$( to_upper $3 )
gcc -E -P -x c -traditional-cpp -DCFG_$mcu_cap intro.rstp > intro.rst
fi
# Generate html
sphinx-build.exe -b html -t $3 . $rdir/_build_$1_$2_$3/html/
# Generate latex
sphinx-build.exe -b latex -t $3 . $rdir/_build_$1_$2_$3/latex/
# Cleanup
rm arch/docref_arch.rst
rm ug_arch.rst
#rm conf.py
popd
# Pdf
pushd $rdir/_build_$1_$2_$3/latex
pdfLatex $1_$2_$3.tex
popd
}
# 1 - module
# 2 - type (um or dd)
# ( 3 - mcu )
function build_mcal_dd_doc() {
# Create conf.py files
cat $cdir/conf_main.py > $rdir/mcal/doc/$2/conf.py
python create_conf.py -m $1 -t $2 >> $rdir/mcal/doc/$2/conf.py
pushd $rdir/mcal/doc/$2
# Generate html
sphinx-build.exe -b html . $rdir/_build_$1_$2/html/
# Generate latex
sphinx-build.exe -b latex . $rdir/_build_$1_$2/latex/
popd
# Pdf
pushd $rdir/_build_$1_$2/latex
pdfLatex $1_$2.tex
popd
}
check_precond
export PATH=$PATH:/c/Python27:/c/devtools/miktex/texmfs/install/miktex/bin
# Get script path
#cdir=$(dirname "$(readlink -f "$0")")
cdir=$ARC_DOC_ROOT
echo $cdir
rdir=$cdir/../..
echo $rdir
# export path so extension can be found by sphinx.
#export ARC_DOC_ROOT=$cdir
#-----------------------------------
# MCAL
#-----------------------------------
# MCAL design description
#build_mcal_dd_doc MCAL dd
# MCAL modules ( um and um_<mcu> )
#build_mcal_doc can um mpc5xxx
# MCAL module design description
#build_mcal_doc can dd mpc5xxx
# module safety manual
#build_mcal_doc can sm mpc5xxx
# MCAL modules ( um and um_<mcu> )
build_mcal_doc pwm um mpc5xxx
# MCAL module design description
build_mcal_doc pwm dd mpc5xxx
# module safety manual
build_mcal_doc pwm sm mpc5xxx
#
# DIO
#
# MCAL modules ( um and um_<mcu> )
build_mcal_doc dio um mpc5xxx
# MCAL module design description
build_mcal_doc dio dd mpc5xxx
# module safety manual
build_mcal_doc dio sm mpc5xxx
#
# Port
#
# MCAL modules ( um and um_<mcu> )
build_mcal_doc Port um mpc5xxx
# MCAL module design description
build_mcal_doc Port dd mpc5xxx
# module safety manual
build_mcal_doc Port sm mpc5xxx
#
# MCU
#
# MCAL modules ( um and um_<mcu> )
build_mcal_doc MCU um mpc5xxx
# MCAL module design description
build_mcal_doc MCU dd mpc5xxx
# module safety manual
build_mcal_doc MCU sm mpc5xxx
#
# ADC
#
# MCAL modules ( um and um_<mcu> )
build_mcal_doc ADC um mpc5xxx
# MCAL module design description
build_mcal_doc ADC dd mpc5xxx
# module safety manual
build_mcal_doc ADC sm mpc5xxx
exit
|
2301_81045437/classic-platform
|
scripts/sphinx/build_doc.sh
|
Shell
|
unknown
| 3,775
|
#!/bin/bash
# $1 - HTML source, e.g. html/content.html
#
cdir=`dirname $0`
echo "Converting"
#/c/devtools/Pandoc/pandoc --columns 1000 -r docx -t rst-simple_tables $1 > index.pandoc
mv $1/page* $1/content.html
/c/devtools/Pandoc/pandoc --columns 1000 -r html -t rst $1/content.html > index_pandoc.rst
#cp $1/*.png .
apa=/c/Users/mahi/git/arc-a4/core/scripts/sphinx/
python $apa/pandoc_to_rst.py index_pandoc.rst > index.rst
#cp index.rst $cdir/../../safety_security/Sm/doc/
#cp *.pnh $cdir/../../safety_security/Sm/doc/
|
2301_81045437/classic-platform
|
scripts/sphinx/confluence_to_rst.sh
|
Shell
|
unknown
| 558
|
import argparse
app = []
sec = []
bla = []
name_map = [
("um","User Manual"),
("dd","Design Description"),
("sm","Safety Manual")
]
userm = ""
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--arch", dest = "arch", help="arc")
parser.add_argument("-t", "--type", dest = "type", help="type")
parser.add_argument("-m", "--module", dest = "module", help="module")
args = parser.parse_args()
for x in name_map:
if ( x[0] == args.type ):
userm = x[1]
if (userm != ""):
module = args.module.upper()
doc_name = "%s %s" % (module,userm)
if (args.arch != None ):
doc_name = "%s for %s" %(doc_name, args.arch.upper())
latex_name="%s_%s_%s.tex" % (args.module,args.type,args.arch)
else:
latex_name="%s_%s.tex" % (args.module,args.type)
print "project = u\'%s'" % (doc_name)
print ""
print "latex_documents = [(master_doc, u\'%s\', u\'%s\',u\'Arccore\', \'manual\'),]" % (latex_name, doc_name)
print ""
if (args.arch != None ):
print "rst_epilog = \"\"\"\n.. |mcu| replace:: %s\n\"\"\"" % (args.arch)
|
2301_81045437/classic-platform
|
scripts/sphinx/create_conf.py
|
Python
|
unknown
| 1,161
|
#!/usr/bin/python
import argparse
#import os
import os
import shutil
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('pairs', metavar='N', nargs='+',
help='an integer for the accumulator')
args = parser.parse_args()
for key,value in vars(args).iteritems():
for val in value:
dst,src=val.split(",")
print src
print dst
shutil.copyfile(src, dst)
#os.symlink(str(src), str(dst))
|
2301_81045437/classic-platform
|
scripts/sphinx/create_symlink.py
|
Python
|
unknown
| 481
|
.PHONY: build_doc
# This dir.
export ARC_DOC_ROOT=$(CURDIR)
# Root of the core directory
export ROOTDIR=$(CURDIR)/../..
export PYTHON_ROOT=/c/Python27
export MIKTEX_ROOT?=/d/tmp/miktex/texmfs/install/miktex/bin
export PATH:=$(PATH):$(MIKTEX_ROOT):$(PYTHON_ROOT)/Scripts
build_doc:
./build_doc.sh
|
2301_81045437/classic-platform
|
scripts/sphinx/makefile
|
Makefile
|
unknown
| 325
|
# -*- coding: utf-8 -*
# Convert a .rst to a
import argparse
import re
if __name__ == "__main__":
state = "toc"
parser = argparse.ArgumentParser()
parser.add_argument("file")
#parser.add_argument("-a", "--arch", dest = "arch", help="arc")
#parser.add_argument("-t", "--type", dest = "type", help="type")
#parser.add_argument("-m", "--module", dest = "module", help="module")
args = parser.parse_args()
file = open(args.file, "r")
for line in file:
#print line,
if ( state == "toc" ):
# Grab some useful information and then remove it..
# +------------------------------------+---------------------------------+-----------------------------------------------+
# | **Document No: **\ 14-05-813-16010 | **Responsible**: Mårten Hildell | **Approver**: LakshmiNarayanan Chandrasekaran |
# +------------------------------------+---------------------------------+-----------------------------------------------+
#
# Extract
#m = re.search('\*\*Document No: \*\* (.*)\|',line)
m = re.search('Document No:.*(14.*?)\|',line)
if m is not None:
print "Yeeeh"
print m.group(1)
print "ASASDASD"
print m.group(0)
#print m.group(1)
m = re.search('.. rubric:: Document References',line)
if m is not None:
state = "body"
else:
# First remove lines we don't want
q = re.search('..raw.*', line )
if q != None:
continue
q = re.sub('.. code:: syntaxhighlighter-pre', '.. code-block:: c', line )
q = re.sub('<.*>', '', q )
q = re.sub('^-','*', q )
print q,
#print line,
"""
#elif ( state == "body" ):
# print line,
#print line,
"""
|
2301_81045437/classic-platform
|
scripts/sphinx/pandoc_to_rst.py
|
Python
|
unknown
| 2,095
|
import os, re
from sphinx import addnodes
docs_to_remove = []
def setup(app):
app.ignore = []
app.connect('builder-inited', builder_inited)
app.connect('env-get-outdated', env_get_outdated)
app.connect('doctree-read', doctree_read)
def builder_inited(app):
for doc in app.env.found_docs:
first_directive = None
print app.env.srcdir
print os.sep
print doc
print app.env.config.source_suffix[0]
with open(app.env.srcdir + os.sep + doc + app.env.config.source_suffix[0], 'r') as f:
first_directive = f.readline() + f.readline()
if first_directive:
m = re.match(r'^\.\. meta::\s+:scope: ([a-zA-Z0-9_-]+)', first_directive)
if m and not app.tags.has(m.group(1)):
docs_to_remove.append(doc)
app.env.found_docs.difference_update(docs_to_remove)
def env_get_outdated(app, env, added, changed, removed):
added.difference_update(docs_to_remove)
changed.difference_update(docs_to_remove)
removed.update(docs_to_remove)
return []
def doctree_read(app, doctree):
for toctreenode in doctree.traverse(addnodes.toctree):
for e in toctreenode['entries']:
ref = str(e[1])
if ref in docs_to_remove:
toctreenode['entries'].remove(e)
|
2301_81045437/classic-platform
|
scripts/sphinx/sphinx-ext/scope.py
|
Python
|
unknown
| 1,357
|
# Verification that the build settings are sound
CORE_BUILD_SYSTEM_VERSION_MAJOR = 1
CORE_BUILD_SYSTEM_VERSION_MINOR = 0
CORE_BUILD_SYSTEM_VERSION_PATCH = 0
# Only check if specified
# (remove when we want to start checking always)
ifneq ($(REQUIRED_BUILD_SYSTEM_VERSION),)
REQUIRED_BUILD_SYSTEM_VERSION:=$(subst ., ,$(REQUIRED_BUILD_SYSTEM_VERSION))
REQUIRED_BUILD_SYSTEM_VERSION_MAJOR=$(word 1,$(REQUIRED_BUILD_SYSTEM_VERSION))
REQUIRED_BUILD_SYSTEM_VERSION_MINOR=$(word 2,$(REQUIRED_BUILD_SYSTEM_VERSION))
REQUIRED_BUILD_SYSTEM_VERSION_PATCH=$(word 3,$(REQUIRED_BUILD_SYSTEM_VERSION))
ifneq ($(CORE_BUILD_SYSTEM_VERSION_MAJOR),$(REQUIRED_BUILD_SYSTEM_VERSION_MAJOR))
ERROR_BUILD_SYSTEM_VERSION = y
endif
ifneq ($(CORE_BUILD_SYSTEM_VERSION_MINOR),$(REQUIRED_BUILD_SYSTEM_VERSION_MINOR))
ERROR_BUILD_SYSTEM_VERSION = y
endif
ifeq (y,$(ERROR_BUILD_SYSTEM_VERSION))
$(error Build system version mismatch. Core has $(CORE_BUILD_SYSTEM_VERSION_MAJOR).$(CORE_BUILD_SYSTEM_VERSION_MINOR), Project requires $(REQUIRED_BUILD_SYSTEM_VERSION_MAJOR).$(REQUIRED_BUILD_SYSTEM_VERSION_MINOR))
endif
else # Only check if specified
$(info >>>> Build system version check not performed.)
endif # Only check if specified
define assert_exist
$(if $(value $(1)),,
$(error [Build system] Missing variable: $(1)))
endef
#$(call assert_exist,BOARDDIR)
#$(call assert_exist,CROSS_COMPILE)
|
2301_81045437/classic-platform
|
scripts/version_check.mk
|
Makefile
|
unknown
| 1,416
|
#BswM
obj-$(USE_BSWM) += BswM.o
obj-$(USE_BSWM) += BswM_Cfg.o
pb-obj-$(USE_BSWM) += BswM_PBcfg.o
pb-pc-file-$(USE_BSWM) += BswM_Cfg.h BswM_Cfg.c
inc-$(USE_BSWM) += $(ROOTDIR)/system/BswM/inc
inc-$(USE_BSWM) += $(ROOTDIR)/system/BswM/src
vpath-$(USE_BSWM) += $(ROOTDIR)/system/BswM/src
|
2301_81045437/classic-platform
|
system/BswM/BswM.mod.mk
|
Makefile
|
unknown
| 295
|